Change method of color look-up table generation

This commit is contained in:
Jaime Passos 2020-09-10 01:43:46 -03:00
parent ca060a4372
commit f24647dc4d
3 changed files with 53 additions and 23 deletions

View file

@ -505,14 +505,14 @@ static void GIF_rgbconvert(UINT8 *linear, UINT8 *scr)
size_t src = 0, dest = 0; size_t src = 0, dest = 0;
size_t size = (vid.width * vid.height * 3); size_t size = (vid.width * vid.height * 3);
InitColorLUT(gif_framepalette); InitColorLUT(gif_framepalette, true);
while (src < size) while (src < size)
{ {
r = (UINT8)linear[src]; r = (UINT8)linear[src];
g = (UINT8)linear[src + 1]; g = (UINT8)linear[src + 1];
b = (UINT8)linear[src + 2]; b = (UINT8)linear[src + 2];
scr[dest] = colorlookup[r >> SHIFTCOLORBITS][g >> SHIFTCOLORBITS][b >> SHIFTCOLORBITS]; scr[dest] = GetColorLUTDirect(r, g, b);
src += (3 * scrbuf_downscaleamt); src += (3 * scrbuf_downscaleamt);
dest += scrbuf_downscaleamt; dest += scrbuf_downscaleamt;
} }

View file

@ -3666,28 +3666,53 @@ Unoptimized version
#endif #endif
} }
// Generates a color look-up table // Generates a RGB565 color look-up table
// which has up to 64 colors at each channel static colorlookup_t colorlookup;
// (see the defines in v_video.h)
UINT8 colorlookup[CLUTSIZE][CLUTSIZE][CLUTSIZE]; void InitColorLUT(RGBA_t *palette, boolean makecolors)
void InitColorLUT(RGBA_t *palette)
{ {
UINT8 r, g, b; size_t palsize = (sizeof(RGBA_t) * 256);
static boolean clutinit = false;
static RGBA_t *lastpalette = NULL; if (!colorlookup.init || memcmp(colorlookup.palette, palette, palsize))
if ((!clutinit) || (lastpalette != palette))
{ {
for (r = 0; r < CLUTSIZE; r++) INT32 i;
for (g = 0; g < CLUTSIZE; g++)
for (b = 0; b < CLUTSIZE; b++) colorlookup.init = true;
colorlookup[r][g][b] = NearestPaletteColor(r << SHIFTCOLORBITS, g << SHIFTCOLORBITS, b << SHIFTCOLORBITS, palette); memcpy(colorlookup.palette, palette, palsize);
clutinit = true;
lastpalette = palette; for (i = 0; i < 0xFFFF; i++)
colorlookup.table[i] = 0xFFFF;
if (makecolors)
{
UINT8 r, g, b;
for (r = 0; r < 0xFF; r++)
for (g = 0; g < 0xFF; g++)
for (b = 0; b < 0xFF; b++)
{
i = CLUTINDEX(r, g, b);
if (colorlookup.table[i] == 0xFFFF)
colorlookup.table[i] = NearestPaletteColor(r, g, b, palette);
}
}
} }
} }
UINT8 GetColorLUT(UINT8 r, UINT8 g, UINT8 b)
{
INT32 i = CLUTINDEX(r, g, b);
if (colorlookup.table[i] == 0xFFFF)
colorlookup.table[i] = NearestPaletteColor(r << 3, g << 2, b << 3, colorlookup.palette);
return colorlookup.table[i];
}
UINT8 GetColorLUTDirect(UINT8 r, UINT8 g, UINT8 b)
{
INT32 i = CLUTINDEX(r, g, b);
return colorlookup.table[i];
}
// V_Init // V_Init
// old software stuff, buffers are allocated at video mode setup // old software stuff, buffers are allocated at video mode setup
// here we set the screens[x] pointers accordingly // here we set the screens[x] pointers accordingly

View file

@ -38,13 +38,18 @@ cv_allcaps;
void V_Init(void); void V_Init(void);
// Color look-up table // Color look-up table
#define COLORBITS 6 #define CLUTINDEX(r, g, b) (((r) >> 3) << 11) | (((g) >> 2) << 5) | ((b) >> 3)
#define SHIFTCOLORBITS (8-COLORBITS)
#define CLUTSIZE (1<<COLORBITS)
extern UINT8 colorlookup[CLUTSIZE][CLUTSIZE][CLUTSIZE]; void InitColorLUT(RGBA_t *palette, boolean makecolors);
UINT8 GetColorLUT(UINT8 r, UINT8 g, UINT8 b);
UINT8 GetColorLUTDirect(UINT8 r, UINT8 g, UINT8 b);
void InitColorLUT(RGBA_t *palette); typedef struct
{
boolean init;
RGBA_t palette[256];
UINT16 table[0xFFFF];
} colorlookup_t;
// Set the current RGB palette lookup to use for palettized graphics // Set the current RGB palette lookup to use for palettized graphics
void V_SetPalette(INT32 palettenum); void V_SetPalette(INT32 palettenum);