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