diff options
author | RedworkDE <10944644+RedworkDE@users.noreply.github.com> | 2023-04-07 17:44:36 +0200 |
---|---|---|
committer | Yuri Sizov <yuris@humnom.net> | 2023-04-07 17:44:36 +0200 |
commit | 4cc8a689bae5e3fe442a7ddbd962732ebf86a3e7 (patch) | |
tree | 1260e8961e05d5862b899a23d0b733846c0b1768 /thirdparty/thorvg/src/loaders/external_png | |
parent | f8517e1c4b05a0a6e5fbf85884d814145a136244 (diff) |
Update thorvg to 0.8.4
(cherry picked from commit cfed867da1a696692442bd6991449b864707b1d3)
Diffstat (limited to 'thirdparty/thorvg/src/loaders/external_png')
-rw-r--r-- | thirdparty/thorvg/src/loaders/external_png/tvgPngLoader.cpp | 29 | ||||
-rw-r--r-- | thirdparty/thorvg/src/loaders/external_png/tvgPngLoader.h | 4 |
2 files changed, 28 insertions, 5 deletions
diff --git a/thirdparty/thorvg/src/loaders/external_png/tvgPngLoader.cpp b/thirdparty/thorvg/src/loaders/external_png/tvgPngLoader.cpp index 05db65cb23..1fb0681814 100644 --- a/thirdparty/thorvg/src/loaders/external_png/tvgPngLoader.cpp +++ b/thirdparty/thorvg/src/loaders/external_png/tvgPngLoader.cpp @@ -42,6 +42,24 @@ static void _premultiply(uint32_t* data, uint32_t w, uint32_t h) } +static inline uint32_t CHANGE_COLORSPACE(uint32_t c) +{ + return (c & 0xff000000) + ((c & 0x00ff0000)>>16) + (c & 0x0000ff00) + ((c & 0x000000ff)<<16); +} + + +static void _changeColorSpace(uint32_t* data, uint32_t w, uint32_t h) +{ + auto buffer = data; + for (uint32_t y = 0; y < h; ++y, buffer += w) { + auto src = buffer; + for (uint32_t x = 0; x < w; ++x, ++src) { + *src = CHANGE_COLORSPACE(*src); + } + } +} + + PngLoader::PngLoader() { image = static_cast<png_imagep>(calloc(1, sizeof(png_image))); @@ -110,16 +128,21 @@ bool PngLoader::close() return true; } -unique_ptr<Surface> PngLoader::bitmap() +unique_ptr<Surface> PngLoader::bitmap(uint32_t colorSpace) { if (!content) return nullptr; + if (this->colorSpace != colorSpace) { + this->colorSpace = colorSpace; + _changeColorSpace(content, w, h); + } auto surface = static_cast<Surface*>(malloc(sizeof(Surface))); - surface->buffer = (uint32_t*)(content); + surface->buffer = content; surface->stride = w; surface->w = w; surface->h = h; - surface->cs = SwCanvas::ARGB8888; + surface->cs = colorSpace; return unique_ptr<Surface>(surface); } + diff --git a/thirdparty/thorvg/src/loaders/external_png/tvgPngLoader.h b/thirdparty/thorvg/src/loaders/external_png/tvgPngLoader.h index 8beff0a3b3..f8c0daa61c 100644 --- a/thirdparty/thorvg/src/loaders/external_png/tvgPngLoader.h +++ b/thirdparty/thorvg/src/loaders/external_png/tvgPngLoader.h @@ -36,11 +36,11 @@ public: bool read() override; bool close() override; - unique_ptr<Surface> bitmap() override; + unique_ptr<Surface> bitmap(uint32_t colorSpace) override; private: png_imagep image = nullptr; - const uint32_t* content = nullptr; + uint32_t* content = nullptr; }; #endif //_TVG_PNG_LOADER_H_ |