2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
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 %
13 % MagickCore Property Methods %
20 % Copyright 1999-2018 ImageMagick Studio LLC, a non-profit organization %
21 % dedicated to making software imaging solutions freely available. %
23 % You may not use this file except in compliance with the License. You may %
24 % obtain a copy of the License at %
26 % https://www.imagemagick.org/script/license.php %
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. %
34 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
43 #include "MagickCore/studio.h"
44 #include "MagickCore/artifact.h"
45 #include "MagickCore/attribute.h"
46 #include "MagickCore/cache.h"
47 #include "MagickCore/cache-private.h"
48 #include "MagickCore/color.h"
49 #include "MagickCore/color-private.h"
50 #include "MagickCore/colorspace-private.h"
51 #include "MagickCore/compare.h"
52 #include "MagickCore/constitute.h"
53 #include "MagickCore/draw.h"
54 #include "MagickCore/effect.h"
55 #include "MagickCore/exception.h"
56 #include "MagickCore/exception-private.h"
57 #include "MagickCore/fx.h"
58 #include "MagickCore/fx-private.h"
59 #include "MagickCore/gem.h"
60 #include "MagickCore/geometry.h"
61 #include "MagickCore/histogram.h"
62 #include "MagickCore/image.h"
63 #include "MagickCore/layer.h"
64 #include "MagickCore/locale-private.h"
65 #include "MagickCore/list.h"
66 #include "MagickCore/magick.h"
67 #include "MagickCore/memory_.h"
68 #include "MagickCore/monitor.h"
69 #include "MagickCore/montage.h"
70 #include "MagickCore/option.h"
71 #include "MagickCore/policy.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_LCMS2_LCMS2_H)
90 #include <lcms2/lcms2.h>
91 #elif defined(MAGICKCORE_HAVE_LCMS2_H)
93 #elif defined(MAGICKCORE_HAVE_LCMS_LCMS_H)
94 #include <lcms/lcms.h>
99 #if defined(MAGICKCORE_XML_DELEGATE)
100 # if defined(MAGICKCORE_WINDOWS_SUPPORT)
101 # if !defined(__MINGW32__)
102 # include <win32config.h>
105 # include <libxml/parser.h>
106 # include <libxml/tree.h>
112 #if defined(MAGICKCORE_LCMS_DELEGATE)
113 #if defined(LCMS_VERSION) && (LCMS_VERSION < 2000)
114 #define cmsUInt32Number DWORD
119 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
123 % C l o n e I m a g e P r o p e r t i e s %
127 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
129 % CloneImageProperties() clones all the image properties to another image.
131 % The format of the CloneImageProperties method is:
133 % MagickBooleanType CloneImageProperties(Image *image,
134 % const Image *clone_image)
136 % A description of each parameter follows:
138 % o image: the image.
140 % o clone_image: the clone image.
143 MagickExport MagickBooleanType CloneImageProperties(Image *image,
144 const Image *clone_image)
146 assert(image != (Image *) NULL);
147 assert(image->signature == MagickCoreSignature);
148 if (image->debug != MagickFalse)
149 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
150 assert(clone_image != (const Image *) NULL);
151 assert(clone_image->signature == MagickCoreSignature);
152 if (clone_image->debug != MagickFalse)
153 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
154 clone_image->filename);
155 (void) CopyMagickString(image->filename,clone_image->filename,
157 (void) CopyMagickString(image->magick_filename,clone_image->magick_filename,
159 image->compression=clone_image->compression;
160 image->quality=clone_image->quality;
161 image->depth=clone_image->depth;
162 image->matte_color=clone_image->matte_color;
163 image->background_color=clone_image->background_color;
164 image->border_color=clone_image->border_color;
165 image->transparent_color=clone_image->transparent_color;
166 image->gamma=clone_image->gamma;
167 image->chromaticity=clone_image->chromaticity;
168 image->rendering_intent=clone_image->rendering_intent;
169 image->black_point_compensation=clone_image->black_point_compensation;
170 image->units=clone_image->units;
171 image->montage=(char *) NULL;
172 image->directory=(char *) NULL;
173 (void) CloneString(&image->geometry,clone_image->geometry);
174 image->offset=clone_image->offset;
175 image->resolution.x=clone_image->resolution.x;
176 image->resolution.y=clone_image->resolution.y;
177 image->page=clone_image->page;
178 image->tile_offset=clone_image->tile_offset;
179 image->extract_info=clone_image->extract_info;
180 image->filter=clone_image->filter;
181 image->fuzz=clone_image->fuzz;
182 image->intensity=clone_image->intensity;
183 image->interlace=clone_image->interlace;
184 image->interpolate=clone_image->interpolate;
185 image->endian=clone_image->endian;
186 image->gravity=clone_image->gravity;
187 image->compose=clone_image->compose;
188 image->orientation=clone_image->orientation;
189 image->scene=clone_image->scene;
190 image->dispose=clone_image->dispose;
191 image->delay=clone_image->delay;
192 image->ticks_per_second=clone_image->ticks_per_second;
193 image->iterations=clone_image->iterations;
194 image->total_colors=clone_image->total_colors;
195 image->taint=clone_image->taint;
196 image->progress_monitor=clone_image->progress_monitor;
197 image->client_data=clone_image->client_data;
198 image->start_loop=clone_image->start_loop;
199 image->error=clone_image->error;
200 image->signature=clone_image->signature;
201 if (clone_image->properties != (void *) NULL)
203 if (image->properties != (void *) NULL)
204 DestroyImageProperties(image);
205 image->properties=CloneSplayTree((SplayTreeInfo *)
206 clone_image->properties,(void *(*)(void *)) ConstantString,
207 (void *(*)(void *)) ConstantString);
213 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
217 % D e f i n e I m a g e P r o p e r t y %
221 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
223 % DefineImageProperty() associates an assignment string of the form
224 % "key=value" with an artifact or options. It is equivelent to
225 % SetImageProperty().
227 % The format of the DefineImageProperty method is:
229 % MagickBooleanType DefineImageProperty(Image *image,const char *property,
230 % ExceptionInfo *exception)
232 % A description of each parameter follows:
234 % o image: the image.
236 % o property: the image property.
238 % o exception: return any errors or warnings in this structure.
241 MagickExport MagickBooleanType DefineImageProperty(Image *image,
242 const char *property,ExceptionInfo *exception)
245 key[MagickPathExtent],
246 value[MagickPathExtent];
251 assert(image != (Image *) NULL);
252 assert(property != (const char *) NULL);
253 (void) CopyMagickString(key,property,MagickPathExtent-1);
254 for (p=key; *p != '\0'; p++)
259 (void) CopyMagickString(value,p+1,MagickPathExtent);
261 return(SetImageProperty(image,key,value,exception));
265 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
269 % D e l e t e I m a g e P r o p e r t y %
273 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
275 % DeleteImageProperty() deletes an image property.
277 % The format of the DeleteImageProperty method is:
279 % MagickBooleanType DeleteImageProperty(Image *image,const char *property)
281 % A description of each parameter follows:
283 % o image: the image.
285 % o property: the image property.
288 MagickExport MagickBooleanType DeleteImageProperty(Image *image,
289 const char *property)
291 assert(image != (Image *) NULL);
292 assert(image->signature == MagickCoreSignature);
293 if (image->debug != MagickFalse)
294 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
295 if (image->properties == (void *) NULL)
297 return(DeleteNodeFromSplayTree((SplayTreeInfo *) image->properties,property));
301 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
305 % D e s t r o y I m a g e P r o p e r t i e s %
309 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
311 % DestroyImageProperties() destroys all properties and associated memory
312 % attached to the given image.
314 % The format of the DestroyDefines method is:
316 % void DestroyImageProperties(Image *image)
318 % A description of each parameter follows:
320 % o image: the image.
323 MagickExport void DestroyImageProperties(Image *image)
325 assert(image != (Image *) NULL);
326 assert(image->signature == MagickCoreSignature);
327 if (image->debug != MagickFalse)
328 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
329 if (image->properties != (void *) NULL)
330 image->properties=(void *) DestroySplayTree((SplayTreeInfo *)
335 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
339 % F o r m a t I m a g e P r o p e r t y %
343 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
345 % FormatImageProperty() permits formatted property/value pairs to be saved as
348 % The format of the FormatImageProperty method is:
350 % MagickBooleanType FormatImageProperty(Image *image,const char *property,
351 % const char *format,...)
353 % A description of each parameter follows.
355 % o image: The image.
357 % o property: The attribute property.
359 % o format: A string describing the format to use to write the remaining
363 MagickExport MagickBooleanType FormatImageProperty(Image *image,
364 const char *property,const char *format,...)
367 value[MagickPathExtent];
381 va_start(operands,format);
382 n=FormatLocaleStringList(value,MagickPathExtent,format,operands);
385 exception=AcquireExceptionInfo();
386 status=SetImageProperty(image,property,value,exception);
387 exception=DestroyExceptionInfo(exception);
392 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
396 % G e t I m a g e P r o p e r t y %
400 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
402 % GetImageProperty() gets a value associated with an image property.
404 % This includes, profile prefixes, such as "exif:", "iptc:" and "8bim:"
405 % It does not handle non-prifile prefixes, such as "fx:", "option:", or
408 % The returned string is stored as a properity of the same name for faster
409 % lookup later. It should NOT be freed by the caller.
411 % The format of the GetImageProperty method is:
413 % const char *GetImageProperty(const Image *image,const char *key,
414 % ExceptionInfo *exception)
416 % A description of each parameter follows:
418 % o image: the image.
422 % o exception: return any errors or warnings in this structure.
427 *TracePSClippath(const unsigned char *,size_t),
428 *TraceSVGClippath(const unsigned char *,size_t,const size_t,
431 static MagickBooleanType GetIPTCProperty(const Image *image,const char *key,
432 ExceptionInfo *exception)
452 profile=GetImageProfile(image,"iptc");
453 if (profile == (StringInfo *) NULL)
454 profile=GetImageProfile(image,"8bim");
455 if (profile == (StringInfo *) NULL)
457 count=sscanf(key,"IPTC:%ld:%ld",&dataset,&record);
460 attribute=(char *) NULL;
461 for (i=0; i < (ssize_t) GetStringInfoLength(profile); i+=(ssize_t) length)
464 if ((ssize_t) GetStringInfoDatum(profile)[i] != 0x1c)
466 length=(size_t) (GetStringInfoDatum(profile)[i+3] << 8);
467 length|=GetStringInfoDatum(profile)[i+4];
468 if (((long) GetStringInfoDatum(profile)[i+1] == dataset) &&
469 ((long) GetStringInfoDatum(profile)[i+2] == record))
471 message=(char *) NULL;
473 message=(char *) AcquireQuantumMemory(length+1UL,sizeof(*message));
474 if (message != (char *) NULL)
476 (void) CopyMagickString(message,(char *) GetStringInfoDatum(
477 profile)+i+5,length+1);
478 (void) ConcatenateString(&attribute,message);
479 (void) ConcatenateString(&attribute,";");
480 message=DestroyString(message);
485 if ((attribute == (char *) NULL) || (*attribute == ';'))
487 if (attribute != (char *) NULL)
488 attribute=DestroyString(attribute);
491 attribute[strlen(attribute)-1]='\0';
492 (void) SetImageProperty((Image *) image,key,(const char *) attribute,
494 attribute=DestroyString(attribute);
498 static inline int ReadPropertyByte(const unsigned char **p,size_t *length)
510 static inline signed int ReadPropertyMSBLong(const unsigned char **p,
536 for (i=0; i < 4; i++)
540 buffer[i]=(unsigned char) c;
542 value=(unsigned int) buffer[0] << 24;
543 value|=(unsigned int) buffer[1] << 16;
544 value|=(unsigned int) buffer[2] << 8;
545 value|=(unsigned int) buffer[3];
546 quantum.unsigned_value=value & 0xffffffff;
547 return(quantum.signed_value);
550 static inline signed short ReadPropertyMSBShort(const unsigned char **p,
575 return((unsigned short) ~0);
576 for (i=0; i < 2; i++)
580 buffer[i]=(unsigned char) c;
582 value=(unsigned short) buffer[0] << 8;
583 value|=(unsigned short) buffer[1];
584 quantum.unsigned_value=value & 0xffff;
585 return(quantum.signed_value);
588 static MagickBooleanType Get8BIMProperty(const Image *image,const char *key,
589 ExceptionInfo *exception)
593 format[MagickPathExtent],
594 name[MagickPathExtent],
622 There are no newlines in path names, so it's safe as terminator.
624 profile=GetImageProfile(image,"8bim");
625 if (profile == (StringInfo *) NULL)
627 count=(ssize_t) sscanf(key,"8BIM:%ld,%ld:%1024[^\n]\n%1024[^\n]",&start,&stop,
629 if ((count != 2) && (count != 3) && (count != 4))
632 (void) CopyMagickString(format,"SVG",MagickPathExtent);
637 sub_number=(ssize_t) StringToLong(&name[1]);
638 sub_number=MagickMax(sub_number,1L);
639 resource=(char *) NULL;
641 length=GetStringInfoLength(profile);
642 info=GetStringInfoDatum(profile);
643 while ((length > 0) && (status == MagickFalse))
645 if (ReadPropertyByte(&info,&length) != (unsigned char) '8')
647 if (ReadPropertyByte(&info,&length) != (unsigned char) 'B')
649 if (ReadPropertyByte(&info,&length) != (unsigned char) 'I')
651 if (ReadPropertyByte(&info,&length) != (unsigned char) 'M')
653 id=(ssize_t) ReadPropertyMSBShort(&info,&length);
654 if (id < (ssize_t) start)
656 if (id > (ssize_t) stop)
658 if (resource != (char *) NULL)
659 resource=DestroyString(resource);
660 count=(ssize_t) ReadPropertyByte(&info,&length);
661 if ((count != 0) && ((size_t) count <= length))
663 resource=(char *) NULL;
664 if (~((size_t) count) >= (MagickPathExtent-1))
665 resource=(char *) AcquireQuantumMemory((size_t) count+
666 MagickPathExtent,sizeof(*resource));
667 if (resource != (char *) NULL)
669 for (i=0; i < (ssize_t) count; i++)
670 resource[i]=(char) ReadPropertyByte(&info,&length);
671 resource[count]='\0';
674 if ((count & 0x01) == 0)
675 (void) ReadPropertyByte(&info,&length);
676 count=(ssize_t) ReadPropertyMSBLong(&info,&length);
677 if ((count < 0) || ((size_t) count > length))
682 if ((*name != '\0') && (*name != '#'))
683 if ((resource == (char *) NULL) || (LocaleCompare(name,resource) != 0))
686 No name match, scroll forward and try next.
689 length-=MagickMin(count,(ssize_t) length);
692 if ((*name == '#') && (sub_number != 1))
695 No numbered match, scroll forward and try next.
699 length-=MagickMin(count,(ssize_t) length);
703 We have the resource of interest.
705 attribute=(char *) NULL;
706 if (~((size_t) count) >= (MagickPathExtent-1))
707 attribute=(char *) AcquireQuantumMemory((size_t) count+MagickPathExtent,
709 if (attribute != (char *) NULL)
711 (void) memcpy(attribute,(char *) info,(size_t) count);
712 attribute[count]='\0';
714 length-=MagickMin(count,(ssize_t) length);
715 if ((id <= 1999) || (id >= 2999))
716 (void) SetImageProperty((Image *) image,key,(const char *) attribute,
723 if (LocaleCompare(format,"svg") == 0)
724 path=TraceSVGClippath((unsigned char *) attribute,(size_t) count,
725 image->columns,image->rows);
727 path=TracePSClippath((unsigned char *) attribute,(size_t) count);
728 (void) SetImageProperty((Image *) image,key,(const char *) path,
730 path=DestroyString(path);
732 attribute=DestroyString(attribute);
736 if (resource != (char *) NULL)
737 resource=DestroyString(resource);
741 static inline signed int ReadPropertySignedLong(const EndianType endian,
742 const unsigned char *buffer)
756 if (endian == LSBEndian)
758 value=(unsigned int) buffer[3] << 24;
759 value|=(unsigned int) buffer[2] << 16;
760 value|=(unsigned int) buffer[1] << 8;
761 value|=(unsigned int) buffer[0];
762 quantum.unsigned_value=value & 0xffffffff;
763 return(quantum.signed_value);
765 value=(unsigned int) buffer[0] << 24;
766 value|=(unsigned int) buffer[1] << 16;
767 value|=(unsigned int) buffer[2] << 8;
768 value|=(unsigned int) buffer[3];
769 quantum.unsigned_value=value & 0xffffffff;
770 return(quantum.signed_value);
773 static inline unsigned int ReadPropertyUnsignedLong(const EndianType endian,
774 const unsigned char *buffer)
779 if (endian == LSBEndian)
781 value=(unsigned int) buffer[3] << 24;
782 value|=(unsigned int) buffer[2] << 16;
783 value|=(unsigned int) buffer[1] << 8;
784 value|=(unsigned int) buffer[0];
785 return(value & 0xffffffff);
787 value=(unsigned int) buffer[0] << 24;
788 value|=(unsigned int) buffer[1] << 16;
789 value|=(unsigned int) buffer[2] << 8;
790 value|=(unsigned int) buffer[3];
791 return(value & 0xffffffff);
794 static inline signed short ReadPropertySignedShort(const EndianType endian,
795 const unsigned char *buffer)
809 if (endian == LSBEndian)
811 value=(unsigned short) buffer[1] << 8;
812 value|=(unsigned short) buffer[0];
813 quantum.unsigned_value=value & 0xffff;
814 return(quantum.signed_value);
816 value=(unsigned short) buffer[0] << 8;
817 value|=(unsigned short) buffer[1];
818 quantum.unsigned_value=value & 0xffff;
819 return(quantum.signed_value);
822 static inline unsigned short ReadPropertyUnsignedShort(const EndianType endian,
823 const unsigned char *buffer)
828 if (endian == LSBEndian)
830 value=(unsigned short) buffer[1] << 8;
831 value|=(unsigned short) buffer[0];
832 return(value & 0xffff);
834 value=(unsigned short) buffer[0] << 8;
835 value|=(unsigned short) buffer[1];
836 return(value & 0xffff);
839 static MagickBooleanType GetEXIFProperty(const Image *image,
840 const char *property,ExceptionInfo *exception)
842 #define MaxDirectoryStack 16
843 #define EXIF_DELIMITER "\n"
844 #define EXIF_NUM_FORMATS 12
845 #define EXIF_FMT_BYTE 1
846 #define EXIF_FMT_STRING 2
847 #define EXIF_FMT_USHORT 3
848 #define EXIF_FMT_ULONG 4
849 #define EXIF_FMT_URATIONAL 5
850 #define EXIF_FMT_SBYTE 6
851 #define EXIF_FMT_UNDEFINED 7
852 #define EXIF_FMT_SSHORT 8
853 #define EXIF_FMT_SLONG 9
854 #define EXIF_FMT_SRATIONAL 10
855 #define EXIF_FMT_SINGLE 11
856 #define EXIF_FMT_DOUBLE 12
857 #define TAG_EXIF_OFFSET 0x8769
858 #define TAG_GPS_OFFSET 0x8825
859 #define TAG_INTEROP_OFFSET 0xa005
861 #define EXIFMultipleValues(size,format,arg) \
874 for (component=0; component < components; component++) \
876 len+=FormatLocaleString(buffer+len,MagickPathExtent-len,format", ",arg); \
877 if (len >= (MagickPathExtent-1)) \
878 len=MagickPathExtent-1; \
882 buffer[len-2]='\0'; \
883 value=AcquireString(buffer); \
886 #define EXIFMultipleFractions(size,format,arg1,arg2) \
899 for (component=0; component < components; component++) \
901 len+=FormatLocaleString(buffer+len,MagickPathExtent-len,format", ", \
903 if (len >= (MagickPathExtent-1)) \
904 len=MagickPathExtent-1; \
908 buffer[len-2]='\0'; \
909 value=AcquireString(buffer); \
912 typedef struct _DirectoryInfo
924 typedef struct _TagInfo
936 { 0x001, "exif:InteroperabilityIndex" },
937 { 0x002, "exif:InteroperabilityVersion" },
938 { 0x100, "exif:ImageWidth" },
939 { 0x101, "exif:ImageLength" },
940 { 0x102, "exif:BitsPerSample" },
941 { 0x103, "exif:Compression" },
942 { 0x106, "exif:PhotometricInterpretation" },
943 { 0x10a, "exif:FillOrder" },
944 { 0x10d, "exif:DocumentName" },
945 { 0x10e, "exif:ImageDescription" },
946 { 0x10f, "exif:Make" },
947 { 0x110, "exif:Model" },
948 { 0x111, "exif:StripOffsets" },
949 { 0x112, "exif:Orientation" },
950 { 0x115, "exif:SamplesPerPixel" },
951 { 0x116, "exif:RowsPerStrip" },
952 { 0x117, "exif:StripByteCounts" },
953 { 0x11a, "exif:XResolution" },
954 { 0x11b, "exif:YResolution" },
955 { 0x11c, "exif:PlanarConfiguration" },
956 { 0x11d, "exif:PageName" },
957 { 0x11e, "exif:XPosition" },
958 { 0x11f, "exif:YPosition" },
959 { 0x118, "exif:MinSampleValue" },
960 { 0x119, "exif:MaxSampleValue" },
961 { 0x120, "exif:FreeOffsets" },
962 { 0x121, "exif:FreeByteCounts" },
963 { 0x122, "exif:GrayResponseUnit" },
964 { 0x123, "exif:GrayResponseCurve" },
965 { 0x124, "exif:T4Options" },
966 { 0x125, "exif:T6Options" },
967 { 0x128, "exif:ResolutionUnit" },
968 { 0x12d, "exif:TransferFunction" },
969 { 0x131, "exif:Software" },
970 { 0x132, "exif:DateTime" },
971 { 0x13b, "exif:Artist" },
972 { 0x13e, "exif:WhitePoint" },
973 { 0x13f, "exif:PrimaryChromaticities" },
974 { 0x140, "exif:ColorMap" },
975 { 0x141, "exif:HalfToneHints" },
976 { 0x142, "exif:TileWidth" },
977 { 0x143, "exif:TileLength" },
978 { 0x144, "exif:TileOffsets" },
979 { 0x145, "exif:TileByteCounts" },
980 { 0x14a, "exif:SubIFD" },
981 { 0x14c, "exif:InkSet" },
982 { 0x14d, "exif:InkNames" },
983 { 0x14e, "exif:NumberOfInks" },
984 { 0x150, "exif:DotRange" },
985 { 0x151, "exif:TargetPrinter" },
986 { 0x152, "exif:ExtraSample" },
987 { 0x153, "exif:SampleFormat" },
988 { 0x154, "exif:SMinSampleValue" },
989 { 0x155, "exif:SMaxSampleValue" },
990 { 0x156, "exif:TransferRange" },
991 { 0x157, "exif:ClipPath" },
992 { 0x158, "exif:XClipPathUnits" },
993 { 0x159, "exif:YClipPathUnits" },
994 { 0x15a, "exif:Indexed" },
995 { 0x15b, "exif:JPEGTables" },
996 { 0x15f, "exif:OPIProxy" },
997 { 0x200, "exif:JPEGProc" },
998 { 0x201, "exif:JPEGInterchangeFormat" },
999 { 0x202, "exif:JPEGInterchangeFormatLength" },
1000 { 0x203, "exif:JPEGRestartInterval" },
1001 { 0x205, "exif:JPEGLosslessPredictors" },
1002 { 0x206, "exif:JPEGPointTransforms" },
1003 { 0x207, "exif:JPEGQTables" },
1004 { 0x208, "exif:JPEGDCTables" },
1005 { 0x209, "exif:JPEGACTables" },
1006 { 0x211, "exif:YCbCrCoefficients" },
1007 { 0x212, "exif:YCbCrSubSampling" },
1008 { 0x213, "exif:YCbCrPositioning" },
1009 { 0x214, "exif:ReferenceBlackWhite" },
1010 { 0x2bc, "exif:ExtensibleMetadataPlatform" },
1011 { 0x301, "exif:Gamma" },
1012 { 0x302, "exif:ICCProfileDescriptor" },
1013 { 0x303, "exif:SRGBRenderingIntent" },
1014 { 0x320, "exif:ImageTitle" },
1015 { 0x5001, "exif:ResolutionXUnit" },
1016 { 0x5002, "exif:ResolutionYUnit" },
1017 { 0x5003, "exif:ResolutionXLengthUnit" },
1018 { 0x5004, "exif:ResolutionYLengthUnit" },
1019 { 0x5005, "exif:PrintFlags" },
1020 { 0x5006, "exif:PrintFlagsVersion" },
1021 { 0x5007, "exif:PrintFlagsCrop" },
1022 { 0x5008, "exif:PrintFlagsBleedWidth" },
1023 { 0x5009, "exif:PrintFlagsBleedWidthScale" },
1024 { 0x500A, "exif:HalftoneLPI" },
1025 { 0x500B, "exif:HalftoneLPIUnit" },
1026 { 0x500C, "exif:HalftoneDegree" },
1027 { 0x500D, "exif:HalftoneShape" },
1028 { 0x500E, "exif:HalftoneMisc" },
1029 { 0x500F, "exif:HalftoneScreen" },
1030 { 0x5010, "exif:JPEGQuality" },
1031 { 0x5011, "exif:GridSize" },
1032 { 0x5012, "exif:ThumbnailFormat" },
1033 { 0x5013, "exif:ThumbnailWidth" },
1034 { 0x5014, "exif:ThumbnailHeight" },
1035 { 0x5015, "exif:ThumbnailColorDepth" },
1036 { 0x5016, "exif:ThumbnailPlanes" },
1037 { 0x5017, "exif:ThumbnailRawBytes" },
1038 { 0x5018, "exif:ThumbnailSize" },
1039 { 0x5019, "exif:ThumbnailCompressedSize" },
1040 { 0x501a, "exif:ColorTransferFunction" },
1041 { 0x501b, "exif:ThumbnailData" },
1042 { 0x5020, "exif:ThumbnailImageWidth" },
1043 { 0x5021, "exif:ThumbnailImageHeight" },
1044 { 0x5022, "exif:ThumbnailBitsPerSample" },
1045 { 0x5023, "exif:ThumbnailCompression" },
1046 { 0x5024, "exif:ThumbnailPhotometricInterp" },
1047 { 0x5025, "exif:ThumbnailImageDescription" },
1048 { 0x5026, "exif:ThumbnailEquipMake" },
1049 { 0x5027, "exif:ThumbnailEquipModel" },
1050 { 0x5028, "exif:ThumbnailStripOffsets" },
1051 { 0x5029, "exif:ThumbnailOrientation" },
1052 { 0x502a, "exif:ThumbnailSamplesPerPixel" },
1053 { 0x502b, "exif:ThumbnailRowsPerStrip" },
1054 { 0x502c, "exif:ThumbnailStripBytesCount" },
1055 { 0x502d, "exif:ThumbnailResolutionX" },
1056 { 0x502e, "exif:ThumbnailResolutionY" },
1057 { 0x502f, "exif:ThumbnailPlanarConfig" },
1058 { 0x5030, "exif:ThumbnailResolutionUnit" },
1059 { 0x5031, "exif:ThumbnailTransferFunction" },
1060 { 0x5032, "exif:ThumbnailSoftwareUsed" },
1061 { 0x5033, "exif:ThumbnailDateTime" },
1062 { 0x5034, "exif:ThumbnailArtist" },
1063 { 0x5035, "exif:ThumbnailWhitePoint" },
1064 { 0x5036, "exif:ThumbnailPrimaryChromaticities" },
1065 { 0x5037, "exif:ThumbnailYCbCrCoefficients" },
1066 { 0x5038, "exif:ThumbnailYCbCrSubsampling" },
1067 { 0x5039, "exif:ThumbnailYCbCrPositioning" },
1068 { 0x503A, "exif:ThumbnailRefBlackWhite" },
1069 { 0x503B, "exif:ThumbnailCopyRight" },
1070 { 0x5090, "exif:LuminanceTable" },
1071 { 0x5091, "exif:ChrominanceTable" },
1072 { 0x5100, "exif:FrameDelay" },
1073 { 0x5101, "exif:LoopCount" },
1074 { 0x5110, "exif:PixelUnit" },
1075 { 0x5111, "exif:PixelPerUnitX" },
1076 { 0x5112, "exif:PixelPerUnitY" },
1077 { 0x5113, "exif:PaletteHistogram" },
1078 { 0x1000, "exif:RelatedImageFileFormat" },
1079 { 0x1001, "exif:RelatedImageLength" },
1080 { 0x1002, "exif:RelatedImageWidth" },
1081 { 0x800d, "exif:ImageID" },
1082 { 0x80e3, "exif:Matteing" },
1083 { 0x80e4, "exif:DataType" },
1084 { 0x80e5, "exif:ImageDepth" },
1085 { 0x80e6, "exif:TileDepth" },
1086 { 0x828d, "exif:CFARepeatPatternDim" },
1087 { 0x828e, "exif:CFAPattern2" },
1088 { 0x828f, "exif:BatteryLevel" },
1089 { 0x8298, "exif:Copyright" },
1090 { 0x829a, "exif:ExposureTime" },
1091 { 0x829d, "exif:FNumber" },
1092 { 0x83bb, "exif:IPTC/NAA" },
1093 { 0x84e3, "exif:IT8RasterPadding" },
1094 { 0x84e5, "exif:IT8ColorTable" },
1095 { 0x8649, "exif:ImageResourceInformation" },
1096 { 0x8769, "exif:ExifOffset" },
1097 { 0x8773, "exif:InterColorProfile" },
1098 { 0x8822, "exif:ExposureProgram" },
1099 { 0x8824, "exif:SpectralSensitivity" },
1100 { 0x8825, "exif:GPSInfo" },
1101 { 0x8827, "exif:ISOSpeedRatings" },
1102 { 0x8828, "exif:OECF" },
1103 { 0x8829, "exif:Interlace" },
1104 { 0x882a, "exif:TimeZoneOffset" },
1105 { 0x882b, "exif:SelfTimerMode" },
1106 { 0x9000, "exif:ExifVersion" },
1107 { 0x9003, "exif:DateTimeOriginal" },
1108 { 0x9004, "exif:DateTimeDigitized" },
1109 { 0x9101, "exif:ComponentsConfiguration" },
1110 { 0x9102, "exif:CompressedBitsPerPixel" },
1111 { 0x9201, "exif:ShutterSpeedValue" },
1112 { 0x9202, "exif:ApertureValue" },
1113 { 0x9203, "exif:BrightnessValue" },
1114 { 0x9204, "exif:ExposureBiasValue" },
1115 { 0x9205, "exif:MaxApertureValue" },
1116 { 0x9206, "exif:SubjectDistance" },
1117 { 0x9207, "exif:MeteringMode" },
1118 { 0x9208, "exif:LightSource" },
1119 { 0x9209, "exif:Flash" },
1120 { 0x920a, "exif:FocalLength" },
1121 { 0x920b, "exif:FlashEnergy" },
1122 { 0x920c, "exif:SpatialFrequencyResponse" },
1123 { 0x920d, "exif:Noise" },
1124 { 0x9211, "exif:ImageNumber" },
1125 { 0x9212, "exif:SecurityClassification" },
1126 { 0x9213, "exif:ImageHistory" },
1127 { 0x9214, "exif:SubjectArea" },
1128 { 0x9215, "exif:ExposureIndex" },
1129 { 0x9216, "exif:TIFF-EPStandardID" },
1130 { 0x927c, "exif:MakerNote" },
1131 { 0x9C9b, "exif:WinXP-Title" },
1132 { 0x9C9c, "exif:WinXP-Comments" },
1133 { 0x9C9d, "exif:WinXP-Author" },
1134 { 0x9C9e, "exif:WinXP-Keywords" },
1135 { 0x9C9f, "exif:WinXP-Subject" },
1136 { 0x9286, "exif:UserComment" },
1137 { 0x9290, "exif:SubSecTime" },
1138 { 0x9291, "exif:SubSecTimeOriginal" },
1139 { 0x9292, "exif:SubSecTimeDigitized" },
1140 { 0xa000, "exif:FlashPixVersion" },
1141 { 0xa001, "exif:ColorSpace" },
1142 { 0xa002, "exif:ExifImageWidth" },
1143 { 0xa003, "exif:ExifImageLength" },
1144 { 0xa004, "exif:RelatedSoundFile" },
1145 { 0xa005, "exif:InteroperabilityOffset" },
1146 { 0xa20b, "exif:FlashEnergy" },
1147 { 0xa20c, "exif:SpatialFrequencyResponse" },
1148 { 0xa20d, "exif:Noise" },
1149 { 0xa20e, "exif:FocalPlaneXResolution" },
1150 { 0xa20f, "exif:FocalPlaneYResolution" },
1151 { 0xa210, "exif:FocalPlaneResolutionUnit" },
1152 { 0xa214, "exif:SubjectLocation" },
1153 { 0xa215, "exif:ExposureIndex" },
1154 { 0xa216, "exif:TIFF/EPStandardID" },
1155 { 0xa217, "exif:SensingMethod" },
1156 { 0xa300, "exif:FileSource" },
1157 { 0xa301, "exif:SceneType" },
1158 { 0xa302, "exif:CFAPattern" },
1159 { 0xa401, "exif:CustomRendered" },
1160 { 0xa402, "exif:ExposureMode" },
1161 { 0xa403, "exif:WhiteBalance" },
1162 { 0xa404, "exif:DigitalZoomRatio" },
1163 { 0xa405, "exif:FocalLengthIn35mmFilm" },
1164 { 0xa406, "exif:SceneCaptureType" },
1165 { 0xa407, "exif:GainControl" },
1166 { 0xa408, "exif:Contrast" },
1167 { 0xa409, "exif:Saturation" },
1168 { 0xa40a, "exif:Sharpness" },
1169 { 0xa40b, "exif:DeviceSettingDescription" },
1170 { 0xa40c, "exif:SubjectDistanceRange" },
1171 { 0xa420, "exif:ImageUniqueID" },
1172 { 0xc4a5, "exif:PrintImageMatching" },
1173 { 0xa500, "exif:Gamma" },
1174 { 0xc640, "exif:CR2Slice" },
1175 { 0x10000, "exif:GPSVersionID" },
1176 { 0x10001, "exif:GPSLatitudeRef" },
1177 { 0x10002, "exif:GPSLatitude" },
1178 { 0x10003, "exif:GPSLongitudeRef" },
1179 { 0x10004, "exif:GPSLongitude" },
1180 { 0x10005, "exif:GPSAltitudeRef" },
1181 { 0x10006, "exif:GPSAltitude" },
1182 { 0x10007, "exif:GPSTimeStamp" },
1183 { 0x10008, "exif:GPSSatellites" },
1184 { 0x10009, "exif:GPSStatus" },
1185 { 0x1000a, "exif:GPSMeasureMode" },
1186 { 0x1000b, "exif:GPSDop" },
1187 { 0x1000c, "exif:GPSSpeedRef" },
1188 { 0x1000d, "exif:GPSSpeed" },
1189 { 0x1000e, "exif:GPSTrackRef" },
1190 { 0x1000f, "exif:GPSTrack" },
1191 { 0x10010, "exif:GPSImgDirectionRef" },
1192 { 0x10011, "exif:GPSImgDirection" },
1193 { 0x10012, "exif:GPSMapDatum" },
1194 { 0x10013, "exif:GPSDestLatitudeRef" },
1195 { 0x10014, "exif:GPSDestLatitude" },
1196 { 0x10015, "exif:GPSDestLongitudeRef" },
1197 { 0x10016, "exif:GPSDestLongitude" },
1198 { 0x10017, "exif:GPSDestBearingRef" },
1199 { 0x10018, "exif:GPSDestBearing" },
1200 { 0x10019, "exif:GPSDestDistanceRef" },
1201 { 0x1001a, "exif:GPSDestDistance" },
1202 { 0x1001b, "exif:GPSProcessingMethod" },
1203 { 0x1001c, "exif:GPSAreaInformation" },
1204 { 0x1001d, "exif:GPSDateStamp" },
1205 { 0x1001e, "exif:GPSDifferential" },
1206 { 0x00000, (const char *) NULL }
1217 directory_stack[MaxDirectoryStack];
1246 tag_bytes[] = {0, 1, 1, 2, 4, 8, 1, 1, 2, 4, 8, 4, 8};
1249 If EXIF data exists, then try to parse the request for a tag.
1251 profile=GetImageProfile(image,"exif");
1252 if (profile == (const StringInfo *) NULL)
1253 return(MagickFalse);
1254 if ((property == (const char *) NULL) || (*property == '\0'))
1255 return(MagickFalse);
1256 while (isspace((int) ((unsigned char) *property)) != 0)
1258 if (strlen(property) <= 5)
1259 return(MagickFalse);
1262 switch (*(property+5))
1267 Caller has asked for all the tags in the EXIF data.
1270 all=1; /* return the data in description=value format */
1276 all=2; /* return the data in tagid=value format */
1289 Check for a hex based tag specification first.
1291 tag=(*(property+5) == '@') ? 1UL : 0UL;
1295 return(MagickFalse);
1297 Parse tag specification as a hex number.
1302 for (i=(ssize_t) n-1L; i >= 0; i--)
1306 if ((c >= '0') && (c <= '9'))
1309 if ((c >= 'A') && (c <= 'F'))
1312 if ((c >= 'a') && (c <= 'f'))
1315 return(MagickFalse);
1317 } while (*property != '\0');
1323 Try to match the text with a tag name instead.
1327 if (EXIFTag[i].tag == 0)
1329 if (LocaleCompare(EXIFTag[i].description,property) == 0)
1331 tag=(size_t) EXIFTag[i].tag;
1339 return(MagickFalse);
1340 length=GetStringInfoLength(profile);
1342 return(MagickFalse);
1343 exif=GetStringInfoDatum(profile);
1346 if (ReadPropertyByte(&exif,&length) != 0x45)
1348 if (ReadPropertyByte(&exif,&length) != 0x78)
1350 if (ReadPropertyByte(&exif,&length) != 0x69)
1352 if (ReadPropertyByte(&exif,&length) != 0x66)
1354 if (ReadPropertyByte(&exif,&length) != 0x00)
1356 if (ReadPropertyByte(&exif,&length) != 0x00)
1361 return(MagickFalse);
1362 id=(ssize_t) ReadPropertySignedShort(LSBEndian,exif);
1370 return(MagickFalse);
1371 if (ReadPropertyUnsignedShort(endian,exif+2) != 0x002a)
1372 return(MagickFalse);
1374 This the offset to the first IFD.
1376 offset=(ssize_t) ReadPropertySignedLong(endian,exif+4);
1377 if ((offset < 0) || (size_t) offset >= length)
1378 return(MagickFalse);
1380 Set the pointer to the first IFD and follow it were it leads.
1383 directory=exif+offset;
1387 exif_resources=NewSplayTree((int (*)(const void *,const void *)) NULL,
1388 (void *(*)(void *)) NULL,(void *(*)(void *)) NULL);
1392 If there is anything on the stack then pop it off.
1397 directory=directory_stack[level].directory;
1398 entry=directory_stack[level].entry;
1399 tag_offset=directory_stack[level].offset;
1401 if ((directory < exif) || (directory > (exif+length-2)))
1404 Determine how many entries there are in the current IFD.
1406 number_entries=(size_t) ReadPropertyUnsignedShort(endian,directory);
1407 for ( ; entry < number_entries; entry++)
1409 register unsigned char
1420 q=(unsigned char *) (directory+(12*entry)+2);
1421 if (q > (exif+length-12))
1422 break; /* corrupt EXIF */
1423 if (GetValueFromSplayTree(exif_resources,q) == q)
1425 (void) AddValueToSplayTree(exif_resources,q,q);
1426 tag_value=(size_t) ReadPropertyUnsignedShort(endian,q)+tag_offset;
1427 format=(size_t) ReadPropertyUnsignedShort(endian,q+2);
1428 if (format >= (sizeof(tag_bytes)/sizeof(*tag_bytes)))
1430 components=(ssize_t) ReadPropertySignedLong(endian,q+4);
1432 break; /* corrupt EXIF */
1433 number_bytes=(size_t) components*tag_bytes[format];
1434 if (number_bytes < components)
1435 break; /* prevent overflow */
1436 if (number_bytes <= 4)
1444 The directory entry contains an offset.
1446 dir_offset=(ssize_t) ReadPropertySignedLong(endian,q+8);
1447 if ((dir_offset < 0) || (size_t) dir_offset >= length)
1449 if ((ssize_t) (dir_offset+number_bytes) < dir_offset)
1450 continue; /* prevent overflow */
1451 if ((size_t) (dir_offset+number_bytes) > length)
1453 p=(unsigned char *) (exif+dir_offset);
1455 if ((all != 0) || (tag == (size_t) tag_value))
1458 buffer[MagickPathExtent],
1461 value=(char *) NULL;
1466 case EXIF_FMT_UNDEFINED:
1468 EXIFMultipleValues(1,"%.20g",(double) (*(unsigned char *) p1));
1471 case EXIF_FMT_SBYTE:
1473 EXIFMultipleValues(1,"%.20g",(double) (*(signed char *) p1));
1476 case EXIF_FMT_SSHORT:
1478 EXIFMultipleValues(2,"%hd",ReadPropertySignedShort(endian,p1));
1481 case EXIF_FMT_USHORT:
1483 EXIFMultipleValues(2,"%hu",ReadPropertyUnsignedShort(endian,p1));
1486 case EXIF_FMT_ULONG:
1488 EXIFMultipleValues(4,"%.20g",(double)
1489 ReadPropertyUnsignedLong(endian,p1));
1492 case EXIF_FMT_SLONG:
1494 EXIFMultipleValues(4,"%.20g",(double)
1495 ReadPropertySignedLong(endian,p1));
1498 case EXIF_FMT_URATIONAL:
1500 EXIFMultipleFractions(8,"%.20g/%.20g",(double)
1501 ReadPropertyUnsignedLong(endian,p1),(double)
1502 ReadPropertyUnsignedLong(endian,p1+4));
1505 case EXIF_FMT_SRATIONAL:
1507 EXIFMultipleFractions(8,"%.20g/%.20g",(double)
1508 ReadPropertySignedLong(endian,p1),(double)
1509 ReadPropertySignedLong(endian,p1+4));
1512 case EXIF_FMT_SINGLE:
1514 EXIFMultipleValues(4,"%f",(double) *(float *) p1);
1517 case EXIF_FMT_DOUBLE:
1519 EXIFMultipleValues(8,"%f",*(double *) p1);
1523 case EXIF_FMT_STRING:
1525 value=(char *) NULL;
1526 if (~((size_t) number_bytes) >= 1)
1527 value=(char *) AcquireQuantumMemory((size_t) number_bytes+1UL,
1529 if (value != (char *) NULL)
1531 for (i=0; i < (ssize_t) number_bytes; i++)
1534 if ((isprint((int) p[i]) != 0) || (p[i] == '\0'))
1535 value[i]=(char) p[i];
1542 if (value != (char *) NULL)
1547 key=AcquireString(property);
1555 description="unknown";
1558 if (EXIFTag[i].tag == 0)
1560 if (EXIFTag[i].tag == tag_value)
1562 description=EXIFTag[i].description;
1566 (void) FormatLocaleString(key,MagickPathExtent,"%s",
1569 (void) SubstituteString(&key,"exif:","exif:thumbnail:");
1574 if (tag_value < 0x10000)
1575 (void) FormatLocaleString(key,MagickPathExtent,"#%04lx",
1576 (unsigned long) tag_value);
1578 if (tag_value < 0x20000)
1579 (void) FormatLocaleString(key,MagickPathExtent,"@%04lx",
1580 (unsigned long) (tag_value & 0xffff));
1582 (void) FormatLocaleString(key,MagickPathExtent,"unknown");
1588 (void) SubstituteString(&key,"exif:","exif:thumbnail:");
1591 if ((image->properties == (void *) NULL) ||
1592 (GetValueFromSplayTree((SplayTreeInfo *) image->properties,
1593 key) == (const void *) NULL))
1594 (void) SetImageProperty((Image *) image,key,value,exception);
1595 value=DestroyString(value);
1596 key=DestroyString(key);
1600 if ((tag_value == TAG_EXIF_OFFSET) ||
1601 (tag_value == TAG_INTEROP_OFFSET) || (tag_value == TAG_GPS_OFFSET))
1606 tag_offset1=(ssize_t) ReadPropertySignedLong(endian,p);
1607 if (((size_t) tag_offset1 < length) &&
1608 (level < (MaxDirectoryStack-2)))
1613 tag_offset2=(ssize_t) ((tag_value == TAG_GPS_OFFSET) ? 0x10000 :
1615 directory_stack[level].directory=directory;
1617 directory_stack[level].entry=entry;
1618 directory_stack[level].offset=tag_offset;
1620 directory_stack[level].directory=exif+tag_offset1;
1621 directory_stack[level].offset=tag_offset2;
1622 directory_stack[level].entry=0;
1624 if ((directory+2+(12*number_entries)) > (exif+length))
1626 tag_offset1=(ssize_t) ReadPropertySignedLong(endian,directory+
1627 2+(12*number_entries));
1628 if ((tag_offset1 != 0) && ((size_t) tag_offset1 < length) &&
1629 (level < (MaxDirectoryStack-2)))
1631 directory_stack[level].directory=exif+tag_offset1;
1632 directory_stack[level].entry=0;
1633 directory_stack[level].offset=tag_offset2;
1640 } while (level > 0);
1641 exif_resources=DestroySplayTree(exif_resources);
1645 static MagickBooleanType GetICCProperty(const Image *image,const char *property,
1646 ExceptionInfo *exception)
1651 magick_unreferenced(property);
1653 profile=GetImageProfile(image,"icc");
1654 if (profile == (StringInfo *) NULL)
1655 profile=GetImageProfile(image,"icm");
1656 if (profile == (StringInfo *) NULL)
1657 return(MagickFalse);
1658 if (GetStringInfoLength(profile) < 128)
1659 return(MagickFalse); /* minimum ICC profile length */
1660 #if defined(MAGICKCORE_LCMS_DELEGATE)
1665 icc_profile=cmsOpenProfileFromMem(GetStringInfoDatum(profile),
1666 (cmsUInt32Number) GetStringInfoLength(profile));
1667 if (icc_profile != (cmsHPROFILE *) NULL)
1669 #if defined(LCMS_VERSION) && (LCMS_VERSION < 2000)
1673 name=cmsTakeProductName(icc_profile);
1674 if (name != (const char *) NULL)
1675 (void) SetImageProperty((Image *) image,"icc:name",name,exception);
1678 info[MagickPathExtent];
1683 (void) memset(info,0,sizeof(info));
1684 extent=cmsGetProfileInfoASCII(icc_profile,cmsInfoDescription,"en","US",
1688 extent=cmsGetProfileInfoASCII(icc_profile,cmsInfoDescription,"en",
1689 "US",info,MagickMin(MagickPathExtent-1,extent));
1690 (void) SetImageProperty((Image *) image,"icc:description",info,
1693 extent=cmsGetProfileInfoASCII(icc_profile,cmsInfoManufacturer,"en","US",
1697 extent=cmsGetProfileInfoASCII(icc_profile,cmsInfoManufacturer,"en",
1698 "US",info,MagickMin(MagickPathExtent-1,extent));
1699 (void) SetImageProperty((Image *) image,"icc:manufacturer",info,
1702 extent=cmsGetProfileInfoASCII(icc_profile,cmsInfoModel,"en","US",
1706 extent=cmsGetProfileInfoASCII(icc_profile,cmsInfoModel,"en","US",
1707 info,MagickMin(MagickPathExtent-1,extent));
1708 (void) SetImageProperty((Image *) image,"icc:model",info,exception);
1710 extent=cmsGetProfileInfoASCII(icc_profile,cmsInfoCopyright,"en","US",
1714 extent=cmsGetProfileInfoASCII(icc_profile,cmsInfoCopyright,"en",
1715 "US",info,MagickMin(MagickPathExtent-1,extent));
1716 (void) SetImageProperty((Image *) image,"icc:copyright",info,
1720 (void) cmsCloseProfile(icc_profile);
1727 static MagickBooleanType SkipXMPValue(const char *value)
1729 if (value == (const char*) NULL)
1731 while (*value != '\0')
1733 if (isspace((int) ((unsigned char) *value)) == 0)
1734 return(MagickFalse);
1740 static MagickBooleanType ValidateXMPProfile(const char *profile,
1741 const size_t length)
1743 #if defined(MAGICKCORE_XML_DELEGATE)
1751 document=xmlReadMemory(profile,(int) length,"xmp.xml",NULL,
1752 XML_PARSE_NOERROR | XML_PARSE_NOWARNING);
1753 if (document == (xmlDocPtr) NULL)
1754 return(MagickFalse);
1755 xmlFreeDoc(document);
1759 return(MagickFalse);
1763 static MagickBooleanType GetXMPProperty(const Image *image,const char *property)
1790 profile=GetImageProfile(image,"xmp");
1791 if (profile == (StringInfo *) NULL)
1792 return(MagickFalse);
1793 if (GetStringInfoLength(profile) < 17)
1794 return(MagickFalse);
1795 if ((property == (const char *) NULL) || (*property == '\0'))
1796 return(MagickFalse);
1797 xmp_profile=StringInfoToString(profile);
1798 if (xmp_profile == (char *) NULL)
1799 return(MagickFalse);
1800 if (ValidateXMPProfile(xmp_profile,GetStringInfoLength(profile)) == MagickFalse)
1802 xmp_profile=DestroyString(xmp_profile);
1803 return(MagickFalse);
1805 for (p=xmp_profile; *p != '\0'; p++)
1806 if ((*p == '<') && (*(p+1) == 'x'))
1808 exception=AcquireExceptionInfo();
1809 xmp=NewXMLTree((char *) p,exception);
1810 xmp_profile=DestroyString(xmp_profile);
1811 exception=DestroyExceptionInfo(exception);
1812 if (xmp == (XMLTreeInfo *) NULL)
1813 return(MagickFalse);
1815 rdf=GetXMLTreeChild(xmp,"rdf:RDF");
1816 if (rdf != (XMLTreeInfo *) NULL)
1818 if (image->properties == (void *) NULL)
1819 ((Image *) image)->properties=NewSplayTree(CompareSplayTreeString,
1820 RelinquishMagickMemory,RelinquishMagickMemory);
1821 description=GetXMLTreeChild(rdf,"rdf:Description");
1822 while (description != (XMLTreeInfo *) NULL)
1827 node=GetXMLTreeChild(description,(const char *) NULL);
1828 while (node != (XMLTreeInfo *) NULL)
1830 child=GetXMLTreeChild(node,(const char *) NULL);
1831 content=GetXMLTreeContent(node);
1832 if ((child == (XMLTreeInfo *) NULL) &&
1833 (SkipXMPValue(content) == MagickFalse))
1835 xmp_namespace=ConstantString(GetXMLTreeTag(node));
1836 (void) SubstituteString(&xmp_namespace,"exif:","xmp:");
1837 (void) AddValueToSplayTree((SplayTreeInfo *) image->properties,
1838 xmp_namespace,ConstantString(content));
1840 while (child != (XMLTreeInfo *) NULL)
1842 content=GetXMLTreeContent(child);
1843 if (SkipXMPValue(content) == MagickFalse)
1845 xmp_namespace=ConstantString(GetXMLTreeTag(node));
1846 (void) SubstituteString(&xmp_namespace,"exif:","xmp:");
1847 (void) AddValueToSplayTree((SplayTreeInfo *) image->properties,
1848 xmp_namespace,ConstantString(content));
1850 child=GetXMLTreeSibling(child);
1852 node=GetXMLTreeSibling(node);
1854 description=GetNextXMLTreeTag(description);
1857 xmp=DestroyXMLTree(xmp);
1861 static char *TracePSClippath(const unsigned char *blob,size_t length)
1884 path=AcquireString((char *) NULL);
1885 if (path == (char *) NULL)
1886 return((char *) NULL);
1887 message=AcquireString((char *) NULL);
1888 (void) FormatLocaleString(message,MagickPathExtent,"/ClipImage\n");
1889 (void) ConcatenateString(&path,message);
1890 (void) FormatLocaleString(message,MagickPathExtent,"{\n");
1891 (void) ConcatenateString(&path,message);
1892 (void) FormatLocaleString(message,MagickPathExtent,
1893 " /c {curveto} bind def\n");
1894 (void) ConcatenateString(&path,message);
1895 (void) FormatLocaleString(message,MagickPathExtent,
1896 " /l {lineto} bind def\n");
1897 (void) ConcatenateString(&path,message);
1898 (void) FormatLocaleString(message,MagickPathExtent,
1899 " /m {moveto} bind def\n");
1900 (void) ConcatenateString(&path,message);
1901 (void) FormatLocaleString(message,MagickPathExtent,
1902 " /v {currentpoint 6 2 roll curveto} bind def\n");
1903 (void) ConcatenateString(&path,message);
1904 (void) FormatLocaleString(message,MagickPathExtent,
1905 " /y {2 copy curveto} bind def\n");
1906 (void) ConcatenateString(&path,message);
1907 (void) FormatLocaleString(message,MagickPathExtent,
1908 " /z {closepath} bind def\n");
1909 (void) ConcatenateString(&path,message);
1910 (void) FormatLocaleString(message,MagickPathExtent," newpath\n");
1911 (void) ConcatenateString(&path,message);
1913 The clipping path format is defined in "Adobe Photoshop File Formats
1914 Specification" version 6.0 downloadable from adobe.com.
1916 (void) memset(point,0,sizeof(point));
1917 (void) memset(first,0,sizeof(first));
1918 (void) memset(last,0,sizeof(last));
1920 in_subpath=MagickFalse;
1923 selector=(ssize_t) ReadPropertyMSBShort(&blob,&length);
1929 if (knot_count != 0)
1932 length-=MagickMin(24,(ssize_t) length);
1936 Expected subpath length record.
1938 knot_count=(ssize_t) ReadPropertyMSBShort(&blob,&length);
1940 length-=MagickMin(22,(ssize_t) length);
1948 if (knot_count == 0)
1951 Unexpected subpath knot
1954 length-=MagickMin(24,(ssize_t) length);
1960 for (i=0; i < 3; i++)
1966 yy=(size_t) ReadPropertyMSBLong(&blob,&length);
1967 xx=(size_t) ReadPropertyMSBLong(&blob,&length);
1969 if (xx > 2147483647)
1970 x=(ssize_t) xx-4294967295U-1;
1972 if (yy > 2147483647)
1973 y=(ssize_t) yy-4294967295U-1;
1974 point[i].x=(double) x/4096/4096;
1975 point[i].y=1.0-(double) y/4096/4096;
1977 if (in_subpath == MagickFalse)
1979 (void) FormatLocaleString(message,MagickPathExtent," %g %g m\n",
1980 point[1].x,point[1].y);
1981 for (i=0; i < 3; i++)
1990 Handle special cases when Bezier curves are used to describe
1991 corners and straight lines.
1993 if ((last[1].x == last[2].x) && (last[1].y == last[2].y) &&
1994 (point[0].x == point[1].x) && (point[0].y == point[1].y))
1995 (void) FormatLocaleString(message,MagickPathExtent,
1996 " %g %g l\n",point[1].x,point[1].y);
1998 if ((last[1].x == last[2].x) && (last[1].y == last[2].y))
1999 (void) FormatLocaleString(message,MagickPathExtent,
2000 " %g %g %g %g v\n",point[0].x,point[0].y,
2001 point[1].x,point[1].y);
2003 if ((point[0].x == point[1].x) && (point[0].y == point[1].y))
2004 (void) FormatLocaleString(message,MagickPathExtent,
2005 " %g %g %g %g y\n",last[2].x,last[2].y,
2006 point[1].x,point[1].y);
2008 (void) FormatLocaleString(message,MagickPathExtent,
2009 " %g %g %g %g %g %g c\n",last[2].x,
2010 last[2].y,point[0].x,point[0].y,point[1].x,point[1].y);
2011 for (i=0; i < 3; i++)
2014 (void) ConcatenateString(&path,message);
2015 in_subpath=MagickTrue;
2018 Close the subpath if there are no more knots.
2020 if (knot_count == 0)
2023 Same special handling as above except we compare to the
2024 first point in the path and close the path.
2026 if ((last[1].x == last[2].x) && (last[1].y == last[2].y) &&
2027 (first[0].x == first[1].x) && (first[0].y == first[1].y))
2028 (void) FormatLocaleString(message,MagickPathExtent,
2029 " %g %g l z\n",first[1].x,first[1].y);
2031 if ((last[1].x == last[2].x) && (last[1].y == last[2].y))
2032 (void) FormatLocaleString(message,MagickPathExtent,
2033 " %g %g %g %g v z\n",first[0].x,first[0].y,
2034 first[1].x,first[1].y);
2036 if ((first[0].x == first[1].x) && (first[0].y == first[1].y))
2037 (void) FormatLocaleString(message,MagickPathExtent,
2038 " %g %g %g %g y z\n",last[2].x,last[2].y,
2039 first[1].x,first[1].y);
2041 (void) FormatLocaleString(message,MagickPathExtent,
2042 " %g %g %g %g %g %g c z\n",last[2].x,
2043 last[2].y,first[0].x,first[0].y,first[1].x,first[1].y);
2044 (void) ConcatenateString(&path,message);
2045 in_subpath=MagickFalse;
2055 length-=MagickMin(24,(ssize_t) length);
2061 Returns an empty PS path if the path has no knots.
2063 (void) FormatLocaleString(message,MagickPathExtent," eoclip\n");
2064 (void) ConcatenateString(&path,message);
2065 (void) FormatLocaleString(message,MagickPathExtent,"} bind def");
2066 (void) ConcatenateString(&path,message);
2067 message=DestroyString(message);
2071 static char *TraceSVGClippath(const unsigned char *blob,size_t length,
2072 const size_t columns,const size_t rows)
2095 path=AcquireString((char *) NULL);
2096 if (path == (char *) NULL)
2097 return((char *) NULL);
2098 message=AcquireString((char *) NULL);
2099 (void) FormatLocaleString(message,MagickPathExtent,(
2100 "<?xml version=\"1.0\" encoding=\"iso-8859-1\"?>\n"
2101 "<svg xmlns=\"http://www.w3.org/2000/svg\""
2102 " width=\"%.20g\" height=\"%.20g\">\n"
2104 "<path fill-rule=\"evenodd\" style=\"fill:#000000;stroke:#000000;"
2105 "stroke-width:0;stroke-antialiasing:false\" d=\"\n"),(double) columns,
2107 (void) ConcatenateString(&path,message);
2108 (void) memset(point,0,sizeof(point));
2109 (void) memset(first,0,sizeof(first));
2110 (void) memset(last,0,sizeof(last));
2112 in_subpath=MagickFalse;
2115 selector=(ssize_t) ReadPropertyMSBShort(&blob,&length);
2121 if (knot_count != 0)
2124 length-=MagickMin(24,(ssize_t) length);
2128 Expected subpath length record.
2130 knot_count=(ssize_t) ReadPropertyMSBShort(&blob,&length);
2132 length-=MagickMin(22,(ssize_t) length);
2140 if (knot_count == 0)
2143 Unexpected subpath knot.
2146 length-=MagickMin(24,(ssize_t) length);
2152 for (i=0; i < 3; i++)
2158 yy=(unsigned int) ReadPropertyMSBLong(&blob,&length);
2159 xx=(unsigned int) ReadPropertyMSBLong(&blob,&length);
2161 if (xx > 2147483647)
2162 x=(ssize_t) xx-4294967295U-1;
2164 if (yy > 2147483647)
2165 y=(ssize_t) yy-4294967295U-1;
2166 point[i].x=(double) x*columns/4096/4096;
2167 point[i].y=(double) y*rows/4096/4096;
2169 if (in_subpath == MagickFalse)
2171 (void) FormatLocaleString(message,MagickPathExtent,"M %g %g\n",
2172 point[1].x,point[1].y);
2173 for (i=0; i < 3; i++)
2182 Handle special cases when Bezier curves are used to describe
2183 corners and straight lines.
2185 if (((last[1].x == last[2].x) || (last[1].y == last[2].y)) &&
2186 (point[0].x == point[1].x) && (point[0].y == point[1].y))
2187 (void) FormatLocaleString(message,MagickPathExtent,
2188 "L %g %g\n",point[1].x,point[1].y);
2190 (void) FormatLocaleString(message,MagickPathExtent,
2191 "C %g %g %g %g %g %g\n",last[2].x,last[2].y,point[0].x,
2192 point[0].y,point[1].x,point[1].y);
2193 for (i=0; i < 3; i++)
2196 (void) ConcatenateString(&path,message);
2197 in_subpath=MagickTrue;
2200 Close the subpath if there are no more knots.
2202 if (knot_count == 0)
2205 Same special handling as above except we compare to the
2206 first point in the path and close the path.
2208 if (((last[1].x == last[2].x) || (last[1].y == last[2].y)) &&
2209 (first[0].x == first[1].x) && (first[0].y == first[1].y))
2210 (void) FormatLocaleString(message,MagickPathExtent,
2211 "L %g %g Z\n",first[1].x,first[1].y);
2213 (void) FormatLocaleString(message,MagickPathExtent,
2214 "C %g %g %g %g %g %g Z\n",last[2].x,last[2].y,first[0].x,
2215 first[0].y,first[1].x,first[1].y);
2216 (void) ConcatenateString(&path,message);
2217 in_subpath=MagickFalse;
2227 length-=MagickMin(24,(ssize_t) length);
2233 Return an empty SVG image if the path does not have knots.
2235 (void) ConcatenateString(&path,"\"/>\n</g>\n</svg>\n");
2236 message=DestroyString(message);
2240 MagickExport const char *GetImageProperty(const Image *image,
2241 const char *property,ExceptionInfo *exception)
2246 assert(image != (Image *) NULL);
2247 assert(image->signature == MagickCoreSignature);
2248 if (image->debug != MagickFalse)
2249 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
2250 p=(const char *) NULL;
2251 if (image->properties != (void *) NULL)
2253 if (property == (const char *) NULL)
2254 return((const char *) GetRootValueFromSplayTree((SplayTreeInfo *)
2255 image->properties));
2256 p=(const char *) GetValueFromSplayTree((SplayTreeInfo *)
2257 image->properties,property);
2258 if (p != (const char *) NULL)
2261 if ((property == (const char *) NULL) ||
2262 (strchr(property,':') == (char *) NULL))
2268 if (LocaleNCompare("8bim:",property,5) == 0)
2270 (void) Get8BIMProperty(image,property,exception);
2278 if (LocaleNCompare("exif:",property,5) == 0)
2280 (void) GetEXIFProperty(image,property,exception);
2288 if ((LocaleNCompare("icc:",property,4) == 0) ||
2289 (LocaleNCompare("icm:",property,4) == 0))
2291 (void) GetICCProperty(image,property,exception);
2294 if (LocaleNCompare("iptc:",property,5) == 0)
2296 (void) GetIPTCProperty(image,property,exception);
2304 if (LocaleNCompare("xmp:",property,4) == 0)
2306 (void) GetXMPProperty(image,property);
2314 if (image->properties != (void *) NULL)
2316 p=(const char *) GetValueFromSplayTree((SplayTreeInfo *)
2317 image->properties,property);
2320 return((const char *) NULL);
2324 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2328 + G e t M a g i c k P r o p e r t y %
2332 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2334 % GetMagickProperty() gets attributes or calculated values that is associated
2335 % with a fixed known property name, or single letter property. It may be
2336 % called if no image is defined (IMv7), in which case only global image_info
2337 % values are available:
2340 % \r carriage return
2341 % < less-than character.
2342 % > greater-than character.
2343 % & ampersand character.
2345 % %b file size of image read in
2346 % %c comment meta-data property
2347 % %d directory component of path
2348 % %e filename extension or suffix
2349 % %f filename (including suffix)
2350 % %g layer canvas page geometry (equivalent to "%Wx%H%X%Y")
2351 % %h current image height in pixels
2352 % %i image filename (note: becomes output filename for "info:")
2353 % %k CALCULATED: number of unique colors
2354 % %l label meta-data property
2355 % %m image file format (file magic)
2356 % %n number of images in current image sequence
2357 % %o output filename (used for delegates)
2358 % %p index of image in current image list
2359 % %q quantum depth (compile-time constant)
2360 % %r image class and colorspace
2361 % %s scene number (from input unless re-assigned)
2362 % %t filename without directory or extension (suffix)
2363 % %u unique temporary filename (used for delegates)
2364 % %w current width in pixels
2365 % %x x resolution (density)
2366 % %y y resolution (density)
2367 % %z image depth (as read in unless modified, image save depth)
2368 % %A image transparency channel enabled (true/false)
2369 % %B file size of image in bytes
2370 % %C image compression type
2371 % %D image GIF dispose method
2372 % %G original image size (%wx%h; before any resizes)
2373 % %H page (canvas) height
2374 % %M Magick filename (original file exactly as given, including read mods)
2375 % %O page (canvas) offset ( = %X%Y )
2376 % %P page (canvas) size ( = %Wx%H )
2377 % %Q image compression quality ( 0 = default )
2379 % %T image time delay (in centi-seconds)
2380 % %U image resolution units
2381 % %W page (canvas) width
2382 % %X page (canvas) x offset (including sign)
2383 % %Y page (canvas) y offset (including sign)
2384 % %Z unique filename (used for delegates)
2385 % %@ CALCULATED: trim bounding box (without actually trimming)
2386 % %# CALCULATED: 'signature' hash of image values
2388 % This routine only handles specifically known properties. It does not
2389 % handle special prefixed properties, profiles, or expressions. Nor does
2390 % it return any free-form property strings.
2392 % The returned string is stored in a structure somewhere, and should not be
2393 % directly freed. If the string was generated (common) the string will be
2394 % stored as as either as artifact or option 'get-property'. These may be
2395 % deleted (cleaned up) when no longer required, but neither artifact or
2396 % option is guranteed to exist.
2398 % The format of the GetMagickProperty method is:
2400 % const char *GetMagickProperty(ImageInfo *image_info,Image *image,
2401 % const char *property,ExceptionInfo *exception)
2403 % A description of each parameter follows:
2405 % o image_info: the image info (optional)
2407 % o image: the image (optional)
2411 % o exception: return any errors or warnings in this structure.
2414 static const char *GetMagickPropertyLetter(ImageInfo *image_info,
2415 Image *image,const char letter,ExceptionInfo *exception)
2417 #define WarnNoImageReturn(format,arg) \
2418 if (image == (Image *) NULL ) { \
2419 (void) ThrowMagickException(exception,GetMagickModule(),OptionWarning, \
2420 "NoImageForProperty",format,arg); \
2421 return((const char *) NULL); \
2423 #define WarnNoImageInfoReturn(format,arg) \
2424 if (image_info == (ImageInfo *) NULL ) { \
2425 (void) ThrowMagickException(exception,GetMagickModule(),OptionWarning, \
2426 "NoImageInfoForProperty",format,arg); \
2427 return((const char *) NULL); \
2431 value[MagickPathExtent]; /* formatted string to store as an artifact */
2434 *string; /* return a string already stored somewher */
2436 if ((image != (Image *) NULL) && (image->debug != MagickFalse))
2437 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
2439 if ((image_info != (ImageInfo *) NULL) &&
2440 (image_info->debug != MagickFalse))
2441 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s","no-images");
2442 *value='\0'; /* formatted string */
2443 string=(char *) NULL; /* constant string reference */
2445 Get properities that are directly defined by images.
2449 case 'b': /* image size read in - in bytes */
2451 WarnNoImageReturn("\"%%%c\"",letter);
2452 (void) FormatMagickSize(image->extent,MagickFalse,"B",MagickPathExtent,
2454 if (image->extent == 0)
2455 (void) FormatMagickSize(GetBlobSize(image),MagickFalse,"B",
2456 MagickPathExtent,value);
2459 case 'c': /* image comment property - empty string by default */
2461 WarnNoImageReturn("\"%%%c\"",letter);
2462 string=GetImageProperty(image,"comment",exception);
2463 if ( string == (const char *) NULL )
2467 case 'd': /* Directory component of filename */
2469 WarnNoImageReturn("\"%%%c\"",letter);
2470 GetPathComponent(image->magick_filename,HeadPath,value);
2475 case 'e': /* Filename extension (suffix) of image file */
2477 WarnNoImageReturn("\"%%%c\"",letter);
2478 GetPathComponent(image->magick_filename,ExtensionPath,value);
2483 case 'f': /* Filename without directory component */
2485 WarnNoImageReturn("\"%%%c\"",letter);
2486 GetPathComponent(image->magick_filename,TailPath,value);
2491 case 'g': /* Image geometry, canvas and offset %Wx%H+%X+%Y */
2493 WarnNoImageReturn("\"%%%c\"",letter);
2494 (void) FormatLocaleString(value,MagickPathExtent,
2495 "%.20gx%.20g%+.20g%+.20g",(double) image->page.width,(double)
2496 image->page.height,(double) image->page.x,(double) image->page.y);
2499 case 'h': /* Image height (current) */
2501 WarnNoImageReturn("\"%%%c\"",letter);
2502 (void) FormatLocaleString(value,MagickPathExtent,"%.20g",(double)
2503 (image->rows != 0 ? image->rows : image->magick_rows));
2506 case 'i': /* Filename last used for an image (read or write) */
2508 WarnNoImageReturn("\"%%%c\"",letter);
2509 string=image->filename;
2512 case 'k': /* Number of unique colors */
2515 FUTURE: ensure this does not generate the formatted comment!
2517 WarnNoImageReturn("\"%%%c\"",letter);
2518 (void) FormatLocaleString(value,MagickPathExtent,"%.20g",(double)
2519 GetNumberColors(image,(FILE *) NULL,exception));
2522 case 'l': /* Image label property - empty string by default */
2524 WarnNoImageReturn("\"%%%c\"",letter);
2525 string=GetImageProperty(image,"label",exception);
2526 if (string == (const char *) NULL)
2530 case 'm': /* Image format (file magick) */
2532 WarnNoImageReturn("\"%%%c\"",letter);
2533 string=image->magick;
2536 case 'n': /* Number of images in the list. */
2538 if ( image != (Image *) NULL )
2539 (void) FormatLocaleString(value,MagickPathExtent,"%.20g",(double)
2540 GetImageListLength(image));
2542 string="0"; /* no images or scenes */
2545 case 'o': /* Output Filename - for delegate use only */
2546 WarnNoImageInfoReturn("\"%%%c\"",letter);
2547 string=image_info->filename;
2549 case 'p': /* Image index in current image list */
2551 WarnNoImageReturn("\"%%%c\"",letter);
2552 (void) FormatLocaleString(value,MagickPathExtent,"%.20g",(double)
2553 GetImageIndexInList(image));
2556 case 'q': /* Quantum depth of image in memory */
2558 WarnNoImageReturn("\"%%%c\"",letter);
2559 (void) FormatLocaleString(value,MagickPathExtent,"%.20g",(double)
2560 MAGICKCORE_QUANTUM_DEPTH);
2563 case 'r': /* Image storage class, colorspace, and alpha enabled. */
2568 WarnNoImageReturn("\"%%%c\"",letter);
2569 colorspace=image->colorspace;
2570 if ((image->columns != 0) && (image->rows != 0) &&
2571 (SetImageGray(image,exception) != MagickFalse))
2572 colorspace=GRAYColorspace; /* FUTURE: this is IMv6 not IMv7 */
2573 (void) FormatLocaleString(value,MagickPathExtent,"%s %s %s",
2574 CommandOptionToMnemonic(MagickClassOptions,(ssize_t)
2575 image->storage_class),CommandOptionToMnemonic(MagickColorspaceOptions,
2576 (ssize_t) colorspace),image->alpha_trait != UndefinedPixelTrait ?
2580 case 's': /* Image scene number */
2582 #if 0 /* this seems non-sensical -- simplifing */
2583 if (image_info->number_scenes != 0)
2584 (void) FormatLocaleString(value,MagickPathExtent,"%.20g",(double)
2586 else if (image != (Image *) NULL)
2587 (void) FormatLocaleString(value,MagickPathExtent,"%.20g",(double)
2592 WarnNoImageReturn("\"%%%c\"",letter);
2593 (void) FormatLocaleString(value,MagickPathExtent,"%.20g",(double)
2598 case 't': /* Base filename without directory or extention */
2600 WarnNoImageReturn("\"%%%c\"",letter);
2601 GetPathComponent(image->magick_filename,BasePath,value);
2606 case 'u': /* Unique filename */
2608 WarnNoImageInfoReturn("\"%%%c\"",letter);
2609 string=image_info->unique;
2612 case 'w': /* Image width (current) */
2614 WarnNoImageReturn("\"%%%c\"",letter);
2615 (void) FormatLocaleString(value,MagickPathExtent,"%.20g",(double)
2616 (image->columns != 0 ? image->columns : image->magick_columns));
2619 case 'x': /* Image horizontal resolution (with units) */
2621 WarnNoImageReturn("\"%%%c\"",letter);
2622 (void) FormatLocaleString(value,MagickPathExtent,"%.20g",
2623 fabs(image->resolution.x) > MagickEpsilon ? image->resolution.x : 72.0);
2626 case 'y': /* Image vertical resolution (with units) */
2628 WarnNoImageReturn("\"%%%c\"",letter);
2629 (void) FormatLocaleString(value,MagickPathExtent,"%.20g",
2630 fabs(image->resolution.y) > MagickEpsilon ? image->resolution.y : 72.0);
2633 case 'z': /* Image depth as read in */
2635 WarnNoImageReturn("\"%%%c\"",letter);
2636 (void) FormatLocaleString(value,MagickPathExtent,"%.20g",(double)
2640 case 'A': /* Image alpha channel */
2642 WarnNoImageReturn("\"%%%c\"",letter);
2643 string=CommandOptionToMnemonic(MagickPixelTraitOptions,(ssize_t)
2644 image->alpha_trait);
2647 case 'B': /* image size read in - in bytes */
2649 WarnNoImageReturn("\"%%%c\"",letter);
2650 (void) FormatLocaleString(value,MagickPathExtent,"%.20g",(double)
2652 if (image->extent == 0)
2653 (void) FormatLocaleString(value,MagickPathExtent,"%.20g",(double)
2654 GetBlobSize(image));
2657 case 'C': /* Image compression method. */
2659 WarnNoImageReturn("\"%%%c\"",letter);
2660 string=CommandOptionToMnemonic(MagickCompressOptions,(ssize_t)
2661 image->compression);
2664 case 'D': /* Image dispose method. */
2666 WarnNoImageReturn("\"%%%c\"",letter);
2667 string=CommandOptionToMnemonic(MagickDisposeOptions,(ssize_t)
2671 case 'G': /* Image size as geometry = "%wx%h" */
2673 WarnNoImageReturn("\"%%%c\"",letter);
2674 (void) FormatLocaleString(value,MagickPathExtent,"%.20gx%.20g",(double)
2675 image->magick_columns,(double) image->magick_rows);
2678 case 'H': /* layer canvas height */
2680 WarnNoImageReturn("\"%%%c\"",letter);
2681 (void) FormatLocaleString(value,MagickPathExtent,"%.20g",(double)
2682 image->page.height);
2685 case 'M': /* Magick filename - filename given incl. coder & read mods */
2687 WarnNoImageReturn("\"%%%c\"",letter);
2688 string=image->magick_filename;
2691 case 'O': /* layer canvas offset with sign = "+%X+%Y" */
2693 WarnNoImageReturn("\"%%%c\"",letter);
2694 (void) FormatLocaleString(value,MagickPathExtent,"%+ld%+ld",(long)
2695 image->page.x,(long) image->page.y);
2698 case 'P': /* layer canvas page size = "%Wx%H" */
2700 WarnNoImageReturn("\"%%%c\"",letter);
2701 (void) FormatLocaleString(value,MagickPathExtent,"%.20gx%.20g",(double)
2702 image->page.width,(double) image->page.height);
2705 case 'Q': /* image compression quality */
2707 WarnNoImageReturn("\"%%%c\"",letter);
2708 (void) FormatLocaleString(value,MagickPathExtent,"%.20g",(double)
2709 (image->quality == 0 ? 92 : image->quality));
2712 case 'S': /* Number of scenes in image list. */
2714 WarnNoImageInfoReturn("\"%%%c\"",letter);
2715 #if 0 /* What is this number? -- it makes no sense - simplifing */
2716 if (image_info->number_scenes == 0)
2717 string="2147483647";
2718 else if ( image != (Image *) NULL )
2719 (void) FormatLocaleString(value,MagickPathExtent,"%.20g",(double)
2720 image_info->scene+image_info->number_scenes);
2724 (void) FormatLocaleString(value,MagickPathExtent,"%.20g",(double)
2725 (image_info->number_scenes == 0 ? 2147483647 :
2726 image_info->number_scenes));
2730 case 'T': /* image time delay for animations */
2732 WarnNoImageReturn("\"%%%c\"",letter);
2733 (void) FormatLocaleString(value,MagickPathExtent,"%.20g",(double)
2737 case 'U': /* Image resolution units. */
2739 WarnNoImageReturn("\"%%%c\"",letter);
2740 string=CommandOptionToMnemonic(MagickResolutionOptions,(ssize_t)
2744 case 'W': /* layer canvas width */
2746 WarnNoImageReturn("\"%%%c\"",letter);
2747 (void) FormatLocaleString(value,MagickPathExtent,"%.20g",(double)
2751 case 'X': /* layer canvas X offset */
2753 WarnNoImageReturn("\"%%%c\"",letter);
2754 (void) FormatLocaleString(value,MagickPathExtent,"%+.20g",(double)
2758 case 'Y': /* layer canvas Y offset */
2760 WarnNoImageReturn("\"%%%c\"",letter);
2761 (void) FormatLocaleString(value,MagickPathExtent,"%+.20g",(double)
2765 case '%': /* percent escaped */
2770 case '@': /* Trim bounding box, without actually Trimming! */
2775 WarnNoImageReturn("\"%%%c\"",letter);
2776 page=GetImageBoundingBox(image,exception);
2777 (void) FormatLocaleString(value,MagickPathExtent,
2778 "%.20gx%.20g%+.20g%+.20g",(double) page.width,(double) page.height,
2779 (double) page.x,(double)page.y);
2787 WarnNoImageReturn("\"%%%c\"",letter);
2788 if ((image->columns != 0) && (image->rows != 0))
2789 (void) SignatureImage(image,exception);
2790 string=GetImageProperty(image,"signature",exception);
2794 if (string != (char *) NULL)
2799 Create a cloned copy of result.
2801 if (image != (Image *) NULL)
2803 (void) SetImageArtifact(image,"get-property",value);
2804 return(GetImageArtifact(image,"get-property"));
2808 (void) SetImageOption(image_info,"get-property",value);
2809 return(GetImageOption(image_info,"get-property"));
2812 return((char *) NULL);
2815 MagickExport const char *GetMagickProperty(ImageInfo *image_info,
2816 Image *image,const char *property,ExceptionInfo *exception)
2819 value[MagickPathExtent];
2824 assert(property[0] != '\0');
2825 assert(image != (Image *) NULL || image_info != (ImageInfo *) NULL );
2826 if (property[1] == '\0') /* single letter property request */
2827 return(GetMagickPropertyLetter(image_info,image,*property,exception));
2828 if ((image != (Image *) NULL) && (image->debug != MagickFalse))
2829 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
2831 if ((image_info != (ImageInfo *) NULL) &&
2832 (image_info->debug != MagickFalse))
2833 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s","no-images");
2834 *value='\0'; /* formated string */
2835 string=(char *) NULL; /* constant string reference */
2840 if (LocaleCompare("basename",property) == 0)
2842 WarnNoImageReturn("\"%%[%s]\"",property);
2843 GetPathComponent(image->magick_filename,BasePath,value);
2848 if (LocaleCompare("bit-depth",property) == 0)
2850 WarnNoImageReturn("\"%%[%s]\"",property);
2851 (void) FormatLocaleString(value,MagickPathExtent,"%.20g",(double)
2852 GetImageDepth(image,exception));
2859 if (LocaleCompare("channels",property) == 0)
2861 WarnNoImageReturn("\"%%[%s]\"",property);
2862 /* FUTURE: return actual image channels */
2863 (void) FormatLocaleString(value,MagickPathExtent,"%s",
2864 CommandOptionToMnemonic(MagickColorspaceOptions,(ssize_t)
2865 image->colorspace));
2867 if( image->alpha_trait != UndefinedPixelTrait )
2868 (void) ConcatenateMagickString(value,"a",MagickPathExtent);
2871 if (LocaleCompare("colorspace",property) == 0)
2873 WarnNoImageReturn("\"%%[%s]\"",property);
2874 string=CommandOptionToMnemonic(MagickColorspaceOptions,(ssize_t)
2878 if (LocaleCompare("compose",property) == 0)
2880 WarnNoImageReturn("\"%%[%s]\"",property);
2881 string=CommandOptionToMnemonic(MagickComposeOptions,(ssize_t)
2885 if (LocaleCompare("compression",property) == 0)
2887 WarnNoImageReturn("\"%%[%s]\"",property);
2888 string=CommandOptionToMnemonic(MagickCompressOptions,(ssize_t)
2889 image->compression);
2892 if (LocaleCompare("copyright",property) == 0)
2894 (void) CopyMagickString(value,GetMagickCopyright(),MagickPathExtent);
2901 if (LocaleCompare("depth",property) == 0)
2903 WarnNoImageReturn("\"%%[%s]\"",property);
2904 (void) FormatLocaleString(value,MagickPathExtent,"%.20g",(double)
2908 if (LocaleCompare("directory",property) == 0)
2910 WarnNoImageReturn("\"%%[%s]\"",property);
2911 GetPathComponent(image->magick_filename,HeadPath,value);
2920 if (LocaleCompare("entropy",property) == 0)
2925 WarnNoImageReturn("\"%%[%s]\"",property);
2926 (void) GetImageEntropy(image,&entropy,exception);
2927 (void) FormatLocaleString(value,MagickPathExtent,"%.*g",
2928 GetMagickPrecision(),entropy);
2931 if (LocaleCompare("extension",property) == 0)
2933 WarnNoImageReturn("\"%%[%s]\"",property);
2934 GetPathComponent(image->magick_filename,ExtensionPath,value);
2943 if (LocaleCompare("gamma",property) == 0)
2945 WarnNoImageReturn("\"%%[%s]\"",property);
2946 (void) FormatLocaleString(value,MagickPathExtent,"%.*g",
2947 GetMagickPrecision(),image->gamma);
2954 if (LocaleCompare("height",property) == 0)
2956 WarnNoImageReturn("\"%%[%s]\"",property);
2957 (void) FormatLocaleString(value,MagickPathExtent,"%.20g",
2958 image->magick_rows != 0 ? (double) image->magick_rows : 256.0);
2965 if (LocaleCompare("input",property) == 0)
2967 WarnNoImageReturn("\"%%[%s]\"",property);
2968 string=image->filename;
2971 if (LocaleCompare("interlace",property) == 0)
2973 WarnNoImageReturn("\"%%[%s]\"",property);
2974 string=CommandOptionToMnemonic(MagickInterlaceOptions,(ssize_t)
2982 if (LocaleCompare("kurtosis",property) == 0)
2988 WarnNoImageReturn("\"%%[%s]\"",property);
2989 (void) GetImageKurtosis(image,&kurtosis,&skewness,exception);
2990 (void) FormatLocaleString(value,MagickPathExtent,"%.*g",
2991 GetMagickPrecision(),kurtosis);
2998 if (LocaleCompare("magick",property) == 0)
3000 WarnNoImageReturn("\"%%[%s]\"",property);
3001 string=image->magick;
3004 if ((LocaleCompare("maxima",property) == 0) ||
3005 (LocaleCompare("max",property) == 0))
3011 WarnNoImageReturn("\"%%[%s]\"",property);
3012 (void) GetImageRange(image,&minimum,&maximum,exception);
3013 (void) FormatLocaleString(value,MagickPathExtent,"%.*g",
3014 GetMagickPrecision(),maximum);
3017 if (LocaleCompare("mean",property) == 0)
3023 WarnNoImageReturn("\"%%[%s]\"",property);
3024 (void) GetImageMean(image,&mean,&standard_deviation,exception);
3025 (void) FormatLocaleString(value,MagickPathExtent,"%.*g",
3026 GetMagickPrecision(),mean);
3029 if ((LocaleCompare("minima",property) == 0) ||
3030 (LocaleCompare("min",property) == 0))
3036 WarnNoImageReturn("\"%%[%s]\"",property);
3037 (void) GetImageRange(image,&minimum,&maximum,exception);
3038 (void) FormatLocaleString(value,MagickPathExtent,"%.*g",
3039 GetMagickPrecision(),minimum);
3046 if (LocaleCompare("opaque",property) == 0)
3048 WarnNoImageReturn("\"%%[%s]\"",property);
3049 string=CommandOptionToMnemonic(MagickBooleanOptions,(ssize_t)
3050 IsImageOpaque(image,exception));
3053 if (LocaleCompare("orientation",property) == 0)
3055 WarnNoImageReturn("\"%%[%s]\"",property);
3056 string=CommandOptionToMnemonic(MagickOrientationOptions,(ssize_t)
3057 image->orientation);
3060 if (LocaleCompare("output",property) == 0)
3062 WarnNoImageInfoReturn("\"%%[%s]\"",property);
3063 (void) CopyMagickString(value,image_info->filename,MagickPathExtent);
3070 if (LocaleCompare("page",property) == 0)
3072 WarnNoImageReturn("\"%%[%s]\"",property);
3073 (void) FormatLocaleString(value,MagickPathExtent,"%.20gx%.20g",
3074 (double) image->page.width,(double) image->page.height);
3077 #if defined(MAGICKCORE_LCMS_DELEGATE)
3078 if (LocaleCompare("profile:icc",property) == 0 ||
3079 LocaleCompare("profile:icm",property) == 0)
3081 #if !defined(LCMS_VERSION) || (LCMS_VERSION < 2000)
3082 #define cmsUInt32Number DWORD
3091 WarnNoImageReturn("\"%%[%s]\"",property);
3092 profile=GetImageProfile(image,property+8);
3093 if (profile == (StringInfo *) NULL)
3095 icc_profile=cmsOpenProfileFromMem(GetStringInfoDatum(profile),
3096 (cmsUInt32Number) GetStringInfoLength(profile));
3097 if (icc_profile != (cmsHPROFILE *) NULL)
3099 #if defined(LCMS_VERSION) && (LCMS_VERSION < 2000)
3100 string=cmsTakeProductName(icc_profile);
3102 (void) cmsGetProfileInfoASCII(icc_profile,cmsInfoDescription,
3103 "en","US",value,MagickPathExtent);
3105 (void) cmsCloseProfile(icc_profile);
3109 if (LocaleCompare("printsize.x",property) == 0)
3111 WarnNoImageReturn("\"%%[%s]\"",property);
3112 (void) FormatLocaleString(value,MagickPathExtent,"%.*g",
3113 GetMagickPrecision(),PerceptibleReciprocal(image->resolution.x)*
3117 if (LocaleCompare("printsize.y",property) == 0)
3119 WarnNoImageReturn("\"%%[%s]\"",property);
3120 (void) FormatLocaleString(value,MagickPathExtent,"%.*g",
3121 GetMagickPrecision(),PerceptibleReciprocal(image->resolution.y)*
3125 if (LocaleCompare("profiles",property) == 0)
3130 WarnNoImageReturn("\"%%[%s]\"",property);
3131 ResetImageProfileIterator(image);
3132 name=GetNextImageProfile(image);
3133 if (name != (char *) NULL)
3135 (void) CopyMagickString(value,name,MagickPathExtent);
3136 name=GetNextImageProfile(image);
3137 while (name != (char *) NULL)
3139 ConcatenateMagickString(value,",",MagickPathExtent);
3140 ConcatenateMagickString(value,name,MagickPathExtent);
3141 name=GetNextImageProfile(image);
3150 if (LocaleCompare("quality",property) == 0)
3152 WarnNoImageReturn("\"%%[%s]\"",property);
3153 (void) FormatLocaleString(value,MagickPathExtent,"%.20g",(double)
3161 if (LocaleCompare("resolution.x",property) == 0)
3163 WarnNoImageReturn("\"%%[%s]\"",property);
3164 (void) FormatLocaleString(value,MagickPathExtent,"%g",
3165 image->resolution.x);
3168 if (LocaleCompare("resolution.y",property) == 0)
3170 WarnNoImageReturn("\"%%[%s]\"",property);
3171 (void) FormatLocaleString(value,MagickPathExtent,"%g",
3172 image->resolution.y);
3179 if (LocaleCompare("scene",property) == 0)
3181 WarnNoImageInfoReturn("\"%%[%s]\"",property);
3182 if (image_info->number_scenes != 0)
3183 (void) FormatLocaleString(value,MagickPathExtent,"%.20g",(double)
3186 WarnNoImageReturn("\"%%[%s]\"",property);
3187 (void) FormatLocaleString(value,MagickPathExtent,"%.20g",(double)
3192 if (LocaleCompare("scenes",property) == 0)
3194 /* FUTURE: equivelent to %n? */
3195 WarnNoImageReturn("\"%%[%s]\"",property);
3196 (void) FormatLocaleString(value,MagickPathExtent,"%.20g",(double)
3197 GetImageListLength(image));
3200 if (LocaleCompare("size",property) == 0)
3202 WarnNoImageReturn("\"%%[%s]\"",property);
3203 (void) FormatMagickSize(GetBlobSize(image),MagickFalse,"B",
3204 MagickPathExtent,value);
3207 if (LocaleCompare("skewness",property) == 0)
3213 WarnNoImageReturn("\"%%[%s]\"",property);
3214 (void) GetImageKurtosis(image,&kurtosis,&skewness,exception);
3215 (void) FormatLocaleString(value,MagickPathExtent,"%.*g",
3216 GetMagickPrecision(),skewness);
3219 if (LocaleCompare("standard-deviation",property) == 0)
3225 WarnNoImageReturn("\"%%[%s]\"",property);
3226 (void) GetImageMean(image,&mean,&standard_deviation,exception);
3227 (void) FormatLocaleString(value,MagickPathExtent,"%.*g",
3228 GetMagickPrecision(),standard_deviation);
3235 if (LocaleCompare("type",property) == 0)
3237 WarnNoImageReturn("\"%%[%s]\"",property);
3238 string=CommandOptionToMnemonic(MagickTypeOptions,(ssize_t)
3239 IdentifyImageType(image,exception));
3246 if (LocaleCompare("unique",property) == 0)
3248 WarnNoImageInfoReturn("\"%%[%s]\"",property);
3249 string=image_info->unique;
3252 if (LocaleCompare("units",property) == 0)
3254 WarnNoImageReturn("\"%%[%s]\"",property);
3255 string=CommandOptionToMnemonic(MagickResolutionOptions,(ssize_t)
3263 if (LocaleCompare("version",property) == 0)
3265 string=GetMagickVersion((size_t *) NULL);
3272 if (LocaleCompare("width",property) == 0)
3274 WarnNoImageReturn("\"%%[%s]\"",property);
3275 (void) FormatLocaleString(value,MagickPathExtent,"%.20g",(double)
3276 (image->magick_columns != 0 ? image->magick_columns : 256));
3282 if (string != (char *) NULL)
3287 Create a cloned copy of result, that will get cleaned up, eventually.
3289 if (image != (Image *) NULL)
3291 (void) SetImageArtifact(image,"get-property",value);
3292 return(GetImageArtifact(image,"get-property"));
3296 (void) SetImageOption(image_info,"get-property",value);
3297 return(GetImageOption(image_info,"get-property"));
3300 return((char *) NULL);
3302 #undef WarnNoImageReturn
3305 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3309 % G e t N e x t I m a g e P r o p e r t y %
3313 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3315 % GetNextImageProperty() gets the next free-form string property name.
3317 % The format of the GetNextImageProperty method is:
3319 % char *GetNextImageProperty(const Image *image)
3321 % A description of each parameter follows:
3323 % o image: the image.
3326 MagickExport const char *GetNextImageProperty(const Image *image)
3328 assert(image != (Image *) NULL);
3329 assert(image->signature == MagickCoreSignature);
3330 if (image->debug != MagickFalse)
3331 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
3333 if (image->properties == (void *) NULL)
3334 return((const char *) NULL);
3335 return((const char *) GetNextKeyInSplayTree((SplayTreeInfo *) image->properties));
3339 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3343 % I n t e r p r e t I m a g e P r o p e r t i e s %
3347 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3349 % InterpretImageProperties() replaces any embedded formatting characters with
3350 % the appropriate image property and returns the interpreted text.
3352 % This searches for and replaces
3353 % \n \r \% replaced by newline, return, and percent resp.
3354 % < > & replaced by '<', '>', '&' resp.
3355 % %% replaced by percent
3357 % %x %[x] where 'x' is a single letter properity, case sensitive).
3358 % %[type:name] where 'type' a is special and known prefix.
3359 % %[name] where 'name' is a specifically known attribute, calculated
3360 % value, or a per-image property string name, or a per-image
3361 % 'artifact' (as generated from a global option).
3362 % It may contain ':' as long as the prefix is not special.
3364 % Single letter % substitutions will only happen if the character before the
3365 % percent is NOT a number. But braced substitutions will always be performed.
3366 % This prevents the typical usage of percent in a interpreted geometry
3367 % argument from being substituted when the percent is a geometry flag.
3369 % If 'glob-expresions' ('*' or '?' characters) is used for 'name' it may be
3370 % used as a search pattern to print multiple lines of "name=value\n" pairs of
3371 % the associacted set of properties.
3373 % The returned string must be freed using DestoryString() by the caller.
3375 % The format of the InterpretImageProperties method is:
3377 % char *InterpretImageProperties(ImageInfo *image_info,
3378 % Image *image,const char *embed_text,ExceptionInfo *exception)
3380 % A description of each parameter follows:
3382 % o image_info: the image info. (required)
3384 % o image: the image. (optional)
3386 % o embed_text: the address of a character string containing the embedded
3387 % formatting characters.
3389 % o exception: return any errors or warnings in this structure.
3392 MagickExport char *InterpretImageProperties(ImageInfo *image_info,Image *image,
3393 const char *embed_text,ExceptionInfo *exception)
3395 #define ExtendInterpretText(string_length) \
3396 DisableMSCWarning(4127) \
3398 size_t length=(string_length); \
3399 if ((size_t) (q-interpret_text+length+1) >= extent) \
3402 interpret_text=(char *) ResizeQuantumMemory(interpret_text,extent+ \
3403 MaxTextExtent,sizeof(*interpret_text)); \
3404 if (interpret_text == (char *) NULL) \
3406 if (property_image != image) \
3407 property_image=DestroyImage(property_image); \
3408 if (property_info != image_info) \
3409 property_info=DestroyImageInfo(property_info); \
3410 return((char *) NULL); \
3412 q=interpret_text+strlen(interpret_text); \
3417 #define AppendKeyValue2Text(key,value)\
3418 DisableMSCWarning(4127) \
3420 size_t length=strlen(key)+strlen(value)+2; \
3421 if ((size_t) (q-interpret_text+length+1) >= extent) \
3424 interpret_text=(char *) ResizeQuantumMemory(interpret_text,extent+ \
3425 MaxTextExtent,sizeof(*interpret_text)); \
3426 if (interpret_text == (char *) NULL) \
3428 if (property_image != image) \
3429 property_image=DestroyImage(property_image); \
3430 if (property_info != image_info) \
3431 property_info=DestroyImageInfo(property_info); \
3432 return((char *) NULL); \
3434 q=interpret_text+strlen(interpret_text); \
3436 q+=FormatLocaleString(q,extent,"%s=%s\n",(key),(value)); \
3440 #define AppendString2Text(string) \
3441 DisableMSCWarning(4127) \
3443 size_t length=strlen((string)); \
3444 if ((size_t) (q-interpret_text+length+1) >= extent) \
3447 interpret_text=(char *) ResizeQuantumMemory(interpret_text,extent+ \
3448 MaxTextExtent,sizeof(*interpret_text)); \
3449 if (interpret_text == (char *) NULL) \
3451 if (property_image != image) \
3452 property_image=DestroyImage(property_image); \
3453 if (property_info != image_info) \
3454 property_info=DestroyImageInfo(property_info); \
3455 return((char *) NULL); \
3457 q=interpret_text+strlen(interpret_text); \
3459 (void) CopyMagickString(q,(string),extent); \
3477 *q; /* current position in interpret_text */
3480 *p; /* position in embed_text string being expanded */
3483 extent; /* allocated length of interpret_text */
3485 if ((image != (Image *) NULL) && (image->debug != MagickFalse))
3486 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
3488 if ((image_info != (ImageInfo *) NULL) && (image_info->debug != MagickFalse))
3489 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
3490 image_info->filename);
3492 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s","no image");
3493 if (embed_text == (const char *) NULL)
3494 return(ConstantString(""));
3496 while ((isspace((int) ((unsigned char) *p)) != 0) && (*p != '\0'))
3499 return(ConstantString(""));
3500 if ((*p == '@') && (IsPathAccessible(p+1) != MagickFalse))
3503 Handle a '@' replace string from file.
3505 if (IsRightsAuthorized(PathPolicyDomain,ReadPolicyRights,p) == MagickFalse)
3508 (void) ThrowMagickException(exception,GetMagickModule(),PolicyError,
3509 "NotAuthorized","`%s'",p);
3510 return(ConstantString(""));
3512 interpret_text=FileToString(p+1,~0UL,exception);
3513 if (interpret_text != (char *) NULL)
3514 return(interpret_text);
3517 Translate any embedded format characters.
3519 if (image_info != (ImageInfo *) NULL)
3520 property_info=image_info;
3522 property_info=CloneImageInfo(image_info);
3523 if ((image != (Image *) NULL) && (image->columns != 0) && (image->rows != 0))
3524 property_image=image;
3527 property_image=AcquireImage(image_info,exception);
3528 (void) SetImageExtent(property_image,1,1,exception);
3529 (void) SetImageBackgroundColor(property_image,exception);
3531 interpret_text=AcquireString(embed_text); /* new string with extra space */
3532 extent=MagickPathExtent; /* allocated space in string */
3533 number=MagickFalse; /* is last char a number? */
3534 for (q=interpret_text; *p!='\0'; number=isdigit((int) ((unsigned char) *p)) ? MagickTrue : MagickFalse,p++)
3537 Look for the various escapes, (and handle other specials)
3540 ExtendInterpretText(MagickPathExtent);
3549 case 'r': /* convert to RETURN */
3555 case 'n': /* convert to NEWLINE */
3561 case '\n': /* EOL removal UNIX,MacOSX */
3566 case '\r': /* EOL removal DOS,Windows */
3569 if (*p == '\n') /* return-newline EOL */
3583 if (LocaleNCompare("<",p,4) == 0)
3589 if (LocaleNCompare(">",p,4) == 0)
3595 if (LocaleNCompare("&",p,5) == 0)
3605 break; /* continue to next set of handlers */
3608 *q++=(*p); /* any thing else is 'as normal' */
3612 p++; /* advance beyond the percent */
3614 Doubled Percent - or percent at end of string.
3616 if ((*p == '\0') || (*p == '\'') || (*p == '"'))
3624 Single letter escapes %c.
3631 if (number != MagickFalse)
3634 But only if not preceeded by a number!
3636 *q++='%'; /* do NOT substitute the percent */
3637 p--; /* back up one */
3640 string=GetMagickPropertyLetter(property_info,property_image,*p,
3642 if (string != (char *) NULL)
3644 AppendString2Text(string);
3645 (void) DeleteImageArtifact(property_image,"get-property");
3646 (void) DeleteImageOption(property_info,"get-property");
3649 (void) ThrowMagickException(exception,GetMagickModule(),OptionWarning,
3650 "UnknownImageProperty","\"%%%c\"",*p);
3655 pattern[2*MagickPathExtent];
3668 Braced Percent Escape %[...].
3670 p++; /* advance p to just inside the opening brace */
3674 (void) ThrowMagickException(exception,GetMagickModule(),OptionWarning,
3675 "UnknownImageProperty","\"%%[]\"");
3678 for (len=0; len < (MagickPathExtent-1L) && (*p != '\0'); )
3680 if ((*p == '\\') && (*(p+1) != '\0'))
3683 Skip escaped braces within braced pattern.
3685 pattern[len++]=(*p++);
3686 pattern[len++]=(*p++);
3695 pattern[len++]=(*p++);
3701 Check for unmatched final ']' for "%[...]".
3705 pattern[61] = '.'; /* truncate string for error message */
3710 (void) ThrowMagickException(exception,GetMagickModule(),OptionError,
3711 "UnbalancedBraces","\"%%[%s\"",pattern);
3712 interpret_text=DestroyString(interpret_text);
3713 if (property_image != image)
3714 property_image=DestroyImage(property_image);
3715 if (property_info != image_info)
3716 property_info=DestroyImageInfo(property_info);
3717 return((char *) NULL);
3720 Special Lookup Prefixes %[prefix:...].
3722 if (LocaleNCompare("fx:",pattern,3) == 0)
3734 FX - value calculator.
3736 fx_info=AcquireFxInfo(property_image,pattern+3,exception);
3737 status=FxEvaluateChannelExpression(fx_info,IntensityPixelChannel,0,0,
3739 fx_info=DestroyFxInfo(fx_info);
3740 if (status != MagickFalse)
3743 result[MagickPathExtent];
3745 (void) FormatLocaleString(result,MagickPathExtent,"%.*g",
3746 GetMagickPrecision(),(double) value);
3747 AppendString2Text(result);
3751 if (LocaleNCompare("hex:",pattern,4) == 0)
3766 Pixel - color value calculator.
3768 GetPixelInfo(property_image,&pixel);
3769 fx_info=AcquireFxInfo(property_image,pattern+4,exception);
3770 status=FxEvaluateChannelExpression(fx_info,RedPixelChannel,0,0,
3772 pixel.red=(double) QuantumRange*value;
3773 status&=FxEvaluateChannelExpression(fx_info,GreenPixelChannel,0,0,
3775 pixel.green=(double) QuantumRange*value;
3776 status&=FxEvaluateChannelExpression(fx_info,BluePixelChannel,0,0,
3778 pixel.blue=(double) QuantumRange*value;
3779 if (property_image->colorspace == CMYKColorspace)
3781 status&=FxEvaluateChannelExpression(fx_info,BlackPixelChannel,0,0,
3783 pixel.black=(double) QuantumRange*value;
3785 status&=FxEvaluateChannelExpression(fx_info,AlphaPixelChannel,0,0,
3787 pixel.alpha=(double) QuantumRange*value;
3788 fx_info=DestroyFxInfo(fx_info);
3789 if (status != MagickFalse)
3792 hex[MagickPathExtent],
3793 name[MagickPathExtent];
3795 (void) QueryColorname(property_image,&pixel,SVGCompliance,name,
3797 GetColorTuple(&pixel,MagickTrue,hex);
3798 AppendString2Text(hex+1);
3802 if (LocaleNCompare("pixel:",pattern,6) == 0)
3817 Pixel - color value calculator.
3819 GetPixelInfo(property_image,&pixel);
3820 fx_info=AcquireFxInfo(property_image,pattern+6,exception);
3821 status=FxEvaluateChannelExpression(fx_info,RedPixelChannel,0,0,
3823 pixel.red=(double) QuantumRange*value;
3824 status&=FxEvaluateChannelExpression(fx_info,GreenPixelChannel,0,0,
3826 pixel.green=(double) QuantumRange*value;
3827 status&=FxEvaluateChannelExpression(fx_info,BluePixelChannel,0,0,
3829 pixel.blue=(double) QuantumRange*value;
3830 if (property_image->colorspace == CMYKColorspace)
3832 status&=FxEvaluateChannelExpression(fx_info,BlackPixelChannel,0,0,
3834 pixel.black=(double) QuantumRange*value;
3836 status&=FxEvaluateChannelExpression(fx_info,AlphaPixelChannel,0,0,
3838 pixel.alpha=(double) QuantumRange*value;
3839 fx_info=DestroyFxInfo(fx_info);
3840 if (status != MagickFalse)
3843 name[MagickPathExtent];
3845 (void) QueryColorname(property_image,&pixel,SVGCompliance,name,
3847 AppendString2Text(name);
3851 if (LocaleNCompare("option:",pattern,7) == 0)
3854 Option - direct global option lookup (with globbing).
3856 if (IsGlob(pattern+7) != MagickFalse)
3858 ResetImageOptionIterator(property_info);
3859 while ((key=GetNextImageOption(property_info)) != (const char *) NULL)
3860 if (GlobExpression(key,pattern+7,MagickTrue) != MagickFalse)
3862 string=GetImageOption(property_info,key);
3863 if (string != (const char *) NULL)
3864 AppendKeyValue2Text(key,string);
3865 /* else - assertion failure? key found but no string value! */
3869 string=GetImageOption(property_info,pattern+7);
3870 if (string == (char *) NULL)
3871 goto PropertyLookupFailure; /* no artifact of this specifc name */
3872 AppendString2Text(string);
3875 if (LocaleNCompare("artifact:",pattern,9) == 0)
3878 Artifact - direct image artifact lookup (with glob).
3880 if (IsGlob(pattern+9) != MagickFalse)
3882 ResetImageArtifactIterator(property_image);
3883 while ((key=GetNextImageArtifact(property_image)) != (const char *) NULL)
3884 if (GlobExpression(key,pattern+9,MagickTrue) != MagickFalse)
3886 string=GetImageArtifact(property_image,key);
3887 if (string != (const char *) NULL)
3888 AppendKeyValue2Text(key,string);
3889 /* else - assertion failure? key found but no string value! */
3893 string=GetImageArtifact(property_image,pattern+9);
3894 if (string == (char *) NULL)
3895 goto PropertyLookupFailure; /* no artifact of this specifc name */
3896 AppendString2Text(string);
3899 if (LocaleNCompare("property:",pattern,9) == 0)
3902 Property - direct image property lookup (with glob).
3904 if (IsGlob(pattern+9) != MagickFalse)
3906 ResetImagePropertyIterator(property_image);
3907 while ((key=GetNextImageProperty(property_image)) != (const char *) NULL)
3908 if (GlobExpression(key,pattern,MagickTrue) != MagickFalse)
3910 string=GetImageProperty(property_image,key,exception);
3911 if (string != (const char *) NULL)
3912 AppendKeyValue2Text(key,string);
3913 /* else - assertion failure? */
3917 string=GetImageProperty(property_image,pattern+9,exception);
3918 if (string == (char *) NULL)
3919 goto PropertyLookupFailure; /* no artifact of this specifc name */
3920 AppendString2Text(string);
3924 Properties without special prefix. This handles attributes,
3925 properties, and profiles such as %[exif:...]. Note the profile
3926 properties may also include a glob expansion pattern.
3928 string=GetImageProperty(property_image,pattern,exception);
3929 if (string != (const char *) NULL)
3931 AppendString2Text(string);
3932 (void)DeleteImageArtifact(property_image,"get-property");
3933 (void)DeleteImageOption(property_info,"get-property");
3936 if (IsGlob(pattern) != MagickFalse)
3939 Handle property 'glob' patterns such as:
3940 %[*] %[user:array_??] %[filename:e*]>
3942 ResetImagePropertyIterator(property_image);
3943 while ((key=GetNextImageProperty(property_image)) != (const char *) NULL)
3944 if (GlobExpression(key,pattern,MagickTrue) != MagickFalse)
3946 string=GetImageProperty(property_image,key,exception);
3947 if (string != (const char *) NULL)
3948 AppendKeyValue2Text(key,string);
3949 /* else - assertion failure? */
3954 Look for a known property or image attribute such as
3955 %[basename] %[denisty] %[delay]. Also handles a braced single
3956 letter: %[b] %[G] %[g].
3958 string=GetMagickProperty(property_info,property_image,pattern,exception);
3959 if (string != (const char *) NULL)
3961 AppendString2Text(string);
3965 Look for a per-image artifact. This includes option lookup
3966 (FUTURE: interpreted according to image).
3968 string=GetImageArtifact(property_image,pattern);
3969 if (string != (char *) NULL)
3971 AppendString2Text(string);
3975 No image, so direct 'option' lookup (no delayed percent escapes).
3977 string=GetImageOption(property_info,pattern);
3978 if (string != (char *) NULL)
3980 AppendString2Text(string);
3983 PropertyLookupFailure:
3985 Failed to find any match anywhere!
3989 pattern[61] = '.'; /* truncate string for error message */
3994 (void) ThrowMagickException(exception,GetMagickModule(),OptionWarning,
3995 "UnknownImageProperty","\"%%[%s]\"",pattern);
3999 if (property_image != image)
4000 property_image=DestroyImage(property_image);
4001 if (property_info != image_info)
4002 property_info=DestroyImageInfo(property_info);
4003 return(interpret_text);
4007 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4011 % R e m o v e I m a g e P r o p e r t y %
4015 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4017 % RemoveImageProperty() removes a property from the image and returns its
4020 % In this case the ConstantString() value returned should be freed by the
4021 % caller when finished.
4023 % The format of the RemoveImageProperty method is:
4025 % char *RemoveImageProperty(Image *image,const char *property)
4027 % A description of each parameter follows:
4029 % o image: the image.
4031 % o property: the image property.
4034 MagickExport char *RemoveImageProperty(Image *image,const char *property)
4039 assert(image != (Image *) NULL);
4040 assert(image->signature == MagickCoreSignature);
4041 if (image->debug != MagickFalse)
4042 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
4043 if (image->properties == (void *) NULL)
4044 return((char *) NULL);
4045 value=(char *) RemoveNodeFromSplayTree((SplayTreeInfo *) image->properties,
4051 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4055 % 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 %
4059 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4061 % ResetImagePropertyIterator() resets the image properties iterator. Use it
4062 % in conjunction with GetNextImageProperty() to iterate over all the values
4063 % associated with an image property.
4065 % The format of the ResetImagePropertyIterator method is:
4067 % ResetImagePropertyIterator(Image *image)
4069 % A description of each parameter follows:
4071 % o image: the image.
4074 MagickExport void ResetImagePropertyIterator(const Image *image)
4076 assert(image != (Image *) NULL);
4077 assert(image->signature == MagickCoreSignature);
4078 if (image->debug != MagickFalse)
4079 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
4080 if (image->properties == (void *) NULL)
4082 ResetSplayTreeIterator((SplayTreeInfo *) image->properties);
4086 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4090 % S e t I m a g e P r o p e r t y %
4094 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4096 % SetImageProperty() saves the given string value either to specific known
4097 % attribute or to a freeform property string.
4099 % Attempting to set a property that is normally calculated will produce
4102 % The format of the SetImageProperty method is:
4104 % MagickBooleanType SetImageProperty(Image *image,const char *property,
4105 % const char *value,ExceptionInfo *exception)
4107 % A description of each parameter follows:
4109 % o image: the image.
4111 % o property: the image property.
4113 % o values: the image property values.
4115 % o exception: return any errors or warnings in this structure.
4118 MagickExport MagickBooleanType SetImageProperty(Image *image,
4119 const char *property,const char *value,ExceptionInfo *exception)
4127 assert(image != (Image *) NULL);
4128 assert(image->signature == MagickCoreSignature);
4129 if (image->debug != MagickFalse)
4130 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
4131 if (image->properties == (void *) NULL)
4132 image->properties=NewSplayTree(CompareSplayTreeString,
4133 RelinquishMagickMemory,RelinquishMagickMemory); /* create splay-tree */
4134 if (value == (const char *) NULL)
4135 return(DeleteImageProperty(image,property)); /* delete if NULL */
4137 if (strlen(property) <= 1)
4140 Do not 'set' single letter properties - read only shorthand.
4142 (void) ThrowMagickException(exception,GetMagickModule(),OptionError,
4143 "SetReadOnlyProperty","`%s'",property);
4144 return(MagickFalse);
4147 /* FUTURE: binary chars or quotes in key should produce a error */
4148 /* Set attributes with known names or special prefixes
4149 return result is found, or break to set a free form properity
4153 #if 0 /* Percent escape's sets values with this prefix: for later use
4154 Throwing an exception causes this setting to fail */
4157 if (LocaleNCompare("8bim:",property,5) == 0)
4159 (void) ThrowMagickException(exception,GetMagickModule(),OptionError,
4160 "SetReadOnlyProperty","`%s'",property);
4161 return(MagickFalse);
4169 if (LocaleCompare("background",property) == 0)
4171 (void) QueryColorCompliance(value,AllCompliance,
4172 &image->background_color,exception);
4173 /* check for FUTURE: value exception?? */
4174 /* also add user input to splay tree */
4176 break; /* not an attribute, add as a property */
4181 if (LocaleCompare("channels",property) == 0)
4183 (void) ThrowMagickException(exception,GetMagickModule(),OptionError,
4184 "SetReadOnlyProperty","`%s'",property);
4185 return(MagickFalse);
4187 if (LocaleCompare("colorspace",property) == 0)
4192 colorspace=ParseCommandOption(MagickColorspaceOptions,MagickFalse,
4195 return(MagickFalse); /* FUTURE: value exception?? */
4196 return(SetImageColorspace(image,(ColorspaceType) colorspace,exception));
4198 if (LocaleCompare("compose",property) == 0)
4203 compose=ParseCommandOption(MagickComposeOptions,MagickFalse,value);
4205 return(MagickFalse); /* FUTURE: value exception?? */
4206 image->compose=(CompositeOperator) compose;
4209 if (LocaleCompare("compress",property) == 0)
4214 compression=ParseCommandOption(MagickCompressOptions,MagickFalse,
4216 if (compression < 0)
4217 return(MagickFalse); /* FUTURE: value exception?? */
4218 image->compression=(CompressionType) compression;
4221 break; /* not an attribute, add as a property */
4226 if (LocaleCompare("delay",property) == 0)
4231 flags=ParseGeometry(value,&geometry_info);
4232 if ((flags & GreaterValue) != 0)
4234 if (image->delay > (size_t) floor(geometry_info.rho+0.5))
4235 image->delay=(size_t) floor(geometry_info.rho+0.5);
4238 if ((flags & LessValue) != 0)
4240 if (image->delay < (size_t) floor(geometry_info.rho+0.5))
4241 image->delay=(ssize_t)
4242 floor(geometry_info.sigma+0.5);
4245 image->delay=(size_t) floor(geometry_info.rho+0.5);
4246 if ((flags & SigmaValue) != 0)
4247 image->ticks_per_second=(ssize_t) floor(geometry_info.sigma+0.5);
4250 if (LocaleCompare("delay_units",property) == 0)
4252 (void) ThrowMagickException(exception,GetMagickModule(),OptionError,
4253 "SetReadOnlyProperty","`%s'",property);
4254 return(MagickFalse);
4256 if (LocaleCompare("density",property) == 0)
4261 flags=ParseGeometry(value,&geometry_info);
4262 if ((flags & RhoValue) != 0)
4263 image->resolution.x=geometry_info.rho;
4264 image->resolution.y=image->resolution.x;
4265 if ((flags & SigmaValue) != 0)
4266 image->resolution.y=geometry_info.sigma;
4269 if (LocaleCompare("depth",property) == 0)
4271 image->depth=StringToUnsignedLong(value);
4274 if (LocaleCompare("dispose",property) == 0)
4279 dispose=ParseCommandOption(MagickDisposeOptions,MagickFalse,value);
4281 return(MagickFalse); /* FUTURE: value exception?? */
4282 image->dispose=(DisposeType) dispose;
4285 break; /* not an attribute, add as a property */
4287 #if 0 /* Percent escape's sets values with this prefix: for later use
4288 Throwing an exception causes this setting to fail */
4292 if (LocaleNCompare("exif:",property,5) == 0)
4294 (void) ThrowMagickException(exception,GetMagickModule(),OptionError,
4295 "SetReadOnlyProperty","`%s'",property);
4296 return(MagickFalse);
4298 break; /* not an attribute, add as a property */
4303 if (LocaleNCompare("fx:",property,3) == 0)
4305 (void) ThrowMagickException(exception,GetMagickModule(),OptionError,
4306 "SetReadOnlyProperty","`%s'",property);
4307 return(MagickFalse);
4309 break; /* not an attribute, add as a property */
4315 if (LocaleCompare("gamma",property) == 0)
4317 image->gamma=StringToDouble(value,(char **) NULL);
4320 if (LocaleCompare("gravity",property) == 0)
4325 gravity=ParseCommandOption(MagickGravityOptions,MagickFalse,value);
4327 return(MagickFalse); /* FUTURE: value exception?? */
4328 image->gravity=(GravityType) gravity;
4331 break; /* not an attribute, add as a property */
4336 if (LocaleCompare("height",property) == 0)
4338 (void) ThrowMagickException(exception,GetMagickModule(),OptionError,
4339 "SetReadOnlyProperty","`%s'",property);
4340 return(MagickFalse);
4342 break; /* not an attribute, add as a property */
4347 if (LocaleCompare("intensity",property) == 0)
4352 intensity=ParseCommandOption(MagickIntentOptions,MagickFalse,value);
4354 return(MagickFalse);
4355 image->intensity=(PixelIntensityMethod) intensity;
4358 if (LocaleCompare("intent",property) == 0)
4363 rendering_intent=ParseCommandOption(MagickIntentOptions,MagickFalse,
4365 if (rendering_intent < 0)
4366 return(MagickFalse); /* FUTURE: value exception?? */
4367 image->rendering_intent=(RenderingIntent) rendering_intent;
4370 if (LocaleCompare("interpolate",property) == 0)
4375 interpolate=ParseCommandOption(MagickInterpolateOptions,MagickFalse,
4377 if (interpolate < 0)
4378 return(MagickFalse); /* FUTURE: value exception?? */
4379 image->interpolate=(PixelInterpolateMethod) interpolate;
4382 #if 0 /* Percent escape's sets values with this prefix: for later use
4383 Throwing an exception causes this setting to fail */
4384 if (LocaleNCompare("iptc:",property,5) == 0)
4386 (void) ThrowMagickException(exception,GetMagickModule(),OptionError,
4387 "SetReadOnlyProperty","`%s'",property);
4388 return(MagickFalse);
4391 break; /* not an attribute, add as a property */
4395 if (LocaleCompare("kurtosis",property) == 0)
4397 (void) ThrowMagickException(exception,GetMagickModule(),OptionError,
4398 "SetReadOnlyProperty","`%s'",property);
4399 return(MagickFalse);
4401 break; /* not an attribute, add as a property */
4405 if (LocaleCompare("loop",property) == 0)
4407 image->iterations=StringToUnsignedLong(value);
4410 break; /* not an attribute, add as a property */
4414 if ((LocaleCompare("magick",property) == 0) ||
4415 (LocaleCompare("max",property) == 0) ||
4416 (LocaleCompare("mean",property) == 0) ||
4417 (LocaleCompare("min",property) == 0) ||
4418 (LocaleCompare("min",property) == 0))
4420 (void) ThrowMagickException(exception,GetMagickModule(),OptionError,
4421 "SetReadOnlyProperty","`%s'",property);
4422 return(MagickFalse);
4424 break; /* not an attribute, add as a property */
4427 if (LocaleCompare("opaque",property) == 0)
4429 (void) ThrowMagickException(exception,GetMagickModule(),OptionError,
4430 "SetReadOnlyProperty","`%s'",property);
4431 return(MagickFalse);
4433 break; /* not an attribute, add as a property */
4437 if (LocaleCompare("page",property) == 0)
4442 geometry=GetPageGeometry(value);
4443 flags=ParseAbsoluteGeometry(geometry,&image->page);
4444 geometry=DestroyString(geometry);
4447 #if 0 /* Percent escape's sets values with this prefix: for later use
4448 Throwing an exception causes this setting to fail */
4449 if (LocaleNCompare("pixel:",property,6) == 0)
4451 (void) ThrowMagickException(exception,GetMagickModule(),OptionError,
4452 "SetReadOnlyProperty","`%s'",property);
4453 return(MagickFalse);
4456 if (LocaleCompare("profile",property) == 0)
4464 image_info=AcquireImageInfo();
4465 (void) CopyMagickString(image_info->filename,value,MagickPathExtent);
4466 (void) SetImageInfo(image_info,1,exception);
4467 profile=FileToStringInfo(image_info->filename,~0UL,exception);
4468 if (profile != (StringInfo *) NULL)
4469 status=SetImageProfile(image,image_info->magick,profile,exception);
4470 image_info=DestroyImageInfo(image_info);
4473 break; /* not an attribute, add as a property */
4478 if (LocaleCompare("rendering-intent",property) == 0)
4483 rendering_intent=ParseCommandOption(MagickIntentOptions,MagickFalse,
4485 if (rendering_intent < 0)
4486 return(MagickFalse); /* FUTURE: value exception?? */
4487 image->rendering_intent=(RenderingIntent) rendering_intent;
4490 break; /* not an attribute, add as a property */
4494 if ((LocaleCompare("size",property) == 0) ||
4495 (LocaleCompare("skewness",property) == 0) ||
4496 (LocaleCompare("scenes",property) == 0) ||
4497 (LocaleCompare("standard-deviation",property) == 0))
4499 (void) ThrowMagickException(exception,GetMagickModule(),OptionError,
4500 "SetReadOnlyProperty","`%s'",property);
4501 return(MagickFalse);
4503 break; /* not an attribute, add as a property */
4507 if (LocaleCompare("tile-offset",property) == 0)
4512 geometry=GetPageGeometry(value);
4513 flags=ParseAbsoluteGeometry(geometry,&image->tile_offset);
4514 geometry=DestroyString(geometry);
4517 break; /* not an attribute, add as a property */
4522 if (LocaleCompare("units",property) == 0)
4527 units=ParseCommandOption(MagickResolutionOptions,MagickFalse,value);
4529 return(MagickFalse); /* FUTURE: value exception?? */
4530 image->units=(ResolutionType) units;
4533 break; /* not an attribute, add as a property */
4538 if (LocaleCompare("version",property) == 0)
4540 (void) ThrowMagickException(exception,GetMagickModule(),OptionError,
4541 "SetReadOnlyProperty","`%s'",property);
4542 return(MagickFalse);
4544 break; /* not an attribute, add as a property */
4549 if (LocaleCompare("width",property) == 0)
4551 (void) ThrowMagickException(exception,GetMagickModule(),OptionError,
4552 "SetReadOnlyProperty","`%s'",property);
4553 return(MagickFalse);
4555 break; /* not an attribute, add as a property */
4557 #if 0 /* Percent escape's sets values with this prefix: for later use
4558 Throwing an exception causes this setting to fail */
4562 if (LocaleNCompare("xmp:",property,4) == 0)
4564 (void) ThrowMagickException(exception,GetMagickModule(),OptionError,
4565 "SetReadOnlyProperty","`%s'",property);
4566 return(MagickFalse);
4568 break; /* not an attribute, add as a property */
4572 /* Default: not an attribute, add as a property */
4573 status=AddValueToSplayTree((SplayTreeInfo *) image->properties,
4574 ConstantString(property),ConstantString(value));
4575 /* FUTURE: error if status is bad? */