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