mirror of
https://git.do.srb2.org/STJr/SRB2.git
synced 2024-11-15 01:01:33 +00:00
Only read first 8 bytes of a PNG image for detection
This commit is contained in:
parent
ee7198cb01
commit
91a37b1018
3 changed files with 40 additions and 25 deletions
|
@ -104,10 +104,10 @@ typedef struct
|
|||
boolean available;
|
||||
} spriteinfo_t;
|
||||
|
||||
// Portable Network Graphics
|
||||
#define PNG_HEADER_SIZE (8)
|
||||
// PNG support
|
||||
#define PNG_HEADER_SIZE 8
|
||||
|
||||
boolean Picture_IsLumpPNG(const UINT8 *d, size_t s);
|
||||
#define Picture_ThrowPNGError(lumpname, wadfilename) I_Error("W_Wad: Lump \"%s\" in file \"%s\" is a .png - please convert to either Doom or Flat (raw) image format.", lumpname, wadfilename); // Fears Of LJ Sonic
|
||||
|
||||
#ifndef NO_PNG_LUMPS
|
||||
void *Picture_PNGConvert(
|
||||
|
|
|
@ -285,42 +285,51 @@ UINT8 *R_GenerateTexture(size_t texnum)
|
|||
// so check if there's holes and if not strip the posts.
|
||||
if (texture->patchcount == 1)
|
||||
{
|
||||
boolean holey = false;
|
||||
patch = texture->patches;
|
||||
patch = &texture->patches[0];
|
||||
|
||||
UINT16 wadnum = patch->wad;
|
||||
lumpnum_t lumpnum = patch->lump;
|
||||
size_t lumplength = W_LumpLengthPwad(wadnum, lumpnum);
|
||||
UINT8 *pdata = W_CacheLumpNumPwad(wadnum, lumpnum, PU_CACHE);
|
||||
softwarepatch_t *realpatch = (softwarepatch_t *)pdata;
|
||||
UINT16 lumpnum = patch->lump;
|
||||
UINT8 *pdata;
|
||||
softwarepatch_t *realpatch;
|
||||
boolean holey = false;
|
||||
|
||||
#ifndef NO_PNG_LUMPS
|
||||
UINT8 header[PNG_HEADER_SIZE];
|
||||
|
||||
W_ReadLumpHeaderPwad(wadnum, lumpnum, header, PNG_HEADER_SIZE, 0);
|
||||
|
||||
// Not worth converting
|
||||
if (Picture_IsLumpPNG(pdata, lumplength))
|
||||
if (Picture_IsLumpPNG(header, W_LumpLengthPwad(wadnum, lumpnum)))
|
||||
goto multipatch;
|
||||
#endif
|
||||
|
||||
pdata = W_CacheLumpNumPwad(wadnum, lumpnum, PU_CACHE);
|
||||
realpatch = (softwarepatch_t *)pdata;
|
||||
|
||||
// Check the patch for holes.
|
||||
if (texture->width > SHORT(realpatch->width) || texture->height > SHORT(realpatch->height))
|
||||
holey = true;
|
||||
UINT8 *colofs = (UINT8 *)realpatch->columnofs;
|
||||
for (x = 0; x < texture->width && !holey; x++)
|
||||
else
|
||||
{
|
||||
doompost_t *col = (doompost_t *)((UINT8 *)realpatch + LONG(*(UINT32 *)&colofs[x<<2]));
|
||||
INT32 topdelta, prevdelta = -1, y = 0;
|
||||
while (col->topdelta != 0xff)
|
||||
UINT8 *colofs = (UINT8 *)realpatch->columnofs;
|
||||
for (x = 0; x < texture->width; x++)
|
||||
{
|
||||
topdelta = col->topdelta;
|
||||
if (topdelta <= prevdelta)
|
||||
topdelta += prevdelta;
|
||||
prevdelta = topdelta;
|
||||
if (topdelta > y)
|
||||
break;
|
||||
y = topdelta + col->length + 1;
|
||||
col = (doompost_t *)((UINT8 *)col + col->length + 4);
|
||||
doompost_t *col = (doompost_t *)((UINT8 *)realpatch + LONG(*(UINT32 *)&colofs[x<<2]));
|
||||
INT32 topdelta, prevdelta = -1, y = 0;
|
||||
while (col->topdelta != 0xff)
|
||||
{
|
||||
topdelta = col->topdelta;
|
||||
if (topdelta <= prevdelta)
|
||||
topdelta += prevdelta;
|
||||
prevdelta = topdelta;
|
||||
if (topdelta > y)
|
||||
break;
|
||||
y = topdelta + col->length + 1;
|
||||
col = (doompost_t *)((UINT8 *)col + col->length + 4);
|
||||
}
|
||||
if (y < texture->height)
|
||||
holey = true; // this texture is HOLEy! D:
|
||||
}
|
||||
if (y < texture->height)
|
||||
holey = true; // this texture is HOLEy! D:
|
||||
}
|
||||
|
||||
// If the patch uses transparency, we have to save it this way.
|
||||
|
@ -346,6 +355,8 @@ UINT8 *R_GenerateTexture(size_t texnum)
|
|||
// we have wait until the texture itself is drawn to do that
|
||||
Patch_MakeColumns(realpatch, texture->width, texture->width, blocktex, columns, posts, patch->flip & 1);
|
||||
|
||||
Z_Free(pdata);
|
||||
|
||||
goto done;
|
||||
}
|
||||
|
||||
|
|
|
@ -1752,6 +1752,10 @@ void zerr(int ret)
|
|||
}
|
||||
#endif
|
||||
|
||||
#ifdef NO_PNG_LUMPS
|
||||
#define Picture_ThrowPNGError(lumpname, wadfilename) I_Error("W_Wad: Lump \"%s\" in file \"%s\" is a .png - please convert to either Doom or Flat (raw) image format.", lumpname, wadfilename)
|
||||
#endif
|
||||
|
||||
/** Reads bytes from the head of a lump.
|
||||
* Note: If the lump is compressed, the whole thing has to be read anyway.
|
||||
*
|
||||
|
|
Loading…
Reference in a new issue