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-2012 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/attribute.h"
45 #include "MagickCore/cache.h"
46 #include "MagickCore/color.h"
47 #include "MagickCore/compare.h"
48 #include "MagickCore/constitute.h"
49 #include "MagickCore/draw.h"
50 #include "MagickCore/effect.h"
51 #include "MagickCore/exception.h"
52 #include "MagickCore/exception-private.h"
53 #include "MagickCore/fx.h"
54 #include "MagickCore/fx-private.h"
55 #include "MagickCore/gem.h"
56 #include "MagickCore/geometry.h"
57 #include "MagickCore/histogram.h"
58 #include "MagickCore/image.h"
59 #include "MagickCore/image.h"
60 #include "MagickCore/layer.h"
61 #include "MagickCore/locale-private.h"
62 #include "MagickCore/list.h"
63 #include "MagickCore/magick.h"
64 #include "MagickCore/memory_.h"
65 #include "MagickCore/monitor.h"
66 #include "MagickCore/montage.h"
67 #include "MagickCore/option.h"
68 #include "MagickCore/profile.h"
69 #include "MagickCore/property.h"
70 #include "MagickCore/quantum.h"
71 #include "MagickCore/resource_.h"
72 #include "MagickCore/splay-tree.h"
73 #include "MagickCore/signature.h"
74 #include "MagickCore/statistic.h"
75 #include "MagickCore/string_.h"
76 #include "MagickCore/string-private.h"
77 #include "MagickCore/token.h"
78 #include "MagickCore/token-private.h"
79 #include "MagickCore/utility.h"
80 #include "MagickCore/utility-private.h"
81 #include "MagickCore/version.h"
82 #include "MagickCore/xml-tree.h"
83 #include "MagickCore/xml-tree-private.h"
86 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
90 % C l o n e I m a g e P r o p e r t i e s %
94 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
96 % CloneImageProperties() clones one or more image properties.
98 % The format of the CloneImageProperties method is:
100 % MagickBooleanType CloneImageProperties(Image *image,
101 % const Image *clone_image)
103 % A description of each parameter follows:
105 % o image: the image.
107 % o clone_image: the clone image.
110 MagickExport MagickBooleanType CloneImageProperties(Image *image,
111 const Image *clone_image)
113 assert(image != (Image *) NULL);
114 assert(image->signature == MagickSignature);
115 if (image->debug != MagickFalse)
116 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
117 assert(clone_image != (const Image *) NULL);
118 assert(clone_image->signature == MagickSignature);
119 if (clone_image->debug != MagickFalse)
120 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
121 clone_image->filename);
122 (void) CopyMagickString(image->filename,clone_image->filename,MaxTextExtent);
123 (void) CopyMagickString(image->magick_filename,clone_image->magick_filename,
125 image->compression=clone_image->compression;
126 image->quality=clone_image->quality;
127 image->depth=clone_image->depth;
128 image->background_color=clone_image->background_color;
129 image->border_color=clone_image->border_color;
130 image->matte_color=clone_image->matte_color;
131 image->transparent_color=clone_image->transparent_color;
132 image->gamma=clone_image->gamma;
133 image->chromaticity=clone_image->chromaticity;
134 image->rendering_intent=clone_image->rendering_intent;
135 image->black_point_compensation=clone_image->black_point_compensation;
136 image->units=clone_image->units;
137 image->montage=(char *) NULL;
138 image->directory=(char *) NULL;
139 (void) CloneString(&image->geometry,clone_image->geometry);
140 image->offset=clone_image->offset;
141 image->resolution.x=clone_image->resolution.x;
142 image->resolution.y=clone_image->resolution.y;
143 image->page=clone_image->page;
144 image->tile_offset=clone_image->tile_offset;
145 image->extract_info=clone_image->extract_info;
146 image->bias=clone_image->bias;
147 image->filter=clone_image->filter;
148 image->blur=clone_image->blur;
149 image->fuzz=clone_image->fuzz;
150 image->interlace=clone_image->interlace;
151 image->interpolate=clone_image->interpolate;
152 image->endian=clone_image->endian;
153 image->gravity=clone_image->gravity;
154 image->compose=clone_image->compose;
155 image->scene=clone_image->scene;
156 image->orientation=clone_image->orientation;
157 image->dispose=clone_image->dispose;
158 image->delay=clone_image->delay;
159 image->ticks_per_second=clone_image->ticks_per_second;
160 image->iterations=clone_image->iterations;
161 image->total_colors=clone_image->total_colors;
162 image->taint=clone_image->taint;
163 image->progress_monitor=clone_image->progress_monitor;
164 image->client_data=clone_image->client_data;
165 image->start_loop=clone_image->start_loop;
166 image->error=clone_image->error;
167 image->signature=clone_image->signature;
168 if (clone_image->properties != (void *) NULL)
170 if (image->properties != (void *) NULL)
171 DestroyImageProperties(image);
172 image->properties=CloneSplayTree((SplayTreeInfo *)
173 clone_image->properties,(void *(*)(void *)) ConstantString,
174 (void *(*)(void *)) ConstantString);
180 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
184 % D e f i n e I m a g e P r o p e r t y %
188 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
190 % DefineImageProperty() associates a key/value pair with an image property.
192 % The format of the DefineImageProperty method is:
194 % MagickBooleanType DefineImageProperty(Image *image,
195 % const char *property,ExceptionInfo *exception)
197 % A description of each parameter follows:
199 % o image: the image.
201 % o property: the image property.
203 % o exception: return any errors or warnings in this structure.
206 MagickExport MagickBooleanType DefineImageProperty(Image *image,
207 const char *property,ExceptionInfo *exception)
211 value[MaxTextExtent];
216 assert(image != (Image *) NULL);
217 assert(property != (const char *) NULL);
218 (void) CopyMagickString(key,property,MaxTextExtent-1);
219 for (p=key; *p != '\0'; p++)
224 (void) CopyMagickString(value,p+1,MaxTextExtent);
226 return(SetImageProperty(image,key,value,exception));
230 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
234 % D e l e t e I m a g e P r o p e r t y %
238 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
240 % DeleteImageProperty() deletes an image property.
242 % The format of the DeleteImageProperty method is:
244 % MagickBooleanType DeleteImageProperty(Image *image,const char *property)
246 % A description of each parameter follows:
248 % o image: the image.
250 % o property: the image property.
253 MagickExport MagickBooleanType DeleteImageProperty(Image *image,
254 const char *property)
256 assert(image != (Image *) NULL);
257 assert(image->signature == MagickSignature);
258 if (image->debug != MagickFalse)
259 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
261 if (image->properties == (void *) NULL)
263 return(DeleteNodeFromSplayTree((SplayTreeInfo *) image->properties,property));
267 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
271 % D e s t r o y I m a g e P r o p e r t i e s %
275 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
277 % DestroyImageProperties() releases memory associated with image property
280 % The format of the DestroyDefines method is:
282 % void DestroyImageProperties(Image *image)
284 % A description of each parameter follows:
286 % o image: the image.
289 MagickExport void DestroyImageProperties(Image *image)
291 assert(image != (Image *) NULL);
292 assert(image->signature == MagickSignature);
293 if (image->debug != MagickFalse)
294 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
296 if (image->properties != (void *) NULL)
297 image->properties=(void *) DestroySplayTree((SplayTreeInfo *)
302 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
306 % F o r m a t I m a g e P r o p e r t y %
310 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
312 % FormatImageProperty() permits formatted property/value pairs to be saved as
315 % The format of the FormatImageProperty method is:
317 % MagickBooleanType FormatImageProperty(Image *image,const char *property,
318 % const char *format,...)
320 % A description of each parameter follows.
322 % o image: The image.
324 % o property: The attribute property.
326 % o format: A string describing the format to use to write the remaining
330 MagickExport MagickBooleanType FormatImageProperty(Image *image,
331 const char *property,const char *format,...)
334 value[MaxTextExtent];
348 va_start(operands,format);
349 n=FormatLocaleStringList(value,MaxTextExtent,format,operands);
352 exception=AcquireExceptionInfo();
353 status=SetImageProperty(image,property,value,exception);
354 exception=DestroyExceptionInfo(exception);
359 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
363 % G e t I m a g e P r o p e r t y %
367 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
369 % GetImageProperty() gets a value associated with an image property.
371 % The format of the GetImageProperty method is:
373 % const char *GetImageProperty(const Image *image,const char *key,
374 % ExceptionInfo *exception)
376 % A description of each parameter follows:
378 % o image: the image.
382 % o exception: return any errors or warnings in this structure.
387 *TracePSClippath(const unsigned char *,size_t,const size_t,
389 *TraceSVGClippath(const unsigned char *,size_t,const size_t,
392 static MagickBooleanType GetIPTCProperty(const Image *image,const char *key,
393 ExceptionInfo *exception)
413 profile=GetImageProfile(image,"iptc");
414 if (profile == (StringInfo *) NULL)
415 profile=GetImageProfile(image,"8bim");
416 if (profile == (StringInfo *) NULL)
418 count=sscanf(key,"IPTC:%ld:%ld",&dataset,&record);
421 attribute=(char *) NULL;
422 for (i=0; i < (ssize_t) GetStringInfoLength(profile); i+=(ssize_t) length)
425 if ((ssize_t) GetStringInfoDatum(profile)[i] != 0x1c)
427 length=(size_t) (GetStringInfoDatum(profile)[i+3] << 8);
428 length|=GetStringInfoDatum(profile)[i+4];
429 if (((long) GetStringInfoDatum(profile)[i+1] == dataset) &&
430 ((long) GetStringInfoDatum(profile)[i+2] == record))
432 message=(char *) NULL;
434 message=(char *) AcquireQuantumMemory(length+1UL,sizeof(*message));
435 if (message != (char *) NULL)
437 (void) CopyMagickString(message,(char *) GetStringInfoDatum(
438 profile)+i+5,length+1);
439 (void) ConcatenateString(&attribute,message);
440 (void) ConcatenateString(&attribute,";");
441 message=DestroyString(message);
446 if ((attribute == (char *) NULL) || (*attribute == ';'))
448 if (attribute != (char *) NULL)
449 attribute=DestroyString(attribute);
452 attribute[strlen(attribute)-1]='\0';
453 (void) SetImageProperty((Image *) image,key,(const char *) attribute,
455 attribute=DestroyString(attribute);
459 static inline ssize_t MagickMax(const ssize_t x,const ssize_t y)
466 static inline int ReadPropertyByte(const unsigned char **p,size_t *length)
478 static inline size_t ReadPropertyMSBLong(const unsigned char **p,
495 for (i=0; i < 4; i++)
499 buffer[i]=(unsigned char) c;
501 value=(size_t) (buffer[0] << 24);
502 value|=buffer[1] << 16;
503 value|=buffer[2] << 8;
505 return(value & 0xffffffff);
508 static inline unsigned short ReadPropertyMSBShort(const unsigned char **p,
524 return((unsigned short) ~0U);
525 for (i=0; i < 2; i++)
529 buffer[i]=(unsigned char) c;
531 value=(unsigned short) (buffer[0] << 8);
533 return((unsigned short) (value & 0xffff));
536 static MagickBooleanType Get8BIMProperty(const Image *image,const char *key,
537 ExceptionInfo *exception)
541 format[MaxTextExtent],
570 There are no newlines in path names, so it's safe as terminator.
572 profile=GetImageProfile(image,"8bim");
573 if (profile == (StringInfo *) NULL)
575 count=(ssize_t) sscanf(key,"8BIM:%ld,%ld:%[^\n]\n%[^\n]",&start,&stop,name,
577 if ((count != 2) && (count != 3) && (count != 4))
580 (void) CopyMagickString(format,"SVG",MaxTextExtent);
585 sub_number=(ssize_t) StringToLong(&name[1]);
586 sub_number=MagickMax(sub_number,1L);
587 resource=(char *) NULL;
589 length=GetStringInfoLength(profile);
590 info=GetStringInfoDatum(profile);
591 while ((length > 0) && (status == MagickFalse))
593 if (ReadPropertyByte(&info,&length) != (unsigned char) '8')
595 if (ReadPropertyByte(&info,&length) != (unsigned char) 'B')
597 if (ReadPropertyByte(&info,&length) != (unsigned char) 'I')
599 if (ReadPropertyByte(&info,&length) != (unsigned char) 'M')
601 id=(ssize_t) ReadPropertyMSBShort(&info,&length);
602 if (id < (ssize_t) start)
604 if (id > (ssize_t) stop)
606 if (resource != (char *) NULL)
607 resource=DestroyString(resource);
608 count=(ssize_t) ReadPropertyByte(&info,&length);
609 if ((count != 0) && ((size_t) count <= length))
611 resource=(char *) NULL;
612 if (~(1UL*count) >= (MaxTextExtent-1))
613 resource=(char *) AcquireQuantumMemory((size_t) count+MaxTextExtent,
615 if (resource != (char *) NULL)
617 for (i=0; i < (ssize_t) count; i++)
618 resource[i]=(char) ReadPropertyByte(&info,&length);
619 resource[count]='\0';
622 if ((count & 0x01) == 0)
623 (void) ReadPropertyByte(&info,&length);
624 count=(ssize_t) ((int) ReadPropertyMSBLong(&info,&length));
625 if ((*name != '\0') && (*name != '#'))
626 if ((resource == (char *) NULL) || (LocaleCompare(name,resource) != 0))
629 No name match, scroll forward and try next.
635 if ((*name == '#') && (sub_number != 1))
638 No numbered match, scroll forward and try next.
646 We have the resource of interest.
648 attribute=(char *) NULL;
649 if (~(1UL*count) >= (MaxTextExtent-1))
650 attribute=(char *) AcquireQuantumMemory((size_t) count+MaxTextExtent,
652 if (attribute != (char *) NULL)
654 (void) CopyMagickMemory(attribute,(char *) info,(size_t) count);
655 attribute[count]='\0';
658 if ((id <= 1999) || (id >= 2999))
659 (void) SetImageProperty((Image *) image,key,(const char *)
660 attribute,exception);
666 if (LocaleCompare(format,"svg") == 0)
667 path=TraceSVGClippath((unsigned char *) attribute,(size_t) count,
668 image->columns,image->rows);
670 path=TracePSClippath((unsigned char *) attribute,(size_t) count,
671 image->columns,image->rows);
672 (void) SetImageProperty((Image *) image,key,(const char *) path,
674 path=DestroyString(path);
676 attribute=DestroyString(attribute);
680 if (resource != (char *) NULL)
681 resource=DestroyString(resource);
685 static inline unsigned short ReadPropertyShort(const EndianType endian,
686 const unsigned char *buffer)
691 if (endian == MSBEndian)
693 value=(unsigned short) ((((unsigned char *) buffer)[0] << 8) |
694 ((unsigned char *) buffer)[1]);
695 return((unsigned short) (value & 0xffff));
697 value=(unsigned short) ((buffer[1] << 8) | buffer[0]);
698 return((unsigned short) (value & 0xffff));
701 static inline size_t ReadPropertyLong(const EndianType endian,
702 const unsigned char *buffer)
707 if (endian == MSBEndian)
709 value=(size_t) ((buffer[0] << 24) | (buffer[1] << 16) |
710 (buffer[2] << 8) | buffer[3]);
711 return((size_t) (value & 0xffffffff));
713 value=(size_t) ((buffer[3] << 24) | (buffer[2] << 16) |
714 (buffer[1] << 8 ) | (buffer[0]));
715 return((size_t) (value & 0xffffffff));
718 static MagickBooleanType GetEXIFProperty(const Image *image,
719 const char *property,ExceptionInfo *exception)
721 #define MaxDirectoryStack 16
722 #define EXIF_DELIMITER "\n"
723 #define EXIF_NUM_FORMATS 12
724 #define EXIF_FMT_BYTE 1
725 #define EXIF_FMT_STRING 2
726 #define EXIF_FMT_USHORT 3
727 #define EXIF_FMT_ULONG 4
728 #define EXIF_FMT_URATIONAL 5
729 #define EXIF_FMT_SBYTE 6
730 #define EXIF_FMT_UNDEFINED 7
731 #define EXIF_FMT_SSHORT 8
732 #define EXIF_FMT_SLONG 9
733 #define EXIF_FMT_SRATIONAL 10
734 #define EXIF_FMT_SINGLE 11
735 #define EXIF_FMT_DOUBLE 12
736 #define TAG_EXIF_OFFSET 0x8769
737 #define TAG_GPS_OFFSET 0x8825
738 #define TAG_INTEROP_OFFSET 0xa005
740 #define EXIFMultipleValues(size,format,arg) \
753 for (component=0; component < components; component++) \
755 length+=FormatLocaleString(buffer+length,MaxTextExtent-length, \
757 if (length >= (MaxTextExtent-1)) \
758 length=MaxTextExtent-1; \
762 buffer[length-2]='\0'; \
763 value=AcquireString(buffer); \
766 #define EXIFMultipleFractions(size,format,arg1,arg2) \
779 for (component=0; component < components; component++) \
781 length+=FormatLocaleString(buffer+length,MaxTextExtent-length, \
782 format", ",arg1,arg2); \
783 if (length >= (MaxTextExtent-1)) \
784 length=MaxTextExtent-1; \
788 buffer[length-2]='\0'; \
789 value=AcquireString(buffer); \
792 typedef struct _DirectoryInfo
802 typedef struct _TagInfo
814 { 0x001, "exif:InteroperabilityIndex" },
815 { 0x002, "exif:InteroperabilityVersion" },
816 { 0x100, "exif:ImageWidth" },
817 { 0x101, "exif:ImageLength" },
818 { 0x102, "exif:BitsPerSample" },
819 { 0x103, "exif:Compression" },
820 { 0x106, "exif:PhotometricInterpretation" },
821 { 0x10a, "exif:FillOrder" },
822 { 0x10d, "exif:DocumentName" },
823 { 0x10e, "exif:ImageDescription" },
824 { 0x10f, "exif:Make" },
825 { 0x110, "exif:Model" },
826 { 0x111, "exif:StripOffsets" },
827 { 0x112, "exif:Orientation" },
828 { 0x115, "exif:SamplesPerPixel" },
829 { 0x116, "exif:RowsPerStrip" },
830 { 0x117, "exif:StripByteCounts" },
831 { 0x11a, "exif:XResolution" },
832 { 0x11b, "exif:YResolution" },
833 { 0x11c, "exif:PlanarConfiguration" },
834 { 0x11d, "exif:PageName" },
835 { 0x11e, "exif:XPosition" },
836 { 0x11f, "exif:YPosition" },
837 { 0x118, "exif:MinSampleValue" },
838 { 0x119, "exif:MaxSampleValue" },
839 { 0x120, "exif:FreeOffsets" },
840 { 0x121, "exif:FreeByteCounts" },
841 { 0x122, "exif:GrayResponseUnit" },
842 { 0x123, "exif:GrayResponseCurve" },
843 { 0x124, "exif:T4Options" },
844 { 0x125, "exif:T6Options" },
845 { 0x128, "exif:ResolutionUnit" },
846 { 0x12d, "exif:TransferFunction" },
847 { 0x131, "exif:Software" },
848 { 0x132, "exif:DateTime" },
849 { 0x13b, "exif:Artist" },
850 { 0x13e, "exif:WhitePoint" },
851 { 0x13f, "exif:PrimaryChromaticities" },
852 { 0x140, "exif:ColorMap" },
853 { 0x141, "exif:HalfToneHints" },
854 { 0x142, "exif:TileWidth" },
855 { 0x143, "exif:TileLength" },
856 { 0x144, "exif:TileOffsets" },
857 { 0x145, "exif:TileByteCounts" },
858 { 0x14a, "exif:SubIFD" },
859 { 0x14c, "exif:InkSet" },
860 { 0x14d, "exif:InkNames" },
861 { 0x14e, "exif:NumberOfInks" },
862 { 0x150, "exif:DotRange" },
863 { 0x151, "exif:TargetPrinter" },
864 { 0x152, "exif:ExtraSample" },
865 { 0x153, "exif:SampleFormat" },
866 { 0x154, "exif:SMinSampleValue" },
867 { 0x155, "exif:SMaxSampleValue" },
868 { 0x156, "exif:TransferRange" },
869 { 0x157, "exif:ClipPath" },
870 { 0x158, "exif:XClipPathUnits" },
871 { 0x159, "exif:YClipPathUnits" },
872 { 0x15a, "exif:Indexed" },
873 { 0x15b, "exif:JPEGTables" },
874 { 0x15f, "exif:OPIProxy" },
875 { 0x200, "exif:JPEGProc" },
876 { 0x201, "exif:JPEGInterchangeFormat" },
877 { 0x202, "exif:JPEGInterchangeFormatLength" },
878 { 0x203, "exif:JPEGRestartInterval" },
879 { 0x205, "exif:JPEGLosslessPredictors" },
880 { 0x206, "exif:JPEGPointTransforms" },
881 { 0x207, "exif:JPEGQTables" },
882 { 0x208, "exif:JPEGDCTables" },
883 { 0x209, "exif:JPEGACTables" },
884 { 0x211, "exif:YCbCrCoefficients" },
885 { 0x212, "exif:YCbCrSubSampling" },
886 { 0x213, "exif:YCbCrPositioning" },
887 { 0x214, "exif:ReferenceBlackWhite" },
888 { 0x2bc, "exif:ExtensibleMetadataPlatform" },
889 { 0x301, "exif:Gamma" },
890 { 0x302, "exif:ICCProfileDescriptor" },
891 { 0x303, "exif:SRGBRenderingIntent" },
892 { 0x320, "exif:ImageTitle" },
893 { 0x5001, "exif:ResolutionXUnit" },
894 { 0x5002, "exif:ResolutionYUnit" },
895 { 0x5003, "exif:ResolutionXLengthUnit" },
896 { 0x5004, "exif:ResolutionYLengthUnit" },
897 { 0x5005, "exif:PrintFlags" },
898 { 0x5006, "exif:PrintFlagsVersion" },
899 { 0x5007, "exif:PrintFlagsCrop" },
900 { 0x5008, "exif:PrintFlagsBleedWidth" },
901 { 0x5009, "exif:PrintFlagsBleedWidthScale" },
902 { 0x500A, "exif:HalftoneLPI" },
903 { 0x500B, "exif:HalftoneLPIUnit" },
904 { 0x500C, "exif:HalftoneDegree" },
905 { 0x500D, "exif:HalftoneShape" },
906 { 0x500E, "exif:HalftoneMisc" },
907 { 0x500F, "exif:HalftoneScreen" },
908 { 0x5010, "exif:JPEGQuality" },
909 { 0x5011, "exif:GridSize" },
910 { 0x5012, "exif:ThumbnailFormat" },
911 { 0x5013, "exif:ThumbnailWidth" },
912 { 0x5014, "exif:ThumbnailHeight" },
913 { 0x5015, "exif:ThumbnailColorDepth" },
914 { 0x5016, "exif:ThumbnailPlanes" },
915 { 0x5017, "exif:ThumbnailRawBytes" },
916 { 0x5018, "exif:ThumbnailSize" },
917 { 0x5019, "exif:ThumbnailCompressedSize" },
918 { 0x501a, "exif:ColorTransferFunction" },
919 { 0x501b, "exif:ThumbnailData" },
920 { 0x5020, "exif:ThumbnailImageWidth" },
921 { 0x5021, "exif:ThumbnailImageHeight" },
922 { 0x5022, "exif:ThumbnailBitsPerSample" },
923 { 0x5023, "exif:ThumbnailCompression" },
924 { 0x5024, "exif:ThumbnailPhotometricInterp" },
925 { 0x5025, "exif:ThumbnailImageDescription" },
926 { 0x5026, "exif:ThumbnailEquipMake" },
927 { 0x5027, "exif:ThumbnailEquipModel" },
928 { 0x5028, "exif:ThumbnailStripOffsets" },
929 { 0x5029, "exif:ThumbnailOrientation" },
930 { 0x502a, "exif:ThumbnailSamplesPerPixel" },
931 { 0x502b, "exif:ThumbnailRowsPerStrip" },
932 { 0x502c, "exif:ThumbnailStripBytesCount" },
933 { 0x502d, "exif:ThumbnailResolutionX" },
934 { 0x502e, "exif:ThumbnailResolutionY" },
935 { 0x502f, "exif:ThumbnailPlanarConfig" },
936 { 0x5030, "exif:ThumbnailResolutionUnit" },
937 { 0x5031, "exif:ThumbnailTransferFunction" },
938 { 0x5032, "exif:ThumbnailSoftwareUsed" },
939 { 0x5033, "exif:ThumbnailDateTime" },
940 { 0x5034, "exif:ThumbnailArtist" },
941 { 0x5035, "exif:ThumbnailWhitePoint" },
942 { 0x5036, "exif:ThumbnailPrimaryChromaticities" },
943 { 0x5037, "exif:ThumbnailYCbCrCoefficients" },
944 { 0x5038, "exif:ThumbnailYCbCrSubsampling" },
945 { 0x5039, "exif:ThumbnailYCbCrPositioning" },
946 { 0x503A, "exif:ThumbnailRefBlackWhite" },
947 { 0x503B, "exif:ThumbnailCopyRight" },
948 { 0x5090, "exif:LuminanceTable" },
949 { 0x5091, "exif:ChrominanceTable" },
950 { 0x5100, "exif:FrameDelay" },
951 { 0x5101, "exif:LoopCount" },
952 { 0x5110, "exif:PixelUnit" },
953 { 0x5111, "exif:PixelPerUnitX" },
954 { 0x5112, "exif:PixelPerUnitY" },
955 { 0x5113, "exif:PaletteHistogram" },
956 { 0x1000, "exif:RelatedImageFileFormat" },
957 { 0x1001, "exif:RelatedImageLength" },
958 { 0x1002, "exif:RelatedImageWidth" },
959 { 0x800d, "exif:ImageID" },
960 { 0x80e3, "exif:Matteing" },
961 { 0x80e4, "exif:DataType" },
962 { 0x80e5, "exif:ImageDepth" },
963 { 0x80e6, "exif:TileDepth" },
964 { 0x828d, "exif:CFARepeatPatternDim" },
965 { 0x828e, "exif:CFAPattern2" },
966 { 0x828f, "exif:BatteryLevel" },
967 { 0x8298, "exif:Copyright" },
968 { 0x829a, "exif:ExposureTime" },
969 { 0x829d, "exif:FNumber" },
970 { 0x83bb, "exif:IPTC/NAA" },
971 { 0x84e3, "exif:IT8RasterPadding" },
972 { 0x84e5, "exif:IT8ColorTable" },
973 { 0x8649, "exif:ImageResourceInformation" },
974 { 0x8769, "exif:ExifOffset" },
975 { 0x8773, "exif:InterColorProfile" },
976 { 0x8822, "exif:ExposureProgram" },
977 { 0x8824, "exif:SpectralSensitivity" },
978 { 0x8825, "exif:GPSInfo" },
979 { 0x8827, "exif:ISOSpeedRatings" },
980 { 0x8828, "exif:OECF" },
981 { 0x8829, "exif:Interlace" },
982 { 0x882a, "exif:TimeZoneOffset" },
983 { 0x882b, "exif:SelfTimerMode" },
984 { 0x9000, "exif:ExifVersion" },
985 { 0x9003, "exif:DateTimeOriginal" },
986 { 0x9004, "exif:DateTimeDigitized" },
987 { 0x9101, "exif:ComponentsConfiguration" },
988 { 0x9102, "exif:CompressedBitsPerPixel" },
989 { 0x9201, "exif:ShutterSpeedValue" },
990 { 0x9202, "exif:ApertureValue" },
991 { 0x9203, "exif:BrightnessValue" },
992 { 0x9204, "exif:ExposureBiasValue" },
993 { 0x9205, "exif:MaxApertureValue" },
994 { 0x9206, "exif:SubjectDistance" },
995 { 0x9207, "exif:MeteringMode" },
996 { 0x9208, "exif:LightSource" },
997 { 0x9209, "exif:Flash" },
998 { 0x920a, "exif:FocalLength" },
999 { 0x920b, "exif:FlashEnergy" },
1000 { 0x920c, "exif:SpatialFrequencyResponse" },
1001 { 0x920d, "exif:Noise" },
1002 { 0x9211, "exif:ImageNumber" },
1003 { 0x9212, "exif:SecurityClassification" },
1004 { 0x9213, "exif:ImageHistory" },
1005 { 0x9214, "exif:SubjectArea" },
1006 { 0x9215, "exif:ExposureIndex" },
1007 { 0x9216, "exif:TIFF-EPStandardID" },
1008 { 0x927c, "exif:MakerNote" },
1009 { 0x9C9b, "exif:WinXP-Title" },
1010 { 0x9C9c, "exif:WinXP-Comments" },
1011 { 0x9C9d, "exif:WinXP-Author" },
1012 { 0x9C9e, "exif:WinXP-Keywords" },
1013 { 0x9C9f, "exif:WinXP-Subject" },
1014 { 0x9286, "exif:UserComment" },
1015 { 0x9290, "exif:SubSecTime" },
1016 { 0x9291, "exif:SubSecTimeOriginal" },
1017 { 0x9292, "exif:SubSecTimeDigitized" },
1018 { 0xa000, "exif:FlashPixVersion" },
1019 { 0xa001, "exif:ColorSpace" },
1020 { 0xa002, "exif:ExifImageWidth" },
1021 { 0xa003, "exif:ExifImageLength" },
1022 { 0xa004, "exif:RelatedSoundFile" },
1023 { 0xa005, "exif:InteroperabilityOffset" },
1024 { 0xa20b, "exif:FlashEnergy" },
1025 { 0xa20c, "exif:SpatialFrequencyResponse" },
1026 { 0xa20d, "exif:Noise" },
1027 { 0xa20e, "exif:FocalPlaneXResolution" },
1028 { 0xa20f, "exif:FocalPlaneYResolution" },
1029 { 0xa210, "exif:FocalPlaneResolutionUnit" },
1030 { 0xa214, "exif:SubjectLocation" },
1031 { 0xa215, "exif:ExposureIndex" },
1032 { 0xa216, "exif:TIFF/EPStandardID" },
1033 { 0xa217, "exif:SensingMethod" },
1034 { 0xa300, "exif:FileSource" },
1035 { 0xa301, "exif:SceneType" },
1036 { 0xa302, "exif:CFAPattern" },
1037 { 0xa401, "exif:CustomRendered" },
1038 { 0xa402, "exif:ExposureMode" },
1039 { 0xa403, "exif:WhiteBalance" },
1040 { 0xa404, "exif:DigitalZoomRatio" },
1041 { 0xa405, "exif:FocalLengthIn35mmFilm" },
1042 { 0xa406, "exif:SceneCaptureType" },
1043 { 0xa407, "exif:GainControl" },
1044 { 0xa408, "exif:Contrast" },
1045 { 0xa409, "exif:Saturation" },
1046 { 0xa40a, "exif:Sharpness" },
1047 { 0xa40b, "exif:DeviceSettingDescription" },
1048 { 0xa40c, "exif:SubjectDistanceRange" },
1049 { 0xa420, "exif:ImageUniqueID" },
1050 { 0xc4a5, "exif:PrintImageMatching" },
1051 { 0xa500, "exif:Gamma" },
1052 { 0xc640, "exif:CR2Slice" },
1053 { 0x10000, "exif:GPSVersionID" },
1054 { 0x10001, "exif:GPSLatitudeRef" },
1055 { 0x10002, "exif:GPSLatitude" },
1056 { 0x10003, "exif:GPSLongitudeRef" },
1057 { 0x10004, "exif:GPSLongitude" },
1058 { 0x10005, "exif:GPSAltitudeRef" },
1059 { 0x10006, "exif:GPSAltitude" },
1060 { 0x10007, "exif:GPSTimeStamp" },
1061 { 0x10008, "exif:GPSSatellites" },
1062 { 0x10009, "exif:GPSStatus" },
1063 { 0x1000a, "exif:GPSMeasureMode" },
1064 { 0x1000b, "exif:GPSDop" },
1065 { 0x1000c, "exif:GPSSpeedRef" },
1066 { 0x1000d, "exif:GPSSpeed" },
1067 { 0x1000e, "exif:GPSTrackRef" },
1068 { 0x1000f, "exif:GPSTrack" },
1069 { 0x10010, "exif:GPSImgDirectionRef" },
1070 { 0x10011, "exif:GPSImgDirection" },
1071 { 0x10012, "exif:GPSMapDatum" },
1072 { 0x10013, "exif:GPSDestLatitudeRef" },
1073 { 0x10014, "exif:GPSDestLatitude" },
1074 { 0x10015, "exif:GPSDestLongitudeRef" },
1075 { 0x10016, "exif:GPSDestLongitude" },
1076 { 0x10017, "exif:GPSDestBearingRef" },
1077 { 0x10018, "exif:GPSDestBearing" },
1078 { 0x10019, "exif:GPSDestDistanceRef" },
1079 { 0x1001a, "exif:GPSDestDistance" },
1080 { 0x1001b, "exif:GPSProcessingMethod" },
1081 { 0x1001c, "exif:GPSAreaInformation" },
1082 { 0x1001d, "exif:GPSDateStamp" },
1083 { 0x1001e, "exif:GPSDifferential" },
1095 directory_stack[MaxDirectoryStack];
1121 tag_bytes[] = {0, 1, 1, 2, 4, 8, 1, 1, 2, 4, 8, 4, 8};
1124 If EXIF data exists, then try to parse the request for a tag.
1126 profile=GetImageProfile(image,"exif");
1127 if (profile == (StringInfo *) NULL)
1128 return(MagickFalse);
1129 if ((property == (const char *) NULL) || (*property == '\0'))
1130 return(MagickFalse);
1131 while (isspace((int) ((unsigned char) *property)) != 0)
1135 switch (*(property+5))
1140 Caller has asked for all the tags in the EXIF data.
1143 all=1; /* return the data in description=value format */
1149 all=2; /* return the data in tagid=value format */
1162 Check for a hex based tag specification first.
1164 tag=(*(property+5) == '@') ? 1UL : 0UL;
1168 return(MagickFalse);
1170 Parse tag specification as a hex number.
1175 for (i=(ssize_t) n-1L; i >= 0; i--)
1179 if ((c >= '0') && (c <= '9'))
1182 if ((c >= 'A') && (c <= 'F'))
1185 if ((c >= 'a') && (c <= 'f'))
1188 return(MagickFalse);
1190 } while (*property != '\0');
1196 Try to match the text with a tag name instead.
1200 if (EXIFTag[i].tag == 0)
1202 if (LocaleCompare(EXIFTag[i].description,property) == 0)
1204 tag=(size_t) EXIFTag[i].tag;
1212 return(MagickFalse);
1213 length=GetStringInfoLength(profile);
1214 exif=GetStringInfoDatum(profile);
1217 if (ReadPropertyByte(&exif,&length) != 0x45)
1219 if (ReadPropertyByte(&exif,&length) != 0x78)
1221 if (ReadPropertyByte(&exif,&length) != 0x69)
1223 if (ReadPropertyByte(&exif,&length) != 0x66)
1225 if (ReadPropertyByte(&exif,&length) != 0x00)
1227 if (ReadPropertyByte(&exif,&length) != 0x00)
1232 return(MagickFalse);
1233 id=(ssize_t) ReadPropertyShort(LSBEndian,exif);
1241 return(MagickFalse);
1242 if (ReadPropertyShort(endian,exif+2) != 0x002a)
1243 return(MagickFalse);
1245 This the offset to the first IFD.
1247 offset=(ssize_t) ((int) ReadPropertyLong(endian,exif+4));
1248 if ((size_t) offset >= length)
1249 return(MagickFalse);
1251 Set the pointer to the first IFD and follow it were it leads.
1254 directory=exif+offset;
1261 If there is anything on the stack then pop it off.
1266 directory=directory_stack[level].directory;
1267 entry=directory_stack[level].entry;
1268 tag_offset=directory_stack[level].offset;
1271 Determine how many entries there are in the current IFD.
1273 number_entries=ReadPropertyShort(endian,directory);
1274 for ( ; entry < number_entries; entry++)
1276 register unsigned char
1287 q=(unsigned char *) (directory+2+(12*entry));
1288 tag_value=(ssize_t) (ReadPropertyShort(endian,q)+tag_offset);
1289 format=(size_t) ReadPropertyShort(endian,q+2);
1290 if (format >= (sizeof(tag_bytes)/sizeof(*tag_bytes)))
1292 components=(ssize_t) ((int) ReadPropertyLong(endian,q+4));
1293 number_bytes=(size_t) components*tag_bytes[format];
1294 if (number_bytes <= 4)
1302 The directory entry contains an offset.
1304 offset=(ssize_t) ((int) ReadPropertyLong(endian,q+8));
1305 if ((size_t) (offset+number_bytes) > length)
1307 p=(unsigned char *) (exif+offset);
1309 if ((all != 0) || (tag == (size_t) tag_value))
1312 buffer[MaxTextExtent],
1318 case EXIF_FMT_UNDEFINED:
1320 EXIFMultipleValues(1,"%.20g",(double) (*(unsigned char *) p1));
1323 case EXIF_FMT_SBYTE:
1325 EXIFMultipleValues(1,"%.20g",(double) (*(signed char *) p1));
1328 case EXIF_FMT_SSHORT:
1330 EXIFMultipleValues(2,"%hd",ReadPropertyShort(endian,p1));
1333 case EXIF_FMT_USHORT:
1335 EXIFMultipleValues(2,"%hu",ReadPropertyShort(endian,p1));
1338 case EXIF_FMT_ULONG:
1340 EXIFMultipleValues(4,"%.20g",(double)
1341 ReadPropertyLong(endian,p1));
1344 case EXIF_FMT_SLONG:
1346 EXIFMultipleValues(4,"%.20g",(double)
1347 ((int) ReadPropertyLong(endian,p1)));
1350 case EXIF_FMT_URATIONAL:
1352 EXIFMultipleFractions(8,"%.20g/%.20g",(double)
1353 ReadPropertyLong(endian,p1),(double)
1354 ReadPropertyLong(endian,p1+4));
1357 case EXIF_FMT_SRATIONAL:
1359 EXIFMultipleFractions(8,"%.20g/%.20g",(double)
1360 ((int) ReadPropertyLong(endian,p1)),(double)
1361 ((int) ReadPropertyLong(endian,p1+4)));
1364 case EXIF_FMT_SINGLE:
1366 EXIFMultipleValues(4,"%f",(double) *(float *) p1);
1369 case EXIF_FMT_DOUBLE:
1371 EXIFMultipleValues(8,"%f",*(double *) p1);
1375 case EXIF_FMT_STRING:
1377 value=(char *) NULL;
1378 if (~(1UL*number_bytes) >= 1)
1379 value=(char *) AcquireQuantumMemory((size_t) number_bytes+1UL,
1381 if (value != (char *) NULL)
1386 for (i=0; i < (ssize_t) number_bytes; i++)
1389 if ((isprint((int) p[i]) != 0) || (p[i] == '\0'))
1390 value[i]=(char) p[i];
1397 if (value != (char *) NULL)
1405 (void) CopyMagickString(key,property,MaxTextExtent);
1416 description="unknown";
1419 if (EXIFTag[i].tag == 0)
1421 if ((ssize_t) EXIFTag[i].tag == tag_value)
1423 description=EXIFTag[i].description;
1427 (void) FormatLocaleString(key,MaxTextExtent,"%s",description);
1432 if (tag_value < 0x10000)
1433 (void) FormatLocaleString(key,MaxTextExtent,"#%04lx",
1434 (unsigned long) tag_value);
1436 if (tag_value < 0x20000)
1437 (void) FormatLocaleString(key,MaxTextExtent,"@%04lx",
1438 (unsigned long) (tag_value & 0xffff));
1440 (void) FormatLocaleString(key,MaxTextExtent,"unknown");
1444 p=(const char *) NULL;
1445 if (image->properties != (void *) NULL)
1446 p=(const char *) GetValueFromSplayTree((SplayTreeInfo *)
1447 image->properties,key);
1448 if (p == (const char *) NULL)
1449 (void) SetImageProperty((Image *) image,key,value,exception);
1450 value=DestroyString(value);
1454 if ((tag_value == TAG_EXIF_OFFSET) ||
1455 (tag_value == TAG_INTEROP_OFFSET) ||
1456 (tag_value == TAG_GPS_OFFSET))
1461 offset=(size_t) ReadPropertyLong(endian,p);
1462 if ((offset < length) && (level < (MaxDirectoryStack-2)))
1467 tag_offset1=(tag_value == TAG_GPS_OFFSET) ? 0x10000UL : 0UL;
1468 directory_stack[level].directory=directory;
1470 directory_stack[level].entry=entry;
1471 directory_stack[level].offset=tag_offset;
1473 directory_stack[level].directory=exif+offset;
1474 directory_stack[level].offset=tag_offset1;
1475 directory_stack[level].entry=0;
1477 if ((directory+2+(12*number_entries)) > (exif+length))
1479 offset=(size_t) ReadPropertyLong(endian,directory+2+(12*
1481 if ((offset != 0) && (offset < length) &&
1482 (level < (MaxDirectoryStack-2)))
1484 directory_stack[level].directory=exif+offset;
1485 directory_stack[level].entry=0;
1486 directory_stack[level].offset=tag_offset1;
1493 } while (level > 0);
1497 static MagickBooleanType GetXMPProperty(const Image *image,const char *property)
1521 profile=GetImageProfile(image,"xmp");
1522 if (profile == (StringInfo *) NULL)
1523 return(MagickFalse);
1524 if ((property == (const char *) NULL) || (*property == '\0'))
1525 return(MagickFalse);
1526 xmp_profile=StringInfoToString(profile);
1527 if (xmp_profile == (char *) NULL)
1528 return(MagickFalse);
1529 for (p=xmp_profile; *p != '\0'; p++)
1530 if ((*p == '<') && (*(p+1) == 'x'))
1532 exception=AcquireExceptionInfo();
1533 xmp=NewXMLTree((char *) p,exception);
1534 xmp_profile=DestroyString(xmp_profile);
1535 exception=DestroyExceptionInfo(exception);
1536 if (xmp == (XMLTreeInfo *) NULL)
1537 return(MagickFalse);
1539 rdf=GetXMLTreeChild(xmp,"rdf:RDF");
1540 if (rdf != (XMLTreeInfo *) NULL)
1542 if (image->properties == (void *) NULL)
1543 ((Image *) image)->properties=NewSplayTree(CompareSplayTreeString,
1544 RelinquishMagickMemory,RelinquishMagickMemory);
1545 description=GetXMLTreeChild(rdf,"rdf:Description");
1546 while (description != (XMLTreeInfo *) NULL)
1548 node=GetXMLTreeChild(description,(const char *) NULL);
1549 while (node != (XMLTreeInfo *) NULL)
1551 child=GetXMLTreeChild(node,(const char *) NULL);
1552 if (child == (XMLTreeInfo *) NULL)
1553 (void) AddValueToSplayTree((SplayTreeInfo *) image->properties,
1554 ConstantString(GetXMLTreeTag(node)),
1555 ConstantString(GetXMLTreeContent(node)));
1556 while (child != (XMLTreeInfo *) NULL)
1558 if (LocaleCompare(GetXMLTreeTag(child),"rdf:Seq") != 0)
1559 (void) AddValueToSplayTree((SplayTreeInfo *) image->properties,
1560 ConstantString(GetXMLTreeTag(child)),
1561 ConstantString(GetXMLTreeContent(child)));
1562 child=GetXMLTreeSibling(child);
1564 node=GetXMLTreeSibling(node);
1566 description=GetNextXMLTreeTag(description);
1569 xmp=DestroyXMLTree(xmp);
1573 static char *TracePSClippath(const unsigned char *blob,size_t length,
1574 const size_t magick_unused(columns),
1575 const size_t magick_unused(rows))
1598 path=AcquireString((char *) NULL);
1599 if (path == (char *) NULL)
1600 return((char *) NULL);
1601 message=AcquireString((char *) NULL);
1602 (void) FormatLocaleString(message,MaxTextExtent,"/ClipImage\n");
1603 (void) ConcatenateString(&path,message);
1604 (void) FormatLocaleString(message,MaxTextExtent,"{\n");
1605 (void) ConcatenateString(&path,message);
1606 (void) FormatLocaleString(message,MaxTextExtent," /c {curveto} bind def\n");
1607 (void) ConcatenateString(&path,message);
1608 (void) FormatLocaleString(message,MaxTextExtent," /l {lineto} bind def\n");
1609 (void) ConcatenateString(&path,message);
1610 (void) FormatLocaleString(message,MaxTextExtent," /m {moveto} bind def\n");
1611 (void) ConcatenateString(&path,message);
1612 (void) FormatLocaleString(message,MaxTextExtent,
1613 " /v {currentpoint 6 2 roll curveto} bind def\n");
1614 (void) ConcatenateString(&path,message);
1615 (void) FormatLocaleString(message,MaxTextExtent,
1616 " /y {2 copy curveto} bind def\n");
1617 (void) ConcatenateString(&path,message);
1618 (void) FormatLocaleString(message,MaxTextExtent,
1619 " /z {closepath} bind def\n");
1620 (void) ConcatenateString(&path,message);
1621 (void) FormatLocaleString(message,MaxTextExtent," newpath\n");
1622 (void) ConcatenateString(&path,message);
1624 The clipping path format is defined in "Adobe Photoshop File
1625 Formats Specification" version 6.0 downloadable from adobe.com.
1627 (void) ResetMagickMemory(point,0,sizeof(point));
1628 (void) ResetMagickMemory(first,0,sizeof(first));
1629 (void) ResetMagickMemory(last,0,sizeof(last));
1631 in_subpath=MagickFalse;
1634 selector=(ssize_t) ReadPropertyMSBShort(&blob,&length);
1640 if (knot_count != 0)
1647 Expected subpath length record.
1649 knot_count=(ssize_t) ReadPropertyMSBShort(&blob,&length);
1659 if (knot_count == 0)
1662 Unexpected subpath knot
1671 for (i=0; i < 3; i++)
1677 yy=ReadPropertyMSBLong(&blob,&length);
1678 xx=ReadPropertyMSBLong(&blob,&length);
1680 if (xx > 2147483647)
1681 x=(ssize_t) xx-4294967295U-1;
1683 if (yy > 2147483647)
1684 y=(ssize_t) yy-4294967295U-1;
1685 point[i].x=(double) x/4096/4096;
1686 point[i].y=1.0-(double) y/4096/4096;
1688 if (in_subpath == MagickFalse)
1690 (void) FormatLocaleString(message,MaxTextExtent," %g %g m\n",
1691 point[1].x,point[1].y);
1692 for (i=0; i < 3; i++)
1701 Handle special cases when Bezier curves are used to describe
1702 corners and straight lines.
1704 if ((last[1].x == last[2].x) && (last[1].y == last[2].y) &&
1705 (point[0].x == point[1].x) && (point[0].y == point[1].y))
1706 (void) FormatLocaleString(message,MaxTextExtent,
1707 " %g %g l\n",point[1].x,point[1].y);
1709 if ((last[1].x == last[2].x) && (last[1].y == last[2].y))
1710 (void) FormatLocaleString(message,MaxTextExtent,
1711 " %g %g %g %g v\n",point[0].x,point[0].y,
1712 point[1].x,point[1].y);
1714 if ((point[0].x == point[1].x) && (point[0].y == point[1].y))
1715 (void) FormatLocaleString(message,MaxTextExtent,
1716 " %g %g %g %g y\n",last[2].x,last[2].y,
1717 point[1].x,point[1].y);
1719 (void) FormatLocaleString(message,MaxTextExtent,
1720 " %g %g %g %g %g %g c\n",last[2].x,
1721 last[2].y,point[0].x,point[0].y,point[1].x,point[1].y);
1722 for (i=0; i < 3; i++)
1725 (void) ConcatenateString(&path,message);
1726 in_subpath=MagickTrue;
1729 Close the subpath if there are no more knots.
1731 if (knot_count == 0)
1734 Same special handling as above except we compare to the
1735 first point in the path and close the path.
1737 if ((last[1].x == last[2].x) && (last[1].y == last[2].y) &&
1738 (first[0].x == first[1].x) && (first[0].y == first[1].y))
1739 (void) FormatLocaleString(message,MaxTextExtent,
1740 " %g %g l z\n",first[1].x,first[1].y);
1742 if ((last[1].x == last[2].x) && (last[1].y == last[2].y))
1743 (void) FormatLocaleString(message,MaxTextExtent,
1744 " %g %g %g %g v z\n",first[0].x,first[0].y,
1745 first[1].x,first[1].y);
1747 if ((first[0].x == first[1].x) && (first[0].y == first[1].y))
1748 (void) FormatLocaleString(message,MaxTextExtent,
1749 " %g %g %g %g y z\n",last[2].x,last[2].y,
1750 first[1].x,first[1].y);
1752 (void) FormatLocaleString(message,MaxTextExtent,
1753 " %g %g %g %g %g %g c z\n",last[2].x,
1754 last[2].y,first[0].x,first[0].y,first[1].x,first[1].y);
1755 (void) ConcatenateString(&path,message);
1756 in_subpath=MagickFalse;
1772 Returns an empty PS path if the path has no knots.
1774 (void) FormatLocaleString(message,MaxTextExtent," eoclip\n");
1775 (void) ConcatenateString(&path,message);
1776 (void) FormatLocaleString(message,MaxTextExtent,"} bind def");
1777 (void) ConcatenateString(&path,message);
1778 message=DestroyString(message);
1782 static char *TraceSVGClippath(const unsigned char *blob,size_t length,
1783 const size_t columns,const size_t rows)
1806 path=AcquireString((char *) NULL);
1807 if (path == (char *) NULL)
1808 return((char *) NULL);
1809 message=AcquireString((char *) NULL);
1810 (void) FormatLocaleString(message,MaxTextExtent,
1811 "<?xml version=\"1.0\" encoding=\"iso-8859-1\"?>\n");
1812 (void) ConcatenateString(&path,message);
1813 (void) FormatLocaleString(message,MaxTextExtent,
1814 "<svg width=\"%.20g\" height=\"%.20g\">\n",(double) columns,(double) rows);
1815 (void) ConcatenateString(&path,message);
1816 (void) FormatLocaleString(message,MaxTextExtent,"<g>\n");
1817 (void) ConcatenateString(&path,message);
1818 (void) FormatLocaleString(message,MaxTextExtent,
1819 "<path style=\"fill:#00000000;stroke:#00000000;");
1820 (void) ConcatenateString(&path,message);
1821 (void) FormatLocaleString(message,MaxTextExtent,
1822 "stroke-width:0;stroke-antialiasing:false\" d=\"\n");
1823 (void) ConcatenateString(&path,message);
1824 (void) ResetMagickMemory(point,0,sizeof(point));
1825 (void) ResetMagickMemory(first,0,sizeof(first));
1826 (void) ResetMagickMemory(last,0,sizeof(last));
1828 in_subpath=MagickFalse;
1831 selector=(ssize_t) ReadPropertyMSBShort(&blob,&length);
1837 if (knot_count != 0)
1844 Expected subpath length record.
1846 knot_count=(ssize_t) ReadPropertyMSBShort(&blob,&length);
1856 if (knot_count == 0)
1859 Unexpected subpath knot.
1868 for (i=0; i < 3; i++)
1874 yy=ReadPropertyMSBLong(&blob,&length);
1875 xx=ReadPropertyMSBLong(&blob,&length);
1877 if (xx > 2147483647)
1878 x=(ssize_t) xx-4294967295U-1;
1880 if (yy > 2147483647)
1881 y=(ssize_t) yy-4294967295U-1;
1882 point[i].x=(double) x*columns/4096/4096;
1883 point[i].y=(double) y*rows/4096/4096;
1885 if (in_subpath == MagickFalse)
1887 (void) FormatLocaleString(message,MaxTextExtent,"M %g,%g\n",
1888 point[1].x,point[1].y);
1889 for (i=0; i < 3; i++)
1897 if ((last[1].x == last[2].x) && (last[1].y == last[2].y) &&
1898 (point[0].x == point[1].x) && (point[0].y == point[1].y))
1899 (void) FormatLocaleString(message,MaxTextExtent,"L %g,%g\n",
1900 point[1].x,point[1].y);
1902 (void) FormatLocaleString(message,MaxTextExtent,
1903 "C %g,%g %g,%g %g,%g\n",last[2].x,last[2].y,
1904 point[0].x,point[0].y,point[1].x,point[1].y);
1905 for (i=0; i < 3; i++)
1908 (void) ConcatenateString(&path,message);
1909 in_subpath=MagickTrue;
1912 Close the subpath if there are no more knots.
1914 if (knot_count == 0)
1916 if ((last[1].x == last[2].x) && (last[1].y == last[2].y) &&
1917 (first[0].x == first[1].x) && (first[0].y == first[1].y))
1918 (void) FormatLocaleString(message,MaxTextExtent,
1919 "L %g,%g Z\n",first[1].x,first[1].y);
1922 (void) FormatLocaleString(message,MaxTextExtent,
1923 "C %g,%g %g,%g %g,%g Z\n",last[2].x,
1924 last[2].y,first[0].x,first[0].y,first[1].x,first[1].y);
1925 (void) ConcatenateString(&path,message);
1927 in_subpath=MagickFalse;
1943 Return an empty SVG image if the path does not have knots.
1945 (void) FormatLocaleString(message,MaxTextExtent,"\"/>\n");
1946 (void) ConcatenateString(&path,message);
1947 (void) FormatLocaleString(message,MaxTextExtent,"</g>\n");
1948 (void) ConcatenateString(&path,message);
1949 (void) FormatLocaleString(message,MaxTextExtent,"</svg>\n");
1950 (void) ConcatenateString(&path,message);
1951 message=DestroyString(message);
1955 MagickExport const char *GetImageProperty(const Image *image,
1956 const char *property,ExceptionInfo *exception)
1970 assert(image != (Image *) NULL);
1971 assert(image->signature == MagickSignature);
1972 if (image->debug != MagickFalse)
1973 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1974 p=(const char *) NULL;
1975 if (image->properties != (void *) NULL)
1977 if (property == (const char *) NULL)
1979 ResetSplayTreeIterator((SplayTreeInfo *) image->properties);
1980 p=(const char *) GetNextValueInSplayTree((SplayTreeInfo *)
1984 if (LocaleNCompare("fx:",property,3) != 0)
1986 p=(const char *) GetValueFromSplayTree((SplayTreeInfo *)
1987 image->properties,property);
1988 if (p != (const char *) NULL)
1992 if ((property == (const char *) NULL) ||
1993 (strchr(property,':') == (char *) NULL))
1999 if (LocaleNCompare("8bim:",property,5) == 0)
2001 if ((Get8BIMProperty(image,property,exception) != MagickFalse) &&
2002 (image->properties != (void *) NULL))
2004 p=(const char *) GetValueFromSplayTree((SplayTreeInfo *)
2005 image->properties,property);
2014 if (LocaleNCompare("exif:",property,5) == 0)
2016 if ((GetEXIFProperty(image,property,exception) != MagickFalse) &&
2017 (image->properties != (void *) NULL))
2019 p=(const char *) GetValueFromSplayTree((SplayTreeInfo *)
2020 image->properties,property);
2029 if (LocaleNCompare("fx:",property,3) == 0)
2031 fx_info=AcquireFxInfo(image,property+3);
2032 status=FxEvaluateChannelExpression(fx_info,IntensityPixelChannel,0,0,
2034 fx_info=DestroyFxInfo(fx_info);
2035 if (status != MagickFalse)
2038 value[MaxTextExtent];
2040 (void) FormatLocaleString(value,MaxTextExtent,"%.*g",
2041 GetMagickPrecision(),(double) alpha);
2042 (void) SetImageProperty((Image *) image,property,value,exception);
2044 if (image->properties != (void *) NULL)
2046 p=(const char *) GetValueFromSplayTree((SplayTreeInfo *)
2047 image->properties,property);
2056 if (LocaleNCompare("iptc:",property,5) == 0)
2058 if ((GetIPTCProperty(image,property,exception) != MagickFalse) &&
2059 (image->properties != (void *) NULL))
2061 p=(const char *) GetValueFromSplayTree((SplayTreeInfo *)
2062 image->properties,property);
2071 if (LocaleNCompare("pixel:",property,6) == 0)
2076 GetPixelInfo(image,&pixel);
2077 fx_info=AcquireFxInfo(image,property+6);
2078 status=FxEvaluateChannelExpression(fx_info,RedPixelChannel,0,0,
2080 pixel.red=(MagickRealType) QuantumRange*alpha;
2081 status|=FxEvaluateChannelExpression(fx_info,GreenPixelChannel,0,0,
2083 pixel.green=(MagickRealType) QuantumRange*alpha;
2084 status|=FxEvaluateChannelExpression(fx_info,BluePixelChannel,0,0,
2086 pixel.blue=(MagickRealType) QuantumRange*alpha;
2087 if (image->colorspace == CMYKColorspace)
2089 status|=FxEvaluateChannelExpression(fx_info,BlackPixelChannel,0,0,
2091 pixel.black=(MagickRealType) QuantumRange*alpha;
2093 status|=FxEvaluateChannelExpression(fx_info,AlphaPixelChannel,0,0,
2095 pixel.alpha=(MagickRealType) QuantumRange*(1.0-alpha);
2096 fx_info=DestroyFxInfo(fx_info);
2097 if (status != MagickFalse)
2100 name[MaxTextExtent];
2102 (void) QueryColorname(image,&pixel,SVGCompliance,name,
2104 (void) SetImageProperty((Image *) image,property,name,exception);
2105 return(GetImageProperty(image,property,exception));
2113 if (LocaleNCompare("xmp:",property,4) == 0)
2115 if ((GetXMPProperty(image,property) != MagickFalse) &&
2116 (image->properties != (void *) NULL))
2118 p=(const char *) GetValueFromSplayTree((SplayTreeInfo *)
2119 image->properties,property);
2132 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2136 + G e t M a g i c k P r o p e r t y %
2140 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2142 % GetMagickProperty() gets a value associated with an image property.
2144 % The format of the GetMagickProperty method is:
2146 % const char *GetMagickProperty(const ImageInfo *image_info,Image *image,
2147 % const char *key,ExceptionInfo *exception)
2149 % A description of each parameter follows:
2151 % o image_info: the image info.
2153 % o image: the image.
2157 % o exception: return any errors or warnings in this structure.
2160 MagickExport const char *GetMagickProperty(const ImageInfo *image_info,
2161 Image *image,const char *property,ExceptionInfo *exception)
2164 value[MaxTextExtent],
2165 filename[MaxTextExtent];
2172 if (LocaleNCompare("base",property,4) == 0)
2174 GetPathComponent(image->magick_filename,BasePath,filename);
2175 (void) CopyMagickString(value,filename,MaxTextExtent);
2182 if (LocaleNCompare("channels",property,8) == 0)
2187 (void) FormatLocaleString(value,MaxTextExtent,"%s",
2188 CommandOptionToMnemonic(MagickColorspaceOptions,(ssize_t)
2189 image->colorspace));
2191 if (image->matte != MagickFalse)
2192 (void) ConcatenateMagickString(value,"a",MaxTextExtent);
2195 if (LocaleNCompare("colorspace",property,10) == 0)
2201 Image storage class and colorspace.
2203 colorspace=image->colorspace;
2204 if (IsImageGray(image,exception) != MagickFalse)
2205 colorspace=GRAYColorspace;
2206 (void) FormatLocaleString(value,MaxTextExtent,"%s",
2207 CommandOptionToMnemonic(MagickColorspaceOptions,(ssize_t)
2211 if (LocaleNCompare("copyright",property,9) == 0)
2213 (void) CopyMagickString(value,GetMagickCopyright(),MaxTextExtent);
2220 if (LocaleNCompare("depth",property,5) == 0)
2222 (void) FormatLocaleString(value,MaxTextExtent,"%.20g",(double)
2226 if (LocaleNCompare("directory",property,9) == 0)
2228 GetPathComponent(image->magick_filename,HeadPath,filename);
2229 (void) CopyMagickString(value,filename,MaxTextExtent);
2236 if (LocaleNCompare("extension",property,9) == 0)
2238 GetPathComponent(image->magick_filename,ExtensionPath,filename);
2239 (void) CopyMagickString(value,filename,MaxTextExtent);
2246 if (LocaleNCompare("group",property,5) == 0)
2248 (void) FormatLocaleString(value,MaxTextExtent,"0x%lx",
2249 (unsigned long) image_info->group);
2256 if (LocaleNCompare("height",property,6) == 0)
2258 (void) FormatLocaleString(value,MaxTextExtent,"%.20g",
2259 image->magick_rows != 0 ? (double) image->magick_rows : 256.0);
2266 if (LocaleNCompare("input",property,5) == 0)
2268 (void) CopyMagickString(value,image->filename,MaxTextExtent);
2275 if (LocaleNCompare("kurtosis",property,8) == 0)
2281 (void) GetImageKurtosis(image,&kurtosis,&skewness,exception);
2282 (void) FormatLocaleString(value,MaxTextExtent,"%.*g",
2283 GetMagickPrecision(),kurtosis);
2290 if (LocaleNCompare("magick",property,6) == 0)
2292 (void) CopyMagickString(value,image->magick,MaxTextExtent);
2295 if (LocaleNCompare("max",property,3) == 0)
2301 (void) GetImageRange(image,&minimum,&maximum,exception);
2302 (void) FormatLocaleString(value,MaxTextExtent,"%.*g",
2303 GetMagickPrecision(),maximum);
2306 if (LocaleNCompare("mean",property,4) == 0)
2312 (void) GetImageMean(image,&mean,&standard_deviation,
2314 (void) FormatLocaleString(value,MaxTextExtent,"%.*g",
2315 GetMagickPrecision(),mean);
2318 if (LocaleNCompare("min",property,3) == 0)
2324 (void) GetImageRange(image,&minimum,&maximum,exception);
2325 (void) FormatLocaleString(value,MaxTextExtent,"%.*g",
2326 GetMagickPrecision(),minimum);
2333 if (LocaleNCompare("name",property,4) == 0)
2335 (void) CopyMagickString(value,filename,MaxTextExtent);
2342 if (LocaleNCompare("opaque",property,6) == 0)
2347 opaque=IsImageOpaque(image,exception);
2348 (void) CopyMagickString(value,opaque == MagickFalse ? "false" :
2349 "true",MaxTextExtent);
2352 if (LocaleNCompare("output",property,6) == 0)
2354 (void) CopyMagickString(value,image_info->filename,MaxTextExtent);
2361 if (LocaleNCompare("page",property,4) == 0)
2363 (void) FormatLocaleString(value,MaxTextExtent,"%.20g",(double)
2364 GetImageIndexInList(image)+1);
2371 if (LocaleNCompare("size",property,4) == 0)
2374 format[MaxTextExtent];
2376 (void) FormatMagickSize(GetBlobSize(image),MagickFalse,format);
2377 (void) FormatLocaleString(value,MaxTextExtent,"%sB",format);
2380 if (LocaleNCompare("scenes",property,6) == 0)
2382 (void) FormatLocaleString(value,MaxTextExtent,"%.20g",(double)
2383 GetImageListLength(image));
2386 if (LocaleNCompare("scene",property,5) == 0)
2388 /* FUTURE: I am not certain this properity return makes sense! */
2389 (void) FormatLocaleString(value,MaxTextExtent,"%.20g",(double)
2391 if (image_info->number_scenes != 0)
2392 (void) FormatLocaleString(value,MaxTextExtent,"%.20g",(double)
2396 if (LocaleNCompare("skewness",property,8) == 0)
2402 (void) GetImageKurtosis(image,&kurtosis,&skewness,exception);
2403 (void) FormatLocaleString(value,MaxTextExtent,"%.*g",
2404 GetMagickPrecision(),skewness);
2407 if (LocaleNCompare("standard-deviation",property,18) == 0)
2413 (void) GetImageMean(image,&mean,&standard_deviation,
2415 (void) FormatLocaleString(value,MaxTextExtent,"%.*g",
2416 GetMagickPrecision(),standard_deviation);
2423 if (LocaleNCompare("unique",property,6) == 0)
2425 (void) CopyMagickString(filename,image_info->unique,MaxTextExtent);
2426 (void) CopyMagickString(value,filename,MaxTextExtent);
2433 if (LocaleNCompare("version",property,7) == 0)
2435 (void) CopyMagickString(value,GetMagickVersion((size_t *) NULL),
2443 if (LocaleNCompare("width",property,5) == 0)
2445 (void) FormatLocaleString(value,MaxTextExtent,"%.20g",(double)
2446 (image->magick_columns != 0 ? image->magick_columns : 256));
2453 if (LocaleNCompare("xresolution",property,11) == 0)
2455 (void) FormatLocaleString(value,MaxTextExtent,"%g",
2456 image->resolution.x);
2463 if (LocaleNCompare("yresolution",property,11) == 0)
2465 (void) FormatLocaleString(value,MaxTextExtent,"%g",
2466 image->resolution.y);
2473 if (LocaleNCompare("zero",property,4) == 0)
2475 (void) CopyMagickString(filename,image_info->zero,MaxTextExtent);
2476 (void) CopyMagickString(value,filename,MaxTextExtent);
2484 if (image->properties == (void *) NULL)
2485 image->properties=NewSplayTree(CompareSplayTreeString,
2486 RelinquishMagickMemory,RelinquishMagickMemory);
2487 (void) AddValueToSplayTree((SplayTreeInfo *) image->properties,
2488 ConstantString(property),ConstantString(value));
2490 return(GetImageProperty(image,property,exception));
2494 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2498 % G e t N e x t I m a g e P r o p e r t y %
2502 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2504 % GetNextImageProperty() gets the next image property value.
2506 % The format of the GetNextImageProperty method is:
2508 % char *GetNextImageProperty(const Image *image)
2510 % A description of each parameter follows:
2512 % o image: the image.
2515 MagickExport char *GetNextImageProperty(const Image *image)
2517 assert(image != (Image *) NULL);
2518 assert(image->signature == MagickSignature);
2519 if (image->debug != MagickFalse)
2520 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
2522 if (image->properties == (void *) NULL)
2523 return((char *) NULL);
2524 return((char *) GetNextKeyInSplayTree((SplayTreeInfo *) image->properties));
2528 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2532 % I n t e r p r e t I m a g e P r o p e r t i e s %
2536 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2538 % InterpretImageProperties() replaces any embedded formatting characters with
2539 % the appropriate image property and returns the interpreted text.
2541 % The format of the InterpretImageProperties method is:
2543 % char *InterpretImageProperties(const ImageInfo *image_info,Image *image,
2544 % const char *embed_text,ExceptionInfo *exception)
2546 % A description of each parameter follows:
2548 % o image_info: the image info.
2550 % o image: the image.
2552 % o embed_text: the address of a character string containing the embedded
2553 % formatting characters.
2555 % o exception: return any errors or warnings in this structure.
2558 MagickExport char *InterpretImageProperties(const ImageInfo *image_info,
2559 Image *image,const char *embed_text,ExceptionInfo *exception)
2562 filename[MaxTextExtent],
2582 assert(image != (Image *) NULL);
2583 assert(image->signature == MagickSignature);
2584 if (image->debug != MagickFalse)
2585 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
2586 if ((embed_text == (const char *) NULL) || (*embed_text == '\0'))
2587 return((char *) NULL);
2588 text=(char *) embed_text;
2589 if ((*text == '@') && ((*(text+1) == '-') ||
2590 (IsPathAccessible(text+1) != MagickFalse)))
2591 return(FileToString(embed_text+1,~0,exception));
2593 Translate any embedded format characters.
2595 interpret_text=AcquireString(text);
2596 extent=MaxTextExtent;
2598 for (q=interpret_text; *p != '\0'; p++)
2601 if ((size_t) (q-interpret_text+MaxTextExtent) >= extent)
2603 extent+=MaxTextExtent;
2604 interpret_text=(char *) ResizeQuantumMemory(interpret_text,extent+
2605 MaxTextExtent+1,sizeof(*interpret_text));
2606 if (interpret_text == (char *) NULL)
2608 q=interpret_text+strlen(interpret_text);
2611 Process formatting characters in text.
2613 if ((*p == '\\') && (*(p+1) == 'r'))
2619 if ((*p == '\\') && (*(p+1) == 'n'))
2639 case '[': /* multi-character substitution */
2642 pattern[MaxTextExtent];
2654 if (strchr(p,']') == (char *) NULL)
2658 for (i=0; (i < (MaxTextExtent-1L)) && (*p != '\0'); i++)
2669 value=GetImageProperty(image,pattern,exception);
2670 if (value != (const char *) NULL)
2672 length=strlen(value);
2673 if ((size_t) (q-interpret_text+length+1) >= extent)
2676 interpret_text=(char *) ResizeQuantumMemory(interpret_text,
2677 extent+MaxTextExtent,sizeof(*interpret_text));
2678 if (interpret_text == (char *) NULL)
2680 q=interpret_text+strlen(interpret_text);
2682 (void) CopyMagickString(q,value,extent);
2687 if (IsGlob(pattern) != MagickFalse)
2690 Iterate over image properties.
2692 ResetImagePropertyIterator(image);
2693 key=GetNextImageProperty(image);
2694 while (key != (const char *) NULL)
2696 if (GlobExpression(key,pattern,MagickTrue) != MagickFalse)
2698 value=GetImageProperty(image,key,exception);
2699 if (value != (const char *) NULL)
2701 length=strlen(key)+strlen(value)+2;
2702 if ((size_t) (q-interpret_text+length+1) >= extent)
2705 interpret_text=(char *) ResizeQuantumMemory(
2706 interpret_text,extent+MaxTextExtent,
2707 sizeof(*interpret_text));
2708 if (interpret_text == (char *) NULL)
2710 q=interpret_text+strlen(interpret_text);
2712 q+=FormatLocaleString(q,extent,"%s=%s\n",key,value);
2715 key=GetNextImageProperty(image);
2718 value=GetMagickProperty(image_info,image,pattern,exception);
2719 if (value != (const char *) NULL)
2721 length=strlen(value);
2722 if ((size_t) (q-interpret_text+length+1) >= extent)
2725 interpret_text=(char *) ResizeQuantumMemory(interpret_text,
2726 extent+MaxTextExtent,sizeof(*interpret_text));
2727 if (interpret_text == (char *) NULL)
2729 q=interpret_text+strlen(interpret_text);
2731 (void) CopyMagickString(q,value,extent);
2735 if (image_info == (ImageInfo *) NULL)
2737 value=GetImageOption(image_info,pattern);
2738 if (value != (char *) NULL)
2740 length=strlen(value);
2741 if ((size_t) (q-interpret_text+length+1) >= extent)
2744 interpret_text=(char *) ResizeQuantumMemory(interpret_text,
2745 extent+MaxTextExtent,sizeof(*interpret_text));
2746 if (interpret_text == (char *) NULL)
2748 q=interpret_text+strlen(interpret_text);
2750 (void) CopyMagickString(q,value,extent);
2756 case 'b': /* image size as read in */
2759 format[MaxTextExtent];
2761 (void) FormatLocaleString(format,MaxTextExtent,"%.20g",(double)
2762 ((MagickOffsetType) image->extent));
2763 if (image->extent != (MagickSizeType) ((size_t) image->extent))
2764 (void) FormatMagickSize(image->extent,MagickFalse,format);
2765 q+=ConcatenateMagickString(q,format,extent);
2766 q+=ConcatenateMagickString(q,"B",extent);
2769 case 'c': /* image comment properity */
2771 value=GetImageProperty(image,"comment",exception);
2772 if (value == (const char *) NULL)
2774 length=strlen(value);
2775 if ((size_t) (q-interpret_text+length+1) >= extent)
2778 interpret_text=(char *) ResizeQuantumMemory(interpret_text,extent+
2779 MaxTextExtent,sizeof(*interpret_text));
2780 if (interpret_text == (char *) NULL)
2782 q=interpret_text+strlen(interpret_text);
2784 (void) CopyMagickString(q,value,extent);
2788 case 'd': /* Directory component of filename */
2790 GetPathComponent(image->magick_filename,HeadPath,filename);
2791 q+=CopyMagickString(q,filename,extent);
2794 case 'e': /* Filename extension (suffix) of image file */
2796 GetPathComponent(image->magick_filename,ExtensionPath,filename);
2797 q+=CopyMagickString(q,filename,extent);
2800 case 'f': /* Filename without directory component */
2802 GetPathComponent(image->magick_filename,TailPath,filename);
2803 q+=CopyMagickString(q,filename,extent);
2806 case 't': /* Base filename without directory or extention */
2808 GetPathComponent(image->magick_filename,BasePath,filename);
2809 q+=CopyMagickString(q,filename,extent);
2812 case 'g': /* Image geometry, canvas and offset */
2814 q+=FormatLocaleString(q,extent,"%.20gx%.20g%+.20g%+.20g",(double)
2815 image->page.width,(double) image->page.height,(double) image->page.x,
2816 (double) image->page.y);
2819 case 'h': /* Image height */
2821 q+=FormatLocaleString(q,extent,"%.20g",(double) (image->rows != 0 ?
2822 image->rows : image->magick_rows));
2825 case 'i': /* Images filename - (output filename with "info:" ) */
2827 q+=CopyMagickString(q,image->filename,extent);
2830 case 'k': /* Number of unique colors */
2832 q+=FormatLocaleString(q,extent,"%.20g",(double) GetNumberColors(image,
2833 (FILE *) NULL,exception));
2836 case 'l': /* Image label */
2838 value=GetImageProperty(image,"label",exception);
2839 if (value == (const char *) NULL)
2841 length=strlen(value);
2842 if ((size_t) (q-interpret_text+length+1) >= extent)
2845 interpret_text=(char *) ResizeQuantumMemory(interpret_text,extent+
2846 MaxTextExtent,sizeof(*interpret_text));
2847 if (interpret_text == (char *) NULL)
2849 q=interpret_text+strlen(interpret_text);
2851 q+=CopyMagickString(q,value,extent);
2854 case 'm': /* Image format (file magick) */
2856 q+=CopyMagickString(q,image->magick,extent);
2859 case 'M': /* Magick filename - exactly as given incl. read mods */
2861 q+=CopyMagickString(q,image->magick_filename,extent);
2864 case 'n': /* Number of images in the list. */
2866 q+=FormatLocaleString(q,extent,"%.20g",(double)
2867 GetImageListLength(image));
2870 case 'o': /* Image output filename */
2872 q+=CopyMagickString(q,image_info->filename,extent);
2875 case 'p': /* Image index in current image list */
2877 q+=FormatLocaleString(q,extent,"%.20g",(double)
2878 GetImageIndexInList(image));
2881 case 'q': /* Quantum depth of image in memory */
2883 q+=FormatLocaleString(q,extent,"%.20g",(double)
2884 MAGICKCORE_QUANTUM_DEPTH);
2887 case 'r': /* Image storage class and colorspace. */
2892 colorspace=image->colorspace;
2893 if (IsImageGray(image,exception) != MagickFalse)
2894 colorspace=GRAYColorspace;
2895 q+=FormatLocaleString(q,extent,"%s%s%s",CommandOptionToMnemonic(
2896 MagickClassOptions,(ssize_t) image->storage_class),
2897 CommandOptionToMnemonic(MagickColorspaceOptions,(ssize_t) colorspace),
2898 image->matte != MagickFalse ? "Matte" : "");
2901 case 's': /* Image scene number */
2903 if (image_info->number_scenes == 0)
2904 q+=FormatLocaleString(q,extent,"%.20g",(double) image->scene);
2906 q+=FormatLocaleString(q,extent,"%.20g",(double) image_info->scene);
2909 case 'u': /* Unique filename */
2911 (void) CopyMagickString(filename,image_info->unique,extent);
2912 q+=CopyMagickString(q,filename,extent);
2915 case 'w': /* Image width */
2917 q+=FormatLocaleString(q,extent,"%.20g",(double) (image->columns != 0 ?
2918 image->columns : image->magick_columns));
2921 case 'x': /* Image horizontal resolution (density). */
2923 q+=FormatLocaleString(q,extent,"%g %s",image->resolution.x,
2924 CommandOptionToMnemonic(MagickResolutionOptions,(ssize_t)
2928 case 'y': /* Image vertical resolution (density) */
2930 q+=FormatLocaleString(q,extent,"%g %s",image->resolution.y,
2931 CommandOptionToMnemonic(MagickResolutionOptions,(ssize_t)
2935 case 'z': /* Image depth as read in */
2937 q+=FormatLocaleString(q,extent,"%.20g",(double) image->depth);
2940 case 'A': /* Image alpha channel */
2942 q+=FormatLocaleString(q,extent,"%s",CommandOptionToMnemonic(
2943 MagickBooleanOptions,(ssize_t) image->matte));
2946 case 'C': /* Image compression method. */
2948 q+=FormatLocaleString(q,extent,"%s",CommandOptionToMnemonic(
2949 MagickCompressOptions,(ssize_t) image->compression));
2952 case 'D': /* Image dispose method. */
2954 q+=FormatLocaleString(q,extent,"%s",CommandOptionToMnemonic(
2955 MagickDisposeOptions,(ssize_t) image->dispose));
2958 case 'G': /* Image size as geometry = "%wx%h" */
2960 q+=FormatLocaleString(q,extent,"%.20gx%.20g",(double)
2961 image->magick_columns,(double) image->magick_rows);
2964 case 'H': /* layer canvas height */
2966 q+=FormatLocaleString(q,extent,"%.20g",(double) image->page.height);
2969 case 'O': /* layer canvas offset with sign = "+%X+%Y" */
2971 q+=FormatLocaleString(q,extent,"%+ld%+ld",(long) image->page.x,(long)
2975 case 'P': /* layer canvas page size = "%Wx%H" */
2977 q+=FormatLocaleString(q,extent,"%.20gx%.20g",(double) image->page.width,
2978 (double) image->page.height);
2981 case 'Q': /* image compression quality */
2983 q+=FormatLocaleString(q,extent,"%.20g",(double) image->quality);
2986 case 'S': /* Image scenes */
2988 if (image_info->number_scenes == 0)
2989 q+=CopyMagickString(q,"2147483647",extent);
2991 q+=FormatLocaleString(q,extent,"%.20g",(double) (image_info->scene+
2992 image_info->number_scenes));
2995 case 'T': /* image time delay for animations */
2997 q+=FormatLocaleString(q,extent,"%.20g",(double) image->delay);
3000 case 'W': /* layer canvas width */
3002 q+=FormatLocaleString(q,extent,"%.20g",(double) image->page.width);
3005 case 'X': /* layer canvas X offset */
3007 q+=FormatLocaleString(q,extent,"%+.20g",(double) image->page.x);
3010 case 'Y': /* layer canvas Y offset */
3012 q+=FormatLocaleString(q,extent,"%+.20g",(double) image->page.y);
3015 case 'Z': /* Unique filename. */
3017 (void) CopyMagickString(filename,image_info->zero,extent);
3018 q+=CopyMagickString(q,filename,extent);
3021 case '@': /* Image bounding box. */
3026 page=GetImageBoundingBox(image,exception);
3027 q+=FormatLocaleString(q,MaxTextExtent,"%.20gx%.20g%+.20g%+.20g",
3028 (double) page.width,(double) page.height,(double) page.x,(double)
3032 case '#': /* Image signature */
3034 (void) SignatureImage(image,exception);
3035 value=GetImageProperty(image,"signature",exception);
3036 if (value == (const char *) NULL)
3038 q+=CopyMagickString(q,value,extent);
3041 case '%': /* percent escaped */
3046 default: /* percent not expanded */
3055 if (text != (const char *) embed_text)
3056 text=DestroyString(text);
3057 (void) SubstituteString(&interpret_text,"<","<");
3058 (void) SubstituteString(&interpret_text,">",">");
3059 return(interpret_text);
3063 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3067 % R e m o v e I m a g e P r o p e r t y %
3071 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3073 % RemoveImageProperty() removes a property from the image and returns its
3076 % The format of the RemoveImageProperty method is:
3078 % char *RemoveImageProperty(Image *image,const char *property)
3080 % A description of each parameter follows:
3082 % o image: the image.
3084 % o property: the image property.
3087 MagickExport char *RemoveImageProperty(Image *image,
3088 const char *property)
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 value=(char *) RemoveNodeFromSplayTree((SplayTreeInfo *) image->properties,
3106 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3110 % 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 %
3114 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3116 % ResetImagePropertyIterator() resets the image properties iterator. Use it
3117 % in conjunction with GetNextImageProperty() to iterate over all the values
3118 % associated with an image property.
3120 % The format of the ResetImagePropertyIterator method is:
3122 % ResetImagePropertyIterator(Image *image)
3124 % A description of each parameter follows:
3126 % o image: the image.
3129 MagickExport void ResetImagePropertyIterator(const Image *image)
3131 assert(image != (Image *) NULL);
3132 assert(image->signature == MagickSignature);
3133 if (image->debug != MagickFalse)
3134 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
3136 if (image->properties == (void *) NULL)
3138 ResetSplayTreeIterator((SplayTreeInfo *) image->properties);
3142 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3146 % S e t I m a g e P r o p e r t y %
3150 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3152 % SetImageProperty() associates an value with an image property.
3154 % The format of the SetImageProperty method is:
3156 % MagickBooleanType SetImageProperty(Image *image,const char *property,
3157 % const char *value,ExceptionInfo *exception)
3159 % A description of each parameter follows:
3161 % o image: the image.
3163 % o property: the image property.
3165 % o values: the image property values.
3167 % o exception: return any errors or warnings in this structure.
3170 MagickExport MagickBooleanType SetImageProperty(Image *image,
3171 const char *property,const char *value,ExceptionInfo *exception)
3179 assert(image != (Image *) NULL);
3180 assert(image->signature == MagickSignature);
3181 if (image->debug != MagickFalse)
3182 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
3184 if (image->properties == (void *) NULL)
3185 image->properties=NewSplayTree(CompareSplayTreeString,
3186 RelinquishMagickMemory,RelinquishMagickMemory);
3187 if ((value == (const char *) NULL) || (*value == '\0'))
3188 return(DeleteImageProperty(image,property));
3195 if (LocaleCompare(property,"background") == 0)
3197 (void) QueryColorCompliance(value,AllCompliance,
3198 &image->background_color,exception);
3201 if (LocaleCompare(property,"bias") == 0)
3203 image->bias=StringToDoubleInterval(value,(double) QuantumRange+1.0);
3206 status=AddValueToSplayTree((SplayTreeInfo *) image->properties,
3207 ConstantString(property),ConstantString(value));
3213 if (LocaleCompare(property,"colorspace") == 0)
3218 colorspace=ParseCommandOption(MagickColorspaceOptions,MagickFalse,
3222 (void) SetImageColorspace(image,(ColorspaceType) colorspace,
3226 if (LocaleCompare(property,"compose") == 0)
3231 compose=ParseCommandOption(MagickComposeOptions,MagickFalse,value);
3234 image->compose=(CompositeOperator) compose;
3237 if (LocaleCompare(property,"compress") == 0)
3242 compression=ParseCommandOption(MagickCompressOptions,MagickFalse,
3244 if (compression < 0)
3246 image->compression=(CompressionType) compression;
3249 status=AddValueToSplayTree((SplayTreeInfo *) image->properties,
3250 ConstantString(property),ConstantString(value));
3256 if (LocaleCompare(property,"delay") == 0)
3261 flags=ParseGeometry(value,&geometry_info);
3262 if ((flags & GreaterValue) != 0)
3264 if (image->delay > (size_t) floor(geometry_info.rho+0.5))
3265 image->delay=(size_t) floor(geometry_info.rho+0.5);
3268 if ((flags & LessValue) != 0)
3270 if (image->delay < (size_t) floor(geometry_info.rho+0.5))
3271 image->ticks_per_second=(ssize_t)
3272 floor(geometry_info.sigma+0.5);
3275 image->delay=(size_t) floor(geometry_info.rho+0.5);
3276 if ((flags & SigmaValue) != 0)
3277 image->ticks_per_second=(ssize_t) floor(geometry_info.sigma+0.5);
3280 if (LocaleCompare(property,"density") == 0)
3285 flags=ParseGeometry(value,&geometry_info);
3286 image->resolution.x=geometry_info.rho;
3287 image->resolution.y=geometry_info.sigma;
3288 if ((flags & SigmaValue) == 0)
3289 image->resolution.y=image->resolution.x;
3291 if (LocaleCompare(property,"depth") == 0)
3293 image->depth=StringToUnsignedLong(value);
3296 if (LocaleCompare(property,"dispose") == 0)
3301 dispose=ParseCommandOption(MagickDisposeOptions,MagickFalse,value);
3304 image->dispose=(DisposeType) dispose;
3307 status=AddValueToSplayTree((SplayTreeInfo *) image->properties,
3308 ConstantString(property),ConstantString(value));
3314 if (LocaleCompare(property,"gravity") == 0)
3319 gravity=ParseCommandOption(MagickGravityOptions,MagickFalse,value);
3322 image->gravity=(GravityType) gravity;
3325 status=AddValueToSplayTree((SplayTreeInfo *) image->properties,
3326 ConstantString(property),ConstantString(value));
3332 if (LocaleCompare(property,"intent") == 0)
3337 rendering_intent=ParseCommandOption(MagickIntentOptions,MagickFalse,
3339 if (rendering_intent < 0)
3341 image->rendering_intent=(RenderingIntent) rendering_intent;
3344 if (LocaleCompare(property,"interpolate") == 0)
3349 interpolate=ParseCommandOption(MagickInterpolateOptions,MagickFalse,
3351 if (interpolate < 0)
3353 image->interpolate=(PixelInterpolateMethod) interpolate;
3356 status=AddValueToSplayTree((SplayTreeInfo *) image->properties,
3357 ConstantString(property),ConstantString(value));
3363 if (LocaleCompare(property,"loop") == 0)
3365 image->iterations=StringToUnsignedLong(value);
3368 status=AddValueToSplayTree((SplayTreeInfo *) image->properties,
3369 ConstantString(property),ConstantString(value));
3375 if (LocaleCompare(property,"page") == 0)
3380 geometry=GetPageGeometry(value);
3381 flags=ParseAbsoluteGeometry(geometry,&image->page);
3382 geometry=DestroyString(geometry);
3385 if (LocaleCompare(property,"profile") == 0)
3393 image_info=AcquireImageInfo();
3394 (void) CopyMagickString(image_info->filename,value,MaxTextExtent);
3395 (void) SetImageInfo(image_info,1,exception);
3396 profile=FileToStringInfo(image_info->filename,~0UL,exception);
3397 if (profile != (StringInfo *) NULL)
3398 status=SetImageProfile(image,image_info->magick,profile,exception);
3399 image_info=DestroyImageInfo(image_info);
3402 status=AddValueToSplayTree((SplayTreeInfo *) image->properties,
3403 ConstantString(property),ConstantString(value));
3409 if (LocaleCompare(property,"rendering-intent") == 0)
3414 rendering_intent=ParseCommandOption(MagickIntentOptions,MagickFalse,
3416 if (rendering_intent < 0)
3418 image->rendering_intent=(RenderingIntent) rendering_intent;
3421 status=AddValueToSplayTree((SplayTreeInfo *) image->properties,
3422 ConstantString(property),ConstantString(value));
3428 if (LocaleCompare(property,"tile-offset") == 0)
3433 geometry=GetPageGeometry(value);
3434 flags=ParseAbsoluteGeometry(geometry,&image->tile_offset);
3435 geometry=DestroyString(geometry);
3438 status=AddValueToSplayTree((SplayTreeInfo *) image->properties,
3439 ConstantString(property),ConstantString(value));
3445 if (LocaleCompare(property,"units") == 0)
3450 units=ParseCommandOption(MagickResolutionOptions,MagickFalse,value);
3453 image->units=(ResolutionType) units;
3456 status=AddValueToSplayTree((SplayTreeInfo *) image->properties,
3457 ConstantString(property),ConstantString(value));
3462 status=AddValueToSplayTree((SplayTreeInfo *) image->properties,
3463 ConstantString(property),ConstantString(value));