Coverage Report

Created: 2025-07-12 06:33

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