Skip to content

Commit

Permalink
libgui|Image: Converting from RGB to RGBA image format
Browse files Browse the repository at this point in the history
  • Loading branch information
skyjake committed Sep 1, 2019
1 parent f0a37af commit a8f1d70
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions doomsday/libs/gui/src/graphics/image.cpp
Expand Up @@ -587,13 +587,28 @@ bool Image::isGLCompatible() const
return d->format >= Luminance_8 && d->format <= RGBA_32ui;
}

Image Image::convertToFormat(Format format) const
Image Image::convertToFormat(Format toFormat) const
{
if (d->format == format)
if (d->format == toFormat)
{
// No conversion necessary.
return *this;
}
if (d->format == RGB_888 && toFormat == RGBA_8888)
{
const int inStep = bytesPerPixel();
Image conv(size(), toFormat);
for (duint y = 0; y < height(); ++y)
{
const duint8 *in = row(y);
for (duint32 *out = conv.row32(y), *outEnd = conv.rowEnd32(y);
out != outEnd; ++out, in += inStep)
{
*out = packColor(Color(in[0], in[1], in[2], 255));
}
}
return conv;
}
DE_ASSERT_FAIL("Image::convertToFormat not implemented");
}

Expand Down

0 comments on commit a8f1d70

Please sign in to comment.