blob: ea6ed3312a324a2be39037cbf0cc01246fd9ff4d [file] [log] [blame]
cristy3ed852e2009-09-05 21:47:34 +00001/*
2%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3% %
4% %
5% %
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 %
11% %
12% W W AAA N N DDDD %
13% W W A A NN N D D %
14% W W W AAAAA N N N D D %
15% WW WW A A N NN D D %
16% W W A A N N DDDD %
17% %
18% %
19% MagickWand Wand Methods %
20% %
21% Software Design %
22% John Cristy %
23% August 2003 %
24% %
25% %
cristy45ef08f2012-12-07 13:13:34 +000026% Copyright 1999-2013 ImageMagick Studio LLC, a non-profit organization %
cristy3ed852e2009-09-05 21:47:34 +000027% dedicated to making software imaging solutions freely available. %
28% %
29% You may not use this file except in compliance with the License. You may %
30% obtain a copy of the License at %
31% %
32% http://www.imagemagick.org/script/license.php %
33% %
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. %
39% %
40%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
41%
42%
43%
44*/
45
46/*
47 Include declarations.
48*/
cristy4c08aed2011-07-01 19:47:50 +000049#include "MagickWand/studio.h"
50#include "MagickWand/MagickWand.h"
51#include "MagickWand/magick-wand-private.h"
52#include "MagickWand/wand.h"
cristy3ed852e2009-09-05 21:47:34 +000053
54/*
55 Define declarations.
56*/
57#define ThrowWandException(severity,tag,context) \
58{ \
59 (void) ThrowMagickException(wand->exception,GetMagickModule(),severity, \
cristyefe601c2013-01-05 17:51:12 +000060 tag,"`%s'",context); \
cristy3ed852e2009-09-05 21:47:34 +000061 return(MagickFalse); \
62}
63
64/*
65%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
66% %
67% %
68% %
69% C l e a r M a g i c k W a n d %
70% %
71% %
72% %
73%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
74%
anthonya89dd172011-10-04 13:29:35 +000075% ClearMagickWand() clears resources associated with the wand, leaving the
76% wand blank, and ready to be used for a new set of images.
cristy3ed852e2009-09-05 21:47:34 +000077%
78% The format of the ClearMagickWand method is:
79%
80% void ClearMagickWand(MagickWand *wand)
81%
82% A description of each parameter follows:
83%
84% o wand: the magick wand.
85%
86*/
87WandExport void ClearMagickWand(MagickWand *wand)
88{
89 assert(wand != (MagickWand *) NULL);
90 assert(wand->signature == WandSignature);
91 if (wand->debug != MagickFalse)
92 (void) LogMagickEvent(WandEvent,GetMagickModule(),"%s",wand->name);
anthonyf93964e2012-03-16 08:25:58 +000093 wand->image_info=DestroyImageInfo(wand->image_info);
cristy3ed852e2009-09-05 21:47:34 +000094 wand->images=DestroyImageList(wand->images);
cristy3ed852e2009-09-05 21:47:34 +000095 wand->image_info=AcquireImageInfo();
anthonyade6afb2012-03-15 13:24:43 +000096 wand->insert_before=MagickFalse;
97 wand->image_pending=MagickFalse;
cristy3ed852e2009-09-05 21:47:34 +000098 ClearMagickException(wand->exception);
99 wand->debug=IsEventLogging();
100}
101
102/*
103%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
104% %
105% %
106% %
107% C l o n e M a g i c k W a n d %
108% %
109% %
110% %
111%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
112%
113% CloneMagickWand() makes an exact copy of the specified wand.
114%
115% The format of the CloneMagickWand method is:
116%
117% MagickWand *CloneMagickWand(const MagickWand *wand)
118%
119% A description of each parameter follows:
120%
121% o wand: the magick wand.
122%
123*/
124WandExport MagickWand *CloneMagickWand(const MagickWand *wand)
125{
126 MagickWand
127 *clone_wand;
128
129 assert(wand != (MagickWand *) NULL);
130 assert(wand->signature == WandSignature);
131 if (wand->debug != MagickFalse)
132 (void) LogMagickEvent(WandEvent,GetMagickModule(),"%s",wand->name);
cristy73bd4a52010-10-05 11:24:23 +0000133 clone_wand=(MagickWand *) AcquireMagickMemory(sizeof(*clone_wand));
cristy3ed852e2009-09-05 21:47:34 +0000134 if (clone_wand == (MagickWand *) NULL)
135 ThrowWandFatalException(ResourceLimitFatalError,"MemoryAllocationFailed",
136 wand->name);
137 (void) ResetMagickMemory(clone_wand,0,sizeof(*clone_wand));
138 clone_wand->id=AcquireWandId();
cristyb51dff52011-05-19 16:55:47 +0000139 (void) FormatLocaleString(clone_wand->name,MaxTextExtent,"%s-%.20g",
cristye8c25f92010-06-03 00:53:06 +0000140 MagickWandId,(double) clone_wand->id);
cristy3ed852e2009-09-05 21:47:34 +0000141 clone_wand->exception=AcquireExceptionInfo();
142 InheritException(clone_wand->exception,wand->exception);
143 clone_wand->image_info=CloneImageInfo(wand->image_info);
cristy3ed852e2009-09-05 21:47:34 +0000144 clone_wand->images=CloneImageList(wand->images,clone_wand->exception);
anthonyade6afb2012-03-15 13:24:43 +0000145 clone_wand->insert_before=MagickFalse;
146 clone_wand->image_pending=MagickFalse;
cristy3ed852e2009-09-05 21:47:34 +0000147 clone_wand->debug=IsEventLogging();
148 if (clone_wand->debug != MagickFalse)
149 (void) LogMagickEvent(WandEvent,GetMagickModule(),"%s",clone_wand->name);
150 clone_wand->signature=WandSignature;
151 return(clone_wand);
152}
153
154/*
155%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
156% %
157% %
158% %
159% D e s t r o y M a g i c k W a n d %
160% %
161% %
162% %
163%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
164%
165% DestroyMagickWand() deallocates memory associated with an MagickWand.
166%
167% The format of the DestroyMagickWand method is:
168%
169% MagickWand *DestroyMagickWand(MagickWand *wand)
170%
171% A description of each parameter follows:
172%
173% o wand: the magick wand.
174%
175*/
176WandExport MagickWand *DestroyMagickWand(MagickWand *wand)
177{
178 assert(wand != (MagickWand *) NULL);
179 assert(wand->signature == WandSignature);
180 if (wand->debug != MagickFalse)
181 (void) LogMagickEvent(WandEvent,GetMagickModule(),"%s",wand->name);
anthonyd2706c72012-02-10 12:51:17 +0000182 wand->images=DestroyImageList(wand->images);
anthonyd2706c72012-02-10 12:51:17 +0000183 if (wand->image_info != (ImageInfo *) NULL )
184 wand->image_info=DestroyImageInfo(wand->image_info);
185 if (wand->exception != (ExceptionInfo *) NULL )
186 wand->exception=DestroyExceptionInfo(wand->exception);
cristy3ed852e2009-09-05 21:47:34 +0000187 RelinquishWandId(wand->id);
188 wand->signature=(~WandSignature);
189 wand=(MagickWand *) RelinquishMagickMemory(wand);
190 return(wand);
191}
192
193/*
194%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
195% %
196% %
197% %
198% I s M a g i c k W a n d %
199% %
200% %
201% %
202%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
203%
204% IsMagickWand() returns MagickTrue if the wand is verified as a magick wand.
205%
206% The format of the IsMagickWand method is:
207%
208% MagickBooleanType IsMagickWand(const MagickWand *wand)
209%
210% A description of each parameter follows:
211%
212% o wand: the magick wand.
213%
214*/
215WandExport MagickBooleanType IsMagickWand(const MagickWand *wand)
216{
217 if (wand == (const MagickWand *) NULL)
218 return(MagickFalse);
219 if (wand->signature != WandSignature)
220 return(MagickFalse);
221 if (LocaleNCompare(wand->name,MagickWandId,strlen(MagickWandId)) != 0)
222 return(MagickFalse);
223 return(MagickTrue);
224}
225
226/*
227%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
228% %
229% %
230% %
231% M a g i c k C l e a r E x c e p t i o n %
232% %
233% %
234% %
235%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
236%
237% MagickClearException() clears any exceptions associated with the wand.
238%
239% The format of the MagickClearException method is:
240%
241% MagickBooleanType MagickClearException(MagickWand *wand)
242%
243% A description of each parameter follows:
244%
245% o wand: the magick wand.
246%
247*/
248WandExport MagickBooleanType MagickClearException(MagickWand *wand)
249{
250 assert(wand != (MagickWand *) NULL);
251 assert(wand->signature == WandSignature);
252 if (wand->debug != MagickFalse)
253 (void) LogMagickEvent(WandEvent,GetMagickModule(),"%s",wand->name);
254 ClearMagickException(wand->exception);
255 return(MagickTrue);
256}
257
258/*
259%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
260% %
261% %
262% %
263% M a g i c k G e t E x c e p t i o n %
264% %
265% %
266% %
267%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
268%
269% MagickGetException() returns the severity, reason, and description of any
270% error that occurs when using other methods in this API.
271%
272% The format of the MagickGetException method is:
273%
274% char *MagickGetException(const MagickWand *wand,ExceptionType *severity)
275%
276% A description of each parameter follows:
277%
278% o wand: the magick wand.
279%
280% o severity: the severity of the error is returned here.
281%
282*/
283WandExport char *MagickGetException(const MagickWand *wand,
284 ExceptionType *severity)
285{
286 char
287 *description;
288
289 assert(wand != (const MagickWand *) NULL);
290 assert(wand->signature == WandSignature);
291 if (wand->debug != MagickFalse)
292 (void) LogMagickEvent(WandEvent,GetMagickModule(),"%s",wand->name);
293 assert(severity != (ExceptionType *) NULL);
294 *severity=wand->exception->severity;
295 description=(char *) AcquireQuantumMemory(2UL*MaxTextExtent,
296 sizeof(*description));
297 if (description == (char *) NULL)
298 {
299 (void) ThrowMagickException(wand->exception,GetMagickModule(),WandError,
cristyefe601c2013-01-05 17:51:12 +0000300 "MemoryAllocationFailed","`%s'",wand->name);
cristy3ed852e2009-09-05 21:47:34 +0000301 return((char *) NULL);
302 }
303 *description='\0';
304 if (wand->exception->reason != (char *) NULL)
305 (void) CopyMagickString(description,GetLocaleExceptionMessage(
306 wand->exception->severity,wand->exception->reason),MaxTextExtent);
307 if (wand->exception->description != (char *) NULL)
308 {
309 (void) ConcatenateMagickString(description," (",MaxTextExtent);
310 (void) ConcatenateMagickString(description,GetLocaleExceptionMessage(
311 wand->exception->severity,wand->exception->description),MaxTextExtent);
312 (void) ConcatenateMagickString(description,")",MaxTextExtent);
313 }
314 return(description);
315}
316
317/*
318%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
319% %
320% %
321% %
anthonyfd706f92012-01-19 04:22:02 +0000322% M a g i c k G e t E x c e p t i o n T y p e %
cristy3ed852e2009-09-05 21:47:34 +0000323% %
324% %
325% %
326%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
327%
328% MagickGetExceptionType() returns the exception type associated with the
329% wand. If no exception has occurred, UndefinedExceptionType is returned.
330%
331% The format of the MagickGetExceptionType method is:
332%
333% ExceptionType MagickGetExceptionType(const MagickWand *wand)
334%
335% A description of each parameter follows:
336%
337% o wand: the magick wand.
338%
339*/
340WandExport ExceptionType MagickGetExceptionType(const MagickWand *wand)
341{
342 assert(wand != (MagickWand *) NULL);
343 assert(wand->signature == WandSignature);
344 if (wand->debug != MagickFalse)
345 (void) LogMagickEvent(WandEvent,GetMagickModule(),"%s",wand->name);
346 return(wand->exception->severity);
347}
348
349/*
350%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
351% %
352% %
353% %
354% M a g i c k G e t I t e r a t o r I n d e x %
355% %
356% %
357% %
358%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
359%
360% MagickGetIteratorIndex() returns the position of the iterator in the image
361% list.
362%
363% The format of the MagickGetIteratorIndex method is:
364%
cristybb503372010-05-27 20:51:26 +0000365% ssize_t MagickGetIteratorIndex(MagickWand *wand)
cristy3ed852e2009-09-05 21:47:34 +0000366%
367% A description of each parameter follows:
368%
369% o wand: the magick wand.
370%
371*/
cristybb503372010-05-27 20:51:26 +0000372WandExport ssize_t MagickGetIteratorIndex(MagickWand *wand)
cristy3ed852e2009-09-05 21:47:34 +0000373{
374 assert(wand != (MagickWand *) NULL);
375 assert(wand->signature == WandSignature);
376 if (wand->debug != MagickFalse)
377 (void) LogMagickEvent(WandEvent,GetMagickModule(),"%s",wand->name);
378 if (wand->images == (Image *) NULL)
379 {
380 (void) ThrowMagickException(wand->exception,GetMagickModule(),WandError,
cristyefe601c2013-01-05 17:51:12 +0000381 "ContainsNoIterators","`%s'",wand->name);
cristy3ed852e2009-09-05 21:47:34 +0000382 return(-1);
383 }
384 return(GetImageIndexInList(wand->images));
385}
386
387/*
388%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
389% %
390% %
391% %
392% 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 %
393% %
394% %
395% %
396%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
397%
398% MagickQueryConfigureOption() returns the value associated with the specified
399% configure option.
400%
401% The format of the MagickQueryConfigureOption function is:
402%
403% char *MagickQueryConfigureOption(const char *option)
404%
405% A description of each parameter follows:
406%
407% o option: the option name.
408%
409*/
410WandExport char *MagickQueryConfigureOption(const char *option)
411{
412 char
413 *value;
414
415 const ConfigureInfo
416 **configure_info;
417
418 ExceptionInfo
419 *exception;
420
cristybb503372010-05-27 20:51:26 +0000421 size_t
cristy3ed852e2009-09-05 21:47:34 +0000422 number_options;
423
424 exception=AcquireExceptionInfo();
425 configure_info=GetConfigureInfoList(option,&number_options,exception);
426 exception=DestroyExceptionInfo(exception);
427 if (configure_info == (const ConfigureInfo **) NULL)
428 return((char *) NULL);
429 value=AcquireString(configure_info[0]->value);
430 configure_info=(const ConfigureInfo **)
431 RelinquishMagickMemory((void *) configure_info);
432 return(value);
433}
434
435/*
436%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
437% %
438% %
439% %
440% 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 %
441% %
442% %
443% %
444%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
445%
446% MagickQueryConfigureOptions() returns any configure options that match the
447% specified pattern (e.g. "*" for all). Options include NAME, VERSION,
448% LIB_VERSION, etc.
449%
450% The format of the MagickQueryConfigureOptions function is:
451%
452% char **MagickQueryConfigureOptions(const char *pattern,
cristybb503372010-05-27 20:51:26 +0000453% size_t *number_options)
cristy3ed852e2009-09-05 21:47:34 +0000454%
455% A description of each parameter follows:
456%
457% o pattern: Specifies a pointer to a text string containing a pattern.
458%
459% o number_options: Returns the number of configure options in the list.
460%
461%
462*/
463WandExport char **MagickQueryConfigureOptions(const char *pattern,
cristybb503372010-05-27 20:51:26 +0000464 size_t *number_options)
cristy3ed852e2009-09-05 21:47:34 +0000465{
466 char
467 **options;
468
469 ExceptionInfo
470 *exception;
471
472 exception=AcquireExceptionInfo();
473 options=GetConfigureList(pattern,number_options,exception);
474 exception=DestroyExceptionInfo(exception);
475 return(options);
476}
477
478/*
479%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
480% %
481% %
482% %
483% M a g i c k Q u e r y F o n t M e t r i c s %
484% %
485% %
486% %
487%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
488%
489% MagickQueryFontMetrics() returns a 13 element array representing the
490% following font metrics:
491%
492% Element Description
493% -------------------------------------------------
494% 0 character width
495% 1 character height
496% 2 ascender
497% 3 descender
498% 4 text width
499% 5 text height
500% 6 maximum horizontal advance
501% 7 bounding box: x1
502% 8 bounding box: y1
503% 9 bounding box: x2
504% 10 bounding box: y2
505% 11 origin: x
506% 12 origin: y
507%
508% The format of the MagickQueryFontMetrics method is:
509%
510% double *MagickQueryFontMetrics(MagickWand *wand,
511% const DrawingWand *drawing_wand,const char *text)
512%
513% A description of each parameter follows:
514%
515% o wand: the Magick wand.
516%
517% o drawing_wand: the drawing wand.
518%
519% o text: the text.
520%
521*/
522WandExport double *MagickQueryFontMetrics(MagickWand *wand,
523 const DrawingWand *drawing_wand,const char *text)
524{
525 double
526 *font_metrics;
527
528 DrawInfo
529 *draw_info;
530
531 MagickBooleanType
532 status;
533
534 TypeMetric
535 metrics;
536
537 assert(wand != (MagickWand *) NULL);
538 assert(wand->signature == WandSignature);
539 if (wand->debug != MagickFalse)
540 (void) LogMagickEvent(WandEvent,GetMagickModule(),"%s",wand->name);
541 assert(drawing_wand != (const DrawingWand *) NULL);
542 if (wand->images == (Image *) NULL)
543 {
544 (void) ThrowMagickException(wand->exception,GetMagickModule(),WandError,
cristyefe601c2013-01-05 17:51:12 +0000545 "ContainsNoImages","`%s'",wand->name);
cristy3ed852e2009-09-05 21:47:34 +0000546 return((double *) NULL);
547 }
548 font_metrics=(double *) AcquireQuantumMemory(13UL,sizeof(*font_metrics));
549 if (font_metrics == (double *) NULL)
550 return((double *) NULL);
551 draw_info=PeekDrawingWand(drawing_wand);
552 if (draw_info == (DrawInfo *) NULL)
553 {
554 font_metrics=(double *) RelinquishMagickMemory(font_metrics);
555 return((double *) NULL);
556 }
557 (void) CloneString(&draw_info->text,text);
558 (void) ResetMagickMemory(&metrics,0,sizeof(metrics));
cristycad4e1b2011-10-16 14:58:39 +0000559 status=GetTypeMetrics(wand->images,draw_info,&metrics,wand->exception);
cristy3ed852e2009-09-05 21:47:34 +0000560 draw_info=DestroyDrawInfo(draw_info);
561 if (status == MagickFalse)
562 {
cristy3ed852e2009-09-05 21:47:34 +0000563 font_metrics=(double *) RelinquishMagickMemory(font_metrics);
564 return((double *) NULL);
565 }
566 font_metrics[0]=metrics.pixels_per_em.x;
567 font_metrics[1]=metrics.pixels_per_em.y;
568 font_metrics[2]=metrics.ascent;
569 font_metrics[3]=metrics.descent;
570 font_metrics[4]=metrics.width;
571 font_metrics[5]=metrics.height;
572 font_metrics[6]=metrics.max_advance;
573 font_metrics[7]=metrics.bounds.x1;
574 font_metrics[8]=metrics.bounds.y1;
575 font_metrics[9]=metrics.bounds.x2;
576 font_metrics[10]=metrics.bounds.y2;
577 font_metrics[11]=metrics.origin.x;
578 font_metrics[12]=metrics.origin.y;
579 return(font_metrics);
580}
581
582/*
583%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
584% %
585% %
586% %
587% 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 %
588% %
589% %
590% %
591%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
592%
593% MagickQueryMultilineFontMetrics() returns a 13 element array representing the
594% following font metrics:
595%
596% Element Description
597% -------------------------------------------------
598% 0 character width
599% 1 character height
600% 2 ascender
601% 3 descender
602% 4 text width
603% 5 text height
604% 6 maximum horizontal advance
605% 7 bounding box: x1
606% 8 bounding box: y1
607% 9 bounding box: x2
608% 10 bounding box: y2
609% 11 origin: x
610% 12 origin: y
611%
612% This method is like MagickQueryFontMetrics() but it returns the maximum text
613% width and height for multiple lines of text.
614%
615% The format of the MagickQueryFontMetrics method is:
616%
617% double *MagickQueryMultilineFontMetrics(MagickWand *wand,
618% const DrawingWand *drawing_wand,const char *text)
619%
620% A description of each parameter follows:
621%
622% o wand: the Magick wand.
623%
624% o drawing_wand: the drawing wand.
625%
626% o text: the text.
627%
628*/
629WandExport double *MagickQueryMultilineFontMetrics(MagickWand *wand,
630 const DrawingWand *drawing_wand,const char *text)
631{
632 double
633 *font_metrics;
634
635 DrawInfo
636 *draw_info;
637
638 MagickBooleanType
639 status;
640
641 TypeMetric
642 metrics;
643
644 assert(wand != (MagickWand *) NULL);
645 assert(wand->signature == WandSignature);
646 if (wand->debug != MagickFalse)
647 (void) LogMagickEvent(WandEvent,GetMagickModule(),"%s",wand->name);
648 assert(drawing_wand != (const DrawingWand *) NULL);
649 if (wand->images == (Image *) NULL)
650 {
651 (void) ThrowMagickException(wand->exception,GetMagickModule(),WandError,
cristyefe601c2013-01-05 17:51:12 +0000652 "ContainsNoImages","`%s'",wand->name);
cristy3ed852e2009-09-05 21:47:34 +0000653 return((double *) NULL);
654 }
655 font_metrics=(double *) AcquireQuantumMemory(13UL,sizeof(*font_metrics));
656 if (font_metrics == (double *) NULL)
657 return((double *) NULL);
658 draw_info=PeekDrawingWand(drawing_wand);
659 if (draw_info == (DrawInfo *) NULL)
660 {
661 font_metrics=(double *) RelinquishMagickMemory(font_metrics);
662 return((double *) NULL);
663 }
664 (void) CloneString(&draw_info->text,text);
665 (void) ResetMagickMemory(&metrics,0,sizeof(metrics));
cristy5cbc0162011-08-29 00:36:28 +0000666 status=GetMultilineTypeMetrics(wand->images,draw_info,&metrics,
cristycad4e1b2011-10-16 14:58:39 +0000667 wand->exception);
cristy3ed852e2009-09-05 21:47:34 +0000668 draw_info=DestroyDrawInfo(draw_info);
669 if (status == MagickFalse)
670 {
cristy3ed852e2009-09-05 21:47:34 +0000671 font_metrics=(double *) RelinquishMagickMemory(font_metrics);
672 return((double *) NULL);
673 }
674 font_metrics[0]=metrics.pixels_per_em.x;
675 font_metrics[1]=metrics.pixels_per_em.y;
676 font_metrics[2]=metrics.ascent;
677 font_metrics[3]=metrics.descent;
678 font_metrics[4]=metrics.width;
679 font_metrics[5]=metrics.height;
680 font_metrics[6]=metrics.max_advance;
681 font_metrics[7]=metrics.bounds.x1;
682 font_metrics[8]=metrics.bounds.y1;
683 font_metrics[9]=metrics.bounds.x2;
684 font_metrics[10]=metrics.bounds.y2;
685 font_metrics[11]=metrics.origin.x;
686 font_metrics[12]=metrics.origin.y;
687 return(font_metrics);
688}
689
690/*
691%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
692% %
693% %
694% %
695% M a g i c k Q u e r y F o n t s %
696% %
697% %
698% %
699%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
700%
701% MagickQueryFonts() returns any font that match the specified pattern (e.g.
702% "*" for all).
703%
704% The format of the MagickQueryFonts function is:
705%
cristybb503372010-05-27 20:51:26 +0000706% char **MagickQueryFonts(const char *pattern,size_t *number_fonts)
cristy3ed852e2009-09-05 21:47:34 +0000707%
708% A description of each parameter follows:
709%
710% o pattern: Specifies a pointer to a text string containing a pattern.
711%
712% o number_fonts: Returns the number of fonts in the list.
713%
714%
715*/
716WandExport char **MagickQueryFonts(const char *pattern,
cristybb503372010-05-27 20:51:26 +0000717 size_t *number_fonts)
cristy3ed852e2009-09-05 21:47:34 +0000718{
719 char
720 **fonts;
721
722 ExceptionInfo
723 *exception;
724
725 exception=AcquireExceptionInfo();
726 fonts=GetTypeList(pattern,number_fonts,exception);
727 exception=DestroyExceptionInfo(exception);
728 return(fonts);
729}
730
731/*
732%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
733% %
734% %
735% %
736% M a g i c k Q u e r y F o r m a t s %
737% %
738% %
739% %
740%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
741%
742% MagickQueryFonts() returns any image formats that match the specified
743% pattern (e.g. "*" for all).
744%
745% The format of the MagickQueryFonts function is:
746%
747% char **MagickQueryFonts(const char *pattern,
cristybb503372010-05-27 20:51:26 +0000748% size_t *number_formats)
cristy3ed852e2009-09-05 21:47:34 +0000749%
750% A description of each parameter follows:
751%
752% o pattern: Specifies a pointer to a text string containing a pattern.
753%
754% o number_formats: This integer returns the number of image formats in the
755% list.
756%
757*/
758WandExport char **MagickQueryFormats(const char *pattern,
cristybb503372010-05-27 20:51:26 +0000759 size_t *number_formats)
cristy3ed852e2009-09-05 21:47:34 +0000760{
761 char
762 **formats;
763
764 ExceptionInfo
765 *exception;
766
767 exception=AcquireExceptionInfo();
768 formats=GetMagickList(pattern,number_formats,exception);
769 exception=DestroyExceptionInfo(exception);
770 return(formats);
771}
772
773/*
774%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
775% %
776% %
777% %
778% M a g i c k R e l i n q u i s h M e m o r y %
779% %
780% %
781% %
782%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
783%
784% MagickRelinquishMemory() relinquishes memory resources returned by such
785% methods as MagickIdentifyImage(), MagickGetException(), etc.
786%
787% The format of the MagickRelinquishMemory method is:
788%
789% void *MagickRelinquishMemory(void *resource)
790%
791% A description of each parameter follows:
792%
793% o resource: Relinquish the memory associated with this resource.
794%
795*/
796WandExport void *MagickRelinquishMemory(void *memory)
797{
798 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
799 return(RelinquishMagickMemory(memory));
800}
801
802/*
803%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
804% %
805% %
806% %
807% M a g i c k R e s e t I t e r a t o r %
808% %
809% %
810% %
811%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
812%
anthonyf93964e2012-03-16 08:25:58 +0000813% MagickResetIterator() resets the wand iterator.
814%
815% It is typically used either before iterating though images, or before
816% calling specific functions such as MagickAppendImages() to append all
817% images together.
818%
819% Afterward you can use MagickNextImage() to iterate over all the images
820% in a wand container, starting with the first image.
821%
822% Using this before MagickAddImages() or MagickReadImages() will cause
823% new images to be inserted between the first and second image.
cristy3ed852e2009-09-05 21:47:34 +0000824%
825% The format of the MagickResetIterator method is:
826%
827% void MagickResetIterator(MagickWand *wand)
828%
829% A description of each parameter follows:
830%
831% o wand: the magick wand.
832%
833*/
834WandExport void MagickResetIterator(MagickWand *wand)
835{
836 assert(wand != (MagickWand *) NULL);
837 assert(wand->signature == WandSignature);
838 if (wand->debug != MagickFalse)
839 (void) LogMagickEvent(WandEvent,GetMagickModule(),"%s",wand->name);
cristy3ed852e2009-09-05 21:47:34 +0000840 wand->images=GetFirstImageInList(wand->images);
anthony45083312012-03-14 14:49:12 +0000841 wand->insert_before=MagickFalse; /* Insert/add after current (first) image */
anthonyade6afb2012-03-15 13:24:43 +0000842 wand->image_pending=MagickTrue; /* NextImage will set first image */
cristy3ed852e2009-09-05 21:47:34 +0000843}
844
845/*
846%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
847% %
848% %
849% %
850% M a g i c k S e t F i r s t I t e r a t o r %
851% %
852% %
853% %
854%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
855%
856% MagickSetFirstIterator() sets the wand iterator to the first image.
857%
anthonyf93964e2012-03-16 08:25:58 +0000858% After using any images added to the wand using MagickAddImage() or
859% MagickReadImage() will be prepended before any image in the wand.
860%
861% Also the current image has been set to the first image (if any) in the
862% Magick Wand. Using MagickNextImage() will then set teh current image
863% to the second image in the list (if present).
864%
865% This operation is similar to MagickResetIterator() but differs in how
866% MagickAddImage(), MagickReadImage(), and MagickNextImage() behaves
867% afterward.
anthonye8f56492012-02-12 12:39:02 +0000868%
cristy3ed852e2009-09-05 21:47:34 +0000869% The format of the MagickSetFirstIterator method is:
870%
871% void MagickSetFirstIterator(MagickWand *wand)
872%
873% A description of each parameter follows:
874%
875% o wand: the magick wand.
876%
877*/
878WandExport void MagickSetFirstIterator(MagickWand *wand)
879{
880 assert(wand != (MagickWand *) NULL);
881 assert(wand->signature == WandSignature);
882 if (wand->debug != MagickFalse)
883 (void) LogMagickEvent(WandEvent,GetMagickModule(),"%s",wand->name);
cristy3ed852e2009-09-05 21:47:34 +0000884 wand->images=GetFirstImageInList(wand->images);
anthony45083312012-03-14 14:49:12 +0000885 wand->insert_before=MagickTrue; /* Insert/add before the first image */
886 wand->image_pending=MagickFalse; /* NextImage will set next image */
cristy3ed852e2009-09-05 21:47:34 +0000887}
888
889/*
890%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
891% %
892% %
893% %
894% M a g i c k S e t I t e r a t o r I n d e x %
895% %
896% %
897% %
898%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
899%
anthonyf93964e2012-03-16 08:25:58 +0000900% MagickSetIteratorIndex() set the iterator to the given position in the
901% image list specified with the index parameter. A zero index will set
902% the first image as current, and so on. Negative indexes can be used
903% to specify an image relative to the end of the images in the wand, with
904% -1 being the last image in the wand.
905%
906% If the index is invalid (range too large for number of images in wand)
anthony2778ac92012-03-18 10:54:08 +0000907% the function will return MagickFalse, but no 'exception' will be raised,
anthonyf93964e2012-03-16 08:25:58 +0000908% as it is not actually an error. In that case the current image will not
909% change.
910%
911% After using any images added to the wand using MagickAddImage() or
912% MagickReadImage() will be added after the image indexed, regardless
913% of if a zero (first image in list) or negative index (from end) is used.
914%
915% Jumping to index 0 is similar to MagickResetIterator() but differs in how
916% MagickNextImage() behaves afterward.
cristy3ed852e2009-09-05 21:47:34 +0000917%
918% The format of the MagickSetIteratorIndex method is:
919%
920% MagickBooleanType MagickSetIteratorIndex(MagickWand *wand,
cristybb503372010-05-27 20:51:26 +0000921% const ssize_t index)
cristy3ed852e2009-09-05 21:47:34 +0000922%
923% A description of each parameter follows:
924%
925% o wand: the magick wand.
926%
927% o index: the scene number.
928%
929*/
930WandExport MagickBooleanType MagickSetIteratorIndex(MagickWand *wand,
cristybb503372010-05-27 20:51:26 +0000931 const ssize_t index)
cristy3ed852e2009-09-05 21:47:34 +0000932{
933 Image
934 *image;
935
936 assert(wand != (MagickWand *) NULL);
937 assert(wand->signature == WandSignature);
938 if (wand->debug != MagickFalse)
939 (void) LogMagickEvent(WandEvent,GetMagickModule(),"%s",wand->name);
940 if (wand->images == (Image *) NULL)
941 return(MagickFalse);
942 image=GetImageFromList(wand->images,index);
943 if (image == (Image *) NULL)
anthony2778ac92012-03-18 10:54:08 +0000944 return(MagickFalse); /* this is not an exception! Just range error. */
cristy3ed852e2009-09-05 21:47:34 +0000945 wand->images=image;
anthony45083312012-03-14 14:49:12 +0000946 wand->insert_before=MagickFalse; /* Insert/Add after (this) image */
947 wand->image_pending=MagickFalse; /* NextImage will set next image */
cristy3ed852e2009-09-05 21:47:34 +0000948 return(MagickTrue);
949}
950/*
951%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
952% %
953% %
954% %
955% M a g i c k S e t L a s t I t e r a t o r %
956% %
957% %
958% %
959%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
960%
961% MagickSetLastIterator() sets the wand iterator to the last image.
962%
anthonyf93964e2012-03-16 08:25:58 +0000963% The last image is actually the current image, and the next use of
964% MagickPreviousImage() will not change this allowing this function to be
965% used to iterate over the images in the reverse direction. In this sense it
966% is more like MagickResetIterator() than MagickSetFirstIterator().
967%
968% Typically this function is used before MagickAddImage(), MagickReadImage()
969% functions to ensure new images are appended to the very end of wand's image
970% list.
anthonye8f56492012-02-12 12:39:02 +0000971%
cristy3ed852e2009-09-05 21:47:34 +0000972% The format of the MagickSetLastIterator method is:
973%
974% void MagickSetLastIterator(MagickWand *wand)
975%
976% A description of each parameter follows:
977%
978% o wand: the magick wand.
979%
980*/
981WandExport void MagickSetLastIterator(MagickWand *wand)
982{
983 assert(wand != (MagickWand *) NULL);
984 assert(wand->signature == WandSignature);
985 if (wand->debug != MagickFalse)
986 (void) LogMagickEvent(WandEvent,GetMagickModule(),"%s",wand->name);
cristy3ed852e2009-09-05 21:47:34 +0000987 wand->images=GetLastImageInList(wand->images);
anthony45083312012-03-14 14:49:12 +0000988 wand->insert_before=MagickFalse; /* Insert/add after current (last) image */
anthonyf93964e2012-03-16 08:25:58 +0000989 wand->image_pending=MagickTrue; /* PreviousImage will return last image */
cristy3ed852e2009-09-05 21:47:34 +0000990}
991
992/*
993%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
994% %
995% %
996% %
997% M a g i c k W a n d G e n e s i s %
998% %
999% %
1000% %
1001%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1002%
1003% MagickWandGenesis() initializes the MagickWand environment.
1004%
1005% The format of the MagickWandGenesis method is:
1006%
1007% void MagickWandGenesis(void)
1008%
1009*/
1010WandExport void MagickWandGenesis(void)
1011{
1012 if (IsMagickInstantiated() == MagickFalse)
1013 MagickCoreGenesis((char *) NULL,MagickFalse);
1014}
1015
1016/*
1017%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1018% %
1019% %
1020% %
1021% M a g i c k W a n d T e r m i n u s %
1022% %
1023% %
1024% %
1025%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1026%
1027% MagickWandTerminus() terminates the MagickWand environment.
1028%
1029% The format of the MaickWandTerminus method is:
1030%
1031% void MagickWandTerminus(void)
1032%
1033*/
1034WandExport void MagickWandTerminus(void)
1035{
1036 DestroyWandIds();
1037 MagickCoreTerminus();
1038}
1039
1040/*
1041%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1042% %
1043% %
1044% %
1045% N e w M a g i c k W a n d %
1046% %
1047% %
1048% %
1049%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1050%
1051% NewMagickWand() returns a wand required for all other methods in the API.
cristyae75b042011-04-17 18:30:49 +00001052% A fatal exception is thrown if there is not enough memory to allocate the
1053% wand. Use DestroyMagickWand() to dispose of the wand when it is no longer
1054% needed.
cristy3ed852e2009-09-05 21:47:34 +00001055%
1056% The format of the NewMagickWand method is:
1057%
1058% MagickWand *NewMagickWand(void)
1059%
1060*/
1061WandExport MagickWand *NewMagickWand(void)
1062{
1063 const char
1064 *quantum;
1065
1066 MagickWand
1067 *wand;
1068
cristybb503372010-05-27 20:51:26 +00001069 size_t
cristy3ed852e2009-09-05 21:47:34 +00001070 depth;
1071
1072 depth=MAGICKCORE_QUANTUM_DEPTH;
1073 quantum=GetMagickQuantumDepth(&depth);
1074 if (depth != MAGICKCORE_QUANTUM_DEPTH)
1075 ThrowWandFatalException(WandError,"QuantumDepthMismatch",quantum);
cristy73bd4a52010-10-05 11:24:23 +00001076 wand=(MagickWand *) AcquireMagickMemory(sizeof(*wand));
cristy3ed852e2009-09-05 21:47:34 +00001077 if (wand == (MagickWand *) NULL)
1078 ThrowWandFatalException(ResourceLimitFatalError,"MemoryAllocationFailed",
1079 GetExceptionMessage(errno));
1080 (void) ResetMagickMemory(wand,0,sizeof(*wand));
1081 wand->id=AcquireWandId();
cristyb51dff52011-05-19 16:55:47 +00001082 (void) FormatLocaleString(wand->name,MaxTextExtent,"%s-%.20g",MagickWandId,
cristye8c25f92010-06-03 00:53:06 +00001083 (double) wand->id);
cristy3ed852e2009-09-05 21:47:34 +00001084 wand->images=NewImageList();
anthonya89dd172011-10-04 13:29:35 +00001085 wand->image_info=AcquireImageInfo();
anthonya89dd172011-10-04 13:29:35 +00001086 wand->exception=AcquireExceptionInfo();
cristy3ed852e2009-09-05 21:47:34 +00001087 wand->debug=IsEventLogging();
1088 if (wand->debug != MagickFalse)
1089 (void) LogMagickEvent(WandEvent,GetMagickModule(),"%s",wand->name);
1090 wand->signature=WandSignature;
1091 return(wand);
1092}
1093
1094/*
1095%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1096% %
1097% %
1098% %
1099% N e w M a g i c k W a n d F r o m I m a g e %
1100% %
1101% %
1102% %
1103%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1104%
1105% NewMagickWandFromImage() returns a wand with an image.
1106%
1107% The format of the NewMagickWandFromImage method is:
1108%
1109% MagickWand *NewMagickWandFromImage(const Image *image)
1110%
1111% A description of each parameter follows:
1112%
1113% o image: the image.
1114%
1115*/
1116WandExport MagickWand *NewMagickWandFromImage(const Image *image)
1117{
1118 MagickWand
1119 *wand;
1120
1121 wand=NewMagickWand();
1122 wand->images=CloneImage(image,0,0,MagickTrue,wand->exception);
1123 return(wand);
1124}