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