49#include "MagickWand/studio.h"
50#include "MagickWand/MagickWand.h"
51#include "MagickWand/magick-wand-private.h"
52#include "MagickWand/wand.h"
77WandExport
void ClearMagickWand(
MagickWand *wand)
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();
120 assert(wand->signature == MagickWandSignature);
121 if (wand->debug != MagickFalse)
122 (void) LogMagickEvent(WandEvent,GetMagickModule(),
"%s",wand->name);
123 clone_wand=(
MagickWand *) AcquireCriticalMemory(
sizeof(*clone_wand));
124 (void) memset(clone_wand,0,
sizeof(*clone_wand));
125 clone_wand->id=AcquireWandId();
126 (void) FormatLocaleString(clone_wand->name,MagickPathExtent,
"%s-%.20g",
127 MagickWandId,(
double) clone_wand->id);
128 clone_wand->exception=AcquireExceptionInfo();
129 InheritException(clone_wand->exception,wand->exception);
130 clone_wand->image_info=CloneImageInfo(wand->image_info);
131 clone_wand->images=CloneImageList(wand->images,clone_wand->exception);
132 clone_wand->insert_before=MagickFalse;
133 clone_wand->image_pending=MagickFalse;
134 clone_wand->debug=IsEventLogging();
135 if (clone_wand->debug != MagickFalse)
136 (void) LogMagickEvent(WandEvent,GetMagickModule(),
"%s",clone_wand->name);
137 clone_wand->signature=MagickWandSignature;
166 assert(wand->signature == MagickWandSignature);
167 if (wand->debug != MagickFalse)
168 (void) LogMagickEvent(WandEvent,GetMagickModule(),
"%s",wand->name);
169 wand->images=DestroyImageList(wand->images);
170 if (wand->image_info != (ImageInfo *) NULL )
171 wand->image_info=DestroyImageInfo(wand->image_info);
172 if (wand->exception != (ExceptionInfo *) NULL )
173 wand->exception=DestroyExceptionInfo(wand->exception);
174 RelinquishWandId(wand->id);
175 wand->signature=(~MagickWandSignature);
176 wand=(
MagickWand *) RelinquishMagickMemory(wand);
202WandExport MagickBooleanType IsMagickWand(
const MagickWand *wand)
206 if (wand->signature != MagickWandSignature)
208 if (LocaleNCompare(wand->name,MagickWandId,strlen(MagickWandId)) != 0)
235WandExport MagickBooleanType MagickClearException(
MagickWand *wand)
238 assert(wand->signature == MagickWandSignature);
239 if (wand->debug != MagickFalse)
240 (void) LogMagickEvent(WandEvent,GetMagickModule(),
"%s",wand->name);
241 ClearMagickException(wand->exception);
273WandExport
char *MagickGetException(
const MagickWand *wand,
274 ExceptionType *severity)
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);
330WandExport ExceptionType MagickGetExceptionType(
const MagickWand *wand)
333 assert(wand->signature == MagickWandSignature);
334 if (wand->debug != MagickFalse)
335 (void) LogMagickEvent(WandEvent,GetMagickModule(),
"%s",wand->name);
336 return(wand->exception->severity);
362WandExport ssize_t MagickGetIteratorIndex(
MagickWand *wand)
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));
400WandExport
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);
420 if (number_options != 0)
421 value=AcquireString(configure_info[0]->value);
422 configure_info=(
const ConfigureInfo **) RelinquishMagickMemory((
void *)
454WandExport
char **MagickQueryConfigureOptions(
const char *pattern,
455 size_t *number_options)
463 exception=AcquireExceptionInfo();
464 options=GetConfigureList(pattern,number_options,exception);
465 exception=DestroyExceptionInfo(exception);
513WandExport
double *MagickQueryFontMetrics(
MagickWand *wand,
529 assert(wand->signature == MagickWandSignature);
530 if (wand->debug != MagickFalse)
531 (void) LogMagickEvent(WandEvent,GetMagickModule(),
"%s",wand->name);
532 assert(drawing_wand != (
const DrawingWand *) NULL);
533 if (wand->images == (Image *) NULL)
535 (void) ThrowMagickException(wand->exception,GetMagickModule(),WandError,
536 "ContainsNoImages",
"`%s'",wand->name);
537 return((
double *) NULL);
539 font_metrics=(
double *) AcquireQuantumMemory(13UL,
sizeof(*font_metrics));
540 if (font_metrics == (
double *) NULL)
541 return((
double *) NULL);
542 draw_info=PeekDrawingWand(drawing_wand);
543 if (draw_info == (DrawInfo *) NULL)
545 font_metrics=(
double *) RelinquishMagickMemory(font_metrics);
546 return((
double *) NULL);
548 (void) CloneString(&draw_info->text,text);
549 (void) memset(&metrics,0,
sizeof(metrics));
550 status=GetTypeMetrics(wand->images,draw_info,&metrics,wand->exception);
551 draw_info=DestroyDrawInfo(draw_info);
552 if (status == MagickFalse)
554 font_metrics=(
double *) RelinquishMagickMemory(font_metrics);
555 return((
double *) NULL);
557 font_metrics[0]=metrics.pixels_per_em.x;
558 font_metrics[1]=metrics.pixels_per_em.y;
559 font_metrics[2]=metrics.ascent;
560 font_metrics[3]=metrics.descent;
561 font_metrics[4]=metrics.width;
562 font_metrics[5]=metrics.height;
563 font_metrics[6]=metrics.max_advance;
564 font_metrics[7]=metrics.bounds.x1;
565 font_metrics[8]=metrics.bounds.y1;
566 font_metrics[9]=metrics.bounds.x2;
567 font_metrics[10]=metrics.bounds.y2;
568 font_metrics[11]=metrics.origin.x;
569 font_metrics[12]=metrics.origin.y;
570 return(font_metrics);
620WandExport
double *MagickQueryMultilineFontMetrics(
MagickWand *wand,
636 assert(wand->signature == MagickWandSignature);
637 if (wand->debug != MagickFalse)
638 (void) LogMagickEvent(WandEvent,GetMagickModule(),
"%s",wand->name);
639 assert(drawing_wand != (
const DrawingWand *) NULL);
640 if (wand->images == (Image *) NULL)
642 (void) ThrowMagickException(wand->exception,GetMagickModule(),WandError,
643 "ContainsNoImages",
"`%s'",wand->name);
644 return((
double *) NULL);
646 font_metrics=(
double *) AcquireQuantumMemory(13UL,
sizeof(*font_metrics));
647 if (font_metrics == (
double *) NULL)
648 return((
double *) NULL);
649 draw_info=PeekDrawingWand(drawing_wand);
650 if (draw_info == (DrawInfo *) NULL)
652 font_metrics=(
double *) RelinquishMagickMemory(font_metrics);
653 return((
double *) NULL);
655 (void) CloneString(&draw_info->text,text);
656 (void) memset(&metrics,0,
sizeof(metrics));
657 status=GetMultilineTypeMetrics(wand->images,draw_info,&metrics,
659 draw_info=DestroyDrawInfo(draw_info);
660 if (status == MagickFalse)
662 font_metrics=(
double *) RelinquishMagickMemory(font_metrics);
663 return((
double *) NULL);
665 font_metrics[0]=metrics.pixels_per_em.x;
666 font_metrics[1]=metrics.pixels_per_em.y;
667 font_metrics[2]=metrics.ascent;
668 font_metrics[3]=metrics.descent;
669 font_metrics[4]=metrics.width;
670 font_metrics[5]=metrics.height;
671 font_metrics[6]=metrics.max_advance;
672 font_metrics[7]=metrics.bounds.x1;
673 font_metrics[8]=metrics.bounds.y1;
674 font_metrics[9]=metrics.bounds.x2;
675 font_metrics[10]=metrics.bounds.y2;
676 font_metrics[11]=metrics.origin.x;
677 font_metrics[12]=metrics.origin.y;
678 return(font_metrics);
706WandExport
char **MagickQueryFonts(
const char *pattern,
707 size_t *number_fonts)
715 exception=AcquireExceptionInfo();
716 fonts=GetTypeList(pattern,number_fonts,exception);
717 exception=DestroyExceptionInfo(exception);
747WandExport
char **MagickQueryFormats(
const char *pattern,
748 size_t *number_formats)
756 exception=AcquireExceptionInfo();
757 formats=GetMagickList(pattern,number_formats,exception);
758 exception=DestroyExceptionInfo(exception);
785WandExport
void *MagickRelinquishMemory(
void *memory)
787 if (IsEventLogging() != MagickFalse)
788 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
789 return(RelinquishMagickMemory(memory));
824WandExport
void MagickResetIterator(
MagickWand *wand)
827 assert(wand->signature == MagickWandSignature);
828 if (wand->debug != MagickFalse)
829 (void) LogMagickEvent(WandEvent,GetMagickModule(),
"%s",wand->name);
830 wand->images=GetFirstImageInList(wand->images);
831 wand->insert_before=MagickFalse;
832 wand->image_pending=MagickTrue;
868WandExport
void MagickSetFirstIterator(
MagickWand *wand)
871 assert(wand->signature == MagickWandSignature);
872 if (wand->debug != MagickFalse)
873 (void) LogMagickEvent(WandEvent,GetMagickModule(),
"%s",wand->name);
874 wand->images=GetFirstImageInList(wand->images);
875 wand->insert_before=MagickTrue;
876 wand->image_pending=MagickFalse;
920WandExport MagickBooleanType MagickSetIteratorIndex(
MagickWand *wand,
927 assert(wand->signature == MagickWandSignature);
928 if (wand->debug != MagickFalse)
929 (void) LogMagickEvent(WandEvent,GetMagickModule(),
"%s",wand->name);
930 if (wand->images == (Image *) NULL)
932 image=GetImageFromList(wand->images,index);
933 if (image == (Image *) NULL)
936 wand->insert_before=MagickFalse;
937 wand->image_pending=MagickFalse;
971WandExport
void MagickSetLastIterator(
MagickWand *wand)
974 assert(wand->signature == MagickWandSignature);
975 if (wand->debug != MagickFalse)
976 (void) LogMagickEvent(WandEvent,GetMagickModule(),
"%s",wand->name);
977 wand->images=GetLastImageInList(wand->images);
978 wand->insert_before=MagickFalse;
979 wand->image_pending=MagickTrue;
1000WandExport
void MagickWandGenesis(
void)
1002 if (IsMagickCoreInstantiated() == MagickFalse)
1003 MagickCoreGenesis((
char *) NULL,MagickFalse);
1046WandExport
void MagickWandTerminus(
void)
1049 MagickCoreTerminus();
1078 CheckMagickCoreCompatibility();
1079 wand=(
MagickWand *) AcquireMagickMemory(
sizeof(*wand));
1081 ThrowWandFatalException(ResourceLimitFatalError,
"MemoryAllocationFailed",
1082 GetExceptionMessage(errno));
1083 (void) memset(wand,0,
sizeof(*wand));
1084 wand->id=AcquireWandId();
1085 (void) FormatLocaleString(wand->name,MagickPathExtent,
"%s-%.20g",MagickWandId,
1087 wand->images=NewImageList();
1088 wand->image_info=AcquireImageInfo();
1089 wand->exception=AcquireExceptionInfo();
1090 wand->debug=IsEventLogging();
1091 if (wand->debug != MagickFalse)
1092 (void) LogMagickEvent(WandEvent,GetMagickModule(),
"%s",wand->name);
1093 wand->signature=MagickWandSignature;
1119WandExport
MagickWand *NewMagickWandFromImage(
const Image *image)
1124 wand=NewMagickWand();
1125 wand->images=CloneImage(image,0,0,MagickTrue,wand->exception);
1149MagickExport MagickBooleanType IsMagickWandInstantiated(
void)
1151 return(IsMagickCoreInstantiated());