Add Warnings for when PNG loads fail due to unsupported flags (#1302)

This was the result of an issue which stumped the entire Discord, which led to me having to debug from source to find why some relatively standard publicly available PBR materials work.  GZDoom is the ONLY program in the typical development stack (GIMP, Slade, UDB) with this narrow of support for the PNG format. As such, the average developer will have no other way to figure out what's going wrong without these: these CANNOT be allowed to fail silently.  As things like PNG-compression and 64-bit color become more common in royalty-free PBR materials, support should be an eventual target.  Even then, these warnings should remain to prevent this from being an issue the next time things change.
This commit is contained in:
Raccoon 2021-02-12 13:37:18 -05:00 committed by GitHub
parent c9ed4293f7
commit 59fcf45222
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -115,16 +115,24 @@ FImageSource *PNGImage_TryCreate(FileReader & data, int lumpnum)
uint8_t filter = data.ReadUInt8();
uint8_t interlace = data.ReadUInt8();
// NOTICE: GZDoom is the ONLY program in the typical development stack (GIMP, Slade, UDB) which does not support these formats
// As such, the average developer will have no other way to figure out what's going wrong without these: these CANNOT be allowed to fail silently.
// As things like PNG-compression and 64-bit color become more common in royalty-free PBR materials, support should be an eventual target.
// Even then, these warnings should remain to prevent this from being an issue the next time things change.
if (compression != 0 || filter != 0 || interlace > 1)
{
Printf(TEXTCOLOR_YELLOW"WARNING: failed to load PNG %s: the compression, filter, or interlace is not supported!\n", fileSystem.GetFileFullName(lumpnum));
return NULL;
}
if (!((1 << colortype) & 0x5D))
{
Printf(TEXTCOLOR_YELLOW"WARNING: failed to load PNG %s: the colortype (%u) is not supported!\n", fileSystem.GetFileFullName(lumpnum), colortype);
return NULL;
}
if (!((1 << bitdepth) & 0x116))
{
Printf(TEXTCOLOR_YELLOW"WARNING: failed to load PNG %s: the bit-depth (%u) is not supported!\n", fileSystem.GetFileFullName(lumpnum), bitdepth);
return NULL;
}
@ -133,9 +141,9 @@ FImageSource *PNGImage_TryCreate(FileReader & data, int lumpnum)
data.Read (first4bytes.b, 4);
if (first4bytes.dw == 0)
{
data.Read (first4bytes.b, 4);
if (first4bytes.dw == MAKE_ID('I','E','N','D'))
if (data.Read(first4bytes.b, 4) != 4 || first4bytes.dw == MAKE_ID('I','E','N','D'))
{
Printf(TEXTCOLOR_YELLOW"WARNING: failed to load PNG %s: the file ends immediately after the IHDR.\n", fileSystem.GetFileFullName(lumpnum));
return NULL;
}
}
@ -755,4 +763,4 @@ FBitmap FPNGFileTexture::GetBgraBitmap(const PalEntry *remap, int *trans)
bmp.CopyPixelDataRGB(0, 0, Pixels.Data(), Width, Height, 3, pixwidth, 0, CF_RGB);
}
return bmp;
}
}