From 636093a59ddd95b25d79c4ebff51dc6412de1956 Mon Sep 17 00:00:00 2001 From: Jaime Passos Date: Mon, 27 Jan 2020 13:55:13 -0300 Subject: [PATCH] Fix color LUT using the wrong palette --- src/m_anigif.c | 18 +++++------------- src/r_data.c | 12 ++++++++---- src/r_data.h | 3 ++- src/v_video.c | 3 +-- src/v_video.h | 5 +---- 5 files changed, 17 insertions(+), 24 deletions(-) diff --git a/src/m_anigif.c b/src/m_anigif.c index 32fc2746d..f062bc826 100644 --- a/src/m_anigif.c +++ b/src/m_anigif.c @@ -624,14 +624,6 @@ static void GIF_framewrite(void) // 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"); if (!gif_out) return 0; @@ -640,13 +632,13 @@ INT32 GIF_open(const char *filename) gif_downscale = (!!cv_gif_downscale.value); // GIF color table - // In hardware mode, uses the master palette - gif_palette = ((cv_screenshot_colorprofile.value + // In hardware mode, forces the local palette #ifdef HWRENDER - && (rendermode == render_soft) + if (rendermode == render_opengl) + gif_palette = pLocalPalette; + else #endif - ) ? pLocalPalette - : pMasterPalette); + gif_palette = ((cv_screenshot_colorprofile.value) ? pLocalPalette : pMasterPalette); GIF_headwrite(); gif_frames = 0; diff --git a/src/r_data.c b/src/r_data.c index 9f80e257b..e0a3d48d4 100644 --- a/src/r_data.c +++ b/src/r_data.c @@ -2465,16 +2465,20 @@ extracolormap_t *R_AddColormaps(extracolormap_t *exc_augend, extracolormap_t *ex // Thanks to quake2 source! // 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 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++) { - dr = r - pMasterPalette[i].s.red; - dg = g - pMasterPalette[i].s.green; - db = b - pMasterPalette[i].s.blue; + dr = r - palette[i].s.red; + dg = g - palette[i].s.green; + db = b - palette[i].s.blue; distortion = dr*dr + dg*dg + db*db; if (distortion < bestdistortion) { diff --git a/src/r_data.h b/src/r_data.h index f028f2f5d..145f0182b 100644 --- a/src/r_data.h +++ b/src/r_data.h @@ -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_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; diff --git a/src/v_video.c b/src/v_video.c index 4785a1541..81625ff9e 100644 --- a/src/v_video.c +++ b/src/v_video.c @@ -3244,7 +3244,6 @@ Unoptimized version #endif } -// Taken from my videos-in-SRB2 project // Generates a color look-up table // which has up to 64 colors at each channel // (see the defines in v_video.h) @@ -3261,7 +3260,7 @@ void InitColorLUT(RGBA_t *palette) for (r = 0; r < CLUTSIZE; r++) for (g = 0; g < CLUTSIZE; g++) 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; lastpalette = palette; } diff --git a/src/v_video.h b/src/v_video.h index eb75a414f..bc19f6e99 100644 --- a/src/v_video.h +++ b/src/v_video.h @@ -37,10 +37,7 @@ cv_allcaps; // Allocates buffer screens, call before R_Init. void V_Init(void); -// Taken from my videos-in-SRB2 project -// Generates a color look-up table -// which has up to 64 colors at each channel - +// Color look-up table #define COLORBITS 6 #define SHIFTCOLORBITS (8-COLORBITS) #define CLUTSIZE (1<