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-2012 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.
250 % If the requested artifact is NULL return the first artifact.
252 % Note, returned string is a constant in the tree and should NOT be freed.
254 % The format of the GetImageArtifact method is:
256 % const char *GetImageArtifact(const Image *image,const char *key)
258 % A description of each parameter follows:
260 % o image: the image.
265 MagickExport const char *GetImageArtifact(const Image *image,
266 const char *artifact)
271 assert(image != (Image *) NULL);
272 assert(image->signature == MagickSignature);
273 if (image->debug != MagickFalse)
274 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
275 p=(const char *) NULL;
276 if (artifact == (const char *) NULL)
278 ResetSplayTreeIterator((SplayTreeInfo *) image->artifacts);
279 p=(const char *) GetNextValueInSplayTree((SplayTreeInfo *)
283 if (image->artifacts != (void *) NULL)
285 p=(const char *) GetValueFromSplayTree((SplayTreeInfo *)
286 image->artifacts,artifact);
287 if (p != (const char *) NULL)
294 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
298 % G e t N e x t I m a g e A r t i f a c t %
302 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
304 % GetNextImageArtifact() gets the next image artifact value.
306 % The format of the GetNextImageArtifact method is:
308 % char *GetNextImageArtifact(const Image *image)
310 % A description of each parameter follows:
312 % o image: the image.
315 MagickExport char *GetNextImageArtifact(const Image *image)
317 assert(image != (Image *) NULL);
318 assert(image->signature == MagickSignature);
319 if (image->debug != MagickFalse)
320 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
322 if (image->artifacts == (void *) NULL)
323 return((char *) NULL);
324 return((char *) GetNextKeyInSplayTree((SplayTreeInfo *) image->artifacts));
328 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
332 % R e m o v e I m a g e A r t i f a c t %
336 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
338 % RemoveImageArtifact() removes an artifact from the image and returns its
341 % The format of the RemoveImageArtifact method is:
343 % char *RemoveImageArtifact(Image *image,const char *artifact)
345 % A description of each parameter follows:
347 % o image: the image.
349 % o artifact: the image artifact.
352 MagickExport char *RemoveImageArtifact(Image *image,const char *artifact)
357 assert(image != (Image *) NULL);
358 assert(image->signature == MagickSignature);
359 if (image->debug != MagickFalse)
360 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
362 if (image->artifacts == (void *) NULL)
363 return((char *) NULL);
364 value=(char *) RemoveNodeFromSplayTree((SplayTreeInfo *) image->artifacts,
370 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
374 % 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 %
378 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
380 % ResetImageArtifactIterator() resets the image artifact iterator. Use it
381 % in conjunction with GetNextImageArtifact() to iterate over all the values
382 % associated with an image artifact.
384 % The format of the ResetImageArtifactIterator method is:
386 % ResetImageArtifactIterator(Image *image)
388 % A description of each parameter follows:
390 % o image: the image.
393 MagickExport void ResetImageArtifactIterator(const Image *image)
395 assert(image != (Image *) NULL);
396 assert(image->signature == MagickSignature);
397 if (image->debug != MagickFalse)
398 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
400 if (image->artifacts == (void *) NULL)
402 ResetSplayTreeIterator((SplayTreeInfo *) image->artifacts);
406 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
410 % S e t I m a g e A r t i f a c t %
414 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
416 % SetImageArtifact() associates a value with an image artifact.
418 % The format of the SetImageArtifact method is:
420 % MagickBooleanType SetImageArtifact(Image *image,const char *artifact,
423 % A description of each parameter follows:
425 % o image: the image.
427 % o artifact: the image artifact.
429 % o values: the image artifact values.
432 MagickExport MagickBooleanType SetImageArtifact(Image *image,
433 const char *artifact,const char *value)
438 assert(image != (Image *) NULL);
439 assert(image->signature == MagickSignature);
440 if (image->debug != MagickFalse)
441 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
444 /* Create tree if needed */
445 if (image->artifacts == (void *) NULL)
446 image->artifacts=NewSplayTree(CompareSplayTreeString,
447 RelinquishMagickMemory,RelinquishMagickMemory);
449 /* Delete artifact if NULL -- empty string values are valid! */
450 if (value == (const char *) NULL)
451 return(DeleteImageArtifact(image,artifact));
453 /* add artifact to splay-tree */
454 status=AddValueToSplayTree((SplayTreeInfo *) image->artifacts,
455 ConstantString(artifact),ConstantString(value));