49 #include "MagickWand/studio.h"
50 #include "MagickWand/MagickWand.h"
51 #include "MagickWand/magick-wand-private.h"
52 #include "MagickWand/wand.h"
77 WandExport
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);
202 WandExport MagickBooleanType IsMagickWand(
const MagickWand *wand)
206 if (wand->signature != MagickWandSignature)
208 if (LocaleNCompare(wand->name,MagickWandId,strlen(MagickWandId)) != 0)
235 WandExport 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);
270 WandExport
char *MagickGetException(
const MagickWand *wand,
271 ExceptionType *severity)
277 assert(wand->signature == MagickWandSignature);
278 if (wand->debug != MagickFalse)
279 (void) LogMagickEvent(WandEvent,GetMagickModule(),
"%s",wand->name);
280 assert(severity != (ExceptionType *) NULL);
281 *severity=wand->exception->severity;
282 description=(
char *) AcquireQuantumMemory(2UL*MagickPathExtent,
283 sizeof(*description));
284 if (description == (
char *) NULL)
286 (void) ThrowMagickException(wand->exception,GetMagickModule(),WandError,
287 "MemoryAllocationFailed",
"`%s'",wand->name);
288 return((
char *) NULL);
291 if (wand->exception->reason != (
char *) NULL)
292 (
void) CopyMagickString(description,GetLocaleExceptionMessage(
293 wand->exception->severity,wand->exception->reason),MagickPathExtent);
294 if (wand->exception->description != (
char *) NULL)
296 (void) ConcatenateMagickString(description,
" (",MagickPathExtent);
297 (void) ConcatenateMagickString(description,GetLocaleExceptionMessage(
298 wand->exception->severity,wand->exception->description),MagickPathExtent);
299 (void) ConcatenateMagickString(description,
")",MagickPathExtent);
327 WandExport ExceptionType MagickGetExceptionType(
const MagickWand *wand)
330 assert(wand->signature == MagickWandSignature);
331 if (wand->debug != MagickFalse)
332 (void) LogMagickEvent(WandEvent,GetMagickModule(),
"%s",wand->name);
333 return(wand->exception->severity);
359 WandExport ssize_t MagickGetIteratorIndex(
MagickWand *wand)
362 assert(wand->signature == MagickWandSignature);
363 if (wand->debug != MagickFalse)
364 (void) LogMagickEvent(WandEvent,GetMagickModule(),
"%s",wand->name);
365 if (wand->images == (Image *) NULL)
367 (void) ThrowMagickException(wand->exception,GetMagickModule(),WandError,
368 "ContainsNoIterators",
"`%s'",wand->name);
371 return(GetImageIndexInList(wand->images));
397 WandExport
char *MagickQueryConfigureOption(
const char *option)
411 exception=AcquireExceptionInfo();
412 configure_info=GetConfigureInfoList(option,&number_options,exception);
413 exception=DestroyExceptionInfo(exception);
414 if (configure_info == (
const ConfigureInfo **) NULL)
415 return((
char *) NULL);
417 if (number_options != 0)
418 value=AcquireString(configure_info[0]->value);
419 configure_info=(
const ConfigureInfo **) RelinquishMagickMemory((
void *)
451 WandExport
char **MagickQueryConfigureOptions(
const char *pattern,
452 size_t *number_options)
460 exception=AcquireExceptionInfo();
461 options=GetConfigureList(pattern,number_options,exception);
462 exception=DestroyExceptionInfo(exception);
510 WandExport
double *MagickQueryFontMetrics(
MagickWand *wand,
526 assert(wand->signature == MagickWandSignature);
527 if (wand->debug != MagickFalse)
528 (void) LogMagickEvent(WandEvent,GetMagickModule(),
"%s",wand->name);
529 assert(drawing_wand != (
const DrawingWand *) NULL);
530 if (wand->images == (Image *) NULL)
532 (void) ThrowMagickException(wand->exception,GetMagickModule(),WandError,
533 "ContainsNoImages",
"`%s'",wand->name);
534 return((
double *) NULL);
536 font_metrics=(
double *) AcquireQuantumMemory(13UL,
sizeof(*font_metrics));
537 if (font_metrics == (
double *) NULL)
538 return((
double *) NULL);
539 draw_info=PeekDrawingWand(drawing_wand);
540 if (draw_info == (DrawInfo *) NULL)
542 font_metrics=(
double *) RelinquishMagickMemory(font_metrics);
543 return((
double *) NULL);
545 (void) CloneString(&draw_info->text,text);
546 (void) memset(&metrics,0,
sizeof(metrics));
547 status=GetTypeMetrics(wand->images,draw_info,&metrics,wand->exception);
548 draw_info=DestroyDrawInfo(draw_info);
549 if (status == MagickFalse)
551 font_metrics=(
double *) RelinquishMagickMemory(font_metrics);
552 return((
double *) NULL);
554 font_metrics[0]=metrics.pixels_per_em.x;
555 font_metrics[1]=metrics.pixels_per_em.y;
556 font_metrics[2]=metrics.ascent;
557 font_metrics[3]=metrics.descent;
558 font_metrics[4]=metrics.width;
559 font_metrics[5]=metrics.height;
560 font_metrics[6]=metrics.max_advance;
561 font_metrics[7]=metrics.bounds.x1;
562 font_metrics[8]=metrics.bounds.y1;
563 font_metrics[9]=metrics.bounds.x2;
564 font_metrics[10]=metrics.bounds.y2;
565 font_metrics[11]=metrics.origin.x;
566 font_metrics[12]=metrics.origin.y;
567 return(font_metrics);
617 WandExport
double *MagickQueryMultilineFontMetrics(
MagickWand *wand,
633 assert(wand->signature == MagickWandSignature);
634 if (wand->debug != MagickFalse)
635 (void) LogMagickEvent(WandEvent,GetMagickModule(),
"%s",wand->name);
636 assert(drawing_wand != (
const DrawingWand *) NULL);
637 if (wand->images == (Image *) NULL)
639 (void) ThrowMagickException(wand->exception,GetMagickModule(),WandError,
640 "ContainsNoImages",
"`%s'",wand->name);
641 return((
double *) NULL);
643 font_metrics=(
double *) AcquireQuantumMemory(13UL,
sizeof(*font_metrics));
644 if (font_metrics == (
double *) NULL)
645 return((
double *) NULL);
646 draw_info=PeekDrawingWand(drawing_wand);
647 if (draw_info == (DrawInfo *) NULL)
649 font_metrics=(
double *) RelinquishMagickMemory(font_metrics);
650 return((
double *) NULL);
652 (void) CloneString(&draw_info->text,text);
653 (void) memset(&metrics,0,
sizeof(metrics));
654 status=GetMultilineTypeMetrics(wand->images,draw_info,&metrics,
656 draw_info=DestroyDrawInfo(draw_info);
657 if (status == MagickFalse)
659 font_metrics=(
double *) RelinquishMagickMemory(font_metrics);
660 return((
double *) NULL);
662 font_metrics[0]=metrics.pixels_per_em.x;
663 font_metrics[1]=metrics.pixels_per_em.y;
664 font_metrics[2]=metrics.ascent;
665 font_metrics[3]=metrics.descent;
666 font_metrics[4]=metrics.width;
667 font_metrics[5]=metrics.height;
668 font_metrics[6]=metrics.max_advance;
669 font_metrics[7]=metrics.bounds.x1;
670 font_metrics[8]=metrics.bounds.y1;
671 font_metrics[9]=metrics.bounds.x2;
672 font_metrics[10]=metrics.bounds.y2;
673 font_metrics[11]=metrics.origin.x;
674 font_metrics[12]=metrics.origin.y;
675 return(font_metrics);
703 WandExport
char **MagickQueryFonts(
const char *pattern,
704 size_t *number_fonts)
712 exception=AcquireExceptionInfo();
713 fonts=GetTypeList(pattern,number_fonts,exception);
714 exception=DestroyExceptionInfo(exception);
744 WandExport
char **MagickQueryFormats(
const char *pattern,
745 size_t *number_formats)
753 exception=AcquireExceptionInfo();
754 formats=GetMagickList(pattern,number_formats,exception);
755 exception=DestroyExceptionInfo(exception);
782 WandExport
void *MagickRelinquishMemory(
void *memory)
784 if (IsEventLogging() != MagickFalse)
785 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
786 return(RelinquishMagickMemory(memory));
821 WandExport
void MagickResetIterator(
MagickWand *wand)
824 assert(wand->signature == MagickWandSignature);
825 if (wand->debug != MagickFalse)
826 (void) LogMagickEvent(WandEvent,GetMagickModule(),
"%s",wand->name);
827 wand->images=GetFirstImageInList(wand->images);
828 wand->insert_before=MagickFalse;
829 wand->image_pending=MagickTrue;
865 WandExport
void MagickSetFirstIterator(
MagickWand *wand)
868 assert(wand->signature == MagickWandSignature);
869 if (wand->debug != MagickFalse)
870 (void) LogMagickEvent(WandEvent,GetMagickModule(),
"%s",wand->name);
871 wand->images=GetFirstImageInList(wand->images);
872 wand->insert_before=MagickTrue;
873 wand->image_pending=MagickFalse;
917 WandExport MagickBooleanType MagickSetIteratorIndex(
MagickWand *wand,
924 assert(wand->signature == MagickWandSignature);
925 if (wand->debug != MagickFalse)
926 (void) LogMagickEvent(WandEvent,GetMagickModule(),
"%s",wand->name);
927 if (wand->images == (Image *) NULL)
929 image=GetImageFromList(wand->images,index);
930 if (image == (Image *) NULL)
933 wand->insert_before=MagickFalse;
934 wand->image_pending=MagickFalse;
968 WandExport
void MagickSetLastIterator(
MagickWand *wand)
971 assert(wand->signature == MagickWandSignature);
972 if (wand->debug != MagickFalse)
973 (void) LogMagickEvent(WandEvent,GetMagickModule(),
"%s",wand->name);
974 wand->images=GetLastImageInList(wand->images);
975 wand->insert_before=MagickFalse;
976 wand->image_pending=MagickTrue;
997 WandExport
void MagickWandGenesis(
void)
999 if (IsMagickCoreInstantiated() == MagickFalse)
1000 MagickCoreGenesis((
char *) NULL,MagickFalse);
1021 WandExport
void MagickWandTerminus(
void)
1024 MagickCoreTerminus();
1053 CheckMagickCoreCompatibility();
1054 wand=(
MagickWand *) AcquireMagickMemory(
sizeof(*wand));
1056 ThrowWandFatalException(ResourceLimitFatalError,
"MemoryAllocationFailed",
1057 GetExceptionMessage(errno));
1058 (void) memset(wand,0,
sizeof(*wand));
1059 wand->id=AcquireWandId();
1060 (void) FormatLocaleString(wand->name,MagickPathExtent,
"%s-%.20g",MagickWandId,
1062 wand->images=NewImageList();
1063 wand->image_info=AcquireImageInfo();
1064 wand->exception=AcquireExceptionInfo();
1065 wand->debug=IsEventLogging();
1066 if (wand->debug != MagickFalse)
1067 (void) LogMagickEvent(WandEvent,GetMagickModule(),
"%s",wand->name);
1068 wand->signature=MagickWandSignature;
1094 WandExport
MagickWand *NewMagickWandFromImage(
const Image *image)
1099 wand=NewMagickWand();
1100 wand->images=CloneImage(image,0,0,MagickTrue,wand->exception);
1124 MagickExport MagickBooleanType IsMagickWandInstantiated(
void)
1126 return(IsMagickCoreInstantiated());