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