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

BGRA Fixes #44

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
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
30 changes: 29 additions & 1 deletion src/PrpShop/PRP/Surface/QMipmap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,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 @@ -193,6 +193,19 @@ QString getCompressionText(plBitmap* tex)
case plBitmap::kAInten88:
return "JPEG (Alpha+Greyscale)";
}
} else if (tex->getCompressionType() == plBitmap::kPNGCompression) {
switch (tex->getARGBType()) {
case plBitmap::kRGB8888:
return "PNG (ARGB8888)";
case plBitmap::kRGB4444:
return "PNG (ARGB4444)";
case plBitmap::kRGB1555:
return "PNG (ARGB1555)";
case plBitmap::kInten8:
return "PNG (Greyscale)";
case plBitmap::kAInten88:
return "PNG (Alpha+Greyscale)";
}
} else {
switch (tex->getARGBType()) {
case plBitmap::kRGB8888:
Expand Down Expand Up @@ -328,6 +341,19 @@ QMipmap::QMipmap(plCreatable* pCre, QWidget* parent)
connect(iJPGLink, &QLinkLabel::activated, this, &QMipmap::onImportJPEG);
}

static void swapColorChannels(unsigned char* data, size_t size)
{
Q_ASSERT(reinterpret_cast<uintptr_t>(data) % alignof(unsigned int) == 0);

unsigned int* dp = reinterpret_cast<unsigned int*>(data);
zrax marked this conversation as resolved.
Show resolved Hide resolved
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 @@ -354,6 +380,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 @@ -412,6 +439,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
Loading