diff --git a/src/loaders/external_jpg/tvgJpgLoader.cpp b/src/loaders/external_jpg/tvgJpgLoader.cpp index 7ead54c1..ebe8d793 100644 --- a/src/loaders/external_jpg/tvgJpgLoader.cpp +++ b/src/loaders/external_jpg/tvgJpgLoader.cpp @@ -55,6 +55,24 @@ uint32_t convertColorSpaceType(uint32_t colorSpace) return tjpfColorSpace; } + +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 */ /************************************************************************/ @@ -172,7 +190,7 @@ unique_ptr JpgLoader::bitmap(uint32_t colorSpace) if (!image) return nullptr; if (this->colorSpace != colorSpace) { this->colorSpace = colorSpace; - read(); + _changeColorSpace(reinterpret_cast(image), w, h); } auto surface = static_cast(malloc(sizeof(Surface)));