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);
141 void BuildGammaTable16(float prescale, float gamma, float scale, float base, unsigned short *out)
146 gamma = bound(0.1, gamma, 5.0);
147 if (gamma == 1) // LordHavoc: dodge the math
149 for (i = 0;i < 256;i++)
151 adjusted = (int) (i * 256.0 * prescale * scale + base * 65535.0);
152 out[i] = bound(0, adjusted, 65535);
157 invgamma = 1.0 / gamma;
159 for (i = 0;i < 256;i++)
161 d = pow((double) i * prescale, invgamma) * scale + base;
162 adjusted = (int) (65535.0 * d);
163 out[i] = bound(0, adjusted, 65535);
168 void Palette_Init(void)
171 float gamma, scale, base;
174 pal = (qbyte *)FS_LoadFile ("gfx/palette.lmp", false);
176 Sys_Error ("Couldn't load gfx/palette.lmp");
177 memcpy(host_basepal, pal, 765);
179 host_basepal[765] = host_basepal[766] = host_basepal[767] = 0; // LordHavoc: force the transparent color to black
184 i = COM_CheckParm("-texgamma");
186 gamma = atof(com_argv[i + 1]);
187 i = COM_CheckParm("-texcontrast");
189 scale = atof(com_argv[i + 1]);
190 i = COM_CheckParm("-texbrightness");
192 base = atof(com_argv[i + 1]);
193 gamma = bound(0.01, gamma, 10.0);
194 scale = bound(0.01, scale, 10.0);
195 base = bound(0, base, 0.95);
197 BuildGammaTable8(1.0f, gamma, scale, base, temp);
198 for (i = 3;i < 765;i++)
199 host_basepal[i] = temp[host_basepal[i]];
201 Palette_Setup8to24();