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