2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6 % M M AAA GGGG IIIII CCCC K K %
7 % MM MM A A G I C K K %
8 % M M M AAAAA G GGG I C KKK %
9 % M M A A G G I C K K %
10 % M M A A GGGG IIIII CCCC K K %
14 % W W W AAAAA N N N D D %
15 % WW WW A A N NN D D %
19 % MagickWand Wand Methods %
26 % Copyright 1999-2012 ImageMagick Studio LLC, a non-profit organization %
27 % dedicated to making software imaging solutions freely available. %
29 % You may not use this file except in compliance with the License. You may %
30 % obtain a copy of the License at %
32 % http://www.imagemagick.org/script/license.php %
34 % Unless required by applicable law or agreed to in writing, software %
35 % distributed under the License is distributed on an "AS IS" BASIS, %
36 % WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. %
37 % See the License for the specific language governing permissions and %
38 % limitations under the License. %
40 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
49 #include "MagickWand/studio.h"
50 #include "MagickWand/MagickWand.h"
51 #include "MagickWand/magick-wand-private.h"
52 #include "MagickWand/wand.h"
57 #define ThrowWandException(severity,tag,context) \
59 (void) ThrowMagickException(wand->exception,GetMagickModule(),severity, \
60 tag,"'%s'",context); \
61 return(MagickFalse); \
65 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
69 % C l e a r M a g i c k W a n d %
73 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
75 % ClearMagickWand() clears resources associated with the wand, leaving the
76 % wand blank, and ready to be used for a new set of images.
78 % The format of the ClearMagickWand method is:
80 % void ClearMagickWand(MagickWand *wand)
82 % A description of each parameter follows:
84 % o wand: the magick wand.
87 WandExport void ClearMagickWand(MagickWand *wand)
89 assert(wand != (MagickWand *) NULL);
90 assert(wand->signature == WandSignature);
91 if (wand->debug != MagickFalse)
92 (void) LogMagickEvent(WandEvent,GetMagickModule(),"%s",wand->name);
93 wand->image_info=DestroyImageInfo(wand->image_info);
94 wand->images=DestroyImageList(wand->images);
95 wand->image_info=AcquireImageInfo();
96 wand->insert_before=MagickFalse;
97 wand->image_pending=MagickFalse;
98 ClearMagickException(wand->exception);
99 wand->debug=IsEventLogging();
103 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
107 % C l o n e M a g i c k W a n d %
111 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
113 % CloneMagickWand() makes an exact copy of the specified wand.
115 % The format of the CloneMagickWand method is:
117 % MagickWand *CloneMagickWand(const MagickWand *wand)
119 % A description of each parameter follows:
121 % o wand: the magick wand.
124 WandExport MagickWand *CloneMagickWand(const MagickWand *wand)
129 assert(wand != (MagickWand *) NULL);
130 assert(wand->signature == WandSignature);
131 if (wand->debug != MagickFalse)
132 (void) LogMagickEvent(WandEvent,GetMagickModule(),"%s",wand->name);
133 clone_wand=(MagickWand *) AcquireMagickMemory(sizeof(*clone_wand));
134 if (clone_wand == (MagickWand *) NULL)
135 ThrowWandFatalException(ResourceLimitFatalError,"MemoryAllocationFailed",
137 (void) ResetMagickMemory(clone_wand,0,sizeof(*clone_wand));
138 clone_wand->id=AcquireWandId();
139 (void) FormatLocaleString(clone_wand->name,MaxTextExtent,"%s-%.20g",
140 MagickWandId,(double) clone_wand->id);
141 clone_wand->exception=AcquireExceptionInfo();
142 InheritException(clone_wand->exception,wand->exception);
143 clone_wand->image_info=CloneImageInfo(wand->image_info);
144 clone_wand->images=CloneImageList(wand->images,clone_wand->exception);
145 clone_wand->insert_before=MagickFalse;
146 clone_wand->image_pending=MagickFalse;
147 clone_wand->debug=IsEventLogging();
148 if (clone_wand->debug != MagickFalse)
149 (void) LogMagickEvent(WandEvent,GetMagickModule(),"%s",clone_wand->name);
150 clone_wand->signature=WandSignature;
155 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
159 % D e s t r o y M a g i c k W a n d %
163 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
165 % DestroyMagickWand() deallocates memory associated with an MagickWand.
167 % The format of the DestroyMagickWand method is:
169 % MagickWand *DestroyMagickWand(MagickWand *wand)
171 % A description of each parameter follows:
173 % o wand: the magick wand.
176 WandExport MagickWand *DestroyMagickWand(MagickWand *wand)
178 assert(wand != (MagickWand *) NULL);
179 assert(wand->signature == WandSignature);
180 if (wand->debug != MagickFalse)
181 (void) LogMagickEvent(WandEvent,GetMagickModule(),"%s",wand->name);
182 wand->images=DestroyImageList(wand->images);
183 if (wand->image_info != (ImageInfo *) NULL )
184 wand->image_info=DestroyImageInfo(wand->image_info);
185 if (wand->exception != (ExceptionInfo *) NULL )
186 wand->exception=DestroyExceptionInfo(wand->exception);
187 RelinquishWandId(wand->id);
188 wand->signature=(~WandSignature);
189 wand=(MagickWand *) RelinquishMagickMemory(wand);
194 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
198 % I s M a g i c k W a n d %
202 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
204 % IsMagickWand() returns MagickTrue if the wand is verified as a magick wand.
206 % The format of the IsMagickWand method is:
208 % MagickBooleanType IsMagickWand(const MagickWand *wand)
210 % A description of each parameter follows:
212 % o wand: the magick wand.
215 WandExport MagickBooleanType IsMagickWand(const MagickWand *wand)
217 if (wand == (const MagickWand *) NULL)
219 if (wand->signature != WandSignature)
221 if (LocaleNCompare(wand->name,MagickWandId,strlen(MagickWandId)) != 0)
227 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
231 % M a g i c k C l e a r E x c e p t i o n %
235 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
237 % MagickClearException() clears any exceptions associated with the wand.
239 % The format of the MagickClearException method is:
241 % MagickBooleanType MagickClearException(MagickWand *wand)
243 % A description of each parameter follows:
245 % o wand: the magick wand.
248 WandExport MagickBooleanType MagickClearException(MagickWand *wand)
250 assert(wand != (MagickWand *) NULL);
251 assert(wand->signature == WandSignature);
252 if (wand->debug != MagickFalse)
253 (void) LogMagickEvent(WandEvent,GetMagickModule(),"%s",wand->name);
254 ClearMagickException(wand->exception);
259 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
263 % M a g i c k G e t E x c e p t i o n %
267 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
269 % MagickGetException() returns the severity, reason, and description of any
270 % error that occurs when using other methods in this API.
272 % The format of the MagickGetException method is:
274 % char *MagickGetException(const MagickWand *wand,ExceptionType *severity)
276 % A description of each parameter follows:
278 % o wand: the magick wand.
280 % o severity: the severity of the error is returned here.
283 WandExport char *MagickGetException(const MagickWand *wand,
284 ExceptionType *severity)
289 assert(wand != (const MagickWand *) NULL);
290 assert(wand->signature == WandSignature);
291 if (wand->debug != MagickFalse)
292 (void) LogMagickEvent(WandEvent,GetMagickModule(),"%s",wand->name);
293 assert(severity != (ExceptionType *) NULL);
294 *severity=wand->exception->severity;
295 description=(char *) AcquireQuantumMemory(2UL*MaxTextExtent,
296 sizeof(*description));
297 if (description == (char *) NULL)
299 (void) ThrowMagickException(wand->exception,GetMagickModule(),WandError,
300 "MemoryAllocationFailed","'%s'",wand->name);
301 return((char *) NULL);
304 if (wand->exception->reason != (char *) NULL)
305 (void) CopyMagickString(description,GetLocaleExceptionMessage(
306 wand->exception->severity,wand->exception->reason),MaxTextExtent);
307 if (wand->exception->description != (char *) NULL)
309 (void) ConcatenateMagickString(description," (",MaxTextExtent);
310 (void) ConcatenateMagickString(description,GetLocaleExceptionMessage(
311 wand->exception->severity,wand->exception->description),MaxTextExtent);
312 (void) ConcatenateMagickString(description,")",MaxTextExtent);
318 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
322 % M a g i c k G e t E x c e p t i o n T y p e %
326 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
328 % MagickGetExceptionType() returns the exception type associated with the
329 % wand. If no exception has occurred, UndefinedExceptionType is returned.
331 % The format of the MagickGetExceptionType method is:
333 % ExceptionType MagickGetExceptionType(const MagickWand *wand)
335 % A description of each parameter follows:
337 % o wand: the magick wand.
340 WandExport ExceptionType MagickGetExceptionType(const MagickWand *wand)
342 assert(wand != (MagickWand *) NULL);
343 assert(wand->signature == WandSignature);
344 if (wand->debug != MagickFalse)
345 (void) LogMagickEvent(WandEvent,GetMagickModule(),"%s",wand->name);
346 return(wand->exception->severity);
350 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
354 % M a g i c k G e t I t e r a t o r I n d e x %
358 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
360 % MagickGetIteratorIndex() returns the position of the iterator in the image
363 % The format of the MagickGetIteratorIndex method is:
365 % ssize_t MagickGetIteratorIndex(MagickWand *wand)
367 % A description of each parameter follows:
369 % o wand: the magick wand.
372 WandExport ssize_t MagickGetIteratorIndex(MagickWand *wand)
374 assert(wand != (MagickWand *) NULL);
375 assert(wand->signature == WandSignature);
376 if (wand->debug != MagickFalse)
377 (void) LogMagickEvent(WandEvent,GetMagickModule(),"%s",wand->name);
378 if (wand->images == (Image *) NULL)
380 (void) ThrowMagickException(wand->exception,GetMagickModule(),WandError,
381 "ContainsNoIterators","'%s'",wand->name);
384 return(GetImageIndexInList(wand->images));
388 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
392 % M a g i c k Q u e r y C o n f i g u r e O p t i o n %
396 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
398 % MagickQueryConfigureOption() returns the value associated with the specified
401 % The format of the MagickQueryConfigureOption function is:
403 % char *MagickQueryConfigureOption(const char *option)
405 % A description of each parameter follows:
407 % o option: the option name.
410 WandExport char *MagickQueryConfigureOption(const char *option)
424 exception=AcquireExceptionInfo();
425 configure_info=GetConfigureInfoList(option,&number_options,exception);
426 exception=DestroyExceptionInfo(exception);
427 if (configure_info == (const ConfigureInfo **) NULL)
428 return((char *) NULL);
429 value=AcquireString(configure_info[0]->value);
430 configure_info=(const ConfigureInfo **)
431 RelinquishMagickMemory((void *) configure_info);
436 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
440 % M a g i c k Q u e r y C o n f i g u r e O p t i o n s %
444 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
446 % MagickQueryConfigureOptions() returns any configure options that match the
447 % specified pattern (e.g. "*" for all). Options include NAME, VERSION,
450 % The format of the MagickQueryConfigureOptions function is:
452 % char **MagickQueryConfigureOptions(const char *pattern,
453 % size_t *number_options)
455 % A description of each parameter follows:
457 % o pattern: Specifies a pointer to a text string containing a pattern.
459 % o number_options: Returns the number of configure options in the list.
463 WandExport char **MagickQueryConfigureOptions(const char *pattern,
464 size_t *number_options)
472 exception=AcquireExceptionInfo();
473 options=GetConfigureList(pattern,number_options,exception);
474 exception=DestroyExceptionInfo(exception);
479 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
483 % M a g i c k Q u e r y F o n t M e t r i c s %
487 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
489 % MagickQueryFontMetrics() returns a 13 element array representing the
490 % following font metrics:
492 % Element Description
493 % -------------------------------------------------
500 % 6 maximum horizontal advance
504 % 10 bounding box: y2
508 % The format of the MagickQueryFontMetrics method is:
510 % double *MagickQueryFontMetrics(MagickWand *wand,
511 % const DrawingWand *drawing_wand,const char *text)
513 % A description of each parameter follows:
515 % o wand: the Magick wand.
517 % o drawing_wand: the drawing wand.
522 WandExport double *MagickQueryFontMetrics(MagickWand *wand,
523 const DrawingWand *drawing_wand,const char *text)
537 assert(wand != (MagickWand *) NULL);
538 assert(wand->signature == WandSignature);
539 if (wand->debug != MagickFalse)
540 (void) LogMagickEvent(WandEvent,GetMagickModule(),"%s",wand->name);
541 assert(drawing_wand != (const DrawingWand *) NULL);
542 if (wand->images == (Image *) NULL)
544 (void) ThrowMagickException(wand->exception,GetMagickModule(),WandError,
545 "ContainsNoImages","'%s'",wand->name);
546 return((double *) NULL);
548 font_metrics=(double *) AcquireQuantumMemory(13UL,sizeof(*font_metrics));
549 if (font_metrics == (double *) NULL)
550 return((double *) NULL);
551 draw_info=PeekDrawingWand(drawing_wand);
552 if (draw_info == (DrawInfo *) NULL)
554 font_metrics=(double *) RelinquishMagickMemory(font_metrics);
555 return((double *) NULL);
557 (void) CloneString(&draw_info->text,text);
558 (void) ResetMagickMemory(&metrics,0,sizeof(metrics));
559 status=GetTypeMetrics(wand->images,draw_info,&metrics,wand->exception);
560 draw_info=DestroyDrawInfo(draw_info);
561 if (status == MagickFalse)
563 font_metrics=(double *) RelinquishMagickMemory(font_metrics);
564 return((double *) NULL);
566 font_metrics[0]=metrics.pixels_per_em.x;
567 font_metrics[1]=metrics.pixels_per_em.y;
568 font_metrics[2]=metrics.ascent;
569 font_metrics[3]=metrics.descent;
570 font_metrics[4]=metrics.width;
571 font_metrics[5]=metrics.height;
572 font_metrics[6]=metrics.max_advance;
573 font_metrics[7]=metrics.bounds.x1;
574 font_metrics[8]=metrics.bounds.y1;
575 font_metrics[9]=metrics.bounds.x2;
576 font_metrics[10]=metrics.bounds.y2;
577 font_metrics[11]=metrics.origin.x;
578 font_metrics[12]=metrics.origin.y;
579 return(font_metrics);
583 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
587 % M a g i c k Q u e r y M u l t i l i n e F o n t M e t r i c s %
591 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
593 % MagickQueryMultilineFontMetrics() returns a 13 element array representing the
594 % following font metrics:
596 % Element Description
597 % -------------------------------------------------
604 % 6 maximum horizontal advance
608 % 10 bounding box: y2
612 % This method is like MagickQueryFontMetrics() but it returns the maximum text
613 % width and height for multiple lines of text.
615 % The format of the MagickQueryFontMetrics method is:
617 % double *MagickQueryMultilineFontMetrics(MagickWand *wand,
618 % const DrawingWand *drawing_wand,const char *text)
620 % A description of each parameter follows:
622 % o wand: the Magick wand.
624 % o drawing_wand: the drawing wand.
629 WandExport double *MagickQueryMultilineFontMetrics(MagickWand *wand,
630 const DrawingWand *drawing_wand,const char *text)
644 assert(wand != (MagickWand *) NULL);
645 assert(wand->signature == WandSignature);
646 if (wand->debug != MagickFalse)
647 (void) LogMagickEvent(WandEvent,GetMagickModule(),"%s",wand->name);
648 assert(drawing_wand != (const DrawingWand *) NULL);
649 if (wand->images == (Image *) NULL)
651 (void) ThrowMagickException(wand->exception,GetMagickModule(),WandError,
652 "ContainsNoImages","'%s'",wand->name);
653 return((double *) NULL);
655 font_metrics=(double *) AcquireQuantumMemory(13UL,sizeof(*font_metrics));
656 if (font_metrics == (double *) NULL)
657 return((double *) NULL);
658 draw_info=PeekDrawingWand(drawing_wand);
659 if (draw_info == (DrawInfo *) NULL)
661 font_metrics=(double *) RelinquishMagickMemory(font_metrics);
662 return((double *) NULL);
664 (void) CloneString(&draw_info->text,text);
665 (void) ResetMagickMemory(&metrics,0,sizeof(metrics));
666 status=GetMultilineTypeMetrics(wand->images,draw_info,&metrics,
668 draw_info=DestroyDrawInfo(draw_info);
669 if (status == MagickFalse)
671 font_metrics=(double *) RelinquishMagickMemory(font_metrics);
672 return((double *) NULL);
674 font_metrics[0]=metrics.pixels_per_em.x;
675 font_metrics[1]=metrics.pixels_per_em.y;
676 font_metrics[2]=metrics.ascent;
677 font_metrics[3]=metrics.descent;
678 font_metrics[4]=metrics.width;
679 font_metrics[5]=metrics.height;
680 font_metrics[6]=metrics.max_advance;
681 font_metrics[7]=metrics.bounds.x1;
682 font_metrics[8]=metrics.bounds.y1;
683 font_metrics[9]=metrics.bounds.x2;
684 font_metrics[10]=metrics.bounds.y2;
685 font_metrics[11]=metrics.origin.x;
686 font_metrics[12]=metrics.origin.y;
687 return(font_metrics);
691 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
695 % M a g i c k Q u e r y F o n t s %
699 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
701 % MagickQueryFonts() returns any font that match the specified pattern (e.g.
704 % The format of the MagickQueryFonts function is:
706 % char **MagickQueryFonts(const char *pattern,size_t *number_fonts)
708 % A description of each parameter follows:
710 % o pattern: Specifies a pointer to a text string containing a pattern.
712 % o number_fonts: Returns the number of fonts in the list.
716 WandExport char **MagickQueryFonts(const char *pattern,
717 size_t *number_fonts)
725 exception=AcquireExceptionInfo();
726 fonts=GetTypeList(pattern,number_fonts,exception);
727 exception=DestroyExceptionInfo(exception);
732 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
736 % M a g i c k Q u e r y F o r m a t s %
740 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
742 % MagickQueryFonts() returns any image formats that match the specified
743 % pattern (e.g. "*" for all).
745 % The format of the MagickQueryFonts function is:
747 % char **MagickQueryFonts(const char *pattern,
748 % size_t *number_formats)
750 % A description of each parameter follows:
752 % o pattern: Specifies a pointer to a text string containing a pattern.
754 % o number_formats: This integer returns the number of image formats in the
758 WandExport char **MagickQueryFormats(const char *pattern,
759 size_t *number_formats)
767 exception=AcquireExceptionInfo();
768 formats=GetMagickList(pattern,number_formats,exception);
769 exception=DestroyExceptionInfo(exception);
774 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
778 % M a g i c k R e l i n q u i s h M e m o r y %
782 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
784 % MagickRelinquishMemory() relinquishes memory resources returned by such
785 % methods as MagickIdentifyImage(), MagickGetException(), etc.
787 % The format of the MagickRelinquishMemory method is:
789 % void *MagickRelinquishMemory(void *resource)
791 % A description of each parameter follows:
793 % o resource: Relinquish the memory associated with this resource.
796 WandExport void *MagickRelinquishMemory(void *memory)
798 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
799 return(RelinquishMagickMemory(memory));
803 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
807 % M a g i c k R e s e t I t e r a t o r %
811 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
813 % MagickResetIterator() resets the wand iterator.
815 % It is typically used either before iterating though images, or before
816 % calling specific functions such as MagickAppendImages() to append all
819 % Afterward you can use MagickNextImage() to iterate over all the images
820 % in a wand container, starting with the first image.
822 % Using this before MagickAddImages() or MagickReadImages() will cause
823 % new images to be inserted between the first and second image.
825 % The format of the MagickResetIterator method is:
827 % void MagickResetIterator(MagickWand *wand)
829 % A description of each parameter follows:
831 % o wand: the magick wand.
834 WandExport void MagickResetIterator(MagickWand *wand)
836 assert(wand != (MagickWand *) NULL);
837 assert(wand->signature == WandSignature);
838 if (wand->debug != MagickFalse)
839 (void) LogMagickEvent(WandEvent,GetMagickModule(),"%s",wand->name);
840 wand->images=GetFirstImageInList(wand->images);
841 wand->insert_before=MagickFalse; /* Insert/add after current (first) image */
842 wand->image_pending=MagickTrue; /* NextImage will set first image */
846 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
850 % M a g i c k S e t F i r s t I t e r a t o r %
854 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
856 % MagickSetFirstIterator() sets the wand iterator to the first image.
858 % After using any images added to the wand using MagickAddImage() or
859 % MagickReadImage() will be prepended before any image in the wand.
861 % Also the current image has been set to the first image (if any) in the
862 % Magick Wand. Using MagickNextImage() will then set teh current image
863 % to the second image in the list (if present).
865 % This operation is similar to MagickResetIterator() but differs in how
866 % MagickAddImage(), MagickReadImage(), and MagickNextImage() behaves
869 % The format of the MagickSetFirstIterator method is:
871 % void MagickSetFirstIterator(MagickWand *wand)
873 % A description of each parameter follows:
875 % o wand: the magick wand.
878 WandExport void MagickSetFirstIterator(MagickWand *wand)
880 assert(wand != (MagickWand *) NULL);
881 assert(wand->signature == WandSignature);
882 if (wand->debug != MagickFalse)
883 (void) LogMagickEvent(WandEvent,GetMagickModule(),"%s",wand->name);
884 wand->images=GetFirstImageInList(wand->images);
885 wand->insert_before=MagickTrue; /* Insert/add before the first image */
886 wand->image_pending=MagickFalse; /* NextImage will set next image */
890 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
894 % M a g i c k S e t I t e r a t o r I n d e x %
898 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
900 % MagickSetIteratorIndex() set the iterator to the given position in the
901 % image list specified with the index parameter. A zero index will set
902 % the first image as current, and so on. Negative indexes can be used
903 % to specify an image relative to the end of the images in the wand, with
904 % -1 being the last image in the wand.
906 % If the index is invalid (range too large for number of images in wand)
907 % the function will return MagickFalse, but no 'exception' will be raised,
908 % as it is not actually an error. In that case the current image will not
911 % After using any images added to the wand using MagickAddImage() or
912 % MagickReadImage() will be added after the image indexed, regardless
913 % of if a zero (first image in list) or negative index (from end) is used.
915 % Jumping to index 0 is similar to MagickResetIterator() but differs in how
916 % MagickNextImage() behaves afterward.
918 % The format of the MagickSetIteratorIndex method is:
920 % MagickBooleanType MagickSetIteratorIndex(MagickWand *wand,
921 % const ssize_t index)
923 % A description of each parameter follows:
925 % o wand: the magick wand.
927 % o index: the scene number.
930 WandExport MagickBooleanType MagickSetIteratorIndex(MagickWand *wand,
936 assert(wand != (MagickWand *) NULL);
937 assert(wand->signature == WandSignature);
938 if (wand->debug != MagickFalse)
939 (void) LogMagickEvent(WandEvent,GetMagickModule(),"%s",wand->name);
940 if (wand->images == (Image *) NULL)
942 image=GetImageFromList(wand->images,index);
943 if (image == (Image *) NULL)
944 return(MagickFalse); /* this is not an exception! Just range error. */
946 wand->insert_before=MagickFalse; /* Insert/Add after (this) image */
947 wand->image_pending=MagickFalse; /* NextImage will set next image */
951 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
955 % M a g i c k S e t L a s t I t e r a t o r %
959 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
961 % MagickSetLastIterator() sets the wand iterator to the last image.
963 % The last image is actually the current image, and the next use of
964 % MagickPreviousImage() will not change this allowing this function to be
965 % used to iterate over the images in the reverse direction. In this sense it
966 % is more like MagickResetIterator() than MagickSetFirstIterator().
968 % Typically this function is used before MagickAddImage(), MagickReadImage()
969 % functions to ensure new images are appended to the very end of wand's image
972 % The format of the MagickSetLastIterator method is:
974 % void MagickSetLastIterator(MagickWand *wand)
976 % A description of each parameter follows:
978 % o wand: the magick wand.
981 WandExport void MagickSetLastIterator(MagickWand *wand)
983 assert(wand != (MagickWand *) NULL);
984 assert(wand->signature == WandSignature);
985 if (wand->debug != MagickFalse)
986 (void) LogMagickEvent(WandEvent,GetMagickModule(),"%s",wand->name);
987 wand->images=GetLastImageInList(wand->images);
988 wand->insert_before=MagickFalse; /* Insert/add after current (last) image */
989 wand->image_pending=MagickTrue; /* PreviousImage will return last image */
993 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
997 % M a g i c k W a n d G e n e s i s %
1001 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1003 % MagickWandGenesis() initializes the MagickWand environment.
1005 % The format of the MagickWandGenesis method is:
1007 % void MagickWandGenesis(void)
1010 WandExport void MagickWandGenesis(void)
1012 if (IsMagickInstantiated() == MagickFalse)
1013 MagickCoreGenesis((char *) NULL,MagickFalse);
1017 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1021 % M a g i c k W a n d T e r m i n u s %
1025 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1027 % MagickWandTerminus() terminates the MagickWand environment.
1029 % The format of the MaickWandTerminus method is:
1031 % void MagickWandTerminus(void)
1034 WandExport void MagickWandTerminus(void)
1037 MagickCoreTerminus();
1041 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1045 % N e w M a g i c k W a n d %
1049 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1051 % NewMagickWand() returns a wand required for all other methods in the API.
1052 % A fatal exception is thrown if there is not enough memory to allocate the
1053 % wand. Use DestroyMagickWand() to dispose of the wand when it is no longer
1056 % The format of the NewMagickWand method is:
1058 % MagickWand *NewMagickWand(void)
1061 WandExport MagickWand *NewMagickWand(void)
1072 depth=MAGICKCORE_QUANTUM_DEPTH;
1073 quantum=GetMagickQuantumDepth(&depth);
1074 if (depth != MAGICKCORE_QUANTUM_DEPTH)
1075 ThrowWandFatalException(WandError,"QuantumDepthMismatch",quantum);
1076 wand=(MagickWand *) AcquireMagickMemory(sizeof(*wand));
1077 if (wand == (MagickWand *) NULL)
1078 ThrowWandFatalException(ResourceLimitFatalError,"MemoryAllocationFailed",
1079 GetExceptionMessage(errno));
1080 (void) ResetMagickMemory(wand,0,sizeof(*wand));
1081 wand->id=AcquireWandId();
1082 (void) FormatLocaleString(wand->name,MaxTextExtent,"%s-%.20g",MagickWandId,
1084 wand->images=NewImageList();
1085 wand->image_info=AcquireImageInfo();
1086 wand->exception=AcquireExceptionInfo();
1087 wand->debug=IsEventLogging();
1088 if (wand->debug != MagickFalse)
1089 (void) LogMagickEvent(WandEvent,GetMagickModule(),"%s",wand->name);
1090 wand->signature=WandSignature;
1095 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1099 % N e w M a g i c k W a n d F r o m I m a g e %
1103 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1105 % NewMagickWandFromImage() returns a wand with an image.
1107 % The format of the NewMagickWandFromImage method is:
1109 % MagickWand *NewMagickWandFromImage(const Image *image)
1111 % A description of each parameter follows:
1113 % o image: the image.
1116 WandExport MagickWand *NewMagickWandFromImage(const Image *image)
1121 wand=NewMagickWand();
1122 wand->images=CloneImage(image,0,0,MagickTrue,wand->exception);