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