From 002ac54ca8191b01a3766a7bd5b785b5a4710c82 Mon Sep 17 00:00:00 2001 From: helixhorned Date: Fri, 31 Dec 2010 01:35:00 +0000 Subject: [PATCH] (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 --- polymer/eduke32/build/src/defs.c | 81 ++++++++++++++++++++++++------- polymer/eduke32/build/src/kplib.c | 2 +- 2 files changed, 65 insertions(+), 18 deletions(-) diff --git a/polymer/eduke32/build/src/defs.c b/polymer/eduke32/build/src/defs.c index 264574b0e..bcae4190c 100644 --- a/polymer/eduke32/build/src/defs.c +++ b/polymer/eduke32/build/src/defs.c @@ -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