]> granicus.if.org Git - imagemagick/blobdiff - MagickWand/magick-wand.c
(no commit message)
[imagemagick] / MagickWand / magick-wand.c
index 8033a01f061621bc0bfb372a1c414a431619af33..ea6ed3312a324a2be39037cbf0cc01246fd9ff4d 100644 (file)
@@ -23,7 +23,7 @@
 %                                 August 2003                                 %
 %                                                                             %
 %                                                                             %
-%  Copyright 1999-2012 ImageMagick Studio LLC, a non-profit organization      %
+%  Copyright 1999-2013 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  %
@@ -90,12 +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);
-  if (wand->quantize_info != (QuantizeInfo *) NULL )
-    wand->quantize_info=DestroyQuantizeInfo(wand->quantize_info);
-  if (wand->draw_info != (DrawInfo *) NULL )
-    wand->draw_info=DestroyDrawInfo(wand->draw_info);
   wand->image_info=AcquireImageInfo();
+  wand->insert_before=MagickFalse;
+  wand->image_pending=MagickFalse;
   ClearMagickException(wand->exception);
   wand->debug=IsEventLogging();
 }
@@ -142,15 +141,9 @@ WandExport MagickWand *CloneMagickWand(const MagickWand *wand)
   clone_wand->exception=AcquireExceptionInfo();
   InheritException(clone_wand->exception,wand->exception);
   clone_wand->image_info=CloneImageInfo(wand->image_info);
-  if ( wand->quantize_info == (QuantizeInfo *) NULL )
-    clone_wand->quantize_info=(QuantizeInfo *) NULL;
-  else
-    clone_wand->quantize_info=CloneQuantizeInfo(wand->quantize_info);
-  if ( wand->draw_info == (DrawInfo *) NULL )
-    clone_wand->draw_info=(DrawInfo *) NULL;
-  else
-    clone_wand->draw_info=CloneDrawInfo(wand->image_info,wand->draw_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);
@@ -186,13 +179,11 @@ WandExport MagickWand *DestroyMagickWand(MagickWand *wand)
   assert(wand->signature == WandSignature);
   if (wand->debug != MagickFalse)
     (void) LogMagickEvent(WandEvent,GetMagickModule(),"%s",wand->name);
-  if (wand->quantize_info != (QuantizeInfo *) NULL )
-    wand->quantize_info=DestroyQuantizeInfo(wand->quantize_info);
-  if (wand->draw_info != (DrawInfo *) NULL )
-    wand->draw_info=DestroyDrawInfo(wand->draw_info);
-  wand->image_info=DestroyImageInfo(wand->image_info);
   wand->images=DestroyImageList(wand->images);
-  wand->exception=DestroyExceptionInfo(wand->exception);
+  if (wand->image_info != (ImageInfo *) NULL )
+    wand->image_info=DestroyImageInfo(wand->image_info);
+  if (wand->exception != (ExceptionInfo *) NULL )
+    wand->exception=DestroyExceptionInfo(wand->exception);
   RelinquishWandId(wand->id);
   wand->signature=(~WandSignature);
   wand=(MagickWand *) RelinquishMagickMemory(wand);
@@ -328,7 +319,7 @@ WandExport char *MagickGetException(const MagickWand *wand,
 %                                                                             %
 %                                                                             %
 %                                                                             %
-%   M a g i c k G e t  E x c e p t i o n T y p e                              %
+%   M a g i c k G e t E x c e p t i o n T y p e                               %
 %                                                                             %
 %                                                                             %
 %                                                                             %
@@ -819,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:
 %
@@ -839,8 +838,8 @@ WandExport void MagickResetIterator(MagickWand *wand)
   if (wand->debug != MagickFalse)
     (void) LogMagickEvent(WandEvent,GetMagickModule(),"%s",wand->name);
   wand->images=GetFirstImageInList(wand->images);
-  wand->set_first=MagickFalse;    /* we did not jump to the first image */
-  wand->image_pending=MagickTrue; /* this image is the 'next' image */
+  wand->insert_before=MagickFalse; /* Insert/add after current (first) image */
+  wand->image_pending=MagickTrue;  /* NextImage will set first image */
 }
 \f
 /*
@@ -856,6 +855,17 @@ WandExport void MagickResetIterator(MagickWand *wand)
 %
 %  MagickSetFirstIterator() sets the wand iterator to the first image.
 %
+%  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:
 %
 %      void MagickSetFirstIterator(MagickWand *wand)
@@ -872,8 +882,8 @@ WandExport void MagickSetFirstIterator(MagickWand *wand)
   if (wand->debug != MagickFalse)
     (void) LogMagickEvent(WandEvent,GetMagickModule(),"%s",wand->name);
   wand->images=GetFirstImageInList(wand->images);
-  wand->set_first=MagickTrue;       /* we jumped to the first image */
-  wand->image_pending=MagickFalse;  /* but this image is not 'next' */
+  wand->insert_before=MagickTrue;   /* Insert/add before the first image */
+  wand->image_pending=MagickFalse;  /* NextImage will set next image */
 }
 \f
 /*
@@ -887,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:
 %
@@ -916,14 +941,10 @@ 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->set_first=MagickFalse;     /* we are not at very start of list */
-  wand->image_pending=MagickFalse; /* but it is not iteration pending */
+  wand->insert_before=MagickFalse;  /* Insert/Add after (this) image */
+  wand->image_pending=MagickFalse;  /* NextImage will set next image */
   return(MagickTrue);
 }
 /*
@@ -939,6 +960,15 @@ WandExport MagickBooleanType MagickSetIteratorIndex(MagickWand *wand,
 %
 %  MagickSetLastIterator() sets the wand iterator to the last image.
 %
+%  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:
 %
 %      void MagickSetLastIterator(MagickWand *wand)
@@ -955,8 +985,8 @@ WandExport void MagickSetLastIterator(MagickWand *wand)
   if (wand->debug != MagickFalse)
     (void) LogMagickEvent(WandEvent,GetMagickModule(),"%s",wand->name);
   wand->images=GetLastImageInList(wand->images);
-  wand->set_first=MagickFalse;     /* we are not at very start of list */
-  wand->image_pending=MagickFalse; /* and is not iteration pending  */
+  wand->insert_before=MagickFalse;  /* Insert/add after current (last) image */
+  wand->image_pending=MagickTrue;   /* PreviousImage will return last image */
 }
 \f
 /*
@@ -1053,8 +1083,6 @@ WandExport MagickWand *NewMagickWand(void)
     (double) wand->id);
   wand->images=NewImageList();
   wand->image_info=AcquireImageInfo();
-  wand->quantize_info=(QuantizeInfo *) NULL; /* not used in MagickWand API */
-  wand->draw_info=(DrawInfo *) NULL;         /* not used in MagickWand API */
   wand->exception=AcquireExceptionInfo();
   wand->debug=IsEventLogging();
   if (wand->debug != MagickFalse)