(ATM broken) support for PNG highpal files; their dimensions must be the same as the TGA ones.

git-svn-id: https://svn.eduke32.com/eduke32@1749 1a8010ca-5511-0410-912e-c29ae57300e0
This commit is contained in:
helixhorned 2010-12-31 01:35:00 +00:00
parent 3d2bcbfba8
commit 002ac54ca8
2 changed files with 65 additions and 18 deletions

View file

@ -1436,6 +1436,8 @@ static int32_t defsparser(scriptfile *script)
char *fn = NULL, *tfn = NULL;
char *highpalend;
char *highpaldata;
static const uint8_t pngheaderref[8] = { 137, 80, 78, 71, 13, 10, 26, 10 };
uint8_t pngheader[8];
static const tokenlist highpaltokens[] =
{
@ -1485,27 +1487,72 @@ static int32_t defsparser(scriptfile *script)
}
else Bfree(tfn);
pathsearchmode = oldpathsearchmode;
// load the highpalookup and send it to polymer
datasize = PR_HIGHPALOOKUP_DATA_SIZE;
highpaldata = Bmalloc(datasize);
fd = kopen4load(fn, 0);
// skip the TGA header
klseek(fd, 18, SEEK_SET);
dataread = 0;
while (1) {
dataread += kread(fd, highpaldata + dataread, datasize - dataread);
if (dataread == datasize)
break;
fd = kopen4load(fn, 0);
if (kread(fd, pngheader, sizeof(pngheader))!=sizeof(pngheader))
break;
highpaldata = Bmalloc(datasize);
if (Bmemcmp(pngheader, pngheaderref, sizeof(pngheader))) // blindly assume TGA
{
// skip the TGA header
klseek(fd, 18, SEEK_SET);
dataread = 0;
while (1) {
dataread += kread(fd, highpaldata + dataread, datasize - dataread);
if (dataread == datasize)
break;
}
// ignore whatever image editors might have put after the interesting stuff
kclose(fd);
}
// ignore whatever image editors might have put after the interesting stuff
kclose(fd);
else
{
char *filebuf, *tmpbuf;
int32_t xsiz, ysiz, filesize, i;
filesize = kfilelength(fd);
filebuf = Bmalloc(filesize);
if (!filebuf) { Bfree(highpaldata); break; }
klseek(fd, 0, SEEK_SET);
if (kread(fd, filebuf, filesize)!=filesize)
{ Bfree(highpaldata); initprintf("Error: didn't read all of '%s'.\n", fn); break; }
kclose(fd);
kpgetdim(filebuf, filesize, &xsiz, &ysiz);
if (xsiz*ysiz != PR_HIGHPALOOKUP_DATA_SIZE/4)
{
initprintf("Error: product of image dimensions of '%s' must equal %d.\n",
fn, PR_HIGHPALOOKUP_DATA_SIZE/4);
Bfree(filebuf); Bfree(highpaldata);
break;
}
i = kprender(filebuf, filesize, (intptr_t)highpaldata, xsiz*sizeof(coltype), xsiz, ysiz, 0, 0);
Bfree(filebuf);
if (i)
{ Bfree(highpaldata); initprintf("Error: failed rendering '%s': code %d.\n", fn, i); break; }
#if 0
for (i=0; i<PR_HIGHPALOOKUP_DATA_SIZE/4; i++)
{
char *col = &highpaldata[i*4];
swapchar(&col[0], &col[2]);
}
#endif
}
polymer_definehighpalookup(pal, highpaldata);
Bfree(highpaldata);

View file

@ -179,7 +179,7 @@ static int32_t ccind[19] = {16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15};
static int32_t hxbit[59][2], ibuf0[288], nbuf0[32], ibuf1[32], nbuf1[32];
static const uint8_t *filptr;
static uint8_t slidebuf[32768], opixbuf0[4], opixbuf1[4];
static uint8_t pnginited = 0, olinbuf[65536] ASMNAME("olinbuf"); //WARNING:max xres is: 65536/bpp-1
static uint8_t pnginited = 0, olinbuf[131072] ASMNAME("olinbuf"); //WARNING:max xres is: 131072/bpp-1
static int32_t gotcmov = -2, abstab10[1024] ASMNAME("abstab10");
//Variables to speed up dynamic Huffman decoding: