2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6 % AAA RRRR TTTTT IIIII FFFFF AAA CCCC TTTTT %
7 % A A R R T I F A A C T %
8 % AAAAA RRRRR T I FFF AAAAA C T %
9 % A A R R T I F A A C T %
10 % A A R R T IIIII F A A CCCCC T %
13 % MagickCore Artifact Methods %
20 % Copyright 1999-2010 ImageMagick Studio LLC, a non-profit organization %
21 % dedicated to making software imaging solutions freely available. %
23 % You may not use this file except in compliance with the License. You may %
24 % obtain a copy of the License at %
26 % http://www.imagemagick.org/script/license.php %
28 % Unless required by applicable law or agreed to in writing, software %
29 % distributed under the License is distributed on an "AS IS" BASIS, %
30 % WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. %
31 % See the License for the specific language governing permissions and %
32 % limitations under the License. %
34 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
43 #include "magick/studio.h"
44 #include "magick/artifact.h"
45 #include "magick/cache.h"
46 #include "magick/color.h"
47 #include "magick/compare.h"
48 #include "magick/constitute.h"
49 #include "magick/draw.h"
50 #include "magick/effect.h"
51 #include "magick/exception.h"
52 #include "magick/exception-private.h"
53 #include "magick/fx.h"
54 #include "magick/fx-private.h"
55 #include "magick/gem.h"
56 #include "magick/geometry.h"
57 #include "magick/image.h"
58 #include "magick/layer.h"
59 #include "magick/list.h"
60 #include "magick/memory_.h"
61 #include "magick/monitor.h"
62 #include "magick/montage.h"
63 #include "magick/option.h"
64 #include "magick/profile.h"
65 #include "magick/quantum.h"
66 #include "magick/resource_.h"
67 #include "magick/splay-tree.h"
68 #include "magick/signature-private.h"
69 #include "magick/statistic.h"
70 #include "magick/string_.h"
71 #include "magick/token.h"
72 #include "magick/utility.h"
73 #include "magick/xml-tree.h"
76 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
80 % C l o n e I m a g e A r t i f a c t s %
84 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
86 % CloneImageArtifacts() clones one or more image artifacts.
88 % The format of the CloneImageArtifacts method is:
90 % MagickBooleanType CloneImageArtifacts(Image *image,
91 % const Image *clone_image)
93 % A description of each parameter follows:
97 % o clone_image: the clone image.
100 MagickExport MagickBooleanType CloneImageArtifacts(Image *image,
101 const Image *clone_image)
103 assert(image != (Image *) NULL);
104 assert(image->signature == MagickSignature);
105 if (image->debug != MagickFalse)
106 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
107 assert(clone_image != (const Image *) NULL);
108 assert(clone_image->signature == MagickSignature);
109 if (clone_image->debug != MagickFalse)
110 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
111 clone_image->filename);
112 if (clone_image->artifacts != (void *) NULL)
113 image->artifacts=CloneSplayTree((SplayTreeInfo *) clone_image->artifacts,
114 (void *(*)(void *)) ConstantString,(void *(*)(void *)) ConstantString);
119 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
123 % D e f i n e I m a g e A r t i f a c t %
127 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
129 % DefineImageArtifact() associates a key/value pair with an image artifact.
131 % The format of the DefineImageArtifact method is:
133 % MagickBooleanType DefineImageArtifact(Image *image,
134 % const char *artifact)
136 % A description of each parameter follows:
138 % o image: the image.
140 % o artifact: the image artifact.
143 MagickExport MagickBooleanType DefineImageArtifact(Image *image,
144 const char *artifact)
148 value[MaxTextExtent];
153 assert(image != (Image *) NULL);
154 assert(artifact != (const char *) NULL);
155 (void) CopyMagickString(key,artifact,MaxTextExtent-1);
156 for (p=key; *p != '\0'; p++)
161 (void) CopyMagickString(value,p+1,MaxTextExtent);
163 return(SetImageArtifact(image,key,value));
167 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
171 % D e l e t e I m a g e A r t i f a c t %
175 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
177 % DeleteImageArtifact() deletes an image artifact.
179 % The format of the DeleteImageArtifact method is:
181 % MagickBooleanType DeleteImageArtifact(Image *image,const char *artifact)
183 % A description of each parameter follows:
185 % o image: the image.
187 % o artifact: the image artifact.
190 MagickExport MagickBooleanType DeleteImageArtifact(Image *image,
191 const char *artifact)
193 assert(image != (Image *) NULL);
194 assert(image->signature == MagickSignature);
195 if (image->debug != MagickFalse)
196 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
198 if (image->artifacts == (void *) NULL)
200 return(DeleteNodeFromSplayTree((SplayTreeInfo *) image->artifacts,artifact));
204 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
208 % D e s t r o y I m a g e A r t i f a c t s %
212 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
214 % DestroyImageArtifacts() releases memory associated with image artifact
217 % The format of the DestroyDefines method is:
219 % void DestroyImageArtifacts(Image *image)
221 % A description of each parameter follows:
223 % o image: the image.
226 MagickExport void DestroyImageArtifacts(Image *image)
228 assert(image != (Image *) NULL);
229 assert(image->signature == MagickSignature);
230 if (image->debug != MagickFalse)
231 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
233 if (image->artifacts != (void *) NULL)
234 image->artifacts=(void *) DestroySplayTree((SplayTreeInfo *)
239 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
243 % G e t I m a g e A r t i f a c t %
247 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
249 % GetImageArtifact() gets a value associated with an image artifact.
251 % The format of the GetImageArtifact method is:
253 % const char *GetImageArtifact(const Image *image,const char *key)
255 % A description of each parameter follows:
257 % o image: the image.
262 MagickExport const char *GetImageArtifact(const Image *image,
263 const char *artifact)
268 assert(image != (Image *) NULL);
269 assert(image->signature == MagickSignature);
270 if (image->debug != MagickFalse)
271 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
272 p=(const char *) NULL;
273 if (artifact == (const char *) NULL)
275 ResetSplayTreeIterator((SplayTreeInfo *) image->artifacts);
276 p=(const char *) GetNextValueInSplayTree((SplayTreeInfo *)
280 if (image->artifacts != (void *) NULL)
282 p=(const char *) GetValueFromSplayTree((SplayTreeInfo *)
283 image->artifacts,artifact);
284 if (p != (const char *) NULL)
291 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
295 % G e t N e x t I m a g e A r t i f a c t %
299 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
301 % GetNextImageArtifact() gets the next image artifact value.
303 % The format of the GetNextImageArtifact method is:
305 % char *GetNextImageArtifact(const Image *image)
307 % A description of each parameter follows:
309 % o image: the image.
312 MagickExport char *GetNextImageArtifact(const Image *image)
314 assert(image != (Image *) NULL);
315 assert(image->signature == MagickSignature);
316 if (image->debug != MagickFalse)
317 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
319 if (image->artifacts == (void *) NULL)
320 return((char *) NULL);
321 return((char *) GetNextKeyInSplayTree((SplayTreeInfo *) image->artifacts));
325 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
329 % R e m o v e I m a g e A r t i f a c t %
333 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
335 % RemoveImageArtifact() removes an artifact from the image and returns its
338 % The format of the RemoveImageArtifact method is:
340 % char *RemoveImageArtifact(Image *image,const char *artifact)
342 % A description of each parameter follows:
344 % o image: the image.
346 % o artifact: the image artifact.
349 MagickExport char *RemoveImageArtifact(Image *image,const char *artifact)
354 assert(image != (Image *) NULL);
355 assert(image->signature == MagickSignature);
356 if (image->debug != MagickFalse)
357 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
359 if (image->artifacts == (void *) NULL)
360 return((char *) NULL);
361 value=(char *) RemoveNodeFromSplayTree((SplayTreeInfo *) image->artifacts,
367 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
371 % R e s e t I m a g e A r t i f a c t I t e r a t o r %
375 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
377 % ResetImageArtifactIterator() resets the image artifact iterator. Use it
378 % in conjunction with GetNextImageArtifact() to iterate over all the values
379 % associated with an image artifact.
381 % The format of the ResetImageArtifactIterator method is:
383 % ResetImageArtifactIterator(Image *image)
385 % A description of each parameter follows:
387 % o image: the image.
390 MagickExport void ResetImageArtifactIterator(const Image *image)
392 assert(image != (Image *) NULL);
393 assert(image->signature == MagickSignature);
394 if (image->debug != MagickFalse)
395 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
397 if (image->artifacts == (void *) NULL)
399 ResetSplayTreeIterator((SplayTreeInfo *) image->artifacts);
403 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
407 % S e t I m a g e A r t i f a c t %
411 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
413 % SetImageArtifact() associates a value with an image artifact.
415 % The format of the SetImageArtifact method is:
417 % MagickBooleanType SetImageArtifact(Image *image,const char *artifact,
420 % A description of each parameter follows:
422 % o image: the image.
424 % o artifact: the image artifact.
426 % o values: the image artifact values.
429 MagickExport MagickBooleanType SetImageArtifact(Image *image,
430 const char *artifact,const char *value)
435 assert(image != (Image *) NULL);
436 assert(image->signature == MagickSignature);
437 if (image->debug != MagickFalse)
438 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
440 if (image->artifacts == (void *) NULL)
441 image->artifacts=NewSplayTree(CompareSplayTreeString,
442 RelinquishMagickMemory,RelinquishMagickMemory);
443 if ((value == (const char *) NULL) || (*value == '\0'))
444 return(DeleteImageArtifact(image,artifact));
445 status=AddValueToSplayTree((SplayTreeInfo *) image->artifacts,
446 ConstantString(artifact),ConstantString(value));