]> 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-2011 ImageMagick Studio LLC, a non-profit organization      %
20 %  dedicated to making software imaging solutions freely available.           %
21 %                                                                             %
22 %  You may not use this file except in compliance with the License.  You may  %
23 %  obtain a copy of the License at                                            %
24 %                                                                             %
25 %    http://www.imagemagick.org/script/license.php                            %
26 %                                                                             %
27 %  Unless required by applicable law or agreed to in writing, software        %
28 %  distributed under the License is distributed on an "AS IS" BASIS,          %
29 %  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.   %
30 %  See the License for the specific language governing permissions and        %
31 %  limitations under the License.                                             %
32 %                                                                             %
33 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
34 %
35 %  We use linked-lists because splay-trees do not currently support duplicate
36 %  key / value pairs (.e.g X11 green compliance and SVG green compliance).
37 %
38 */
39 \f
40 /*
41   Include declarations.
42 */
43 #include "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 unsigned char
83     red,
84     green,
85     blue;
86
87   const float
88     alpha;
89
90   const ssize_t
91     compliance;
92 } ColorMapInfo;
93 \f
94 /*
95   Static declarations.
96 */
97 static const ColorMapInfo
98   ColorMap[] =
99   {
100     { "none", 0, 0, 0, 0, SVGCompliance | XPMCompliance },
101     { "black", 0, 0, 0, 1, SVGCompliance | X11Compliance | XPMCompliance },
102     { "red", 255, 0, 0, 1, SVGCompliance | X11Compliance | XPMCompliance },
103     { "magenta", 255, 0, 255, 1, SVGCompliance | X11Compliance | XPMCompliance },
104     { "green", 0, 128, 0, 1, SVGCompliance },
105     { "cyan", 0, 255, 255, 1, SVGCompliance | X11Compliance | XPMCompliance },
106     { "blue", 0, 0, 255, 1, SVGCompliance | X11Compliance | XPMCompliance },
107     { "yellow", 255, 255, 0, 1, SVGCompliance | X11Compliance | XPMCompliance },
108     { "white", 255, 255, 255, 1, SVGCompliance | X11Compliance },
109     { "AliceBlue", 240, 248, 255, 1, SVGCompliance | X11Compliance | XPMCompliance },
110     { "AntiqueWhite", 250, 235, 215, 1, SVGCompliance | X11Compliance | XPMCompliance },
111     { "AntiqueWhite1", 255, 239, 219, 1, X11Compliance },
112     { "AntiqueWhite2", 238, 223, 204, 1, X11Compliance },
113     { "AntiqueWhite3", 205, 192, 176, 1, X11Compliance },
114     { "AntiqueWhite4", 139, 131, 120, 1, X11Compliance },
115     { "aqua", 0, 255, 255, 1, SVGCompliance },
116     { "aquamarine", 127, 255, 212, 1, SVGCompliance | X11Compliance | XPMCompliance },
117     { "aquamarine1", 127, 255, 212, 1, X11Compliance },
118     { "aquamarine2", 118, 238, 198, 1, X11Compliance },
119     { "aquamarine3", 102, 205, 170, 1, X11Compliance },
120     { "aquamarine4", 69, 139, 116, 1, X11Compliance },
121     { "azure", 240, 255, 255, 1, SVGCompliance | X11Compliance | XPMCompliance },
122     { "azure1", 240, 255, 255, 1, X11Compliance },
123     { "azure2", 224, 238, 238, 1, X11Compliance },
124     { "azure3", 193, 205, 205, 1, X11Compliance },
125     { "azure4", 131, 139, 139, 1, X11Compliance },
126     { "beige", 245, 245, 220, 1, SVGCompliance | X11Compliance | XPMCompliance },
127     { "bisque", 255, 228, 196, 1, SVGCompliance | X11Compliance | XPMCompliance },
128     { "bisque1", 255, 228, 196, 1, X11Compliance },
129     { "bisque2", 238, 213, 183, 1, X11Compliance },
130     { "bisque3", 205, 183, 158, 1, X11Compliance },
131     { "bisque4", 139, 125, 107, 1, X11Compliance },
132     { "BlanchedAlmond", 255, 235, 205, 1, SVGCompliance | X11Compliance | XPMCompliance },
133     { "blue1", 0, 0, 255, 1, X11Compliance },
134     { "blue2", 0, 0, 238, 1, X11Compliance },
135     { "blue3", 0, 0, 205, 1, X11Compliance },
136     { "blue4", 0, 0, 139, 1, X11Compliance },
137     { "BlueViolet", 138, 43, 226, 1, SVGCompliance | X11Compliance | XPMCompliance },
138     { "brown", 165, 42, 42, 1, SVGCompliance | X11Compliance | XPMCompliance },
139     { "brown1", 255, 64, 64, 1, X11Compliance },
140     { "brown2", 238, 59, 59, 1, X11Compliance },
141     { "brown3", 205, 51, 51, 1, X11Compliance },
142     { "brown4", 139, 35, 35, 1, X11Compliance },
143     { "burlywood", 222, 184, 135, 1, SVGCompliance | X11Compliance | XPMCompliance },
144     { "burlywood1", 255, 211, 155, 1, X11Compliance },
145     { "burlywood2", 238, 197, 145, 1, X11Compliance },
146     { "burlywood3", 205, 170, 125, 1, X11Compliance },
147     { "burlywood4", 139, 115, 85, 1, X11Compliance },
148     { "CadetBlue", 95, 158, 160, 1, SVGCompliance | X11Compliance | XPMCompliance },
149     { "CadetBlue1", 152, 245, 255, 1, X11Compliance },
150     { "CadetBlue2", 142, 229, 238, 1, X11Compliance },
151     { "CadetBlue3", 122, 197, 205, 1, X11Compliance },
152     { "CadetBlue4", 83, 134, 139, 1, X11Compliance },
153     { "chartreuse", 127, 255, 0, 1, SVGCompliance | X11Compliance | XPMCompliance },
154     { "chartreuse1", 127, 255, 0, 1, X11Compliance },
155     { "chartreuse2", 118, 238, 0, 1, X11Compliance },
156     { "chartreuse3", 102, 205, 0, 1, X11Compliance },
157     { "chartreuse4", 69, 139, 0, 1, X11Compliance },
158     { "chocolate", 210, 105, 30, 1, SVGCompliance | X11Compliance | XPMCompliance },
159     { "chocolate1", 255, 127, 36, 1, X11Compliance },
160     { "chocolate2", 238, 118, 33, 1, X11Compliance },
161     { "chocolate3", 205, 102, 29, 1, X11Compliance },
162     { "chocolate4", 139, 69, 19, 1, X11Compliance },
163     { "coral", 255, 127, 80, 1, SVGCompliance | X11Compliance | XPMCompliance },
164     { "coral1", 255, 114, 86, 1, X11Compliance },
165     { "coral2", 238, 106, 80, 1, X11Compliance },
166     { "coral3", 205, 91, 69, 1, X11Compliance },
167     { "coral4", 139, 62, 47, 1, X11Compliance },
168     { "CornflowerBlue", 100, 149, 237, 1, SVGCompliance | X11Compliance | XPMCompliance },
169     { "cornsilk", 255, 248, 220, 1, SVGCompliance | X11Compliance | XPMCompliance },
170     { "cornsilk1", 255, 248, 220, 1, X11Compliance },
171     { "cornsilk2", 238, 232, 205, 1, X11Compliance },
172     { "cornsilk3", 205, 200, 177, 1, X11Compliance },
173     { "cornsilk4", 139, 136, 120, 1, X11Compliance },
174     { "crimson", 220, 20, 60, 1, SVGCompliance },
175     { "cyan1", 0, 255, 255, 1, X11Compliance },
176     { "cyan2", 0, 238, 238, 1, X11Compliance },
177     { "cyan3", 0, 205, 205, 1, X11Compliance },
178     { "cyan4", 0, 139, 139, 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, 127, 127, 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   AcquireSemaphoreInfo(&color_semaphore);
820   return(MagickTrue);
821 }
822 \f
823 /*
824 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
825 %                                                                             %
826 %                                                                             %
827 %                                                                             %
828 +   C o l o r C o m p o n e n t T e r m i n u s                               %
829 %                                                                             %
830 %                                                                             %
831 %                                                                             %
832 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
833 %
834 %  ColorComponentTerminus() destroys the color component.
835 %
836 %  The format of the ColorComponentTerminus method is:
837 %
838 %      ColorComponentTerminus(void)
839 %
840 */
841
842 static void *DestroyColorElement(void *color_info)
843 {
844   register ColorInfo
845     *p;
846
847   p=(ColorInfo *) color_info;
848   if (p->exempt  == MagickFalse)
849     {
850       if (p->path != (char *) NULL)
851         p->path=DestroyString(p->path);
852       if (p->name != (char *) NULL)
853         p->name=DestroyString(p->name);
854     }
855   p=(ColorInfo *) RelinquishMagickMemory(p);
856   return((void *) NULL);
857 }
858
859 MagickExport void ColorComponentTerminus(void)
860 {
861   if (color_semaphore == (SemaphoreInfo *) NULL)
862     AcquireSemaphoreInfo(&color_semaphore);
863   LockSemaphoreInfo(color_semaphore);
864   if (color_list != (LinkedListInfo *) NULL)
865     color_list=DestroyLinkedList(color_list,DestroyColorElement);
866   instantiate_color=MagickFalse;
867   UnlockSemaphoreInfo(color_semaphore);
868   DestroySemaphoreInfo(&color_semaphore);
869 }
870 \f
871 /*
872 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
873 %                                                                             %
874 %                                                                             %
875 %                                                                             %
876 +   G e t C o l o r C o m p l i a n c e                                       %
877 %                                                                             %
878 %                                                                             %
879 %                                                                             %
880 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
881 %
882 %  GetColorInfo() searches the color list for the specified name and standards
883 %  compliance and if found returns attributes for that color.
884 %
885 %  The format of the GetColorInfo method is:
886 %
887 %      const PixelPacket *GetColorInfo(const char *name,
888 %        const ComplianceType compliance,ExceptionInfo *exception)
889 %
890 %  A description of each parameter follows:
891 %
892 %    o name: the color name.
893 %
894 %    o compliance: Adhere to this color standard: SVG, X11, or XPM.
895 %
896 %    o exception: return any errors or warnings in this structure.
897 %
898 */
899 MagickExport const ColorInfo *GetColorCompliance(const char *name,
900   const ComplianceType compliance,ExceptionInfo *exception)
901 {
902   char
903     colorname[MaxTextExtent];
904
905   register const ColorInfo
906     *p;
907
908   register char
909     *q;
910
911   assert(exception != (ExceptionInfo *) NULL);
912   if ((color_list == (LinkedListInfo *) NULL) ||
913       (instantiate_color == MagickFalse))
914     if (InitializeColorList(exception) == MagickFalse)
915       return((const ColorInfo *) NULL);
916   if ((color_list == (LinkedListInfo *) NULL) ||
917       (IsLinkedListEmpty(color_list) != MagickFalse))
918     return((const ColorInfo *) NULL);
919   if ((name == (const char *) NULL) || (LocaleCompare(name,"*") == 0))
920     return((const ColorInfo *) GetValueFromLinkedList(color_list,0));
921   /*
922     Strip names of whitespace.
923   */
924   (void) CopyMagickString(colorname,name,MaxTextExtent);
925   for (q=colorname; *q != '\0'; q++)
926   {
927     if (isspace((int) ((unsigned char) *q)) == 0)
928       continue;
929     (void) CopyMagickString(q,q+1,MaxTextExtent);
930     q--;
931   }
932   /*
933     Search for color tag.
934   */
935   LockSemaphoreInfo(color_semaphore);
936   ResetLinkedListIterator(color_list);
937   p=(const ColorInfo *) GetNextValueInLinkedList(color_list);
938   while (p != (const ColorInfo *) NULL)
939   {
940     if (((p->compliance & compliance) != 0) &&
941         (LocaleCompare(colorname,p->name) == 0))
942       break;
943     p=(const ColorInfo *) GetNextValueInLinkedList(color_list);
944   }
945   if (p == (ColorInfo *) NULL)
946     (void) ThrowMagickException(exception,GetMagickModule(),OptionWarning,
947       "UnrecognizedColor","`%s'",name);
948   else
949     (void) InsertValueInLinkedList(color_list,0,
950       RemoveElementByValueFromLinkedList(color_list,p));
951   UnlockSemaphoreInfo(color_semaphore);
952   return(p);
953 }
954 \f
955 /*
956 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
957 %                                                                             %
958 %                                                                             %
959 %                                                                             %
960 +   G e t C o l o r I n f o                                                   %
961 %                                                                             %
962 %                                                                             %
963 %                                                                             %
964 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
965 %
966 %  GetColorInfo() searches the color list for the specified name and if found
967 %  returns attributes for that color.
968 %
969 %  The format of the GetColorInfo method is:
970 %
971 %      const PixelPacket *GetColorInfo(const char *name,
972 %        ExceptionInfo *exception)
973 %
974 %  A description of each parameter follows:
975 %
976 %    o color_info: search the color list for the specified name and if found
977 %      return attributes for that color.
978 %
979 %    o name: the color name.
980 %
981 %    o exception: return any errors or warnings in this structure.
982 %
983 */
984 MagickExport const ColorInfo *GetColorInfo(const char *name,
985   ExceptionInfo *exception)
986 {
987   return(GetColorCompliance(name,AllCompliance,exception));
988 }
989 \f
990 /*
991 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
992 %                                                                             %
993 %                                                                             %
994 %                                                                             %
995 +   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                         %
996 %                                                                             %
997 %                                                                             %
998 %                                                                             %
999 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1000 %
1001 %  ConcatenateColorComponent() returns the pixel as a canonical string.
1002 %
1003 %  The format of the ConcatenateColorComponent() method is:
1004 %
1005 %      void ConcatenateColorComponent(const MagickPixelPacket *pixel,
1006 %        const ChannelType channel,const ComplianceType compliance,char *tuple)
1007 %
1008 %  A description of each parameter follows.
1009 %
1010 %    o pixel:  The pixel.
1011 %
1012 %    channel:  The channel.
1013 %
1014 %    o compliance: Adhere to this color standard: SVG, X11, or XPM.
1015 %
1016 %    tuple:  The color tuple.
1017 %
1018 */
1019 MagickExport void ConcatenateColorComponent(const MagickPixelPacket *pixel,
1020   const ChannelType channel,const ComplianceType compliance,char *tuple)
1021 {
1022   char
1023     component[MaxTextExtent];
1024
1025   MagickRealType
1026     color;
1027
1028   color=0.0;
1029   switch (channel)
1030   {
1031     case RedChannel:
1032     {
1033       color=pixel->red;
1034       break;
1035     }
1036     case GreenChannel:
1037     {
1038       color=pixel->green;
1039       break;
1040     }
1041     case BlueChannel:
1042     {
1043       color=pixel->blue;
1044       break;
1045     }
1046     case AlphaChannel:
1047     {
1048       color=QuantumRange-pixel->opacity;
1049       break;
1050     }
1051     case IndexChannel:
1052     {
1053       color=pixel->index;
1054       break;
1055     }
1056     default:
1057       break;
1058   }
1059   if (compliance != SVGCompliance)
1060     {
1061       if (pixel->depth > 16)
1062         {
1063           (void) FormatMagickString(component,MaxTextExtent,"%10lu",
1064             (unsigned long) ScaleQuantumToLong(ClampToQuantum(color)));
1065           (void) ConcatenateMagickString(tuple,component,MaxTextExtent);
1066           return;
1067         }
1068       if (pixel->depth > 8)
1069         {
1070           (void) FormatMagickString(component,MaxTextExtent,"%5d",
1071             ScaleQuantumToShort(ClampToQuantum(color)));
1072           (void) ConcatenateMagickString(tuple,component,MaxTextExtent);
1073           return;
1074         }
1075       (void) FormatMagickString(component,MaxTextExtent,"%3d",
1076         ScaleQuantumToChar(ClampToQuantum(color)));
1077       (void) ConcatenateMagickString(tuple,component,MaxTextExtent);
1078       return;
1079     }
1080   if (channel == OpacityChannel)
1081     {
1082       (void) FormatMagickString(component,MaxTextExtent,"%g",
1083         (double) (QuantumScale*color));
1084       (void) ConcatenateMagickString(tuple,component,MaxTextExtent);
1085       return;
1086     }
1087   if ((pixel->colorspace == HSLColorspace) ||
1088       (pixel->colorspace == HSBColorspace))
1089     {
1090       (void) FormatMagickString(component,MaxTextExtent,"%g%%",
1091         (double) (100.0*QuantumScale*color));
1092       (void) ConcatenateMagickString(tuple,component,MaxTextExtent);
1093       return;
1094     }
1095   if (pixel->depth > 8)
1096     {
1097       (void) FormatMagickString(component,MaxTextExtent,"%g%%",
1098         (double) (100.0*QuantumScale*color));
1099       (void) ConcatenateMagickString(tuple,component,MaxTextExtent);
1100       return;
1101     }
1102   (void) FormatMagickString(component,MaxTextExtent,"%d",
1103     ScaleQuantumToChar(ClampToQuantum(color)));
1104   (void) ConcatenateMagickString(tuple,component,MaxTextExtent);
1105 }
1106 \f
1107 /*
1108 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1109 %                                                                             %
1110 %                                                                             %
1111 %                                                                             %
1112 %   G e t C o l o r I n f o L i s t                                           %
1113 %                                                                             %
1114 %                                                                             %
1115 %                                                                             %
1116 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1117 %
1118 %  GetColorInfoList() returns any colors that match the specified pattern.
1119 %
1120 %  The format of the GetColorInfoList function is:
1121 %
1122 %      const ColorInfo **GetColorInfoList(const char *pattern,
1123 %        size_t *number_colors,ExceptionInfo *exception)
1124 %
1125 %  A description of each parameter follows:
1126 %
1127 %    o pattern: Specifies a pointer to a text string containing a pattern.
1128 %
1129 %    o number_colors:  This integer returns the number of colors in the list.
1130 %
1131 %    o exception: return any errors or warnings in this structure.
1132 %
1133 */
1134
1135 #if defined(__cplusplus) || defined(c_plusplus)
1136 extern "C" {
1137 #endif
1138
1139 static int ColorInfoCompare(const void *x,const void *y)
1140 {
1141   const ColorInfo
1142     **p,
1143     **q;
1144
1145   p=(const ColorInfo **) x,
1146   q=(const ColorInfo **) y;
1147   if (LocaleCompare((*p)->path,(*q)->path) == 0)
1148     return(LocaleCompare((*p)->name,(*q)->name));
1149   return(LocaleCompare((*p)->path,(*q)->path));
1150 }
1151
1152 #if defined(__cplusplus) || defined(c_plusplus)
1153 }
1154 #endif
1155
1156 MagickExport const ColorInfo **GetColorInfoList(const char *pattern,
1157   size_t *number_colors,ExceptionInfo *exception)
1158 {
1159   const ColorInfo
1160     **colors;
1161
1162   register const ColorInfo
1163     *p;
1164
1165   register ssize_t
1166     i;
1167
1168   /*
1169     Allocate color list.
1170   */
1171   assert(pattern != (char *) NULL);
1172   (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",pattern);
1173   assert(number_colors != (size_t *) NULL);
1174   *number_colors=0;
1175   p=GetColorInfo("*",exception);
1176   if (p == (const ColorInfo *) NULL)
1177     return((const ColorInfo **) NULL);
1178   colors=(const ColorInfo **) AcquireQuantumMemory((size_t)
1179     GetNumberOfElementsInLinkedList(color_list)+1UL,sizeof(*colors));
1180   if (colors == (const ColorInfo **) NULL)
1181     return((const ColorInfo **) NULL);
1182   /*
1183     Generate color list.
1184   */
1185   LockSemaphoreInfo(color_semaphore);
1186   ResetLinkedListIterator(color_list);
1187   p=(const ColorInfo *) GetNextValueInLinkedList(color_list);
1188   for (i=0; p != (const ColorInfo *) NULL; )
1189   {
1190     if ((p->stealth == MagickFalse) &&
1191         (GlobExpression(p->name,pattern,MagickFalse) != MagickFalse))
1192       colors[i++]=p;
1193     p=(const ColorInfo *) GetNextValueInLinkedList(color_list);
1194   }
1195   UnlockSemaphoreInfo(color_semaphore);
1196   qsort((void *) colors,(size_t) i,sizeof(*colors),ColorInfoCompare);
1197   colors[i]=(ColorInfo *) NULL;
1198   *number_colors=(size_t) i;
1199   return(colors);
1200 }
1201 \f
1202 /*
1203 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1204 %                                                                             %
1205 %                                                                             %
1206 %                                                                             %
1207 %   G e t C o l o r L i s t                                                   %
1208 %                                                                             %
1209 %                                                                             %
1210 %                                                                             %
1211 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1212 %
1213 %  GetColorList() returns any colors that match the specified pattern.
1214 %
1215 %  The format of the GetColorList function is:
1216 %
1217 %      char **GetColorList(const char *pattern,size_t *number_colors,
1218 %        ExceptionInfo *exception)
1219 %
1220 %  A description of each parameter follows:
1221 %
1222 %    o pattern: Specifies a pointer to a text string containing a pattern.
1223 %
1224 %    o number_colors:  This integer returns the number of colors in the list.
1225 %
1226 %    o exception: return any errors or warnings in this structure.
1227 %
1228 */
1229
1230 #if defined(__cplusplus) || defined(c_plusplus)
1231 extern "C" {
1232 #endif
1233
1234 static int ColorCompare(const void *x,const void *y)
1235 {
1236   register const char
1237     **p,
1238     **q;
1239
1240   p=(const char **) x;
1241   q=(const char **) y;
1242   return(LocaleCompare(*p,*q));
1243 }
1244
1245 #if defined(__cplusplus) || defined(c_plusplus)
1246 }
1247 #endif
1248
1249 MagickExport char **GetColorList(const char *pattern,
1250   size_t *number_colors,ExceptionInfo *exception)
1251 {
1252   char
1253     **colors;
1254
1255   register const ColorInfo
1256     *p;
1257
1258   register ssize_t
1259     i;
1260
1261   /*
1262     Allocate color list.
1263   */
1264   assert(pattern != (char *) NULL);
1265   (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",pattern);
1266   assert(number_colors != (size_t *) NULL);
1267   *number_colors=0;
1268   p=GetColorInfo("*",exception);
1269   if (p == (const ColorInfo *) NULL)
1270     return((char **) NULL);
1271   colors=(char **) AcquireQuantumMemory((size_t)
1272     GetNumberOfElementsInLinkedList(color_list)+1UL,sizeof(*colors));
1273   if (colors == (char **) NULL)
1274     return((char **) NULL);
1275   /*
1276     Generate color list.
1277   */
1278   LockSemaphoreInfo(color_semaphore);
1279   ResetLinkedListIterator(color_list);
1280   p=(const ColorInfo *) GetNextValueInLinkedList(color_list);
1281   for (i=0; p != (const ColorInfo *) NULL; )
1282   {
1283     if ((p->stealth == MagickFalse) &&
1284         (GlobExpression(p->name,pattern,MagickFalse) != MagickFalse))
1285       colors[i++]=ConstantString(p->name);
1286     p=(const ColorInfo *) GetNextValueInLinkedList(color_list);
1287   }
1288   UnlockSemaphoreInfo(color_semaphore);
1289   qsort((void *) colors,(size_t) i,sizeof(*colors),ColorCompare);
1290   colors[i]=(char *) NULL;
1291   *number_colors=(size_t) i;
1292   return(colors);
1293 }
1294 \f
1295 /*
1296 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1297 %                                                                             %
1298 %                                                                             %
1299 %                                                                             %
1300 +   G e t C o l o r T u p l e                                                 %
1301 %                                                                             %
1302 %                                                                             %
1303 %                                                                             %
1304 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1305 %
1306 %  GetColorTuple() returns a color as a color tuple string (e.g. rgba(255,0,0))
1307 %  or hex string (e.g. #FF0000).
1308 %
1309 %  The format of the GetColorTuple method is:
1310 %
1311 %      GetColorTuple(const MagickPixelPacket *pixel,const MagickBooleanType hex,
1312 %        char *tuple)
1313 %
1314 %  A description of each parameter follows.
1315 %
1316 %    o pixel: the pixel.
1317 %
1318 %    o hex: A value other than zero returns the tuple in a hexidecimal format.
1319 %
1320 %    o tuple: Return the color tuple as this string.
1321 %
1322 */
1323
1324 static void ConcatentateHexColorComponent(const MagickPixelPacket *pixel,
1325   const ChannelType channel,char *tuple)
1326 {
1327   char
1328     component[MaxTextExtent];
1329
1330   MagickRealType
1331     color;
1332
1333   color=0.0;
1334   switch (channel)
1335   {
1336     case RedChannel:
1337     {
1338       color=pixel->red;
1339       break;
1340     }
1341     case GreenChannel:
1342     {
1343       color=pixel->green;
1344       break;
1345     }
1346     case BlueChannel:
1347     {
1348       color=pixel->blue;
1349       break;
1350     }
1351     case OpacityChannel:
1352     {
1353       color=(MagickRealType) QuantumRange-pixel->opacity;
1354       break;
1355     }
1356     case IndexChannel:
1357     {
1358       color=pixel->index;
1359       break;
1360     }
1361     default:
1362       break;
1363   }
1364   if (pixel->depth > 32)
1365     {
1366       (void) FormatMagickString(component,MaxTextExtent,"%08lX%08lX",
1367         (unsigned long) ScaleQuantumToLong(ClampToQuantum(color)),
1368         (unsigned long) ScaleQuantumToLong(ClampToQuantum(color)));
1369       (void) ConcatenateMagickString(tuple,component,MaxTextExtent);
1370       return;
1371     }
1372   if (pixel->depth > 16)
1373     {
1374       (void) FormatMagickString(component,MaxTextExtent,"%08X",
1375         (unsigned int) ScaleQuantumToLong(ClampToQuantum(color)));
1376       (void) ConcatenateMagickString(tuple,component,MaxTextExtent);
1377       return;
1378     }
1379   if (pixel->depth > 8)
1380     {
1381       (void) FormatMagickString(component,MaxTextExtent,"%04X",
1382         ScaleQuantumToShort(ClampToQuantum(color)));
1383       (void) ConcatenateMagickString(tuple,component,MaxTextExtent);
1384       return;
1385     }
1386   (void) FormatMagickString(component,MaxTextExtent,"%02X",
1387     ScaleQuantumToChar(ClampToQuantum(color)));
1388   (void) ConcatenateMagickString(tuple,component,MaxTextExtent);
1389   return;
1390 }
1391
1392 MagickExport void GetColorTuple(const MagickPixelPacket *pixel,
1393   const MagickBooleanType hex,char *tuple)
1394 {
1395   MagickPixelPacket
1396     color;
1397
1398   assert(pixel != (const MagickPixelPacket *) NULL);
1399   assert(tuple != (char *) NULL);
1400   (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",tuple);
1401   *tuple='\0';
1402   if (hex != MagickFalse)
1403     {
1404       /*
1405         Convert pixel to hex color.
1406       */
1407       (void) ConcatenateMagickString(tuple,"#",MaxTextExtent);
1408       ConcatentateHexColorComponent(pixel,RedChannel,tuple);
1409       ConcatentateHexColorComponent(pixel,GreenChannel,tuple);
1410       ConcatentateHexColorComponent(pixel,BlueChannel,tuple);
1411       if (pixel->colorspace == CMYKColorspace)
1412         ConcatentateHexColorComponent(pixel,IndexChannel,tuple);
1413       if ((pixel->matte != MagickFalse) && (pixel->opacity != OpaqueOpacity))
1414         ConcatentateHexColorComponent(pixel,OpacityChannel,tuple);
1415       return;
1416     }
1417   /*
1418     Convert pixel to rgb() or cmyk() color.
1419   */
1420   color=(*pixel);
1421   if (color.depth > 8)
1422     {
1423 #define SVGCompliant(component) ((MagickRealType) \
1424    ScaleCharToQuantum(ScaleQuantumToChar(ClampToQuantum(component))));
1425
1426       MagickStatusType
1427         status;
1428
1429       /*
1430         SVG requires color depths > 8 expressed as percentages.
1431       */
1432       status=color.red == SVGCompliant(color.red);
1433       status&=color.green == SVGCompliant(color.green);
1434       status&=color.blue == SVGCompliant(color.blue);
1435       if (color.colorspace != CMYKColorspace)
1436         status&=color.index == SVGCompliant(color.index);
1437       if (color.matte != MagickFalse)
1438         status&=color.opacity == SVGCompliant(color.opacity);
1439       if (status != MagickFalse)
1440         color.depth=8;
1441     }
1442   (void) ConcatenateMagickString(tuple,CommandOptionToMnemonic(
1443     MagickColorspaceOptions,(ssize_t) color.colorspace),MaxTextExtent);
1444   if (color.matte != MagickFalse)
1445     (void) ConcatenateMagickString(tuple,"a",MaxTextExtent);
1446   (void) ConcatenateMagickString(tuple,"(",MaxTextExtent);
1447   ConcatenateColorComponent(&color,RedChannel,SVGCompliance,tuple);
1448   (void) ConcatenateMagickString(tuple,",",MaxTextExtent);
1449   ConcatenateColorComponent(&color,GreenChannel,SVGCompliance,tuple);
1450   (void) ConcatenateMagickString(tuple,",",MaxTextExtent);
1451   ConcatenateColorComponent(&color,BlueChannel,SVGCompliance,tuple);
1452   if (color.colorspace == CMYKColorspace)
1453     {
1454       (void) ConcatenateMagickString(tuple,",",MaxTextExtent);
1455       ConcatenateColorComponent(&color,IndexChannel,SVGCompliance,tuple);
1456     }
1457   if (color.matte != MagickFalse)
1458     {
1459       (void) ConcatenateMagickString(tuple,",",MaxTextExtent);
1460       ConcatenateColorComponent(&color,AlphaChannel,SVGCompliance,tuple);
1461     }
1462   (void) ConcatenateMagickString(tuple,")",MaxTextExtent);
1463   LocaleLower(tuple);
1464   return;
1465 }
1466 \f
1467 /*
1468 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1469 %                                                                             %
1470 %                                                                             %
1471 %                                                                             %
1472 +   I n i t i a l i z e C o l o r L i s t                                     %
1473 %                                                                             %
1474 %                                                                             %
1475 %                                                                             %
1476 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1477 %
1478 %  InitializeColorList() initializes the color list.
1479 %
1480 %  The format of the InitializeColorList method is:
1481 %
1482 %      MagickBooleanType InitializeColorList(ExceptionInfo *exception)
1483 %
1484 %  A description of each parameter follows.
1485 %
1486 %    o exception: return any errors or warnings in this structure.
1487 %
1488 */
1489 static MagickBooleanType InitializeColorList(ExceptionInfo *exception)
1490 {
1491   if ((color_list == (LinkedListInfo *) NULL) &&
1492       (instantiate_color == MagickFalse))
1493     {
1494       if (color_semaphore == (SemaphoreInfo *) NULL)
1495         AcquireSemaphoreInfo(&color_semaphore);
1496       LockSemaphoreInfo(color_semaphore);
1497       if ((color_list == (LinkedListInfo *) NULL) &&
1498           (instantiate_color == MagickFalse))
1499         {
1500           (void) LoadColorLists(ColorFilename,exception);
1501           instantiate_color=MagickTrue;
1502         }
1503       UnlockSemaphoreInfo(color_semaphore);
1504     }
1505   return(color_list != (LinkedListInfo *) NULL ? MagickTrue : MagickFalse);
1506 }
1507 \f
1508 /*
1509 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1510 %                                                                             %
1511 %                                                                             %
1512 %                                                                             %
1513 +   I s C o l o r S i m i l a r                                               %
1514 %                                                                             %
1515 %                                                                             %
1516 %                                                                             %
1517 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1518 %
1519 %  IsColorSimilar() returns MagickTrue if the distance between two colors is
1520 %  less than the specified distance in a linear three dimensional color space.
1521 %  This method is used by ColorFloodFill() and other algorithms which
1522 %  compare two colors.
1523 %
1524 %  The format of the IsColorSimilar method is:
1525 %
1526 %      void IsColorSimilar(const Image *image,const PixelPacket *p,
1527 %        const PixelPacket *q)
1528 %
1529 %  A description of each parameter follows:
1530 %
1531 %    o image: the image.
1532 %
1533 %    o p: Pixel p.
1534 %
1535 %    o q: Pixel q.
1536 %
1537 */
1538
1539 static inline double MagickMax(const double x,const double y)
1540 {
1541   if (x > y)
1542     return(x);
1543   return(y);
1544 }
1545
1546 MagickExport MagickBooleanType IsColorSimilar(const Image *image,
1547   const PixelPacket *p,const PixelPacket *q)
1548 {
1549   MagickRealType
1550     fuzz,
1551     pixel;
1552
1553   register MagickRealType
1554     distance,
1555     scale;
1556
1557   if ((image->fuzz == 0.0) && (image->matte == MagickFalse))
1558     return(IsColorEqual(p,q));
1559   fuzz=MagickMax(image->fuzz,MagickSQ1_2)*MagickMax(image->fuzz,MagickSQ1_2);
1560   scale=1.0;
1561   distance=0.0;
1562   if (image->matte != MagickFalse)
1563     {
1564       /*
1565         Transparencies are involved - set alpha distance
1566       */
1567       pixel=(MagickRealType) ((image->matte != MagickFalse ? GetOpacityPixelComponent(p) :
1568         OpaqueOpacity)-(image->matte != MagickFalse ? q->opacity :
1569         OpaqueOpacity));
1570       distance=pixel*pixel;
1571       if (distance > fuzz)
1572         return(MagickFalse);
1573       /*
1574         Generate a alpha scaling factor to generate a 4D cone on colorspace
1575         Note that if one color is transparent, distance has no color component.
1576       */
1577       scale=(QuantumScale*GetAlphaPixelComponent(p));
1578       scale*=(QuantumScale*GetAlphaPixelComponent(q));
1579       if (scale <= MagickEpsilon)
1580         return(MagickTrue);
1581     }
1582   /*
1583     RGB or CMY color cube
1584   */
1585   distance*=3.0;  /* rescale appropriately */
1586   fuzz*=3.0;
1587   pixel=(MagickRealType) GetRedPixelComponent(p)-GetRedPixelComponent(q);
1588   if ((image->colorspace == HSLColorspace) ||
1589       (image->colorspace == HSBColorspace) ||
1590       (image->colorspace == HWBColorspace))
1591     {
1592       /* This calculates a arc distance for hue.  Really if should be a vector
1593          angle of 'S'/'W' length with 'L'/'B' forming appropriate cones.  In
1594          other words this is a hack - Anthony
1595       */
1596       if (fabs((double) pixel) > (QuantumRange/2))
1597         pixel-=QuantumRange;
1598       pixel*=2;
1599     }
1600   distance+=scale*pixel*pixel;
1601   if (distance > fuzz)
1602     return(MagickFalse);
1603   pixel=(MagickRealType) GetGreenPixelComponent(p)-q->green;
1604   distance+=scale*pixel*pixel;
1605   if (distance > fuzz)
1606     return(MagickFalse);
1607   pixel=(MagickRealType) GetBluePixelComponent(p)-q->blue;
1608   distance+=scale*pixel*pixel;
1609   if (distance > fuzz)
1610     return(MagickFalse);
1611   return(MagickTrue);
1612 }
1613 \f
1614 /*
1615 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1616 %                                                                             %
1617 %                                                                             %
1618 %                                                                             %
1619 +   I s I m a g e S i m i l a r                                               %
1620 %                                                                             %
1621 %                                                                             %
1622 %                                                                             %
1623 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1624 %
1625 %  IsImageSimilar() returns true if the target is similar to a region of the
1626 %  image.
1627 %
1628 %  The format of the IsImageSimilar method is:
1629 %
1630 %      MagickBooleanType IsImageSimilar(const Image *image,
1631 %        const Image *target_image,ssize_t *x_offset,ssize_t *y_offset,
1632 %        ExceptionInfo *exception)
1633 %
1634 %  A description of each parameter follows:
1635 %
1636 %    o image: the image.
1637 %
1638 %    o target_image: the target image.
1639 %
1640 %    o x_offset: On input the starting x position to search for a match;
1641 %      on output the x position of the first match found.
1642 %
1643 %    o y_offset: On input the starting y position to search for a match;
1644 %      on output the y position of the first match found.
1645 %
1646 %    o exception: return any errors or warnings in this structure.
1647 %
1648 */
1649 MagickExport MagickBooleanType IsImageSimilar(const Image *image,
1650   const Image *target_image,ssize_t *x_offset,ssize_t *y_offset,
1651   ExceptionInfo *exception)
1652 {
1653 #define SearchImageText  "  Searching image...  "
1654
1655   CacheView
1656     *image_view,
1657     *target_view;
1658
1659   MagickBooleanType
1660     status;
1661
1662   MagickPixelPacket
1663     target,
1664     pixel;
1665
1666   register const PixelPacket
1667     *p,
1668     *q;
1669
1670   register const IndexPacket
1671     *indexes,
1672     *target_indexes;
1673
1674   register ssize_t
1675     i,
1676     x;
1677
1678   ssize_t
1679     j,
1680     y;
1681
1682   assert(image != (Image *) NULL);
1683   assert(image->signature == MagickSignature);
1684   if (image->debug != MagickFalse)
1685     (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1686   assert(target_image != (Image *) NULL);
1687   assert(target_image->signature == MagickSignature);
1688   assert(x_offset != (ssize_t *) NULL);
1689   assert(y_offset != (ssize_t *) NULL);
1690   assert(exception != (ExceptionInfo *) NULL);
1691   x=0;
1692   status=MagickTrue;
1693   GetMagickPixelPacket(image,&pixel);
1694   GetMagickPixelPacket(image,&target);
1695   image_view=AcquireCacheView(image);
1696   target_view=AcquireCacheView(target_image);
1697   for (y=(*y_offset); y < (ssize_t) image->rows; y++)
1698   {
1699     for (x=y == 0 ? *x_offset : 0; x < (ssize_t) image->columns; x++)
1700     {
1701       for (j=0; j < (ssize_t) target_image->rows; j++)
1702       {
1703         for (i=0; i < (ssize_t) target_image->columns; i++)
1704         {
1705           p=GetCacheViewVirtualPixels(image_view,x+i,y+j,1,1,exception);
1706           indexes=GetCacheViewVirtualIndexQueue(image_view);
1707           SetMagickPixelPacket(image,p,indexes,&pixel);
1708           q=GetCacheViewVirtualPixels(target_view,i,j,1,1,exception);
1709           target_indexes=GetCacheViewVirtualIndexQueue(target_view);
1710           SetMagickPixelPacket(image,q,target_indexes,&target);
1711           if (IsMagickColorSimilar(&pixel,&target) == MagickFalse)
1712             break;
1713         }
1714         if (i < (ssize_t) target_image->columns)
1715           break;
1716       }
1717       if (j == (ssize_t) target_image->rows)
1718         break;
1719     }
1720     if (x < (ssize_t) image->columns)
1721       break;
1722     if (image->progress_monitor != (MagickProgressMonitor) NULL)
1723       {
1724         MagickBooleanType
1725           proceed;
1726
1727         proceed=SetImageProgress(image,SearchImageText,(MagickOffsetType) y,
1728           image->rows);
1729         if (proceed == MagickFalse)
1730           status=MagickFalse;
1731       }
1732   }
1733   target_view=DestroyCacheView(target_view);
1734   image_view=DestroyCacheView(image_view);
1735   *x_offset=x;
1736   *y_offset=y;
1737   if (status == MagickFalse)
1738     return(status);
1739   return(y < (ssize_t) image->rows ? MagickTrue : MagickFalse);
1740 }
1741 \f
1742 /*
1743 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1744 %                                                                             %
1745 %                                                                             %
1746 %                                                                             %
1747 +   I s M a g i c k C o l o r S i m i l a r                                   %
1748 %                                                                             %
1749 %                                                                             %
1750 %                                                                             %
1751 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1752 %
1753 %  IsMagickColorSimilar() returns true if the distance between two colors is
1754 %  less than the specified distance in a linear three dimensional color space.
1755 %  This method is used by ColorFloodFill() and other algorithms which
1756 %  compare two colors.
1757 %
1758 %  This implements the equivalent of...
1759 %    fuzz < sqrt( color_distance^2 * u.a*v.a  + alpha_distance^2 )
1760 %
1761 %  Which produces a multi-dimentional cone for that colorspace along the
1762 %  transparency vector.
1763 %
1764 %  For example for an RGB
1765 %    color_distance^2  = ( (u.r-v.r)^2 + (u.g-v.g)^2 + (u.b-v.b)^2 ) / 3
1766 %
1767 %  See http://www.imagemagick.org/Usage/bugs/fuzz_distance/
1768 %
1769 %  Hue colorspace distances need more work.  Hue is not a distance, it is an
1770 %  angle!
1771 %
1772 %  A check that q is in the same color space as p should be made and the
1773 %  appropriate mapping made.  -- Anthony Thyssen  8 December 2010
1774 %
1775 %  The format of the IsMagickColorSimilar method is:
1776 %
1777 %      MagickBooleanType IsMagickColorSimilar(const MagickPixelPacket *p,
1778 %        const MagickPixelPacket *q)
1779 %
1780 %  A description of each parameter follows:
1781 %
1782 %    o p: Pixel p.
1783 %
1784 %    o q: Pixel q.
1785 %
1786 */
1787 MagickExport MagickBooleanType IsMagickColorSimilar(const MagickPixelPacket *p,
1788   const MagickPixelPacket *q)
1789 {
1790   MagickRealType
1791     fuzz,
1792     pixel;
1793
1794   register MagickRealType
1795     scale,
1796     distance;
1797
1798   if ((p->fuzz == 0.0) && (q->fuzz == 0.0))
1799     return(IsMagickColorEqual(p,q));
1800   if (p->fuzz == 0.0)
1801     fuzz=MagickMax(q->fuzz,MagickSQ1_2)*MagickMax(q->fuzz,MagickSQ1_2);
1802   else if (q->fuzz == 0.0)
1803     fuzz=MagickMax(p->fuzz,MagickSQ1_2)*MagickMax(p->fuzz,MagickSQ1_2);
1804   else
1805     fuzz=MagickMax(p->fuzz,MagickSQ1_2)*MagickMax(q->fuzz,MagickSQ1_2);
1806   scale=1.0;
1807   distance=0.0;
1808   if ((p->matte != MagickFalse) || (q->matte != MagickFalse))
1809     {
1810       /*
1811         Transparencies are involved - set alpha distance.
1812       */
1813       pixel=(p->matte != MagickFalse ? GetOpacityPixelComponent(p) :
1814         OpaqueOpacity)-(q->matte != MagickFalse ? q->opacity : OpaqueOpacity);
1815       distance=pixel*pixel;
1816       if (distance > fuzz)
1817         return(MagickFalse);
1818       /*
1819         Generate a alpha scaling factor to generate a 4D cone on colorspace.
1820         Note that if one color is transparent, distance has no color component
1821       */
1822       if (p->matte != MagickFalse)
1823         scale=(QuantumScale*GetAlphaPixelComponent(p));
1824       if (q->matte != MagickFalse)
1825         scale*=(QuantumScale*GetAlphaPixelComponent(q));
1826       if ( scale <= MagickEpsilon )
1827         return(MagickTrue);
1828     }
1829   /*
1830     CMYK create a CMY cube with a multi-dimensional cone toward black.
1831   */
1832   if (p->colorspace == CMYKColorspace)
1833     {
1834       pixel=p->index-q->index;
1835       distance+=pixel*pixel*scale;
1836       if (distance > fuzz)
1837         return(MagickFalse);
1838       scale*=(MagickRealType) (QuantumScale*(QuantumRange-p->index));
1839       scale*=(MagickRealType) (QuantumScale*(QuantumRange-q->index));
1840     }
1841   /*
1842     RGB or CMY color cube.
1843   */
1844   distance*=3.0;  /* rescale appropriately */
1845   fuzz*=3.0;
1846   pixel=p->red-q->red;
1847   if ((p->colorspace == HSLColorspace) || (p->colorspace == HSBColorspace) ||
1848       (p->colorspace == HWBColorspace))
1849     {
1850       /* This calculates a arc distance for hue
1851          Really if should be a vector angle of 'S'/'W' length
1852          with 'L'/'B' forming appropriate cones.
1853          In other words this is a hack - Anthony
1854       */
1855       if (fabs((double) pixel) > (QuantumRange/2))
1856         pixel-=QuantumRange;
1857       pixel*=2;
1858     }
1859   distance+=pixel*pixel*scale;
1860   if (distance > fuzz)
1861     return(MagickFalse);
1862   pixel=GetGreenPixelComponent(p)-q->green;
1863   distance+=pixel*pixel*scale;
1864   if (distance > fuzz)
1865     return(MagickFalse);
1866   pixel=GetBluePixelComponent(p)-q->blue;
1867   distance+=pixel*pixel*scale;
1868   if (distance > fuzz)
1869     return(MagickFalse);
1870   return(MagickTrue);
1871 }
1872 \f
1873 /*
1874 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1875 %                                                                             %
1876 %                                                                             %
1877 %                                                                             %
1878 +   I s O p a c i t y S i m i l a r                                           %
1879 %                                                                             %
1880 %                                                                             %
1881 %                                                                             %
1882 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1883 %
1884 %  IsOpacitySimilar() returns true if the distance between two opacity
1885 %  values is less than the specified distance in a linear color space.  This
1886 %  method is used by MatteFloodFill() and other algorithms which compare
1887 %  two opacity values.
1888 %
1889 %  The format of the IsOpacitySimilar method is:
1890 %
1891 %      void IsOpacitySimilar(const Image *image,const PixelPacket *p,
1892 %        const PixelPacket *q)
1893 %
1894 %  A description of each parameter follows:
1895 %
1896 %    o image: the image.
1897 %
1898 %    o p: Pixel p.
1899 %
1900 %    o q: Pixel q.
1901 %
1902 */
1903 MagickExport MagickBooleanType IsOpacitySimilar(const Image *image,
1904   const PixelPacket *p,const PixelPacket *q)
1905 {
1906   MagickRealType
1907     fuzz,
1908     pixel;
1909
1910   register MagickRealType
1911     distance;
1912
1913   if (image->matte == MagickFalse)
1914     return(MagickTrue);
1915   if (GetOpacityPixelComponent(p) == q->opacity)
1916     return(MagickTrue);
1917   fuzz=MagickMax(image->fuzz,MagickSQ1_2)*MagickMax(image->fuzz,MagickSQ1_2);
1918   pixel=(MagickRealType) GetOpacityPixelComponent(p)-(MagickRealType) q->opacity;
1919   distance=pixel*pixel;
1920   if (distance > fuzz)
1921     return(MagickFalse);
1922   return(MagickTrue);
1923 }
1924 \f
1925 /*
1926 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1927 %                                                                             %
1928 %                                                                             %
1929 %                                                                             %
1930 %  L i s t C o l o r I n f o                                                  %
1931 %                                                                             %
1932 %                                                                             %
1933 %                                                                             %
1934 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1935 %
1936 %  ListColorInfo() lists color names to the specified file.  Color names
1937 %  are a convenience.  Rather than defining a color by its red, green, and
1938 %  blue intensities just use a color name such as white, blue, or yellow.
1939 %
1940 %  The format of the ListColorInfo method is:
1941 %
1942 %      MagickBooleanType ListColorInfo(FILE *file,ExceptionInfo *exception)
1943 %
1944 %  A description of each parameter follows.
1945 %
1946 %    o file:  List color names to this file handle.
1947 %
1948 %    o exception: return any errors or warnings in this structure.
1949 %
1950 */
1951 MagickExport MagickBooleanType ListColorInfo(FILE *file,
1952   ExceptionInfo *exception)
1953 {
1954   char
1955     tuple[MaxTextExtent];
1956
1957   const char
1958     *path;
1959
1960   const ColorInfo
1961     **color_info;
1962
1963   register ssize_t
1964     i;
1965
1966   size_t
1967     number_colors;
1968
1969   /*
1970     List name and attributes of each color in the list.
1971   */
1972   if (file == (const FILE *) NULL)
1973     file=stdout;
1974   color_info=GetColorInfoList("*",&number_colors,exception);
1975   if (color_info == (const ColorInfo **) NULL)
1976     return(MagickFalse);
1977   path=(const char *) NULL;
1978   for (i=0; i < (ssize_t) number_colors; i++)
1979   {
1980     if (color_info[i]->stealth != MagickFalse)
1981       continue;
1982     if ((path == (const char *) NULL) ||
1983         (LocaleCompare(path,color_info[i]->path) != 0))
1984       {
1985         if (color_info[i]->path != (char *) NULL)
1986           (void) fprintf(file,"\nPath: %s\n\n",color_info[i]->path);
1987         (void) fprintf(file,"Name                  Color                  "
1988           "                       Compliance\n");
1989         (void) fprintf(file,"-------------------------------------------------"
1990           "------------------------------\n");
1991       }
1992     path=color_info[i]->path;
1993     (void) fprintf(file,"%-21.21s ",color_info[i]->name);
1994     GetColorTuple(&color_info[i]->color,MagickFalse,tuple);
1995     (void) fprintf(file,"%-45.45s ",tuple);
1996     if ((color_info[i]->compliance & SVGCompliance) != 0)
1997       (void) fprintf(file,"SVG ");
1998     if ((color_info[i]->compliance & X11Compliance) != 0)
1999       (void) fprintf(file,"X11 ");
2000     if ((color_info[i]->compliance & XPMCompliance) != 0)
2001       (void) fprintf(file,"XPM ");
2002     (void) fprintf(file,"\n");
2003   }
2004   color_info=(const ColorInfo **) RelinquishMagickMemory((void *) color_info);
2005   (void) fflush(file);
2006   return(MagickTrue);
2007 }
2008 \f
2009 /*
2010 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2011 %                                                                             %
2012 %                                                                             %
2013 %                                                                             %
2014 +   L o a d C o l o r L i s t                                                 %
2015 %                                                                             %
2016 %                                                                             %
2017 %                                                                             %
2018 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2019 %
2020 %  LoadColorList() loads the color configuration file which provides a mapping
2021 %  between color attributes and a color name.
2022 %
2023 %  The format of the LoadColorList method is:
2024 %
2025 %      MagickBooleanType LoadColorList(const char *xml,const char *filename,
2026 %        const size_t depth,ExceptionInfo *exception)
2027 %
2028 %  A description of each parameter follows:
2029 %
2030 %    o xml:  The color list in XML format.
2031 %
2032 %    o filename:  The color list filename.
2033 %
2034 %    o depth: depth of <include /> statements.
2035 %
2036 %    o exception: return any errors or warnings in this structure.
2037 %
2038 */
2039 static MagickBooleanType LoadColorList(const char *xml,const char *filename,
2040   const size_t depth,ExceptionInfo *exception)
2041 {
2042   char
2043     keyword[MaxTextExtent],
2044     *token;
2045
2046   ColorInfo
2047     *color_info;
2048
2049   const char
2050     *q;
2051
2052   MagickBooleanType
2053     status;
2054
2055   /*
2056     Load the color map file.
2057   */
2058   (void) LogMagickEvent(ConfigureEvent,GetMagickModule(),
2059     "Loading color file \"%s\" ...",filename);
2060   if (xml == (char *) NULL)
2061     return(MagickFalse);
2062   if (color_list == (LinkedListInfo *) NULL)
2063     {
2064       color_list=NewLinkedList(0);
2065       if (color_list == (LinkedListInfo *) NULL)
2066         {
2067           ThrowFileException(exception,ResourceLimitError,
2068             "MemoryAllocationFailed",filename);
2069           return(MagickFalse);
2070         }
2071     }
2072   status=MagickTrue;
2073   color_info=(ColorInfo *) NULL;
2074   token=AcquireString(xml);
2075   for (q=(char *) xml; *q != '\0'; )
2076   {
2077     /*
2078       Interpret XML.
2079     */
2080     GetMagickToken(q,&q,token);
2081     if (*token == '\0')
2082       break;
2083     (void) CopyMagickString(keyword,token,MaxTextExtent);
2084     if (LocaleNCompare(keyword,"<!DOCTYPE",9) == 0)
2085       {
2086         /*
2087           Doctype element.
2088         */
2089         while ((LocaleNCompare(q,"]>",2) != 0) && (*q != '\0'))
2090           GetMagickToken(q,&q,token);
2091         continue;
2092       }
2093     if (LocaleNCompare(keyword,"<!--",4) == 0)
2094       {
2095         /*
2096           Comment element.
2097         */
2098         while ((LocaleNCompare(q,"->",2) != 0) && (*q != '\0'))
2099           GetMagickToken(q,&q,token);
2100         continue;
2101       }
2102     if (LocaleCompare(keyword,"<include") == 0)
2103       {
2104         /*
2105           Include element.
2106         */
2107         while (((*token != '/') && (*(token+1) != '>')) && (*q != '\0'))
2108         {
2109           (void) CopyMagickString(keyword,token,MaxTextExtent);
2110           GetMagickToken(q,&q,token);
2111           if (*token != '=')
2112             continue;
2113           GetMagickToken(q,&q,token);
2114           if (LocaleCompare(keyword,"file") == 0)
2115             {
2116               if (depth > 200)
2117                 (void) ThrowMagickException(exception,GetMagickModule(),
2118                   ConfigureError,"IncludeElementNestedTooDeeply","`%s'",token);
2119               else
2120                 {
2121                   char
2122                     path[MaxTextExtent],
2123                     *xml;
2124
2125                   GetPathComponent(filename,HeadPath,path);
2126                   if (*path != '\0')
2127                     (void) ConcatenateMagickString(path,DirectorySeparator,
2128                       MaxTextExtent);
2129                   if (*token == *DirectorySeparator)
2130                     (void) CopyMagickString(path,token,MaxTextExtent);
2131                   else
2132                     (void) ConcatenateMagickString(path,token,MaxTextExtent);
2133                   xml=FileToString(path,~0,exception);
2134                   if (xml != (char *) NULL)
2135                     {
2136                       status=LoadColorList(xml,path,depth+1,exception);
2137                       xml=(char *) RelinquishMagickMemory(xml);
2138                     }
2139                 }
2140             }
2141         }
2142         continue;
2143       }
2144     if (LocaleCompare(keyword,"<color") == 0)
2145       {
2146         /*
2147           Color element.
2148         */
2149         color_info=(ColorInfo *) AcquireMagickMemory(sizeof(*color_info));
2150         if (color_info == (ColorInfo *) NULL)
2151           ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed");
2152         (void) ResetMagickMemory(color_info,0,sizeof(*color_info));
2153         color_info->path=ConstantString(filename);
2154         color_info->exempt=MagickFalse;
2155         color_info->signature=MagickSignature;
2156         continue;
2157       }
2158     if (color_info == (ColorInfo *) NULL)
2159       continue;
2160     if (LocaleCompare(keyword,"/>") == 0)
2161       {
2162         status=AppendValueToLinkedList(color_list,color_info);
2163         if (status == MagickFalse)
2164           (void) ThrowMagickException(exception,GetMagickModule(),
2165             ResourceLimitError,"MemoryAllocationFailed","`%s'",
2166             color_info->name);
2167         color_info=(ColorInfo *) NULL;
2168       }
2169     GetMagickToken(q,(const char **) NULL,token);
2170     if (*token != '=')
2171       continue;
2172     GetMagickToken(q,&q,token);
2173     GetMagickToken(q,&q,token);
2174     switch (*keyword)
2175     {
2176       case 'C':
2177       case 'c':
2178       {
2179         if (LocaleCompare((char *) keyword,"color") == 0)
2180           {
2181             (void) QueryMagickColor(token,&color_info->color,exception);
2182             break;
2183           }
2184         if (LocaleCompare((char *) keyword,"compliance") == 0)
2185           {
2186             ssize_t
2187               compliance;
2188
2189             compliance=color_info->compliance;
2190             if (GlobExpression(token,"*SVG*",MagickTrue) != MagickFalse)
2191               compliance|=SVGCompliance;
2192             if (GlobExpression(token,"*X11*",MagickTrue) != MagickFalse)
2193               compliance|=X11Compliance;
2194             if (GlobExpression(token,"*XPM*",MagickTrue) != MagickFalse)
2195               compliance|=XPMCompliance;
2196             color_info->compliance=(ComplianceType) compliance;
2197             break;
2198           }
2199         break;
2200       }
2201       case 'N':
2202       case 'n':
2203       {
2204         if (LocaleCompare((char *) keyword,"name") == 0)
2205           {
2206             color_info->name=ConstantString(token);
2207             break;
2208           }
2209         break;
2210       }
2211       case 'S':
2212       case 's':
2213       {
2214         if (LocaleCompare((char *) keyword,"stealth") == 0)
2215           {
2216             color_info->stealth=IsMagickTrue(token);
2217             break;
2218           }
2219         break;
2220       }
2221       default:
2222         break;
2223     }
2224   }
2225   token=(char *) RelinquishMagickMemory(token);
2226   return(status);
2227 }
2228 \f
2229 /*
2230 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2231 %                                                                             %
2232 %                                                                             %
2233 %                                                                             %
2234 %  L o a d C o l o r L i s t s                                                %
2235 %                                                                             %
2236 %                                                                             %
2237 %                                                                             %
2238 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2239 %
2240 %  LoadColorList() loads one or more color configuration file which provides a
2241 %  mapping between color attributes and a color name.
2242 %
2243 %  The format of the LoadColorLists method is:
2244 %
2245 %      MagickBooleanType LoadColorLists(const char *filename,
2246 %        ExceptionInfo *exception)
2247 %
2248 %  A description of each parameter follows:
2249 %
2250 %    o filename: the font file name.
2251 %
2252 %    o exception: return any errors or warnings in this structure.
2253 %
2254 */
2255 static MagickBooleanType LoadColorLists(const char *filename,
2256   ExceptionInfo *exception)
2257 {
2258   const StringInfo
2259     *option;
2260
2261   LinkedListInfo
2262     *options;
2263
2264   MagickStatusType
2265     status;
2266
2267   register ssize_t
2268     i;
2269
2270   /*
2271     Load built-in color map.
2272   */
2273   status=MagickFalse;
2274   if (color_list == (LinkedListInfo *) NULL)
2275     {
2276       color_list=NewLinkedList(0);
2277       if (color_list == (LinkedListInfo *) NULL)
2278         {
2279           ThrowFileException(exception,ResourceLimitError,
2280             "MemoryAllocationFailed",filename);
2281           return(MagickFalse);
2282         }
2283     }
2284   for (i=0; i < (ssize_t) (sizeof(ColorMap)/sizeof(*ColorMap)); i++)
2285   {
2286     ColorInfo
2287       *color_info;
2288
2289     register const ColorMapInfo
2290       *p;
2291
2292     p=ColorMap+i;
2293     color_info=(ColorInfo *) AcquireMagickMemory(sizeof(*color_info));
2294     if (color_info == (ColorInfo *) NULL)
2295       {
2296         (void) ThrowMagickException(exception,GetMagickModule(),
2297           ResourceLimitError,"MemoryAllocationFailed","`%s'",color_info->name);
2298         continue;
2299       }
2300     (void) ResetMagickMemory(color_info,0,sizeof(*color_info));
2301     color_info->path=(char *) "[built-in]";
2302     color_info->name=(char *) p->name;
2303     GetMagickPixelPacket((Image *) NULL,&color_info->color);
2304     color_info->color.red=(MagickRealType) ScaleCharToQuantum(
2305       GetRedPixelComponent(p));
2306     color_info->color.green=(MagickRealType) ScaleCharToQuantum(
2307       GetGreenPixelComponent(p));
2308     color_info->color.blue=(MagickRealType) ScaleCharToQuantum(
2309       GetBluePixelComponent(p));
2310     color_info->color.opacity=(MagickRealType) (QuantumRange-QuantumRange*
2311       p->alpha);
2312     color_info->compliance=(ComplianceType) p->compliance;
2313     color_info->exempt=MagickTrue;
2314     color_info->signature=MagickSignature;
2315     status=AppendValueToLinkedList(color_list,color_info);
2316     if (status == MagickFalse)
2317       (void) ThrowMagickException(exception,GetMagickModule(),
2318         ResourceLimitError,"MemoryAllocationFailed","`%s'",color_info->name);
2319   }
2320   /*
2321     Load external color map.
2322   */
2323   options=GetConfigureOptions(filename,exception);
2324   option=(const StringInfo *) GetNextValueInLinkedList(options);
2325   while (option != (const StringInfo *) NULL)
2326   {
2327     status|=LoadColorList((const char *) GetStringInfoDatum(option),
2328       GetStringInfoPath(option),0,exception);
2329     option=(const StringInfo *) GetNextValueInLinkedList(options);
2330   }
2331   options=DestroyConfigureOptions(options);
2332   return(status != 0 ? MagickTrue : MagickFalse);
2333 }
2334 \f
2335 /*
2336 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2337 %                                                                             %
2338 %                                                                             %
2339 %                                                                             %
2340 %   Q u e r y C o l o r D a t a b a s e                                       %
2341 %                                                                             %
2342 %                                                                             %
2343 %                                                                             %
2344 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2345 %
2346 %  QueryColorDatabase() returns the red, green, blue, and opacity intensities
2347 %  for a given color name.
2348 %
2349 %  The format of the QueryColorDatabase method is:
2350 %
2351 %      MagickBooleanType QueryColorDatabase(const char *name,
2352 %        const ComplianceType compliance,PixelPacket *color,
2353 %        ExceptionInfo *exception)
2354 %
2355 %  A description of each parameter follows:
2356 %
2357 %    o name: the color name (e.g. white, blue, yellow).
2358 %
2359 %    o compliance: Adhere to this color standard: SVG, X11, or XPM.
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
2368 static inline double MagickMin(const double x,const double y)
2369 {
2370   if (x < y)
2371     return(x);
2372   return(y);
2373 }
2374
2375 MagickExport MagickBooleanType QueryColorCompliance(const char *name,
2376   const ComplianceType compliance,PixelPacket *color,ExceptionInfo *exception)
2377 {
2378   MagickBooleanType
2379     status;
2380
2381   MagickPixelPacket
2382     pixel;
2383
2384   status=QueryMagickColorCompliance(name,compliance,&pixel,exception);
2385   SetOpacityPixelComponent(color,ClampToQuantum(pixel.opacity));
2386   if (pixel.colorspace == CMYKColorspace)
2387     {
2388       SetRedPixelComponent(color,ClampToQuantum((MagickRealType)
2389         (QuantumRange-MagickMin(QuantumRange,(MagickRealType) (QuantumScale*
2390         pixel.red*(QuantumRange-pixel.index)+pixel.index)))));
2391       SetGreenPixelComponent(color,ClampToQuantum((MagickRealType)
2392         (QuantumRange-MagickMin(QuantumRange,(MagickRealType) (QuantumScale*
2393         pixel.green*(QuantumRange-pixel.index)+pixel.index)))));
2394       SetBluePixelComponent(color,ClampToQuantum((MagickRealType)
2395         (QuantumRange-MagickMin(QuantumRange,(MagickRealType) (QuantumScale*
2396         pixel.blue*(QuantumRange-pixel.index)+pixel.index)))));
2397       return(status);
2398     }
2399   SetRedPixelComponent(color,ClampToQuantum(pixel.red));
2400   SetGreenPixelComponent(color,ClampToQuantum(pixel.green));
2401   SetBluePixelComponent(color,ClampToQuantum(pixel.blue));
2402   return(status);
2403 }
2404 \f
2405 /*
2406 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2407 %                                                                             %
2408 %                                                                             %
2409 %                                                                             %
2410 %   Q u e r y C o l o r D a t a b a s e                                       %
2411 %                                                                             %
2412 %                                                                             %
2413 %                                                                             %
2414 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2415 %
2416 %  QueryColorDatabase() returns the red, green, blue, and opacity intensities
2417 %  for a given color name.
2418 %
2419 %  The format of the QueryColorDatabase method is:
2420 %
2421 %      MagickBooleanType QueryColorDatabase(const char *name,PixelPacket *color,
2422 %        ExceptionInfo *exception)
2423 %
2424 %  A description of each parameter follows:
2425 %
2426 %    o name: the color name (e.g. white, blue, yellow).
2427 %
2428 %    o color: the red, green, blue, and opacity intensities values of the
2429 %      named color in this structure.
2430 %
2431 %    o exception: return any errors or warnings in this structure.
2432 %
2433 */
2434 MagickExport MagickBooleanType QueryColorDatabase(const char *name,
2435   PixelPacket *color,ExceptionInfo *exception)
2436 {
2437   return(QueryColorCompliance(name,AllCompliance,color,exception));
2438 }
2439 \f
2440 /*
2441 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2442 %                                                                             %
2443 %                                                                             %
2444 %                                                                             %
2445 %  Q u e r y C o l o r n a m e                                                %
2446 %                                                                             %
2447 %                                                                             %
2448 %                                                                             %
2449 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2450 %
2451 %  QueryColorname() returns a named color for the given color intensity.  If
2452 %  an exact match is not found, a rgb() color is returned instead.
2453 %
2454 %  The format of the QueryColorname method is:
2455 %
2456 %      MagickBooleanType QueryColorname(const Image *image,
2457 %        const PixelPacket *color,const ComplianceType compliance,char *name,
2458 %        ExceptionInfo *exception)
2459 %
2460 %  A description of each parameter follows.
2461 %
2462 %    o image: the image.
2463 %
2464 %    o color: the color intensities.
2465 %
2466 %    o compliance: Adhere to this color standard: SVG, X11, or XPM.
2467 %
2468 %    o name: Return the color name or hex value.
2469 %
2470 %    o exception: return any errors or warnings in this structure.
2471 %
2472 */
2473 MagickExport MagickBooleanType QueryColorname(const Image *image,
2474   const PixelPacket *color,const ComplianceType compliance,char *name,
2475   ExceptionInfo *exception)
2476 {
2477   MagickPixelPacket
2478     pixel;
2479
2480   GetMagickPixelPacket(image,&pixel);
2481   SetMagickPixelPacket(image,color,(IndexPacket *) NULL,&pixel);
2482   return(QueryMagickColorname(image,&pixel,compliance,name,exception));
2483 }
2484 \f
2485 /*
2486 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2487 %                                                                             %
2488 %                                                                             %
2489 %                                                                             %
2490 %   Q u e r y M a g i c k C o l o r C o m p l i a n c e                       %
2491 %                                                                             %
2492 %                                                                             %
2493 %                                                                             %
2494 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2495 %
2496 %  QueryMagickColorCompliance() returns the red, green, blue, and opacity
2497 %  intensities for a given color name and standards compliance.
2498 %
2499 %  The format of the QueryMagickColor method is:
2500 %
2501 %      MagickBooleanType QueryMagickColor(const char *name,
2502 %        const ComplianceType compliance,MagickPixelPacket *color,
2503 %        ExceptionInfo *exception)
2504 %
2505 %  A description of each parameter follows:
2506 %
2507 %    o name: the color name (e.g. white, blue, yellow).
2508 %
2509 %    o compliance: Adhere to this color standard: SVG, X11, or XPM.
2510 %
2511 %    o color: the red, green, blue, and opacity intensities values of the
2512 %      named color in this structure.
2513 %
2514 %    o exception: return any errors or warnings in this structure.
2515 %
2516 */
2517 MagickExport MagickBooleanType QueryMagickColorCompliance(const char *name,
2518   const ComplianceType compliance,MagickPixelPacket *color,
2519   ExceptionInfo *exception)
2520 {
2521   GeometryInfo
2522     geometry_info;
2523
2524   MagickRealType
2525     scale;
2526
2527   MagickStatusType
2528     flags;
2529
2530   register const ColorInfo
2531     *p;
2532
2533   register ssize_t
2534     i;
2535
2536   ssize_t
2537     type;
2538
2539   /*
2540     Initialize color return value.
2541   */
2542   assert(name != (const char *) NULL);
2543   (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",name);
2544   assert(color != (MagickPixelPacket *) NULL);
2545   GetMagickPixelPacket((Image *) NULL,color);
2546   if ((name == (char *) NULL) || (*name == '\0'))
2547     name=BackgroundColor;
2548   while (isspace((int) ((unsigned char) *name)) != 0)
2549     name++;
2550   if (*name == '#')
2551     {
2552       char
2553         c;
2554
2555       LongPixelPacket
2556         pixel;
2557
2558       QuantumAny
2559         range;
2560
2561       size_t
2562         depth,
2563         n;
2564
2565       /*
2566         Parse hex color.
2567       */
2568       (void) ResetMagickMemory(&pixel,0,sizeof(pixel));
2569       name++;
2570       for (n=0; isxdigit((int) ((unsigned char) name[n])) != MagickFalse; n++) ;
2571       if ((n % 3) == 0)
2572         {
2573           do
2574           {
2575             pixel.red=pixel.green;
2576             pixel.green=pixel.blue;
2577             pixel.blue=0;
2578             for (i=(ssize_t) (n/3-1); i >= 0; i--)
2579             {
2580               c=(*name++);
2581               pixel.blue<<=4;
2582               if ((c >= '0') && (c <= '9'))
2583                 pixel.blue|=(int) (c-'0');
2584               else
2585                 if ((c >= 'A') && (c <= 'F'))
2586                   pixel.blue|=(int) c-((int) 'A'-10);
2587                 else
2588                   if ((c >= 'a') && (c <= 'f'))
2589                     pixel.blue|=(int) c-((int) 'a'-10);
2590                   else
2591                     return(MagickFalse);
2592             }
2593           } while (isxdigit((int) ((unsigned char) *name)) != MagickFalse);
2594           depth=4*(n/3);
2595         }
2596       else
2597         {
2598           if ((n % 4) != 0)
2599             {
2600               (void) ThrowMagickException(exception,GetMagickModule(),
2601                 OptionWarning,"UnrecognizedColor","`%s'",name);
2602               return(MagickFalse);
2603             }
2604           do
2605           {
2606             pixel.red=pixel.green;
2607             pixel.green=pixel.blue;
2608             pixel.blue=pixel.opacity;
2609             pixel.opacity=0;
2610             for (i=(ssize_t) (n/4-1); i >= 0; i--)
2611             {
2612               c=(*name++);
2613               pixel.opacity<<=4;
2614               if ((c >= '0') && (c <= '9'))
2615                 pixel.opacity|=(int) (c-'0');
2616               else
2617                 if ((c >= 'A') && (c <= 'F'))
2618                   pixel.opacity|=(int) c-((int) 'A'-10);
2619                 else
2620                   if ((c >= 'a') && (c <= 'f'))
2621                     pixel.opacity|=(int) c-((int) 'a'-10);
2622                   else
2623                     return(MagickFalse);
2624             }
2625           } while (isxdigit((int) ((unsigned char) *name)) != MagickFalse);
2626           depth=4*(n/4);
2627         }
2628       color->colorspace=RGBColorspace;
2629       color->matte=MagickFalse;
2630       range=GetQuantumRange(depth);
2631       color->red=(MagickRealType) ScaleAnyToQuantum(pixel.red,range);
2632       color->green=(MagickRealType) ScaleAnyToQuantum(pixel.green,range);
2633       color->blue=(MagickRealType) ScaleAnyToQuantum(pixel.blue,range);
2634       color->opacity=(MagickRealType) OpaqueOpacity;
2635       if ((n % 3) != 0)
2636         {
2637           color->matte=MagickTrue;
2638           color->opacity=(MagickRealType) (QuantumRange-ScaleAnyToQuantum(
2639             pixel.opacity,range));
2640         }
2641       color->index=0.0;
2642       return(MagickTrue);
2643     }
2644   if (strchr(name,'(') != (char *) NULL)
2645     {
2646       char
2647         colorspace[MaxTextExtent];
2648
2649       /*
2650         Parse color of the form rgb(100,255,0).
2651       */
2652       (void) CopyMagickString(colorspace,name,MaxTextExtent);
2653       for (i=0; colorspace[i] != '\0'; i++)
2654         if (colorspace[i] == '(')
2655           break;
2656       colorspace[i--]='\0';
2657       LocaleLower(colorspace);
2658       color->matte=MagickFalse;
2659       if ((i > 0) && (colorspace[i] == 'a'))
2660         {
2661           colorspace[i]='\0';
2662           color->matte=MagickTrue;
2663         }
2664       type=ParseCommandOption(MagickColorspaceOptions,MagickFalse,colorspace);
2665       if (type < 0)
2666         {
2667           (void) ThrowMagickException(exception,GetMagickModule(),
2668             OptionWarning,"UnrecognizedColor","`%s'",name);
2669           return(MagickFalse);
2670         }
2671       color->colorspace=(ColorspaceType) type;
2672       SetGeometryInfo(&geometry_info);
2673       flags=ParseGeometry(name+i+1,&geometry_info);
2674       scale=(MagickRealType) ScaleCharToQuantum(1);
2675       if ((flags & PercentValue) != 0)
2676         scale=(MagickRealType) (QuantumRange/100.0);
2677       if ((flags & RhoValue) != 0)
2678         color->red=(MagickRealType) ClampToQuantum(scale*geometry_info.rho);
2679       if ((flags & SigmaValue) != 0)
2680         color->green=(MagickRealType) ClampToQuantum(scale*geometry_info.sigma);
2681       if ((flags & XiValue) != 0)
2682         color->blue=(MagickRealType) ClampToQuantum(scale*geometry_info.xi);
2683       color->opacity=(MagickRealType) OpaqueOpacity;
2684       if ((flags & PsiValue) != 0)
2685         {
2686           if (color->colorspace == CMYKColorspace)
2687             color->index=(MagickRealType) ClampToQuantum(scale*
2688               geometry_info.psi);
2689           else
2690             if (color->matte != MagickFalse)
2691               color->opacity=(MagickRealType) ClampToQuantum((MagickRealType)
2692                 (QuantumRange-QuantumRange*geometry_info.psi));
2693         }
2694       if (((flags & ChiValue) != 0) && (color->matte != MagickFalse))
2695         color->opacity=(MagickRealType) ClampToQuantum((MagickRealType)
2696           (QuantumRange-QuantumRange*geometry_info.chi));
2697       if (LocaleCompare(colorspace,"gray") == 0)
2698         {
2699           color->green=color->red;
2700           color->blue=color->red;
2701           if (((flags & SigmaValue) != 0) && (color->matte != MagickFalse))
2702             color->opacity=(MagickRealType) ClampToQuantum((MagickRealType)
2703               (QuantumRange-QuantumRange*geometry_info.sigma));
2704         }
2705       if ((LocaleCompare(colorspace,"HSB") == 0) ||
2706           (LocaleCompare(colorspace,"HSL") == 0) ||
2707           (LocaleCompare(colorspace,"HWB") == 0))
2708         {
2709           PixelPacket
2710             pixel;
2711
2712           scale=1.0/360.0;
2713           if ((flags & PercentValue) != 0)
2714             scale=1.0/100.0;
2715           geometry_info.rho*=360.0*scale;
2716           scale=1.0/255.0;
2717           if ((flags & PercentValue) != 0)
2718             scale=1.0/100.0;
2719           geometry_info.sigma*=scale;
2720           geometry_info.xi*=scale;
2721           if (LocaleCompare(colorspace,"HSB") == 0)
2722             ConvertHSBToRGB(fmod(fmod(geometry_info.rho,360.0)+360.0,360.0)/
2723               360.0,geometry_info.sigma,geometry_info.xi,&pixel.red,
2724               &pixel.green,&pixel.blue);
2725           else
2726             if (LocaleCompare(colorspace,"HSL") == 0)
2727               ConvertHSLToRGB(fmod(fmod(geometry_info.rho,360.0)+360.0,360.0)/
2728                 360.0,geometry_info.sigma,geometry_info.xi,&pixel.red,
2729                 &pixel.green,&pixel.blue);
2730             else
2731               ConvertHWBToRGB(fmod(fmod(geometry_info.rho,360.0)+360.0,360.0)/
2732                 360.0,geometry_info.sigma,geometry_info.xi,&pixel.red,
2733                 &pixel.green,&pixel.blue);
2734           color->colorspace=RGBColorspace;
2735           color->red=(MagickRealType) pixel.red;
2736           color->green=(MagickRealType) pixel.green;
2737           color->blue=(MagickRealType) pixel.blue;
2738         }
2739       return(MagickTrue);
2740     }
2741   /*
2742     Parse named color.
2743   */
2744   p=GetColorCompliance(name,compliance,exception);
2745   if (p == (const ColorInfo *) NULL)
2746     return(MagickFalse);
2747   color->colorspace=RGBColorspace;
2748   color->matte=p->color.opacity != OpaqueOpacity ? MagickTrue : MagickFalse;
2749   color->red=(MagickRealType) p->color.red;
2750   color->green=(MagickRealType) p->color.green;
2751   color->blue=(MagickRealType) p->color.blue;
2752   color->opacity=(MagickRealType) p->color.opacity;
2753   color->index=0.0;
2754   return(MagickTrue);
2755 }
2756 \f
2757 /*
2758 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2759 %                                                                             %
2760 %                                                                             %
2761 %                                                                             %
2762 %   Q u e r y M a g i c k C o l o r                                           %
2763 %                                                                             %
2764 %                                                                             %
2765 %                                                                             %
2766 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2767 %
2768 %  QueryMagickColor() returns the red, green, blue, and opacity intensities
2769 %  for a given color name.
2770 %
2771 %  The format of the QueryMagickColor method is:
2772 %
2773 %      MagickBooleanType QueryMagickColor(const char *name,
2774 %        MagickPixelPacket *color,ExceptionInfo *exception)
2775 %
2776 %  A description of each parameter follows:
2777 %
2778 %    o name: the color name (e.g. white, blue, yellow).
2779 %
2780 %    o color: the red, green, blue, and opacity intensities values of the
2781 %      named color in this structure.
2782 %
2783 %    o exception: return any errors or warnings in this structure.
2784 %
2785 */
2786 MagickExport MagickBooleanType QueryMagickColor(const char *name,
2787   MagickPixelPacket *color,ExceptionInfo *exception)
2788 {
2789   return(QueryMagickColorCompliance(name,AllCompliance,color,exception));
2790 }
2791 \f
2792 /*
2793 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2794 %                                                                             %
2795 %                                                                             %
2796 %                                                                             %
2797 %  Q u e r y M a g i c k C o l o r n a m e                                    %
2798 %                                                                             %
2799 %                                                                             %
2800 %                                                                             %
2801 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2802 %
2803 %  QueryMagickColorname() returns a named color for the given color intensity.
2804 %  If an exact match is not found, a hex value is returned instead.  For
2805 %  example an intensity of rgb:(0,0,0) returns black whereas rgb:(223,223,223)
2806 %  returns #dfdfdf.
2807 %
2808 %  The format of the QueryMagickColorname method is:
2809 %
2810 %      MagickBooleanType QueryMagickColorname(const Image *image,
2811 %        const PixelPacket *color,const ComplianceType compliance,char *name,
2812 %        ExceptionInfo *exception)
2813 %
2814 %  A description of each parameter follows.
2815 %
2816 %    o image: the image.
2817 %
2818 %    o color: the color intensities.
2819 %
2820 %    o Compliance: Adhere to this color standard: SVG, X11, or XPM.
2821 %
2822 %    o name: Return the color name or hex value.
2823 %
2824 %    o exception: return any errors or warnings in this structure.
2825 %
2826 */
2827 MagickExport MagickBooleanType QueryMagickColorname(const Image *image,
2828   const MagickPixelPacket *color,const ComplianceType compliance,
2829   char *name,ExceptionInfo *exception)
2830 {
2831   MagickPixelPacket
2832     pixel;
2833
2834   MagickRealType
2835     opacity;
2836
2837   register const ColorInfo
2838     *p;
2839
2840   *name='\0';
2841   pixel=(*color);
2842   if (compliance == XPMCompliance)
2843     {
2844       pixel.matte=MagickFalse;
2845       pixel.depth=(size_t) MagickMin(1.0*image->depth,16.0);
2846     }
2847   GetColorTuple(&pixel,compliance != SVGCompliance ? MagickTrue : MagickFalse,
2848     name);
2849   (void) GetColorInfo("*",exception);
2850   ResetLinkedListIterator(color_list);
2851   opacity=image->matte != MagickFalse ? color->opacity : OpaqueOpacity;
2852   p=(const ColorInfo *) GetNextValueInLinkedList(color_list);
2853   while (p != (const ColorInfo *) NULL)
2854   {
2855     if (((p->compliance & compliance) != 0) && ((p->color.red == color->red)) &&
2856          (p->color.green == color->green) && (p->color.blue == color->blue) &&
2857          (p->color.opacity == opacity))
2858       {
2859         (void) CopyMagickString(name,p->name,MaxTextExtent);
2860         break;
2861       }
2862     p=(const ColorInfo *) GetNextValueInLinkedList(color_list);
2863   }
2864   return(MagickTrue);
2865 }