]> granicus.if.org Git - imagemagick/blobdiff - MagickWand/magick-wand.c
(no commit message)
[imagemagick] / MagickWand / magick-wand.c
index 2fd8ce15f26b370f7638e36159cce6dab4810fc3..8b8d7a0d15a6f1645b5626355f756b28d15a06a2 100644 (file)
@@ -57,7 +57,7 @@
 #define ThrowWandException(severity,tag,context) \
 { \
   (void) ThrowMagickException(wand->exception,GetMagickModule(),severity, \
-    tag,"`%s'",context); \
+    tag,"'%s'",context); \
   return(MagickFalse); \
 }
 \f
@@ -90,8 +90,11 @@ WandExport void ClearMagickWand(MagickWand *wand)
   assert(wand->signature == WandSignature);
   if (wand->debug != MagickFalse)
     (void) LogMagickEvent(WandEvent,GetMagickModule(),"%s",wand->name);
+  wand->image_info=DestroyImageInfo(wand->image_info);
   wand->images=DestroyImageList(wand->images);
   wand->image_info=AcquireImageInfo();
+  wand->insert_before=MagickFalse;
+  wand->image_pending=MagickFalse;
   ClearMagickException(wand->exception);
   wand->debug=IsEventLogging();
 }
@@ -139,6 +142,8 @@ WandExport MagickWand *CloneMagickWand(const MagickWand *wand)
   InheritException(clone_wand->exception,wand->exception);
   clone_wand->image_info=CloneImageInfo(wand->image_info);
   clone_wand->images=CloneImageList(wand->images,clone_wand->exception);
+  clone_wand->insert_before=MagickFalse;
+  clone_wand->image_pending=MagickFalse;
   clone_wand->debug=IsEventLogging();
   if (clone_wand->debug != MagickFalse)
     (void) LogMagickEvent(WandEvent,GetMagickModule(),"%s",clone_wand->name);
@@ -292,7 +297,7 @@ WandExport char *MagickGetException(const MagickWand *wand,
   if (description == (char *) NULL)
     {
       (void) ThrowMagickException(wand->exception,GetMagickModule(),WandError,
-        "MemoryAllocationFailed","`%s'",wand->name);
+        "MemoryAllocationFailed","'%s'",wand->name);
       return((char *) NULL);
     }
   *description='\0';
@@ -373,7 +378,7 @@ WandExport ssize_t MagickGetIteratorIndex(MagickWand *wand)
   if (wand->images == (Image *) NULL)
     {
       (void) ThrowMagickException(wand->exception,GetMagickModule(),WandError,
-        "ContainsNoIterators","`%s'",wand->name);
+        "ContainsNoIterators","'%s'",wand->name);
       return(-1);
     }
   return(GetImageIndexInList(wand->images));
@@ -537,7 +542,7 @@ WandExport double *MagickQueryFontMetrics(MagickWand *wand,
   if (wand->images == (Image *) NULL)
     {
       (void) ThrowMagickException(wand->exception,GetMagickModule(),WandError,
-        "ContainsNoImages","`%s'",wand->name);
+        "ContainsNoImages","'%s'",wand->name);
       return((double *) NULL);
     }
   font_metrics=(double *) AcquireQuantumMemory(13UL,sizeof(*font_metrics));
@@ -644,7 +649,7 @@ WandExport double *MagickQueryMultilineFontMetrics(MagickWand *wand,
   if (wand->images == (Image *) NULL)
     {
       (void) ThrowMagickException(wand->exception,GetMagickModule(),WandError,
-        "ContainsNoImages","`%s'",wand->name);
+        "ContainsNoImages","'%s'",wand->name);
       return((double *) NULL);
     }
   font_metrics=(double *) AcquireQuantumMemory(13UL,sizeof(*font_metrics));
@@ -805,9 +810,17 @@ WandExport void *MagickRelinquishMemory(void *memory)
 %                                                                             %
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 %
-%  MagickResetIterator() resets the wand iterator.  Use it in conjunction
-%  with MagickNextImage() to iterate over all the images in a wand
-%  container.
+%  MagickResetIterator() resets the wand iterator.
+%
+%  It is typically used either before iterating though images, or before
+%  calling specific functions such as  MagickAppendImages() to append all
+%  images together.
+%
+%  Afterward you can use MagickNextImage() to iterate over all the images
+%  in a wand container, starting with the first image.
+%
+%  Using this before MagickAddImages() or MagickReadImages() will cause
+%  new images to be inserted between the first and second image.
 %
 %  The format of the MagickResetIterator method is:
 %
@@ -826,7 +839,7 @@ WandExport void MagickResetIterator(MagickWand *wand)
     (void) LogMagickEvent(WandEvent,GetMagickModule(),"%s",wand->name);
   wand->images=GetFirstImageInList(wand->images);
   wand->insert_before=MagickFalse; /* Insert/add after current (first) image */
-  wand->image_pending=MagickTrue;  /* NextImage will remain this image */
+  wand->image_pending=MagickTrue;  /* NextImage will set first image */
 }
 \f
 /*
@@ -842,9 +855,16 @@ WandExport void MagickResetIterator(MagickWand *wand)
 %
 %  MagickSetFirstIterator() sets the wand iterator to the first image.
 %
-%  Flags are set to point not only to the 'next' image to be processed,
-%  but also sets that MagickAddImage() (such as from MagickReadImage())
-%  should add prepend images.
+%  After using any images added to the wand using MagickAddImage() or
+%  MagickReadImage() will be prepended before any image in the wand.
+%
+%  Also the current image has been set to the first image (if any) in the
+%  Magick Wand.  Using MagickNextImage() will then set teh current image
+%  to the second image in the list (if present).
+%
+%  This operation is similar to MagickResetIterator() but differs in how
+%  MagickAddImage(), MagickReadImage(), and MagickNextImage() behaves
+%  afterward.
 %
 %  The format of the MagickSetFirstIterator method is:
 %
@@ -877,8 +897,23 @@ WandExport void MagickSetFirstIterator(MagickWand *wand)
 %                                                                             %
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 %
-%  MagickSetIteratorIndex() set the iterator to the position in the image list
-%  specified with the index parameter.
+%  MagickSetIteratorIndex() set the iterator to the given position in the
+%  image list specified with the index parameter.  A zero index will set
+%  the first image as current, and so on.  Negative indexes can be used
+%  to specify an image relative to the end of the images in the wand, with
+%  -1 being the last image in the wand.
+%
+%  If the index is invalid (range too large for number of images in wand)
+%  the function will return MagickFalse, but no 'exception' will be raised,
+%  as it is not actually an error.  In that case the current image will not
+%  change.
+%
+%  After using any images added to the wand using MagickAddImage() or
+%  MagickReadImage() will be added after the image indexed, regardless
+%  of if a zero (first image in list) or negative index (from end) is used.
+%
+%  Jumping to index 0 is similar to MagickResetIterator() but differs in how
+%  MagickNextImage() behaves afterward.
 %
 %  The format of the MagickSetIteratorIndex method is:
 %
@@ -906,11 +941,7 @@ WandExport MagickBooleanType MagickSetIteratorIndex(MagickWand *wand,
     return(MagickFalse);
   image=GetImageFromList(wand->images,index);
   if (image == (Image *) NULL)
-    {
-      (void) ThrowMagickException(wand->exception,GetMagickModule(),WandError,
-        "NoSuchImage","`%s'",wand->name);
-      return(MagickFalse);
-    }
+    return(MagickFalse);    /* this is not an exception! Just range error. */
   wand->images=image;
   wand->insert_before=MagickFalse;  /* Insert/Add after (this) image */
   wand->image_pending=MagickFalse;  /* NextImage will set next image */
@@ -929,9 +960,14 @@ WandExport MagickBooleanType MagickSetIteratorIndex(MagickWand *wand,
 %
 %  MagickSetLastIterator() sets the wand iterator to the last image.
 %
-%  Flags are set to point not only to the 'previous' image to be processed,
-%  but also define where InsertImageInWand() (such as from MagickReadImage())
-%  should instert new images.
+%  The last image is actually the current image, and the next use of
+%  MagickPreviousImage() will not change this allowing this function to be
+%  used to iterate over the images in the reverse direction. In this sense it
+%  is more like  MagickResetIterator() than MagickSetFirstIterator().
+%
+%  Typically this function is used before MagickAddImage(), MagickReadImage()
+%  functions to ensure new images are appended to the very end of wand's image
+%  list.
 %
 %  The format of the MagickSetLastIterator method is:
 %
@@ -950,7 +986,7 @@ WandExport void MagickSetLastIterator(MagickWand *wand)
     (void) LogMagickEvent(WandEvent,GetMagickModule(),"%s",wand->name);
   wand->images=GetLastImageInList(wand->images);
   wand->insert_before=MagickFalse;  /* Insert/add after current (last) image */
-  wand->image_pending=MagickFalse;  /* PreviousImage will set previous image */
+  wand->image_pending=MagickTrue;   /* PreviousImage will return last image */
 }
 \f
 /*