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->filter=clone_image->filter;
147 image->fuzz=clone_image->fuzz;
148 image->interlace=clone_image->interlace;
149 image->interpolate=clone_image->interpolate;
150 image->endian=clone_image->endian;
151 image->gravity=clone_image->gravity;
152 image->compose=clone_image->compose;
153 image->scene=clone_image->scene;
154 image->orientation=clone_image->orientation;
155 image->dispose=clone_image->dispose;
156 image->delay=clone_image->delay;
157 image->ticks_per_second=clone_image->ticks_per_second;
158 image->iterations=clone_image->iterations;
159 image->total_colors=clone_image->total_colors;
160 image->taint=clone_image->taint;
161 image->progress_monitor=clone_image->progress_monitor;
162 image->client_data=clone_image->client_data;
163 image->start_loop=clone_image->start_loop;
164 image->error=clone_image->error;
165 image->signature=clone_image->signature;
166 if (clone_image->properties != (void *) NULL)
168 if (image->properties != (void *) NULL)
169 DestroyImageProperties(image);
170 image->properties=CloneSplayTree((SplayTreeInfo *)
171 clone_image->properties,(void *(*)(void *)) ConstantString,
172 (void *(*)(void *)) ConstantString);
178 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
182 % D e f i n e I m a g e P r o p e r t y %
186 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
188 % DefineImageProperty() associates a key/value pair with an image property.
190 % The format of the DefineImageProperty method is:
192 % MagickBooleanType DefineImageProperty(Image *image,
193 % const char *property,ExceptionInfo *exception)
195 % A description of each parameter follows:
197 % o image: the image.
199 % o property: the image property.
201 % o exception: return any errors or warnings in this structure.
204 MagickExport MagickBooleanType DefineImageProperty(Image *image,
205 const char *property,ExceptionInfo *exception)
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,exception));
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];
346 va_start(operands,format);
347 n=FormatLocaleStringList(value,MaxTextExtent,format,operands);
350 exception=AcquireExceptionInfo();
351 status=SetImageProperty(image,property,value,exception);
352 exception=DestroyExceptionInfo(exception);
357 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
361 % G e t I m a g e P r o p e r t y %
365 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
367 % GetImageProperty() gets a value associated with an image property.
369 % The format of the GetImageProperty method is:
371 % const char *GetImageProperty(const Image *image,const char *key,
372 % ExceptionInfo *exception)
374 % A description of each parameter follows:
376 % o image: the image.
380 % o exception: return any errors or warnings in this structure.
385 *TracePSClippath(const unsigned char *,size_t,const size_t,
387 *TraceSVGClippath(const unsigned char *,size_t,const size_t,
390 static MagickBooleanType GetIPTCProperty(const Image *image,const char *key,
391 ExceptionInfo *exception)
411 profile=GetImageProfile(image,"iptc");
412 if (profile == (StringInfo *) NULL)
413 profile=GetImageProfile(image,"8bim");
414 if (profile == (StringInfo *) NULL)
416 count=sscanf(key,"IPTC:%ld:%ld",&dataset,&record);
419 attribute=(char *) NULL;
420 for (i=0; i < (ssize_t) GetStringInfoLength(profile); i+=(ssize_t) length)
423 if ((ssize_t) GetStringInfoDatum(profile)[i] != 0x1c)
425 length=(size_t) (GetStringInfoDatum(profile)[i+3] << 8);
426 length|=GetStringInfoDatum(profile)[i+4];
427 if (((long) GetStringInfoDatum(profile)[i+1] == dataset) &&
428 ((long) GetStringInfoDatum(profile)[i+2] == record))
430 message=(char *) NULL;
432 message=(char *) AcquireQuantumMemory(length+1UL,sizeof(*message));
433 if (message != (char *) NULL)
435 (void) CopyMagickString(message,(char *) GetStringInfoDatum(
436 profile)+i+5,length+1);
437 (void) ConcatenateString(&attribute,message);
438 (void) ConcatenateString(&attribute,";");
439 message=DestroyString(message);
444 if ((attribute == (char *) NULL) || (*attribute == ';'))
446 if (attribute != (char *) NULL)
447 attribute=DestroyString(attribute);
450 attribute[strlen(attribute)-1]='\0';
451 (void) SetImageProperty((Image *) image,key,(const char *) attribute,
453 attribute=DestroyString(attribute);
457 static inline ssize_t MagickMax(const ssize_t x,const ssize_t y)
464 static inline ssize_t MagickMin(const ssize_t x,const ssize_t y)
471 static inline int ReadPropertyByte(const unsigned char **p,size_t *length)
483 static inline size_t ReadPropertyMSBLong(const unsigned char **p,
500 for (i=0; i < 4; i++)
504 buffer[i]=(unsigned char) c;
506 value=(size_t) (buffer[0] << 24);
507 value|=buffer[1] << 16;
508 value|=buffer[2] << 8;
510 return(value & 0xffffffff);
513 static inline unsigned short ReadPropertyMSBShort(const unsigned char **p,
529 return((unsigned short) ~0U);
530 for (i=0; i < 2; i++)
534 buffer[i]=(unsigned char) c;
536 value=(unsigned short) (buffer[0] << 8);
538 return((unsigned short) (value & 0xffff));
541 static MagickBooleanType Get8BIMProperty(const Image *image,const char *key,
542 ExceptionInfo *exception)
546 format[MaxTextExtent],
575 There are no newlines in path names, so it's safe as terminator.
577 profile=GetImageProfile(image,"8bim");
578 if (profile == (StringInfo *) NULL)
580 count=(ssize_t) sscanf(key,"8BIM:%ld,%ld:%[^\n]\n%[^\n]",&start,&stop,name,
582 if ((count != 2) && (count != 3) && (count != 4))
585 (void) CopyMagickString(format,"SVG",MaxTextExtent);
590 sub_number=(ssize_t) StringToLong(&name[1]);
591 sub_number=MagickMax(sub_number,1L);
592 resource=(char *) NULL;
594 length=GetStringInfoLength(profile);
595 info=GetStringInfoDatum(profile);
596 while ((length > 0) && (status == MagickFalse))
598 if (ReadPropertyByte(&info,&length) != (unsigned char) '8')
600 if (ReadPropertyByte(&info,&length) != (unsigned char) 'B')
602 if (ReadPropertyByte(&info,&length) != (unsigned char) 'I')
604 if (ReadPropertyByte(&info,&length) != (unsigned char) 'M')
606 id=(ssize_t) ((int) ReadPropertyMSBShort(&info,&length));
607 if (id < (ssize_t) start)
609 if (id > (ssize_t) stop)
611 if (resource != (char *) NULL)
612 resource=DestroyString(resource);
613 count=(ssize_t) ReadPropertyByte(&info,&length);
614 if ((count != 0) && ((size_t) count <= length))
616 resource=(char *) NULL;
617 if (~(1UL*count) >= (MaxTextExtent-1))
618 resource=(char *) AcquireQuantumMemory((size_t) count+MaxTextExtent,
620 if (resource != (char *) NULL)
622 for (i=0; i < (ssize_t) count; i++)
623 resource[i]=(char) ReadPropertyByte(&info,&length);
624 resource[count]='\0';
627 if ((count & 0x01) == 0)
628 (void) ReadPropertyByte(&info,&length);
629 count=(ssize_t) ((int) ReadPropertyMSBLong(&info,&length));
630 if ((*name != '\0') && (*name != '#'))
631 if ((resource == (char *) NULL) || (LocaleCompare(name,resource) != 0))
634 No name match, scroll forward and try next.
637 length-=MagickMin(count,(ssize_t) length);
640 if ((*name == '#') && (sub_number != 1))
643 No numbered match, scroll forward and try next.
647 length-=MagickMin(count,(ssize_t) length);
651 We have the resource of interest.
653 attribute=(char *) NULL;
654 if (~(1UL*count) >= (MaxTextExtent-1))
655 attribute=(char *) AcquireQuantumMemory((size_t) count+MaxTextExtent,
657 if (attribute != (char *) NULL)
659 (void) CopyMagickMemory(attribute,(char *) info,(size_t) count);
660 attribute[count]='\0';
662 length-=MagickMin(count,(ssize_t) length);
663 if ((id <= 1999) || (id >= 2999))
664 (void) SetImageProperty((Image *) image,key,(const char *)
665 attribute,exception);
671 if (LocaleCompare(format,"svg") == 0)
672 path=TraceSVGClippath((unsigned char *) attribute,(size_t) count,
673 image->columns,image->rows);
675 path=TracePSClippath((unsigned char *) attribute,(size_t) count,
676 image->columns,image->rows);
677 (void) SetImageProperty((Image *) image,key,(const char *) path,
679 path=DestroyString(path);
681 attribute=DestroyString(attribute);
685 if (resource != (char *) NULL)
686 resource=DestroyString(resource);
690 static inline unsigned short ReadPropertyShort(const EndianType endian,
691 const unsigned char *buffer)
696 if (endian == MSBEndian)
698 value=(unsigned short) ((((unsigned char *) buffer)[0] << 8) |
699 ((unsigned char *) buffer)[1]);
700 return((unsigned short) (value & 0xffff));
702 value=(unsigned short) ((buffer[1] << 8) | buffer[0]);
703 return((unsigned short) (value & 0xffff));
706 static inline size_t ReadPropertyLong(const EndianType endian,
707 const unsigned char *buffer)
712 if (endian == MSBEndian)
714 value=(size_t) ((buffer[0] << 24) | (buffer[1] << 16) |
715 (buffer[2] << 8) | buffer[3]);
716 return((size_t) (value & 0xffffffff));
718 value=(size_t) ((buffer[3] << 24) | (buffer[2] << 16) |
719 (buffer[1] << 8 ) | (buffer[0]));
720 return((size_t) (value & 0xffffffff));
723 static MagickBooleanType GetEXIFProperty(const Image *image,
724 const char *property,ExceptionInfo *exception)
726 #define MaxDirectoryStack 16
727 #define EXIF_DELIMITER "\n"
728 #define EXIF_NUM_FORMATS 12
729 #define EXIF_FMT_BYTE 1
730 #define EXIF_FMT_STRING 2
731 #define EXIF_FMT_USHORT 3
732 #define EXIF_FMT_ULONG 4
733 #define EXIF_FMT_URATIONAL 5
734 #define EXIF_FMT_SBYTE 6
735 #define EXIF_FMT_UNDEFINED 7
736 #define EXIF_FMT_SSHORT 8
737 #define EXIF_FMT_SLONG 9
738 #define EXIF_FMT_SRATIONAL 10
739 #define EXIF_FMT_SINGLE 11
740 #define EXIF_FMT_DOUBLE 12
741 #define TAG_EXIF_OFFSET 0x8769
742 #define TAG_GPS_OFFSET 0x8825
743 #define TAG_INTEROP_OFFSET 0xa005
745 #define EXIFMultipleValues(size,format,arg) \
758 for (component=0; component < components; component++) \
760 length+=FormatLocaleString(buffer+length,MaxTextExtent-length, \
762 if (length >= (MaxTextExtent-1)) \
763 length=MaxTextExtent-1; \
767 buffer[length-2]='\0'; \
768 value=AcquireString(buffer); \
771 #define EXIFMultipleFractions(size,format,arg1,arg2) \
784 for (component=0; component < components; component++) \
786 length+=FormatLocaleString(buffer+length,MaxTextExtent-length, \
787 format", ",(arg1),(arg2)); \
788 if (length >= (MaxTextExtent-1)) \
789 length=MaxTextExtent-1; \
793 buffer[length-2]='\0'; \
794 value=AcquireString(buffer); \
797 typedef struct _DirectoryInfo
809 typedef struct _TagInfo
821 { 0x001, "exif:InteroperabilityIndex" },
822 { 0x002, "exif:InteroperabilityVersion" },
823 { 0x100, "exif:ImageWidth" },
824 { 0x101, "exif:ImageLength" },
825 { 0x102, "exif:BitsPerSample" },
826 { 0x103, "exif:Compression" },
827 { 0x106, "exif:PhotometricInterpretation" },
828 { 0x10a, "exif:FillOrder" },
829 { 0x10d, "exif:DocumentName" },
830 { 0x10e, "exif:ImageDescription" },
831 { 0x10f, "exif:Make" },
832 { 0x110, "exif:Model" },
833 { 0x111, "exif:StripOffsets" },
834 { 0x112, "exif:Orientation" },
835 { 0x115, "exif:SamplesPerPixel" },
836 { 0x116, "exif:RowsPerStrip" },
837 { 0x117, "exif:StripByteCounts" },
838 { 0x11a, "exif:XResolution" },
839 { 0x11b, "exif:YResolution" },
840 { 0x11c, "exif:PlanarConfiguration" },
841 { 0x11d, "exif:PageName" },
842 { 0x11e, "exif:XPosition" },
843 { 0x11f, "exif:YPosition" },
844 { 0x118, "exif:MinSampleValue" },
845 { 0x119, "exif:MaxSampleValue" },
846 { 0x120, "exif:FreeOffsets" },
847 { 0x121, "exif:FreeByteCounts" },
848 { 0x122, "exif:GrayResponseUnit" },
849 { 0x123, "exif:GrayResponseCurve" },
850 { 0x124, "exif:T4Options" },
851 { 0x125, "exif:T6Options" },
852 { 0x128, "exif:ResolutionUnit" },
853 { 0x12d, "exif:TransferFunction" },
854 { 0x131, "exif:Software" },
855 { 0x132, "exif:DateTime" },
856 { 0x13b, "exif:Artist" },
857 { 0x13e, "exif:WhitePoint" },
858 { 0x13f, "exif:PrimaryChromaticities" },
859 { 0x140, "exif:ColorMap" },
860 { 0x141, "exif:HalfToneHints" },
861 { 0x142, "exif:TileWidth" },
862 { 0x143, "exif:TileLength" },
863 { 0x144, "exif:TileOffsets" },
864 { 0x145, "exif:TileByteCounts" },
865 { 0x14a, "exif:SubIFD" },
866 { 0x14c, "exif:InkSet" },
867 { 0x14d, "exif:InkNames" },
868 { 0x14e, "exif:NumberOfInks" },
869 { 0x150, "exif:DotRange" },
870 { 0x151, "exif:TargetPrinter" },
871 { 0x152, "exif:ExtraSample" },
872 { 0x153, "exif:SampleFormat" },
873 { 0x154, "exif:SMinSampleValue" },
874 { 0x155, "exif:SMaxSampleValue" },
875 { 0x156, "exif:TransferRange" },
876 { 0x157, "exif:ClipPath" },
877 { 0x158, "exif:XClipPathUnits" },
878 { 0x159, "exif:YClipPathUnits" },
879 { 0x15a, "exif:Indexed" },
880 { 0x15b, "exif:JPEGTables" },
881 { 0x15f, "exif:OPIProxy" },
882 { 0x200, "exif:JPEGProc" },
883 { 0x201, "exif:JPEGInterchangeFormat" },
884 { 0x202, "exif:JPEGInterchangeFormatLength" },
885 { 0x203, "exif:JPEGRestartInterval" },
886 { 0x205, "exif:JPEGLosslessPredictors" },
887 { 0x206, "exif:JPEGPointTransforms" },
888 { 0x207, "exif:JPEGQTables" },
889 { 0x208, "exif:JPEGDCTables" },
890 { 0x209, "exif:JPEGACTables" },
891 { 0x211, "exif:YCbCrCoefficients" },
892 { 0x212, "exif:YCbCrSubSampling" },
893 { 0x213, "exif:YCbCrPositioning" },
894 { 0x214, "exif:ReferenceBlackWhite" },
895 { 0x2bc, "exif:ExtensibleMetadataPlatform" },
896 { 0x301, "exif:Gamma" },
897 { 0x302, "exif:ICCProfileDescriptor" },
898 { 0x303, "exif:SRGBRenderingIntent" },
899 { 0x320, "exif:ImageTitle" },
900 { 0x5001, "exif:ResolutionXUnit" },
901 { 0x5002, "exif:ResolutionYUnit" },
902 { 0x5003, "exif:ResolutionXLengthUnit" },
903 { 0x5004, "exif:ResolutionYLengthUnit" },
904 { 0x5005, "exif:PrintFlags" },
905 { 0x5006, "exif:PrintFlagsVersion" },
906 { 0x5007, "exif:PrintFlagsCrop" },
907 { 0x5008, "exif:PrintFlagsBleedWidth" },
908 { 0x5009, "exif:PrintFlagsBleedWidthScale" },
909 { 0x500A, "exif:HalftoneLPI" },
910 { 0x500B, "exif:HalftoneLPIUnit" },
911 { 0x500C, "exif:HalftoneDegree" },
912 { 0x500D, "exif:HalftoneShape" },
913 { 0x500E, "exif:HalftoneMisc" },
914 { 0x500F, "exif:HalftoneScreen" },
915 { 0x5010, "exif:JPEGQuality" },
916 { 0x5011, "exif:GridSize" },
917 { 0x5012, "exif:ThumbnailFormat" },
918 { 0x5013, "exif:ThumbnailWidth" },
919 { 0x5014, "exif:ThumbnailHeight" },
920 { 0x5015, "exif:ThumbnailColorDepth" },
921 { 0x5016, "exif:ThumbnailPlanes" },
922 { 0x5017, "exif:ThumbnailRawBytes" },
923 { 0x5018, "exif:ThumbnailSize" },
924 { 0x5019, "exif:ThumbnailCompressedSize" },
925 { 0x501a, "exif:ColorTransferFunction" },
926 { 0x501b, "exif:ThumbnailData" },
927 { 0x5020, "exif:ThumbnailImageWidth" },
928 { 0x5021, "exif:ThumbnailImageHeight" },
929 { 0x5022, "exif:ThumbnailBitsPerSample" },
930 { 0x5023, "exif:ThumbnailCompression" },
931 { 0x5024, "exif:ThumbnailPhotometricInterp" },
932 { 0x5025, "exif:ThumbnailImageDescription" },
933 { 0x5026, "exif:ThumbnailEquipMake" },
934 { 0x5027, "exif:ThumbnailEquipModel" },
935 { 0x5028, "exif:ThumbnailStripOffsets" },
936 { 0x5029, "exif:ThumbnailOrientation" },
937 { 0x502a, "exif:ThumbnailSamplesPerPixel" },
938 { 0x502b, "exif:ThumbnailRowsPerStrip" },
939 { 0x502c, "exif:ThumbnailStripBytesCount" },
940 { 0x502d, "exif:ThumbnailResolutionX" },
941 { 0x502e, "exif:ThumbnailResolutionY" },
942 { 0x502f, "exif:ThumbnailPlanarConfig" },
943 { 0x5030, "exif:ThumbnailResolutionUnit" },
944 { 0x5031, "exif:ThumbnailTransferFunction" },
945 { 0x5032, "exif:ThumbnailSoftwareUsed" },
946 { 0x5033, "exif:ThumbnailDateTime" },
947 { 0x5034, "exif:ThumbnailArtist" },
948 { 0x5035, "exif:ThumbnailWhitePoint" },
949 { 0x5036, "exif:ThumbnailPrimaryChromaticities" },
950 { 0x5037, "exif:ThumbnailYCbCrCoefficients" },
951 { 0x5038, "exif:ThumbnailYCbCrSubsampling" },
952 { 0x5039, "exif:ThumbnailYCbCrPositioning" },
953 { 0x503A, "exif:ThumbnailRefBlackWhite" },
954 { 0x503B, "exif:ThumbnailCopyRight" },
955 { 0x5090, "exif:LuminanceTable" },
956 { 0x5091, "exif:ChrominanceTable" },
957 { 0x5100, "exif:FrameDelay" },
958 { 0x5101, "exif:LoopCount" },
959 { 0x5110, "exif:PixelUnit" },
960 { 0x5111, "exif:PixelPerUnitX" },
961 { 0x5112, "exif:PixelPerUnitY" },
962 { 0x5113, "exif:PaletteHistogram" },
963 { 0x1000, "exif:RelatedImageFileFormat" },
964 { 0x1001, "exif:RelatedImageLength" },
965 { 0x1002, "exif:RelatedImageWidth" },
966 { 0x800d, "exif:ImageID" },
967 { 0x80e3, "exif:Matteing" },
968 { 0x80e4, "exif:DataType" },
969 { 0x80e5, "exif:ImageDepth" },
970 { 0x80e6, "exif:TileDepth" },
971 { 0x828d, "exif:CFARepeatPatternDim" },
972 { 0x828e, "exif:CFAPattern2" },
973 { 0x828f, "exif:BatteryLevel" },
974 { 0x8298, "exif:Copyright" },
975 { 0x829a, "exif:ExposureTime" },
976 { 0x829d, "exif:FNumber" },
977 { 0x83bb, "exif:IPTC/NAA" },
978 { 0x84e3, "exif:IT8RasterPadding" },
979 { 0x84e5, "exif:IT8ColorTable" },
980 { 0x8649, "exif:ImageResourceInformation" },
981 { 0x8769, "exif:ExifOffset" },
982 { 0x8773, "exif:InterColorProfile" },
983 { 0x8822, "exif:ExposureProgram" },
984 { 0x8824, "exif:SpectralSensitivity" },
985 { 0x8825, "exif:GPSInfo" },
986 { 0x8827, "exif:ISOSpeedRatings" },
987 { 0x8828, "exif:OECF" },
988 { 0x8829, "exif:Interlace" },
989 { 0x882a, "exif:TimeZoneOffset" },
990 { 0x882b, "exif:SelfTimerMode" },
991 { 0x9000, "exif:ExifVersion" },
992 { 0x9003, "exif:DateTimeOriginal" },
993 { 0x9004, "exif:DateTimeDigitized" },
994 { 0x9101, "exif:ComponentsConfiguration" },
995 { 0x9102, "exif:CompressedBitsPerPixel" },
996 { 0x9201, "exif:ShutterSpeedValue" },
997 { 0x9202, "exif:ApertureValue" },
998 { 0x9203, "exif:BrightnessValue" },
999 { 0x9204, "exif:ExposureBiasValue" },
1000 { 0x9205, "exif:MaxApertureValue" },
1001 { 0x9206, "exif:SubjectDistance" },
1002 { 0x9207, "exif:MeteringMode" },
1003 { 0x9208, "exif:LightSource" },
1004 { 0x9209, "exif:Flash" },
1005 { 0x920a, "exif:FocalLength" },
1006 { 0x920b, "exif:FlashEnergy" },
1007 { 0x920c, "exif:SpatialFrequencyResponse" },
1008 { 0x920d, "exif:Noise" },
1009 { 0x9211, "exif:ImageNumber" },
1010 { 0x9212, "exif:SecurityClassification" },
1011 { 0x9213, "exif:ImageHistory" },
1012 { 0x9214, "exif:SubjectArea" },
1013 { 0x9215, "exif:ExposureIndex" },
1014 { 0x9216, "exif:TIFF-EPStandardID" },
1015 { 0x927c, "exif:MakerNote" },
1016 { 0x9C9b, "exif:WinXP-Title" },
1017 { 0x9C9c, "exif:WinXP-Comments" },
1018 { 0x9C9d, "exif:WinXP-Author" },
1019 { 0x9C9e, "exif:WinXP-Keywords" },
1020 { 0x9C9f, "exif:WinXP-Subject" },
1021 { 0x9286, "exif:UserComment" },
1022 { 0x9290, "exif:SubSecTime" },
1023 { 0x9291, "exif:SubSecTimeOriginal" },
1024 { 0x9292, "exif:SubSecTimeDigitized" },
1025 { 0xa000, "exif:FlashPixVersion" },
1026 { 0xa001, "exif:ColorSpace" },
1027 { 0xa002, "exif:ExifImageWidth" },
1028 { 0xa003, "exif:ExifImageLength" },
1029 { 0xa004, "exif:RelatedSoundFile" },
1030 { 0xa005, "exif:InteroperabilityOffset" },
1031 { 0xa20b, "exif:FlashEnergy" },
1032 { 0xa20c, "exif:SpatialFrequencyResponse" },
1033 { 0xa20d, "exif:Noise" },
1034 { 0xa20e, "exif:FocalPlaneXResolution" },
1035 { 0xa20f, "exif:FocalPlaneYResolution" },
1036 { 0xa210, "exif:FocalPlaneResolutionUnit" },
1037 { 0xa214, "exif:SubjectLocation" },
1038 { 0xa215, "exif:ExposureIndex" },
1039 { 0xa216, "exif:TIFF/EPStandardID" },
1040 { 0xa217, "exif:SensingMethod" },
1041 { 0xa300, "exif:FileSource" },
1042 { 0xa301, "exif:SceneType" },
1043 { 0xa302, "exif:CFAPattern" },
1044 { 0xa401, "exif:CustomRendered" },
1045 { 0xa402, "exif:ExposureMode" },
1046 { 0xa403, "exif:WhiteBalance" },
1047 { 0xa404, "exif:DigitalZoomRatio" },
1048 { 0xa405, "exif:FocalLengthIn35mmFilm" },
1049 { 0xa406, "exif:SceneCaptureType" },
1050 { 0xa407, "exif:GainControl" },
1051 { 0xa408, "exif:Contrast" },
1052 { 0xa409, "exif:Saturation" },
1053 { 0xa40a, "exif:Sharpness" },
1054 { 0xa40b, "exif:DeviceSettingDescription" },
1055 { 0xa40c, "exif:SubjectDistanceRange" },
1056 { 0xa420, "exif:ImageUniqueID" },
1057 { 0xc4a5, "exif:PrintImageMatching" },
1058 { 0xa500, "exif:Gamma" },
1059 { 0xc640, "exif:CR2Slice" },
1060 { 0x10000, "exif:GPSVersionID" },
1061 { 0x10001, "exif:GPSLatitudeRef" },
1062 { 0x10002, "exif:GPSLatitude" },
1063 { 0x10003, "exif:GPSLongitudeRef" },
1064 { 0x10004, "exif:GPSLongitude" },
1065 { 0x10005, "exif:GPSAltitudeRef" },
1066 { 0x10006, "exif:GPSAltitude" },
1067 { 0x10007, "exif:GPSTimeStamp" },
1068 { 0x10008, "exif:GPSSatellites" },
1069 { 0x10009, "exif:GPSStatus" },
1070 { 0x1000a, "exif:GPSMeasureMode" },
1071 { 0x1000b, "exif:GPSDop" },
1072 { 0x1000c, "exif:GPSSpeedRef" },
1073 { 0x1000d, "exif:GPSSpeed" },
1074 { 0x1000e, "exif:GPSTrackRef" },
1075 { 0x1000f, "exif:GPSTrack" },
1076 { 0x10010, "exif:GPSImgDirectionRef" },
1077 { 0x10011, "exif:GPSImgDirection" },
1078 { 0x10012, "exif:GPSMapDatum" },
1079 { 0x10013, "exif:GPSDestLatitudeRef" },
1080 { 0x10014, "exif:GPSDestLatitude" },
1081 { 0x10015, "exif:GPSDestLongitudeRef" },
1082 { 0x10016, "exif:GPSDestLongitude" },
1083 { 0x10017, "exif:GPSDestBearingRef" },
1084 { 0x10018, "exif:GPSDestBearing" },
1085 { 0x10019, "exif:GPSDestDistanceRef" },
1086 { 0x1001a, "exif:GPSDestDistance" },
1087 { 0x1001b, "exif:GPSProcessingMethod" },
1088 { 0x1001c, "exif:GPSAreaInformation" },
1089 { 0x1001d, "exif:GPSDateStamp" },
1090 { 0x1001e, "exif:GPSDifferential" },
1102 directory_stack[MaxDirectoryStack];
1131 tag_bytes[] = {0, 1, 1, 2, 4, 8, 1, 1, 2, 4, 8, 4, 8};
1134 If EXIF data exists, then try to parse the request for a tag.
1136 profile=GetImageProfile(image,"exif");
1137 if (profile == (StringInfo *) NULL)
1138 return(MagickFalse);
1139 if ((property == (const char *) NULL) || (*property == '\0'))
1140 return(MagickFalse);
1141 while (isspace((int) ((unsigned char) *property)) != 0)
1145 switch (*(property+5))
1150 Caller has asked for all the tags in the EXIF data.
1153 all=1; /* return the data in description=value format */
1159 all=2; /* return the data in tagid=value format */
1172 Check for a hex based tag specification first.
1174 tag=(*(property+5) == '@') ? 1UL : 0UL;
1178 return(MagickFalse);
1180 Parse tag specification as a hex number.
1185 for (i=(ssize_t) n-1L; i >= 0; i--)
1189 if ((c >= '0') && (c <= '9'))
1192 if ((c >= 'A') && (c <= 'F'))
1195 if ((c >= 'a') && (c <= 'f'))
1198 return(MagickFalse);
1200 } while (*property != '\0');
1206 Try to match the text with a tag name instead.
1210 if (EXIFTag[i].tag == 0)
1212 if (LocaleCompare(EXIFTag[i].description,property) == 0)
1214 tag=(size_t) EXIFTag[i].tag;
1222 return(MagickFalse);
1223 length=GetStringInfoLength(profile);
1224 exif=GetStringInfoDatum(profile);
1227 if (ReadPropertyByte(&exif,&length) != 0x45)
1229 if (ReadPropertyByte(&exif,&length) != 0x78)
1231 if (ReadPropertyByte(&exif,&length) != 0x69)
1233 if (ReadPropertyByte(&exif,&length) != 0x66)
1235 if (ReadPropertyByte(&exif,&length) != 0x00)
1237 if (ReadPropertyByte(&exif,&length) != 0x00)
1242 return(MagickFalse);
1243 id=(ssize_t) ((int) ReadPropertyShort(LSBEndian,exif));
1251 return(MagickFalse);
1252 if (ReadPropertyShort(endian,exif+2) != 0x002a)
1253 return(MagickFalse);
1255 This the offset to the first IFD.
1257 offset=(ssize_t) ((int) ReadPropertyLong(endian,exif+4));
1258 if ((offset < 0) || (size_t) offset >= length)
1259 return(MagickFalse);
1261 Set the pointer to the first IFD and follow it were it leads.
1264 directory=exif+offset;
1268 exif_resources=NewSplayTree((int (*)(const void *,const void *)) NULL,
1269 (void *(*)(void *)) NULL,(void *(*)(void *)) NULL);
1273 If there is anything on the stack then pop it off.
1278 directory=directory_stack[level].directory;
1279 entry=directory_stack[level].entry;
1280 tag_offset=directory_stack[level].offset;
1283 Determine how many entries there are in the current IFD.
1285 number_entries=(size_t) ((int) ReadPropertyShort(endian,directory));
1286 for ( ; entry < number_entries; entry++)
1288 register unsigned char
1299 q=(unsigned char *) (directory+(12*entry)+2);
1300 if (GetValueFromSplayTree(exif_resources,q) == q)
1302 (void) AddValueToSplayTree(exif_resources,q,q);
1303 tag_value=(ssize_t) ((int) ReadPropertyShort(endian,q)+tag_offset);
1304 format=(size_t) ((int) ReadPropertyShort(endian,q+2));
1305 if (format >= (sizeof(tag_bytes)/sizeof(*tag_bytes)))
1307 components=(ssize_t) ((int) ReadPropertyLong(endian,q+4));
1308 number_bytes=(size_t) components*tag_bytes[format];
1309 if (number_bytes <= 4)
1317 The directory entry contains an offset.
1319 offset=(ssize_t) ((int) ReadPropertyLong(endian,q+8));
1320 if ((size_t) (offset+number_bytes) > length)
1322 if (~length < number_bytes)
1323 continue; /* prevent overflow */
1324 p=(unsigned char *) (exif+offset);
1326 if ((all != 0) || (tag == (size_t) tag_value))
1329 buffer[MaxTextExtent],
1332 value=(char *) NULL;
1337 case EXIF_FMT_UNDEFINED:
1339 EXIFMultipleValues(1,"%.20g",(double) (*(unsigned char *) p1));
1342 case EXIF_FMT_SBYTE:
1344 EXIFMultipleValues(1,"%.20g",(double) (*(signed char *) p1));
1347 case EXIF_FMT_SSHORT:
1349 EXIFMultipleValues(2,"%hd",ReadPropertyShort(endian,p1));
1352 case EXIF_FMT_USHORT:
1354 EXIFMultipleValues(2,"%hu",ReadPropertyShort(endian,p1));
1357 case EXIF_FMT_ULONG:
1359 EXIFMultipleValues(4,"%.20g",(double)
1360 ((int) ReadPropertyLong(endian,p1)));
1363 case EXIF_FMT_SLONG:
1365 EXIFMultipleValues(4,"%.20g",(double)
1366 ((int) ReadPropertyLong(endian,p1)));
1369 case EXIF_FMT_URATIONAL:
1371 EXIFMultipleFractions(8,"%.20g/%.20g",(double)
1372 ((int) ReadPropertyLong(endian,p1)),(double)
1373 ((int) ReadPropertyLong(endian,p1+4)));
1376 case EXIF_FMT_SRATIONAL:
1378 EXIFMultipleFractions(8,"%.20g/%.20g",(double)
1379 ((int) ReadPropertyLong(endian,p1)),(double)
1380 ((int) ReadPropertyLong(endian,p1+4)));
1383 case EXIF_FMT_SINGLE:
1385 EXIFMultipleValues(4,"%f",(double) *(float *) p1);
1388 case EXIF_FMT_DOUBLE:
1390 EXIFMultipleValues(8,"%f",*(double *) p1);
1394 case EXIF_FMT_STRING:
1396 value=(char *) NULL;
1397 if (~(1UL*number_bytes) >= 1)
1398 value=(char *) AcquireQuantumMemory((size_t) number_bytes+1UL,
1400 if (value != (char *) NULL)
1405 for (i=0; i < (ssize_t) number_bytes; i++)
1408 if ((isprint((int) p[i]) != 0) || (p[i] == '\0'))
1409 value[i]=(char) p[i];
1416 if (value != (char *) NULL)
1424 (void) CopyMagickString(key,property,MaxTextExtent);
1435 description="unknown";
1438 if (EXIFTag[i].tag == 0)
1440 if ((ssize_t) EXIFTag[i].tag == tag_value)
1442 description=EXIFTag[i].description;
1446 (void) FormatLocaleString(key,MaxTextExtent,"%s",description);
1451 if (tag_value < 0x10000)
1452 (void) FormatLocaleString(key,MaxTextExtent,"#%04lx",
1453 (unsigned long) tag_value);
1455 if (tag_value < 0x20000)
1456 (void) FormatLocaleString(key,MaxTextExtent,"@%04lx",
1457 (unsigned long) (tag_value & 0xffff));
1459 (void) FormatLocaleString(key,MaxTextExtent,"unknown");
1463 p=(const char *) NULL;
1464 if (image->properties != (void *) NULL)
1465 p=(const char *) GetValueFromSplayTree((SplayTreeInfo *)
1466 image->properties,key);
1467 if (p == (const char *) NULL)
1468 (void) SetImageProperty((Image *) image,key,value,exception);
1469 value=DestroyString(value);
1473 if ((tag_value == TAG_EXIF_OFFSET) ||
1474 (tag_value == TAG_INTEROP_OFFSET) || (tag_value == TAG_GPS_OFFSET))
1479 offset=(ssize_t) ((int) ReadPropertyLong(endian,p));
1480 if (((size_t) offset < length) && (level < (MaxDirectoryStack-2)))
1485 tag_offset1=(ssize_t) ((tag_value == TAG_GPS_OFFSET) ? 0x10000 :
1487 directory_stack[level].directory=directory;
1489 directory_stack[level].entry=entry;
1490 directory_stack[level].offset=tag_offset;
1492 directory_stack[level].directory=exif+offset;
1493 directory_stack[level].offset=tag_offset1;
1494 directory_stack[level].entry=0;
1496 if ((directory+2+(12*number_entries)) > (exif+length))
1498 offset=(ssize_t) ((int) ReadPropertyLong(endian,directory+2+(12*
1500 if ((offset != 0) && ((size_t) offset < length) &&
1501 (level < (MaxDirectoryStack-2)))
1503 directory_stack[level].directory=exif+offset;
1504 directory_stack[level].entry=0;
1505 directory_stack[level].offset=tag_offset1;
1512 } while (level > 0);
1513 exif_resources=DestroySplayTree(exif_resources);
1517 static MagickBooleanType GetXMPProperty(const Image *image,const char *property)
1541 profile=GetImageProfile(image,"xmp");
1542 if (profile == (StringInfo *) NULL)
1543 return(MagickFalse);
1544 if ((property == (const char *) NULL) || (*property == '\0'))
1545 return(MagickFalse);
1546 xmp_profile=StringInfoToString(profile);
1547 if (xmp_profile == (char *) NULL)
1548 return(MagickFalse);
1549 for (p=xmp_profile; *p != '\0'; p++)
1550 if ((*p == '<') && (*(p+1) == 'x'))
1552 exception=AcquireExceptionInfo();
1553 xmp=NewXMLTree((char *) p,exception);
1554 xmp_profile=DestroyString(xmp_profile);
1555 exception=DestroyExceptionInfo(exception);
1556 if (xmp == (XMLTreeInfo *) NULL)
1557 return(MagickFalse);
1559 rdf=GetXMLTreeChild(xmp,"rdf:RDF");
1560 if (rdf != (XMLTreeInfo *) NULL)
1562 if (image->properties == (void *) NULL)
1563 ((Image *) image)->properties=NewSplayTree(CompareSplayTreeString,
1564 RelinquishMagickMemory,RelinquishMagickMemory);
1565 description=GetXMLTreeChild(rdf,"rdf:Description");
1566 while (description != (XMLTreeInfo *) NULL)
1568 node=GetXMLTreeChild(description,(const char *) NULL);
1569 while (node != (XMLTreeInfo *) NULL)
1571 child=GetXMLTreeChild(node,(const char *) NULL);
1572 if (child == (XMLTreeInfo *) NULL)
1573 (void) AddValueToSplayTree((SplayTreeInfo *) image->properties,
1574 ConstantString(GetXMLTreeTag(node)),
1575 ConstantString(GetXMLTreeContent(node)));
1576 while (child != (XMLTreeInfo *) NULL)
1578 if (LocaleCompare(GetXMLTreeTag(child),"rdf:Seq") != 0)
1579 (void) AddValueToSplayTree((SplayTreeInfo *) image->properties,
1580 ConstantString(GetXMLTreeTag(child)),
1581 ConstantString(GetXMLTreeContent(child)));
1582 child=GetXMLTreeSibling(child);
1584 node=GetXMLTreeSibling(node);
1586 description=GetNextXMLTreeTag(description);
1589 xmp=DestroyXMLTree(xmp);
1593 static char *TracePSClippath(const unsigned char *blob,size_t length,
1594 const size_t magick_unused(columns),const size_t magick_unused(rows))
1617 path=AcquireString((char *) NULL);
1618 if (path == (char *) NULL)
1619 return((char *) NULL);
1620 message=AcquireString((char *) NULL);
1621 (void) FormatLocaleString(message,MaxTextExtent,"/ClipImage\n");
1622 (void) ConcatenateString(&path,message);
1623 (void) FormatLocaleString(message,MaxTextExtent,"{\n");
1624 (void) ConcatenateString(&path,message);
1625 (void) FormatLocaleString(message,MaxTextExtent," /c {curveto} bind def\n");
1626 (void) ConcatenateString(&path,message);
1627 (void) FormatLocaleString(message,MaxTextExtent," /l {lineto} bind def\n");
1628 (void) ConcatenateString(&path,message);
1629 (void) FormatLocaleString(message,MaxTextExtent," /m {moveto} bind def\n");
1630 (void) ConcatenateString(&path,message);
1631 (void) FormatLocaleString(message,MaxTextExtent,
1632 " /v {currentpoint 6 2 roll curveto} bind def\n");
1633 (void) ConcatenateString(&path,message);
1634 (void) FormatLocaleString(message,MaxTextExtent,
1635 " /y {2 copy curveto} bind def\n");
1636 (void) ConcatenateString(&path,message);
1637 (void) FormatLocaleString(message,MaxTextExtent,
1638 " /z {closepath} bind def\n");
1639 (void) ConcatenateString(&path,message);
1640 (void) FormatLocaleString(message,MaxTextExtent," newpath\n");
1641 (void) ConcatenateString(&path,message);
1643 The clipping path format is defined in "Adobe Photoshop File
1644 Formats Specification" version 6.0 downloadable from adobe.com.
1646 (void) ResetMagickMemory(point,0,sizeof(point));
1647 (void) ResetMagickMemory(first,0,sizeof(first));
1648 (void) ResetMagickMemory(last,0,sizeof(last));
1650 in_subpath=MagickFalse;
1653 selector=(ssize_t) ((int) ReadPropertyMSBShort(&blob,&length));
1659 if (knot_count != 0)
1662 length-=MagickMin(24,(ssize_t) length);
1666 Expected subpath length record.
1668 knot_count=(ssize_t) ((int) ReadPropertyMSBShort(&blob,&length));
1670 length-=MagickMin(22,(ssize_t) length);
1678 if (knot_count == 0)
1681 Unexpected subpath knot
1684 length-=MagickMin(24,(ssize_t) length);
1690 for (i=0; i < 3; i++)
1696 yy=(size_t) ((int) ReadPropertyMSBLong(&blob,&length));
1697 xx=(size_t) ((int) ReadPropertyMSBLong(&blob,&length));
1699 if (xx > 2147483647)
1700 x=(ssize_t) xx-4294967295U-1;
1702 if (yy > 2147483647)
1703 y=(ssize_t) yy-4294967295U-1;
1704 point[i].x=(double) x/4096/4096;
1705 point[i].y=1.0-(double) y/4096/4096;
1707 if (in_subpath == MagickFalse)
1709 (void) FormatLocaleString(message,MaxTextExtent," %g %g m\n",
1710 point[1].x,point[1].y);
1711 for (i=0; i < 3; i++)
1720 Handle special cases when Bezier curves are used to describe
1721 corners and straight lines.
1723 if ((last[1].x == last[2].x) && (last[1].y == last[2].y) &&
1724 (point[0].x == point[1].x) && (point[0].y == point[1].y))
1725 (void) FormatLocaleString(message,MaxTextExtent,
1726 " %g %g l\n",point[1].x,point[1].y);
1728 if ((last[1].x == last[2].x) && (last[1].y == last[2].y))
1729 (void) FormatLocaleString(message,MaxTextExtent,
1730 " %g %g %g %g v\n",point[0].x,point[0].y,
1731 point[1].x,point[1].y);
1733 if ((point[0].x == point[1].x) && (point[0].y == point[1].y))
1734 (void) FormatLocaleString(message,MaxTextExtent,
1735 " %g %g %g %g y\n",last[2].x,last[2].y,
1736 point[1].x,point[1].y);
1738 (void) FormatLocaleString(message,MaxTextExtent,
1739 " %g %g %g %g %g %g c\n",last[2].x,
1740 last[2].y,point[0].x,point[0].y,point[1].x,point[1].y);
1741 for (i=0; i < 3; i++)
1744 (void) ConcatenateString(&path,message);
1745 in_subpath=MagickTrue;
1748 Close the subpath if there are no more knots.
1750 if (knot_count == 0)
1753 Same special handling as above except we compare to the
1754 first point in the path and close the path.
1756 if ((last[1].x == last[2].x) && (last[1].y == last[2].y) &&
1757 (first[0].x == first[1].x) && (first[0].y == first[1].y))
1758 (void) FormatLocaleString(message,MaxTextExtent,
1759 " %g %g l z\n",first[1].x,first[1].y);
1761 if ((last[1].x == last[2].x) && (last[1].y == last[2].y))
1762 (void) FormatLocaleString(message,MaxTextExtent,
1763 " %g %g %g %g v z\n",first[0].x,first[0].y,
1764 first[1].x,first[1].y);
1766 if ((first[0].x == first[1].x) && (first[0].y == first[1].y))
1767 (void) FormatLocaleString(message,MaxTextExtent,
1768 " %g %g %g %g y z\n",last[2].x,last[2].y,
1769 first[1].x,first[1].y);
1771 (void) FormatLocaleString(message,MaxTextExtent,
1772 " %g %g %g %g %g %g c z\n",last[2].x,
1773 last[2].y,first[0].x,first[0].y,first[1].x,first[1].y);
1774 (void) ConcatenateString(&path,message);
1775 in_subpath=MagickFalse;
1785 length-=MagickMin(24,(ssize_t) length);
1791 Returns an empty PS path if the path has no knots.
1793 (void) FormatLocaleString(message,MaxTextExtent," eoclip\n");
1794 (void) ConcatenateString(&path,message);
1795 (void) FormatLocaleString(message,MaxTextExtent,"} bind def");
1796 (void) ConcatenateString(&path,message);
1797 message=DestroyString(message);
1801 static char *TraceSVGClippath(const unsigned char *blob,size_t length,
1802 const size_t columns,const size_t rows)
1825 path=AcquireString((char *) NULL);
1826 if (path == (char *) NULL)
1827 return((char *) NULL);
1828 message=AcquireString((char *) NULL);
1829 (void) FormatLocaleString(message,MaxTextExtent,
1830 "<?xml version=\"1.0\" encoding=\"iso-8859-1\"?>\n");
1831 (void) ConcatenateString(&path,message);
1832 (void) FormatLocaleString(message,MaxTextExtent,
1833 "<svg width=\"%.20g\" height=\"%.20g\">\n",(double) columns,(double) rows);
1834 (void) ConcatenateString(&path,message);
1835 (void) FormatLocaleString(message,MaxTextExtent,"<g>\n");
1836 (void) ConcatenateString(&path,message);
1837 (void) FormatLocaleString(message,MaxTextExtent,
1838 "<path style=\"fill:#00000000;stroke:#00000000;");
1839 (void) ConcatenateString(&path,message);
1840 (void) FormatLocaleString(message,MaxTextExtent,
1841 "stroke-width:0;stroke-antialiasing:false\" d=\"\n");
1842 (void) ConcatenateString(&path,message);
1843 (void) ResetMagickMemory(point,0,sizeof(point));
1844 (void) ResetMagickMemory(first,0,sizeof(first));
1845 (void) ResetMagickMemory(last,0,sizeof(last));
1847 in_subpath=MagickFalse;
1850 selector=(ssize_t) ((int) ReadPropertyMSBShort(&blob,&length));
1856 if (knot_count != 0)
1859 length-=MagickMin(24,(ssize_t) length);
1863 Expected subpath length record.
1865 knot_count=(ssize_t) ((int) ReadPropertyMSBShort(&blob,&length));
1867 length-=MagickMin(22,(ssize_t) length);
1875 if (knot_count == 0)
1878 Unexpected subpath knot.
1881 length-=MagickMin(24,(ssize_t) length);
1887 for (i=0; i < 3; i++)
1893 yy=(size_t) ((int) ReadPropertyMSBLong(&blob,&length));
1894 xx=(size_t) ((int) ReadPropertyMSBLong(&blob,&length));
1896 if (xx > 2147483647)
1897 x=(ssize_t) xx-4294967295U-1;
1899 if (yy > 2147483647)
1900 y=(ssize_t) yy-4294967295U-1;
1901 point[i].x=(double) x*columns/4096/4096;
1902 point[i].y=(double) y*rows/4096/4096;
1904 if (in_subpath == MagickFalse)
1906 (void) FormatLocaleString(message,MaxTextExtent,"M %g,%g\n",
1907 point[1].x,point[1].y);
1908 for (i=0; i < 3; i++)
1916 if ((last[1].x == last[2].x) && (last[1].y == last[2].y) &&
1917 (point[0].x == point[1].x) && (point[0].y == point[1].y))
1918 (void) FormatLocaleString(message,MaxTextExtent,"L %g,%g\n",
1919 point[1].x,point[1].y);
1921 (void) FormatLocaleString(message,MaxTextExtent,
1922 "C %g,%g %g,%g %g,%g\n",last[2].x,last[2].y,
1923 point[0].x,point[0].y,point[1].x,point[1].y);
1924 for (i=0; i < 3; i++)
1927 (void) ConcatenateString(&path,message);
1928 in_subpath=MagickTrue;
1931 Close the subpath if there are no more knots.
1933 if (knot_count == 0)
1935 if ((last[1].x == last[2].x) && (last[1].y == last[2].y) &&
1936 (first[0].x == first[1].x) && (first[0].y == first[1].y))
1937 (void) FormatLocaleString(message,MaxTextExtent,
1938 "L %g,%g Z\n",first[1].x,first[1].y);
1941 (void) FormatLocaleString(message,MaxTextExtent,
1942 "C %g,%g %g,%g %g,%g Z\n",last[2].x,
1943 last[2].y,first[0].x,first[0].y,first[1].x,first[1].y);
1944 (void) ConcatenateString(&path,message);
1946 in_subpath=MagickFalse;
1956 length-=MagickMin(24,(ssize_t) length);
1962 Return an empty SVG image if the path does not have knots.
1964 (void) FormatLocaleString(message,MaxTextExtent,"\"/>\n");
1965 (void) ConcatenateString(&path,message);
1966 (void) FormatLocaleString(message,MaxTextExtent,"</g>\n");
1967 (void) ConcatenateString(&path,message);
1968 (void) FormatLocaleString(message,MaxTextExtent,"</svg>\n");
1969 (void) ConcatenateString(&path,message);
1970 message=DestroyString(message);
1974 MagickExport const char *GetImageProperty(const Image *image,
1975 const char *property,ExceptionInfo *exception)
1989 assert(image != (Image *) NULL);
1990 assert(image->signature == MagickSignature);
1991 if (image->debug != MagickFalse)
1992 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1993 p=(const char *) NULL;
1994 if (image->properties != (void *) NULL)
1996 if (property == (const char *) NULL)
1998 ResetSplayTreeIterator((SplayTreeInfo *) image->properties);
1999 p=(const char *) GetNextValueInSplayTree((SplayTreeInfo *)
2003 if (LocaleNCompare("fx:",property,3) != 0)
2005 p=(const char *) GetValueFromSplayTree((SplayTreeInfo *)
2006 image->properties,property);
2007 if (p != (const char *) NULL)
2011 if ((property == (const char *) NULL) ||
2012 (strchr(property,':') == (char *) NULL))
2018 if (LocaleNCompare("8bim:",property,5) == 0)
2020 if ((Get8BIMProperty(image,property,exception) != MagickFalse) &&
2021 (image->properties != (void *) NULL))
2023 p=(const char *) GetValueFromSplayTree((SplayTreeInfo *)
2024 image->properties,property);
2033 if (LocaleNCompare("exif:",property,5) == 0)
2035 if ((GetEXIFProperty(image,property,exception) != MagickFalse) &&
2036 (image->properties != (void *) NULL))
2038 p=(const char *) GetValueFromSplayTree((SplayTreeInfo *)
2039 image->properties,property);
2048 if (LocaleNCompare("fx:",property,3) == 0)
2050 fx_info=AcquireFxInfo(image,property+3);
2051 status=FxEvaluateChannelExpression(fx_info,IntensityPixelChannel,0,0,
2053 fx_info=DestroyFxInfo(fx_info);
2054 if (status != MagickFalse)
2057 value[MaxTextExtent];
2059 (void) FormatLocaleString(value,MaxTextExtent,"%.*g",
2060 GetMagickPrecision(),(double) alpha);
2061 (void) SetImageProperty((Image *) image,property,value,exception);
2063 if (image->properties != (void *) NULL)
2065 p=(const char *) GetValueFromSplayTree((SplayTreeInfo *)
2066 image->properties,property);
2075 if (LocaleNCompare("iptc:",property,5) == 0)
2077 if ((GetIPTCProperty(image,property,exception) != MagickFalse) &&
2078 (image->properties != (void *) NULL))
2080 p=(const char *) GetValueFromSplayTree((SplayTreeInfo *)
2081 image->properties,property);
2090 if (LocaleNCompare("pixel:",property,6) == 0)
2095 GetPixelInfo(image,&pixel);
2096 fx_info=AcquireFxInfo(image,property+6);
2097 status=FxEvaluateChannelExpression(fx_info,RedPixelChannel,0,0,
2099 pixel.red=(MagickRealType) QuantumRange*alpha;
2100 status|=FxEvaluateChannelExpression(fx_info,GreenPixelChannel,0,0,
2102 pixel.green=(MagickRealType) QuantumRange*alpha;
2103 status|=FxEvaluateChannelExpression(fx_info,BluePixelChannel,0,0,
2105 pixel.blue=(MagickRealType) QuantumRange*alpha;
2106 if (image->colorspace == CMYKColorspace)
2108 status|=FxEvaluateChannelExpression(fx_info,BlackPixelChannel,0,0,
2110 pixel.black=(MagickRealType) QuantumRange*alpha;
2112 status|=FxEvaluateChannelExpression(fx_info,AlphaPixelChannel,0,0,
2114 pixel.alpha=(MagickRealType) QuantumRange*(1.0-alpha);
2115 fx_info=DestroyFxInfo(fx_info);
2116 if (status != MagickFalse)
2119 name[MaxTextExtent];
2121 (void) QueryColorname(image,&pixel,SVGCompliance,name,
2123 (void) SetImageProperty((Image *) image,property,name,exception);
2124 return(GetImageProperty(image,property,exception));
2132 if (LocaleNCompare("xmp:",property,4) == 0)
2134 if ((GetXMPProperty(image,property) != MagickFalse) &&
2135 (image->properties != (void *) NULL))
2137 p=(const char *) GetValueFromSplayTree((SplayTreeInfo *)
2138 image->properties,property);
2151 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2155 + G e t M a g i c k P r o p e r t y %
2159 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2161 % GetMagickProperty() gets a value associated with an image property.
2163 % The format of the GetMagickProperty method is:
2165 % const char *GetMagickProperty(const ImageInfo *image_info,Image *image,
2166 % const char *key,ExceptionInfo *exception)
2168 % A description of each parameter follows:
2170 % o image_info: the image info.
2172 % o image: the image.
2176 % o exception: return any errors or warnings in this structure.
2179 MagickExport const char *GetMagickProperty(const ImageInfo *image_info,
2180 Image *image,const char *property,ExceptionInfo *exception)
2183 value[MaxTextExtent],
2184 filename[MaxTextExtent];
2191 if (LocaleNCompare("base",property,4) == 0)
2193 GetPathComponent(image->magick_filename,BasePath,filename);
2194 (void) CopyMagickString(value,filename,MaxTextExtent);
2201 if (LocaleNCompare("channels",property,8) == 0)
2206 (void) FormatLocaleString(value,MaxTextExtent,"%s",
2207 CommandOptionToMnemonic(MagickColorspaceOptions,(ssize_t)
2208 image->colorspace));
2210 if (image->matte != MagickFalse)
2211 (void) ConcatenateMagickString(value,"a",MaxTextExtent);
2214 if (LocaleNCompare("colorspace",property,10) == 0)
2220 Image storage class and colorspace.
2222 colorspace=image->colorspace;
2223 if (IsImageGray(image,exception) != MagickFalse)
2224 colorspace=GRAYColorspace;
2225 (void) FormatLocaleString(value,MaxTextExtent,"%s",
2226 CommandOptionToMnemonic(MagickColorspaceOptions,(ssize_t)
2230 if (LocaleNCompare("copyright",property,9) == 0)
2232 (void) CopyMagickString(value,GetMagickCopyright(),MaxTextExtent);
2239 if (LocaleNCompare("depth",property,5) == 0)
2241 (void) FormatLocaleString(value,MaxTextExtent,"%.20g",(double)
2245 if (LocaleNCompare("directory",property,9) == 0)
2247 GetPathComponent(image->magick_filename,HeadPath,filename);
2248 (void) CopyMagickString(value,filename,MaxTextExtent);
2255 if (LocaleNCompare("extension",property,9) == 0)
2257 GetPathComponent(image->magick_filename,ExtensionPath,filename);
2258 (void) CopyMagickString(value,filename,MaxTextExtent);
2265 if (LocaleNCompare("group",property,5) == 0)
2267 (void) FormatLocaleString(value,MaxTextExtent,"0x%lx",
2268 (unsigned long) image_info->group);
2275 if (LocaleNCompare("height",property,6) == 0)
2277 (void) FormatLocaleString(value,MaxTextExtent,"%.20g",
2278 image->magick_rows != 0 ? (double) image->magick_rows : 256.0);
2285 if (LocaleNCompare("input",property,5) == 0)
2287 (void) CopyMagickString(value,image->filename,MaxTextExtent);
2294 if (LocaleNCompare("kurtosis",property,8) == 0)
2300 (void) GetImageKurtosis(image,&kurtosis,&skewness,exception);
2301 (void) FormatLocaleString(value,MaxTextExtent,"%.*g",
2302 GetMagickPrecision(),kurtosis);
2309 if (LocaleNCompare("magick",property,6) == 0)
2311 (void) CopyMagickString(value,image->magick,MaxTextExtent);
2314 if (LocaleNCompare("max",property,3) == 0)
2320 (void) GetImageRange(image,&minimum,&maximum,exception);
2321 (void) FormatLocaleString(value,MaxTextExtent,"%.*g",
2322 GetMagickPrecision(),maximum);
2325 if (LocaleNCompare("mean",property,4) == 0)
2331 (void) GetImageMean(image,&mean,&standard_deviation,
2333 (void) FormatLocaleString(value,MaxTextExtent,"%.*g",
2334 GetMagickPrecision(),mean);
2337 if (LocaleNCompare("min",property,3) == 0)
2343 (void) GetImageRange(image,&minimum,&maximum,exception);
2344 (void) FormatLocaleString(value,MaxTextExtent,"%.*g",
2345 GetMagickPrecision(),minimum);
2352 if (LocaleNCompare("name",property,4) == 0)
2354 (void) CopyMagickString(value,filename,MaxTextExtent);
2361 if (LocaleNCompare("opaque",property,6) == 0)
2366 opaque=IsImageOpaque(image,exception);
2367 (void) CopyMagickString(value,opaque == MagickFalse ? "false" :
2368 "true",MaxTextExtent);
2371 if (LocaleNCompare("orientation",property,11) == 0)
2373 (void) FormatLocaleString(value,MaxTextExtent,"%s",
2374 CommandOptionToMnemonic(MagickOrientationOptions,(ssize_t)
2375 image->orientation));
2378 if (LocaleNCompare("output",property,6) == 0)
2380 (void) CopyMagickString(value,image_info->filename,MaxTextExtent);
2387 if (LocaleNCompare("page",property,4) == 0)
2389 (void) FormatLocaleString(value,MaxTextExtent,"%.20g",(double)
2390 GetImageIndexInList(image)+1);
2397 if (LocaleNCompare("size",property,4) == 0)
2400 format[MaxTextExtent];
2402 (void) FormatMagickSize(GetBlobSize(image),MagickFalse,format);
2403 (void) FormatLocaleString(value,MaxTextExtent,"%sB",format);
2406 if (LocaleNCompare("scenes",property,6) == 0)
2408 (void) FormatLocaleString(value,MaxTextExtent,"%.20g",(double)
2409 GetImageListLength(image));
2412 if (LocaleNCompare("scene",property,5) == 0)
2414 /* FUTURE: I am not certain this property return makes sense! */
2415 (void) FormatLocaleString(value,MaxTextExtent,"%.20g",(double)
2417 if (image_info->number_scenes != 0)
2418 (void) FormatLocaleString(value,MaxTextExtent,"%.20g",(double)
2422 if (LocaleNCompare("skewness",property,8) == 0)
2428 (void) GetImageKurtosis(image,&kurtosis,&skewness,exception);
2429 (void) FormatLocaleString(value,MaxTextExtent,"%.*g",
2430 GetMagickPrecision(),skewness);
2433 if (LocaleNCompare("standard-deviation",property,18) == 0)
2439 (void) GetImageMean(image,&mean,&standard_deviation,
2441 (void) FormatLocaleString(value,MaxTextExtent,"%.*g",
2442 GetMagickPrecision(),standard_deviation);
2449 if (LocaleNCompare("unique",property,6) == 0)
2451 (void) CopyMagickString(filename,image_info->unique,MaxTextExtent);
2452 (void) CopyMagickString(value,filename,MaxTextExtent);
2459 if (LocaleNCompare("version",property,7) == 0)
2461 (void) CopyMagickString(value,GetMagickVersion((size_t *) NULL),
2469 if (LocaleNCompare("width",property,5) == 0)
2471 (void) FormatLocaleString(value,MaxTextExtent,"%.20g",(double)
2472 (image->magick_columns != 0 ? image->magick_columns : 256));
2479 if (LocaleNCompare("xresolution",property,11) == 0)
2481 (void) FormatLocaleString(value,MaxTextExtent,"%g",
2482 image->resolution.x);
2489 if (LocaleNCompare("yresolution",property,11) == 0)
2491 (void) FormatLocaleString(value,MaxTextExtent,"%g",
2492 image->resolution.y);
2499 if (LocaleNCompare("zero",property,4) == 0)
2501 (void) CopyMagickString(filename,image_info->zero,MaxTextExtent);
2502 (void) CopyMagickString(value,filename,MaxTextExtent);
2510 if (image->properties == (void *) NULL)
2511 image->properties=NewSplayTree(CompareSplayTreeString,
2512 RelinquishMagickMemory,RelinquishMagickMemory);
2513 (void) AddValueToSplayTree((SplayTreeInfo *) image->properties,
2514 ConstantString(property),ConstantString(value));
2516 return(GetImageProperty(image,property,exception));
2520 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2524 % G e t N e x t I m a g e P r o p e r t y %
2528 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2530 % GetNextImageProperty() gets the next image property value.
2532 % The format of the GetNextImageProperty method is:
2534 % char *GetNextImageProperty(const Image *image)
2536 % A description of each parameter follows:
2538 % o image: the image.
2541 MagickExport char *GetNextImageProperty(const Image *image)
2543 assert(image != (Image *) NULL);
2544 assert(image->signature == MagickSignature);
2545 if (image->debug != MagickFalse)
2546 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
2548 if (image->properties == (void *) NULL)
2549 return((char *) NULL);
2550 return((char *) GetNextKeyInSplayTree((SplayTreeInfo *) image->properties));
2554 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2558 % I n t e r p r e t I m a g e P r o p e r t i e s %
2562 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2564 % InterpretImageProperties() replaces any embedded formatting characters with
2565 % the appropriate image property and returns the interpreted text.
2567 % The format of the InterpretImageProperties method is:
2569 % char *InterpretImageProperties(const ImageInfo *image_info,Image *image,
2570 % const char *embed_text,ExceptionInfo *exception)
2572 % A description of each parameter follows:
2574 % o image_info: the image info.
2576 % o image: the image.
2578 % o embed_text: the address of a character string containing the embedded
2579 % formatting characters.
2581 % o exception: return any errors or warnings in this structure.
2584 MagickExport char *InterpretImageProperties(const ImageInfo *image_info,
2585 Image *image,const char *embed_text,ExceptionInfo *exception)
2588 filename[MaxTextExtent],
2608 assert(image != (Image *) NULL);
2609 assert(image->signature == MagickSignature);
2610 if (image->debug != MagickFalse)
2611 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
2612 if ((embed_text == (const char *) NULL) || (*embed_text == '\0'))
2613 return((char *) NULL);
2614 text=(char *) embed_text;
2615 if ((*text == '@') && ((*(text+1) == '-') ||
2616 (IsPathAccessible(text+1) != MagickFalse)))
2617 return(FileToString(embed_text+1,~0,exception));
2619 Translate any embedded format characters.
2621 interpret_text=AcquireString(text);
2622 extent=MaxTextExtent;
2624 for (q=interpret_text; *p != '\0'; p++)
2627 if ((size_t) (q-interpret_text+MaxTextExtent) >= extent)
2629 extent+=MaxTextExtent;
2630 interpret_text=(char *) ResizeQuantumMemory(interpret_text,extent+
2631 MaxTextExtent+1,sizeof(*interpret_text));
2632 if (interpret_text == (char *) NULL)
2634 q=interpret_text+strlen(interpret_text);
2637 Process formatting characters in text.
2639 if ((*p == '\\') && (*(p+1) == 'r'))
2645 if ((*p == '\\') && (*(p+1) == 'n'))
2665 case '[': /* multi-character substitution */
2668 pattern[MaxTextExtent];
2680 if (strchr(p,']') == (char *) NULL)
2684 for (i=0; (i < (MaxTextExtent-1L)) && (*p != '\0'); i++)
2695 value=GetImageProperty(image,pattern,exception);
2696 if (value != (const char *) NULL)
2698 length=strlen(value);
2699 if ((size_t) (q-interpret_text+length+1) >= extent)
2702 interpret_text=(char *) ResizeQuantumMemory(interpret_text,
2703 extent+MaxTextExtent,sizeof(*interpret_text));
2704 if (interpret_text == (char *) NULL)
2706 q=interpret_text+strlen(interpret_text);
2708 (void) CopyMagickString(q,value,extent);
2713 if (IsGlob(pattern) != MagickFalse)
2716 Iterate over image properties.
2718 ResetImagePropertyIterator(image);
2719 key=GetNextImageProperty(image);
2720 while (key != (const char *) NULL)
2722 if (GlobExpression(key,pattern,MagickTrue) != MagickFalse)
2724 value=GetImageProperty(image,key,exception);
2725 if (value != (const char *) NULL)
2727 length=strlen(key)+strlen(value)+2;
2728 if ((size_t) (q-interpret_text+length+1) >= extent)
2731 interpret_text=(char *) ResizeQuantumMemory(
2732 interpret_text,extent+MaxTextExtent,
2733 sizeof(*interpret_text));
2734 if (interpret_text == (char *) NULL)
2736 q=interpret_text+strlen(interpret_text);
2738 q+=FormatLocaleString(q,extent,"%s=%s\n",key,value);
2741 key=GetNextImageProperty(image);
2744 value=GetMagickProperty(image_info,image,pattern,exception);
2745 if (value != (const char *) NULL)
2747 length=strlen(value);
2748 if ((size_t) (q-interpret_text+length+1) >= extent)
2751 interpret_text=(char *) ResizeQuantumMemory(interpret_text,
2752 extent+MaxTextExtent,sizeof(*interpret_text));
2753 if (interpret_text == (char *) NULL)
2755 q=interpret_text+strlen(interpret_text);
2757 (void) CopyMagickString(q,value,extent);
2761 if (image_info == (ImageInfo *) NULL)
2763 value=GetImageOption(image_info,pattern);
2764 if (value != (char *) NULL)
2766 length=strlen(value);
2767 if ((size_t) (q-interpret_text+length+1) >= extent)
2770 interpret_text=(char *) ResizeQuantumMemory(interpret_text,
2771 extent+MaxTextExtent,sizeof(*interpret_text));
2772 if (interpret_text == (char *) NULL)
2774 q=interpret_text+strlen(interpret_text);
2776 (void) CopyMagickString(q,value,extent);
2782 case 'b': /* image size as read in */
2785 format[MaxTextExtent];
2787 (void) FormatLocaleString(format,MaxTextExtent,"%.20g",(double)
2788 ((MagickOffsetType) image->extent));
2789 if (image->extent != (MagickSizeType) ((size_t) image->extent))
2790 (void) FormatMagickSize(image->extent,MagickFalse,format);
2791 q+=ConcatenateMagickString(q,format,extent);
2792 q+=ConcatenateMagickString(q,"B",extent);
2795 case 'c': /* image comment properity */
2797 value=GetImageProperty(image,"comment",exception);
2798 if (value == (const char *) NULL)
2800 length=strlen(value);
2801 if ((size_t) (q-interpret_text+length+1) >= extent)
2804 interpret_text=(char *) ResizeQuantumMemory(interpret_text,extent+
2805 MaxTextExtent,sizeof(*interpret_text));
2806 if (interpret_text == (char *) NULL)
2808 q=interpret_text+strlen(interpret_text);
2810 (void) CopyMagickString(q,value,extent);
2814 case 'd': /* Directory component of filename */
2816 GetPathComponent(image->magick_filename,HeadPath,filename);
2817 q+=CopyMagickString(q,filename,extent);
2820 case 'e': /* Filename extension (suffix) of image file */
2822 GetPathComponent(image->magick_filename,ExtensionPath,filename);
2823 q+=CopyMagickString(q,filename,extent);
2826 case 'f': /* Filename without directory component */
2828 GetPathComponent(image->magick_filename,TailPath,filename);
2829 q+=CopyMagickString(q,filename,extent);
2832 case 't': /* Base filename without directory or extention */
2834 GetPathComponent(image->magick_filename,BasePath,filename);
2835 q+=CopyMagickString(q,filename,extent);
2838 case 'g': /* Image geometry, canvas and offset */
2840 q+=FormatLocaleString(q,extent,"%.20gx%.20g%+.20g%+.20g",(double)
2841 image->page.width,(double) image->page.height,(double) image->page.x,
2842 (double) image->page.y);
2845 case 'h': /* Image height */
2847 q+=FormatLocaleString(q,extent,"%.20g",(double) (image->rows != 0 ?
2848 image->rows : image->magick_rows));
2851 case 'i': /* Images filename - (output filename with "info:" ) */
2853 q+=CopyMagickString(q,image->filename,extent);
2856 case 'k': /* Number of unique colors */
2858 q+=FormatLocaleString(q,extent,"%.20g",(double) GetNumberColors(image,
2859 (FILE *) NULL,exception));
2862 case 'l': /* Image label */
2864 value=GetImageProperty(image,"label",exception);
2865 if (value == (const char *) NULL)
2867 length=strlen(value);
2868 if ((size_t) (q-interpret_text+length+1) >= extent)
2871 interpret_text=(char *) ResizeQuantumMemory(interpret_text,extent+
2872 MaxTextExtent,sizeof(*interpret_text));
2873 if (interpret_text == (char *) NULL)
2875 q=interpret_text+strlen(interpret_text);
2877 q+=CopyMagickString(q,value,extent);
2880 case 'm': /* Image format (file magick) */
2882 q+=CopyMagickString(q,image->magick,extent);
2885 case 'M': /* Magick filename - exactly as given incl. read mods */
2887 q+=CopyMagickString(q,image->magick_filename,extent);
2890 case 'n': /* Number of images in the list. */
2892 q+=FormatLocaleString(q,extent,"%.20g",(double)
2893 GetImageListLength(image));
2896 case 'o': /* Image output filename */
2898 q+=CopyMagickString(q,image_info->filename,extent);
2901 case 'p': /* Image index in current image list */
2903 q+=FormatLocaleString(q,extent,"%.20g",(double)
2904 GetImageIndexInList(image));
2907 case 'q': /* Quantum depth of image in memory */
2909 q+=FormatLocaleString(q,extent,"%.20g",(double)
2910 MAGICKCORE_QUANTUM_DEPTH);
2913 case 'r': /* Image storage class and colorspace. */
2918 colorspace=image->colorspace;
2919 if (IsImageGray(image,exception) != MagickFalse)
2920 colorspace=GRAYColorspace;
2921 q+=FormatLocaleString(q,extent,"%s%s%s",CommandOptionToMnemonic(
2922 MagickClassOptions,(ssize_t) image->storage_class),
2923 CommandOptionToMnemonic(MagickColorspaceOptions,(ssize_t) colorspace),
2924 image->matte != MagickFalse ? "Matte" : "");
2927 case 's': /* Image scene number */
2929 if (image_info->number_scenes == 0)
2930 q+=FormatLocaleString(q,extent,"%.20g",(double) image->scene);
2932 q+=FormatLocaleString(q,extent,"%.20g",(double) image_info->scene);
2935 case 'u': /* Unique filename */
2937 (void) CopyMagickString(filename,image_info->unique,extent);
2938 q+=CopyMagickString(q,filename,extent);
2941 case 'w': /* Image width */
2943 q+=FormatLocaleString(q,extent,"%.20g",(double) (image->columns != 0 ?
2944 image->columns : image->magick_columns));
2947 case 'x': /* Image horizontal resolution (density). */
2949 q+=FormatLocaleString(q,extent,"%g %s",image->resolution.x,
2950 CommandOptionToMnemonic(MagickResolutionOptions,(ssize_t)
2954 case 'y': /* Image vertical resolution (density) */
2956 q+=FormatLocaleString(q,extent,"%g %s",image->resolution.y,
2957 CommandOptionToMnemonic(MagickResolutionOptions,(ssize_t)
2961 case 'z': /* Image depth as read in */
2963 q+=FormatLocaleString(q,extent,"%.20g",(double) image->depth);
2966 case 'A': /* Image alpha channel */
2968 q+=FormatLocaleString(q,extent,"%s",CommandOptionToMnemonic(
2969 MagickBooleanOptions,(ssize_t) image->matte));
2972 case 'C': /* Image compression method. */
2974 q+=FormatLocaleString(q,extent,"%s",CommandOptionToMnemonic(
2975 MagickCompressOptions,(ssize_t) image->compression));
2978 case 'D': /* Image dispose method. */
2980 q+=FormatLocaleString(q,extent,"%s",CommandOptionToMnemonic(
2981 MagickDisposeOptions,(ssize_t) image->dispose));
2984 case 'G': /* Image size as geometry = "%wx%h" */
2986 q+=FormatLocaleString(q,extent,"%.20gx%.20g",(double)
2987 image->magick_columns,(double) image->magick_rows);
2990 case 'H': /* layer canvas height */
2992 q+=FormatLocaleString(q,extent,"%.20g",(double) image->page.height);
2995 case 'O': /* layer canvas offset with sign = "+%X+%Y" */
2997 q+=FormatLocaleString(q,extent,"%+ld%+ld",(long) image->page.x,(long)
3001 case 'P': /* layer canvas page size = "%Wx%H" */
3003 q+=FormatLocaleString(q,extent,"%.20gx%.20g",(double) image->page.width,
3004 (double) image->page.height);
3007 case 'Q': /* image compression quality */
3009 q+=FormatLocaleString(q,extent,"%.20g",(double) image->quality);
3012 case 'S': /* Image scenes */
3014 if (image_info->number_scenes == 0)
3015 q+=CopyMagickString(q,"2147483647",extent);
3017 q+=FormatLocaleString(q,extent,"%.20g",(double) (image_info->scene+
3018 image_info->number_scenes));
3021 case 'T': /* image time delay for animations */
3023 q+=FormatLocaleString(q,extent,"%.20g",(double) image->delay);
3026 case 'W': /* layer canvas width */
3028 q+=FormatLocaleString(q,extent,"%.20g",(double) image->page.width);
3031 case 'X': /* layer canvas X offset */
3033 q+=FormatLocaleString(q,extent,"%+.20g",(double) image->page.x);
3036 case 'Y': /* layer canvas Y offset */
3038 q+=FormatLocaleString(q,extent,"%+.20g",(double) image->page.y);
3041 case 'Z': /* Unique filename. */
3043 (void) CopyMagickString(filename,image_info->zero,extent);
3044 q+=CopyMagickString(q,filename,extent);
3047 case '@': /* Image bounding box. */
3052 page=GetImageBoundingBox(image,exception);
3053 q+=FormatLocaleString(q,MaxTextExtent,"%.20gx%.20g%+.20g%+.20g",
3054 (double) page.width,(double) page.height,(double) page.x,(double)
3058 case '#': /* Image signature */
3060 (void) SignatureImage(image,exception);
3061 value=GetImageProperty(image,"signature",exception);
3062 if (value == (const char *) NULL)
3064 q+=CopyMagickString(q,value,extent);
3067 case '%': /* percent escaped */
3072 default: /* percent not expanded */
3081 if (text != (const char *) embed_text)
3082 text=DestroyString(text);
3083 (void) SubstituteString(&interpret_text,"<","<");
3084 (void) SubstituteString(&interpret_text,">",">");
3085 return(interpret_text);
3089 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3093 % R e m o v e I m a g e P r o p e r t y %
3097 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3099 % RemoveImageProperty() removes a property from the image and returns its
3102 % The format of the RemoveImageProperty method is:
3104 % char *RemoveImageProperty(Image *image,const char *property)
3106 % A description of each parameter follows:
3108 % o image: the image.
3110 % o property: the image property.
3113 MagickExport char *RemoveImageProperty(Image *image,
3114 const char *property)
3119 assert(image != (Image *) NULL);
3120 assert(image->signature == MagickSignature);
3121 if (image->debug != MagickFalse)
3122 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
3124 if (image->properties == (void *) NULL)
3125 return((char *) NULL);
3126 value=(char *) RemoveNodeFromSplayTree((SplayTreeInfo *) image->properties,
3132 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3136 % 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 %
3140 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3142 % ResetImagePropertyIterator() resets the image properties iterator. Use it
3143 % in conjunction with GetNextImageProperty() to iterate over all the values
3144 % associated with an image property.
3146 % The format of the ResetImagePropertyIterator method is:
3148 % ResetImagePropertyIterator(Image *image)
3150 % A description of each parameter follows:
3152 % o image: the image.
3155 MagickExport void ResetImagePropertyIterator(const Image *image)
3157 assert(image != (Image *) NULL);
3158 assert(image->signature == MagickSignature);
3159 if (image->debug != MagickFalse)
3160 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
3162 if (image->properties == (void *) NULL)
3164 ResetSplayTreeIterator((SplayTreeInfo *) image->properties);
3168 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3172 % S e t I m a g e P r o p e r t y %
3176 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3178 % SetImageProperty() associates an value with an image property.
3180 % The format of the SetImageProperty method is:
3182 % MagickBooleanType SetImageProperty(Image *image,const char *property,
3183 % const char *value,ExceptionInfo *exception)
3185 % A description of each parameter follows:
3187 % o image: the image.
3189 % o property: the image property.
3191 % o values: the image property values.
3193 % o exception: return any errors or warnings in this structure.
3196 MagickExport MagickBooleanType SetImageProperty(Image *image,
3197 const char *property,const char *value,ExceptionInfo *exception)
3205 assert(image != (Image *) NULL);
3206 assert(image->signature == MagickSignature);
3207 if (image->debug != MagickFalse)
3208 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
3210 if (image->properties == (void *) NULL)
3211 image->properties=NewSplayTree(CompareSplayTreeString,
3212 RelinquishMagickMemory,RelinquishMagickMemory);
3213 if ((value == (const char *) NULL) || (*value == '\0'))
3214 return(DeleteImageProperty(image,property));
3221 if (LocaleCompare(property,"background") == 0)
3223 (void) QueryColorCompliance(value,AllCompliance,
3224 &image->background_color,exception);
3227 status=AddValueToSplayTree((SplayTreeInfo *) image->properties,
3228 ConstantString(property),ConstantString(value));
3234 if (LocaleCompare(property,"colorspace") == 0)
3239 colorspace=ParseCommandOption(MagickColorspaceOptions,MagickFalse,
3243 (void) SetImageColorspace(image,(ColorspaceType) colorspace,
3247 if (LocaleCompare(property,"compose") == 0)
3252 compose=ParseCommandOption(MagickComposeOptions,MagickFalse,value);
3255 image->compose=(CompositeOperator) compose;
3258 if (LocaleCompare(property,"compress") == 0)
3263 compression=ParseCommandOption(MagickCompressOptions,MagickFalse,
3265 if (compression < 0)
3267 image->compression=(CompressionType) compression;
3270 status=AddValueToSplayTree((SplayTreeInfo *) image->properties,
3271 ConstantString(property),ConstantString(value));
3277 if (LocaleCompare(property,"delay") == 0)
3282 flags=ParseGeometry(value,&geometry_info);
3283 if ((flags & GreaterValue) != 0)
3285 if (image->delay > (size_t) floor(geometry_info.rho+0.5))
3286 image->delay=(size_t) floor(geometry_info.rho+0.5);
3289 if ((flags & LessValue) != 0)
3291 if (image->delay < (size_t) floor(geometry_info.rho+0.5))
3292 image->ticks_per_second=(ssize_t)
3293 floor(geometry_info.sigma+0.5);
3296 image->delay=(size_t) floor(geometry_info.rho+0.5);
3297 if ((flags & SigmaValue) != 0)
3298 image->ticks_per_second=(ssize_t) floor(geometry_info.sigma+0.5);
3301 if (LocaleCompare(property,"density") == 0)
3306 flags=ParseGeometry(value,&geometry_info);
3307 image->resolution.x=geometry_info.rho;
3308 image->resolution.y=geometry_info.sigma;
3309 if ((flags & SigmaValue) == 0)
3310 image->resolution.y=image->resolution.x;
3312 if (LocaleCompare(property,"depth") == 0)
3314 image->depth=StringToUnsignedLong(value);
3317 if (LocaleCompare(property,"dispose") == 0)
3322 dispose=ParseCommandOption(MagickDisposeOptions,MagickFalse,value);
3325 image->dispose=(DisposeType) dispose;
3328 status=AddValueToSplayTree((SplayTreeInfo *) image->properties,
3329 ConstantString(property),ConstantString(value));
3335 if (LocaleCompare(property,"gravity") == 0)
3340 gravity=ParseCommandOption(MagickGravityOptions,MagickFalse,value);
3343 image->gravity=(GravityType) gravity;
3346 status=AddValueToSplayTree((SplayTreeInfo *) image->properties,
3347 ConstantString(property),ConstantString(value));
3353 if (LocaleCompare(property,"intent") == 0)
3358 rendering_intent=ParseCommandOption(MagickIntentOptions,MagickFalse,
3360 if (rendering_intent < 0)
3362 image->rendering_intent=(RenderingIntent) rendering_intent;
3365 if (LocaleCompare(property,"interpolate") == 0)
3370 interpolate=ParseCommandOption(MagickInterpolateOptions,MagickFalse,
3372 if (interpolate < 0)
3374 image->interpolate=(PixelInterpolateMethod) interpolate;
3377 status=AddValueToSplayTree((SplayTreeInfo *) image->properties,
3378 ConstantString(property),ConstantString(value));
3384 if (LocaleCompare(property,"loop") == 0)
3386 image->iterations=StringToUnsignedLong(value);
3389 status=AddValueToSplayTree((SplayTreeInfo *) image->properties,
3390 ConstantString(property),ConstantString(value));
3396 if (LocaleCompare(property,"page") == 0)
3401 geometry=GetPageGeometry(value);
3402 flags=ParseAbsoluteGeometry(geometry,&image->page);
3403 geometry=DestroyString(geometry);
3406 if (LocaleCompare(property,"profile") == 0)
3414 image_info=AcquireImageInfo();
3415 (void) CopyMagickString(image_info->filename,value,MaxTextExtent);
3416 (void) SetImageInfo(image_info,1,exception);
3417 profile=FileToStringInfo(image_info->filename,~0UL,exception);
3418 if (profile != (StringInfo *) NULL)
3419 status=SetImageProfile(image,image_info->magick,profile,exception);
3420 image_info=DestroyImageInfo(image_info);
3423 status=AddValueToSplayTree((SplayTreeInfo *) image->properties,
3424 ConstantString(property),ConstantString(value));
3430 if (LocaleCompare(property,"rendering-intent") == 0)
3435 rendering_intent=ParseCommandOption(MagickIntentOptions,MagickFalse,
3437 if (rendering_intent < 0)
3439 image->rendering_intent=(RenderingIntent) rendering_intent;
3442 status=AddValueToSplayTree((SplayTreeInfo *) image->properties,
3443 ConstantString(property),ConstantString(value));
3449 if (LocaleCompare(property,"tile-offset") == 0)
3454 geometry=GetPageGeometry(value);
3455 flags=ParseAbsoluteGeometry(geometry,&image->tile_offset);
3456 geometry=DestroyString(geometry);
3459 status=AddValueToSplayTree((SplayTreeInfo *) image->properties,
3460 ConstantString(property),ConstantString(value));
3466 if (LocaleCompare(property,"units") == 0)
3471 units=ParseCommandOption(MagickResolutionOptions,MagickFalse,value);
3474 image->units=(ResolutionType) units;
3477 status=AddValueToSplayTree((SplayTreeInfo *) image->properties,
3478 ConstantString(property),ConstantString(value));
3483 status=AddValueToSplayTree((SplayTreeInfo *) image->properties,
3484 ConstantString(property),ConstantString(value));