49#include "wand/studio.h"
50#include "wand/MagickWand.h"
51#include "wand/magick-wand-private.h"
77WandExport
void ClearMagickWand(
MagickWand *wand)
80 assert(wand->signature == WandSignature);
81 if (wand->debug != MagickFalse)
82 (void) LogMagickEvent(WandEvent,GetMagickModule(),
"%s",wand->name);
83 wand->quantize_info=DestroyQuantizeInfo(wand->quantize_info);
84 wand->image_info=DestroyImageInfo(wand->image_info);
85 wand->images=DestroyImageList(wand->images);
86 wand->image_info=AcquireImageInfo();
87 wand->quantize_info=CloneQuantizeInfo((QuantizeInfo *) NULL);
88 wand->insert_before=MagickFalse;
89 wand->image_pending=MagickFalse;
90 ClearMagickException(wand->exception);
91 wand->debug=IsEventLogging();
122 assert(wand->signature == WandSignature);
123 if (wand->debug != MagickFalse)
124 (void) LogMagickEvent(WandEvent,GetMagickModule(),
"%s",wand->name);
125 clone_wand=(
MagickWand *) AcquireCriticalMemory(
sizeof(*clone_wand));
126 (void) memset(clone_wand,0,
sizeof(*clone_wand));
127 clone_wand->id=AcquireWandId();
128 (void) FormatLocaleString(clone_wand->name,MaxTextExtent,
"%s-%.20g",
129 MagickWandId,(
double) clone_wand->id);
130 clone_wand->exception=AcquireExceptionInfo();
131 InheritException(clone_wand->exception,wand->exception);
132 clone_wand->image_info=CloneImageInfo(wand->image_info);
133 clone_wand->quantize_info=CloneQuantizeInfo(wand->quantize_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=WandSignature;
169 assert(wand->signature == WandSignature);
170 if (wand->debug != MagickFalse)
171 (void) LogMagickEvent(WandEvent,GetMagickModule(),
"%s",wand->name);
172 wand->images=DestroyImageList(wand->images);
173 if (wand->quantize_info != (QuantizeInfo *) NULL )
174 wand->quantize_info=DestroyQuantizeInfo(wand->quantize_info);
175 if (wand->image_info != (ImageInfo *) NULL )
176 wand->image_info=DestroyImageInfo(wand->image_info);
177 if (wand->exception != (ExceptionInfo *) NULL )
178 wand->exception=DestroyExceptionInfo(wand->exception);
179 RelinquishWandId(wand->id);
180 wand->signature=(~WandSignature);
181 wand=(
MagickWand *) RelinquishMagickMemory(wand);
207WandExport MagickBooleanType IsMagickWand(
const MagickWand *wand)
211 if (wand->signature != WandSignature)
213 if (LocaleNCompare(wand->name,MagickWandId,strlen(MagickWandId)) != 0)
240WandExport MagickBooleanType MagickClearException(
MagickWand *wand)
243 assert(wand->signature == WandSignature);
244 if (wand->debug != MagickFalse)
245 (void) LogMagickEvent(WandEvent,GetMagickModule(),
"%s",wand->name);
246 ClearMagickException(wand->exception);
278WandExport
char *MagickGetException(
const MagickWand *wand,
279 ExceptionType *severity)
285 assert(wand->signature == WandSignature);
286 if (wand->debug != MagickFalse)
287 (void) LogMagickEvent(WandEvent,GetMagickModule(),
"%s",wand->name);
288 assert(severity != (ExceptionType *) NULL);
289 *severity=wand->exception->severity;
290 description=(
char *) AcquireQuantumMemory(2UL*MaxTextExtent,
291 sizeof(*description));
292 if (description == (
char *) NULL)
294 (void) ThrowMagickException(wand->exception,GetMagickModule(),WandError,
295 "MemoryAllocationFailed",
"`%s'",wand->name);
296 return((
char *) NULL);
299 if (wand->exception->reason != (
char *) NULL)
300 (
void) CopyMagickString(description,GetLocaleExceptionMessage(
301 wand->exception->severity,wand->exception->reason),MaxTextExtent);
302 if (wand->exception->description != (
char *) NULL)
304 (void) ConcatenateMagickString(description,
" (",MaxTextExtent);
305 (void) ConcatenateMagickString(description,GetLocaleExceptionMessage(
306 wand->exception->severity,wand->exception->description),MaxTextExtent);
307 (void) ConcatenateMagickString(description,
")",MaxTextExtent);
335WandExport ExceptionType MagickGetExceptionType(
const MagickWand *wand)
338 assert(wand->signature == WandSignature);
339 if (wand->debug != MagickFalse)
340 (void) LogMagickEvent(WandEvent,GetMagickModule(),
"%s",wand->name);
341 return(wand->exception->severity);
367WandExport ssize_t MagickGetIteratorIndex(
MagickWand *wand)
370 assert(wand->signature == WandSignature);
371 if (wand->debug != MagickFalse)
372 (void) LogMagickEvent(WandEvent,GetMagickModule(),
"%s",wand->name);
373 if (wand->images == (Image *) NULL)
375 (void) ThrowMagickException(wand->exception,GetMagickModule(),WandError,
376 "ContainsNoIterators",
"`%s'",wand->name);
379 return(GetImageIndexInList(wand->images));
405WandExport
char *MagickQueryConfigureOption(
const char *option)
419 exception=AcquireExceptionInfo();
420 configure_info=GetConfigureInfoList(option,&number_options,exception);
421 exception=DestroyExceptionInfo(exception);
422 if (configure_info == (
const ConfigureInfo **) NULL)
423 return((
char *) NULL);
425 if (number_options != 0)
426 value=AcquireString(configure_info[0]->value);
427 configure_info=(
const ConfigureInfo **)
428 RelinquishMagickMemory((
void *) configure_info);
460WandExport
char **MagickQueryConfigureOptions(
const char *pattern,
461 size_t *number_options)
469 exception=AcquireExceptionInfo();
470 options=GetConfigureList(pattern,number_options,exception);
471 exception=DestroyExceptionInfo(exception);
519WandExport
double *MagickQueryFontMetrics(
MagickWand *wand,
535 assert(wand->signature == WandSignature);
536 if (wand->debug != MagickFalse)
537 (void) LogMagickEvent(WandEvent,GetMagickModule(),
"%s",wand->name);
538 assert(drawing_wand != (
const DrawingWand *) NULL);
539 if (wand->images == (Image *) NULL)
541 (void) ThrowMagickException(wand->exception,GetMagickModule(),WandError,
542 "ContainsNoImages",
"`%s'",wand->name);
543 return((
double *) NULL);
545 font_metrics=(
double *) AcquireQuantumMemory(13UL,
sizeof(*font_metrics));
546 if (font_metrics == (
double *) NULL)
547 return((
double *) NULL);
548 draw_info=PeekDrawingWand(drawing_wand);
549 if (draw_info == (DrawInfo *) NULL)
551 font_metrics=(
double *) RelinquishMagickMemory(font_metrics);
552 return((
double *) NULL);
554 (void) CloneString(&draw_info->text,text);
555 (void) memset(&metrics,0,
sizeof(metrics));
556 status=GetTypeMetrics(wand->images,draw_info,&metrics);
557 draw_info=DestroyDrawInfo(draw_info);
558 if (status == MagickFalse)
560 InheritException(wand->exception,&wand->images->exception);
561 font_metrics=(
double *) RelinquishMagickMemory(font_metrics);
562 return((
double *) NULL);
564 font_metrics[0]=metrics.pixels_per_em.x;
565 font_metrics[1]=metrics.pixels_per_em.y;
566 font_metrics[2]=metrics.ascent;
567 font_metrics[3]=metrics.descent;
568 font_metrics[4]=metrics.width;
569 font_metrics[5]=metrics.height;
570 font_metrics[6]=metrics.max_advance;
571 font_metrics[7]=metrics.bounds.x1;
572 font_metrics[8]=metrics.bounds.y1;
573 font_metrics[9]=metrics.bounds.x2;
574 font_metrics[10]=metrics.bounds.y2;
575 font_metrics[11]=metrics.origin.x;
576 font_metrics[12]=metrics.origin.y;
577 return(font_metrics);
627WandExport
double *MagickQueryMultilineFontMetrics(
MagickWand *wand,
643 assert(wand->signature == WandSignature);
644 if (wand->debug != MagickFalse)
645 (void) LogMagickEvent(WandEvent,GetMagickModule(),
"%s",wand->name);
646 assert(drawing_wand != (
const DrawingWand *) NULL);
647 if (wand->images == (Image *) NULL)
649 (void) ThrowMagickException(wand->exception,GetMagickModule(),WandError,
650 "ContainsNoImages",
"`%s'",wand->name);
651 return((
double *) NULL);
653 font_metrics=(
double *) AcquireQuantumMemory(13UL,
sizeof(*font_metrics));
654 if (font_metrics == (
double *) NULL)
655 return((
double *) NULL);
656 draw_info=PeekDrawingWand(drawing_wand);
657 if (draw_info == (DrawInfo *) NULL)
659 font_metrics=(
double *) RelinquishMagickMemory(font_metrics);
660 return((
double *) NULL);
662 (void) CloneString(&draw_info->text,text);
663 (void) memset(&metrics,0,
sizeof(metrics));
664 status=GetMultilineTypeMetrics(wand->images,draw_info,&metrics);
665 draw_info=DestroyDrawInfo(draw_info);
666 if (status == MagickFalse)
668 InheritException(wand->exception,&wand->images->exception);
669 font_metrics=(
double *) RelinquishMagickMemory(font_metrics);
670 return((
double *) NULL);
672 font_metrics[0]=metrics.pixels_per_em.x;
673 font_metrics[1]=metrics.pixels_per_em.y;
674 font_metrics[2]=metrics.ascent;
675 font_metrics[3]=metrics.descent;
676 font_metrics[4]=metrics.width;
677 font_metrics[5]=metrics.height;
678 font_metrics[6]=metrics.max_advance;
679 font_metrics[7]=metrics.bounds.x1;
680 font_metrics[8]=metrics.bounds.y1;
681 font_metrics[9]=metrics.bounds.x2;
682 font_metrics[10]=metrics.bounds.y2;
683 font_metrics[11]=metrics.origin.x;
684 font_metrics[12]=metrics.origin.y;
685 return(font_metrics);
714WandExport
char **MagickQueryFonts(
const char *pattern,
715 size_t *number_fonts)
723 exception=AcquireExceptionInfo();
724 fonts=GetTypeList(pattern,number_fonts,exception);
725 exception=DestroyExceptionInfo(exception);
755WandExport
char **MagickQueryFormats(
const char *pattern,
756 size_t *number_formats)
764 exception=AcquireExceptionInfo();
765 formats=GetMagickList(pattern,number_formats,exception);
766 exception=DestroyExceptionInfo(exception);
793WandExport
void *MagickRelinquishMemory(
void *memory)
795 if (IsEventLogging() != MagickFalse)
796 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
797 return(RelinquishMagickMemory(memory));
832WandExport
void MagickResetIterator(
MagickWand *wand)
835 assert(wand->signature == WandSignature);
836 if (wand->debug != MagickFalse)
837 (void) LogMagickEvent(WandEvent,GetMagickModule(),
"%s",wand->name);
838 wand->images=GetFirstImageInList(wand->images);
839 wand->insert_before=MagickFalse;
840 wand->image_pending=MagickTrue;
876WandExport
void MagickSetFirstIterator(
MagickWand *wand)
879 assert(wand->signature == WandSignature);
880 if (wand->debug != MagickFalse)
881 (void) LogMagickEvent(WandEvent,GetMagickModule(),
"%s",wand->name);
882 wand->images=GetFirstImageInList(wand->images);
883 wand->insert_before=MagickTrue;
884 wand->image_pending=MagickFalse;
928WandExport MagickBooleanType MagickSetIteratorIndex(
MagickWand *wand,
935 assert(wand->signature == WandSignature);
936 if (wand->debug != MagickFalse)
937 (void) LogMagickEvent(WandEvent,GetMagickModule(),
"%s",wand->name);
938 if (wand->images == (Image *) NULL)
940 image=GetImageFromList(wand->images,index);
941 if (image == (Image *) NULL)
943 InheritException(wand->exception,&wand->images->exception);
947 wand->insert_before=MagickFalse;
948 wand->image_pending=MagickFalse;
982WandExport
void MagickSetLastIterator(
MagickWand *wand)
985 assert(wand->signature == WandSignature);
986 if (wand->debug != MagickFalse)
987 (void) LogMagickEvent(WandEvent,GetMagickModule(),
"%s",wand->name);
988 wand->images=GetLastImageInList(wand->images);
989 wand->insert_before=MagickFalse;
990 wand->image_pending=MagickTrue;
1011WandExport
void MagickWandGenesis(
void)
1013 if (IsMagickCoreInstantiated() == MagickFalse)
1014 MagickCoreGenesis((
char *) NULL,MagickFalse);
1057WandExport
void MagickWandTerminus(
void)
1060 MagickCoreTerminus();
1095 depth=MAGICKCORE_QUANTUM_DEPTH;
1096 quantum=GetMagickQuantumDepth(&depth);
1097 if (depth != MAGICKCORE_QUANTUM_DEPTH)
1098 ThrowWandFatalException(WandError,
"QuantumDepthMismatch",quantum);
1099 wand=(
MagickWand *) AcquireMagickMemory(
sizeof(*wand));
1101 ThrowWandFatalException(ResourceLimitFatalError,
"MemoryAllocationFailed",
1102 GetExceptionMessage(errno));
1103 (void) memset(wand,0,
sizeof(*wand));
1104 wand->id=AcquireWandId();
1105 (void) FormatLocaleString(wand->name,MaxTextExtent,
"%s-%.20g",MagickWandId,
1107 wand->images=NewImageList();
1108 wand->image_info=AcquireImageInfo();
1109 wand->exception=AcquireExceptionInfo();
1110 wand->quantize_info=CloneQuantizeInfo((QuantizeInfo *) NULL);
1111 wand->debug=IsEventLogging();
1112 if (wand->debug != MagickFalse)
1113 (void) LogMagickEvent(WandEvent,GetMagickModule(),
"%s",wand->name);
1114 wand->signature=WandSignature;
1140WandExport
MagickWand *NewMagickWandFromImage(
const Image *image)
1145 wand=NewMagickWand();
1146 wand->images=CloneImage(image,0,0,MagickTrue,wand->exception);
1170MagickExport MagickBooleanType IsMagickWandInstantiated(
void)
1172 return(IsMagickCoreInstantiated());