]> granicus.if.org Git - imagemagick/blobdiff - MagickCore/artifact.c
(no commit message)
[imagemagick] / MagickCore / artifact.c
index 9693c7fac27af1c194a8a7af2ca5dfed44f251e0..b51c7114702ed3403e0ddedfe57f8471dc839b33 100644 (file)
 %                         MagickCore Artifact Methods                         %
 %                                                                             %
 %                              Software Design                                %
-%                                John Cristy                                  %
+%                                   Cristy                                    %
 %                                 March 2000                                  %
 %                                                                             %
 %                                                                             %
-%  Copyright 1999-2011 ImageMagick Studio LLC, a non-profit organization      %
+%  Copyright 1999-2014 ImageMagick Studio LLC, a non-profit organization      %
 %  dedicated to making software imaging solutions freely available.           %
 %                                                                             %
 %  You may not use this file except in compliance with the License.  You may  %
@@ -83,7 +83,9 @@
 %                                                                             %
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 %
-%  CloneImageArtifacts() clones one or more image artifacts.
+%  CloneImageArtifacts() clones all image artifacts to another image.
+%
+%  This will not delete any existing artifacts that may be present!
 %
 %  The format of the CloneImageArtifacts method is:
 %
@@ -92,9 +94,9 @@
 %
 %  A description of each parameter follows:
 %
-%    o image: the image.
+%    o image: the image, to recieve the cloned artifacts.
 %
-%    o clone_image: the clone image.
+%    o clone_image: the source image for artifacts to clone.
 %
 */
 MagickExport MagickBooleanType CloneImageArtifacts(Image *image,
@@ -110,8 +112,12 @@ MagickExport MagickBooleanType CloneImageArtifacts(Image *image,
     (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
       clone_image->filename);
   if (clone_image->artifacts != (void *) NULL)
-    image->artifacts=CloneSplayTree((SplayTreeInfo *) clone_image->artifacts,
-      (void *(*)(void *)) ConstantString,(void *(*)(void *)) ConstantString);
+    {
+      if (image->artifacts != (void *) NULL)
+        DestroyImageArtifacts(image);
+      image->artifacts=CloneSplayTree((SplayTreeInfo *) clone_image->artifacts,
+        (void *(*)(void *)) ConstantString,(void *(*)(void *)) ConstantString);
+    }
   return(MagickTrue);
 }
 \f
@@ -126,7 +132,9 @@ MagickExport MagickBooleanType CloneImageArtifacts(Image *image,
 %                                                                             %
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 %
-%  DefineImageArtifact() associates a key/value pair with an image artifact.
+%  DefineImageArtifact() associates an assignment string of the form
+%  "key=value" with per-image artifact. It is equivelent to
+%  SetImageArtifact().
 %
 %  The format of the DefineImageArtifact method is:
 %
@@ -193,8 +201,7 @@ MagickExport MagickBooleanType DeleteImageArtifact(Image *image,
   assert(image != (Image *) NULL);
   assert(image->signature == MagickSignature);
   if (image->debug != MagickFalse)
-    (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
-      image->filename);
+    (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
   if (image->artifacts == (void *) NULL)
     return(MagickFalse);
   return(DeleteNodeFromSplayTree((SplayTreeInfo *) image->artifacts,artifact));
@@ -211,10 +218,10 @@ MagickExport MagickBooleanType DeleteImageArtifact(Image *image,
 %                                                                             %
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 %
-%  DestroyImageArtifacts() releases memory associated with image artifact
-%  values.
+%  DestroyImageArtifacts() destroys all artifacts and associated memory
+%  attached to the given image.
 %
-%  The format of the DestroyDefines method is:
+%  The format of the DestroyImageArtifacts method is:
 %
 %      void DestroyImageArtifacts(Image *image)
 %
@@ -228,8 +235,7 @@ MagickExport void DestroyImageArtifacts(Image *image)
   assert(image != (Image *) NULL);
   assert(image->signature == MagickSignature);
   if (image->debug != MagickFalse)
-    (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
-      image->filename);
+    (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
   if (image->artifacts != (void *) NULL)
     image->artifacts=(void *) DestroySplayTree((SplayTreeInfo *)
       image->artifacts);
@@ -247,8 +253,11 @@ MagickExport void DestroyImageArtifacts(Image *image)
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 %
 %  GetImageArtifact() gets a value associated with an image artifact.
+%  If the requested artifact is NULL return the first artifact, to
+%  prepare to iterate over all artifacts.
 %
-%  Note, the artifact is a constant.  Do not attempt to free it.
+%  The returned string is a constant string in the tree and should NOT be
+%  freed by the caller.
 %
 %  The format of the GetImageArtifact method is:
 %
@@ -281,11 +290,15 @@ MagickExport const char *GetImageArtifact(const Image *image,
     }
   if (image->artifacts != (void *) NULL)
     {
-      p=(const char *) GetValueFromSplayTree((SplayTreeInfo *)
-        image->artifacts,artifact);
+      p=(const char *) GetValueFromSplayTree((SplayTreeInfo *) image->artifacts,
+        artifact);
       if (p != (const char *) NULL)
         return(p);
     }
+  if ((image->image_info != (ImageInfo *) NULL) &&
+      (image->image_info->options != (void *) NULL))
+    p=(const char *) GetValueFromSplayTree((SplayTreeInfo *)
+      image->image_info->options,artifact);
   return(p);
 }
 \f
@@ -316,8 +329,7 @@ MagickExport char *GetNextImageArtifact(const Image *image)
   assert(image != (Image *) NULL);
   assert(image->signature == MagickSignature);
   if (image->debug != MagickFalse)
-    (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
-      image->filename);
+    (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
   if (image->artifacts == (void *) NULL)
     return((char *) NULL);
   return((char *) GetNextKeyInSplayTree((SplayTreeInfo *) image->artifacts));
@@ -337,6 +349,9 @@ MagickExport char *GetNextImageArtifact(const Image *image)
 %  RemoveImageArtifact() removes an artifact from the image and returns its
 %  value.
 %
+%  In this case the ConstantString() value returned should be freed by the
+%  caller when finished.
+%
 %  The format of the RemoveImageArtifact method is:
 %
 %      char *RemoveImageArtifact(Image *image,const char *artifact)
@@ -356,8 +371,7 @@ MagickExport char *RemoveImageArtifact(Image *image,const char *artifact)
   assert(image != (Image *) NULL);
   assert(image->signature == MagickSignature);
   if (image->debug != MagickFalse)
-    (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
-      image->filename);
+    (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
   if (image->artifacts == (void *) NULL)
     return((char *) NULL);
   value=(char *) RemoveNodeFromSplayTree((SplayTreeInfo *) image->artifacts,
@@ -380,6 +394,9 @@ MagickExport char *RemoveImageArtifact(Image *image,const char *artifact)
 %  in conjunction with GetNextImageArtifact() to iterate over all the values
 %  associated with an image artifact.
 %
+%  Alternatively you can use GetImageArtifact() with a NULL artifact field to
+%  reset the iterator and return the first artifact.
+%
 %  The format of the ResetImageArtifactIterator method is:
 %
 %      ResetImageArtifactIterator(Image *image)
@@ -394,8 +411,7 @@ MagickExport void ResetImageArtifactIterator(const Image *image)
   assert(image != (Image *) NULL);
   assert(image->signature == MagickSignature);
   if (image->debug != MagickFalse)
-    (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
-      image->filename);
+    (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
   if (image->artifacts == (void *) NULL)
     return;
   ResetSplayTreeIterator((SplayTreeInfo *) image->artifacts);
@@ -412,7 +428,8 @@ MagickExport void ResetImageArtifactIterator(const Image *image)
 %                                                                             %
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 %
-%  SetImageArtifact() associates a value with an image artifact.
+%  SetImageArtifact() associates makes a copy of the given string arguments
+%  and inserts it into the artifact tree of the given image.
 %
 %  The format of the SetImageArtifact method is:
 %
@@ -423,9 +440,9 @@ MagickExport void ResetImageArtifactIterator(const Image *image)
 %
 %    o image: the image.
 %
-%    o artifact: the image artifact.
+%    o artifact: the image artifact key.
 %
-%    o values: the image artifact values.
+%    o value: the image artifact value.
 %
 */
 MagickExport MagickBooleanType SetImageArtifact(Image *image,
@@ -437,13 +454,21 @@ MagickExport MagickBooleanType SetImageArtifact(Image *image,
   assert(image != (Image *) NULL);
   assert(image->signature == MagickSignature);
   if (image->debug != MagickFalse)
-    (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
-      image->filename);
+    (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
+  /*
+    Create tree if needed - specify how key,values are to be freed.
+  */
   if (image->artifacts == (void *) NULL)
-    image->artifacts=NewSplayTree(CompareSplayTreeString,
-      RelinquishMagickMemory,RelinquishMagickMemory);
-  if ((value == (const char *) NULL) || (*value == '\0'))
+    image->artifacts=NewSplayTree(CompareSplayTreeString,RelinquishMagickMemory,
+      RelinquishMagickMemory);
+  /*
+    Delete artifact if NULL --  empty string values are valid!,
+  */
+  if (value == (const char *) NULL)
     return(DeleteImageArtifact(image,artifact));
+  /*
+    Add artifact to splay-tree.
+  */
   status=AddValueToSplayTree((SplayTreeInfo *) image->artifacts,
     ConstantString(artifact),ConstantString(value));
   return(status);