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