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