Skip to content

Commit

Permalink
Fix non-DXT image channels
Browse files Browse the repository at this point in the history
All Plasma image data, other than DXT, is stored as BGR in plMipmap
  • Loading branch information
Hoikas committed Aug 21, 2018
1 parent fd8c6c2 commit 6aa9853
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion src/PrpShop/PRP/Surface/QMipmap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ void QTextureBox::setTexture(plMipmap* tex, int level)
fImageData = new unsigned char[size];
tex->DecompressImage(level, fImageData, size);

if (tex->getCompressionType() != plMipmap::kUncompressed) {
if (tex->getCompressionType() == plMipmap::kDirectXCompression) {
// Manipulate the data from RGBA to BGRA
unsigned int* dp = (unsigned int*)fImageData;
for (size_t i=0; i<size; i += 4) {
Expand Down Expand Up @@ -353,6 +353,17 @@ void QMipmap::saveDamage()
| (fFlags[kIsOrtho]->isChecked() ? plBitmap::kIsOrtho : 0));
}

static void swapColorChannels(unsigned char* data, size_t size)
{
unsigned int* dp = reinterpret_cast<unsigned int*>(data);
for (size_t i=0; i<size; i += 4) {
*dp = (*dp & 0xFF00FF00)
| (*dp & 0x00FF0000) >> 16
| (*dp & 0x000000FF) << 16;
dp++;
}
}

static void makeJColorSurface(const plMipmap* tex, hsStream* S)
{
if (tex->getCompressionType() != plBitmap::kJPEGCompression) {
Expand All @@ -379,6 +390,7 @@ static void makeJColorSurface(const plMipmap* tex, hsStream* S)
// Strip down data to 24 bit color
unsigned char* data = new unsigned char[dds.fLinearSize];
tex->extractColorData(data, dds.fLinearSize);
swapColorChannels(data, dds.fLinearSize);
dds.setData(dds.fLinearSize, data);
delete[] data;

Expand Down Expand Up @@ -437,6 +449,7 @@ static bool getJColorSurface(const plDDSurface& dds, plMipmap* tex)

tex->Create(dds.fWidth, dds.fHeight, 0, plBitmap::kJPEGCompression, plBitmap::kRGB8888);
tex->setColorData(dds.getData(), dds.getDataSize());
swapColorChannels(reinterpret_cast<unsigned char*>(tex->getImageData()), dds.getDataSize());
return true;
}

Expand Down

0 comments on commit 6aa9853

Please sign in to comment.