mirror of
https://github.com/yquake2/yquake2remaster.git
synced 2025-02-01 05:30:58 +00:00
Automatically generate 16to8 bit colors
This commit is contained in:
parent
903272ee09
commit
43e4951f43
3 changed files with 58 additions and 9 deletions
|
@ -640,7 +640,7 @@ R_FindPic(const char *name, findimage_t find_image)
|
|||
Com_sprintf(pathname, sizeof(pathname), "pics/%s.pcx", name);
|
||||
image = find_image(pathname, it_pic);
|
||||
|
||||
/* Quake 2 Re Release*/
|
||||
/* Quake 2 Re-Release */
|
||||
if (!image)
|
||||
{
|
||||
Com_sprintf(pathname, sizeof(pathname), "pics/%s.png", name);
|
||||
|
|
|
@ -691,14 +691,17 @@ R_InitImages (void)
|
|||
registration_sequence = 1;
|
||||
image_max = 0;
|
||||
|
||||
R_Printf(PRINT_ALL, "%s() Load colormap\n", __func__);
|
||||
|
||||
GetPCXPalette (&vid_colormap, (unsigned *)d_8to24table);
|
||||
vid_alphamap = vid_colormap + 64*256;
|
||||
|
||||
d_16to8table = NULL;
|
||||
ri.FS_LoadFile("pics/16to8.dat", (void **)&table16to8);
|
||||
|
||||
if ( !table16to8 )
|
||||
{
|
||||
ri.Sys_Error(ERR_FATAL, "%s: Couldn't load pics/16to8.dat", __func__);
|
||||
// code never returns after ERR_FATAL
|
||||
return;
|
||||
R_Printf(PRINT_ALL, "%s: Couldn't load pics/16to8.dat", __func__);
|
||||
}
|
||||
|
||||
d_16to8table = malloc(0x10000);
|
||||
|
@ -708,8 +711,57 @@ R_InitImages (void)
|
|||
// code never returns after ERR_FATAL
|
||||
return;
|
||||
}
|
||||
memcpy(d_16to8table, table16to8, 0x10000);
|
||||
ri.FS_FreeFile((void *)table16to8);
|
||||
|
||||
if (table16to8)
|
||||
{
|
||||
// Use predefined convert map
|
||||
memcpy(d_16to8table, table16to8, 0x10000);
|
||||
ri.FS_FreeFile((void *)table16to8);
|
||||
}
|
||||
else
|
||||
{
|
||||
// create new one
|
||||
unsigned int r, g, b, i;
|
||||
|
||||
for (r = 0; r < 32; r++)
|
||||
{
|
||||
for (g = 0; g < 64; g++)
|
||||
{
|
||||
for (b = 0; b < 32; b++)
|
||||
{
|
||||
float diff = 1024;
|
||||
|
||||
for (i = 0; i < 256; i ++)
|
||||
{
|
||||
int r_c, g_c, b_c;
|
||||
float curr_diff;
|
||||
|
||||
r_c = d_8to24table[i * 4 + 0] - (r << 3);
|
||||
g_c = d_8to24table[i * 4 + 1] - (g << 2);
|
||||
b_c = d_8to24table[i * 4 + 2] - (b << 3);
|
||||
|
||||
curr_diff = sqrt(
|
||||
(r_c * r_c) +
|
||||
(g_c * g_c) +
|
||||
(b_c * b_c)
|
||||
);
|
||||
|
||||
if (curr_diff < diff)
|
||||
{
|
||||
int c;
|
||||
|
||||
diff = curr_diff;
|
||||
|
||||
c = r | ( g << 5 ) | ( b << 11 );
|
||||
|
||||
// set color with minimal difference
|
||||
d_16to8table[c & 0xFFFF] = i;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
R_InitTextures ();
|
||||
}
|
||||
|
|
|
@ -471,9 +471,6 @@ RE_Init(void)
|
|||
|
||||
r_aliasuvscale = 1.0;
|
||||
|
||||
GetPCXPalette (&vid_colormap, (unsigned *)d_8to24table);
|
||||
vid_alphamap = vid_colormap + 64*256;
|
||||
|
||||
/* set our "safe" mode */
|
||||
sw_state.prev_mode = 4;
|
||||
|
||||
|
|
Loading…
Reference in a new issue