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-2011 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 "MagickCore/studio.h"
44 #include "MagickCore/artifact.h"
45 #include "MagickCore/cache.h"
46 #include "MagickCore/color.h"
47 #include "MagickCore/compare.h"
48 #include "MagickCore/constitute.h"
49 #include "MagickCore/draw.h"
50 #include "MagickCore/effect.h"
51 #include "MagickCore/exception.h"
52 #include "MagickCore/exception-private.h"
53 #include "MagickCore/fx.h"
54 #include "MagickCore/fx-private.h"
55 #include "MagickCore/gem.h"
56 #include "MagickCore/geometry.h"
57 #include "MagickCore/image.h"
58 #include "MagickCore/layer.h"
59 #include "MagickCore/list.h"
60 #include "MagickCore/memory_.h"
61 #include "MagickCore/monitor.h"
62 #include "MagickCore/montage.h"
63 #include "MagickCore/option.h"
64 #include "MagickCore/profile.h"
65 #include "MagickCore/quantum.h"
66 #include "MagickCore/resource_.h"
67 #include "MagickCore/splay-tree.h"
68 #include "MagickCore/signature-private.h"
69 #include "MagickCore/statistic.h"
70 #include "MagickCore/string_.h"
71 #include "MagickCore/token.h"
72 #include "MagickCore/utility.h"
73 #include "MagickCore/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 % Note, the artifact is a constant. Do not attempt to free it.
253 % The format of the GetImageArtifact method is:
255 % const char *GetImageArtifact(const Image *image,const char *key)
257 % A description of each parameter follows:
259 % o image: the image.
264 MagickExport const char *GetImageArtifact(const Image *image,
265 const char *artifact)
270 assert(image != (Image *) NULL);
271 assert(image->signature == MagickSignature);
272 if (image->debug != MagickFalse)
273 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
274 p=(const char *) NULL;
275 if (artifact == (const char *) NULL)
277 ResetSplayTreeIterator((SplayTreeInfo *) image->artifacts);
278 p=(const char *) GetNextValueInSplayTree((SplayTreeInfo *)
282 if (image->artifacts != (void *) NULL)
284 p=(const char *) GetValueFromSplayTree((SplayTreeInfo *)
285 image->artifacts,artifact);
286 if (p != (const char *) NULL)
293 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
297 % G e t N e x t I m a g e A r t i f a c t %
301 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
303 % GetNextImageArtifact() gets the next image artifact value.
305 % The format of the GetNextImageArtifact method is:
307 % char *GetNextImageArtifact(const Image *image)
309 % A description of each parameter follows:
311 % o image: the image.
314 MagickExport char *GetNextImageArtifact(const Image *image)
316 assert(image != (Image *) NULL);
317 assert(image->signature == MagickSignature);
318 if (image->debug != MagickFalse)
319 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
321 if (image->artifacts == (void *) NULL)
322 return((char *) NULL);
323 return((char *) GetNextKeyInSplayTree((SplayTreeInfo *) image->artifacts));
327 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
331 % R e m o v e I m a g e A r t i f a c t %
335 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
337 % RemoveImageArtifact() removes an artifact from the image and returns its
340 % The format of the RemoveImageArtifact method is:
342 % char *RemoveImageArtifact(Image *image,const char *artifact)
344 % A description of each parameter follows:
346 % o image: the image.
348 % o artifact: the image artifact.
351 MagickExport char *RemoveImageArtifact(Image *image,const char *artifact)
356 assert(image != (Image *) NULL);
357 assert(image->signature == MagickSignature);
358 if (image->debug != MagickFalse)
359 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
361 if (image->artifacts == (void *) NULL)
362 return((char *) NULL);
363 value=(char *) RemoveNodeFromSplayTree((SplayTreeInfo *) image->artifacts,
369 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
373 % 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 %
377 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
379 % ResetImageArtifactIterator() resets the image artifact iterator. Use it
380 % in conjunction with GetNextImageArtifact() to iterate over all the values
381 % associated with an image artifact.
383 % The format of the ResetImageArtifactIterator method is:
385 % ResetImageArtifactIterator(Image *image)
387 % A description of each parameter follows:
389 % o image: the image.
392 MagickExport void ResetImageArtifactIterator(const Image *image)
394 assert(image != (Image *) NULL);
395 assert(image->signature == MagickSignature);
396 if (image->debug != MagickFalse)
397 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
399 if (image->artifacts == (void *) NULL)
401 ResetSplayTreeIterator((SplayTreeInfo *) image->artifacts);
405 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
409 % S e t I m a g e A r t i f a c t %
413 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
415 % SetImageArtifact() associates a value with an image artifact.
417 % The format of the SetImageArtifact method is:
419 % MagickBooleanType SetImageArtifact(Image *image,const char *artifact,
422 % A description of each parameter follows:
424 % o image: the image.
426 % o artifact: the image artifact.
428 % o values: the image artifact values.
431 MagickExport MagickBooleanType SetImageArtifact(Image *image,
432 const char *artifact,const char *value)
437 assert(image != (Image *) NULL);
438 assert(image->signature == MagickSignature);
439 if (image->debug != MagickFalse)
440 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
443 /* Create tree if needed */
444 if (image->artifacts == (void *) NULL)
445 image->artifacts=NewSplayTree(CompareSplayTreeString,
446 RelinquishMagickMemory,RelinquishMagickMemory);
447 /* Delete artifact if NULL or empty */
448 if ((value == (const char *) NULL) || (*value == '\0'))
449 return(DeleteImageArtifact(image,artifact));
450 /* add option to tree */
451 status=AddValueToSplayTree((SplayTreeInfo *) image->artifacts,
452 ConstantString(artifact),ConstantString(value));