Skip to content

Commit

Permalink
Merge pull request #127 from Hoikas/bgra
Browse files Browse the repository at this point in the history
Fix plJPEG image channels order
  • Loading branch information
zrax authored Mar 6, 2024
2 parents 1d29805 + 643ba2f commit 82a6b6c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
1 change: 1 addition & 0 deletions core/PRP/Surface/plMipmap.h
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
Expand Down
12 changes: 12 additions & 0 deletions core/Util/plJPEG.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,18 @@ void plJPEG::DecompressJPEG(hsStream* S, void* buf, size_t size)
offs += out_stride;
}

// Data stored as RGB on disk but Plasma uses BGR
if (reinterpret_cast<uintptr_t>(buf) % alignof(uint32_t) != 0)
throw hsBadParamException(__FILE__, __LINE__, "buf should be aligned on a 32-bit boundary");

uint32_t* dp = reinterpret_cast<uint32_t*>(buf);
for (size_t i=0; i<size; i += 4) {
*dp = (*dp & 0xFF00FF00)
| (*dp & 0x00FF0000) >> 16
| (*dp & 0x000000FF) << 16;
dp++;
}

jpeg_finish_decompress(&ji.dinfo);
}

Expand Down

0 comments on commit 82a6b6c

Please sign in to comment.