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