28static const struct key {
33 {
"aliceblue", 0xf0f8ff},
34 {
"antiquewhite", 0xfaebd7},
38 {
"aquamarine", 0x7fffd4},
41 {
"bisque", 0xffe4c4},
45 {
"blanchedalmond", 0xffebcd},
49 {
"blueviolet", 0x8a2be2},
51 {
"burlywood", 0xdeb887},
52 {
"cadetblue", 0x5f9ea0},
53 {
"chartreuse", 0x7fff00},
54 {
"chocolate", 0xd2691e},
56 {
"cornflowerblue", 0x6495ed},
57 {
"cornsilk", 0xfff8dc},
58 {
"crimson", 0xdc1436},
60 {
"darkblue", 0x00008b},
61 {
"darkcyan", 0x008b8b},
62 {
"darkgoldenrod", 0xb8860b},
63 {
"darkgray", 0xa9a9a9},
64 {
"darkgreen", 0x006400},
65 {
"darkgrey", 0xa9a9a9},
66 {
"darkkhaki", 0xbdb76b},
67 {
"darkmagenta", 0x8b008b},
68 {
"darkolivegreen", 0x556b2f},
69 {
"darkorange", 0xff8c00},
70 {
"darkorchid", 0x9932cc},
71 {
"darkred", 0x8b0000},
72 {
"darksalmon", 0xe9967a},
73 {
"darkseagreen", 0x8fbc8f},
74 {
"darkslateblue", 0x483d8b},
75 {
"darkslategray", 0x2f4f4f},
76 {
"darkslategrey", 0x2f4f4f},
77 {
"darkturquoise", 0x00ced1},
78 {
"darkviolet", 0x9400d3},
79 {
"deeppink", 0xff1493},
80 {
"deepskyblue", 0x00bfff},
81 {
"dimgray", 0x696969},
82 {
"dimgrey", 0x696969},
83 {
"dodgerblue", 0x1e90ff},
84 {
"firebrick", 0xb22222},
85 {
"floralwhite", 0xfffaf0},
86 {
"forestgreen", 0x228b22},
88 {
"fuchsia", 0xff00ff},
90 {
"gainsboro", 0xdcdcdc},
91 {
"ghostwhite", 0xf8f8ff},
93 {
"goldenrod", 0xdaa520},
98 {
"greenyellow", 0xadff2f},
100 {
"honeydew", 0xf0fff0},
101 {
"hotpink", 0xff69b4},
102 {
"indianred", 0xcd5c5c},
103 {
"indigo", 0x4b0082},
104 {
"ivory", 0xfffff0},
105 {
"khaki", 0xf0e68c},
106 {
"lavender", 0xe6e6fa},
107 {
"lavenderblush", 0xfff0f5},
108 {
"lawngreen", 0x7cfc00},
109 {
"lemonchiffon", 0xfffacd},
110 {
"lightblue", 0xadd8e6},
111 {
"lightcoral", 0xf08080},
112 {
"lightcyan", 0xe0ffff},
113 {
"lightgoldenrodyellow", 0xfafad2},
114 {
"lightgray", 0xd3d3d3},
115 {
"lightgreen", 0x90ee90},
116 {
"lightgrey", 0xd3d3d3},
117 {
"lightpink", 0xffb6c1},
118 {
"lightsalmon", 0xffa07a},
119 {
"lightseagreen", 0x20b2aa},
120 {
"lightskyblue", 0x87cefa},
121 {
"lightslategray", 0x778899},
122 {
"lightslategrey", 0x778899},
123 {
"lightsteelblue", 0xb0c4de},
124 {
"lightyellow", 0xffffe0},
128 {
"limegreen", 0x32cd32},
129 {
"linen", 0xfaf0e6},
130 {
"magenta", 0xff00ff},
132 {
"maroon", 0x800000},
134 {
"mediumaquamarine", 0x66cdaa},
135 {
"mediumblue", 0x0000cd},
136 {
"mediumorchid", 0xba55d3},
137 {
"mediumpurple", 0x9370db},
138 {
"mediumseagreen", 0x3cb371},
139 {
"mediumslateblue", 0x7b68ee},
140 {
"mediumspringgreen", 0x00fa9a},
141 {
"mediumturquoise", 0x48d1cc},
142 {
"mediumvioletred", 0xc71585},
143 {
"midnightblue", 0x191970},
144 {
"mintcream", 0xf5fffa},
145 {
"mistyrose", 0xffe4e1},
146 {
"moccasin", 0xffe4b5},
147 {
"navajowhite", 0xffdead},
151 {
"oldlace", 0xfdf5e6},
153 {
"olive", 0x808000},
155 {
"olivedrab", 0x6b8e23},
156 {
"orange", 0xffa500},
157 {
"orangered", 0xff4500},
158 {
"orchid", 0xda70d6},
159 {
"palegoldenrod", 0xeee8aa},
160 {
"palegreen", 0x98fb98},
161 {
"paleturquoise", 0xafeeee},
162 {
"palevioletred", 0xdb7093},
163 {
"papayawhip", 0xffefd5},
164 {
"peachpuff", 0xffdab9},
168 {
"powderblue", 0xb0e0e6},
170 {
"purple", 0x800080},
173 {
"rosybrown", 0xbc8f8f},
174 {
"royalblue", 0x4169e1},
175 {
"saddlebrown", 0x8b4513},
176 {
"salmon", 0xfa8072},
177 {
"sandybrown", 0xf4a460},
178 {
"seagreen", 0x2e8b57},
179 {
"seashell", 0xfff5ee},
180 {
"sienna", 0xa0522d},
182 {
"silver", 0xc0c0c0},
184 {
"skyblue", 0x87ceeb},
185 {
"slateblue", 0x6a5acd},
186 {
"slategray", 0x708090},
187 {
"slategrey", 0x708090},
189 {
"springgreen", 0x00ff7f},
190 {
"steelblue", 0x4682b4},
195 {
"thistle", 0xd8bfd8},
196 {
"tomato", 0xff6347},
197 {
"turquoise", 0x40e0d0},
198 {
"violet", 0xee82ee},
199 {
"wheat", 0xf5deb3},
201 {
"white", 0xffffff},
203 {
"whitesmoke", 0xf5f5f5},
205 {
"yellow", 0xffff00},
207 {
"yellowgreen", 0x9acd32},
211#define NCOLORS (sizeof(color_keyword) / sizeof(color_keyword[0]))
226 ret_color = strtol(s, &tail, 16);
229 else if (tail - s == 3) {
231 ret_color = ((ret_color & 0xf00) << 12) | ((ret_color & 0xf00) << 8) |
232 ((ret_color & 0x0f0) << 8) | ((ret_color & 0x0f0) << 4) |
233 ((ret_color & 0x00f) << 4) | ((ret_color & 0x00f) << 0);
235 ret_color = default_color;
262 int ret, low, mid, high, st = 1;
265 for (cp = str;
dIsspace(*cp); cp++);
267 ret_color = default_color;
271 }
else if (*cp ==
'0' && (cp[1] ==
'x' || cp[1] ==
'X') ) {
279 while (low <= high) {
280 mid = (low + high) / 2;
299 _MSG(
"color string: %s\n", str);
300 _MSG(
"color : %X\n", ret_color);
310static int Color_distance(
long c1,
long c2)
312 return (labs((c1 & 0x0000ff) - (c2 & 0x0000ff)) +
313 labs(((c1 & 0x00ff00) - (c2 & 0x00ff00)) >> 8) +
314 labs(((c1 & 0xff0000) - (c2 & 0xff0000)) >> 16)) / 75;
323 return (labs((c1 & 0x0000ff) - (c2 & 0x0000ff)) >= 0x000060) +
324 (labs((c1 & 0x00ff00) - (c2 & 0x00ff00)) >= 0x006000) +
325 (labs((c1 & 0xff0000) - (c2 & 0xff0000)) >= 0x600000);
333 return (labs((c1 & 0x0000ff) - (c2 & 0x0000ff)) >= 0x000040) +
334 (labs((c1 & 0x00ff00) - (c2 & 0x00ff00)) >= 0x004000) +
335 (labs((c1 & 0xff0000) - (c2 & 0xff0000)) >= 0x400000);
345 int32_t C_txt, int32_t C_lnk, int32_t C_bg)
348 static int32_t v[] = {0x000000, 0x800080, 0x008b8b, 0x8b008b, 0x808000,
350 0x8b0000, 0xff7f50, 0x000000};
351 int v_size =
sizeof(v) /
sizeof(v[0]);
352 int i, max_i, score, max_score, d_bg, d_txt, d_lnk;
359 max_i = max_score = 0;
360 for (i = 0; i < v_size; ++i) {
361 _MSG(
"a_Color_vc: [%d]%.6x: %d %d %d\n", i, v[i],
372 score = (d_bg >= 2 ? 4 : 2 * d_bg) +
373 (d_txt + d_lnk >= 2 ? 2 : d_txt + d_lnk) +
379 }
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)