Skip to content

Commit

Permalink
Add Warnings for when PNG loads fail due to unsupported flags (#1302)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
NukiRaccoon committed Feb 12, 2021
1 parent c9ed429 commit 59fcf45
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions src/common/textures/formats/pngtexture.cpp
Expand Up @@ -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;
}

Expand All @@ -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;
}
}
Expand Down Expand Up @@ -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;
}
}

0 comments on commit 59fcf45

Please sign in to comment.