]> granicus.if.org Git - imagemagick/blob - MagickWand/magick-wand.c
Removed 3 redundant lines of code from coders/png.c
[imagemagick] / MagickWand / magick-wand.c
1 /*
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 %                                                                             %
26 %  Copyright 1999-2012 ImageMagick Studio LLC, a non-profit organization      %
27 %  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 \f
46 /*
47   Include declarations.
48 */
49 #include "MagickWand/studio.h"
50 #include "MagickWand/MagickWand.h"
51 #include "MagickWand/magick-wand-private.h"
52 #include "MagickWand/wand.h"
53 \f
54 /*
55   Define declarations.
56 */
57 #define ThrowWandException(severity,tag,context) \
58 { \
59   (void) ThrowMagickException(wand->exception,GetMagickModule(),severity, \
60     tag,"`%s'",context); \
61   return(MagickFalse); \
62 }
63 \f
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 %
75 %  ClearMagickWand() clears resources associated with the wand, leaving the
76 %  wand blank, and ready to be used for a new set of images.
77 %
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 */
87 WandExport 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);
93   wand->images=DestroyImageList(wand->images);
94   if (wand->quantize_info != (QuantizeInfo *) NULL )
95     wand->quantize_info=DestroyQuantizeInfo(wand->quantize_info);
96   if (wand->draw_info != (DrawInfo *) NULL )
97     wand->draw_info=DestroyDrawInfo(wand->draw_info);
98   wand->image_info=AcquireImageInfo();
99   ClearMagickException(wand->exception);
100   wand->debug=IsEventLogging();
101 }
102 \f
103 /*
104 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
105 %                                                                             %
106 %                                                                             %
107 %                                                                             %
108 %   C l o n e M a g i c k W a n d                                             %
109 %                                                                             %
110 %                                                                             %
111 %                                                                             %
112 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
113 %
114 %  CloneMagickWand() makes an exact copy of the specified wand.
115 %
116 %  The format of the CloneMagickWand method is:
117 %
118 %      MagickWand *CloneMagickWand(const MagickWand *wand)
119 %
120 %  A description of each parameter follows:
121 %
122 %    o wand: the magick wand.
123 %
124 */
125 WandExport MagickWand *CloneMagickWand(const MagickWand *wand)
126 {
127   MagickWand
128     *clone_wand;
129
130   assert(wand != (MagickWand *) NULL);
131   assert(wand->signature == WandSignature);
132   if (wand->debug != MagickFalse)
133     (void) LogMagickEvent(WandEvent,GetMagickModule(),"%s",wand->name);
134   clone_wand=(MagickWand *) AcquireMagickMemory(sizeof(*clone_wand));
135   if (clone_wand == (MagickWand *) NULL)
136     ThrowWandFatalException(ResourceLimitFatalError,"MemoryAllocationFailed",
137       wand->name);
138   (void) ResetMagickMemory(clone_wand,0,sizeof(*clone_wand));
139   clone_wand->id=AcquireWandId();
140   (void) FormatLocaleString(clone_wand->name,MaxTextExtent,"%s-%.20g",
141     MagickWandId,(double) clone_wand->id);
142   clone_wand->exception=AcquireExceptionInfo();
143   InheritException(clone_wand->exception,wand->exception);
144   clone_wand->image_info=CloneImageInfo(wand->image_info);
145   if ( wand->quantize_info == (QuantizeInfo *) NULL )
146     clone_wand->quantize_info=(QuantizeInfo *) NULL;
147   else
148     clone_wand->quantize_info=CloneQuantizeInfo(wand->quantize_info);
149   if ( wand->draw_info == (DrawInfo *) NULL )
150     clone_wand->draw_info=(DrawInfo *) NULL;
151   else
152     clone_wand->draw_info=CloneDrawInfo(wand->image_info,wand->draw_info);
153   clone_wand->images=CloneImageList(wand->images,clone_wand->exception);
154   clone_wand->debug=IsEventLogging();
155   if (clone_wand->debug != MagickFalse)
156     (void) LogMagickEvent(WandEvent,GetMagickModule(),"%s",clone_wand->name);
157   clone_wand->signature=WandSignature;
158   return(clone_wand);
159 }
160 \f
161 /*
162 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
163 %                                                                             %
164 %                                                                             %
165 %                                                                             %
166 %   D e s t r o y M a g i c k W a n d                                         %
167 %                                                                             %
168 %                                                                             %
169 %                                                                             %
170 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
171 %
172 %  DestroyMagickWand() deallocates memory associated with an MagickWand.
173 %
174 %  The format of the DestroyMagickWand method is:
175 %
176 %      MagickWand *DestroyMagickWand(MagickWand *wand)
177 %
178 %  A description of each parameter follows:
179 %
180 %    o wand: the magick wand.
181 %
182 */
183 WandExport MagickWand *DestroyMagickWand(MagickWand *wand)
184 {
185   assert(wand != (MagickWand *) NULL);
186   assert(wand->signature == WandSignature);
187   if (wand->debug != MagickFalse)
188     (void) LogMagickEvent(WandEvent,GetMagickModule(),"%s",wand->name);
189   if (wand->quantize_info != (QuantizeInfo *) NULL )
190     wand->quantize_info=DestroyQuantizeInfo(wand->quantize_info);
191   if (wand->draw_info != (DrawInfo *) NULL )
192     wand->draw_info=DestroyDrawInfo(wand->draw_info);
193   wand->image_info=DestroyImageInfo(wand->image_info);
194   wand->images=DestroyImageList(wand->images);
195   wand->exception=DestroyExceptionInfo(wand->exception);
196   RelinquishWandId(wand->id);
197   wand->signature=(~WandSignature);
198   wand=(MagickWand *) RelinquishMagickMemory(wand);
199   return(wand);
200 }
201 \f
202 /*
203 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
204 %                                                                             %
205 %                                                                             %
206 %                                                                             %
207 %   I s M a g i c k W a n d                                                   %
208 %                                                                             %
209 %                                                                             %
210 %                                                                             %
211 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
212 %
213 %  IsMagickWand() returns MagickTrue if the wand is verified as a magick wand.
214 %
215 %  The format of the IsMagickWand method is:
216 %
217 %      MagickBooleanType IsMagickWand(const MagickWand *wand)
218 %
219 %  A description of each parameter follows:
220 %
221 %    o wand: the magick wand.
222 %
223 */
224 WandExport MagickBooleanType IsMagickWand(const MagickWand *wand)
225 {
226   if (wand == (const MagickWand *) NULL)
227     return(MagickFalse);
228   if (wand->signature != WandSignature)
229     return(MagickFalse);
230   if (LocaleNCompare(wand->name,MagickWandId,strlen(MagickWandId)) != 0)
231     return(MagickFalse);
232   return(MagickTrue);
233 }
234 \f
235 /*
236 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
237 %                                                                             %
238 %                                                                             %
239 %                                                                             %
240 %   M a g i c k C l e a r E x c e p t i o n                                   %
241 %                                                                             %
242 %                                                                             %
243 %                                                                             %
244 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
245 %
246 %  MagickClearException() clears any exceptions associated with the wand.
247 %
248 %  The format of the MagickClearException method is:
249 %
250 %      MagickBooleanType MagickClearException(MagickWand *wand)
251 %
252 %  A description of each parameter follows:
253 %
254 %    o wand: the magick wand.
255 %
256 */
257 WandExport MagickBooleanType MagickClearException(MagickWand *wand)
258 {
259   assert(wand != (MagickWand *) NULL);
260   assert(wand->signature == WandSignature);
261   if (wand->debug != MagickFalse)
262     (void) LogMagickEvent(WandEvent,GetMagickModule(),"%s",wand->name);
263   ClearMagickException(wand->exception);
264   return(MagickTrue);
265 }
266 \f
267 /*
268 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
269 %                                                                             %
270 %                                                                             %
271 %                                                                             %
272 %   M a g i c k G e t E x c e p t i o n                                       %
273 %                                                                             %
274 %                                                                             %
275 %                                                                             %
276 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
277 %
278 %  MagickGetException() returns the severity, reason, and description of any
279 %  error that occurs when using other methods in this API.
280 %
281 %  The format of the MagickGetException method is:
282 %
283 %      char *MagickGetException(const MagickWand *wand,ExceptionType *severity)
284 %
285 %  A description of each parameter follows:
286 %
287 %    o wand: the magick wand.
288 %
289 %    o severity: the severity of the error is returned here.
290 %
291 */
292 WandExport char *MagickGetException(const MagickWand *wand,
293   ExceptionType *severity)
294 {
295   char
296     *description;
297
298   assert(wand != (const MagickWand *) NULL);
299   assert(wand->signature == WandSignature);
300   if (wand->debug != MagickFalse)
301     (void) LogMagickEvent(WandEvent,GetMagickModule(),"%s",wand->name);
302   assert(severity != (ExceptionType *) NULL);
303   *severity=wand->exception->severity;
304   description=(char *) AcquireQuantumMemory(2UL*MaxTextExtent,
305     sizeof(*description));
306   if (description == (char *) NULL)
307     {
308       (void) ThrowMagickException(wand->exception,GetMagickModule(),WandError,
309         "MemoryAllocationFailed","`%s'",wand->name);
310       return((char *) NULL);
311     }
312   *description='\0';
313   if (wand->exception->reason != (char *) NULL)
314     (void) CopyMagickString(description,GetLocaleExceptionMessage(
315       wand->exception->severity,wand->exception->reason),MaxTextExtent);
316   if (wand->exception->description != (char *) NULL)
317     {
318       (void) ConcatenateMagickString(description," (",MaxTextExtent);
319       (void) ConcatenateMagickString(description,GetLocaleExceptionMessage(
320         wand->exception->severity,wand->exception->description),MaxTextExtent);
321       (void) ConcatenateMagickString(description,")",MaxTextExtent);
322     }
323   return(description);
324 }
325 \f
326 /*
327 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
328 %                                                                             %
329 %                                                                             %
330 %                                                                             %
331 %   M a g i c k G e t  E x c e p t i o n T y p e                              %
332 %                                                                             %
333 %                                                                             %
334 %                                                                             %
335 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
336 %
337 %  MagickGetExceptionType() returns the exception type associated with the
338 %  wand.  If no exception has occurred, UndefinedExceptionType is returned.
339 %
340 %  The format of the MagickGetExceptionType method is:
341 %
342 %      ExceptionType MagickGetExceptionType(const MagickWand *wand)
343 %
344 %  A description of each parameter follows:
345 %
346 %    o wand: the magick wand.
347 %
348 */
349 WandExport ExceptionType MagickGetExceptionType(const MagickWand *wand)
350 {
351   assert(wand != (MagickWand *) NULL);
352   assert(wand->signature == WandSignature);
353   if (wand->debug != MagickFalse)
354     (void) LogMagickEvent(WandEvent,GetMagickModule(),"%s",wand->name);
355   return(wand->exception->severity);
356 }
357 \f
358 /*
359 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
360 %                                                                             %
361 %                                                                             %
362 %                                                                             %
363 %   M a g i c k G e t I t e r a t o r I n d e x                               %
364 %                                                                             %
365 %                                                                             %
366 %                                                                             %
367 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
368 %
369 %  MagickGetIteratorIndex() returns the position of the iterator in the image
370 %  list.
371 %
372 %  The format of the MagickGetIteratorIndex method is:
373 %
374 %      ssize_t MagickGetIteratorIndex(MagickWand *wand)
375 %
376 %  A description of each parameter follows:
377 %
378 %    o wand: the magick wand.
379 %
380 */
381 WandExport ssize_t MagickGetIteratorIndex(MagickWand *wand)
382 {
383   assert(wand != (MagickWand *) NULL);
384   assert(wand->signature == WandSignature);
385   if (wand->debug != MagickFalse)
386     (void) LogMagickEvent(WandEvent,GetMagickModule(),"%s",wand->name);
387   if (wand->images == (Image *) NULL)
388     {
389       (void) ThrowMagickException(wand->exception,GetMagickModule(),WandError,
390         "ContainsNoIterators","`%s'",wand->name);
391       return(-1);
392     }
393   return(GetImageIndexInList(wand->images));
394 }
395 \f
396 /*
397 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
398 %                                                                             %
399 %                                                                             %
400 %                                                                             %
401 %   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                       %
402 %                                                                             %
403 %                                                                             %
404 %                                                                             %
405 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
406 %
407 %  MagickQueryConfigureOption() returns the value associated with the specified
408 %  configure option.
409 %
410 %  The format of the MagickQueryConfigureOption function is:
411 %
412 %      char *MagickQueryConfigureOption(const char *option)
413 %
414 %  A description of each parameter follows:
415 %
416 %    o option: the option name.
417 %
418 */
419 WandExport char *MagickQueryConfigureOption(const char *option)
420 {
421   char
422     *value;
423
424   const ConfigureInfo
425     **configure_info;
426
427   ExceptionInfo
428     *exception;
429
430   size_t
431     number_options;
432
433   exception=AcquireExceptionInfo();
434   configure_info=GetConfigureInfoList(option,&number_options,exception);
435   exception=DestroyExceptionInfo(exception);
436   if (configure_info == (const ConfigureInfo **) NULL)
437     return((char *) NULL);
438   value=AcquireString(configure_info[0]->value);
439   configure_info=(const ConfigureInfo **)
440     RelinquishMagickMemory((void *) configure_info);
441   return(value);
442 }
443 \f
444 /*
445 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
446 %                                                                             %
447 %                                                                             %
448 %                                                                             %
449 %   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                     %
450 %                                                                             %
451 %                                                                             %
452 %                                                                             %
453 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
454 %
455 %  MagickQueryConfigureOptions() returns any configure options that match the
456 %  specified pattern (e.g.  "*" for all).  Options include NAME, VERSION,
457 %  LIB_VERSION, etc.
458 %
459 %  The format of the MagickQueryConfigureOptions function is:
460 %
461 %      char **MagickQueryConfigureOptions(const char *pattern,
462 %        size_t *number_options)
463 %
464 %  A description of each parameter follows:
465 %
466 %    o pattern: Specifies a pointer to a text string containing a pattern.
467 %
468 %    o number_options:  Returns the number of configure options in the list.
469 %
470 %
471 */
472 WandExport char **MagickQueryConfigureOptions(const char *pattern,
473   size_t *number_options)
474 {
475   char
476     **options;
477
478   ExceptionInfo
479     *exception;
480
481   exception=AcquireExceptionInfo();
482   options=GetConfigureList(pattern,number_options,exception);
483   exception=DestroyExceptionInfo(exception);
484   return(options);
485 }
486 \f
487 /*
488 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
489 %                                                                             %
490 %                                                                             %
491 %                                                                             %
492 %   M a g i c k Q u e r y F o n t M e t r i c s                               %
493 %                                                                             %
494 %                                                                             %
495 %                                                                             %
496 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
497 %
498 %  MagickQueryFontMetrics() returns a 13 element array representing the
499 %  following font metrics:
500 %
501 %    Element Description
502 %    -------------------------------------------------
503 %          0 character width
504 %          1 character height
505 %          2 ascender
506 %          3 descender
507 %          4 text width
508 %          5 text height
509 %          6 maximum horizontal advance
510 %          7 bounding box: x1
511 %          8 bounding box: y1
512 %          9 bounding box: x2
513 %         10 bounding box: y2
514 %         11 origin: x
515 %         12 origin: y
516 %
517 %  The format of the MagickQueryFontMetrics method is:
518 %
519 %      double *MagickQueryFontMetrics(MagickWand *wand,
520 %        const DrawingWand *drawing_wand,const char *text)
521 %
522 %  A description of each parameter follows:
523 %
524 %    o wand: the Magick wand.
525 %
526 %    o drawing_wand: the drawing wand.
527 %
528 %    o text: the text.
529 %
530 */
531 WandExport double *MagickQueryFontMetrics(MagickWand *wand,
532   const DrawingWand *drawing_wand,const char *text)
533 {
534   double
535     *font_metrics;
536
537   DrawInfo
538     *draw_info;
539
540   MagickBooleanType
541     status;
542
543   TypeMetric
544     metrics;
545
546   assert(wand != (MagickWand *) NULL);
547   assert(wand->signature == WandSignature);
548   if (wand->debug != MagickFalse)
549     (void) LogMagickEvent(WandEvent,GetMagickModule(),"%s",wand->name);
550   assert(drawing_wand != (const DrawingWand *) NULL);
551   if (wand->images == (Image *) NULL)
552     {
553       (void) ThrowMagickException(wand->exception,GetMagickModule(),WandError,
554         "ContainsNoImages","`%s'",wand->name);
555       return((double *) NULL);
556     }
557   font_metrics=(double *) AcquireQuantumMemory(13UL,sizeof(*font_metrics));
558   if (font_metrics == (double *) NULL)
559     return((double *) NULL);
560   draw_info=PeekDrawingWand(drawing_wand);
561   if (draw_info == (DrawInfo *) NULL)
562     {
563       font_metrics=(double *) RelinquishMagickMemory(font_metrics);
564       return((double *) NULL);
565     }
566   (void) CloneString(&draw_info->text,text);
567   (void) ResetMagickMemory(&metrics,0,sizeof(metrics));
568   status=GetTypeMetrics(wand->images,draw_info,&metrics,wand->exception);
569   draw_info=DestroyDrawInfo(draw_info);
570   if (status == MagickFalse)
571     {
572       font_metrics=(double *) RelinquishMagickMemory(font_metrics);
573       return((double *) NULL);
574     }
575   font_metrics[0]=metrics.pixels_per_em.x;
576   font_metrics[1]=metrics.pixels_per_em.y;
577   font_metrics[2]=metrics.ascent;
578   font_metrics[3]=metrics.descent;
579   font_metrics[4]=metrics.width;
580   font_metrics[5]=metrics.height;
581   font_metrics[6]=metrics.max_advance;
582   font_metrics[7]=metrics.bounds.x1;
583   font_metrics[8]=metrics.bounds.y1;
584   font_metrics[9]=metrics.bounds.x2;
585   font_metrics[10]=metrics.bounds.y2;
586   font_metrics[11]=metrics.origin.x;
587   font_metrics[12]=metrics.origin.y;
588   return(font_metrics);
589 }
590 \f
591 /*
592 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
593 %                                                                             %
594 %                                                                             %
595 %                                                                             %
596 %   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             %
597 %                                                                             %
598 %                                                                             %
599 %                                                                             %
600 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
601 %
602 %  MagickQueryMultilineFontMetrics() returns a 13 element array representing the
603 %  following font metrics:
604 %
605 %    Element Description
606 %    -------------------------------------------------
607 %          0 character width
608 %          1 character height
609 %          2 ascender
610 %          3 descender
611 %          4 text width
612 %          5 text height
613 %          6 maximum horizontal advance
614 %          7 bounding box: x1
615 %          8 bounding box: y1
616 %          9 bounding box: x2
617 %         10 bounding box: y2
618 %         11 origin: x
619 %         12 origin: y
620 %
621 %  This method is like MagickQueryFontMetrics() but it returns the maximum text
622 %  width and height for multiple lines of text.
623 %
624 %  The format of the MagickQueryFontMetrics method is:
625 %
626 %      double *MagickQueryMultilineFontMetrics(MagickWand *wand,
627 %        const DrawingWand *drawing_wand,const char *text)
628 %
629 %  A description of each parameter follows:
630 %
631 %    o wand: the Magick wand.
632 %
633 %    o drawing_wand: the drawing wand.
634 %
635 %    o text: the text.
636 %
637 */
638 WandExport double *MagickQueryMultilineFontMetrics(MagickWand *wand,
639   const DrawingWand *drawing_wand,const char *text)
640 {
641   double
642     *font_metrics;
643
644   DrawInfo
645     *draw_info;
646
647   MagickBooleanType
648     status;
649
650   TypeMetric
651     metrics;
652
653   assert(wand != (MagickWand *) NULL);
654   assert(wand->signature == WandSignature);
655   if (wand->debug != MagickFalse)
656     (void) LogMagickEvent(WandEvent,GetMagickModule(),"%s",wand->name);
657   assert(drawing_wand != (const DrawingWand *) NULL);
658   if (wand->images == (Image *) NULL)
659     {
660       (void) ThrowMagickException(wand->exception,GetMagickModule(),WandError,
661         "ContainsNoImages","`%s'",wand->name);
662       return((double *) NULL);
663     }
664   font_metrics=(double *) AcquireQuantumMemory(13UL,sizeof(*font_metrics));
665   if (font_metrics == (double *) NULL)
666     return((double *) NULL);
667   draw_info=PeekDrawingWand(drawing_wand);
668   if (draw_info == (DrawInfo *) NULL)
669     {
670       font_metrics=(double *) RelinquishMagickMemory(font_metrics);
671       return((double *) NULL);
672     }
673   (void) CloneString(&draw_info->text,text);
674   (void) ResetMagickMemory(&metrics,0,sizeof(metrics));
675   status=GetMultilineTypeMetrics(wand->images,draw_info,&metrics,
676     wand->exception);
677   draw_info=DestroyDrawInfo(draw_info);
678   if (status == MagickFalse)
679     {
680       font_metrics=(double *) RelinquishMagickMemory(font_metrics);
681       return((double *) NULL);
682     }
683   font_metrics[0]=metrics.pixels_per_em.x;
684   font_metrics[1]=metrics.pixels_per_em.y;
685   font_metrics[2]=metrics.ascent;
686   font_metrics[3]=metrics.descent;
687   font_metrics[4]=metrics.width;
688   font_metrics[5]=metrics.height;
689   font_metrics[6]=metrics.max_advance;
690   font_metrics[7]=metrics.bounds.x1;
691   font_metrics[8]=metrics.bounds.y1;
692   font_metrics[9]=metrics.bounds.x2;
693   font_metrics[10]=metrics.bounds.y2;
694   font_metrics[11]=metrics.origin.x;
695   font_metrics[12]=metrics.origin.y;
696   return(font_metrics);
697 }
698 \f
699 /*
700 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
701 %                                                                             %
702 %                                                                             %
703 %                                                                             %
704 %   M a g i c k Q u e r y F o n t s                                           %
705 %                                                                             %
706 %                                                                             %
707 %                                                                             %
708 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
709 %
710 %  MagickQueryFonts() returns any font that match the specified pattern (e.g.
711 %  "*" for all).
712 %
713 %  The format of the MagickQueryFonts function is:
714 %
715 %      char **MagickQueryFonts(const char *pattern,size_t *number_fonts)
716 %
717 %  A description of each parameter follows:
718 %
719 %    o pattern: Specifies a pointer to a text string containing a pattern.
720 %
721 %    o number_fonts:  Returns the number of fonts in the list.
722 %
723 %
724 */
725 WandExport char **MagickQueryFonts(const char *pattern,
726   size_t *number_fonts)
727 {
728   char
729     **fonts;
730
731   ExceptionInfo
732     *exception;
733
734   exception=AcquireExceptionInfo();
735   fonts=GetTypeList(pattern,number_fonts,exception);
736   exception=DestroyExceptionInfo(exception);
737   return(fonts);
738 }
739 \f
740 /*
741 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
742 %                                                                             %
743 %                                                                             %
744 %                                                                             %
745 %   M a g i c k Q u e r y F o r m a t s                                       %
746 %                                                                             %
747 %                                                                             %
748 %                                                                             %
749 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
750 %
751 %  MagickQueryFonts() returns any image formats that match the specified
752 %  pattern (e.g.  "*" for all).
753 %
754 %  The format of the MagickQueryFonts function is:
755 %
756 %      char **MagickQueryFonts(const char *pattern,
757 %        size_t *number_formats)
758 %
759 %  A description of each parameter follows:
760 %
761 %    o pattern: Specifies a pointer to a text string containing a pattern.
762 %
763 %    o number_formats:  This integer returns the number of image formats in the
764 %      list.
765 %
766 */
767 WandExport char **MagickQueryFormats(const char *pattern,
768   size_t *number_formats)
769 {
770   char
771     **formats;
772
773   ExceptionInfo
774     *exception;
775
776   exception=AcquireExceptionInfo();
777   formats=GetMagickList(pattern,number_formats,exception);
778   exception=DestroyExceptionInfo(exception);
779   return(formats);
780 }
781 \f
782 /*
783 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
784 %                                                                             %
785 %                                                                             %
786 %                                                                             %
787 %   M a g i c k R e l i n q u i s h M e m o r y                               %
788 %                                                                             %
789 %                                                                             %
790 %                                                                             %
791 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
792 %
793 %  MagickRelinquishMemory() relinquishes memory resources returned by such
794 %  methods as MagickIdentifyImage(), MagickGetException(), etc.
795 %
796 %  The format of the MagickRelinquishMemory method is:
797 %
798 %      void *MagickRelinquishMemory(void *resource)
799 %
800 %  A description of each parameter follows:
801 %
802 %    o resource: Relinquish the memory associated with this resource.
803 %
804 */
805 WandExport void *MagickRelinquishMemory(void *memory)
806 {
807   (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
808   return(RelinquishMagickMemory(memory));
809 }
810 \f
811 /*
812 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
813 %                                                                             %
814 %                                                                             %
815 %                                                                             %
816 %   M a g i c k R e s e t I t e r a t o r                                     %
817 %                                                                             %
818 %                                                                             %
819 %                                                                             %
820 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
821 %
822 %  MagickResetIterator() resets the wand iterator.  Use it in conjunction
823 %  with MagickNextImage() to iterate over all the images in a wand
824 %  container.
825 %
826 %  The format of the MagickResetIterator method is:
827 %
828 %      void MagickResetIterator(MagickWand *wand)
829 %
830 %  A description of each parameter follows:
831 %
832 %    o wand: the magick wand.
833 %
834 */
835 WandExport void MagickResetIterator(MagickWand *wand)
836 {
837   assert(wand != (MagickWand *) NULL);
838   assert(wand->signature == WandSignature);
839   if (wand->debug != MagickFalse)
840     (void) LogMagickEvent(WandEvent,GetMagickModule(),"%s",wand->name);
841   wand->images=GetFirstImageInList(wand->images);
842   wand->set_first=MagickFalse;    /* we did not jump to the first image */
843   wand->image_pending=MagickTrue; /* this image is the 'next' image */
844 }
845 \f
846 /*
847 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
848 %                                                                             %
849 %                                                                             %
850 %                                                                             %
851 %   M a g i c k S e t F i r s t I t e r a t o r                               %
852 %                                                                             %
853 %                                                                             %
854 %                                                                             %
855 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
856 %
857 %  MagickSetFirstIterator() sets the wand iterator to the first image.
858 %
859 %  The format of the MagickSetFirstIterator method is:
860 %
861 %      void MagickSetFirstIterator(MagickWand *wand)
862 %
863 %  A description of each parameter follows:
864 %
865 %    o wand: the magick wand.
866 %
867 */
868 WandExport void MagickSetFirstIterator(MagickWand *wand)
869 {
870   assert(wand != (MagickWand *) NULL);
871   assert(wand->signature == WandSignature);
872   if (wand->debug != MagickFalse)
873     (void) LogMagickEvent(WandEvent,GetMagickModule(),"%s",wand->name);
874   wand->images=GetFirstImageInList(wand->images);
875   wand->set_first=MagickTrue;       /* we jumped to the first image */
876   wand->image_pending=MagickFalse;  /* but this image is not 'next' */
877 }
878 \f
879 /*
880 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
881 %                                                                             %
882 %                                                                             %
883 %                                                                             %
884 %   M a g i c k S e t I t e r a t o r I n d e x                               %
885 %                                                                             %
886 %                                                                             %
887 %                                                                             %
888 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
889 %
890 %  MagickSetIteratorIndex() set the iterator to the position in the image list
891 %  specified with the index parameter.
892 %
893 %  The format of the MagickSetIteratorIndex method is:
894 %
895 %      MagickBooleanType MagickSetIteratorIndex(MagickWand *wand,
896 %        const ssize_t index)
897 %
898 %  A description of each parameter follows:
899 %
900 %    o wand: the magick wand.
901 %
902 %    o index: the scene number.
903 %
904 */
905 WandExport MagickBooleanType MagickSetIteratorIndex(MagickWand *wand,
906   const ssize_t index)
907 {
908   Image
909     *image;
910
911   assert(wand != (MagickWand *) NULL);
912   assert(wand->signature == WandSignature);
913   if (wand->debug != MagickFalse)
914     (void) LogMagickEvent(WandEvent,GetMagickModule(),"%s",wand->name);
915   if (wand->images == (Image *) NULL)
916     return(MagickFalse);
917   image=GetImageFromList(wand->images,index);
918   if (image == (Image *) NULL)
919     {
920       (void) ThrowMagickException(wand->exception,GetMagickModule(),WandError,
921         "NoSuchImage","`%s'",wand->name);
922       return(MagickFalse);
923     }
924   wand->images=image;
925   wand->set_first=MagickFalse;     /* we are not at very start of list */
926   wand->image_pending=MagickFalse; /* but it is not iteration pending */
927   return(MagickTrue);
928 }
929 /*
930 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
931 %                                                                             %
932 %                                                                             %
933 %                                                                             %
934 %   M a g i c k S e t L a s t I t e r a t o r                                 %
935 %                                                                             %
936 %                                                                             %
937 %                                                                             %
938 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
939 %
940 %  MagickSetLastIterator() sets the wand iterator to the last image.
941 %
942 %  The format of the MagickSetLastIterator method is:
943 %
944 %      void MagickSetLastIterator(MagickWand *wand)
945 %
946 %  A description of each parameter follows:
947 %
948 %    o wand: the magick wand.
949 %
950 */
951 WandExport void MagickSetLastIterator(MagickWand *wand)
952 {
953   assert(wand != (MagickWand *) NULL);
954   assert(wand->signature == WandSignature);
955   if (wand->debug != MagickFalse)
956     (void) LogMagickEvent(WandEvent,GetMagickModule(),"%s",wand->name);
957   wand->images=GetLastImageInList(wand->images);
958   wand->set_first=MagickFalse;     /* we are not at very start of list */
959   wand->image_pending=MagickFalse; /* and is not iteration pending  */
960 }
961 \f
962 /*
963 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
964 %                                                                             %
965 %                                                                             %
966 %                                                                             %
967 %   M a g i c k W a n d G e n e s i s                                         %
968 %                                                                             %
969 %                                                                             %
970 %                                                                             %
971 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
972 %
973 %  MagickWandGenesis() initializes the MagickWand environment.
974 %
975 %  The format of the MagickWandGenesis method is:
976 %
977 %      void MagickWandGenesis(void)
978 %
979 */
980 WandExport void MagickWandGenesis(void)
981 {
982   if (IsMagickInstantiated() == MagickFalse)
983     MagickCoreGenesis((char *) NULL,MagickFalse);
984 }
985 \f
986 /*
987 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
988 %                                                                             %
989 %                                                                             %
990 %                                                                             %
991 %   M a g i c k W a n d T e r m i n u s                                       %
992 %                                                                             %
993 %                                                                             %
994 %                                                                             %
995 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
996 %
997 %  MagickWandTerminus() terminates the MagickWand environment.
998 %
999 %  The format of the MaickWandTerminus method is:
1000 %
1001 %      void MagickWandTerminus(void)
1002 %
1003 */
1004 WandExport void MagickWandTerminus(void)
1005 {
1006   DestroyWandIds();
1007   MagickCoreTerminus();
1008 }
1009 \f
1010 /*
1011 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1012 %                                                                             %
1013 %                                                                             %
1014 %                                                                             %
1015 %   N e w M a g i c k W a n d                                                 %
1016 %                                                                             %
1017 %                                                                             %
1018 %                                                                             %
1019 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1020 %
1021 %  NewMagickWand() returns a wand required for all other methods in the API.
1022 %  A fatal exception is thrown if there is not enough memory to allocate the
1023 %  wand.   Use DestroyMagickWand() to dispose of the wand when it is no longer
1024 %  needed.
1025 %
1026 %  The format of the NewMagickWand method is:
1027 %
1028 %      MagickWand *NewMagickWand(void)
1029 %
1030 */
1031 WandExport MagickWand *NewMagickWand(void)
1032 {
1033   const char
1034     *quantum;
1035
1036   MagickWand
1037     *wand;
1038
1039   size_t
1040     depth;
1041
1042   depth=MAGICKCORE_QUANTUM_DEPTH;
1043   quantum=GetMagickQuantumDepth(&depth);
1044   if (depth != MAGICKCORE_QUANTUM_DEPTH)
1045     ThrowWandFatalException(WandError,"QuantumDepthMismatch",quantum);
1046   wand=(MagickWand *) AcquireMagickMemory(sizeof(*wand));
1047   if (wand == (MagickWand *) NULL)
1048     ThrowWandFatalException(ResourceLimitFatalError,"MemoryAllocationFailed",
1049       GetExceptionMessage(errno));
1050   (void) ResetMagickMemory(wand,0,sizeof(*wand));
1051   wand->id=AcquireWandId();
1052   (void) FormatLocaleString(wand->name,MaxTextExtent,"%s-%.20g",MagickWandId,
1053     (double) wand->id);
1054   wand->images=NewImageList();
1055   wand->image_info=AcquireImageInfo();
1056   wand->quantize_info=(QuantizeInfo *) NULL; /* not used in MagickWand API */
1057   wand->draw_info=(DrawInfo *) NULL;         /* not used in MagickWand API */
1058   wand->exception=AcquireExceptionInfo();
1059   wand->debug=IsEventLogging();
1060   if (wand->debug != MagickFalse)
1061     (void) LogMagickEvent(WandEvent,GetMagickModule(),"%s",wand->name);
1062   wand->signature=WandSignature;
1063   return(wand);
1064 }
1065 \f
1066 /*
1067 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1068 %                                                                             %
1069 %                                                                             %
1070 %                                                                             %
1071 %   N e w M a g i c k W a n d F r o m I m a g e                               %
1072 %                                                                             %
1073 %                                                                             %
1074 %                                                                             %
1075 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1076 %
1077 %  NewMagickWandFromImage() returns a wand with an image.
1078 %
1079 %  The format of the NewMagickWandFromImage method is:
1080 %
1081 %      MagickWand *NewMagickWandFromImage(const Image *image)
1082 %
1083 %  A description of each parameter follows:
1084 %
1085 %    o image: the image.
1086 %
1087 */
1088 WandExport MagickWand *NewMagickWandFromImage(const Image *image)
1089 {
1090   MagickWand
1091     *wand;
1092
1093   wand=NewMagickWand();
1094   wand->images=CloneImage(image,0,0,MagickTrue,wand->exception);
1095   return(wand);
1096 }