Add support for ART files containing exactly one tile as an input format for hightile textures and model skins. They are rendered in the global game palette and function as conventional hightile.

git-svn-id: https://svn.eduke32.com/eduke32@5179 1a8010ca-5511-0410-912e-c29ae57300e0
This commit is contained in:
hendricks266 2015-05-03 07:05:21 +00:00
parent 8b7aa949dd
commit 6091a842db
2 changed files with 90 additions and 33 deletions

View File

@ -585,21 +585,35 @@ int32_t md_undefinemodel(int32_t modelid)
static int32_t daskinloader(int32_t filh, intptr_t *fptr, int32_t *bpl, int32_t *sizx, int32_t *sizy, static int32_t daskinloader(int32_t filh, intptr_t *fptr, int32_t *bpl, int32_t *sizx, int32_t *sizy,
int32_t *osizx, int32_t *osizy, char *hasalpha, int32_t pal, char effect) int32_t *osizx, int32_t *osizy, char *hasalpha, int32_t pal, char effect)
{ {
int32_t picfillen, j,y,x; char *cptr,al=255;
char *picfil,*cptr,al=255;
coltype *pic; coltype *pic;
int32_t xsiz, ysiz, tsizx, tsizy; int32_t xsiz, ysiz, tsizx = 0, tsizy = 0;
int32_t r, g, b; int32_t r, g, b;
int32_t j, y, x;
int32_t isart = 0;
picfillen = kfilelength(filh); int32_t const picfillen = kpzbufloadfil(filh);
picfil = (char *)Xmalloc(picfillen+1);
kread(filh, picfil, picfillen);
// tsizx/y = replacement texture's natural size // tsizx/y = replacement texture's natural size
// xsiz/y = 2^x size of replacement // xsiz/y = 2^x size of replacement
kpgetdim(picfil,picfillen,&tsizx,&tsizy); #ifdef WITHKPLIB
if (tsizx == 0 || tsizy == 0) { Bfree(picfil); return -2; } kpgetdim(kpzbuf,picfillen,&tsizx,&tsizy);
#endif
if (tsizx == 0 || tsizy == 0)
{
if (E_CheckUnitArtFileHeader((uint8_t *)kpzbuf, picfillen))
return -2;
tsizx = B_LITTLE16(B_UNBUF16(&kpzbuf[16]));
tsizy = B_LITTLE16(B_UNBUF16(&kpzbuf[18]));
if (tsizx == 0 || tsizy == 0)
return -2;
isart = 1;
}
if (!glinfo.texnpot) if (!glinfo.texnpot)
{ {
@ -612,13 +626,30 @@ static int32_t daskinloader(int32_t filh, intptr_t *fptr, int32_t *bpl, int32_t
ysiz = tsizy; ysiz = tsizy;
} }
*osizx = tsizx; *osizy = tsizy; *osizx = tsizx; *osizy = tsizy;
pic = (coltype *)Xmalloc(xsiz*ysiz*sizeof(coltype));
memset(pic,0,xsiz*ysiz*sizeof(coltype)); if (isart)
{
if (tsizx * tsizy + ARTv1_UNITOFFSET > picfillen)
return -2;
}
if (kprender(picfil,picfillen,(intptr_t)pic,xsiz*sizeof(coltype),xsiz,ysiz)) int32_t const bytesperline = xsiz * sizeof(coltype);
{ Bfree(picfil); Bfree(pic); return -2; } pic = (coltype *)Xcalloc(ysiz, bytesperline);
Bfree(picfil);
if (isart)
{
E_RenderArtDataIntoBuffer((palette_t *)pic, (uint8_t *)&kpzbuf[ARTv1_UNITOFFSET], xsiz, tsizx, tsizy);
}
#ifdef WITHKPLIB
else
{
if (kprender(kpzbuf,picfillen,(intptr_t)pic,bytesperline,xsiz,ysiz))
{
Bfree(pic);
return -2;
}
}
#endif
cptr = &britable[gammabrightness ? 0 : curbrightness][0]; cptr = &britable[gammabrightness ? 0 : curbrightness][0];
r=(glinfo.bgra)?hictinting[pal].b:hictinting[pal].r; r=(glinfo.bgra)?hictinting[pal].b:hictinting[pal].r;

View File

@ -995,7 +995,7 @@ int32_t gloadtile_hi(int32_t dapic,int32_t dapalnum, int32_t facen, hicreplctyp
coltype *pic = NULL; coltype *pic = NULL;
char *picfil = NULL, *fn; char *fn;
int32_t picfillen, intexfmt = GL_RGBA, filh; int32_t picfillen, intexfmt = GL_RGBA, filh;
int32_t startticks=0, willprint=0; int32_t startticks=0, willprint=0;
@ -1028,7 +1028,7 @@ int32_t gloadtile_hi(int32_t dapic,int32_t dapalnum, int32_t facen, hicreplctyp
char hasalpha = 255; char hasalpha = 255;
texcacheheader cachead; texcacheheader cachead;
int32_t gotcache = texcache_readtexheader(fn, picfillen+(dapalnum<<8), dameth, effect, &cachead, 0); int32_t gotcache = texcache_readtexheader(fn, picfillen+(dapalnum<<8), dameth, effect, &cachead, 0);
vec2_t siz ={ 0, 0 }, tsiz; vec2_t siz = { 0, 0 }, tsiz = { 0, 0 };
if (gotcache && !texcache_loadtile(&cachead, &doalloc, pth)) if (gotcache && !texcache_loadtile(&cachead, &doalloc, pth))
{ {
@ -1040,27 +1040,34 @@ int32_t gloadtile_hi(int32_t dapic,int32_t dapalnum, int32_t facen, hicreplctyp
{ {
int32_t r, g, b; int32_t r, g, b;
int32_t j, y; int32_t j, y;
int32_t isart = 0;
gotcache = 0; // the compressed version will be saved to disk gotcache = 0; // the compressed version will be saved to disk
if ((filh = kopen4load(fn, 0)) < 0) return -1; int32_t const length = kpzbufload(fn);
if (length == 0)
picfil = (char *)Xmalloc(picfillen+1); return -1;
if (EDUKE32_PREDICT_FALSE(kread(filh, picfil, picfillen) != picfillen))
initprintf("warning: didn't fully read %s\n", fn);
// prevent
// Conditional jump or move depends on uninitialised value(s)
// at kpegrend (kplib.c:1655)
picfil[picfillen] = 0;
kclose(filh);
// tsizx/y = replacement texture's natural size // tsizx/y = replacement texture's natural size
// xsiz/y = 2^x size of replacement // xsiz/y = 2^x size of replacement
kpgetdim(picfil,picfillen,&tsiz.x,&tsiz.y); #ifdef WITHKPLIB
if (tsiz.x == 0 || tsiz.y == 0) { Bfree(picfil); return -1; } kpgetdim(kpzbuf,picfillen,&tsiz.x,&tsiz.y);
#endif
if (tsiz.x == 0 || tsiz.y == 0)
{
if (E_CheckUnitArtFileHeader((uint8_t *)kpzbuf, picfillen))
return -1;
tsiz.x = B_LITTLE16(B_UNBUF16(&kpzbuf[16]));
tsiz.y = B_LITTLE16(B_UNBUF16(&kpzbuf[18]));
if (tsiz.x == 0 || tsiz.y == 0)
return -1;
isart = 1;
}
pth->siz = tsiz; pth->siz = tsiz;
@ -1072,7 +1079,14 @@ int32_t gloadtile_hi(int32_t dapic,int32_t dapalnum, int32_t facen, hicreplctyp
else else
siz = tsiz; siz = tsiz;
pic = (coltype *)Xcalloc(siz.x,siz.y*sizeof(coltype)); if (isart)
{
if (tsiz.x * tsiz.y + ARTv1_UNITOFFSET > picfillen)
return -2;
}
int32_t const bytesperline = siz.x * sizeof(coltype);
pic = (coltype *)Xcalloc(siz.x, bytesperline);
startticks = getticks(); startticks = getticks();
@ -1087,7 +1101,21 @@ int32_t gloadtile_hi(int32_t dapic,int32_t dapalnum, int32_t facen, hicreplctyp
} }
else else
{ {
if (kprender(picfil,picfillen,(intptr_t)pic,siz.x*sizeof(coltype),siz.x,siz.y)) { Bfree(picfil); Bfree(pic); return -2; } if (isart)
{
E_RenderArtDataIntoBuffer((palette_t *)pic, (uint8_t *)&kpzbuf[ARTv1_UNITOFFSET], siz.x, tsiz.x, tsiz.y);
}
#ifdef WITHKPLIB
else
{
if (kprender(kpzbuf,picfillen,(intptr_t)pic,bytesperline,siz.x,siz.y))
{
Bfree(pic);
return -2;
}
}
#endif
willprint=2; willprint=2;
if (hicprecaching) if (hicprecaching)
@ -1203,8 +1231,6 @@ int32_t gloadtile_hi(int32_t dapic,int32_t dapalnum, int32_t facen, hicreplctyp
} }
else texfmt = GL_BGRA; else texfmt = GL_BGRA;
Bfree(picfil); picfil = 0;
if (tsiz.x>>r_downsize <= tilesiz[dapic].x || tsiz.y>>r_downsize <= tilesiz[dapic].y) if (tsiz.x>>r_downsize <= tilesiz[dapic].x || tsiz.y>>r_downsize <= tilesiz[dapic].y)
hicr->flags |= (HICR_NOCOMPRESS + HICR_NOSAVE); hicr->flags |= (HICR_NOCOMPRESS + HICR_NOSAVE);