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