]> granicus.if.org Git - imagemagick/blob - MagickCore/property.c
(no commit message)
[imagemagick] / MagickCore / property.c
1 /*
2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3 %                                                                             %
4 %                                                                             %
5 %                                                                             %
6 %            PPPP    RRRR    OOO   PPPP   EEEEE  RRRR   TTTTT  Y   Y          %
7 %            P   P   R   R  O   O  P   P  E      R   R    T     Y Y           %
8 %            PPPP    RRRR   O   O  PPPP   EEE    RRRR     T      Y            %
9 %            P       R R    O   O  P      E      R R      T      Y            %
10 %            P       R  R    OOO   P      EEEEE  R  R     T      Y            %
11 %                                                                             %
12 %                                                                             %
13 %                         MagickCore Property Methods                         %
14 %                                                                             %
15 %                              Software Design                                %
16 %                                John Cristy                                  %
17 %                                 March 2000                                  %
18 %                                                                             %
19 %                                                                             %
20 %  Copyright 1999-2011 ImageMagick Studio LLC, a non-profit organization      %
21 %  dedicated to making software imaging solutions freely available.           %
22 %                                                                             %
23 %  You may not use this file except in compliance with the License.  You may  %
24 %  obtain a copy of the License at                                            %
25 %                                                                             %
26 %    http://www.imagemagick.org/script/license.php                            %
27 %                                                                             %
28 %  Unless required by applicable law or agreed to in writing, software        %
29 %  distributed under the License is distributed on an "AS IS" BASIS,          %
30 %  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.   %
31 %  See the License for the specific language governing permissions and        %
32 %  limitations under the License.                                             %
33 %                                                                             %
34 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
35 %
36 %
37 %
38 */
39 \f
40 /*
41   Include declarations.
42 */
43 #include "MagickCore/studio.h"
44 #include "MagickCore/attribute.h"
45 #include "MagickCore/cache.h"
46 #include "MagickCore/color.h"
47 #include "MagickCore/compare.h"
48 #include "MagickCore/constitute.h"
49 #include "MagickCore/draw.h"
50 #include "MagickCore/effect.h"
51 #include "MagickCore/exception.h"
52 #include "MagickCore/exception-private.h"
53 #include "MagickCore/fx.h"
54 #include "MagickCore/fx-private.h"
55 #include "MagickCore/gem.h"
56 #include "MagickCore/geometry.h"
57 #include "MagickCore/histogram.h"
58 #include "MagickCore/image.h"
59 #include "MagickCore/image.h"
60 #include "MagickCore/layer.h"
61 #include "MagickCore/list.h"
62 #include "MagickCore/magick.h"
63 #include "MagickCore/memory_.h"
64 #include "MagickCore/monitor.h"
65 #include "MagickCore/montage.h"
66 #include "MagickCore/option.h"
67 #include "MagickCore/profile.h"
68 #include "MagickCore/property.h"
69 #include "MagickCore/quantum.h"
70 #include "MagickCore/resource_.h"
71 #include "MagickCore/splay-tree.h"
72 #include "MagickCore/signature-private.h"
73 #include "MagickCore/statistic.h"
74 #include "MagickCore/string_.h"
75 #include "MagickCore/string-private.h"
76 #include "MagickCore/token.h"
77 #include "MagickCore/utility.h"
78 #include "MagickCore/version.h"
79 #include "MagickCore/xml-tree.h"
80 \f
81 /*
82 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
83 %                                                                             %
84 %                                                                             %
85 %                                                                             %
86 %   C l o n e I m a g e P r o p e r t i e s                                   %
87 %                                                                             %
88 %                                                                             %
89 %                                                                             %
90 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
91 %
92 %  CloneImageProperties() clones one or more image properties.
93 %
94 %  The format of the CloneImageProperties method is:
95 %
96 %      MagickBooleanType CloneImageProperties(Image *image,
97 %        const Image *clone_image)
98 %
99 %  A description of each parameter follows:
100 %
101 %    o image: the image.
102 %
103 %    o clone_image: the clone image.
104 %
105 */
106 MagickExport MagickBooleanType CloneImageProperties(Image *image,
107   const Image *clone_image)
108 {
109   assert(image != (Image *) NULL);
110   assert(image->signature == MagickSignature);
111   if (image->debug != MagickFalse)
112     (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
113   assert(clone_image != (const Image *) NULL);
114   assert(clone_image->signature == MagickSignature);
115   if (clone_image->debug != MagickFalse)
116     (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
117       clone_image->filename);
118   (void) CopyMagickString(image->filename,clone_image->filename,MaxTextExtent);
119   (void) CopyMagickString(image->magick_filename,clone_image->magick_filename,
120     MaxTextExtent);
121   image->compression=clone_image->compression;
122   image->quality=clone_image->quality;
123   image->depth=clone_image->depth;
124   image->background_color=clone_image->background_color;
125   image->border_color=clone_image->border_color;
126   image->matte_color=clone_image->matte_color;
127   image->transparent_color=clone_image->transparent_color;
128   image->gamma=clone_image->gamma;
129   image->chromaticity=clone_image->chromaticity;
130   image->rendering_intent=clone_image->rendering_intent;
131   image->black_point_compensation=clone_image->black_point_compensation;
132   image->units=clone_image->units;
133   image->montage=(char *) NULL;
134   image->directory=(char *) NULL;
135   (void) CloneString(&image->geometry,clone_image->geometry);
136   image->offset=clone_image->offset;
137   image->x_resolution=clone_image->x_resolution;
138   image->y_resolution=clone_image->y_resolution;
139   image->page=clone_image->page;
140   image->tile_offset=clone_image->tile_offset;
141   image->extract_info=clone_image->extract_info;
142   image->bias=clone_image->bias;
143   image->filter=clone_image->filter;
144   image->blur=clone_image->blur;
145   image->fuzz=clone_image->fuzz;
146   image->interlace=clone_image->interlace;
147   image->interpolate=clone_image->interpolate;
148   image->endian=clone_image->endian;
149   image->gravity=clone_image->gravity;
150   image->compose=clone_image->compose;
151   image->scene=clone_image->scene;
152   image->orientation=clone_image->orientation;
153   image->dispose=clone_image->dispose;
154   image->delay=clone_image->delay;
155   image->ticks_per_second=clone_image->ticks_per_second;
156   image->iterations=clone_image->iterations;
157   image->total_colors=clone_image->total_colors;
158   image->taint=clone_image->taint;
159   image->progress_monitor=clone_image->progress_monitor;
160   image->client_data=clone_image->client_data;
161   image->start_loop=clone_image->start_loop;
162   image->error=clone_image->error;
163   image->signature=clone_image->signature;
164   if (clone_image->properties != (void *) NULL)
165     {
166       if (image->properties != (void *) NULL)
167         DestroyImageProperties(image);
168       image->properties=CloneSplayTree((SplayTreeInfo *)
169         clone_image->properties,(void *(*)(void *)) ConstantString,
170         (void *(*)(void *)) ConstantString);
171     }
172   return(MagickTrue);
173 }
174 \f
175 /*
176 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
177 %                                                                             %
178 %                                                                             %
179 %                                                                             %
180 %   D e f i n e I m a g e P r o p e r t y                                     %
181 %                                                                             %
182 %                                                                             %
183 %                                                                             %
184 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
185 %
186 %  DefineImageProperty() associates a key/value pair with an image property.
187 %
188 %  The format of the DefineImageProperty method is:
189 %
190 %      MagickBooleanType DefineImageProperty(Image *image,
191 %        const char *property)
192 %
193 %  A description of each parameter follows:
194 %
195 %    o image: the image.
196 %
197 %    o property: the image property.
198 %
199 */
200 MagickExport MagickBooleanType DefineImageProperty(Image *image,
201   const char *property)
202 {
203   char
204     key[MaxTextExtent],
205     value[MaxTextExtent];
206
207   register char
208     *p;
209
210   assert(image != (Image *) NULL);
211   assert(property != (const char *) NULL);
212   (void) CopyMagickString(key,property,MaxTextExtent-1);
213   for (p=key; *p != '\0'; p++)
214     if (*p == '=')
215       break;
216   *value='\0';
217   if (*p == '=')
218     (void) CopyMagickString(value,p+1,MaxTextExtent);
219   *p='\0';
220   return(SetImageProperty(image,key,value));
221 }
222 \f
223 /*
224 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
225 %                                                                             %
226 %                                                                             %
227 %                                                                             %
228 %   D e l e t e I m a g e P r o p e r t y                                     %
229 %                                                                             %
230 %                                                                             %
231 %                                                                             %
232 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
233 %
234 %  DeleteImageProperty() deletes an image property.
235 %
236 %  The format of the DeleteImageProperty method is:
237 %
238 %      MagickBooleanType DeleteImageProperty(Image *image,const char *property)
239 %
240 %  A description of each parameter follows:
241 %
242 %    o image: the image.
243 %
244 %    o property: the image property.
245 %
246 */
247 MagickExport MagickBooleanType DeleteImageProperty(Image *image,
248   const char *property)
249 {
250   assert(image != (Image *) NULL);
251   assert(image->signature == MagickSignature);
252   if (image->debug != MagickFalse)
253     (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
254       image->filename);
255   if (image->properties == (void *) NULL)
256     return(MagickFalse);
257   return(DeleteNodeFromSplayTree((SplayTreeInfo *) image->properties,property));
258 }
259 \f
260 /*
261 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
262 %                                                                             %
263 %                                                                             %
264 %                                                                             %
265 %   D e s t r o y I m a g e P r o p e r t i e s                               %
266 %                                                                             %
267 %                                                                             %
268 %                                                                             %
269 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
270 %
271 %  DestroyImageProperties() releases memory associated with image property
272 %  values.
273 %
274 %  The format of the DestroyDefines method is:
275 %
276 %      void DestroyImageProperties(Image *image)
277 %
278 %  A description of each parameter follows:
279 %
280 %    o image: the image.
281 %
282 */
283 MagickExport void DestroyImageProperties(Image *image)
284 {
285   assert(image != (Image *) NULL);
286   assert(image->signature == MagickSignature);
287   if (image->debug != MagickFalse)
288     (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
289       image->filename);
290   if (image->properties != (void *) NULL)
291     image->properties=(void *) DestroySplayTree((SplayTreeInfo *)
292       image->properties);
293 }
294 \f
295 /*
296 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
297 %                                                                             %
298 %                                                                             %
299 %                                                                             %
300 %  F o r m a t I m a g e P r o p e r t y                                      %
301 %                                                                             %
302 %                                                                             %
303 %                                                                             %
304 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
305 %
306 %  FormatImageProperty() permits formatted property/value pairs to be saved as
307 %  an image property.
308 %
309 %  The format of the FormatImageProperty method is:
310 %
311 %      MagickBooleanType FormatImageProperty(Image *image,const char *property,
312 %        const char *format,...)
313 %
314 %  A description of each parameter follows.
315 %
316 %   o  image:  The image.
317 %
318 %   o  property:  The attribute property.
319 %
320 %   o  format:  A string describing the format to use to write the remaining
321 %      arguments.
322 %
323 */
324 MagickExport MagickBooleanType FormatImageProperty(Image *image,
325   const char *property,const char *format,...)
326 {
327   char
328     value[MaxTextExtent];
329
330   ssize_t
331     n;
332
333   va_list
334     operands;
335
336   va_start(operands,format);
337   n=FormatLocaleStringList(value,MaxTextExtent,format,operands);
338   (void) n;
339   va_end(operands);
340   return(SetImageProperty(image,property,value));
341 }
342 \f
343 /*
344 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
345 %                                                                             %
346 %                                                                             %
347 %                                                                             %
348 %   G e t I m a g e P r o p e r t y                                           %
349 %                                                                             %
350 %                                                                             %
351 %                                                                             %
352 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
353 %
354 %  GetImageProperty() gets a value associated with an image property.
355 %
356 %  The format of the GetImageProperty method is:
357 %
358 %      const char *GetImageProperty(const Image *image,const char *key)
359 %
360 %  A description of each parameter follows:
361 %
362 %    o image: the image.
363 %
364 %    o key: the key.
365 %
366 */
367
368 static char
369   *TracePSClippath(const unsigned char *,size_t,const size_t,
370     const size_t),
371   *TraceSVGClippath(const unsigned char *,size_t,const size_t,
372     const size_t);
373
374 static MagickBooleanType GetIPTCProperty(const Image *image,const char *key)
375 {
376   char
377     *attribute,
378     *message;
379
380   const StringInfo
381     *profile;
382
383   long
384     count,
385     dataset,
386     record;
387
388   register ssize_t
389     i;
390
391   size_t
392     length;
393
394   profile=GetImageProfile(image,"iptc");
395   if (profile == (StringInfo *) NULL)
396     profile=GetImageProfile(image,"8bim");
397   if (profile == (StringInfo *) NULL)
398     return(MagickFalse);
399   count=sscanf(key,"IPTC:%ld:%ld",&dataset,&record);
400   if (count != 2)
401     return(MagickFalse);
402   attribute=(char *) NULL;
403   for (i=0; i < (ssize_t) GetStringInfoLength(profile); i+=(ssize_t) length)
404   {
405     length=1;
406     if ((ssize_t) GetStringInfoDatum(profile)[i] != 0x1c)
407       continue;
408     length=(size_t) (GetStringInfoDatum(profile)[i+3] << 8);
409     length|=GetStringInfoDatum(profile)[i+4];
410     if (((long) GetStringInfoDatum(profile)[i+1] == dataset) &&
411         ((long) GetStringInfoDatum(profile)[i+2] == record))
412       {
413         message=(char *) NULL;
414         if (~length >= 1)
415           message=(char *) AcquireQuantumMemory(length+1UL,sizeof(*message));
416         if (message != (char *) NULL)
417           {
418             (void) CopyMagickString(message,(char *) GetStringInfoDatum(
419               profile)+i+5,length+1);
420             (void) ConcatenateString(&attribute,message);
421             (void) ConcatenateString(&attribute,";");
422             message=DestroyString(message);
423           }
424       }
425     i+=5;
426   }
427   if ((attribute == (char *) NULL) || (*attribute == ';'))
428     {
429       if (attribute != (char *) NULL)
430         attribute=DestroyString(attribute);
431       return(MagickFalse);
432     }
433   attribute[strlen(attribute)-1]='\0';
434   (void) SetImageProperty((Image *) image,key,(const char *) attribute);
435   attribute=DestroyString(attribute);
436   return(MagickTrue);
437 }
438
439 static inline ssize_t MagickMax(const ssize_t x,const ssize_t y)
440 {
441   if (x > y)
442     return(x);
443   return(y);
444 }
445
446 static inline int ReadPropertyByte(const unsigned char **p,size_t *length)
447 {
448   int
449     c;
450
451   if (*length < 1)
452     return(EOF);
453   c=(int) (*(*p)++);
454   (*length)--;
455   return(c);
456 }
457
458 static inline size_t ReadPropertyMSBLong(const unsigned char **p,
459   size_t *length)
460 {
461   int
462     c;
463
464   register ssize_t
465     i;
466
467   unsigned char
468     buffer[4];
469
470   size_t
471     value;
472
473   if (*length < 4)
474     return(~0UL);
475   for (i=0; i < 4; i++)
476   {
477     c=(int) (*(*p)++);
478     (*length)--;
479     buffer[i]=(unsigned char) c;
480   }
481   value=(size_t) (buffer[0] << 24);
482   value|=buffer[1] << 16;
483   value|=buffer[2] << 8;
484   value|=buffer[3];
485   return(value & 0xffffffff);
486 }
487
488 static inline unsigned short ReadPropertyMSBShort(const unsigned char **p,
489   size_t *length)
490 {
491   int
492     c;
493
494   register ssize_t
495     i;
496
497   unsigned char
498     buffer[2];
499
500   unsigned short
501     value;
502
503   if (*length < 2)
504     return((unsigned short) ~0U);
505   for (i=0; i < 2; i++)
506   {
507     c=(int) (*(*p)++);
508     (*length)--;
509     buffer[i]=(unsigned char) c;
510   }
511   value=(unsigned short) (buffer[0] << 8);
512   value|=buffer[1];
513   return((unsigned short) (value & 0xffff));
514 }
515
516 static MagickBooleanType Get8BIMProperty(const Image *image,const char *key)
517 {
518   char
519     *attribute,
520     format[MaxTextExtent],
521     name[MaxTextExtent],
522     *resource;
523
524   const StringInfo
525     *profile;
526
527   const unsigned char
528     *info;
529
530   long
531     start,
532     stop;
533
534   MagickBooleanType
535     status;
536
537   register ssize_t
538     i;
539
540   ssize_t
541     count,
542     id,
543     sub_number;
544
545   size_t
546     length;
547
548   /*
549     There are no newlines in path names, so it's safe as terminator.
550   */
551   profile=GetImageProfile(image,"8bim");
552   if (profile == (StringInfo *) NULL)
553     return(MagickFalse);
554   count=(ssize_t) sscanf(key,"8BIM:%ld,%ld:%[^\n]\n%[^\n]",&start,&stop,name,
555     format);
556   if ((count != 2) && (count != 3) && (count != 4))
557     return(MagickFalse);
558   if (count < 4)
559     (void) CopyMagickString(format,"SVG",MaxTextExtent);
560   if (count < 3)
561     *name='\0';
562   sub_number=1;
563   if (*name == '#')
564     sub_number=(ssize_t) StringToLong(&name[1]);
565   sub_number=MagickMax(sub_number,1L);
566   resource=(char *) NULL;
567   status=MagickFalse;
568   length=GetStringInfoLength(profile);
569   info=GetStringInfoDatum(profile);
570   while ((length > 0) && (status == MagickFalse))
571   {
572     if (ReadPropertyByte(&info,&length) != (unsigned char) '8')
573       continue;
574     if (ReadPropertyByte(&info,&length) != (unsigned char) 'B')
575       continue;
576     if (ReadPropertyByte(&info,&length) != (unsigned char) 'I')
577       continue;
578     if (ReadPropertyByte(&info,&length) != (unsigned char) 'M')
579       continue;
580     id=(ssize_t) ReadPropertyMSBShort(&info,&length);
581     if (id < (ssize_t) start)
582       continue;
583     if (id > (ssize_t) stop)
584       continue;
585     if (resource != (char *) NULL)
586       resource=DestroyString(resource);
587     count=(ssize_t) ReadPropertyByte(&info,&length);
588     if ((count != 0) && ((size_t) count <= length))
589       {
590         resource=(char *) NULL;
591         if (~(1UL*count) >= (MaxTextExtent-1))
592           resource=(char *) AcquireQuantumMemory((size_t) count+MaxTextExtent,
593             sizeof(*resource));
594         if (resource != (char *) NULL)
595           {
596             for (i=0; i < (ssize_t) count; i++)
597               resource[i]=(char) ReadPropertyByte(&info,&length);
598             resource[count]='\0';
599           }
600       }
601     if ((count & 0x01) == 0)
602       (void) ReadPropertyByte(&info,&length);
603     count=(ssize_t) ((int) ReadPropertyMSBLong(&info,&length));
604     if ((*name != '\0') && (*name != '#'))
605       if ((resource == (char *) NULL) || (LocaleCompare(name,resource) != 0))
606         {
607           /*
608             No name match, scroll forward and try next.
609           */
610           info+=count;
611           length-=count;
612           continue;
613         }
614     if ((*name == '#') && (sub_number != 1))
615       {
616         /*
617           No numbered match, scroll forward and try next.
618         */
619         sub_number--;
620         info+=count;
621         length-=count;
622         continue;
623       }
624     /*
625       We have the resource of interest.
626     */
627     attribute=(char *) NULL;
628     if (~(1UL*count) >= (MaxTextExtent-1))
629       attribute=(char *) AcquireQuantumMemory((size_t) count+MaxTextExtent,
630         sizeof(*attribute));
631     if (attribute != (char *) NULL)
632       {
633         (void) CopyMagickMemory(attribute,(char *) info,(size_t) count);
634         attribute[count]='\0';
635         info+=count;
636         length-=count;
637         if ((id <= 1999) || (id >= 2999))
638           (void) SetImageProperty((Image *) image,key,(const char *)
639             attribute);
640         else
641           {
642             char
643               *path;
644
645             if (LocaleCompare(format,"svg") == 0)
646               path=TraceSVGClippath((unsigned char *) attribute,(size_t) count,
647                 image->columns,image->rows);
648             else
649               path=TracePSClippath((unsigned char *) attribute,(size_t) count,
650                 image->columns,image->rows);
651             (void) SetImageProperty((Image *) image,key,(const char *) path);
652             path=DestroyString(path);
653           }
654         attribute=DestroyString(attribute);
655         status=MagickTrue;
656       }
657   }
658   if (resource != (char *) NULL)
659     resource=DestroyString(resource);
660   return(status);
661 }
662
663 static inline unsigned short ReadPropertyShort(const EndianType endian,
664   const unsigned char *buffer)
665 {
666   unsigned short
667     value;
668
669   if (endian == MSBEndian)
670     {
671       value=(unsigned short) ((((unsigned char *) buffer)[0] << 8) |
672         ((unsigned char *) buffer)[1]);
673       return((unsigned short) (value & 0xffff));
674     }
675   value=(unsigned short) ((buffer[1] << 8) | buffer[0]);
676   return((unsigned short) (value & 0xffff));
677 }
678
679 static inline size_t ReadPropertyLong(const EndianType endian,
680   const unsigned char *buffer)
681 {
682   size_t
683     value;
684
685   if (endian == MSBEndian)
686     {
687       value=(size_t) ((buffer[0] << 24) | (buffer[1] << 16) |
688         (buffer[2] << 8) | buffer[3]);
689       return((size_t) (value & 0xffffffff));
690     }
691   value=(size_t) ((buffer[3] << 24) | (buffer[2] << 16) |
692     (buffer[1] << 8 ) | (buffer[0]));
693   return((size_t) (value & 0xffffffff));
694 }
695
696 static MagickBooleanType GetEXIFProperty(const Image *image,
697   const char *property)
698 {
699 #define MaxDirectoryStack  16
700 #define EXIF_DELIMITER  "\n"
701 #define EXIF_NUM_FORMATS  12
702 #define EXIF_FMT_BYTE  1
703 #define EXIF_FMT_STRING  2
704 #define EXIF_FMT_USHORT  3
705 #define EXIF_FMT_ULONG  4
706 #define EXIF_FMT_URATIONAL  5
707 #define EXIF_FMT_SBYTE  6
708 #define EXIF_FMT_UNDEFINED  7
709 #define EXIF_FMT_SSHORT  8
710 #define EXIF_FMT_SLONG  9
711 #define EXIF_FMT_SRATIONAL  10
712 #define EXIF_FMT_SINGLE  11
713 #define EXIF_FMT_DOUBLE  12
714 #define TAG_EXIF_OFFSET  0x8769
715 #define TAG_GPS_OFFSET  0x8825
716 #define TAG_INTEROP_OFFSET  0xa005
717
718 #define EXIFMultipleValues(size, format, arg) \
719 { \
720    ssize_t \
721      component; \
722  \
723    size_t \
724      length; \
725  \
726    unsigned char \
727      *p1; \
728  \
729    length=0; \
730    p1=p; \
731    for (component=0; component < components; component++) \
732    { \
733      length+=FormatLocaleString(buffer+length,MaxTextExtent-length, \
734        format", ",arg); \
735      if (length >= (MaxTextExtent-1)) \
736        length=MaxTextExtent-1; \
737      p1+=size; \
738    } \
739    if (length > 1) \
740      buffer[length-2]='\0'; \
741    value=AcquireString(buffer); \
742 }
743
744 #define EXIFMultipleFractions(size, format, arg1, arg2) \
745 { \
746    ssize_t \
747      component; \
748  \
749    size_t \
750      length; \
751  \
752    unsigned char \
753      *p1; \
754  \
755    length=0; \
756    p1=p; \
757    for (component=0; component < components; component++) \
758    { \
759      length+=FormatLocaleString(buffer+length,MaxTextExtent-length, \
760        format", ",arg1, arg2); \
761      if (length >= (MaxTextExtent-1)) \
762        length=MaxTextExtent-1; \
763      p1+=size; \
764    } \
765    if (length > 1) \
766      buffer[length-2]='\0'; \
767    value=AcquireString(buffer); \
768 }
769
770   typedef struct _DirectoryInfo
771   {
772     const unsigned char
773       *directory;
774
775     size_t
776       entry,
777       offset;
778   } DirectoryInfo;
779
780   typedef struct _TagInfo
781   {
782     size_t
783       tag;
784
785     const char
786       *description;
787   } TagInfo;
788
789   static TagInfo
790     EXIFTag[] =
791     {
792       {  0x001, "exif:InteroperabilityIndex" },
793       {  0x002, "exif:InteroperabilityVersion" },
794       {  0x100, "exif:ImageWidth" },
795       {  0x101, "exif:ImageLength" },
796       {  0x102, "exif:BitsPerSample" },
797       {  0x103, "exif:Compression" },
798       {  0x106, "exif:PhotometricInterpretation" },
799       {  0x10a, "exif:FillOrder" },
800       {  0x10d, "exif:DocumentName" },
801       {  0x10e, "exif:ImageDescription" },
802       {  0x10f, "exif:Make" },
803       {  0x110, "exif:Model" },
804       {  0x111, "exif:StripOffsets" },
805       {  0x112, "exif:Orientation" },
806       {  0x115, "exif:SamplesPerPixel" },
807       {  0x116, "exif:RowsPerStrip" },
808       {  0x117, "exif:StripByteCounts" },
809       {  0x11a, "exif:XResolution" },
810       {  0x11b, "exif:YResolution" },
811       {  0x11c, "exif:PlanarConfiguration" },
812       {  0x11d, "exif:PageName" },
813       {  0x11e, "exif:XPosition" },
814       {  0x11f, "exif:YPosition" },
815       {  0x118, "exif:MinSampleValue" },
816       {  0x119, "exif:MaxSampleValue" },
817       {  0x120, "exif:FreeOffsets" },
818       {  0x121, "exif:FreeByteCounts" },
819       {  0x122, "exif:GrayResponseUnit" },
820       {  0x123, "exif:GrayResponseCurve" },
821       {  0x124, "exif:T4Options" },
822       {  0x125, "exif:T6Options" },
823       {  0x128, "exif:ResolutionUnit" },
824       {  0x12d, "exif:TransferFunction" },
825       {  0x131, "exif:Software" },
826       {  0x132, "exif:DateTime" },
827       {  0x13b, "exif:Artist" },
828       {  0x13e, "exif:WhitePoint" },
829       {  0x13f, "exif:PrimaryChromaticities" },
830       {  0x140, "exif:ColorMap" },
831       {  0x141, "exif:HalfToneHints" },
832       {  0x142, "exif:TileWidth" },
833       {  0x143, "exif:TileLength" },
834       {  0x144, "exif:TileOffsets" },
835       {  0x145, "exif:TileByteCounts" },
836       {  0x14a, "exif:SubIFD" },
837       {  0x14c, "exif:InkSet" },
838       {  0x14d, "exif:InkNames" },
839       {  0x14e, "exif:NumberOfInks" },
840       {  0x150, "exif:DotRange" },
841       {  0x151, "exif:TargetPrinter" },
842       {  0x152, "exif:ExtraSample" },
843       {  0x153, "exif:SampleFormat" },
844       {  0x154, "exif:SMinSampleValue" },
845       {  0x155, "exif:SMaxSampleValue" },
846       {  0x156, "exif:TransferRange" },
847       {  0x157, "exif:ClipPath" },
848       {  0x158, "exif:XClipPathUnits" },
849       {  0x159, "exif:YClipPathUnits" },
850       {  0x15a, "exif:Indexed" },
851       {  0x15b, "exif:JPEGTables" },
852       {  0x15f, "exif:OPIProxy" },
853       {  0x200, "exif:JPEGProc" },
854       {  0x201, "exif:JPEGInterchangeFormat" },
855       {  0x202, "exif:JPEGInterchangeFormatLength" },
856       {  0x203, "exif:JPEGRestartInterval" },
857       {  0x205, "exif:JPEGLosslessPredictors" },
858       {  0x206, "exif:JPEGPointTransforms" },
859       {  0x207, "exif:JPEGQTables" },
860       {  0x208, "exif:JPEGDCTables" },
861       {  0x209, "exif:JPEGACTables" },
862       {  0x211, "exif:YCbCrCoefficients" },
863       {  0x212, "exif:YCbCrSubSampling" },
864       {  0x213, "exif:YCbCrPositioning" },
865       {  0x214, "exif:ReferenceBlackWhite" },
866       {  0x2bc, "exif:ExtensibleMetadataPlatform" },
867       {  0x301, "exif:Gamma" },
868       {  0x302, "exif:ICCProfileDescriptor" },
869       {  0x303, "exif:SRGBRenderingIntent" },
870       {  0x320, "exif:ImageTitle" },
871       {  0x5001, "exif:ResolutionXUnit" },
872       {  0x5002, "exif:ResolutionYUnit" },
873       {  0x5003, "exif:ResolutionXLengthUnit" },
874       {  0x5004, "exif:ResolutionYLengthUnit" },
875       {  0x5005, "exif:PrintFlags" },
876       {  0x5006, "exif:PrintFlagsVersion" },
877       {  0x5007, "exif:PrintFlagsCrop" },
878       {  0x5008, "exif:PrintFlagsBleedWidth" },
879       {  0x5009, "exif:PrintFlagsBleedWidthScale" },
880       {  0x500A, "exif:HalftoneLPI" },
881       {  0x500B, "exif:HalftoneLPIUnit" },
882       {  0x500C, "exif:HalftoneDegree" },
883       {  0x500D, "exif:HalftoneShape" },
884       {  0x500E, "exif:HalftoneMisc" },
885       {  0x500F, "exif:HalftoneScreen" },
886       {  0x5010, "exif:JPEGQuality" },
887       {  0x5011, "exif:GridSize" },
888       {  0x5012, "exif:ThumbnailFormat" },
889       {  0x5013, "exif:ThumbnailWidth" },
890       {  0x5014, "exif:ThumbnailHeight" },
891       {  0x5015, "exif:ThumbnailColorDepth" },
892       {  0x5016, "exif:ThumbnailPlanes" },
893       {  0x5017, "exif:ThumbnailRawBytes" },
894       {  0x5018, "exif:ThumbnailSize" },
895       {  0x5019, "exif:ThumbnailCompressedSize" },
896       {  0x501a, "exif:ColorTransferFunction" },
897       {  0x501b, "exif:ThumbnailData" },
898       {  0x5020, "exif:ThumbnailImageWidth" },
899       {  0x5021, "exif:ThumbnailImageHeight" },
900       {  0x5022, "exif:ThumbnailBitsPerSample" },
901       {  0x5023, "exif:ThumbnailCompression" },
902       {  0x5024, "exif:ThumbnailPhotometricInterp" },
903       {  0x5025, "exif:ThumbnailImageDescription" },
904       {  0x5026, "exif:ThumbnailEquipMake" },
905       {  0x5027, "exif:ThumbnailEquipModel" },
906       {  0x5028, "exif:ThumbnailStripOffsets" },
907       {  0x5029, "exif:ThumbnailOrientation" },
908       {  0x502a, "exif:ThumbnailSamplesPerPixel" },
909       {  0x502b, "exif:ThumbnailRowsPerStrip" },
910       {  0x502c, "exif:ThumbnailStripBytesCount" },
911       {  0x502d, "exif:ThumbnailResolutionX" },
912       {  0x502e, "exif:ThumbnailResolutionY" },
913       {  0x502f, "exif:ThumbnailPlanarConfig" },
914       {  0x5030, "exif:ThumbnailResolutionUnit" },
915       {  0x5031, "exif:ThumbnailTransferFunction" },
916       {  0x5032, "exif:ThumbnailSoftwareUsed" },
917       {  0x5033, "exif:ThumbnailDateTime" },
918       {  0x5034, "exif:ThumbnailArtist" },
919       {  0x5035, "exif:ThumbnailWhitePoint" },
920       {  0x5036, "exif:ThumbnailPrimaryChromaticities" },
921       {  0x5037, "exif:ThumbnailYCbCrCoefficients" },
922       {  0x5038, "exif:ThumbnailYCbCrSubsampling" },
923       {  0x5039, "exif:ThumbnailYCbCrPositioning" },
924       {  0x503A, "exif:ThumbnailRefBlackWhite" },
925       {  0x503B, "exif:ThumbnailCopyRight" },
926       {  0x5090, "exif:LuminanceTable" },
927       {  0x5091, "exif:ChrominanceTable" },
928       {  0x5100, "exif:FrameDelay" },
929       {  0x5101, "exif:LoopCount" },
930       {  0x5110, "exif:PixelUnit" },
931       {  0x5111, "exif:PixelPerUnitX" },
932       {  0x5112, "exif:PixelPerUnitY" },
933       {  0x5113, "exif:PaletteHistogram" },
934       {  0x1000, "exif:RelatedImageFileFormat" },
935       {  0x1001, "exif:RelatedImageLength" },
936       {  0x1002, "exif:RelatedImageWidth" },
937       {  0x800d, "exif:ImageID" },
938       {  0x80e3, "exif:Matteing" },
939       {  0x80e4, "exif:DataType" },
940       {  0x80e5, "exif:ImageDepth" },
941       {  0x80e6, "exif:TileDepth" },
942       {  0x828d, "exif:CFARepeatPatternDim" },
943       {  0x828e, "exif:CFAPattern2" },
944       {  0x828f, "exif:BatteryLevel" },
945       {  0x8298, "exif:Copyright" },
946       {  0x829a, "exif:ExposureTime" },
947       {  0x829d, "exif:FNumber" },
948       {  0x83bb, "exif:IPTC/NAA" },
949       {  0x84e3, "exif:IT8RasterPadding" },
950       {  0x84e5, "exif:IT8ColorTable" },
951       {  0x8649, "exif:ImageResourceInformation" },
952       {  0x8769, "exif:ExifOffset" },
953       {  0x8773, "exif:InterColorProfile" },
954       {  0x8822, "exif:ExposureProgram" },
955       {  0x8824, "exif:SpectralSensitivity" },
956       {  0x8825, "exif:GPSInfo" },
957       {  0x8827, "exif:ISOSpeedRatings" },
958       {  0x8828, "exif:OECF" },
959       {  0x8829, "exif:Interlace" },
960       {  0x882a, "exif:TimeZoneOffset" },
961       {  0x882b, "exif:SelfTimerMode" },
962       {  0x9000, "exif:ExifVersion" },
963       {  0x9003, "exif:DateTimeOriginal" },
964       {  0x9004, "exif:DateTimeDigitized" },
965       {  0x9101, "exif:ComponentsConfiguration" },
966       {  0x9102, "exif:CompressedBitsPerPixel" },
967       {  0x9201, "exif:ShutterSpeedValue" },
968       {  0x9202, "exif:ApertureValue" },
969       {  0x9203, "exif:BrightnessValue" },
970       {  0x9204, "exif:ExposureBiasValue" },
971       {  0x9205, "exif:MaxApertureValue" },
972       {  0x9206, "exif:SubjectDistance" },
973       {  0x9207, "exif:MeteringMode" },
974       {  0x9208, "exif:LightSource" },
975       {  0x9209, "exif:Flash" },
976       {  0x920a, "exif:FocalLength" },
977       {  0x920b, "exif:FlashEnergy" },
978       {  0x920c, "exif:SpatialFrequencyResponse" },
979       {  0x920d, "exif:Noise" },
980       {  0x9211, "exif:ImageNumber" },
981       {  0x9212, "exif:SecurityClassification" },
982       {  0x9213, "exif:ImageHistory" },
983       {  0x9214, "exif:SubjectArea" },
984       {  0x9215, "exif:ExposureIndex" },
985       {  0x9216, "exif:TIFF-EPStandardID" },
986       {  0x927c, "exif:MakerNote" },
987       {  0x9C9b, "exif:WinXP-Title" },
988       {  0x9C9c, "exif:WinXP-Comments" },
989       {  0x9C9d, "exif:WinXP-Author" },
990       {  0x9C9e, "exif:WinXP-Keywords" },
991       {  0x9C9f, "exif:WinXP-Subject" },
992       {  0x9286, "exif:UserComment" },
993       {  0x9290, "exif:SubSecTime" },
994       {  0x9291, "exif:SubSecTimeOriginal" },
995       {  0x9292, "exif:SubSecTimeDigitized" },
996       {  0xa000, "exif:FlashPixVersion" },
997       {  0xa001, "exif:ColorSpace" },
998       {  0xa002, "exif:ExifImageWidth" },
999       {  0xa003, "exif:ExifImageLength" },
1000       {  0xa004, "exif:RelatedSoundFile" },
1001       {  0xa005, "exif:InteroperabilityOffset" },
1002       {  0xa20b, "exif:FlashEnergy" },
1003       {  0xa20c, "exif:SpatialFrequencyResponse" },
1004       {  0xa20d, "exif:Noise" },
1005       {  0xa20e, "exif:FocalPlaneXResolution" },
1006       {  0xa20f, "exif:FocalPlaneYResolution" },
1007       {  0xa210, "exif:FocalPlaneResolutionUnit" },
1008       {  0xa214, "exif:SubjectLocation" },
1009       {  0xa215, "exif:ExposureIndex" },
1010       {  0xa216, "exif:TIFF/EPStandardID" },
1011       {  0xa217, "exif:SensingMethod" },
1012       {  0xa300, "exif:FileSource" },
1013       {  0xa301, "exif:SceneType" },
1014       {  0xa302, "exif:CFAPattern" },
1015       {  0xa401, "exif:CustomRendered" },
1016       {  0xa402, "exif:ExposureMode" },
1017       {  0xa403, "exif:WhiteBalance" },
1018       {  0xa404, "exif:DigitalZoomRatio" },
1019       {  0xa405, "exif:FocalLengthIn35mmFilm" },
1020       {  0xa406, "exif:SceneCaptureType" },
1021       {  0xa407, "exif:GainControl" },
1022       {  0xa408, "exif:Contrast" },
1023       {  0xa409, "exif:Saturation" },
1024       {  0xa40a, "exif:Sharpness" },
1025       {  0xa40b, "exif:DeviceSettingDescription" },
1026       {  0xa40c, "exif:SubjectDistanceRange" },
1027       {  0xa420, "exif:ImageUniqueID" },
1028       {  0xc4a5, "exif:PrintImageMatching" },
1029       {  0xa500, "exif:Gamma" },
1030       {  0xc640, "exif:CR2Slice" },
1031       { 0x10000, "exif:GPSVersionID" },
1032       { 0x10001, "exif:GPSLatitudeRef" },
1033       { 0x10002, "exif:GPSLatitude" },
1034       { 0x10003, "exif:GPSLongitudeRef" },
1035       { 0x10004, "exif:GPSLongitude" },
1036       { 0x10005, "exif:GPSAltitudeRef" },
1037       { 0x10006, "exif:GPSAltitude" },
1038       { 0x10007, "exif:GPSTimeStamp" },
1039       { 0x10008, "exif:GPSSatellites" },
1040       { 0x10009, "exif:GPSStatus" },
1041       { 0x1000a, "exif:GPSMeasureMode" },
1042       { 0x1000b, "exif:GPSDop" },
1043       { 0x1000c, "exif:GPSSpeedRef" },
1044       { 0x1000d, "exif:GPSSpeed" },
1045       { 0x1000e, "exif:GPSTrackRef" },
1046       { 0x1000f, "exif:GPSTrack" },
1047       { 0x10010, "exif:GPSImgDirectionRef" },
1048       { 0x10011, "exif:GPSImgDirection" },
1049       { 0x10012, "exif:GPSMapDatum" },
1050       { 0x10013, "exif:GPSDestLatitudeRef" },
1051       { 0x10014, "exif:GPSDestLatitude" },
1052       { 0x10015, "exif:GPSDestLongitudeRef" },
1053       { 0x10016, "exif:GPSDestLongitude" },
1054       { 0x10017, "exif:GPSDestBearingRef" },
1055       { 0x10018, "exif:GPSDestBearing" },
1056       { 0x10019, "exif:GPSDestDistanceRef" },
1057       { 0x1001a, "exif:GPSDestDistance" },
1058       { 0x1001b, "exif:GPSProcessingMethod" },
1059       { 0x1001c, "exif:GPSAreaInformation" },
1060       { 0x1001d, "exif:GPSDateStamp" },
1061       { 0x1001e, "exif:GPSDifferential" },
1062       {  0x0000, NULL}
1063     };
1064
1065   const StringInfo
1066     *profile;
1067
1068   const unsigned char
1069     *directory,
1070     *exif;
1071
1072   DirectoryInfo
1073     directory_stack[MaxDirectoryStack];
1074
1075   EndianType
1076     endian;
1077
1078   MagickBooleanType
1079     status;
1080
1081   register ssize_t
1082     i;
1083
1084   size_t
1085     entry,
1086     length,
1087     number_entries,
1088     tag_offset,
1089     tag;
1090
1091   ssize_t
1092     all,
1093     id,
1094     level,
1095     offset,
1096     tag_value;
1097
1098   static int
1099     tag_bytes[] = {0, 1, 1, 2, 4, 8, 1, 1, 2, 4, 8, 4, 8};
1100
1101   /*
1102     If EXIF data exists, then try to parse the request for a tag.
1103   */
1104   profile=GetImageProfile(image,"exif");
1105   if (profile == (StringInfo *) NULL)
1106     return(MagickFalse);
1107   if ((property == (const char *) NULL) || (*property == '\0'))
1108     return(MagickFalse);
1109   while (isspace((int) ((unsigned char) *property)) != 0)
1110     property++;
1111   all=0;
1112   tag=(~0UL);
1113   switch (*(property+5))
1114   {
1115     case '*':
1116     {
1117       /*
1118         Caller has asked for all the tags in the EXIF data.
1119       */
1120       tag=0;
1121       all=1; /* return the data in description=value format */
1122       break;
1123     }
1124     case '!':
1125     {
1126       tag=0;
1127       all=2; /* return the data in tagid=value format */
1128       break;
1129     }
1130     case '#':
1131     case '@':
1132     {
1133       int
1134         c;
1135
1136       size_t
1137         n;
1138
1139       /*
1140         Check for a hex based tag specification first.
1141       */
1142       tag=(*(property+5) == '@') ? 1UL : 0UL;
1143       property+=6;
1144       n=strlen(property);
1145       if (n != 4)
1146         return(MagickFalse);
1147       /*
1148         Parse tag specification as a hex number.
1149       */
1150       n/=4;
1151       do
1152       {
1153         for (i=(ssize_t) n-1L; i >= 0; i--)
1154         {
1155           c=(*property++);
1156           tag<<=4;
1157           if ((c >= '0') && (c <= '9'))
1158             tag|=(c-'0');
1159           else
1160             if ((c >= 'A') && (c <= 'F'))
1161               tag|=(c-('A'-10));
1162             else
1163               if ((c >= 'a') && (c <= 'f'))
1164                 tag|=(c-('a'-10));
1165               else
1166                 return(MagickFalse);
1167         }
1168       } while (*property != '\0');
1169       break;
1170     }
1171     default:
1172     {
1173       /*
1174         Try to match the text with a tag name instead.
1175       */
1176       for (i=0; ; i++)
1177       {
1178         if (EXIFTag[i].tag == 0)
1179           break;
1180         if (LocaleCompare(EXIFTag[i].description,property) == 0)
1181           {
1182             tag=(size_t) EXIFTag[i].tag;
1183             break;
1184           }
1185       }
1186       break;
1187     }
1188   }
1189   if (tag == (~0UL))
1190     return(MagickFalse);
1191   length=GetStringInfoLength(profile);
1192   exif=GetStringInfoDatum(profile);
1193   while (length != 0)
1194   {
1195     if (ReadPropertyByte(&exif,&length) != 0x45)
1196       continue;
1197     if (ReadPropertyByte(&exif,&length) != 0x78)
1198       continue;
1199     if (ReadPropertyByte(&exif,&length) != 0x69)
1200       continue;
1201     if (ReadPropertyByte(&exif,&length) != 0x66)
1202       continue;
1203     if (ReadPropertyByte(&exif,&length) != 0x00)
1204       continue;
1205     if (ReadPropertyByte(&exif,&length) != 0x00)
1206       continue;
1207     break;
1208   }
1209   if (length < 16)
1210     return(MagickFalse);
1211   id=(ssize_t) ReadPropertyShort(LSBEndian,exif);
1212   endian=LSBEndian;
1213   if (id == 0x4949)
1214     endian=LSBEndian;
1215   else
1216     if (id == 0x4D4D)
1217       endian=MSBEndian;
1218     else
1219       return(MagickFalse);
1220   if (ReadPropertyShort(endian,exif+2) != 0x002a)
1221     return(MagickFalse);
1222   /*
1223     This the offset to the first IFD.
1224   */
1225   offset=(ssize_t) ((int) ReadPropertyLong(endian,exif+4));
1226   if ((size_t) offset >= length)
1227     return(MagickFalse);
1228   /*
1229     Set the pointer to the first IFD and follow it were it leads.
1230   */
1231   status=MagickFalse;
1232   directory=exif+offset;
1233   level=0;
1234   entry=0;
1235   tag_offset=0;
1236   do
1237   {
1238     /*
1239       If there is anything on the stack then pop it off.
1240     */
1241     if (level > 0)
1242       {
1243         level--;
1244         directory=directory_stack[level].directory;
1245         entry=directory_stack[level].entry;
1246         tag_offset=directory_stack[level].offset;
1247       }
1248     /*
1249       Determine how many entries there are in the current IFD.
1250     */
1251     number_entries=ReadPropertyShort(endian,directory);
1252     for ( ; entry < number_entries; entry++)
1253     {
1254       register unsigned char
1255         *p,
1256         *q;
1257
1258       size_t
1259         format,
1260         number_bytes;
1261
1262       ssize_t
1263         components;
1264
1265       q=(unsigned char *) (directory+2+(12*entry));
1266       tag_value=(ssize_t) (ReadPropertyShort(endian,q)+tag_offset);
1267       format=(size_t) ReadPropertyShort(endian,q+2);
1268       if (format >= (sizeof(tag_bytes)/sizeof(*tag_bytes)))
1269         break;
1270       components=(ssize_t) ((int) ReadPropertyLong(endian,q+4));
1271       number_bytes=(size_t) components*tag_bytes[format];
1272       if (number_bytes <= 4)
1273         p=q+8;
1274       else
1275         {
1276           ssize_t
1277             offset;
1278
1279           /*
1280             The directory entry contains an offset.
1281           */
1282           offset=(ssize_t) ((int) ReadPropertyLong(endian,q+8));
1283           if ((size_t) (offset+number_bytes) > length)
1284             continue;
1285           p=(unsigned char *) (exif+offset);
1286         }
1287       if ((all != 0) || (tag == (size_t) tag_value))
1288         {
1289           char
1290             buffer[MaxTextExtent],
1291             *value;
1292
1293           switch (format)
1294           {
1295             case EXIF_FMT_BYTE:
1296             case EXIF_FMT_UNDEFINED:
1297             {
1298               EXIFMultipleValues(1,"%.20g",(double) (*(unsigned char *) p1));
1299               break;
1300             }
1301             case EXIF_FMT_SBYTE:
1302             {
1303               EXIFMultipleValues(1,"%.20g",(double) (*(signed char *) p1));
1304               break;
1305             }
1306             case EXIF_FMT_SSHORT:
1307             {
1308               EXIFMultipleValues(2,"%hd",ReadPropertyShort(endian,p1));
1309               break;
1310             }
1311             case EXIF_FMT_USHORT:
1312             {
1313               EXIFMultipleValues(2,"%hu",ReadPropertyShort(endian,p1));
1314               break;
1315             }
1316             case EXIF_FMT_ULONG:
1317             {
1318               EXIFMultipleValues(4,"%.20g",(double)
1319                 ReadPropertyLong(endian,p1));
1320               break;
1321             }
1322             case EXIF_FMT_SLONG:
1323             {
1324               EXIFMultipleValues(4,"%.20g",(double)
1325                 ReadPropertyLong(endian,p1));
1326               break;
1327             }
1328             case EXIF_FMT_URATIONAL:
1329             {
1330               EXIFMultipleFractions(8,"%.20g/%.20g",(double)
1331                 ReadPropertyLong(endian,p1),(double)
1332                 ReadPropertyLong(endian,p1+4));
1333               break;
1334             }
1335             case EXIF_FMT_SRATIONAL:
1336             {
1337               EXIFMultipleFractions(8,"%.20g/%.20g",(double)
1338                 ReadPropertyLong(endian,p1),(double)
1339                 ReadPropertyLong(endian,p1+4));
1340               break;
1341             }
1342             case EXIF_FMT_SINGLE:
1343             {
1344               EXIFMultipleValues(4,"%f",(double) *(float *) p1);
1345               break;
1346             }
1347             case EXIF_FMT_DOUBLE:
1348             {
1349               EXIFMultipleValues(8,"%f",*(double *) p1);
1350               break;
1351             }
1352             default:
1353             case EXIF_FMT_STRING:
1354             {
1355               value=(char *) NULL;
1356               if (~(1UL*number_bytes) >= 1)
1357                 value=(char *) AcquireQuantumMemory((size_t) number_bytes+1UL,
1358                   sizeof(*value));
1359               if (value != (char *) NULL)
1360                 {
1361                   register ssize_t
1362                     i;
1363
1364                   for (i=0; i < (ssize_t) number_bytes; i++)
1365                   {
1366                     value[i]='.';
1367                     if ((isprint((int) p[i]) != 0) || (p[i] == '\0'))
1368                       value[i]=(char) p[i];
1369                   }
1370                   value[i]='\0';
1371                 }
1372               break;
1373             }
1374           }
1375           if (value != (char *) NULL)
1376             {
1377               char
1378                 key[MaxTextExtent];
1379
1380               register const char
1381                 *p;
1382
1383               (void) CopyMagickString(key,property,MaxTextExtent);
1384               switch (all)
1385               {
1386                 case 1:
1387                 {
1388                   const char
1389                     *description;
1390
1391                   register ssize_t
1392                     i;
1393
1394                   description="unknown";
1395                   for (i=0; ; i++)
1396                   {
1397                     if (EXIFTag[i].tag == 0)
1398                       break;
1399                     if ((ssize_t) EXIFTag[i].tag == tag_value)
1400                       {
1401                         description=EXIFTag[i].description;
1402                         break;
1403                       }
1404                   }
1405                   (void) FormatLocaleString(key,MaxTextExtent,"%s",
1406                     description);
1407                   break;
1408                 }
1409                 case 2:
1410                 {
1411                   if (tag_value < 0x10000)
1412                     (void) FormatLocaleString(key,MaxTextExtent,"#%04lx",
1413                       (unsigned long) tag_value);
1414                   else
1415                     if (tag_value < 0x20000)
1416                       (void) FormatLocaleString(key,MaxTextExtent,"@%04lx",
1417                         (unsigned long) (tag_value & 0xffff));
1418                     else
1419                       (void) FormatLocaleString(key,MaxTextExtent,"unknown");
1420                   break;
1421                 }
1422               }
1423               p=(const char *) NULL;
1424               if (image->properties != (void *) NULL)
1425                 p=(const char *) GetValueFromSplayTree((SplayTreeInfo *)
1426                   image->properties,key);
1427               if (p == (const char *) NULL)
1428                 (void) SetImageProperty((Image *) image,key,value);
1429               value=DestroyString(value);
1430               status=MagickTrue;
1431             }
1432         }
1433         if ((tag_value == TAG_EXIF_OFFSET) ||
1434             (tag_value == TAG_INTEROP_OFFSET) ||
1435             (tag_value == TAG_GPS_OFFSET))
1436           {
1437             size_t
1438               offset;
1439
1440             offset=(size_t) ReadPropertyLong(endian,p);
1441             if ((offset < length) && (level < (MaxDirectoryStack-2)))
1442               {
1443                 size_t
1444                   tag_offset1;
1445
1446                 tag_offset1=(tag_value == TAG_GPS_OFFSET) ? 0x10000UL : 0UL;
1447                 directory_stack[level].directory=directory;
1448                 entry++;
1449                 directory_stack[level].entry=entry;
1450                 directory_stack[level].offset=tag_offset;
1451                 level++;
1452                 directory_stack[level].directory=exif+offset;
1453                 directory_stack[level].offset=tag_offset1;
1454                 directory_stack[level].entry=0;
1455                 level++;
1456                 if ((directory+2+(12*number_entries)) > (exif+length))
1457                   break;
1458                 offset=(size_t) ReadPropertyLong(endian,directory+2+(12*
1459                   number_entries));
1460                 if ((offset != 0) && (offset < length) &&
1461                     (level < (MaxDirectoryStack-2)))
1462                   {
1463                     directory_stack[level].directory=exif+offset;
1464                     directory_stack[level].entry=0;
1465                     directory_stack[level].offset=tag_offset1;
1466                     level++;
1467                   }
1468               }
1469             break;
1470           }
1471     }
1472   } while (level > 0);
1473   return(status);
1474 }
1475
1476 static MagickBooleanType GetXMPProperty(const Image *image,const char *property)
1477 {
1478   char
1479     *xmp_profile;
1480
1481   const StringInfo
1482     *profile;
1483
1484   ExceptionInfo
1485     *exception;
1486
1487   MagickBooleanType
1488     status;
1489
1490   register const char
1491     *p;
1492
1493   XMLTreeInfo
1494     *child,
1495     *description,
1496     *node,
1497     *rdf,
1498     *xmp;
1499
1500   profile=GetImageProfile(image,"xmp");
1501   if (profile == (StringInfo *) NULL)
1502     return(MagickFalse);
1503   if ((property == (const char *) NULL) || (*property == '\0'))
1504     return(MagickFalse);
1505   xmp_profile=StringInfoToString(profile);
1506   if (xmp_profile == (char *) NULL)
1507     return(MagickFalse);
1508   for (p=xmp_profile; *p != '\0'; p++)
1509     if ((*p == '<') && (*(p+1) == 'x'))
1510       break;
1511   exception=AcquireExceptionInfo();
1512   xmp=NewXMLTree((char *) p,exception);
1513   xmp_profile=DestroyString(xmp_profile);
1514   exception=DestroyExceptionInfo(exception);
1515   if (xmp == (XMLTreeInfo *) NULL)
1516     return(MagickFalse);
1517   status=MagickFalse;
1518   rdf=GetXMLTreeChild(xmp,"rdf:RDF");
1519   if (rdf != (XMLTreeInfo *) NULL)
1520     {
1521       if (image->properties == (void *) NULL)
1522         ((Image *) image)->properties=NewSplayTree(CompareSplayTreeString,
1523           RelinquishMagickMemory,RelinquishMagickMemory);
1524       description=GetXMLTreeChild(rdf,"rdf:Description");
1525       while (description != (XMLTreeInfo *) NULL)
1526       {
1527         node=GetXMLTreeChild(description,(const char *) NULL);
1528         while (node != (XMLTreeInfo *) NULL)
1529         {
1530           child=GetXMLTreeChild(node,(const char *) NULL);
1531           if (child == (XMLTreeInfo *) NULL)
1532             (void) AddValueToSplayTree((SplayTreeInfo *) image->properties,
1533               ConstantString(GetXMLTreeTag(node)),
1534               ConstantString(GetXMLTreeContent(node)));
1535           while (child != (XMLTreeInfo *) NULL)
1536           {
1537             if (LocaleCompare(GetXMLTreeTag(child),"rdf:Seq") != 0)
1538               (void) AddValueToSplayTree((SplayTreeInfo *) image->properties,
1539                 ConstantString(GetXMLTreeTag(child)),
1540                 ConstantString(GetXMLTreeContent(child)));
1541             child=GetXMLTreeSibling(child);
1542           }
1543           node=GetXMLTreeSibling(node);
1544         }
1545         description=GetNextXMLTreeTag(description);
1546       }
1547     }
1548   xmp=DestroyXMLTree(xmp);
1549   return(status);
1550 }
1551
1552 static char *TracePSClippath(const unsigned char *blob,size_t length,
1553   const size_t magick_unused(columns),
1554   const size_t magick_unused(rows))
1555 {
1556   char
1557     *path,
1558     *message;
1559
1560   MagickBooleanType
1561     in_subpath;
1562
1563   PointInfo
1564     first[3],
1565     last[3],
1566     point[3];
1567
1568   register ssize_t
1569     i,
1570     x;
1571
1572   ssize_t
1573     knot_count,
1574     selector,
1575     y;
1576
1577   path=AcquireString((char *) NULL);
1578   if (path == (char *) NULL)
1579     return((char *) NULL);
1580   message=AcquireString((char *) NULL);
1581   (void) FormatLocaleString(message,MaxTextExtent,"/ClipImage\n");
1582   (void) ConcatenateString(&path,message);
1583   (void) FormatLocaleString(message,MaxTextExtent,"{\n");
1584   (void) ConcatenateString(&path,message);
1585   (void) FormatLocaleString(message,MaxTextExtent,"  /c {curveto} bind def\n");
1586   (void) ConcatenateString(&path,message);
1587   (void) FormatLocaleString(message,MaxTextExtent,"  /l {lineto} bind def\n");
1588   (void) ConcatenateString(&path,message);
1589   (void) FormatLocaleString(message,MaxTextExtent,"  /m {moveto} bind def\n");
1590   (void) ConcatenateString(&path,message);
1591   (void) FormatLocaleString(message,MaxTextExtent,
1592     "  /v {currentpoint 6 2 roll curveto} bind def\n");
1593   (void) ConcatenateString(&path,message);
1594   (void) FormatLocaleString(message,MaxTextExtent,
1595     "  /y {2 copy curveto} bind def\n");
1596   (void) ConcatenateString(&path,message);
1597   (void) FormatLocaleString(message,MaxTextExtent,
1598     "  /z {closepath} bind def\n");
1599   (void) ConcatenateString(&path,message);
1600   (void) FormatLocaleString(message,MaxTextExtent,"  newpath\n");
1601   (void) ConcatenateString(&path,message);
1602   /*
1603     The clipping path format is defined in "Adobe Photoshop File
1604     Formats Specification" version 6.0 downloadable from adobe.com.
1605   */
1606   (void) ResetMagickMemory(point,0,sizeof(point));
1607   (void) ResetMagickMemory(first,0,sizeof(first));
1608   (void) ResetMagickMemory(last,0,sizeof(last));
1609   knot_count=0;
1610   in_subpath=MagickFalse;
1611   while (length > 0)
1612   {
1613     selector=(ssize_t) ReadPropertyMSBShort(&blob,&length);
1614     switch (selector)
1615     {
1616       case 0:
1617       case 3:
1618       {
1619         if (knot_count != 0)
1620           {
1621             blob+=24;
1622             length-=24;
1623             break;
1624           }
1625         /*
1626           Expected subpath length record.
1627         */
1628         knot_count=(ssize_t) ReadPropertyMSBShort(&blob,&length);
1629         blob+=22;
1630         length-=22;
1631         break;
1632       }
1633       case 1:
1634       case 2:
1635       case 4:
1636       case 5:
1637       {
1638         if (knot_count == 0)
1639           {
1640             /*
1641               Unexpected subpath knot
1642             */
1643             blob+=24;
1644             length-=24;
1645             break;
1646           }
1647         /*
1648           Add sub-path knot
1649         */
1650         for (i=0; i < 3; i++)
1651         {
1652           size_t
1653             xx,
1654             yy;
1655
1656           yy=ReadPropertyMSBLong(&blob,&length);
1657           xx=ReadPropertyMSBLong(&blob,&length);
1658           x=(ssize_t) xx;
1659           if (xx > 2147483647)
1660             x=(ssize_t) xx-4294967295U-1;
1661           y=(ssize_t) yy;
1662           if (yy > 2147483647)
1663             y=(ssize_t) yy-4294967295U-1;
1664           point[i].x=(double) x/4096/4096;
1665           point[i].y=1.0-(double) y/4096/4096;
1666         }
1667         if (in_subpath == MagickFalse)
1668           {
1669             (void) FormatLocaleString(message,MaxTextExtent,"  %g %g m\n",
1670               point[1].x,point[1].y);
1671             for (i=0; i < 3; i++)
1672             {
1673               first[i]=point[i];
1674               last[i]=point[i];
1675             }
1676           }
1677         else
1678           {
1679             /*
1680               Handle special cases when Bezier curves are used to describe
1681               corners and straight lines.
1682             */
1683             if ((last[1].x == last[2].x) && (last[1].y == last[2].y) &&
1684                 (point[0].x == point[1].x) && (point[0].y == point[1].y))
1685               (void) FormatLocaleString(message,MaxTextExtent,
1686                 "  %g %g l\n",point[1].x,point[1].y);
1687             else
1688               if ((last[1].x == last[2].x) && (last[1].y == last[2].y))
1689                 (void) FormatLocaleString(message,MaxTextExtent,
1690                   "  %g %g %g %g v\n",point[0].x,point[0].y,
1691                   point[1].x,point[1].y);
1692               else
1693                 if ((point[0].x == point[1].x) && (point[0].y == point[1].y))
1694                   (void) FormatLocaleString(message,MaxTextExtent,
1695                     "  %g %g %g %g y\n",last[2].x,last[2].y,
1696                     point[1].x,point[1].y);
1697                 else
1698                   (void) FormatLocaleString(message,MaxTextExtent,
1699                     "  %g %g %g %g %g %g c\n",last[2].x,
1700                     last[2].y,point[0].x,point[0].y,point[1].x,point[1].y);
1701             for (i=0; i < 3; i++)
1702               last[i]=point[i];
1703           }
1704         (void) ConcatenateString(&path,message);
1705         in_subpath=MagickTrue;
1706         knot_count--;
1707         /*
1708           Close the subpath if there are no more knots.
1709         */
1710         if (knot_count == 0)
1711           {
1712             /*
1713               Same special handling as above except we compare to the
1714               first point in the path and close the path.
1715             */
1716             if ((last[1].x == last[2].x) && (last[1].y == last[2].y) &&
1717                 (first[0].x == first[1].x) && (first[0].y == first[1].y))
1718               (void) FormatLocaleString(message,MaxTextExtent,
1719                 "  %g %g l z\n",first[1].x,first[1].y);
1720             else
1721               if ((last[1].x == last[2].x) && (last[1].y == last[2].y))
1722                 (void) FormatLocaleString(message,MaxTextExtent,
1723                   "  %g %g %g %g v z\n",first[0].x,first[0].y,
1724                   first[1].x,first[1].y);
1725               else
1726                 if ((first[0].x == first[1].x) && (first[0].y == first[1].y))
1727                   (void) FormatLocaleString(message,MaxTextExtent,
1728                     "  %g %g %g %g y z\n",last[2].x,last[2].y,
1729                     first[1].x,first[1].y);
1730                 else
1731                   (void) FormatLocaleString(message,MaxTextExtent,
1732                     "  %g %g %g %g %g %g c z\n",last[2].x,
1733                     last[2].y,first[0].x,first[0].y,first[1].x,first[1].y);
1734             (void) ConcatenateString(&path,message);
1735             in_subpath=MagickFalse;
1736           }
1737         break;
1738       }
1739       case 6:
1740       case 7:
1741       case 8:
1742       default:
1743       {
1744         blob+=24;
1745         length-=24;
1746         break;
1747       }
1748     }
1749   }
1750   /*
1751     Returns an empty PS path if the path has no knots.
1752   */
1753   (void) FormatLocaleString(message,MaxTextExtent,"  eoclip\n");
1754   (void) ConcatenateString(&path,message);
1755   (void) FormatLocaleString(message,MaxTextExtent,"} bind def");
1756   (void) ConcatenateString(&path,message);
1757   message=DestroyString(message);
1758   return(path);
1759 }
1760
1761 static char *TraceSVGClippath(const unsigned char *blob,size_t length,
1762   const size_t columns,const size_t rows)
1763 {
1764   char
1765     *path,
1766     *message;
1767
1768   MagickBooleanType
1769     in_subpath;
1770
1771   PointInfo
1772     first[3],
1773     last[3],
1774     point[3];
1775
1776   register ssize_t
1777     i;
1778
1779   ssize_t
1780     knot_count,
1781     selector,
1782     x,
1783     y;
1784
1785   path=AcquireString((char *) NULL);
1786   if (path == (char *) NULL)
1787     return((char *) NULL);
1788   message=AcquireString((char *) NULL);
1789   (void) FormatLocaleString(message,MaxTextExtent,
1790     "<?xml version=\"1.0\" encoding=\"iso-8859-1\"?>\n");
1791   (void) ConcatenateString(&path,message);
1792   (void) FormatLocaleString(message,MaxTextExtent,
1793     "<svg width=\"%.20g\" height=\"%.20g\">\n",(double) columns,(double) rows);
1794   (void) ConcatenateString(&path,message);
1795   (void) FormatLocaleString(message,MaxTextExtent,"<g>\n");
1796   (void) ConcatenateString(&path,message);
1797   (void) FormatLocaleString(message,MaxTextExtent,
1798     "<path style=\"fill:#00000000;stroke:#00000000;");
1799   (void) ConcatenateString(&path,message);
1800   (void) FormatLocaleString(message,MaxTextExtent,
1801     "stroke-width:0;stroke-antialiasing:false\" d=\"\n");
1802   (void) ConcatenateString(&path,message);
1803   (void) ResetMagickMemory(point,0,sizeof(point));
1804   (void) ResetMagickMemory(first,0,sizeof(first));
1805   (void) ResetMagickMemory(last,0,sizeof(last));
1806   knot_count=0;
1807   in_subpath=MagickFalse;
1808   while (length != 0)
1809   {
1810     selector=(ssize_t) ReadPropertyMSBShort(&blob,&length);
1811     switch (selector)
1812     {
1813       case 0:
1814       case 3:
1815       {
1816         if (knot_count != 0)
1817           {
1818             blob+=24;
1819             length-=24;
1820             break;
1821           }
1822         /*
1823           Expected subpath length record.
1824         */
1825         knot_count=(ssize_t) ReadPropertyMSBShort(&blob,&length);
1826         blob+=22;
1827         length-=22;
1828         break;
1829       }
1830       case 1:
1831       case 2:
1832       case 4:
1833       case 5:
1834       {
1835         if (knot_count == 0)
1836           {
1837             /*
1838               Unexpected subpath knot.
1839             */
1840             blob+=24;
1841             length-=24;
1842             break;
1843           }
1844         /*
1845           Add sub-path knot
1846         */
1847         for (i=0; i < 3; i++)
1848         {
1849           size_t
1850             xx,
1851             yy;
1852
1853           yy=ReadPropertyMSBLong(&blob,&length);
1854           xx=ReadPropertyMSBLong(&blob,&length);
1855           x=(ssize_t) xx;
1856           if (xx > 2147483647)
1857             x=(ssize_t) xx-4294967295U-1;
1858           y=(ssize_t) yy;
1859           if (yy > 2147483647)
1860             y=(ssize_t) yy-4294967295U-1;
1861           point[i].x=(double) x*columns/4096/4096;
1862           point[i].y=(double) y*rows/4096/4096;
1863         }
1864         if (in_subpath == MagickFalse)
1865           {
1866             (void) FormatLocaleString(message,MaxTextExtent,"M %g,%g\n",
1867               point[1].x,point[1].y);
1868             for (i=0; i < 3; i++)
1869             {
1870               first[i]=point[i];
1871               last[i]=point[i];
1872             }
1873           }
1874         else
1875           {
1876             if ((last[1].x == last[2].x) && (last[1].y == last[2].y) &&
1877                 (point[0].x == point[1].x) && (point[0].y == point[1].y))
1878               (void) FormatLocaleString(message,MaxTextExtent,"L %g,%g\n",
1879                 point[1].x,point[1].y);
1880             else
1881               (void) FormatLocaleString(message,MaxTextExtent,
1882                 "C %g,%g %g,%g %g,%g\n",last[2].x,last[2].y,
1883                 point[0].x,point[0].y,point[1].x,point[1].y);
1884             for (i=0; i < 3; i++)
1885               last[i]=point[i];
1886           }
1887         (void) ConcatenateString(&path,message);
1888         in_subpath=MagickTrue;
1889         knot_count--;
1890         /*
1891           Close the subpath if there are no more knots.
1892         */
1893         if (knot_count == 0)
1894           {
1895             if ((last[1].x == last[2].x) && (last[1].y == last[2].y) &&
1896                 (first[0].x == first[1].x) && (first[0].y == first[1].y))
1897               (void) FormatLocaleString(message,MaxTextExtent,
1898                 "L %g,%g Z\n",first[1].x,first[1].y);
1899             else
1900               {
1901                 (void) FormatLocaleString(message,MaxTextExtent,
1902                   "C %g,%g %g,%g %g,%g Z\n",last[2].x,
1903                   last[2].y,first[0].x,first[0].y,first[1].x,first[1].y);
1904                 (void) ConcatenateString(&path,message);
1905               }
1906             in_subpath=MagickFalse;
1907           }
1908         break;
1909       }
1910       case 6:
1911       case 7:
1912       case 8:
1913       default:
1914       {
1915         blob+=24;
1916         length-=24;
1917         break;
1918       }
1919     }
1920   }
1921   /*
1922     Return an empty SVG image if the path does not have knots.
1923   */
1924   (void) FormatLocaleString(message,MaxTextExtent,"\"/>\n");
1925   (void) ConcatenateString(&path,message);
1926   (void) FormatLocaleString(message,MaxTextExtent,"</g>\n");
1927   (void) ConcatenateString(&path,message);
1928   (void) FormatLocaleString(message,MaxTextExtent,"</svg>\n");
1929   (void) ConcatenateString(&path,message);
1930   message=DestroyString(message);
1931   return(path);
1932 }
1933
1934 MagickExport const char *GetImageProperty(const Image *image,
1935   const char *property)
1936 {
1937   ExceptionInfo
1938     *exception;
1939
1940   FxInfo
1941     *fx_info;
1942
1943   MagickRealType
1944     alpha;
1945
1946   MagickStatusType
1947     status;
1948
1949   register const char
1950     *p;
1951
1952   assert(image != (Image *) NULL);
1953   assert(image->signature == MagickSignature);
1954   if (image->debug != MagickFalse)
1955     (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1956   p=(const char *) NULL;
1957   if (image->properties != (void *) NULL)
1958     {
1959       if (property == (const char *) NULL)
1960         {
1961           ResetSplayTreeIterator((SplayTreeInfo *) image->properties);
1962           p=(const char *) GetNextValueInSplayTree((SplayTreeInfo *)
1963             image->properties);
1964           return(p);
1965         }
1966       if (LocaleNCompare("fx:",property,3) != 0)
1967         {
1968           p=(const char *) GetValueFromSplayTree((SplayTreeInfo *)
1969             image->properties,property);
1970           if (p != (const char *) NULL)
1971             return(p);
1972         }
1973     }
1974   if ((property == (const char *) NULL) ||
1975       (strchr(property,':') == (char *) NULL))
1976     return(p);
1977   exception=(&((Image *) image)->exception);
1978   switch (*property)
1979   {
1980     case '8':
1981     {
1982       if (LocaleNCompare("8bim:",property,5) == 0)
1983         {
1984           if ((Get8BIMProperty(image,property) != MagickFalse) &&
1985               (image->properties != (void *) NULL))
1986             {
1987               p=(const char *) GetValueFromSplayTree((SplayTreeInfo *)
1988                 image->properties,property);
1989               return(p);
1990             }
1991         }
1992       break;
1993     }
1994     case 'E':
1995     case 'e':
1996     {
1997       if (LocaleNCompare("exif:",property,5) == 0)
1998         {
1999           if ((GetEXIFProperty(image,property) != MagickFalse) &&
2000               (image->properties != (void *) NULL))
2001             {
2002               p=(const char *) GetValueFromSplayTree((SplayTreeInfo *)
2003                 image->properties,property);
2004               return(p);
2005             }
2006         }
2007       break;
2008     }
2009     case 'F':
2010     case 'f':
2011     {
2012       if (LocaleNCompare("fx:",property,3) == 0)
2013         {
2014           fx_info=AcquireFxInfo(image,property+3);
2015           status=FxEvaluateChannelExpression(fx_info,IntensityPixelChannel,0,0,
2016             &alpha,exception);
2017           fx_info=DestroyFxInfo(fx_info);
2018           if (status != MagickFalse)
2019             {
2020               char
2021                 value[MaxTextExtent];
2022
2023               (void) FormatLocaleString(value,MaxTextExtent,"%.*g",
2024                 GetMagickPrecision(),(double) alpha);
2025               (void) SetImageProperty((Image *) image,property,value);
2026             }
2027           if (image->properties != (void *) NULL)
2028             {
2029               p=(const char *) GetValueFromSplayTree((SplayTreeInfo *)
2030                 image->properties,property);
2031               return(p);
2032             }
2033         }
2034       break;
2035     }
2036     case 'I':
2037     case 'i':
2038     {
2039       if (LocaleNCompare("iptc:",property,5) == 0)
2040         {
2041           if ((GetIPTCProperty(image,property) != MagickFalse) &&
2042               (image->properties != (void *) NULL))
2043             {
2044               p=(const char *) GetValueFromSplayTree((SplayTreeInfo *)
2045                 image->properties,property);
2046               return(p);
2047             }
2048         }
2049       break;
2050     }
2051     case 'P':
2052     case 'p':
2053     {
2054       if (LocaleNCompare("pixel:",property,6) == 0)
2055         {
2056           PixelInfo
2057             pixel;
2058
2059           GetPixelInfo(image,&pixel);
2060           fx_info=AcquireFxInfo(image,property+6);
2061           status=FxEvaluateChannelExpression(fx_info,RedPixelChannel,0,0,
2062             &alpha,exception);
2063           pixel.red=(MagickRealType) QuantumRange*alpha;
2064           status|=FxEvaluateChannelExpression(fx_info,GreenPixelChannel,0,0,
2065             &alpha,exception);
2066           pixel.green=(MagickRealType) QuantumRange*alpha;
2067           status|=FxEvaluateChannelExpression(fx_info,BluePixelChannel,0,0,
2068             &alpha,exception);
2069           pixel.blue=(MagickRealType) QuantumRange*alpha;
2070           if (image->colorspace == CMYKColorspace)
2071             {
2072               status|=FxEvaluateChannelExpression(fx_info,BlackPixelChannel,0,0,
2073                 &alpha,exception);
2074               pixel.black=(MagickRealType) QuantumRange*alpha;
2075             }
2076           status|=FxEvaluateChannelExpression(fx_info,AlphaPixelChannel,0,0,
2077             &alpha,exception);
2078           pixel.alpha=(MagickRealType) QuantumRange*(1.0-alpha);
2079           fx_info=DestroyFxInfo(fx_info);
2080           if (status != MagickFalse)
2081             {
2082               char
2083                 name[MaxTextExtent];
2084
2085               (void) QueryMagickColorname(image,&pixel,SVGCompliance,name,
2086                 exception);
2087               (void) SetImageProperty((Image *) image,property,name);
2088               return(GetImageProperty(image,property));
2089             }
2090         }
2091       break;
2092     }
2093     case 'X':
2094     case 'x':
2095     {
2096       if (LocaleNCompare("xmp:",property,4) == 0)
2097         {
2098           if ((GetXMPProperty(image,property) != MagickFalse) &&
2099               (image->properties != (void *) NULL))
2100             {
2101               p=(const char *) GetValueFromSplayTree((SplayTreeInfo *)
2102                 image->properties,property);
2103               return(p);
2104             }
2105         }
2106       break;
2107     }
2108     default:
2109       break;
2110   }
2111   return(p);
2112 }
2113 \f
2114 /*
2115 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2116 %                                                                             %
2117 %                                                                             %
2118 %                                                                             %
2119 +   G e t M a g i c k P r o p e r t y                                         %
2120 %                                                                             %
2121 %                                                                             %
2122 %                                                                             %
2123 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2124 %
2125 %  GetMagickProperty() gets a value associated with an image property.
2126 %
2127 %  The format of the GetMagickProperty method is:
2128 %
2129 %      const char *GetMagickProperty(const ImageInfo *image_info,Image *image,
2130 %        const char *key)
2131 %
2132 %  A description of each parameter follows:
2133 %
2134 %    o image_info: the image info.
2135 %
2136 %    o image: the image.
2137 %
2138 %    o key: the key.
2139 %
2140 */
2141 MagickExport const char *GetMagickProperty(const ImageInfo *image_info,
2142   Image *image,const char *property)
2143 {
2144   char
2145     value[MaxTextExtent],
2146     filename[MaxTextExtent];
2147
2148   *value='\0';
2149   switch (*property)
2150   {
2151     case 'b':
2152     {
2153       if (LocaleNCompare("base",property,4) == 0)
2154         {
2155           GetPathComponent(image->magick_filename,BasePath,filename);
2156           (void) CopyMagickString(value,filename,MaxTextExtent);
2157           break;
2158         }
2159       break;
2160     }
2161     case 'c':
2162     {
2163       if (LocaleNCompare("channels",property,8) == 0)
2164         {
2165           /*
2166             Image channels.
2167           */
2168           (void) FormatLocaleString(value,MaxTextExtent,"%s",
2169             CommandOptionToMnemonic(MagickColorspaceOptions,(ssize_t)
2170             image->colorspace));
2171           LocaleLower(value);
2172           if (image->matte != MagickFalse)
2173             (void) ConcatenateMagickString(value,"a",MaxTextExtent);
2174           break;
2175         }
2176       if (LocaleNCompare("colorspace",property,10) == 0)
2177         {
2178           ColorspaceType
2179             colorspace;
2180
2181           /*
2182             Image storage class and colorspace.
2183           */
2184           colorspace=image->colorspace;
2185           if (IsImageGray(image,&image->exception) != MagickFalse)
2186             colorspace=GRAYColorspace;
2187           (void) FormatLocaleString(value,MaxTextExtent,"%s",
2188             CommandOptionToMnemonic(MagickColorspaceOptions,(ssize_t)
2189             colorspace));
2190           break;
2191         }
2192       if (LocaleNCompare("copyright",property,9) == 0)
2193         {
2194           (void) CopyMagickString(value,GetMagickCopyright(),MaxTextExtent);
2195           break;
2196         }
2197       break;
2198     }
2199     case 'd':
2200     {
2201       if (LocaleNCompare("depth",property,5) == 0)
2202         {
2203           (void) FormatLocaleString(value,MaxTextExtent,"%.20g",(double)
2204             image->depth);
2205           break;
2206         }
2207       if (LocaleNCompare("directory",property,9) == 0)
2208         {
2209           GetPathComponent(image->magick_filename,HeadPath,filename);
2210           (void) CopyMagickString(value,filename,MaxTextExtent);
2211           break;
2212         }
2213       break;
2214     }
2215     case 'e':
2216     {
2217       if (LocaleNCompare("extension",property,9) == 0)
2218         {
2219           GetPathComponent(image->magick_filename,ExtensionPath,filename);
2220           (void) CopyMagickString(value,filename,MaxTextExtent);
2221           break;
2222         }
2223       break;
2224     }
2225     case 'g':
2226     {
2227       if (LocaleNCompare("group",property,5) == 0)
2228         {
2229           (void) FormatLocaleString(value,MaxTextExtent,"0x%lx",
2230             (unsigned long) image_info->group);
2231           break;
2232         }
2233       break;
2234     }
2235     case 'h':
2236     {
2237       if (LocaleNCompare("height",property,6) == 0)
2238         {
2239           (void) FormatLocaleString(value,MaxTextExtent,"%.20g",
2240             image->magick_rows != 0 ? (double) image->magick_rows : 256.0);
2241           break;
2242         }
2243       break;
2244     }
2245     case 'i':
2246     {
2247       if (LocaleNCompare("input",property,5) == 0)
2248         {
2249           (void) CopyMagickString(value,image->filename,MaxTextExtent);
2250           break;
2251         }
2252       break;
2253     }
2254     case 'k':
2255     {
2256       if (LocaleNCompare("kurtosis",property,8) == 0)
2257         {
2258           double
2259             kurtosis,
2260             skewness;
2261
2262           (void) GetImageKurtosis(image,&kurtosis,&skewness,&image->exception);
2263           (void) FormatLocaleString(value,MaxTextExtent,"%.*g",
2264             GetMagickPrecision(),kurtosis);
2265           break;
2266         }
2267       break;
2268     }
2269     case 'm':
2270     {
2271       if (LocaleNCompare("magick",property,6) == 0)
2272         {
2273           (void) CopyMagickString(value,image->magick,MaxTextExtent);
2274           break;
2275         }
2276       if (LocaleNCompare("max",property,3) == 0)
2277         {
2278           double
2279             maximum,
2280             minimum;
2281
2282           (void) GetImageRange(image,&minimum,&maximum,&image->exception);
2283           (void) FormatLocaleString(value,MaxTextExtent,"%.*g",
2284             GetMagickPrecision(),maximum);
2285           break;
2286         }
2287       if (LocaleNCompare("mean",property,4) == 0)
2288         {
2289           double
2290             mean,
2291             standard_deviation;
2292
2293           (void) GetImageMean(image,&mean,&standard_deviation,
2294              &image->exception);
2295           (void) FormatLocaleString(value,MaxTextExtent,"%.*g",
2296             GetMagickPrecision(),mean);
2297           break;
2298         }
2299       if (LocaleNCompare("min",property,3) == 0)
2300         {
2301           double
2302             maximum,
2303             minimum;
2304
2305           (void) GetImageRange(image,&minimum,&maximum,&image->exception);
2306           (void) FormatLocaleString(value,MaxTextExtent,"%.*g",
2307             GetMagickPrecision(),minimum);
2308           break;
2309         }
2310       break;
2311     }
2312     case 'n':
2313     {
2314       if (LocaleNCompare("name",property,4) == 0)
2315         {
2316           (void) CopyMagickString(value,filename,MaxTextExtent);
2317           break;
2318         }
2319      break;
2320     }
2321     case 'o':
2322     {
2323       if (LocaleNCompare("opaque",property,6) == 0)
2324         {
2325           MagickBooleanType
2326             opaque;
2327
2328           opaque=IsImageOpaque(image,&image->exception);
2329           (void) CopyMagickString(value,opaque == MagickFalse ? "false" :
2330             "true",MaxTextExtent);
2331           break;
2332         }
2333       if (LocaleNCompare("output",property,6) == 0)
2334         {
2335           (void) CopyMagickString(value,image_info->filename,MaxTextExtent);
2336           break;
2337         }
2338      break;
2339     }
2340     case 'p':
2341     {
2342       if (LocaleNCompare("page",property,4) == 0)
2343         {
2344           (void) FormatLocaleString(value,MaxTextExtent,"%.20g",(double)
2345             GetImageIndexInList(image)+1);
2346           break;
2347         }
2348       break;
2349     }
2350     case 's':
2351     {
2352       if (LocaleNCompare("size",property,4) == 0)
2353         {
2354           char
2355             format[MaxTextExtent];
2356
2357           (void) FormatMagickSize(GetBlobSize(image),MagickFalse,format);
2358           (void) FormatLocaleString(value,MaxTextExtent,"%sB",format);
2359           break;
2360         }
2361       if (LocaleNCompare("scenes",property,6) == 0)
2362         {
2363           (void) FormatLocaleString(value,MaxTextExtent,"%.20g",(double)
2364             GetImageListLength(image));
2365           break;
2366         }
2367       if (LocaleNCompare("scene",property,5) == 0)
2368         {
2369           (void) FormatLocaleString(value,MaxTextExtent,"%.20g",(double)
2370             image->scene);
2371           if (image_info->number_scenes != 0)
2372             (void) FormatLocaleString(value,MaxTextExtent,"%.20g",(double)
2373               image_info->scene);
2374           break;
2375         }
2376       if (LocaleNCompare("skewness",property,8) == 0)
2377         {
2378           double
2379             kurtosis,
2380             skewness;
2381
2382           (void) GetImageKurtosis(image,&kurtosis,&skewness,&image->exception);
2383           (void) FormatLocaleString(value,MaxTextExtent,"%.*g",
2384             GetMagickPrecision(),skewness);
2385           break;
2386         }
2387       if (LocaleNCompare("standard-deviation",property,18) == 0)
2388         {
2389           double
2390             mean,
2391             standard_deviation;
2392
2393           (void) GetImageMean(image,&mean,&standard_deviation,
2394             &image->exception);
2395           (void) FormatLocaleString(value,MaxTextExtent,"%.*g",
2396             GetMagickPrecision(),standard_deviation);
2397           break;
2398         }
2399        break;
2400     }
2401     case 'u':
2402     {
2403       if (LocaleNCompare("unique",property,6) == 0)
2404         {
2405           (void) CopyMagickString(filename,image_info->unique,MaxTextExtent);
2406           (void) CopyMagickString(value,filename,MaxTextExtent);
2407           break;
2408         }
2409       break;
2410     }
2411     case 'v':
2412     {
2413       if (LocaleNCompare("version",property,7) == 0)
2414         {
2415           (void) CopyMagickString(value,GetMagickVersion((size_t *) NULL),
2416             MaxTextExtent);
2417           break;
2418         }
2419       break;
2420     }
2421     case 'w':
2422     {
2423       if (LocaleNCompare("width",property,5) == 0)
2424         {
2425           (void) FormatLocaleString(value,MaxTextExtent,"%.20g",(double)
2426             (image->magick_columns != 0 ? image->magick_columns : 256));
2427           break;
2428         }
2429       break;
2430     }
2431     case 'x':
2432     {
2433       if (LocaleNCompare("xresolution",property,11) == 0)
2434         {
2435           (void) FormatLocaleString(value,MaxTextExtent,"%g",
2436             image->x_resolution);
2437           break;
2438         }
2439       break;
2440     }
2441     case 'y':
2442     {
2443       if (LocaleNCompare("yresolution",property,11) == 0)
2444         {
2445           (void) FormatLocaleString(value,MaxTextExtent,"%g",
2446             image->y_resolution);
2447           break;
2448         }
2449       break;
2450     }
2451     case 'z':
2452     {
2453       if (LocaleNCompare("zero",property,4) == 0)
2454         {
2455           (void) CopyMagickString(filename,image_info->zero,MaxTextExtent);
2456           (void) CopyMagickString(value,filename,MaxTextExtent);
2457           break;
2458         }
2459       break;
2460     }
2461   }
2462   if (*value != '\0')
2463    {
2464      if (image->properties == (void *) NULL)
2465        image->properties=NewSplayTree(CompareSplayTreeString,
2466          RelinquishMagickMemory,RelinquishMagickMemory);
2467      (void) AddValueToSplayTree((SplayTreeInfo *) image->properties,
2468        ConstantString(property),ConstantString(value));
2469    }
2470   return(GetImageProperty(image,property));
2471 }
2472 \f
2473 /*
2474 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2475 %                                                                             %
2476 %                                                                             %
2477 %                                                                             %
2478 %   G e t N e x t I m a g e P r o p e r t y                                   %
2479 %                                                                             %
2480 %                                                                             %
2481 %                                                                             %
2482 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2483 %
2484 %  GetNextImageProperty() gets the next image property value.
2485 %
2486 %  The format of the GetNextImageProperty method is:
2487 %
2488 %      char *GetNextImageProperty(const Image *image)
2489 %
2490 %  A description of each parameter follows:
2491 %
2492 %    o image: the image.
2493 %
2494 */
2495 MagickExport char *GetNextImageProperty(const Image *image)
2496 {
2497   assert(image != (Image *) NULL);
2498   assert(image->signature == MagickSignature);
2499   if (image->debug != MagickFalse)
2500     (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
2501       image->filename);
2502   if (image->properties == (void *) NULL)
2503     return((char *) NULL);
2504   return((char *) GetNextKeyInSplayTree((SplayTreeInfo *) image->properties));
2505 }
2506 \f
2507 /*
2508 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2509 %                                                                             %
2510 %                                                                             %
2511 %                                                                             %
2512 %   I n t e r p r e t I m a g e P r o p e r t i e s                           %
2513 %                                                                             %
2514 %                                                                             %
2515 %                                                                             %
2516 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2517 %
2518 %  InterpretImageProperties() replaces any embedded formatting characters with
2519 %  the appropriate image property and returns the interpreted text.
2520 %
2521 %  The format of the InterpretImageProperties method is:
2522 %
2523 %      char *InterpretImageProperties(const ImageInfo *image_info,Image *image,
2524 %        const char *embed_text)
2525 %
2526 %  A description of each parameter follows:
2527 %
2528 %    o image_info: the image info.
2529 %
2530 %    o image: the image.
2531 %
2532 %    o embed_text: the address of a character string containing the embedded
2533 %      formatting characters.
2534 %
2535 */
2536 MagickExport char *InterpretImageProperties(const ImageInfo *image_info,
2537   Image *image,const char *embed_text)
2538 {
2539   char
2540     filename[MaxTextExtent],
2541     *interpret_text,
2542     *text;
2543
2544   const char
2545     *value;
2546
2547   register char
2548     *q;
2549
2550   register const char
2551     *p;
2552
2553   register ssize_t
2554     i;
2555
2556   size_t
2557     extent,
2558     length;
2559
2560   assert(image != (Image *) NULL);
2561   assert(image->signature == MagickSignature);
2562   if (image->debug != MagickFalse)
2563     (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
2564   if ((embed_text == (const char *) NULL) || (*embed_text == '\0'))
2565     return((char *) NULL);
2566   text=(char *) embed_text;
2567   if ((*text == '@') && ((*(text+1) == '-') ||
2568       (IsPathAccessible(text+1) != MagickFalse)))
2569     return(FileToString(embed_text+1,~0,&image->exception));
2570   /*
2571     Translate any embedded format characters.
2572   */
2573   interpret_text=AcquireString(text);
2574   extent=MaxTextExtent;
2575   p=text;
2576   for (q=interpret_text; *p != '\0'; p++)
2577   {
2578     *q='\0';
2579     if ((size_t) (q-interpret_text+MaxTextExtent) >= extent)
2580       {
2581         extent+=MaxTextExtent;
2582         interpret_text=(char *) ResizeQuantumMemory(interpret_text,extent+
2583           MaxTextExtent+1,sizeof(*interpret_text));
2584         if (interpret_text == (char *) NULL)
2585           break;
2586         q=interpret_text+strlen(interpret_text);
2587       }
2588     /*
2589       Process formatting characters in text.
2590     */
2591     if ((*p == '\\') && (*(p+1) == 'r'))
2592       {
2593         *q++='\r';
2594         p++;
2595         continue;
2596       }
2597     if ((*p == '\\') && (*(p+1) == 'n'))
2598       {
2599         *q++='\n';
2600         p++;
2601         continue;
2602       }
2603     if (*p == '\\')
2604       {
2605         p++;
2606         *q++=(*p);
2607         continue;
2608       }
2609     if (*p != '%')
2610       {
2611         *q++=(*p);
2612         continue;
2613       }
2614     p++;
2615     switch (*p)
2616     {
2617       case 'b':
2618       {
2619         char
2620           format[MaxTextExtent];
2621
2622         /*
2623           File size.
2624         */
2625         (void) FormatLocaleString(format,MaxTextExtent,"%.20g",(double)
2626           ((MagickOffsetType) image->extent));
2627         if (image->extent != (MagickSizeType) ((size_t) image->extent))
2628           (void) FormatMagickSize(image->extent,MagickFalse,format);
2629         q+=ConcatenateMagickString(q,format,extent);
2630         q+=ConcatenateMagickString(q,"B",extent);
2631         break;
2632       }
2633       case 'c':
2634       {
2635         /*
2636           Image comment.
2637         */
2638         value=GetImageProperty(image,"comment");
2639         if (value == (const char *) NULL)
2640           break;
2641         length=strlen(value);
2642         if ((size_t) (q-interpret_text+length+1) >= extent)
2643           {
2644             extent+=length;
2645             interpret_text=(char *) ResizeQuantumMemory(interpret_text,extent+
2646               MaxTextExtent,sizeof(*interpret_text));
2647             if (interpret_text == (char *) NULL)
2648               break;
2649             q=interpret_text+strlen(interpret_text);
2650           }
2651         (void) CopyMagickString(q,value,extent);
2652         q+=length;
2653         break;
2654       }
2655       case 'd':
2656       case 'e':
2657       case 'f':
2658       case 't':
2659       {
2660         /*
2661           Label segment is the base of the filename.
2662         */
2663         if (*image->magick_filename == '\0')
2664           break;
2665         switch (*p)
2666         {
2667           case 'd':
2668           {
2669             /*
2670               Directory.
2671             */
2672             GetPathComponent(image->magick_filename,HeadPath,filename);
2673             q+=CopyMagickString(q,filename,extent);
2674             break;
2675           }
2676           case 'e':
2677           {
2678             /*
2679               Filename extension.
2680             */
2681             GetPathComponent(image->magick_filename,ExtensionPath,filename);
2682             q+=CopyMagickString(q,filename,extent);
2683             break;
2684           }
2685           case 'f':
2686           {
2687             /*
2688               Filename.
2689             */
2690             GetPathComponent(image->magick_filename,TailPath,filename);
2691             q+=CopyMagickString(q,filename,extent);
2692             break;
2693           }
2694           case 't':
2695           {
2696             /*
2697               Base filename.
2698             */
2699             GetPathComponent(image->magick_filename,BasePath,filename);
2700             q+=CopyMagickString(q,filename,extent);
2701             break;
2702           }
2703         }
2704         break;
2705       }
2706       case 'g':
2707       {
2708         /*
2709           Image geometry.
2710         */
2711         q+=FormatLocaleString(q,extent,"%.20gx%.20g%+.20g%+.20g",(double)
2712           image->page.width,(double) image->page.height,(double) image->page.x,
2713           (double) image->page.y);
2714         break;
2715       }
2716       case 'h':
2717       {
2718         /*
2719           Image height.
2720         */
2721         q+=FormatLocaleString(q,extent,"%.20g",(double) (image->rows != 0 ?
2722           image->rows : image->magick_rows));
2723         break;
2724       }
2725       case 'i':
2726       {
2727         /*
2728           Image filename.
2729         */
2730         q+=CopyMagickString(q,image->filename,extent);
2731         break;
2732       }
2733       case 'k':
2734       {
2735         /*
2736           Number of unique colors.
2737         */
2738         q+=FormatLocaleString(q,extent,"%.20g",(double) GetNumberColors(image,
2739           (FILE *) NULL,&image->exception));
2740         break;
2741       }
2742       case 'l':
2743       {
2744         /*
2745           Image label.
2746         */
2747         value=GetImageProperty(image,"label");
2748         if (value == (const char *) NULL)
2749           break;
2750         length=strlen(value);
2751         if ((size_t) (q-interpret_text+length+1) >= extent)
2752           {
2753             extent+=length;
2754             interpret_text=(char *) ResizeQuantumMemory(interpret_text,extent+
2755               MaxTextExtent,sizeof(*interpret_text));
2756             if (interpret_text == (char *) NULL)
2757               break;
2758             q=interpret_text+strlen(interpret_text);
2759           }
2760         q+=CopyMagickString(q,value,extent);
2761         break;
2762       }
2763       case 'm':
2764       {
2765         /*
2766           Image format.
2767         */
2768         q+=CopyMagickString(q,image->magick,extent);
2769         break;
2770       }
2771       case 'M':
2772       {
2773         /*
2774           Image magick filename.
2775         */
2776         q+=CopyMagickString(q,image->magick_filename,extent);
2777         break;
2778       }
2779       case 'n':
2780       {
2781         /*
2782           Number of images in the list.
2783         */
2784         q+=FormatLocaleString(q,extent,"%.20g",(double)
2785           GetImageListLength(image));
2786         break;
2787       }
2788       case 'o':
2789       {
2790         /*
2791           Image output filename.
2792         */
2793         q+=CopyMagickString(q,image_info->filename,extent);
2794         break;
2795       }
2796       case 'p':
2797       {
2798         /*
2799           Image index in list.
2800         */
2801         q+=FormatLocaleString(q,extent,"%.20g",(double)
2802             GetImageIndexInList(image));
2803         break;
2804       }
2805       case 'q':
2806       {
2807         /*
2808           Image depth.
2809         */
2810         q+=FormatLocaleString(q,extent,"%.20g",(double)
2811           MAGICKCORE_QUANTUM_DEPTH);
2812         break;
2813       }
2814       case 'r':
2815       {
2816         ColorspaceType
2817           colorspace;
2818
2819         /*
2820           Image storage class and colorspace.
2821         */
2822         colorspace=image->colorspace;
2823         if (IsImageGray(image,&image->exception) != MagickFalse)
2824           colorspace=GRAYColorspace;
2825         q+=FormatLocaleString(q,extent,"%s%s%s",CommandOptionToMnemonic(
2826           MagickClassOptions,(ssize_t) image->storage_class),
2827           CommandOptionToMnemonic(MagickColorspaceOptions,(ssize_t) colorspace),
2828           image->matte != MagickFalse ? "Matte" : "");
2829         break;
2830       }
2831       case 's':
2832       {
2833         /*
2834           Image scene number.
2835         */
2836         if (image_info->number_scenes == 0)
2837           q+=FormatLocaleString(q,extent,"%.20g",(double) image->scene);
2838         else
2839           q+=FormatLocaleString(q,extent,"%.20g",(double) image_info->scene);
2840         break;
2841       }
2842       case 'u':
2843       {
2844         /*
2845           Unique filename.
2846         */
2847         (void) CopyMagickString(filename,image_info->unique,extent);
2848         q+=CopyMagickString(q,filename,extent);
2849         break;
2850       }
2851       case 'w':
2852       {
2853         /*
2854           Image width.
2855         */
2856         q+=FormatLocaleString(q,extent,"%.20g",(double) (image->columns != 0 ?
2857           image->columns : image->magick_columns));
2858         break;
2859       }
2860       case 'x':
2861       {
2862         /*
2863           Image horizontal resolution.
2864         */
2865         q+=FormatLocaleString(q,extent,"%g %s",image->x_resolution,
2866           CommandOptionToMnemonic(MagickResolutionOptions,(ssize_t)
2867             image->units));
2868         break;
2869       }
2870       case 'y':
2871       {
2872         /*
2873           Image vertical resolution.
2874         */
2875         q+=FormatLocaleString(q,extent,"%g %s",image->y_resolution,
2876           CommandOptionToMnemonic(MagickResolutionOptions,(ssize_t)
2877           image->units));
2878         break;
2879       }
2880       case 'z':
2881       {
2882         /*
2883           Image depth.
2884         */
2885         q+=FormatLocaleString(q,extent,"%.20g",(double) image->depth);
2886         break;
2887       }
2888       case 'A':
2889       {
2890         /*
2891           Image alpha channel.
2892         */
2893         q+=FormatLocaleString(q,extent,"%s",CommandOptionToMnemonic(
2894           MagickBooleanOptions,(ssize_t) image->matte));
2895         break;
2896       }
2897       case 'C':
2898       {
2899         /*
2900           Image compression method.
2901         */
2902         q+=FormatLocaleString(q,extent,"%s",CommandOptionToMnemonic(
2903           MagickCompressOptions,(ssize_t) image->compression));
2904         break;
2905       }
2906       case 'D':
2907       {
2908         /*
2909           Image dispose method.
2910         */
2911         q+=FormatLocaleString(q,extent,"%s",CommandOptionToMnemonic(
2912           MagickDisposeOptions,(ssize_t) image->dispose));
2913         break;
2914       }
2915       case 'G':
2916       {
2917         q+=FormatLocaleString(q,extent,"%.20gx%.20g",(double)
2918           image->magick_columns,(double) image->magick_rows);
2919         break;
2920       }
2921       case 'H':
2922       {
2923         q+=FormatLocaleString(q,extent,"%.20g",(double) image->page.height);
2924         break;
2925       }
2926       case 'O':
2927       {
2928         q+=FormatLocaleString(q,extent,"%+ld%+ld",(long) image->page.x,(long)
2929           image->page.y);
2930         break;
2931       }
2932       case 'P':
2933       {
2934         q+=FormatLocaleString(q,extent,"%.20gx%.20g",(double) image->page.width,
2935           (double) image->page.height);
2936         break;
2937       }
2938       case 'Q':
2939       {
2940         q+=FormatLocaleString(q,extent,"%.20g",(double) image->quality);
2941         break;
2942       }
2943       case 'S':
2944       {
2945         /*
2946           Image scenes.
2947         */
2948         if (image_info->number_scenes == 0)
2949           q+=CopyMagickString(q,"2147483647",extent);
2950         else
2951           q+=FormatLocaleString(q,extent,"%.20g",(double) (image_info->scene+
2952             image_info->number_scenes));
2953         break;
2954       }
2955       case 'T':
2956       {
2957         q+=FormatLocaleString(q,extent,"%.20g",(double) image->delay);
2958         break;
2959       }
2960       case 'W':
2961       {
2962         q+=FormatLocaleString(q,extent,"%.20g",(double) image->page.width);
2963         break;
2964       }
2965       case 'X':
2966       {
2967         q+=FormatLocaleString(q,extent,"%+.20g",(double) image->page.x);
2968         break;
2969       }
2970       case 'Y':
2971       {
2972         q+=FormatLocaleString(q,extent,"%+.20g",(double) image->page.y);
2973         break;
2974       }
2975       case 'Z':
2976       {
2977         /*
2978           Unique filename.
2979         */
2980         (void) CopyMagickString(filename,image_info->zero,extent);
2981         q+=CopyMagickString(q,filename,extent);
2982         break;
2983       }
2984       case '[':
2985       {
2986         char
2987           pattern[MaxTextExtent];
2988
2989         const char
2990           *key,
2991           *value;
2992
2993         ssize_t
2994           depth;
2995
2996         /*
2997           Image value.
2998         */
2999         if (strchr(p,']') == (char *) NULL)
3000           break;
3001         depth=1;
3002         p++;
3003         for (i=0; (i < (MaxTextExtent-1L)) && (*p != '\0'); i++)
3004         {
3005           if (*p == '[')
3006             depth++;
3007           if (*p == ']')
3008             depth--;
3009           if (depth <= 0)
3010             break;
3011           pattern[i]=(*p++);
3012         }
3013         pattern[i]='\0';
3014         value=GetImageProperty(image,pattern);
3015         if (value != (const char *) NULL)
3016           {
3017             length=strlen(value);
3018             if ((size_t) (q-interpret_text+length+1) >= extent)
3019               {
3020                 extent+=length;
3021                 interpret_text=(char *) ResizeQuantumMemory(interpret_text,
3022                   extent+MaxTextExtent,sizeof(*interpret_text));
3023                 if (interpret_text == (char *) NULL)
3024                   break;
3025                 q=interpret_text+strlen(interpret_text);
3026               }
3027             (void) CopyMagickString(q,value,extent);
3028             q+=length;
3029             break;
3030           }
3031         else
3032           if (IsGlob(pattern) != MagickFalse)
3033             {
3034               /*
3035                 Iterate over image properties.
3036               */
3037               ResetImagePropertyIterator(image);
3038               key=GetNextImageProperty(image);
3039               while (key != (const char *) NULL)
3040               {
3041                 if (GlobExpression(key,pattern,MagickTrue) != MagickFalse)
3042                   {
3043                     value=GetImageProperty(image,key);
3044                     if (value != (const char *) NULL)
3045                       {
3046                         length=strlen(key)+strlen(value)+2;
3047                         if ((size_t) (q-interpret_text+length+1) >= extent)
3048                           {
3049                             extent+=length;
3050                             interpret_text=(char *) ResizeQuantumMemory(
3051                               interpret_text,extent+MaxTextExtent,
3052                               sizeof(*interpret_text));
3053                             if (interpret_text == (char *) NULL)
3054                               break;
3055                             q=interpret_text+strlen(interpret_text);
3056                           }
3057                         q+=FormatLocaleString(q,extent,"%s=%s\n",key,value);
3058                       }
3059                   }
3060                 key=GetNextImageProperty(image);
3061               }
3062             }
3063         value=GetMagickProperty(image_info,image,pattern);
3064         if (value != (const char *) NULL)
3065           {
3066             length=strlen(value);
3067             if ((size_t) (q-interpret_text+length+1) >= extent)
3068               {
3069                 extent+=length;
3070                 interpret_text=(char *) ResizeQuantumMemory(interpret_text,
3071                   extent+MaxTextExtent,sizeof(*interpret_text));
3072                 if (interpret_text == (char *) NULL)
3073                   break;
3074                 q=interpret_text+strlen(interpret_text);
3075               }
3076             (void) CopyMagickString(q,value,extent);
3077             q+=length;
3078             break;
3079           }
3080         if (image_info == (ImageInfo *) NULL)
3081           break;
3082         value=GetImageOption(image_info,pattern);
3083         if (value != (char *) NULL)
3084           {
3085             length=strlen(value);
3086             if ((size_t) (q-interpret_text+length+1) >= extent)
3087               {
3088                 extent+=length;
3089                 interpret_text=(char *) ResizeQuantumMemory(interpret_text,
3090                   extent+MaxTextExtent,sizeof(*interpret_text));
3091                 if (interpret_text == (char *) NULL)
3092                   break;
3093                 q=interpret_text+strlen(interpret_text);
3094               }
3095             (void) CopyMagickString(q,value,extent);
3096             q+=length;
3097             break;
3098           }
3099         break;
3100       }
3101       case '@':
3102       {
3103         RectangleInfo
3104           page;
3105
3106         /*
3107           Image bounding box.
3108         */
3109         page=GetImageBoundingBox(image,&image->exception);
3110         q+=FormatLocaleString(q,MaxTextExtent,"%.20gx%.20g%+.20g%+.20g",
3111           (double) page.width,(double) page.height,(double) page.x,(double)
3112           page.y);
3113         break;
3114       }
3115       case '#':
3116       {
3117         /*
3118           Image signature.
3119         */
3120         (void) SignatureImage(image);
3121         value=GetImageProperty(image,"signature");
3122         if (value == (const char *) NULL)
3123           break;
3124         q+=CopyMagickString(q,value,extent);
3125         break;
3126       }
3127       case '%':
3128       {
3129         *q++=(*p);
3130         break;
3131       }
3132       default:
3133       {
3134         *q++='%';
3135         *q++=(*p);
3136         break;
3137       }
3138     }
3139   }
3140   *q='\0';
3141   if (text != (const char *) embed_text)
3142     text=DestroyString(text);
3143   (void) SubstituteString(&interpret_text,"&lt;","<");
3144   (void) SubstituteString(&interpret_text,"&gt;",">");
3145   return(interpret_text);
3146 }
3147 \f
3148 /*
3149 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3150 %                                                                             %
3151 %                                                                             %
3152 %                                                                             %
3153 %   R e m o v e I m a g e P r o p e r t y                                     %
3154 %                                                                             %
3155 %                                                                             %
3156 %                                                                             %
3157 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3158 %
3159 %  RemoveImageProperty() removes a property from the image and returns its
3160 %  value.
3161 %
3162 %  The format of the RemoveImageProperty method is:
3163 %
3164 %      char *RemoveImageProperty(Image *image,const char *property)
3165 %
3166 %  A description of each parameter follows:
3167 %
3168 %    o image: the image.
3169 %
3170 %    o property: the image property.
3171 %
3172 */
3173 MagickExport char *RemoveImageProperty(Image *image,
3174   const char *property)
3175 {
3176   char
3177     *value;
3178
3179   assert(image != (Image *) NULL);
3180   assert(image->signature == MagickSignature);
3181   if (image->debug != MagickFalse)
3182     (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
3183       image->filename);
3184   if (image->properties == (void *) NULL)
3185     return((char *) NULL);
3186   value=(char *) RemoveNodeFromSplayTree((SplayTreeInfo *) image->properties,
3187     property);
3188   return(value);
3189 }
3190 \f
3191 /*
3192 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3193 %                                                                             %
3194 %                                                                             %
3195 %                                                                             %
3196 %   R e s e t I m a g e P r o p e r t y I t e r a t o r                       %
3197 %                                                                             %
3198 %                                                                             %
3199 %                                                                             %
3200 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3201 %
3202 %  ResetImagePropertyIterator() resets the image properties iterator.  Use it
3203 %  in conjunction with GetNextImageProperty() to iterate over all the values
3204 %  associated with an image property.
3205 %
3206 %  The format of the ResetImagePropertyIterator method is:
3207 %
3208 %      ResetImagePropertyIterator(Image *image)
3209 %
3210 %  A description of each parameter follows:
3211 %
3212 %    o image: the image.
3213 %
3214 */
3215 MagickExport void ResetImagePropertyIterator(const Image *image)
3216 {
3217   assert(image != (Image *) NULL);
3218   assert(image->signature == MagickSignature);
3219   if (image->debug != MagickFalse)
3220     (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
3221       image->filename);
3222   if (image->properties == (void *) NULL)
3223     return;
3224   ResetSplayTreeIterator((SplayTreeInfo *) image->properties);
3225 }
3226 \f
3227 /*
3228 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3229 %                                                                             %
3230 %                                                                             %
3231 %                                                                             %
3232 %   S e t I m a g e P r o p e r t y                                           %
3233 %                                                                             %
3234 %                                                                             %
3235 %                                                                             %
3236 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3237 %
3238 %  SetImageProperty() associates an value with an image property.
3239 %
3240 %  The format of the SetImageProperty method is:
3241 %
3242 %      MagickBooleanType SetImageProperty(Image *image,const char *property,
3243 %        const char *value)
3244 %
3245 %  A description of each parameter follows:
3246 %
3247 %    o image: the image.
3248 %
3249 %    o property: the image property.
3250 %
3251 %    o values: the image property values.
3252 %
3253 */
3254 MagickExport MagickBooleanType SetImageProperty(Image *image,
3255   const char *property,const char *value)
3256 {
3257   ExceptionInfo
3258     *exception;
3259
3260   MagickBooleanType
3261     status;
3262
3263   MagickStatusType
3264     flags;
3265
3266   assert(image != (Image *) NULL);
3267   assert(image->signature == MagickSignature);
3268   if (image->debug != MagickFalse)
3269     (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
3270       image->filename);
3271   if (image->properties == (void *) NULL)
3272     image->properties=NewSplayTree(CompareSplayTreeString,
3273       RelinquishMagickMemory,RelinquishMagickMemory);
3274   if ((value == (const char *) NULL) || (*value == '\0'))
3275     return(DeleteImageProperty(image,property));
3276   status=MagickTrue;
3277   exception=(&image->exception);
3278   switch (*property)
3279   {
3280     case 'B':
3281     case 'b':
3282     {
3283       if (LocaleCompare(property,"background") == 0)
3284         {
3285           (void) QueryColorDatabase(value,&image->background_color,exception);
3286           break;
3287         }
3288       if (LocaleCompare(property,"bias") == 0)
3289         {
3290           image->bias=SiPrefixToDouble(value,QuantumRange);
3291           break;
3292         }
3293       status=AddValueToSplayTree((SplayTreeInfo *) image->properties,
3294         ConstantString(property),ConstantString(value));
3295       break;
3296     }
3297     case 'C':
3298     case 'c':
3299     {
3300       if (LocaleCompare(property,"colorspace") == 0)
3301         {
3302           ssize_t
3303             colorspace;
3304
3305           colorspace=ParseCommandOption(MagickColorspaceOptions,MagickFalse,
3306             value);
3307           if (colorspace < 0)
3308             break;
3309           (void) SetImageColorspace(image,(ColorspaceType) colorspace,
3310             exception);
3311           break;
3312         }
3313       if (LocaleCompare(property,"compose") == 0)
3314         {
3315           ssize_t
3316             compose;
3317
3318           compose=ParseCommandOption(MagickComposeOptions,MagickFalse,value);
3319           if (compose < 0)
3320             break;
3321           image->compose=(CompositeOperator) compose;
3322           break;
3323         }
3324       if (LocaleCompare(property,"compress") == 0)
3325         {
3326           ssize_t
3327             compression;
3328
3329           compression=ParseCommandOption(MagickCompressOptions,MagickFalse,
3330             value);
3331           if (compression < 0)
3332             break;
3333           image->compression=(CompressionType) compression;
3334           break;
3335         }
3336       status=AddValueToSplayTree((SplayTreeInfo *) image->properties,
3337         ConstantString(property),ConstantString(value));
3338       break;
3339     }
3340     case 'D':
3341     case 'd':
3342     {
3343       if (LocaleCompare(property,"delay") == 0)
3344         {
3345           GeometryInfo
3346             geometry_info;
3347
3348           flags=ParseGeometry(value,&geometry_info);
3349           if ((flags & GreaterValue) != 0)
3350             {
3351               if (image->delay > (size_t) floor(geometry_info.rho+0.5))
3352                 image->delay=(size_t) floor(geometry_info.rho+0.5);
3353             }
3354           else
3355             if ((flags & LessValue) != 0)
3356               {
3357                 if (image->delay < (size_t) floor(geometry_info.rho+0.5))
3358                   image->ticks_per_second=(ssize_t)
3359                     floor(geometry_info.sigma+0.5);
3360               }
3361             else
3362               image->delay=(size_t) floor(geometry_info.rho+0.5);
3363           if ((flags & SigmaValue) != 0)
3364             image->ticks_per_second=(ssize_t) floor(geometry_info.sigma+0.5);
3365           break;
3366         }
3367       if (LocaleCompare(property,"density") == 0)
3368         {
3369           GeometryInfo
3370             geometry_info;
3371
3372           flags=ParseGeometry(value,&geometry_info);
3373           image->x_resolution=geometry_info.rho;
3374           image->y_resolution=geometry_info.sigma;
3375           if ((flags & SigmaValue) == 0)
3376             image->y_resolution=image->x_resolution;
3377         }
3378       if (LocaleCompare(property,"depth") == 0)
3379         {
3380           image->depth=StringToUnsignedLong(value);
3381           break;
3382         }
3383       if (LocaleCompare(property,"dispose") == 0)
3384         {
3385           ssize_t
3386             dispose;
3387
3388           dispose=ParseCommandOption(MagickDisposeOptions,MagickFalse,value);
3389           if (dispose < 0)
3390             break;
3391           image->dispose=(DisposeType) dispose;
3392           break;
3393         }
3394       status=AddValueToSplayTree((SplayTreeInfo *) image->properties,
3395         ConstantString(property),ConstantString(value));
3396       break;
3397     }
3398     case 'G':
3399     case 'g':
3400     {
3401       if (LocaleCompare(property,"gravity") == 0)
3402         {
3403           ssize_t
3404             gravity;
3405
3406           gravity=ParseCommandOption(MagickGravityOptions,MagickFalse,value);
3407           if (gravity < 0)
3408             break;
3409           image->gravity=(GravityType) gravity;
3410           break;
3411         }
3412       status=AddValueToSplayTree((SplayTreeInfo *) image->properties,
3413         ConstantString(property),ConstantString(value));
3414       break;
3415     }
3416     case 'I':
3417     case 'i':
3418     {
3419       if (LocaleCompare(property,"intent") == 0)
3420         {
3421           ssize_t
3422             rendering_intent;
3423
3424           rendering_intent=ParseCommandOption(MagickIntentOptions,MagickFalse,
3425             value);
3426           if (rendering_intent < 0)
3427             break;
3428           image->rendering_intent=(RenderingIntent) rendering_intent;
3429           break;
3430         }
3431       if (LocaleCompare(property,"interpolate") == 0)
3432         {
3433           ssize_t
3434             interpolate;
3435
3436           interpolate=ParseCommandOption(MagickInterpolateOptions,MagickFalse,
3437             value);
3438           if (interpolate < 0)
3439             break;
3440           image->interpolate=(InterpolatePixelMethod) interpolate;
3441           break;
3442         }
3443       status=AddValueToSplayTree((SplayTreeInfo *) image->properties,
3444         ConstantString(property),ConstantString(value));
3445       break;
3446     }
3447     case 'L':
3448     case 'l':
3449     {
3450       if (LocaleCompare(property,"loop") == 0)
3451         {
3452           image->iterations=StringToUnsignedLong(value);
3453           break;
3454         }
3455       status=AddValueToSplayTree((SplayTreeInfo *) image->properties,
3456         ConstantString(property),ConstantString(value));
3457       break;
3458     }
3459     case 'P':
3460     case 'p':
3461     {
3462       if (LocaleCompare(property,"page") == 0)
3463         {
3464           char
3465             *geometry;
3466
3467           geometry=GetPageGeometry(value);
3468           flags=ParseAbsoluteGeometry(geometry,&image->page);
3469           geometry=DestroyString(geometry);
3470           break;
3471         }
3472       if (LocaleCompare(property,"profile") == 0)
3473         {
3474           ImageInfo
3475             *image_info;
3476
3477           StringInfo
3478             *profile;
3479
3480           image_info=AcquireImageInfo();
3481           (void) CopyMagickString(image_info->filename,value,MaxTextExtent);
3482           (void) SetImageInfo(image_info,1,exception);
3483           profile=FileToStringInfo(image_info->filename,~0UL,exception);
3484           if (profile != (StringInfo *) NULL)
3485             status=SetImageProfile(image,image_info->magick,profile);
3486           image_info=DestroyImageInfo(image_info);
3487           break;
3488         }
3489       status=AddValueToSplayTree((SplayTreeInfo *) image->properties,
3490         ConstantString(property),ConstantString(value));
3491       break;
3492     }
3493     case 'R':
3494     case 'r':
3495     {
3496       if (LocaleCompare(property,"rendering-intent") == 0)
3497         {
3498           ssize_t
3499             rendering_intent;
3500
3501           rendering_intent=ParseCommandOption(MagickIntentOptions,MagickFalse,
3502             value);
3503           if (rendering_intent < 0)
3504             break;
3505           image->rendering_intent=(RenderingIntent) rendering_intent;
3506           break;
3507         }
3508       status=AddValueToSplayTree((SplayTreeInfo *) image->properties,
3509         ConstantString(property),ConstantString(value));
3510       break;
3511     }
3512     case 'T':
3513     case 't':
3514     {
3515       if (LocaleCompare(property,"tile-offset") == 0)
3516         {
3517           char
3518             *geometry;
3519
3520           geometry=GetPageGeometry(value);
3521           flags=ParseAbsoluteGeometry(geometry,&image->tile_offset);
3522           geometry=DestroyString(geometry);
3523           break;
3524         }
3525       status=AddValueToSplayTree((SplayTreeInfo *) image->properties,
3526         ConstantString(property),ConstantString(value));
3527       break;
3528     }
3529     case 'U':
3530     case 'u':
3531     {
3532       if (LocaleCompare(property,"units") == 0)
3533         {
3534           ssize_t
3535             units;
3536
3537           units=ParseCommandOption(MagickResolutionOptions,MagickFalse,value);
3538           if (units < 0)
3539             break;
3540           image->units=(ResolutionType) units;
3541           break;
3542         }
3543       status=AddValueToSplayTree((SplayTreeInfo *) image->properties,
3544         ConstantString(property),ConstantString(value));
3545       break;
3546     }
3547     default:
3548     {
3549       status=AddValueToSplayTree((SplayTreeInfo *) image->properties,
3550         ConstantString(property),ConstantString(value));
3551       break;
3552     }
3553   }
3554   return(status);
3555 }