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-2017 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"
55 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
59 % C l e a r M a g i c k W a n d %
63 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
65 % ClearMagickWand() clears resources associated with the wand, leaving the
66 % wand blank, and ready to be used for a new set of images.
68 % The format of the ClearMagickWand method is:
70 % void ClearMagickWand(MagickWand *wand)
72 % A description of each parameter follows:
74 % o wand: the magick wand.
77 WandExport void ClearMagickWand(MagickWand *wand)
79 assert(wand != (MagickWand *) NULL);
80 assert(wand->signature == MagickWandSignature);
81 if (wand->debug != MagickFalse)
82 (void) LogMagickEvent(WandEvent,GetMagickModule(),"%s",wand->name);
83 wand->image_info=DestroyImageInfo(wand->image_info);
84 wand->images=DestroyImageList(wand->images);
85 wand->image_info=AcquireImageInfo();
86 wand->insert_before=MagickFalse;
87 wand->image_pending=MagickFalse;
88 ClearMagickException(wand->exception);
89 wand->debug=IsEventLogging();
93 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
97 % C l o n e M a g i c k W a n d %
101 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
103 % CloneMagickWand() makes an exact copy of the specified wand.
105 % The format of the CloneMagickWand method is:
107 % MagickWand *CloneMagickWand(const MagickWand *wand)
109 % A description of each parameter follows:
111 % o wand: the magick wand.
114 WandExport MagickWand *CloneMagickWand(const MagickWand *wand)
119 assert(wand != (MagickWand *) NULL);
120 assert(wand->signature == MagickWandSignature);
121 if (wand->debug != MagickFalse)
122 (void) LogMagickEvent(WandEvent,GetMagickModule(),"%s",wand->name);
123 clone_wand=(MagickWand *) AcquireMagickMemory(sizeof(*clone_wand));
124 if (clone_wand == (MagickWand *) NULL)
125 ThrowWandFatalException(ResourceLimitFatalError,"MemoryAllocationFailed",
127 (void) ResetMagickMemory(clone_wand,0,sizeof(*clone_wand));
128 clone_wand->id=AcquireWandId();
129 (void) FormatLocaleString(clone_wand->name,MagickPathExtent,"%s-%.20g",
130 MagickWandId,(double) clone_wand->id);
131 clone_wand->exception=AcquireExceptionInfo();
132 InheritException(clone_wand->exception,wand->exception);
133 clone_wand->image_info=CloneImageInfo(wand->image_info);
134 clone_wand->images=CloneImageList(wand->images,clone_wand->exception);
135 clone_wand->insert_before=MagickFalse;
136 clone_wand->image_pending=MagickFalse;
137 clone_wand->debug=IsEventLogging();
138 if (clone_wand->debug != MagickFalse)
139 (void) LogMagickEvent(WandEvent,GetMagickModule(),"%s",clone_wand->name);
140 clone_wand->signature=MagickWandSignature;
145 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
149 % D e s t r o y M a g i c k W a n d %
153 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
155 % DestroyMagickWand() deallocates memory associated with an MagickWand.
157 % The format of the DestroyMagickWand method is:
159 % MagickWand *DestroyMagickWand(MagickWand *wand)
161 % A description of each parameter follows:
163 % o wand: the magick wand.
166 WandExport MagickWand *DestroyMagickWand(MagickWand *wand)
168 assert(wand != (MagickWand *) NULL);
169 assert(wand->signature == MagickWandSignature);
170 if (wand->debug != MagickFalse)
171 (void) LogMagickEvent(WandEvent,GetMagickModule(),"%s",wand->name);
172 wand->images=DestroyImageList(wand->images);
173 if (wand->image_info != (ImageInfo *) NULL )
174 wand->image_info=DestroyImageInfo(wand->image_info);
175 if (wand->exception != (ExceptionInfo *) NULL )
176 wand->exception=DestroyExceptionInfo(wand->exception);
177 RelinquishWandId(wand->id);
178 wand->signature=(~MagickWandSignature);
179 wand=(MagickWand *) RelinquishMagickMemory(wand);
184 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
188 % I s M a g i c k W a n d %
192 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
194 % IsMagickWand() returns MagickTrue if the wand is verified as a magick wand.
196 % The format of the IsMagickWand method is:
198 % MagickBooleanType IsMagickWand(const MagickWand *wand)
200 % A description of each parameter follows:
202 % o wand: the magick wand.
205 WandExport MagickBooleanType IsMagickWand(const MagickWand *wand)
207 if (wand == (const MagickWand *) NULL)
209 if (wand->signature != MagickWandSignature)
211 if (LocaleNCompare(wand->name,MagickWandId,strlen(MagickWandId)) != 0)
217 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
221 % M a g i c k C l e a r E x c e p t i o n %
225 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
227 % MagickClearException() clears any exceptions associated with the wand.
229 % The format of the MagickClearException method is:
231 % MagickBooleanType MagickClearException(MagickWand *wand)
233 % A description of each parameter follows:
235 % o wand: the magick wand.
238 WandExport MagickBooleanType MagickClearException(MagickWand *wand)
240 assert(wand != (MagickWand *) NULL);
241 assert(wand->signature == MagickWandSignature);
242 if (wand->debug != MagickFalse)
243 (void) LogMagickEvent(WandEvent,GetMagickModule(),"%s",wand->name);
244 ClearMagickException(wand->exception);
249 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
253 % M a g i c k G e t E x c e p t i o n %
257 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
259 % MagickGetException() returns the severity, reason, and description of any
260 % error that occurs when using other methods in this API.
262 % The format of the MagickGetException method is:
264 % char *MagickGetException(const MagickWand *wand,ExceptionType *severity)
266 % A description of each parameter follows:
268 % o wand: the magick wand.
270 % o severity: the severity of the error is returned here.
273 WandExport char *MagickGetException(const MagickWand *wand,
274 ExceptionType *severity)
279 assert(wand != (const MagickWand *) NULL);
280 assert(wand->signature == MagickWandSignature);
281 if (wand->debug != MagickFalse)
282 (void) LogMagickEvent(WandEvent,GetMagickModule(),"%s",wand->name);
283 assert(severity != (ExceptionType *) NULL);
284 *severity=wand->exception->severity;
285 description=(char *) AcquireQuantumMemory(2UL*MagickPathExtent,
286 sizeof(*description));
287 if (description == (char *) NULL)
289 (void) ThrowMagickException(wand->exception,GetMagickModule(),WandError,
290 "MemoryAllocationFailed","`%s'",wand->name);
291 return((char *) NULL);
294 if (wand->exception->reason != (char *) NULL)
295 (void) CopyMagickString(description,GetLocaleExceptionMessage(
296 wand->exception->severity,wand->exception->reason),MagickPathExtent);
297 if (wand->exception->description != (char *) NULL)
299 (void) ConcatenateMagickString(description," (",MagickPathExtent);
300 (void) ConcatenateMagickString(description,GetLocaleExceptionMessage(
301 wand->exception->severity,wand->exception->description),MagickPathExtent);
302 (void) ConcatenateMagickString(description,")",MagickPathExtent);
308 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
312 % M a g i c k G e t E x c e p t i o n T y p e %
316 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
318 % MagickGetExceptionType() returns the exception type associated with the
319 % wand. If no exception has occurred, UndefinedExceptionType is returned.
321 % The format of the MagickGetExceptionType method is:
323 % ExceptionType MagickGetExceptionType(const MagickWand *wand)
325 % A description of each parameter follows:
327 % o wand: the magick wand.
330 WandExport ExceptionType MagickGetExceptionType(const MagickWand *wand)
332 assert(wand != (MagickWand *) NULL);
333 assert(wand->signature == MagickWandSignature);
334 if (wand->debug != MagickFalse)
335 (void) LogMagickEvent(WandEvent,GetMagickModule(),"%s",wand->name);
336 return(wand->exception->severity);
340 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
344 % M a g i c k G e t I t e r a t o r I n d e x %
348 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
350 % MagickGetIteratorIndex() returns the position of the iterator in the image
353 % The format of the MagickGetIteratorIndex method is:
355 % ssize_t MagickGetIteratorIndex(MagickWand *wand)
357 % A description of each parameter follows:
359 % o wand: the magick wand.
362 WandExport ssize_t MagickGetIteratorIndex(MagickWand *wand)
364 assert(wand != (MagickWand *) NULL);
365 assert(wand->signature == MagickWandSignature);
366 if (wand->debug != MagickFalse)
367 (void) LogMagickEvent(WandEvent,GetMagickModule(),"%s",wand->name);
368 if (wand->images == (Image *) NULL)
370 (void) ThrowMagickException(wand->exception,GetMagickModule(),WandError,
371 "ContainsNoIterators","`%s'",wand->name);
374 return(GetImageIndexInList(wand->images));
378 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
382 % 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 %
386 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
388 % MagickQueryConfigureOption() returns the value associated with the specified
391 % The format of the MagickQueryConfigureOption function is:
393 % char *MagickQueryConfigureOption(const char *option)
395 % A description of each parameter follows:
397 % o option: the option name.
400 WandExport char *MagickQueryConfigureOption(const char *option)
414 exception=AcquireExceptionInfo();
415 configure_info=GetConfigureInfoList(option,&number_options,exception);
416 exception=DestroyExceptionInfo(exception);
417 if (configure_info == (const ConfigureInfo **) NULL)
418 return((char *) NULL);
419 value=AcquireString(configure_info[0]->value);
420 configure_info=(const ConfigureInfo **)
421 RelinquishMagickMemory((void *) configure_info);
426 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
430 % 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 %
434 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
436 % MagickQueryConfigureOptions() returns any configure options that match the
437 % specified pattern (e.g. "*" for all). Options include NAME, VERSION,
440 % The format of the MagickQueryConfigureOptions function is:
442 % char **MagickQueryConfigureOptions(const char *pattern,
443 % size_t *number_options)
445 % A description of each parameter follows:
447 % o pattern: Specifies a pointer to a text string containing a pattern.
449 % o number_options: Returns the number of configure options in the list.
453 WandExport char **MagickQueryConfigureOptions(const char *pattern,
454 size_t *number_options)
462 exception=AcquireExceptionInfo();
463 options=GetConfigureList(pattern,number_options,exception);
464 exception=DestroyExceptionInfo(exception);
469 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
473 % M a g i c k Q u e r y F o n t M e t r i c s %
477 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
479 % MagickQueryFontMetrics() returns a 13 element array representing the
480 % following font metrics:
482 % Element Description
483 % -------------------------------------------------
490 % 6 maximum horizontal advance
494 % 10 bounding box: y2
498 % The format of the MagickQueryFontMetrics method is:
500 % double *MagickQueryFontMetrics(MagickWand *wand,
501 % const DrawingWand *drawing_wand,const char *text)
503 % A description of each parameter follows:
505 % o wand: the Magick wand.
507 % o drawing_wand: the drawing wand.
512 WandExport double *MagickQueryFontMetrics(MagickWand *wand,
513 const DrawingWand *drawing_wand,const char *text)
527 assert(wand != (MagickWand *) NULL);
528 assert(wand->signature == MagickWandSignature);
529 if (wand->debug != MagickFalse)
530 (void) LogMagickEvent(WandEvent,GetMagickModule(),"%s",wand->name);
531 assert(drawing_wand != (const DrawingWand *) NULL);
532 if (wand->images == (Image *) NULL)
534 (void) ThrowMagickException(wand->exception,GetMagickModule(),WandError,
535 "ContainsNoImages","`%s'",wand->name);
536 return((double *) NULL);
538 font_metrics=(double *) AcquireQuantumMemory(13UL,sizeof(*font_metrics));
539 if (font_metrics == (double *) NULL)
540 return((double *) NULL);
541 draw_info=PeekDrawingWand(drawing_wand);
542 if (draw_info == (DrawInfo *) NULL)
544 font_metrics=(double *) RelinquishMagickMemory(font_metrics);
545 return((double *) NULL);
547 (void) CloneString(&draw_info->text,text);
548 (void) ResetMagickMemory(&metrics,0,sizeof(metrics));
549 status=GetTypeMetrics(wand->images,draw_info,&metrics,wand->exception);
550 draw_info=DestroyDrawInfo(draw_info);
551 if (status == MagickFalse)
553 font_metrics=(double *) RelinquishMagickMemory(font_metrics);
554 return((double *) NULL);
556 font_metrics[0]=metrics.pixels_per_em.x;
557 font_metrics[1]=metrics.pixels_per_em.y;
558 font_metrics[2]=metrics.ascent;
559 font_metrics[3]=metrics.descent;
560 font_metrics[4]=metrics.width;
561 font_metrics[5]=metrics.height;
562 font_metrics[6]=metrics.max_advance;
563 font_metrics[7]=metrics.bounds.x1;
564 font_metrics[8]=metrics.bounds.y1;
565 font_metrics[9]=metrics.bounds.x2;
566 font_metrics[10]=metrics.bounds.y2;
567 font_metrics[11]=metrics.origin.x;
568 font_metrics[12]=metrics.origin.y;
569 return(font_metrics);
573 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
577 % 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 %
581 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
583 % MagickQueryMultilineFontMetrics() returns a 13 element array representing the
584 % following font metrics:
586 % Element Description
587 % -------------------------------------------------
594 % 6 maximum horizontal advance
598 % 10 bounding box: y2
602 % This method is like MagickQueryFontMetrics() but it returns the maximum text
603 % width and height for multiple lines of text.
605 % The format of the MagickQueryFontMetrics method is:
607 % double *MagickQueryMultilineFontMetrics(MagickWand *wand,
608 % const DrawingWand *drawing_wand,const char *text)
610 % A description of each parameter follows:
612 % o wand: the Magick wand.
614 % o drawing_wand: the drawing wand.
619 WandExport double *MagickQueryMultilineFontMetrics(MagickWand *wand,
620 const DrawingWand *drawing_wand,const char *text)
634 assert(wand != (MagickWand *) NULL);
635 assert(wand->signature == MagickWandSignature);
636 if (wand->debug != MagickFalse)
637 (void) LogMagickEvent(WandEvent,GetMagickModule(),"%s",wand->name);
638 assert(drawing_wand != (const DrawingWand *) NULL);
639 if (wand->images == (Image *) NULL)
641 (void) ThrowMagickException(wand->exception,GetMagickModule(),WandError,
642 "ContainsNoImages","`%s'",wand->name);
643 return((double *) NULL);
645 font_metrics=(double *) AcquireQuantumMemory(13UL,sizeof(*font_metrics));
646 if (font_metrics == (double *) NULL)
647 return((double *) NULL);
648 draw_info=PeekDrawingWand(drawing_wand);
649 if (draw_info == (DrawInfo *) NULL)
651 font_metrics=(double *) RelinquishMagickMemory(font_metrics);
652 return((double *) NULL);
654 (void) CloneString(&draw_info->text,text);
655 (void) ResetMagickMemory(&metrics,0,sizeof(metrics));
656 status=GetMultilineTypeMetrics(wand->images,draw_info,&metrics,
658 draw_info=DestroyDrawInfo(draw_info);
659 if (status == MagickFalse)
661 font_metrics=(double *) RelinquishMagickMemory(font_metrics);
662 return((double *) NULL);
664 font_metrics[0]=metrics.pixels_per_em.x;
665 font_metrics[1]=metrics.pixels_per_em.y;
666 font_metrics[2]=metrics.ascent;
667 font_metrics[3]=metrics.descent;
668 font_metrics[4]=metrics.width;
669 font_metrics[5]=metrics.height;
670 font_metrics[6]=metrics.max_advance;
671 font_metrics[7]=metrics.bounds.x1;
672 font_metrics[8]=metrics.bounds.y1;
673 font_metrics[9]=metrics.bounds.x2;
674 font_metrics[10]=metrics.bounds.y2;
675 font_metrics[11]=metrics.origin.x;
676 font_metrics[12]=metrics.origin.y;
677 return(font_metrics);
681 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
685 % M a g i c k Q u e r y F o n t s %
689 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
691 % MagickQueryFonts() returns any font that match the specified pattern (e.g.
694 % The format of the MagickQueryFonts function is:
696 % char **MagickQueryFonts(const char *pattern,size_t *number_fonts)
698 % A description of each parameter follows:
700 % o pattern: Specifies a pointer to a text string containing a pattern.
702 % o number_fonts: Returns the number of fonts in the list.
706 WandExport char **MagickQueryFonts(const char *pattern,
707 size_t *number_fonts)
715 exception=AcquireExceptionInfo();
716 fonts=GetTypeList(pattern,number_fonts,exception);
717 exception=DestroyExceptionInfo(exception);
722 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
726 % M a g i c k Q u e r y F o r m a t s %
730 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
732 % MagickQueryFormats() returns any image formats that match the specified
733 % pattern (e.g. "*" for all).
735 % The format of the MagickQueryFormats function is:
737 % char **MagickQueryFormats(const char *pattern,size_t *number_formats)
739 % A description of each parameter follows:
741 % o pattern: Specifies a pointer to a text string containing a pattern.
743 % o number_formats: This integer returns the number of image formats in the
747 WandExport char **MagickQueryFormats(const char *pattern,
748 size_t *number_formats)
756 exception=AcquireExceptionInfo();
757 formats=GetMagickList(pattern,number_formats,exception);
758 exception=DestroyExceptionInfo(exception);
763 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
767 % M a g i c k R e l i n q u i s h M e m o r y %
771 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
773 % MagickRelinquishMemory() relinquishes memory resources returned by such
774 % methods as MagickIdentifyImage(), MagickGetException(), etc.
776 % The format of the MagickRelinquishMemory method is:
778 % void *MagickRelinquishMemory(void *resource)
780 % A description of each parameter follows:
782 % o resource: Relinquish the memory associated with this resource.
785 WandExport void *MagickRelinquishMemory(void *memory)
787 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
788 return(RelinquishMagickMemory(memory));
792 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
796 % M a g i c k R e s e t I t e r a t o r %
800 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
802 % MagickResetIterator() resets the wand iterator.
804 % It is typically used either before iterating though images, or before
805 % calling specific functions such as MagickAppendImages() to append all
808 % Afterward you can use MagickNextImage() to iterate over all the images
809 % in a wand container, starting with the first image.
811 % Using this before MagickAddImages() or MagickReadImages() will cause
812 % new images to be inserted between the first and second image.
814 % The format of the MagickResetIterator method is:
816 % void MagickResetIterator(MagickWand *wand)
818 % A description of each parameter follows:
820 % o wand: the magick wand.
823 WandExport void MagickResetIterator(MagickWand *wand)
825 assert(wand != (MagickWand *) NULL);
826 assert(wand->signature == MagickWandSignature);
827 if (wand->debug != MagickFalse)
828 (void) LogMagickEvent(WandEvent,GetMagickModule(),"%s",wand->name);
829 wand->images=GetFirstImageInList(wand->images);
830 wand->insert_before=MagickFalse; /* Insert/add after current (first) image */
831 wand->image_pending=MagickTrue; /* NextImage will set first image */
835 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
839 % M a g i c k S e t F i r s t I t e r a t o r %
843 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
845 % MagickSetFirstIterator() sets the wand iterator to the first image.
847 % After using any images added to the wand using MagickAddImage() or
848 % MagickReadImage() will be prepended before any image in the wand.
850 % Also the current image has been set to the first image (if any) in the
851 % Magick Wand. Using MagickNextImage() will then set teh current image
852 % to the second image in the list (if present).
854 % This operation is similar to MagickResetIterator() but differs in how
855 % MagickAddImage(), MagickReadImage(), and MagickNextImage() behaves
858 % The format of the MagickSetFirstIterator method is:
860 % void MagickSetFirstIterator(MagickWand *wand)
862 % A description of each parameter follows:
864 % o wand: the magick wand.
867 WandExport void MagickSetFirstIterator(MagickWand *wand)
869 assert(wand != (MagickWand *) NULL);
870 assert(wand->signature == MagickWandSignature);
871 if (wand->debug != MagickFalse)
872 (void) LogMagickEvent(WandEvent,GetMagickModule(),"%s",wand->name);
873 wand->images=GetFirstImageInList(wand->images);
874 wand->insert_before=MagickTrue; /* Insert/add before the first image */
875 wand->image_pending=MagickFalse; /* NextImage will set next image */
879 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
883 % M a g i c k S e t I t e r a t o r I n d e x %
887 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
889 % MagickSetIteratorIndex() set the iterator to the given position in the
890 % image list specified with the index parameter. A zero index will set
891 % the first image as current, and so on. Negative indexes can be used
892 % to specify an image relative to the end of the images in the wand, with
893 % -1 being the last image in the wand.
895 % If the index is invalid (range too large for number of images in wand)
896 % the function will return MagickFalse, but no 'exception' will be raised,
897 % as it is not actually an error. In that case the current image will not
900 % After using any images added to the wand using MagickAddImage() or
901 % MagickReadImage() will be added after the image indexed, regardless
902 % of if a zero (first image in list) or negative index (from end) is used.
904 % Jumping to index 0 is similar to MagickResetIterator() but differs in how
905 % MagickNextImage() behaves afterward.
907 % The format of the MagickSetIteratorIndex method is:
909 % MagickBooleanType MagickSetIteratorIndex(MagickWand *wand,
910 % const ssize_t index)
912 % A description of each parameter follows:
914 % o wand: the magick wand.
916 % o index: the scene number.
919 WandExport MagickBooleanType MagickSetIteratorIndex(MagickWand *wand,
925 assert(wand != (MagickWand *) NULL);
926 assert(wand->signature == MagickWandSignature);
927 if (wand->debug != MagickFalse)
928 (void) LogMagickEvent(WandEvent,GetMagickModule(),"%s",wand->name);
929 if (wand->images == (Image *) NULL)
931 image=GetImageFromList(wand->images,index);
932 if (image == (Image *) NULL)
933 return(MagickFalse); /* this is not an exception! Just range error. */
935 wand->insert_before=MagickFalse; /* Insert/Add after (this) image */
936 wand->image_pending=MagickFalse; /* NextImage will set next image */
940 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
944 % M a g i c k S e t L a s t I t e r a t o r %
948 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
950 % MagickSetLastIterator() sets the wand iterator to the last image.
952 % The last image is actually the current image, and the next use of
953 % MagickPreviousImage() will not change this allowing this function to be
954 % used to iterate over the images in the reverse direction. In this sense it
955 % is more like MagickResetIterator() than MagickSetFirstIterator().
957 % Typically this function is used before MagickAddImage(), MagickReadImage()
958 % functions to ensure new images are appended to the very end of wand's image
961 % The format of the MagickSetLastIterator method is:
963 % void MagickSetLastIterator(MagickWand *wand)
965 % A description of each parameter follows:
967 % o wand: the magick wand.
970 WandExport void MagickSetLastIterator(MagickWand *wand)
972 assert(wand != (MagickWand *) NULL);
973 assert(wand->signature == MagickWandSignature);
974 if (wand->debug != MagickFalse)
975 (void) LogMagickEvent(WandEvent,GetMagickModule(),"%s",wand->name);
976 wand->images=GetLastImageInList(wand->images);
977 wand->insert_before=MagickFalse; /* Insert/add after current (last) image */
978 wand->image_pending=MagickTrue; /* PreviousImage will return last image */
982 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
986 % M a g i c k W a n d G e n e s i s %
990 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
992 % MagickWandGenesis() initializes the MagickWand environment.
994 % The format of the MagickWandGenesis method is:
996 % void MagickWandGenesis(void)
999 WandExport void MagickWandGenesis(void)
1001 if (IsMagickCoreInstantiated() == MagickFalse)
1002 MagickCoreGenesis((char *) NULL,MagickFalse);
1006 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1010 % M a g i c k W a n d T e r m i n u s %
1014 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1016 % MagickWandTerminus() terminates the MagickWand environment.
1018 % The format of the MaickWandTerminus method is:
1020 % void MagickWandTerminus(void)
1023 WandExport void MagickWandTerminus(void)
1026 MagickCoreTerminus();
1030 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1034 % N e w M a g i c k W a n d %
1038 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1040 % NewMagickWand() returns a wand required for all other methods in the API.
1041 % A fatal exception is thrown if there is not enough memory to allocate the
1042 % wand. Use DestroyMagickWand() to dispose of the wand when it is no longer
1045 % The format of the NewMagickWand method is:
1047 % MagickWand *NewMagickWand(void)
1050 WandExport MagickWand *NewMagickWand(void)
1061 depth=MAGICKCORE_QUANTUM_DEPTH;
1062 quantum=GetMagickQuantumDepth(&depth);
1063 if (depth != MAGICKCORE_QUANTUM_DEPTH)
1064 ThrowWandFatalException(WandError,"QuantumDepthMismatch",quantum);
1065 wand=(MagickWand *) AcquireMagickMemory(sizeof(*wand));
1066 if (wand == (MagickWand *) NULL)
1067 ThrowWandFatalException(ResourceLimitFatalError,"MemoryAllocationFailed",
1068 GetExceptionMessage(errno));
1069 (void) ResetMagickMemory(wand,0,sizeof(*wand));
1070 wand->id=AcquireWandId();
1071 (void) FormatLocaleString(wand->name,MagickPathExtent,"%s-%.20g",MagickWandId,
1073 wand->images=NewImageList();
1074 wand->image_info=AcquireImageInfo();
1075 wand->exception=AcquireExceptionInfo();
1076 wand->debug=IsEventLogging();
1077 if (wand->debug != MagickFalse)
1078 (void) LogMagickEvent(WandEvent,GetMagickModule(),"%s",wand->name);
1079 wand->signature=MagickWandSignature;
1084 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1088 % N e w M a g i c k W a n d F r o m I m a g e %
1092 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1094 % NewMagickWandFromImage() returns a wand with an image.
1096 % The format of the NewMagickWandFromImage method is:
1098 % MagickWand *NewMagickWandFromImage(const Image *image)
1100 % A description of each parameter follows:
1102 % o image: the image.
1105 WandExport MagickWand *NewMagickWandFromImage(const Image *image)
1110 wand=NewMagickWand();
1111 wand->images=CloneImage(image,0,0,MagickTrue,wand->exception);
1116 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1120 % I s M a g i c k W a n d I n s t a n t i a t e d %
1124 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1126 % IsMagickWandInstantiated() returns MagickTrue if the ImageMagick environment
1127 % is currently instantiated-- that is, MagickWandGenesis() has been called but
1128 % MagickWandTerminus() has not.
1130 % The format of the IsMagickWandInstantiated method is:
1132 % MagickBooleanType IsMagickWandInstantiated(void)
1135 MagickExport MagickBooleanType IsMagickWandInstantiated(void)
1137 return(IsMagickCoreInstantiated());