Coverage Report

Created: 2024-09-11 06:44

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