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