Skip to content

Commit

Permalink
Fixed: Convert 8-bit paletted images to RGB
Browse files Browse the repository at this point in the history
Currently the engine's texture processing does not handle images with
a custom palette, so they must be converted to RGB(A).
  • Loading branch information
skyjake committed Jun 16, 2012
1 parent b14e135 commit 75dea85
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion doomsday/engine/portable/src/image.cpp
Expand Up @@ -150,14 +150,32 @@ boolean Image_Load(image_t* img, const char* format, DFile* file)
data.resize(DFile_Length(file) - initPos);
DFile_Read(file, reinterpret_cast<uint8_t*>(data.data()), data.size());

QImage image = QImage::fromData(data, format).rgbSwapped();
QImage image = QImage::fromData(data, format);
if(image.isNull())
{
// Back to the original file position.
DFile_Seek(file, initPos, SEEK_SET);
return false;
}

// Convert paletted images to RGB.
if(image.colorCount() && !image.hasAlphaChannel())
{
image = image.convertToFormat(QImage::Format_RGB888);
assert(!image.colorCount());
assert(image.depth() == 24);
}
else if(image.colorCount() && image.hasAlphaChannel())
{
image = image.convertToFormat(QImage::Format_ARGB32);
assert(image.depth() == 32);
}
else
{
// Swap the red and blue channels.
image = image.rgbSwapped();
}

img->size.width = image.width();
img->size.height = image.height();
img->pixelSize = image.depth() / 8;
Expand Down

0 comments on commit 75dea85

Please sign in to comment.