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->images=DestroyImageList(wand->images);
94 if (wand->quantize_info != (QuantizeInfo *) NULL )
95 wand->quantize_info=DestroyQuantizeInfo(wand->quantize_info);
96 if (wand->draw_info != (DrawInfo *) NULL )
97 wand->draw_info=DestroyDrawInfo(wand->draw_info);
98 wand->image_info=AcquireImageInfo();
99 ClearMagickException(wand->exception);
100 wand->debug=IsEventLogging();
104 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
108 % C l o n e M a g i c k W a n d %
112 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
114 % CloneMagickWand() makes an exact copy of the specified wand.
116 % The format of the CloneMagickWand method is:
118 % MagickWand *CloneMagickWand(const MagickWand *wand)
120 % A description of each parameter follows:
122 % o wand: the magick wand.
125 WandExport MagickWand *CloneMagickWand(const MagickWand *wand)
130 assert(wand != (MagickWand *) NULL);
131 assert(wand->signature == WandSignature);
132 if (wand->debug != MagickFalse)
133 (void) LogMagickEvent(WandEvent,GetMagickModule(),"%s",wand->name);
134 clone_wand=(MagickWand *) AcquireMagickMemory(sizeof(*clone_wand));
135 if (clone_wand == (MagickWand *) NULL)
136 ThrowWandFatalException(ResourceLimitFatalError,"MemoryAllocationFailed",
138 (void) ResetMagickMemory(clone_wand,0,sizeof(*clone_wand));
139 clone_wand->id=AcquireWandId();
140 (void) FormatLocaleString(clone_wand->name,MaxTextExtent,"%s-%.20g",
141 MagickWandId,(double) clone_wand->id);
142 clone_wand->exception=AcquireExceptionInfo();
143 InheritException(clone_wand->exception,wand->exception);
144 clone_wand->image_info=CloneImageInfo(wand->image_info);
145 if ( wand->quantize_info == (QuantizeInfo *) NULL )
146 clone_wand->quantize_info=(QuantizeInfo *) NULL;
148 clone_wand->quantize_info=CloneQuantizeInfo(wand->quantize_info);
149 if ( wand->draw_info == (DrawInfo *) NULL )
150 clone_wand->draw_info=(DrawInfo *) NULL;
152 clone_wand->draw_info=CloneDrawInfo(wand->image_info,wand->draw_info);
153 clone_wand->images=CloneImageList(wand->images,clone_wand->exception);
154 clone_wand->debug=IsEventLogging();
155 if (clone_wand->debug != MagickFalse)
156 (void) LogMagickEvent(WandEvent,GetMagickModule(),"%s",clone_wand->name);
157 clone_wand->signature=WandSignature;
162 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
166 % D e s t r o y M a g i c k W a n d %
170 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
172 % DestroyMagickWand() deallocates memory associated with an MagickWand.
174 % The format of the DestroyMagickWand method is:
176 % MagickWand *DestroyMagickWand(MagickWand *wand)
178 % A description of each parameter follows:
180 % o wand: the magick wand.
183 WandExport MagickWand *DestroyMagickWand(MagickWand *wand)
185 assert(wand != (MagickWand *) NULL);
186 assert(wand->signature == WandSignature);
187 if (wand->debug != MagickFalse)
188 (void) LogMagickEvent(WandEvent,GetMagickModule(),"%s",wand->name);
189 if (wand->quantize_info != (QuantizeInfo *) NULL )
190 wand->quantize_info=DestroyQuantizeInfo(wand->quantize_info);
191 if (wand->draw_info != (DrawInfo *) NULL )
192 wand->draw_info=DestroyDrawInfo(wand->draw_info);
193 wand->image_info=DestroyImageInfo(wand->image_info);
194 wand->images=DestroyImageList(wand->images);
195 wand->exception=DestroyExceptionInfo(wand->exception);
196 RelinquishWandId(wand->id);
197 wand->signature=(~WandSignature);
198 wand=(MagickWand *) RelinquishMagickMemory(wand);
203 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
207 % I s M a g i c k W a n d %
211 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
213 % IsMagickWand() returns MagickTrue if the wand is verified as a magick wand.
215 % The format of the IsMagickWand method is:
217 % MagickBooleanType IsMagickWand(const MagickWand *wand)
219 % A description of each parameter follows:
221 % o wand: the magick wand.
224 WandExport MagickBooleanType IsMagickWand(const MagickWand *wand)
226 if (wand == (const MagickWand *) NULL)
228 if (wand->signature != WandSignature)
230 if (LocaleNCompare(wand->name,MagickWandId,strlen(MagickWandId)) != 0)
236 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
240 % M a g i c k C l e a r E x c e p t i o n %
244 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
246 % MagickClearException() clears any exceptions associated with the wand.
248 % The format of the MagickClearException method is:
250 % MagickBooleanType MagickClearException(MagickWand *wand)
252 % A description of each parameter follows:
254 % o wand: the magick wand.
257 WandExport MagickBooleanType MagickClearException(MagickWand *wand)
259 assert(wand != (MagickWand *) NULL);
260 assert(wand->signature == WandSignature);
261 if (wand->debug != MagickFalse)
262 (void) LogMagickEvent(WandEvent,GetMagickModule(),"%s",wand->name);
263 ClearMagickException(wand->exception);
268 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
272 % M a g i c k G e t E x c e p t i o n %
276 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
278 % MagickGetException() returns the severity, reason, and description of any
279 % error that occurs when using other methods in this API.
281 % The format of the MagickGetException method is:
283 % char *MagickGetException(const MagickWand *wand,ExceptionType *severity)
285 % A description of each parameter follows:
287 % o wand: the magick wand.
289 % o severity: the severity of the error is returned here.
292 WandExport char *MagickGetException(const MagickWand *wand,
293 ExceptionType *severity)
298 assert(wand != (const MagickWand *) NULL);
299 assert(wand->signature == WandSignature);
300 if (wand->debug != MagickFalse)
301 (void) LogMagickEvent(WandEvent,GetMagickModule(),"%s",wand->name);
302 assert(severity != (ExceptionType *) NULL);
303 *severity=wand->exception->severity;
304 description=(char *) AcquireQuantumMemory(2UL*MaxTextExtent,
305 sizeof(*description));
306 if (description == (char *) NULL)
308 (void) ThrowMagickException(wand->exception,GetMagickModule(),WandError,
309 "MemoryAllocationFailed","`%s'",wand->name);
310 return((char *) NULL);
313 if (wand->exception->reason != (char *) NULL)
314 (void) CopyMagickString(description,GetLocaleExceptionMessage(
315 wand->exception->severity,wand->exception->reason),MaxTextExtent);
316 if (wand->exception->description != (char *) NULL)
318 (void) ConcatenateMagickString(description," (",MaxTextExtent);
319 (void) ConcatenateMagickString(description,GetLocaleExceptionMessage(
320 wand->exception->severity,wand->exception->description),MaxTextExtent);
321 (void) ConcatenateMagickString(description,")",MaxTextExtent);
327 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
331 % M a g i c k G e t E x c e p t i o n T y p e %
335 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
337 % MagickGetExceptionType() returns the exception type associated with the
338 % wand. If no exception has occurred, UndefinedExceptionType is returned.
340 % The format of the MagickGetExceptionType method is:
342 % ExceptionType MagickGetExceptionType(const MagickWand *wand)
344 % A description of each parameter follows:
346 % o wand: the magick wand.
349 WandExport ExceptionType MagickGetExceptionType(const MagickWand *wand)
351 assert(wand != (MagickWand *) NULL);
352 assert(wand->signature == WandSignature);
353 if (wand->debug != MagickFalse)
354 (void) LogMagickEvent(WandEvent,GetMagickModule(),"%s",wand->name);
355 return(wand->exception->severity);
359 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
363 % M a g i c k G e t I t e r a t o r I n d e x %
367 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
369 % MagickGetIteratorIndex() returns the position of the iterator in the image
372 % The format of the MagickGetIteratorIndex method is:
374 % ssize_t MagickGetIteratorIndex(MagickWand *wand)
376 % A description of each parameter follows:
378 % o wand: the magick wand.
381 WandExport ssize_t MagickGetIteratorIndex(MagickWand *wand)
383 assert(wand != (MagickWand *) NULL);
384 assert(wand->signature == WandSignature);
385 if (wand->debug != MagickFalse)
386 (void) LogMagickEvent(WandEvent,GetMagickModule(),"%s",wand->name);
387 if (wand->images == (Image *) NULL)
389 (void) ThrowMagickException(wand->exception,GetMagickModule(),WandError,
390 "ContainsNoIterators","`%s'",wand->name);
393 return(GetImageIndexInList(wand->images));
397 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
401 % 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 %
405 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
407 % MagickQueryConfigureOption() returns the value associated with the specified
410 % The format of the MagickQueryConfigureOption function is:
412 % char *MagickQueryConfigureOption(const char *option)
414 % A description of each parameter follows:
416 % o option: the option name.
419 WandExport char *MagickQueryConfigureOption(const char *option)
433 exception=AcquireExceptionInfo();
434 configure_info=GetConfigureInfoList(option,&number_options,exception);
435 exception=DestroyExceptionInfo(exception);
436 if (configure_info == (const ConfigureInfo **) NULL)
437 return((char *) NULL);
438 value=AcquireString(configure_info[0]->value);
439 configure_info=(const ConfigureInfo **)
440 RelinquishMagickMemory((void *) configure_info);
445 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
449 % 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 %
453 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
455 % MagickQueryConfigureOptions() returns any configure options that match the
456 % specified pattern (e.g. "*" for all). Options include NAME, VERSION,
459 % The format of the MagickQueryConfigureOptions function is:
461 % char **MagickQueryConfigureOptions(const char *pattern,
462 % size_t *number_options)
464 % A description of each parameter follows:
466 % o pattern: Specifies a pointer to a text string containing a pattern.
468 % o number_options: Returns the number of configure options in the list.
472 WandExport char **MagickQueryConfigureOptions(const char *pattern,
473 size_t *number_options)
481 exception=AcquireExceptionInfo();
482 options=GetConfigureList(pattern,number_options,exception);
483 exception=DestroyExceptionInfo(exception);
488 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
492 % M a g i c k Q u e r y F o n t M e t r i c s %
496 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
498 % MagickQueryFontMetrics() returns a 13 element array representing the
499 % following font metrics:
501 % Element Description
502 % -------------------------------------------------
509 % 6 maximum horizontal advance
513 % 10 bounding box: y2
517 % The format of the MagickQueryFontMetrics method is:
519 % double *MagickQueryFontMetrics(MagickWand *wand,
520 % const DrawingWand *drawing_wand,const char *text)
522 % A description of each parameter follows:
524 % o wand: the Magick wand.
526 % o drawing_wand: the drawing wand.
531 WandExport double *MagickQueryFontMetrics(MagickWand *wand,
532 const DrawingWand *drawing_wand,const char *text)
546 assert(wand != (MagickWand *) NULL);
547 assert(wand->signature == WandSignature);
548 if (wand->debug != MagickFalse)
549 (void) LogMagickEvent(WandEvent,GetMagickModule(),"%s",wand->name);
550 assert(drawing_wand != (const DrawingWand *) NULL);
551 if (wand->images == (Image *) NULL)
553 (void) ThrowMagickException(wand->exception,GetMagickModule(),WandError,
554 "ContainsNoImages","`%s'",wand->name);
555 return((double *) NULL);
557 font_metrics=(double *) AcquireQuantumMemory(13UL,sizeof(*font_metrics));
558 if (font_metrics == (double *) NULL)
559 return((double *) NULL);
560 draw_info=PeekDrawingWand(drawing_wand);
561 if (draw_info == (DrawInfo *) NULL)
563 font_metrics=(double *) RelinquishMagickMemory(font_metrics);
564 return((double *) NULL);
566 (void) CloneString(&draw_info->text,text);
567 (void) ResetMagickMemory(&metrics,0,sizeof(metrics));
568 status=GetTypeMetrics(wand->images,draw_info,&metrics,wand->exception);
569 draw_info=DestroyDrawInfo(draw_info);
570 if (status == MagickFalse)
572 font_metrics=(double *) RelinquishMagickMemory(font_metrics);
573 return((double *) NULL);
575 font_metrics[0]=metrics.pixels_per_em.x;
576 font_metrics[1]=metrics.pixels_per_em.y;
577 font_metrics[2]=metrics.ascent;
578 font_metrics[3]=metrics.descent;
579 font_metrics[4]=metrics.width;
580 font_metrics[5]=metrics.height;
581 font_metrics[6]=metrics.max_advance;
582 font_metrics[7]=metrics.bounds.x1;
583 font_metrics[8]=metrics.bounds.y1;
584 font_metrics[9]=metrics.bounds.x2;
585 font_metrics[10]=metrics.bounds.y2;
586 font_metrics[11]=metrics.origin.x;
587 font_metrics[12]=metrics.origin.y;
588 return(font_metrics);
592 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
596 % 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 %
600 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
602 % MagickQueryMultilineFontMetrics() returns a 13 element array representing the
603 % following font metrics:
605 % Element Description
606 % -------------------------------------------------
613 % 6 maximum horizontal advance
617 % 10 bounding box: y2
621 % This method is like MagickQueryFontMetrics() but it returns the maximum text
622 % width and height for multiple lines of text.
624 % The format of the MagickQueryFontMetrics method is:
626 % double *MagickQueryMultilineFontMetrics(MagickWand *wand,
627 % const DrawingWand *drawing_wand,const char *text)
629 % A description of each parameter follows:
631 % o wand: the Magick wand.
633 % o drawing_wand: the drawing wand.
638 WandExport double *MagickQueryMultilineFontMetrics(MagickWand *wand,
639 const DrawingWand *drawing_wand,const char *text)
653 assert(wand != (MagickWand *) NULL);
654 assert(wand->signature == WandSignature);
655 if (wand->debug != MagickFalse)
656 (void) LogMagickEvent(WandEvent,GetMagickModule(),"%s",wand->name);
657 assert(drawing_wand != (const DrawingWand *) NULL);
658 if (wand->images == (Image *) NULL)
660 (void) ThrowMagickException(wand->exception,GetMagickModule(),WandError,
661 "ContainsNoImages","`%s'",wand->name);
662 return((double *) NULL);
664 font_metrics=(double *) AcquireQuantumMemory(13UL,sizeof(*font_metrics));
665 if (font_metrics == (double *) NULL)
666 return((double *) NULL);
667 draw_info=PeekDrawingWand(drawing_wand);
668 if (draw_info == (DrawInfo *) NULL)
670 font_metrics=(double *) RelinquishMagickMemory(font_metrics);
671 return((double *) NULL);
673 (void) CloneString(&draw_info->text,text);
674 (void) ResetMagickMemory(&metrics,0,sizeof(metrics));
675 status=GetMultilineTypeMetrics(wand->images,draw_info,&metrics,
677 draw_info=DestroyDrawInfo(draw_info);
678 if (status == MagickFalse)
680 font_metrics=(double *) RelinquishMagickMemory(font_metrics);
681 return((double *) NULL);
683 font_metrics[0]=metrics.pixels_per_em.x;
684 font_metrics[1]=metrics.pixels_per_em.y;
685 font_metrics[2]=metrics.ascent;
686 font_metrics[3]=metrics.descent;
687 font_metrics[4]=metrics.width;
688 font_metrics[5]=metrics.height;
689 font_metrics[6]=metrics.max_advance;
690 font_metrics[7]=metrics.bounds.x1;
691 font_metrics[8]=metrics.bounds.y1;
692 font_metrics[9]=metrics.bounds.x2;
693 font_metrics[10]=metrics.bounds.y2;
694 font_metrics[11]=metrics.origin.x;
695 font_metrics[12]=metrics.origin.y;
696 return(font_metrics);
700 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
704 % M a g i c k Q u e r y F o n t s %
708 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
710 % MagickQueryFonts() returns any font that match the specified pattern (e.g.
713 % The format of the MagickQueryFonts function is:
715 % char **MagickQueryFonts(const char *pattern,size_t *number_fonts)
717 % A description of each parameter follows:
719 % o pattern: Specifies a pointer to a text string containing a pattern.
721 % o number_fonts: Returns the number of fonts in the list.
725 WandExport char **MagickQueryFonts(const char *pattern,
726 size_t *number_fonts)
734 exception=AcquireExceptionInfo();
735 fonts=GetTypeList(pattern,number_fonts,exception);
736 exception=DestroyExceptionInfo(exception);
741 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
745 % M a g i c k Q u e r y F o r m a t s %
749 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
751 % MagickQueryFonts() returns any image formats that match the specified
752 % pattern (e.g. "*" for all).
754 % The format of the MagickQueryFonts function is:
756 % char **MagickQueryFonts(const char *pattern,
757 % size_t *number_formats)
759 % A description of each parameter follows:
761 % o pattern: Specifies a pointer to a text string containing a pattern.
763 % o number_formats: This integer returns the number of image formats in the
767 WandExport char **MagickQueryFormats(const char *pattern,
768 size_t *number_formats)
776 exception=AcquireExceptionInfo();
777 formats=GetMagickList(pattern,number_formats,exception);
778 exception=DestroyExceptionInfo(exception);
783 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
787 % M a g i c k R e l i n q u i s h M e m o r y %
791 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
793 % MagickRelinquishMemory() relinquishes memory resources returned by such
794 % methods as MagickIdentifyImage(), MagickGetException(), etc.
796 % The format of the MagickRelinquishMemory method is:
798 % void *MagickRelinquishMemory(void *resource)
800 % A description of each parameter follows:
802 % o resource: Relinquish the memory associated with this resource.
805 WandExport void *MagickRelinquishMemory(void *memory)
807 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
808 return(RelinquishMagickMemory(memory));
812 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
816 % M a g i c k R e s e t I t e r a t o r %
820 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
822 % MagickResetIterator() resets the wand iterator. Use it in conjunction
823 % with MagickNextImage() to iterate over all the images in a wand
826 % The format of the MagickResetIterator method is:
828 % void MagickResetIterator(MagickWand *wand)
830 % A description of each parameter follows:
832 % o wand: the magick wand.
835 WandExport void MagickResetIterator(MagickWand *wand)
837 assert(wand != (MagickWand *) NULL);
838 assert(wand->signature == WandSignature);
839 if (wand->debug != MagickFalse)
840 (void) LogMagickEvent(WandEvent,GetMagickModule(),"%s",wand->name);
841 wand->images=GetFirstImageInList(wand->images);
842 wand->set_first=MagickFalse; /* we did not jump to the first image */
843 wand->image_pending=MagickTrue; /* this image is the 'next' image */
847 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
851 % M a g i c k S e t F i r s t I t e r a t o r %
855 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
857 % MagickSetFirstIterator() sets the wand iterator to the first image.
859 % The format of the MagickSetFirstIterator method is:
861 % void MagickSetFirstIterator(MagickWand *wand)
863 % A description of each parameter follows:
865 % o wand: the magick wand.
868 WandExport void MagickSetFirstIterator(MagickWand *wand)
870 assert(wand != (MagickWand *) NULL);
871 assert(wand->signature == WandSignature);
872 if (wand->debug != MagickFalse)
873 (void) LogMagickEvent(WandEvent,GetMagickModule(),"%s",wand->name);
874 wand->images=GetFirstImageInList(wand->images);
875 wand->set_first=MagickTrue; /* we jumped to the first image */
876 wand->image_pending=MagickFalse; /* but this image is not 'next' */
880 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
884 % M a g i c k S e t I t e r a t o r I n d e x %
888 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
890 % MagickSetIteratorIndex() set the iterator to the position in the image list
891 % specified with the index parameter.
893 % The format of the MagickSetIteratorIndex method is:
895 % MagickBooleanType MagickSetIteratorIndex(MagickWand *wand,
896 % const ssize_t index)
898 % A description of each parameter follows:
900 % o wand: the magick wand.
902 % o index: the scene number.
905 WandExport MagickBooleanType MagickSetIteratorIndex(MagickWand *wand,
911 assert(wand != (MagickWand *) NULL);
912 assert(wand->signature == WandSignature);
913 if (wand->debug != MagickFalse)
914 (void) LogMagickEvent(WandEvent,GetMagickModule(),"%s",wand->name);
915 if (wand->images == (Image *) NULL)
917 image=GetImageFromList(wand->images,index);
918 if (image == (Image *) NULL)
920 (void) ThrowMagickException(wand->exception,GetMagickModule(),WandError,
921 "NoSuchImage","`%s'",wand->name);
925 wand->set_first=MagickFalse; /* we are not at very start of list */
926 wand->image_pending=MagickFalse; /* but it is not iteration pending */
930 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
934 % M a g i c k S e t L a s t I t e r a t o r %
938 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
940 % MagickSetLastIterator() sets the wand iterator to the last image.
942 % The format of the MagickSetLastIterator method is:
944 % void MagickSetLastIterator(MagickWand *wand)
946 % A description of each parameter follows:
948 % o wand: the magick wand.
951 WandExport void MagickSetLastIterator(MagickWand *wand)
953 assert(wand != (MagickWand *) NULL);
954 assert(wand->signature == WandSignature);
955 if (wand->debug != MagickFalse)
956 (void) LogMagickEvent(WandEvent,GetMagickModule(),"%s",wand->name);
957 wand->images=GetLastImageInList(wand->images);
958 wand->set_first=MagickFalse; /* we are not at very start of list */
959 wand->image_pending=MagickFalse; /* and is not iteration pending */
963 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
967 % M a g i c k W a n d G e n e s i s %
971 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
973 % MagickWandGenesis() initializes the MagickWand environment.
975 % The format of the MagickWandGenesis method is:
977 % void MagickWandGenesis(void)
980 WandExport void MagickWandGenesis(void)
982 if (IsMagickInstantiated() == MagickFalse)
983 MagickCoreGenesis((char *) NULL,MagickFalse);
987 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
991 % M a g i c k W a n d T e r m i n u s %
995 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
997 % MagickWandTerminus() terminates the MagickWand environment.
999 % The format of the MaickWandTerminus method is:
1001 % void MagickWandTerminus(void)
1004 WandExport void MagickWandTerminus(void)
1007 MagickCoreTerminus();
1011 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1015 % N e w M a g i c k W a n d %
1019 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1021 % NewMagickWand() returns a wand required for all other methods in the API.
1022 % A fatal exception is thrown if there is not enough memory to allocate the
1023 % wand. Use DestroyMagickWand() to dispose of the wand when it is no longer
1026 % The format of the NewMagickWand method is:
1028 % MagickWand *NewMagickWand(void)
1031 WandExport MagickWand *NewMagickWand(void)
1042 depth=MAGICKCORE_QUANTUM_DEPTH;
1043 quantum=GetMagickQuantumDepth(&depth);
1044 if (depth != MAGICKCORE_QUANTUM_DEPTH)
1045 ThrowWandFatalException(WandError,"QuantumDepthMismatch",quantum);
1046 wand=(MagickWand *) AcquireMagickMemory(sizeof(*wand));
1047 if (wand == (MagickWand *) NULL)
1048 ThrowWandFatalException(ResourceLimitFatalError,"MemoryAllocationFailed",
1049 GetExceptionMessage(errno));
1050 (void) ResetMagickMemory(wand,0,sizeof(*wand));
1051 wand->id=AcquireWandId();
1052 (void) FormatLocaleString(wand->name,MaxTextExtent,"%s-%.20g",MagickWandId,
1054 wand->images=NewImageList();
1055 wand->image_info=AcquireImageInfo();
1056 wand->quantize_info=(QuantizeInfo *) NULL; /* not used in MagickWand API */
1057 wand->draw_info=(DrawInfo *) NULL; /* not used in MagickWand API */
1058 wand->exception=AcquireExceptionInfo();
1059 wand->debug=IsEventLogging();
1060 if (wand->debug != MagickFalse)
1061 (void) LogMagickEvent(WandEvent,GetMagickModule(),"%s",wand->name);
1062 wand->signature=WandSignature;
1067 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1071 % N e w M a g i c k W a n d F r o m I m a g e %
1075 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1077 % NewMagickWandFromImage() returns a wand with an image.
1079 % The format of the NewMagickWandFromImage method is:
1081 % MagickWand *NewMagickWandFromImage(const Image *image)
1083 % A description of each parameter follows:
1085 % o image: the image.
1088 WandExport MagickWand *NewMagickWandFromImage(const Image *image)
1093 wand=NewMagickWand();
1094 wand->images=CloneImage(image,0,0,MagickTrue,wand->exception);