Handle all color channel counts in image loader

Greyscale images with alpha channel (i.e. channel count = 2) were incorrectly handled as RGBA images, causing the client to crash when loading such images. Now the images can successfully be loaded with the image loader, but the client still only supports loading RGB and RGBA images like before.
This commit is contained in:
Robert Müller 2023-11-20 19:42:02 +01:00
parent f0a17435e6
commit bcae7da6b4
2 changed files with 16 additions and 6 deletions

View file

@ -59,12 +59,15 @@ static EImageFormat LibPNGGetImageFormat(int ColorChannelCount)
{
case 1:
return IMAGE_FORMAT_R;
case 2:
return IMAGE_FORMAT_RA;
case 3:
return IMAGE_FORMAT_RGB;
case 4:
return IMAGE_FORMAT_RGBA;
default:
return IMAGE_FORMAT_RGBA;
dbg_assert(false, "ColorChannelCount invalid");
dbg_break();
}
}
@ -276,14 +279,20 @@ static void FlushPNGWrite(png_structp png_ptr) {}
static int ImageLoaderHelperFormatToColorChannel(EImageFormat Format)
{
if(Format == IMAGE_FORMAT_R)
switch(Format)
{
case IMAGE_FORMAT_R:
return 1;
else if(Format == IMAGE_FORMAT_RGB)
case IMAGE_FORMAT_RA:
return 2;
case IMAGE_FORMAT_RGB:
return 3;
else if(Format == IMAGE_FORMAT_RGBA)
case IMAGE_FORMAT_RGBA:
return 4;
return 4;
default:
dbg_assert(false, "Format invalid");
dbg_break();
}
}
bool SavePNG(EImageFormat ImageFormat, const uint8_t *pRawBuffer, SImageByteBuffer &WrittenBytes, int Width, int Height)

View file

@ -8,6 +8,7 @@
enum EImageFormat
{
IMAGE_FORMAT_R = 0,
IMAGE_FORMAT_RA,
IMAGE_FORMAT_RGB,
IMAGE_FORMAT_RGBA,
};