MagickWand  6.8.9
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 % MagickQueryFonts() returns any image formats that match the specified
739 % pattern (e.g. "*" for all).
740 %
741 % The format of the MagickQueryFonts function is:
742 %
743 % char **MagickQueryFonts(const char *pattern,
744 % size_t *number_formats)
745 %
746 % A description of each parameter follows:
747 %
748 % o pattern: Specifies a pointer to a text string containing a pattern.
749 %
750 % o number_formats: This integer returns the number of image formats in the
751 % list.
752 %
753 */
754 WandExport char **MagickQueryFormats(const char *pattern,
755  size_t *number_formats)
756 {
757  char
758  **formats;
759 
760  ExceptionInfo
761  *exception;
762 
763  exception=AcquireExceptionInfo();
764  formats=GetMagickList(pattern,number_formats,exception);
765  exception=DestroyExceptionInfo(exception);
766  return(formats);
767 }
768 
769 /*
770 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
771 % %
772 % %
773 % %
774 % M a g i c k R e l i n q u i s h M e m o r y %
775 % %
776 % %
777 % %
778 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
779 %
780 % MagickRelinquishMemory() relinquishes memory resources returned by such
781 % methods as MagickIdentifyImage(), MagickGetException(), etc.
782 %
783 % The format of the MagickRelinquishMemory method is:
784 %
785 % void *MagickRelinquishMemory(void *resource)
786 %
787 % A description of each parameter follows:
788 %
789 % o resource: Relinquish the memory associated with this resource.
790 %
791 */
793 {
794  (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
795  return(RelinquishMagickMemory(memory));
796 }
797 
798 /*
799 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
800 % %
801 % %
802 % %
803 % M a g i c k R e s e t I t e r a t o r %
804 % %
805 % %
806 % %
807 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
808 %
809 % MagickResetIterator() resets the wand iterator.
810 %
811 % It is typically used either before iterating though images, or before
812 % calling specific functions such as MagickAppendImages() to append all
813 % images together.
814 %
815 % Afterward you can use MagickNextImage() to iterate over all the images
816 % in a wand container, starting with the first image.
817 %
818 % Using this before MagickAddImages() or MagickReadImages() will cause
819 % new images to be inserted between the first and second image.
820 %
821 % The format of the MagickResetIterator method is:
822 %
823 % void MagickResetIterator(MagickWand *wand)
824 %
825 % A description of each parameter follows:
826 %
827 % o wand: the magick wand.
828 %
829 */
831 {
832  assert(wand != (MagickWand *) NULL);
833  assert(wand->signature == WandSignature);
834  if (wand->debug != MagickFalse)
835  (void) LogMagickEvent(WandEvent,GetMagickModule(),"%s",wand->name);
836  wand->images=GetFirstImageInList(wand->images);
837  wand->insert_before=MagickFalse; /* Insert/add after current (first) image */
838  wand->image_pending=MagickTrue; /* NextImage will set first image */
839 }
840 
841 /*
842 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
843 % %
844 % %
845 % %
846 % M a g i c k S e t F i r s t I t e r a t o r %
847 % %
848 % %
849 % %
850 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
851 %
852 % MagickSetFirstIterator() sets the wand iterator to the first image.
853 %
854 % After using any images added to the wand using MagickAddImage() or
855 % MagickReadImage() will be prepended before any image in the wand.
856 %
857 % Also the current image has been set to the first image (if any) in the
858 % Magick Wand. Using MagickNextImage() will then set teh current image
859 % to the second image in the list (if present).
860 %
861 % This operation is similar to MagickResetIterator() but differs in how
862 % MagickAddImage(), MagickReadImage(), and MagickNextImage() behaves
863 % afterward.
864 %
865 % The format of the MagickSetFirstIterator method is:
866 %
867 % void MagickSetFirstIterator(MagickWand *wand)
868 %
869 % A description of each parameter follows:
870 %
871 % o wand: the magick wand.
872 %
873 */
875 {
876  assert(wand != (MagickWand *) NULL);
877  assert(wand->signature == WandSignature);
878  if (wand->debug != MagickFalse)
879  (void) LogMagickEvent(WandEvent,GetMagickModule(),"%s",wand->name);
880  wand->images=GetFirstImageInList(wand->images);
881  wand->insert_before=MagickTrue; /* Insert/add before the first image */
882  wand->image_pending=MagickFalse; /* NextImage will set next image */
883 }
884 
885 /*
886 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
887 % %
888 % %
889 % %
890 % M a g i c k S e t I t e r a t o r I n d e x %
891 % %
892 % %
893 % %
894 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
895 %
896 % MagickSetIteratorIndex() set the iterator to the given position in the
897 % image list specified with the index parameter. A zero index will set
898 % the first image as current, and so on. Negative indexes can be used
899 % to specify an image relative to the end of the images in the wand, with
900 % -1 being the last image in the wand.
901 %
902 % If the index is invalid (range too large for number of images in wand)
903 % the function will return MagickFalse, but no 'exception' will be raised,
904 % as it is not actually an error. In that case the current image will not
905 % change.
906 %
907 % After using any images added to the wand using MagickAddImage() or
908 % MagickReadImage() will be added after the image indexed, regardless
909 % of if a zero (first image in list) or negative index (from end) is used.
910 %
911 % Jumping to index 0 is similar to MagickResetIterator() but differs in how
912 % MagickNextImage() behaves afterward.
913 %
914 % The format of the MagickSetIteratorIndex method is:
915 %
916 % MagickBooleanType MagickSetIteratorIndex(MagickWand *wand,
917 % const ssize_t index)
918 %
919 % A description of each parameter follows:
920 %
921 % o wand: the magick wand.
922 %
923 % o index: the scene number.
924 %
925 */
927  const ssize_t index)
928 {
929  Image
930  *image;
931 
932  assert(wand != (MagickWand *) NULL);
933  assert(wand->signature == WandSignature);
934  if (wand->debug != MagickFalse)
935  (void) LogMagickEvent(WandEvent,GetMagickModule(),"%s",wand->name);
936  if (wand->images == (Image *) NULL)
937  return(MagickFalse);
938  image=GetImageFromList(wand->images,index);
939  if (image == (Image *) NULL)
940  {
941  InheritException(wand->exception,&wand->images->exception);
942  return(MagickFalse);
943  }
944  wand->images=image;
945  wand->insert_before=MagickFalse; /* Insert/Add after (this) image */
946  wand->image_pending=MagickFalse; /* NextImage will set next image */
947  return(MagickTrue);
948 }
949 /*
950 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
951 % %
952 % %
953 % %
954 % M a g i c k S e t L a s t I t e r a t o r %
955 % %
956 % %
957 % %
958 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
959 %
960 % MagickSetLastIterator() sets the wand iterator to the last image.
961 %
962 % The last image is actually the current image, and the next use of
963 % MagickPreviousImage() will not change this allowing this function to be
964 % used to iterate over the images in the reverse direction. In this sense it
965 % is more like MagickResetIterator() than MagickSetFirstIterator().
966 %
967 % Typically this function is used before MagickAddImage(), MagickReadImage()
968 % functions to ensure new images are appended to the very end of wand's image
969 % list.
970 %
971 % The format of the MagickSetLastIterator method is:
972 %
973 % void MagickSetLastIterator(MagickWand *wand)
974 %
975 % A description of each parameter follows:
976 %
977 % o wand: the magick wand.
978 %
979 */
981 {
982  assert(wand != (MagickWand *) NULL);
983  assert(wand->signature == WandSignature);
984  if (wand->debug != MagickFalse)
985  (void) LogMagickEvent(WandEvent,GetMagickModule(),"%s",wand->name);
986  wand->images=GetLastImageInList(wand->images);
987  wand->insert_before=MagickFalse; /* Insert/add after current (last) image */
988  wand->image_pending=MagickTrue; /* PreviousImage will return last image */
989 }
990 
991 /*
992 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
993 % %
994 % %
995 % %
996 % M a g i c k W a n d G e n e s i s %
997 % %
998 % %
999 % %
1000 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1001 %
1002 % MagickWandGenesis() initializes the MagickWand environment.
1003 %
1004 % The format of the MagickWandGenesis method is:
1005 %
1006 % void MagickWandGenesis(void)
1007 %
1008 */
1010 {
1011  if (IsMagickCoreInstantiated() == MagickFalse)
1012  MagickCoreGenesis((char *) NULL,MagickFalse);
1013 }
1014 
1015 /*
1016 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1017 % %
1018 % %
1019 % %
1020 % M a g i c k W a n d T e r m i n u s %
1021 % %
1022 % %
1023 % %
1024 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1025 %
1026 % MagickWandTerminus() terminates the MagickWand environment.
1027 %
1028 % The format of the MaickWandTerminus method is:
1029 %
1030 % void MagickWandTerminus(void)
1031 %
1032 */
1034 {
1035  DestroyWandIds();
1036  MagickCoreTerminus();
1037 }
1038 
1039 /*
1040 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1041 % %
1042 % %
1043 % %
1044 % N e w M a g i c k W a n d %
1045 % %
1046 % %
1047 % %
1048 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1049 %
1050 % NewMagickWand() returns a wand required for all other methods in the API.
1051 % A fatal exception is thrown if there is not enough memory to allocate the
1052 % wand. Use DestroyMagickWand() to dispose of the wand when it is no longer
1053 % needed.
1054 %
1055 % The format of the NewMagickWand method is:
1056 %
1057 % MagickWand *NewMagickWand(void)
1058 %
1059 */
1061 {
1062  const char
1063  *quantum;
1064 
1065  MagickWand
1066  *wand;
1067 
1068  size_t
1069  depth;
1070 
1071  depth=MAGICKCORE_QUANTUM_DEPTH;
1072  quantum=GetMagickQuantumDepth(&depth);
1073  if (depth != MAGICKCORE_QUANTUM_DEPTH)
1074  ThrowWandFatalException(WandError,"QuantumDepthMismatch",quantum);
1075  wand=(MagickWand *) AcquireMagickMemory(sizeof(*wand));
1076  if (wand == (MagickWand *) NULL)
1077  ThrowWandFatalException(ResourceLimitFatalError,"MemoryAllocationFailed",
1078  GetExceptionMessage(errno));
1079  (void) ResetMagickMemory(wand,0,sizeof(*wand));
1080  wand->id=AcquireWandId();
1081  (void) FormatLocaleString(wand->name,MaxTextExtent,"%s-%.20g",MagickWandId,
1082  (double) wand->id);
1083  wand->images=NewImageList();
1084  wand->image_info=AcquireImageInfo();
1085  wand->exception=AcquireExceptionInfo();
1086  wand->quantize_info=CloneQuantizeInfo((QuantizeInfo *) NULL);
1087  wand->debug=IsEventLogging();
1088  if (wand->debug != MagickFalse)
1089  (void) LogMagickEvent(WandEvent,GetMagickModule(),"%s",wand->name);
1090  wand->signature=WandSignature;
1091  return(wand);
1092 }
1093 
1094 /*
1095 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1096 % %
1097 % %
1098 % %
1099 % N e w M a g i c k W a n d F r o m I m a g e %
1100 % %
1101 % %
1102 % %
1103 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1104 %
1105 % NewMagickWandFromImage() returns a wand with an image.
1106 %
1107 % The format of the NewMagickWandFromImage method is:
1108 %
1109 % MagickWand *NewMagickWandFromImage(const Image *image)
1110 %
1111 % A description of each parameter follows:
1112 %
1113 % o image: the image.
1114 %
1115 */
1117 {
1118  MagickWand
1119  *wand;
1120 
1121  wand=NewMagickWand();
1122  wand->images=CloneImage(image,0,0,MagickTrue,wand->exception);
1123  return(wand);
1124 }
1125 
1126 /*
1127 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1128 % %
1129 % %
1130 % %
1131 % I s M a g i c k W a n d I n s t a n t i a t e d %
1132 % %
1133 % %
1134 % %
1135 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1136 %
1137 % IsMagickWandInstantiated() returns MagickTrue if the ImageMagick environment
1138 % is currently instantiated-- that is, MagickWandGenesis() has been called but
1139 % MagickWandTerminus() has not.
1140 %
1141 % The format of the IsMagickWandInstantiated method is:
1142 %
1143 % MagickBooleanType IsMagickWandInstantiated(void)
1144 %
1145 */
1146 MagickExport MagickBooleanType IsMagickWandInstantiated(void)
1147 {
1148  return(IsMagickCoreInstantiated());
1149 }
#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:792
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:1146
#define WandExport
WandExport MagickWand * NewMagickWand(void)
Definition: magick-wand.c:1060
MagickBooleanType insert_before
WandExport MagickBooleanType MagickSetIteratorIndex(MagickWand *wand, const ssize_t index)
Definition: magick-wand.c:926
WandExport void MagickSetLastIterator(MagickWand *wand)
Definition: magick-wand.c:980
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:1033
WandExport void MagickWandGenesis(void)
Definition: magick-wand.c:1009
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:754
#define WandSignature
#define MagickWandId
Definition: magick-image.c:59
WandExport void MagickResetIterator(MagickWand *wand)
Definition: magick-wand.c:830
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:1116
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:874
WandExport char * MagickGetException(const MagickWand *wand, ExceptionType *severity)
Definition: magick-wand.c:278
ExceptionInfo * exception