mirror of
https://github.com/ZDoom/raze-gles.git
synced 2024-12-27 04:00:42 +00:00
Build tools: Clean up transpal and link it to colmatch.c instead of including a separate copy of the (old!) getclosestcol code.
git-svn-id: https://svn.eduke32.com/eduke32@5363 1a8010ca-5511-0410-912e-c29ae57300e0
This commit is contained in:
parent
ff416551ce
commit
a43cd066fb
2 changed files with 30 additions and 146 deletions
|
@ -163,7 +163,7 @@ endif
|
||||||
|
|
||||||
# Tools
|
# Tools
|
||||||
|
|
||||||
UTIL_OBJS=compat pragmas kplib cache1d crc32 compat_tools
|
UTIL_OBJS=compat pragmas kplib cache1d crc32 colmatch compat_tools
|
||||||
UTILS=kextract kgroup transpal wad2art wad2map kmd2tool md2tool generateicon cacheinfo arttool givedepth mkpalette unpackssi bsuite
|
UTILS=kextract kgroup transpal wad2art wad2map kmd2tool md2tool generateicon cacheinfo arttool givedepth mkpalette unpackssi bsuite
|
||||||
GAMEUTILS=ivfrate
|
GAMEUTILS=ivfrate
|
||||||
DXUTILS=enumdisplay getdxdidf
|
DXUTILS=enumdisplay getdxdidf
|
||||||
|
|
|
@ -7,97 +7,29 @@
|
||||||
|
|
||||||
#include "compat.h"
|
#include "compat.h"
|
||||||
#include "pragmas.h"
|
#include "pragmas.h"
|
||||||
|
#include "colmatch.h"
|
||||||
|
|
||||||
#define MAXPALOOKUPS 256
|
#define MAXPALOOKUPS 256
|
||||||
|
|
||||||
static int numpalookups, transratio;
|
static int numshades, transratio;
|
||||||
static char palettefilename[13], origpalookup[MAXPALOOKUPS<<8];
|
static char const * const palettefilename = "palette.dat";
|
||||||
static char palette[768], palookup[MAXPALOOKUPS<<8], transluc[65536];
|
static uint8_t origpalookup[MAXPALOOKUPS<<8], palookup[MAXPALOOKUPS<<8], transluc[65536];
|
||||||
static char closestcol[64][64][64];
|
static uint8_t origpalette[768], palette[768];
|
||||||
|
|
||||||
#define FASTPALGRIDSIZ 8
|
static char getshade(char dashade, char dacol)
|
||||||
static int rdist[129], gdist[129], bdist[129];
|
|
||||||
static char colhere[((FASTPALGRIDSIZ+2)*(FASTPALGRIDSIZ+2)*(FASTPALGRIDSIZ+2))>>3];
|
|
||||||
static char colhead[(FASTPALGRIDSIZ+2)*(FASTPALGRIDSIZ+2)*(FASTPALGRIDSIZ+2)];
|
|
||||||
static int colnext[256];
|
|
||||||
static char coldist[8] = {0,1,2,3,4,3,2,1};
|
|
||||||
static int colscan[27];
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
char getclosestcol(int r, int g, int b)
|
|
||||||
{
|
|
||||||
int i, j, k, dist, mindist, retcol;
|
|
||||||
int *rlookup, *glookup, *blookup;
|
|
||||||
char *ptr;
|
|
||||||
|
|
||||||
if (closestcol[r][g][b] != 255) return(closestcol[r][g][b]);
|
|
||||||
|
|
||||||
j = (r>>3)*FASTPALGRIDSIZ*FASTPALGRIDSIZ+(g>>3)*FASTPALGRIDSIZ+(b>>3)+FASTPALGRIDSIZ*FASTPALGRIDSIZ+FASTPALGRIDSIZ+1;
|
|
||||||
mindist = min(rdist[coldist[r&7]+64+8],gdist[coldist[g&7]+64+8]);
|
|
||||||
mindist = min(mindist,bdist[coldist[b&7]+64+8]);
|
|
||||||
mindist++;
|
|
||||||
|
|
||||||
rlookup = (int *)&rdist[64-r];
|
|
||||||
glookup = (int *)&gdist[64-g];
|
|
||||||
blookup = (int *)&bdist[64-b];
|
|
||||||
|
|
||||||
retcol = -1;
|
|
||||||
for(k=26;k>=0;k--)
|
|
||||||
{
|
|
||||||
i = colscan[k]+j; if ((colhere[i>>3]&(1<<(i&7))) == 0) continue;
|
|
||||||
for(i=colhead[i];i>=0;i=colnext[i])
|
|
||||||
{
|
|
||||||
ptr = (char *)&palette[i*3];
|
|
||||||
dist = glookup[ptr[1]]; if (dist >= mindist) continue;
|
|
||||||
dist += rlookup[ptr[0]]; if (dist >= mindist) continue;
|
|
||||||
dist += blookup[ptr[2]]; if (dist >= mindist) continue;
|
|
||||||
mindist = dist; retcol = i;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (retcol < 0)
|
|
||||||
{
|
|
||||||
mindist = 0x7fffffff;
|
|
||||||
ptr = (char *)&palette[768-3];
|
|
||||||
for(i=255;i>=0;i--,ptr-=3)
|
|
||||||
{
|
|
||||||
dist = glookup[ptr[1]]; if (dist >= mindist) continue;
|
|
||||||
dist += rlookup[ptr[0]]; if (dist >= mindist) continue;
|
|
||||||
dist += blookup[ptr[2]]; if (dist >= mindist) continue;
|
|
||||||
mindist = dist; retcol = i;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
ptr = (char *)&closestcol[r][g][b];
|
|
||||||
*ptr = retcol;
|
|
||||||
if ((r >= 4) && (ptr[(-2)<<12] == retcol)) ptr[(-3)<<12] = retcol, ptr[(-2)<<12] = retcol, ptr[(-1)<<12] = retcol;
|
|
||||||
if ((g >= 4) && (ptr[(-2)<<6] == retcol)) ptr[(-3)<<6] = retcol, ptr[(-2)<<6] = retcol, ptr[(-1)<<6] = retcol;
|
|
||||||
if ((b >= 4) && (ptr[(-2)] == retcol)) ptr[(-3)] = retcol, ptr[(-2)] = retcol, ptr[(-1)] = retcol;
|
|
||||||
if ((r < 64-4) && (ptr[(2)<<12] == retcol)) ptr[(3)<<12] = retcol, ptr[(2)<<12] = retcol, ptr[(1)<<12] = retcol;
|
|
||||||
if ((g < 64-4) && (ptr[(2)<<6] == retcol)) ptr[(3)<<6] = retcol, ptr[(2)<<6] = retcol, ptr[(1)<<6] = retcol;
|
|
||||||
if ((b < 64-4) && (ptr[(2)] == retcol)) ptr[(3)] = retcol, ptr[(2)] = retcol, ptr[(1)] = retcol;
|
|
||||||
if ((r >= 2) && (ptr[(-1)<<12] == retcol)) ptr[(-1)<<12] = retcol;
|
|
||||||
if ((g >= 2) && (ptr[(-1)<<6] == retcol)) ptr[(-1)<<6] = retcol;
|
|
||||||
if ((b >= 2) && (ptr[(-1)] == retcol)) ptr[(-1)] = retcol;
|
|
||||||
if ((r < 64-2) && (ptr[(1)<<12] == retcol)) ptr[(1)<<12] = retcol;
|
|
||||||
if ((g < 64-2) && (ptr[(1)<<6] == retcol)) ptr[(1)<<6] = retcol;
|
|
||||||
if ((b < 64-2) && (ptr[(1)] == retcol)) ptr[(1)] = retcol;
|
|
||||||
return(retcol);
|
|
||||||
}
|
|
||||||
|
|
||||||
char getpalookup(char dashade, char dacol)
|
|
||||||
{
|
{
|
||||||
int r, g, b, t;
|
int r, g, b, t;
|
||||||
char *ptr;
|
char *ptr;
|
||||||
|
|
||||||
ptr = (char *)&palette[dacol*3];
|
ptr = (char *)&palette[dacol*3];
|
||||||
t = divscale16(numpalookups-dashade,numpalookups);
|
t = divscale16(numshades-dashade,numshades);
|
||||||
r = ((ptr[0]*t+32768)>>16);
|
r = ((ptr[0]*t+32768)>>16);
|
||||||
g = ((ptr[1]*t+32768)>>16);
|
g = ((ptr[1]*t+32768)>>16);
|
||||||
b = ((ptr[2]*t+32768)>>16);
|
b = ((ptr[2]*t+32768)>>16);
|
||||||
return(getclosestcol(r,g,b));
|
return(getclosestcol(r,g,b));
|
||||||
}
|
}
|
||||||
|
|
||||||
char gettrans(char dat1, char dat2, int datransratio)
|
static char gettrans(char dat1, char dat2, int datransratio)
|
||||||
{
|
{
|
||||||
int r, g, b;
|
int r, g, b;
|
||||||
char *ptr, *ptr2;
|
char *ptr, *ptr2;
|
||||||
|
@ -110,47 +42,11 @@ char gettrans(char dat1, char dat2, int datransratio)
|
||||||
return(getclosestcol(r,g,b));
|
return(getclosestcol(r,g,b));
|
||||||
}
|
}
|
||||||
|
|
||||||
void initfastcolorlookup(int rscale, int gscale, int bscale)
|
|
||||||
{
|
|
||||||
int i, j, x, y, z;
|
|
||||||
char *ptr;
|
|
||||||
|
|
||||||
j = 0;
|
|
||||||
for(i=64;i>=0;i--)
|
|
||||||
{
|
|
||||||
//j = (i-64)*(i-64);
|
|
||||||
rdist[i] = rdist[128-i] = j*rscale;
|
|
||||||
gdist[i] = gdist[128-i] = j*gscale;
|
|
||||||
bdist[i] = bdist[128-i] = j*bscale;
|
|
||||||
j += 129-(i<<1);
|
|
||||||
}
|
|
||||||
|
|
||||||
Bmemset(colhere, 0, sizeof(colhere));
|
|
||||||
Bmemset(colhead, 0, sizeof(colhead));
|
|
||||||
|
|
||||||
ptr = (char *)&palette[768-3];
|
|
||||||
for(i=255;i>=0;i--,ptr-=3)
|
|
||||||
{
|
|
||||||
j = (ptr[0]>>3)*FASTPALGRIDSIZ*FASTPALGRIDSIZ+(ptr[1]>>3)*FASTPALGRIDSIZ+(ptr[2]>>3)+FASTPALGRIDSIZ*FASTPALGRIDSIZ+FASTPALGRIDSIZ+1;
|
|
||||||
if (colhere[j>>3]&(1<<(j&7))) colnext[i] = colhead[j]; else colnext[i] = -1;
|
|
||||||
colhead[j] = i;
|
|
||||||
colhere[j>>3] |= (1<<(j&7));
|
|
||||||
}
|
|
||||||
|
|
||||||
i = 0;
|
|
||||||
for(x=-FASTPALGRIDSIZ*FASTPALGRIDSIZ;x<=FASTPALGRIDSIZ*FASTPALGRIDSIZ;x+=FASTPALGRIDSIZ*FASTPALGRIDSIZ)
|
|
||||||
for(y=-FASTPALGRIDSIZ;y<=FASTPALGRIDSIZ;y+=FASTPALGRIDSIZ)
|
|
||||||
for(z=-1;z<=1;z++)
|
|
||||||
colscan[i++] = x+y+z;
|
|
||||||
i = colscan[13]; colscan[13] = colscan[26]; colscan[26] = i;
|
|
||||||
}
|
|
||||||
|
|
||||||
int main(int argc, char **argv)
|
int main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
char col, ch;
|
char col, ch;
|
||||||
short orignumpalookups;
|
short orignumshades;
|
||||||
int fil, i, j, rscale, gscale, bscale;
|
int fil, i, j, rscale, gscale, bscale;
|
||||||
char buf[65536];
|
|
||||||
|
|
||||||
ch = 13;
|
ch = 13;
|
||||||
if (argc>1) {
|
if (argc>1) {
|
||||||
|
@ -173,8 +69,7 @@ int main(int argc, char **argv)
|
||||||
exit(0);
|
exit(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
Bstrcpy(palettefilename,"palette.dat");
|
numshades = Batol(argv[1]);
|
||||||
numpalookups = Batol(argv[1]);
|
|
||||||
transratio = Batol(argv[2]);
|
transratio = Batol(argv[2]);
|
||||||
|
|
||||||
if (argc == 6)
|
if (argc == 6)
|
||||||
|
@ -190,7 +85,7 @@ int main(int argc, char **argv)
|
||||||
bscale = 11;
|
bscale = 11;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((numpalookups < 1) || (numpalookups > 256))
|
if ((numshades < 1) || (numshades > 256))
|
||||||
{ Bprintf("Invalid number of shades\n"); exit(0); }
|
{ Bprintf("Invalid number of shades\n"); exit(0); }
|
||||||
if ((transratio < 0) || (transratio > 256))
|
if ((transratio < 0) || (transratio > 256))
|
||||||
{ Bprintf("Invalid transluscent ratio\n"); exit(0); }
|
{ Bprintf("Invalid transluscent ratio\n"); exit(0); }
|
||||||
|
@ -200,33 +95,25 @@ int main(int argc, char **argv)
|
||||||
Bprintf("%s not found",palettefilename);
|
Bprintf("%s not found",palettefilename);
|
||||||
return(0);
|
return(0);
|
||||||
}
|
}
|
||||||
Bread(fil,palette,768);
|
Bread(fil,origpalette,768);
|
||||||
Bread(fil,&orignumpalookups,2); orignumpalookups = B_LITTLE16(orignumpalookups);
|
Bread(fil,&orignumshades,2); orignumshades = B_LITTLE16(orignumshades);
|
||||||
orignumpalookups = min(max(orignumpalookups,1),256);
|
orignumshades = min(max(orignumshades,1),256);
|
||||||
Bread(fil,origpalookup,(int)orignumpalookups<<8);
|
Bread(fil,origpalookup,(int)orignumshades<<8);
|
||||||
Bclose(fil);
|
Bclose(fil);
|
||||||
|
|
||||||
clearbuf(buf,65536>>2,0L);
|
for (int k = 0; k < 768; k++)
|
||||||
|
palette[k] = origpalette[k] << 2;
|
||||||
|
|
||||||
initfastcolorlookup(rscale,gscale,bscale);
|
initdivtables();
|
||||||
clearbuf(closestcol,262144>>2,0xffffffff);
|
initfastcolorlookup_scale(rscale,gscale,bscale);
|
||||||
|
initfastcolorlookup_palette(palette);
|
||||||
|
initfastcolorlookup_gridvectors();
|
||||||
|
|
||||||
for(i=0;i<numpalookups;i++)
|
for(i=0;i<numshades;i++)
|
||||||
for(j=0;j<256;j++)
|
for(j=0;j<256;j++)
|
||||||
{
|
{
|
||||||
col = getpalookup((char)i,(char)j);
|
col = getshade((char)i,(char)j);
|
||||||
palookup[(i<<8)+j] = col;
|
palookup[(i<<8)+j] = col;
|
||||||
|
|
||||||
drawpixel(((((i<<1)+0)*320+(j+8))>>2)+buf,(int)col);
|
|
||||||
drawpixel(((((i<<1)+1)*320+(j+8))>>2)+buf,(int)col);
|
|
||||||
}
|
|
||||||
|
|
||||||
for(i=0;i<256;i++)
|
|
||||||
for(j=0;j<6;j++)
|
|
||||||
{
|
|
||||||
drawpixel((((j+132+0)*320+(i+8))>>2)+buf,i);
|
|
||||||
|
|
||||||
drawpixel((((i+132+8)*320+(j+0))>>2)+buf,i);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for(i=0;i<256;i++)
|
for(i=0;i<256;i++)
|
||||||
|
@ -234,8 +121,6 @@ int main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
col = gettrans((char)i,(char)j,transratio);
|
col = gettrans((char)i,(char)j,transratio);
|
||||||
transluc[(i<<8)+j] = col;
|
transluc[(i<<8)+j] = col;
|
||||||
|
|
||||||
drawpixel((((j+132+8)*320+(i+8))>>2)+buf,(int)col);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ch == 13)
|
if (ch == 13)
|
||||||
|
@ -243,9 +128,9 @@ int main(int argc, char **argv)
|
||||||
short s;
|
short s;
|
||||||
if ((fil = Bopen(palettefilename,BO_BINARY|BO_TRUNC|BO_CREAT|BO_WRONLY,BS_IREAD|BS_IWRITE)) == -1)
|
if ((fil = Bopen(palettefilename,BO_BINARY|BO_TRUNC|BO_CREAT|BO_WRONLY,BS_IREAD|BS_IWRITE)) == -1)
|
||||||
{ Bprintf("Couldn't save file %s",palettefilename); return(0); }
|
{ Bprintf("Couldn't save file %s",palettefilename); return(0); }
|
||||||
Bwrite(fil,palette,768);
|
Bwrite(fil,origpalette,768);
|
||||||
s = B_LITTLE16(numpalookups); Bwrite(fil,&s,2);
|
s = B_LITTLE16(numshades); Bwrite(fil,&s,2);
|
||||||
Bwrite(fil,palookup,numpalookups<<8);
|
Bwrite(fil,palookup,numshades<<8);
|
||||||
Bwrite(fil,transluc,65536);
|
Bwrite(fil,transluc,65536);
|
||||||
Bclose(fil);
|
Bclose(fil);
|
||||||
Bprintf("Shade table AND transluscent table updated\n");
|
Bprintf("Shade table AND transluscent table updated\n");
|
||||||
|
@ -255,9 +140,9 @@ int main(int argc, char **argv)
|
||||||
short s;
|
short s;
|
||||||
if ((fil = Bopen(palettefilename,BO_BINARY|BO_TRUNC|BO_CREAT|BO_WRONLY,BS_IREAD|BS_IWRITE)) == -1)
|
if ((fil = Bopen(palettefilename,BO_BINARY|BO_TRUNC|BO_CREAT|BO_WRONLY,BS_IREAD|BS_IWRITE)) == -1)
|
||||||
{ Bprintf("Couldn't save file %s",palettefilename); return(0); }
|
{ Bprintf("Couldn't save file %s",palettefilename); return(0); }
|
||||||
Bwrite(fil,palette,768);
|
Bwrite(fil,origpalette,768);
|
||||||
s = B_LITTLE16(orignumpalookups); Bwrite(fil,&s,2);
|
s = B_LITTLE16(orignumshades); Bwrite(fil,&s,2);
|
||||||
Bwrite(fil,origpalookup,(int)orignumpalookups<<8);
|
Bwrite(fil,origpalookup,(int)orignumshades<<8);
|
||||||
Bwrite(fil,transluc,65536);
|
Bwrite(fil,transluc,65536);
|
||||||
Bclose(fil);
|
Bclose(fil);
|
||||||
Bprintf("Transluscent table updated\n");
|
Bprintf("Transluscent table updated\n");
|
||||||
|
@ -267,4 +152,3 @@ int main(int argc, char **argv)
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue