diff options
author | Martin Capitanio <capnm@capitanio.org> | 2023-05-11 17:39:50 +0200 |
---|---|---|
committer | RĂ©mi Verschelde <rverschelde@gmail.com> | 2023-05-12 12:31:23 +0200 |
commit | 9e11b78d1cb6718fa8357be3b3f4b8bdadd6b660 (patch) | |
tree | 7245ce16b8f3769b9126a180db7cf961a3855650 /thirdparty/thorvg/src/loaders/external_png | |
parent | ce0c61b6e33807bd9868ff3fe18ffac737a1c55d (diff) |
Update ThorVG to v0.9.0
https://github.com/thorvg/thorvg/releases/tag/v0.9.0
Fixes #72478
(cherry picked from commit 5db751832d54092c9d153c0fe07f9cc4616a2d01)
Diffstat (limited to 'thirdparty/thorvg/src/loaders/external_png')
-rw-r--r-- | thirdparty/thorvg/src/loaders/external_png/tvgPngLoader.cpp | 62 | ||||
-rw-r--r-- | thirdparty/thorvg/src/loaders/external_png/tvgPngLoader.h | 5 |
2 files changed, 20 insertions, 47 deletions
diff --git a/thirdparty/thorvg/src/loaders/external_png/tvgPngLoader.cpp b/thirdparty/thorvg/src/loaders/external_png/tvgPngLoader.cpp index 1fb0681814..b0a9fdd579 100644 --- a/thirdparty/thorvg/src/loaders/external_png/tvgPngLoader.cpp +++ b/thirdparty/thorvg/src/loaders/external_png/tvgPngLoader.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020 - 2022 Samsung Electronics Co., Ltd. All rights reserved. + * Copyright (c) 2020 - 2023 the ThorVG project. All rights reserved. * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -23,42 +23,14 @@ #include "tvgLoader.h" #include "tvgPngLoader.h" -static inline uint32_t PREMULTIPLY(uint32_t c) -{ - auto a = (c >> 24); - return (c & 0xff000000) + ((((c >> 8) & 0xff) * a) & 0xff00) + ((((c & 0x00ff00ff) * a) >> 8) & 0x00ff00ff); -} +/************************************************************************/ +/* Internal Class Implementation */ +/************************************************************************/ -static void _premultiply(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 = PREMULTIPLY(*src); - } - } -} - - -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); - } - } -} - +/************************************************************************/ +/* External Class Implementation */ +/************************************************************************/ PngLoader::PngLoader() { @@ -84,6 +56,7 @@ bool PngLoader::open(const string& path) w = (float)image->width; h = (float)image->height; + cs = ColorSpace::ARGB8888; return true; } @@ -96,6 +69,7 @@ bool PngLoader::open(const char* data, uint32_t size, bool copy) w = (float)image->width; h = (float)image->height; + cs = ColorSpace::ARGB8888; return true; } @@ -117,8 +91,6 @@ bool PngLoader::read() } content = reinterpret_cast<uint32_t*>(buffer); - _premultiply(reinterpret_cast<uint32_t*>(buffer), image->width, image->height); - return true; } @@ -128,20 +100,20 @@ bool PngLoader::close() return true; } -unique_ptr<Surface> PngLoader::bitmap(uint32_t colorSpace) +unique_ptr<Surface> PngLoader::bitmap() { 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 = content; + //TODO: It's better to keep this surface instance in the loader side + auto surface = new Surface; + surface->buf32 = content; surface->stride = w; surface->w = w; surface->h = h; - surface->cs = colorSpace; + surface->cs = cs; + surface->channelSize = sizeof(uint32_t); + surface->owner = true; + surface->premultiplied = false; 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 f8c0daa61c..5354e1bdd6 100644 --- a/thirdparty/thorvg/src/loaders/external_png/tvgPngLoader.h +++ b/thirdparty/thorvg/src/loaders/external_png/tvgPngLoader.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020 - 2022 Samsung Electronics Co., Ltd. All rights reserved. + * Copyright (c) 2020 - 2023 the ThorVG project. All rights reserved. * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -19,6 +19,7 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ + #ifndef _TVG_PNG_LOADER_H_ #define _TVG_PNG_LOADER_H_ @@ -36,7 +37,7 @@ public: bool read() override; bool close() override; - unique_ptr<Surface> bitmap(uint32_t colorSpace) override; + unique_ptr<Surface> bitmap() override; private: png_imagep image = nullptr; |