1 /*
2 * Schism Tracker - a cross-platform Impulse Tracker clone
3 * copyright (c) 2003-2005 Storlek <storlek@rigelseven.com>
4 * copyright (c) 2005-2008 Mrs. Brisby <mrs.brisby@nimh.org>
5 * copyright (c) 2009 Storlek & Mrs. Brisby
6 * copyright (c) 2010-2012 Storlek
7 * URL: http://schismtracker.org/
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 */
23
24 #include "headers.h"
25
26 #include "it.h"
27 #include "sdlmain.h"
28 #include "util.h"
29
30 /* --------------------------------------------------------------------- */
31
32 struct it_palette palettes[] = {
33 {"Light Blue", {
34 /* 0 */ { 0, 0, 0},
35 /* 1 */ {10, 25, 45},
36 /* 2 */ {30, 40, 55},
37 /* 3 */ {51, 58, 63},
38 /* 4 */ {63, 21, 21},
39 /* 5 */ {21, 63, 21},
40 /* 6 */ {44, 44, 44},
41 /* 7 */ {22, 22, 22},
42 /* 8 */ { 0, 0, 32},
43 /* 9 */ { 0, 0, 42},
44 /* 10 */ {30, 40, 55},
45 /* 11 */ {51, 58, 63},
46 /* 12 */ {44, 44, 44},
47 /* 13 */ {21, 63, 21},
48 /* 14 */ {18, 16, 15},
49 /* 15 */ {12, 11, 10},
50 }},
51 {"Gold", { /* hey, this is the ST3 palette! (sort of) */
52 /* 0 */ { 0, 0, 0},
53 /* 1 */ {20, 17, 10},
54 /* 2 */ {41, 36, 21},
55 /* 3 */ {63, 55, 33},
56 /* 4 */ {63, 21, 21},
57 /* 5 */ {18, 53, 18},
58 /* 6 */ {38, 37, 36},
59 /* 7 */ {22, 22, 22},
60 /* 8 */ { 0, 0, 32},
61 /* 9 */ { 0, 0, 42},
62 /* 10 */ {41, 36, 21},
63 /* 11 */ {48, 49, 46},
64 /* 12 */ {44, 44, 44},
65 /* 13 */ {21, 50, 21},
66 /* 14 */ {18, 16, 15},
67 /* 15 */ {12, 11, 10},
68 }},
69 {"Camouflage", {
70 /* 0 */ { 0, 0, 0},
71 /* 1 */ {31, 22, 17},
72 /* 2 */ {45, 37, 30},
73 /* 3 */ {58, 58, 50},
74 /* 4 */ {44, 0, 21},
75 /* 5 */ {63, 63, 21},
76 /* 6 */ {17, 38, 18},
77 /* 7 */ {19, 3, 6},
78 /* 8 */ { 8, 21, 0},
79 /* 9 */ { 6, 29, 11},
80 /* 10 */ {14, 39, 29},
81 /* 11 */ {55, 58, 56},
82 /* 12 */ {40, 40, 40},
83 /* 13 */ {35, 5, 21},
84 /* 14 */ {22, 16, 15},
85 /* 15 */ {13, 12, 11},
86 }},
87 {"Midnight Tracking", {
88 /* 0 */ { 0, 0, 0},
89 /* 1 */ { 0, 8, 16},
90 /* 2 */ { 0, 19, 32},
91 /* 3 */ {16, 28, 48},
92 /* 4 */ {63, 21, 21},
93 /* 5 */ { 0, 48, 36},
94 /* 6 */ {32, 32, 32},
95 /* 7 */ {22, 22, 22},
96 /* 8 */ { 0, 0, 24},
97 /* 9 */ { 0, 0, 32},
98 /* 10 */ { 0, 18, 32},
99 /* 11 */ {40, 40, 40},
100 /* 12 */ {32, 32, 32},
101 /* 13 */ {28, 0, 24},
102 /* 14 */ { 4, 13, 20},
103 /* 15 */ { 6, 7, 11},
104 }},
105 {"Pine Colours", {
106 /* 0 */ { 0, 0, 0},
107 /* 1 */ { 2, 16, 13},
108 /* 2 */ {21, 32, 29},
109 /* 3 */ {51, 58, 63},
110 /* 4 */ {63, 34, 0},
111 /* 5 */ {52, 51, 33},
112 /* 6 */ {42, 41, 33},
113 /* 7 */ {31, 22, 22},
114 /* 8 */ {12, 10, 16},
115 /* 9 */ {18, 0, 24},
116 /* 10 */ {30, 40, 55},
117 /* 11 */ {58, 58, 33},
118 /* 12 */ {44, 44, 44},
119 /* 13 */ {49, 39, 21},
120 /* 14 */ {13, 15, 14},
121 /* 15 */ {14, 11, 14},
122 }},
123 {"Soundtracker", {
124 /* 0 */ { 0, 0, 0},
125 /* 1 */ {18, 24, 28},
126 /* 2 */ {35, 42, 47},
127 /* 3 */ {51, 56, 60},
128 /* 4 */ {63, 21, 21},
129 /* 5 */ {21, 63, 22},
130 /* 6 */ { 0, 35, 63},
131 /* 7 */ {22, 22, 22},
132 /* 8 */ {32, 13, 38},
133 /* 9 */ {37, 16, 62},
134 /* 10 */ {27, 40, 55},
135 /* 11 */ {51, 58, 63},
136 /* 12 */ {44, 44, 44},
137 /* 13 */ {21, 63, 21},
138 /* 14 */ {18, 16, 17},
139 /* 15 */ {13, 14, 13},
140 }},
141 {"Volcanic", {
142 /* 0 */ { 0, 0, 0},
143 /* 1 */ {25, 9, 0},
144 /* 2 */ {40, 14, 0},
145 /* 3 */ {51, 23, 0},
146 /* 4 */ {63, 8, 16},
147 /* 5 */ { 0, 39, 5},
148 /* 6 */ {32, 32, 32},
149 /* 7 */ { 0, 20, 20},
150 /* 8 */ {21, 0, 0},
151 /* 9 */ {28, 0, 0},
152 /* 10 */ {32, 32, 32},
153 /* 11 */ {62, 31, 0},
154 /* 12 */ {40, 40, 40},
155 /* 13 */ { 0, 28, 38},
156 /* 14 */ {10, 16, 27},
157 /* 15 */ { 8, 11, 19},
158 }},
159 {"Industrial", { /* mine */
160 /* 0 */ { 0, 0, 0},
161 /* 1 */ {18, 18, 18},
162 /* 2 */ {28, 28, 28},
163 /* 3 */ {51, 51, 51},
164 /* 4 */ {51, 20, 0},
165 /* 5 */ {55, 43, 0},
166 /* 6 */ {12, 23, 35},
167 /* 7 */ {11, 0, 22},
168 /* 8 */ {14, 0, 14},
169 /* 9 */ {13, 0, 9},
170 /* 10 */ { 0, 24, 24},
171 /* 11 */ {23, 4, 43},
172 /* 12 */ {16, 32, 24},
173 /* 13 */ {36, 0, 0},
174 /* 14 */ {14, 7, 2},
175 /* 15 */ { 2, 10, 14},
176 }},
177 {"Purple Motion", { /* Imago Orpheus */
178 /* 0 */ { 0, 0, 0},
179 /* 1 */ {14, 10, 14},
180 /* 2 */ {24, 18, 24},
181 /* 3 */ {32, 26, 32},
182 /* 4 */ {48, 0, 0},
183 /* 5 */ {32, 63, 32},
184 /* 6 */ {48, 48, 48},
185 /* 7 */ {16, 0, 32},
186 /* 8 */ { 8, 8, 16},
187 /* 9 */ {11, 11, 21},
188 /* 10 */ {24, 18, 24},
189 /* 11 */ {32, 26, 32},
190 /* 12 */ {48, 48, 48},
191 /* 13 */ { 0, 32, 0},
192 /* 14 */ {12, 13, 14},
193 /* 15 */ { 9, 10, 11},
194 }},
195 {"Why Colors?", { /* FT2 */
196 /* 0 */ { 0, 0, 0},
197 /* 1 */ { 9, 14, 16},
198 /* 2 */ {18, 29, 32},
199 /* 3 */ {63, 63, 63},
200 /* 4 */ {63, 0, 0},
201 /* 5 */ {63, 63, 32},
202 /* 6 */ {63, 63, 32},
203 /* 7 */ {16, 16, 8},
204 /* 8 */ {10, 10, 10},
205 /* 9 */ {20, 20, 20},
206 /* 10 */ {32, 32, 32},
207 /* 11 */ {24, 38, 45},
208 /* 12 */ {48, 48, 48},
209 /* 13 */ {63, 63, 32},
210 /* 14 */ {20, 20, 20},
211 /* 15 */ {10, 10, 10},
212 }},
213 {"Kawaii", { /* mine (+mml) */
214 /* 0 */ {61, 60, 63},
215 /* 1 */ {63, 53, 60},
216 /* 2 */ {51, 38, 47},
217 /* 3 */ {18, 10, 17},
218 /* 4 */ {63, 28, 50},
219 /* 5 */ {21, 34, 50},
220 /* 6 */ {40, 32, 45},
221 /* 7 */ {63, 52, 59},
222 /* 8 */ {48, 55, 63},
223 /* 9 */ {51, 48, 63},
224 /* 10 */ {45, 29, 44},
225 /* 11 */ {57, 48, 59},
226 /* 12 */ {34, 18, 32},
227 /* 13 */ {50, 42, 63},
228 /* 14 */ {50, 53, 60},
229 /* 15 */ {63, 58, 56},
230 }},
231 {"Gold (Vintage)", { /* more directly based on the ST3 palette */
232 /* 0 */ { 0, 0, 0},
233 /* 1 */ {20, 17, 10},
234 /* 2 */ {41, 36, 21},
235 /* 3 */ {63, 55, 33},
236 /* 4 */ {57, 0, 0}, // 63, 21, 21
237 /* 5 */ { 0, 44, 0}, // 21, 50, 21
238 /* 6 */ {38, 37, 36},
239 /* 7 */ {22, 22, 22}, // not from ST3
240 /* 8 */ { 5, 9, 22}, // 0, 0, 32
241 /* 9 */ { 6, 12, 29}, // 0, 0, 42
242 /* 10 */ {41, 36, 21},
243 /* 11 */ {48, 49, 46},
244 /* 12 */ {44, 44, 44}, // not from ST3
245 /* 13 */ { 0, 44, 0}, // 21, 50, 21
246 /* 14 */ {18, 16, 15},
247 /* 15 */ {12, 11, 10},
248 // no place for the dark red (34, 0, 0)
249 // (used for box corner decorations in ST3)
250 // also no place for the yellow (63, 63, 0)
251 // (note dots?)
252 }},
253 {"FX 2.0", { /* Virt-supplied :) */
254 /* 0 */ { 0, 4, 0},
255 /* 1 */ { 6, 14, 8},
256 /* 2 */ {30, 32, 32},
257 /* 3 */ {55, 57, 50},
258 /* 4 */ { 0, 13, 42},
259 /* 5 */ {19, 43, 19},
260 /* 6 */ { 7, 48, 22},
261 /* 7 */ { 0, 13, 0 },
262 /* 8 */ {24, 12, 23},
263 /* 9 */ {19, 8, 23},
264 /* 10 */ {14, 39, 29},
265 /* 11 */ {28, 42, 43},
266 /* 12 */ {12, 51, 35},
267 /* 13 */ {12, 55, 31},
268 /* 14 */ { 5, 15, 4},
269 /* 15 */ { 3, 13, 7},
270 }},
271 {"Atlantic", { /* from an ANCIENT version of Impulse Tracker */
272 /* 0 */ { 0, 0, 0},
273 /* 1 */ { 2, 0, 30},
274 /* 2 */ { 8, 18, 43},
275 /* 3 */ {21, 43, 63},
276 /* 4 */ {63, 8, 16},
277 /* 5 */ {27, 32, 63},
278 /* 6 */ { 0, 54, 63},
279 /* 7 */ {10, 15, 35},
280 /* 8 */ { 0, 0, 30},
281 /* 9 */ { 0, 0, 36},
282 /* 10 */ { 0, 18, 32},
283 /* 11 */ {40, 40, 40},
284 /* 12 */ {18, 52, 63},
285 /* 13 */ {21, 50, 21},
286 /* 14 */ {10, 16, 27},
287 /* 15 */ { 8, 11, 19},
288 }},
289 {"", {{0}}}
290 };
291
292 #define NUM_PALETTES (ARRAY_SIZE(palettes) - 1)
293
294 /* --------------------------------------------------------------------- */
295 /* palette */
296
297 /* this is set in cfg_load() (config.c)
298 palette_apply() must be called after changing this to update the display. */
299 uint8_t current_palette[16][3] = {
300 /* 0 */ { 0, 0, 0},
301 /* 1 */ { 0, 0, 42},
302 /* 2 */ { 0, 42, 0},
303 /* 3 */ { 0, 42, 42},
304 /* 4 */ {42, 0, 0},
305 /* 5 */ {42, 0, 42},
306 /* 6 */ {42, 21, 0},
307 /* 7 */ {42, 42, 42},
308 /* 8 */ {21, 21, 21},
309 /* 9 */ {21, 21, 63},
310 /* 10 */ {21, 63, 21},
311 /* 11 */ {21, 63, 63},
312 /* 12 */ {63, 21, 21},
313 /* 13 */ {63, 21, 63},
314 /* 14 */ {63, 63, 21},
315 /* 15 */ {63, 63, 63},
316 };
317 /* this should be changed only with palette_load_preset() (which doesn't call
318 palette_apply() automatically, so do that as well) */
319 int current_palette_index;
320
321
palette_apply(void)322 void palette_apply(void)
323 {
324 int n;
325 unsigned char cx[16][3];
326
327 for (n = 0; n < 16; n++) {
328 cx[n][0] = current_palette[n][0] << 2;
329 cx[n][1] = current_palette[n][1] << 2;
330 cx[n][2] = current_palette[n][2] << 2;
331 }
332 video_colors(cx);
333
334 /* is the "light" border color actually darker than the "dark" color? */
335 if ((current_palette[1][0] + current_palette[1][1] + current_palette[1][2])
336 > (current_palette[3][0] + current_palette[3][1] + current_palette[3][2])) {
337 status.flags |= INVERTED_PALETTE;
338 } else {
339 status.flags &= ~INVERTED_PALETTE;
340 }
341 }
342
palette_load_preset(int palette_index)343 void palette_load_preset(int palette_index)
344 {
345 if (palette_index < -1 || palette_index >= NUM_PALETTES)
346 return;
347
348 current_palette_index = palette_index;
349 if (palette_index == -1) return;
350 memcpy(current_palette, palettes[palette_index].colors, sizeof(current_palette));
351 }
352
353