mirror of
https://git.do.srb2.org/KartKrew/Kart-Public.git
synced 2024-12-27 12:50:44 +00:00
Merge branch 'errorifpng' into 'master'
Error if the lump is a PNG lump See merge request STJr/SRB2!466
This commit is contained in:
commit
828691a7ac
1 changed files with 32 additions and 0 deletions
32
src/w_wad.c
32
src/w_wad.c
|
@ -1179,6 +1179,23 @@ void zerr(int ret)
|
|||
}
|
||||
#endif
|
||||
|
||||
#define NO_PNG_LUMPS
|
||||
|
||||
#ifdef NO_PNG_LUMPS
|
||||
static void ErrorIfPNG(UINT8 *d, size_t s, char *f, char *l)
|
||||
{
|
||||
if (s < 67) // http://garethrees.org/2007/11/14/pngcrush/
|
||||
return;
|
||||
// Check for PNG file signature using memcmp
|
||||
// As it may be faster on CPUs with slow unaligned memory access
|
||||
// Ref: http://www.libpng.org/pub/png/spec/1.2/PNG-Rationale.html#R.PNG-file-signature
|
||||
if (memcmp(&d[0], "\x89\x50\x4e\x47\x0d\x0a\x1a\x0a", 8) == 0)
|
||||
{
|
||||
I_Error("W_Wad: Lump \"%s\" in file \"%s\" is a .PNG - please convert to either Doom or Flat (raw) image format.", l, f);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
/** Reads bytes from the head of a lump.
|
||||
* Note: If the lump is compressed, the whole thing has to be read anyway.
|
||||
*
|
||||
|
@ -1218,7 +1235,15 @@ size_t W_ReadLumpHeaderPwad(UINT16 wad, UINT16 lump, void *dest, size_t size, si
|
|||
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.
|
||||
#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);
|
||||
#endif
|
||||
case CM_LZF: // Is it LZF compressed? Used by ZWADs.
|
||||
{
|
||||
#ifdef ZWAD
|
||||
|
@ -1253,11 +1278,15 @@ size_t W_ReadLumpHeaderPwad(UINT16 wad, UINT16 lump, void *dest, size_t size, si
|
|||
M_Memcpy(dest, decData + offset, size);
|
||||
Z_Free(rawData);
|
||||
Z_Free(decData);
|
||||
#ifdef NO_PNG_LUMPS
|
||||
ErrorIfPNG(dest, size, wadfiles[wad]->filename, l->name2);
|
||||
#endif
|
||||
return size;
|
||||
#else
|
||||
//I_Error("ZWAD files not supported on this platform.");
|
||||
return 0;
|
||||
#endif
|
||||
|
||||
}
|
||||
#ifdef HAVE_ZLIB
|
||||
case CM_DEFLATE: // Is it compressed via DEFLATE? Very common in ZIPs/PK3s, also what most doom-related editors support.
|
||||
|
@ -1311,6 +1340,9 @@ size_t W_ReadLumpHeaderPwad(UINT16 wad, UINT16 lump, void *dest, size_t size, si
|
|||
Z_Free(rawData);
|
||||
Z_Free(decData);
|
||||
|
||||
#ifdef NO_PNG_LUMPS
|
||||
ErrorIfPNG(dest, size, wadfiles[wad]->filename, l->name2);
|
||||
#endif
|
||||
return size;
|
||||
}
|
||||
#endif
|
||||
|
|
Loading…
Reference in a new issue