/Miranda IM - CK Release/Miranda/Plugins/Freeimage/Source/FreeImage/ColorLookup.cpp

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