#include "quakedef.h"
+cvar_t r_colormap_palette = {0, "r_colormap_palette", "gfx/colormap_palette.lmp", "name of a palette lmp file to override the shirt/pants colors of player models. It consists of 16 shirt colors, 16 scoreboard shirt colors, 16 pants colors and 16 scoreboard pants colors"};
+
unsigned int palette_complete[256];
unsigned int palette_font[256];
unsigned int palette_alpha[256];
unsigned int palette_pantsaswhite[256];
unsigned int palette_shirtaswhite[256];
unsigned int palette_transparent[256];
+unsigned int palette_pantscolormap[16];
+unsigned int palette_shirtcolormap[16];
+unsigned int palette_pantsscoreboard[16];
+unsigned int palette_shirtscoreboard[16];
// John Carmack said the quake palette.lmp can be considered public domain because it is not an important asset to id, so I include it here as a fallback if no external palette file is found.
unsigned char host_quakepal[768] =
// 0xB* 11 v
111,131,123, 103,123,111, 95,115,103, 87,107,95, 79,99,87, 71,91,79, 63,83,71, 55,75,63,
47,67,55, 43,59,47, 35,51,39, 31,43,31, 23,35,23, 15,27,19, 11,19,11, 7,11,7,
-// 0xC*
+// 0xC* 12 v
255,243,27, 239,223,23, 219,203,19, 203,183,15, 187,167,15, 171,151,11, 155,131,7, 139,115,7,
123,99,7, 107,83,0, 91,71,0, 75,55,0, 59,43,0, 43,31,0, 27,15,0, 11,7,0,
-// 0xD* 12 ^
+// 0xD* 13 v
0,0,255, 11,11,239, 19,19,223, 27,27,207, 35,35,191, 43,43,175, 47,47,159, 47,47,143,
47,47,127, 47,47,111, 47,47,95, 43,43,79, 35,35,63, 27,27,47, 19,19,31, 11,11,15,
-// 0xE* 13 ^
+// 0xE*
43,0,0, 59,0,0, 75,7,0, 95,7,0, 111,15,0, 127,23,7, 147,31,7, 163,39,11,
183,51,15, 195,75,27, 207,99,43, 219,127,59, 227,151,79, 231,171,95, 239,191,119, 247,211,139,
// 0xF* 14 ^
}
}
-void Palette_Init(void)
+void Palette_Shutdown(void)
+{
+}
+
+void Palette_NewMap(void)
+{
+}
+
+void Palette_Load(void)
{
int i;
float gamma, scale, base;
if (palfile)
Mem_Free(palfile);
+if(*r_colormap_palette.string)
+ palfile = (unsigned char *)FS_LoadFile (r_colormap_palette.string, tempmempool, false, &filesize);
+else
+ palfile = NULL;
+
+in = palfile;
+if (palfile && filesize >= 48)
+{
+ out = (unsigned char *) palette_shirtcolormap;
+ for (i = 0;i < 16;i++)
+ {
+ *out++ = texturegammaramp[*in++];
+ *out++ = texturegammaramp[*in++];
+ *out++ = texturegammaramp[*in++];
+ *out++ = 255;
+ }
+}
+else
+ for(i = 0; i < 16; ++i)
+ palette_shirtcolormap[i] = palette_complete[(i << 4) | ((i >= 8 && i <= 13) ? 0x04 : 0x0C)];
+
+if(palfile && filesize >= 48 + 48)
+{
+ out = (unsigned char *) palette_shirtscoreboard;
+ for (i = 0;i < 16;i++)
+ {
+ *out++ = texturegammaramp[*in++];
+ *out++ = texturegammaramp[*in++];
+ *out++ = texturegammaramp[*in++];
+ *out++ = 255;
+ }
+}
+else
+ for(i = 0; i < 16; ++i)
+ palette_shirtscoreboard[i] = palette_complete[(i << 4) | 0x08];
+
+if (palfile && filesize >= 48 + 48 + 48)
+{
+ out = (unsigned char *) palette_pantscolormap;
+ for (i = 0;i < 16;i++)
+ {
+ *out++ = texturegammaramp[*in++];
+ *out++ = texturegammaramp[*in++];
+ *out++ = texturegammaramp[*in++];
+ *out++ = 255;
+ }
+}
+else
+ memcpy(palette_pantscolormap, palette_shirtcolormap, sizeof(palette_pantscolormap));
+
+if (palfile && filesize >= 48 + 48 + 48 + 48)
+{
+ out = (unsigned char *) palette_pantsscoreboard;
+ for (i = 0;i < 16;i++)
+ {
+ *out++ = texturegammaramp[*in++];
+ *out++ = texturegammaramp[*in++];
+ *out++ = texturegammaramp[*in++];
+ *out++ = 255;
+ }
+}
+else
+ memcpy(palette_pantsscoreboard, palette_shirtscoreboard, sizeof(palette_pantsscoreboard));
+
+if(palfile)
+ Mem_Free(palfile);
+
Palette_SetupSpecialPalettes();
}
+void Palette_Init(void)
+{
+ R_RegisterModule("Palette", Palette_Load, Palette_Shutdown, Palette_NewMap);
+ Cvar_RegisterVariable(&r_colormap_palette);
+ Palette_Load();
+}