diff options
Diffstat (limited to 'source/core')
-rw-r--r-- | source/core/StarImage.cpp | 6 | ||||
-rw-r--r-- | source/core/StarImage.hpp | 28 | ||||
-rw-r--r-- | source/core/StarJsonExtra.cpp | 19 |
3 files changed, 39 insertions, 14 deletions
diff --git a/source/core/StarImage.cpp b/source/core/StarImage.cpp index 0147369..82e3b05 100644 --- a/source/core/StarImage.cpp +++ b/source/core/StarImage.cpp @@ -518,4 +518,10 @@ void Image::writePng(IODevicePtr device) const { png_destroy_write_struct(&png_ptr, &info_ptr); } +ImageView::ImageView(Image const& image) { + size = image.size(); + data = image.data(); + format = image.pixelFormat(); +} + } diff --git a/source/core/StarImage.hpp b/source/core/StarImage.hpp index 6f186df..478d074 100644 --- a/source/core/StarImage.hpp +++ b/source/core/StarImage.hpp @@ -6,11 +6,13 @@ namespace Star { -enum class PixelFormat { +enum class PixelFormat : uint8_t { RGB24, RGBA32, BGR24, - BGRA32 + BGRA32, + RGB_F, + RGBA_F }; uint8_t bitsPerPixel(PixelFormat pf); @@ -148,8 +150,12 @@ inline uint8_t bitsPerPixel(PixelFormat pf) { return 32; case PixelFormat::BGR24: return 24; - default: + case PixelFormat::BGRA32: return 32; + case PixelFormat::RGB_F: + return 96; + default: + return 128; } } @@ -161,8 +167,12 @@ inline uint8_t bytesPerPixel(PixelFormat pf) { return 4; case PixelFormat::BGR24: return 3; - default: + case PixelFormat::BGRA32: return 4; + case PixelFormat::RGB_F: + return 12; + default: + return 16; } } @@ -307,4 +317,14 @@ void Image::forEachPixel(CallbackType&& callback) { } } +struct ImageView { + inline bool empty() const { return size.x() == 0 || size.y() == 0; } + ImageView() = default; + ImageView(Image const& image); + + Vec2U size{0, 0}; + uint8_t const* data = nullptr; + PixelFormat format = PixelFormat::RGB24; +}; + } diff --git a/source/core/StarJsonExtra.cpp b/source/core/StarJsonExtra.cpp index dcf2bf6..81bc858 100644 --- a/source/core/StarJsonExtra.cpp +++ b/source/core/StarJsonExtra.cpp @@ -214,13 +214,12 @@ Color jsonToColor(Json const& v) { if (v.type() != Json::Type::Array || (v.size() != 3 && v.size() != 4)) throw JsonException("Json not an array of size 3 or 4 in jsonToColor"); Color c = Color::rgba(0, 0, 0, 255); - - c.setRed(v.getInt(0)); - c.setGreen(v.getInt(1)); - c.setBlue(v.getInt(2)); + c.setRedF((float)v.getInt(0) / 255.f); + c.setGreenF((float)v.getInt(1) / 255.f); + c.setBlueF((float)v.getInt(2) / 255.f); if (v.size() == 4) - c.setAlpha(v.getInt(3)); + c.setAlphaF((float)v.getInt(3) / 255.f); return c; } else if (v.type() == Json::Type::String) { @@ -232,11 +231,11 @@ Color jsonToColor(Json const& v) { Json jsonFromColor(Color const& color) { JsonArray result; - result.push_back(color.red()); - result.push_back(color.green()); - result.push_back(color.blue()); - if (color.alpha() != 255) { - result.push_back(color.alpha()); + result.push_back(color.redF() * 255.f); + result.push_back(color.greenF() * 255.f); + result.push_back(color.blueF() * 255.f); + if (color.alphaF() < 255.f) { + result.push_back(color.alphaF() * 255.f); } return result; } |