added support for BD game engine to Makefile for Android
[rocksndiamonds.git] / src / game_bd / bd_colors.c
1 /*
2  * Copyright (c) 2007, 2008, 2009, Czirkos Zoltan <cirix@fw.hu>
3  *
4  * Permission to use, copy, modify, and distribute this software for any
5  * purpose with or without fee is hereby granted, provided that the above
6  * copyright notice and this permission notice appear in all copies.
7  *
8  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15  */
16
17 #include "main_bd.h"
18
19
20 static char *c64_color_names[] =
21 {
22   "Black",  "White", "Red",      "Cyan",  "Purple", "Green",      "Blue",      "Yellow",
23   "Orange", "Brown", "LightRed", "Gray1", "Gray2",  "LightGreen", "LightBlue", "Gray3",
24 };
25
26 static unsigned int c64_colors_vice_old[] =
27 {
28   0x000000, 0xFFFFFF, 0x68372b, 0x70a4b2, 0x6f3d86, 0x588d43, 0x352879, 0xb8c76f,
29   0x6f4f25, 0x433900, 0x9a6759, 0x444444, 0x6c6c6c, 0x9ad284, 0x6c5eb5, 0x959595,
30 };
31
32 static unsigned int c64_colors_vice_new[] =
33 {
34   0x000000, 0xffffff, 0x894036, 0x7abfc7, 0x8a46ae, 0x68a941, 0x3e31a2, 0xd0dc71,
35   0x905f25, 0x5c4700, 0xbb776d, 0x555555, 0x808080, 0xacea88, 0x7c70da, 0xababab,
36 };
37
38 static unsigned int c64_colors_c64_hq[] =
39 {
40   0x0A0A0A, 0xFFF8FF, 0x851F02, 0x65CDA8, 0xA73B9F, 0x4DAB19, 0x1A0C92, 0xEBE353,
41   0xA94B02, 0x441E00, 0xD28074, 0x464646, 0x8B8B8B, 0x8EF68E, 0x4D91D1, 0xBABABA,
42 };
43
44 static unsigned int c64_colors_c64s[] =
45 {
46   0x000000, 0xFCFCFC, 0xA80000, 0x54FCFC, 0xA800A8, 0x00A800, 0x0000A8, 0xFCFC00,
47   0xA85400, 0x802C00, 0xFC5454, 0x545454, 0x808080, 0x54FC54, 0x5454FC, 0xA8A8A8,
48 };
49
50 static unsigned int c64_colors_ccs64[] =
51 {
52   0x101010, 0xFFFFFF, 0xE04040, 0x60FFFF, 0xE060E0, 0x40E040, 0x4040E0, 0xFFFF40,
53   0xE0A040, 0x9C7448, 0xFFA0A0, 0x545454, 0x888888, 0xA0FFA0, 0xA0A0FF, 0xC0C0C0,
54 };
55
56 static unsigned int c64_colors_vice_default[] =
57 {
58   0x000000, 0xFDFEFC, 0xBE1A24, 0x30E6C6, 0xB41AE2, 0x1FD21E, 0x211BAE, 0xDFF60A,
59   0xB84104, 0x6A3304, 0xFE4A57, 0x424540, 0x70746F, 0x59FE59, 0x5F53FE, 0xA4A7A2,
60 };
61
62 static unsigned int c64_colors_frodo[] =
63 {
64   0x000000, 0xFFFFFF, 0xCC0000, 0x00FFCC, 0xFF00FF, 0x00CC00, 0x0000CC, 0xFFFF00,
65   0xFF8800, 0x884400, 0xFF8888, 0x444444, 0x888888, 0x88FF88, 0x8888FF, 0xCCCCCC,
66 };
67
68 static unsigned int c64_colors_godot[] =
69 {
70   0x000000, 0xFFFFFF, 0x880000, 0xAAFFEE, 0xCC44CC, 0x00CC55, 0x0000AA, 0xEEEE77,
71   0xDD8855, 0x664400, 0xFE7777, 0x333333, 0x777777, 0xAAFF66, 0x0088FF, 0xBBBBBB,
72 };
73
74 static unsigned int c64_colors_pc64[] =
75 {
76   0x212121, 0xFFFFFF, 0xB52121, 0x73FFFF, 0xB521B5, 0x21B521, 0x2121B5, 0xFFFF21,
77   0xB57321, 0x944221, 0xFF7373, 0x737373, 0x949494, 0x73FF73, 0x7373FF, 0xB5B5B5,
78 };
79
80 static unsigned int c64_colors_rtadash[]={
81   0x000000, 0xffffff, 0xea3418, 0x58ffff, 0xd82cff, 0x55fb00, 0x4925ff, 0xffff09,
82   0xe66c00, 0x935f00, 0xff7c64, 0x6c6c6c, 0xa1a1a1, 0xafff4d, 0x9778ff, 0xd8d8d8,
83 };
84
85 // pointer array positions must match palette numbers in header file
86 static unsigned int *c64_palettes_pointers[] =
87 {
88     c64_colors_vice_new,
89     c64_colors_vice_old,
90     c64_colors_vice_default,
91     c64_colors_c64_hq,
92     c64_colors_c64s,
93     c64_colors_ccs64,
94     c64_colors_frodo,
95     c64_colors_godot,
96     c64_colors_pc64,
97     c64_colors_rtadash,
98
99     NULL
100 };
101
102 static byte BuiltIn[] =
103 {
104   0,0,0,16,16,16,32,32,32,48,48,48,64,64,64,80,80,80,96,96,96,112,112,112,
105   128,128,128,144,144,144,160,160,160,176,176,176,192,192,192,208,208,208,
106   224,224,224,240,240,240,56,0,0,72,16,0,88,32,0,104,48,0,120,64,0,136,80,
107   0,152,96,0,168,112,0,184,128,0,200,144,0,216,160,12,232,176,28,248,192,
108   44,255,208,60,255,224,76,255,240,92,63,0,0,79,2,0,95,18,0,111,34,0,127,
109   50,0,143,66,0,159,82,3,175,98,19,191,114,35,207,130,51,223,146,67,239,162,
110   83,255,178,99,255,194,115,255,210,131,255,226,147,58,0,0,74,0,0,90,6,12,
111   106,22,28,122,38,44,138,54,60,154,70,76,170,86,92,186,102,108,202,118,124,
112   218,134,140,234,150,156,250,166,172,255,182,188,255,198,204,255,214,220,
113   42,0,56,58,0,72,74,1,88,90,17,104,106,33,120,122,49,136,138,65,152,154,
114   81,168,170,97,184,186,113,200,202,129,216,218,145,232,234,161,248,250,177,
115   255,255,193,255,255,209,255,17,0,122,33,0,138,49,1,154,65,17,170,81,33,
116   186,97,49,202,113,65,218,129,81,234,145,97,250,161,113,255,177,129,255,
117   193,145,255,209,161,255,225,177,255,241,193,255,255,209,255,0,0,164,5,0,
118   180,21,8,196,37,24,212,53,40,228,69,56,244,85,72,255,101,88,255,117,104,
119   255,133,120,255,149,136,255,165,152,255,181,168,255,197,184,255,213,200,
120   255,229,216,255,0,0,173,0,3,189,0,19,205,11,35,221,27,51,237,43,67,253,
121   59,83,255,75,99,255,91,115,255,107,131,255,123,147,255,139,163,255,155,
122   179,255,171,195,255,187,211,255,203,227,255,0,0,148,0,16,164,0,32,180,0,
123   48,196,8,64,212,24,80,228,40,96,244,56,112,255,72,128,255,88,144,255,104,
124   160,255,120,176,255,136,192,255,152,208,255,168,224,255,184,240,255,0,14,
125   93,0,30,109,0,46,125,0,62,141,1,78,157,17,94,173,33,110,189,49,126,205,
126   65,142,221,81,158,237,97,174,253,113,190,255,129,206,255,145,222,255,161,
127   238,255,177,254,255,0,26,20,0,42,36,0,58,52,0,74,68,6,90,84,22,106,100,
128   38,122,116,54,138,132,70,154,148,86,170,164,102,186,180,118,202,196,134,
129   218,212,150,234,228,166,250,244,182,255,255,0,31,0,0,47,0,0,63,0,6,79,0,
130   22,95,8,38,111,24,54,127,40,70,143,56,86,159,72,102,175,88,118,191,104,
131   134,207,120,150,223,136,166,239,152,182,255,168,198,255,184,0,31,0,0,47,
132   0,15,63,0,31,79,0,47,95,0,63,111,0,79,127,0,95,143,0,111,159,6,127,175,
133   22,143,191,38,159,207,54,175,223,70,191,239,86,207,255,102,223,255,118,
134   11,24,0,27,40,0,43,56,0,59,72,0,75,88,0,91,104,0,107,120,0,123,136,0,139,
135   152,0,155,168,0,171,184,0,187,200,12,203,216,28,219,232,44,235,248,60,251,
136   255,76,37,13,0,53,29,0,69,45,0,85,61,0,101,77,0,117,93,0,133,109,0,149,
137   125,0,165,141,0,181,157,0,197,173,0,213,189,3,229,205,19,245,221,35,255,
138   237,51,255,253,67,56,0,0,72,16,0,88,32,0,104,48,0,120,64,0,136,80,0,152,
139   96,0,168,112,0,184,128,0,200,144,0,216,160,12,232,176,28,248,192,44,255,
140   208,60,255,224,76,255,240,92
141 };
142
143 static byte BuiltIn_contrast[] =
144 {
145   0,0,0,17,17,17,34,34,34,51,51,51,68,68,68,85,85,85,102,102,102,119,119,
146   119,136,136,136,153,153,153,170,170,170,187,187,187,204,204,204,221,221,
147   221,238,238,238,255,255,255,59,0,0,76,16,0,93,33,0,110,50,0,127,67,0,144,
148   84,0,161,101,0,178,118,0,195,135,0,212,152,0,229,169,13,246,186,30,255,
149   203,47,255,220,64,255,237,81,255,254,98,67,0,0,84,2,0,101,19,0,118,36,0,
150   135,53,0,152,70,0,169,87,3,186,104,20,203,121,37,220,138,54,237,155,71,
151   254,172,88,255,189,105,255,206,122,255,223,139,255,240,156,62,0,0,79,0,
152   0,96,7,12,113,24,29,130,41,46,147,58,63,164,75,80,181,92,97,198,109,114,
153   215,126,131,232,143,148,249,160,165,255,177,182,255,194,199,255,211,216,
154   255,228,233,44,0,59,61,0,76,78,1,93,95,18,110,112,35,127,129,52,144,146,
155   69,161,163,86,178,180,103,195,197,120,212,214,137,229,231,154,246,248,171,
156   255,255,188,255,255,205,255,255,222,255,18,0,130,35,0,147,52,1,164,69,18,
157   181,86,35,198,103,52,215,120,69,232,137,86,249,154,103,255,171,120,255,
158   188,137,255,205,154,255,222,171,255,239,188,255,255,205,255,255,222,255,
159   0,0,174,5,0,191,22,8,208,39,25,225,56,42,242,73,59,255,90,76,255,107,93,
160   255,124,110,255,141,127,255,158,144,255,175,161,255,192,178,255,209,195,
161   255,226,212,255,243,229,255,0,0,184,0,3,201,0,20,218,12,37,235,29,54,252,
162   46,71,255,63,88,255,80,105,255,97,122,255,114,139,255,131,156,255,148,173,
163   255,165,190,255,182,207,255,199,224,255,216,241,255,0,1,157,0,18,174,0,
164   35,191,0,52,208,9,69,225,26,86,242,43,103,255,60,120,255,77,137,255,94,
165   154,255,111,171,255,128,188,255,145,205,255,162,222,255,179,239,255,196,
166   255,255,0,15,99,0,32,116,0,49,133,0,66,150,1,83,167,18,100,184,35,117,201,
167   52,134,218,69,151,235,86,168,252,103,185,255,120,202,255,137,219,255,154,
168   236,255,171,253,255,188,255,255,0,27,22,0,44,39,0,61,56,0,78,73,6,95,90,
169   23,112,107,40,129,124,57,146,141,74,163,158,91,180,175,108,197,192,125,
170   214,209,142,231,226,159,248,243,176,255,255,193,255,255,0,33,0,0,50,0,0,
171   67,0,7,84,0,24,101,9,41,118,26,58,135,43,75,152,60,92,169,77,109,186,94,
172   126,203,111,143,220,128,160,237,145,177,254,162,194,255,179,211,255,196,
173   0,33,0,0,50,0,16,67,0,33,84,0,50,101,0,67,118,0,84,135,0,101,152,0,118,
174   169,6,135,186,23,152,203,40,169,220,57,186,237,74,203,254,91,220,255,108,
175   237,255,125,12,26,0,29,43,0,46,60,0,63,77,0,80,94,0,97,111,0,114,128,0,
176   131,145,0,148,162,0,165,179,0,182,196,0,199,213,13,216,230,30,233,247,47,
177   250,255,64,255,255,81,39,14,0,56,31,0,73,48,0,90,65,0,107,82,0,124,99,0,
178   141,116,0,158,133,0,175,150,0,192,167,0,209,184,0,226,201,3,243,218,20,
179   255,235,37,255,252,54,255,255,71,59,0,0,76,16,0,93,33,0,110,50,0,127,67,
180   0,144,84,0,161,101,0,178,118,0,195,135,0,212,152,0,229,169,13,246,186,30,
181   255,203,47,255,220,64,255,237,81,255,254,98
182 };
183
184 static byte Default[] =
185 {
186   0,0,0,28,28,28,57,57,57,89,89,89,121,121,121,146,146,146,171,171,171,188,
187   188,188,205,205,205,217,217,217,230,230,230,236,236,236,242,242,242,248,
188   248,248,255,255,255,255,255,255,57,23,1,94,35,4,131,48,8,165,71,22,200,
189   95,36,227,120,32,255,145,29,255,171,29,255,197,29,255,206,52,255,216,76,
190   255,230,81,255,244,86,255,249,119,255,255,152,255,255,152,69,25,4,114,30,
191   17,159,36,30,179,58,32,200,81,34,227,105,32,255,129,30,255,140,37,255,152,
192   44,255,174,56,255,197,69,255,197,89,255,198,109,255,213,135,255,228,161,
193   255,228,161,74,23,4,126,26,13,178,29,23,200,33,25,223,37,28,236,59,56,250,
194   82,85,252,97,97,255,112,110,255,127,126,255,143,143,255,157,158,255,171,
195   173,255,185,189,255,199,206,255,199,206,5,5,104,59,19,109,113,34,114,139,
196   42,140,165,50,166,185,56,186,205,62,207,219,71,221,234,81,235,244,95,245,
197   254,109,255,254,122,253,255,135,251,255,149,253,255,164,255,255,164,255,
198   40,4,121,64,9,132,89,15,144,112,36,157,136,57,170,164,65,195,192,74,220,
199   208,84,237,224,94,255,233,109,255,242,124,255,248,138,255,255,152,255,254,
200   161,255,254,171,255,254,171,255,53,8,138,66,10,173,80,12,208,100,40,208,
201   121,69,208,141,75,212,162,81,217,176,88,236,190,96,255,197,107,255,204,
202   119,255,209,131,255,215,144,255,219,157,255,223,170,255,223,170,255,5,30,
203   129,6,38,165,8,47,202,38,61,212,68,76,222,79,90,238,90,104,255,101,117,
204   255,113,131,255,128,145,255,144,160,255,151,169,255,159,178,255,175,190,
205   255,192,203,255,192,203,255,12,4,139,34,24,160,56,45,181,72,62,199,88,79,
206   218,97,89,236,107,100,255,122,116,255,138,132,255,145,142,255,153,152,255,
207   165,163,255,177,174,255,184,184,255,192,194,255,192,194,255,29,41,90,29,
208   56,118,29,72,146,28,92,172,28,113,198,50,134,207,72,155,217,78,168,236,
209   85,182,255,112,199,255,140,216,255,147,219,255,155,223,255,175,228,255,
210   195,233,255,195,233,255,47,67,2,57,82,2,68,97,3,65,122,18,62,148,33,74,
211   159,46,87,171,59,92,189,85,97,208,112,105,226,122,114,245,132,124,250,141,
212   135,255,151,154,255,166,173,255,182,173,255,182,10,65,8,13,84,10,16,104,
213   13,19,125,15,22,146,18,25,165,20,28,185,23,30,201,25,33,217,27,71,228,45,
214   110,240,64,120,247,77,131,255,91,154,255,122,178,255,154,178,255,154,4,
215   65,11,5,83,14,6,102,17,7,119,20,8,136,23,9,155,26,11,175,29,72,196,31,134,
216   217,34,143,233,36,153,249,39,168,252,65,183,255,91,201,255,110,220,255,
217   129,220,255,129,2,53,15,7,63,21,12,74,28,45,95,30,79,116,32,89,131,36,100,
218   146,40,130,161,46,161,176,52,169,193,58,178,210,65,196,217,69,214,225,73,
219   228,240,78,242,255,83,242,255,83,38,48,1,36,56,3,35,64,5,81,84,27,128,105,
220   49,151,129,53,175,153,58,194,167,62,213,181,67,219,192,61,225,203,56,226,
221   216,54,227,229,52,239,242,88,251,255,125,251,255,125,64,26,2,88,31,5,112,
222   36,8,141,58,19,171,81,31,181,100,39,191,119,48,208,133,58,225,147,68,237,
223   160,78,249,173,88,252,183,92,255,193,96,255,198,113,255,203,131,255,203,
224   131
225 };
226
227 static byte Jakub[] =
228 {
229   45,45,45,59,59,59,73,73,73,87,87,87,101,101,101,115,115,115,129,129,129,
230   143,143,143,157,157,157,171,171,171,185,185,185,199,199,199,213,213,213,
231   227,227,227,241,241,241,255,255,255,92,35,0,106,49,0,120,63,0,134,77,10,
232   148,91,24,162,105,38,176,119,52,190,133,66,204,147,80,218,161,94,232,175,
233   108,246,189,122,255,203,136,255,217,150,255,231,164,255,245,178,105,20,
234   9,119,34,23,133,48,37,147,62,51,161,76,65,175,90,79,189,104,93,203,118,
235   107,217,132,121,231,146,135,245,160,149,255,174,163,255,188,177,255,202,
236   191,255,216,205,255,230,219,108,10,56,122,24,70,136,38,84,150,52,98,164,
237   66,112,178,80,126,192,94,140,206,108,154,220,122,168,234,136,182,248,150,
238   196,255,164,210,255,178,224,255,192,238,255,206,252,255,220,255,100,5,101,
239   114,19,115,128,33,129,142,47,143,156,61,157,170,75,171,184,89,185,198,103,
240   199,212,117,213,226,131,227,240,145,241,254,159,255,255,173,255,255,187,
241   255,255,201,255,255,215,255,82,7,137,96,21,151,110,35,165,124,49,179,138,
242   63,193,152,77,207,166,91,221,180,105,235,194,119,249,208,133,255,222,147,
243   255,236,161,255,250,175,255,255,189,255,255,203,255,255,217,255,58,16,156,
244   72,30,170,86,44,184,100,58,198,114,72,212,128,86,226,142,100,240,156,114,
245   254,170,128,255,184,142,255,198,156,255,212,170,255,226,184,255,240,198,
246   255,254,212,255,255,226,255,31,30,156,45,44,170,59,58,184,73,72,198,87,
247   86,212,101,100,226,115,114,240,129,128,254,143,142,255,157,156,255,171,
248   170,255,185,184,255,199,198,255,213,212,255,227,226,255,241,240,255,7,46,
249   137,21,60,151,35,74,165,49,88,179,63,102,193,77,116,207,91,130,221,105,
250   144,235,119,158,249,133,172,255,147,186,255,161,200,255,175,214,255,189,
251   228,255,203,242,255,217,255,255,0,62,101,3,76,115,17,90,129,31,104,143,
252   45,118,157,59,132,171,73,146,185,87,160,199,101,174,213,115,188,227,129,
253   202,241,143,216,255,157,230,255,171,244,255,185,255,255,199,255,255,0,75,
254   56,0,89,70,9,103,84,23,117,98,37,131,112,51,145,126,65,159,140,79,173,154,
255   93,187,168,107,201,182,121,215,196,135,229,210,149,243,224,163,255,238,
256   177,255,252,191,255,255,0,82,9,0,96,23,12,110,37,26,124,51,40,138,65,54,
257   152,79,68,166,93,82,180,107,96,194,121,110,208,135,124,222,149,138,236,
258   163,152,250,177,166,255,191,180,255,205,194,255,219,0,83,0,11,97,0,25,111,
259   0,39,125,10,53,139,24,67,153,38,81,167,52,95,181,66,109,195,80,123,209,
260   94,137,223,108,151,237,122,165,251,136,179,255,150,193,255,164,207,255,
261   178,19,78,0,33,92,0,47,106,0,61,120,0,75,134,0,89,148,11,103,162,25,117,
262   176,39,131,190,53,145,204,67,159,218,81,173,232,95,187,246,109,201,255,
263   123,215,255,137,229,255,151,45,67,0,59,81,0,73,95,0,87,109,0,101,123,0,
264   115,137,1,129,151,15,143,165,29,157,179,43,171,193,57,185,207,71,199,221,
265   85,213,235,99,227,249,113,241,255,127,255,255,141,70,51,0,84,65,0,98,79,
266   0,112,93,0,126,107,0,140,121,11,154,135,25,168,149,39,182,163,53,196,177,
267   67,210,191,81,224,205,95,238,219,109,252,233,123,255,247,137,255,255,151
268 };
269
270 static byte Jakub_contrast[] =
271 {
272   0,0,0,17,17,17,34,34,34,50,50,50,67,67,67,85,85,85,101,101,101,118,118,
273   118,136,136,136,153,153,153,170,170,170,186,186,186,203,203,203,220,220,
274   220,237,237,237,254,254,254,57,0,0,74,4,0,91,21,0,108,38,0,125,55,0,142,
275   72,0,159,89,8,176,106,25,193,123,42,210,140,59,227,157,76,244,174,93,254,
276   191,110,255,208,127,255,225,144,254,242,161,72,0,0,89,0,0,106,3,0,123,20,
277   7,140,37,24,157,54,41,174,71,58,191,88,75,208,105,92,225,122,109,242,139,
278   126,255,156,143,255,173,160,255,190,177,254,207,194,254,224,211,76,0,13,
279   93,0,30,110,0,47,127,8,64,144,25,81,161,42,98,178,59,115,195,76,132,212,
280   93,149,229,110,166,246,127,183,254,144,200,254,161,217,255,178,234,255,
281   195,251,255,212,255,66,0,68,83,0,85,100,0,102,117,2,119,134,19,136,151,
282   36,153,168,53,170,185,70,187,202,87,204,219,104,221,236,121,238,253,138,
283   255,254,155,254,255,172,255,254,189,254,254,206,254,44,0,111,61,0,128,78,
284   0,145,95,4,162,112,21,179,129,38,196,146,55,213,163,72,230,180,89,247,197,
285   106,254,214,123,255,231,140,255,248,157,254,255,174,255,254,191,254,254,
286   208,254,15,0,134,32,0,151,49,0,168,66,15,185,83,32,202,100,49,219,117,66,
287   236,134,83,253,151,100,255,168,117,254,185,134,254,202,151,255,219,168,
288   254,236,185,255,253,202,254,255,219,255,0,0,134,0,0,151,16,15,168,33,32,
289   185,50,49,202,68,66,219,85,83,236,102,100,253,119,117,255,135,134,254,152,
290   151,254,170,168,255,186,185,254,204,202,255,220,219,254,237,236,254,0,1,
291   111,0,18,128,0,35,145,4,52,162,21,69,179,38,86,196,55,103,213,72,120,230,
292   89,137,247,106,154,255,123,171,255,140,188,254,157,205,255,174,222,254,
293   191,239,255,208,255,255,0,20,67,0,37,85,0,54,101,0,71,118,0,88,136,17,105,
294   153,34,122,170,50,139,186,67,156,203,84,173,220,101,190,237,118,207,254,
295   136,224,255,153,241,254,169,254,254,187,254,254,0,36,13,0,53,30,0,70,47,
296   0,87,64,0,104,81,7,121,98,24,138,115,41,155,132,58,172,149,75,189,166,92,
297   206,183,109,223,200,126,240,217,143,254,234,160,255,251,177,254,254,0,44,
298   0,0,61,0,0,78,0,0,95,7,0,112,24,10,129,41,27,146,58,44,163,75,61,180,92,
299   78,197,109,95,214,126,112,231,143,129,248,160,146,254,177,163,254,194,180,
300   255,211,0,46,0,0,63,0,0,80,0,0,97,0,9,114,0,26,131,0,43,148,8,60,165,25,
301   77,182,42,94,199,59,111,216,76,128,233,93,145,250,110,162,255,127,179,254,
302   144,196,254,161,0,40,0,0,57,0,2,74,0,19,91,0,36,108,0,53,125,0,70,142,0,
303   87,159,0,104,176,9,121,193,26,138,210,43,155,227,60,172,244,77,189,254,
304   94,206,254,111,223,255,128,0,26,0,16,43,0,34,60,0,50,77,0,67,94,0,84,111,
305   0,101,128,0,118,145,0,135,162,0,152,179,14,169,196,31,186,213,48,204,230,
306   65,220,247,82,237,254,99,255,255,116,30,7,0,47,24,0,64,41,0,81,58,0,98,
307   75,0,115,92,0,132,109,0,149,126,0,166,143,9,183,160,26,200,177,43,217,194,
308   60,234,211,77,251,228,94,254,245,111,255,255,128
309 };
310
311 static byte Real[] =
312 {
313   50,49,50,63,62,63,77,76,77,91,91,91,106,105,106,121,120,121,136,135,136,
314   151,151,151,161,160,161,175,175,175,190,190,190,206,205,206,219,219,219,
315   235,234,235,250,250,250,255,255,255,97,46,0,108,59,0,122,74,0,136,88,0,
316   148,103,12,165,118,27,178,132,42,193,148,58,202,157,67,218,173,83,232,187,
317   98,248,203,114,255,216,127,255,232,143,255,247,159,255,255,174,108,36,0,
318   119,48,0,132,64,3,146,78,17,158,93,34,175,108,49,188,123,65,204,138,80,
319   213,147,91,228,163,105,242,177,121,255,194,137,255,207,151,255,223,166,
320   255,237,181,255,253,196,117,22,24,129,35,36,143,49,52,157,64,67,170,78,
321   80,184,94,96,198,109,111,213,125,127,222,135,135,237,149,150,252,164,165,
322   255,180,181,255,194,196,255,209,211,255,224,225,255,239,240,98,14,113,110,
323   27,124,123,42,138,138,57,152,150,71,165,165,87,181,179,101,195,195,117,
324   209,205,126,218,220,141,233,234,151,247,249,172,255,255,186,255,255,201,
325   255,255,217,255,255,232,255,86,15,135,97,29,144,113,44,158,127,58,172,141,
326   72,186,155,88,199,169,103,213,184,119,229,194,128,237,208,144,252,223,159,
327   255,238,175,255,252,189,255,255,204,255,255,219,255,255,234,255,70,22,149,
328   81,34,160,96,50,172,110,65,187,124,79,200,138,94,214,153,109,227,168,124,
329   242,177,133,251,192,149,255,207,163,255,223,179,255,238,193,255,252,208,
330   255,255,223,255,255,239,255,33,41,148,45,53,159,61,68,173,75,83,186,89,
331   97,199,104,111,213,119,126,226,135,142,242,144,151,250,150,166,255,174,
332   181,255,191,196,255,205,210,255,218,227,255,234,241,255,250,254,255,15,
333   53,132,28,65,141,44,80,155,58,94,170,72,108,183,88,123,197,103,138,210,
334   118,153,226,128,162,235,143,178,249,158,192,255,173,208,255,189,221,255,
335   203,236,255,219,252,255,234,255,255,4,63,112,17,75,121,33,89,136,47,104,
336   150,62,117,164,77,131,178,92,146,193,108,161,210,116,171,217,131,186,231,
337   147,201,246,162,216,255,177,230,255,192,245,255,208,255,255,222,255,255,
338   0,89,24,0,101,38,15,114,53,29,129,68,44,142,80,59,157,96,74,172,111,89,
339   187,126,99,196,135,114,211,150,130,226,165,146,241,181,159,254,195,174,
340   255,210,190,255,226,206,255,241,7,92,0,20,104,0,34,117,0,50,131,0,63,145,
341   11,79,160,27,94,174,42,110,189,59,119,198,68,135,213,83,150,227,99,167,
342   243,115,179,254,128,195,255,143,211,255,160,227,255,176,26,86,0,40,98,0,
343   54,112,0,69,126,0,83,140,0,98,155,7,112,169,22,128,185,38,137,194,47,153,
344   209,62,168,223,77,183,239,92,197,252,107,213,255,123,227,255,139,243,255,
345   153,51,75,0,64,87,0,77,101,0,93,115,0,106,130,0,122,145,0,136,158,15,152,
346   174,31,161,183,40,186,198,56,191,213,72,206,228,88,220,242,102,235,255,
347   117,250,255,133,255,255,149,75,60,0,88,73,0,101,87,0,116,101,0,129,116,
348   0,144,131,7,159,145,22,174,161,38,183,170,46,199,186,62,213,199,77,229,
349   215,93,242,229,107,254,244,122,255,255,139,255,255,154,96,46,0,109,58,0,
350   122,73,0,137,88,0,149,103,10,164,118,27,178,131,42,194,148,58,203,157,68,
351   218,172,83,232,186,98,248,203,115,255,215,127,255,231,145,255,246,159,255,
352   255,175
353 };
354
355 static byte Real_contrast[] =
356 {
357   0,0,0,16,15,16,34,32,34,51,51,51,70,68,70,88,87,88,107,106,107,126,126,
358   126,138,137,138,155,155,155,174,174,174,194,192,194,210,210,210,230,228,
359   230,248,248,248,255,255,255,59,0,0,72,11,0,90,30,0,107,47,0,122,66,0,143,
360   85,0,159,102,0,178,122,10,189,133,21,209,153,41,226,170,60,246,190,80,255,
361   206,96,255,226,116,255,245,135,255,255,154,72,0,0,86,0,0,102,18,0,119,35,
362   0,134,54,0,155,72,0,171,91,19,191,109,37,202,121,51,221,140,68,238,158,
363   88,255,179,108,255,195,126,255,215,144,255,232,163,255,252,181,83,0,0,98,
364   0,0,116,0,3,133,18,21,149,35,37,166,55,57,184,73,76,202,93,96,214,106,106,
365   232,123,124,251,142,143,255,161,163,255,179,181,255,197,200,255,216,217,
366   255,235,236,60,0,78,75,0,92,91,0,109,109,9,127,124,26,143,143,46,163,160,
367   63,180,180,83,197,192,94,209,211,113,227,228,126,245,247,152,255,255,169,
368   255,255,188,255,255,207,255,255,226,255,45,0,106,59,0,117,78,0,134,96,10,
369   152,113,28,169,130,47,185,148,66,202,166,86,222,179,97,232,196,117,251,
370   215,135,255,233,155,255,251,173,255,255,191,255,255,210,255,255,228,255,
371   25,0,123,39,0,137,57,0,152,75,19,170,92,36,186,109,55,204,128,73,220,147,
372   92,238,158,103,250,176,123,255,195,140,255,215,160,255,233,178,255,251,
373   196,255,255,215,255,255,235,255,0,0,122,0,4,135,14,23,153,31,41,169,49,
374   59,185,67,76,202,86,94,219,106,114,238,117,126,248,124,144,255,154,163,
375   255,175,181,255,192,199,255,209,220,255,228,237,255,248,253,255,0,4,102,
376   0,19,113,0,37,130,10,55,149,28,72,165,47,91,183,66,109,199,85,128,219,97,
377   139,230,116,159,247,134,176,255,153,196,255,173,212,255,190,231,255,210,
378   251,255,228,255,255,0,16,77,0,31,88,0,49,107,0,67,124,15,83,142,34,101,
379   159,52,119,178,72,138,199,82,150,207,101,169,225,121,188,243,139,206,255,
380   158,223,255,176,242,255,196,255,255,214,255,255,0,49,0,0,63,0,0,80,4,0,
381   98,23,0,114,37,11,133,57,30,152,76,49,170,94,61,181,106,80,200,124,99,219,
382   143,119,237,163,135,253,180,154,255,199,174,255,219,194,255,237,0,52,0,
383   0,67,0,0,83,0,0,101,0,16,118,0,36,137,0,55,154,0,75,173,11,86,184,23,106,
384   202,41,124,220,61,145,240,81,160,253,97,180,255,116,200,255,137,220,255,
385   157,0,45,0,0,60,0,5,77,0,24,94,0,41,112,0,60,130,0,77,148,0,97,168,0,108,
386   179,0,128,197,15,147,215,34,165,235,52,183,251,71,202,255,91,220,255,111,
387   240,255,128,1,31,0,18,46,0,34,63,0,54,81,0,70,99,0,90,118,0,107,134,0,127,
388   154,0,138,165,0,169,184,8,175,202,28,194,221,47,211,238,65,230,255,83,248,
389   255,103,255,255,123,31,13,0,47,29,0,63,46,0,82,63,0,98,82,0,117,101,0,135,
390   118,0,154,138,0,165,149,0,185,169,15,202,185,34,222,205,54,238,222,71,253,
391   241,90,255,255,111,255,255,129,57,0,0,73,10,0,90,29,0,108,47,0,123,66,0,
392   142,85,0,159,101,0,179,122,10,190,133,23,209,152,41,226,169,60,246,190,
393   81,255,205,96,255,225,118,255,243,135,255,255,155
394 };
395
396 static byte XFormer[] =
397 {
398   0,0,0,32,32,32,64,64,64,97,97,97,125,125,125,145,145,145,161,161,161,178,
399   178,178,190,190,190,202,202,202,214,214,214,226,226,226,234,234,234,242,
400   242,242,250,250,250,255,255,255,24,20,0,48,40,0,97,60,4,121,80,8,141,109,
401   12,157,133,24,178,170,48,190,178,68,198,194,80,210,206,93,218,214,105,222,
402   222,117,226,226,133,230,230,145,234,234,157,238,238,165,36,20,0,56,36,0,
403   80,52,0,113,80,0,145,113,4,174,133,4,190,157,40,198,174,68,206,186,97,214,
404   190,105,222,198,113,230,202,121,238,206,129,242,214,145,246,222,157,250,
405   226,161,44,12,4,72,20,8,109,28,16,145,44,32,178,80,52,186,97,64,198,113,
406   85,206,121,101,214,141,121,218,153,137,222,170,149,226,174,153,230,178,
407   157,230,186,161,234,194,170,238,198,178,44,4,12,89,24,36,149,40,68,170,
408   60,89,182,85,113,194,97,121,202,105,129,210,113,137,214,121,145,218,133,
409   153,222,141,161,226,149,170,230,157,178,234,165,182,238,170,186,242,174,
410   190,48,0,44,80,8,72,113,16,105,157,32,149,194,72,198,214,97,214,222,117,
411   222,226,129,226,230,141,230,234,149,234,238,157,238,238,165,238,238,170,
412   238,238,174,238,238,178,238,242,182,242,20,4,64,40,8,129,89,40,186,109,
413   60,198,129,85,206,141,101,210,153,113,214,161,129,218,170,141,222,178,149,
414   226,186,153,230,190,161,230,194,165,234,198,174,234,202,178,238,206,182,
415   238,0,0,52,16,16,105,40,40,186,72,72,198,97,97,214,109,109,218,121,121,
416   222,133,133,226,145,145,230,157,157,230,165,165,234,174,174,234,178,178,
417   238,186,186,242,194,194,246,198,198,250,4,28,72,8,52,121,12,76,170,16,97,
418   170,36,113,182,56,129,194,68,141,206,80,149,214,97,157,222,113,165,226,
419   125,178,230,137,186,230,149,190,234,157,194,234,165,198,238,170,202,242,
420   4,16,48,8,24,89,12,40,129,20,60,145,32,80,153,60,101,178,85,121,190,97,
421   137,198,109,153,210,117,170,218,125,178,222,133,186,226,145,190,230,153,
422   198,234,161,202,238,170,206,242,0,36,28,4,72,56,8,105,80,12,141,109,16,
423   170,133,24,190,153,56,206,178,72,214,186,89,222,198,101,226,206,113,230,
424   210,129,234,214,145,238,222,161,242,226,178,246,230,182,250,234,0,40,4,
425   0,64,12,4,89,20,20,133,28,36,178,64,56,194,85,76,206,97,89,210,113,97,214,
426   125,121,222,141,145,230,153,157,234,165,165,238,178,174,238,190,186,238,
427   198,190,242,202,12,40,0,24,80,0,36,121,4,56,149,16,72,178,28,89,186,48,
428   105,194,68,117,202,89,133,210,105,145,218,113,153,222,121,161,226,133,170,
429   230,145,182,234,157,194,238,170,198,242,174,20,36,0,44,89,0,68,141,4,93,
430   170,8,117,194,32,137,202,48,153,206,68,161,210,85,170,214,97,178,218,109,
431   186,222,117,190,226,125,194,230,137,202,234,149,210,238,161,214,242,170,
432   32,28,0,76,64,0,113,97,16,133,125,24,194,153,32,210,178,48,222,202,60,230,
433   210,76,234,218,89,234,226,97,238,230,105,238,234,117,242,234,133,246,238,
434   141,246,238,145,250,242,153,32,20,0,52,36,0,89,56,4,129,85,12,170,117,20,
435   182,133,28,194,145,48,202,157,72,214,170,97,218,182,109,222,186,121,226,
436   190,133,230,198,145,234,202,153,234,214,157,238,218,161
437 };
438
439 // pointer array positions must match palette numbers in header file
440 static const byte *atari_palettes_pointers[] =
441 {
442   BuiltIn,
443   BuiltIn_contrast,
444   Default,
445   Jakub,
446   Jakub_contrast,
447   Real,
448   Real_contrast,
449   XFormer,
450
451   NULL
452 };
453
454 static byte Spiff[] =
455 {
456   2,5,10,12,16,19,29,28,30,36,43,43,54,53,52,63,68,67,82,79,80,91,94,94,103,
457   102,104,114,116,114,130,128,131,139,143,143,157,153,154,167,167,169,181,
458   180,178,193,196,194,35,2,0,45,13,0,58,27,0,68,43,0,80,54,0,92,68,0,109,
459   80,0,120,94,0,130,102,4,141,117,21,157,129,35,167,142,51,182,154,63,194,
460   168,77,210,180,91,223,196,104,52,0,0,63,8,0,76,16,0,85,34,0,99,46,0,108,
461   61,0,127,72,14,139,85,27,150,93,39,162,107,49,175,120,59,185,134,74,201,
462   144,85,212,158,100,229,171,113,243,188,129,62,0,0,75,0,0,86,0,0,96,26,6,
463   110,38,21,121,52,36,139,63,47,152,77,62,163,85,70,174,99,79,188,111,95,
464   199,126,106,212,136,121,226,151,132,244,163,147,255,178,166,64,0,12,78,
465   0,22,89,0,36,101,15,52,112,32,62,126,46,76,143,58,88,155,72,105,167,79,
466   109,176,93,124,192,106,139,200,120,151,216,132,161,226,146,176,246,158,
467   192,254,173,207,58,0,49,68,0,60,82,0,77,90,19,88,107,30,103,116,46,112,
468   135,58,126,146,71,137,158,80,145,170,92,165,181,106,174,193,120,192,209,
469   131,198,219,145,215,236,158,227,252,174,241,40,0,77,50,0,90,66,3,102,73,
470   24,119,89,35,130,99,49,144,118,61,153,130,74,167,139,83,176,152,96,190,
471   165,108,206,175,123,217,191,133,232,203,148,242,220,160,253,232,176,255,
472   20,0,97,31,0,104,44,14,119,56,28,133,68,40,146,79,53,158,97,65,170,108,
473   80,182,118,87,191,130,101,208,147,113,220,154,128,236,172,138,245,182,153,
474   255,199,165,255,217,180,255,0,0,98,5,8,107,23,20,121,32,34,135,48,45,150,
475   57,59,163,74,71,174,84,85,187,96,94,197,108,107,212,123,120,225,134,134,
476   241,149,145,254,157,160,255,174,172,255,189,187,255,0,6,88,0,15,99,0,27,
477   111,0,41,129,20,52,140,31,66,154,47,78,167,59,93,179,69,101,190,84,115,
478   204,102,127,220,111,142,233,126,152,246,134,167,254,149,180,255,161,196,
479   255,0,13,68,0,23,79,0,35,93,0,48,110,0,60,118,0,73,132,12,86,147,25,102,
480   160,43,110,168,57,124,184,78,136,199,89,150,213,102,161,223,111,176,233,
481   125,189,249,140,205,254,0,20,36,0,30,46,0,41,62,0,56,72,0,66,87,0,80,97,
482   0,93,113,0,108,124,5,118,132,32,131,152,56,144,161,69,158,177,87,169,188,
483   95,183,198,109,196,212,121,213,223,0,25,0,0,35,0,0,46,14,0,60,30,0,70,40,
484   0,86,55,0,97,68,6,113,82,25,122,93,43,136,105,61,148,119,77,162,131,91,
485   174,143,100,188,156,113,201,169,127,217,186,0,26,0,0,36,0,0,48,0,0,61,0,
486   0,72,0,0,86,21,19,99,32,34,114,47,46,122,56,57,137,66,78,148,79,88,163,
487   89,102,173,106,111,188,120,124,201,132,137,214,145,3,25,0,5,35,0,0,47,0,
488   2,61,0,5,71,0,23,86,0,39,98,0,52,112,16,63,121,25,76,134,40,94,147,47,105,
489   161,64,119,173,73,126,187,92,140,199,106,155,217,119,0,20,0,0,31,0,7,42,
490   0,15,58,0,36,67,0,43,82,0,62,94,0,74,108,0,85,116,0,98,130,11,112,143,32,
491   126,156,45,137,168,59,148,182,72,164,194,89,177,210,99
492 };
493
494 static byte Murray[] =
495 {
496   0,0,0,16,17,20,30,37,32,49,56,47,66,69,64,85,87,83,103,106,99,120,123,119,
497   132,135,130,152,155,150,165,168,163,186,189,185,199,201,193,221,223,219,
498   236,239,235,255,255,255,50,0,0,67,7,0,82,26,0,102,44,0,117,59,0,135,80,
499   0,153,96,11,166,116,36,183,126,42,202,140,67,218,159,79,235,181,92,252,
500   196,112,255,213,132,255,232,153,255,251,162,66,0,0,77,0,0,100,9,0,115,30,
501   7,130,43,16,150,63,37,169,80,59,173,93,60,199,109,85,213,130,99,235,148,
502   120,255,162,142,255,179,155,255,199,170,255,213,192,255,232,208,76,0,3,
503   83,0,9,105,0,29,123,19,46,139,33,66,155,50,79,172,66,99,192,86,107,198,
504   99,140,223,116,146,236,138,165,255,150,186,255,166,205,255,185,223,255,
505   203,238,255,219,252,66,0,49,77,0,62,99,0,83,119,10,102,130,24,112,146,44,
506   130,166,63,153,185,79,166,198,92,179,215,107,201,231,125,209,251,142,234,
507   255,162,255,255,181,255,255,195,255,255,213,255,49,0,89,62,0,102,83,0,119,
508   102,7,136,112,26,149,132,43,182,155,60,186,169,79,209,183,90,222,196,109,
509   242,221,129,255,236,146,255,254,165,255,255,179,255,255,196,255,255,212,
510   255,26,0,115,40,0,135,63,0,146,77,16,166,93,32,185,106,52,199,129,70,219,
511   148,86,239,159,99,254,176,117,255,193,133,255,208,150,255,228,168,255,244,
512   188,255,255,205,255,255,225,255,0,0,125,17,0,139,33,10,163,52,30,181,66,
513   44,192,86,64,212,103,82,229,120,96,248,130,107,255,152,128,255,166,149,
514   255,182,165,255,201,179,255,222,198,255,239,215,255,255,239,255,0,0,115,
515   0,7,135,3,26,148,23,43,169,36,62,185,57,76,208,72,93,212,97,112,239,105,
516   129,244,122,146,255,138,160,255,153,176,255,173,198,255,186,215,255,209,
517   231,255,228,249,255,0,10,89,0,24,99,0,47,123,3,64,143,14,74,158,36,97,176,
518   49,113,192,67,133,208,82,143,219,102,158,236,119,181,255,135,196,255,149,
519   211,255,168,234,255,186,248,255,201,255,255,0,27,43,0,42,56,0,57,82,0,83,
520   102,0,92,115,17,112,135,34,129,149,46,150,160,69,159,183,85,175,196,99,
521   192,218,119,215,226,136,231,254,152,249,255,168,255,255,185,255,255,0,36,
522   3,0,53,13,0,72,24,0,90,50,0,106,64,11,126,87,29,142,100,46,163,112,63,172,
523   132,79,188,145,95,203,163,115,223,183,133,241,198,152,255,218,162,255,236,
524   186,255,255,0,46,0,0,59,0,0,80,0,0,100,1,3,110,14,13,132,32,39,149,52,57,
525   166,73,64,179,77,80,198,92,97,212,113,120,229,136,132,248,149,159,255,175,
526   172,255,182,183,255,203,0,44,0,0,63,0,0,76,0,1,97,0,19,115,0,36,128,0,53,
527   149,10,70,163,32,82,178,42,102,201,49,117,211,79,136,226,96,153,248,109,
528   168,255,125,186,255,143,206,255,162,0,39,0,0,56,0,6,73,0,24,95,0,36,105,
529   0,56,125,0,77,145,0,92,160,0,103,172,16,129,189,34,142,205,46,158,226,66,
530   173,239,85,196,255,100,206,255,110,231,255,139,0,26,0,16,42,0,33,59,0,50,
531   79,0,66,93,0,87,109,0,103,129,0,115,146,0,132,160,1,149,181,26,170,196,
532   39,185,212,57,208,232,80,225,249,89,238,255,107,255,255,126
533 };
534
535 // pointer array positions must match palette numbers in header file
536 static const byte *c64dtv_palettes_pointers[] =
537 {
538   Spiff,
539   Murray,
540
541   NULL
542 };
543
544 // return c64 color with index.
545 GdColor gd_c64_color(int index)
546 {
547   return (GD_COLOR_TYPE_C64 << 24) + index;
548 }
549
550 // return atari color with index.
551 GdColor gd_atari_color(int index)
552 {
553   return (GD_COLOR_TYPE_ATARI << 24) + index;
554 }
555
556 GdColor gd_atari_color_huesat(int hue, int sat)
557 {
558   return gd_atari_color(16 * hue + sat);
559 }
560
561 // return c64dtv color with index.
562 GdColor gd_c64dtv_color(int index)
563 {
564   return (GD_COLOR_TYPE_C64DTV << 24) + index;
565 }
566
567 GdColor gd_c64dtv_color_huesat(int hue, int sat)
568 {
569   return gd_c64dtv_color(16 * hue + sat);
570 }
571
572 // return "unknown color"
573 static GdColor unknown_color(void)
574 {
575   return (GD_COLOR_TYPE_UNKNOWN << 24);
576 }
577
578 // convert color to rgbcolor; using the current palette.
579 GdColor gd_color_get_rgb(GdColor color)
580 {
581   int index;
582   const unsigned char *atari_pal;
583   const unsigned char *c64dtv_pal;
584   const GdColor *c64_pal;
585
586   switch (color >> 24)
587   {
588     case GD_COLOR_TYPE_RGB:
589       // is already rgb
590       return color;
591
592     case GD_COLOR_TYPE_C64:
593       if (setup.bd_palette_c64 < 0 ||
594           setup.bd_palette_c64 >= ARRAY_SIZE(c64_palettes_pointers) - 1)
595         setup.bd_palette_c64 = 0;       // silently switch to default, if invalid value
596       c64_pal = c64_palettes_pointers[setup.bd_palette_c64];
597       index = color & 0x0f;
598       return c64_pal[index];
599
600     case GD_COLOR_TYPE_C64DTV:
601       if (setup.bd_palette_c64dtv < 0 ||
602           setup.bd_palette_c64dtv >= ARRAY_SIZE(c64dtv_palettes_pointers) - 1)
603         setup.bd_palette_c64dtv = 0;    // silently switch to default, if invalid value
604       c64dtv_pal = c64dtv_palettes_pointers[setup.bd_palette_c64dtv];
605       index = color & 0xff;
606       return gd_color_get_from_rgb(c64dtv_pal[index * 3],
607                                    c64dtv_pal[index * 3 + 1],
608                                    c64dtv_pal[index * 3 + 2]);
609
610     case GD_COLOR_TYPE_ATARI:
611       if (setup.bd_palette_atari < 0 ||
612           setup.bd_palette_atari >= ARRAY_SIZE(atari_palettes_pointers) - 1)
613         setup.bd_palette_atari = 0;     // silently switch to default, if invalid value
614       atari_pal = atari_palettes_pointers[setup.bd_palette_atari];
615       index = color & 0xff;
616       return gd_color_get_from_rgb(atari_pal[index * 3],
617                                    atari_pal[index * 3 + 1],
618                                    atari_pal[index * 3 + 2]);
619
620     default:
621       return 0; // (never reached)
622   }
623 }
624
625 unsigned int gd_color_get_r(GdColor color)
626 {
627   return ((gd_color_get_rgb(color) >> 16) & 0xff);
628 }
629
630 unsigned int gd_color_get_g(GdColor color)
631 {
632   return ((gd_color_get_rgb(color) >> 8) & 0xff);
633 }
634
635 unsigned int gd_color_get_b(GdColor color)
636 {
637   return ((gd_color_get_rgb(color) >> 0) & 0xff);
638 }
639
640 // make up GdColor from r,g,b values.
641 GdColor gd_color_get_from_rgb(int r, int g, int b)
642 {
643   return (GD_COLOR_TYPE_RGB << 24) + (r << 16) + (g << 8) + b;
644 }
645
646 // make up GdColor from h,s,v values.
647 // h=0..360, s=0..1, v=0..1
648 GdColor gd_color_get_from_hsv(double h, double s, double v)
649 {
650   int hi = (int)(h / 60) % 6;
651   double f = h / 60 - (int)(h / 60);    // fractional part
652   double p = v * (1 - s);
653   double q = v * (1 - f * s);
654   double t = v * (1 - (1 - f) * s);
655
656   v *= 255;
657   p *= 255;
658   q *= 255;
659   t *= 255;
660
661   switch(hi)
662   {
663     case 0: return gd_color_get_from_rgb(v, t, p);
664     case 1: return gd_color_get_from_rgb(q, v, p);
665     case 2: return gd_color_get_from_rgb(p, v, t);
666     case 3: return gd_color_get_from_rgb(p, q, v);
667     case 4: return gd_color_get_from_rgb(t, p, v);
668     case 5: return gd_color_get_from_rgb(v, p, q);
669   }
670
671   // no way we reach this
672   return gd_color_get_from_rgb(0, 0, 0);
673 }
674
675
676 GdColor gd_color_get_from_string(const char *color)
677 {
678   int i, r, g, b;
679
680   for (i = 0; i < ARRAY_SIZE(c64_color_names); i++)
681     if (strEqualCase(color, c64_color_names[i]))
682       return gd_c64_color(i);
683
684   // we do not use sscanf(color, "atari..." as may be lowercase
685   if (strEqualCaseN(color, "Atari", strlen("Atari")))
686   {
687     const char *b = color + strlen("Atari");
688     int c;
689
690     if (sscanf(b, "%02x", &c) == 1)
691       return gd_atari_color(c);
692
693     Warn("Unknown Atari color: %s", color);
694
695     return unknown_color();
696   }
697
698   // we do not use sscanf(color, "c64dtv..." as may be lowercase
699   if (strEqualCaseN(color, "C64DTV", strlen("C64DTV")))
700   {
701     const char *b = color + strlen("C64DTV");
702     int c;
703
704     if (sscanf(b, "%02x", &c) == 1)
705       return gd_c64dtv_color(c);
706
707     Warn("Unknown C64DTV color: %s", color);
708
709     return unknown_color();
710   }
711
712   // may or may not have a #
713   if (color[0] == '#')
714     color++;
715
716   if (sscanf(color, "%02x%02x%02x", &r, &g, &b) != 3)
717   {
718     i = gd_random_int_range(0, 16);
719
720     Warn("Unkonwn color %s", color);
721
722     return unknown_color();
723   }
724
725   return gd_color_get_from_rgb(r, g, b);
726 }
727
728 const char *gd_color_get_string(GdColor color)
729 {
730   static char text[16];
731
732   if (gd_color_is_c64(color))
733   {
734     return c64_color_names[color & 0xff];
735   }
736
737   if (gd_color_is_atari(color))
738   {
739     sprintf(text, "Atari%02x", color & 0xff);
740     return text;
741   }
742
743   if (gd_color_is_dtv(color))
744   {
745     sprintf(text, "C64DTV%02x", color & 0xff);
746     return text;
747   }
748
749   sprintf(text, "#%02x%02x%02x", (color >> 16) & 255, (color >> 8) & 255, color & 255);
750   return text;
751 }
752
753 boolean gd_color_is_c64(GdColor color)
754 {
755   return (color >> 24) == GD_COLOR_TYPE_C64;
756 }
757
758 boolean gd_color_is_atari(GdColor color)
759 {
760     return (color >> 24) == GD_COLOR_TYPE_ATARI;
761 }
762
763 boolean gd_color_is_dtv(GdColor color)
764 {
765     return (color >> 24) == GD_COLOR_TYPE_C64DTV;
766 }
767
768 boolean gd_color_is_unknown(GdColor color)
769 {
770   return (color >> 24) == GD_COLOR_TYPE_UNKNOWN;
771 }
772
773 GdColor gd_gdash_color(int c)
774 {
775   // these values are taken from the title screen, drawn by cws.
776   // so menus and everything else will look nice!
777   // the 16 colors that can be used are the same as on c64.
778   // "Black", "White", "Red", "Cyan", "Purple", "Green", "Blue", "Yellow",
779   // "Orange", "Brown", "LightRed", "Gray1", "Gray2", "LightGreen", "LightBlue", "Gray3",
780   // not in the png: cyan, purple. gray3 is darker in the png.
781   // 17th color is the player's leg in the png. i not connected it to any c64
782   // color, but it is used for theme images for example.
783   const GdColor gdash_colors[] =
784   {
785     0x000000, 0xffffff, 0xe33939, 0x55aaaa, 0xaa55aa, 0x71aa55, 0x0039ff, 0xffff55,
786     0xe37139, 0xaa7139, 0xe09080, 0x555555, 0x717171, 0xc6e38e, 0xaaaaff, 0x8e8e8e,
787
788     0x5555aa,
789   };
790
791   return gdash_colors[c];
792 }