4 unsigned int palette_complete[256];
5 unsigned int palette_nofullbrights[256];
6 unsigned int palette_onlyfullbrights[256];
7 unsigned int palette_nocolormapnofullbrights[256];
8 unsigned int palette_nocolormap[256];
9 unsigned int palette_pantsaswhite[256];
10 unsigned int palette_shirtaswhite[256];
11 unsigned int palette_alpha[256];
12 unsigned int palette_font[256];
14 qbyte host_basepal[768];
16 void Palette_Setup8to24(void)
19 int fullbright_start, fullbright_end;
20 int pants_start, pants_end;
21 int shirt_start, shirt_end;
22 int reversed_start, reversed_end;
27 out = (qbyte *) palette_complete; // palette is accessed as 32bit for speed reasons, but is created as 8bit bytes
28 for (i = 0;i < 255;i++)
35 palette_complete[255] = 0; // completely transparent black
37 // FIXME: fullbright_start should be read from colormap.lmp
38 colormap = FS_LoadFile("gfx/colormap.lmp", true);
39 if (colormap && fs_filesize >= 16385)
40 fullbright_start = 256 - colormap[16384];
42 fullbright_start = 256;
53 for (i = 0;i < fullbright_start;i++)
54 palette_nofullbrights[i] = palette_complete[i];
55 for (i = fullbright_start;i < 255;i++)
56 palette_nofullbrights[i] = palette_complete[0];
57 palette_nofullbrights[255] = 0;
59 for (i = 0;i < 256;i++)
60 palette_onlyfullbrights[i] = palette_complete[0];
61 for (i = fullbright_start;i < fullbright_end;i++)
62 palette_onlyfullbrights[i] = palette_complete[i];
63 palette_onlyfullbrights[255] = 0;
65 for (i = 0;i < 256;i++)
66 palette_nocolormapnofullbrights[i] = palette_complete[i];
67 for (i = pants_start;i < pants_end;i++)
68 palette_nocolormapnofullbrights[i] = palette_complete[0];
69 for (i = shirt_start;i < shirt_end;i++)
70 palette_nocolormapnofullbrights[i] = palette_complete[0];
71 for (i = fullbright_start;i < fullbright_end;i++)
72 palette_nocolormapnofullbrights[i] = palette_complete[0];
73 palette_nocolormapnofullbrights[255] = 0;
75 for (i = 0;i < 256;i++)
76 palette_nocolormap[i] = palette_complete[i];
77 for (i = pants_start;i < pants_end;i++)
78 palette_nocolormap[i] = palette_complete[0];
79 for (i = shirt_start;i < shirt_end;i++)
80 palette_nocolormap[i] = palette_complete[0];
81 palette_nocolormap[255] = 0;
83 for (i = 0;i < 256;i++)
84 palette_pantsaswhite[i] = palette_complete[0];
85 for (i = pants_start;i < pants_end;i++)
87 if (i >= reversed_start && i < reversed_end)
88 palette_pantsaswhite[i] = palette_complete[15 - (i - pants_start)];
90 palette_pantsaswhite[i] = palette_complete[i - pants_start];
93 for (i = 0;i < 256;i++)
94 palette_shirtaswhite[i] = palette_complete[0];
95 for (i = shirt_start;i < shirt_end;i++)
97 if (i >= reversed_start && i < reversed_end)
98 palette_shirtaswhite[i] = palette_complete[15 - (i - shirt_start)];
100 palette_shirtaswhite[i] = palette_complete[i - shirt_start];
103 for (i = 0;i < 255;i++)
104 palette_alpha[i] = 0xFFFFFFFF;
105 palette_alpha[255] = 0;
108 for (i = 1;i < 255;i++)
109 palette_font[i] = palette_complete[i];
110 palette_font[255] = 0;
114 void BuildGammaTable8(float prescale, float gamma, float scale, float base, qbyte *out)
119 gamma = bound(0.1, gamma, 5.0);
120 if (gamma == 1) // LordHavoc: dodge the math
122 for (i = 0;i < 256;i++)
124 adjusted = (int) (i * prescale * scale + base * 255.0);
125 out[i] = bound(0, adjusted, 255);
130 invgamma = 1.0 / gamma;
132 for (i = 0;i < 256;i++)
134 d = pow((double) i * prescale, invgamma) * scale + base;
135 adjusted = (int) (255.0 * d);
136 out[i] = bound(0, adjusted, 255);
142 void BuildGammaTable16(float prescale, float gamma, float scale, float base, unsigned short *out)
147 gamma = bound(0.1, gamma, 5.0);
148 if (gamma == 1) // LordHavoc: dodge the math
150 for (i = 0;i < 256;i++)
152 adjusted = (int) (i * 256.0 * prescale * scale + base * 65535.0);
153 out[i] = bound(0, adjusted, 65535);
158 invgamma = 1.0 / gamma;
160 for (i = 0;i < 256;i++)
162 d = pow((double) i * prescale, invgamma) * scale + base;
163 adjusted = (int) (65535.0 * d);
164 out[i] = bound(0, adjusted, 65535);
169 void Palette_Init(void)
172 float gamma, scale, base;
175 pal = (qbyte *)FS_LoadFile ("gfx/palette.lmp", false);
177 Sys_Error ("Couldn't load gfx/palette.lmp");
178 memcpy(host_basepal, pal, 765);
180 host_basepal[765] = host_basepal[766] = host_basepal[767] = 0; // LordHavoc: force the transparent color to black
185 i = COM_CheckParm("-texgamma");
187 gamma = atof(com_argv[i + 1]);
188 i = COM_CheckParm("-texcontrast");
190 scale = atof(com_argv[i + 1]);
191 i = COM_CheckParm("-texbrightness");
193 base = atof(com_argv[i + 1]);
194 gamma = bound(0.01, gamma, 10.0);
195 scale = bound(0.01, scale, 10.0);
196 base = bound(0, base, 0.95);
198 BuildGammaTable8(1.0f, gamma, scale, base, temp);
199 for (i = 3;i < 765;i++)
200 host_basepal[i] = temp[host_basepal[i]];
202 Palette_Setup8to24();