X-Git-Url: http://de.git.xonotic.org/?p=xonotic%2Fdarkplaces.git;a=blobdiff_plain;f=palette.c;h=d9cafbe455c7fbd4b3f36bf4e113e788e527e0a1;hp=6b4aa922186cc04150160269d18809a5c01f7c8d;hb=7fc7bebd4d2729c358cecb531cc3443da4eee795;hpb=c4ee1bbcc6b2f917465f07269ad09942bbf40849 diff --git a/palette.c b/palette.c index 6b4aa922..d9cafbe4 100644 --- a/palette.c +++ b/palette.c @@ -1,66 +1,110 @@ #include "quakedef.h" -unsigned int d_8to24table[256]; -//qbyte d_15to8table[32768]; -qbyte host_basepal[768]; -qbyte texgamma[256]; - -cvar_t v_gamma = {CVAR_SAVE, "v_gamma", "1"}; -cvar_t v_contrast = {CVAR_SAVE, "v_contrast", "1"}; -cvar_t v_brightness = {CVAR_SAVE, "v_brightness", "0"}; -cvar_t v_overbrightbits = {CVAR_SAVE, "v_overbrightbits", "0"}; -cvar_t v_hwgamma = {0, "v_hwgamma", "1"}; - -void Palette_Setup8to24(void) +unsigned int palette_complete[256]; +unsigned int palette_nofullbrights[256]; +unsigned int palette_onlyfullbrights[256]; +unsigned int palette_nocolormapnofullbrights[256]; +unsigned int palette_nocolormap[256]; +unsigned int palette_pantsaswhite[256]; +unsigned int palette_shirtaswhite[256]; +unsigned int palette_alpha[256]; +unsigned int palette_font[256]; + +// 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. +qbyte host_quakepal[768] = { - qbyte *in, *out; - unsigned short i; - - in = host_basepal; - out = (qbyte *) d_8to24table; // d_8to24table is accessed as 32bit for speed reasons, but is created as 8bit bytes - for (i=0 ; i<255 ; i++) +0,0,0,15,15,15,31,31,31,47,47,47,63,63,63,75,75,75,91,91,91,107,107,107,123,123,123,139,139,139,155,155,155,171,171,171,187,187,187,203,203,203,219,219,219,235,235,235,15,11,7,23,15,11,31,23,11,39,27,15,47,35,19,55,43,23,63,47,23,75,55,27,83,59,27,91,67,31,99,75,31,107,83,31,115,87,31,123,95,35,131,103,35,143,111,35,11,11,15,19,19,27,27,27,39,39,39,51,47,47,63,55,55,75,63,63,87,71,71,103,79,79,115,91,91,127,99,99, +139,107,107,151,115,115,163,123,123,175,131,131,187,139,139,203,0,0,0,7,7,0,11,11,0,19,19,0,27,27,0,35,35,0,43,43,7,47,47,7,55,55,7,63,63,7,71,71,7,75,75,11,83,83,11,91,91,11,99,99,11,107,107,15,7,0,0,15,0,0,23,0,0,31,0,0,39,0,0,47,0,0,55,0,0,63,0,0,71,0,0,79,0,0,87,0,0,95,0,0,103,0,0,111,0,0,119,0,0,127,0,0,19,19,0,27,27,0,35,35,0,47,43,0,55,47,0,67, +55,0,75,59,7,87,67,7,95,71,7,107,75,11,119,83,15,131,87,19,139,91,19,151,95,27,163,99,31,175,103,35,35,19,7,47,23,11,59,31,15,75,35,19,87,43,23,99,47,31,115,55,35,127,59,43,143,67,51,159,79,51,175,99,47,191,119,47,207,143,43,223,171,39,239,203,31,255,243,27,11,7,0,27,19,0,43,35,15,55,43,19,71,51,27,83,55,35,99,63,43,111,71,51,127,83,63,139,95,71,155,107,83,167,123,95,183,135,107,195,147,123,211,163,139,227,179,151, +171,139,163,159,127,151,147,115,135,139,103,123,127,91,111,119,83,99,107,75,87,95,63,75,87,55,67,75,47,55,67,39,47,55,31,35,43,23,27,35,19,19,23,11,11,15,7,7,187,115,159,175,107,143,163,95,131,151,87,119,139,79,107,127,75,95,115,67,83,107,59,75,95,51,63,83,43,55,71,35,43,59,31,35,47,23,27,35,19,19,23,11,11,15,7,7,219,195,187,203,179,167,191,163,155,175,151,139,163,135,123,151,123,111,135,111,95,123,99,83,107,87,71,95,75,59,83,63, +51,67,51,39,55,43,31,39,31,23,27,19,15,15,11,7,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,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,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,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,167,123,59,183,155,55,199,195,55,231,227,87,127,191,255,171,231,255,215,255,255,103,0,0,139,0,0,179,0,0,215,0,0,255,0,0,255,243,147,255,247,199,255,255,255,159,91,83 +}; + +void Palette_SetupSpecialPalettes(void) +{ + int i; + int fullbright_start, fullbright_end; + int pants_start, pants_end; + int shirt_start, shirt_end; + int reversed_start, reversed_end; + qbyte *colormap; + + colormap = FS_LoadFile("gfx/colormap.lmp", tempmempool, true); + if (colormap && fs_filesize >= 16385) + fullbright_start = 256 - colormap[16384]; + else + fullbright_start = 256; + if (colormap) + Mem_Free(colormap); + fullbright_end = 256; + pants_start = 96; + pants_end = 112; + shirt_start = 16; + shirt_end = 32; + reversed_start = 128; + reversed_end = 224; + + for (i = 0;i < fullbright_start;i++) + palette_nofullbrights[i] = palette_complete[i]; + for (i = fullbright_start;i < 255;i++) + palette_nofullbrights[i] = palette_complete[0]; + palette_nofullbrights[255] = 0; + + for (i = 0;i < 256;i++) + palette_onlyfullbrights[i] = palette_complete[0]; + for (i = fullbright_start;i < fullbright_end;i++) + palette_onlyfullbrights[i] = palette_complete[i]; + palette_onlyfullbrights[255] = 0; + + for (i = 0;i < 256;i++) + palette_nocolormapnofullbrights[i] = palette_complete[i]; + for (i = pants_start;i < pants_end;i++) + palette_nocolormapnofullbrights[i] = palette_complete[0]; + for (i = shirt_start;i < shirt_end;i++) + palette_nocolormapnofullbrights[i] = palette_complete[0]; + for (i = fullbright_start;i < fullbright_end;i++) + palette_nocolormapnofullbrights[i] = palette_complete[0]; + palette_nocolormapnofullbrights[255] = 0; + + for (i = 0;i < 256;i++) + palette_nocolormap[i] = palette_complete[i]; + for (i = pants_start;i < pants_end;i++) + palette_nocolormap[i] = palette_complete[0]; + for (i = shirt_start;i < shirt_end;i++) + palette_nocolormap[i] = palette_complete[0]; + palette_nocolormap[255] = 0; + + for (i = 0;i < 256;i++) + palette_pantsaswhite[i] = palette_complete[0]; + for (i = pants_start;i < pants_end;i++) { - *out++ = *in++; - *out++ = *in++; - *out++ = *in++; - *out++ = 255; + if (i >= reversed_start && i < reversed_end) + palette_pantsaswhite[i] = palette_complete[15 - (i - pants_start)]; + else + palette_pantsaswhite[i] = palette_complete[i - pants_start]; } - d_8to24table[255] = 0; // completely transparent black -} -/* -void Palette_Setup15to8(void) -{ - qbyte *pal; - unsigned r,g,b; - unsigned v; - int r1,g1,b1; - int j,k,l; - unsigned short i; - - for (i = 0;i < 32768;i++) + for (i = 0;i < 256;i++) + palette_shirtaswhite[i] = palette_complete[0]; + for (i = shirt_start;i < shirt_end;i++) { - r = ((i & 0x001F) << 3)+4; - g = ((i & 0x03E0) >> 2)+4; - b = ((i & 0x7C00) >> 7)+4; - pal = (unsigned char *)d_8to24table; - for (v = 0, k = 0, l = 1000000000;v < 256;v++, pal += 4) - { - r1 = r - pal[0]; - g1 = g - pal[1]; - b1 = b - pal[2]; - j = r1*r1+g1*g1+b1*b1; - if (j < l) - { - k = v; - l = j; - } - } - d_15to8table[i] = k; + if (i >= reversed_start && i < reversed_end) + palette_shirtaswhite[i] = palette_complete[15 - (i - shirt_start)]; + else + palette_shirtaswhite[i] = palette_complete[i - shirt_start]; } + + for (i = 0;i < 255;i++) + palette_alpha[i] = 0xFFFFFFFF; + palette_alpha[255] = 0; + + palette_font[0] = 0; + for (i = 1;i < 255;i++) + palette_font[i] = palette_complete[i]; + palette_font[255] = 0; } -*/ void BuildGammaTable8(float prescale, float gamma, float scale, float base, qbyte *out) { @@ -116,71 +160,54 @@ void BuildGammaTable16(float prescale, float gamma, float scale, float base, uns } } -qboolean hardwaregammasupported = false; -void VID_UpdateGamma(qboolean force) +void Palette_Init(void) { - static float cachegamma = -1, cachebrightness = -1, cachecontrast = -1; - static int cacheoverbrightbits = -1, cachehwgamma = -1; - - // LordHavoc: don't mess with gamma tables if running dedicated - if (cls.state == ca_dedicated) - return; - - if (!force - && v_gamma.value == cachegamma - && v_contrast.value == cachecontrast - && v_brightness.value == cachebrightness - && v_overbrightbits.integer == cacheoverbrightbits - && v_hwgamma.value == cachehwgamma) - return; - - if (v_gamma.value < 0.1) - Cvar_SetValue("v_gamma", 0.1); - if (v_gamma.value > 5.0) - Cvar_SetValue("v_gamma", 5.0); - - if (v_contrast.value < 0.5) - Cvar_SetValue("v_contrast", 0.5); - if (v_contrast.value > 5.0) - Cvar_SetValue("v_contrast", 5.0); - - if (v_brightness.value < 0) - Cvar_SetValue("v_brightness", 0); - if (v_brightness.value > 0.8) - Cvar_SetValue("v_brightness", 0.8); - - cachegamma = v_gamma.value; - cachecontrast = v_contrast.value; - cachebrightness = v_brightness.value; - cacheoverbrightbits = v_overbrightbits.integer; - - hardwaregammasupported = VID_SetGamma((float) (1 << cacheoverbrightbits), cachegamma, cachecontrast, cachebrightness); - if (!hardwaregammasupported) + int i; + float gamma, scale, base; + qbyte *in, *out, *palfile; + qbyte texturegammaramp[256]; + + gamma = 1; + scale = 1; + base = 0; +// COMMANDLINEOPTION: Client: -texgamma sets the quake palette gamma, allowing you to make quake textures brighter/darker, not recommended + i = COM_CheckParm("-texgamma"); + if (i) + gamma = atof(com_argv[i + 1]); +// COMMANDLINEOPTION: Client: -texcontrast sets the quake palette contrast, allowing you to make quake textures brighter/darker, not recommended + i = COM_CheckParm("-texcontrast"); + if (i) + scale = atof(com_argv[i + 1]); +// COMMANDLINEOPTION: Client: -texbrightness sets the quake palette brightness (brightness of black), allowing you to make quake textures brighter/darker, not recommended + i = COM_CheckParm("-texbrightness"); + if (i) + base = atof(com_argv[i + 1]); + gamma = bound(0.01, gamma, 10.0); + scale = bound(0.01, scale, 10.0); + base = bound(0, base, 0.95); + + BuildGammaTable8(1.0f, gamma, scale, base, texturegammaramp); + + palfile = (qbyte *)FS_LoadFile ("gfx/palette.lmp", tempmempool, false); + if (palfile && fs_filesize >= 768) + in = palfile; + else { - Con_Printf("Hardware gamma not supported.\n"); - Cvar_SetValue("v_hwgamma", 0); + Con_DPrint("Couldn't load gfx/palette.lmp, falling back on internal palette\n"); + in = host_quakepal; } - cachehwgamma = v_hwgamma.integer; -} + out = (qbyte *) palette_complete; // palette is accessed as 32bit for speed reasons, but is created as 8bit bytes + for (i = 0;i < 255;i++) + { + *out++ = texturegammaramp[*in++]; + *out++ = texturegammaramp[*in++]; + *out++ = texturegammaramp[*in++]; + *out++ = 255; + } + palette_complete[255] = 0; // completely transparent black + if (palfile) + Mem_Free(palfile); -void Gamma_Init(void) -{ - Cvar_RegisterVariable(&v_gamma); - Cvar_RegisterVariable(&v_brightness); - Cvar_RegisterVariable(&v_contrast); - Cvar_RegisterVariable(&v_hwgamma); - Cvar_RegisterVariable(&v_overbrightbits); + Palette_SetupSpecialPalettes(); } -void Palette_Init(void) -{ - qbyte *pal; - pal = (qbyte *)COM_LoadFile ("gfx/palette.lmp", false); - if (!pal) - Sys_Error ("Couldn't load gfx/palette.lmp"); - memcpy(host_basepal, pal, 765); - Mem_Free(pal); - host_basepal[765] = host_basepal[766] = host_basepal[767] = 0; // LordHavoc: force the transparent color to black - Palette_Setup8to24(); -// Palette_Setup15to8(); -}