Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix plJPEG image channels order #127

Merged
merged 4 commits into from
Mar 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As in the PlasmaShop PR, we should probably add an assert to ensure the buf is properly aligned for the cast...

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

libHSPlasma doesn't seem to have a standard assertion macro like Plasma does, so I added a throw hsBadParamException if the alignment doesn't smell right.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, that's reasonable...

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
Loading