Navigation Menu

Skip to content

Commit

Permalink
Fixed|libgui|Image: Loading a TGA image
Browse files Browse the repository at this point in the history
Swapping red and blue channels not needed.
  • Loading branch information
skyjake committed Apr 2, 2014
1 parent 0f45648 commit f5c5868
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions doomsday/libgui/src/graphics/image.cpp
Expand Up @@ -254,24 +254,27 @@ static QImage load(Block const &data)
pixelSize == 4? QImage::Format_ARGB32 : QImage::Format_RGB888);
dbyte *base = img.bits();

bool const isUpperOrigin = header.flags.testFlag(Header::ScreenOriginUpper);

// RGB can be read line by line.
if(header.imageType == Header::RGB)
{
for(int y = 0; y < header.size.y; y++)
{
int inY = (header.flags.testFlag(Header::ScreenOriginUpper)? y : (header.size.y - y - 1));

int inY = (isUpperOrigin? y : (header.size.y - y - 1));
ByteRefArray line(base + (inY * header.size.x * pixelSize), header.size.x * pixelSize);
input.readPresetSize(line);
}
}
else if(header.imageType == Header::RleRGB)
{
img.fill(0);

// RLE packets may cross over to the next line.
int x = 0;
int y = (header.flags.testFlag(Header::ScreenOriginUpper)? 0 : (header.size.y - 1));
int y = (isUpperOrigin? 0 : (header.size.y - 1));
int endY = header.size.y - y - 1;
int stepY = (header.flags.testFlag(Header::ScreenOriginUpper)? 1 : -1);
int stepY = (isUpperOrigin? 1 : -1);

while(y != endY && x < header.size.x)
{
Expand Down Expand Up @@ -301,6 +304,8 @@ static QImage load(Block const &data)

std::memcpy(base + (x + y * header.size.x) * pixelSize,
pixel.constData(), pixelSize);

// Advance the position.
if(++x == header.size.x)
{
x = 0;
Expand All @@ -310,8 +315,7 @@ static QImage load(Block const &data)
}
}

// Pixels were stored in ABGR format.
return img.rgbSwapped();
return img;
}

} // namespace tga
Expand Down

0 comments on commit f5c5868

Please sign in to comment.