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