From f333d9fb309445dac31addbfd3f745aadcdf888b Mon Sep 17 00:00:00 2001 From: Adam Johnson Date: Sun, 19 Aug 2018 20:59:45 -0400 Subject: [PATCH 1/4] Fix plJPEG image channels Plasma's plMipmaps store image data in BGR(A) for all uncompressed image types. However, JPEGs are stored as RGB on disk, so we must flip the channels for images that we read in. RLE images are unaffected because they operate on the pixel level. --- core/Util/plJPEG.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/core/Util/plJPEG.cpp b/core/Util/plJPEG.cpp index 13815247b..8557d71aa 100644 --- a/core/Util/plJPEG.cpp +++ b/core/Util/plJPEG.cpp @@ -192,6 +192,15 @@ void plJPEG::DecompressJPEG(hsStream* S, void* buf, size_t size) offs += out_stride; } + // Data stored as RGB on disk but Plasma uses BGR + uint32_t* dp = reinterpret_cast(buf); + for (size_t i=0; i> 16 + | (*dp & 0x000000FF) << 16; + dp++; + } + jpeg_finish_decompress(&ji.dinfo); } From a10a3f76f77e5166024d1717b9c9fa77483e489e Mon Sep 17 00:00:00 2001 From: Adam Johnson Date: Tue, 21 Aug 2018 18:46:55 -0400 Subject: [PATCH 2/4] Add mutable image data getter to plMipmap --- core/PRP/Surface/plMipmap.h | 1 + 1 file changed, 1 insertion(+) diff --git a/core/PRP/Surface/plMipmap.h b/core/PRP/Surface/plMipmap.h index 3b80cab3c..dff6f2d43 100644 --- a/core/PRP/Surface/plMipmap.h +++ b/core/PRP/Surface/plMipmap.h @@ -82,6 +82,7 @@ class HSPLASMA_EXPORT plMipmap : public plBitmap unsigned int getWidth() const { return fWidth; } unsigned int getHeight() const { return fHeight; } const void* getImageData() const { return fImageData; } + void* getImageData() { return fImageData; } size_t getTotalSize() const { return fTotalSize; } size_t getNumLevels() const { return fLevelData.size(); } unsigned int getLevelSize(size_t idx) const { return fLevelData[idx].fSize; } From 31d53e2eef13ff04f580573d358c51f5069b4475 Mon Sep 17 00:00:00 2001 From: Adam Johnson Date: Tue, 5 Mar 2024 18:11:28 -0500 Subject: [PATCH 3/4] Add alignment check per CR. --- core/Util/plJPEG.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/core/Util/plJPEG.cpp b/core/Util/plJPEG.cpp index 8557d71aa..7546ed47d 100644 --- a/core/Util/plJPEG.cpp +++ b/core/Util/plJPEG.cpp @@ -193,6 +193,9 @@ void plJPEG::DecompressJPEG(hsStream* S, void* buf, size_t size) } // Data stored as RGB on disk but Plasma uses BGR + if (reinterpret_cast(buf) % sizeof(uint32_t) != 0) + throw hsBadParamException(__FILE__, __LINE__, "buf should be aligned on a 32-bit boundary"); + uint32_t* dp = reinterpret_cast(buf); for (size_t i=0; i Date: Tue, 5 Mar 2024 22:00:22 -0500 Subject: [PATCH 4/4] Apply suggestion from CR. Co-authored-by: Michael Hansen --- core/Util/plJPEG.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/Util/plJPEG.cpp b/core/Util/plJPEG.cpp index 7546ed47d..d18d9b448 100644 --- a/core/Util/plJPEG.cpp +++ b/core/Util/plJPEG.cpp @@ -193,7 +193,7 @@ void plJPEG::DecompressJPEG(hsStream* S, void* buf, size_t size) } // Data stored as RGB on disk but Plasma uses BGR - if (reinterpret_cast(buf) % sizeof(uint32_t) != 0) + if (reinterpret_cast(buf) % alignof(uint32_t) != 0) throw hsBadParamException(__FILE__, __LINE__, "buf should be aligned on a 32-bit boundary"); uint32_t* dp = reinterpret_cast(buf);