colour.c revision 1.12 1 1.5 christos /* $OpenBSD$ */
2 1.1 jmmv
3 1.1 jmmv /*
4 1.6 christos * Copyright (c) 2008 Nicholas Marriott <nicholas.marriott (at) gmail.com>
5 1.7 christos * Copyright (c) 2016 Avi Halachmi <avihpit (at) yahoo.com>
6 1.1 jmmv *
7 1.1 jmmv * Permission to use, copy, modify, and distribute this software for any
8 1.1 jmmv * purpose with or without fee is hereby granted, provided that the above
9 1.1 jmmv * copyright notice and this permission notice appear in all copies.
10 1.1 jmmv *
11 1.1 jmmv * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
12 1.1 jmmv * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
13 1.1 jmmv * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
14 1.1 jmmv * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
15 1.1 jmmv * WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER
16 1.1 jmmv * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
17 1.1 jmmv * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
18 1.1 jmmv */
19 1.1 jmmv
20 1.1 jmmv #include <sys/types.h>
21 1.1 jmmv
22 1.2 he #include <ctype.h>
23 1.1 jmmv #include <stdlib.h>
24 1.1 jmmv #include <string.h>
25 1.10 christos #include <math.h>
26 1.1 jmmv
27 1.1 jmmv #include "tmux.h"
28 1.1 jmmv
29 1.7 christos static int
30 1.7 christos colour_dist_sq(int R, int G, int B, int r, int g, int b)
31 1.7 christos {
32 1.7 christos return ((R - r) * (R - r) + (G - g) * (G - g) + (B - b) * (B - b));
33 1.7 christos }
34 1.2 he
35 1.7 christos static int
36 1.7 christos colour_to_6cube(int v)
37 1.2 he {
38 1.7 christos if (v < 48)
39 1.7 christos return (0);
40 1.7 christos if (v < 114)
41 1.5 christos return (1);
42 1.7 christos return ((v - 35) / 40);
43 1.2 he }
44 1.2 he
45 1.7 christos /*
46 1.7 christos * Convert an RGB triplet to the xterm(1) 256 colour palette.
47 1.7 christos *
48 1.7 christos * xterm provides a 6x6x6 colour cube (16 - 231) and 24 greys (232 - 255). We
49 1.7 christos * map our RGB colour to the closest in the cube, also work out the closest
50 1.7 christos * grey, and use the nearest of the two.
51 1.7 christos *
52 1.7 christos * Note that the xterm has much lower resolution for darker colours (they are
53 1.7 christos * not evenly spread out), so our 6 levels are not evenly spread: 0x0, 0x5f
54 1.7 christos * (95), 0x87 (135), 0xaf (175), 0xd7 (215) and 0xff (255). Greys are more
55 1.7 christos * evenly spread (8, 18, 28 ... 238).
56 1.7 christos */
57 1.2 he int
58 1.5 christos colour_find_rgb(u_char r, u_char g, u_char b)
59 1.2 he {
60 1.7 christos static const int q2c[6] = { 0x00, 0x5f, 0x87, 0xaf, 0xd7, 0xff };
61 1.7 christos int qr, qg, qb, cr, cg, cb, d, idx;
62 1.7 christos int grey_avg, grey_idx, grey;
63 1.7 christos
64 1.7 christos /* Map RGB to 6x6x6 cube. */
65 1.7 christos qr = colour_to_6cube(r); cr = q2c[qr];
66 1.7 christos qg = colour_to_6cube(g); cg = q2c[qg];
67 1.7 christos qb = colour_to_6cube(b); cb = q2c[qb];
68 1.7 christos
69 1.7 christos /* If we have hit the colour exactly, return early. */
70 1.7 christos if (cr == r && cg == g && cb == b)
71 1.7 christos return ((16 + (36 * qr) + (6 * qg) + qb) | COLOUR_FLAG_256);
72 1.7 christos
73 1.7 christos /* Work out the closest grey (average of RGB). */
74 1.7 christos grey_avg = (r + g + b) / 3;
75 1.7 christos if (grey_avg > 238)
76 1.7 christos grey_idx = 23;
77 1.7 christos else
78 1.7 christos grey_idx = (grey_avg - 3) / 10;
79 1.7 christos grey = 8 + (10 * grey_idx);
80 1.7 christos
81 1.7 christos /* Is grey or 6x6x6 colour closest? */
82 1.7 christos d = colour_dist_sq(cr, cg, cb, r, g, b);
83 1.7 christos if (colour_dist_sq(grey, grey, grey, r, g, b) < d)
84 1.7 christos idx = 232 + grey_idx;
85 1.7 christos else
86 1.7 christos idx = 16 + (36 * qr) + (6 * qg) + qb;
87 1.7 christos return (idx | COLOUR_FLAG_256);
88 1.2 he }
89 1.2 he
90 1.7 christos /* Join RGB into a colour. */
91 1.7 christos int
92 1.7 christos colour_join_rgb(u_char r, u_char g, u_char b)
93 1.1 jmmv {
94 1.7 christos return ((((int)((r) & 0xff)) << 16) |
95 1.7 christos (((int)((g) & 0xff)) << 8) |
96 1.7 christos (((int)((b) & 0xff))) | COLOUR_FLAG_RGB);
97 1.1 jmmv }
98 1.1 jmmv
99 1.7 christos /* Split colour into RGB. */
100 1.1 jmmv void
101 1.7 christos colour_split_rgb(int c, u_char *r, u_char *g, u_char *b)
102 1.1 jmmv {
103 1.7 christos *r = (c >> 16) & 0xff;
104 1.7 christos *g = (c >> 8) & 0xff;
105 1.7 christos *b = c & 0xff;
106 1.1 jmmv }
107 1.1 jmmv
108 1.11 wiz /* Force colour to RGB if not already. */
109 1.11 wiz int
110 1.11 wiz colour_force_rgb(int c)
111 1.11 wiz {
112 1.11 wiz if (c & COLOUR_FLAG_RGB)
113 1.11 wiz return (c);
114 1.11 wiz if (c & COLOUR_FLAG_256)
115 1.11 wiz return (colour_256toRGB(c));
116 1.11 wiz if (c >= 0 && c <= 7)
117 1.11 wiz return (colour_256toRGB(c));
118 1.11 wiz if (c >= 90 && c <= 97)
119 1.11 wiz return (colour_256toRGB(8 + c - 90));
120 1.11 wiz return (-1);
121 1.11 wiz }
122 1.11 wiz
123 1.2 he /* Convert colour to a string. */
124 1.1 jmmv const char *
125 1.1 jmmv colour_tostring(int c)
126 1.1 jmmv {
127 1.1 jmmv static char s[32];
128 1.7 christos u_char r, g, b;
129 1.7 christos
130 1.10 christos if (c == -1)
131 1.11 wiz return ("none");
132 1.10 christos
133 1.7 christos if (c & COLOUR_FLAG_RGB) {
134 1.7 christos colour_split_rgb(c, &r, &g, &b);
135 1.7 christos xsnprintf(s, sizeof s, "#%02x%02x%02x", r, g, b);
136 1.7 christos return (s);
137 1.7 christos }
138 1.1 jmmv
139 1.7 christos if (c & COLOUR_FLAG_256) {
140 1.7 christos xsnprintf(s, sizeof s, "colour%u", c & 0xff);
141 1.1 jmmv return (s);
142 1.1 jmmv }
143 1.1 jmmv
144 1.1 jmmv switch (c) {
145 1.1 jmmv case 0:
146 1.1 jmmv return ("black");
147 1.1 jmmv case 1:
148 1.1 jmmv return ("red");
149 1.1 jmmv case 2:
150 1.1 jmmv return ("green");
151 1.1 jmmv case 3:
152 1.1 jmmv return ("yellow");
153 1.1 jmmv case 4:
154 1.1 jmmv return ("blue");
155 1.1 jmmv case 5:
156 1.1 jmmv return ("magenta");
157 1.1 jmmv case 6:
158 1.1 jmmv return ("cyan");
159 1.1 jmmv case 7:
160 1.1 jmmv return ("white");
161 1.1 jmmv case 8:
162 1.1 jmmv return ("default");
163 1.8 christos case 9:
164 1.8 christos return ("terminal");
165 1.4 christos case 90:
166 1.4 christos return ("brightblack");
167 1.4 christos case 91:
168 1.4 christos return ("brightred");
169 1.4 christos case 92:
170 1.4 christos return ("brightgreen");
171 1.4 christos case 93:
172 1.4 christos return ("brightyellow");
173 1.4 christos case 94:
174 1.4 christos return ("brightblue");
175 1.4 christos case 95:
176 1.4 christos return ("brightmagenta");
177 1.4 christos case 96:
178 1.4 christos return ("brightcyan");
179 1.4 christos case 97:
180 1.4 christos return ("brightwhite");
181 1.1 jmmv }
182 1.8 christos return ("invalid");
183 1.1 jmmv }
184 1.1 jmmv
185 1.2 he /* Convert colour from string. */
186 1.1 jmmv int
187 1.1 jmmv colour_fromstring(const char *s)
188 1.1 jmmv {
189 1.5 christos const char *errstr;
190 1.5 christos const char *cp;
191 1.5 christos int n;
192 1.5 christos u_char r, g, b;
193 1.2 he
194 1.2 he if (*s == '#' && strlen(s) == 7) {
195 1.2 he for (cp = s + 1; isxdigit((u_char) *cp); cp++)
196 1.2 he ;
197 1.2 he if (*cp != '\0')
198 1.2 he return (-1);
199 1.5 christos n = sscanf(s + 1, "%2hhx%2hhx%2hhx", &r, &g, &b);
200 1.2 he if (n != 3)
201 1.2 he return (-1);
202 1.7 christos return (colour_join_rgb(r, g, b));
203 1.2 he }
204 1.1 jmmv
205 1.1 jmmv if (strncasecmp(s, "colour", (sizeof "colour") - 1) == 0) {
206 1.1 jmmv n = strtonum(s + (sizeof "colour") - 1, 0, 255, &errstr);
207 1.1 jmmv if (errstr != NULL)
208 1.1 jmmv return (-1);
209 1.7 christos return (n | COLOUR_FLAG_256);
210 1.1 jmmv }
211 1.10 christos if (strncasecmp(s, "color", (sizeof "color") - 1) == 0) {
212 1.10 christos n = strtonum(s + (sizeof "color") - 1, 0, 255, &errstr);
213 1.10 christos if (errstr != NULL)
214 1.10 christos return (-1);
215 1.10 christos return (n | COLOUR_FLAG_256);
216 1.10 christos }
217 1.1 jmmv
218 1.8 christos if (strcasecmp(s, "default") == 0)
219 1.8 christos return (8);
220 1.8 christos if (strcasecmp(s, "terminal") == 0)
221 1.8 christos return (9);
222 1.8 christos
223 1.5 christos if (strcasecmp(s, "black") == 0 || strcmp(s, "0") == 0)
224 1.1 jmmv return (0);
225 1.5 christos if (strcasecmp(s, "red") == 0 || strcmp(s, "1") == 0)
226 1.1 jmmv return (1);
227 1.5 christos if (strcasecmp(s, "green") == 0 || strcmp(s, "2") == 0)
228 1.1 jmmv return (2);
229 1.5 christos if (strcasecmp(s, "yellow") == 0 || strcmp(s, "3") == 0)
230 1.1 jmmv return (3);
231 1.5 christos if (strcasecmp(s, "blue") == 0 || strcmp(s, "4") == 0)
232 1.1 jmmv return (4);
233 1.5 christos if (strcasecmp(s, "magenta") == 0 || strcmp(s, "5") == 0)
234 1.1 jmmv return (5);
235 1.5 christos if (strcasecmp(s, "cyan") == 0 || strcmp(s, "6") == 0)
236 1.1 jmmv return (6);
237 1.5 christos if (strcasecmp(s, "white") == 0 || strcmp(s, "7") == 0)
238 1.1 jmmv return (7);
239 1.5 christos if (strcasecmp(s, "brightblack") == 0 || strcmp(s, "90") == 0)
240 1.4 christos return (90);
241 1.5 christos if (strcasecmp(s, "brightred") == 0 || strcmp(s, "91") == 0)
242 1.4 christos return (91);
243 1.5 christos if (strcasecmp(s, "brightgreen") == 0 || strcmp(s, "92") == 0)
244 1.4 christos return (92);
245 1.5 christos if (strcasecmp(s, "brightyellow") == 0 || strcmp(s, "93") == 0)
246 1.4 christos return (93);
247 1.5 christos if (strcasecmp(s, "brightblue") == 0 || strcmp(s, "94") == 0)
248 1.4 christos return (94);
249 1.5 christos if (strcasecmp(s, "brightmagenta") == 0 || strcmp(s, "95") == 0)
250 1.4 christos return (95);
251 1.5 christos if (strcasecmp(s, "brightcyan") == 0 || strcmp(s, "96") == 0)
252 1.4 christos return (96);
253 1.5 christos if (strcasecmp(s, "brightwhite") == 0 || strcmp(s, "97") == 0)
254 1.4 christos return (97);
255 1.10 christos return (colour_byname(s));
256 1.1 jmmv }
257 1.1 jmmv
258 1.9 christos /* Convert 256 colour to RGB colour. */
259 1.9 christos int
260 1.9 christos colour_256toRGB(int c)
261 1.1 jmmv {
262 1.9 christos static const int table[256] = {
263 1.9 christos 0x000000, 0x800000, 0x008000, 0x808000,
264 1.9 christos 0x000080, 0x800080, 0x008080, 0xc0c0c0,
265 1.9 christos 0x808080, 0xff0000, 0x00ff00, 0xffff00,
266 1.9 christos 0x0000ff, 0xff00ff, 0x00ffff, 0xffffff,
267 1.9 christos 0x000000, 0x00005f, 0x000087, 0x0000af,
268 1.9 christos 0x0000d7, 0x0000ff, 0x005f00, 0x005f5f,
269 1.9 christos 0x005f87, 0x005faf, 0x005fd7, 0x005fff,
270 1.9 christos 0x008700, 0x00875f, 0x008787, 0x0087af,
271 1.9 christos 0x0087d7, 0x0087ff, 0x00af00, 0x00af5f,
272 1.9 christos 0x00af87, 0x00afaf, 0x00afd7, 0x00afff,
273 1.9 christos 0x00d700, 0x00d75f, 0x00d787, 0x00d7af,
274 1.9 christos 0x00d7d7, 0x00d7ff, 0x00ff00, 0x00ff5f,
275 1.9 christos 0x00ff87, 0x00ffaf, 0x00ffd7, 0x00ffff,
276 1.9 christos 0x5f0000, 0x5f005f, 0x5f0087, 0x5f00af,
277 1.9 christos 0x5f00d7, 0x5f00ff, 0x5f5f00, 0x5f5f5f,
278 1.9 christos 0x5f5f87, 0x5f5faf, 0x5f5fd7, 0x5f5fff,
279 1.9 christos 0x5f8700, 0x5f875f, 0x5f8787, 0x5f87af,
280 1.9 christos 0x5f87d7, 0x5f87ff, 0x5faf00, 0x5faf5f,
281 1.9 christos 0x5faf87, 0x5fafaf, 0x5fafd7, 0x5fafff,
282 1.9 christos 0x5fd700, 0x5fd75f, 0x5fd787, 0x5fd7af,
283 1.9 christos 0x5fd7d7, 0x5fd7ff, 0x5fff00, 0x5fff5f,
284 1.9 christos 0x5fff87, 0x5fffaf, 0x5fffd7, 0x5fffff,
285 1.9 christos 0x870000, 0x87005f, 0x870087, 0x8700af,
286 1.9 christos 0x8700d7, 0x8700ff, 0x875f00, 0x875f5f,
287 1.9 christos 0x875f87, 0x875faf, 0x875fd7, 0x875fff,
288 1.9 christos 0x878700, 0x87875f, 0x878787, 0x8787af,
289 1.9 christos 0x8787d7, 0x8787ff, 0x87af00, 0x87af5f,
290 1.9 christos 0x87af87, 0x87afaf, 0x87afd7, 0x87afff,
291 1.9 christos 0x87d700, 0x87d75f, 0x87d787, 0x87d7af,
292 1.9 christos 0x87d7d7, 0x87d7ff, 0x87ff00, 0x87ff5f,
293 1.9 christos 0x87ff87, 0x87ffaf, 0x87ffd7, 0x87ffff,
294 1.9 christos 0xaf0000, 0xaf005f, 0xaf0087, 0xaf00af,
295 1.9 christos 0xaf00d7, 0xaf00ff, 0xaf5f00, 0xaf5f5f,
296 1.9 christos 0xaf5f87, 0xaf5faf, 0xaf5fd7, 0xaf5fff,
297 1.9 christos 0xaf8700, 0xaf875f, 0xaf8787, 0xaf87af,
298 1.9 christos 0xaf87d7, 0xaf87ff, 0xafaf00, 0xafaf5f,
299 1.9 christos 0xafaf87, 0xafafaf, 0xafafd7, 0xafafff,
300 1.9 christos 0xafd700, 0xafd75f, 0xafd787, 0xafd7af,
301 1.9 christos 0xafd7d7, 0xafd7ff, 0xafff00, 0xafff5f,
302 1.9 christos 0xafff87, 0xafffaf, 0xafffd7, 0xafffff,
303 1.9 christos 0xd70000, 0xd7005f, 0xd70087, 0xd700af,
304 1.9 christos 0xd700d7, 0xd700ff, 0xd75f00, 0xd75f5f,
305 1.9 christos 0xd75f87, 0xd75faf, 0xd75fd7, 0xd75fff,
306 1.9 christos 0xd78700, 0xd7875f, 0xd78787, 0xd787af,
307 1.9 christos 0xd787d7, 0xd787ff, 0xd7af00, 0xd7af5f,
308 1.9 christos 0xd7af87, 0xd7afaf, 0xd7afd7, 0xd7afff,
309 1.9 christos 0xd7d700, 0xd7d75f, 0xd7d787, 0xd7d7af,
310 1.9 christos 0xd7d7d7, 0xd7d7ff, 0xd7ff00, 0xd7ff5f,
311 1.9 christos 0xd7ff87, 0xd7ffaf, 0xd7ffd7, 0xd7ffff,
312 1.9 christos 0xff0000, 0xff005f, 0xff0087, 0xff00af,
313 1.9 christos 0xff00d7, 0xff00ff, 0xff5f00, 0xff5f5f,
314 1.9 christos 0xff5f87, 0xff5faf, 0xff5fd7, 0xff5fff,
315 1.9 christos 0xff8700, 0xff875f, 0xff8787, 0xff87af,
316 1.9 christos 0xff87d7, 0xff87ff, 0xffaf00, 0xffaf5f,
317 1.9 christos 0xffaf87, 0xffafaf, 0xffafd7, 0xffafff,
318 1.9 christos 0xffd700, 0xffd75f, 0xffd787, 0xffd7af,
319 1.9 christos 0xffd7d7, 0xffd7ff, 0xffff00, 0xffff5f,
320 1.9 christos 0xffff87, 0xffffaf, 0xffffd7, 0xffffff,
321 1.9 christos 0x080808, 0x121212, 0x1c1c1c, 0x262626,
322 1.9 christos 0x303030, 0x3a3a3a, 0x444444, 0x4e4e4e,
323 1.9 christos 0x585858, 0x626262, 0x6c6c6c, 0x767676,
324 1.9 christos 0x808080, 0x8a8a8a, 0x949494, 0x9e9e9e,
325 1.9 christos 0xa8a8a8, 0xb2b2b2, 0xbcbcbc, 0xc6c6c6,
326 1.9 christos 0xd0d0d0, 0xdadada, 0xe4e4e4, 0xeeeeee
327 1.9 christos };
328 1.9 christos
329 1.9 christos return (table[c & 0xff] | COLOUR_FLAG_RGB);
330 1.9 christos }
331 1.9 christos
332 1.9 christos /* Convert 256 colour to 16 colour. */
333 1.9 christos int
334 1.9 christos colour_256to16(int c)
335 1.9 christos {
336 1.9 christos static const char table[256] = {
337 1.1 jmmv 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
338 1.1 jmmv 0, 4, 4, 4, 12, 12, 2, 6, 4, 4, 12, 12, 2, 2, 6, 4,
339 1.1 jmmv 12, 12, 2, 2, 2, 6, 12, 12, 10, 10, 10, 10, 14, 12, 10, 10,
340 1.1 jmmv 10, 10, 10, 14, 1, 5, 4, 4, 12, 12, 3, 8, 4, 4, 12, 12,
341 1.1 jmmv 2, 2, 6, 4, 12, 12, 2, 2, 2, 6, 12, 12, 10, 10, 10, 10,
342 1.1 jmmv 14, 12, 10, 10, 10, 10, 10, 14, 1, 1, 5, 4, 12, 12, 1, 1,
343 1.1 jmmv 5, 4, 12, 12, 3, 3, 8, 4, 12, 12, 2, 2, 2, 6, 12, 12,
344 1.1 jmmv 10, 10, 10, 10, 14, 12, 10, 10, 10, 10, 10, 14, 1, 1, 1, 5,
345 1.1 jmmv 12, 12, 1, 1, 1, 5, 12, 12, 1, 1, 1, 5, 12, 12, 3, 3,
346 1.1 jmmv 3, 7, 12, 12, 10, 10, 10, 10, 14, 12, 10, 10, 10, 10, 10, 14,
347 1.1 jmmv 9, 9, 9, 9, 13, 12, 9, 9, 9, 9, 13, 12, 9, 9, 9, 9,
348 1.1 jmmv 13, 12, 9, 9, 9, 9, 13, 12, 11, 11, 11, 11, 7, 12, 10, 10,
349 1.1 jmmv 10, 10, 10, 14, 9, 9, 9, 9, 9, 13, 9, 9, 9, 9, 9, 13,
350 1.1 jmmv 9, 9, 9, 9, 9, 13, 9, 9, 9, 9, 9, 13, 9, 9, 9, 9,
351 1.1 jmmv 9, 13, 11, 11, 11, 11, 11, 15, 0, 0, 0, 0, 0, 0, 8, 8,
352 1.1 jmmv 8, 8, 8, 8, 7, 7, 7, 7, 7, 7, 15, 15, 15, 15, 15, 15
353 1.1 jmmv };
354 1.1 jmmv
355 1.9 christos return (table[c & 0xff]);
356 1.1 jmmv }
357 1.10 christos
358 1.10 christos /* Get colour by X11 colour name. */
359 1.10 christos int
360 1.10 christos colour_byname(const char *name)
361 1.10 christos {
362 1.10 christos static const struct {
363 1.10 christos const char *name;
364 1.10 christos int c;
365 1.10 christos } colours[] = {
366 1.10 christos { "AliceBlue", 0xf0f8ff },
367 1.10 christos { "AntiqueWhite", 0xfaebd7 },
368 1.10 christos { "AntiqueWhite1", 0xffefdb },
369 1.10 christos { "AntiqueWhite2", 0xeedfcc },
370 1.10 christos { "AntiqueWhite3", 0xcdc0b0 },
371 1.10 christos { "AntiqueWhite4", 0x8b8378 },
372 1.10 christos { "BlanchedAlmond", 0xffebcd },
373 1.10 christos { "BlueViolet", 0x8a2be2 },
374 1.10 christos { "CadetBlue", 0x5f9ea0 },
375 1.10 christos { "CadetBlue1", 0x98f5ff },
376 1.10 christos { "CadetBlue2", 0x8ee5ee },
377 1.10 christos { "CadetBlue3", 0x7ac5cd },
378 1.10 christos { "CadetBlue4", 0x53868b },
379 1.10 christos { "CornflowerBlue", 0x6495ed },
380 1.10 christos { "DarkBlue", 0x00008b },
381 1.10 christos { "DarkCyan", 0x008b8b },
382 1.10 christos { "DarkGoldenrod", 0xb8860b },
383 1.10 christos { "DarkGoldenrod1", 0xffb90f },
384 1.10 christos { "DarkGoldenrod2", 0xeead0e },
385 1.10 christos { "DarkGoldenrod3", 0xcd950c },
386 1.10 christos { "DarkGoldenrod4", 0x8b6508 },
387 1.10 christos { "DarkGray", 0xa9a9a9 },
388 1.10 christos { "DarkGreen", 0x006400 },
389 1.10 christos { "DarkGrey", 0xa9a9a9 },
390 1.10 christos { "DarkKhaki", 0xbdb76b },
391 1.10 christos { "DarkMagenta", 0x8b008b },
392 1.10 christos { "DarkOliveGreen", 0x556b2f },
393 1.10 christos { "DarkOliveGreen1", 0xcaff70 },
394 1.10 christos { "DarkOliveGreen2", 0xbcee68 },
395 1.10 christos { "DarkOliveGreen3", 0xa2cd5a },
396 1.10 christos { "DarkOliveGreen4", 0x6e8b3d },
397 1.10 christos { "DarkOrange", 0xff8c00 },
398 1.10 christos { "DarkOrange1", 0xff7f00 },
399 1.10 christos { "DarkOrange2", 0xee7600 },
400 1.10 christos { "DarkOrange3", 0xcd6600 },
401 1.10 christos { "DarkOrange4", 0x8b4500 },
402 1.10 christos { "DarkOrchid", 0x9932cc },
403 1.10 christos { "DarkOrchid1", 0xbf3eff },
404 1.10 christos { "DarkOrchid2", 0xb23aee },
405 1.10 christos { "DarkOrchid3", 0x9a32cd },
406 1.10 christos { "DarkOrchid4", 0x68228b },
407 1.10 christos { "DarkRed", 0x8b0000 },
408 1.10 christos { "DarkSalmon", 0xe9967a },
409 1.10 christos { "DarkSeaGreen", 0x8fbc8f },
410 1.10 christos { "DarkSeaGreen1", 0xc1ffc1 },
411 1.10 christos { "DarkSeaGreen2", 0xb4eeb4 },
412 1.10 christos { "DarkSeaGreen3", 0x9bcd9b },
413 1.10 christos { "DarkSeaGreen4", 0x698b69 },
414 1.10 christos { "DarkSlateBlue", 0x483d8b },
415 1.10 christos { "DarkSlateGray", 0x2f4f4f },
416 1.10 christos { "DarkSlateGray1", 0x97ffff },
417 1.10 christos { "DarkSlateGray2", 0x8deeee },
418 1.10 christos { "DarkSlateGray3", 0x79cdcd },
419 1.10 christos { "DarkSlateGray4", 0x528b8b },
420 1.10 christos { "DarkSlateGrey", 0x2f4f4f },
421 1.10 christos { "DarkTurquoise", 0x00ced1 },
422 1.10 christos { "DarkViolet", 0x9400d3 },
423 1.10 christos { "DeepPink", 0xff1493 },
424 1.10 christos { "DeepPink1", 0xff1493 },
425 1.10 christos { "DeepPink2", 0xee1289 },
426 1.10 christos { "DeepPink3", 0xcd1076 },
427 1.10 christos { "DeepPink4", 0x8b0a50 },
428 1.10 christos { "DeepSkyBlue", 0x00bfff },
429 1.10 christos { "DeepSkyBlue1", 0x00bfff },
430 1.10 christos { "DeepSkyBlue2", 0x00b2ee },
431 1.10 christos { "DeepSkyBlue3", 0x009acd },
432 1.10 christos { "DeepSkyBlue4", 0x00688b },
433 1.10 christos { "DimGray", 0x696969 },
434 1.10 christos { "DimGrey", 0x696969 },
435 1.10 christos { "DodgerBlue", 0x1e90ff },
436 1.10 christos { "DodgerBlue1", 0x1e90ff },
437 1.10 christos { "DodgerBlue2", 0x1c86ee },
438 1.10 christos { "DodgerBlue3", 0x1874cd },
439 1.10 christos { "DodgerBlue4", 0x104e8b },
440 1.10 christos { "FloralWhite", 0xfffaf0 },
441 1.10 christos { "ForestGreen", 0x228b22 },
442 1.10 christos { "GhostWhite", 0xf8f8ff },
443 1.10 christos { "GreenYellow", 0xadff2f },
444 1.10 christos { "HotPink", 0xff69b4 },
445 1.10 christos { "HotPink1", 0xff6eb4 },
446 1.10 christos { "HotPink2", 0xee6aa7 },
447 1.10 christos { "HotPink3", 0xcd6090 },
448 1.10 christos { "HotPink4", 0x8b3a62 },
449 1.10 christos { "IndianRed", 0xcd5c5c },
450 1.10 christos { "IndianRed1", 0xff6a6a },
451 1.10 christos { "IndianRed2", 0xee6363 },
452 1.10 christos { "IndianRed3", 0xcd5555 },
453 1.10 christos { "IndianRed4", 0x8b3a3a },
454 1.10 christos { "LavenderBlush", 0xfff0f5 },
455 1.10 christos { "LavenderBlush1", 0xfff0f5 },
456 1.10 christos { "LavenderBlush2", 0xeee0e5 },
457 1.10 christos { "LavenderBlush3", 0xcdc1c5 },
458 1.10 christos { "LavenderBlush4", 0x8b8386 },
459 1.10 christos { "LawnGreen", 0x7cfc00 },
460 1.10 christos { "LemonChiffon", 0xfffacd },
461 1.10 christos { "LemonChiffon1", 0xfffacd },
462 1.10 christos { "LemonChiffon2", 0xeee9bf },
463 1.10 christos { "LemonChiffon3", 0xcdc9a5 },
464 1.10 christos { "LemonChiffon4", 0x8b8970 },
465 1.10 christos { "LightBlue", 0xadd8e6 },
466 1.10 christos { "LightBlue1", 0xbfefff },
467 1.10 christos { "LightBlue2", 0xb2dfee },
468 1.10 christos { "LightBlue3", 0x9ac0cd },
469 1.10 christos { "LightBlue4", 0x68838b },
470 1.10 christos { "LightCoral", 0xf08080 },
471 1.10 christos { "LightCyan", 0xe0ffff },
472 1.10 christos { "LightCyan1", 0xe0ffff },
473 1.10 christos { "LightCyan2", 0xd1eeee },
474 1.10 christos { "LightCyan3", 0xb4cdcd },
475 1.10 christos { "LightCyan4", 0x7a8b8b },
476 1.10 christos { "LightGoldenrod", 0xeedd82 },
477 1.10 christos { "LightGoldenrod1", 0xffec8b },
478 1.10 christos { "LightGoldenrod2", 0xeedc82 },
479 1.10 christos { "LightGoldenrod3", 0xcdbe70 },
480 1.10 christos { "LightGoldenrod4", 0x8b814c },
481 1.10 christos { "LightGoldenrodYellow", 0xfafad2 },
482 1.10 christos { "LightGray", 0xd3d3d3 },
483 1.10 christos { "LightGreen", 0x90ee90 },
484 1.10 christos { "LightGrey", 0xd3d3d3 },
485 1.10 christos { "LightPink", 0xffb6c1 },
486 1.10 christos { "LightPink1", 0xffaeb9 },
487 1.10 christos { "LightPink2", 0xeea2ad },
488 1.10 christos { "LightPink3", 0xcd8c95 },
489 1.10 christos { "LightPink4", 0x8b5f65 },
490 1.10 christos { "LightSalmon", 0xffa07a },
491 1.10 christos { "LightSalmon1", 0xffa07a },
492 1.10 christos { "LightSalmon2", 0xee9572 },
493 1.10 christos { "LightSalmon3", 0xcd8162 },
494 1.10 christos { "LightSalmon4", 0x8b5742 },
495 1.10 christos { "LightSeaGreen", 0x20b2aa },
496 1.10 christos { "LightSkyBlue", 0x87cefa },
497 1.10 christos { "LightSkyBlue1", 0xb0e2ff },
498 1.10 christos { "LightSkyBlue2", 0xa4d3ee },
499 1.10 christos { "LightSkyBlue3", 0x8db6cd },
500 1.10 christos { "LightSkyBlue4", 0x607b8b },
501 1.10 christos { "LightSlateBlue", 0x8470ff },
502 1.10 christos { "LightSlateGray", 0x778899 },
503 1.10 christos { "LightSlateGrey", 0x778899 },
504 1.10 christos { "LightSteelBlue", 0xb0c4de },
505 1.10 christos { "LightSteelBlue1", 0xcae1ff },
506 1.10 christos { "LightSteelBlue2", 0xbcd2ee },
507 1.10 christos { "LightSteelBlue3", 0xa2b5cd },
508 1.10 christos { "LightSteelBlue4", 0x6e7b8b },
509 1.10 christos { "LightYellow", 0xffffe0 },
510 1.10 christos { "LightYellow1", 0xffffe0 },
511 1.10 christos { "LightYellow2", 0xeeeed1 },
512 1.10 christos { "LightYellow3", 0xcdcdb4 },
513 1.10 christos { "LightYellow4", 0x8b8b7a },
514 1.10 christos { "LimeGreen", 0x32cd32 },
515 1.10 christos { "MediumAquamarine", 0x66cdaa },
516 1.10 christos { "MediumBlue", 0x0000cd },
517 1.10 christos { "MediumOrchid", 0xba55d3 },
518 1.10 christos { "MediumOrchid1", 0xe066ff },
519 1.10 christos { "MediumOrchid2", 0xd15fee },
520 1.10 christos { "MediumOrchid3", 0xb452cd },
521 1.10 christos { "MediumOrchid4", 0x7a378b },
522 1.10 christos { "MediumPurple", 0x9370db },
523 1.10 christos { "MediumPurple1", 0xab82ff },
524 1.10 christos { "MediumPurple2", 0x9f79ee },
525 1.10 christos { "MediumPurple3", 0x8968cd },
526 1.10 christos { "MediumPurple4", 0x5d478b },
527 1.10 christos { "MediumSeaGreen", 0x3cb371 },
528 1.10 christos { "MediumSlateBlue", 0x7b68ee },
529 1.10 christos { "MediumSpringGreen", 0x00fa9a },
530 1.10 christos { "MediumTurquoise", 0x48d1cc },
531 1.10 christos { "MediumVioletRed", 0xc71585 },
532 1.10 christos { "MidnightBlue", 0x191970 },
533 1.10 christos { "MintCream", 0xf5fffa },
534 1.10 christos { "MistyRose", 0xffe4e1 },
535 1.10 christos { "MistyRose1", 0xffe4e1 },
536 1.10 christos { "MistyRose2", 0xeed5d2 },
537 1.10 christos { "MistyRose3", 0xcdb7b5 },
538 1.10 christos { "MistyRose4", 0x8b7d7b },
539 1.10 christos { "NavajoWhite", 0xffdead },
540 1.10 christos { "NavajoWhite1", 0xffdead },
541 1.10 christos { "NavajoWhite2", 0xeecfa1 },
542 1.10 christos { "NavajoWhite3", 0xcdb38b },
543 1.10 christos { "NavajoWhite4", 0x8b795e },
544 1.10 christos { "NavyBlue", 0x000080 },
545 1.10 christos { "OldLace", 0xfdf5e6 },
546 1.10 christos { "OliveDrab", 0x6b8e23 },
547 1.10 christos { "OliveDrab1", 0xc0ff3e },
548 1.10 christos { "OliveDrab2", 0xb3ee3a },
549 1.10 christos { "OliveDrab3", 0x9acd32 },
550 1.10 christos { "OliveDrab4", 0x698b22 },
551 1.10 christos { "OrangeRed", 0xff4500 },
552 1.10 christos { "OrangeRed1", 0xff4500 },
553 1.10 christos { "OrangeRed2", 0xee4000 },
554 1.10 christos { "OrangeRed3", 0xcd3700 },
555 1.10 christos { "OrangeRed4", 0x8b2500 },
556 1.10 christos { "PaleGoldenrod", 0xeee8aa },
557 1.10 christos { "PaleGreen", 0x98fb98 },
558 1.10 christos { "PaleGreen1", 0x9aff9a },
559 1.10 christos { "PaleGreen2", 0x90ee90 },
560 1.10 christos { "PaleGreen3", 0x7ccd7c },
561 1.10 christos { "PaleGreen4", 0x548b54 },
562 1.10 christos { "PaleTurquoise", 0xafeeee },
563 1.10 christos { "PaleTurquoise1", 0xbbffff },
564 1.10 christos { "PaleTurquoise2", 0xaeeeee },
565 1.10 christos { "PaleTurquoise3", 0x96cdcd },
566 1.10 christos { "PaleTurquoise4", 0x668b8b },
567 1.10 christos { "PaleVioletRed", 0xdb7093 },
568 1.10 christos { "PaleVioletRed1", 0xff82ab },
569 1.10 christos { "PaleVioletRed2", 0xee799f },
570 1.10 christos { "PaleVioletRed3", 0xcd6889 },
571 1.10 christos { "PaleVioletRed4", 0x8b475d },
572 1.10 christos { "PapayaWhip", 0xffefd5 },
573 1.10 christos { "PeachPuff", 0xffdab9 },
574 1.10 christos { "PeachPuff1", 0xffdab9 },
575 1.10 christos { "PeachPuff2", 0xeecbad },
576 1.10 christos { "PeachPuff3", 0xcdaf95 },
577 1.10 christos { "PeachPuff4", 0x8b7765 },
578 1.10 christos { "PowderBlue", 0xb0e0e6 },
579 1.10 christos { "RebeccaPurple", 0x663399 },
580 1.10 christos { "RosyBrown", 0xbc8f8f },
581 1.10 christos { "RosyBrown1", 0xffc1c1 },
582 1.10 christos { "RosyBrown2", 0xeeb4b4 },
583 1.10 christos { "RosyBrown3", 0xcd9b9b },
584 1.10 christos { "RosyBrown4", 0x8b6969 },
585 1.10 christos { "RoyalBlue", 0x4169e1 },
586 1.10 christos { "RoyalBlue1", 0x4876ff },
587 1.10 christos { "RoyalBlue2", 0x436eee },
588 1.10 christos { "RoyalBlue3", 0x3a5fcd },
589 1.10 christos { "RoyalBlue4", 0x27408b },
590 1.10 christos { "SaddleBrown", 0x8b4513 },
591 1.10 christos { "SandyBrown", 0xf4a460 },
592 1.10 christos { "SeaGreen", 0x2e8b57 },
593 1.10 christos { "SeaGreen1", 0x54ff9f },
594 1.10 christos { "SeaGreen2", 0x4eee94 },
595 1.10 christos { "SeaGreen3", 0x43cd80 },
596 1.10 christos { "SeaGreen4", 0x2e8b57 },
597 1.10 christos { "SkyBlue", 0x87ceeb },
598 1.10 christos { "SkyBlue1", 0x87ceff },
599 1.10 christos { "SkyBlue2", 0x7ec0ee },
600 1.10 christos { "SkyBlue3", 0x6ca6cd },
601 1.10 christos { "SkyBlue4", 0x4a708b },
602 1.10 christos { "SlateBlue", 0x6a5acd },
603 1.10 christos { "SlateBlue1", 0x836fff },
604 1.10 christos { "SlateBlue2", 0x7a67ee },
605 1.10 christos { "SlateBlue3", 0x6959cd },
606 1.10 christos { "SlateBlue4", 0x473c8b },
607 1.10 christos { "SlateGray", 0x708090 },
608 1.10 christos { "SlateGray1", 0xc6e2ff },
609 1.10 christos { "SlateGray2", 0xb9d3ee },
610 1.10 christos { "SlateGray3", 0x9fb6cd },
611 1.10 christos { "SlateGray4", 0x6c7b8b },
612 1.10 christos { "SlateGrey", 0x708090 },
613 1.10 christos { "SpringGreen", 0x00ff7f },
614 1.10 christos { "SpringGreen1", 0x00ff7f },
615 1.10 christos { "SpringGreen2", 0x00ee76 },
616 1.10 christos { "SpringGreen3", 0x00cd66 },
617 1.10 christos { "SpringGreen4", 0x008b45 },
618 1.10 christos { "SteelBlue", 0x4682b4 },
619 1.10 christos { "SteelBlue1", 0x63b8ff },
620 1.10 christos { "SteelBlue2", 0x5cacee },
621 1.10 christos { "SteelBlue3", 0x4f94cd },
622 1.10 christos { "SteelBlue4", 0x36648b },
623 1.10 christos { "VioletRed", 0xd02090 },
624 1.10 christos { "VioletRed1", 0xff3e96 },
625 1.10 christos { "VioletRed2", 0xee3a8c },
626 1.10 christos { "VioletRed3", 0xcd3278 },
627 1.10 christos { "VioletRed4", 0x8b2252 },
628 1.10 christos { "WebGray", 0x808080 },
629 1.10 christos { "WebGreen", 0x008000 },
630 1.10 christos { "WebGrey", 0x808080 },
631 1.10 christos { "WebMaroon", 0x800000 },
632 1.10 christos { "WebPurple", 0x800080 },
633 1.10 christos { "WhiteSmoke", 0xf5f5f5 },
634 1.10 christos { "X11Gray", 0xbebebe },
635 1.10 christos { "X11Green", 0x00ff00 },
636 1.10 christos { "X11Grey", 0xbebebe },
637 1.10 christos { "X11Maroon", 0xb03060 },
638 1.10 christos { "X11Purple", 0xa020f0 },
639 1.10 christos { "YellowGreen", 0x9acd32 },
640 1.10 christos { "alice blue", 0xf0f8ff },
641 1.10 christos { "antique white", 0xfaebd7 },
642 1.10 christos { "aqua", 0x00ffff },
643 1.10 christos { "aquamarine", 0x7fffd4 },
644 1.10 christos { "aquamarine1", 0x7fffd4 },
645 1.10 christos { "aquamarine2", 0x76eec6 },
646 1.10 christos { "aquamarine3", 0x66cdaa },
647 1.10 christos { "aquamarine4", 0x458b74 },
648 1.10 christos { "azure", 0xf0ffff },
649 1.10 christos { "azure1", 0xf0ffff },
650 1.10 christos { "azure2", 0xe0eeee },
651 1.10 christos { "azure3", 0xc1cdcd },
652 1.10 christos { "azure4", 0x838b8b },
653 1.10 christos { "beige", 0xf5f5dc },
654 1.10 christos { "bisque", 0xffe4c4 },
655 1.10 christos { "bisque1", 0xffe4c4 },
656 1.10 christos { "bisque2", 0xeed5b7 },
657 1.10 christos { "bisque3", 0xcdb79e },
658 1.10 christos { "bisque4", 0x8b7d6b },
659 1.10 christos { "black", 0x000000 },
660 1.10 christos { "blanched almond", 0xffebcd },
661 1.10 christos { "blue violet", 0x8a2be2 },
662 1.10 christos { "blue", 0x0000ff },
663 1.10 christos { "blue1", 0x0000ff },
664 1.10 christos { "blue2", 0x0000ee },
665 1.10 christos { "blue3", 0x0000cd },
666 1.10 christos { "blue4", 0x00008b },
667 1.10 christos { "brown", 0xa52a2a },
668 1.10 christos { "brown1", 0xff4040 },
669 1.10 christos { "brown2", 0xee3b3b },
670 1.10 christos { "brown3", 0xcd3333 },
671 1.10 christos { "brown4", 0x8b2323 },
672 1.10 christos { "burlywood", 0xdeb887 },
673 1.10 christos { "burlywood1", 0xffd39b },
674 1.10 christos { "burlywood2", 0xeec591 },
675 1.10 christos { "burlywood3", 0xcdaa7d },
676 1.10 christos { "burlywood4", 0x8b7355 },
677 1.10 christos { "cadet blue", 0x5f9ea0 },
678 1.10 christos { "chartreuse", 0x7fff00 },
679 1.10 christos { "chartreuse1", 0x7fff00 },
680 1.10 christos { "chartreuse2", 0x76ee00 },
681 1.10 christos { "chartreuse3", 0x66cd00 },
682 1.10 christos { "chartreuse4", 0x458b00 },
683 1.10 christos { "chocolate", 0xd2691e },
684 1.10 christos { "chocolate1", 0xff7f24 },
685 1.10 christos { "chocolate2", 0xee7621 },
686 1.10 christos { "chocolate3", 0xcd661d },
687 1.10 christos { "chocolate4", 0x8b4513 },
688 1.10 christos { "coral", 0xff7f50 },
689 1.10 christos { "coral1", 0xff7256 },
690 1.10 christos { "coral2", 0xee6a50 },
691 1.10 christos { "coral3", 0xcd5b45 },
692 1.10 christos { "coral4", 0x8b3e2f },
693 1.10 christos { "cornflower blue", 0x6495ed },
694 1.10 christos { "cornsilk", 0xfff8dc },
695 1.10 christos { "cornsilk1", 0xfff8dc },
696 1.10 christos { "cornsilk2", 0xeee8cd },
697 1.10 christos { "cornsilk3", 0xcdc8b1 },
698 1.10 christos { "cornsilk4", 0x8b8878 },
699 1.10 christos { "crimson", 0xdc143c },
700 1.10 christos { "cyan", 0x00ffff },
701 1.10 christos { "cyan1", 0x00ffff },
702 1.10 christos { "cyan2", 0x00eeee },
703 1.10 christos { "cyan3", 0x00cdcd },
704 1.10 christos { "cyan4", 0x008b8b },
705 1.10 christos { "dark blue", 0x00008b },
706 1.10 christos { "dark cyan", 0x008b8b },
707 1.10 christos { "dark goldenrod", 0xb8860b },
708 1.10 christos { "dark gray", 0xa9a9a9 },
709 1.10 christos { "dark green", 0x006400 },
710 1.10 christos { "dark grey", 0xa9a9a9 },
711 1.10 christos { "dark khaki", 0xbdb76b },
712 1.10 christos { "dark magenta", 0x8b008b },
713 1.10 christos { "dark olive green", 0x556b2f },
714 1.10 christos { "dark orange", 0xff8c00 },
715 1.10 christos { "dark orchid", 0x9932cc },
716 1.10 christos { "dark red", 0x8b0000 },
717 1.10 christos { "dark salmon", 0xe9967a },
718 1.10 christos { "dark sea green", 0x8fbc8f },
719 1.10 christos { "dark slate blue", 0x483d8b },
720 1.10 christos { "dark slate gray", 0x2f4f4f },
721 1.10 christos { "dark slate grey", 0x2f4f4f },
722 1.10 christos { "dark turquoise", 0x00ced1 },
723 1.10 christos { "dark violet", 0x9400d3 },
724 1.10 christos { "deep pink", 0xff1493 },
725 1.10 christos { "deep sky blue", 0x00bfff },
726 1.10 christos { "dim gray", 0x696969 },
727 1.10 christos { "dim grey", 0x696969 },
728 1.10 christos { "dodger blue", 0x1e90ff },
729 1.10 christos { "firebrick", 0xb22222 },
730 1.10 christos { "firebrick1", 0xff3030 },
731 1.10 christos { "firebrick2", 0xee2c2c },
732 1.10 christos { "firebrick3", 0xcd2626 },
733 1.10 christos { "firebrick4", 0x8b1a1a },
734 1.10 christos { "floral white", 0xfffaf0 },
735 1.10 christos { "forest green", 0x228b22 },
736 1.10 christos { "fuchsia", 0xff00ff },
737 1.10 christos { "gainsboro", 0xdcdcdc },
738 1.10 christos { "ghost white", 0xf8f8ff },
739 1.10 christos { "gold", 0xffd700 },
740 1.10 christos { "gold1", 0xffd700 },
741 1.10 christos { "gold2", 0xeec900 },
742 1.10 christos { "gold3", 0xcdad00 },
743 1.10 christos { "gold4", 0x8b7500 },
744 1.10 christos { "goldenrod", 0xdaa520 },
745 1.10 christos { "goldenrod1", 0xffc125 },
746 1.10 christos { "goldenrod2", 0xeeb422 },
747 1.10 christos { "goldenrod3", 0xcd9b1d },
748 1.10 christos { "goldenrod4", 0x8b6914 },
749 1.10 christos { "green yellow", 0xadff2f },
750 1.10 christos { "green", 0x00ff00 },
751 1.10 christos { "green1", 0x00ff00 },
752 1.10 christos { "green2", 0x00ee00 },
753 1.10 christos { "green3", 0x00cd00 },
754 1.10 christos { "green4", 0x008b00 },
755 1.10 christos { "honeydew", 0xf0fff0 },
756 1.10 christos { "honeydew1", 0xf0fff0 },
757 1.10 christos { "honeydew2", 0xe0eee0 },
758 1.10 christos { "honeydew3", 0xc1cdc1 },
759 1.10 christos { "honeydew4", 0x838b83 },
760 1.10 christos { "hot pink", 0xff69b4 },
761 1.10 christos { "indian red", 0xcd5c5c },
762 1.10 christos { "indigo", 0x4b0082 },
763 1.10 christos { "ivory", 0xfffff0 },
764 1.10 christos { "ivory1", 0xfffff0 },
765 1.10 christos { "ivory2", 0xeeeee0 },
766 1.10 christos { "ivory3", 0xcdcdc1 },
767 1.10 christos { "ivory4", 0x8b8b83 },
768 1.10 christos { "khaki", 0xf0e68c },
769 1.10 christos { "khaki1", 0xfff68f },
770 1.10 christos { "khaki2", 0xeee685 },
771 1.10 christos { "khaki3", 0xcdc673 },
772 1.10 christos { "khaki4", 0x8b864e },
773 1.10 christos { "lavender blush", 0xfff0f5 },
774 1.10 christos { "lavender", 0xe6e6fa },
775 1.10 christos { "lawn green", 0x7cfc00 },
776 1.10 christos { "lemon chiffon", 0xfffacd },
777 1.10 christos { "light blue", 0xadd8e6 },
778 1.10 christos { "light coral", 0xf08080 },
779 1.10 christos { "light cyan", 0xe0ffff },
780 1.10 christos { "light goldenrod yellow", 0xfafad2 },
781 1.10 christos { "light goldenrod", 0xeedd82 },
782 1.10 christos { "light gray", 0xd3d3d3 },
783 1.10 christos { "light green", 0x90ee90 },
784 1.10 christos { "light grey", 0xd3d3d3 },
785 1.10 christos { "light pink", 0xffb6c1 },
786 1.10 christos { "light salmon", 0xffa07a },
787 1.10 christos { "light sea green", 0x20b2aa },
788 1.10 christos { "light sky blue", 0x87cefa },
789 1.10 christos { "light slate blue", 0x8470ff },
790 1.10 christos { "light slate gray", 0x778899 },
791 1.10 christos { "light slate grey", 0x778899 },
792 1.10 christos { "light steel blue", 0xb0c4de },
793 1.10 christos { "light yellow", 0xffffe0 },
794 1.10 christos { "lime green", 0x32cd32 },
795 1.10 christos { "lime", 0x00ff00 },
796 1.10 christos { "linen", 0xfaf0e6 },
797 1.10 christos { "magenta", 0xff00ff },
798 1.10 christos { "magenta1", 0xff00ff },
799 1.10 christos { "magenta2", 0xee00ee },
800 1.10 christos { "magenta3", 0xcd00cd },
801 1.10 christos { "magenta4", 0x8b008b },
802 1.10 christos { "maroon", 0xb03060 },
803 1.10 christos { "maroon1", 0xff34b3 },
804 1.10 christos { "maroon2", 0xee30a7 },
805 1.10 christos { "maroon3", 0xcd2990 },
806 1.10 christos { "maroon4", 0x8b1c62 },
807 1.10 christos { "medium aquamarine", 0x66cdaa },
808 1.10 christos { "medium blue", 0x0000cd },
809 1.10 christos { "medium orchid", 0xba55d3 },
810 1.10 christos { "medium purple", 0x9370db },
811 1.10 christos { "medium sea green", 0x3cb371 },
812 1.10 christos { "medium slate blue", 0x7b68ee },
813 1.10 christos { "medium spring green", 0x00fa9a },
814 1.10 christos { "medium turquoise", 0x48d1cc },
815 1.10 christos { "medium violet red", 0xc71585 },
816 1.10 christos { "midnight blue", 0x191970 },
817 1.10 christos { "mint cream", 0xf5fffa },
818 1.10 christos { "misty rose", 0xffe4e1 },
819 1.10 christos { "moccasin", 0xffe4b5 },
820 1.10 christos { "navajo white", 0xffdead },
821 1.10 christos { "navy blue", 0x000080 },
822 1.10 christos { "navy", 0x000080 },
823 1.10 christos { "old lace", 0xfdf5e6 },
824 1.10 christos { "olive drab", 0x6b8e23 },
825 1.10 christos { "olive", 0x808000 },
826 1.10 christos { "orange red", 0xff4500 },
827 1.10 christos { "orange", 0xffa500 },
828 1.10 christos { "orange1", 0xffa500 },
829 1.10 christos { "orange2", 0xee9a00 },
830 1.10 christos { "orange3", 0xcd8500 },
831 1.10 christos { "orange4", 0x8b5a00 },
832 1.10 christos { "orchid", 0xda70d6 },
833 1.10 christos { "orchid1", 0xff83fa },
834 1.10 christos { "orchid2", 0xee7ae9 },
835 1.10 christos { "orchid3", 0xcd69c9 },
836 1.10 christos { "orchid4", 0x8b4789 },
837 1.10 christos { "pale goldenrod", 0xeee8aa },
838 1.10 christos { "pale green", 0x98fb98 },
839 1.10 christos { "pale turquoise", 0xafeeee },
840 1.10 christos { "pale violet red", 0xdb7093 },
841 1.10 christos { "papaya whip", 0xffefd5 },
842 1.10 christos { "peach puff", 0xffdab9 },
843 1.10 christos { "peru", 0xcd853f },
844 1.10 christos { "pink", 0xffc0cb },
845 1.10 christos { "pink1", 0xffb5c5 },
846 1.10 christos { "pink2", 0xeea9b8 },
847 1.10 christos { "pink3", 0xcd919e },
848 1.10 christos { "pink4", 0x8b636c },
849 1.10 christos { "plum", 0xdda0dd },
850 1.10 christos { "plum1", 0xffbbff },
851 1.10 christos { "plum2", 0xeeaeee },
852 1.10 christos { "plum3", 0xcd96cd },
853 1.10 christos { "plum4", 0x8b668b },
854 1.10 christos { "powder blue", 0xb0e0e6 },
855 1.10 christos { "purple", 0xa020f0 },
856 1.10 christos { "purple1", 0x9b30ff },
857 1.10 christos { "purple2", 0x912cee },
858 1.10 christos { "purple3", 0x7d26cd },
859 1.10 christos { "purple4", 0x551a8b },
860 1.10 christos { "rebecca purple", 0x663399 },
861 1.10 christos { "red", 0xff0000 },
862 1.10 christos { "red1", 0xff0000 },
863 1.10 christos { "red2", 0xee0000 },
864 1.10 christos { "red3", 0xcd0000 },
865 1.10 christos { "red4", 0x8b0000 },
866 1.10 christos { "rosy brown", 0xbc8f8f },
867 1.10 christos { "royal blue", 0x4169e1 },
868 1.10 christos { "saddle brown", 0x8b4513 },
869 1.10 christos { "salmon", 0xfa8072 },
870 1.10 christos { "salmon1", 0xff8c69 },
871 1.10 christos { "salmon2", 0xee8262 },
872 1.10 christos { "salmon3", 0xcd7054 },
873 1.10 christos { "salmon4", 0x8b4c39 },
874 1.10 christos { "sandy brown", 0xf4a460 },
875 1.10 christos { "sea green", 0x2e8b57 },
876 1.10 christos { "seashell", 0xfff5ee },
877 1.10 christos { "seashell1", 0xfff5ee },
878 1.10 christos { "seashell2", 0xeee5de },
879 1.10 christos { "seashell3", 0xcdc5bf },
880 1.10 christos { "seashell4", 0x8b8682 },
881 1.10 christos { "sienna", 0xa0522d },
882 1.10 christos { "sienna1", 0xff8247 },
883 1.10 christos { "sienna2", 0xee7942 },
884 1.10 christos { "sienna3", 0xcd6839 },
885 1.10 christos { "sienna4", 0x8b4726 },
886 1.10 christos { "silver", 0xc0c0c0 },
887 1.10 christos { "sky blue", 0x87ceeb },
888 1.10 christos { "slate blue", 0x6a5acd },
889 1.10 christos { "slate gray", 0x708090 },
890 1.10 christos { "slate grey", 0x708090 },
891 1.10 christos { "snow", 0xfffafa },
892 1.10 christos { "snow1", 0xfffafa },
893 1.10 christos { "snow2", 0xeee9e9 },
894 1.10 christos { "snow3", 0xcdc9c9 },
895 1.10 christos { "snow4", 0x8b8989 },
896 1.10 christos { "spring green", 0x00ff7f },
897 1.10 christos { "steel blue", 0x4682b4 },
898 1.10 christos { "tan", 0xd2b48c },
899 1.10 christos { "tan1", 0xffa54f },
900 1.10 christos { "tan2", 0xee9a49 },
901 1.10 christos { "tan3", 0xcd853f },
902 1.10 christos { "tan4", 0x8b5a2b },
903 1.10 christos { "teal", 0x008080 },
904 1.10 christos { "thistle", 0xd8bfd8 },
905 1.10 christos { "thistle1", 0xffe1ff },
906 1.10 christos { "thistle2", 0xeed2ee },
907 1.10 christos { "thistle3", 0xcdb5cd },
908 1.10 christos { "thistle4", 0x8b7b8b },
909 1.10 christos { "tomato", 0xff6347 },
910 1.10 christos { "tomato1", 0xff6347 },
911 1.10 christos { "tomato2", 0xee5c42 },
912 1.10 christos { "tomato3", 0xcd4f39 },
913 1.10 christos { "tomato4", 0x8b3626 },
914 1.10 christos { "turquoise", 0x40e0d0 },
915 1.10 christos { "turquoise1", 0x00f5ff },
916 1.10 christos { "turquoise2", 0x00e5ee },
917 1.10 christos { "turquoise3", 0x00c5cd },
918 1.10 christos { "turquoise4", 0x00868b },
919 1.10 christos { "violet red", 0xd02090 },
920 1.10 christos { "violet", 0xee82ee },
921 1.10 christos { "web gray", 0x808080 },
922 1.10 christos { "web green", 0x008000 },
923 1.10 christos { "web grey", 0x808080 },
924 1.10 christos { "web maroon", 0x800000 },
925 1.10 christos { "web purple", 0x800080 },
926 1.10 christos { "wheat", 0xf5deb3 },
927 1.10 christos { "wheat1", 0xffe7ba },
928 1.10 christos { "wheat2", 0xeed8ae },
929 1.10 christos { "wheat3", 0xcdba96 },
930 1.10 christos { "wheat4", 0x8b7e66 },
931 1.10 christos { "white smoke", 0xf5f5f5 },
932 1.10 christos { "white", 0xffffff },
933 1.10 christos { "x11 gray", 0xbebebe },
934 1.10 christos { "x11 green", 0x00ff00 },
935 1.10 christos { "x11 grey", 0xbebebe },
936 1.10 christos { "x11 maroon", 0xb03060 },
937 1.10 christos { "x11 purple", 0xa020f0 },
938 1.10 christos { "yellow green", 0x9acd32 },
939 1.10 christos { "yellow", 0xffff00 },
940 1.10 christos { "yellow1", 0xffff00 },
941 1.10 christos { "yellow2", 0xeeee00 },
942 1.10 christos { "yellow3", 0xcdcd00 },
943 1.10 christos { "yellow4", 0x8b8b00 }
944 1.10 christos };
945 1.10 christos u_int i;
946 1.10 christos int c;
947 1.10 christos
948 1.10 christos if (strncmp(name, "grey", 4) == 0 || strncmp(name, "gray", 4) == 0) {
949 1.10 christos if (!isdigit((u_char)name[4]))
950 1.10 christos return (0xbebebe|COLOUR_FLAG_RGB);
951 1.10 christos c = round(2.55 * atoi(name + 4));
952 1.10 christos if (c < 0 || c > 255)
953 1.10 christos return (-1);
954 1.10 christos return (colour_join_rgb(c, c, c));
955 1.10 christos }
956 1.10 christos for (i = 0; i < nitems(colours); i++) {
957 1.10 christos if (strcasecmp(colours[i].name, name) == 0)
958 1.10 christos return (colours[i].c|COLOUR_FLAG_RGB);
959 1.10 christos }
960 1.10 christos return (-1);
961 1.10 christos }
962 1.11 wiz
963 1.12 wiz /* Parse colour from an X11 string. */
964 1.12 wiz int
965 1.12 wiz colour_parseX11(const char *p)
966 1.12 wiz {
967 1.12 wiz double c, m, y, k = 0;
968 1.12 wiz u_int r, g, b;
969 1.12 wiz size_t len = strlen(p);
970 1.12 wiz int colour = -1;
971 1.12 wiz char *copy;
972 1.12 wiz
973 1.12 wiz if ((len == 12 && sscanf(p, "rgb:%02x/%02x/%02x", &r, &g, &b) == 3) ||
974 1.12 wiz (len == 7 && sscanf(p, "#%02x%02x%02x", &r, &g, &b) == 3) ||
975 1.12 wiz sscanf(p, "%d,%d,%d", &r, &g, &b) == 3)
976 1.12 wiz colour = colour_join_rgb(r, g, b);
977 1.12 wiz else if ((len == 18 &&
978 1.12 wiz sscanf(p, "rgb:%04x/%04x/%04x", &r, &g, &b) == 3) ||
979 1.12 wiz (len == 13 && sscanf(p, "#%04x%04x%04x", &r, &g, &b) == 3))
980 1.12 wiz colour = colour_join_rgb(r >> 8, g >> 8, b >> 8);
981 1.12 wiz else if ((sscanf(p, "cmyk:%lf/%lf/%lf/%lf", &c, &m, &y, &k) == 4 ||
982 1.12 wiz sscanf(p, "cmy:%lf/%lf/%lf", &c, &m, &y) == 3) &&
983 1.12 wiz c >= 0 && c <= 1 && m >= 0 && m <= 1 &&
984 1.12 wiz y >= 0 && y <= 1 && k >= 0 && k <= 1) {
985 1.12 wiz colour = colour_join_rgb(
986 1.12 wiz (1 - c) * (1 - k) * 255,
987 1.12 wiz (1 - m) * (1 - k) * 255,
988 1.12 wiz (1 - y) * (1 - k) * 255);
989 1.12 wiz } else {
990 1.12 wiz while (len != 0 && *p == ' ') {
991 1.12 wiz p++;
992 1.12 wiz len--;
993 1.12 wiz }
994 1.12 wiz while (len != 0 && p[len - 1] == ' ')
995 1.12 wiz len--;
996 1.12 wiz copy = xstrndup(p, len);
997 1.12 wiz colour = colour_byname(copy);
998 1.12 wiz free(copy);
999 1.12 wiz }
1000 1.12 wiz log_debug("%s: %s = %s", __func__, p, colour_tostring(colour));
1001 1.12 wiz return (colour);
1002 1.12 wiz }
1003 1.12 wiz
1004 1.11 wiz /* Initialize palette. */
1005 1.11 wiz void
1006 1.11 wiz colour_palette_init(struct colour_palette *p)
1007 1.11 wiz {
1008 1.11 wiz p->fg = 8;
1009 1.11 wiz p->bg = 8;
1010 1.11 wiz p->palette = NULL;
1011 1.11 wiz p->default_palette = NULL;
1012 1.11 wiz }
1013 1.11 wiz
1014 1.11 wiz /* Clear palette. */
1015 1.11 wiz void
1016 1.11 wiz colour_palette_clear(struct colour_palette *p)
1017 1.11 wiz {
1018 1.11 wiz if (p != NULL) {
1019 1.11 wiz p->fg = 8;
1020 1.11 wiz p->bg = 8;
1021 1.11 wiz free(p->palette);
1022 1.11 wiz p->palette = NULL;
1023 1.11 wiz }
1024 1.11 wiz }
1025 1.11 wiz
1026 1.11 wiz /* Free a palette. */
1027 1.11 wiz void
1028 1.11 wiz colour_palette_free(struct colour_palette *p)
1029 1.11 wiz {
1030 1.11 wiz if (p != NULL) {
1031 1.11 wiz free(p->palette);
1032 1.11 wiz p->palette = NULL;
1033 1.11 wiz free(p->default_palette);
1034 1.11 wiz p->default_palette = NULL;
1035 1.11 wiz }
1036 1.11 wiz }
1037 1.11 wiz
1038 1.11 wiz /* Get a colour from a palette. */
1039 1.11 wiz int
1040 1.11 wiz colour_palette_get(struct colour_palette *p, int c)
1041 1.11 wiz {
1042 1.11 wiz if (p == NULL)
1043 1.11 wiz return (-1);
1044 1.11 wiz
1045 1.11 wiz if (c >= 90 && c <= 97)
1046 1.11 wiz c = 8 + c - 90;
1047 1.11 wiz else if (c & COLOUR_FLAG_256)
1048 1.11 wiz c &= ~COLOUR_FLAG_256;
1049 1.11 wiz else if (c >= 8)
1050 1.11 wiz return (-1);
1051 1.11 wiz
1052 1.11 wiz if (p->palette != NULL && p->palette[c] != -1)
1053 1.11 wiz return (p->palette[c]);
1054 1.11 wiz if (p->default_palette != NULL && p->default_palette[c] != -1)
1055 1.11 wiz return (p->default_palette[c]);
1056 1.11 wiz return (-1);
1057 1.11 wiz }
1058 1.11 wiz
1059 1.11 wiz /* Set a colour in a palette. */
1060 1.11 wiz int
1061 1.11 wiz colour_palette_set(struct colour_palette *p, int n, int c)
1062 1.11 wiz {
1063 1.11 wiz u_int i;
1064 1.11 wiz
1065 1.11 wiz if (p == NULL || n > 255)
1066 1.11 wiz return (0);
1067 1.11 wiz
1068 1.11 wiz if (c == -1 && p->palette == NULL)
1069 1.11 wiz return (0);
1070 1.11 wiz
1071 1.11 wiz if (c != -1 && p->palette == NULL) {
1072 1.11 wiz if (p->palette == NULL)
1073 1.11 wiz p->palette = xcalloc(256, sizeof *p->palette);
1074 1.11 wiz for (i = 0; i < 256; i++)
1075 1.11 wiz p->palette[i] = -1;
1076 1.11 wiz }
1077 1.11 wiz p->palette[n] = c;
1078 1.11 wiz return (1);
1079 1.11 wiz }
1080 1.11 wiz
1081 1.11 wiz /* Build palette defaults from an option. */
1082 1.11 wiz void
1083 1.11 wiz colour_palette_from_option(struct colour_palette *p, struct options *oo)
1084 1.11 wiz {
1085 1.11 wiz struct options_entry *o;
1086 1.11 wiz struct options_array_item *a;
1087 1.11 wiz u_int i, n;
1088 1.11 wiz int c;
1089 1.11 wiz
1090 1.11 wiz if (p == NULL)
1091 1.11 wiz return;
1092 1.11 wiz
1093 1.11 wiz o = options_get(oo, "pane-colours");
1094 1.11 wiz if ((a = options_array_first(o)) == NULL) {
1095 1.11 wiz if (p->default_palette != NULL) {
1096 1.11 wiz free(p->default_palette);
1097 1.11 wiz p->default_palette = NULL;
1098 1.11 wiz }
1099 1.11 wiz return;
1100 1.11 wiz }
1101 1.11 wiz if (p->default_palette == NULL)
1102 1.11 wiz p->default_palette = xcalloc(256, sizeof *p->default_palette);
1103 1.11 wiz for (i = 0; i < 256; i++)
1104 1.11 wiz p->default_palette[i] = -1;
1105 1.11 wiz while (a != NULL) {
1106 1.11 wiz n = options_array_item_index(a);
1107 1.11 wiz if (n < 256) {
1108 1.11 wiz c = options_array_item_value(a)->number;
1109 1.11 wiz p->default_palette[n] = c;
1110 1.11 wiz }
1111 1.11 wiz a = options_array_next(a);
1112 1.11 wiz }
1113 1.11 wiz }
1114