diff --git a/src/m_anigif.c b/src/m_anigif.c
index 91f70dcfe0f6c2399825bb060c9f6e7fe8919fd5..f761db143b0cb016ee0395e9f045c8cdeb49d444 100644
--- a/src/m_anigif.c
+++ b/src/m_anigif.c
@@ -33,6 +33,7 @@ consvar_t cv_gif_downscale =  {"gif_downscale", "On", CV_SAVE, CV_OnOff, NULL, 0
 #ifdef HAVE_ANIGIF
 static boolean gif_optimize = false; // So nobody can do something dumb
 static boolean gif_downscale = false; // like changing cvars mid output
+static RGBA_t *gif_palette = NULL;
 
 static FILE *gif_out = NULL;
 static INT32 gif_frames = 0;
@@ -432,13 +433,7 @@ static void GIF_headwrite(void)
 
 	// write color table
 	{
-		RGBA_t *pal = ((cv_screenshot_colorprofile.value
-#ifdef HWRENDER
-		&& (rendermode == render_soft)
-#endif
-		) ? pLocalPalette
-		: pMasterPalette);
-
+		RGBA_t *pal = gif_palette;
 		for (i = 0; i < 256; i++)
 		{
 			WRITEUINT8(p, pal[i].s.red);
@@ -473,7 +468,7 @@ static void hwrconvert(void)
 	INT32 x, y;
 	size_t i = 0;
 
-	InitColorLUT();
+	InitColorLUT(gif_palette);
 
 	for (y = 0; y < vid.height; y++)
 	{
@@ -643,6 +638,16 @@ INT32 GIF_open(const char *filename)
 
 	gif_optimize = (!!cv_gif_optimize.value);
 	gif_downscale = (!!cv_gif_downscale.value);
+
+	// GIF color table
+	// In hardware mode, uses the master palette
+	gif_palette = ((cv_screenshot_colorprofile.value
+#ifdef HWRENDER
+	&& (rendermode == render_soft)
+#endif
+	) ? pLocalPalette
+	: pMasterPalette);
+
 	GIF_headwrite();
 	gif_frames = 0;
 	return 1;
diff --git a/src/v_video.c b/src/v_video.c
index 1e901f2b3f037548a7f66e89b578c40acf0cabc3..c91e5f213e8fb7ec0eca1ddc9d29176dbc2d8440 100644
--- a/src/v_video.c
+++ b/src/v_video.c
@@ -3251,19 +3251,19 @@ Unoptimized version
 
 UINT8 colorlookup[CLUTSIZE][CLUTSIZE][CLUTSIZE];
 
-void InitColorLUT(void)
+void InitColorLUT(RGBA_t *palette)
 {
 	UINT8 r, g, b;
 	static boolean clutinit = false;
 	static RGBA_t *lastpalette = NULL;
-	if ((!clutinit) || (lastpalette != pLocalPalette))
+	if ((!clutinit) || (lastpalette != 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);
 		clutinit = true;
-		lastpalette = pLocalPalette;
+		lastpalette = palette;
 	}
 }
 
diff --git a/src/v_video.h b/src/v_video.h
index 0cd78d2e59fe9c601ca17a7f5b352d4523444e24..36d1914af6edec7f1b9996e4c767d507dcaf8a71 100644
--- a/src/v_video.h
+++ b/src/v_video.h
@@ -47,7 +47,7 @@ void V_Init(void);
 
 extern UINT8 colorlookup[CLUTSIZE][CLUTSIZE][CLUTSIZE];
 
-void InitColorLUT(void);
+void InitColorLUT(RGBA_t *palette);
 
 // Set the current RGB palette lookup to use for palettized graphics
 void V_SetPalette(INT32 palettenum);