MagickCore  6.9.12-67
Convert, Edit, Or Compose Bitmap Images
 All Data Structures
color.c
1 /*
2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3 % %
4 % %
5 % CCCC OOO L OOO RRRR %
6 % C O O L O O R R %
7 % C O O L O O RRRR %
8 % C O O L O O R R %
9 % CCCC OOO LLLLL OOO R R %
10 % %
11 % %
12 % MagickCore Color Methods %
13 % %
14 % Software Design %
15 % Cristy %
16 % July 1992 %
17 % %
18 % %
19 % Copyright 1999-2021 ImageMagick Studio LLC, a non-profit organization %
20 % dedicated to making software imaging solutions freely available. %
21 % %
22 % You may not use this file except in compliance with the License. You may %
23 % obtain a copy of the License at %
24 % %
25 % https://imagemagick.org/script/license.php %
26 % %
27 % Unless required by applicable law or agreed to in writing, software %
28 % distributed under the License is distributed on an "AS IS" BASIS, %
29 % WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. %
30 % See the License for the specific language governing permissions and %
31 % limitations under the License. %
32 % %
33 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
34 %
35 % We use linked-lists because splay-trees do not currently support duplicate
36 % key / value pairs (.e.g X11 green compliance and SVG green compliance).
37 %
38 */
39 
40 /*
41  Include declarations.
42 */
43 #include "magick/studio.h"
44 #include "magick/blob.h"
45 #include "magick/cache-view.h"
46 #include "magick/cache.h"
47 #include "magick/color.h"
48 #include "magick/color-private.h"
49 #include "magick/colorspace-private.h"
50 #include "magick/client.h"
51 #include "magick/configure.h"
52 #include "magick/exception.h"
53 #include "magick/exception-private.h"
54 #include "magick/gem.h"
55 #include "magick/geometry.h"
56 #include "magick/image-private.h"
57 #include "magick/memory_.h"
58 #include "magick/monitor.h"
59 #include "magick/monitor-private.h"
60 #include "magick/option.h"
61 #include "magick/pixel-private.h"
62 #include "magick/quantize.h"
63 #include "magick/quantum.h"
64 #include "magick/semaphore.h"
65 #include "magick/string_.h"
66 #include "magick/string-private.h"
67 #include "magick/token.h"
68 #include "magick/utility.h"
69 #include "magick/xml-tree.h"
70 #include "magick/xml-tree-private.h"
71 
72 /*
73  Define declarations.
74 */
75 #define ColorFilename "colors.xml"
76 
77 /*
78  Typedef declarations.
79 */
80 typedef struct _ColormapInfo
81 {
82  const char
83  name[21];
84 
85  const unsigned char
86  red,
87  green,
88  blue;
89 
90  const float
91  alpha;
92 
93  const ssize_t
94  compliance;
95 } ColormapInfo;
96 
97 /*
98  Static declarations.
99 */
100 static const ColormapInfo
101  Colormap[] =
102  {
103  { "none", 0, 0, 0, 0, SVGCompliance | XPMCompliance },
104  { "black", 0, 0, 0, 1, SVGCompliance | X11Compliance | XPMCompliance },
105  { "red", 255, 0, 0, 1, SVGCompliance | X11Compliance | XPMCompliance },
106  { "magenta", 255, 0, 255, 1, SVGCompliance | X11Compliance | XPMCompliance },
107  { "green", 0, 128, 0, 1, SVGCompliance },
108  { "cyan", 0, 255, 255, 1, SVGCompliance | X11Compliance | XPMCompliance },
109  { "blue", 0, 0, 255, 1, SVGCompliance | X11Compliance | XPMCompliance },
110  { "yellow", 255, 255, 0, 1, SVGCompliance | X11Compliance | XPMCompliance },
111  { "white", 255, 255, 255, 1, SVGCompliance | X11Compliance | XPMCompliance },
112  { "AliceBlue", 240, 248, 255, 1, SVGCompliance | X11Compliance | XPMCompliance },
113  { "AntiqueWhite", 250, 235, 215, 1, SVGCompliance | X11Compliance | XPMCompliance },
114  { "AntiqueWhite1", 255, 239, 219, 1, X11Compliance },
115  { "AntiqueWhite2", 238, 223, 204, 1, X11Compliance },
116  { "AntiqueWhite3", 205, 192, 176, 1, X11Compliance },
117  { "AntiqueWhite4", 139, 131, 120, 1, X11Compliance },
118  { "aqua", 0, 255, 255, 1, SVGCompliance },
119  { "aquamarine", 127, 255, 212, 1, SVGCompliance | X11Compliance | XPMCompliance },
120  { "aquamarine1", 127, 255, 212, 1, X11Compliance },
121  { "aquamarine2", 118, 238, 198, 1, X11Compliance },
122  { "aquamarine3", 102, 205, 170, 1, X11Compliance },
123  { "aquamarine4", 69, 139, 116, 1, X11Compliance },
124  { "azure", 240, 255, 255, 1, SVGCompliance | X11Compliance | XPMCompliance },
125  { "azure1", 240, 255, 255, 1, X11Compliance },
126  { "azure2", 224, 238, 238, 1, X11Compliance },
127  { "azure3", 193, 205, 205, 1, X11Compliance },
128  { "azure4", 131, 139, 139, 1, X11Compliance },
129  { "beige", 245, 245, 220, 1, SVGCompliance | X11Compliance | XPMCompliance },
130  { "bisque", 255, 228, 196, 1, SVGCompliance | X11Compliance | XPMCompliance },
131  { "bisque1", 255, 228, 196, 1, X11Compliance },
132  { "bisque2", 238, 213, 183, 1, X11Compliance },
133  { "bisque3", 205, 183, 158, 1, X11Compliance },
134  { "bisque4", 139, 125, 107, 1, X11Compliance },
135  { "BlanchedAlmond", 255, 235, 205, 1, SVGCompliance | X11Compliance | XPMCompliance },
136  { "blue1", 0, 0, 255, 1, X11Compliance },
137  { "blue2", 0, 0, 238, 1, X11Compliance },
138  { "blue3", 0, 0, 205, 1, X11Compliance },
139  { "blue4", 0, 0, 139, 1, X11Compliance },
140  { "BlueViolet", 138, 43, 226, 1, SVGCompliance | X11Compliance | XPMCompliance },
141  { "brown", 165, 42, 42, 1, SVGCompliance | X11Compliance | XPMCompliance },
142  { "brown1", 255, 64, 64, 1, X11Compliance },
143  { "brown2", 238, 59, 59, 1, X11Compliance },
144  { "brown3", 205, 51, 51, 1, X11Compliance },
145  { "brown4", 139, 35, 35, 1, X11Compliance },
146  { "burlywood", 222, 184, 135, 1, SVGCompliance | X11Compliance | XPMCompliance },
147  { "burlywood1", 255, 211, 155, 1, X11Compliance },
148  { "burlywood2", 238, 197, 145, 1, X11Compliance },
149  { "burlywood3", 205, 170, 125, 1, X11Compliance },
150  { "burlywood4", 139, 115, 85, 1, X11Compliance },
151  { "CadetBlue", 95, 158, 160, 1, SVGCompliance | X11Compliance | XPMCompliance },
152  { "CadetBlue1", 152, 245, 255, 1, X11Compliance },
153  { "CadetBlue2", 142, 229, 238, 1, X11Compliance },
154  { "CadetBlue3", 122, 197, 205, 1, X11Compliance },
155  { "CadetBlue4", 83, 134, 139, 1, X11Compliance },
156  { "chartreuse", 127, 255, 0, 1, SVGCompliance | X11Compliance | XPMCompliance },
157  { "chartreuse1", 127, 255, 0, 1, X11Compliance },
158  { "chartreuse2", 118, 238, 0, 1, X11Compliance },
159  { "chartreuse3", 102, 205, 0, 1, X11Compliance },
160  { "chartreuse4", 69, 139, 0, 1, X11Compliance },
161  { "chocolate", 210, 105, 30, 1, SVGCompliance | X11Compliance | XPMCompliance },
162  { "chocolate1", 255, 127, 36, 1, X11Compliance },
163  { "chocolate2", 238, 118, 33, 1, X11Compliance },
164  { "chocolate3", 205, 102, 29, 1, X11Compliance },
165  { "chocolate4", 139, 69, 19, 1, X11Compliance },
166  { "coral", 255, 127, 80, 1, SVGCompliance | X11Compliance | XPMCompliance },
167  { "coral1", 255, 114, 86, 1, X11Compliance },
168  { "coral2", 238, 106, 80, 1, X11Compliance },
169  { "coral3", 205, 91, 69, 1, X11Compliance },
170  { "coral4", 139, 62, 47, 1, X11Compliance },
171  { "CornflowerBlue", 100, 149, 237, 1, SVGCompliance | X11Compliance | XPMCompliance },
172  { "cornsilk", 255, 248, 220, 1, SVGCompliance | X11Compliance | XPMCompliance },
173  { "cornsilk1", 255, 248, 220, 1, X11Compliance },
174  { "cornsilk2", 238, 232, 205, 1, X11Compliance },
175  { "cornsilk3", 205, 200, 177, 1, X11Compliance },
176  { "cornsilk4", 139, 136, 120, 1, X11Compliance },
177  { "crimson", 220, 20, 60, 1, SVGCompliance },
178  { "cyan1", 0, 255, 255, 1, X11Compliance },
179  { "cyan2", 0, 238, 238, 1, X11Compliance },
180  { "cyan3", 0, 205, 205, 1, X11Compliance },
181  { "cyan4", 0, 139, 139, 1, X11Compliance },
182  { "DarkBlue", 0, 0, 139, 1, SVGCompliance | X11Compliance },
183  { "DarkCyan", 0, 139, 139, 1, SVGCompliance | X11Compliance },
184  { "DarkGoldenrod", 184, 134, 11, 1, SVGCompliance | X11Compliance | XPMCompliance },
185  { "DarkGoldenrod1", 255, 185, 15, 1, X11Compliance },
186  { "DarkGoldenrod2", 238, 173, 14, 1, X11Compliance },
187  { "DarkGoldenrod3", 205, 149, 12, 1, X11Compliance },
188  { "DarkGoldenrod4", 139, 101, 8, 1, X11Compliance },
189  { "DarkGray", 169, 169, 169, 1, SVGCompliance | X11Compliance },
190  { "DarkGreen", 0, 100, 0, 1, SVGCompliance | X11Compliance | XPMCompliance },
191  { "DarkGrey", 169, 169, 169, 1, SVGCompliance | X11Compliance },
192  { "DarkKhaki", 189, 183, 107, 1, SVGCompliance | X11Compliance | XPMCompliance },
193  { "DarkMagenta", 139, 0, 139, 1, SVGCompliance | X11Compliance },
194  { "DarkOliveGreen", 85, 107, 47, 1, SVGCompliance | X11Compliance | XPMCompliance },
195  { "DarkOliveGreen1", 202, 255, 112, 1, X11Compliance },
196  { "DarkOliveGreen2", 188, 238, 104, 1, X11Compliance },
197  { "DarkOliveGreen3", 162, 205, 90, 1, X11Compliance },
198  { "DarkOliveGreen4", 110, 139, 61, 1, X11Compliance },
199  { "DarkOrange", 255, 140, 0, 1, SVGCompliance | X11Compliance | XPMCompliance },
200  { "DarkOrange1", 255, 127, 0, 1, X11Compliance },
201  { "DarkOrange2", 238, 118, 0, 1, X11Compliance },
202  { "DarkOrange3", 205, 102, 0, 1, X11Compliance },
203  { "DarkOrange4", 139, 69, 0, 1, X11Compliance },
204  { "DarkOrchid", 153, 50, 204, 1, SVGCompliance | X11Compliance | XPMCompliance },
205  { "DarkOrchid1", 191, 62, 255, 1, X11Compliance },
206  { "DarkOrchid2", 178, 58, 238, 1, X11Compliance },
207  { "DarkOrchid3", 154, 50, 205, 1, X11Compliance },
208  { "DarkOrchid4", 104, 34, 139, 1, X11Compliance },
209  { "DarkRed", 139, 0, 0, 1, SVGCompliance | X11Compliance },
210  { "DarkSalmon", 233, 150, 122, 1, SVGCompliance | X11Compliance | XPMCompliance },
211  { "DarkSeaGreen", 143, 188, 143, 1, SVGCompliance | X11Compliance | XPMCompliance },
212  { "DarkSeaGreen1", 193, 255, 193, 1, X11Compliance },
213  { "DarkSeaGreen2", 180, 238, 180, 1, X11Compliance },
214  { "DarkSeaGreen3", 155, 205, 155, 1, X11Compliance },
215  { "DarkSeaGreen4", 105, 139, 105, 1, X11Compliance },
216  { "DarkSlateBlue", 72, 61, 139, 1, SVGCompliance | X11Compliance | XPMCompliance },
217  { "DarkSlateGray", 47, 79, 79, 1, SVGCompliance | X11Compliance | XPMCompliance },
218  { "DarkSlateGray1", 151, 255, 255, 1, X11Compliance },
219  { "DarkSlateGray2", 141, 238, 238, 1, X11Compliance },
220  { "DarkSlateGray3", 121, 205, 205, 1, X11Compliance },
221  { "DarkSlateGray4", 82, 139, 139, 1, X11Compliance },
222  { "DarkSlateGrey", 47, 79, 79, 1, SVGCompliance | X11Compliance },
223  { "DarkTurquoise", 0, 206, 209, 1, SVGCompliance | X11Compliance | XPMCompliance },
224  { "DarkViolet", 148, 0, 211, 1, SVGCompliance | X11Compliance | XPMCompliance },
225  { "DeepPink", 255, 20, 147, 1, SVGCompliance | X11Compliance | XPMCompliance },
226  { "DeepPink1", 255, 20, 147, 1, X11Compliance },
227  { "DeepPink2", 238, 18, 137, 1, X11Compliance },
228  { "DeepPink3", 205, 16, 118, 1, X11Compliance },
229  { "DeepPink4", 139, 10, 80, 1, X11Compliance },
230  { "DeepSkyBlue", 0, 191, 255, 1, SVGCompliance | X11Compliance | XPMCompliance },
231  { "DeepSkyBlue1", 0, 191, 255, 1, X11Compliance },
232  { "DeepSkyBlue2", 0, 178, 238, 1, X11Compliance },
233  { "DeepSkyBlue3", 0, 154, 205, 1, X11Compliance },
234  { "DeepSkyBlue4", 0, 104, 139, 1, X11Compliance },
235  { "DimGray", 105, 105, 105, 1, SVGCompliance | X11Compliance | XPMCompliance },
236  { "DimGrey", 105, 105, 105, 1, SVGCompliance | X11Compliance },
237  { "DodgerBlue", 30, 144, 255, 1, SVGCompliance | X11Compliance | XPMCompliance },
238  { "DodgerBlue1", 30, 144, 255, 1, X11Compliance },
239  { "DodgerBlue2", 28, 134, 238, 1, X11Compliance },
240  { "DodgerBlue3", 24, 116, 205, 1, X11Compliance },
241  { "DodgerBlue4", 16, 78, 139, 1, X11Compliance },
242  { "firebrick", 178, 34, 34, 1, SVGCompliance | X11Compliance | XPMCompliance },
243  { "firebrick1", 255, 48, 48, 1, X11Compliance },
244  { "firebrick2", 238, 44, 44, 1, X11Compliance },
245  { "firebrick3", 205, 38, 38, 1, X11Compliance },
246  { "firebrick4", 139, 26, 26, 1, X11Compliance },
247  { "FloralWhite", 255, 250, 240, 1, SVGCompliance | X11Compliance | XPMCompliance },
248  { "ForestGreen", 34, 139, 34, 1, SVGCompliance | X11Compliance | XPMCompliance },
249  { "fractal", 128, 128, 128, 1, SVGCompliance },
250  { "freeze", 0, 0, 0, 0, SVGCompliance },
251  { "fuchsia", 255, 0, 255, 1, SVGCompliance },
252  { "gainsboro", 220, 220, 220, 1, SVGCompliance | X11Compliance | XPMCompliance },
253  { "GhostWhite", 248, 248, 255, 1, SVGCompliance | X11Compliance | XPMCompliance },
254  { "gold", 255, 215, 0, 1, SVGCompliance | X11Compliance | XPMCompliance },
255  { "gold1", 255, 215, 0, 1, X11Compliance },
256  { "gold2", 238, 201, 0, 1, X11Compliance },
257  { "gold3", 205, 173, 0, 1, X11Compliance },
258  { "gold4", 139, 117, 0, 1, X11Compliance },
259  { "goldenrod", 218, 165, 32, 1, SVGCompliance | X11Compliance | XPMCompliance },
260  { "goldenrod1", 255, 193, 37, 1, X11Compliance },
261  { "goldenrod2", 238, 180, 34, 1, X11Compliance },
262  { "goldenrod3", 205, 155, 29, 1, X11Compliance },
263  { "goldenrod4", 139, 105, 20, 1, X11Compliance },
264  { "gray", 126, 126, 126, 1, SVGCompliance },
265  { "gray", 190, 190, 190, 1, X11Compliance | XPMCompliance },
266  { "gray0", 0, 0, 0, 1, X11Compliance | XPMCompliance },
267  { "gray1", 3, 3, 3, 1, X11Compliance | XPMCompliance },
268  { "gray10", 26, 26, 26, 1, X11Compliance | XPMCompliance },
269  { "gray100", 255, 255, 255, 1, X11Compliance | XPMCompliance },
270  { "gray100", 255, 255, 255, 1, X11Compliance | XPMCompliance },
271  { "gray11", 28, 28, 28, 1, X11Compliance | XPMCompliance },
272  { "gray12", 31, 31, 31, 1, X11Compliance | XPMCompliance },
273  { "gray13", 33, 33, 33, 1, X11Compliance | XPMCompliance },
274  { "gray14", 36, 36, 36, 1, X11Compliance | XPMCompliance },
275  { "gray15", 38, 38, 38, 1, X11Compliance | XPMCompliance },
276  { "gray16", 41, 41, 41, 1, X11Compliance | XPMCompliance },
277  { "gray17", 43, 43, 43, 1, X11Compliance | XPMCompliance },
278  { "gray18", 46, 46, 46, 1, X11Compliance | XPMCompliance },
279  { "gray19", 48, 48, 48, 1, X11Compliance | XPMCompliance },
280  { "gray2", 5, 5, 5, 1, X11Compliance | XPMCompliance },
281  { "gray20", 51, 51, 51, 1, X11Compliance | XPMCompliance },
282  { "gray21", 54, 54, 54, 1, X11Compliance | XPMCompliance },
283  { "gray22", 56, 56, 56, 1, X11Compliance | XPMCompliance },
284  { "gray23", 59, 59, 59, 1, X11Compliance | XPMCompliance },
285  { "gray24", 61, 61, 61, 1, X11Compliance | XPMCompliance },
286  { "gray25", 64, 64, 64, 1, X11Compliance | XPMCompliance },
287  { "gray26", 66, 66, 66, 1, X11Compliance | XPMCompliance },
288  { "gray27", 69, 69, 69, 1, X11Compliance | XPMCompliance },
289  { "gray28", 71, 71, 71, 1, X11Compliance | XPMCompliance },
290  { "gray29", 74, 74, 74, 1, X11Compliance | XPMCompliance },
291  { "gray3", 8, 8, 8, 1, X11Compliance | XPMCompliance },
292  { "gray30", 77, 77, 77, 1, X11Compliance | XPMCompliance },
293  { "gray31", 79, 79, 79, 1, X11Compliance | XPMCompliance },
294  { "gray32", 82, 82, 82, 1, X11Compliance | XPMCompliance },
295  { "gray33", 84, 84, 84, 1, X11Compliance | XPMCompliance },
296  { "gray34", 87, 87, 87, 1, X11Compliance | XPMCompliance },
297  { "gray35", 89, 89, 89, 1, X11Compliance | XPMCompliance },
298  { "gray36", 92, 92, 92, 1, X11Compliance | XPMCompliance },
299  { "gray37", 94, 94, 94, 1, X11Compliance | XPMCompliance },
300  { "gray38", 97, 97, 97, 1, X11Compliance | XPMCompliance },
301  { "gray39", 99, 99, 99, 1, X11Compliance | XPMCompliance },
302  { "gray4", 10, 10, 10, 1, X11Compliance | XPMCompliance },
303  { "gray40", 102, 102, 102, 1, X11Compliance | XPMCompliance },
304  { "gray41", 105, 105, 105, 1, X11Compliance | XPMCompliance },
305  { "gray42", 107, 107, 107, 1, X11Compliance | XPMCompliance },
306  { "gray43", 110, 110, 110, 1, X11Compliance | XPMCompliance },
307  { "gray44", 112, 112, 112, 1, X11Compliance | XPMCompliance },
308  { "gray45", 115, 115, 115, 1, X11Compliance | XPMCompliance },
309  { "gray46", 117, 117, 117, 1, X11Compliance | XPMCompliance },
310  { "gray47", 120, 120, 120, 1, X11Compliance | XPMCompliance },
311  { "gray48", 122, 122, 122, 1, X11Compliance | XPMCompliance },
312  { "gray49", 125, 125, 125, 1, X11Compliance | XPMCompliance },
313  { "gray5", 13, 13, 13, 1, X11Compliance | XPMCompliance },
314  { "gray50", 127, 127, 127, 1, X11Compliance | XPMCompliance },
315  { "gray51", 130, 130, 130, 1, X11Compliance | XPMCompliance },
316  { "gray52", 133, 133, 133, 1, X11Compliance | XPMCompliance },
317  { "gray53", 135, 135, 135, 1, X11Compliance | XPMCompliance },
318  { "gray54", 138, 138, 138, 1, X11Compliance | XPMCompliance },
319  { "gray55", 140, 140, 140, 1, X11Compliance | XPMCompliance },
320  { "gray56", 143, 143, 143, 1, X11Compliance | XPMCompliance },
321  { "gray57", 145, 145, 145, 1, X11Compliance | XPMCompliance },
322  { "gray58", 148, 148, 148, 1, X11Compliance | XPMCompliance },
323  { "gray59", 150, 150, 150, 1, X11Compliance | XPMCompliance },
324  { "gray6", 15, 15, 15, 1, X11Compliance | XPMCompliance },
325  { "gray60", 153, 153, 153, 1, X11Compliance | XPMCompliance },
326  { "gray61", 156, 156, 156, 1, X11Compliance | XPMCompliance },
327  { "gray62", 158, 158, 158, 1, X11Compliance | XPMCompliance },
328  { "gray63", 161, 161, 161, 1, X11Compliance | XPMCompliance },
329  { "gray64", 163, 163, 163, 1, X11Compliance | XPMCompliance },
330  { "gray65", 166, 166, 166, 1, X11Compliance | XPMCompliance },
331  { "gray66", 168, 168, 168, 1, X11Compliance | XPMCompliance },
332  { "gray67", 171, 171, 171, 1, X11Compliance | XPMCompliance },
333  { "gray68", 173, 173, 173, 1, X11Compliance | XPMCompliance },
334  { "gray69", 176, 176, 176, 1, X11Compliance | XPMCompliance },
335  { "gray7", 18, 18, 18, 1, X11Compliance | XPMCompliance },
336  { "gray70", 179, 179, 179, 1, X11Compliance | XPMCompliance },
337  { "gray71", 181, 181, 181, 1, X11Compliance | XPMCompliance },
338  { "gray72", 184, 184, 184, 1, X11Compliance | XPMCompliance },
339  { "gray73", 186, 186, 186, 1, X11Compliance | XPMCompliance },
340  { "gray74", 189, 189, 189, 1, X11Compliance | XPMCompliance },
341  { "gray75", 191, 191, 191, 1, X11Compliance | XPMCompliance },
342  { "gray76", 194, 194, 194, 1, X11Compliance | XPMCompliance },
343  { "gray77", 196, 196, 196, 1, X11Compliance | XPMCompliance },
344  { "gray78", 199, 199, 199, 1, X11Compliance | XPMCompliance },
345  { "gray79", 201, 201, 201, 1, X11Compliance | XPMCompliance },
346  { "gray8", 20, 20, 20, 1, X11Compliance | XPMCompliance },
347  { "gray80", 204, 204, 204, 1, X11Compliance | XPMCompliance },
348  { "gray81", 207, 207, 207, 1, X11Compliance | XPMCompliance },
349  { "gray82", 209, 209, 209, 1, X11Compliance | XPMCompliance },
350  { "gray83", 212, 212, 212, 1, X11Compliance | XPMCompliance },
351  { "gray84", 214, 214, 214, 1, X11Compliance | XPMCompliance },
352  { "gray85", 217, 217, 217, 1, X11Compliance | XPMCompliance },
353  { "gray86", 219, 219, 219, 1, X11Compliance | XPMCompliance },
354  { "gray87", 222, 222, 222, 1, X11Compliance | XPMCompliance },
355  { "gray88", 224, 224, 224, 1, X11Compliance | XPMCompliance },
356  { "gray89", 227, 227, 227, 1, X11Compliance | XPMCompliance },
357  { "gray9", 23, 23, 23, 1, X11Compliance | XPMCompliance },
358  { "gray90", 229, 229, 229, 1, X11Compliance | XPMCompliance },
359  { "gray91", 232, 232, 232, 1, X11Compliance | XPMCompliance },
360  { "gray92", 235, 235, 235, 1, X11Compliance | XPMCompliance },
361  { "gray93", 237, 237, 237, 1, X11Compliance | XPMCompliance },
362  { "gray94", 240, 240, 240, 1, X11Compliance | XPMCompliance },
363  { "gray95", 242, 242, 242, 1, X11Compliance | XPMCompliance },
364  { "gray96", 245, 245, 245, 1, X11Compliance | XPMCompliance },
365  { "gray97", 247, 247, 247, 1, X11Compliance | XPMCompliance },
366  { "gray98", 250, 250, 250, 1, X11Compliance | XPMCompliance },
367  { "gray99", 252, 252, 252, 1, X11Compliance | XPMCompliance },
368  { "green", 0, 255, 0, 1, X11Compliance | XPMCompliance },
369  { "green1", 0, 255, 0, 1, X11Compliance },
370  { "green2", 0, 238, 0, 1, X11Compliance },
371  { "green3", 0, 205, 0, 1, X11Compliance },
372  { "green4", 0, 139, 0, 1, X11Compliance },
373  { "GreenYellow", 173, 255, 47, 1, X11Compliance | XPMCompliance },
374  { "grey", 190, 190, 190, 1, SVGCompliance | X11Compliance },
375  { "grey0", 0, 0, 0, 1, SVGCompliance | X11Compliance },
376  { "grey1", 3, 3, 3, 1, SVGCompliance | X11Compliance },
377  { "grey10", 26, 26, 26, 1, SVGCompliance | X11Compliance },
378  { "grey100", 255, 255, 255, 1, SVGCompliance | X11Compliance },
379  { "grey11", 28, 28, 28, 1, SVGCompliance | X11Compliance },
380  { "grey12", 31, 31, 31, 1, SVGCompliance | X11Compliance },
381  { "grey13", 33, 33, 33, 1, SVGCompliance | X11Compliance },
382  { "grey14", 36, 36, 36, 1, SVGCompliance | X11Compliance },
383  { "grey15", 38, 38, 38, 1, SVGCompliance | X11Compliance },
384  { "grey16", 41, 41, 41, 1, SVGCompliance | X11Compliance },
385  { "grey17", 43, 43, 43, 1, SVGCompliance | X11Compliance },
386  { "grey18", 46, 46, 46, 1, SVGCompliance | X11Compliance },
387  { "grey19", 48, 48, 48, 1, SVGCompliance | X11Compliance },
388  { "grey2", 5, 5, 5, 1, SVGCompliance | X11Compliance },
389  { "grey20", 51, 51, 51, 1, SVGCompliance | X11Compliance },
390  { "grey21", 54, 54, 54, 1, SVGCompliance | X11Compliance },
391  { "grey22", 56, 56, 56, 1, SVGCompliance | X11Compliance },
392  { "grey23", 59, 59, 59, 1, SVGCompliance | X11Compliance },
393  { "grey24", 61, 61, 61, 1, SVGCompliance | X11Compliance },
394  { "grey25", 64, 64, 64, 1, SVGCompliance | X11Compliance },
395  { "grey26", 66, 66, 66, 1, SVGCompliance | X11Compliance },
396  { "grey27", 69, 69, 69, 1, SVGCompliance | X11Compliance },
397  { "grey28", 71, 71, 71, 1, SVGCompliance | X11Compliance },
398  { "grey29", 74, 74, 74, 1, SVGCompliance | X11Compliance },
399  { "grey3", 8, 8, 8, 1, SVGCompliance | X11Compliance },
400  { "grey30", 77, 77, 77, 1, SVGCompliance | X11Compliance },
401  { "grey31", 79, 79, 79, 1, SVGCompliance | X11Compliance },
402  { "grey32", 82, 82, 82, 1, SVGCompliance | X11Compliance },
403  { "grey33", 84, 84, 84, 1, SVGCompliance | X11Compliance },
404  { "grey34", 87, 87, 87, 1, SVGCompliance | X11Compliance },
405  { "grey35", 89, 89, 89, 1, SVGCompliance | X11Compliance },
406  { "grey36", 92, 92, 92, 1, SVGCompliance | X11Compliance },
407  { "grey37", 94, 94, 94, 1, SVGCompliance | X11Compliance },
408  { "grey38", 97, 97, 97, 1, SVGCompliance | X11Compliance },
409  { "grey39", 99, 99, 99, 1, SVGCompliance | X11Compliance },
410  { "grey4", 10, 10, 10, 1, SVGCompliance | X11Compliance },
411  { "grey40", 102, 102, 102, 1, SVGCompliance | X11Compliance },
412  { "grey41", 105, 105, 105, 1, SVGCompliance | X11Compliance },
413  { "grey42", 107, 107, 107, 1, SVGCompliance | X11Compliance },
414  { "grey43", 110, 110, 110, 1, SVGCompliance | X11Compliance },
415  { "grey44", 112, 112, 112, 1, SVGCompliance | X11Compliance },
416  { "grey45", 115, 115, 115, 1, SVGCompliance | X11Compliance },
417  { "grey46", 117, 117, 117, 1, SVGCompliance | X11Compliance },
418  { "grey47", 120, 120, 120, 1, SVGCompliance | X11Compliance },
419  { "grey48", 122, 122, 122, 1, SVGCompliance | X11Compliance },
420  { "grey49", 125, 125, 125, 1, SVGCompliance | X11Compliance },
421  { "grey5", 13, 13, 13, 1, SVGCompliance | X11Compliance },
422  { "grey50", 127, 127, 127, 1, SVGCompliance | X11Compliance },
423  { "grey51", 130, 130, 130, 1, SVGCompliance | X11Compliance },
424  { "grey52", 133, 133, 133, 1, SVGCompliance | X11Compliance },
425  { "grey53", 135, 135, 135, 1, SVGCompliance | X11Compliance },
426  { "grey54", 138, 138, 138, 1, SVGCompliance | X11Compliance },
427  { "grey55", 140, 140, 140, 1, SVGCompliance | X11Compliance },
428  { "grey56", 143, 143, 143, 1, SVGCompliance | X11Compliance },
429  { "grey57", 145, 145, 145, 1, SVGCompliance | X11Compliance },
430  { "grey58", 148, 148, 148, 1, SVGCompliance | X11Compliance },
431  { "grey59", 150, 150, 150, 1, SVGCompliance | X11Compliance },
432  { "grey6", 15, 15, 15, 1, SVGCompliance | X11Compliance },
433  { "grey60", 153, 153, 153, 1, SVGCompliance | X11Compliance },
434  { "grey61", 156, 156, 156, 1, SVGCompliance | X11Compliance },
435  { "grey62", 158, 158, 158, 1, SVGCompliance | X11Compliance },
436  { "grey63", 161, 161, 161, 1, SVGCompliance | X11Compliance },
437  { "grey64", 163, 163, 163, 1, SVGCompliance | X11Compliance },
438  { "grey65", 166, 166, 166, 1, SVGCompliance | X11Compliance },
439  { "grey66", 168, 168, 168, 1, SVGCompliance | X11Compliance },
440  { "grey67", 171, 171, 171, 1, SVGCompliance | X11Compliance },
441  { "grey68", 173, 173, 173, 1, SVGCompliance | X11Compliance },
442  { "grey69", 176, 176, 176, 1, SVGCompliance | X11Compliance },
443  { "grey7", 18, 18, 18, 1, SVGCompliance | X11Compliance },
444  { "grey70", 179, 179, 179, 1, SVGCompliance | X11Compliance },
445  { "grey71", 181, 181, 181, 1, SVGCompliance | X11Compliance },
446  { "grey72", 184, 184, 184, 1, SVGCompliance | X11Compliance },
447  { "grey73", 186, 186, 186, 1, SVGCompliance | X11Compliance },
448  { "grey74", 189, 189, 189, 1, SVGCompliance | X11Compliance },
449  { "grey75", 191, 191, 191, 1, SVGCompliance | X11Compliance },
450  { "grey76", 194, 194, 194, 1, SVGCompliance | X11Compliance },
451  { "grey77", 196, 196, 196, 1, SVGCompliance | X11Compliance },
452  { "grey78", 199, 199, 199, 1, SVGCompliance | X11Compliance },
453  { "grey79", 201, 201, 201, 1, SVGCompliance | X11Compliance },
454  { "grey8", 20, 20, 20, 1, SVGCompliance | X11Compliance },
455  { "grey80", 204, 204, 204, 1, SVGCompliance | X11Compliance },
456  { "grey81", 207, 207, 207, 1, SVGCompliance | X11Compliance },
457  { "grey82", 209, 209, 209, 1, SVGCompliance | X11Compliance },
458  { "grey83", 212, 212, 212, 1, SVGCompliance | X11Compliance },
459  { "grey84", 214, 214, 214, 1, SVGCompliance | X11Compliance },
460  { "grey85", 217, 217, 217, 1, SVGCompliance | X11Compliance },
461  { "grey86", 219, 219, 219, 1, SVGCompliance | X11Compliance },
462  { "grey87", 222, 222, 222, 1, SVGCompliance | X11Compliance },
463  { "grey88", 224, 224, 224, 1, SVGCompliance | X11Compliance },
464  { "grey89", 227, 227, 227, 1, SVGCompliance | X11Compliance },
465  { "grey9", 23, 23, 23, 1, SVGCompliance | X11Compliance },
466  { "grey90", 229, 229, 229, 1, SVGCompliance | X11Compliance },
467  { "grey91", 232, 232, 232, 1, SVGCompliance | X11Compliance },
468  { "grey92", 235, 235, 235, 1, SVGCompliance | X11Compliance },
469  { "grey93", 237, 237, 237, 1, SVGCompliance | X11Compliance },
470  { "grey94", 240, 240, 240, 1, SVGCompliance | X11Compliance },
471  { "grey95", 242, 242, 242, 1, SVGCompliance | X11Compliance },
472  { "grey96", 245, 245, 245, 1, SVGCompliance | X11Compliance },
473  { "grey97", 247, 247, 247, 1, SVGCompliance | X11Compliance },
474  { "grey98", 250, 250, 250, 1, SVGCompliance | X11Compliance },
475  { "grey99", 252, 252, 252, 1, SVGCompliance | X11Compliance },
476  { "honeydew", 240, 255, 240, 1, SVGCompliance | X11Compliance | XPMCompliance },
477  { "honeydew1", 240, 255, 240, 1, X11Compliance },
478  { "honeydew2", 224, 238, 224, 1, X11Compliance },
479  { "honeydew3", 193, 205, 193, 1, X11Compliance },
480  { "honeydew4", 131, 139, 131, 1, X11Compliance },
481  { "HotPink", 255, 105, 180, 1, SVGCompliance | X11Compliance | XPMCompliance },
482  { "HotPink1", 255, 110, 180, 1, X11Compliance },
483  { "HotPink2", 238, 106, 167, 1, X11Compliance },
484  { "HotPink3", 205, 96, 144, 1, X11Compliance },
485  { "HotPink4", 139, 58, 98, 1, X11Compliance },
486  { "IndianRed", 205, 92, 92, 1, SVGCompliance | X11Compliance | XPMCompliance },
487  { "IndianRed1", 255, 106, 106, 1, X11Compliance },
488  { "IndianRed2", 238, 99, 99, 1, X11Compliance },
489  { "IndianRed3", 205, 85, 85, 1, X11Compliance },
490  { "IndianRed4", 139, 58, 58, 1, X11Compliance },
491  { "indigo", 75, 0, 130, 1, SVGCompliance },
492  { "ivory", 255, 255, 240, 1, SVGCompliance | X11Compliance | XPMCompliance },
493  { "ivory1", 255, 255, 240, 1, X11Compliance },
494  { "ivory2", 238, 238, 224, 1, X11Compliance },
495  { "ivory3", 205, 205, 193, 1, X11Compliance },
496  { "ivory4", 139, 139, 131, 1, X11Compliance },
497  { "khaki", 240, 230, 140, 1, SVGCompliance | X11Compliance | XPMCompliance },
498  { "khaki1", 255, 246, 143, 1, X11Compliance },
499  { "khaki2", 238, 230, 133, 1, X11Compliance },
500  { "khaki3", 205, 198, 115, 1, X11Compliance },
501  { "khaki4", 139, 134, 78, 1, X11Compliance },
502  { "lavender", 230, 230, 250, 1, SVGCompliance | X11Compliance | XPMCompliance },
503  { "LavenderBlush", 255, 240, 245, 1, SVGCompliance | X11Compliance | XPMCompliance },
504  { "LavenderBlush1", 255, 240, 245, 1, X11Compliance },
505  { "LavenderBlush2", 238, 224, 229, 1, X11Compliance },
506  { "LavenderBlush3", 205, 193, 197, 1, X11Compliance },
507  { "LavenderBlush4", 139, 131, 134, 1, X11Compliance },
508  { "LawnGreen", 124, 252, 0, 1, SVGCompliance | X11Compliance | XPMCompliance },
509  { "LemonChiffon", 255, 250, 205, 1, SVGCompliance | X11Compliance | XPMCompliance },
510  { "LemonChiffon1", 255, 250, 205, 1, X11Compliance },
511  { "LemonChiffon2", 238, 233, 191, 1, X11Compliance },
512  { "LemonChiffon3", 205, 201, 165, 1, X11Compliance },
513  { "LemonChiffon4", 139, 137, 112, 1, X11Compliance },
514  { "LightBlue", 173, 216, 230, 1, SVGCompliance | X11Compliance | XPMCompliance },
515  { "LightBlue1", 191, 239, 255, 1, X11Compliance },
516  { "LightBlue2", 178, 223, 238, 1, X11Compliance },
517  { "LightBlue3", 154, 192, 205, 1, X11Compliance },
518  { "LightBlue4", 104, 131, 139, 1, X11Compliance },
519  { "LightCoral", 240, 128, 128, 1, SVGCompliance | X11Compliance | XPMCompliance },
520  { "LightCyan", 224, 255, 255, 1, SVGCompliance | X11Compliance | XPMCompliance },
521  { "LightCyan1", 224, 255, 255, 1, X11Compliance },
522  { "LightCyan2", 209, 238, 238, 1, X11Compliance },
523  { "LightCyan3", 180, 205, 205, 1, X11Compliance },
524  { "LightCyan4", 122, 139, 139, 1, X11Compliance },
525  { "LightGoldenrod", 238, 221, 130, 1, X11Compliance | XPMCompliance },
526  { "LightGoldenrod1", 255, 236, 139, 1, X11Compliance },
527  { "LightGoldenrod2", 238, 220, 130, 1, X11Compliance },
528  { "LightGoldenrod3", 205, 190, 112, 1, X11Compliance },
529  { "LightGoldenrod4", 139, 129, 76, 1, X11Compliance },
530  { "LightGoldenrodYellow", 250, 250, 210, 1, SVGCompliance | X11Compliance | XPMCompliance },
531  { "LightGray", 211, 211, 211, 1, SVGCompliance | X11Compliance | XPMCompliance },
532  { "LightGreen", 144, 238, 144, 1, SVGCompliance | X11Compliance },
533  { "LightGrey", 211, 211, 211, 1, SVGCompliance | X11Compliance },
534  { "LightPink", 255, 182, 193, 1, SVGCompliance | X11Compliance | XPMCompliance },
535  { "LightPink1", 255, 174, 185, 1, X11Compliance },
536  { "LightPink2", 238, 162, 173, 1, X11Compliance },
537  { "LightPink3", 205, 140, 149, 1, X11Compliance },
538  { "LightPink4", 139, 95, 101, 1, X11Compliance },
539  { "LightSalmon", 255, 160, 122, 1, SVGCompliance | X11Compliance | XPMCompliance },
540  { "LightSalmon1", 255, 160, 122, 1, X11Compliance },
541  { "LightSalmon2", 238, 149, 114, 1, X11Compliance },
542  { "LightSalmon3", 205, 129, 98, 1, X11Compliance },
543  { "LightSalmon4", 139, 87, 66, 1, X11Compliance },
544  { "LightSeaGreen", 32, 178, 170, 1, SVGCompliance | X11Compliance | XPMCompliance },
545  { "LightSkyBlue", 135, 206, 250, 1, SVGCompliance | X11Compliance | XPMCompliance },
546  { "LightSkyBlue1", 176, 226, 255, 1, X11Compliance },
547  { "LightSkyBlue2", 164, 211, 238, 1, X11Compliance },
548  { "LightSkyBlue3", 141, 182, 205, 1, X11Compliance },
549  { "LightSkyBlue4", 96, 123, 139, 1, X11Compliance },
550  { "LightSlateBlue", 132, 112, 255, 1, X11Compliance | XPMCompliance },
551  { "LightSlateGray", 119, 136, 153, 1, SVGCompliance | X11Compliance | XPMCompliance },
552  { "LightSlateGrey", 119, 136, 153, 1, SVGCompliance | X11Compliance },
553  { "LightSteelBlue", 176, 196, 222, 1, SVGCompliance | X11Compliance | XPMCompliance },
554  { "LightSteelBlue1", 202, 225, 255, 1, X11Compliance },
555  { "LightSteelBlue2", 188, 210, 238, 1, X11Compliance },
556  { "LightSteelBlue3", 162, 181, 205, 1, X11Compliance },
557  { "LightSteelBlue4", 110, 123, 139, 1, X11Compliance },
558  { "LightYellow", 255, 255, 224, 1, SVGCompliance | X11Compliance | XPMCompliance },
559  { "LightYellow1", 255, 255, 224, 1, X11Compliance },
560  { "LightYellow2", 238, 238, 209, 1, X11Compliance },
561  { "LightYellow3", 205, 205, 180, 1, X11Compliance },
562  { "LightYellow4", 139, 139, 122, 1, X11Compliance },
563  { "lime", 0, 255, 0, 1, SVGCompliance },
564  { "LimeGreen", 50, 205, 50, 1, SVGCompliance | X11Compliance | XPMCompliance },
565  { "linen", 250, 240, 230, 1, SVGCompliance | X11Compliance | XPMCompliance },
566  { "magenta1", 255, 0, 255, 1, X11Compliance },
567  { "magenta2", 238, 0, 238, 1, X11Compliance },
568  { "magenta3", 205, 0, 205, 1, X11Compliance },
569  { "magenta4", 139, 0, 139, 1, X11Compliance },
570  { "maroon", 128, 0, 0, 1, SVGCompliance },
571  { "maroon", 176, 48, 96, 1, X11Compliance | XPMCompliance },
572  { "maroon1", 255, 52, 179, 1, X11Compliance },
573  { "maroon2", 238, 48, 167, 1, X11Compliance },
574  { "maroon3", 205, 41, 144, 1, X11Compliance },
575  { "maroon4", 139, 28, 98, 1, X11Compliance },
576  { "MediumAquamarine", 102, 205, 170, 1, SVGCompliance | X11Compliance | XPMCompliance },
577  { "MediumBlue", 0, 0, 205, 1, SVGCompliance | X11Compliance | XPMCompliance },
578  { "MediumForestGreen", 50, 129, 75, 1, X11Compliance | XPMCompliance },
579  { "MediumGoldenRod", 209, 193, 102, 1, X11Compliance | XPMCompliance },
580  { "MediumOrchid", 186, 85, 211, 1, SVGCompliance | X11Compliance | XPMCompliance },
581  { "MediumOrchid1", 224, 102, 255, 1, X11Compliance },
582  { "MediumOrchid2", 209, 95, 238, 1, X11Compliance },
583  { "MediumOrchid3", 180, 82, 205, 1, X11Compliance },
584  { "MediumOrchid4", 122, 55, 139, 1, X11Compliance },
585  { "MediumPurple", 147, 112, 219, 1, SVGCompliance | X11Compliance | XPMCompliance },
586  { "MediumPurple1", 171, 130, 255, 1, X11Compliance },
587  { "MediumPurple2", 159, 121, 238, 1, X11Compliance },
588  { "MediumPurple3", 137, 104, 205, 1, X11Compliance },
589  { "MediumPurple4", 93, 71, 139, 1, X11Compliance },
590  { "MediumSeaGreen", 60, 179, 113, 1, SVGCompliance | X11Compliance | XPMCompliance },
591  { "MediumSlateBlue", 123, 104, 238, 1, SVGCompliance | X11Compliance | XPMCompliance },
592  { "MediumSpringGreen", 0, 250, 154, 1, SVGCompliance | X11Compliance | XPMCompliance },
593  { "MediumTurquoise", 72, 209, 204, 1, SVGCompliance | X11Compliance | XPMCompliance },
594  { "MediumVioletRed", 199, 21, 133, 1, SVGCompliance | X11Compliance | XPMCompliance },
595  { "MidnightBlue", 25, 25, 112, 1, SVGCompliance | X11Compliance | XPMCompliance },
596  { "MintCream", 245, 255, 250, 1, SVGCompliance | X11Compliance | XPMCompliance },
597  { "MistyRose", 255, 228, 225, 1, SVGCompliance | X11Compliance | XPMCompliance },
598  { "MistyRose1", 255, 228, 225, 1, X11Compliance },
599  { "MistyRose2", 238, 213, 210, 1, X11Compliance },
600  { "MistyRose3", 205, 183, 181, 1, X11Compliance },
601  { "MistyRose4", 139, 125, 123, 1, X11Compliance },
602  { "moccasin", 255, 228, 181, 1, SVGCompliance | X11Compliance | XPMCompliance },
603  { "NavajoWhite", 255, 222, 173, 1, SVGCompliance | X11Compliance | XPMCompliance },
604  { "NavajoWhite1", 255, 222, 173, 1, X11Compliance },
605  { "NavajoWhite2", 238, 207, 161, 1, X11Compliance },
606  { "NavajoWhite3", 205, 179, 139, 1, X11Compliance },
607  { "NavajoWhite4", 139, 121, 94, 1, X11Compliance },
608  { "navy", 0, 0, 128, 1, SVGCompliance | X11Compliance | XPMCompliance },
609  { "NavyBlue", 0, 0, 128, 1, X11Compliance | XPMCompliance },
610  { "matte", 0, 0, 0, 0, SVGCompliance },
611  { "OldLace", 253, 245, 230, 1, SVGCompliance | X11Compliance | XPMCompliance },
612  { "olive", 128, 128, 0, 1, SVGCompliance },
613  { "OliveDrab", 107, 142, 35, 1, SVGCompliance | X11Compliance | XPMCompliance },
614  { "OliveDrab1", 192, 255, 62, 1, X11Compliance },
615  { "OliveDrab2", 179, 238, 58, 1, X11Compliance },
616  { "OliveDrab3", 154, 205, 50, 1, X11Compliance },
617  { "OliveDrab4", 105, 139, 34, 1, X11Compliance },
618  { "opaque", 0, 0, 0, 1, SVGCompliance },
619  { "orange", 255, 165, 0, 1, SVGCompliance | X11Compliance | XPMCompliance },
620  { "orange1", 255, 165, 0, 1, X11Compliance },
621  { "orange2", 238, 154, 0, 1, X11Compliance },
622  { "orange3", 205, 133, 0, 1, X11Compliance },
623  { "orange4", 139, 90, 0, 1, X11Compliance },
624  { "OrangeRed", 255, 69, 0, 1, SVGCompliance | X11Compliance | XPMCompliance },
625  { "OrangeRed1", 255, 69, 0, 1, X11Compliance },
626  { "OrangeRed2", 238, 64, 0, 1, X11Compliance },
627  { "OrangeRed3", 205, 55, 0, 1, X11Compliance },
628  { "OrangeRed4", 139, 37, 0, 1, X11Compliance },
629  { "orchid", 218, 112, 214, 1, SVGCompliance | X11Compliance | XPMCompliance },
630  { "orchid1", 255, 131, 250, 1, X11Compliance },
631  { "orchid2", 238, 122, 233, 1, X11Compliance },
632  { "orchid3", 205, 105, 201, 1, X11Compliance },
633  { "orchid4", 139, 71, 137, 1, X11Compliance },
634  { "PaleGoldenrod", 238, 232, 170, 1, SVGCompliance | X11Compliance | XPMCompliance },
635  { "PaleGreen", 152, 251, 152, 1, SVGCompliance | X11Compliance | XPMCompliance },
636  { "PaleGreen1", 154, 255, 154, 1, X11Compliance },
637  { "PaleGreen2", 144, 238, 144, 1, X11Compliance },
638  { "PaleGreen3", 124, 205, 124, 1, X11Compliance },
639  { "PaleGreen4", 84, 139, 84, 1, X11Compliance },
640  { "PaleTurquoise", 175, 238, 238, 1, SVGCompliance | X11Compliance | XPMCompliance },
641  { "PaleTurquoise1", 187, 255, 255, 1, X11Compliance },
642  { "PaleTurquoise2", 174, 238, 238, 1, X11Compliance },
643  { "PaleTurquoise3", 150, 205, 205, 1, X11Compliance },
644  { "PaleTurquoise4", 102, 139, 139, 1, X11Compliance },
645  { "PaleVioletRed", 219, 112, 147, 1, SVGCompliance | X11Compliance | XPMCompliance },
646  { "PaleVioletRed1", 255, 130, 171, 1, X11Compliance },
647  { "PaleVioletRed2", 238, 121, 159, 1, X11Compliance },
648  { "PaleVioletRed3", 205, 104, 137, 1, X11Compliance },
649  { "PaleVioletRed4", 139, 71, 93, 1, X11Compliance },
650  { "PapayaWhip", 255, 239, 213, 1, SVGCompliance | X11Compliance | XPMCompliance },
651  { "PeachPuff", 255, 218, 185, 1, SVGCompliance | X11Compliance | XPMCompliance },
652  { "PeachPuff1", 255, 218, 185, 1, X11Compliance },
653  { "PeachPuff2", 238, 203, 173, 1, X11Compliance },
654  { "PeachPuff3", 205, 175, 149, 1, X11Compliance },
655  { "PeachPuff4", 139, 119, 101, 1, X11Compliance },
656  { "peru", 205, 133, 63, 1, SVGCompliance | X11Compliance | XPMCompliance },
657  { "pink", 255, 192, 203, 1, SVGCompliance | X11Compliance | XPMCompliance },
658  { "pink1", 255, 181, 197, 1, X11Compliance },
659  { "pink2", 238, 169, 184, 1, X11Compliance },
660  { "pink3", 205, 145, 158, 1, X11Compliance },
661  { "pink4", 139, 99, 108, 1, X11Compliance },
662  { "plum", 221, 160, 221, 1, SVGCompliance | X11Compliance | XPMCompliance },
663  { "plum1", 255, 187, 255, 1, X11Compliance },
664  { "plum2", 238, 174, 238, 1, X11Compliance },
665  { "plum3", 205, 150, 205, 1, X11Compliance },
666  { "plum4", 139, 102, 139, 1, X11Compliance },
667  { "PowderBlue", 176, 224, 230, 1, SVGCompliance | X11Compliance | XPMCompliance },
668  { "purple", 128, 0, 128, 1, SVGCompliance },
669  { "purple", 160, 32, 240, 1, X11Compliance | XPMCompliance },
670  { "purple1", 155, 48, 255, 1, X11Compliance },
671  { "purple2", 145, 44, 238, 1, X11Compliance },
672  { "purple3", 125, 38, 205, 1, X11Compliance },
673  { "purple4", 85, 26, 139, 1, X11Compliance },
674  { "red1", 255, 0, 0, 1, X11Compliance },
675  { "red2", 238, 0, 0, 1, X11Compliance },
676  { "red3", 205, 0, 0, 1, X11Compliance },
677  { "red4", 139, 0, 0, 1, X11Compliance },
678  { "RosyBrown", 188, 143, 143, 1, SVGCompliance | X11Compliance | XPMCompliance },
679  { "RosyBrown1", 255, 193, 193, 1, X11Compliance },
680  { "RosyBrown2", 238, 180, 180, 1, X11Compliance },
681  { "RosyBrown3", 205, 155, 155, 1, X11Compliance },
682  { "RosyBrown4", 139, 105, 105, 1, X11Compliance },
683  { "RoyalBlue", 65, 105, 225, 1, SVGCompliance | X11Compliance | XPMCompliance },
684  { "RoyalBlue1", 72, 118, 255, 1, X11Compliance },
685  { "RoyalBlue2", 67, 110, 238, 1, X11Compliance },
686  { "RoyalBlue3", 58, 95, 205, 1, X11Compliance },
687  { "RoyalBlue4", 39, 64, 139, 1, X11Compliance },
688  { "SaddleBrown", 139, 69, 19, 1, SVGCompliance | X11Compliance | XPMCompliance },
689  { "salmon", 250, 128, 114, 1, SVGCompliance | X11Compliance | XPMCompliance },
690  { "salmon1", 255, 140, 105, 1, X11Compliance },
691  { "salmon2", 238, 130, 98, 1, X11Compliance },
692  { "salmon3", 205, 112, 84, 1, X11Compliance },
693  { "salmon4", 139, 76, 57, 1, X11Compliance },
694  { "SandyBrown", 244, 164, 96, 1, SVGCompliance | X11Compliance | XPMCompliance },
695  { "SeaGreen", 46, 139, 87, 1, SVGCompliance | X11Compliance | XPMCompliance },
696  { "SeaGreen1", 84, 255, 159, 1, X11Compliance },
697  { "SeaGreen2", 78, 238, 148, 1, X11Compliance },
698  { "SeaGreen3", 67, 205, 128, 1, X11Compliance },
699  { "SeaGreen4", 46, 139, 87, 1, X11Compliance },
700  { "seashell", 255, 245, 238, 1, SVGCompliance | X11Compliance | XPMCompliance },
701  { "seashell1", 255, 245, 238, 1, X11Compliance },
702  { "seashell2", 238, 229, 222, 1, X11Compliance },
703  { "seashell3", 205, 197, 191, 1, X11Compliance },
704  { "seashell4", 139, 134, 130, 1, X11Compliance },
705  { "sienna", 160, 82, 45, 1, SVGCompliance | X11Compliance | XPMCompliance },
706  { "sienna1", 255, 130, 71, 1, X11Compliance },
707  { "sienna2", 238, 121, 66, 1, X11Compliance },
708  { "sienna3", 205, 104, 57, 1, X11Compliance },
709  { "sienna4", 139, 71, 38, 1, X11Compliance },
710  { "silver", 192, 192, 192, 1, SVGCompliance },
711  { "SkyBlue", 135, 206, 235, 1, SVGCompliance | X11Compliance | XPMCompliance },
712  { "SkyBlue1", 135, 206, 255, 1, X11Compliance },
713  { "SkyBlue2", 126, 192, 238, 1, X11Compliance },
714  { "SkyBlue3", 108, 166, 205, 1, X11Compliance },
715  { "SkyBlue4", 74, 112, 139, 1, X11Compliance },
716  { "SlateBlue", 106, 90, 205, 1, SVGCompliance | X11Compliance | XPMCompliance },
717  { "SlateBlue1", 131, 111, 255, 1, X11Compliance },
718  { "SlateBlue2", 122, 103, 238, 1, X11Compliance },
719  { "SlateBlue3", 105, 89, 205, 1, X11Compliance },
720  { "SlateBlue4", 71, 60, 139, 1, X11Compliance },
721  { "SlateGray", 112, 128, 144, 1, SVGCompliance | X11Compliance | XPMCompliance },
722  { "SlateGray1", 198, 226, 255, 1, X11Compliance },
723  { "SlateGray2", 185, 211, 238, 1, X11Compliance },
724  { "SlateGray3", 159, 182, 205, 1, X11Compliance },
725  { "SlateGray4", 108, 123, 139, 1, X11Compliance },
726  { "SlateGrey", 112, 128, 144, 1, SVGCompliance | X11Compliance },
727  { "snow", 255, 250, 250, 1, SVGCompliance | X11Compliance | XPMCompliance },
728  { "snow1", 255, 250, 250, 1, X11Compliance },
729  { "snow2", 238, 233, 233, 1, X11Compliance },
730  { "snow3", 205, 201, 201, 1, X11Compliance },
731  { "snow4", 139, 137, 137, 1, X11Compliance },
732  { "SpringGreen", 0, 255, 127, 1, SVGCompliance | X11Compliance | XPMCompliance },
733  { "SpringGreen1", 0, 255, 127, 1, X11Compliance },
734  { "SpringGreen2", 0, 238, 118, 1, X11Compliance },
735  { "SpringGreen3", 0, 205, 102, 1, X11Compliance },
736  { "SpringGreen4", 0, 139, 69, 1, X11Compliance },
737  { "SteelBlue", 70, 130, 180, 1, SVGCompliance | X11Compliance | XPMCompliance },
738  { "SteelBlue1", 99, 184, 255, 1, X11Compliance },
739  { "SteelBlue2", 92, 172, 238, 1, X11Compliance },
740  { "SteelBlue3", 79, 148, 205, 1, X11Compliance },
741  { "SteelBlue4", 54, 100, 139, 1, X11Compliance },
742  { "tan", 210, 180, 140, 1, SVGCompliance | X11Compliance | XPMCompliance },
743  { "tan1", 255, 165, 79, 1, X11Compliance },
744  { "tan2", 238, 154, 73, 1, X11Compliance },
745  { "tan3", 205, 133, 63, 1, X11Compliance },
746  { "tan4", 139, 90, 43, 1, X11Compliance },
747  { "teal", 0, 128, 128, 1, SVGCompliance },
748  { "thistle", 216, 191, 216, 1, SVGCompliance | X11Compliance | XPMCompliance },
749  { "thistle1", 255, 225, 255, 1, X11Compliance },
750  { "thistle2", 238, 210, 238, 1, X11Compliance },
751  { "thistle3", 205, 181, 205, 1, X11Compliance },
752  { "thistle4", 139, 123, 139, 1, X11Compliance },
753  { "tomato", 255, 99, 71, 1, SVGCompliance | X11Compliance | XPMCompliance },
754  { "tomato1", 255, 99, 71, 1, X11Compliance },
755  { "tomato2", 238, 92, 66, 1, X11Compliance },
756  { "tomato3", 205, 79, 57, 1, X11Compliance },
757  { "tomato4", 139, 54, 38, 1, X11Compliance },
758  { "transparent", 0, 0, 0, 0, SVGCompliance },
759  { "turquoise", 64, 224, 208, 1, SVGCompliance | X11Compliance | XPMCompliance },
760  { "turquoise1", 0, 245, 255, 1, X11Compliance },
761  { "turquoise2", 0, 229, 238, 1, X11Compliance },
762  { "turquoise3", 0, 197, 205, 1, X11Compliance },
763  { "turquoise4", 0, 134, 139, 1, X11Compliance },
764  { "violet", 238, 130, 238, 1, SVGCompliance | X11Compliance | XPMCompliance },
765  { "VioletRed", 208, 32, 144, 1, X11Compliance | XPMCompliance },
766  { "VioletRed1", 255, 62, 150, 1, X11Compliance },
767  { "VioletRed2", 238, 58, 140, 1, X11Compliance },
768  { "VioletRed3", 205, 50, 120, 1, X11Compliance },
769  { "VioletRed4", 139, 34, 82, 1, X11Compliance },
770  { "wheat", 245, 222, 179, 1, SVGCompliance | X11Compliance | XPMCompliance },
771  { "wheat1", 255, 231, 186, 1, X11Compliance },
772  { "wheat2", 238, 216, 174, 1, X11Compliance },
773  { "wheat3", 205, 186, 150, 1, X11Compliance },
774  { "wheat4", 139, 126, 102, 1, X11Compliance },
775  { "WhiteSmoke", 245, 245, 245, 1, SVGCompliance | X11Compliance | XPMCompliance },
776  { "yellow1", 255, 255, 0, 1, X11Compliance },
777  { "yellow2", 238, 238, 0, 1, X11Compliance },
778  { "yellow3", 205, 205, 0, 1, X11Compliance },
779  { "yellow4", 139, 139, 0, 1, X11Compliance },
780  { "YellowGreen", 154, 205, 50, 1, SVGCompliance | X11Compliance | XPMCompliance }
781  };
782 
783 /*
784  Static declarations.
785 */
786 static LinkedListInfo
787  *color_cache = (LinkedListInfo *) NULL;
788 
789 static SemaphoreInfo
790  *color_semaphore = (SemaphoreInfo *) NULL;
791 
792 /*
793  Forward declarations.
794 */
795 static MagickBooleanType
796  IsColorCacheInstantiated(ExceptionInfo *);
797 
798 #if !MAGICKCORE_ZERO_CONFIGURATION_SUPPORT
799 static MagickBooleanType
800  LoadColorCache(LinkedListInfo *,const char *,const char *,const size_t,
801  ExceptionInfo *);
802 #endif
803 
804 /*
805 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
806 % %
807 % %
808 % %
809 % A c q u i r e C o l o r C a c h e %
810 % %
811 % %
812 % %
813 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
814 %
815 % AcquireColorCache() caches one or more color configurations which provides a
816 % mapping between color attributes and a color name.
817 %
818 % The format of the AcquireColorCache method is:
819 %
820 % LinkedListInfo *AcquireColorCache(const char *filename,
821 % ExceptionInfo *exception)
822 %
823 % A description of each parameter follows:
824 %
825 % o filename: the font file name.
826 %
827 % o exception: return any errors or warnings in this structure.
828 %
829 */
830 static LinkedListInfo *AcquireColorCache(const char *filename,
831  ExceptionInfo *exception)
832 {
834  *cache;
835 
836  MagickStatusType
837  status;
838 
839  ssize_t
840  i;
841 
842  /*
843  Load external color map.
844  */
845  cache=NewLinkedList(0);
846  if (cache == (LinkedListInfo *) NULL)
847  ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed");
848  status=MagickTrue;
849 #if !MAGICKCORE_ZERO_CONFIGURATION_SUPPORT
850  {
851  const StringInfo
852  *option;
853 
855  *options;
856 
857  options=GetConfigureOptions(filename,exception);
858  option=(const StringInfo *) GetNextValueInLinkedList(options);
859  while (option != (const StringInfo *) NULL)
860  {
861  status&=LoadColorCache(cache,(const char *) GetStringInfoDatum(option),
862  GetStringInfoPath(option),0,exception);
863  option=(const StringInfo *) GetNextValueInLinkedList(options);
864  }
865  options=DestroyConfigureOptions(options);
866  }
867 #endif
868  /*
869  Load built-in color map.
870  */
871  for (i=0; i < (ssize_t) (sizeof(Colormap)/sizeof(*Colormap)); i++)
872  {
873  ColorInfo
874  *color_info;
875 
876  const ColormapInfo
877  *p;
878 
879  p=Colormap+i;
880  color_info=(ColorInfo *) AcquireMagickMemory(sizeof(*color_info));
881  if (color_info == (ColorInfo *) NULL)
882  {
883  (void) ThrowMagickException(exception,GetMagickModule(),
884  ResourceLimitError,"MemoryAllocationFailed","`%s'",p->name);
885  continue;
886  }
887  (void) memset(color_info,0,sizeof(*color_info));
888  color_info->path=(char *) "[built-in]";
889  color_info->name=(char *) p->name;
890  GetMagickPixelPacket((Image *) NULL,&color_info->color);
891  color_info->color.red=(MagickRealType) ScaleCharToQuantum(
892  GetPixelRed(p));
893  color_info->color.green=(MagickRealType) ScaleCharToQuantum(
894  GetPixelGreen(p));
895  color_info->color.blue=(MagickRealType) ScaleCharToQuantum(
896  GetPixelBlue(p));
897  color_info->color.opacity=(QuantumRange-(MagickRealType) QuantumRange*
898  p->alpha);
899  color_info->compliance=(ComplianceType) p->compliance;
900  color_info->exempt=MagickTrue;
901  color_info->signature=MagickCoreSignature;
902  status&=AppendValueToLinkedList(cache,color_info);
903  if (status == MagickFalse)
904  (void) ThrowMagickException(exception,GetMagickModule(),
905  ResourceLimitError,"MemoryAllocationFailed","`%s'",color_info->name);
906  }
907  return(cache);
908 }
909 
910 /*
911 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
912 % %
913 % %
914 % %
915 + C o l o r C o m p o n e n t G e n e s i s %
916 % %
917 % %
918 % %
919 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
920 %
921 % ColorComponentGenesis() instantiates the color component.
922 %
923 % The format of the ColorComponentGenesis method is:
924 %
925 % MagickBooleanType ColorComponentGenesis(void)
926 %
927 */
928 MagickExport MagickBooleanType ColorComponentGenesis(void)
929 {
930  if (color_semaphore == (SemaphoreInfo *) NULL)
931  color_semaphore=AllocateSemaphoreInfo();
932  return(MagickTrue);
933 }
934 
935 /*
936 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
937 % %
938 % %
939 % %
940 + C o l o r C o m p o n e n t T e r m i n u s %
941 % %
942 % %
943 % %
944 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
945 %
946 % ColorComponentTerminus() destroys the color component.
947 %
948 % The format of the ColorComponentTerminus method is:
949 %
950 % ColorComponentTerminus(void)
951 %
952 */
953 
954 static void *DestroyColorElement(void *color_info)
955 {
956  ColorInfo
957  *p;
958 
959  p=(ColorInfo *) color_info;
960  if (p->exempt == MagickFalse)
961  {
962  if (p->path != (char *) NULL)
963  p->path=DestroyString(p->path);
964  if (p->name != (char *) NULL)
965  p->name=DestroyString(p->name);
966  }
967  p=(ColorInfo *) RelinquishMagickMemory(p);
968  return((void *) NULL);
969 }
970 
971 MagickExport void ColorComponentTerminus(void)
972 {
973  if (color_semaphore == (SemaphoreInfo *) NULL)
974  ActivateSemaphoreInfo(&color_semaphore);
975  LockSemaphoreInfo(color_semaphore);
976  if (color_cache != (LinkedListInfo *) NULL)
977  color_cache=DestroyLinkedList(color_cache,DestroyColorElement);
978  UnlockSemaphoreInfo(color_semaphore);
979  DestroySemaphoreInfo(&color_semaphore);
980 }
981 
982 /*
983 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
984 % %
985 % %
986 % %
987 + G e t C o l o r C o m p l i a n c e %
988 % %
989 % %
990 % %
991 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
992 %
993 % GetColorInfo() searches the color list for the specified name and standards
994 % compliance and if found returns attributes for that color.
995 %
996 % The format of the GetColorInfo method is:
997 %
998 % const PixelPacket *GetColorInfo(const char *name,
999 % const ComplianceType compliance,ExceptionInfo *exception)
1000 %
1001 % A description of each parameter follows:
1002 %
1003 % o name: the color name.
1004 %
1005 % o compliance: Adhere to this color standard: SVG, X11, or XPM.
1006 %
1007 % o exception: return any errors or warnings in this structure.
1008 %
1009 */
1010 MagickExport const ColorInfo *GetColorCompliance(const char *name,
1011  const ComplianceType compliance,ExceptionInfo *exception)
1012 {
1013  char
1014  colorname[MaxTextExtent];
1015 
1016  const ColorInfo
1017  *p;
1018 
1019  char
1020  *q;
1021 
1022  assert(exception != (ExceptionInfo *) NULL);
1023  if (IsColorCacheInstantiated(exception) == MagickFalse)
1024  return((const ColorInfo *) NULL);
1025  /*
1026  Strip names of whitespace.
1027  */
1028  *colorname='\0';
1029  if (name != (const char *) NULL)
1030  (void) CopyMagickString(colorname,name,MaxTextExtent);
1031  for (q=colorname; *q != '\0'; q++)
1032  {
1033  if (isspace((int) ((unsigned char) *q)) == 0)
1034  continue;
1035  (void) CopyMagickString(q,q+1,MaxTextExtent);
1036  q--;
1037  }
1038  /*
1039  Search for color tag.
1040  */
1041  LockSemaphoreInfo(color_semaphore);
1042  ResetLinkedListIterator(color_cache);
1043  p=(const ColorInfo *) GetNextValueInLinkedList(color_cache);
1044  if ((name == (const char *) NULL) || (LocaleCompare(name,"*") == 0))
1045  {
1046  UnlockSemaphoreInfo(color_semaphore);
1047  return(p);
1048  }
1049  while (p != (const ColorInfo *) NULL)
1050  {
1051  if (((p->compliance & compliance) != 0) &&
1052  (LocaleCompare(colorname,p->name) == 0))
1053  break;
1054  p=(const ColorInfo *) GetNextValueInLinkedList(color_cache);
1055  }
1056  if (p == (ColorInfo *) NULL)
1057  (void) ThrowMagickException(exception,GetMagickModule(),OptionWarning,
1058  "UnrecognizedColor","`%s'",name);
1059  else
1060  (void) InsertValueInLinkedList(color_cache,0,
1061  RemoveElementByValueFromLinkedList(color_cache,p));
1062  UnlockSemaphoreInfo(color_semaphore);
1063  return(p);
1064 }
1065 
1066 /*
1067 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1068 % %
1069 % %
1070 % %
1071 + G e t C o l o r I n f o %
1072 % %
1073 % %
1074 % %
1075 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1076 %
1077 % GetColorInfo() searches the color list for the specified name and if found
1078 % returns attributes for that color.
1079 %
1080 % The format of the GetColorInfo method is:
1081 %
1082 % const PixelPacket *GetColorInfo(const char *name,
1083 % ExceptionInfo *exception)
1084 %
1085 % A description of each parameter follows:
1086 %
1087 % o color_info: search the color list for the specified name and if found
1088 % return attributes for that color.
1089 %
1090 % o name: the color name.
1091 %
1092 % o exception: return any errors or warnings in this structure.
1093 %
1094 */
1095 MagickExport const ColorInfo *GetColorInfo(const char *name,
1096  ExceptionInfo *exception)
1097 {
1098  return(GetColorCompliance(name,AllCompliance,exception));
1099 }
1100 
1101 /*
1102 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1103 % %
1104 % %
1105 % %
1106 + C o n c a t e n a t e C o l o r C o m p o n e n t %
1107 % %
1108 % %
1109 % %
1110 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1111 %
1112 % ConcatenateColorComponent() returns the pixel as a canonical string.
1113 %
1114 % The format of the ConcatenateColorComponent() method is:
1115 %
1116 % void ConcatenateColorComponent(const MagickPixelPacket *pixel,
1117 % const ChannelType channel,const ComplianceType compliance,char *tuple)
1118 %
1119 % A description of each parameter follows.
1120 %
1121 % o pixel: The pixel.
1122 %
1123 % channel: The channel.
1124 %
1125 % o compliance: Adhere to this color standard: SVG, X11, or XPM.
1126 %
1127 % o tuple: The color tuple.
1128 %
1129 */
1130 
1131 static inline MagickBooleanType IsSVGCompliant(const MagickPixelPacket *pixel)
1132 {
1133 #define SVGCompliant(component) ((double) \
1134  ScaleCharToQuantum(ScaleQuantumToChar(ClampToQuantum(component))))
1135 #define SVGEpsilon 1.0e-6
1136 
1137  /*
1138  SVG requires color depths > 8 expressed as percentages.
1139  */
1140  if (fabs((double) (SVGCompliant(pixel->red)-pixel->red)) >= SVGEpsilon)
1141  return(MagickFalse);
1142  if (fabs((double) (SVGCompliant(pixel->green)-pixel->green)) >= SVGEpsilon)
1143  return(MagickFalse);
1144  if (fabs((double) (SVGCompliant(pixel->blue)-pixel->blue)) >= SVGEpsilon)
1145  return(MagickFalse);
1146  if ((pixel->colorspace == CMYKColorspace) &&
1147  (fabs((double) (SVGCompliant(pixel->index)-pixel->index)) >= SVGEpsilon))
1148  return(MagickFalse);
1149  return(MagickTrue);
1150 }
1151 
1152 MagickExport void ConcatenateColorComponent(const MagickPixelPacket *pixel,
1153  const ChannelType channel,const ComplianceType compliance,char *tuple)
1154 {
1155  char
1156  component[MagickPathExtent];
1157 
1158  float
1159  color,
1160  scale;
1161 
1162  color=0.0f;
1163  scale=QuantumRange;
1164  if ((compliance != NoCompliance) || (pixel->depth <= 8))
1165  scale=255.0f;
1166  if ((compliance != NoCompliance) &&
1167  (IssRGBCompatibleColorspace(pixel->colorspace) != MagickFalse) &&
1168  (IsSVGCompliant(pixel) == MagickFalse))
1169  scale=100.0f;
1170  switch (channel)
1171  {
1172  case RedChannel:
1173  {
1174  color=pixel->red;
1175  if (IsHueCompatibleColorspace(pixel->colorspace) != MagickFalse)
1176  scale=360.0f;
1177  if ((compliance != NoCompliance) && (pixel->colorspace == LabColorspace))
1178  scale=100.0f;
1179  break;
1180  }
1181  case GreenChannel:
1182  {
1183  color=pixel->green;
1184  if (IsHueCompatibleColorspace(pixel->colorspace) != MagickFalse)
1185  scale=100.0f;
1186  if ((compliance != NoCompliance) && (pixel->colorspace == LabColorspace))
1187  color-=QuantumRange/2.0f;
1188  break;
1189  }
1190  case BlueChannel:
1191  {
1192  color=pixel->blue;
1193  if (IsHueCompatibleColorspace(pixel->colorspace) != MagickFalse)
1194  scale=100.0f;
1195  if (pixel->colorspace == LabColorspace)
1196  color-=QuantumRange/2.0f;
1197  break;
1198  }
1199  case AlphaChannel:
1200  {
1201  color=QuantumRange-pixel->opacity;
1202  if (compliance != NoCompliance)
1203  scale=1.0f;
1204  break;
1205  }
1206  case IndexChannel:
1207  {
1208  color=pixel->index;
1209  break;
1210  }
1211  default:
1212  break;
1213  }
1214  if ((scale != 100.0f) || (pixel->colorspace == LabColorspace))
1215  (void) FormatLocaleString(component,MagickPathExtent,"%.*g",
1216  GetMagickPrecision(),(double) (scale*QuantumScale*color));
1217  else
1218  (void) FormatLocaleString(component,MagickPathExtent,"%.*g%%",
1219  GetMagickPrecision(),(double) (scale*QuantumScale*color));
1220  (void) ConcatenateMagickString(tuple,component,MagickPathExtent);
1221 }
1222 
1223 /*
1224 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1225 % %
1226 % %
1227 % %
1228 % G e t C o l o r I n f o L i s t %
1229 % %
1230 % %
1231 % %
1232 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1233 %
1234 % GetColorInfoList() returns any colors that match the specified pattern.
1235 %
1236 % The format of the GetColorInfoList function is:
1237 %
1238 % const ColorInfo **GetColorInfoList(const char *pattern,
1239 % size_t *number_colors,ExceptionInfo *exception)
1240 %
1241 % A description of each parameter follows:
1242 %
1243 % o pattern: Specifies a pointer to a text string containing a pattern.
1244 %
1245 % o number_colors: This integer returns the number of colors in the list.
1246 %
1247 % o exception: return any errors or warnings in this structure.
1248 %
1249 */
1250 
1251 #if defined(__cplusplus) || defined(c_plusplus)
1252 extern "C" {
1253 #endif
1254 
1255 static int ColorInfoCompare(const void *x,const void *y)
1256 {
1257  const ColorInfo
1258  **p,
1259  **q;
1260 
1261  int
1262  cmp;
1263 
1264  p=(const ColorInfo **) x,
1265  q=(const ColorInfo **) y;
1266  cmp=LocaleCompare((*p)->path,(*q)->path);
1267  if (cmp == 0)
1268  return(LocaleCompare((*p)->name,(*q)->name));
1269  return(cmp);
1270 }
1271 
1272 #if defined(__cplusplus) || defined(c_plusplus)
1273 }
1274 #endif
1275 
1276 MagickExport const ColorInfo **GetColorInfoList(const char *pattern,
1277  size_t *number_colors,ExceptionInfo *exception)
1278 {
1279  const ColorInfo
1280  **colors;
1281 
1282  const ColorInfo
1283  *p;
1284 
1285  ssize_t
1286  i;
1287 
1288  /*
1289  Allocate color list.
1290  */
1291  assert(pattern != (char *) NULL);
1292  assert(number_colors != (size_t *) NULL);
1293  if (IsEventLogging() != MagickFalse)
1294  (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",pattern);
1295  *number_colors=0;
1296  p=GetColorInfo("*",exception);
1297  if (p == (const ColorInfo *) NULL)
1298  return((const ColorInfo **) NULL);
1299  colors=(const ColorInfo **) AcquireQuantumMemory((size_t)
1300  GetNumberOfElementsInLinkedList(color_cache)+1UL,sizeof(*colors));
1301  if (colors == (const ColorInfo **) NULL)
1302  return((const ColorInfo **) NULL);
1303  /*
1304  Generate color list.
1305  */
1306  LockSemaphoreInfo(color_semaphore);
1307  ResetLinkedListIterator(color_cache);
1308  p=(const ColorInfo *) GetNextValueInLinkedList(color_cache);
1309  for (i=0; p != (const ColorInfo *) NULL; )
1310  {
1311  if ((p->stealth == MagickFalse) &&
1312  (GlobExpression(p->name,pattern,MagickFalse) != MagickFalse))
1313  colors[i++]=p;
1314  p=(const ColorInfo *) GetNextValueInLinkedList(color_cache);
1315  }
1316  UnlockSemaphoreInfo(color_semaphore);
1317  qsort((void *) colors,(size_t) i,sizeof(*colors),ColorInfoCompare);
1318  colors[i]=(ColorInfo *) NULL;
1319  *number_colors=(size_t) i;
1320  return(colors);
1321 }
1322 
1323 /*
1324 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1325 % %
1326 % %
1327 % %
1328 % G e t C o l o r L i s t %
1329 % %
1330 % %
1331 % %
1332 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1333 %
1334 % GetColorList() returns any colors that match the specified pattern.
1335 %
1336 % The format of the GetColorList function is:
1337 %
1338 % char **GetColorList(const char *pattern,size_t *number_colors,
1339 % ExceptionInfo *exception)
1340 %
1341 % A description of each parameter follows:
1342 %
1343 % o pattern: Specifies a pointer to a text string containing a pattern.
1344 %
1345 % o number_colors: This integer returns the number of colors in the list.
1346 %
1347 % o exception: return any errors or warnings in this structure.
1348 %
1349 */
1350 
1351 #if defined(__cplusplus) || defined(c_plusplus)
1352 extern "C" {
1353 #endif
1354 
1355 static int ColorCompare(const void *x,const void *y)
1356 {
1357  const char
1358  **p,
1359  **q;
1360 
1361  p=(const char **) x;
1362  q=(const char **) y;
1363  return(LocaleCompare(*p,*q));
1364 }
1365 
1366 #if defined(__cplusplus) || defined(c_plusplus)
1367 }
1368 #endif
1369 
1370 MagickExport char **GetColorList(const char *pattern,
1371  size_t *number_colors,ExceptionInfo *exception)
1372 {
1373  char
1374  **colors;
1375 
1376  const ColorInfo
1377  *p;
1378 
1379  ssize_t
1380  i;
1381 
1382  /*
1383  Allocate color list.
1384  */
1385  assert(pattern != (char *) NULL);
1386  assert(number_colors != (size_t *) NULL);
1387  if (IsEventLogging() != MagickFalse)
1388  (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",pattern);
1389  *number_colors=0;
1390  p=GetColorInfo("*",exception);
1391  if (p == (const ColorInfo *) NULL)
1392  return((char **) NULL);
1393  colors=(char **) AcquireQuantumMemory((size_t)
1394  GetNumberOfElementsInLinkedList(color_cache)+1UL,sizeof(*colors));
1395  if (colors == (char **) NULL)
1396  return((char **) NULL);
1397  /*
1398  Generate color list.
1399  */
1400  LockSemaphoreInfo(color_semaphore);
1401  ResetLinkedListIterator(color_cache);
1402  p=(const ColorInfo *) GetNextValueInLinkedList(color_cache);
1403  for (i=0; p != (const ColorInfo *) NULL; )
1404  {
1405  if ((p->stealth == MagickFalse) &&
1406  (GlobExpression(p->name,pattern,MagickFalse) != MagickFalse))
1407  colors[i++]=ConstantString(p->name);
1408  p=(const ColorInfo *) GetNextValueInLinkedList(color_cache);
1409  }
1410  UnlockSemaphoreInfo(color_semaphore);
1411  qsort((void *) colors,(size_t) i,sizeof(*colors),ColorCompare);
1412  colors[i]=(char *) NULL;
1413  *number_colors=(size_t) i;
1414  return(colors);
1415 }
1416 
1417 /*
1418 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1419 % %
1420 % %
1421 % %
1422 + G e t C o l o r T u p l e %
1423 % %
1424 % %
1425 % %
1426 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1427 %
1428 % GetColorTuple() returns a color as a color tuple string (e.g. rgba(255,0,0))
1429 % or hex string (e.g. #FF0000).
1430 %
1431 % The format of the GetColorTuple method is:
1432 %
1433 % GetColorTuple(const MagickPixelPacket *pixel,const MagickBooleanType hex,
1434 % char *tuple)
1435 %
1436 % A description of each parameter follows.
1437 %
1438 % o pixel: the pixel.
1439 %
1440 % o hex: A value other than zero returns the tuple in a hexidecimal format.
1441 %
1442 % o tuple: Return the color tuple as this string.
1443 %
1444 */
1445 
1446 static void ConcatentateHexColorComponent(const MagickPixelPacket *pixel,
1447  const ChannelType channel,char *tuple)
1448 {
1449  char
1450  component[MaxTextExtent];
1451 
1452  MagickRealType
1453  color;
1454 
1455  color=0.0;
1456  switch (channel)
1457  {
1458  case RedChannel:
1459  {
1460  color=pixel->red;
1461  break;
1462  }
1463  case GreenChannel:
1464  {
1465  color=pixel->green;
1466  break;
1467  }
1468  case BlueChannel:
1469  {
1470  color=pixel->blue;
1471  break;
1472  }
1473  case OpacityChannel:
1474  {
1475  color=(MagickRealType) QuantumRange-pixel->opacity;
1476  break;
1477  }
1478  case IndexChannel:
1479  {
1480  color=pixel->index;
1481  break;
1482  }
1483  default:
1484  break;
1485  }
1486  if (pixel->depth > 32)
1487  {
1488  (void) FormatLocaleString(component,MaxTextExtent,"%08lX%08lX",
1489  (unsigned long) ScaleQuantumToLong(ClampToQuantum(color)),
1490  (unsigned long) ScaleQuantumToLong(ClampToQuantum(color)));
1491  (void) ConcatenateMagickString(tuple,component,MaxTextExtent);
1492  return;
1493  }
1494  if (pixel->depth > 16)
1495  {
1496  (void) FormatLocaleString(component,MaxTextExtent,"%08X",
1497  (unsigned int) ScaleQuantumToLong(ClampToQuantum(color)));
1498  (void) ConcatenateMagickString(tuple,component,MaxTextExtent);
1499  return;
1500  }
1501  if (pixel->depth > 8)
1502  {
1503  (void) FormatLocaleString(component,MaxTextExtent,"%04X",
1504  ScaleQuantumToShort(ClampToQuantum(color)));
1505  (void) ConcatenateMagickString(tuple,component,MaxTextExtent);
1506  return;
1507  }
1508  (void) FormatLocaleString(component,MaxTextExtent,"%02X",
1509  ScaleQuantumToChar(ClampToQuantum(color)));
1510  (void) ConcatenateMagickString(tuple,component,MaxTextExtent);
1511  return;
1512 }
1513 
1514 MagickExport void GetColorTuple(const MagickPixelPacket *pixel,
1515  const MagickBooleanType hex,char *tuple)
1516 {
1518  color;
1519 
1520  assert(pixel != (const MagickPixelPacket *) NULL);
1521  assert(tuple != (char *) NULL);
1522  if (IsEventLogging() != MagickFalse)
1523  (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",tuple);
1524  *tuple='\0';
1525  if (hex != MagickFalse)
1526  {
1527  /*
1528  Convert pixel to hex color.
1529  */
1530  (void) ConcatenateMagickString(tuple,"#",MaxTextExtent);
1531  ConcatentateHexColorComponent(pixel,RedChannel,tuple);
1532  ConcatentateHexColorComponent(pixel,GreenChannel,tuple);
1533  ConcatentateHexColorComponent(pixel,BlueChannel,tuple);
1534  if (pixel->colorspace == CMYKColorspace)
1535  ConcatentateHexColorComponent(pixel,IndexChannel,tuple);
1536  if (pixel->matte != MagickFalse)
1537  ConcatentateHexColorComponent(pixel,OpacityChannel,tuple);
1538  return;
1539  }
1540  /*
1541  Convert pixel to rgb() or cmyk() color.
1542  */
1543  color=(*pixel);
1544  if (color.depth > 8)
1545  {
1546  MagickStatusType
1547  status;
1548 
1549  /*
1550  SVG requires color depths > 8 expressed as percentages.
1551  */
1552  status=color.red == SVGCompliant(color.red);
1553  status&=color.green == SVGCompliant(color.green);
1554  status&=color.blue == SVGCompliant(color.blue);
1555  if (color.colorspace != CMYKColorspace)
1556  status&=color.index == SVGCompliant(color.index);
1557  if (color.matte != MagickFalse)
1558  status&=color.opacity == SVGCompliant(color.opacity);
1559  if (status != MagickFalse)
1560  color.depth=8;
1561  }
1562  (void) ConcatenateMagickString(tuple,CommandOptionToMnemonic(
1563  MagickColorspaceOptions,(ssize_t) color.colorspace),MaxTextExtent);
1564  if (color.matte != MagickFalse)
1565  (void) ConcatenateMagickString(tuple,"a",MaxTextExtent);
1566  (void) ConcatenateMagickString(tuple,"(",MaxTextExtent);
1567  if ((color.colorspace == LinearGRAYColorspace) ||
1568  (color.colorspace == GRAYColorspace))
1569  ConcatenateColorComponent(&color,GrayChannel,SVGCompliance,tuple);
1570  else
1571  {
1572  ConcatenateColorComponent(&color,RedChannel,SVGCompliance,tuple);
1573  (void) ConcatenateMagickString(tuple,",",MaxTextExtent);
1574  ConcatenateColorComponent(&color,GreenChannel,SVGCompliance,tuple);
1575  (void) ConcatenateMagickString(tuple,",",MaxTextExtent);
1576  ConcatenateColorComponent(&color,BlueChannel,SVGCompliance,tuple);
1577  }
1578  if (color.colorspace == CMYKColorspace)
1579  {
1580  (void) ConcatenateMagickString(tuple,",",MaxTextExtent);
1581  ConcatenateColorComponent(&color,IndexChannel,SVGCompliance,tuple);
1582  }
1583  if (color.matte != MagickFalse)
1584  {
1585  (void) ConcatenateMagickString(tuple,",",MaxTextExtent);
1586  ConcatenateColorComponent(&color,AlphaChannel,SVGCompliance,tuple);
1587  }
1588  (void) ConcatenateMagickString(tuple,")",MaxTextExtent);
1589  LocaleLower(tuple);
1590  return;
1591 }
1592 
1593 /*
1594 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1595 % %
1596 % %
1597 % %
1598 + I s C o l o r C a c h e I n s t a n t i a t e d %
1599 % %
1600 % %
1601 % %
1602 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1603 %
1604 % IsColorCacheInstantiated() determines if the color list is instantiated. If
1605 % not, it instantiates the list and returns it.
1606 %
1607 % The format of the IsColorInstantiated method is:
1608 %
1609 % MagickBooleanType IsColorCacheInstantiated(ExceptionInfo *exception)
1610 %
1611 % A description of each parameter follows.
1612 %
1613 % o exception: return any errors or warnings in this structure.
1614 %
1615 */
1616 static MagickBooleanType IsColorCacheInstantiated(ExceptionInfo *exception)
1617 {
1618  if (color_cache == (LinkedListInfo *) NULL)
1619  {
1620  if (color_semaphore == (SemaphoreInfo *) NULL)
1621  ActivateSemaphoreInfo(&color_semaphore);
1622  LockSemaphoreInfo(color_semaphore);
1623  if (color_cache == (LinkedListInfo *) NULL)
1624  color_cache=AcquireColorCache(ColorFilename,exception);
1625  UnlockSemaphoreInfo(color_semaphore);
1626  }
1627  return(color_cache != (LinkedListInfo *) NULL ? MagickTrue : MagickFalse);
1628 }
1629 
1630 /*
1631 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1632 % %
1633 % %
1634 % %
1635 + I s C o l o r S i m i l a r %
1636 % %
1637 % %
1638 % %
1639 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1640 %
1641 % IsColorSimilar() returns MagickTrue if the distance between two colors is
1642 % less than the specified distance in a linear three dimensional color space.
1643 % This method is used by ColorFloodFill() and other algorithms which
1644 % compare two colors.
1645 %
1646 % The format of the IsColorSimilar method is:
1647 %
1648 % void IsColorSimilar(const Image *image,const PixelPacket *p,
1649 % const PixelPacket *q)
1650 %
1651 % A description of each parameter follows:
1652 %
1653 % o image: the image.
1654 %
1655 % o p: Pixel p.
1656 %
1657 % o q: Pixel q.
1658 %
1659 */
1660 MagickExport MagickBooleanType IsColorSimilar(const Image *image,
1661  const PixelPacket *p,const PixelPacket *q)
1662 {
1663  MagickRealType
1664  fuzz,
1665  pixel;
1666 
1667  MagickRealType
1668  distance,
1669  scale;
1670 
1671  fuzz=(double) MagickMax(image->fuzz,(MagickRealType) MagickSQ1_2);
1672  fuzz*=fuzz;
1673  scale=1.0;
1674  distance=0.0;
1675  if (image->matte != MagickFalse)
1676  {
1677  /*
1678  Transparencies are involved - set alpha distance
1679  */
1680  pixel=(MagickRealType) ((image->matte != MagickFalse ?
1681  GetPixelOpacity(p) : OpaqueOpacity)-(image->matte != MagickFalse ?
1682  q->opacity : OpaqueOpacity));
1683  distance=pixel*pixel;
1684  if (distance > fuzz)
1685  return(MagickFalse);
1686  /*
1687  Generate a alpha scaling factor to generate a 4D cone on colorspace
1688  Note that if one color is transparent, distance has no color component.
1689  */
1690  scale=(QuantumScale*GetPixelAlpha(p));
1691  scale*=(QuantumScale*GetPixelAlpha(q));
1692  if (scale <= MagickEpsilon)
1693  return(MagickTrue);
1694  }
1695  /*
1696  RGB or CMY color cube
1697  */
1698  distance*=3.0; /* rescale appropriately */
1699  fuzz*=3.0;
1700  pixel=(MagickRealType) GetPixelRed(p)-GetPixelRed(q);
1701  if (IsHueCompatibleColorspace(image->colorspace) != MagickFalse)
1702  {
1703  /*
1704  This calculates a arc distance for hue. Really it should be a vector
1705  angle of 'S'/'W' length with 'L'/'B' forming appropriate cones. In
1706  other words this is a hack - Anthony
1707  */
1708  if (fabs((double) pixel) > (QuantumRange/2.0))
1709  pixel-=QuantumRange;
1710  pixel*=2.0;
1711  }
1712  distance+=scale*pixel*pixel;
1713  if (distance > fuzz)
1714  return(MagickFalse);
1715  pixel=(MagickRealType) GetPixelGreen(p)-q->green;
1716  distance+=scale*pixel*pixel;
1717  if (distance > fuzz)
1718  return(MagickFalse);
1719  pixel=(MagickRealType) GetPixelBlue(p)-q->blue;
1720  distance+=scale*pixel*pixel;
1721  if (distance > fuzz)
1722  return(MagickFalse);
1723  return(MagickTrue);
1724 }
1725 
1726 /*
1727 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1728 % %
1729 % %
1730 % %
1731 + I s I m a g e S i m i l a r %
1732 % %
1733 % %
1734 % %
1735 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1736 %
1737 % IsImageSimilar() returns true if the target is similar to a region of the
1738 % image.
1739 %
1740 % The format of the IsImageSimilar method is:
1741 %
1742 % MagickBooleanType IsImageSimilar(const Image *image,
1743 % const Image *target_image,ssize_t *x_offset,ssize_t *y_offset,
1744 % ExceptionInfo *exception)
1745 %
1746 % A description of each parameter follows:
1747 %
1748 % o image: the image.
1749 %
1750 % o target_image: the target image.
1751 %
1752 % o x_offset: On input the starting x position to search for a match;
1753 % on output the x position of the first match found.
1754 %
1755 % o y_offset: On input the starting y position to search for a match;
1756 % on output the y position of the first match found.
1757 %
1758 % o exception: return any errors or warnings in this structure.
1759 %
1760 */
1761 MagickExport MagickBooleanType IsImageSimilar(const Image *image,
1762  const Image *target_image,ssize_t *x_offset,ssize_t *y_offset,
1763  ExceptionInfo *exception)
1764 {
1765 #define SearchImageText " Searching image... "
1766 
1767  CacheView
1768  *image_view,
1769  *target_view;
1770 
1771  MagickBooleanType
1772  status;
1773 
1775  target,
1776  pixel;
1777 
1778  const PixelPacket
1779  *p,
1780  *q;
1781 
1782  const IndexPacket
1783  *indexes,
1784  *target_indexes;
1785 
1786  ssize_t
1787  i,
1788  x;
1789 
1790  ssize_t
1791  j,
1792  y;
1793 
1794  assert(image != (Image *) NULL);
1795  assert(image->signature == MagickCoreSignature);
1796  assert(target_image != (Image *) NULL);
1797  assert(target_image->signature == MagickCoreSignature);
1798  assert(x_offset != (ssize_t *) NULL);
1799  assert(y_offset != (ssize_t *) NULL);
1800  assert(exception != (ExceptionInfo *) NULL);
1801  if (IsEventLogging() != MagickFalse)
1802  (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1803  x=0;
1804  status=MagickTrue;
1805  GetMagickPixelPacket(image,&pixel);
1806  GetMagickPixelPacket(image,&target);
1807  image_view=AcquireVirtualCacheView(image,exception);
1808  target_view=AcquireVirtualCacheView(target_image,exception);
1809  for (y=(*y_offset); y < (ssize_t) image->rows; y++)
1810  {
1811  for (x=y == 0 ? *x_offset : 0; x < (ssize_t) image->columns; x++)
1812  {
1813  for (j=0; j < (ssize_t) target_image->rows; j++)
1814  {
1815  for (i=0; i < (ssize_t) target_image->columns; i++)
1816  {
1817  p=GetCacheViewVirtualPixels(image_view,x+i,y+j,1,1,exception);
1818  if (p == (const PixelPacket *) NULL)
1819  break;
1820  indexes=GetCacheViewVirtualIndexQueue(image_view);
1821  SetMagickPixelPacket(image,p,indexes,&pixel);
1822  q=GetCacheViewVirtualPixels(target_view,i,j,1,1,exception);
1823  if (q == (const PixelPacket *) NULL)
1824  break;
1825  target_indexes=GetCacheViewVirtualIndexQueue(target_view);
1826  SetMagickPixelPacket(image,q,target_indexes,&target);
1827  if (IsMagickColorSimilar(&pixel,&target) == MagickFalse)
1828  break;
1829  }
1830  if (i < (ssize_t) target_image->columns)
1831  break;
1832  }
1833  if (j == (ssize_t) target_image->rows)
1834  break;
1835  }
1836  if (x < (ssize_t) image->columns)
1837  break;
1838  if (image->progress_monitor != (MagickProgressMonitor) NULL)
1839  {
1840  MagickBooleanType
1841  proceed;
1842 
1843  proceed=SetImageProgress(image,SearchImageText,(MagickOffsetType) y,
1844  image->rows);
1845  if (proceed == MagickFalse)
1846  status=MagickFalse;
1847  }
1848  }
1849  target_view=DestroyCacheView(target_view);
1850  image_view=DestroyCacheView(image_view);
1851  *x_offset=x;
1852  *y_offset=y;
1853  if (status == MagickFalse)
1854  return(status);
1855  return(y < (ssize_t) image->rows ? MagickTrue : MagickFalse);
1856 }
1857 
1858 /*
1859 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1860 % %
1861 % %
1862 % %
1863 + I s I n t e n s i t y S i m i l a r %
1864 % %
1865 % %
1866 % %
1867 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1868 %
1869 % IsIntensitySimilar() returns true if the distance between two intensity
1870 % values is less than the specified distance in a linear color space.
1871 %
1872 % The format of the IsIntensitySimilar method is:
1873 %
1874 % void IsIntensitySimilar(const Image *image,const PixelPacket *p,
1875 % const PixelPacket *q)
1876 %
1877 % A description of each parameter follows:
1878 %
1879 % o image: the image.
1880 %
1881 % o p: Pixel p.
1882 %
1883 % o q: Pixel q.
1884 %
1885 */
1886 MagickPrivate MagickBooleanType IsIntensitySimilar(const Image *image,
1887  const PixelPacket *p,const PixelPacket *q)
1888 {
1889  MagickRealType
1890  fuzz,
1891  pixel;
1892 
1893  MagickRealType
1894  distance;
1895 
1896  if (GetPixelIntensity(image,p) == GetPixelIntensity(image,q))
1897  return(MagickTrue);
1898  fuzz=(MagickRealType) MagickMax(image->fuzz,MagickSQ1_2);
1899  fuzz*=fuzz;
1900  pixel=GetPixelIntensity(image,p)-GetPixelIntensity(image,q);
1901  distance=pixel*pixel;
1902  if (distance > fuzz)
1903  return(MagickFalse);
1904  return(MagickTrue);
1905 }
1906 
1907 /*
1908 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1909 % %
1910 % %
1911 % %
1912 + I s M a g i c k C o l o r S i m i l a r %
1913 % %
1914 % %
1915 % %
1916 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1917 %
1918 % IsMagickColorSimilar() returns true if the distance between two colors is
1919 % less than the specified distance in a linear three dimensional color space.
1920 % This method is used by ColorFloodFill() and other algorithms which
1921 % compare two colors.
1922 %
1923 % This implements the equivalent of...
1924 % fuzz < sqrt( color_distance^2 * u.a*v.a + alpha_distance^2 )
1925 %
1926 % Which produces a multi-dimensional cone for that colorspace along the
1927 % transparency vector.
1928 %
1929 % For example for an RGB
1930 % color_distance^2 = ( (u.r-v.r)^2 + (u.g-v.g)^2 + (u.b-v.b)^2 ) / 3
1931 %
1932 % See http://imagemagick.org/Usage/bugs/fuzz_distance/
1933 %
1934 % Hue colorspace distances need more work. Hue is not a distance, it is an
1935 % angle!
1936 %
1937 % A check that q is in the same color space as p should be made and the
1938 % appropriate mapping made. -- Anthony Thyssen 8 December 2010
1939 %
1940 % The format of the IsMagickColorSimilar method is:
1941 %
1942 % MagickBooleanType IsMagickColorSimilar(const MagickPixelPacket *p,
1943 % const MagickPixelPacket *q)
1944 %
1945 % A description of each parameter follows:
1946 %
1947 % o p: Pixel p.
1948 %
1949 % o q: Pixel q.
1950 %
1951 */
1952 MagickExport MagickBooleanType IsMagickColorSimilar(const MagickPixelPacket *p,
1953  const MagickPixelPacket *q)
1954 {
1955  MagickRealType
1956  fuzz,
1957  pixel;
1958 
1959  MagickRealType
1960  scale,
1961  distance;
1962 
1963  if ((p->fuzz == 0.0) && (q->fuzz == 0.0))
1964  return(IsMagickColorEqual(p,q));
1965  fuzz=(MagickRealType) MagickMax(MagickMax(p->fuzz,q->fuzz),(double)
1966  MagickSQ1_2);
1967  fuzz*=fuzz;
1968  scale=1.0;
1969  distance=0.0;
1970  if ((p->matte != MagickFalse) || (q->matte != MagickFalse))
1971  {
1972  /*
1973  Transparencies are involved - set alpha distance.
1974  */
1975  pixel=(p->matte != MagickFalse ? GetPixelOpacity(p) : OpaqueOpacity)-
1976  (q->matte != MagickFalse ? q->opacity : OpaqueOpacity);
1977  distance=pixel*pixel;
1978  if (distance > fuzz)
1979  return(MagickFalse);
1980  /*
1981  Generate a alpha scaling factor to generate a 4D cone on colorspace.
1982  Note that if one color is transparent, distance has no color component
1983  */
1984  if (p->matte != MagickFalse)
1985  scale=(QuantumScale*GetPixelAlpha(p));
1986  if (q->matte != MagickFalse)
1987  scale*=(QuantumScale*GetPixelAlpha(q));
1988  if (scale <= MagickEpsilon)
1989  return(MagickTrue);
1990  }
1991  /*
1992  CMYK create a CMY cube with a multi-dimensional cone toward black.
1993  */
1994  if (p->colorspace == CMYKColorspace)
1995  {
1996  pixel=p->index-q->index;
1997  distance+=pixel*pixel*scale;
1998  if (distance > fuzz)
1999  return(MagickFalse);
2000  scale*=(MagickRealType) (QuantumScale*(QuantumRange-p->index));
2001  scale*=(MagickRealType) (QuantumScale*(QuantumRange-q->index));
2002  }
2003  /*
2004  RGB or CMY color cube.
2005  */
2006  distance*=3.0; /* rescale appropriately */
2007  fuzz*=3.0;
2008  pixel=p->red-q->red;
2009  if (IsHueCompatibleColorspace(p->colorspace) != MagickFalse)
2010  {
2011  /*
2012  This calculates a arc distance for hue. Really if should be a vector
2013  angle of 'S'/'W' length with 'L'/'B' forming appropriate cones. In
2014  other words this is a hack - Anthony
2015  */
2016  if (fabs((double) pixel) > (QuantumRange/2.0))
2017  pixel-=QuantumRange;
2018  pixel*=2.0;
2019  }
2020  distance+=pixel*pixel*scale;
2021  if (distance > fuzz)
2022  return(MagickFalse);
2023  pixel=GetPixelGreen(p)-q->green;
2024  distance+=pixel*pixel*scale;
2025  if (distance > fuzz)
2026  return(MagickFalse);
2027  pixel=GetPixelBlue(p)-q->blue;
2028  distance+=pixel*pixel*scale;
2029  if (distance > fuzz)
2030  return(MagickFalse);
2031  return(MagickTrue);
2032 }
2033 
2034 /*
2035 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2036 % %
2037 % %
2038 % %
2039 + I s O p a c i t y S i m i l a r %
2040 % %
2041 % %
2042 % %
2043 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2044 %
2045 % IsOpacitySimilar() returns true if the distance between two opacity
2046 % values is less than the specified distance in a linear color space. This
2047 % method is used by MatteFloodFill() and other algorithms which compare
2048 % two opacity values.
2049 %
2050 % The format of the IsOpacitySimilar method is:
2051 %
2052 % void IsOpacitySimilar(const Image *image,const PixelPacket *p,
2053 % const PixelPacket *q)
2054 %
2055 % A description of each parameter follows:
2056 %
2057 % o image: the image.
2058 %
2059 % o p: Pixel p.
2060 %
2061 % o q: Pixel q.
2062 %
2063 */
2064 MagickExport MagickBooleanType IsOpacitySimilar(const Image *image,
2065  const PixelPacket *p,const PixelPacket *q)
2066 {
2067  MagickRealType
2068  fuzz,
2069  pixel;
2070 
2071  MagickRealType
2072  distance;
2073 
2074  if (image->matte == MagickFalse)
2075  return(MagickTrue);
2076  if (GetPixelOpacity(p) == GetPixelOpacity(q))
2077  return(MagickTrue);
2078  fuzz=MagickMax(image->fuzz,(double) MagickSQ1_2);
2079  fuzz*=fuzz;
2080  pixel=(MagickRealType) GetPixelOpacity(p)-(MagickRealType) GetPixelOpacity(q);
2081  distance=pixel*pixel;
2082  if (distance > fuzz)
2083  return(MagickFalse);
2084  return(MagickTrue);
2085 }
2086 
2087 /*
2088 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2089 % %
2090 % %
2091 % %
2092 % L i s t C o l o r I n f o %
2093 % %
2094 % %
2095 % %
2096 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2097 %
2098 % ListColorInfo() lists color names to the specified file. Color names
2099 % are a convenience. Rather than defining a color by its red, green, and
2100 % blue intensities just use a color name such as white, blue, or yellow.
2101 %
2102 % The format of the ListColorInfo method is:
2103 %
2104 % MagickBooleanType ListColorInfo(FILE *file,ExceptionInfo *exception)
2105 %
2106 % A description of each parameter follows.
2107 %
2108 % o file: List color names to this file handle.
2109 %
2110 % o exception: return any errors or warnings in this structure.
2111 %
2112 */
2113 MagickExport MagickBooleanType ListColorInfo(FILE *file,
2114  ExceptionInfo *exception)
2115 {
2116  char
2117  tuple[MaxTextExtent];
2118 
2119  const char
2120  *path;
2121 
2122  const ColorInfo
2123  **color_info;
2124 
2125  ssize_t
2126  i;
2127 
2128  size_t
2129  number_colors;
2130 
2131  /*
2132  List name and attributes of each color in the list.
2133  */
2134  if (file == (const FILE *) NULL)
2135  file=stdout;
2136  color_info=GetColorInfoList("*",&number_colors,exception);
2137  if (color_info == (const ColorInfo **) NULL)
2138  return(MagickFalse);
2139  path=(const char *) NULL;
2140  for (i=0; i < (ssize_t) number_colors; i++)
2141  {
2142  if (color_info[i]->stealth != MagickFalse)
2143  continue;
2144  if ((path == (const char *) NULL) ||
2145  (LocaleCompare(path,color_info[i]->path) != 0))
2146  {
2147  if (color_info[i]->path != (char *) NULL)
2148  (void) FormatLocaleFile(file,"\nPath: %s\n\n",color_info[i]->path);
2149  (void) FormatLocaleFile(file,
2150  "Name Color "
2151  " Compliance\n");
2152  (void) FormatLocaleFile(file,
2153  "-------------------------------------------------"
2154  "------------------------------\n");
2155  }
2156  path=color_info[i]->path;
2157  (void) FormatLocaleFile(file,"%-21.21s ",color_info[i]->name);
2158  GetColorTuple(&color_info[i]->color,MagickFalse,tuple);
2159  (void) FormatLocaleFile(file,"%-45.45s ",tuple);
2160  if ((color_info[i]->compliance & SVGCompliance) != 0)
2161  (void) FormatLocaleFile(file,"SVG ");
2162  if ((color_info[i]->compliance & X11Compliance) != 0)
2163  (void) FormatLocaleFile(file,"X11 ");
2164  if ((color_info[i]->compliance & XPMCompliance) != 0)
2165  (void) FormatLocaleFile(file,"XPM ");
2166  (void) FormatLocaleFile(file,"\n");
2167  }
2168  color_info=(const ColorInfo **) RelinquishMagickMemory((void *) color_info);
2169  (void) fflush(file);
2170  return(MagickTrue);
2171 }
2172 
2173 #if !MAGICKCORE_ZERO_CONFIGURATION_SUPPORT
2174 /*
2175 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2176 % %
2177 % %
2178 % %
2179 + L o a d C o l o r C a c h e %
2180 % %
2181 % %
2182 % %
2183 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2184 %
2185 % LoadColorCache() loads the color configurations which provides a mapping
2186 % between color attributes and a color name.
2187 %
2188 % The format of the LoadColorCache method is:
2189 %
2190 % MagickBooleanType LoadColorCache(LinkedListInfo *cache,const char *xml,
2191 % const char *filename,const size_t depth,ExceptionInfo *exception)
2192 %
2193 % A description of each parameter follows:
2194 %
2195 % o xml: The color list in XML format.
2196 %
2197 % o filename: The color list filename.
2198 %
2199 % o depth: depth of <include /> statements.
2200 %
2201 % o exception: return any errors or warnings in this structure.
2202 %
2203 */
2204 static MagickBooleanType LoadColorCache(LinkedListInfo *cache,const char *xml,
2205  const char *filename,const size_t depth,ExceptionInfo *exception)
2206 {
2207  char
2208  keyword[MaxTextExtent],
2209  *token;
2210 
2211  ColorInfo
2212  *color_info;
2213 
2214  const char
2215  *q;
2216 
2217  MagickStatusType
2218  status;
2219 
2220  size_t
2221  extent;
2222 
2223  /*
2224  Load the color map file.
2225  */
2226  (void) LogMagickEvent(ConfigureEvent,GetMagickModule(),
2227  "Loading color file \"%s\" ...",filename);
2228  if (xml == (char *) NULL)
2229  return(MagickFalse);
2230  status=MagickTrue;
2231  color_info=(ColorInfo *) NULL;
2232  token=AcquireString(xml);
2233  extent=strlen(token)+MaxTextExtent;
2234  for (q=(char *) xml; *q != '\0'; )
2235  {
2236  /*
2237  Interpret XML.
2238  */
2239  (void) GetNextToken(q,&q,extent,token);
2240  if (*token == '\0')
2241  break;
2242  (void) CopyMagickString(keyword,token,MaxTextExtent);
2243  if (LocaleNCompare(keyword,"<!DOCTYPE",9) == 0)
2244  {
2245  /*
2246  Doctype element.
2247  */
2248  while ((LocaleNCompare(q,"]>",2) != 0) && (*q != '\0'))
2249  (void) GetNextToken(q,&q,extent,token);
2250  continue;
2251  }
2252  if (LocaleNCompare(keyword,"<!--",4) == 0)
2253  {
2254  /*
2255  Comment element.
2256  */
2257  while ((LocaleNCompare(q,"->",2) != 0) && (*q != '\0'))
2258  (void) GetNextToken(q,&q,extent,token);
2259  continue;
2260  }
2261  if (LocaleCompare(keyword,"<include") == 0)
2262  {
2263  /*
2264  Include element.
2265  */
2266  while (((*token != '/') && (*(token+1) != '>')) && (*q != '\0'))
2267  {
2268  (void) CopyMagickString(keyword,token,MaxTextExtent);
2269  (void) GetNextToken(q,&q,extent,token);
2270  if (*token != '=')
2271  continue;
2272  (void) GetNextToken(q,&q,extent,token);
2273  if (LocaleCompare(keyword,"file") == 0)
2274  {
2275  if (depth > MagickMaxRecursionDepth)
2276  (void) ThrowMagickException(exception,GetMagickModule(),
2277  ConfigureError,"IncludeElementNestedTooDeeply","`%s'",token);
2278  else
2279  {
2280  char
2281  path[MaxTextExtent],
2282  *xml;
2283 
2284  GetPathComponent(filename,HeadPath,path);
2285  if (*path != '\0')
2286  (void) ConcatenateMagickString(path,DirectorySeparator,
2287  MaxTextExtent);
2288  if (*token == *DirectorySeparator)
2289  (void) CopyMagickString(path,token,MaxTextExtent);
2290  else
2291  (void) ConcatenateMagickString(path,token,MaxTextExtent);
2292  xml=FileToXML(path,~0UL);
2293  if (xml != (char *) NULL)
2294  {
2295  status&=LoadColorCache(cache,xml,path,depth+1,exception);
2296  xml=(char *) RelinquishMagickMemory(xml);
2297  }
2298  }
2299  }
2300  }
2301  continue;
2302  }
2303  if (LocaleCompare(keyword,"<color") == 0)
2304  {
2305  /*
2306  Color element.
2307  */
2308  color_info=(ColorInfo *) AcquireMagickMemory(sizeof(*color_info));
2309  if (color_info == (ColorInfo *) NULL)
2310  ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed");
2311  (void) memset(color_info,0,sizeof(*color_info));
2312  color_info->path=ConstantString(filename);
2313  color_info->exempt=MagickFalse;
2314  color_info->signature=MagickCoreSignature;
2315  continue;
2316  }
2317  if (color_info == (ColorInfo *) NULL)
2318  continue;
2319  if ((LocaleCompare(keyword,"/>") == 0) ||
2320  (LocaleCompare(keyword,"</policy>") == 0))
2321  {
2322  status=AppendValueToLinkedList(cache,color_info);
2323  if (status == MagickFalse)
2324  (void) ThrowMagickException(exception,GetMagickModule(),
2325  ResourceLimitError,"MemoryAllocationFailed","`%s'",
2326  color_info->name);
2327  color_info=(ColorInfo *) NULL;
2328  continue;
2329  }
2330  (void) GetNextToken(q,(const char **) NULL,extent,token);
2331  if (*token != '=')
2332  continue;
2333  (void) GetNextToken(q,&q,extent,token);
2334  (void) GetNextToken(q,&q,extent,token);
2335  switch (*keyword)
2336  {
2337  case 'C':
2338  case 'c':
2339  {
2340  if (LocaleCompare((char *) keyword,"color") == 0)
2341  {
2342  (void) QueryMagickColor(token,&color_info->color,exception);
2343  break;
2344  }
2345  if (LocaleCompare((char *) keyword,"compliance") == 0)
2346  {
2347  ssize_t
2348  compliance;
2349 
2350  compliance=color_info->compliance;
2351  if (StringLocateSubstring(token,"*SVG*") != (char *) NULL)
2352  compliance|=SVGCompliance;
2353  if (StringLocateSubstring(token,"*X11*") != (char *) NULL)
2354  compliance|=X11Compliance;
2355  if (StringLocateSubstring(token,"*XPM*") != (char *) NULL)
2356  compliance|=XPMCompliance;
2357  color_info->compliance=(ComplianceType) compliance;
2358  break;
2359  }
2360  break;
2361  }
2362  case 'N':
2363  case 'n':
2364  {
2365  if (LocaleCompare((char *) keyword,"name") == 0)
2366  {
2367  color_info->name=ConstantString(token);
2368  break;
2369  }
2370  break;
2371  }
2372  case 'S':
2373  case 's':
2374  {
2375  if (LocaleCompare((char *) keyword,"stealth") == 0)
2376  {
2377  color_info->stealth=IsMagickTrue(token);
2378  break;
2379  }
2380  break;
2381  }
2382  default:
2383  break;
2384  }
2385  }
2386  token=(char *) RelinquishMagickMemory(token);
2387  return(status != 0 ? MagickTrue : MagickFalse);
2388 }
2389 #endif
2390 
2391 /*
2392 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2393 % %
2394 % %
2395 % %
2396 % Q u e r y C o l o r C o m p l i e n c e %
2397 % %
2398 % %
2399 % %
2400 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2401 %
2402 % QueryColorCompliance() returns the red, green, blue, and opacity intensities
2403 % for a given color name.
2404 %
2405 % The format of the QueryColorCompliance method is:
2406 %
2407 % MagickBooleanType QueryColorCompliance(const char *name,
2408 % const ComplianceType compliance,PixelPacket *color,
2409 % ExceptionInfo *exception)
2410 %
2411 % A description of each parameter follows:
2412 %
2413 % o name: the color name (e.g. white, blue, yellow).
2414 %
2415 % o compliance: Adhere to this color standard: SVG, X11, or XPM.
2416 %
2417 % o color: the red, green, blue, and opacity intensities values of the
2418 % named color in this structure.
2419 %
2420 % o exception: return any errors or warnings in this structure.
2421 %
2422 */
2423 MagickExport MagickBooleanType QueryColorCompliance(const char *name,
2424  const ComplianceType compliance,PixelPacket *color,ExceptionInfo *exception)
2425 {
2426  MagickBooleanType
2427  status;
2428 
2430  pixel;
2431 
2432  status=QueryMagickColorCompliance(name,compliance,&pixel,exception);
2433  SetPixelOpacity(color,ClampToQuantum(pixel.opacity));
2434  if (pixel.colorspace == CMYKColorspace)
2435  {
2436  SetPixelRed(color,ClampToQuantum((MagickRealType)
2437  (QuantumRange-MagickMin(QuantumRange,(MagickRealType) (QuantumScale*
2438  pixel.red*(QuantumRange-pixel.index)+pixel.index)))));
2439  SetPixelGreen(color,ClampToQuantum((MagickRealType)
2440  (QuantumRange-MagickMin(QuantumRange,(MagickRealType) (QuantumScale*
2441  pixel.green*(QuantumRange-pixel.index)+pixel.index)))));
2442  SetPixelBlue(color,ClampToQuantum((MagickRealType)
2443  (QuantumRange-MagickMin(QuantumRange,(MagickRealType) (QuantumScale*
2444  pixel.blue*(QuantumRange-pixel.index)+pixel.index)))));
2445  return(status);
2446  }
2447  SetPixelRed(color,ClampToQuantum(pixel.red));
2448  SetPixelGreen(color,ClampToQuantum(pixel.green));
2449  SetPixelBlue(color,ClampToQuantum(pixel.blue));
2450  return(status);
2451 }
2452 
2453 /*
2454 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2455 % %
2456 % %
2457 % %
2458 % Q u e r y C o l o r D a t a b a s e %
2459 % %
2460 % %
2461 % %
2462 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2463 %
2464 % QueryColorDatabase() returns the red, green, blue, and opacity intensities
2465 % for a given color name.
2466 %
2467 % The format of the QueryColorDatabase method is:
2468 %
2469 % MagickBooleanType QueryColorDatabase(const char *name,PixelPacket *color,
2470 % ExceptionInfo *exception)
2471 %
2472 % A description of each parameter follows:
2473 %
2474 % o name: the color name (e.g. white, blue, yellow).
2475 %
2476 % o color: the red, green, blue, and opacity intensities values of the
2477 % named color in this structure.
2478 %
2479 % o exception: return any errors or warnings in this structure.
2480 %
2481 */
2482 MagickExport MagickBooleanType QueryColorDatabase(const char *name,
2483  PixelPacket *color,ExceptionInfo *exception)
2484 {
2485  return(QueryColorCompliance(name,AllCompliance,color,exception));
2486 }
2487 
2488 /*
2489 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2490 % %
2491 % %
2492 % %
2493 % Q u e r y C o l o r n a m e %
2494 % %
2495 % %
2496 % %
2497 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2498 %
2499 % QueryColorname() returns a named color for the given color intensity. If
2500 % an exact match is not found, a rgb() color is returned instead.
2501 %
2502 % The format of the QueryColorname method is:
2503 %
2504 % MagickBooleanType QueryColorname(const Image *image,
2505 % const PixelPacket *color,const ComplianceType compliance,char *name,
2506 % ExceptionInfo *exception)
2507 %
2508 % A description of each parameter follows.
2509 %
2510 % o image: the image.
2511 %
2512 % o color: the color intensities.
2513 %
2514 % o compliance: Adhere to this color standard: SVG, X11, or XPM.
2515 %
2516 % o name: Return the color name or hex value.
2517 %
2518 % o exception: return any errors or warnings in this structure.
2519 %
2520 */
2521 MagickExport MagickBooleanType QueryColorname(const Image *image,
2522  const PixelPacket *color,const ComplianceType compliance,char *name,
2523  ExceptionInfo *exception)
2524 {
2526  pixel;
2527 
2528  GetMagickPixelPacket(image,&pixel);
2529  SetMagickPixelPacket(image,color,(IndexPacket *) NULL,&pixel);
2530  return(QueryMagickColorname(image,&pixel,compliance,name,exception));
2531 }
2532 
2533 /*
2534 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2535 % %
2536 % %
2537 % %
2538 % Q u e r y M a g i c k C o l o r C o m p l i a n c e %
2539 % %
2540 % %
2541 % %
2542 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2543 %
2544 % QueryMagickColorCompliance() returns the red, green, blue, and opacity
2545 % intensities for a given color name and standards compliance.
2546 %
2547 % The format of the QueryMagickColor method is:
2548 %
2549 % MagickBooleanType QueryMagickColorCompiliance(const char *name,
2550 % const ComplianceType compliance,MagickPixelPacket *color,
2551 % ExceptionInfo *exception)
2552 %
2553 % A description of each parameter follows:
2554 %
2555 % o name: the color name (e.g. white, blue, yellow).
2556 %
2557 % o compliance: Adhere to this color standard: SVG, X11, or XPM.
2558 %
2559 % o color: the red, green, blue, and opacity intensities values of the
2560 % named color in this structure.
2561 %
2562 % o exception: return any errors or warnings in this structure.
2563 %
2564 */
2565 
2566 static MagickStatusType ParseCSSColor(const char *magick_restrict color,
2567  GeometryInfo *geometry_info)
2568 {
2569  char
2570  *q;
2571 
2572  ssize_t
2573  i;
2574 
2575  MagickStatusType
2576  flags;
2577 
2578  SetGeometryInfo(geometry_info);
2579  flags=NoValue;
2580  if ((color == (char *) NULL) || (*color == '\0'))
2581  return(flags);
2582  q=(char *) color;
2583  if (*q == '(')
2584  q++;
2585  for (i=0; (i < 5) && (*q != ')') && (*q != '\0'); i++)
2586  {
2587  char
2588  *p;
2589 
2590  double
2591  intensity;
2592 
2593  p=q;
2594  intensity=(float) StringToDouble(p,&q);
2595  if (p == q)
2596  break;
2597  if (*q == '%')
2598  {
2599  intensity*=0.01*255.0;
2600  q++;
2601  }
2602  switch (i)
2603  {
2604  case 0:
2605  {
2606  geometry_info->rho=intensity;
2607  flags|=RhoValue;
2608  if (LocaleNCompare(q,"deg",3) == 0)
2609  q+=3;
2610  break;
2611  }
2612  case 1:
2613  {
2614  geometry_info->sigma=intensity;
2615  flags|=SigmaValue;
2616  break;
2617  }
2618  case 2:
2619  {
2620  geometry_info->xi=intensity;
2621  flags|=XiValue;
2622  break;
2623  }
2624  case 3:
2625  {
2626  geometry_info->psi=intensity;
2627  flags|=PsiValue;
2628  break;
2629  }
2630  case 4:
2631  {
2632  geometry_info->chi=intensity;
2633  flags|=ChiValue;
2634  break;
2635  }
2636  }
2637  while (isspace((int) ((unsigned char) *q)) != 0)
2638  q++;
2639  if (*q == ',')
2640  q++;
2641  if (*q == '/')
2642  {
2643  flags|=AlphaValue;
2644  q++;
2645  }
2646  }
2647  return(flags);
2648 }
2649 
2650 MagickExport MagickBooleanType QueryMagickColorCompliance(const char *name,
2651  const ComplianceType compliance,MagickPixelPacket *color,
2652  ExceptionInfo *exception)
2653 {
2654  double
2655  scale;
2656 
2657  GeometryInfo
2658  geometry_info;
2659 
2660  MagickStatusType
2661  flags;
2662 
2663  const ColorInfo
2664  *p;
2665 
2666  ssize_t
2667  i;
2668 
2669  ssize_t
2670  type;
2671 
2672  /*
2673  Initialize color return value.
2674  */
2675  assert(color != (MagickPixelPacket *) NULL);
2676  if ((name == (char *) NULL) || (*name == '\0'))
2677  name=BackgroundColor;
2678  if (IsEventLogging() != MagickFalse)
2679  (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",name);
2680  if (strlen(name) > MagickPathExtent)
2681  {
2682  (void) ThrowMagickException(exception,GetMagickModule(),OptionWarning,
2683  "UnrecognizedColor","`%s'",name);
2684  return(MagickFalse);
2685  }
2686  while (isspace((int) ((unsigned char) *name)) != 0)
2687  name++;
2688  GetMagickPixelPacket((Image *) NULL,color);
2689  if (*name == '#')
2690  {
2691  char
2692  c;
2693 
2695  pixel;
2696 
2697  QuantumAny
2698  range;
2699 
2700  size_t
2701  depth,
2702  n;
2703 
2704  /*
2705  Parse hex color.
2706  */
2707  (void) memset(&pixel,0,sizeof(pixel));
2708  name++;
2709  for (n=0; isxdigit((int) ((unsigned char) name[n])) != 0; n++) ;
2710  if ((n == 3) || (n == 6) || (n == 9) || (n == 12) || (n == 24) ||
2711  (n == 48))
2712  {
2713  do
2714  {
2715  pixel.red=pixel.green;
2716  pixel.green=pixel.blue;
2717  pixel.blue=0;
2718  for (i=(ssize_t) (n/3-1); i >= 0; i--)
2719  {
2720  c=(*name++);
2721  pixel.blue<<=4;
2722  if ((c >= '0') && (c <= '9'))
2723  pixel.blue|=(int) (c-'0');
2724  else
2725  if ((c >= 'A') && (c <= 'F'))
2726  pixel.blue|=(int) c-((int) 'A'-10);
2727  else
2728  if ((c >= 'a') && (c <= 'f'))
2729  pixel.blue|=(int) c-((int) 'a'-10);
2730  else
2731  return(MagickFalse);
2732  }
2733  } while (isxdigit((int) ((unsigned char) *name)) != 0);
2734  depth=4*(n/3);
2735  }
2736  else
2737  {
2738  if ((n != 4) && (n != 8) && (n != 16) && (n != 32) && (n != 64))
2739  {
2740  (void) ThrowMagickException(exception,GetMagickModule(),
2741  OptionWarning,"UnrecognizedColor","`%s'",name);
2742  return(MagickFalse);
2743  }
2744  do
2745  {
2746  pixel.red=pixel.green;
2747  pixel.green=pixel.blue;
2748  pixel.blue=pixel.opacity;
2749  pixel.opacity=0;
2750  for (i=(ssize_t) (n/4-1); i >= 0; i--)
2751  {
2752  c=(*name++);
2753  pixel.opacity<<=4;
2754  if ((c >= '0') && (c <= '9'))
2755  pixel.opacity|=(int) (c-'0');
2756  else
2757  if ((c >= 'A') && (c <= 'F'))
2758  pixel.opacity|=(int) c-((int) 'A'-10);
2759  else
2760  if ((c >= 'a') && (c <= 'f'))
2761  pixel.opacity|=(int) c-((int) 'a'-10);
2762  else
2763  return(MagickFalse);
2764  }
2765  } while (isxdigit((int) ((unsigned char) *name)) != 0);
2766  depth=4*(n/4);
2767  }
2768  color->colorspace=sRGBColorspace;
2769  color->depth=depth;
2770  color->matte=MagickFalse;
2771  range=GetQuantumRange(depth);
2772  color->red=(MagickRealType) ScaleAnyToQuantum(pixel.red,range);
2773  color->green=(MagickRealType) ScaleAnyToQuantum(pixel.green,range);
2774  color->blue=(MagickRealType) ScaleAnyToQuantum(pixel.blue,range);
2775  color->opacity=(MagickRealType) OpaqueOpacity;
2776  if ((n % 3) != 0)
2777  {
2778  color->matte=MagickTrue;
2779  color->opacity=(MagickRealType) (QuantumRange-ScaleAnyToQuantum(
2780  pixel.opacity,range));
2781  }
2782  color->index=0.0;
2783  return(MagickTrue);
2784  }
2785  if (strchr(name,'(') != (char *) NULL)
2786  {
2787  char
2788  colorspace[2*MaxTextExtent];
2789 
2790  MagickBooleanType
2791  icc_color;
2792 
2793  /*
2794  Parse color of the form rgb(100,255,0).
2795  */
2796  (void) memset(colorspace,0,sizeof(colorspace));
2797  (void) CopyMagickString(colorspace,name,MaxTextExtent);
2798  for (i=0; colorspace[i] != '\0'; i++)
2799  if (colorspace[i] == '(')
2800  break;
2801  colorspace[i--]='\0';
2802  scale=(double) ScaleCharToQuantum(1);
2803  icc_color=MagickFalse;
2804  if (LocaleNCompare(colorspace,"device-",7) == 0)
2805  {
2806  (void) CopyMagickString(colorspace,colorspace+7,MaxTextExtent);
2807  if (strchr(name,'%') == (char *) NULL)
2808  scale=(double) QuantumRange;
2809  icc_color=MagickTrue;
2810  }
2811  if ((LocaleCompare(colorspace,"color") == 0) ||
2812  (LocaleCompare(colorspace,"icc-color") == 0))
2813  {
2814  ssize_t
2815  j;
2816 
2817  (void) CopyMagickString(colorspace,name+i+2,MaxTextExtent);
2818  for (j=0; colorspace[j] != '\0'; j++)
2819  if ((colorspace[j] == ' ') || (colorspace[j] == ','))
2820  break;
2821  colorspace[j--]='\0';
2822  i+=j+3;
2823  scale=(double) QuantumRange;
2824  icc_color=MagickTrue;
2825  }
2826  LocaleLower(colorspace);
2827  color->matte=MagickFalse;
2828  if ((i > 0) && (colorspace[i] == 'a'))
2829  {
2830  colorspace[i]='\0';
2831  color->matte=MagickTrue;
2832  }
2833  type=ParseCommandOption(MagickColorspaceOptions,MagickFalse,colorspace);
2834  if (type < 0)
2835  {
2836  (void) ThrowMagickException(exception,GetMagickModule(),
2837  OptionWarning,"UnrecognizedColor","`%s'",name);
2838  return(MagickFalse);
2839  }
2840  color->colorspace=(ColorspaceType) type;
2841  if ((icc_color == MagickFalse) && (color->colorspace == RGBColorspace))
2842  {
2843  color->colorspace=sRGBColorspace; /* as required by SVG standard */
2844  color->depth=8;
2845  }
2846  if (i >= (ssize_t) strlen(name))
2847  flags=ParseCSSColor(name,&geometry_info);
2848  else
2849  flags=ParseCSSColor(name+i+1,&geometry_info);
2850  if (flags == 0)
2851  {
2852  char
2853  *colorname;
2854 
2855  ColorspaceType
2856  colorspace;
2857 
2858  MagickBooleanType
2859  status;
2860 
2861  colorspace=color->colorspace;
2862  if (i >= (ssize_t) strlen(name))
2863  colorname=AcquireString(name);
2864  else
2865  colorname=AcquireString(name+i+1);
2866  (void) SubstituteString(&colorname,"(","");
2867  (void) SubstituteString(&colorname,")","");
2868  status=MagickFalse;
2869  if (LocaleCompare(name,colorname) != 0)
2870  status=QueryMagickColor(colorname,color,exception);
2871  color->colorspace=colorspace;
2872  if (*colorname == '\0')
2873  {
2874  (void) ThrowMagickException(exception,GetMagickModule(),
2875  OptionWarning,"UnrecognizedColor","`%s'",name);
2876  status=MagickFalse;
2877  }
2878  colorname=DestroyString(colorname);
2879  return(status);
2880  }
2881  if ((flags & AlphaValue) != 0)
2882  color->matte=MagickTrue;
2883  if ((flags & RhoValue) != 0)
2884  color->red=(MagickRealType) ClampToQuantum((MagickRealType)
2885  (scale*geometry_info.rho));
2886  if ((flags & SigmaValue) != 0)
2887  color->green=(MagickRealType) ClampToQuantum((MagickRealType)
2888  (scale*geometry_info.sigma));
2889  if ((flags & XiValue) != 0)
2890  color->blue=(MagickRealType) ClampToQuantum((MagickRealType)
2891  (scale*geometry_info.xi));
2892  color->opacity=(MagickRealType) OpaqueOpacity;
2893  if ((flags & PsiValue) != 0)
2894  {
2895  if (color->colorspace == CMYKColorspace)
2896  color->index=(MagickRealType) ClampToQuantum((MagickRealType)
2897  (scale*geometry_info.psi));
2898  else
2899  if (color->matte != MagickFalse)
2900  {
2901  if ((flags & AlphaValue) != 0)
2902  color->opacity=(MagickRealType) ClampToQuantum(
2903  (MagickRealType) (scale*geometry_info.psi));
2904  else
2905  color->opacity=(MagickRealType) ClampToQuantum(
2906  (MagickRealType) (QuantumRange-QuantumRange*
2907  geometry_info.psi));
2908  }
2909  }
2910  if (((flags & ChiValue) != 0) && (color->matte != MagickFalse))
2911  color->opacity=(MagickRealType) ClampToQuantum((MagickRealType)
2912  (QuantumRange-QuantumRange*geometry_info.chi));
2913  if (color->colorspace == LabColorspace)
2914  {
2915  color->red=(MagickRealType) ClampToQuantum((MagickRealType)
2916  (QuantumRange*geometry_info.rho/100.0));
2917  if ((flags & SigmaValue) != 0)
2918  color->green=(MagickRealType) ClampToQuantum((MagickRealType)
2919  (scale*geometry_info.sigma+(QuantumRange+1)/2.0));
2920  if ((flags & XiValue) != 0)
2921  color->blue=(MagickRealType) ClampToQuantum((MagickRealType)
2922  (scale*geometry_info.xi+(QuantumRange+1)/2.0));
2923  }
2924  if ((LocaleCompare(colorspace,"gray") == 0) ||
2925  (LocaleCompare(colorspace,"lineargray") == 0))
2926  {
2927  color->green=color->red;
2928  color->blue=color->red;
2929  if (((flags & SigmaValue) != 0) && (color->matte != MagickFalse))
2930  color->opacity=(MagickRealType) ClampToQuantum((MagickRealType)
2931  (QuantumRange-QuantumRange*geometry_info.sigma));
2932  }
2933  if ((LocaleCompare(colorspace,"HCL") == 0) ||
2934  (LocaleCompare(colorspace,"HSB") == 0) ||
2935  (LocaleCompare(colorspace,"HSL") == 0) ||
2936  (LocaleCompare(colorspace,"HSV") == 0) ||
2937  (LocaleCompare(colorspace,"HWB") == 0))
2938  {
2939  PixelPacket
2940  pixel;
2941 
2942  scale=1.0/255.0;
2943  geometry_info.sigma*=scale;
2944  geometry_info.xi*=scale;
2945  pixel.red=0.0;
2946  pixel.green=0.0;
2947  pixel.blue=0.0;
2948  switch (color->colorspace)
2949  {
2950  case HCLColorspace:
2951  {
2952  ConvertHCLToRGB(fmod(fmod(geometry_info.rho,360.0)+360.0,360.0)/
2953  360.0,geometry_info.sigma,geometry_info.xi,&pixel.red,
2954  &pixel.green,&pixel.blue);
2955  break;
2956  }
2957  case HSBColorspace:
2958  {
2959  ConvertHSBToRGB(fmod(fmod(geometry_info.rho,360.0)+360.0,
2960  360.0)/360.0,geometry_info.sigma,geometry_info.xi,
2961  &pixel.red,&pixel.green,&pixel.blue);
2962  break;
2963  }
2964  case HSLColorspace:
2965  {
2966  ConvertHSLToRGB(fmod(fmod(geometry_info.rho,360.0)+360.0,
2967  360.0)/360.0,geometry_info.sigma,geometry_info.xi,
2968  &pixel.red,&pixel.green,&pixel.blue);
2969  break;
2970  }
2971  case HSVColorspace:
2972  {
2973  ConvertHSVToRGB(fmod(fmod(geometry_info.rho,360.0)+360.0,
2974  360.0)/360.0,geometry_info.sigma,geometry_info.xi,
2975  &pixel.red,&pixel.green,&pixel.blue);
2976  break;
2977  }
2978  case HWBColorspace:
2979  {
2980  ConvertHWBToRGB(fmod(fmod(geometry_info.rho,360.0)+360.0,
2981  360.0)/360.0,geometry_info.sigma,geometry_info.xi,
2982  &pixel.red,&pixel.green,&pixel.blue);
2983  break;
2984  }
2985  default:
2986  break;
2987  }
2988  color->colorspace=sRGBColorspace;
2989  color->red=(MagickRealType) pixel.red;
2990  color->green=(MagickRealType) pixel.green;
2991  color->blue=(MagickRealType) pixel.blue;
2992  }
2993  return(MagickTrue);
2994  }
2995  /*
2996  Parse named color.
2997  */
2998  p=GetColorCompliance(name,compliance,exception);
2999  if (p == (const ColorInfo *) NULL)
3000  return(MagickFalse);
3001  color->colorspace=sRGBColorspace;
3002  if ((LocaleNCompare(name,"gray",4) == 0) ||
3003  (LocaleNCompare(name,"grey",4) == 0))
3004  color->colorspace=GRAYColorspace;
3005  color->depth=8;
3006  color->matte=p->color.opacity != OpaqueOpacity ? MagickTrue : MagickFalse;
3007  color->red=(MagickRealType) p->color.red;
3008  color->green=(MagickRealType) p->color.green;
3009  color->blue=(MagickRealType) p->color.blue;
3010  color->opacity=(MagickRealType) p->color.opacity;
3011  color->index=0.0;
3012  return(MagickTrue);
3013 }
3014 
3015 /*
3016 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3017 % %
3018 % %
3019 % %
3020 % Q u e r y M a g i c k C o l o r %
3021 % %
3022 % %
3023 % %
3024 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3025 %
3026 % QueryMagickColor() returns the red, green, blue, and opacity intensities
3027 % for a given color name.
3028 %
3029 % The format of the QueryMagickColor method is:
3030 %
3031 % MagickBooleanType QueryMagickColor(const char *name,
3032 % MagickPixelPacket *color,ExceptionInfo *exception)
3033 %
3034 % A description of each parameter follows:
3035 %
3036 % o name: the color name (e.g. white, blue, yellow).
3037 %
3038 % o color: the red, green, blue, and opacity intensities values of the
3039 % named color in this structure.
3040 %
3041 % o exception: return any errors or warnings in this structure.
3042 %
3043 */
3044 MagickExport MagickBooleanType QueryMagickColor(const char *name,
3045  MagickPixelPacket *color,ExceptionInfo *exception)
3046 {
3047  return(QueryMagickColorCompliance(name,AllCompliance,color,exception));
3048 }
3049 
3050 /*
3051 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3052 % %
3053 % %
3054 % %
3055 % Q u e r y M a g i c k C o l o r n a m e %
3056 % %
3057 % %
3058 % %
3059 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3060 %
3061 % QueryMagickColorname() returns a named color for the given color intensity.
3062 % If an exact match is not found, a hex value is returned instead. For
3063 % example an intensity of rgb:(0,0,0) returns black whereas rgb:(223,223,223)
3064 % returns #dfdfdf.
3065 %
3066 % The format of the QueryMagickColorname method is:
3067 %
3068 % MagickBooleanType QueryMagickColorname(const Image *image,
3069 % const PixelPacket *color,const ComplianceType compliance,char *name,
3070 % ExceptionInfo *exception)
3071 %
3072 % A description of each parameter follows.
3073 %
3074 % o image: the image.
3075 %
3076 % o color: the color intensities.
3077 %
3078 % o Compliance: Adhere to this color standard: SVG, X11, or XPM.
3079 %
3080 % o name: Return the color name or hex value.
3081 %
3082 % o exception: return any errors or warnings in this structure.
3083 %
3084 */
3085 MagickExport MagickBooleanType QueryMagickColorname(const Image *image,
3086  const MagickPixelPacket *color,const ComplianceType compliance,
3087  char *name,ExceptionInfo *exception)
3088 {
3090  pixel;
3091 
3092  MagickRealType
3093  opacity;
3094 
3095  const ColorInfo
3096  *p;
3097 
3098  *name='\0';
3099  pixel=(*color);
3100  if (compliance == XPMCompliance)
3101  {
3102  pixel.matte=MagickFalse;
3103  pixel.depth=(size_t) MagickMin(1.0*image->depth,16.0);
3104  }
3105  GetColorTuple(&pixel,compliance != SVGCompliance ? MagickTrue : MagickFalse,
3106  name);
3107  if (IssRGBColorspace(pixel.colorspace) == MagickFalse)
3108  return(MagickFalse);
3109  (void) GetColorInfo("*",exception);
3110  ResetLinkedListIterator(color_cache);
3111  opacity=image->matte != MagickFalse ? color->opacity : OpaqueOpacity;
3112  p=(const ColorInfo *) GetNextValueInLinkedList(color_cache);
3113  while (p != (const ColorInfo *) NULL)
3114  {
3115  if (((p->compliance & compliance) != 0) && ((p->color.red == color->red)) &&
3116  (p->color.green == color->green) && (p->color.blue == color->blue) &&
3117  (p->color.opacity == opacity))
3118  {
3119  (void) CopyMagickString(name,p->name,MaxTextExtent);
3120  break;
3121  }
3122  p=(const ColorInfo *) GetNextValueInLinkedList(color_cache);
3123  }
3124  return(MagickTrue);
3125 }
Definition: image.h:152