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-2014 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 % http://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/profile.h"
72 #include "MagickCore/property.h"
73 #include "MagickCore/quantum.h"
74 #include "MagickCore/resource_.h"
75 #include "MagickCore/splay-tree.h"
76 #include "MagickCore/signature.h"
77 #include "MagickCore/statistic.h"
78 #include "MagickCore/string_.h"
79 #include "MagickCore/string-private.h"
80 #include "MagickCore/token.h"
81 #include "MagickCore/token-private.h"
82 #include "MagickCore/utility.h"
83 #include "MagickCore/utility-private.h"
84 #include "MagickCore/version.h"
85 #include "MagickCore/xml-tree.h"
86 #include "MagickCore/xml-tree-private.h"
87 #if defined(MAGICKCORE_LCMS_DELEGATE)
88 #if defined(MAGICKCORE_HAVE_LCMS_LCMS2_H)
89 #include <lcms/lcms2.h>
90 #elif defined(MAGICKCORE_HAVE_LCMS2_H)
92 #elif defined(MAGICKCORE_HAVE_LCMS_LCMS_H)
93 #include <lcms/lcms.h>
102 #if defined(MAGICKCORE_LCMS_DELEGATE)
103 #if defined(LCMS_VERSION) && (LCMS_VERSION < 2000)
104 #define cmsUInt32Number DWORD
109 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
113 % C l o n e I m a g e P r o p e r t i e s %
117 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
119 % CloneImageProperties() clones all the image properties to another image.
121 % The format of the CloneImageProperties method is:
123 % MagickBooleanType CloneImageProperties(Image *image,
124 % const Image *clone_image)
126 % A description of each parameter follows:
128 % o image: the image.
130 % o clone_image: the clone image.
133 MagickExport MagickBooleanType CloneImageProperties(Image *image,
134 const Image *clone_image)
136 assert(image != (Image *) NULL);
137 assert(image->signature == MagickSignature);
138 if (image->debug != MagickFalse)
139 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
140 assert(clone_image != (const Image *) NULL);
141 assert(clone_image->signature == MagickSignature);
142 if( IfMagickTrue(clone_image->debug) )
143 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
144 clone_image->filename);
145 (void) CopyMagickString(image->filename,clone_image->filename,MaxTextExtent);
146 (void) CopyMagickString(image->magick_filename,clone_image->magick_filename,
148 image->compression=clone_image->compression;
149 image->quality=clone_image->quality;
150 image->depth=clone_image->depth;
151 image->background_color=clone_image->background_color;
152 image->border_color=clone_image->border_color;
153 image->matte_color=clone_image->matte_color;
154 image->transparent_color=clone_image->transparent_color;
155 image->gamma=clone_image->gamma;
156 image->chromaticity=clone_image->chromaticity;
157 image->rendering_intent=clone_image->rendering_intent;
158 image->black_point_compensation=clone_image->black_point_compensation;
159 image->units=clone_image->units;
160 image->montage=(char *) NULL;
161 image->directory=(char *) NULL;
162 (void) CloneString(&image->geometry,clone_image->geometry);
163 image->offset=clone_image->offset;
164 image->resolution.x=clone_image->resolution.x;
165 image->resolution.y=clone_image->resolution.y;
166 image->page=clone_image->page;
167 image->tile_offset=clone_image->tile_offset;
168 image->extract_info=clone_image->extract_info;
169 image->filter=clone_image->filter;
170 image->fuzz=clone_image->fuzz;
171 image->intensity=clone_image->intensity;
172 image->interlace=clone_image->interlace;
173 image->interpolate=clone_image->interpolate;
174 image->endian=clone_image->endian;
175 image->gravity=clone_image->gravity;
176 image->compose=clone_image->compose;
177 image->orientation=clone_image->orientation;
178 image->scene=clone_image->scene;
179 image->dispose=clone_image->dispose;
180 image->delay=clone_image->delay;
181 image->ticks_per_second=clone_image->ticks_per_second;
182 image->iterations=clone_image->iterations;
183 image->total_colors=clone_image->total_colors;
184 image->taint=clone_image->taint;
185 image->progress_monitor=clone_image->progress_monitor;
186 image->client_data=clone_image->client_data;
187 image->start_loop=clone_image->start_loop;
188 image->error=clone_image->error;
189 image->signature=clone_image->signature;
190 if (clone_image->properties != (void *) NULL)
192 if (image->properties != (void *) NULL)
193 DestroyImageProperties(image);
194 image->properties=CloneSplayTree((SplayTreeInfo *)
195 clone_image->properties,(void *(*)(void *)) ConstantString,
196 (void *(*)(void *)) ConstantString);
202 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
206 % D e f i n e I m a g e P r o p e r t y %
210 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
212 % DefineImageProperty() associates an assignment string of the form
213 % "key=value" with an artifact or options. It is equivelent to
216 % The format of the DefineImageProperty method is:
218 % MagickBooleanType DefineImageProperty(Image *image,const char *property,
219 % ExceptionInfo *exception)
221 % A description of each parameter follows:
223 % o image: the image.
225 % o property: the image property.
227 % o exception: return any errors or warnings in this structure.
230 MagickExport MagickBooleanType DefineImageProperty(Image *image,
231 const char *property,ExceptionInfo *exception)
235 value[MaxTextExtent];
240 assert(image != (Image *) NULL);
241 assert(property != (const char *) NULL);
242 (void) CopyMagickString(key,property,MaxTextExtent-1);
243 for (p=key; *p != '\0'; p++)
248 (void) CopyMagickString(value,p+1,MaxTextExtent);
250 return(SetImageProperty(image,key,value,exception));
254 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
258 % D e l e t e I m a g e P r o p e r t y %
262 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
264 % DeleteImageProperty() deletes an image property.
266 % The format of the DeleteImageProperty method is:
268 % MagickBooleanType DeleteImageProperty(Image *image,const char *property)
270 % A description of each parameter follows:
272 % o image: the image.
274 % o property: the image property.
277 MagickExport MagickBooleanType DeleteImageProperty(Image *image,
278 const char *property)
280 assert(image != (Image *) NULL);
281 assert(image->signature == MagickSignature);
282 if (image->debug != MagickFalse)
283 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
285 if (image->properties == (void *) NULL)
287 return(DeleteNodeFromSplayTree((SplayTreeInfo *) image->properties,property));
291 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
295 % D e s t r o y I m a g e P r o p e r t i e s %
299 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
301 % DestroyImageProperties() destroys all properties and associated memory
302 % attached to the given image.
304 % The format of the DestroyDefines method is:
306 % void DestroyImageProperties(Image *image)
308 % A description of each parameter follows:
310 % o image: the image.
313 MagickExport void DestroyImageProperties(Image *image)
315 assert(image != (Image *) NULL);
316 assert(image->signature == MagickSignature);
317 if (image->debug != MagickFalse)
318 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
320 if (image->properties != (void *) NULL)
321 image->properties=(void *) DestroySplayTree((SplayTreeInfo *)
326 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
330 % F o r m a t I m a g e P r o p e r t y %
334 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
336 % FormatImageProperty() permits formatted property/value pairs to be saved as
339 % The format of the FormatImageProperty method is:
341 % MagickBooleanType FormatImageProperty(Image *image,const char *property,
342 % const char *format,...)
344 % A description of each parameter follows.
346 % o image: The image.
348 % o property: The attribute property.
350 % o format: A string describing the format to use to write the remaining
354 MagickExport MagickBooleanType FormatImageProperty(Image *image,
355 const char *property,const char *format,...)
358 value[MaxTextExtent];
372 va_start(operands,format);
373 n=FormatLocaleStringList(value,MaxTextExtent,format,operands);
376 exception=AcquireExceptionInfo();
377 status=SetImageProperty(image,property,value,exception);
378 exception=DestroyExceptionInfo(exception);
383 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
387 % G e t I m a g e P r o p e r t y %
391 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
393 % GetImageProperty() gets a value associated with an image property.
395 % This includes, profile prefixes, such as "exif:", "iptc:" and "8bim:"
396 % It does not handle non-prifile prefixes, such as "fx:", "option:", or
399 % The returned string is stored as a properity of the same name for faster
400 % lookup later. It should NOT be freed by the caller.
402 % The format of the GetImageProperty method is:
404 % const char *GetImageProperty(const Image *image,const char *key,
405 % ExceptionInfo *exception)
407 % A description of each parameter follows:
409 % o image: the image.
413 % o exception: return any errors or warnings in this structure.
418 *TracePSClippath(const unsigned char *,size_t,const size_t,
420 *TraceSVGClippath(const unsigned char *,size_t,const size_t,
423 static MagickBooleanType GetIPTCProperty(const Image *image,const char *key,
424 ExceptionInfo *exception)
444 profile=GetImageProfile(image,"iptc");
445 if (profile == (StringInfo *) NULL)
446 profile=GetImageProfile(image,"8bim");
447 if (profile == (StringInfo *) NULL)
449 count=sscanf(key,"IPTC:%ld:%ld",&dataset,&record);
452 attribute=(char *) NULL;
453 for (i=0; i < (ssize_t) GetStringInfoLength(profile); i+=(ssize_t) length)
456 if ((ssize_t) GetStringInfoDatum(profile)[i] != 0x1c)
458 length=(size_t) (GetStringInfoDatum(profile)[i+3] << 8);
459 length|=GetStringInfoDatum(profile)[i+4];
460 if (((long) GetStringInfoDatum(profile)[i+1] == dataset) &&
461 ((long) GetStringInfoDatum(profile)[i+2] == record))
463 message=(char *) NULL;
465 message=(char *) AcquireQuantumMemory(length+1UL,sizeof(*message));
466 if (message != (char *) NULL)
468 (void) CopyMagickString(message,(char *) GetStringInfoDatum(
469 profile)+i+5,length+1);
470 (void) ConcatenateString(&attribute,message);
471 (void) ConcatenateString(&attribute,";");
472 message=DestroyString(message);
477 if ((attribute == (char *) NULL) || (*attribute == ';'))
479 if (attribute != (char *) NULL)
480 attribute=DestroyString(attribute);
483 attribute[strlen(attribute)-1]='\0';
484 (void) SetImageProperty((Image *) image,key,(const char *) attribute,
486 attribute=DestroyString(attribute);
490 static inline ssize_t MagickMax(const ssize_t x,const ssize_t y)
497 static inline ssize_t MagickMin(const ssize_t x,const ssize_t y)
504 static inline int ReadPropertyByte(const unsigned char **p,size_t *length)
516 static inline size_t ReadPropertyMSBLong(const unsigned char **p,
533 for (i=0; i < 4; i++)
537 buffer[i]=(unsigned char) c;
539 value=(size_t) (buffer[0] << 24);
540 value|=buffer[1] << 16;
541 value|=buffer[2] << 8;
543 return(value & 0xffffffff);
546 static inline unsigned short ReadPropertyMSBShort(const unsigned char **p,
562 return((unsigned short) ~0);
563 for (i=0; i < 2; i++)
567 buffer[i]=(unsigned char) c;
569 value=(unsigned short) (buffer[0] << 8);
571 return((unsigned short) (value & 0xffff));
574 static MagickBooleanType Get8BIMProperty(const Image *image,const char *key,
575 ExceptionInfo *exception)
579 format[MaxTextExtent],
608 There are no newlines in path names, so it's safe as terminator.
610 profile=GetImageProfile(image,"8bim");
611 if (profile == (StringInfo *) NULL)
613 count=(ssize_t) sscanf(key,"8BIM:%ld,%ld:%[^\n]\n%[^\n]",&start,&stop,name,
615 if ((count != 2) && (count != 3) && (count != 4))
618 (void) CopyMagickString(format,"SVG",MaxTextExtent);
623 sub_number=(ssize_t) StringToLong(&name[1]);
624 sub_number=MagickMax(sub_number,1L);
625 resource=(char *) NULL;
627 length=GetStringInfoLength(profile);
628 info=GetStringInfoDatum(profile);
629 while ((length > 0) && IfMagickFalse(status))
631 if (ReadPropertyByte(&info,&length) != (unsigned char) '8')
633 if (ReadPropertyByte(&info,&length) != (unsigned char) 'B')
635 if (ReadPropertyByte(&info,&length) != (unsigned char) 'I')
637 if (ReadPropertyByte(&info,&length) != (unsigned char) 'M')
639 id=(ssize_t) ((int) ReadPropertyMSBShort(&info,&length));
640 if (id < (ssize_t) start)
642 if (id > (ssize_t) stop)
644 if (resource != (char *) NULL)
645 resource=DestroyString(resource);
646 count=(ssize_t) ReadPropertyByte(&info,&length);
647 if ((count != 0) && ((size_t) count <= length))
649 resource=(char *) NULL;
650 if (~((size_t) count) >= (MaxTextExtent-1))
651 resource=(char *) AcquireQuantumMemory((size_t) count+MaxTextExtent,
653 if (resource != (char *) NULL)
655 for (i=0; i < (ssize_t) count; i++)
656 resource[i]=(char) ReadPropertyByte(&info,&length);
657 resource[count]='\0';
660 if ((count & 0x01) == 0)
661 (void) ReadPropertyByte(&info,&length);
662 count=(ssize_t) ((int) ReadPropertyMSBLong(&info,&length));
663 if ((*name != '\0') && (*name != '#'))
664 if ((resource == (char *) NULL) || (LocaleCompare(name,resource) != 0))
667 No name match, scroll forward and try next.
670 length-=MagickMin(count,(ssize_t) length);
673 if ((*name == '#') && (sub_number != 1))
676 No numbered match, scroll forward and try next.
680 length-=MagickMin(count,(ssize_t) length);
684 We have the resource of interest.
686 attribute=(char *) NULL;
687 if (~((size_t) count) >= (MaxTextExtent-1))
688 attribute=(char *) AcquireQuantumMemory((size_t) count+MaxTextExtent,
690 if (attribute != (char *) NULL)
692 (void) CopyMagickMemory(attribute,(char *) info,(size_t) count);
693 attribute[count]='\0';
695 length-=MagickMin(count,(ssize_t) length);
696 if ((id <= 1999) || (id >= 2999))
697 (void) SetImageProperty((Image *) image,key,(const char *)
698 attribute,exception);
704 if (LocaleCompare(format,"svg") == 0)
705 path=TraceSVGClippath((unsigned char *) attribute,(size_t) count,
706 image->columns,image->rows);
708 path=TracePSClippath((unsigned char *) attribute,(size_t) count,
709 image->columns,image->rows);
710 (void) SetImageProperty((Image *) image,key,(const char *) path,
712 path=DestroyString(path);
714 attribute=DestroyString(attribute);
718 if (resource != (char *) NULL)
719 resource=DestroyString(resource);
723 static inline unsigned short ReadPropertyShort(const EndianType endian,
724 const unsigned char *buffer)
729 if (endian == LSBEndian)
731 value=(unsigned short) ((buffer[1] << 8) | buffer[0]);
732 return((unsigned short) (value & 0xffff));
734 value=(unsigned short) ((((unsigned char *) buffer)[0] << 8) |
735 ((unsigned char *) buffer)[1]);
736 return((unsigned short) (value & 0xffff));
739 static inline size_t ReadPropertyLong(const EndianType endian,
740 const unsigned char *buffer)
745 if (endian == LSBEndian)
747 value=(size_t) ((buffer[3] << 24) | (buffer[2] << 16) |
748 (buffer[1] << 8 ) | (buffer[0]));
749 return((size_t) (value & 0xffffffff));
751 value=(size_t) ((buffer[0] << 24) | (buffer[1] << 16) |
752 (buffer[2] << 8) | buffer[3]);
753 return((size_t) (value & 0xffffffff));
756 static MagickBooleanType GetEXIFProperty(const Image *image,
757 const char *property,ExceptionInfo *exception)
759 #define MaxDirectoryStack 16
760 #define EXIF_DELIMITER "\n"
761 #define EXIF_NUM_FORMATS 12
762 #define EXIF_FMT_BYTE 1
763 #define EXIF_FMT_STRING 2
764 #define EXIF_FMT_USHORT 3
765 #define EXIF_FMT_ULONG 4
766 #define EXIF_FMT_URATIONAL 5
767 #define EXIF_FMT_SBYTE 6
768 #define EXIF_FMT_UNDEFINED 7
769 #define EXIF_FMT_SSHORT 8
770 #define EXIF_FMT_SLONG 9
771 #define EXIF_FMT_SRATIONAL 10
772 #define EXIF_FMT_SINGLE 11
773 #define EXIF_FMT_DOUBLE 12
774 #define TAG_EXIF_OFFSET 0x8769
775 #define TAG_GPS_OFFSET 0x8825
776 #define TAG_INTEROP_OFFSET 0xa005
778 #define EXIFMultipleValues(size,format,arg) \
791 for (component=0; component < components; component++) \
793 length+=FormatLocaleString(buffer+length,MaxTextExtent-length, \
795 if (length >= (MaxTextExtent-1)) \
796 length=MaxTextExtent-1; \
800 buffer[length-2]='\0'; \
801 value=AcquireString(buffer); \
804 #define EXIFMultipleFractions(size,format,arg1,arg2) \
817 for (component=0; component < components; component++) \
819 length+=FormatLocaleString(buffer+length,MaxTextExtent-length, \
820 format", ",(arg1),(arg2)); \
821 if (length >= (MaxTextExtent-1)) \
822 length=MaxTextExtent-1; \
826 buffer[length-2]='\0'; \
827 value=AcquireString(buffer); \
830 typedef struct _DirectoryInfo
842 typedef struct _TagInfo
854 { 0x001, "exif:InteroperabilityIndex" },
855 { 0x002, "exif:InteroperabilityVersion" },
856 { 0x100, "exif:ImageWidth" },
857 { 0x101, "exif:ImageLength" },
858 { 0x102, "exif:BitsPerSample" },
859 { 0x103, "exif:Compression" },
860 { 0x106, "exif:PhotometricInterpretation" },
861 { 0x10a, "exif:FillOrder" },
862 { 0x10d, "exif:DocumentName" },
863 { 0x10e, "exif:ImageDescription" },
864 { 0x10f, "exif:Make" },
865 { 0x110, "exif:Model" },
866 { 0x111, "exif:StripOffsets" },
867 { 0x112, "exif:Orientation" },
868 { 0x115, "exif:SamplesPerPixel" },
869 { 0x116, "exif:RowsPerStrip" },
870 { 0x117, "exif:StripByteCounts" },
871 { 0x11a, "exif:XResolution" },
872 { 0x11b, "exif:YResolution" },
873 { 0x11c, "exif:PlanarConfiguration" },
874 { 0x11d, "exif:PageName" },
875 { 0x11e, "exif:XPosition" },
876 { 0x11f, "exif:YPosition" },
877 { 0x118, "exif:MinSampleValue" },
878 { 0x119, "exif:MaxSampleValue" },
879 { 0x120, "exif:FreeOffsets" },
880 { 0x121, "exif:FreeByteCounts" },
881 { 0x122, "exif:GrayResponseUnit" },
882 { 0x123, "exif:GrayResponseCurve" },
883 { 0x124, "exif:T4Options" },
884 { 0x125, "exif:T6Options" },
885 { 0x128, "exif:ResolutionUnit" },
886 { 0x12d, "exif:TransferFunction" },
887 { 0x131, "exif:Software" },
888 { 0x132, "exif:DateTime" },
889 { 0x13b, "exif:Artist" },
890 { 0x13e, "exif:WhitePoint" },
891 { 0x13f, "exif:PrimaryChromaticities" },
892 { 0x140, "exif:ColorMap" },
893 { 0x141, "exif:HalfToneHints" },
894 { 0x142, "exif:TileWidth" },
895 { 0x143, "exif:TileLength" },
896 { 0x144, "exif:TileOffsets" },
897 { 0x145, "exif:TileByteCounts" },
898 { 0x14a, "exif:SubIFD" },
899 { 0x14c, "exif:InkSet" },
900 { 0x14d, "exif:InkNames" },
901 { 0x14e, "exif:NumberOfInks" },
902 { 0x150, "exif:DotRange" },
903 { 0x151, "exif:TargetPrinter" },
904 { 0x152, "exif:ExtraSample" },
905 { 0x153, "exif:SampleFormat" },
906 { 0x154, "exif:SMinSampleValue" },
907 { 0x155, "exif:SMaxSampleValue" },
908 { 0x156, "exif:TransferRange" },
909 { 0x157, "exif:ClipPath" },
910 { 0x158, "exif:XClipPathUnits" },
911 { 0x159, "exif:YClipPathUnits" },
912 { 0x15a, "exif:Indexed" },
913 { 0x15b, "exif:JPEGTables" },
914 { 0x15f, "exif:OPIProxy" },
915 { 0x200, "exif:JPEGProc" },
916 { 0x201, "exif:JPEGInterchangeFormat" },
917 { 0x202, "exif:JPEGInterchangeFormatLength" },
918 { 0x203, "exif:JPEGRestartInterval" },
919 { 0x205, "exif:JPEGLosslessPredictors" },
920 { 0x206, "exif:JPEGPointTransforms" },
921 { 0x207, "exif:JPEGQTables" },
922 { 0x208, "exif:JPEGDCTables" },
923 { 0x209, "exif:JPEGACTables" },
924 { 0x211, "exif:YCbCrCoefficients" },
925 { 0x212, "exif:YCbCrSubSampling" },
926 { 0x213, "exif:YCbCrPositioning" },
927 { 0x214, "exif:ReferenceBlackWhite" },
928 { 0x2bc, "exif:ExtensibleMetadataPlatform" },
929 { 0x301, "exif:Gamma" },
930 { 0x302, "exif:ICCProfileDescriptor" },
931 { 0x303, "exif:SRGBRenderingIntent" },
932 { 0x320, "exif:ImageTitle" },
933 { 0x5001, "exif:ResolutionXUnit" },
934 { 0x5002, "exif:ResolutionYUnit" },
935 { 0x5003, "exif:ResolutionXLengthUnit" },
936 { 0x5004, "exif:ResolutionYLengthUnit" },
937 { 0x5005, "exif:PrintFlags" },
938 { 0x5006, "exif:PrintFlagsVersion" },
939 { 0x5007, "exif:PrintFlagsCrop" },
940 { 0x5008, "exif:PrintFlagsBleedWidth" },
941 { 0x5009, "exif:PrintFlagsBleedWidthScale" },
942 { 0x500A, "exif:HalftoneLPI" },
943 { 0x500B, "exif:HalftoneLPIUnit" },
944 { 0x500C, "exif:HalftoneDegree" },
945 { 0x500D, "exif:HalftoneShape" },
946 { 0x500E, "exif:HalftoneMisc" },
947 { 0x500F, "exif:HalftoneScreen" },
948 { 0x5010, "exif:JPEGQuality" },
949 { 0x5011, "exif:GridSize" },
950 { 0x5012, "exif:ThumbnailFormat" },
951 { 0x5013, "exif:ThumbnailWidth" },
952 { 0x5014, "exif:ThumbnailHeight" },
953 { 0x5015, "exif:ThumbnailColorDepth" },
954 { 0x5016, "exif:ThumbnailPlanes" },
955 { 0x5017, "exif:ThumbnailRawBytes" },
956 { 0x5018, "exif:ThumbnailSize" },
957 { 0x5019, "exif:ThumbnailCompressedSize" },
958 { 0x501a, "exif:ColorTransferFunction" },
959 { 0x501b, "exif:ThumbnailData" },
960 { 0x5020, "exif:ThumbnailImageWidth" },
961 { 0x5021, "exif:ThumbnailImageHeight" },
962 { 0x5022, "exif:ThumbnailBitsPerSample" },
963 { 0x5023, "exif:ThumbnailCompression" },
964 { 0x5024, "exif:ThumbnailPhotometricInterp" },
965 { 0x5025, "exif:ThumbnailImageDescription" },
966 { 0x5026, "exif:ThumbnailEquipMake" },
967 { 0x5027, "exif:ThumbnailEquipModel" },
968 { 0x5028, "exif:ThumbnailStripOffsets" },
969 { 0x5029, "exif:ThumbnailOrientation" },
970 { 0x502a, "exif:ThumbnailSamplesPerPixel" },
971 { 0x502b, "exif:ThumbnailRowsPerStrip" },
972 { 0x502c, "exif:ThumbnailStripBytesCount" },
973 { 0x502d, "exif:ThumbnailResolutionX" },
974 { 0x502e, "exif:ThumbnailResolutionY" },
975 { 0x502f, "exif:ThumbnailPlanarConfig" },
976 { 0x5030, "exif:ThumbnailResolutionUnit" },
977 { 0x5031, "exif:ThumbnailTransferFunction" },
978 { 0x5032, "exif:ThumbnailSoftwareUsed" },
979 { 0x5033, "exif:ThumbnailDateTime" },
980 { 0x5034, "exif:ThumbnailArtist" },
981 { 0x5035, "exif:ThumbnailWhitePoint" },
982 { 0x5036, "exif:ThumbnailPrimaryChromaticities" },
983 { 0x5037, "exif:ThumbnailYCbCrCoefficients" },
984 { 0x5038, "exif:ThumbnailYCbCrSubsampling" },
985 { 0x5039, "exif:ThumbnailYCbCrPositioning" },
986 { 0x503A, "exif:ThumbnailRefBlackWhite" },
987 { 0x503B, "exif:ThumbnailCopyRight" },
988 { 0x5090, "exif:LuminanceTable" },
989 { 0x5091, "exif:ChrominanceTable" },
990 { 0x5100, "exif:FrameDelay" },
991 { 0x5101, "exif:LoopCount" },
992 { 0x5110, "exif:PixelUnit" },
993 { 0x5111, "exif:PixelPerUnitX" },
994 { 0x5112, "exif:PixelPerUnitY" },
995 { 0x5113, "exif:PaletteHistogram" },
996 { 0x1000, "exif:RelatedImageFileFormat" },
997 { 0x1001, "exif:RelatedImageLength" },
998 { 0x1002, "exif:RelatedImageWidth" },
999 { 0x800d, "exif:ImageID" },
1000 { 0x80e3, "exif:Matteing" },
1001 { 0x80e4, "exif:DataType" },
1002 { 0x80e5, "exif:ImageDepth" },
1003 { 0x80e6, "exif:TileDepth" },
1004 { 0x828d, "exif:CFARepeatPatternDim" },
1005 { 0x828e, "exif:CFAPattern2" },
1006 { 0x828f, "exif:BatteryLevel" },
1007 { 0x8298, "exif:Copyright" },
1008 { 0x829a, "exif:ExposureTime" },
1009 { 0x829d, "exif:FNumber" },
1010 { 0x83bb, "exif:IPTC/NAA" },
1011 { 0x84e3, "exif:IT8RasterPadding" },
1012 { 0x84e5, "exif:IT8ColorTable" },
1013 { 0x8649, "exif:ImageResourceInformation" },
1014 { 0x8769, "exif:ExifOffset" },
1015 { 0x8773, "exif:InterColorProfile" },
1016 { 0x8822, "exif:ExposureProgram" },
1017 { 0x8824, "exif:SpectralSensitivity" },
1018 { 0x8825, "exif:GPSInfo" },
1019 { 0x8827, "exif:ISOSpeedRatings" },
1020 { 0x8828, "exif:OECF" },
1021 { 0x8829, "exif:Interlace" },
1022 { 0x882a, "exif:TimeZoneOffset" },
1023 { 0x882b, "exif:SelfTimerMode" },
1024 { 0x9000, "exif:ExifVersion" },
1025 { 0x9003, "exif:DateTimeOriginal" },
1026 { 0x9004, "exif:DateTimeDigitized" },
1027 { 0x9101, "exif:ComponentsConfiguration" },
1028 { 0x9102, "exif:CompressedBitsPerPixel" },
1029 { 0x9201, "exif:ShutterSpeedValue" },
1030 { 0x9202, "exif:ApertureValue" },
1031 { 0x9203, "exif:BrightnessValue" },
1032 { 0x9204, "exif:ExposureBiasValue" },
1033 { 0x9205, "exif:MaxApertureValue" },
1034 { 0x9206, "exif:SubjectDistance" },
1035 { 0x9207, "exif:MeteringMode" },
1036 { 0x9208, "exif:LightSource" },
1037 { 0x9209, "exif:Flash" },
1038 { 0x920a, "exif:FocalLength" },
1039 { 0x920b, "exif:FlashEnergy" },
1040 { 0x920c, "exif:SpatialFrequencyResponse" },
1041 { 0x920d, "exif:Noise" },
1042 { 0x9211, "exif:ImageNumber" },
1043 { 0x9212, "exif:SecurityClassification" },
1044 { 0x9213, "exif:ImageHistory" },
1045 { 0x9214, "exif:SubjectArea" },
1046 { 0x9215, "exif:ExposureIndex" },
1047 { 0x9216, "exif:TIFF-EPStandardID" },
1048 { 0x927c, "exif:MakerNote" },
1049 { 0x9C9b, "exif:WinXP-Title" },
1050 { 0x9C9c, "exif:WinXP-Comments" },
1051 { 0x9C9d, "exif:WinXP-Author" },
1052 { 0x9C9e, "exif:WinXP-Keywords" },
1053 { 0x9C9f, "exif:WinXP-Subject" },
1054 { 0x9286, "exif:UserComment" },
1055 { 0x9290, "exif:SubSecTime" },
1056 { 0x9291, "exif:SubSecTimeOriginal" },
1057 { 0x9292, "exif:SubSecTimeDigitized" },
1058 { 0xa000, "exif:FlashPixVersion" },
1059 { 0xa001, "exif:ColorSpace" },
1060 { 0xa002, "exif:ExifImageWidth" },
1061 { 0xa003, "exif:ExifImageLength" },
1062 { 0xa004, "exif:RelatedSoundFile" },
1063 { 0xa005, "exif:InteroperabilityOffset" },
1064 { 0xa20b, "exif:FlashEnergy" },
1065 { 0xa20c, "exif:SpatialFrequencyResponse" },
1066 { 0xa20d, "exif:Noise" },
1067 { 0xa20e, "exif:FocalPlaneXResolution" },
1068 { 0xa20f, "exif:FocalPlaneYResolution" },
1069 { 0xa210, "exif:FocalPlaneResolutionUnit" },
1070 { 0xa214, "exif:SubjectLocation" },
1071 { 0xa215, "exif:ExposureIndex" },
1072 { 0xa216, "exif:TIFF/EPStandardID" },
1073 { 0xa217, "exif:SensingMethod" },
1074 { 0xa300, "exif:FileSource" },
1075 { 0xa301, "exif:SceneType" },
1076 { 0xa302, "exif:CFAPattern" },
1077 { 0xa401, "exif:CustomRendered" },
1078 { 0xa402, "exif:ExposureMode" },
1079 { 0xa403, "exif:WhiteBalance" },
1080 { 0xa404, "exif:DigitalZoomRatio" },
1081 { 0xa405, "exif:FocalLengthIn35mmFilm" },
1082 { 0xa406, "exif:SceneCaptureType" },
1083 { 0xa407, "exif:GainControl" },
1084 { 0xa408, "exif:Contrast" },
1085 { 0xa409, "exif:Saturation" },
1086 { 0xa40a, "exif:Sharpness" },
1087 { 0xa40b, "exif:DeviceSettingDescription" },
1088 { 0xa40c, "exif:SubjectDistanceRange" },
1089 { 0xa420, "exif:ImageUniqueID" },
1090 { 0xc4a5, "exif:PrintImageMatching" },
1091 { 0xa500, "exif:Gamma" },
1092 { 0xc640, "exif:CR2Slice" },
1093 { 0x10000, "exif:GPSVersionID" },
1094 { 0x10001, "exif:GPSLatitudeRef" },
1095 { 0x10002, "exif:GPSLatitude" },
1096 { 0x10003, "exif:GPSLongitudeRef" },
1097 { 0x10004, "exif:GPSLongitude" },
1098 { 0x10005, "exif:GPSAltitudeRef" },
1099 { 0x10006, "exif:GPSAltitude" },
1100 { 0x10007, "exif:GPSTimeStamp" },
1101 { 0x10008, "exif:GPSSatellites" },
1102 { 0x10009, "exif:GPSStatus" },
1103 { 0x1000a, "exif:GPSMeasureMode" },
1104 { 0x1000b, "exif:GPSDop" },
1105 { 0x1000c, "exif:GPSSpeedRef" },
1106 { 0x1000d, "exif:GPSSpeed" },
1107 { 0x1000e, "exif:GPSTrackRef" },
1108 { 0x1000f, "exif:GPSTrack" },
1109 { 0x10010, "exif:GPSImgDirectionRef" },
1110 { 0x10011, "exif:GPSImgDirection" },
1111 { 0x10012, "exif:GPSMapDatum" },
1112 { 0x10013, "exif:GPSDestLatitudeRef" },
1113 { 0x10014, "exif:GPSDestLatitude" },
1114 { 0x10015, "exif:GPSDestLongitudeRef" },
1115 { 0x10016, "exif:GPSDestLongitude" },
1116 { 0x10017, "exif:GPSDestBearingRef" },
1117 { 0x10018, "exif:GPSDestBearing" },
1118 { 0x10019, "exif:GPSDestDistanceRef" },
1119 { 0x1001a, "exif:GPSDestDistance" },
1120 { 0x1001b, "exif:GPSProcessingMethod" },
1121 { 0x1001c, "exif:GPSAreaInformation" },
1122 { 0x1001d, "exif:GPSDateStamp" },
1123 { 0x1001e, "exif:GPSDifferential" },
1124 { 0x00000, (const char *) NULL }
1135 directory_stack[MaxDirectoryStack];
1164 tag_bytes[] = {0, 1, 1, 2, 4, 8, 1, 1, 2, 4, 8, 4, 8};
1167 If EXIF data exists, then try to parse the request for a tag.
1169 profile=GetImageProfile(image,"exif");
1170 if (profile == (StringInfo *) NULL)
1171 return(MagickFalse);
1172 if ((property == (const char *) NULL) || (*property == '\0'))
1173 return(MagickFalse);
1174 while (isspace((int) ((unsigned char) *property)) != 0)
1178 switch (*(property+5))
1183 Caller has asked for all the tags in the EXIF data.
1186 all=1; /* return the data in description=value format */
1192 all=2; /* return the data in tagid=value format */
1205 Check for a hex based tag specification first.
1207 tag=(*(property+5) == '@') ? 1UL : 0UL;
1211 return(MagickFalse);
1213 Parse tag specification as a hex number.
1218 for (i=(ssize_t) n-1L; i >= 0; i--)
1222 if ((c >= '0') && (c <= '9'))
1225 if ((c >= 'A') && (c <= 'F'))
1228 if ((c >= 'a') && (c <= 'f'))
1231 return(MagickFalse);
1233 } while (*property != '\0');
1239 Try to match the text with a tag name instead.
1243 if (EXIFTag[i].tag == 0)
1245 if (LocaleCompare(EXIFTag[i].description,property) == 0)
1247 tag=(size_t) EXIFTag[i].tag;
1255 return(MagickFalse);
1256 length=GetStringInfoLength(profile);
1257 exif=GetStringInfoDatum(profile);
1260 if (ReadPropertyByte(&exif,&length) != 0x45)
1262 if (ReadPropertyByte(&exif,&length) != 0x78)
1264 if (ReadPropertyByte(&exif,&length) != 0x69)
1266 if (ReadPropertyByte(&exif,&length) != 0x66)
1268 if (ReadPropertyByte(&exif,&length) != 0x00)
1270 if (ReadPropertyByte(&exif,&length) != 0x00)
1275 return(MagickFalse);
1276 id=(ssize_t) ((int) ReadPropertyShort(LSBEndian,exif));
1284 return(MagickFalse);
1285 if (ReadPropertyShort(endian,exif+2) != 0x002a)
1286 return(MagickFalse);
1288 This the offset to the first IFD.
1290 offset=(ssize_t) ((int) ReadPropertyLong(endian,exif+4));
1291 if ((offset < 0) || (size_t) offset >= length)
1292 return(MagickFalse);
1294 Set the pointer to the first IFD and follow it were it leads.
1297 directory=exif+offset;
1301 exif_resources=NewSplayTree((int (*)(const void *,const void *)) NULL,
1302 (void *(*)(void *)) NULL,(void *(*)(void *)) NULL);
1306 If there is anything on the stack then pop it off.
1311 directory=directory_stack[level].directory;
1312 entry=directory_stack[level].entry;
1313 tag_offset=directory_stack[level].offset;
1316 Determine how many entries there are in the current IFD.
1318 number_entries=(size_t) ((int) ReadPropertyShort(endian,directory));
1319 for ( ; entry < number_entries; entry++)
1321 register unsigned char
1332 q=(unsigned char *) (directory+(12*entry)+2);
1333 if (GetValueFromSplayTree(exif_resources,q) == q)
1335 (void) AddValueToSplayTree(exif_resources,q,q);
1336 tag_value=(ssize_t) ((int) ReadPropertyShort(endian,q)+tag_offset);
1337 format=(size_t) ((int) ReadPropertyShort(endian,q+2));
1338 if (format >= (sizeof(tag_bytes)/sizeof(*tag_bytes)))
1340 components=(ssize_t) ((int) ReadPropertyLong(endian,q+4));
1341 number_bytes=(size_t) components*tag_bytes[format];
1342 if (number_bytes < components)
1343 break; /* prevent overflow */
1344 if (number_bytes <= 4)
1352 The directory entry contains an offset.
1354 offset=(ssize_t) ((int) ReadPropertyLong(endian,q+8));
1355 if ((offset < 0) || (size_t) offset >= length)
1357 if ((ssize_t) (offset+number_bytes) < offset)
1358 continue; /* prevent overflow */
1359 if ((size_t) (offset+number_bytes) > length)
1361 p=(unsigned char *) (exif+offset);
1363 if ((all != 0) || (tag == (size_t) tag_value))
1366 buffer[MaxTextExtent],
1369 value=(char *) NULL;
1374 case EXIF_FMT_UNDEFINED:
1376 EXIFMultipleValues(1,"%.20g",(double) (*(unsigned char *) p1));
1379 case EXIF_FMT_SBYTE:
1381 EXIFMultipleValues(1,"%.20g",(double) (*(signed char *) p1));
1384 case EXIF_FMT_SSHORT:
1386 EXIFMultipleValues(2,"%hd",ReadPropertyShort(endian,p1));
1389 case EXIF_FMT_USHORT:
1391 EXIFMultipleValues(2,"%hu",ReadPropertyShort(endian,p1));
1394 case EXIF_FMT_ULONG:
1396 EXIFMultipleValues(4,"%.20g",(double)
1397 ((int) ReadPropertyLong(endian,p1)));
1400 case EXIF_FMT_SLONG:
1402 EXIFMultipleValues(4,"%.20g",(double)
1403 ((int) ReadPropertyLong(endian,p1)));
1406 case EXIF_FMT_URATIONAL:
1408 EXIFMultipleFractions(8,"%.20g/%.20g",(double)
1409 ((int) ReadPropertyLong(endian,p1)),(double)
1410 ((int) ReadPropertyLong(endian,p1+4)));
1413 case EXIF_FMT_SRATIONAL:
1415 EXIFMultipleFractions(8,"%.20g/%.20g",(double)
1416 ((int) ReadPropertyLong(endian,p1)),(double)
1417 ((int) ReadPropertyLong(endian,p1+4)));
1420 case EXIF_FMT_SINGLE:
1422 EXIFMultipleValues(4,"%f",(double) *(float *) p1);
1425 case EXIF_FMT_DOUBLE:
1427 EXIFMultipleValues(8,"%f",*(double *) p1);
1431 case EXIF_FMT_STRING:
1433 value=(char *) NULL;
1434 if (~((size_t) number_bytes) >= 1)
1435 value=(char *) AcquireQuantumMemory((size_t) number_bytes+1UL,
1437 if (value != (char *) NULL)
1442 for (i=0; i < (ssize_t) number_bytes; i++)
1445 if ((isprint((int) p[i]) != 0) || (p[i] == '\0'))
1446 value[i]=(char) p[i];
1453 if (value != (char *) NULL)
1461 key=AcquireString(property);
1463 (void) SubstituteString(&key,"exif:","exif:thumbnail:");
1474 description="unknown";
1477 if (EXIFTag[i].tag == 0)
1479 if ((ssize_t) EXIFTag[i].tag == tag_value)
1481 description=EXIFTag[i].description;
1485 (void) FormatLocaleString(key,MaxTextExtent,"%s",description);
1490 if (tag_value < 0x10000)
1491 (void) FormatLocaleString(key,MaxTextExtent,"#%04lx",
1492 (unsigned long) tag_value);
1494 if (tag_value < 0x20000)
1495 (void) FormatLocaleString(key,MaxTextExtent,"@%04lx",
1496 (unsigned long) (tag_value & 0xffff));
1498 (void) FormatLocaleString(key,MaxTextExtent,"unknown");
1502 p=(const char *) NULL;
1503 if (image->properties != (void *) NULL)
1504 p=(const char *) GetValueFromSplayTree((SplayTreeInfo *)
1505 image->properties,key);
1506 if (p == (const char *) NULL)
1507 (void) SetImageProperty((Image *) image,key,value,exception);
1508 value=DestroyString(value);
1509 key=DestroyString(key);
1513 if ((tag_value == TAG_EXIF_OFFSET) ||
1514 (tag_value == TAG_INTEROP_OFFSET) || (tag_value == TAG_GPS_OFFSET))
1519 offset=(ssize_t) ((int) ReadPropertyLong(endian,p));
1520 if (((size_t) offset < length) && (level < (MaxDirectoryStack-2)))
1525 tag_offset1=(ssize_t) ((tag_value == TAG_GPS_OFFSET) ? 0x10000 :
1527 directory_stack[level].directory=directory;
1529 directory_stack[level].entry=entry;
1530 directory_stack[level].offset=tag_offset;
1532 directory_stack[level].directory=exif+offset;
1533 directory_stack[level].offset=tag_offset1;
1534 directory_stack[level].entry=0;
1536 if ((directory+2+(12*number_entries)) > (exif+length))
1538 offset=(ssize_t) ((int) ReadPropertyLong(endian,directory+2+(12*
1540 if ((offset != 0) && ((size_t) offset < length) &&
1541 (level < (MaxDirectoryStack-2)))
1543 directory_stack[level].directory=exif+offset;
1544 directory_stack[level].entry=0;
1545 directory_stack[level].offset=tag_offset1;
1552 } while (level > 0);
1553 exif_resources=DestroySplayTree(exif_resources);
1557 static MagickBooleanType GetICCProperty(const Image *image,const char *property,
1558 ExceptionInfo *exception)
1563 magick_unreferenced(property);
1565 profile=GetImageProfile(image,"icc");
1566 if (profile == (StringInfo *) NULL)
1567 profile=GetImageProfile(image,"icm");
1568 if (profile == (StringInfo *) NULL)
1569 return(MagickFalse);
1570 if (GetStringInfoLength(profile) < 128)
1571 return(MagickFalse); /* minimum ICC profile length */
1572 #if defined(MAGICKCORE_LCMS_DELEGATE)
1577 icc_profile=cmsOpenProfileFromMem(GetStringInfoDatum(profile),
1578 (cmsUInt32Number) GetStringInfoLength(profile));
1579 if (icc_profile != (cmsHPROFILE *) NULL)
1581 #if defined(LCMS_VERSION) && (LCMS_VERSION < 2000)
1585 name=cmsTakeProductName(icc_profile);
1586 if (name != (const char *) NULL)
1587 (void) SetImageProperty((Image *) image,"icc:name",name,exception);
1590 info[MaxTextExtent];
1592 (void) cmsGetProfileInfoASCII(icc_profile,cmsInfoDescription,
1593 "en","US",info,MaxTextExtent);
1594 (void) SetImageProperty((Image *) image,"icc:description",info,
1596 (void) cmsGetProfileInfoASCII(icc_profile,cmsInfoManufacturer,
1597 "en","US",info,MaxTextExtent);
1598 (void) SetImageProperty((Image *) image,"icc:manufacturer",info,
1600 (void) cmsGetProfileInfoASCII(icc_profile,cmsInfoModel,"en",
1601 "US",info,MaxTextExtent);
1602 (void) SetImageProperty((Image *) image,"icc:model",info,exception);
1603 (void) cmsGetProfileInfoASCII(icc_profile,cmsInfoCopyright,
1604 "en","US",info,MaxTextExtent);
1605 (void) SetImageProperty((Image *) image,"icc:copyright",info,exception);
1607 (void) cmsCloseProfile(icc_profile);
1614 static MagickBooleanType SkipXMPValue(const char *value)
1616 if (value == (const char*) NULL)
1618 while (*value != '\0')
1620 if (isspace((int) ((unsigned char) *value)) == 0)
1621 return(MagickFalse);
1627 static MagickBooleanType GetXMPProperty(const Image *image,const char *property)
1654 profile=GetImageProfile(image,"xmp");
1655 if (profile == (StringInfo *) NULL)
1656 return(MagickFalse);
1657 if ((property == (const char *) NULL) || (*property == '\0'))
1658 return(MagickFalse);
1659 xmp_profile=StringInfoToString(profile);
1660 if (xmp_profile == (char *) NULL)
1661 return(MagickFalse);
1662 for (p=xmp_profile; *p != '\0'; p++)
1663 if ((*p == '<') && (*(p+1) == 'x'))
1665 exception=AcquireExceptionInfo();
1666 xmp=NewXMLTree((char *) p,exception);
1667 xmp_profile=DestroyString(xmp_profile);
1668 exception=DestroyExceptionInfo(exception);
1669 if (xmp == (XMLTreeInfo *) NULL)
1670 return(MagickFalse);
1672 rdf=GetXMLTreeChild(xmp,"rdf:RDF");
1673 if (rdf != (XMLTreeInfo *) NULL)
1675 if (image->properties == (void *) NULL)
1676 ((Image *) image)->properties=NewSplayTree(CompareSplayTreeString,
1677 RelinquishMagickMemory,RelinquishMagickMemory);
1678 description=GetXMLTreeChild(rdf,"rdf:Description");
1679 while (description != (XMLTreeInfo *) NULL)
1681 node=GetXMLTreeChild(description,(const char *) NULL);
1682 while (node != (XMLTreeInfo *) NULL)
1684 child=GetXMLTreeChild(node,(const char *) NULL);
1685 content=GetXMLTreeContent(node);
1686 if ((child == (XMLTreeInfo *) NULL) &&
1687 (SkipXMPValue(content) == MagickFalse))
1688 (void) AddValueToSplayTree((SplayTreeInfo *) image->properties,
1689 ConstantString(GetXMLTreeTag(node)),ConstantString(content));
1690 while (child != (XMLTreeInfo *) NULL)
1692 content=GetXMLTreeContent(child);
1693 if (SkipXMPValue(content) == MagickFalse)
1694 (void) AddValueToSplayTree((SplayTreeInfo *) image->properties,
1695 ConstantString(GetXMLTreeTag(child)),ConstantString(content));
1696 child=GetXMLTreeSibling(child);
1698 node=GetXMLTreeSibling(node);
1700 description=GetNextXMLTreeTag(description);
1703 xmp=DestroyXMLTree(xmp);
1707 static char *TracePSClippath(const unsigned char *blob,size_t length,
1708 const size_t magick_unused(columns),const size_t magick_unused(rows))
1731 path=AcquireString((char *) NULL);
1732 if (path == (char *) NULL)
1733 return((char *) NULL);
1734 message=AcquireString((char *) NULL);
1735 (void) FormatLocaleString(message,MaxTextExtent,"/ClipImage\n");
1736 (void) ConcatenateString(&path,message);
1737 (void) FormatLocaleString(message,MaxTextExtent,"{\n");
1738 (void) ConcatenateString(&path,message);
1739 (void) FormatLocaleString(message,MaxTextExtent," /c {curveto} bind def\n");
1740 (void) ConcatenateString(&path,message);
1741 (void) FormatLocaleString(message,MaxTextExtent," /l {lineto} bind def\n");
1742 (void) ConcatenateString(&path,message);
1743 (void) FormatLocaleString(message,MaxTextExtent," /m {moveto} bind def\n");
1744 (void) ConcatenateString(&path,message);
1745 (void) FormatLocaleString(message,MaxTextExtent,
1746 " /v {currentpoint 6 2 roll curveto} bind def\n");
1747 (void) ConcatenateString(&path,message);
1748 (void) FormatLocaleString(message,MaxTextExtent,
1749 " /y {2 copy curveto} bind def\n");
1750 (void) ConcatenateString(&path,message);
1751 (void) FormatLocaleString(message,MaxTextExtent,
1752 " /z {closepath} bind def\n");
1753 (void) ConcatenateString(&path,message);
1754 (void) FormatLocaleString(message,MaxTextExtent," newpath\n");
1755 (void) ConcatenateString(&path,message);
1757 The clipping path format is defined in "Adobe Photoshop File
1758 Formats Specification" version 6.0 downloadable from adobe.com.
1760 (void) ResetMagickMemory(point,0,sizeof(point));
1761 (void) ResetMagickMemory(first,0,sizeof(first));
1762 (void) ResetMagickMemory(last,0,sizeof(last));
1764 in_subpath=MagickFalse;
1767 selector=(ssize_t) ((int) ReadPropertyMSBShort(&blob,&length));
1773 if (knot_count != 0)
1776 length-=MagickMin(24,(ssize_t) length);
1780 Expected subpath length record.
1782 knot_count=(ssize_t) ((int) ReadPropertyMSBShort(&blob,&length));
1784 length-=MagickMin(22,(ssize_t) length);
1792 if (knot_count == 0)
1795 Unexpected subpath knot
1798 length-=MagickMin(24,(ssize_t) length);
1804 for (i=0; i < 3; i++)
1810 yy=(size_t) ((int) ReadPropertyMSBLong(&blob,&length));
1811 xx=(size_t) ((int) ReadPropertyMSBLong(&blob,&length));
1813 if (xx > 2147483647)
1814 x=(ssize_t) xx-4294967295U-1;
1816 if (yy > 2147483647)
1817 y=(ssize_t) yy-4294967295U-1;
1818 point[i].x=(double) x/4096/4096;
1819 point[i].y=1.0-(double) y/4096/4096;
1821 if( IfMagickFalse(in_subpath) )
1823 (void) FormatLocaleString(message,MaxTextExtent," %g %g m\n",
1824 point[1].x,point[1].y);
1825 for (i=0; i < 3; i++)
1834 Handle special cases when Bezier curves are used to describe
1835 corners and straight lines.
1837 if ((last[1].x == last[2].x) && (last[1].y == last[2].y) &&
1838 (point[0].x == point[1].x) && (point[0].y == point[1].y))
1839 (void) FormatLocaleString(message,MaxTextExtent,
1840 " %g %g l\n",point[1].x,point[1].y);
1842 if ((last[1].x == last[2].x) && (last[1].y == last[2].y))
1843 (void) FormatLocaleString(message,MaxTextExtent,
1844 " %g %g %g %g v\n",point[0].x,point[0].y,
1845 point[1].x,point[1].y);
1847 if ((point[0].x == point[1].x) && (point[0].y == point[1].y))
1848 (void) FormatLocaleString(message,MaxTextExtent,
1849 " %g %g %g %g y\n",last[2].x,last[2].y,
1850 point[1].x,point[1].y);
1852 (void) FormatLocaleString(message,MaxTextExtent,
1853 " %g %g %g %g %g %g c\n",last[2].x,
1854 last[2].y,point[0].x,point[0].y,point[1].x,point[1].y);
1855 for (i=0; i < 3; i++)
1858 (void) ConcatenateString(&path,message);
1859 in_subpath=MagickTrue;
1862 Close the subpath if there are no more knots.
1864 if (knot_count == 0)
1867 Same special handling as above except we compare to the
1868 first point in the path and close the path.
1870 if ((last[1].x == last[2].x) && (last[1].y == last[2].y) &&
1871 (first[0].x == first[1].x) && (first[0].y == first[1].y))
1872 (void) FormatLocaleString(message,MaxTextExtent,
1873 " %g %g l z\n",first[1].x,first[1].y);
1875 if ((last[1].x == last[2].x) && (last[1].y == last[2].y))
1876 (void) FormatLocaleString(message,MaxTextExtent,
1877 " %g %g %g %g v z\n",first[0].x,first[0].y,
1878 first[1].x,first[1].y);
1880 if ((first[0].x == first[1].x) && (first[0].y == first[1].y))
1881 (void) FormatLocaleString(message,MaxTextExtent,
1882 " %g %g %g %g y z\n",last[2].x,last[2].y,
1883 first[1].x,first[1].y);
1885 (void) FormatLocaleString(message,MaxTextExtent,
1886 " %g %g %g %g %g %g c z\n",last[2].x,
1887 last[2].y,first[0].x,first[0].y,first[1].x,first[1].y);
1888 (void) ConcatenateString(&path,message);
1889 in_subpath=MagickFalse;
1899 length-=MagickMin(24,(ssize_t) length);
1905 Returns an empty PS path if the path has no knots.
1907 (void) FormatLocaleString(message,MaxTextExtent," eoclip\n");
1908 (void) ConcatenateString(&path,message);
1909 (void) FormatLocaleString(message,MaxTextExtent,"} bind def");
1910 (void) ConcatenateString(&path,message);
1911 message=DestroyString(message);
1915 static char *TraceSVGClippath(const unsigned char *blob,size_t length,
1916 const size_t columns,const size_t rows)
1939 path=AcquireString((char *) NULL);
1940 if (path == (char *) NULL)
1941 return((char *) NULL);
1942 message=AcquireString((char *) NULL);
1943 (void) FormatLocaleString(message,MaxTextExtent,
1944 ("<?xml version=\"1.0\" encoding=\"iso-8859-1\"?>\n"
1945 "<svg xmlns=\"http://www.w3.org/2000/svg\""
1946 " width=\"%.20g\" height=\"%.20g\">\n"
1948 "<path fill-rule=\"evenodd\" style=\"fill:#00000000;stroke:#00000000;"
1949 "stroke-width:0;stroke-antialiasing:false\" d=\"\n"),
1950 (double) columns,(double) rows);
1951 (void) ConcatenateString(&path,message);
1952 (void) ResetMagickMemory(point,0,sizeof(point));
1953 (void) ResetMagickMemory(first,0,sizeof(first));
1954 (void) ResetMagickMemory(last,0,sizeof(last));
1956 in_subpath=MagickFalse;
1959 selector=(ssize_t) ((int) ReadPropertyMSBShort(&blob,&length));
1965 if (knot_count != 0)
1968 length-=MagickMin(24,(ssize_t) length);
1972 Expected subpath length record.
1974 knot_count=(ssize_t) ((int) ReadPropertyMSBShort(&blob,&length));
1976 length-=MagickMin(22,(ssize_t) length);
1984 if (knot_count == 0)
1987 Unexpected subpath knot.
1990 length-=MagickMin(24,(ssize_t) length);
1996 for (i=0; i < 3; i++)
2002 yy=(unsigned int) ((int) ReadPropertyMSBLong(&blob,&length));
2003 xx=(unsigned int) ((int) ReadPropertyMSBLong(&blob,&length));
2005 if (xx > 2147483647)
2006 x=(ssize_t) xx-4294967295U-1;
2008 if (yy > 2147483647)
2009 y=(ssize_t) yy-4294967295U-1;
2010 point[i].x=(double) x*columns/4096/4096;
2011 point[i].y=(double) y*rows/4096/4096;
2013 if (in_subpath == MagickFalse)
2015 (void) FormatLocaleString(message,MaxTextExtent,"M %g %g\n",
2016 point[1].x,point[1].y);
2017 for (i=0; i < 3; i++)
2026 Handle special cases when Bezier curves are used to describe
2027 corners and straight lines.
2029 if ((last[1].x == last[2].x) && (last[1].y == last[2].y) &&
2030 (point[0].x == point[1].x) && (point[0].y == point[1].y))
2031 (void) FormatLocaleString(message,MaxTextExtent,
2032 "L %g %g\n",point[1].x,point[1].y);
2034 (void) FormatLocaleString(message,MaxTextExtent,
2035 "C %g %g %g %g %g %g\n",last[2].x,
2036 last[2].y,point[0].x,point[0].y,point[1].x,point[1].y);
2037 for (i=0; i < 3; i++)
2040 (void) ConcatenateString(&path,message);
2041 in_subpath=MagickTrue;
2044 Close the subpath if there are no more knots.
2046 if (knot_count == 0)
2049 Same special handling as above except we compare to the
2050 first point in the path and close the path.
2052 if ((last[1].x == last[2].x) && (last[1].y == last[2].y) &&
2053 (first[0].x == first[1].x) && (first[0].y == first[1].y))
2054 (void) FormatLocaleString(message,MaxTextExtent,
2055 "L %g %g Z\n",first[1].x,first[1].y);
2057 (void) FormatLocaleString(message,MaxTextExtent,
2058 "C %g %g %g %g %g %g Z\n",last[2].x,
2059 last[2].y,first[0].x,first[0].y,first[1].x,first[1].y);
2060 (void) ConcatenateString(&path,message);
2061 in_subpath=MagickFalse;
2071 length-=MagickMin(24,(ssize_t) length);
2077 Return an empty SVG image if the path does not have knots.
2079 (void) ConcatenateString(&path,"\"/>\n</g>\n</svg>\n");
2080 message=DestroyString(message);
2084 MagickExport const char *GetImageProperty(const Image *image,
2085 const char *property,ExceptionInfo *exception)
2090 assert(image != (Image *) NULL);
2091 assert(image->signature == MagickSignature);
2092 if (IfMagickTrue(image->debug))
2093 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
2094 p=(const char *) NULL;
2095 if (image->properties != (void *) NULL)
2097 if (property == (const char *) NULL)
2099 ResetSplayTreeIterator((SplayTreeInfo *) image->properties);
2100 p=(const char *) GetNextValueInSplayTree((SplayTreeInfo *)
2104 p=(const char *) GetValueFromSplayTree((SplayTreeInfo *)
2105 image->properties,property);
2106 if (p != (const char *) NULL)
2109 if ((property == (const char *) NULL) ||
2110 (strchr(property,':') == (char *) NULL))
2116 if (LocaleNCompare("8bim:",property,5) == 0)
2118 (void) Get8BIMProperty(image,property,exception);
2126 if (LocaleNCompare("exif:",property,5) == 0)
2128 (void) GetEXIFProperty(image,property,exception);
2136 if ((LocaleNCompare("icc:",property,4) == 0) ||
2137 (LocaleNCompare("icm:",property,4) == 0))
2139 (void) GetICCProperty(image,property,exception);
2142 if (LocaleNCompare("iptc:",property,5) == 0)
2144 (void) GetIPTCProperty(image,property,exception);
2152 if (LocaleNCompare("xmp:",property,4) == 0)
2154 (void) GetXMPProperty(image,property);
2162 if (image->properties != (void *) NULL)
2164 p=(const char *) GetValueFromSplayTree((SplayTreeInfo *)
2165 image->properties,property);
2168 return((const char *) NULL);
2172 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2176 + G e t M a g i c k P r o p e r t y %
2180 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2182 % GetMagickProperty() gets attributes or calculated values that is associated
2183 % with a fixed known property name, or single letter property. It may be
2184 % called if no image is defined (IMv7), in which case only global image_info
2185 % values are available.
2187 % This routine only handles specifically known properties. It does not
2188 % handle special prefixed properties, profiles, or expressions. Nor does
2189 % it return any free-form property strings.
2191 % The returned string is stored in a structure somewhere, and should not be
2192 % directly freed. If the string was generated (common) the string will be
2193 % stored as as either as artifact or option 'get-property'. These may be
2194 % deleted (cleaned up) when no longer required, but neither artifact or
2195 % option is guranteed to exist.
2197 % The format of the GetMagickProperty method is:
2199 % const char *GetMagickProperty(ImageInfo *image_info,Image *image,
2200 % const char *property,ExceptionInfo *exception)
2202 % A description of each parameter follows:
2204 % o image_info: the image info (optional)
2206 % o image: the image (optional)
2210 % o exception: return any errors or warnings in this structure.
2213 #define WarnNoImageReturn(format,arg) \
2214 if (image == (Image *) NULL ) { \
2215 (void) ThrowMagickException(exception,GetMagickModule(),OptionWarning, \
2216 "NoImageForProperty",format,arg); \
2217 return((const char *)NULL); \
2219 #define WarnNoImageInfoReturn(format,arg) \
2220 if (image_info == (ImageInfo *) NULL ) { \
2221 (void) ThrowMagickException(exception,GetMagickModule(),OptionWarning, \
2222 "NoImageInfoForProperty",format,arg); \
2223 return((const char *)NULL); \
2226 static const char *GetMagickPropertyLetter(ImageInfo *image_info,
2227 Image *image,const char letter,ExceptionInfo *exception)
2230 value[MaxTextExtent]; /* formated string to store as a returned artifact */
2233 *string; /* return a string already stored somewher */
2235 if (image != (Image *) NULL && IfMagickTrue(image->debug))
2236 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
2237 else if( image_info != (ImageInfo *) NULL && IfMagickTrue(image_info->debug))
2238 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s","no-images");
2240 *value='\0'; /* formatted string */
2241 string=(char *) NULL; /* constant string reference */
2243 /* Get properities that are directly defined by images */
2246 case 'b': /* image size read in - in bytes */
2248 WarnNoImageReturn("\"%%%c\"",letter);
2249 (void) FormatLocaleString(value,MaxTextExtent,"%.20g",(double)
2250 ((MagickOffsetType) image->extent));
2251 if (image->extent != (MagickSizeType) ((size_t) image->extent))
2252 (void) FormatMagickSize(image->extent,MagickFalse,value);
2253 ConcatenateMagickString(value,"B",MaxTextExtent);
2256 case 'c': /* image comment property - empty string by default */
2258 WarnNoImageReturn("\"%%%c\"",letter);
2259 string=GetImageProperty(image,"comment",exception);
2260 if ( string == (const char *) NULL )
2264 case 'd': /* Directory component of filename */
2266 WarnNoImageReturn("\"%%%c\"",letter);
2267 GetPathComponent(image->magick_filename,HeadPath,value);
2268 if (*value == '\0') string="";
2271 case 'e': /* Filename extension (suffix) of image file */
2273 WarnNoImageReturn("\"%%%c\"",letter);
2274 GetPathComponent(image->magick_filename,ExtensionPath,value);
2275 if (*value == '\0') string="";
2278 case 'f': /* Filename without directory component */
2280 WarnNoImageReturn("\"%%%c\"",letter);
2281 GetPathComponent(image->magick_filename,TailPath,value);
2282 if (*value == '\0') string="";
2285 case 'g': /* Image geometry, canvas and offset %Wx%H+%X+%Y */
2287 WarnNoImageReturn("\"%%%c\"",letter);
2288 (void) FormatLocaleString(value,MaxTextExtent,"%.20gx%.20g%+.20g%+.20g",
2289 (double) image->page.width,(double) image->page.height,
2290 (double) image->page.x,(double) image->page.y);
2293 case 'h': /* Image height (current) */
2295 WarnNoImageReturn("\"%%%c\"",letter);
2296 (void) FormatLocaleString(value,MaxTextExtent,"%.20g",(double)
2297 (image->rows != 0 ? image->rows : image->magick_rows));
2300 case 'i': /* Filename last used for an image (read or write) */
2302 WarnNoImageReturn("\"%%%c\"",letter);
2303 string=image->filename;
2306 case 'k': /* Number of unique colors */
2309 FUTURE: ensure this does not generate the formatted comment!
2311 WarnNoImageReturn("\"%%%c\"",letter);
2312 (void) FormatLocaleString(value,MaxTextExtent,"%.20g",(double)
2313 GetNumberColors(image,(FILE *) NULL,exception));
2316 case 'l': /* Image label property - empty string by default */
2318 WarnNoImageReturn("\"%%%c\"",letter);
2319 string=GetImageProperty(image,"label",exception);
2320 if ( string == (const char *) NULL)
2324 case 'm': /* Image format (file magick) */
2326 WarnNoImageReturn("\"%%%c\"",letter);
2327 string=image->magick;
2330 case 'n': /* Number of images in the list. */
2332 if ( image != (Image *) NULL )
2333 (void) FormatLocaleString(value,MaxTextExtent,"%.20g",(double)
2334 GetImageListLength(image));
2336 string="0"; /* no images or scenes */
2339 case 'o': /* Output Filename - for delegate use only */
2340 WarnNoImageInfoReturn("\"%%%c\"",letter);
2341 string=image_info->filename;
2343 case 'p': /* Image index in current image list */
2345 WarnNoImageReturn("\"%%%c\"",letter);
2346 (void) FormatLocaleString(value,MaxTextExtent,"%.20g",(double)
2347 GetImageIndexInList(image));
2350 case 'q': /* Quantum depth of image in memory */
2352 WarnNoImageReturn("\"%%%c\"",letter);
2353 (void) FormatLocaleString(value,MaxTextExtent,"%.20g",(double)
2354 MAGICKCORE_QUANTUM_DEPTH);
2357 case 'r': /* Image storage class, colorspace, and alpha enabled. */
2362 WarnNoImageReturn("\"%%%c\"",letter);
2363 colorspace=image->colorspace;
2364 if (IfMagickTrue(IsImageGray(image,exception)))
2365 colorspace=GRAYColorspace; /* FUTURE: this is IMv6 not IMv7 */
2366 (void) FormatLocaleString(value,MaxTextExtent,"%s %s %s",
2367 CommandOptionToMnemonic(MagickClassOptions,(ssize_t) image->storage_class),
2368 CommandOptionToMnemonic(MagickColorspaceOptions,(ssize_t) colorspace),
2369 image->alpha_trait == BlendPixelTrait ? "Alpha" : "");
2372 case 's': /* Image scene number */
2374 #if 0 /* this seems non-sensical -- simplifing */
2375 if (image_info->number_scenes != 0)
2376 (void) FormatLocaleString(value,MaxTextExtent,"%.20g",(double)
2378 else if (image != (Image *)NULL)
2379 (void) FormatLocaleString(value,MaxTextExtent,"%.20g",(double)
2384 WarnNoImageReturn("\"%%%c\"",letter);
2385 (void) FormatLocaleString(value,MaxTextExtent,"%.20g",(double)
2390 case 't': /* Base filename without directory or extention */
2392 WarnNoImageReturn("\"%%%c\"",letter);
2393 GetPathComponent(image->magick_filename,BasePath,value);
2394 if (*value == '\0') string="";
2397 case 'u': /* Unique filename */
2398 WarnNoImageInfoReturn("\"%%%c\"",letter);
2399 string=image_info->unique;
2401 case 'w': /* Image width (current) */
2403 WarnNoImageReturn("\"%%%c\"",letter);
2404 (void) FormatLocaleString(value,MaxTextExtent,"%.20g",(double)
2405 (image->columns != 0 ? image->columns : image->magick_columns));
2408 case 'x': /* Image horizontal resolution (with units) */
2410 WarnNoImageReturn("\"%%%c\"",letter);
2411 (void) FormatLocaleString(value,MaxTextExtent,"%.20g",
2412 fabs(image->resolution.x) > MagickEpsilon ? image->resolution.x : 72.0);
2415 case 'y': /* Image vertical resolution (with units) */
2417 WarnNoImageReturn("\"%%%c\"",letter);
2418 (void) FormatLocaleString(value,MaxTextExtent,"%.20g",
2419 fabs(image->resolution.y) > MagickEpsilon ? image->resolution.y : 72.0);
2422 case 'z': /* Image depth as read in */
2424 WarnNoImageReturn("\"%%%c\"",letter);
2425 (void) FormatLocaleString(value,MaxTextExtent,"%.20g",
2426 (double) image->depth);
2429 case 'A': /* Image alpha channel */
2431 WarnNoImageReturn("\"%%%c\"",letter);
2432 string=CommandOptionToMnemonic(MagickBooleanOptions,
2433 (ssize_t) image->alpha_trait);
2436 case 'C': /* Image compression method. */
2438 WarnNoImageReturn("\"%%%c\"",letter);
2439 string=CommandOptionToMnemonic(MagickCompressOptions,
2440 (ssize_t) image->compression);
2443 case 'D': /* Image dispose method. */
2445 WarnNoImageReturn("\"%%%c\"",letter);
2446 string=CommandOptionToMnemonic(MagickDisposeOptions,
2447 (ssize_t) image->dispose);
2450 case 'G': /* Image size as geometry = "%wx%h" */
2452 WarnNoImageReturn("\"%%%c\"",letter);
2453 (void) FormatLocaleString(value,MaxTextExtent,"%.20gx%.20g",
2454 (double)image->magick_columns,(double) image->magick_rows);
2457 case 'H': /* layer canvas height */
2459 WarnNoImageReturn("\"%%%c\"",letter);
2460 (void) FormatLocaleString(value,MaxTextExtent,"%.20g",
2461 (double) image->page.height);
2464 case 'M': /* Magick filename - filename given incl. coder & read mods */
2466 WarnNoImageReturn("\"%%%c\"",letter);
2467 string=image->magick_filename;
2470 case 'O': /* layer canvas offset with sign = "+%X+%Y" */
2472 WarnNoImageReturn("\"%%%c\"",letter);
2473 (void) FormatLocaleString(value,MaxTextExtent,"%+ld%+ld",(long)
2474 image->page.x,(long) image->page.y);
2477 case 'P': /* layer canvas page size = "%Wx%H" */
2479 WarnNoImageReturn("\"%%%c\"",letter);
2480 (void) FormatLocaleString(value,MaxTextExtent,"%.20gx%.20g",
2481 (double) image->page.width,(double) image->page.height);
2484 case 'Q': /* image compression quality */
2486 WarnNoImageReturn("\"%%%c\"",letter);
2487 (void) FormatLocaleString(value,MaxTextExtent,"%.20g",(double)
2488 (image->quality == 0 ? 92 : image->quality));
2491 case 'S': /* Number of scenes in image list. */
2493 WarnNoImageInfoReturn("\"%%%c\"",letter);
2494 #if 0 /* What is this number? -- it makes no sense - simplifing */
2495 if (image_info->number_scenes == 0)
2496 string="2147483647";
2497 else if ( image != (Image *) NULL )
2498 (void) FormatLocaleString(value,MaxTextExtent,"%.20g",(double)
2499 image_info->scene+image_info->number_scenes);
2503 (void) FormatLocaleString(value,MaxTextExtent,"%.20g",(double)
2504 (image_info->number_scenes == 0 ? 2147483647 :
2505 image_info->number_scenes));
2509 case 'T': /* image time delay for animations */
2511 WarnNoImageReturn("\"%%%c\"",letter);
2512 (void) FormatLocaleString(value,MaxTextExtent,"%.20g",(double)
2516 case 'U': /* Image resolution units. */
2518 WarnNoImageReturn("\"%%%c\"",letter);
2519 string=CommandOptionToMnemonic(MagickResolutionOptions,
2520 (ssize_t) image->units);
2523 case 'W': /* layer canvas width */
2525 WarnNoImageReturn("\"%%%c\"",letter);
2526 (void) FormatLocaleString(value,MaxTextExtent,"%.20g",(double)
2530 case 'X': /* layer canvas X offset */
2532 WarnNoImageReturn("\"%%%c\"",letter);
2533 (void) FormatLocaleString(value,MaxTextExtent,"%+.20g",(double)
2537 case 'Y': /* layer canvas Y offset */
2539 WarnNoImageReturn("\"%%%c\"",letter);
2540 (void) FormatLocaleString(value,MaxTextExtent,"%+.20g",(double)
2544 case 'Z': /* Zero filename ??? */
2545 WarnNoImageInfoReturn("\"%%%c\"",letter);
2546 string=image_info->zero;
2548 case '%': /* percent escaped */
2551 case '@': /* Trim bounding box, without actually Trimming! */
2556 WarnNoImageReturn("\"%%%c\"",letter);
2557 page=GetImageBoundingBox(image,exception);
2558 (void) FormatLocaleString(value,MaxTextExtent,"%.20gx%.20g%+.20g%+.20g",
2559 (double) page.width,(double) page.height,(double) page.x,(double)
2568 WarnNoImageReturn("\"%%%c\"",letter);
2569 (void) SignatureImage(image,exception);
2570 string=GetImageProperty(image,"signature",exception);
2574 if (string != (char *) NULL)
2579 Create a cloned copy of result.
2581 if (image != (Image *)NULL)
2583 (void) SetImageArtifact(image,"get-property",value);
2584 return(GetImageArtifact(image,"get-property"));
2588 (void) SetImageOption(image_info,"get-property",value);
2589 return(GetImageOption(image_info,"get-property"));
2592 return((char *)NULL);
2595 MagickExport const char *GetMagickProperty(ImageInfo *image_info,
2596 Image *image,const char *property,ExceptionInfo *exception)
2599 value[MaxTextExtent];
2604 assert(property[0] != '\0');
2605 assert(image != (Image *)NULL || image_info != (ImageInfo *)NULL );
2607 if (property[1] == '\0') /* single letter property request */
2608 return(GetMagickPropertyLetter(image_info,image,*property,exception));
2610 if (image != (Image *) NULL && IfMagickTrue(image->debug))
2611 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
2612 else if( image_info != (ImageInfo *) NULL && IfMagickTrue(image_info->debug))
2613 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s","no-images");
2615 *value='\0'; /* formated string */
2616 string=(char *) NULL; /* constant string reference */
2621 if ((LocaleCompare("base",property) == 0) ||
2622 (LocaleCompare("basename",property) == 0) )
2624 WarnNoImageReturn("\"%%[%s]\"",property);
2625 GetPathComponent(image->magick_filename,BasePath,value);
2626 if (*value == '\0') string="";
2629 if (LocaleCompare("bit-depth",property) == 0)
2631 (void) FormatLocaleString(value,MaxTextExtent,"%.20g",(double)
2632 GetImageDepth(image, exception));
2639 if (LocaleCompare("channels",property) == 0)
2641 WarnNoImageReturn("\"%%[%s]\"",property);
2642 /* FUTURE: return actual image channels */
2643 (void) FormatLocaleString(value,MaxTextExtent,"%s",
2644 CommandOptionToMnemonic(MagickColorspaceOptions,(ssize_t)
2645 image->colorspace));
2647 if( image->alpha_trait == BlendPixelTrait )
2648 (void) ConcatenateMagickString(value,"a",MaxTextExtent);
2651 if (LocaleCompare("colorspace",property) == 0)
2653 WarnNoImageReturn("\"%%[%s]\"",property);
2654 /* FUTURE: return actual colorspace - no 'gray' stuff */
2655 string=CommandOptionToMnemonic(MagickColorspaceOptions,(ssize_t)
2659 if (LocaleCompare("copyright",property) == 0)
2661 (void) CopyMagickString(value,GetMagickCopyright(),MaxTextExtent);
2668 if (LocaleCompare("depth",property) == 0)
2670 WarnNoImageReturn("\"%%[%s]\"",property);
2671 (void) FormatLocaleString(value,MaxTextExtent,"%.20g",(double)
2675 if (LocaleCompare("directory",property) == 0)
2677 WarnNoImageReturn("\"%%[%s]\"",property);
2678 GetPathComponent(image->magick_filename,HeadPath,value);
2679 if (*value == '\0') string="";
2686 if (LocaleCompare("entropy",property) == 0)
2691 WarnNoImageReturn("\"%%[%s]\"",property);
2692 (void) GetImageEntropy(image,&entropy,exception);
2693 (void) FormatLocaleString(value,MaxTextExtent,"%.*g",
2694 GetMagickPrecision(),entropy);
2697 if (LocaleCompare("extension",property) == 0)
2699 WarnNoImageReturn("\"%%[%s]\"",property);
2700 GetPathComponent(image->magick_filename,ExtensionPath,value);
2701 if (*value == '\0') string="";
2708 if (LocaleCompare("gamma",property) == 0)
2710 WarnNoImageReturn("\"%%[%s]\"",property);
2711 (void) FormatLocaleString(value,MaxTextExtent,"%.*g",
2712 GetMagickPrecision(),image->gamma);
2715 if (LocaleCompare("group",property) == 0)
2717 WarnNoImageInfoReturn("\"%%[%s]\"",property);
2718 (void) FormatLocaleString(value,MaxTextExtent,"0x%lx",(unsigned long)
2726 if (LocaleCompare("height",property) == 0)
2728 WarnNoImageReturn("\"%%[%s]\"",property);
2729 (void) FormatLocaleString(value,MaxTextExtent,"%.20g",
2730 image->magick_rows != 0 ? (double) image->magick_rows : 256.0);
2737 if (LocaleCompare("input",property) == 0)
2739 WarnNoImageReturn("\"%%[%s]\"",property);
2740 string=image->filename;
2747 if (LocaleCompare("kurtosis",property) == 0)
2753 WarnNoImageReturn("\"%%[%s]\"",property);
2754 (void) GetImageKurtosis(image,&kurtosis,&skewness,exception);
2755 (void) FormatLocaleString(value,MaxTextExtent,"%.*g",
2756 GetMagickPrecision(),kurtosis);
2763 if (LocaleCompare("magick",property) == 0)
2765 WarnNoImageReturn("\"%%[%s]\"",property);
2766 string=image->magick;
2769 if (LocaleCompare("max",property) == 0)
2775 WarnNoImageReturn("\"%%[%s]\"",property);
2776 (void) GetImageRange(image,&minimum,&maximum,exception);
2777 (void) FormatLocaleString(value,MaxTextExtent,"%.*g",
2778 GetMagickPrecision(),maximum);
2781 if (LocaleCompare("mean",property) == 0)
2787 WarnNoImageReturn("\"%%[%s]\"",property);
2788 (void) GetImageMean(image,&mean,&standard_deviation,exception);
2789 (void) FormatLocaleString(value,MaxTextExtent,"%.*g",
2790 GetMagickPrecision(),mean);
2793 if (LocaleCompare("min",property) == 0)
2799 WarnNoImageReturn("\"%%[%s]\"",property);
2800 (void) GetImageRange(image,&minimum,&maximum,exception);
2801 (void) FormatLocaleString(value,MaxTextExtent,"%.*g",
2802 GetMagickPrecision(),minimum);
2809 if (LocaleCompare("opaque",property) == 0)
2811 WarnNoImageReturn("\"%%[%s]\"",property);
2812 string=CommandOptionToMnemonic(MagickBooleanOptions,
2813 (ssize_t) IsImageOpaque(image,exception));
2816 if (LocaleCompare("orientation",property) == 0)
2818 WarnNoImageReturn("\"%%[%s]\"",property);
2819 string=CommandOptionToMnemonic(MagickOrientationOptions,(ssize_t)
2820 image->orientation);
2823 if (LocaleCompare("output",property) == 0)
2825 WarnNoImageInfoReturn("\"%%[%s]\"",property);
2826 (void) CopyMagickString(value,image_info->filename,MaxTextExtent);
2833 #if defined(MAGICKCORE_LCMS_DELEGATE)
2834 if (LocaleCompare("profile:icc",property) == 0 ||
2835 LocaleCompare("profile:icm",property) == 0)
2837 #if !defined(LCMS_VERSION) || (LCMS_VERSION < 2000)
2838 #define cmsUInt32Number DWORD
2847 profile=GetImageProfile(image,property+8);
2848 if (profile == (StringInfo *) NULL)
2851 icc_profile=cmsOpenProfileFromMem(GetStringInfoDatum(profile),
2852 (cmsUInt32Number) GetStringInfoLength(profile));
2853 if (icc_profile != (cmsHPROFILE *) NULL)
2855 #if defined(LCMS_VERSION) && (LCMS_VERSION < 2000)
2856 string=cmsTakeProductName(icc_profile);
2858 (void) cmsGetProfileInfoASCII(icc_profile,cmsInfoDescription,
2859 "en","US",value,MaxTextExtent);
2861 (void) cmsCloseProfile(icc_profile);
2865 if (LocaleCompare("profiles",property) == 0)
2870 ResetImageProfileIterator(image);
2871 name=GetNextImageProfile(image);
2872 if (name != (char *) NULL)
2874 (void) CopyMagickString(value,name,MaxTextExtent);
2875 name=GetNextImageProfile(image);
2876 while (name != (char *) NULL)
2878 ConcatenateMagickString(value,",",MaxTextExtent);
2879 ConcatenateMagickString(value,name,MaxTextExtent);
2880 name=GetNextImageProfile(image);
2889 if (LocaleCompare("resolution.x",property) == 0)
2891 WarnNoImageReturn("\"%%[%s]\"",property);
2892 (void) FormatLocaleString(value,MaxTextExtent,"%g",
2893 image->resolution.x);
2896 if (LocaleCompare("resolution.y",property) == 0)
2898 WarnNoImageReturn("\"%%[%s]\"",property);
2899 (void) FormatLocaleString(value,MaxTextExtent,"%g",
2900 image->resolution.y);
2907 if (LocaleCompare("scene",property) == 0)
2909 WarnNoImageInfoReturn("\"%%[%s]\"",property);
2910 if (image_info->number_scenes != 0)
2911 (void) FormatLocaleString(value,MaxTextExtent,"%.20g",(double)
2914 WarnNoImageReturn("\"%%[%s]\"",property);
2915 (void) FormatLocaleString(value,MaxTextExtent,"%.20g",(double)
2920 if (LocaleCompare("scenes",property) == 0)
2922 /* FUTURE: equivelent to %n? */
2923 WarnNoImageReturn("\"%%[%s]\"",property);
2924 (void) FormatLocaleString(value,MaxTextExtent,"%.20g",(double)
2925 GetImageListLength(image));
2928 if (LocaleCompare("size",property) == 0)
2931 format[MaxTextExtent];
2933 WarnNoImageReturn("\"%%[%s]\"",property);
2934 (void) FormatMagickSize(GetBlobSize(image),MagickFalse,format);
2935 (void) FormatLocaleString(value,MaxTextExtent,"%sB",format);
2938 if (LocaleCompare("skewness",property) == 0)
2944 WarnNoImageReturn("\"%%[%s]\"",property);
2945 (void) GetImageKurtosis(image,&kurtosis,&skewness,exception);
2946 (void) FormatLocaleString(value,MaxTextExtent,"%.*g",
2947 GetMagickPrecision(),skewness);
2950 if ((LocaleCompare("standard-deviation",property) == 0) ||
2951 (LocaleCompare("standard_deviation",property) == 0))
2957 WarnNoImageReturn("\"%%[%s]\"",property);
2958 (void) GetImageMean(image,&mean,&standard_deviation,exception);
2959 (void) FormatLocaleString(value,MaxTextExtent,"%.*g",
2960 GetMagickPrecision(),standard_deviation);
2967 if (LocaleCompare("type",property) == 0)
2969 WarnNoImageReturn("\"%%[%s]\"",property);
2970 string=CommandOptionToMnemonic(MagickTypeOptions,(ssize_t)
2971 GetImageType(image,exception));
2978 if (LocaleCompare("unique",property) == 0)
2980 WarnNoImageInfoReturn("\"%%[%s]\"",property);
2981 string=image_info->unique;
2984 if (LocaleCompare("units",property) == 0)
2986 WarnNoImageReturn("\"%%[%s]\"",property);
2987 string=CommandOptionToMnemonic(MagickResolutionOptions,(ssize_t)
2991 if (LocaleCompare("copyright",property) == 0)
2996 if (LocaleCompare("version",property) == 0)
2998 string=GetMagickVersion((size_t *) NULL);
3005 if (LocaleCompare("width",property) == 0)
3007 WarnNoImageReturn("\"%%[%s]\"",property);
3008 (void) FormatLocaleString(value,MaxTextExtent,"%.20g",(double)
3009 (image->magick_columns != 0 ? image->magick_columns : 256));
3014 case 'x': /* FUTURE: Obsolete X resolution */
3016 if ((LocaleCompare("xresolution",property) == 0) ||
3017 (LocaleCompare("x-resolution",property) == 0) )
3019 WarnNoImageReturn("\"%%[%s]\"",property);
3020 (void) FormatLocaleString(value,MaxTextExtent,"%.20g",
3021 image->resolution.x);
3026 case 'y': /* FUTURE: Obsolete Y resolution */
3028 if ((LocaleCompare("yresolution",property) == 0) ||
3029 (LocaleCompare("y-resolution",property) == 0) )
3031 WarnNoImageReturn("\"%%[%s]\"",property);
3032 (void) FormatLocaleString(value,MaxTextExtent,"%.20g",
3033 image->resolution.y);
3040 if (LocaleCompare("zero",property) == 0)
3042 WarnNoImageInfoReturn("\"%%[%s]\"",property);
3043 string=image_info->zero;
3049 if (string != (char *) NULL)
3053 /* create a cloned copy of result, that will get cleaned up, eventually */
3054 if (image != (Image *)NULL)
3056 (void) SetImageArtifact(image,"get-property",value);
3057 return(GetImageArtifact(image,"get-property"));
3061 (void) SetImageOption(image_info,"get-property",value);
3062 return(GetImageOption(image_info,"get-property"));
3065 return((char *)NULL);
3067 #undef WarnNoImageReturn
3070 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3074 % G e t N e x t I m a g e P r o p e r t y %
3078 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3080 % GetNextImageProperty() gets the next free-form string property name.
3082 % The format of the GetNextImageProperty method is:
3084 % char *GetNextImageProperty(const Image *image)
3086 % A description of each parameter follows:
3088 % o image: the image.
3091 MagickExport char *GetNextImageProperty(const Image *image)
3093 assert(image != (Image *) NULL);
3094 assert(image->signature == MagickSignature);
3095 if (image->debug != MagickFalse)
3096 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
3098 if (image->properties == (void *) NULL)
3099 return((char *) NULL);
3100 return((char *) GetNextKeyInSplayTree((SplayTreeInfo *) image->properties));
3104 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3108 % I n t e r p r e t I m a g e P r o p e r t i e s %
3112 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3114 % InterpretImageProperties() replaces any embedded formatting characters with
3115 % the appropriate image property and returns the interpreted text.
3117 % This searches for and replaces
3118 % \n \r \% replaced by newline, return, and percent resp.
3119 % < > & replaced by '<', '>', '&' resp.
3120 % %% replaced by percent
3122 % %x %[x] where 'x' is a single letter properity, case sensitive).
3123 % %[type:name] where 'type' a is special and known prefix.
3124 % %[name] where 'name' is a specifically known attribute, calculated
3125 % value, or a per-image property string name, or a per-image
3126 % 'artifact' (as generated from a global option).
3127 % It may contain ':' as long as the prefix is not special.
3129 % Single letter % substitutions will only happen if the character before the
3130 % percent is NOT a number. But braced substitutions will always be performed.
3131 % This prevents the typical usage of percent in a interpreted geometry
3132 % argument from being substituted when the percent is a geometry flag.
3134 % If 'glob-expresions' ('*' or '?' characters) is used for 'name' it may be
3135 % used as a search pattern to print multiple lines of "name=value\n" pairs of
3136 % the associacted set of properties.
3138 % The returned string must be freed using DestoryString() by the caller.
3140 % The format of the InterpretImageProperties method is:
3142 % char *InterpretImageProperties(ImageInfo *image_info,
3143 % Image *image,const char *embed_text,ExceptionInfo *exception)
3145 % A description of each parameter follows:
3147 % o image_info: the image info. (required)
3149 % o image: the image. (optional)
3151 % o embed_text: the address of a character string containing the embedded
3152 % formatting characters.
3154 % o exception: return any errors or warnings in this structure.
3158 /* common inline code to expand the interpreted text string */
3159 #define ExtendInterpretText(string_length) do { \
3160 DisableMSCWarning(4127) \
3161 size_t length=(string_length); \
3162 if ((size_t) (q-interpret_text+length+1) >= extent) \
3164 interpret_text=(char *) ResizeQuantumMemory(interpret_text, \
3165 extent+MaxTextExtent,sizeof(*interpret_text)); \
3166 if (interpret_text == (char *) NULL) \
3167 return((char *)NULL); \
3168 q=interpret_text+strlen(interpret_text); \
3169 } } while (0) /* no trailing ; */ \
3172 /* same but append the given string */
3173 #define AppendString2Text(string) do { \
3174 DisableMSCWarning(4127) \
3175 size_t length=strlen((string)); \
3176 if ((size_t) (q-interpret_text+length+1) >= extent) \
3178 interpret_text=(char *) ResizeQuantumMemory(interpret_text, \
3179 extent+MaxTextExtent,sizeof(*interpret_text)); \
3180 if (interpret_text == (char *) NULL) \
3181 return((char *)NULL); \
3182 q=interpret_text+strlen(interpret_text); \
3184 (void) CopyMagickString(q,(string),extent); \
3186 } while (0) /* no trailing ; */ \
3189 /* same but append a 'key' and 'string' pair */
3190 #define AppendKeyValue2Text(key,string) do { \
3191 DisableMSCWarning(4127) \
3192 size_t length=strlen(key)+strlen(string)+2; \
3193 if ((size_t) (q-interpret_text+length+1) >= extent) \
3195 interpret_text=(char *) ResizeQuantumMemory(interpret_text, \
3196 extent+MaxTextExtent,sizeof(*interpret_text)); \
3197 if (interpret_text == (char *) NULL) \
3198 return((char *)NULL); \
3199 q=interpret_text+strlen(interpret_text); \
3201 q+=FormatLocaleString(q,extent,"%s=%s\n",(key),(string)); \
3202 } while (0) /* no trailing ; */ \
3205 MagickExport char *InterpretImageProperties(ImageInfo *image_info,
3206 Image *image,const char *embed_text,ExceptionInfo *exception)
3212 *q; /* current position in interpret_text */
3215 *p; /* position in embed_text string being expanded */
3218 extent; /* allocated length of interpret_text */
3223 assert(image == NULL || image->signature == MagickSignature);
3224 assert(image_info == NULL || image_info->signature == MagickSignature);
3226 if (image != (Image *) NULL && IfMagickTrue(image->debug))
3227 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
3228 else if( image_info != (ImageInfo *) NULL && IfMagickTrue(image_info->debug))
3229 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s","no-image");
3231 if (embed_text == (const char *) NULL)
3232 return((char *) NULL);
3236 return(ConstantString(""));
3238 /* handle a '@' replace string from file */
3241 if (*p != '-' && IfMagickFalse(IsPathAccessible(p)) ) {
3242 (void) ThrowMagickException(exception,GetMagickModule(),
3243 OptionError,"UnableToAccessPath","%s",p);
3244 return((char *) NULL);
3246 return(FileToString(p,~0UL,exception));
3250 Translate any embedded format characters.
3252 interpret_text=AcquireString(embed_text); /* new string with extra space */
3253 extent=MaxTextExtent; /* allocated space in string */
3254 number=MagickFalse; /* is last char a number? */
3255 for (q=interpret_text; *p!='\0'; number=IsMagickTrue(isdigit(*p)),p++)
3258 ExtendInterpretText(MaxTextExtent);
3260 Look for the various escapes, (and handle other specials)
3267 case 'r': /* convert to RETURN */
3271 case 'n': /* convert to NEWLINE */
3275 case '\n': /* EOL removal UNIX,MacOSX */
3278 case '\r': /* EOL removal DOS,Windows */
3280 if (*p == '\n') /* return-newline EOL */
3289 if (LocaleNCompare("<",p,4) == 0)
3291 else if (LocaleNCompare(">",p,4) == 0)
3293 else if (LocaleNCompare("&",p,5) == 0)
3299 break; /* continue to next set of handlers */
3301 *q++=(*p); /* any thing else is 'as normal' */
3304 p++; /* advance beyond the percent */
3307 Doubled Percent - or percent at end of string
3317 Single letter escapes %c
3323 /* But only if not preceeded by a number! */
3324 if ( IfMagickTrue(number) ) {
3325 *q++='%'; /* do NOT substitute the percent */
3326 p--; /* back up one */
3329 string=GetMagickPropertyLetter(image_info,image,*p, exception);
3330 if (string != (char *) NULL)
3332 AppendString2Text(string);
3333 if (image != (Image *) NULL)
3334 (void)DeleteImageArtifact(image,"get-property");
3335 if (image_info != (ImageInfo *) NULL)
3336 (void)DeleteImageOption(image_info,"get-property");
3339 (void) ThrowMagickException(exception,GetMagickModule(),OptionWarning,
3340 "UnknownImageProperty","\"%%%c\"",*p);
3345 Braced Percent Escape %[...]
3349 pattern[2*MaxTextExtent];
3361 /* get the property name framed by the %[...] */
3362 p++; /* advance p to just inside the opening brace */
3365 (void) ThrowMagickException(exception,GetMagickModule(),OptionWarning,
3366 "UnknownImageProperty","\"%%[]\"");
3369 for (len=0; len<(MaxTextExtent-1L) && (*p != '\0');)
3371 /* skip escaped braces within braced pattern */
3372 if ( (*p == '\\') && (*(p+1) != '\0') ) {
3373 pattern[len++]=(*p++);
3374 pattern[len++]=(*p++);
3383 pattern[len++]=(*p++);
3386 /* Check for unmatched final ']' for "%[...]" */
3388 if (len >= 64) { /* truncate string for error message */
3394 (void) ThrowMagickException(exception,GetMagickModule(),
3395 OptionError,"UnbalancedBraces","\"%%[%s\"",pattern);
3396 interpret_text=DestroyString(interpret_text);
3397 return((char *)NULL);
3401 Special Lookup Prefixes %[prefix:...]
3403 /* fx - value calculator */
3404 if (LocaleNCompare("fx:",pattern,3) == 0)
3415 if (image == (Image *) NULL ) {
3416 (void) ThrowMagickException(exception,GetMagickModule(),
3417 OptionWarning,"NoImageForProperty","\"%%[%s]\"",pattern);
3418 continue; /* else no image to retrieve artifact */
3420 fx_info=AcquireFxInfo(image,pattern+3,exception);
3421 status=FxEvaluateChannelExpression(fx_info,IntensityPixelChannel,0,0,
3423 fx_info=DestroyFxInfo(fx_info);
3424 if( IfMagickTrue(status) )
3427 result[MaxTextExtent];
3429 (void) FormatLocaleString(result,MaxTextExtent,"%.*g",
3430 GetMagickPrecision(),(double) value);
3431 AppendString2Text(result);
3435 /* pixel - color value calculator */
3436 if (LocaleNCompare("pixel:",pattern,6) == 0)
3450 if (image == (Image *) NULL ) {
3451 (void) ThrowMagickException(exception,GetMagickModule(),
3452 OptionWarning,"NoImageForProperty","\"%%[%s]\"",pattern);
3453 continue; /* else no image to retrieve artifact */
3455 GetPixelInfo(image,&pixel);
3456 fx_info=AcquireFxInfo(image,pattern+6,exception);
3457 status=FxEvaluateChannelExpression(fx_info,RedPixelChannel,0,0,
3459 pixel.red=(double) QuantumRange*value;
3460 status&=FxEvaluateChannelExpression(fx_info,GreenPixelChannel,0,0,
3462 pixel.green=(double) QuantumRange*value;
3463 status&=FxEvaluateChannelExpression(fx_info,BluePixelChannel,0,0,
3465 pixel.blue=(double) QuantumRange*value;
3466 if (image->colorspace == CMYKColorspace)
3468 status&=FxEvaluateChannelExpression(fx_info,BlackPixelChannel,0,0,
3470 pixel.black=(double) QuantumRange*value;
3472 status&=FxEvaluateChannelExpression(fx_info,AlphaPixelChannel,0,0,
3474 pixel.alpha=(double) QuantumRange*value;
3475 fx_info=DestroyFxInfo(fx_info);
3476 if( IfMagickTrue(status) )
3479 name[MaxTextExtent];
3481 (void) QueryColorname(image,&pixel,SVGCompliance,name,
3483 AppendString2Text(name);
3487 /* option - direct global option lookup (with globbing) */
3488 if (LocaleNCompare("option:",pattern,7) == 0)
3490 if (image_info == (ImageInfo *) NULL ) {
3491 (void) ThrowMagickException(exception,GetMagickModule(),
3492 OptionWarning,"NoImageForProperty","\"%%[%s]\"",pattern);
3493 continue; /* else no image to retrieve artifact */
3495 if( IfMagickTrue(IsGlob(pattern+7)) )
3497 ResetImageOptionIterator(image_info);
3498 while ((key=GetNextImageOption(image_info)) != (const char *) NULL)
3499 if( IfMagickTrue(GlobExpression(key,pattern+7,MagickTrue)) )
3501 string=GetImageOption(image_info,key);
3502 if (string != (const char *) NULL)
3503 AppendKeyValue2Text(key,string);
3504 /* else - assertion failure? key found but no string value! */
3508 string=GetImageOption(image_info,pattern+7);
3509 if (string == (char *) NULL)
3510 goto PropertyLookupFailure; /* no artifact of this specifc name */
3511 AppendString2Text(string);
3514 /* artifact - direct image artifact lookup (with glob) */
3515 if (LocaleNCompare("artifact:",pattern,9) == 0)
3517 if (image == (Image *) NULL ) {
3518 (void) ThrowMagickException(exception,GetMagickModule(),
3519 OptionWarning,"NoImageForProperty","\"%%[%s]\"",pattern);
3520 continue; /* else no image to retrieve artifact */
3522 if( IfMagickTrue(IsGlob(pattern+9)) )
3524 ResetImageArtifactIterator(image);
3525 while ((key=GetNextImageArtifact(image)) != (const char *) NULL)
3526 if( IfMagickTrue(GlobExpression(key,pattern+9,MagickTrue)) )
3528 string=GetImageArtifact(image,key);
3529 if (string != (const char *) NULL)
3530 AppendKeyValue2Text(key,string);
3531 /* else - assertion failure? key found but no string value! */
3535 string=GetImageArtifact(image,pattern+9);
3536 if (string == (char *) NULL)
3537 goto PropertyLookupFailure; /* no artifact of this specifc name */
3538 AppendString2Text(string);
3541 /* property - direct image property lookup (with glob) */
3542 if (LocaleNCompare("property:",pattern,9) == 0)
3544 if (image == (Image *) NULL ) {
3545 (void) ThrowMagickException(exception,GetMagickModule(),
3546 OptionWarning,"NoImageForProperty","\"%%[%s]\"",pattern);
3547 continue; /* else no image to retrieve artifact */
3549 if( IfMagickTrue(IsGlob(pattern+9)) )
3551 ResetImagePropertyIterator(image);
3552 while ((key=GetNextImageProperty(image)) != (const char *) NULL)
3553 if( IfMagickTrue(GlobExpression(key,pattern,MagickTrue)) )
3555 string=GetImageProperty(image,key,exception);
3556 if (string != (const char *) NULL)
3557 AppendKeyValue2Text(key,string);
3558 /* else - assertion failure? */
3562 string=GetImageProperty(image,pattern+9,exception);
3563 if (string == (char *) NULL)
3564 goto PropertyLookupFailure; /* no artifact of this specifc name */
3565 AppendString2Text(string);
3568 /* Properties without special prefix.
3569 This handles attributes, properties, and profiles such as %[exif:...]
3570 Note the profile properties may also include a glob expansion pattern.
3572 if ( image != (Image *)NULL )
3574 string=GetImageProperty(image,pattern,exception);
3575 if (string != (const char *) NULL)
3577 AppendString2Text(string);
3578 if (image != (Image *) NULL)
3579 (void)DeleteImageArtifact(image,"get-property");
3580 if (image_info != (ImageInfo *) NULL)
3581 (void)DeleteImageOption(image_info,"get-property");
3586 Handle property 'glob' patterns
3587 Such as: %[*] %[user:array_??] %[filename:e*]
3589 if( IfMagickTrue(IsGlob(pattern)) )
3591 if (image == (Image *) NULL)
3592 continue; /* else no image to retrieve proprty - no list */
3593 ResetImagePropertyIterator(image);
3594 while ((key=GetNextImageProperty(image)) != (const char *) NULL)
3595 if( IfMagickTrue(GlobExpression(key,pattern,MagickTrue)) )
3597 string=GetImageProperty(image,key,exception);
3598 if (string != (const char *) NULL)
3599 AppendKeyValue2Text(key,string);
3600 /* else - assertion failure? */
3605 Look for a known property or image attribute
3606 Such as %[basename] %[denisty] %[delay]
3607 Also handles a braced single letter: %[b] %[G] %[g]
3609 string=GetMagickProperty(image_info,image,pattern,exception);
3610 if (string != (const char *) NULL)
3612 AppendString2Text(string);
3616 Look for a per-image Artifact
3617 This includes option lookup (FUTURE: interpreted according to image)
3619 if (image != (Image *)NULL)
3621 string=GetImageArtifact(image,pattern);
3622 if (string != (char *) NULL)
3624 AppendString2Text(string);
3629 /* no image, so direct 'option' lookup (no delayed percent escapes) */
3630 if (image_info != (ImageInfo *) NULL)
3632 string=GetImageOption(image_info,pattern);
3633 if (string != (char *) NULL)
3635 AppendString2Text(string);
3639 PropertyLookupFailure:
3641 Failed to find any match anywhere!
3643 if (len >= 64) { /* truncate string for error message */
3649 (void) ThrowMagickException(exception,GetMagickModule(),
3650 OptionWarning,"UnknownImageProperty","\"%%[%s]\"",pattern);
3652 } /* Braced Percent Escape */
3654 } /* for each char in 'embed_text' */
3656 return(interpret_text);
3660 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3664 % R e m o v e I m a g e P r o p e r t y %
3668 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3670 % RemoveImageProperty() removes a property from the image and returns its
3673 % In this case the ConstantString() value returned should be freed by the
3674 % caller when finished.
3676 % The format of the RemoveImageProperty method is:
3678 % char *RemoveImageProperty(Image *image,const char *property)
3680 % A description of each parameter follows:
3682 % o image: the image.
3684 % o property: the image property.
3687 MagickExport char *RemoveImageProperty(Image *image,
3688 const char *property)
3693 assert(image != (Image *) NULL);
3694 assert(image->signature == MagickSignature);
3695 if (image->debug != MagickFalse)
3696 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
3698 if (image->properties == (void *) NULL)
3699 return((char *) NULL);
3700 value=(char *) RemoveNodeFromSplayTree((SplayTreeInfo *) image->properties,
3706 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3710 % 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 %
3714 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3716 % ResetImagePropertyIterator() resets the image properties iterator. Use it
3717 % in conjunction with GetNextImageProperty() to iterate over all the values
3718 % associated with an image property.
3720 % The format of the ResetImagePropertyIterator method is:
3722 % ResetImagePropertyIterator(Image *image)
3724 % A description of each parameter follows:
3726 % o image: the image.
3729 MagickExport void ResetImagePropertyIterator(const Image *image)
3731 assert(image != (Image *) NULL);
3732 assert(image->signature == MagickSignature);
3733 if (image->debug != MagickFalse)
3734 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
3736 if (image->properties == (void *) NULL)
3738 ResetSplayTreeIterator((SplayTreeInfo *) image->properties);
3742 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3746 % S e t I m a g e P r o p e r t y %
3750 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3752 % SetImageProperty() saves the given string value either to specific known
3753 % attribute or to a freeform property string.
3755 % Attempting to set a property that is normally calculated will produce
3758 % The format of the SetImageProperty method is:
3760 % MagickBooleanType SetImageProperty(Image *image,const char *property,
3761 % const char *value,ExceptionInfo *exception)
3763 % A description of each parameter follows:
3765 % o image: the image.
3767 % o property: the image property.
3769 % o values: the image property values.
3771 % o exception: return any errors or warnings in this structure.
3774 MagickExport MagickBooleanType SetImageProperty(Image *image,
3775 const char *property,const char *value,ExceptionInfo *exception)
3783 assert(image != (Image *) NULL);
3784 assert(image->signature == MagickSignature);
3785 if (image->debug != MagickFalse)
3786 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
3787 if (image->properties == (void *) NULL)
3788 image->properties=NewSplayTree(CompareSplayTreeString,
3789 RelinquishMagickMemory,RelinquishMagickMemory); /* create splay-tree */
3790 if (value == (const char *) NULL)
3791 return(DeleteImageProperty(image,property)); /* delete if NULL */
3793 if (strlen(property) <= 1)
3796 Do not 'set' single letter properties - read only shorthand.
3798 (void) ThrowMagickException(exception,GetMagickModule(),OptionError,
3799 "SetReadOnlyProperty","`%s'",property);
3800 return(MagickFalse);
3803 /* FUTURE: binary chars or quotes in key should produce a error */
3804 /* Set attributes with known names or special prefixes
3805 return result is found, or break to set a free form properity
3809 #if 0 /* Percent escape's sets values with this prefix: for later use
3810 Throwing an exception causes this setting to fail */
3813 if (LocaleNCompare("8bim:",property,5) == 0)
3815 (void) ThrowMagickException(exception,GetMagickModule(),
3816 OptionError,"SetReadOnlyProperty","`%s'",property);
3817 return(MagickFalse);
3825 if (LocaleCompare("background",property) == 0)
3827 (void) QueryColorCompliance(value,AllCompliance,
3828 &image->background_color,exception);
3829 /* check for FUTURE: value exception?? */
3830 /* also add user input to splay tree */
3832 break; /* not an attribute, add as a property */
3837 if (LocaleCompare("channels",property) == 0)
3839 (void) ThrowMagickException(exception,GetMagickModule(),OptionError,
3840 "SetReadOnlyProperty","`%s'",property);
3841 return(MagickFalse);
3843 if (LocaleCompare("colorspace",property) == 0)
3848 colorspace=ParseCommandOption(MagickColorspaceOptions,MagickFalse,
3851 return(MagickFalse); /* FUTURE: value exception?? */
3852 return(SetImageColorspace(image,(ColorspaceType) colorspace,exception));
3854 if (LocaleCompare("compose",property) == 0)
3859 compose=ParseCommandOption(MagickComposeOptions,MagickFalse,value);
3861 return(MagickFalse); /* FUTURE: value exception?? */
3862 image->compose=(CompositeOperator) compose;
3865 if (LocaleCompare("compress",property) == 0)
3870 compression=ParseCommandOption(MagickCompressOptions,MagickFalse,
3872 if (compression < 0)
3873 return(MagickFalse); /* FUTURE: value exception?? */
3874 image->compression=(CompressionType) compression;
3877 break; /* not an attribute, add as a property */
3882 if (LocaleCompare("delay",property) == 0)
3887 flags=ParseGeometry(value,&geometry_info);
3888 if ((flags & GreaterValue) != 0)
3890 if (image->delay > (size_t) floor(geometry_info.rho+0.5))
3891 image->delay=(size_t) floor(geometry_info.rho+0.5);
3894 if ((flags & LessValue) != 0)
3896 if (image->delay < (size_t) floor(geometry_info.rho+0.5))
3897 image->delay=(ssize_t)
3898 floor(geometry_info.sigma+0.5);
3901 image->delay=(size_t) floor(geometry_info.rho+0.5);
3902 if ((flags & SigmaValue) != 0)
3903 image->ticks_per_second=(ssize_t) floor(geometry_info.sigma+0.5);
3906 if (LocaleCompare("delay_units",property) == 0)
3908 (void) ThrowMagickException(exception,GetMagickModule(),
3909 OptionError,"SetReadOnlyProperty","`%s'",property);
3910 return(MagickFalse);
3912 if (LocaleCompare("density",property) == 0)
3917 flags=ParseGeometry(value,&geometry_info);
3918 image->resolution.x=geometry_info.rho;
3919 image->resolution.y=geometry_info.sigma;
3920 if ((flags & SigmaValue) == 0)
3921 image->resolution.y=image->resolution.x;
3924 if (LocaleCompare("depth",property) == 0)
3926 image->depth=StringToUnsignedLong(value);
3929 if (LocaleCompare("dispose",property) == 0)
3934 dispose=ParseCommandOption(MagickDisposeOptions,MagickFalse,value);
3936 return(MagickFalse); /* FUTURE: value exception?? */
3937 image->dispose=(DisposeType) dispose;
3940 break; /* not an attribute, add as a property */
3942 #if 0 /* Percent escape's sets values with this prefix: for later use
3943 Throwing an exception causes this setting to fail */
3947 if (LocaleNCompare("exif:",property,5) == 0)
3949 (void) ThrowMagickException(exception,GetMagickModule(),
3950 OptionError,"SetReadOnlyProperty","`%s'",property);
3951 return(MagickFalse);
3953 break; /* not an attribute, add as a property */
3958 if (LocaleNCompare("fx:",property,3) == 0)
3960 (void) ThrowMagickException(exception,GetMagickModule(),
3961 OptionError,"SetReadOnlyProperty","`%s'",property);
3962 return(MagickFalse);
3964 break; /* not an attribute, add as a property */
3970 if (LocaleCompare("gamma",property) == 0)
3972 image->gamma=StringToDouble(value,(char **) NULL);
3975 if (LocaleCompare("gravity",property) == 0)
3980 gravity=ParseCommandOption(MagickGravityOptions,MagickFalse,value);
3982 return(MagickFalse); /* FUTURE: value exception?? */
3983 image->gravity=(GravityType) gravity;
3986 break; /* not an attribute, add as a property */
3991 if (LocaleCompare("height",property) == 0)
3993 (void) ThrowMagickException(exception,GetMagickModule(),
3994 OptionError,"SetReadOnlyProperty","`%s'",property);
3995 return(MagickFalse);
3997 break; /* not an attribute, add as a property */
4002 if (LocaleCompare("intensity",property) == 0)
4007 intensity=ParseCommandOption(MagickIntentOptions,MagickFalse,
4010 return(MagickFalse);
4011 image->intensity=(PixelIntensityMethod) intensity;
4014 if (LocaleCompare("intent",property) == 0)
4019 rendering_intent=ParseCommandOption(MagickIntentOptions,MagickFalse,
4021 if (rendering_intent < 0)
4022 return(MagickFalse); /* FUTURE: value exception?? */
4023 image->rendering_intent=(RenderingIntent) rendering_intent;
4026 if (LocaleCompare("interpolate",property) == 0)
4031 interpolate=ParseCommandOption(MagickInterpolateOptions,MagickFalse,
4033 if (interpolate < 0)
4034 return(MagickFalse); /* FUTURE: value exception?? */
4035 image->interpolate=(PixelInterpolateMethod) interpolate;
4038 #if 0 /* Percent escape's sets values with this prefix: for later use
4039 Throwing an exception causes this setting to fail */
4040 if (LocaleNCompare("iptc:",property,5) == 0)
4042 (void) ThrowMagickException(exception,GetMagickModule(),
4043 OptionError,"SetReadOnlyProperty","`%s'",property);
4044 return(MagickFalse);
4047 break; /* not an attribute, add as a property */
4051 if (LocaleCompare("kurtosis",property) == 0)
4053 (void) ThrowMagickException(exception,GetMagickModule(),
4054 OptionError,"SetReadOnlyProperty","`%s'",property);
4055 return(MagickFalse);
4057 break; /* not an attribute, add as a property */
4061 if (LocaleCompare("loop",property) == 0)
4063 image->iterations=StringToUnsignedLong(value);
4066 break; /* not an attribute, add as a property */
4070 if ( (LocaleCompare("magick",property) == 0) ||
4071 (LocaleCompare("max",property) == 0) ||
4072 (LocaleCompare("mean",property) == 0) ||
4073 (LocaleCompare("min",property) == 0) ||
4074 (LocaleCompare("min",property) == 0) )
4076 (void) ThrowMagickException(exception,GetMagickModule(),OptionError,
4077 "SetReadOnlyProperty","`%s'",property);
4078 return(MagickFalse);
4080 break; /* not an attribute, add as a property */
4083 if (LocaleCompare("opaque",property) == 0)
4085 (void) ThrowMagickException(exception,GetMagickModule(),
4086 OptionError,"SetReadOnlyProperty","`%s'",property);
4087 return(MagickFalse);
4089 break; /* not an attribute, add as a property */
4093 if (LocaleCompare("page",property) == 0)
4098 geometry=GetPageGeometry(value);
4099 flags=ParseAbsoluteGeometry(geometry,&image->page);
4100 geometry=DestroyString(geometry);
4103 #if 0 /* Percent escape's sets values with this prefix: for later use
4104 Throwing an exception causes this setting to fail */
4105 if (LocaleNCompare("pixel:",property,6) == 0)
4107 (void) ThrowMagickException(exception,GetMagickModule(),
4108 OptionError,"SetReadOnlyProperty","`%s'",property);
4109 return(MagickFalse);
4112 if (LocaleCompare("profile",property) == 0)
4120 image_info=AcquireImageInfo();
4121 (void) CopyMagickString(image_info->filename,value,MaxTextExtent);
4122 (void) SetImageInfo(image_info,1,exception);
4123 profile=FileToStringInfo(image_info->filename,~0UL,exception);
4124 if (profile != (StringInfo *) NULL)
4125 status=SetImageProfile(image,image_info->magick,profile,exception);
4126 image_info=DestroyImageInfo(image_info);
4129 break; /* not an attribute, add as a property */
4134 if (LocaleCompare("rendering-intent",property) == 0)
4139 rendering_intent=ParseCommandOption(MagickIntentOptions,MagickFalse,
4141 if (rendering_intent < 0)
4142 return(MagickFalse); /* FUTURE: value exception?? */
4143 image->rendering_intent=(RenderingIntent) rendering_intent;
4146 break; /* not an attribute, add as a property */
4150 if ( (LocaleCompare("size",property) == 0) ||
4151 (LocaleCompare("skewness",property) == 0) ||
4152 (LocaleCompare("scenes",property) == 0) ||
4153 (LocaleCompare("standard-deviation",property) == 0) )
4155 (void) ThrowMagickException(exception,GetMagickModule(),
4156 OptionError,"SetReadOnlyProperty","`%s'",property);
4157 return(MagickFalse);
4159 break; /* not an attribute, add as a property */
4163 if (LocaleCompare("tile-offset",property) == 0)
4168 geometry=GetPageGeometry(value);
4169 flags=ParseAbsoluteGeometry(geometry,&image->tile_offset);
4170 geometry=DestroyString(geometry);
4173 break; /* not an attribute, add as a property */
4178 if (LocaleCompare("units",property) == 0)
4183 units=ParseCommandOption(MagickResolutionOptions,MagickFalse,value);
4185 return(MagickFalse); /* FUTURE: value exception?? */
4186 image->units=(ResolutionType) units;
4189 break; /* not an attribute, add as a property */
4194 if (LocaleCompare("version",property) == 0)
4196 (void) ThrowMagickException(exception,GetMagickModule(),
4197 OptionError,"SetReadOnlyProperty","`%s'",property);
4198 return(MagickFalse);
4200 break; /* not an attribute, add as a property */
4205 if (LocaleCompare("width",property) == 0)
4207 (void) ThrowMagickException(exception,GetMagickModule(),
4208 OptionError,"SetReadOnlyProperty","`%s'",property);
4209 return(MagickFalse);
4211 break; /* not an attribute, add as a property */
4213 #if 0 /* Percent escape's sets values with this prefix: for later use
4214 Throwing an exception causes this setting to fail */
4218 if (LocaleNCompare("xmp:",property,4) == 0)
4220 (void) ThrowMagickException(exception,GetMagickModule(),
4221 OptionError,"SetReadOnlyProperty","`%s'",property);
4222 return(MagickFalse);
4224 break; /* not an attribute, add as a property */
4228 /* Default: not an attribute, add as a property */
4229 status=AddValueToSplayTree((SplayTreeInfo *) image->properties,
4230 ConstantString(property),ConstantString(value));
4231 /* FUTURE: error if status is bad? */