Reimplement png warning

This commit is contained in:
TehRealSalt 2018-11-29 11:16:40 -05:00
parent d9654bcc1a
commit 4cfaf746bb

View file

@ -1175,6 +1175,29 @@ void zerr(int ret)
} }
#endif #endif
#define NO_PNG_LUMPS
#ifdef NO_PNG_LUMPS
static void ErrorIfPNG(void *d, size_t s, char *f, char *l)
{
if (s < 67) // http://garethrees.org/2007/11/14/pngcrush/
return;
#define sigcheck ((UINT8 *)d)
if (sigcheck[0] == 0x89
&& sigcheck[1] == 0x50
&& sigcheck[2] == 0x4e
&& sigcheck[3] == 0x47
&& sigcheck[4] == 0x0d
&& sigcheck[5] == 0x0a
&& sigcheck[6] == 0x1a
&& sigcheck[7] == 0x0a)
{
I_Error("W_Wad: Lump \"%s\" in file \"%s\" is a .PNG - please convert to either Doom or Flat (raw) image format.", l, f);
}
#undef sigcheck
}
#endif
/** Reads bytes from the head of a lump. /** Reads bytes from the head of a lump.
* Note: If the lump is compressed, the whole thing has to be read anyway. * Note: If the lump is compressed, the whole thing has to be read anyway.
* *
@ -1214,7 +1237,15 @@ size_t W_ReadLumpHeaderPwad(UINT16 wad, UINT16 lump, void *dest, size_t size, si
switch(wadfiles[wad]->lumpinfo[lump].compression) switch(wadfiles[wad]->lumpinfo[lump].compression)
{ {
case CM_NOCOMPRESSION: // If it's uncompressed, we directly write the data into our destination, and return the bytes read. case CM_NOCOMPRESSION: // If it's uncompressed, we directly write the data into our destination, and return the bytes read.
#ifdef NO_PNG_LUMPS
{
size_t bytesread = fread(dest, 1, size, handle);
ErrorIfPNG(dest, bytesread, wadfiles[wad]->filename, l->name2);
return bytesread;
}
#else
return fread(dest, 1, size, handle); return fread(dest, 1, size, handle);
#endif
case CM_LZF: // Is it LZF compressed? Used by ZWADs. case CM_LZF: // Is it LZF compressed? Used by ZWADs.
{ {
#ifdef ZWAD #ifdef ZWAD
@ -1249,6 +1280,9 @@ size_t W_ReadLumpHeaderPwad(UINT16 wad, UINT16 lump, void *dest, size_t size, si
M_Memcpy(dest, decData + offset, size); M_Memcpy(dest, decData + offset, size);
Z_Free(rawData); Z_Free(rawData);
Z_Free(decData); Z_Free(decData);
#ifdef NO_PNG_LUMPS
ErrorIfPNG(dest, size, wadfiles[wad]->filename, l->name2);
#endif
return size; return size;
#else #else
//I_Error("ZWAD files not supported on this platform."); //I_Error("ZWAD files not supported on this platform.");
@ -1307,6 +1341,9 @@ size_t W_ReadLumpHeaderPwad(UINT16 wad, UINT16 lump, void *dest, size_t size, si
Z_Free(rawData); Z_Free(rawData);
Z_Free(decData); Z_Free(decData);
#ifdef NO_PNG_LUMPS
ErrorIfPNG(dest, size, wadfiles[wad]->filename, l->name2);
#endif
return size; return size;
} }
#endif #endif