15to8 palette pre-loading for win32 targets too...

This commit is contained in:
Dabb 2000-07-09 09:43:10 +00:00
parent 01148e4ce9
commit 728a5dfc47

View file

@ -718,13 +718,19 @@ void VID_SetPalette (unsigned char *palette)
unsigned r,g,b; unsigned r,g,b;
unsigned v; unsigned v;
int r1,g1,b1; int r1,g1,b1;
int j,k,l; int k;
unsigned short i; unsigned short i;
unsigned *table; unsigned *table;
FILE *f;
char s[255];
float dist, bestdist;
static qboolean palflag = false;
// //
// 8 8 8 encoding // 8 8 8 encoding
// //
// Con_Printf("Converting 8to24\n");
pal = palette; pal = palette;
table = d_8to24table; table = d_8to24table;
for (i=0 ; i<256 ; i++) for (i=0 ; i<256 ; i++)
@ -739,10 +745,19 @@ void VID_SetPalette (unsigned char *palette)
v = (255<<24) + (r<<0) + (g<<8) + (b<<16); v = (255<<24) + (r<<0) + (g<<8) + (b<<16);
*table++ = v; *table++ = v;
} }
d_8to24table[255] &= 0xffffff; // 255 is transparent d_8to24table[255] &= 0; // 255 is transparent
// JACK: 3D distance calcs - k is last closest, l is the distance. // JACK: 3D distance calcs - k is last closest, l is the distance.
// FIXME: Precalculate this and cache to disk. // FIXME: Precalculate this and cache to disk.
if (palflag)
return;
palflag = true;
COM_FOpenFile("glquake/15to8.pal", &f);
if (f) {
fread(d_15to8table, 1<<15, 1, f);
fclose(f);
} else {
for (i=0; i < (1<<15); i++) { for (i=0; i < (1<<15); i++) {
/* Maps /* Maps
000000000000000 000000000000000
@ -754,18 +769,26 @@ void VID_SetPalette (unsigned char *palette)
g = ((i & 0x03E0) >> 2)+4; g = ((i & 0x03E0) >> 2)+4;
b = ((i & 0x7C00) >> 7)+4; b = ((i & 0x7C00) >> 7)+4;
pal = (unsigned char *)d_8to24table; pal = (unsigned char *)d_8to24table;
for (v=0,k=0,l=10000*10000; v<256; v++,pal+=4) { for (v=0,k=0,bestdist=10000.0; v<256; v++,pal+=4) {
r1 = r-pal[0]; r1 = (int)r - (int)pal[0];
g1 = g-pal[1]; g1 = (int)g - (int)pal[1];
b1 = b-pal[2]; b1 = (int)b - (int)pal[2];
j = (r1*r1)+(g1*g1)+(b1*b1); dist = sqrt(((r1*r1)+(g1*g1)+(b1*b1)));
if (j<l) { if (dist < bestdist) {
k=v; k=v;
l=j; bestdist = dist;
} }
} }
d_15to8table[i]=k; d_15to8table[i]=k;
} }
snprintf(s, sizeof(s), "%s/glquake", com_gamedir);
Sys_mkdir (s);
snprintf(s, sizeof(s), "%s/glquake/15to8.pal", com_gamedir);
if ((f = fopen(s, "wb")) != NULL) {
fwrite(d_15to8table, 1<<15, 1, f);
fclose(f);
}
}
} }
BOOL gammaworks; BOOL gammaworks;