49 #include "wand/studio.h"
50 #include "wand/MagickWand.h"
51 #include "wand/magick-wand-private.h"
52 #include "wand/wand.h"
77 WandExport
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);
207 WandExport MagickBooleanType IsMagickWand(
const MagickWand *wand)
211 if (wand->signature != WandSignature)
213 if (LocaleNCompare(wand->name,MagickWandId,strlen(MagickWandId)) != 0)
240 WandExport 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);
275 WandExport
char *MagickGetException(
const MagickWand *wand,
276 ExceptionType *severity)
282 assert(wand->signature == WandSignature);
283 if (wand->debug != MagickFalse)
284 (void) LogMagickEvent(WandEvent,GetMagickModule(),
"%s",wand->name);
285 assert(severity != (ExceptionType *) NULL);
286 *severity=wand->exception->severity;
287 description=(
char *) AcquireQuantumMemory(2UL*MaxTextExtent,
288 sizeof(*description));
289 if (description == (
char *) NULL)
291 (void) ThrowMagickException(wand->exception,GetMagickModule(),WandError,
292 "MemoryAllocationFailed",
"`%s'",wand->name);
293 return((
char *) NULL);
296 if (wand->exception->reason != (
char *) NULL)
297 (
void) CopyMagickString(description,GetLocaleExceptionMessage(
298 wand->exception->severity,wand->exception->reason),MaxTextExtent);
299 if (wand->exception->description != (
char *) NULL)
301 (void) ConcatenateMagickString(description,
" (",MaxTextExtent);
302 (void) ConcatenateMagickString(description,GetLocaleExceptionMessage(
303 wand->exception->severity,wand->exception->description),MaxTextExtent);
304 (void) ConcatenateMagickString(description,
")",MaxTextExtent);
332 WandExport ExceptionType MagickGetExceptionType(
const MagickWand *wand)
335 assert(wand->signature == WandSignature);
336 if (wand->debug != MagickFalse)
337 (void) LogMagickEvent(WandEvent,GetMagickModule(),
"%s",wand->name);
338 return(wand->exception->severity);
364 WandExport ssize_t MagickGetIteratorIndex(
MagickWand *wand)
367 assert(wand->signature == WandSignature);
368 if (wand->debug != MagickFalse)
369 (void) LogMagickEvent(WandEvent,GetMagickModule(),
"%s",wand->name);
370 if (wand->images == (Image *) NULL)
372 (void) ThrowMagickException(wand->exception,GetMagickModule(),WandError,
373 "ContainsNoIterators",
"`%s'",wand->name);
376 return(GetImageIndexInList(wand->images));
402 WandExport
char *MagickQueryConfigureOption(
const char *option)
416 exception=AcquireExceptionInfo();
417 configure_info=GetConfigureInfoList(option,&number_options,exception);
418 exception=DestroyExceptionInfo(exception);
419 if (configure_info == (
const ConfigureInfo **) NULL)
420 return((
char *) NULL);
422 if (number_options != 0)
423 value=AcquireString(configure_info[0]->value);
424 configure_info=(
const ConfigureInfo **)
425 RelinquishMagickMemory((
void *) configure_info);
457 WandExport
char **MagickQueryConfigureOptions(
const char *pattern,
458 size_t *number_options)
466 exception=AcquireExceptionInfo();
467 options=GetConfigureList(pattern,number_options,exception);
468 exception=DestroyExceptionInfo(exception);
516 WandExport
double *MagickQueryFontMetrics(
MagickWand *wand,
532 assert(wand->signature == WandSignature);
533 if (wand->debug != MagickFalse)
534 (void) LogMagickEvent(WandEvent,GetMagickModule(),
"%s",wand->name);
535 assert(drawing_wand != (
const DrawingWand *) NULL);
536 if (wand->images == (Image *) NULL)
538 (void) ThrowMagickException(wand->exception,GetMagickModule(),WandError,
539 "ContainsNoImages",
"`%s'",wand->name);
540 return((
double *) NULL);
542 font_metrics=(
double *) AcquireQuantumMemory(13UL,
sizeof(*font_metrics));
543 if (font_metrics == (
double *) NULL)
544 return((
double *) NULL);
545 draw_info=PeekDrawingWand(drawing_wand);
546 if (draw_info == (DrawInfo *) NULL)
548 font_metrics=(
double *) RelinquishMagickMemory(font_metrics);
549 return((
double *) NULL);
551 (void) CloneString(&draw_info->text,text);
552 (void) memset(&metrics,0,
sizeof(metrics));
553 status=GetTypeMetrics(wand->images,draw_info,&metrics);
554 draw_info=DestroyDrawInfo(draw_info);
555 if (status == MagickFalse)
557 InheritException(wand->exception,&wand->images->exception);
558 font_metrics=(
double *) RelinquishMagickMemory(font_metrics);
559 return((
double *) NULL);
561 font_metrics[0]=metrics.pixels_per_em.x;
562 font_metrics[1]=metrics.pixels_per_em.y;
563 font_metrics[2]=metrics.ascent;
564 font_metrics[3]=metrics.descent;
565 font_metrics[4]=metrics.width;
566 font_metrics[5]=metrics.height;
567 font_metrics[6]=metrics.max_advance;
568 font_metrics[7]=metrics.bounds.x1;
569 font_metrics[8]=metrics.bounds.y1;
570 font_metrics[9]=metrics.bounds.x2;
571 font_metrics[10]=metrics.bounds.y2;
572 font_metrics[11]=metrics.origin.x;
573 font_metrics[12]=metrics.origin.y;
574 return(font_metrics);
624 WandExport
double *MagickQueryMultilineFontMetrics(
MagickWand *wand,
640 assert(wand->signature == WandSignature);
641 if (wand->debug != MagickFalse)
642 (void) LogMagickEvent(WandEvent,GetMagickModule(),
"%s",wand->name);
643 assert(drawing_wand != (
const DrawingWand *) NULL);
644 if (wand->images == (Image *) NULL)
646 (void) ThrowMagickException(wand->exception,GetMagickModule(),WandError,
647 "ContainsNoImages",
"`%s'",wand->name);
648 return((
double *) NULL);
650 font_metrics=(
double *) AcquireQuantumMemory(13UL,
sizeof(*font_metrics));
651 if (font_metrics == (
double *) NULL)
652 return((
double *) NULL);
653 draw_info=PeekDrawingWand(drawing_wand);
654 if (draw_info == (DrawInfo *) NULL)
656 font_metrics=(
double *) RelinquishMagickMemory(font_metrics);
657 return((
double *) NULL);
659 (void) CloneString(&draw_info->text,text);
660 (void) memset(&metrics,0,
sizeof(metrics));
661 status=GetMultilineTypeMetrics(wand->images,draw_info,&metrics);
662 draw_info=DestroyDrawInfo(draw_info);
663 if (status == MagickFalse)
665 InheritException(wand->exception,&wand->images->exception);
666 font_metrics=(
double *) RelinquishMagickMemory(font_metrics);
667 return((
double *) NULL);
669 font_metrics[0]=metrics.pixels_per_em.x;
670 font_metrics[1]=metrics.pixels_per_em.y;
671 font_metrics[2]=metrics.ascent;
672 font_metrics[3]=metrics.descent;
673 font_metrics[4]=metrics.width;
674 font_metrics[5]=metrics.height;
675 font_metrics[6]=metrics.max_advance;
676 font_metrics[7]=metrics.bounds.x1;
677 font_metrics[8]=metrics.bounds.y1;
678 font_metrics[9]=metrics.bounds.x2;
679 font_metrics[10]=metrics.bounds.y2;
680 font_metrics[11]=metrics.origin.x;
681 font_metrics[12]=metrics.origin.y;
682 return(font_metrics);
711 WandExport
char **MagickQueryFonts(
const char *pattern,
712 size_t *number_fonts)
720 exception=AcquireExceptionInfo();
721 fonts=GetTypeList(pattern,number_fonts,exception);
722 exception=DestroyExceptionInfo(exception);
752 WandExport
char **MagickQueryFormats(
const char *pattern,
753 size_t *number_formats)
761 exception=AcquireExceptionInfo();
762 formats=GetMagickList(pattern,number_formats,exception);
763 exception=DestroyExceptionInfo(exception);
790 WandExport
void *MagickRelinquishMemory(
void *memory)
792 if (IsEventLogging() != MagickFalse)
793 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
794 return(RelinquishMagickMemory(memory));
829 WandExport
void MagickResetIterator(
MagickWand *wand)
832 assert(wand->signature == WandSignature);
833 if (wand->debug != MagickFalse)
834 (void) LogMagickEvent(WandEvent,GetMagickModule(),
"%s",wand->name);
835 wand->images=GetFirstImageInList(wand->images);
836 wand->insert_before=MagickFalse;
837 wand->image_pending=MagickTrue;
873 WandExport
void MagickSetFirstIterator(
MagickWand *wand)
876 assert(wand->signature == WandSignature);
877 if (wand->debug != MagickFalse)
878 (void) LogMagickEvent(WandEvent,GetMagickModule(),
"%s",wand->name);
879 wand->images=GetFirstImageInList(wand->images);
880 wand->insert_before=MagickTrue;
881 wand->image_pending=MagickFalse;
925 WandExport MagickBooleanType MagickSetIteratorIndex(
MagickWand *wand,
932 assert(wand->signature == WandSignature);
933 if (wand->debug != MagickFalse)
934 (void) LogMagickEvent(WandEvent,GetMagickModule(),
"%s",wand->name);
935 if (wand->images == (Image *) NULL)
937 image=GetImageFromList(wand->images,index);
938 if (image == (Image *) NULL)
940 InheritException(wand->exception,&wand->images->exception);
944 wand->insert_before=MagickFalse;
945 wand->image_pending=MagickFalse;
979 WandExport
void MagickSetLastIterator(
MagickWand *wand)
982 assert(wand->signature == WandSignature);
983 if (wand->debug != MagickFalse)
984 (void) LogMagickEvent(WandEvent,GetMagickModule(),
"%s",wand->name);
985 wand->images=GetLastImageInList(wand->images);
986 wand->insert_before=MagickFalse;
987 wand->image_pending=MagickTrue;
1008 WandExport
void MagickWandGenesis(
void)
1010 if (IsMagickCoreInstantiated() == MagickFalse)
1011 MagickCoreGenesis((
char *) NULL,MagickFalse);
1032 WandExport
void MagickWandTerminus(
void)
1035 MagickCoreTerminus();
1070 depth=MAGICKCORE_QUANTUM_DEPTH;
1071 quantum=GetMagickQuantumDepth(&depth);
1072 if (depth != MAGICKCORE_QUANTUM_DEPTH)
1073 ThrowWandFatalException(WandError,
"QuantumDepthMismatch",quantum);
1074 wand=(
MagickWand *) AcquireMagickMemory(
sizeof(*wand));
1076 ThrowWandFatalException(ResourceLimitFatalError,
"MemoryAllocationFailed",
1077 GetExceptionMessage(errno));
1078 (void) memset(wand,0,
sizeof(*wand));
1079 wand->id=AcquireWandId();
1080 (void) FormatLocaleString(wand->name,MaxTextExtent,
"%s-%.20g",MagickWandId,
1082 wand->images=NewImageList();
1083 wand->image_info=AcquireImageInfo();
1084 wand->exception=AcquireExceptionInfo();
1085 wand->quantize_info=CloneQuantizeInfo((QuantizeInfo *) NULL);
1086 wand->debug=IsEventLogging();
1087 if (wand->debug != MagickFalse)
1088 (void) LogMagickEvent(WandEvent,GetMagickModule(),
"%s",wand->name);
1089 wand->signature=WandSignature;
1115 WandExport
MagickWand *NewMagickWandFromImage(
const Image *image)
1120 wand=NewMagickWand();
1121 wand->images=CloneImage(image,0,0,MagickTrue,wand->exception);
1145 MagickExport MagickBooleanType IsMagickWandInstantiated(
void)
1147 return(IsMagickCoreInstantiated());