PageRenderTime 89ms CodeModel.GetById 2ms app.highlight 78ms RepoModel.GetById 2ms app.codeStats 0ms

/src/FreeImage/Source/FreeImage/ColorLookup.cpp

https://bitbucket.org/cabalistic/ogredeps/
C++ | 782 lines | 693 code | 31 blank | 58 comment | 44 complexity | 241a3511803df7e58ad4b4aebf885731 MD5 | raw file
  1// ==========================================================
  2// X11 and SVG Color name lookup
  3//
  4// Design and implementation by
  5// - Karl-Heinz Bussian (khbussian@moss.de)
  6//
  7// This file is part of FreeImage 3
  8//
  9// COVERED CODE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTY
 10// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES
 11// THAT THE COVERED CODE IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE
 12// OR NON-INFRINGING. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED
 13// CODE IS WITH YOU. SHOULD ANY COVERED CODE PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT
 14// THE INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE COST OF ANY NECESSARY
 15// SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL
 16// PART OF THIS LICENSE. NO USE OF ANY COVERED CODE IS AUTHORIZED HEREUNDER EXCEPT UNDER
 17// THIS DISCLAIMER.
 18//
 19// Use at your own risk!
 20//
 21// ==========================================================
 22
 23#include "FreeImage.h"
 24#include "Utilities.h"
 25
 26// RGB color names  ---------------------------------------------------------
 27
 28typedef struct tagNamedColor {
 29        const char *name;     // color name
 30        BYTE  r;        // red value
 31        BYTE  g;        // green value
 32        BYTE  b;        // blue value
 33} NamedColor;
 34
 35// --------------------------------------------------------------------------
 36
 37/**
 38Helper function : perform a binary search on a color array
 39@param name Color name
 40@param color_array Color array
 41@param n Length of the color array
 42@return Returns the color index in the array if successful, returns -1 otherwise
 43*/
 44static int
 45binsearch(const char *name, const NamedColor *color_array, int n) {
 46    int cond, low, mid, high;
 47
 48    low = 0;
 49    high = n - 1;
 50    while (low <= high) {
 51                mid = (low + high) / 2;
 52                if ((cond = strcmp(name, color_array[mid].name)) < 0)
 53                        high = mid - 1;
 54                else if (cond > 0)
 55                        low = mid + 1;
 56                else
 57                        return mid;
 58        }
 59    return -1;
 60}
 61
 62/**
 63Perform a binary search on a color array
 64@param szColor Color name
 65@param color_array Color array
 66@param ncolors Length of the color array
 67@return Returns the color index in the array if successful, returns -1 otherwise
 68*/
 69static int
 70FreeImage_LookupNamedColor(const char *szColor, const NamedColor *color_array, int ncolors) {
 71    int i;
 72    char color[64];
 73
 74    // make lower case name, squezze white space
 75
 76    for (i = 0; szColor[i] && i < sizeof(color) - 1; i++) {
 77        if (isspace(szColor[i]))
 78            continue;
 79        if (isupper(szColor[i]))
 80            color[i] = (char)tolower(szColor[i]);
 81        else
 82            color[i] = szColor[i];
 83    }
 84    color[i] = 0;
 85
 86    return (binsearch(color, color_array, ncolors));
 87}
 88
 89// ==========================================================
 90// X11 Color name lookup
 91
 92/**
 93 This big list of color names was formed from the file: /usr/X11R6/lib/X11/rgb.txt
 94 found on a standard Linux installation.
 95*/
 96
 97static NamedColor X11ColorMap[] = {
 98    { "aliceblue",            240, 248, 255 },
 99    { "antiquewhite",         250, 235, 215 },
100    { "antiquewhite1",        255, 239, 219 },
101    { "antiquewhite2",        238, 223, 204 },
102    { "antiquewhite3",        205, 192, 176 },
103    { "antiquewhite4",        139, 131, 120 },
104    { "aquamarine",           127, 255, 212 },
105    { "aquamarine1",          127, 255, 212 },
106    { "aquamarine2",          118, 238, 198 },
107    { "aquamarine3",          102, 205, 170 },
108    { "aquamarine4",           69, 139, 116 },
109    { "azure",                240, 255, 255 },
110    { "azure1",               240, 255, 255 },
111    { "azure2",               224, 238, 238 },
112    { "azure3",               193, 205, 205 },
113    { "azure4",               131, 139, 139 },
114    { "beige",                245, 245, 220 },
115    { "bisque",               255, 228, 196 },
116    { "bisque1",              255, 228, 196 },
117    { "bisque2",              238, 213, 183 },
118    { "bisque3",              205, 183, 158 },
119    { "bisque4",              139, 125, 107 },
120    { "black",                  0,   0,   0 },
121    { "blanchedalmond",       255, 235, 205 },
122    { "blue",                   0,   0, 255 },
123    { "blue1",                  0,   0, 255 },
124    { "blue2",                  0,   0, 238 },
125    { "blue3",                  0,   0, 205 },
126    { "blue4",                  0,   0, 139 },
127    { "blueviolet",           138,  43, 226 },
128    { "brown",                165,  42,  42 },
129    { "brown1",               255,  64,  64 },
130    { "brown2",               238,  59,  59 },
131    { "brown3",               205,  51,  51 },
132    { "brown4",               139,  35,  35 },
133    { "burlywood",            222, 184, 135 },
134    { "burlywood1",           255, 211, 155 },
135    { "burlywood2",           238, 197, 145 },
136    { "burlywood3",           205, 170, 125 },
137    { "burlywood4",           139, 115,  85 },
138    { "cadetblue",             95, 158, 160 },
139    { "cadetblue1",           152, 245, 255 },
140    { "cadetblue2",           142, 229, 238 },
141    { "cadetblue3",           122, 197, 205 },
142    { "cadetblue4",            83, 134, 139 },
143    { "chartreuse",           127, 255,   0 },
144    { "chartreuse1",          127, 255,   0 },
145    { "chartreuse2",          118, 238,   0 },
146    { "chartreuse3",          102, 205,   0 },
147    { "chartreuse4",           69, 139,   0 },
148    { "chocolate",            210, 105,  30 },
149    { "chocolate1",           255, 127,  36 },
150    { "chocolate2",           238, 118,  33 },
151    { "chocolate3",           205, 102,  29 },
152    { "chocolate4",           139,  69,  19 },
153    { "coral",                255, 127,  80 },
154    { "coral1",               255, 114,  86 },
155    { "coral2",               238, 106,  80 },
156    { "coral3",               205,  91,  69 },
157    { "coral4",               139,  62,  47 },
158    { "cornflowerblue",       100, 149, 237 },
159    { "cornsilk",             255, 248, 220 },
160    { "cornsilk1",            255, 248, 220 },
161    { "cornsilk2",            238, 232, 205 },
162    { "cornsilk3",            205, 200, 177 },
163    { "cornsilk4",            139, 136, 120 },
164    { "cyan",                   0, 255, 255 },
165    { "cyan1",                  0, 255, 255 },
166    { "cyan2",                  0, 238, 238 },
167    { "cyan3",                  0, 205, 205 },
168    { "cyan4",                  0, 139, 139 },
169    { "darkblue",               0,   0, 139 },
170    { "darkcyan",               0, 139, 139 },
171    { "darkgoldenrod",        184, 134,  11 },
172    { "darkgoldenrod1",       255, 185,  15 },
173    { "darkgoldenrod2",       238, 173,  14 },
174    { "darkgoldenrod3",       205, 149,  12 },
175    { "darkgoldenrod4",       139, 101,   8 },
176    { "darkgreen",              0, 100,   0 },
177    { "darkkhaki",            189, 183, 107 },
178    { "darkmagenta",          139,   0, 139 },
179    { "darkolivegreen",        85, 107,  47 },
180    { "darkolivegreen1",      202, 255, 112 },
181    { "darkolivegreen2",      188, 238, 104 },
182    { "darkolivegreen3",      162, 205,  90 },
183    { "darkolivegreen4",      110, 139,  61 },
184    { "darkorange",           255, 140,   0 },
185    { "darkorange1",          255, 127,   0 },
186    { "darkorange2",          238, 118,   0 },
187    { "darkorange3",          205, 102,   0 },
188    { "darkorange4",          139,  69,   0 },
189    { "darkorchid",           153,  50, 204 },
190    { "darkorchid1",          191,  62, 255 },
191    { "darkorchid2",          178,  58, 238 },
192    { "darkorchid3",          154,  50, 205 },
193    { "darkorchid4",          104,  34, 139 },
194    { "darkred",              139,   0,   0 },
195    { "darksalmon",           233, 150, 122 },
196    { "darkseagreen",         143, 188, 143 },
197    { "darkseagreen1",        193, 255, 193 },
198    { "darkseagreen2",        180, 238, 180 },
199    { "darkseagreen3",        155, 205, 155 },
200    { "darkseagreen4",        105, 139, 105 },
201    { "darkslateblue",         72,  61, 139 },
202    { "darkslategray",         47,  79,  79 },
203    { "darkslategray1",       151, 255, 255 },
204    { "darkslategray2",       141, 238, 238 },
205    { "darkslategray3",       121, 205, 205 },
206    { "darkslategray4",        82, 139, 139 },
207    { "darkslategrey",         47,  79,  79 },
208    { "darkturquoise",          0, 206, 209 },
209    { "darkviolet",           148,   0, 211 },
210    { "deeppink",             255,  20, 147 },
211    { "deeppink1",            255,  20, 147 },
212    { "deeppink2",            238,  18, 137 },
213    { "deeppink3",            205,  16, 118 },
214    { "deeppink4",            139,  10,  80 },
215    { "deepskyblue",            0, 191, 255 },
216    { "deepskyblue1",           0, 191, 255 },
217    { "deepskyblue2",           0, 178, 238 },
218    { "deepskyblue3",           0, 154, 205 },
219    { "deepskyblue4",           0, 104, 139 },
220    { "dimgray",              105, 105, 105 },
221    { "dimgrey",              105, 105, 105 },
222    { "dodgerblue",            30, 144, 255 },
223    { "dodgerblue1",           30, 144, 255 },
224    { "dodgerblue2",           28, 134, 238 },
225    { "dodgerblue3",           24, 116, 205 },
226    { "dodgerblue4",           16,  78, 139 },
227    { "firebrick",            178,  34,  34 },
228    { "firebrick1",           255,  48,  48 },
229    { "firebrick2",           238,  44,  44 },
230    { "firebrick3",           205,  38,  38 },
231    { "firebrick4",           139,  26,  26 },
232    { "floralwhite",          255, 250, 240 },
233    { "forestgreen",          176,  48,  96 },
234    { "gainsboro",            220, 220, 220 },
235    { "ghostwhite",           248, 248, 255 },
236    { "gold",                 255, 215,   0 },
237    { "gold1",                255, 215,   0 },
238    { "gold2",                238, 201,   0 },
239    { "gold3",                205, 173,   0 },
240    { "gold4",                139, 117,   0 },
241    { "goldenrod",            218, 165,  32 },
242    { "goldenrod1",           255, 193,  37 },
243    { "goldenrod2",           238, 180,  34 },
244    { "goldenrod3",           205, 155,  29 },
245    { "goldenrod4",           139, 105,  20 },
246    { "gray",                 190, 190, 190 },
247    { "green",                  0, 255,   0 },
248    { "green1",                 0, 255,   0 },
249    { "green2",                 0, 238,   0 },
250    { "green3",                 0, 205,   0 },
251    { "green4",                 0, 139,   0 },
252    { "greenyellow",          173, 255,  47 },
253    { "grey",                 190, 190, 190 },
254    { "honeydew",             240, 255, 240 },
255    { "honeydew1",            240, 255, 240 },
256    { "honeydew2",            224, 238, 224 },
257    { "honeydew3",            193, 205, 193 },
258    { "honeydew4",            131, 139, 131 },
259    { "hotpink",              255, 105, 180 },
260    { "hotpink1",             255, 110, 180 },
261    { "hotpink2",             238, 106, 167 },
262    { "hotpink3",             205,  96, 144 },
263    { "hotpink4",             139,  58,  98 },
264    { "indianred",            205,  92,  92 },
265    { "indianred1",           255, 106, 106 },
266    { "indianred2",           238,  99,  99 },
267    { "indianred3",           205,  85,  85 },
268    { "indianred4",           139,  58,  58 },
269    { "ivory",                255, 255, 240 },
270    { "ivory1",               255, 255, 240 },
271    { "ivory2",               238, 238, 224 },
272    { "ivory3",               205, 205, 193 },
273    { "ivory4",               139, 139, 131 },
274    { "khaki",                240, 230, 140 },
275    { "khaki1",               255, 246, 143 },
276    { "khaki2",               238, 230, 133 },
277    { "khaki3",               205, 198, 115 },
278    { "khaki4",               139, 134,  78 },
279    { "lavender",             230, 230, 250 },
280    { "lavenderblush",        255, 240, 245 },
281    { "lavenderblush1",       255, 240, 245 },
282    { "lavenderblush2",       238, 224, 229 },
283    { "lavenderblush3",       205, 193, 197 },
284    { "lavenderblush4",       139, 131, 134 },
285    { "lawngreen",            124, 252,   0 },
286    { "lemonchiffon",         255, 250, 205 },
287    { "lemonchiffon1",        255, 250, 205 },
288    { "lemonchiffon2",        238, 233, 191 },
289    { "lemonchiffon3",        205, 201, 165 },
290    { "lemonchiffon4",        139, 137, 112 },
291    { "lightblue",            173, 216, 230 },
292    { "lightblue1",           191, 239, 255 },
293    { "lightblue2",           178, 223, 238 },
294    { "lightblue3",           154, 192, 205 },
295    { "lightblue4",           104, 131, 139 },
296    { "lightcoral",           240, 128, 128 },
297    { "lightcyan",            224, 255, 255 },
298    { "lightcyan1",           224, 255, 255 },
299    { "lightcyan2",           209, 238, 238 },
300    { "lightcyan3",           180, 205, 205 },
301    { "lightcyan4",           122, 139, 139 },
302    { "lightgoldenrod",       238, 221, 130 },
303    { "lightgoldenrod1",      255, 236, 139 },
304    { "lightgoldenrod2",      238, 220, 130 },
305    { "lightgoldenrod3",      205, 190, 112 },
306    { "lightgoldenrod4",      139, 129,  76 },
307    { "lightgoldenrodyellow", 250, 250, 210 },
308    { "lightgray",            211, 211, 211 },
309    { "lightgreen",           144, 238, 144 },
310    { "lightgrey",            211, 211, 211 },
311    { "lightpink",            255, 182, 193 },
312    { "lightpink1",           255, 174, 185 },
313    { "lightpink2",           238, 162, 173 },
314    { "lightpink3",           205, 140, 149 },
315    { "lightpink4",           139,  95, 101 },
316    { "lightsalmon",          255, 160, 122 },
317    { "lightsalmon1",         255, 160, 122 },
318    { "lightsalmon2",         238, 149, 114 },
319    { "lightsalmon3",         205, 129,  98 },
320    { "lightsalmon4",         139,  87,  66 },
321    { "lightseagreen",         32, 178, 170 },
322    { "lightskyblue",         135, 206, 250 },
323    { "lightskyblue1",        176, 226, 255 },
324    { "lightskyblue2",        164, 211, 238 },
325    { "lightskyblue3",        141, 182, 205 },
326    { "lightskyblue4",         96, 123, 139 },
327    { "lightslateblue",       132, 112, 255 },
328    { "lightslategray",       119, 136, 153 },
329    { "lightslategrey",       119, 136, 153 },
330    { "lightsteelblue",       176, 196, 222 },
331    { "lightsteelblue1",      202, 225, 255 },
332    { "lightsteelblue2",      188, 210, 238 },
333    { "lightsteelblue3",      162, 181, 205 },
334    { "lightsteelblue4",      110, 123, 139 },
335    { "lightyellow",          255, 255, 224 },
336    { "lightyellow1",         255, 255, 224 },
337    { "lightyellow2",         238, 238, 209 },
338    { "lightyellow3",         205, 205, 180 },
339    { "lightyellow4",         139, 139, 122 },
340    { "limegreen",             50, 205,  50 },
341    { "linen",                250, 240, 230 },
342    { "magenta",              255,   0, 255 },
343    { "magenta1",             255,   0, 255 },
344    { "magenta2",             238,   0, 238 },
345    { "magenta3",             205,   0, 205 },
346    { "magenta4",             139,   0, 139 },
347    { "maroon",                 0, 255, 255 },
348    { "maroon1",              255,  52, 179 },
349    { "maroon2",              238,  48, 167 },
350    { "maroon3",              205,  41, 144 },
351    { "maroon4",              139,  28,  98 },
352    { "mediumaquamarine",     102, 205, 170 },
353    { "mediumblue",             0,   0, 205 },
354    { "mediumorchid",         186,  85, 211 },
355    { "mediumorchid1",        224, 102, 255 },
356    { "mediumorchid2",        209,  95, 238 },
357    { "mediumorchid3",        180,  82, 205 },
358    { "mediumorchid4",        122,  55, 139 },
359    { "mediumpurple",         147, 112, 219 },
360    { "mediumpurple1",        171, 130, 255 },
361    { "mediumpurple2",        159, 121, 238 },
362    { "mediumpurple3",        137, 104, 205 },
363    { "mediumpurple4",         93,  71, 139 },
364    { "mediumseagreen",        60, 179, 113 },
365    { "mediumslateblue",      123, 104, 238 },
366    { "mediumspringgreen",      0, 250, 154 },
367    { "mediumturquoise",       72, 209, 204 },
368    { "mediumvioletred",      199,  21, 133 },
369    { "midnightblue",          25,  25, 112 },
370    { "mintcream",            245, 255, 250 },
371    { "mistyrose",            255, 228, 225 },
372    { "mistyrose1",           255, 228, 225 },
373    { "mistyrose2",           238, 213, 210 },
374    { "mistyrose3",           205, 183, 181 },
375    { "mistyrose4",           139, 125, 123 },
376    { "moccasin",             255, 228, 181 },
377    { "navajowhite",          255, 222, 173 },
378    { "navajowhite1",         255, 222, 173 },
379    { "navajowhite2",         238, 207, 161 },
380    { "navajowhite3",         205, 179, 139 },
381    { "navajowhite4",         139, 121,  94 },
382    { "navy",                   0,   0, 128 },
383    { "navyblue",               0,   0, 128 },
384    { "oldlace",              253, 245, 230 },
385    { "olivedrab",            107, 142,  35 },
386    { "olivedrab1",           192, 255,  62 },
387    { "olivedrab2",           179, 238,  58 },
388    { "olivedrab3",           154, 205,  50 },
389    { "olivedrab4",           105, 139,  34 },
390    { "orange",               255, 165,   0 },
391    { "orange1",              255, 165,   0 },
392    { "orange2",              238, 154,   0 },
393    { "orange3",              205, 133,   0 },
394    { "orange4",              139,  90,   0 },
395    { "orangered",            255,  69,   0 },
396    { "orangered1",           255,  69,   0 },
397    { "orangered2",           238,  64,   0 },
398    { "orangered3",           205,  55,   0 },
399    { "orangered4",           139,  37,   0 },
400    { "orchid",               218, 112, 214 },
401    { "orchid1",              255, 131, 250 },
402    { "orchid2",              238, 122, 233 },
403    { "orchid3",              205, 105, 201 },
404    { "orchid4",              139,  71, 137 },
405    { "palegoldenrod",        238, 232, 170 },
406    { "palegreen",            152, 251, 152 },
407    { "palegreen1",           154, 255, 154 },
408    { "palegreen2",           144, 238, 144 },
409    { "palegreen3",           124, 205, 124 },
410    { "palegreen4",            84, 139,  84 },
411    { "paleturquoise",        175, 238, 238 },
412    { "paleturquoise1",       187, 255, 255 },
413    { "paleturquoise2",       174, 238, 238 },
414    { "paleturquoise3",       150, 205, 205 },
415    { "paleturquoise4",       102, 139, 139 },
416    { "palevioletred",        219, 112, 147 },
417    { "palevioletred1",       255, 130, 171 },
418    { "palevioletred2",       238, 121, 159 },
419    { "palevioletred3",       205, 104, 137 },
420    { "palevioletred4",       139,  71,  93 },
421    { "papayawhip",           255, 239, 213 },
422    { "peachpuff",            255, 218, 185 },
423    { "peachpuff1",           255, 218, 185 },
424    { "peachpuff2",           238, 203, 173 },
425    { "peachpuff3",           205, 175, 149 },
426    { "peachpuff4",           139, 119, 101 },
427    { "peru",                 205, 133,  63 },
428    { "pink",                 255, 192, 203 },
429    { "pink1",                255, 181, 197 },
430    { "pink2",                238, 169, 184 },
431    { "pink3",                205, 145, 158 },
432    { "pink4",                139,  99, 108 },
433    { "plum",                 221, 160, 221 },
434    { "plum1",                255, 187, 255 },
435    { "plum2",                238, 174, 238 },
436    { "plum3",                205, 150, 205 },
437    { "plum4",                139, 102, 139 },
438    { "powderblue",           176, 224, 230 },
439    { "purple",               160,  32, 240 },
440    { "purple1",              155,  48, 255 },
441    { "purple2",              145,  44, 238 },
442    { "purple3",              125,  38, 205 },
443    { "purple4",               85,  26, 139 },
444    { "red",                  255,   0,   0 },
445    { "red1",                 255,   0,   0 },
446    { "red2",                 238,   0,   0 },
447    { "red3",                 205,   0,   0 },
448    { "red4",                 139,   0,   0 },
449    { "rosybrown",            188, 143, 143 },
450    { "rosybrown1",           255, 193, 193 },
451    { "rosybrown2",           238, 180, 180 },
452    { "rosybrown3",           205, 155, 155 },
453    { "rosybrown4",           139, 105, 105 },
454    { "royalblue",             65, 105, 225 },
455    { "royalblue1",            72, 118, 255 },
456    { "royalblue2",            67, 110, 238 },
457    { "royalblue3",            58,  95, 205 },
458    { "royalblue4",            39,  64, 139 },
459    { "saddlebrown",          139,  69,  19 },
460    { "salmon",               250, 128, 114 },
461    { "salmon1",              255, 140, 105 },
462    { "salmon2",              238, 130,  98 },
463    { "salmon3",              205, 112,  84 },
464    { "salmon4",              139,  76,  57 },
465    { "sandybrown",           244, 164,  96 },
466    { "seagreen",              46, 139,  87 },
467    { "seagreen1",             84, 255, 159 },
468    { "seagreen2",             78, 238, 148 },
469    { "seagreen3",             67, 205, 128 },
470    { "seagreen4",             46, 139,  87 },
471    { "seashell",             255, 245, 238 },
472    { "seashell1",            255, 245, 238 },
473    { "seashell2",            238, 229, 222 },
474    { "seashell3",            205, 197, 191 },
475    { "seashell4",            139, 134, 130 },
476    { "sienna",               160,  82,  45 },
477    { "sienna1",              255, 130,  71 },
478    { "sienna2",              238, 121,  66 },
479    { "sienna3",              205, 104,  57 },
480    { "sienna4",              139,  71,  38 },
481    { "skyblue",              135, 206, 235 },
482    { "skyblue1",             135, 206, 255 },
483    { "skyblue2",             126, 192, 238 },
484    { "skyblue3",             108, 166, 205 },
485    { "skyblue4",              74, 112, 139 },
486    { "slateblue",            106,  90, 205 },
487    { "slateblue1",           131, 111, 255 },
488    { "slateblue2",           122, 103, 238 },
489    { "slateblue3",           105,  89, 205 },
490    { "slateblue4",            71,  60, 139 },
491    { "slategray",            112, 128, 144 },
492    { "slategray1",           198, 226, 255 },
493    { "slategray2",           185, 211, 238 },
494    { "slategray3",           159, 182, 205 },
495    { "slategray4",           108, 123, 139 },
496    { "slategrey",            112, 128, 144 },
497    { "snow",                 255, 250, 250 },
498    { "snow1",                255, 250, 250 },
499    { "snow2",                238, 233, 233 },
500    { "snow3",                205, 201, 201 },
501    { "snow4",                139, 137, 137 },
502    { "springgreen",            0, 255, 127 },
503    { "springgreen1",           0, 255, 127 },
504    { "springgreen2",           0, 238, 118 },
505    { "springgreen3",           0, 205, 102 },
506    { "springgreen4",           0, 139,  69 },
507    { "steelblue",             70, 130, 180 },
508    { "steelblue1",            99, 184, 255 },
509    { "steelblue2",            92, 172, 238 },
510    { "steelblue3",            79, 148, 205 },
511    { "steelblue4",            54, 100, 139 },
512    { "tan",                  210, 180, 140 },
513    { "tan1",                 255, 165,  79 },
514    { "tan2",                 238, 154,  73 },
515    { "tan3",                 205, 133,  63 },
516    { "tan4",                 139,  90,  43 },
517    { "thistle",              216, 191, 216 },
518    { "thistle1",             255, 225, 255 },
519    { "thistle2",             238, 210, 238 },
520    { "thistle3",             205, 181, 205 },
521    { "thistle4",             139, 123, 139 },
522    { "tomato",               255,  99,  71 },
523    { "tomato1",              255,  99,  71 },
524    { "tomato2",              238,  92,  66 },
525    { "tomato3",              205,  79,  57 },
526    { "tomato4",              139,  54,  38 },
527    { "turquoise",             64, 224, 208 },
528    { "turquoise1",             0, 245, 255 },
529    { "turquoise2",             0, 229, 238 },
530    { "turquoise3",             0, 197, 205 },
531    { "turquoise4",             0, 134, 139 },
532    { "violet",               238, 130, 238 },
533    { "violetred",            208,  32, 144 },
534    { "violetred1",           255,  62, 150 },
535    { "violetred2",           238,  58, 140 },
536    { "violetred3",           205,  50, 120 },
537    { "violetred4",           139,  34,  82 },
538    { "wheat",                245, 222, 179 },
539    { "wheat1",               255, 231, 186 },
540    { "wheat2",               238, 216, 174 },
541    { "wheat3",               205, 186, 150 },
542    { "wheat4",               139, 126, 102 },
543    { "white",                255, 255, 255 },
544    { "whitesmoke",           245, 245, 245 },
545    { "yellow",               255, 255,   0 },
546    { "yellow1",              255, 255,   0 },
547    { "yellow2",              238, 238,   0 },
548    { "yellow3",              205, 205,   0 },
549    { "yellow4",              139, 139,   0 },
550    { "yellowgreen",          154, 205,  50 }
551};
552
553
554BOOL DLL_CALLCONV
555FreeImage_LookupX11Color(const char *szColor, BYTE *nRed, BYTE *nGreen, BYTE *nBlue) {
556    int i;
557
558    // lookup color
559    i = FreeImage_LookupNamedColor(szColor, X11ColorMap, sizeof(X11ColorMap)/sizeof(X11ColorMap[0]));
560    if (i >= 0) {
561        *nRed   = X11ColorMap[i].r;
562        *nGreen = X11ColorMap[i].g;
563        *nBlue  = X11ColorMap[i].b;
564        return TRUE;
565    }
566
567    // not found, try for grey color with attached percent value
568    if ( (szColor[0] == 'g' || szColor[0] == 'G') &&
569         (szColor[1] == 'r' || szColor[1] == 'R') &&
570         (szColor[2] == 'e' || szColor[2] == 'E' || szColor[2] == 'a' || szColor[2] == 'A' ) &&
571         (szColor[3] == 'y' || szColor[3] == 'Y' ) )  {
572
573        // grey<num>, or gray<num>, num 1...100
574        i = strtol(szColor+4, NULL, 10);
575        *nRed   = (BYTE)(255.0/100.0 * i);
576        *nGreen = *nRed;
577        *nBlue  = *nRed;
578
579        return TRUE;
580    }
581
582    // not found at all
583    *nRed   = 0;
584    *nGreen = 0;
585    *nBlue  = 0;
586
587    return FALSE;
588}
589
590// ==========================================================
591// SVG Color name lookup
592
593/**
594 These are the colors defined in the SVG standard (I haven't checked
595 the final recommendation for changes)
596*/
597static NamedColor SVGColorMap[] = {
598        { "aliceblue",                  240, 248, 255 },
599        { "antiquewhite",               250, 235, 215 },
600        { "aqua",                         0, 255, 255 },
601        { "aquamarine",                 127, 255, 212 },
602        { "azure",                      240, 255, 255 },
603        { "beige",                      245, 245, 220 },
604        { "bisque",                     255, 228, 196 },
605        { "black",                        0,   0,   0 },
606        { "blanchedalmond",             255, 235, 205 },
607        { "blue",                         0,   0, 255 },
608        { "blueviolet",                 138,  43, 226 },
609        { "brown",                      165,  42,  42 },
610        { "burlywood",                  222, 184, 135 },
611        { "cadetblue",                   95, 158, 160 },
612        { "chartreuse",                 127, 255,   0 },
613        { "chocolate",                  210, 105,  30 },
614        { "coral",                      255, 127,  80 },
615        { "cornflowerblue",             100, 149, 237 },
616        { "cornsilk",                   255, 248, 220 },
617        { "crimson",                    220,  20,  60 },
618        { "cyan",                         0, 255, 255 },
619        { "darkblue",                     0,   0, 139 },
620        { "darkcyan",                     0, 139, 139 },
621        { "darkgoldenrod",              184, 134,  11 },
622        { "darkgray",                   169, 169, 169 },
623        { "darkgreen",                    0, 100,   0 },
624        { "darkgrey",                   169, 169, 169 },
625        { "darkkhaki",                  189, 183, 107 },
626        { "darkmagenta",                139,   0, 139 },
627        { "darkolivegreen",              85, 107,  47 },
628        { "darkorange",                 255, 140,   0 },
629        { "darkorchid",                 153,  50, 204 },
630        { "darkred",                    139,   0,   0 },
631        { "darksalmon",                 233, 150, 122 },
632        { "darkseagreen",               143, 188, 143 },
633        { "darkslateblue",               72,  61, 139 },
634        { "darkslategray",               47,  79,  79 },
635        { "darkslategrey",               47,  79,  79 },
636        { "darkturquoise",                0, 206, 209 },
637        { "darkviolet",                 148,   0, 211 },
638        { "deeppink",                   255,  20, 147 },
639        { "deepskyblue",                  0, 191, 255 },
640        { "dimgray",                    105, 105, 105 },
641        { "dimgrey",                    105, 105, 105 },
642        { "dodgerblue",                  30, 144, 255 },
643        { "firebrick",                  178,  34,  34 },
644        { "floralwhite",                255, 250, 240 },
645        { "forestgreen",                 34, 139,  34 },
646        { "fuchsia",                    255,   0, 255 },
647        { "gainsboro",                  220, 220, 220 },
648        { "ghostwhite",                 248, 248, 255 },
649        { "gold",                       255, 215,   0 },
650        { "goldenrod",                  218, 165,  32 },
651        { "gray",                       128, 128, 128 },
652        { "grey",                       128, 128, 128 },
653        { "green",                        0, 128,   0 },
654        { "greenyellow",                173, 255,  47 },
655        { "honeydew",                   240, 255, 240 },
656        { "hotpink",                    255, 105, 180 },
657        { "indianred",                  205,  92,  92 },
658        { "indigo",                      75,   0, 130 },
659        { "ivory",                      255, 255, 240 },
660        { "khaki",                      240, 230, 140 },
661        { "lavender",                   230, 230, 250 },
662        { "lavenderblush",              255, 240, 245 },
663        { "lawngreen",                  124, 252,   0 },
664        { "lemonchiffon",               255, 250, 205 },
665        { "lightblue",                  173, 216, 230 },
666        { "lightcoral",                 240, 128, 128 },
667        { "lightcyan",                  224, 255, 255 },
668        { "lightgoldenrodyellow",       250, 250, 210 },
669        { "lightgray",                  211, 211, 211 },
670        { "lightgreen",                 144, 238, 144 },
671        { "lightgrey",                  211, 211, 211 },
672        { "lightpink",                  255, 182, 193 },
673        { "lightsalmon",                255, 160, 122 },
674        { "lightseagreen",               32, 178, 170 },
675        { "lightskyblue",               135, 206, 250 },
676        { "lightslategray",             119, 136, 153 },
677        { "lightslategrey",             119, 136, 153 },
678        { "lightsteelblue",             176, 196, 222 },
679        { "lightyellow",                255, 255, 224 },
680        { "lime",                         0, 255,   0 },
681        { "limegreen",                   50, 205,  50 },
682        { "linen",                      250, 240, 230 },
683        { "magenta",                    255,   0, 255 },
684        { "maroon",                     128,   0,   0 },
685        { "mediumaquamarine",           102, 205, 170 },
686        { "mediumblue",                   0,   0, 205 },
687        { "mediumorchid",               186,  85, 211 },
688        { "mediumpurple",               147, 112, 219 },
689        { "mediumseagreen",              60, 179, 113 },
690        { "mediumslateblue",            123, 104, 238 },
691        { "mediumspringgreen",            0, 250, 154 },
692        { "mediumturquoise",             72, 209, 204 },
693        { "mediumvioletred",            199,  21, 133 },
694        { "midnightblue",                25,  25, 112 },
695        { "mintcream",                  245, 255, 250 },
696        { "mistyrose",                  255, 228, 225 },
697        { "moccasin",                   255, 228, 181 },
698        { "navajowhite",                255, 222, 173 },
699        { "navy",                         0,   0, 128 },
700        { "oldlace",                    253, 245, 230 },
701        { "olive",                      128, 128,   0 },
702        { "olivedrab",                  107, 142,  35 },
703        { "orange",                     255, 165,   0 },
704        { "orangered",                  255,  69,   0 },
705        { "orchid",                     218, 112, 214 },
706        { "palegoldenrod",              238, 232, 170 },
707        { "palegreen",                  152, 251, 152 },
708        { "paleturquoise",              175, 238, 238 },
709        { "palevioletred",              219, 112, 147 },
710        { "papayawhip",                 255, 239, 213 },
711        { "peachpuff",                  255, 218, 185 },
712        { "peru",                       205, 133,  63 },
713        { "pink",                       255, 192, 203 },
714        { "plum",                       221, 160, 221 },
715        { "powderblue",                 176, 224, 230 },
716        { "purple",                     128,   0, 128 },
717        { "red",                        255,   0,   0 },
718        { "rosybrown",                  188, 143, 143 },
719        { "royalblue",                   65, 105, 225 },
720        { "saddlebrown",                139,  69,  19 },
721        { "salmon",                     250, 128, 114 },
722        { "sandybrown",                 244, 164,  96 },
723        { "seagreen",                    46, 139,  87 },
724        { "seashell",                   255, 245, 238 },
725        { "sienna",                     160,  82,  45 },
726        { "silver",                     192, 192, 192 },
727        { "skyblue",                    135, 206, 235 },
728        { "slateblue",                  106,  90, 205 },
729        { "slategray",                  112, 128, 144 },
730        { "slategrey",                  112, 128, 144 },
731        { "snow",                       255, 250, 250 },
732        { "springgreen",                  0, 255, 127 },
733        { "steelblue",                   70, 130, 180 },
734        { "tan",                        210, 180, 140 },
735        { "teal",                         0, 128, 128 },
736        { "thistle",                    216, 191, 216 },
737        { "tomato",                     255,  99,  71 },
738        { "turquoise",                   64, 224, 208 },
739        { "violet",                     238, 130, 238 },
740        { "wheat",                      245, 222, 179 },
741        { "white",                      255, 255, 255 },
742        { "whitesmoke",                 245, 245, 245 },
743        { "yellow",                     255, 255,   0 },
744        { "yellowgreen",                154, 205,  50 }
745};
746
747
748BOOL DLL_CALLCONV
749FreeImage_LookupSVGColor(const char *szColor, BYTE *nRed, BYTE *nGreen, BYTE *nBlue) {
750    int i;
751
752    // lookup color
753    i = FreeImage_LookupNamedColor(szColor, SVGColorMap, sizeof(SVGColorMap)/sizeof(SVGColorMap[0]));
754    if (i >= 0) {
755        *nRed   = SVGColorMap[i].r;
756        *nGreen = SVGColorMap[i].g;
757        *nBlue  = SVGColorMap[i].b;
758        return TRUE;
759    }
760
761    // not found, try for grey color with attached percent value
762    if ( (szColor[0] == 'g' || szColor[0] == 'G') &&
763         (szColor[1] == 'r' || szColor[1] == 'R') &&
764         (szColor[2] == 'e' || szColor[2] == 'E' || szColor[2] == 'a' || szColor[2] == 'A' ) &&
765         (szColor[3] == 'y' || szColor[3] == 'Y' ) )  {
766
767        // grey<num>, or gray<num>, num 1...100
768        i = strtol(szColor+4, NULL, 10);
769        *nRed   = (BYTE)(255.0/100.0 * i);
770        *nGreen = *nRed;
771        *nBlue  = *nRed;
772        return TRUE;
773    }
774
775    // not found at all
776    *nRed   = 0;
777    *nGreen = 0;
778    *nBlue  = 0;
779
780    return FALSE;
781}
782