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