]> 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)
1299                 (*(unsigned char *) p1));
1300               break;
1301             }
1302             case EXIF_FMT_SBYTE:
1303             {
1304               EXIFMultipleValues(1,"%.20g",(double) (*(signed char *) p1));
1305               break;
1306             }
1307             case EXIF_FMT_SSHORT:
1308             {
1309               EXIFMultipleValues(2,"%hd",ReadPropertyShort(endian,p1));
1310               break;
1311             }
1312             case EXIF_FMT_USHORT:
1313             {
1314               EXIFMultipleValues(2,"%hu",ReadPropertyShort(endian,p1));
1315               break;
1316             }
1317             case EXIF_FMT_ULONG:
1318             {
1319               EXIFMultipleValues(4,"%.20g",(double)
1320                 ReadPropertyLong(endian,p1));
1321               break;
1322             }
1323             case EXIF_FMT_SLONG:
1324             {
1325               EXIFMultipleValues(4,"%.20g",(double)
1326                 ReadPropertyLong(endian,p1));
1327               break;
1328             }
1329             case EXIF_FMT_URATIONAL:
1330             {
1331               EXIFMultipleFractions(8,"%.20g/%.20g",(double)
1332                 ReadPropertyLong(endian,p1),(double)
1333                 ReadPropertyLong(endian,p1+4));
1334               break;
1335             }
1336             case EXIF_FMT_SRATIONAL:
1337             {
1338               EXIFMultipleFractions(8,"%.20g/%.20g",(double)
1339                 ReadPropertyLong(endian,p1),(double)
1340                 ReadPropertyLong(endian,p1+4));
1341               break;
1342             }
1343             case EXIF_FMT_SINGLE:
1344             {
1345               EXIFMultipleValues(4,"%f",(double) *(float *) p1);
1346               break;
1347             }
1348             case EXIF_FMT_DOUBLE:
1349             {
1350               EXIFMultipleValues(8,"%f",*(double *) p1);
1351               break;
1352             }
1353             default:
1354             case EXIF_FMT_STRING:
1355             {
1356               value=(char *) NULL;
1357               if (~(1UL*number_bytes) >= 1)
1358                 value=(char *) AcquireQuantumMemory((size_t) number_bytes+1UL,
1359                   sizeof(*value));
1360               if (value != (char *) NULL)
1361                 {
1362                   register ssize_t
1363                     i;
1364
1365                   for (i=0; i < (ssize_t) number_bytes; i++)
1366                   {
1367                     value[i]='.';
1368                     if ((isprint((int) p[i]) != 0) || (p[i] == '\0'))
1369                       value[i]=(char) p[i];
1370                   }
1371                   value[i]='\0';
1372                 }
1373               break;
1374             }
1375           }
1376           if (value != (char *) NULL)
1377             {
1378               char
1379                 key[MaxTextExtent];
1380
1381               register const char
1382                 *p;
1383
1384               (void) CopyMagickString(key,property,MaxTextExtent);
1385               switch (all)
1386               {
1387                 case 1:
1388                 {
1389                   const char
1390                     *description;
1391
1392                   register ssize_t
1393                     i;
1394
1395                   description="unknown";
1396                   for (i=0; ; i++)
1397                   {
1398                     if (EXIFTag[i].tag == 0)
1399                       break;
1400                     if ((ssize_t) EXIFTag[i].tag == tag_value)
1401                       {
1402                         description=EXIFTag[i].description;
1403                         break;
1404                       }
1405                   }
1406                   (void) FormatLocaleString(key,MaxTextExtent,"%s",
1407                     description);
1408                   break;
1409                 }
1410                 case 2:
1411                 {
1412                   if (tag_value < 0x10000)
1413                     (void) FormatLocaleString(key,MaxTextExtent,"#%04lx",
1414                       (unsigned long) tag_value);
1415                   else
1416                     if (tag_value < 0x20000)
1417                       (void) FormatLocaleString(key,MaxTextExtent,"@%04lx",
1418                         (unsigned long) (tag_value & 0xffff));
1419                     else
1420                       (void) FormatLocaleString(key,MaxTextExtent,"unknown");
1421                   break;
1422                 }
1423               }
1424               p=(const char *) NULL;
1425               if (image->properties != (void *) NULL)
1426                 p=(const char *) GetValueFromSplayTree((SplayTreeInfo *)
1427                   image->properties,key);
1428               if (p == (const char *) NULL)
1429                 (void) SetImageProperty((Image *) image,key,value);
1430               value=DestroyString(value);
1431               status=MagickTrue;
1432             }
1433         }
1434         if ((tag_value == TAG_EXIF_OFFSET) ||
1435             (tag_value == TAG_INTEROP_OFFSET) ||
1436             (tag_value == TAG_GPS_OFFSET))
1437           {
1438             size_t
1439               offset;
1440
1441             offset=(size_t) ReadPropertyLong(endian,p);
1442             if ((offset < length) && (level < (MaxDirectoryStack-2)))
1443               {
1444                 size_t
1445                   tag_offset1;
1446
1447                 tag_offset1=(tag_value == TAG_GPS_OFFSET) ? 0x10000UL : 0UL;
1448                 directory_stack[level].directory=directory;
1449                 entry++;
1450                 directory_stack[level].entry=entry;
1451                 directory_stack[level].offset=tag_offset;
1452                 level++;
1453                 directory_stack[level].directory=exif+offset;
1454                 directory_stack[level].offset=tag_offset1;
1455                 directory_stack[level].entry=0;
1456                 level++;
1457                 if ((directory+2+(12*number_entries)) > (exif+length))
1458                   break;
1459                 offset=(size_t) ReadPropertyLong(endian,directory+2+(12*
1460                   number_entries));
1461                 if ((offset != 0) && (offset < length) &&
1462                     (level < (MaxDirectoryStack-2)))
1463                   {
1464                     directory_stack[level].directory=exif+offset;
1465                     directory_stack[level].entry=0;
1466                     directory_stack[level].offset=tag_offset1;
1467                     level++;
1468                   }
1469               }
1470             break;
1471           }
1472     }
1473   } while (level > 0);
1474   return(status);
1475 }
1476
1477 static MagickBooleanType GetXMPProperty(const Image *image,
1478   const char *property)
1479 {
1480   char
1481     *xmp_profile;
1482
1483   const StringInfo
1484     *profile;
1485
1486   ExceptionInfo
1487     *exception;
1488
1489   MagickBooleanType
1490     status;
1491
1492   register const char
1493     *p;
1494
1495   XMLTreeInfo
1496     *child,
1497     *description,
1498     *node,
1499     *rdf,
1500     *xmp;
1501
1502   profile=GetImageProfile(image,"xmp");
1503   if (profile == (StringInfo *) NULL)
1504     return(MagickFalse);
1505   if ((property == (const char *) NULL) || (*property == '\0'))
1506     return(MagickFalse);
1507   xmp_profile=StringInfoToString(profile);
1508   if (xmp_profile == (char *) NULL)
1509     return(MagickFalse);
1510   for (p=xmp_profile; *p != '\0'; p++)
1511     if ((*p == '<') && (*(p+1) == 'x'))
1512       break;
1513   exception=AcquireExceptionInfo();
1514   xmp=NewXMLTree((char *) p,exception);
1515   xmp_profile=DestroyString(xmp_profile);
1516   exception=DestroyExceptionInfo(exception);
1517   if (xmp == (XMLTreeInfo *) NULL)
1518     return(MagickFalse);
1519   status=MagickFalse;
1520   rdf=GetXMLTreeChild(xmp,"rdf:RDF");
1521   if (rdf != (XMLTreeInfo *) NULL)
1522     {
1523       if (image->properties == (void *) NULL)
1524         ((Image *) image)->properties=NewSplayTree(CompareSplayTreeString,
1525           RelinquishMagickMemory,RelinquishMagickMemory);
1526       description=GetXMLTreeChild(rdf,"rdf:Description");
1527       while (description != (XMLTreeInfo *) NULL)
1528       {
1529         node=GetXMLTreeChild(description,(const char *) NULL);
1530         while (node != (XMLTreeInfo *) NULL)
1531         {
1532           child=GetXMLTreeChild(node,(const char *) NULL);
1533           if (child == (XMLTreeInfo *) NULL)
1534             (void) AddValueToSplayTree((SplayTreeInfo *) image->properties,
1535               ConstantString(GetXMLTreeTag(node)),
1536               ConstantString(GetXMLTreeContent(node)));
1537           while (child != (XMLTreeInfo *) NULL)
1538           {
1539             if (LocaleCompare(GetXMLTreeTag(child),"rdf:Seq") != 0)
1540               (void) AddValueToSplayTree((SplayTreeInfo *) image->properties,
1541                 ConstantString(GetXMLTreeTag(child)),
1542                 ConstantString(GetXMLTreeContent(child)));
1543             child=GetXMLTreeSibling(child);
1544           }
1545           node=GetXMLTreeSibling(node);
1546         }
1547         description=GetNextXMLTreeTag(description);
1548       }
1549     }
1550   xmp=DestroyXMLTree(xmp);
1551   return(status);
1552 }
1553
1554 static char *TracePSClippath(const unsigned char *blob,size_t length,
1555   const size_t magick_unused(columns),
1556   const size_t magick_unused(rows))
1557 {
1558   char
1559     *path,
1560     *message;
1561
1562   MagickBooleanType
1563     in_subpath;
1564
1565   PointInfo
1566     first[3],
1567     last[3],
1568     point[3];
1569
1570   register ssize_t
1571     i,
1572     x;
1573
1574   ssize_t
1575     knot_count,
1576     selector,
1577     y;
1578
1579   path=AcquireString((char *) NULL);
1580   if (path == (char *) NULL)
1581     return((char *) NULL);
1582   message=AcquireString((char *) NULL);
1583   (void) FormatLocaleString(message,MaxTextExtent,"/ClipImage\n");
1584   (void) ConcatenateString(&path,message);
1585   (void) FormatLocaleString(message,MaxTextExtent,"{\n");
1586   (void) ConcatenateString(&path,message);
1587   (void) FormatLocaleString(message,MaxTextExtent,"  /c {curveto} bind def\n");
1588   (void) ConcatenateString(&path,message);
1589   (void) FormatLocaleString(message,MaxTextExtent,"  /l {lineto} bind def\n");
1590   (void) ConcatenateString(&path,message);
1591   (void) FormatLocaleString(message,MaxTextExtent,"  /m {moveto} bind def\n");
1592   (void) ConcatenateString(&path,message);
1593   (void) FormatLocaleString(message,MaxTextExtent,
1594     "  /v {currentpoint 6 2 roll curveto} bind def\n");
1595   (void) ConcatenateString(&path,message);
1596   (void) FormatLocaleString(message,MaxTextExtent,
1597     "  /y {2 copy curveto} bind def\n");
1598   (void) ConcatenateString(&path,message);
1599   (void) FormatLocaleString(message,MaxTextExtent,
1600     "  /z {closepath} bind def\n");
1601   (void) ConcatenateString(&path,message);
1602   (void) FormatLocaleString(message,MaxTextExtent,"  newpath\n");
1603   (void) ConcatenateString(&path,message);
1604   /*
1605     The clipping path format is defined in "Adobe Photoshop File
1606     Formats Specification" version 6.0 downloadable from adobe.com.
1607   */
1608   (void) ResetMagickMemory(point,0,sizeof(point));
1609   (void) ResetMagickMemory(first,0,sizeof(first));
1610   (void) ResetMagickMemory(last,0,sizeof(last));
1611   knot_count=0;
1612   in_subpath=MagickFalse;
1613   while (length > 0)
1614   {
1615     selector=(ssize_t) ReadPropertyMSBShort(&blob,&length);
1616     switch (selector)
1617     {
1618       case 0:
1619       case 3:
1620       {
1621         if (knot_count != 0)
1622           {
1623             blob+=24;
1624             length-=24;
1625             break;
1626           }
1627         /*
1628           Expected subpath length record.
1629         */
1630         knot_count=(ssize_t) ReadPropertyMSBShort(&blob,&length);
1631         blob+=22;
1632         length-=22;
1633         break;
1634       }
1635       case 1:
1636       case 2:
1637       case 4:
1638       case 5:
1639       {
1640         if (knot_count == 0)
1641           {
1642             /*
1643               Unexpected subpath knot
1644             */
1645             blob+=24;
1646             length-=24;
1647             break;
1648           }
1649         /*
1650           Add sub-path knot
1651         */
1652         for (i=0; i < 3; i++)
1653         {
1654           size_t
1655             xx,
1656             yy;
1657
1658           yy=ReadPropertyMSBLong(&blob,&length);
1659           xx=ReadPropertyMSBLong(&blob,&length);
1660           x=(ssize_t) xx;
1661           if (xx > 2147483647)
1662             x=(ssize_t) xx-4294967295U-1;
1663           y=(ssize_t) yy;
1664           if (yy > 2147483647)
1665             y=(ssize_t) yy-4294967295U-1;
1666           point[i].x=(double) x/4096/4096;
1667           point[i].y=1.0-(double) y/4096/4096;
1668         }
1669         if (in_subpath == MagickFalse)
1670           {
1671             (void) FormatLocaleString(message,MaxTextExtent,"  %g %g m\n",
1672               point[1].x,point[1].y);
1673             for (i=0; i < 3; i++)
1674             {
1675               first[i]=point[i];
1676               last[i]=point[i];
1677             }
1678           }
1679         else
1680           {
1681             /*
1682               Handle special cases when Bezier curves are used to describe
1683               corners and straight lines.
1684             */
1685             if ((last[1].x == last[2].x) && (last[1].y == last[2].y) &&
1686                 (point[0].x == point[1].x) && (point[0].y == point[1].y))
1687               (void) FormatLocaleString(message,MaxTextExtent,
1688                 "  %g %g l\n",point[1].x,point[1].y);
1689             else
1690               if ((last[1].x == last[2].x) && (last[1].y == last[2].y))
1691                 (void) FormatLocaleString(message,MaxTextExtent,
1692                   "  %g %g %g %g v\n",point[0].x,point[0].y,
1693                   point[1].x,point[1].y);
1694               else
1695                 if ((point[0].x == point[1].x) && (point[0].y == point[1].y))
1696                   (void) FormatLocaleString(message,MaxTextExtent,
1697                     "  %g %g %g %g y\n",last[2].x,last[2].y,
1698                     point[1].x,point[1].y);
1699                 else
1700                   (void) FormatLocaleString(message,MaxTextExtent,
1701                     "  %g %g %g %g %g %g c\n",last[2].x,
1702                     last[2].y,point[0].x,point[0].y,point[1].x,point[1].y);
1703             for (i=0; i < 3; i++)
1704               last[i]=point[i];
1705           }
1706         (void) ConcatenateString(&path,message);
1707         in_subpath=MagickTrue;
1708         knot_count--;
1709         /*
1710           Close the subpath if there are no more knots.
1711         */
1712         if (knot_count == 0)
1713           {
1714             /*
1715               Same special handling as above except we compare to the
1716               first point in the path and close the path.
1717             */
1718             if ((last[1].x == last[2].x) && (last[1].y == last[2].y) &&
1719                 (first[0].x == first[1].x) && (first[0].y == first[1].y))
1720               (void) FormatLocaleString(message,MaxTextExtent,
1721                 "  %g %g l z\n",first[1].x,first[1].y);
1722             else
1723               if ((last[1].x == last[2].x) && (last[1].y == last[2].y))
1724                 (void) FormatLocaleString(message,MaxTextExtent,
1725                   "  %g %g %g %g v z\n",first[0].x,first[0].y,
1726                   first[1].x,first[1].y);
1727               else
1728                 if ((first[0].x == first[1].x) && (first[0].y == first[1].y))
1729                   (void) FormatLocaleString(message,MaxTextExtent,
1730                     "  %g %g %g %g y z\n",last[2].x,last[2].y,
1731                     first[1].x,first[1].y);
1732                 else
1733                   (void) FormatLocaleString(message,MaxTextExtent,
1734                     "  %g %g %g %g %g %g c z\n",last[2].x,
1735                     last[2].y,first[0].x,first[0].y,first[1].x,first[1].y);
1736             (void) ConcatenateString(&path,message);
1737             in_subpath=MagickFalse;
1738           }
1739         break;
1740       }
1741       case 6:
1742       case 7:
1743       case 8:
1744       default:
1745       {
1746         blob+=24;
1747         length-=24;
1748         break;
1749       }
1750     }
1751   }
1752   /*
1753     Returns an empty PS path if the path has no knots.
1754   */
1755   (void) FormatLocaleString(message,MaxTextExtent,"  eoclip\n");
1756   (void) ConcatenateString(&path,message);
1757   (void) FormatLocaleString(message,MaxTextExtent,"} bind def");
1758   (void) ConcatenateString(&path,message);
1759   message=DestroyString(message);
1760   return(path);
1761 }
1762
1763 static char *TraceSVGClippath(const unsigned char *blob,size_t length,
1764   const size_t columns,const size_t rows)
1765 {
1766   char
1767     *path,
1768     *message;
1769
1770   MagickBooleanType
1771     in_subpath;
1772
1773   PointInfo
1774     first[3],
1775     last[3],
1776     point[3];
1777
1778   register ssize_t
1779     i;
1780
1781   ssize_t
1782     knot_count,
1783     selector,
1784     x,
1785     y;
1786
1787   path=AcquireString((char *) NULL);
1788   if (path == (char *) NULL)
1789     return((char *) NULL);
1790   message=AcquireString((char *) NULL);
1791   (void) FormatLocaleString(message,MaxTextExtent,
1792     "<?xml version=\"1.0\" encoding=\"iso-8859-1\"?>\n");
1793   (void) ConcatenateString(&path,message);
1794   (void) FormatLocaleString(message,MaxTextExtent,
1795     "<svg width=\"%.20g\" height=\"%.20g\">\n",(double) columns,(double) rows);
1796   (void) ConcatenateString(&path,message);
1797   (void) FormatLocaleString(message,MaxTextExtent,"<g>\n");
1798   (void) ConcatenateString(&path,message);
1799   (void) FormatLocaleString(message,MaxTextExtent,
1800     "<path style=\"fill:#00000000;stroke:#00000000;");
1801   (void) ConcatenateString(&path,message);
1802   (void) FormatLocaleString(message,MaxTextExtent,
1803     "stroke-width:0;stroke-antialiasing:false\" d=\"\n");
1804   (void) ConcatenateString(&path,message);
1805   (void) ResetMagickMemory(point,0,sizeof(point));
1806   (void) ResetMagickMemory(first,0,sizeof(first));
1807   (void) ResetMagickMemory(last,0,sizeof(last));
1808   knot_count=0;
1809   in_subpath=MagickFalse;
1810   while (length != 0)
1811   {
1812     selector=(ssize_t) ReadPropertyMSBShort(&blob,&length);
1813     switch (selector)
1814     {
1815       case 0:
1816       case 3:
1817       {
1818         if (knot_count != 0)
1819           {
1820             blob+=24;
1821             length-=24;
1822             break;
1823           }
1824         /*
1825           Expected subpath length record.
1826         */
1827         knot_count=(ssize_t) ReadPropertyMSBShort(&blob,&length);
1828         blob+=22;
1829         length-=22;
1830         break;
1831       }
1832       case 1:
1833       case 2:
1834       case 4:
1835       case 5:
1836       {
1837         if (knot_count == 0)
1838           {
1839             /*
1840               Unexpected subpath knot.
1841             */
1842             blob+=24;
1843             length-=24;
1844             break;
1845           }
1846         /*
1847           Add sub-path knot
1848         */
1849         for (i=0; i < 3; i++)
1850         {
1851           size_t
1852             xx,
1853             yy;
1854
1855           yy=ReadPropertyMSBLong(&blob,&length);
1856           xx=ReadPropertyMSBLong(&blob,&length);
1857           x=(ssize_t) xx;
1858           if (xx > 2147483647)
1859             x=(ssize_t) xx-4294967295U-1;
1860           y=(ssize_t) yy;
1861           if (yy > 2147483647)
1862             y=(ssize_t) yy-4294967295U-1;
1863           point[i].x=(double) x*columns/4096/4096;
1864           point[i].y=(double) y*rows/4096/4096;
1865         }
1866         if (in_subpath == MagickFalse)
1867           {
1868             (void) FormatLocaleString(message,MaxTextExtent,"M %g,%g\n",
1869               point[1].x,point[1].y);
1870             for (i=0; i < 3; i++)
1871             {
1872               first[i]=point[i];
1873               last[i]=point[i];
1874             }
1875           }
1876         else
1877           {
1878             if ((last[1].x == last[2].x) && (last[1].y == last[2].y) &&
1879                 (point[0].x == point[1].x) && (point[0].y == point[1].y))
1880               (void) FormatLocaleString(message,MaxTextExtent,"L %g,%g\n",
1881                 point[1].x,point[1].y);
1882             else
1883               (void) FormatLocaleString(message,MaxTextExtent,
1884                 "C %g,%g %g,%g %g,%g\n",last[2].x,last[2].y,
1885                 point[0].x,point[0].y,point[1].x,point[1].y);
1886             for (i=0; i < 3; i++)
1887               last[i]=point[i];
1888           }
1889         (void) ConcatenateString(&path,message);
1890         in_subpath=MagickTrue;
1891         knot_count--;
1892         /*
1893           Close the subpath if there are no more knots.
1894         */
1895         if (knot_count == 0)
1896           {
1897             if ((last[1].x == last[2].x) && (last[1].y == last[2].y) &&
1898                 (first[0].x == first[1].x) && (first[0].y == first[1].y))
1899               (void) FormatLocaleString(message,MaxTextExtent,
1900                 "L %g,%g Z\n",first[1].x,first[1].y);
1901             else
1902               {
1903                 (void) FormatLocaleString(message,MaxTextExtent,
1904                   "C %g,%g %g,%g %g,%g Z\n",last[2].x,
1905                   last[2].y,first[0].x,first[0].y,first[1].x,first[1].y);
1906                 (void) ConcatenateString(&path,message);
1907               }
1908             in_subpath=MagickFalse;
1909           }
1910         break;
1911       }
1912       case 6:
1913       case 7:
1914       case 8:
1915       default:
1916       {
1917         blob+=24;
1918         length-=24;
1919         break;
1920       }
1921     }
1922   }
1923   /*
1924     Return an empty SVG image if the path does not have knots.
1925   */
1926   (void) FormatLocaleString(message,MaxTextExtent,"\"/>\n");
1927   (void) ConcatenateString(&path,message);
1928   (void) FormatLocaleString(message,MaxTextExtent,"</g>\n");
1929   (void) ConcatenateString(&path,message);
1930   (void) FormatLocaleString(message,MaxTextExtent,"</svg>\n");
1931   (void) ConcatenateString(&path,message);
1932   message=DestroyString(message);
1933   return(path);
1934 }
1935
1936 MagickExport const char *GetImageProperty(const Image *image,
1937   const char *property)
1938 {
1939   ExceptionInfo
1940     *exception;
1941
1942   FxInfo
1943     *fx_info;
1944
1945   MagickRealType
1946     alpha;
1947
1948   MagickStatusType
1949     status;
1950
1951   register const char
1952     *p;
1953
1954   assert(image != (Image *) NULL);
1955   assert(image->signature == MagickSignature);
1956   if (image->debug != MagickFalse)
1957     (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1958   p=(const char *) NULL;
1959   if (image->properties != (void *) NULL)
1960     {
1961       if (property == (const char *) NULL)
1962         {
1963           ResetSplayTreeIterator((SplayTreeInfo *) image->properties);
1964           p=(const char *) GetNextValueInSplayTree((SplayTreeInfo *)
1965             image->properties);
1966           return(p);
1967         }
1968       if (LocaleNCompare("fx:",property,3) != 0)
1969         {
1970           p=(const char *) GetValueFromSplayTree((SplayTreeInfo *)
1971             image->properties,property);
1972           if (p != (const char *) NULL)
1973             return(p);
1974         }
1975     }
1976   if ((property == (const char *) NULL) ||
1977       (strchr(property,':') == (char *) NULL))
1978     return(p);
1979   exception=(&((Image *) image)->exception);
1980   switch (*property)
1981   {
1982     case '8':
1983     {
1984       if (LocaleNCompare("8bim:",property,5) == 0)
1985         {
1986           if ((Get8BIMProperty(image,property) != MagickFalse) &&
1987               (image->properties != (void *) NULL))
1988             {
1989               p=(const char *) GetValueFromSplayTree((SplayTreeInfo *)
1990                 image->properties,property);
1991               return(p);
1992             }
1993         }
1994       break;
1995     }
1996     case 'E':
1997     case 'e':
1998     {
1999       if (LocaleNCompare("exif:",property,5) == 0)
2000         {
2001           if ((GetEXIFProperty(image,property) != MagickFalse) &&
2002               (image->properties != (void *) NULL))
2003             {
2004               p=(const char *) GetValueFromSplayTree((SplayTreeInfo *)
2005                 image->properties,property);
2006               return(p);
2007             }
2008         }
2009       break;
2010     }
2011     case 'F':
2012     case 'f':
2013     {
2014       if (LocaleNCompare("fx:",property,3) == 0)
2015         {
2016           fx_info=AcquireFxInfo(image,property+3);
2017           status=FxEvaluateChannelExpression(fx_info,DefaultChannels,0,0,&alpha,
2018             exception);
2019           fx_info=DestroyFxInfo(fx_info);
2020           if (status != MagickFalse)
2021             {
2022               char
2023                 value[MaxTextExtent];
2024
2025               (void) FormatLocaleString(value,MaxTextExtent,"%.*g",
2026                 GetMagickPrecision(),(double) alpha);
2027               (void) SetImageProperty((Image *) image,property,value);
2028             }
2029           if (image->properties != (void *) NULL)
2030             {
2031               p=(const char *) GetValueFromSplayTree((SplayTreeInfo *)
2032                 image->properties,property);
2033               return(p);
2034             }
2035         }
2036       break;
2037     }
2038     case 'I':
2039     case 'i':
2040     {
2041       if (LocaleNCompare("iptc:",property,5) == 0)
2042         {
2043           if ((GetIPTCProperty(image,property) != MagickFalse) &&
2044               (image->properties != (void *) NULL))
2045             {
2046               p=(const char *) GetValueFromSplayTree((SplayTreeInfo *)
2047                 image->properties,property);
2048               return(p);
2049             }
2050         }
2051       break;
2052     }
2053     case 'P':
2054     case 'p':
2055     {
2056       if (LocaleNCompare("pixel:",property,6) == 0)
2057         {
2058           PixelInfo
2059             pixel;
2060
2061           GetPixelInfo(image,&pixel);
2062           fx_info=AcquireFxInfo(image,property+6);
2063           status=FxEvaluateChannelExpression(fx_info,RedChannel,0,0,&alpha,
2064             exception);
2065           pixel.red=(MagickRealType) QuantumRange*alpha;
2066           status|=FxEvaluateChannelExpression(fx_info,GreenChannel,0,0,&alpha,
2067             exception);
2068           pixel.green=(MagickRealType) QuantumRange*alpha;
2069           status|=FxEvaluateChannelExpression(fx_info,BlueChannel,0,0,&alpha,
2070             exception);
2071           pixel.blue=(MagickRealType) QuantumRange*alpha;
2072           if (image->colorspace == CMYKColorspace)
2073             {
2074               status|=FxEvaluateChannelExpression(fx_info,BlackChannel,0,0,
2075                 &alpha,exception);
2076               pixel.black=(MagickRealType) QuantumRange*alpha;
2077             }
2078           status|=FxEvaluateChannelExpression(fx_info,OpacityChannel,0,0,&alpha,
2079             exception);
2080           pixel.alpha=(MagickRealType) QuantumRange*(1.0-alpha);
2081           fx_info=DestroyFxInfo(fx_info);
2082           if (status != MagickFalse)
2083             {
2084               char
2085                 name[MaxTextExtent];
2086
2087               (void) QueryMagickColorname(image,&pixel,SVGCompliance,name,
2088                 exception);
2089               (void) SetImageProperty((Image *) image,property,name);
2090               return(GetImageProperty(image,property));
2091             }
2092         }
2093       break;
2094     }
2095     case 'X':
2096     case 'x':
2097     {
2098       if (LocaleNCompare("xmp:",property,4) == 0)
2099         {
2100           if ((GetXMPProperty(image,property) != MagickFalse) &&
2101               (image->properties != (void *) NULL))
2102             {
2103               p=(const char *) GetValueFromSplayTree((SplayTreeInfo *)
2104                 image->properties,property);
2105               return(p);
2106             }
2107         }
2108       break;
2109     }
2110     default:
2111       break;
2112   }
2113   return(p);
2114 }
2115 \f
2116 /*
2117 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2118 %                                                                             %
2119 %                                                                             %
2120 %                                                                             %
2121 +   G e t M a g i c k P r o p e r t y                                         %
2122 %                                                                             %
2123 %                                                                             %
2124 %                                                                             %
2125 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2126 %
2127 %  GetMagickProperty() gets a value associated with an image property.
2128 %
2129 %  The format of the GetMagickProperty method is:
2130 %
2131 %      const char *GetMagickProperty(const ImageInfo *image_info,
2132 %        Image *image,const char *key)
2133 %
2134 %  A description of each parameter follows:
2135 %
2136 %    o image_info: the image info.
2137 %
2138 %    o image: the image.
2139 %
2140 %    o key: the key.
2141 %
2142 */
2143 MagickExport const char *GetMagickProperty(const ImageInfo *image_info,
2144   Image *image,const char *property)
2145 {
2146   char
2147     value[MaxTextExtent],
2148     filename[MaxTextExtent];
2149
2150   *value='\0';
2151   switch (*property)
2152   {
2153     case 'b':
2154     {
2155       if (LocaleNCompare("base",property,4) == 0)
2156         {
2157           GetPathComponent(image->magick_filename,BasePath,filename);
2158           (void) CopyMagickString(value,filename,MaxTextExtent);
2159           break;
2160         }
2161       break;
2162     }
2163     case 'c':
2164     {
2165       if (LocaleNCompare("channels",property,8) == 0)
2166         {
2167           /*
2168             Image channels.
2169           */
2170           (void) FormatLocaleString(value,MaxTextExtent,"%s",
2171             CommandOptionToMnemonic(MagickColorspaceOptions,(ssize_t)
2172             image->colorspace));
2173           LocaleLower(value);
2174           if (image->matte != MagickFalse)
2175             (void) ConcatenateMagickString(value,"a",MaxTextExtent);
2176           break;
2177         }
2178       if (LocaleNCompare("colorspace",property,10) == 0)
2179         {
2180           ColorspaceType
2181             colorspace;
2182
2183           /*
2184             Image storage class and colorspace.
2185           */
2186           colorspace=image->colorspace;
2187           if (IsImageGray(image,&image->exception) != MagickFalse)
2188             colorspace=GRAYColorspace;
2189           (void) FormatLocaleString(value,MaxTextExtent,"%s",
2190             CommandOptionToMnemonic(MagickColorspaceOptions,(ssize_t)
2191             colorspace));
2192           break;
2193         }
2194       if (LocaleNCompare("copyright",property,9) == 0)
2195         {
2196           (void) CopyMagickString(value,GetMagickCopyright(),MaxTextExtent);
2197           break;
2198         }
2199       break;
2200     }
2201     case 'd':
2202     {
2203       if (LocaleNCompare("depth",property,5) == 0)
2204         {
2205           (void) FormatLocaleString(value,MaxTextExtent,"%.20g",(double)
2206             image->depth);
2207           break;
2208         }
2209       if (LocaleNCompare("directory",property,9) == 0)
2210         {
2211           GetPathComponent(image->magick_filename,HeadPath,filename);
2212           (void) CopyMagickString(value,filename,MaxTextExtent);
2213           break;
2214         }
2215       break;
2216     }
2217     case 'e':
2218     {
2219       if (LocaleNCompare("extension",property,9) == 0)
2220         {
2221           GetPathComponent(image->magick_filename,ExtensionPath,filename);
2222           (void) CopyMagickString(value,filename,MaxTextExtent);
2223           break;
2224         }
2225       break;
2226     }
2227     case 'g':
2228     {
2229       if (LocaleNCompare("group",property,5) == 0)
2230         {
2231           (void) FormatLocaleString(value,MaxTextExtent,"0x%lx",
2232             (unsigned long) image_info->group);
2233           break;
2234         }
2235       break;
2236     }
2237     case 'h':
2238     {
2239       if (LocaleNCompare("height",property,6) == 0)
2240         {
2241           (void) FormatLocaleString(value,MaxTextExtent,"%.20g",
2242             image->magick_rows != 0 ? (double) image->magick_rows : 256.0);
2243           break;
2244         }
2245       break;
2246     }
2247     case 'i':
2248     {
2249       if (LocaleNCompare("input",property,5) == 0)
2250         {
2251           (void) CopyMagickString(value,image->filename,MaxTextExtent);
2252           break;
2253         }
2254       break;
2255     }
2256     case 'k':
2257     {
2258       if (LocaleNCompare("kurtosis",property,8) == 0)
2259         {
2260           double
2261             kurtosis,
2262             skewness;
2263
2264           (void) GetImageChannelKurtosis(image,image_info->channel,&kurtosis,
2265             &skewness,&image->exception);
2266           (void) FormatLocaleString(value,MaxTextExtent,"%.*g",
2267             GetMagickPrecision(),kurtosis);
2268           break;
2269         }
2270       break;
2271     }
2272     case 'm':
2273     {
2274       if (LocaleNCompare("magick",property,6) == 0)
2275         {
2276           (void) CopyMagickString(value,image->magick,MaxTextExtent);
2277           break;
2278         }
2279       if (LocaleNCompare("max",property,3) == 0)
2280         {
2281           double
2282             maximum,
2283             minimum;
2284
2285           (void) GetImageChannelRange(image,image_info->channel,&minimum,
2286             &maximum,&image->exception);
2287           (void) FormatLocaleString(value,MaxTextExtent,"%.*g",
2288             GetMagickPrecision(),maximum);
2289           break;
2290         }
2291       if (LocaleNCompare("mean",property,4) == 0)
2292         {
2293           double
2294             mean,
2295             standard_deviation;
2296
2297           (void) GetImageChannelMean(image,image_info->channel,&mean,
2298             &standard_deviation,&image->exception);
2299           (void) FormatLocaleString(value,MaxTextExtent,"%.*g",
2300             GetMagickPrecision(),mean);
2301           break;
2302         }
2303       if (LocaleNCompare("min",property,3) == 0)
2304         {
2305           double
2306             maximum,
2307             minimum;
2308
2309           (void) GetImageChannelRange(image,image_info->channel,&minimum,
2310             &maximum,&image->exception);
2311           (void) FormatLocaleString(value,MaxTextExtent,"%.*g",
2312             GetMagickPrecision(),minimum);
2313           break;
2314         }
2315       break;
2316     }
2317     case 'n':
2318     {
2319       if (LocaleNCompare("name",property,4) == 0)
2320         {
2321           (void) CopyMagickString(value,filename,MaxTextExtent);
2322           break;
2323         }
2324      break;
2325     }
2326     case 'o':
2327     {
2328       if (LocaleNCompare("opaque",property,6) == 0)
2329         {
2330           MagickBooleanType
2331             opaque;
2332
2333           opaque=IsImageOpaque(image,&image->exception);
2334           (void) CopyMagickString(value,opaque == MagickFalse ? "false" :
2335             "true",MaxTextExtent);
2336           break;
2337         }
2338       if (LocaleNCompare("output",property,6) == 0)
2339         {
2340           (void) CopyMagickString(value,image_info->filename,MaxTextExtent);
2341           break;
2342         }
2343      break;
2344     }
2345     case 'p':
2346     {
2347       if (LocaleNCompare("page",property,4) == 0)
2348         {
2349           (void) FormatLocaleString(value,MaxTextExtent,"%.20g",(double)
2350               GetImageIndexInList(image)+1);
2351           break;
2352         }
2353       break;
2354     }
2355     case 's':
2356     {
2357       if (LocaleNCompare("size",property,4) == 0)
2358         {
2359           char
2360             format[MaxTextExtent];
2361
2362           (void) FormatMagickSize(GetBlobSize(image),MagickFalse,format);
2363           (void) FormatLocaleString(value,MaxTextExtent,"%sB",format);
2364           break;
2365         }
2366       if (LocaleNCompare("scenes",property,6) == 0)
2367         {
2368           (void) FormatLocaleString(value,MaxTextExtent,"%.20g",(double)
2369             GetImageListLength(image));
2370           break;
2371         }
2372       if (LocaleNCompare("scene",property,5) == 0)
2373         {
2374           (void) FormatLocaleString(value,MaxTextExtent,"%.20g",(double)
2375             image->scene);
2376           if (image_info->number_scenes != 0)
2377             (void) FormatLocaleString(value,MaxTextExtent,"%.20g",(double)
2378               image_info->scene);
2379           break;
2380         }
2381       if (LocaleNCompare("skewness",property,8) == 0)
2382         {
2383           double
2384             kurtosis,
2385             skewness;
2386
2387           (void) GetImageChannelKurtosis(image,image_info->channel,&kurtosis,
2388             &skewness,&image->exception);
2389           (void) FormatLocaleString(value,MaxTextExtent,"%.*g",
2390             GetMagickPrecision(),skewness);
2391           break;
2392         }
2393       if ((LocaleNCompare("standard-deviation",property,18) == 0) ||
2394           (LocaleNCompare("standard_deviation",property,18) == 0))
2395         {
2396           double
2397             mean,
2398             standard_deviation;
2399
2400           (void) GetImageChannelMean(image,image_info->channel,&mean,
2401             &standard_deviation,&image->exception);
2402           (void) FormatLocaleString(value,MaxTextExtent,"%.*g",
2403             GetMagickPrecision(),standard_deviation);
2404           break;
2405         }
2406        break;
2407     }
2408     case 'u':
2409     {
2410       if (LocaleNCompare("unique",property,6) == 0)
2411         {
2412           (void) CopyMagickString(filename,image_info->unique,MaxTextExtent);
2413           (void) CopyMagickString(value,filename,MaxTextExtent);
2414           break;
2415         }
2416       break;
2417     }
2418     case 'v':
2419     {
2420       if (LocaleNCompare("version",property,7) == 0)
2421         {
2422           (void) CopyMagickString(value,GetMagickVersion((size_t *) NULL),
2423             MaxTextExtent);
2424           break;
2425         }
2426       break;
2427     }
2428     case 'w':
2429     {
2430       if (LocaleNCompare("width",property,5) == 0)
2431         {
2432           (void) FormatLocaleString(value,MaxTextExtent,"%.20g",(double)
2433             (image->magick_columns != 0 ? image->magick_columns : 256));
2434           break;
2435         }
2436       break;
2437     }
2438     case 'x':
2439     {
2440       if (LocaleNCompare("xresolution",property,11) == 0)
2441         {
2442           (void) FormatLocaleString(value,MaxTextExtent,"%g",
2443             image->x_resolution);
2444           break;
2445         }
2446       break;
2447     }
2448     case 'y':
2449     {
2450       if (LocaleNCompare("yresolution",property,11) == 0)
2451         {
2452           (void) FormatLocaleString(value,MaxTextExtent,"%g",
2453             image->y_resolution);
2454           break;
2455         }
2456       break;
2457     }
2458     case 'z':
2459     {
2460       if (LocaleNCompare("zero",property,4) == 0)
2461         {
2462           (void) CopyMagickString(filename,image_info->zero,MaxTextExtent);
2463           (void) CopyMagickString(value,filename,MaxTextExtent);
2464           break;
2465         }
2466       break;
2467     }
2468   }
2469   if (*value != '\0')
2470    {
2471      if (image->properties == (void *) NULL)
2472        image->properties=NewSplayTree(CompareSplayTreeString,
2473          RelinquishMagickMemory,RelinquishMagickMemory);
2474      (void) AddValueToSplayTree((SplayTreeInfo *) image->properties,
2475        ConstantString(property),ConstantString(value));
2476    }
2477   return(GetImageProperty(image,property));
2478 }
2479 \f
2480 /*
2481 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2482 %                                                                             %
2483 %                                                                             %
2484 %                                                                             %
2485 %   G e t N e x t I m a g e P r o p e r t y                                   %
2486 %                                                                             %
2487 %                                                                             %
2488 %                                                                             %
2489 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2490 %
2491 %  GetNextImageProperty() gets the next image property value.
2492 %
2493 %  The format of the GetNextImageProperty method is:
2494 %
2495 %      char *GetNextImageProperty(const Image *image)
2496 %
2497 %  A description of each parameter follows:
2498 %
2499 %    o image: the image.
2500 %
2501 */
2502 MagickExport char *GetNextImageProperty(const Image *image)
2503 {
2504   assert(image != (Image *) NULL);
2505   assert(image->signature == MagickSignature);
2506   if (image->debug != MagickFalse)
2507     (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
2508       image->filename);
2509   if (image->properties == (void *) NULL)
2510     return((char *) NULL);
2511   return((char *) GetNextKeyInSplayTree((SplayTreeInfo *) image->properties));
2512 }
2513 \f
2514 /*
2515 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2516 %                                                                             %
2517 %                                                                             %
2518 %                                                                             %
2519 %   I n t e r p r e t I m a g e P r o p e r t i e s                           %
2520 %                                                                             %
2521 %                                                                             %
2522 %                                                                             %
2523 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2524 %
2525 %  InterpretImageProperties() replaces any embedded formatting characters with
2526 %  the appropriate image property and returns the interpretted text.
2527 %
2528 %  The format of the InterpretImageProperties method is:
2529 %
2530 %      char *InterpretImageProperties(const ImageInfo *image_info,Image *image,
2531 %        const char *embed_text)
2532 %
2533 %  A description of each parameter follows:
2534 %
2535 %    o image_info: the image info.
2536 %
2537 %    o image: the image.
2538 %
2539 %    o embed_text: the address of a character string containing the embedded
2540 %      formatting characters.
2541 %
2542 */
2543 MagickExport char *InterpretImageProperties(const ImageInfo *image_info,
2544   Image *image,const char *embed_text)
2545 {
2546   char
2547     filename[MaxTextExtent],
2548     *interpret_text,
2549     *text;
2550
2551   const char
2552     *value;
2553
2554   register char
2555     *q;
2556
2557   register const char
2558     *p;
2559
2560   register ssize_t
2561     i;
2562
2563   size_t
2564     extent,
2565     length;
2566
2567   assert(image != (Image *) NULL);
2568   assert(image->signature == MagickSignature);
2569   if (image->debug != MagickFalse)
2570     (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
2571   if ((embed_text == (const char *) NULL) || (*embed_text == '\0'))
2572     return((char *) NULL);
2573   text=(char *) embed_text;
2574   if ((*text == '@') && ((*(text+1) == '-') ||
2575       (IsPathAccessible(text+1) != MagickFalse)))
2576     return(FileToString(embed_text+1,~0,&image->exception));
2577   /*
2578     Translate any embedded format characters.
2579   */
2580   interpret_text=AcquireString(text);
2581   extent=MaxTextExtent;
2582   p=text;
2583   for (q=interpret_text; *p != '\0'; p++)
2584   {
2585     *q='\0';
2586     if ((size_t) (q-interpret_text+MaxTextExtent) >= extent)
2587       {
2588         extent+=MaxTextExtent;
2589         interpret_text=(char *) ResizeQuantumMemory(interpret_text,extent+
2590           MaxTextExtent+1,sizeof(*interpret_text));
2591         if (interpret_text == (char *) NULL)
2592           break;
2593         q=interpret_text+strlen(interpret_text);
2594       }
2595     /*
2596       Process formatting characters in text.
2597     */
2598     if ((*p == '\\') && (*(p+1) == 'r'))
2599       {
2600         *q++='\r';
2601         p++;
2602         continue;
2603       }
2604     if ((*p == '\\') && (*(p+1) == 'n'))
2605       {
2606         *q++='\n';
2607         p++;
2608         continue;
2609       }
2610     if (*p == '\\')
2611       {
2612         p++;
2613         *q++=(*p);
2614         continue;
2615       }
2616     if (*p != '%')
2617       {
2618         *q++=(*p);
2619         continue;
2620       }
2621     p++;
2622     switch (*p)
2623     {
2624       case 'b':
2625       {
2626         char
2627           format[MaxTextExtent];
2628
2629         /*
2630           File size.
2631         */
2632         (void) FormatLocaleString(format,MaxTextExtent,"%.20g",(double)
2633           ((MagickOffsetType) image->extent));
2634         if (image->extent != (MagickSizeType) ((size_t) image->extent))
2635           (void) FormatMagickSize(image->extent,MagickFalse,format);
2636         q+=ConcatenateMagickString(q,format,extent);
2637         q+=ConcatenateMagickString(q,"B",extent);
2638         break;
2639       }
2640       case 'c':
2641       {
2642         /*
2643           Image comment.
2644         */
2645         value=GetImageProperty(image,"comment");
2646         if (value == (const char *) NULL)
2647           break;
2648         length=strlen(value);
2649         if ((size_t) (q-interpret_text+length+1) >= extent)
2650           {
2651             extent+=length;
2652             interpret_text=(char *) ResizeQuantumMemory(interpret_text,extent+
2653               MaxTextExtent,sizeof(*interpret_text));
2654             if (interpret_text == (char *) NULL)
2655               break;
2656             q=interpret_text+strlen(interpret_text);
2657           }
2658         (void) CopyMagickString(q,value,extent);
2659         q+=length;
2660         break;
2661       }
2662       case 'd':
2663       case 'e':
2664       case 'f':
2665       case 't':
2666       {
2667         /*
2668           Label segment is the base of the filename.
2669         */
2670         if (*image->magick_filename == '\0')
2671           break;
2672         switch (*p)
2673         {
2674           case 'd':
2675           {
2676             /*
2677               Directory.
2678             */
2679             GetPathComponent(image->magick_filename,HeadPath,filename);
2680             q+=CopyMagickString(q,filename,extent);
2681             break;
2682           }
2683           case 'e':
2684           {
2685             /*
2686               Filename extension.
2687             */
2688             GetPathComponent(image->magick_filename,ExtensionPath,filename);
2689             q+=CopyMagickString(q,filename,extent);
2690             break;
2691           }
2692           case 'f':
2693           {
2694             /*
2695               Filename.
2696             */
2697             GetPathComponent(image->magick_filename,TailPath,filename);
2698             q+=CopyMagickString(q,filename,extent);
2699             break;
2700           }
2701           case 't':
2702           {
2703             /*
2704               Base filename.
2705             */
2706             GetPathComponent(image->magick_filename,BasePath,filename);
2707             q+=CopyMagickString(q,filename,extent);
2708             break;
2709           }
2710         }
2711         break;
2712       }
2713       case 'g':
2714       {
2715         /*
2716           Image geometry.
2717         */
2718         q+=FormatLocaleString(q,extent,"%.20gx%.20g%+.20g%+.20g",(double)
2719           image->page.width,(double) image->page.height,(double) image->page.x,
2720           (double) image->page.y);
2721         break;
2722       }
2723       case 'h':
2724       {
2725         /*
2726           Image height.
2727         */
2728         q+=FormatLocaleString(q,extent,"%.20g",(double) (image->rows != 0 ?
2729           image->rows : image->magick_rows));
2730         break;
2731       }
2732       case 'i':
2733       {
2734         /*
2735           Image filename.
2736         */
2737         q+=CopyMagickString(q,image->filename,extent);
2738         break;
2739       }
2740       case 'k':
2741       {
2742         /*
2743           Number of unique colors.
2744         */
2745         q+=FormatLocaleString(q,extent,"%.20g",(double) GetNumberColors(image,
2746           (FILE *) NULL,&image->exception));
2747         break;
2748       }
2749       case 'l':
2750       {
2751         /*
2752           Image label.
2753         */
2754         value=GetImageProperty(image,"label");
2755         if (value == (const char *) NULL)
2756           break;
2757         length=strlen(value);
2758         if ((size_t) (q-interpret_text+length+1) >= extent)
2759           {
2760             extent+=length;
2761             interpret_text=(char *) ResizeQuantumMemory(interpret_text,extent+
2762               MaxTextExtent,sizeof(*interpret_text));
2763             if (interpret_text == (char *) NULL)
2764               break;
2765             q=interpret_text+strlen(interpret_text);
2766           }
2767         q+=CopyMagickString(q,value,extent);
2768         break;
2769       }
2770       case 'm':
2771       {
2772         /*
2773           Image format.
2774         */
2775         q+=CopyMagickString(q,image->magick,extent);
2776         break;
2777       }
2778       case 'M':
2779       {
2780         /*
2781           Image magick filename.
2782         */
2783         q+=CopyMagickString(q,image->magick_filename,extent);
2784         break;
2785       }
2786       case 'n':
2787       {
2788         /*
2789           Number of images in the list.
2790         */
2791         q+=FormatLocaleString(q,extent,"%.20g",(double)
2792              GetImageListLength(image));
2793         break;
2794       }
2795       case 'o':
2796       {
2797         /*
2798           Image output filename.
2799         */
2800         q+=CopyMagickString(q,image_info->filename,extent);
2801         break;
2802       }
2803       case 'p':
2804       {
2805         /*
2806           Image index in list.
2807         */
2808         q+=FormatLocaleString(q,extent,"%.20g",(double)
2809             GetImageIndexInList(image));
2810         break;
2811       }
2812       case 'q':
2813       {
2814         /*
2815           Image depth.
2816         */
2817         q+=FormatLocaleString(q,extent,"%.20g",(double)
2818           MAGICKCORE_QUANTUM_DEPTH);
2819         break;
2820       }
2821       case 'r':
2822       {
2823         ColorspaceType
2824           colorspace;
2825
2826         /*
2827           Image storage class and colorspace.
2828         */
2829         colorspace=image->colorspace;
2830         if (IsImageGray(image,&image->exception) != MagickFalse)
2831           colorspace=GRAYColorspace;
2832         q+=FormatLocaleString(q,extent,"%s%s%s",CommandOptionToMnemonic(
2833           MagickClassOptions,(ssize_t) image->storage_class),
2834           CommandOptionToMnemonic(MagickColorspaceOptions,(ssize_t) colorspace),
2835           image->matte != MagickFalse ? "Matte" : "");
2836         break;
2837       }
2838       case 's':
2839       {
2840         /*
2841           Image scene number.
2842         */
2843         if (image_info->number_scenes == 0)
2844           q+=FormatLocaleString(q,extent,"%.20g",(double) image->scene);
2845         else
2846           q+=FormatLocaleString(q,extent,"%.20g",(double) image_info->scene);
2847         break;
2848       }
2849       case 'u':
2850       {
2851         /*
2852           Unique filename.
2853         */
2854         (void) CopyMagickString(filename,image_info->unique,extent);
2855         q+=CopyMagickString(q,filename,extent);
2856         break;
2857       }
2858       case 'w':
2859       {
2860         /*
2861           Image width.
2862         */
2863         q+=FormatLocaleString(q,extent,"%.20g",(double) (image->columns != 0 ?
2864           image->columns : image->magick_columns));
2865         break;
2866       }
2867       case 'x':
2868       {
2869         /*
2870           Image horizontal resolution.
2871         */
2872         q+=FormatLocaleString(q,extent,"%g %s",image->x_resolution,
2873           CommandOptionToMnemonic(MagickResolutionOptions,(ssize_t)
2874             image->units));
2875         break;
2876       }
2877       case 'y':
2878       {
2879         /*
2880           Image vertical resolution.
2881         */
2882         q+=FormatLocaleString(q,extent,"%g %s",image->y_resolution,
2883           CommandOptionToMnemonic(MagickResolutionOptions,(ssize_t)
2884           image->units));
2885         break;
2886       }
2887       case 'z':
2888       {
2889         /*
2890           Image depth.
2891         */
2892         q+=FormatLocaleString(q,extent,"%.20g",(double) image->depth);
2893         break;
2894       }
2895       case 'A':
2896       {
2897         /*
2898           Image alpha channel.
2899         */
2900         q+=FormatLocaleString(q,extent,"%s",CommandOptionToMnemonic(
2901           MagickBooleanOptions,(ssize_t) image->matte));
2902         break;
2903       }
2904       case 'C':
2905       {
2906         /*
2907           Image compression method.
2908         */
2909         q+=FormatLocaleString(q,extent,"%s",CommandOptionToMnemonic(
2910           MagickCompressOptions,(ssize_t) image->compression));
2911         break;
2912       }
2913       case 'D':
2914       {
2915         /*
2916           Image dispose method.
2917         */
2918         q+=FormatLocaleString(q,extent,"%s",CommandOptionToMnemonic(
2919           MagickDisposeOptions,(ssize_t) image->dispose));
2920         break;
2921       }
2922       case 'G':
2923       {
2924         q+=FormatLocaleString(q,extent,"%.20gx%.20g",(double)
2925           image->magick_columns,(double) image->magick_rows);
2926         break;
2927       }
2928       case 'H':
2929       {
2930         q+=FormatLocaleString(q,extent,"%.20g",(double) image->page.height);
2931         break;
2932       }
2933       case 'O':
2934       {
2935         q+=FormatLocaleString(q,extent,"%+ld%+ld",(long) image->page.x,(long)
2936           image->page.y);
2937         break;
2938       }
2939       case 'P':
2940       {
2941         q+=FormatLocaleString(q,extent,"%.20gx%.20g",(double) image->page.width,
2942           (double) image->page.height);
2943         break;
2944       }
2945       case 'Q':
2946       {
2947         q+=FormatLocaleString(q,extent,"%.20g",(double) image->quality);
2948         break;
2949       }
2950       case 'S':
2951       {
2952         /*
2953           Image scenes.
2954         */
2955         if (image_info->number_scenes == 0)
2956           q+=CopyMagickString(q,"2147483647",extent);
2957         else
2958           q+=FormatLocaleString(q,extent,"%.20g",(double) (image_info->scene+
2959             image_info->number_scenes));
2960         break;
2961       }
2962       case 'T':
2963       {
2964         q+=FormatLocaleString(q,extent,"%.20g",(double) image->delay);
2965         break;
2966       }
2967       case 'W':
2968       {
2969         q+=FormatLocaleString(q,extent,"%.20g",(double) image->page.width);
2970         break;
2971       }
2972       case 'X':
2973       {
2974         q+=FormatLocaleString(q,extent,"%+.20g",(double) image->page.x);
2975         break;
2976       }
2977       case 'Y':
2978       {
2979         q+=FormatLocaleString(q,extent,"%+.20g",(double) image->page.y);
2980         break;
2981       }
2982       case 'Z':
2983       {
2984         /*
2985           Unique filename.
2986         */
2987         (void) CopyMagickString(filename,image_info->zero,extent);
2988         q+=CopyMagickString(q,filename,extent);
2989         break;
2990       }
2991       case '[':
2992       {
2993         char
2994           pattern[MaxTextExtent];
2995
2996         const char
2997           *key,
2998           *value;
2999
3000         ssize_t
3001           depth;
3002
3003         /*
3004           Image value.
3005         */
3006         if (strchr(p,']') == (char *) NULL)
3007           break;
3008         depth=1;
3009         p++;
3010         for (i=0; (i < (MaxTextExtent-1L)) && (*p != '\0'); i++)
3011         {
3012           if (*p == '[')
3013             depth++;
3014           if (*p == ']')
3015             depth--;
3016           if (depth <= 0)
3017             break;
3018           pattern[i]=(*p++);
3019         }
3020         pattern[i]='\0';
3021         value=GetImageProperty(image,pattern);
3022         if (value != (const char *) NULL)
3023           {
3024             length=strlen(value);
3025             if ((size_t) (q-interpret_text+length+1) >= extent)
3026               {
3027                 extent+=length;
3028                 interpret_text=(char *) ResizeQuantumMemory(interpret_text,
3029                   extent+MaxTextExtent,sizeof(*interpret_text));
3030                 if (interpret_text == (char *) NULL)
3031                   break;
3032                 q=interpret_text+strlen(interpret_text);
3033               }
3034             (void) CopyMagickString(q,value,extent);
3035             q+=length;
3036             break;
3037           }
3038         else
3039           if (IsGlob(pattern) != MagickFalse)
3040             {
3041               /*
3042                 Iterate over image properties.
3043               */
3044               ResetImagePropertyIterator(image);
3045               key=GetNextImageProperty(image);
3046               while (key != (const char *) NULL)
3047               {
3048                 if (GlobExpression(key,pattern,MagickTrue) != MagickFalse)
3049                   {
3050                     value=GetImageProperty(image,key);
3051                     if (value != (const char *) NULL)
3052                       {
3053                         length=strlen(key)+strlen(value)+2;
3054                         if ((size_t) (q-interpret_text+length+1) >= extent)
3055                           {
3056                             extent+=length;
3057                             interpret_text=(char *) ResizeQuantumMemory(
3058                               interpret_text,extent+MaxTextExtent,
3059                               sizeof(*interpret_text));
3060                             if (interpret_text == (char *) NULL)
3061                               break;
3062                             q=interpret_text+strlen(interpret_text);
3063                           }
3064                         q+=FormatLocaleString(q,extent,"%s=%s\n",key,value);
3065                       }
3066                   }
3067                 key=GetNextImageProperty(image);
3068               }
3069             }
3070         value=GetMagickProperty(image_info,image,pattern);
3071         if (value != (const char *) NULL)
3072           {
3073             length=strlen(value);
3074             if ((size_t) (q-interpret_text+length+1) >= extent)
3075               {
3076                 extent+=length;
3077                 interpret_text=(char *) ResizeQuantumMemory(interpret_text,
3078                   extent+MaxTextExtent,sizeof(*interpret_text));
3079                 if (interpret_text == (char *) NULL)
3080                   break;
3081                 q=interpret_text+strlen(interpret_text);
3082               }
3083             (void) CopyMagickString(q,value,extent);
3084             q+=length;
3085             break;
3086           }
3087         if (image_info == (ImageInfo *) NULL)
3088           break;
3089         value=GetImageOption(image_info,pattern);
3090         if (value != (char *) NULL)
3091           {
3092             length=strlen(value);
3093             if ((size_t) (q-interpret_text+length+1) >= extent)
3094               {
3095                 extent+=length;
3096                 interpret_text=(char *) ResizeQuantumMemory(interpret_text,
3097                   extent+MaxTextExtent,sizeof(*interpret_text));
3098                 if (interpret_text == (char *) NULL)
3099                   break;
3100                 q=interpret_text+strlen(interpret_text);
3101               }
3102             (void) CopyMagickString(q,value,extent);
3103             q+=length;
3104             break;
3105           }
3106         break;
3107       }
3108       case '@':
3109       {
3110         RectangleInfo
3111           page;
3112
3113         /*
3114           Image bounding box.
3115         */
3116         page=GetImageBoundingBox(image,&image->exception);
3117         q+=FormatLocaleString(q,MaxTextExtent,"%.20gx%.20g%+.20g%+.20g",
3118           (double) page.width,(double) page.height,(double) page.x,(double)
3119           page.y);
3120         break;
3121       }
3122       case '#':
3123       {
3124         /*
3125           Image signature.
3126         */
3127         (void) SignatureImage(image);
3128         value=GetImageProperty(image,"signature");
3129         if (value == (const char *) NULL)
3130           break;
3131         q+=CopyMagickString(q,value,extent);
3132         break;
3133       }
3134       case '%':
3135       {
3136         *q++=(*p);
3137         break;
3138       }
3139       default:
3140       {
3141         *q++='%';
3142         *q++=(*p);
3143         break;
3144       }
3145     }
3146   }
3147   *q='\0';
3148   if (text != (const char *) embed_text)
3149     text=DestroyString(text);
3150   (void) SubstituteString(&interpret_text,"&lt;","<");
3151   (void) SubstituteString(&interpret_text,"&gt;",">");
3152   return(interpret_text);
3153 }
3154 \f
3155 /*
3156 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3157 %                                                                             %
3158 %                                                                             %
3159 %                                                                             %
3160 %   R e m o v e I m a g e P r o p e r t y                                     %
3161 %                                                                             %
3162 %                                                                             %
3163 %                                                                             %
3164 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3165 %
3166 %  RemoveImageProperty() removes a property from the image and returns its
3167 %  value.
3168 %
3169 %  The format of the RemoveImageProperty method is:
3170 %
3171 %      char *RemoveImageProperty(Image *image,const char *property)
3172 %
3173 %  A description of each parameter follows:
3174 %
3175 %    o image: the image.
3176 %
3177 %    o property: the image property.
3178 %
3179 */
3180 MagickExport char *RemoveImageProperty(Image *image,
3181   const char *property)
3182 {
3183   char
3184     *value;
3185
3186   assert(image != (Image *) NULL);
3187   assert(image->signature == MagickSignature);
3188   if (image->debug != MagickFalse)
3189     (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
3190       image->filename);
3191   if (image->properties == (void *) NULL)
3192     return((char *) NULL);
3193   value=(char *) RemoveNodeFromSplayTree((SplayTreeInfo *) image->properties,
3194     property);
3195   return(value);
3196 }
3197 \f
3198 /*
3199 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3200 %                                                                             %
3201 %                                                                             %
3202 %                                                                             %
3203 %   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                       %
3204 %                                                                             %
3205 %                                                                             %
3206 %                                                                             %
3207 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3208 %
3209 %  ResetImagePropertyIterator() resets the image properties iterator.  Use it
3210 %  in conjunction with GetNextImageProperty() to iterate over all the values
3211 %  associated with an image property.
3212 %
3213 %  The format of the ResetImagePropertyIterator method is:
3214 %
3215 %      ResetImagePropertyIterator(Image *image)
3216 %
3217 %  A description of each parameter follows:
3218 %
3219 %    o image: the image.
3220 %
3221 */
3222 MagickExport void ResetImagePropertyIterator(const Image *image)
3223 {
3224   assert(image != (Image *) NULL);
3225   assert(image->signature == MagickSignature);
3226   if (image->debug != MagickFalse)
3227     (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
3228       image->filename);
3229   if (image->properties == (void *) NULL)
3230     return;
3231   ResetSplayTreeIterator((SplayTreeInfo *) image->properties);
3232 }
3233 \f
3234 /*
3235 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3236 %                                                                             %
3237 %                                                                             %
3238 %                                                                             %
3239 %   S e t I m a g e P r o p e r t y                                           %
3240 %                                                                             %
3241 %                                                                             %
3242 %                                                                             %
3243 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3244 %
3245 %  SetImageProperty() associates an value with an image property.
3246 %
3247 %  The format of the SetImageProperty method is:
3248 %
3249 %      MagickBooleanType SetImageProperty(Image *image,const char *property,
3250 %        const char *value)
3251 %
3252 %  A description of each parameter follows:
3253 %
3254 %    o image: the image.
3255 %
3256 %    o property: the image property.
3257 %
3258 %    o values: the image property values.
3259 %
3260 */
3261 MagickExport MagickBooleanType SetImageProperty(Image *image,
3262   const char *property,const char *value)
3263 {
3264   ExceptionInfo
3265     *exception;
3266
3267   MagickBooleanType
3268     status;
3269
3270   MagickStatusType
3271     flags;
3272
3273   assert(image != (Image *) NULL);
3274   assert(image->signature == MagickSignature);
3275   if (image->debug != MagickFalse)
3276     (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
3277       image->filename);
3278   if (image->properties == (void *) NULL)
3279     image->properties=NewSplayTree(CompareSplayTreeString,
3280       RelinquishMagickMemory,RelinquishMagickMemory);
3281   if ((value == (const char *) NULL) || (*value == '\0'))
3282     return(DeleteImageProperty(image,property));
3283   status=MagickTrue;
3284   exception=(&image->exception);
3285   switch (*property)
3286   {
3287     case 'B':
3288     case 'b':
3289     {
3290       if (LocaleCompare(property,"background") == 0)
3291         {
3292           (void) QueryColorDatabase(value,&image->background_color,exception);
3293           break;
3294         }
3295       if (LocaleCompare(property,"bias") == 0)
3296         {
3297           image->bias=SiPrefixToDouble(value,QuantumRange);
3298           break;
3299         }
3300       status=AddValueToSplayTree((SplayTreeInfo *) image->properties,
3301         ConstantString(property),ConstantString(value));
3302       break;
3303     }
3304     case 'C':
3305     case 'c':
3306     {
3307       if (LocaleCompare(property,"colorspace") == 0)
3308         {
3309           ssize_t
3310             colorspace;
3311
3312           colorspace=ParseCommandOption(MagickColorspaceOptions,MagickFalse,
3313             value);
3314           if (colorspace < 0)
3315             break;
3316           (void) SetImageColorspace(image,(ColorspaceType) colorspace);
3317           break;
3318         }
3319       if (LocaleCompare(property,"compose") == 0)
3320         {
3321           ssize_t
3322             compose;
3323
3324           compose=ParseCommandOption(MagickComposeOptions,MagickFalse,value);
3325           if (compose < 0)
3326             break;
3327           image->compose=(CompositeOperator) compose;
3328           break;
3329         }
3330       if (LocaleCompare(property,"compress") == 0)
3331         {
3332           ssize_t
3333             compression;
3334
3335           compression=ParseCommandOption(MagickCompressOptions,MagickFalse,
3336             value);
3337           if (compression < 0)
3338             break;
3339           image->compression=(CompressionType) compression;
3340           break;
3341         }
3342       status=AddValueToSplayTree((SplayTreeInfo *) image->properties,
3343         ConstantString(property),ConstantString(value));
3344       break;
3345     }
3346     case 'D':
3347     case 'd':
3348     {
3349       if (LocaleCompare(property,"delay") == 0)
3350         {
3351           GeometryInfo
3352             geometry_info;
3353
3354           flags=ParseGeometry(value,&geometry_info);
3355           if ((flags & GreaterValue) != 0)
3356             {
3357               if (image->delay > (size_t) floor(geometry_info.rho+0.5))
3358                 image->delay=(size_t) floor(geometry_info.rho+0.5);
3359             }
3360           else
3361             if ((flags & LessValue) != 0)
3362               {
3363                 if (image->delay < (size_t) floor(geometry_info.rho+0.5))
3364                   image->ticks_per_second=(ssize_t)
3365                     floor(geometry_info.sigma+0.5);
3366               }
3367             else
3368               image->delay=(size_t) floor(geometry_info.rho+0.5);
3369           if ((flags & SigmaValue) != 0)
3370             image->ticks_per_second=(ssize_t) floor(geometry_info.sigma+0.5);
3371           break;
3372         }
3373       if (LocaleCompare(property,"density") == 0)
3374         {
3375           GeometryInfo
3376             geometry_info;
3377
3378           flags=ParseGeometry(value,&geometry_info);
3379           image->x_resolution=geometry_info.rho;
3380           image->y_resolution=geometry_info.sigma;
3381           if ((flags & SigmaValue) == 0)
3382             image->y_resolution=image->x_resolution;
3383         }
3384       if (LocaleCompare(property,"depth") == 0)
3385         {
3386           image->depth=StringToUnsignedLong(value);
3387           break;
3388         }
3389       if (LocaleCompare(property,"dispose") == 0)
3390         {
3391           ssize_t
3392             dispose;
3393
3394           dispose=ParseCommandOption(MagickDisposeOptions,MagickFalse,value);
3395           if (dispose < 0)
3396             break;
3397           image->dispose=(DisposeType) dispose;
3398           break;
3399         }
3400       status=AddValueToSplayTree((SplayTreeInfo *) image->properties,
3401         ConstantString(property),ConstantString(value));
3402       break;
3403     }
3404     case 'G':
3405     case 'g':
3406     {
3407       if (LocaleCompare(property,"gravity") == 0)
3408         {
3409           ssize_t
3410             gravity;
3411
3412           gravity=ParseCommandOption(MagickGravityOptions,MagickFalse,value);
3413           if (gravity < 0)
3414             break;
3415           image->gravity=(GravityType) gravity;
3416           break;
3417         }
3418       status=AddValueToSplayTree((SplayTreeInfo *) image->properties,
3419         ConstantString(property),ConstantString(value));
3420       break;
3421     }
3422     case 'I':
3423     case 'i':
3424     {
3425       if (LocaleCompare(property,"intent") == 0)
3426         {
3427           ssize_t
3428             rendering_intent;
3429
3430           rendering_intent=ParseCommandOption(MagickIntentOptions,MagickFalse,
3431             value);
3432           if (rendering_intent < 0)
3433             break;
3434           image->rendering_intent=(RenderingIntent) rendering_intent;
3435           break;
3436         }
3437       if (LocaleCompare(property,"interpolate") == 0)
3438         {
3439           ssize_t
3440             interpolate;
3441
3442           interpolate=ParseCommandOption(MagickInterpolateOptions,MagickFalse,
3443             value);
3444           if (interpolate < 0)
3445             break;
3446           image->interpolate=(InterpolatePixelMethod) interpolate;
3447           break;
3448         }
3449       status=AddValueToSplayTree((SplayTreeInfo *) image->properties,
3450         ConstantString(property),ConstantString(value));
3451       break;
3452     }
3453     case 'L':
3454     case 'l':
3455     {
3456       if (LocaleCompare(property,"loop") == 0)
3457         {
3458           image->iterations=StringToUnsignedLong(value);
3459           break;
3460         }
3461       status=AddValueToSplayTree((SplayTreeInfo *) image->properties,
3462         ConstantString(property),ConstantString(value));
3463       break;
3464     }
3465     case 'P':
3466     case 'p':
3467     {
3468       if (LocaleCompare(property,"page") == 0)
3469         {
3470           char
3471             *geometry;
3472
3473           geometry=GetPageGeometry(value);
3474           flags=ParseAbsoluteGeometry(geometry,&image->page);
3475           geometry=DestroyString(geometry);
3476           break;
3477         }
3478       if (LocaleCompare(property,"profile") == 0)
3479         {
3480           ImageInfo
3481             *image_info;
3482
3483           StringInfo
3484             *profile;
3485
3486           image_info=AcquireImageInfo();
3487           (void) CopyMagickString(image_info->filename,value,MaxTextExtent);
3488           (void) SetImageInfo(image_info,1,exception);
3489           profile=FileToStringInfo(image_info->filename,~0UL,exception);
3490           if (profile != (StringInfo *) NULL)
3491             status=SetImageProfile(image,image_info->magick,profile);
3492           image_info=DestroyImageInfo(image_info);
3493           break;
3494         }
3495       status=AddValueToSplayTree((SplayTreeInfo *) image->properties,
3496         ConstantString(property),ConstantString(value));
3497       break;
3498     }
3499     case 'R':
3500     case 'r':
3501     {
3502       if (LocaleCompare(property,"rendering-intent") == 0)
3503         {
3504           ssize_t
3505             rendering_intent;
3506
3507           rendering_intent=ParseCommandOption(MagickIntentOptions,MagickFalse,
3508             value);
3509           if (rendering_intent < 0)
3510             break;
3511           image->rendering_intent=(RenderingIntent) rendering_intent;
3512           break;
3513         }
3514       status=AddValueToSplayTree((SplayTreeInfo *) image->properties,
3515         ConstantString(property),ConstantString(value));
3516       break;
3517     }
3518     case 'T':
3519     case 't':
3520     {
3521       if (LocaleCompare(property,"tile-offset") == 0)
3522         {
3523           char
3524             *geometry;
3525
3526           geometry=GetPageGeometry(value);
3527           flags=ParseAbsoluteGeometry(geometry,&image->tile_offset);
3528           geometry=DestroyString(geometry);
3529           break;
3530         }
3531       status=AddValueToSplayTree((SplayTreeInfo *) image->properties,
3532         ConstantString(property),ConstantString(value));
3533       break;
3534     }
3535     case 'U':
3536     case 'u':
3537     {
3538       if (LocaleCompare(property,"units") == 0)
3539         {
3540           ssize_t
3541             units;
3542
3543           units=ParseCommandOption(MagickResolutionOptions,MagickFalse,value);
3544           if (units < 0)
3545             break;
3546           image->units=(ResolutionType) units;
3547           break;
3548         }
3549       status=AddValueToSplayTree((SplayTreeInfo *) image->properties,
3550         ConstantString(property),ConstantString(value));
3551       break;
3552     }
3553     default:
3554     {
3555       status=AddValueToSplayTree((SplayTreeInfo *) image->properties,
3556         ConstantString(property),ConstantString(value));
3557       break;
3558     }
3559   }
3560   return(status);
3561 }