Fix color LUT using the wrong palette

This commit is contained in:
Jaime Passos 2020-01-27 13:55:13 -03:00
parent 3c5a4462c4
commit e1ee02c308
5 changed files with 17 additions and 24 deletions

View file

@ -624,14 +624,6 @@ static void GIF_framewrite(void)
// //
INT32 GIF_open(const char *filename) INT32 GIF_open(const char *filename)
{ {
#if 0
if (rendermode != render_soft)
{
CONS_Alert(CONS_WARNING, M_GetText("GIFs cannot be taken in non-software modes!\n"));
return 0;
}
#endif
gif_out = fopen(filename, "wb"); gif_out = fopen(filename, "wb");
if (!gif_out) if (!gif_out)
return 0; return 0;
@ -640,13 +632,13 @@ INT32 GIF_open(const char *filename)
gif_downscale = (!!cv_gif_downscale.value); gif_downscale = (!!cv_gif_downscale.value);
// GIF color table // GIF color table
// In hardware mode, uses the master palette // In hardware mode, forces the local palette
gif_palette = ((cv_screenshot_colorprofile.value
#ifdef HWRENDER #ifdef HWRENDER
&& (rendermode == render_soft) if (rendermode == render_opengl)
gif_palette = pLocalPalette;
else
#endif #endif
) ? pLocalPalette gif_palette = ((cv_screenshot_colorprofile.value) ? pLocalPalette : pMasterPalette);
: pMasterPalette);
GIF_headwrite(); GIF_headwrite();
gif_frames = 0; gif_frames = 0;

View file

@ -2465,16 +2465,20 @@ extracolormap_t *R_AddColormaps(extracolormap_t *exc_augend, extracolormap_t *ex
// Thanks to quake2 source! // Thanks to quake2 source!
// utils3/qdata/images.c // utils3/qdata/images.c
UINT8 NearestColor(UINT8 r, UINT8 g, UINT8 b) UINT8 NearestPaletteColor(UINT8 r, UINT8 g, UINT8 b, RGBA_t *palette)
{ {
int dr, dg, db; int dr, dg, db;
int distortion, bestdistortion = 256 * 256 * 4, bestcolor = 0, i; int distortion, bestdistortion = 256 * 256 * 4, bestcolor = 0, i;
// Use master palette if none specified
if (palette == NULL)
palette = pMasterPalette;
for (i = 0; i < 256; i++) for (i = 0; i < 256; i++)
{ {
dr = r - pMasterPalette[i].s.red; dr = r - palette[i].s.red;
dg = g - pMasterPalette[i].s.green; dg = g - palette[i].s.green;
db = b - pMasterPalette[i].s.blue; db = b - palette[i].s.blue;
distortion = dr*dr + dg*dg + db*db; distortion = dr*dr + dg*dg + db*db;
if (distortion < bestdistortion) if (distortion < bestdistortion)
{ {

View file

@ -171,7 +171,8 @@ const char *R_NameForColormap(extracolormap_t *extra_colormap);
#define R_PutRgbaRGB(r, g, b) (R_PutRgbaR(r) + R_PutRgbaG(g) + R_PutRgbaB(b)) #define R_PutRgbaRGB(r, g, b) (R_PutRgbaR(r) + R_PutRgbaG(g) + R_PutRgbaB(b))
#define R_PutRgbaRGBA(r, g, b, a) (R_PutRgbaRGB(r, g, b) + R_PutRgbaA(a)) #define R_PutRgbaRGBA(r, g, b, a) (R_PutRgbaRGB(r, g, b) + R_PutRgbaA(a))
UINT8 NearestColor(UINT8 r, UINT8 g, UINT8 b); UINT8 NearestPaletteColor(UINT8 r, UINT8 g, UINT8 b, RGBA_t *palette);
#define NearestColor(r, g, b) NearestPaletteColor(r, g, b, NULL)
extern INT32 numtextures; extern INT32 numtextures;

View file

@ -3244,7 +3244,6 @@ Unoptimized version
#endif #endif
} }
// Taken from my videos-in-SRB2 project
// Generates a color look-up table // Generates a color look-up table
// which has up to 64 colors at each channel // which has up to 64 colors at each channel
// (see the defines in v_video.h) // (see the defines in v_video.h)
@ -3261,7 +3260,7 @@ void InitColorLUT(RGBA_t *palette)
for (r = 0; r < CLUTSIZE; r++) for (r = 0; r < CLUTSIZE; r++)
for (g = 0; g < CLUTSIZE; g++) for (g = 0; g < CLUTSIZE; g++)
for (b = 0; b < CLUTSIZE; b++) for (b = 0; b < CLUTSIZE; b++)
colorlookup[r][g][b] = NearestColor(r << SHIFTCOLORBITS, g << SHIFTCOLORBITS, b << SHIFTCOLORBITS); colorlookup[r][g][b] = NearestPaletteColor(r << SHIFTCOLORBITS, g << SHIFTCOLORBITS, b << SHIFTCOLORBITS, palette);
clutinit = true; clutinit = true;
lastpalette = palette; lastpalette = palette;
} }

View file

@ -37,10 +37,7 @@ cv_allcaps;
// Allocates buffer screens, call before R_Init. // Allocates buffer screens, call before R_Init.
void V_Init(void); void V_Init(void);
// Taken from my videos-in-SRB2 project // Color look-up table
// Generates a color look-up table
// which has up to 64 colors at each channel
#define COLORBITS 6 #define COLORBITS 6
#define SHIFTCOLORBITS (8-COLORBITS) #define SHIFTCOLORBITS (8-COLORBITS)
#define CLUTSIZE (1<<COLORBITS) #define CLUTSIZE (1<<COLORBITS)