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