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-2011 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->x_resolution=clone_image->x_resolution;
142 image->y_resolution=clone_image->y_resolution;
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)
197 % A description of each parameter follows:
199 % o image: the image.
201 % o property: the image property.
204 MagickExport MagickBooleanType DefineImageProperty(Image *image,
205 const char *property)
209 value[MaxTextExtent];
214 assert(image != (Image *) NULL);
215 assert(property != (const char *) NULL);
216 (void) CopyMagickString(key,property,MaxTextExtent-1);
217 for (p=key; *p != '\0'; p++)
222 (void) CopyMagickString(value,p+1,MaxTextExtent);
224 return(SetImageProperty(image,key,value));
228 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
232 % D e l e t e I m a g e P r o p e r t y %
236 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
238 % DeleteImageProperty() deletes an image property.
240 % The format of the DeleteImageProperty method is:
242 % MagickBooleanType DeleteImageProperty(Image *image,const char *property)
244 % A description of each parameter follows:
246 % o image: the image.
248 % o property: the image property.
251 MagickExport MagickBooleanType DeleteImageProperty(Image *image,
252 const char *property)
254 assert(image != (Image *) NULL);
255 assert(image->signature == MagickSignature);
256 if (image->debug != MagickFalse)
257 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
259 if (image->properties == (void *) NULL)
261 return(DeleteNodeFromSplayTree((SplayTreeInfo *) image->properties,property));
265 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
269 % D e s t r o y I m a g e P r o p e r t i e s %
273 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
275 % DestroyImageProperties() releases memory associated with image property
278 % The format of the DestroyDefines method is:
280 % void DestroyImageProperties(Image *image)
282 % A description of each parameter follows:
284 % o image: the image.
287 MagickExport void DestroyImageProperties(Image *image)
289 assert(image != (Image *) NULL);
290 assert(image->signature == MagickSignature);
291 if (image->debug != MagickFalse)
292 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
294 if (image->properties != (void *) NULL)
295 image->properties=(void *) DestroySplayTree((SplayTreeInfo *)
300 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
304 % F o r m a t I m a g e P r o p e r t y %
308 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
310 % FormatImageProperty() permits formatted property/value pairs to be saved as
313 % The format of the FormatImageProperty method is:
315 % MagickBooleanType FormatImageProperty(Image *image,const char *property,
316 % const char *format,...)
318 % A description of each parameter follows.
320 % o image: The image.
322 % o property: The attribute property.
324 % o format: A string describing the format to use to write the remaining
328 MagickExport MagickBooleanType FormatImageProperty(Image *image,
329 const char *property,const char *format,...)
332 value[MaxTextExtent];
340 va_start(operands,format);
341 n=FormatLocaleStringList(value,MaxTextExtent,format,operands);
344 return(SetImageProperty(image,property,value));
348 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
352 % G e t I m a g e P r o p e r t y %
356 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
358 % GetImageProperty() gets a value associated with an image property.
360 % The format of the GetImageProperty method is:
362 % const char *GetImageProperty(const Image *image,const char *key)
364 % A description of each parameter follows:
366 % o image: the image.
373 *TracePSClippath(const unsigned char *,size_t,const size_t,
375 *TraceSVGClippath(const unsigned char *,size_t,const size_t,
378 static MagickBooleanType GetIPTCProperty(const Image *image,const char *key)
398 profile=GetImageProfile(image,"iptc");
399 if (profile == (StringInfo *) NULL)
400 profile=GetImageProfile(image,"8bim");
401 if (profile == (StringInfo *) NULL)
403 count=sscanf(key,"IPTC:%ld:%ld",&dataset,&record);
406 attribute=(char *) NULL;
407 for (i=0; i < (ssize_t) GetStringInfoLength(profile); i+=(ssize_t) length)
410 if ((ssize_t) GetStringInfoDatum(profile)[i] != 0x1c)
412 length=(size_t) (GetStringInfoDatum(profile)[i+3] << 8);
413 length|=GetStringInfoDatum(profile)[i+4];
414 if (((long) GetStringInfoDatum(profile)[i+1] == dataset) &&
415 ((long) GetStringInfoDatum(profile)[i+2] == record))
417 message=(char *) NULL;
419 message=(char *) AcquireQuantumMemory(length+1UL,sizeof(*message));
420 if (message != (char *) NULL)
422 (void) CopyMagickString(message,(char *) GetStringInfoDatum(
423 profile)+i+5,length+1);
424 (void) ConcatenateString(&attribute,message);
425 (void) ConcatenateString(&attribute,";");
426 message=DestroyString(message);
431 if ((attribute == (char *) NULL) || (*attribute == ';'))
433 if (attribute != (char *) NULL)
434 attribute=DestroyString(attribute);
437 attribute[strlen(attribute)-1]='\0';
438 (void) SetImageProperty((Image *) image,key,(const char *) attribute);
439 attribute=DestroyString(attribute);
443 static inline ssize_t MagickMax(const ssize_t x,const ssize_t y)
450 static inline int ReadPropertyByte(const unsigned char **p,size_t *length)
462 static inline size_t ReadPropertyMSBLong(const unsigned char **p,
479 for (i=0; i < 4; i++)
483 buffer[i]=(unsigned char) c;
485 value=(size_t) (buffer[0] << 24);
486 value|=buffer[1] << 16;
487 value|=buffer[2] << 8;
489 return(value & 0xffffffff);
492 static inline unsigned short ReadPropertyMSBShort(const unsigned char **p,
508 return((unsigned short) ~0U);
509 for (i=0; i < 2; i++)
513 buffer[i]=(unsigned char) c;
515 value=(unsigned short) (buffer[0] << 8);
517 return((unsigned short) (value & 0xffff));
520 static MagickBooleanType Get8BIMProperty(const Image *image,const char *key)
524 format[MaxTextExtent],
553 There are no newlines in path names, so it's safe as terminator.
555 profile=GetImageProfile(image,"8bim");
556 if (profile == (StringInfo *) NULL)
558 count=(ssize_t) sscanf(key,"8BIM:%ld,%ld:%[^\n]\n%[^\n]",&start,&stop,name,
560 if ((count != 2) && (count != 3) && (count != 4))
563 (void) CopyMagickString(format,"SVG",MaxTextExtent);
568 sub_number=(ssize_t) StringToLong(&name[1]);
569 sub_number=MagickMax(sub_number,1L);
570 resource=(char *) NULL;
572 length=GetStringInfoLength(profile);
573 info=GetStringInfoDatum(profile);
574 while ((length > 0) && (status == MagickFalse))
576 if (ReadPropertyByte(&info,&length) != (unsigned char) '8')
578 if (ReadPropertyByte(&info,&length) != (unsigned char) 'B')
580 if (ReadPropertyByte(&info,&length) != (unsigned char) 'I')
582 if (ReadPropertyByte(&info,&length) != (unsigned char) 'M')
584 id=(ssize_t) ReadPropertyMSBShort(&info,&length);
585 if (id < (ssize_t) start)
587 if (id > (ssize_t) stop)
589 if (resource != (char *) NULL)
590 resource=DestroyString(resource);
591 count=(ssize_t) ReadPropertyByte(&info,&length);
592 if ((count != 0) && ((size_t) count <= length))
594 resource=(char *) NULL;
595 if (~(1UL*count) >= (MaxTextExtent-1))
596 resource=(char *) AcquireQuantumMemory((size_t) count+MaxTextExtent,
598 if (resource != (char *) NULL)
600 for (i=0; i < (ssize_t) count; i++)
601 resource[i]=(char) ReadPropertyByte(&info,&length);
602 resource[count]='\0';
605 if ((count & 0x01) == 0)
606 (void) ReadPropertyByte(&info,&length);
607 count=(ssize_t) ((int) ReadPropertyMSBLong(&info,&length));
608 if ((*name != '\0') && (*name != '#'))
609 if ((resource == (char *) NULL) || (LocaleCompare(name,resource) != 0))
612 No name match, scroll forward and try next.
618 if ((*name == '#') && (sub_number != 1))
621 No numbered match, scroll forward and try next.
629 We have the resource of interest.
631 attribute=(char *) NULL;
632 if (~(1UL*count) >= (MaxTextExtent-1))
633 attribute=(char *) AcquireQuantumMemory((size_t) count+MaxTextExtent,
635 if (attribute != (char *) NULL)
637 (void) CopyMagickMemory(attribute,(char *) info,(size_t) count);
638 attribute[count]='\0';
641 if ((id <= 1999) || (id >= 2999))
642 (void) SetImageProperty((Image *) image,key,(const char *)
649 if (LocaleCompare(format,"svg") == 0)
650 path=TraceSVGClippath((unsigned char *) attribute,(size_t) count,
651 image->columns,image->rows);
653 path=TracePSClippath((unsigned char *) attribute,(size_t) count,
654 image->columns,image->rows);
655 (void) SetImageProperty((Image *) image,key,(const char *) path);
656 path=DestroyString(path);
658 attribute=DestroyString(attribute);
662 if (resource != (char *) NULL)
663 resource=DestroyString(resource);
667 static inline unsigned short ReadPropertyShort(const EndianType endian,
668 const unsigned char *buffer)
673 if (endian == MSBEndian)
675 value=(unsigned short) ((((unsigned char *) buffer)[0] << 8) |
676 ((unsigned char *) buffer)[1]);
677 return((unsigned short) (value & 0xffff));
679 value=(unsigned short) ((buffer[1] << 8) | buffer[0]);
680 return((unsigned short) (value & 0xffff));
683 static inline size_t ReadPropertyLong(const EndianType endian,
684 const unsigned char *buffer)
689 if (endian == MSBEndian)
691 value=(size_t) ((buffer[0] << 24) | (buffer[1] << 16) |
692 (buffer[2] << 8) | buffer[3]);
693 return((size_t) (value & 0xffffffff));
695 value=(size_t) ((buffer[3] << 24) | (buffer[2] << 16) |
696 (buffer[1] << 8 ) | (buffer[0]));
697 return((size_t) (value & 0xffffffff));
700 static MagickBooleanType GetEXIFProperty(const Image *image,
701 const char *property)
703 #define MaxDirectoryStack 16
704 #define EXIF_DELIMITER "\n"
705 #define EXIF_NUM_FORMATS 12
706 #define EXIF_FMT_BYTE 1
707 #define EXIF_FMT_STRING 2
708 #define EXIF_FMT_USHORT 3
709 #define EXIF_FMT_ULONG 4
710 #define EXIF_FMT_URATIONAL 5
711 #define EXIF_FMT_SBYTE 6
712 #define EXIF_FMT_UNDEFINED 7
713 #define EXIF_FMT_SSHORT 8
714 #define EXIF_FMT_SLONG 9
715 #define EXIF_FMT_SRATIONAL 10
716 #define EXIF_FMT_SINGLE 11
717 #define EXIF_FMT_DOUBLE 12
718 #define TAG_EXIF_OFFSET 0x8769
719 #define TAG_GPS_OFFSET 0x8825
720 #define TAG_INTEROP_OFFSET 0xa005
722 #define EXIFMultipleValues(size, format, arg) \
735 for (component=0; component < components; component++) \
737 length+=FormatLocaleString(buffer+length,MaxTextExtent-length, \
739 if (length >= (MaxTextExtent-1)) \
740 length=MaxTextExtent-1; \
744 buffer[length-2]='\0'; \
745 value=AcquireString(buffer); \
748 #define EXIFMultipleFractions(size, format, arg1, arg2) \
761 for (component=0; component < components; component++) \
763 length+=FormatLocaleString(buffer+length,MaxTextExtent-length, \
764 format", ",arg1, arg2); \
765 if (length >= (MaxTextExtent-1)) \
766 length=MaxTextExtent-1; \
770 buffer[length-2]='\0'; \
771 value=AcquireString(buffer); \
774 typedef struct _DirectoryInfo
784 typedef struct _TagInfo
796 { 0x001, "exif:InteroperabilityIndex" },
797 { 0x002, "exif:InteroperabilityVersion" },
798 { 0x100, "exif:ImageWidth" },
799 { 0x101, "exif:ImageLength" },
800 { 0x102, "exif:BitsPerSample" },
801 { 0x103, "exif:Compression" },
802 { 0x106, "exif:PhotometricInterpretation" },
803 { 0x10a, "exif:FillOrder" },
804 { 0x10d, "exif:DocumentName" },
805 { 0x10e, "exif:ImageDescription" },
806 { 0x10f, "exif:Make" },
807 { 0x110, "exif:Model" },
808 { 0x111, "exif:StripOffsets" },
809 { 0x112, "exif:Orientation" },
810 { 0x115, "exif:SamplesPerPixel" },
811 { 0x116, "exif:RowsPerStrip" },
812 { 0x117, "exif:StripByteCounts" },
813 { 0x11a, "exif:XResolution" },
814 { 0x11b, "exif:YResolution" },
815 { 0x11c, "exif:PlanarConfiguration" },
816 { 0x11d, "exif:PageName" },
817 { 0x11e, "exif:XPosition" },
818 { 0x11f, "exif:YPosition" },
819 { 0x118, "exif:MinSampleValue" },
820 { 0x119, "exif:MaxSampleValue" },
821 { 0x120, "exif:FreeOffsets" },
822 { 0x121, "exif:FreeByteCounts" },
823 { 0x122, "exif:GrayResponseUnit" },
824 { 0x123, "exif:GrayResponseCurve" },
825 { 0x124, "exif:T4Options" },
826 { 0x125, "exif:T6Options" },
827 { 0x128, "exif:ResolutionUnit" },
828 { 0x12d, "exif:TransferFunction" },
829 { 0x131, "exif:Software" },
830 { 0x132, "exif:DateTime" },
831 { 0x13b, "exif:Artist" },
832 { 0x13e, "exif:WhitePoint" },
833 { 0x13f, "exif:PrimaryChromaticities" },
834 { 0x140, "exif:ColorMap" },
835 { 0x141, "exif:HalfToneHints" },
836 { 0x142, "exif:TileWidth" },
837 { 0x143, "exif:TileLength" },
838 { 0x144, "exif:TileOffsets" },
839 { 0x145, "exif:TileByteCounts" },
840 { 0x14a, "exif:SubIFD" },
841 { 0x14c, "exif:InkSet" },
842 { 0x14d, "exif:InkNames" },
843 { 0x14e, "exif:NumberOfInks" },
844 { 0x150, "exif:DotRange" },
845 { 0x151, "exif:TargetPrinter" },
846 { 0x152, "exif:ExtraSample" },
847 { 0x153, "exif:SampleFormat" },
848 { 0x154, "exif:SMinSampleValue" },
849 { 0x155, "exif:SMaxSampleValue" },
850 { 0x156, "exif:TransferRange" },
851 { 0x157, "exif:ClipPath" },
852 { 0x158, "exif:XClipPathUnits" },
853 { 0x159, "exif:YClipPathUnits" },
854 { 0x15a, "exif:Indexed" },
855 { 0x15b, "exif:JPEGTables" },
856 { 0x15f, "exif:OPIProxy" },
857 { 0x200, "exif:JPEGProc" },
858 { 0x201, "exif:JPEGInterchangeFormat" },
859 { 0x202, "exif:JPEGInterchangeFormatLength" },
860 { 0x203, "exif:JPEGRestartInterval" },
861 { 0x205, "exif:JPEGLosslessPredictors" },
862 { 0x206, "exif:JPEGPointTransforms" },
863 { 0x207, "exif:JPEGQTables" },
864 { 0x208, "exif:JPEGDCTables" },
865 { 0x209, "exif:JPEGACTables" },
866 { 0x211, "exif:YCbCrCoefficients" },
867 { 0x212, "exif:YCbCrSubSampling" },
868 { 0x213, "exif:YCbCrPositioning" },
869 { 0x214, "exif:ReferenceBlackWhite" },
870 { 0x2bc, "exif:ExtensibleMetadataPlatform" },
871 { 0x301, "exif:Gamma" },
872 { 0x302, "exif:ICCProfileDescriptor" },
873 { 0x303, "exif:SRGBRenderingIntent" },
874 { 0x320, "exif:ImageTitle" },
875 { 0x5001, "exif:ResolutionXUnit" },
876 { 0x5002, "exif:ResolutionYUnit" },
877 { 0x5003, "exif:ResolutionXLengthUnit" },
878 { 0x5004, "exif:ResolutionYLengthUnit" },
879 { 0x5005, "exif:PrintFlags" },
880 { 0x5006, "exif:PrintFlagsVersion" },
881 { 0x5007, "exif:PrintFlagsCrop" },
882 { 0x5008, "exif:PrintFlagsBleedWidth" },
883 { 0x5009, "exif:PrintFlagsBleedWidthScale" },
884 { 0x500A, "exif:HalftoneLPI" },
885 { 0x500B, "exif:HalftoneLPIUnit" },
886 { 0x500C, "exif:HalftoneDegree" },
887 { 0x500D, "exif:HalftoneShape" },
888 { 0x500E, "exif:HalftoneMisc" },
889 { 0x500F, "exif:HalftoneScreen" },
890 { 0x5010, "exif:JPEGQuality" },
891 { 0x5011, "exif:GridSize" },
892 { 0x5012, "exif:ThumbnailFormat" },
893 { 0x5013, "exif:ThumbnailWidth" },
894 { 0x5014, "exif:ThumbnailHeight" },
895 { 0x5015, "exif:ThumbnailColorDepth" },
896 { 0x5016, "exif:ThumbnailPlanes" },
897 { 0x5017, "exif:ThumbnailRawBytes" },
898 { 0x5018, "exif:ThumbnailSize" },
899 { 0x5019, "exif:ThumbnailCompressedSize" },
900 { 0x501a, "exif:ColorTransferFunction" },
901 { 0x501b, "exif:ThumbnailData" },
902 { 0x5020, "exif:ThumbnailImageWidth" },
903 { 0x5021, "exif:ThumbnailImageHeight" },
904 { 0x5022, "exif:ThumbnailBitsPerSample" },
905 { 0x5023, "exif:ThumbnailCompression" },
906 { 0x5024, "exif:ThumbnailPhotometricInterp" },
907 { 0x5025, "exif:ThumbnailImageDescription" },
908 { 0x5026, "exif:ThumbnailEquipMake" },
909 { 0x5027, "exif:ThumbnailEquipModel" },
910 { 0x5028, "exif:ThumbnailStripOffsets" },
911 { 0x5029, "exif:ThumbnailOrientation" },
912 { 0x502a, "exif:ThumbnailSamplesPerPixel" },
913 { 0x502b, "exif:ThumbnailRowsPerStrip" },
914 { 0x502c, "exif:ThumbnailStripBytesCount" },
915 { 0x502d, "exif:ThumbnailResolutionX" },
916 { 0x502e, "exif:ThumbnailResolutionY" },
917 { 0x502f, "exif:ThumbnailPlanarConfig" },
918 { 0x5030, "exif:ThumbnailResolutionUnit" },
919 { 0x5031, "exif:ThumbnailTransferFunction" },
920 { 0x5032, "exif:ThumbnailSoftwareUsed" },
921 { 0x5033, "exif:ThumbnailDateTime" },
922 { 0x5034, "exif:ThumbnailArtist" },
923 { 0x5035, "exif:ThumbnailWhitePoint" },
924 { 0x5036, "exif:ThumbnailPrimaryChromaticities" },
925 { 0x5037, "exif:ThumbnailYCbCrCoefficients" },
926 { 0x5038, "exif:ThumbnailYCbCrSubsampling" },
927 { 0x5039, "exif:ThumbnailYCbCrPositioning" },
928 { 0x503A, "exif:ThumbnailRefBlackWhite" },
929 { 0x503B, "exif:ThumbnailCopyRight" },
930 { 0x5090, "exif:LuminanceTable" },
931 { 0x5091, "exif:ChrominanceTable" },
932 { 0x5100, "exif:FrameDelay" },
933 { 0x5101, "exif:LoopCount" },
934 { 0x5110, "exif:PixelUnit" },
935 { 0x5111, "exif:PixelPerUnitX" },
936 { 0x5112, "exif:PixelPerUnitY" },
937 { 0x5113, "exif:PaletteHistogram" },
938 { 0x1000, "exif:RelatedImageFileFormat" },
939 { 0x1001, "exif:RelatedImageLength" },
940 { 0x1002, "exif:RelatedImageWidth" },
941 { 0x800d, "exif:ImageID" },
942 { 0x80e3, "exif:Matteing" },
943 { 0x80e4, "exif:DataType" },
944 { 0x80e5, "exif:ImageDepth" },
945 { 0x80e6, "exif:TileDepth" },
946 { 0x828d, "exif:CFARepeatPatternDim" },
947 { 0x828e, "exif:CFAPattern2" },
948 { 0x828f, "exif:BatteryLevel" },
949 { 0x8298, "exif:Copyright" },
950 { 0x829a, "exif:ExposureTime" },
951 { 0x829d, "exif:FNumber" },
952 { 0x83bb, "exif:IPTC/NAA" },
953 { 0x84e3, "exif:IT8RasterPadding" },
954 { 0x84e5, "exif:IT8ColorTable" },
955 { 0x8649, "exif:ImageResourceInformation" },
956 { 0x8769, "exif:ExifOffset" },
957 { 0x8773, "exif:InterColorProfile" },
958 { 0x8822, "exif:ExposureProgram" },
959 { 0x8824, "exif:SpectralSensitivity" },
960 { 0x8825, "exif:GPSInfo" },
961 { 0x8827, "exif:ISOSpeedRatings" },
962 { 0x8828, "exif:OECF" },
963 { 0x8829, "exif:Interlace" },
964 { 0x882a, "exif:TimeZoneOffset" },
965 { 0x882b, "exif:SelfTimerMode" },
966 { 0x9000, "exif:ExifVersion" },
967 { 0x9003, "exif:DateTimeOriginal" },
968 { 0x9004, "exif:DateTimeDigitized" },
969 { 0x9101, "exif:ComponentsConfiguration" },
970 { 0x9102, "exif:CompressedBitsPerPixel" },
971 { 0x9201, "exif:ShutterSpeedValue" },
972 { 0x9202, "exif:ApertureValue" },
973 { 0x9203, "exif:BrightnessValue" },
974 { 0x9204, "exif:ExposureBiasValue" },
975 { 0x9205, "exif:MaxApertureValue" },
976 { 0x9206, "exif:SubjectDistance" },
977 { 0x9207, "exif:MeteringMode" },
978 { 0x9208, "exif:LightSource" },
979 { 0x9209, "exif:Flash" },
980 { 0x920a, "exif:FocalLength" },
981 { 0x920b, "exif:FlashEnergy" },
982 { 0x920c, "exif:SpatialFrequencyResponse" },
983 { 0x920d, "exif:Noise" },
984 { 0x9211, "exif:ImageNumber" },
985 { 0x9212, "exif:SecurityClassification" },
986 { 0x9213, "exif:ImageHistory" },
987 { 0x9214, "exif:SubjectArea" },
988 { 0x9215, "exif:ExposureIndex" },
989 { 0x9216, "exif:TIFF-EPStandardID" },
990 { 0x927c, "exif:MakerNote" },
991 { 0x9C9b, "exif:WinXP-Title" },
992 { 0x9C9c, "exif:WinXP-Comments" },
993 { 0x9C9d, "exif:WinXP-Author" },
994 { 0x9C9e, "exif:WinXP-Keywords" },
995 { 0x9C9f, "exif:WinXP-Subject" },
996 { 0x9286, "exif:UserComment" },
997 { 0x9290, "exif:SubSecTime" },
998 { 0x9291, "exif:SubSecTimeOriginal" },
999 { 0x9292, "exif:SubSecTimeDigitized" },
1000 { 0xa000, "exif:FlashPixVersion" },
1001 { 0xa001, "exif:ColorSpace" },
1002 { 0xa002, "exif:ExifImageWidth" },
1003 { 0xa003, "exif:ExifImageLength" },
1004 { 0xa004, "exif:RelatedSoundFile" },
1005 { 0xa005, "exif:InteroperabilityOffset" },
1006 { 0xa20b, "exif:FlashEnergy" },
1007 { 0xa20c, "exif:SpatialFrequencyResponse" },
1008 { 0xa20d, "exif:Noise" },
1009 { 0xa20e, "exif:FocalPlaneXResolution" },
1010 { 0xa20f, "exif:FocalPlaneYResolution" },
1011 { 0xa210, "exif:FocalPlaneResolutionUnit" },
1012 { 0xa214, "exif:SubjectLocation" },
1013 { 0xa215, "exif:ExposureIndex" },
1014 { 0xa216, "exif:TIFF/EPStandardID" },
1015 { 0xa217, "exif:SensingMethod" },
1016 { 0xa300, "exif:FileSource" },
1017 { 0xa301, "exif:SceneType" },
1018 { 0xa302, "exif:CFAPattern" },
1019 { 0xa401, "exif:CustomRendered" },
1020 { 0xa402, "exif:ExposureMode" },
1021 { 0xa403, "exif:WhiteBalance" },
1022 { 0xa404, "exif:DigitalZoomRatio" },
1023 { 0xa405, "exif:FocalLengthIn35mmFilm" },
1024 { 0xa406, "exif:SceneCaptureType" },
1025 { 0xa407, "exif:GainControl" },
1026 { 0xa408, "exif:Contrast" },
1027 { 0xa409, "exif:Saturation" },
1028 { 0xa40a, "exif:Sharpness" },
1029 { 0xa40b, "exif:DeviceSettingDescription" },
1030 { 0xa40c, "exif:SubjectDistanceRange" },
1031 { 0xa420, "exif:ImageUniqueID" },
1032 { 0xc4a5, "exif:PrintImageMatching" },
1033 { 0xa500, "exif:Gamma" },
1034 { 0xc640, "exif:CR2Slice" },
1035 { 0x10000, "exif:GPSVersionID" },
1036 { 0x10001, "exif:GPSLatitudeRef" },
1037 { 0x10002, "exif:GPSLatitude" },
1038 { 0x10003, "exif:GPSLongitudeRef" },
1039 { 0x10004, "exif:GPSLongitude" },
1040 { 0x10005, "exif:GPSAltitudeRef" },
1041 { 0x10006, "exif:GPSAltitude" },
1042 { 0x10007, "exif:GPSTimeStamp" },
1043 { 0x10008, "exif:GPSSatellites" },
1044 { 0x10009, "exif:GPSStatus" },
1045 { 0x1000a, "exif:GPSMeasureMode" },
1046 { 0x1000b, "exif:GPSDop" },
1047 { 0x1000c, "exif:GPSSpeedRef" },
1048 { 0x1000d, "exif:GPSSpeed" },
1049 { 0x1000e, "exif:GPSTrackRef" },
1050 { 0x1000f, "exif:GPSTrack" },
1051 { 0x10010, "exif:GPSImgDirectionRef" },
1052 { 0x10011, "exif:GPSImgDirection" },
1053 { 0x10012, "exif:GPSMapDatum" },
1054 { 0x10013, "exif:GPSDestLatitudeRef" },
1055 { 0x10014, "exif:GPSDestLatitude" },
1056 { 0x10015, "exif:GPSDestLongitudeRef" },
1057 { 0x10016, "exif:GPSDestLongitude" },
1058 { 0x10017, "exif:GPSDestBearingRef" },
1059 { 0x10018, "exif:GPSDestBearing" },
1060 { 0x10019, "exif:GPSDestDistanceRef" },
1061 { 0x1001a, "exif:GPSDestDistance" },
1062 { 0x1001b, "exif:GPSProcessingMethod" },
1063 { 0x1001c, "exif:GPSAreaInformation" },
1064 { 0x1001d, "exif:GPSDateStamp" },
1065 { 0x1001e, "exif:GPSDifferential" },
1077 directory_stack[MaxDirectoryStack];
1103 tag_bytes[] = {0, 1, 1, 2, 4, 8, 1, 1, 2, 4, 8, 4, 8};
1106 If EXIF data exists, then try to parse the request for a tag.
1108 profile=GetImageProfile(image,"exif");
1109 if (profile == (StringInfo *) NULL)
1110 return(MagickFalse);
1111 if ((property == (const char *) NULL) || (*property == '\0'))
1112 return(MagickFalse);
1113 while (isspace((int) ((unsigned char) *property)) != 0)
1117 switch (*(property+5))
1122 Caller has asked for all the tags in the EXIF data.
1125 all=1; /* return the data in description=value format */
1131 all=2; /* return the data in tagid=value format */
1144 Check for a hex based tag specification first.
1146 tag=(*(property+5) == '@') ? 1UL : 0UL;
1150 return(MagickFalse);
1152 Parse tag specification as a hex number.
1157 for (i=(ssize_t) n-1L; i >= 0; i--)
1161 if ((c >= '0') && (c <= '9'))
1164 if ((c >= 'A') && (c <= 'F'))
1167 if ((c >= 'a') && (c <= 'f'))
1170 return(MagickFalse);
1172 } while (*property != '\0');
1178 Try to match the text with a tag name instead.
1182 if (EXIFTag[i].tag == 0)
1184 if (LocaleCompare(EXIFTag[i].description,property) == 0)
1186 tag=(size_t) EXIFTag[i].tag;
1194 return(MagickFalse);
1195 length=GetStringInfoLength(profile);
1196 exif=GetStringInfoDatum(profile);
1199 if (ReadPropertyByte(&exif,&length) != 0x45)
1201 if (ReadPropertyByte(&exif,&length) != 0x78)
1203 if (ReadPropertyByte(&exif,&length) != 0x69)
1205 if (ReadPropertyByte(&exif,&length) != 0x66)
1207 if (ReadPropertyByte(&exif,&length) != 0x00)
1209 if (ReadPropertyByte(&exif,&length) != 0x00)
1214 return(MagickFalse);
1215 id=(ssize_t) ReadPropertyShort(LSBEndian,exif);
1223 return(MagickFalse);
1224 if (ReadPropertyShort(endian,exif+2) != 0x002a)
1225 return(MagickFalse);
1227 This the offset to the first IFD.
1229 offset=(ssize_t) ((int) ReadPropertyLong(endian,exif+4));
1230 if ((size_t) offset >= length)
1231 return(MagickFalse);
1233 Set the pointer to the first IFD and follow it were it leads.
1236 directory=exif+offset;
1243 If there is anything on the stack then pop it off.
1248 directory=directory_stack[level].directory;
1249 entry=directory_stack[level].entry;
1250 tag_offset=directory_stack[level].offset;
1253 Determine how many entries there are in the current IFD.
1255 number_entries=ReadPropertyShort(endian,directory);
1256 for ( ; entry < number_entries; entry++)
1258 register unsigned char
1269 q=(unsigned char *) (directory+2+(12*entry));
1270 tag_value=(ssize_t) (ReadPropertyShort(endian,q)+tag_offset);
1271 format=(size_t) ReadPropertyShort(endian,q+2);
1272 if (format >= (sizeof(tag_bytes)/sizeof(*tag_bytes)))
1274 components=(ssize_t) ((int) ReadPropertyLong(endian,q+4));
1275 number_bytes=(size_t) components*tag_bytes[format];
1276 if (number_bytes <= 4)
1284 The directory entry contains an offset.
1286 offset=(ssize_t) ((int) ReadPropertyLong(endian,q+8));
1287 if ((size_t) (offset+number_bytes) > length)
1289 p=(unsigned char *) (exif+offset);
1291 if ((all != 0) || (tag == (size_t) tag_value))
1294 buffer[MaxTextExtent],
1300 case EXIF_FMT_UNDEFINED:
1302 EXIFMultipleValues(1,"%.20g",(double) (*(unsigned char *) p1));
1305 case EXIF_FMT_SBYTE:
1307 EXIFMultipleValues(1,"%.20g",(double) (*(signed char *) p1));
1310 case EXIF_FMT_SSHORT:
1312 EXIFMultipleValues(2,"%hd",ReadPropertyShort(endian,p1));
1315 case EXIF_FMT_USHORT:
1317 EXIFMultipleValues(2,"%hu",ReadPropertyShort(endian,p1));
1320 case EXIF_FMT_ULONG:
1322 EXIFMultipleValues(4,"%.20g",(double)
1323 ReadPropertyLong(endian,p1));
1326 case EXIF_FMT_SLONG:
1328 EXIFMultipleValues(4,"%.20g",(double)
1329 ReadPropertyLong(endian,p1));
1332 case EXIF_FMT_URATIONAL:
1334 EXIFMultipleFractions(8,"%.20g/%.20g",(double)
1335 ReadPropertyLong(endian,p1),(double)
1336 ReadPropertyLong(endian,p1+4));
1339 case EXIF_FMT_SRATIONAL:
1341 EXIFMultipleFractions(8,"%.20g/%.20g",(double)
1342 ReadPropertyLong(endian,p1),(double)
1343 ReadPropertyLong(endian,p1+4));
1346 case EXIF_FMT_SINGLE:
1348 EXIFMultipleValues(4,"%f",(double) *(float *) p1);
1351 case EXIF_FMT_DOUBLE:
1353 EXIFMultipleValues(8,"%f",*(double *) p1);
1357 case EXIF_FMT_STRING:
1359 value=(char *) NULL;
1360 if (~(1UL*number_bytes) >= 1)
1361 value=(char *) AcquireQuantumMemory((size_t) number_bytes+1UL,
1363 if (value != (char *) NULL)
1368 for (i=0; i < (ssize_t) number_bytes; i++)
1371 if ((isprint((int) p[i]) != 0) || (p[i] == '\0'))
1372 value[i]=(char) p[i];
1379 if (value != (char *) NULL)
1387 (void) CopyMagickString(key,property,MaxTextExtent);
1398 description="unknown";
1401 if (EXIFTag[i].tag == 0)
1403 if ((ssize_t) EXIFTag[i].tag == tag_value)
1405 description=EXIFTag[i].description;
1409 (void) FormatLocaleString(key,MaxTextExtent,"%s",
1415 if (tag_value < 0x10000)
1416 (void) FormatLocaleString(key,MaxTextExtent,"#%04lx",
1417 (unsigned long) tag_value);
1419 if (tag_value < 0x20000)
1420 (void) FormatLocaleString(key,MaxTextExtent,"@%04lx",
1421 (unsigned long) (tag_value & 0xffff));
1423 (void) FormatLocaleString(key,MaxTextExtent,"unknown");
1427 p=(const char *) NULL;
1428 if (image->properties != (void *) NULL)
1429 p=(const char *) GetValueFromSplayTree((SplayTreeInfo *)
1430 image->properties,key);
1431 if (p == (const char *) NULL)
1432 (void) SetImageProperty((Image *) image,key,value);
1433 value=DestroyString(value);
1437 if ((tag_value == TAG_EXIF_OFFSET) ||
1438 (tag_value == TAG_INTEROP_OFFSET) ||
1439 (tag_value == TAG_GPS_OFFSET))
1444 offset=(size_t) ReadPropertyLong(endian,p);
1445 if ((offset < length) && (level < (MaxDirectoryStack-2)))
1450 tag_offset1=(tag_value == TAG_GPS_OFFSET) ? 0x10000UL : 0UL;
1451 directory_stack[level].directory=directory;
1453 directory_stack[level].entry=entry;
1454 directory_stack[level].offset=tag_offset;
1456 directory_stack[level].directory=exif+offset;
1457 directory_stack[level].offset=tag_offset1;
1458 directory_stack[level].entry=0;
1460 if ((directory+2+(12*number_entries)) > (exif+length))
1462 offset=(size_t) ReadPropertyLong(endian,directory+2+(12*
1464 if ((offset != 0) && (offset < length) &&
1465 (level < (MaxDirectoryStack-2)))
1467 directory_stack[level].directory=exif+offset;
1468 directory_stack[level].entry=0;
1469 directory_stack[level].offset=tag_offset1;
1476 } while (level > 0);
1480 static MagickBooleanType GetXMPProperty(const Image *image,const char *property)
1504 profile=GetImageProfile(image,"xmp");
1505 if (profile == (StringInfo *) NULL)
1506 return(MagickFalse);
1507 if ((property == (const char *) NULL) || (*property == '\0'))
1508 return(MagickFalse);
1509 xmp_profile=StringInfoToString(profile);
1510 if (xmp_profile == (char *) NULL)
1511 return(MagickFalse);
1512 for (p=xmp_profile; *p != '\0'; p++)
1513 if ((*p == '<') && (*(p+1) == 'x'))
1515 exception=AcquireExceptionInfo();
1516 xmp=NewXMLTree((char *) p,exception);
1517 xmp_profile=DestroyString(xmp_profile);
1518 exception=DestroyExceptionInfo(exception);
1519 if (xmp == (XMLTreeInfo *) NULL)
1520 return(MagickFalse);
1522 rdf=GetXMLTreeChild(xmp,"rdf:RDF");
1523 if (rdf != (XMLTreeInfo *) NULL)
1525 if (image->properties == (void *) NULL)
1526 ((Image *) image)->properties=NewSplayTree(CompareSplayTreeString,
1527 RelinquishMagickMemory,RelinquishMagickMemory);
1528 description=GetXMLTreeChild(rdf,"rdf:Description");
1529 while (description != (XMLTreeInfo *) NULL)
1531 node=GetXMLTreeChild(description,(const char *) NULL);
1532 while (node != (XMLTreeInfo *) NULL)
1534 child=GetXMLTreeChild(node,(const char *) NULL);
1535 if (child == (XMLTreeInfo *) NULL)
1536 (void) AddValueToSplayTree((SplayTreeInfo *) image->properties,
1537 ConstantString(GetXMLTreeTag(node)),
1538 ConstantString(GetXMLTreeContent(node)));
1539 while (child != (XMLTreeInfo *) NULL)
1541 if (LocaleCompare(GetXMLTreeTag(child),"rdf:Seq") != 0)
1542 (void) AddValueToSplayTree((SplayTreeInfo *) image->properties,
1543 ConstantString(GetXMLTreeTag(child)),
1544 ConstantString(GetXMLTreeContent(child)));
1545 child=GetXMLTreeSibling(child);
1547 node=GetXMLTreeSibling(node);
1549 description=GetNextXMLTreeTag(description);
1552 xmp=DestroyXMLTree(xmp);
1556 static char *TracePSClippath(const unsigned char *blob,size_t length,
1557 const size_t magick_unused(columns),
1558 const size_t magick_unused(rows))
1581 path=AcquireString((char *) NULL);
1582 if (path == (char *) NULL)
1583 return((char *) NULL);
1584 message=AcquireString((char *) NULL);
1585 (void) FormatLocaleString(message,MaxTextExtent,"/ClipImage\n");
1586 (void) ConcatenateString(&path,message);
1587 (void) FormatLocaleString(message,MaxTextExtent,"{\n");
1588 (void) ConcatenateString(&path,message);
1589 (void) FormatLocaleString(message,MaxTextExtent," /c {curveto} bind def\n");
1590 (void) ConcatenateString(&path,message);
1591 (void) FormatLocaleString(message,MaxTextExtent," /l {lineto} bind def\n");
1592 (void) ConcatenateString(&path,message);
1593 (void) FormatLocaleString(message,MaxTextExtent," /m {moveto} bind def\n");
1594 (void) ConcatenateString(&path,message);
1595 (void) FormatLocaleString(message,MaxTextExtent,
1596 " /v {currentpoint 6 2 roll curveto} bind def\n");
1597 (void) ConcatenateString(&path,message);
1598 (void) FormatLocaleString(message,MaxTextExtent,
1599 " /y {2 copy curveto} bind def\n");
1600 (void) ConcatenateString(&path,message);
1601 (void) FormatLocaleString(message,MaxTextExtent,
1602 " /z {closepath} bind def\n");
1603 (void) ConcatenateString(&path,message);
1604 (void) FormatLocaleString(message,MaxTextExtent," newpath\n");
1605 (void) ConcatenateString(&path,message);
1607 The clipping path format is defined in "Adobe Photoshop File
1608 Formats Specification" version 6.0 downloadable from adobe.com.
1610 (void) ResetMagickMemory(point,0,sizeof(point));
1611 (void) ResetMagickMemory(first,0,sizeof(first));
1612 (void) ResetMagickMemory(last,0,sizeof(last));
1614 in_subpath=MagickFalse;
1617 selector=(ssize_t) ReadPropertyMSBShort(&blob,&length);
1623 if (knot_count != 0)
1630 Expected subpath length record.
1632 knot_count=(ssize_t) ReadPropertyMSBShort(&blob,&length);
1642 if (knot_count == 0)
1645 Unexpected subpath knot
1654 for (i=0; i < 3; i++)
1660 yy=ReadPropertyMSBLong(&blob,&length);
1661 xx=ReadPropertyMSBLong(&blob,&length);
1663 if (xx > 2147483647)
1664 x=(ssize_t) xx-4294967295U-1;
1666 if (yy > 2147483647)
1667 y=(ssize_t) yy-4294967295U-1;
1668 point[i].x=(double) x/4096/4096;
1669 point[i].y=1.0-(double) y/4096/4096;
1671 if (in_subpath == MagickFalse)
1673 (void) FormatLocaleString(message,MaxTextExtent," %g %g m\n",
1674 point[1].x,point[1].y);
1675 for (i=0; i < 3; i++)
1684 Handle special cases when Bezier curves are used to describe
1685 corners and straight lines.
1687 if ((last[1].x == last[2].x) && (last[1].y == last[2].y) &&
1688 (point[0].x == point[1].x) && (point[0].y == point[1].y))
1689 (void) FormatLocaleString(message,MaxTextExtent,
1690 " %g %g l\n",point[1].x,point[1].y);
1692 if ((last[1].x == last[2].x) && (last[1].y == last[2].y))
1693 (void) FormatLocaleString(message,MaxTextExtent,
1694 " %g %g %g %g v\n",point[0].x,point[0].y,
1695 point[1].x,point[1].y);
1697 if ((point[0].x == point[1].x) && (point[0].y == point[1].y))
1698 (void) FormatLocaleString(message,MaxTextExtent,
1699 " %g %g %g %g y\n",last[2].x,last[2].y,
1700 point[1].x,point[1].y);
1702 (void) FormatLocaleString(message,MaxTextExtent,
1703 " %g %g %g %g %g %g c\n",last[2].x,
1704 last[2].y,point[0].x,point[0].y,point[1].x,point[1].y);
1705 for (i=0; i < 3; i++)
1708 (void) ConcatenateString(&path,message);
1709 in_subpath=MagickTrue;
1712 Close the subpath if there are no more knots.
1714 if (knot_count == 0)
1717 Same special handling as above except we compare to the
1718 first point in the path and close the path.
1720 if ((last[1].x == last[2].x) && (last[1].y == last[2].y) &&
1721 (first[0].x == first[1].x) && (first[0].y == first[1].y))
1722 (void) FormatLocaleString(message,MaxTextExtent,
1723 " %g %g l z\n",first[1].x,first[1].y);
1725 if ((last[1].x == last[2].x) && (last[1].y == last[2].y))
1726 (void) FormatLocaleString(message,MaxTextExtent,
1727 " %g %g %g %g v z\n",first[0].x,first[0].y,
1728 first[1].x,first[1].y);
1730 if ((first[0].x == first[1].x) && (first[0].y == first[1].y))
1731 (void) FormatLocaleString(message,MaxTextExtent,
1732 " %g %g %g %g y z\n",last[2].x,last[2].y,
1733 first[1].x,first[1].y);
1735 (void) FormatLocaleString(message,MaxTextExtent,
1736 " %g %g %g %g %g %g c z\n",last[2].x,
1737 last[2].y,first[0].x,first[0].y,first[1].x,first[1].y);
1738 (void) ConcatenateString(&path,message);
1739 in_subpath=MagickFalse;
1755 Returns an empty PS path if the path has no knots.
1757 (void) FormatLocaleString(message,MaxTextExtent," eoclip\n");
1758 (void) ConcatenateString(&path,message);
1759 (void) FormatLocaleString(message,MaxTextExtent,"} bind def");
1760 (void) ConcatenateString(&path,message);
1761 message=DestroyString(message);
1765 static char *TraceSVGClippath(const unsigned char *blob,size_t length,
1766 const size_t columns,const size_t rows)
1789 path=AcquireString((char *) NULL);
1790 if (path == (char *) NULL)
1791 return((char *) NULL);
1792 message=AcquireString((char *) NULL);
1793 (void) FormatLocaleString(message,MaxTextExtent,
1794 "<?xml version=\"1.0\" encoding=\"iso-8859-1\"?>\n");
1795 (void) ConcatenateString(&path,message);
1796 (void) FormatLocaleString(message,MaxTextExtent,
1797 "<svg width=\"%.20g\" height=\"%.20g\">\n",(double) columns,(double) rows);
1798 (void) ConcatenateString(&path,message);
1799 (void) FormatLocaleString(message,MaxTextExtent,"<g>\n");
1800 (void) ConcatenateString(&path,message);
1801 (void) FormatLocaleString(message,MaxTextExtent,
1802 "<path style=\"fill:#00000000;stroke:#00000000;");
1803 (void) ConcatenateString(&path,message);
1804 (void) FormatLocaleString(message,MaxTextExtent,
1805 "stroke-width:0;stroke-antialiasing:false\" d=\"\n");
1806 (void) ConcatenateString(&path,message);
1807 (void) ResetMagickMemory(point,0,sizeof(point));
1808 (void) ResetMagickMemory(first,0,sizeof(first));
1809 (void) ResetMagickMemory(last,0,sizeof(last));
1811 in_subpath=MagickFalse;
1814 selector=(ssize_t) ReadPropertyMSBShort(&blob,&length);
1820 if (knot_count != 0)
1827 Expected subpath length record.
1829 knot_count=(ssize_t) ReadPropertyMSBShort(&blob,&length);
1839 if (knot_count == 0)
1842 Unexpected subpath knot.
1851 for (i=0; i < 3; i++)
1857 yy=ReadPropertyMSBLong(&blob,&length);
1858 xx=ReadPropertyMSBLong(&blob,&length);
1860 if (xx > 2147483647)
1861 x=(ssize_t) xx-4294967295U-1;
1863 if (yy > 2147483647)
1864 y=(ssize_t) yy-4294967295U-1;
1865 point[i].x=(double) x*columns/4096/4096;
1866 point[i].y=(double) y*rows/4096/4096;
1868 if (in_subpath == MagickFalse)
1870 (void) FormatLocaleString(message,MaxTextExtent,"M %g,%g\n",
1871 point[1].x,point[1].y);
1872 for (i=0; i < 3; i++)
1880 if ((last[1].x == last[2].x) && (last[1].y == last[2].y) &&
1881 (point[0].x == point[1].x) && (point[0].y == point[1].y))
1882 (void) FormatLocaleString(message,MaxTextExtent,"L %g,%g\n",
1883 point[1].x,point[1].y);
1885 (void) FormatLocaleString(message,MaxTextExtent,
1886 "C %g,%g %g,%g %g,%g\n",last[2].x,last[2].y,
1887 point[0].x,point[0].y,point[1].x,point[1].y);
1888 for (i=0; i < 3; i++)
1891 (void) ConcatenateString(&path,message);
1892 in_subpath=MagickTrue;
1895 Close the subpath if there are no more knots.
1897 if (knot_count == 0)
1899 if ((last[1].x == last[2].x) && (last[1].y == last[2].y) &&
1900 (first[0].x == first[1].x) && (first[0].y == first[1].y))
1901 (void) FormatLocaleString(message,MaxTextExtent,
1902 "L %g,%g Z\n",first[1].x,first[1].y);
1905 (void) FormatLocaleString(message,MaxTextExtent,
1906 "C %g,%g %g,%g %g,%g Z\n",last[2].x,
1907 last[2].y,first[0].x,first[0].y,first[1].x,first[1].y);
1908 (void) ConcatenateString(&path,message);
1910 in_subpath=MagickFalse;
1926 Return an empty SVG image if the path does not have knots.
1928 (void) FormatLocaleString(message,MaxTextExtent,"\"/>\n");
1929 (void) ConcatenateString(&path,message);
1930 (void) FormatLocaleString(message,MaxTextExtent,"</g>\n");
1931 (void) ConcatenateString(&path,message);
1932 (void) FormatLocaleString(message,MaxTextExtent,"</svg>\n");
1933 (void) ConcatenateString(&path,message);
1934 message=DestroyString(message);
1938 MagickExport const char *GetImageProperty(const Image *image,
1939 const char *property)
1956 assert(image != (Image *) NULL);
1957 assert(image->signature == MagickSignature);
1958 if (image->debug != MagickFalse)
1959 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1960 p=(const char *) NULL;
1961 if (image->properties != (void *) NULL)
1963 if (property == (const char *) NULL)
1965 ResetSplayTreeIterator((SplayTreeInfo *) image->properties);
1966 p=(const char *) GetNextValueInSplayTree((SplayTreeInfo *)
1970 if (LocaleNCompare("fx:",property,3) != 0)
1972 p=(const char *) GetValueFromSplayTree((SplayTreeInfo *)
1973 image->properties,property);
1974 if (p != (const char *) NULL)
1978 if ((property == (const char *) NULL) ||
1979 (strchr(property,':') == (char *) NULL))
1981 exception=(&((Image *) image)->exception);
1986 if (LocaleNCompare("8bim:",property,5) == 0)
1988 if ((Get8BIMProperty(image,property) != MagickFalse) &&
1989 (image->properties != (void *) NULL))
1991 p=(const char *) GetValueFromSplayTree((SplayTreeInfo *)
1992 image->properties,property);
2001 if (LocaleNCompare("exif:",property,5) == 0)
2003 if ((GetEXIFProperty(image,property) != MagickFalse) &&
2004 (image->properties != (void *) NULL))
2006 p=(const char *) GetValueFromSplayTree((SplayTreeInfo *)
2007 image->properties,property);
2016 if (LocaleNCompare("fx:",property,3) == 0)
2018 fx_info=AcquireFxInfo(image,property+3);
2019 status=FxEvaluateChannelExpression(fx_info,IntensityPixelChannel,0,0,
2021 fx_info=DestroyFxInfo(fx_info);
2022 if (status != MagickFalse)
2025 value[MaxTextExtent];
2027 (void) FormatLocaleString(value,MaxTextExtent,"%.*g",
2028 GetMagickPrecision(),(double) alpha);
2029 (void) SetImageProperty((Image *) image,property,value);
2031 if (image->properties != (void *) NULL)
2033 p=(const char *) GetValueFromSplayTree((SplayTreeInfo *)
2034 image->properties,property);
2043 if (LocaleNCompare("iptc:",property,5) == 0)
2045 if ((GetIPTCProperty(image,property) != MagickFalse) &&
2046 (image->properties != (void *) NULL))
2048 p=(const char *) GetValueFromSplayTree((SplayTreeInfo *)
2049 image->properties,property);
2058 if (LocaleNCompare("pixel:",property,6) == 0)
2063 GetPixelInfo(image,&pixel);
2064 fx_info=AcquireFxInfo(image,property+6);
2065 status=FxEvaluateChannelExpression(fx_info,RedPixelChannel,0,0,
2067 pixel.red=(MagickRealType) QuantumRange*alpha;
2068 status|=FxEvaluateChannelExpression(fx_info,GreenPixelChannel,0,0,
2070 pixel.green=(MagickRealType) QuantumRange*alpha;
2071 status|=FxEvaluateChannelExpression(fx_info,BluePixelChannel,0,0,
2073 pixel.blue=(MagickRealType) QuantumRange*alpha;
2074 if (image->colorspace == CMYKColorspace)
2076 status|=FxEvaluateChannelExpression(fx_info,BlackPixelChannel,0,0,
2078 pixel.black=(MagickRealType) QuantumRange*alpha;
2080 status|=FxEvaluateChannelExpression(fx_info,AlphaPixelChannel,0,0,
2082 pixel.alpha=(MagickRealType) QuantumRange*(1.0-alpha);
2083 fx_info=DestroyFxInfo(fx_info);
2084 if (status != MagickFalse)
2087 name[MaxTextExtent];
2089 (void) QueryColorname(image,&pixel,SVGCompliance,name,
2091 (void) SetImageProperty((Image *) image,property,name);
2092 return(GetImageProperty(image,property));
2100 if (LocaleNCompare("xmp:",property,4) == 0)
2102 if ((GetXMPProperty(image,property) != MagickFalse) &&
2103 (image->properties != (void *) NULL))
2105 p=(const char *) GetValueFromSplayTree((SplayTreeInfo *)
2106 image->properties,property);
2119 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2123 + G e t M a g i c k P r o p e r t y %
2127 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2129 % GetMagickProperty() gets a value associated with an image property.
2131 % The format of the GetMagickProperty method is:
2133 % const char *GetMagickProperty(const ImageInfo *image_info,Image *image,
2136 % A description of each parameter follows:
2138 % o image_info: the image info.
2140 % o image: the image.
2145 MagickExport const char *GetMagickProperty(const ImageInfo *image_info,
2146 Image *image,const char *property)
2149 value[MaxTextExtent],
2150 filename[MaxTextExtent];
2157 if (LocaleNCompare("base",property,4) == 0)
2159 GetPathComponent(image->magick_filename,BasePath,filename);
2160 (void) CopyMagickString(value,filename,MaxTextExtent);
2167 if (LocaleNCompare("channels",property,8) == 0)
2172 (void) FormatLocaleString(value,MaxTextExtent,"%s",
2173 CommandOptionToMnemonic(MagickColorspaceOptions,(ssize_t)
2174 image->colorspace));
2176 if (image->matte != MagickFalse)
2177 (void) ConcatenateMagickString(value,"a",MaxTextExtent);
2180 if (LocaleNCompare("colorspace",property,10) == 0)
2186 Image storage class and colorspace.
2188 colorspace=image->colorspace;
2189 if (IsImageGray(image,&image->exception) != MagickFalse)
2190 colorspace=GRAYColorspace;
2191 (void) FormatLocaleString(value,MaxTextExtent,"%s",
2192 CommandOptionToMnemonic(MagickColorspaceOptions,(ssize_t)
2196 if (LocaleNCompare("copyright",property,9) == 0)
2198 (void) CopyMagickString(value,GetMagickCopyright(),MaxTextExtent);
2205 if (LocaleNCompare("depth",property,5) == 0)
2207 (void) FormatLocaleString(value,MaxTextExtent,"%.20g",(double)
2211 if (LocaleNCompare("directory",property,9) == 0)
2213 GetPathComponent(image->magick_filename,HeadPath,filename);
2214 (void) CopyMagickString(value,filename,MaxTextExtent);
2221 if (LocaleNCompare("extension",property,9) == 0)
2223 GetPathComponent(image->magick_filename,ExtensionPath,filename);
2224 (void) CopyMagickString(value,filename,MaxTextExtent);
2231 if (LocaleNCompare("group",property,5) == 0)
2233 (void) FormatLocaleString(value,MaxTextExtent,"0x%lx",
2234 (unsigned long) image_info->group);
2241 if (LocaleNCompare("height",property,6) == 0)
2243 (void) FormatLocaleString(value,MaxTextExtent,"%.20g",
2244 image->magick_rows != 0 ? (double) image->magick_rows : 256.0);
2251 if (LocaleNCompare("input",property,5) == 0)
2253 (void) CopyMagickString(value,image->filename,MaxTextExtent);
2260 if (LocaleNCompare("kurtosis",property,8) == 0)
2266 (void) GetImageKurtosis(image,&kurtosis,&skewness,&image->exception);
2267 (void) FormatLocaleString(value,MaxTextExtent,"%.*g",
2268 GetMagickPrecision(),kurtosis);
2275 if (LocaleNCompare("magick",property,6) == 0)
2277 (void) CopyMagickString(value,image->magick,MaxTextExtent);
2280 if (LocaleNCompare("max",property,3) == 0)
2286 (void) GetImageRange(image,&minimum,&maximum,&image->exception);
2287 (void) FormatLocaleString(value,MaxTextExtent,"%.*g",
2288 GetMagickPrecision(),maximum);
2291 if (LocaleNCompare("mean",property,4) == 0)
2297 (void) GetImageMean(image,&mean,&standard_deviation,
2299 (void) FormatLocaleString(value,MaxTextExtent,"%.*g",
2300 GetMagickPrecision(),mean);
2303 if (LocaleNCompare("min",property,3) == 0)
2309 (void) GetImageRange(image,&minimum,&maximum,&image->exception);
2310 (void) FormatLocaleString(value,MaxTextExtent,"%.*g",
2311 GetMagickPrecision(),minimum);
2318 if (LocaleNCompare("name",property,4) == 0)
2320 (void) CopyMagickString(value,filename,MaxTextExtent);
2327 if (LocaleNCompare("opaque",property,6) == 0)
2332 opaque=IsImageOpaque(image,&image->exception);
2333 (void) CopyMagickString(value,opaque == MagickFalse ? "false" :
2334 "true",MaxTextExtent);
2337 if (LocaleNCompare("output",property,6) == 0)
2339 (void) CopyMagickString(value,image_info->filename,MaxTextExtent);
2346 if (LocaleNCompare("page",property,4) == 0)
2348 (void) FormatLocaleString(value,MaxTextExtent,"%.20g",(double)
2349 GetImageIndexInList(image)+1);
2356 if (LocaleNCompare("size",property,4) == 0)
2359 format[MaxTextExtent];
2361 (void) FormatMagickSize(GetBlobSize(image),MagickFalse,format);
2362 (void) FormatLocaleString(value,MaxTextExtent,"%sB",format);
2365 if (LocaleNCompare("scenes",property,6) == 0)
2367 (void) FormatLocaleString(value,MaxTextExtent,"%.20g",(double)
2368 GetImageListLength(image));
2371 if (LocaleNCompare("scene",property,5) == 0)
2373 (void) FormatLocaleString(value,MaxTextExtent,"%.20g",(double)
2375 if (image_info->number_scenes != 0)
2376 (void) FormatLocaleString(value,MaxTextExtent,"%.20g",(double)
2380 if (LocaleNCompare("skewness",property,8) == 0)
2386 (void) GetImageKurtosis(image,&kurtosis,&skewness,&image->exception);
2387 (void) FormatLocaleString(value,MaxTextExtent,"%.*g",
2388 GetMagickPrecision(),skewness);
2391 if (LocaleNCompare("standard-deviation",property,18) == 0)
2397 (void) GetImageMean(image,&mean,&standard_deviation,
2399 (void) FormatLocaleString(value,MaxTextExtent,"%.*g",
2400 GetMagickPrecision(),standard_deviation);
2407 if (LocaleNCompare("unique",property,6) == 0)
2409 (void) CopyMagickString(filename,image_info->unique,MaxTextExtent);
2410 (void) CopyMagickString(value,filename,MaxTextExtent);
2417 if (LocaleNCompare("version",property,7) == 0)
2419 (void) CopyMagickString(value,GetMagickVersion((size_t *) NULL),
2427 if (LocaleNCompare("width",property,5) == 0)
2429 (void) FormatLocaleString(value,MaxTextExtent,"%.20g",(double)
2430 (image->magick_columns != 0 ? image->magick_columns : 256));
2437 if (LocaleNCompare("xresolution",property,11) == 0)
2439 (void) FormatLocaleString(value,MaxTextExtent,"%g",
2440 image->x_resolution);
2447 if (LocaleNCompare("yresolution",property,11) == 0)
2449 (void) FormatLocaleString(value,MaxTextExtent,"%g",
2450 image->y_resolution);
2457 if (LocaleNCompare("zero",property,4) == 0)
2459 (void) CopyMagickString(filename,image_info->zero,MaxTextExtent);
2460 (void) CopyMagickString(value,filename,MaxTextExtent);
2468 if (image->properties == (void *) NULL)
2469 image->properties=NewSplayTree(CompareSplayTreeString,
2470 RelinquishMagickMemory,RelinquishMagickMemory);
2471 (void) AddValueToSplayTree((SplayTreeInfo *) image->properties,
2472 ConstantString(property),ConstantString(value));
2474 return(GetImageProperty(image,property));
2478 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2482 % G e t N e x t I m a g e P r o p e r t y %
2486 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2488 % GetNextImageProperty() gets the next image property value.
2490 % The format of the GetNextImageProperty method is:
2492 % char *GetNextImageProperty(const Image *image)
2494 % A description of each parameter follows:
2496 % o image: the image.
2499 MagickExport char *GetNextImageProperty(const Image *image)
2501 assert(image != (Image *) NULL);
2502 assert(image->signature == MagickSignature);
2503 if (image->debug != MagickFalse)
2504 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
2506 if (image->properties == (void *) NULL)
2507 return((char *) NULL);
2508 return((char *) GetNextKeyInSplayTree((SplayTreeInfo *) image->properties));
2512 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2516 % I n t e r p r e t I m a g e P r o p e r t i e s %
2520 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2522 % InterpretImageProperties() replaces any embedded formatting characters with
2523 % the appropriate image property and returns the interpreted text.
2525 % The format of the InterpretImageProperties method is:
2527 % char *InterpretImageProperties(const ImageInfo *image_info,Image *image,
2528 % const char *embed_text,ExceptionInfo *exception)
2530 % A description of each parameter follows:
2532 % o image_info: the image info.
2534 % o image: the image.
2536 % o embed_text: the address of a character string containing the embedded
2537 % formatting characters.
2539 % o exception: return any errors or warnings in this structure.
2542 MagickExport char *InterpretImageProperties(const ImageInfo *image_info,
2543 Image *image,const char *embed_text,ExceptionInfo *exception)
2546 filename[MaxTextExtent],
2566 assert(image != (Image *) NULL);
2567 assert(image->signature == MagickSignature);
2568 if (image->debug != MagickFalse)
2569 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
2570 if ((embed_text == (const char *) NULL) || (*embed_text == '\0'))
2571 return((char *) NULL);
2572 text=(char *) embed_text;
2573 if ((*text == '@') && ((*(text+1) == '-') ||
2574 (IsPathAccessible(text+1) != MagickFalse)))
2575 return(FileToString(embed_text+1,~0,&image->exception));
2577 Translate any embedded format characters.
2579 interpret_text=AcquireString(text);
2580 extent=MaxTextExtent;
2582 for (q=interpret_text; *p != '\0'; p++)
2585 if ((size_t) (q-interpret_text+MaxTextExtent) >= extent)
2587 extent+=MaxTextExtent;
2588 interpret_text=(char *) ResizeQuantumMemory(interpret_text,extent+
2589 MaxTextExtent+1,sizeof(*interpret_text));
2590 if (interpret_text == (char *) NULL)
2592 q=interpret_text+strlen(interpret_text);
2595 Process formatting characters in text.
2597 if ((*p == '\\') && (*(p+1) == 'r'))
2603 if ((*p == '\\') && (*(p+1) == 'n'))
2623 case '[': /* multi-character substitution */
2626 pattern[MaxTextExtent];
2638 if (strchr(p,']') == (char *) NULL)
2642 for (i=0; (i < (MaxTextExtent-1L)) && (*p != '\0'); i++)
2653 value=GetImageProperty(image,pattern);
2654 if (value != (const char *) NULL)
2656 length=strlen(value);
2657 if ((size_t) (q-interpret_text+length+1) >= extent)
2660 interpret_text=(char *) ResizeQuantumMemory(interpret_text,
2661 extent+MaxTextExtent,sizeof(*interpret_text));
2662 if (interpret_text == (char *) NULL)
2664 q=interpret_text+strlen(interpret_text);
2666 (void) CopyMagickString(q,value,extent);
2671 if (IsGlob(pattern) != MagickFalse)
2674 Iterate over image properties.
2676 ResetImagePropertyIterator(image);
2677 key=GetNextImageProperty(image);
2678 while (key != (const char *) NULL)
2680 if (GlobExpression(key,pattern,MagickTrue) != MagickFalse)
2682 value=GetImageProperty(image,key);
2683 if (value != (const char *) NULL)
2685 length=strlen(key)+strlen(value)+2;
2686 if ((size_t) (q-interpret_text+length+1) >= extent)
2689 interpret_text=(char *) ResizeQuantumMemory(
2690 interpret_text,extent+MaxTextExtent,
2691 sizeof(*interpret_text));
2692 if (interpret_text == (char *) NULL)
2694 q=interpret_text+strlen(interpret_text);
2696 q+=FormatLocaleString(q,extent,"%s=%s\n",key,value);
2699 key=GetNextImageProperty(image);
2702 value=GetMagickProperty(image_info,image,pattern);
2703 if (value != (const char *) NULL)
2705 length=strlen(value);
2706 if ((size_t) (q-interpret_text+length+1) >= extent)
2709 interpret_text=(char *) ResizeQuantumMemory(interpret_text,
2710 extent+MaxTextExtent,sizeof(*interpret_text));
2711 if (interpret_text == (char *) NULL)
2713 q=interpret_text+strlen(interpret_text);
2715 (void) CopyMagickString(q,value,extent);
2719 if (image_info == (ImageInfo *) NULL)
2721 value=GetImageOption(image_info,pattern);
2722 if (value != (char *) NULL)
2724 length=strlen(value);
2725 if ((size_t) (q-interpret_text+length+1) >= extent)
2728 interpret_text=(char *) ResizeQuantumMemory(interpret_text,
2729 extent+MaxTextExtent,sizeof(*interpret_text));
2730 if (interpret_text == (char *) NULL)
2732 q=interpret_text+strlen(interpret_text);
2734 (void) CopyMagickString(q,value,extent);
2740 case 'b': /* image size as read in */
2743 format[MaxTextExtent];
2745 (void) FormatLocaleString(format,MaxTextExtent,"%.20g",(double)
2746 ((MagickOffsetType) image->extent));
2747 if (image->extent != (MagickSizeType) ((size_t) image->extent))
2748 (void) FormatMagickSize(image->extent,MagickFalse,format);
2749 q+=ConcatenateMagickString(q,format,extent);
2750 q+=ConcatenateMagickString(q,"B",extent);
2753 case 'c': /* image comment properity */
2755 value=GetImageProperty(image,"comment");
2756 if (value == (const char *) NULL)
2758 length=strlen(value);
2759 if ((size_t) (q-interpret_text+length+1) >= extent)
2762 interpret_text=(char *) ResizeQuantumMemory(interpret_text,extent+
2763 MaxTextExtent,sizeof(*interpret_text));
2764 if (interpret_text == (char *) NULL)
2766 q=interpret_text+strlen(interpret_text);
2768 (void) CopyMagickString(q,value,extent);
2772 case 'd': /* Directory component of filename */
2774 GetPathComponent(image->magick_filename,HeadPath,filename);
2775 q+=CopyMagickString(q,filename,extent);
2778 case 'e': /* Filename extension (suffix) of image file */
2780 GetPathComponent(image->magick_filename,ExtensionPath,filename);
2781 q+=CopyMagickString(q,filename,extent);
2784 case 'f': /* Filename without directory component */
2786 GetPathComponent(image->magick_filename,TailPath,filename);
2787 q+=CopyMagickString(q,filename,extent);
2790 case 't': /* Base filename without directory or extention */
2792 GetPathComponent(image->magick_filename,BasePath,filename);
2793 q+=CopyMagickString(q,filename,extent);
2796 case 'g': /* Image geometry, canvas and offset */
2798 q+=FormatLocaleString(q,extent,"%.20gx%.20g%+.20g%+.20g",(double)
2799 image->page.width,(double) image->page.height,(double) image->page.x,
2800 (double) image->page.y);
2803 case 'h': /* Image height */
2805 q+=FormatLocaleString(q,extent,"%.20g",(double) (image->rows != 0 ?
2806 image->rows : image->magick_rows));
2809 case 'i': /* Images filename - (output filename with "info:" ) */
2811 q+=CopyMagickString(q,image->filename,extent);
2814 case 'k': /* Number of unique colors */
2816 q+=FormatLocaleString(q,extent,"%.20g",(double) GetNumberColors(image,
2817 (FILE *) NULL,&image->exception));
2820 case 'l': /* Image label */
2822 value=GetImageProperty(image,"label");
2823 if (value == (const char *) NULL)
2825 length=strlen(value);
2826 if ((size_t) (q-interpret_text+length+1) >= extent)
2829 interpret_text=(char *) ResizeQuantumMemory(interpret_text,extent+
2830 MaxTextExtent,sizeof(*interpret_text));
2831 if (interpret_text == (char *) NULL)
2833 q=interpret_text+strlen(interpret_text);
2835 q+=CopyMagickString(q,value,extent);
2838 case 'm': /* Image format (file magick) */
2840 q+=CopyMagickString(q,image->magick,extent);
2843 case 'M': /* Magick filename - exactly as given incl. read mods */
2845 q+=CopyMagickString(q,image->magick_filename,extent);
2848 case 'n': /* Number of images in the list. */
2850 q+=FormatLocaleString(q,extent,"%.20g",(double)
2851 GetImageListLength(image));
2854 case 'o': /* Image output filename */
2856 q+=CopyMagickString(q,image_info->filename,extent);
2859 case 'p': /* Image index in curent image list */
2861 q+=FormatLocaleString(q,extent,"%.20g",(double)
2862 GetImageIndexInList(image));
2865 case 'q': /* Quantum depth of image in memory */
2867 q+=FormatLocaleString(q,extent,"%.20g",(double)
2868 MAGICKCORE_QUANTUM_DEPTH);
2871 case 'r': /* Image storage class and colorspace. */
2876 colorspace=image->colorspace;
2877 if (IsImageGray(image,&image->exception) != MagickFalse)
2878 colorspace=GRAYColorspace;
2879 q+=FormatLocaleString(q,extent,"%s%s%s",CommandOptionToMnemonic(
2880 MagickClassOptions,(ssize_t) image->storage_class),
2881 CommandOptionToMnemonic(MagickColorspaceOptions,(ssize_t) colorspace),
2882 image->matte != MagickFalse ? "Matte" : "");
2885 case 's': /* Image scene number */
2887 if (image_info->number_scenes == 0)
2888 q+=FormatLocaleString(q,extent,"%.20g",(double) image->scene);
2890 q+=FormatLocaleString(q,extent,"%.20g",(double) image_info->scene);
2893 case 'u': /* Unique filename */
2895 (void) CopyMagickString(filename,image_info->unique,extent);
2896 q+=CopyMagickString(q,filename,extent);
2899 case 'w': /* Image width */
2901 q+=FormatLocaleString(q,extent,"%.20g",(double) (image->columns != 0 ?
2902 image->columns : image->magick_columns));
2905 case 'x': /* Image horizontal resolution (density). */
2907 q+=FormatLocaleString(q,extent,"%g %s",image->x_resolution,
2908 CommandOptionToMnemonic(MagickResolutionOptions,(ssize_t)
2912 case 'y': /* Image vertical resolution (density) */
2914 q+=FormatLocaleString(q,extent,"%g %s",image->y_resolution,
2915 CommandOptionToMnemonic(MagickResolutionOptions,(ssize_t)
2919 case 'z': /* Image depth as read in */
2921 q+=FormatLocaleString(q,extent,"%.20g",(double) image->depth);
2924 case 'A': /* Image alpha channel */
2926 q+=FormatLocaleString(q,extent,"%s",CommandOptionToMnemonic(
2927 MagickBooleanOptions,(ssize_t) image->matte));
2930 case 'C': /* Image compression method. */
2932 q+=FormatLocaleString(q,extent,"%s",CommandOptionToMnemonic(
2933 MagickCompressOptions,(ssize_t) image->compression));
2936 case 'D': /* Image dispose method. */
2938 q+=FormatLocaleString(q,extent,"%s",CommandOptionToMnemonic(
2939 MagickDisposeOptions,(ssize_t) image->dispose));
2942 case 'G': /* Image size as geometry = "%wx%h" */
2944 q+=FormatLocaleString(q,extent,"%.20gx%.20g",(double)
2945 image->magick_columns,(double) image->magick_rows);
2948 case 'H': /* layer canvas height */
2950 q+=FormatLocaleString(q,extent,"%.20g",(double) image->page.height);
2953 case 'O': /* layer canvas offset with sign = "+%X+%Y" */
2955 q+=FormatLocaleString(q,extent,"%+ld%+ld",(long) image->page.x,(long)
2959 case 'P': /* layer canvas page size = "%Wx%H" */
2961 q+=FormatLocaleString(q,extent,"%.20gx%.20g",(double) image->page.width,
2962 (double) image->page.height);
2965 case 'Q': /* image compression quality */
2967 q+=FormatLocaleString(q,extent,"%.20g",(double) image->quality);
2970 case 'S': /* Image scenes */
2972 if (image_info->number_scenes == 0)
2973 q+=CopyMagickString(q,"2147483647",extent);
2975 q+=FormatLocaleString(q,extent,"%.20g",(double) (image_info->scene+
2976 image_info->number_scenes));
2979 case 'T': /* image time delay for animations */
2981 q+=FormatLocaleString(q,extent,"%.20g",(double) image->delay);
2984 case 'W': /* layer canvas width */
2986 q+=FormatLocaleString(q,extent,"%.20g",(double) image->page.width);
2989 case 'X': /* layer canvas X offset */
2991 q+=FormatLocaleString(q,extent,"%+.20g",(double) image->page.x);
2994 case 'Y': /* layer canvas Y offset */
2996 q+=FormatLocaleString(q,extent,"%+.20g",(double) image->page.y);
2999 case 'Z': /* Unique filename. */
3001 (void) CopyMagickString(filename,image_info->zero,extent);
3002 q+=CopyMagickString(q,filename,extent);
3005 case '@': /* Image bounding box. */
3010 page=GetImageBoundingBox(image,exception);
3011 q+=FormatLocaleString(q,MaxTextExtent,"%.20gx%.20g%+.20g%+.20g",
3012 (double) page.width,(double) page.height,(double) page.x,(double)
3016 case '#': /* Image signature */
3018 (void) SignatureImage(image,exception);
3019 value=GetImageProperty(image,"signature");
3020 if (value == (const char *) NULL)
3022 q+=CopyMagickString(q,value,extent);
3025 case '%': /* percent escaped */
3030 default: /* percent not expanded */
3039 if (text != (const char *) embed_text)
3040 text=DestroyString(text);
3041 (void) SubstituteString(&interpret_text,"<","<");
3042 (void) SubstituteString(&interpret_text,">",">");
3043 return(interpret_text);
3047 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3051 % R e m o v e I m a g e P r o p e r t y %
3055 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3057 % RemoveImageProperty() removes a property from the image and returns its
3060 % The format of the RemoveImageProperty method is:
3062 % char *RemoveImageProperty(Image *image,const char *property)
3064 % A description of each parameter follows:
3066 % o image: the image.
3068 % o property: the image property.
3071 MagickExport char *RemoveImageProperty(Image *image,
3072 const char *property)
3077 assert(image != (Image *) NULL);
3078 assert(image->signature == MagickSignature);
3079 if (image->debug != MagickFalse)
3080 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
3082 if (image->properties == (void *) NULL)
3083 return((char *) NULL);
3084 value=(char *) RemoveNodeFromSplayTree((SplayTreeInfo *) image->properties,
3090 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3094 % 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 %
3098 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3100 % ResetImagePropertyIterator() resets the image properties iterator. Use it
3101 % in conjunction with GetNextImageProperty() to iterate over all the values
3102 % associated with an image property.
3104 % The format of the ResetImagePropertyIterator method is:
3106 % ResetImagePropertyIterator(Image *image)
3108 % A description of each parameter follows:
3110 % o image: the image.
3113 MagickExport void ResetImagePropertyIterator(const Image *image)
3115 assert(image != (Image *) NULL);
3116 assert(image->signature == MagickSignature);
3117 if (image->debug != MagickFalse)
3118 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
3120 if (image->properties == (void *) NULL)
3122 ResetSplayTreeIterator((SplayTreeInfo *) image->properties);
3126 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3130 % S e t I m a g e P r o p e r t y %
3134 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3136 % SetImageProperty() associates an value with an image property.
3138 % The format of the SetImageProperty method is:
3140 % MagickBooleanType SetImageProperty(Image *image,const char *property,
3141 % const char *value)
3143 % A description of each parameter follows:
3145 % o image: the image.
3147 % o property: the image property.
3149 % o values: the image property values.
3152 MagickExport MagickBooleanType SetImageProperty(Image *image,
3153 const char *property,const char *value)
3164 assert(image != (Image *) NULL);
3165 assert(image->signature == MagickSignature);
3166 if (image->debug != MagickFalse)
3167 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
3169 if (image->properties == (void *) NULL)
3170 image->properties=NewSplayTree(CompareSplayTreeString,
3171 RelinquishMagickMemory,RelinquishMagickMemory);
3172 if ((value == (const char *) NULL) || (*value == '\0'))
3173 return(DeleteImageProperty(image,property));
3175 exception=(&image->exception);
3181 if (LocaleCompare(property,"background") == 0)
3183 (void) QueryColorCompliance(value,AllCompliance,
3184 &image->background_color,exception);
3187 if (LocaleCompare(property,"bias") == 0)
3189 image->bias=SiPrefixToDouble(value,QuantumRange);
3192 status=AddValueToSplayTree((SplayTreeInfo *) image->properties,
3193 ConstantString(property),ConstantString(value));
3199 if (LocaleCompare(property,"colorspace") == 0)
3204 colorspace=ParseCommandOption(MagickColorspaceOptions,MagickFalse,
3208 (void) SetImageColorspace(image,(ColorspaceType) colorspace,
3212 if (LocaleCompare(property,"compose") == 0)
3217 compose=ParseCommandOption(MagickComposeOptions,MagickFalse,value);
3220 image->compose=(CompositeOperator) compose;
3223 if (LocaleCompare(property,"compress") == 0)
3228 compression=ParseCommandOption(MagickCompressOptions,MagickFalse,
3230 if (compression < 0)
3232 image->compression=(CompressionType) compression;
3235 status=AddValueToSplayTree((SplayTreeInfo *) image->properties,
3236 ConstantString(property),ConstantString(value));
3242 if (LocaleCompare(property,"delay") == 0)
3247 flags=ParseGeometry(value,&geometry_info);
3248 if ((flags & GreaterValue) != 0)
3250 if (image->delay > (size_t) floor(geometry_info.rho+0.5))
3251 image->delay=(size_t) floor(geometry_info.rho+0.5);
3254 if ((flags & LessValue) != 0)
3256 if (image->delay < (size_t) floor(geometry_info.rho+0.5))
3257 image->ticks_per_second=(ssize_t)
3258 floor(geometry_info.sigma+0.5);
3261 image->delay=(size_t) floor(geometry_info.rho+0.5);
3262 if ((flags & SigmaValue) != 0)
3263 image->ticks_per_second=(ssize_t) floor(geometry_info.sigma+0.5);
3266 if (LocaleCompare(property,"density") == 0)
3271 flags=ParseGeometry(value,&geometry_info);
3272 image->x_resolution=geometry_info.rho;
3273 image->y_resolution=geometry_info.sigma;
3274 if ((flags & SigmaValue) == 0)
3275 image->y_resolution=image->x_resolution;
3277 if (LocaleCompare(property,"depth") == 0)
3279 image->depth=StringToUnsignedLong(value);
3282 if (LocaleCompare(property,"dispose") == 0)
3287 dispose=ParseCommandOption(MagickDisposeOptions,MagickFalse,value);
3290 image->dispose=(DisposeType) dispose;
3293 status=AddValueToSplayTree((SplayTreeInfo *) image->properties,
3294 ConstantString(property),ConstantString(value));
3300 if (LocaleCompare(property,"gravity") == 0)
3305 gravity=ParseCommandOption(MagickGravityOptions,MagickFalse,value);
3308 image->gravity=(GravityType) gravity;
3311 status=AddValueToSplayTree((SplayTreeInfo *) image->properties,
3312 ConstantString(property),ConstantString(value));
3318 if (LocaleCompare(property,"intent") == 0)
3323 rendering_intent=ParseCommandOption(MagickIntentOptions,MagickFalse,
3325 if (rendering_intent < 0)
3327 image->rendering_intent=(RenderingIntent) rendering_intent;
3330 if (LocaleCompare(property,"interpolate") == 0)
3335 interpolate=ParseCommandOption(MagickInterpolateOptions,MagickFalse,
3337 if (interpolate < 0)
3339 image->interpolate=(PixelInterpolateMethod) interpolate;
3342 status=AddValueToSplayTree((SplayTreeInfo *) image->properties,
3343 ConstantString(property),ConstantString(value));
3349 if (LocaleCompare(property,"loop") == 0)
3351 image->iterations=StringToUnsignedLong(value);
3354 status=AddValueToSplayTree((SplayTreeInfo *) image->properties,
3355 ConstantString(property),ConstantString(value));
3361 if (LocaleCompare(property,"page") == 0)
3366 geometry=GetPageGeometry(value);
3367 flags=ParseAbsoluteGeometry(geometry,&image->page);
3368 geometry=DestroyString(geometry);
3371 if (LocaleCompare(property,"profile") == 0)
3379 image_info=AcquireImageInfo();
3380 (void) CopyMagickString(image_info->filename,value,MaxTextExtent);
3381 (void) SetImageInfo(image_info,1,exception);
3382 profile=FileToStringInfo(image_info->filename,~0UL,exception);
3383 if (profile != (StringInfo *) NULL)
3384 status=SetImageProfile(image,image_info->magick,profile);
3385 image_info=DestroyImageInfo(image_info);
3388 status=AddValueToSplayTree((SplayTreeInfo *) image->properties,
3389 ConstantString(property),ConstantString(value));
3395 if (LocaleCompare(property,"rendering-intent") == 0)
3400 rendering_intent=ParseCommandOption(MagickIntentOptions,MagickFalse,
3402 if (rendering_intent < 0)
3404 image->rendering_intent=(RenderingIntent) rendering_intent;
3407 status=AddValueToSplayTree((SplayTreeInfo *) image->properties,
3408 ConstantString(property),ConstantString(value));
3414 if (LocaleCompare(property,"tile-offset") == 0)
3419 geometry=GetPageGeometry(value);
3420 flags=ParseAbsoluteGeometry(geometry,&image->tile_offset);
3421 geometry=DestroyString(geometry);
3424 status=AddValueToSplayTree((SplayTreeInfo *) image->properties,
3425 ConstantString(property),ConstantString(value));
3431 if (LocaleCompare(property,"units") == 0)
3436 units=ParseCommandOption(MagickResolutionOptions,MagickFalse,value);
3439 image->units=(ResolutionType) units;
3442 status=AddValueToSplayTree((SplayTreeInfo *) image->properties,
3443 ConstantString(property),ConstantString(value));
3448 status=AddValueToSplayTree((SplayTreeInfo *) image->properties,
3449 ConstantString(property),ConstantString(value));