29static const struct key {
34 {
"aliceblue", 0xf0f8ff},
35 {
"antiquewhite", 0xfaebd7},
39 {
"aquamarine", 0x7fffd4},
42 {
"bisque", 0xffe4c4},
46 {
"blanchedalmond", 0xffebcd},
50 {
"blueviolet", 0x8a2be2},
52 {
"burlywood", 0xdeb887},
53 {
"cadetblue", 0x5f9ea0},
54 {
"chartreuse", 0x7fff00},
55 {
"chocolate", 0xd2691e},
57 {
"cornflowerblue", 0x6495ed},
58 {
"cornsilk", 0xfff8dc},
59 {
"crimson", 0xdc1436},
61 {
"darkblue", 0x00008b},
62 {
"darkcyan", 0x008b8b},
63 {
"darkgoldenrod", 0xb8860b},
64 {
"darkgray", 0xa9a9a9},
65 {
"darkgreen", 0x006400},
66 {
"darkgrey", 0xa9a9a9},
67 {
"darkkhaki", 0xbdb76b},
68 {
"darkmagenta", 0x8b008b},
69 {
"darkolivegreen", 0x556b2f},
70 {
"darkorange", 0xff8c00},
71 {
"darkorchid", 0x9932cc},
72 {
"darkred", 0x8b0000},
73 {
"darksalmon", 0xe9967a},
74 {
"darkseagreen", 0x8fbc8f},
75 {
"darkslateblue", 0x483d8b},
76 {
"darkslategray", 0x2f4f4f},
77 {
"darkslategrey", 0x2f4f4f},
78 {
"darkturquoise", 0x00ced1},
79 {
"darkviolet", 0x9400d3},
80 {
"deeppink", 0xff1493},
81 {
"deepskyblue", 0x00bfff},
82 {
"dimgray", 0x696969},
83 {
"dimgrey", 0x696969},
84 {
"dodgerblue", 0x1e90ff},
85 {
"firebrick", 0xb22222},
86 {
"floralwhite", 0xfffaf0},
87 {
"forestgreen", 0x228b22},
89 {
"fuchsia", 0xff00ff},
91 {
"gainsboro", 0xdcdcdc},
92 {
"ghostwhite", 0xf8f8ff},
94 {
"goldenrod", 0xdaa520},
99 {
"greenyellow", 0xadff2f},
101 {
"honeydew", 0xf0fff0},
102 {
"hotpink", 0xff69b4},
103 {
"indianred", 0xcd5c5c},
104 {
"indigo", 0x4b0082},
105 {
"ivory", 0xfffff0},
106 {
"khaki", 0xf0e68c},
107 {
"lavender", 0xe6e6fa},
108 {
"lavenderblush", 0xfff0f5},
109 {
"lawngreen", 0x7cfc00},
110 {
"lemonchiffon", 0xfffacd},
111 {
"lightblue", 0xadd8e6},
112 {
"lightcoral", 0xf08080},
113 {
"lightcyan", 0xe0ffff},
114 {
"lightgoldenrodyellow", 0xfafad2},
115 {
"lightgray", 0xd3d3d3},
116 {
"lightgreen", 0x90ee90},
117 {
"lightgrey", 0xd3d3d3},
118 {
"lightpink", 0xffb6c1},
119 {
"lightsalmon", 0xffa07a},
120 {
"lightseagreen", 0x20b2aa},
121 {
"lightskyblue", 0x87cefa},
122 {
"lightslategray", 0x778899},
123 {
"lightslategrey", 0x778899},
124 {
"lightsteelblue", 0xb0c4de},
125 {
"lightyellow", 0xffffe0},
129 {
"limegreen", 0x32cd32},
130 {
"linen", 0xfaf0e6},
131 {
"magenta", 0xff00ff},
133 {
"maroon", 0x800000},
135 {
"mediumaquamarine", 0x66cdaa},
136 {
"mediumblue", 0x0000cd},
137 {
"mediumorchid", 0xba55d3},
138 {
"mediumpurple", 0x9370db},
139 {
"mediumseagreen", 0x3cb371},
140 {
"mediumslateblue", 0x7b68ee},
141 {
"mediumspringgreen", 0x00fa9a},
142 {
"mediumturquoise", 0x48d1cc},
143 {
"mediumvioletred", 0xc71585},
144 {
"midnightblue", 0x191970},
145 {
"mintcream", 0xf5fffa},
146 {
"mistyrose", 0xffe4e1},
147 {
"moccasin", 0xffe4b5},
148 {
"navajowhite", 0xffdead},
152 {
"oldlace", 0xfdf5e6},
154 {
"olive", 0x808000},
156 {
"olivedrab", 0x6b8e23},
157 {
"orange", 0xffa500},
158 {
"orangered", 0xff4500},
159 {
"orchid", 0xda70d6},
160 {
"palegoldenrod", 0xeee8aa},
161 {
"palegreen", 0x98fb98},
162 {
"paleturquoise", 0xafeeee},
163 {
"palevioletred", 0xdb7093},
164 {
"papayawhip", 0xffefd5},
165 {
"peachpuff", 0xffdab9},
169 {
"powderblue", 0xb0e0e6},
171 {
"purple", 0x800080},
174 {
"rosybrown", 0xbc8f8f},
175 {
"royalblue", 0x4169e1},
176 {
"saddlebrown", 0x8b4513},
177 {
"salmon", 0xfa8072},
178 {
"sandybrown", 0xf4a460},
179 {
"seagreen", 0x2e8b57},
180 {
"seashell", 0xfff5ee},
181 {
"sienna", 0xa0522d},
183 {
"silver", 0xc0c0c0},
185 {
"skyblue", 0x87ceeb},
186 {
"slateblue", 0x6a5acd},
187 {
"slategray", 0x708090},
188 {
"slategrey", 0x708090},
190 {
"springgreen", 0x00ff7f},
191 {
"steelblue", 0x4682b4},
196 {
"thistle", 0xd8bfd8},
197 {
"tomato", 0xff6347},
198 {
"turquoise", 0x40e0d0},
199 {
"violet", 0xee82ee},
200 {
"wheat", 0xf5deb3},
202 {
"white", 0xffffff},
204 {
"whitesmoke", 0xf5f5f5},
206 {
"yellow", 0xffff00},
208 {
"yellowgreen", 0x9acd32},
212#define NCOLORS (sizeof(color_keyword) / sizeof(color_keyword[0]))
227 ret_color = strtol(s, &tail, 16);
230 else if (tail - s == 3) {
232 ret_color = ((ret_color & 0xf00) << 12) | ((ret_color & 0xf00) << 8) |
233 ((ret_color & 0x0f0) << 8) | ((ret_color & 0x0f0) << 4) |
234 ((ret_color & 0x00f) << 4) | ((ret_color & 0x00f) << 0);
236 ret_color = default_color;
263 int ret, low, mid, high, st = 1;
266 for (cp = str;
dIsspace(*cp); cp++);
268 ret_color = default_color;
272 }
else if (*cp ==
'0' && (cp[1] ==
'x' || cp[1] ==
'X') ) {
280 while (low <= high) {
281 mid = (low + high) / 2;
300 _MSG(
"color string: %s\n", str);
301 _MSG(
"color : %X\n", ret_color);
311static int Color_distance(
long c1,
long c2)
313 return (labs((c1 & 0x0000ff) - (c2 & 0x0000ff)) +
314 labs(((c1 & 0x00ff00) - (c2 & 0x00ff00)) >> 8) +
315 labs(((c1 & 0xff0000) - (c2 & 0xff0000)) >> 16)) / 75;
324 return (labs((c1 & 0x0000ff) - (c2 & 0x0000ff)) >= 0x000060) +
325 (labs((c1 & 0x00ff00) - (c2 & 0x00ff00)) >= 0x006000) +
326 (labs((c1 & 0xff0000) - (c2 & 0xff0000)) >= 0x600000);
334 return (labs((c1 & 0x0000ff) - (c2 & 0x0000ff)) >= 0x000040) +
335 (labs((c1 & 0x00ff00) - (c2 & 0x00ff00)) >= 0x004000) +
336 (labs((c1 & 0xff0000) - (c2 & 0xff0000)) >= 0x400000);
346 int32_t C_txt, int32_t C_lnk, int32_t C_bg)
349 static int32_t v[] = {0x000000, 0x800080, 0x008b8b, 0x8b008b, 0x808000,
351 0x8b0000, 0xff7f50, 0x000000};
352 int v_size =
sizeof(v) /
sizeof(v[0]);
353 int i, max_i, score, max_score, d_bg, d_txt, d_lnk;
360 max_i = max_score = 0;
361 for (i = 0; i < v_size; ++i) {
362 _MSG(
"a_Color_vc: [%d]%.6x: %d %d %d\n", i, v[i],
373 score = (d_bg >= 2 ? 4 : 2 * d_bg) +
374 (d_txt + d_lnk >= 2 ? 2 : d_txt + d_lnk) +
380 }
else if (score > max_score) {
static int Color_distance2(long c1, long c2)
static int Color_distance3(long c1, long c2)
static int32_t Color_parse_hex(const char *s, int32_t default_color, int *err)
Parse a color in hex (RRGGBB) or (RGB).
int32_t a_Color_parse(const char *str, int32_t default_color, int *err)
Parse a color string.
static const struct key color_keyword[]
int32_t a_Color_vc(int32_t candidate, int32_t C_txt, int32_t C_lnk, int32_t C_bg)
Return a suitable "visited link" color.
int dStrAsciiCasecmp(const char *s1, const char *s2)
static int dIsspace(unsigned char c)