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 < components)
1310 break; /* prevent overflow */
1311 if (number_bytes <= 4)
1319 The directory entry contains an offset.
1321 offset=(ssize_t) ((int) ReadPropertyLong(endian,q+8));
1322 if ((ssize_t) (offset+number_bytes) < offset)
1323 continue; /* prevent overflow */
1324 if ((size_t) (offset+number_bytes) > length)
1326 p=(unsigned char *) (exif+offset);
1328 if ((all != 0) || (tag == (size_t) tag_value))
1331 buffer[MaxTextExtent],
1334 value=(char *) NULL;
1339 case EXIF_FMT_UNDEFINED:
1341 EXIFMultipleValues(1,"%.20g",(double) (*(unsigned char *) p1));
1344 case EXIF_FMT_SBYTE:
1346 EXIFMultipleValues(1,"%.20g",(double) (*(signed char *) p1));
1349 case EXIF_FMT_SSHORT:
1351 EXIFMultipleValues(2,"%hd",ReadPropertyShort(endian,p1));
1354 case EXIF_FMT_USHORT:
1356 EXIFMultipleValues(2,"%hu",ReadPropertyShort(endian,p1));
1359 case EXIF_FMT_ULONG:
1361 EXIFMultipleValues(4,"%.20g",(double)
1362 ((int) ReadPropertyLong(endian,p1)));
1365 case EXIF_FMT_SLONG:
1367 EXIFMultipleValues(4,"%.20g",(double)
1368 ((int) ReadPropertyLong(endian,p1)));
1371 case EXIF_FMT_URATIONAL:
1373 EXIFMultipleFractions(8,"%.20g/%.20g",(double)
1374 ((int) ReadPropertyLong(endian,p1)),(double)
1375 ((int) ReadPropertyLong(endian,p1+4)));
1378 case EXIF_FMT_SRATIONAL:
1380 EXIFMultipleFractions(8,"%.20g/%.20g",(double)
1381 ((int) ReadPropertyLong(endian,p1)),(double)
1382 ((int) ReadPropertyLong(endian,p1+4)));
1385 case EXIF_FMT_SINGLE:
1387 EXIFMultipleValues(4,"%f",(double) *(float *) p1);
1390 case EXIF_FMT_DOUBLE:
1392 EXIFMultipleValues(8,"%f",*(double *) p1);
1396 case EXIF_FMT_STRING:
1398 value=(char *) NULL;
1399 if (~(1UL*number_bytes) >= 1)
1400 value=(char *) AcquireQuantumMemory((size_t) number_bytes+1UL,
1402 if (value != (char *) NULL)
1407 for (i=0; i < (ssize_t) number_bytes; i++)
1410 if ((isprint((int) p[i]) != 0) || (p[i] == '\0'))
1411 value[i]=(char) p[i];
1418 if (value != (char *) NULL)
1426 (void) CopyMagickString(key,property,MaxTextExtent);
1437 description="unknown";
1440 if (EXIFTag[i].tag == 0)
1442 if ((ssize_t) EXIFTag[i].tag == tag_value)
1444 description=EXIFTag[i].description;
1448 (void) FormatLocaleString(key,MaxTextExtent,"%s",description);
1453 if (tag_value < 0x10000)
1454 (void) FormatLocaleString(key,MaxTextExtent,"#%04lx",
1455 (unsigned long) tag_value);
1457 if (tag_value < 0x20000)
1458 (void) FormatLocaleString(key,MaxTextExtent,"@%04lx",
1459 (unsigned long) (tag_value & 0xffff));
1461 (void) FormatLocaleString(key,MaxTextExtent,"unknown");
1465 p=(const char *) NULL;
1466 if (image->properties != (void *) NULL)
1467 p=(const char *) GetValueFromSplayTree((SplayTreeInfo *)
1468 image->properties,key);
1469 if (p == (const char *) NULL)
1470 (void) SetImageProperty((Image *) image,key,value,exception);
1471 value=DestroyString(value);
1475 if ((tag_value == TAG_EXIF_OFFSET) ||
1476 (tag_value == TAG_INTEROP_OFFSET) || (tag_value == TAG_GPS_OFFSET))
1481 offset=(ssize_t) ((int) ReadPropertyLong(endian,p));
1482 if (((size_t) offset < length) && (level < (MaxDirectoryStack-2)))
1487 tag_offset1=(ssize_t) ((tag_value == TAG_GPS_OFFSET) ? 0x10000 :
1489 directory_stack[level].directory=directory;
1491 directory_stack[level].entry=entry;
1492 directory_stack[level].offset=tag_offset;
1494 directory_stack[level].directory=exif+offset;
1495 directory_stack[level].offset=tag_offset1;
1496 directory_stack[level].entry=0;
1498 if ((directory+2+(12*number_entries)) > (exif+length))
1500 offset=(ssize_t) ((int) ReadPropertyLong(endian,directory+2+(12*
1502 if ((offset != 0) && ((size_t) offset < length) &&
1503 (level < (MaxDirectoryStack-2)))
1505 directory_stack[level].directory=exif+offset;
1506 directory_stack[level].entry=0;
1507 directory_stack[level].offset=tag_offset1;
1514 } while (level > 0);
1515 exif_resources=DestroySplayTree(exif_resources);
1519 static MagickBooleanType GetXMPProperty(const Image *image,const char *property)
1543 profile=GetImageProfile(image,"xmp");
1544 if (profile == (StringInfo *) NULL)
1545 return(MagickFalse);
1546 if ((property == (const char *) NULL) || (*property == '\0'))
1547 return(MagickFalse);
1548 xmp_profile=StringInfoToString(profile);
1549 if (xmp_profile == (char *) NULL)
1550 return(MagickFalse);
1551 for (p=xmp_profile; *p != '\0'; p++)
1552 if ((*p == '<') && (*(p+1) == 'x'))
1554 exception=AcquireExceptionInfo();
1555 xmp=NewXMLTree((char *) p,exception);
1556 xmp_profile=DestroyString(xmp_profile);
1557 exception=DestroyExceptionInfo(exception);
1558 if (xmp == (XMLTreeInfo *) NULL)
1559 return(MagickFalse);
1561 rdf=GetXMLTreeChild(xmp,"rdf:RDF");
1562 if (rdf != (XMLTreeInfo *) NULL)
1564 if (image->properties == (void *) NULL)
1565 ((Image *) image)->properties=NewSplayTree(CompareSplayTreeString,
1566 RelinquishMagickMemory,RelinquishMagickMemory);
1567 description=GetXMLTreeChild(rdf,"rdf:Description");
1568 while (description != (XMLTreeInfo *) NULL)
1570 node=GetXMLTreeChild(description,(const char *) NULL);
1571 while (node != (XMLTreeInfo *) NULL)
1573 child=GetXMLTreeChild(node,(const char *) NULL);
1574 if (child == (XMLTreeInfo *) NULL)
1575 (void) AddValueToSplayTree((SplayTreeInfo *) image->properties,
1576 ConstantString(GetXMLTreeTag(node)),
1577 ConstantString(GetXMLTreeContent(node)));
1578 while (child != (XMLTreeInfo *) NULL)
1580 if (LocaleCompare(GetXMLTreeTag(child),"rdf:Seq") != 0)
1581 (void) AddValueToSplayTree((SplayTreeInfo *) image->properties,
1582 ConstantString(GetXMLTreeTag(child)),
1583 ConstantString(GetXMLTreeContent(child)));
1584 child=GetXMLTreeSibling(child);
1586 node=GetXMLTreeSibling(node);
1588 description=GetNextXMLTreeTag(description);
1591 xmp=DestroyXMLTree(xmp);
1595 static char *TracePSClippath(const unsigned char *blob,size_t length,
1596 const size_t magick_unused(columns),const size_t magick_unused(rows))
1619 path=AcquireString((char *) NULL);
1620 if (path == (char *) NULL)
1621 return((char *) NULL);
1622 message=AcquireString((char *) NULL);
1623 (void) FormatLocaleString(message,MaxTextExtent,"/ClipImage\n");
1624 (void) ConcatenateString(&path,message);
1625 (void) FormatLocaleString(message,MaxTextExtent,"{\n");
1626 (void) ConcatenateString(&path,message);
1627 (void) FormatLocaleString(message,MaxTextExtent," /c {curveto} bind def\n");
1628 (void) ConcatenateString(&path,message);
1629 (void) FormatLocaleString(message,MaxTextExtent," /l {lineto} bind def\n");
1630 (void) ConcatenateString(&path,message);
1631 (void) FormatLocaleString(message,MaxTextExtent," /m {moveto} bind def\n");
1632 (void) ConcatenateString(&path,message);
1633 (void) FormatLocaleString(message,MaxTextExtent,
1634 " /v {currentpoint 6 2 roll curveto} bind def\n");
1635 (void) ConcatenateString(&path,message);
1636 (void) FormatLocaleString(message,MaxTextExtent,
1637 " /y {2 copy curveto} bind def\n");
1638 (void) ConcatenateString(&path,message);
1639 (void) FormatLocaleString(message,MaxTextExtent,
1640 " /z {closepath} bind def\n");
1641 (void) ConcatenateString(&path,message);
1642 (void) FormatLocaleString(message,MaxTextExtent," newpath\n");
1643 (void) ConcatenateString(&path,message);
1645 The clipping path format is defined in "Adobe Photoshop File
1646 Formats Specification" version 6.0 downloadable from adobe.com.
1648 (void) ResetMagickMemory(point,0,sizeof(point));
1649 (void) ResetMagickMemory(first,0,sizeof(first));
1650 (void) ResetMagickMemory(last,0,sizeof(last));
1652 in_subpath=MagickFalse;
1655 selector=(ssize_t) ((int) ReadPropertyMSBShort(&blob,&length));
1661 if (knot_count != 0)
1664 length-=MagickMin(24,(ssize_t) length);
1668 Expected subpath length record.
1670 knot_count=(ssize_t) ((int) ReadPropertyMSBShort(&blob,&length));
1672 length-=MagickMin(22,(ssize_t) length);
1680 if (knot_count == 0)
1683 Unexpected subpath knot
1686 length-=MagickMin(24,(ssize_t) length);
1692 for (i=0; i < 3; i++)
1698 yy=(size_t) ((int) ReadPropertyMSBLong(&blob,&length));
1699 xx=(size_t) ((int) ReadPropertyMSBLong(&blob,&length));
1701 if (xx > 2147483647)
1702 x=(ssize_t) xx-4294967295U-1;
1704 if (yy > 2147483647)
1705 y=(ssize_t) yy-4294967295U-1;
1706 point[i].x=(double) x/4096/4096;
1707 point[i].y=1.0-(double) y/4096/4096;
1709 if (in_subpath == MagickFalse)
1711 (void) FormatLocaleString(message,MaxTextExtent," %g %g m\n",
1712 point[1].x,point[1].y);
1713 for (i=0; i < 3; i++)
1722 Handle special cases when Bezier curves are used to describe
1723 corners and straight lines.
1725 if ((last[1].x == last[2].x) && (last[1].y == last[2].y) &&
1726 (point[0].x == point[1].x) && (point[0].y == point[1].y))
1727 (void) FormatLocaleString(message,MaxTextExtent,
1728 " %g %g l\n",point[1].x,point[1].y);
1730 if ((last[1].x == last[2].x) && (last[1].y == last[2].y))
1731 (void) FormatLocaleString(message,MaxTextExtent,
1732 " %g %g %g %g v\n",point[0].x,point[0].y,
1733 point[1].x,point[1].y);
1735 if ((point[0].x == point[1].x) && (point[0].y == point[1].y))
1736 (void) FormatLocaleString(message,MaxTextExtent,
1737 " %g %g %g %g y\n",last[2].x,last[2].y,
1738 point[1].x,point[1].y);
1740 (void) FormatLocaleString(message,MaxTextExtent,
1741 " %g %g %g %g %g %g c\n",last[2].x,
1742 last[2].y,point[0].x,point[0].y,point[1].x,point[1].y);
1743 for (i=0; i < 3; i++)
1746 (void) ConcatenateString(&path,message);
1747 in_subpath=MagickTrue;
1750 Close the subpath if there are no more knots.
1752 if (knot_count == 0)
1755 Same special handling as above except we compare to the
1756 first point in the path and close the path.
1758 if ((last[1].x == last[2].x) && (last[1].y == last[2].y) &&
1759 (first[0].x == first[1].x) && (first[0].y == first[1].y))
1760 (void) FormatLocaleString(message,MaxTextExtent,
1761 " %g %g l z\n",first[1].x,first[1].y);
1763 if ((last[1].x == last[2].x) && (last[1].y == last[2].y))
1764 (void) FormatLocaleString(message,MaxTextExtent,
1765 " %g %g %g %g v z\n",first[0].x,first[0].y,
1766 first[1].x,first[1].y);
1768 if ((first[0].x == first[1].x) && (first[0].y == first[1].y))
1769 (void) FormatLocaleString(message,MaxTextExtent,
1770 " %g %g %g %g y z\n",last[2].x,last[2].y,
1771 first[1].x,first[1].y);
1773 (void) FormatLocaleString(message,MaxTextExtent,
1774 " %g %g %g %g %g %g c z\n",last[2].x,
1775 last[2].y,first[0].x,first[0].y,first[1].x,first[1].y);
1776 (void) ConcatenateString(&path,message);
1777 in_subpath=MagickFalse;
1787 length-=MagickMin(24,(ssize_t) length);
1793 Returns an empty PS path if the path has no knots.
1795 (void) FormatLocaleString(message,MaxTextExtent," eoclip\n");
1796 (void) ConcatenateString(&path,message);
1797 (void) FormatLocaleString(message,MaxTextExtent,"} bind def");
1798 (void) ConcatenateString(&path,message);
1799 message=DestroyString(message);
1803 static char *TraceSVGClippath(const unsigned char *blob,size_t length,
1804 const size_t columns,const size_t rows)
1827 path=AcquireString((char *) NULL);
1828 if (path == (char *) NULL)
1829 return((char *) NULL);
1830 message=AcquireString((char *) NULL);
1831 (void) FormatLocaleString(message,MaxTextExtent,
1832 "<?xml version=\"1.0\" encoding=\"iso-8859-1\"?>\n");
1833 (void) ConcatenateString(&path,message);
1834 (void) FormatLocaleString(message,MaxTextExtent,
1835 "<svg width=\"%.20g\" height=\"%.20g\">\n",(double) columns,(double) rows);
1836 (void) ConcatenateString(&path,message);
1837 (void) FormatLocaleString(message,MaxTextExtent,"<g>\n");
1838 (void) ConcatenateString(&path,message);
1839 (void) FormatLocaleString(message,MaxTextExtent,
1840 "<path style=\"fill:#00000000;stroke:#00000000;");
1841 (void) ConcatenateString(&path,message);
1842 (void) FormatLocaleString(message,MaxTextExtent,
1843 "stroke-width:0;stroke-antialiasing:false\" d=\"\n");
1844 (void) ConcatenateString(&path,message);
1845 (void) ResetMagickMemory(point,0,sizeof(point));
1846 (void) ResetMagickMemory(first,0,sizeof(first));
1847 (void) ResetMagickMemory(last,0,sizeof(last));
1849 in_subpath=MagickFalse;
1852 selector=(ssize_t) ((int) ReadPropertyMSBShort(&blob,&length));
1858 if (knot_count != 0)
1861 length-=MagickMin(24,(ssize_t) length);
1865 Expected subpath length record.
1867 knot_count=(ssize_t) ((int) ReadPropertyMSBShort(&blob,&length));
1869 length-=MagickMin(22,(ssize_t) length);
1877 if (knot_count == 0)
1880 Unexpected subpath knot.
1883 length-=MagickMin(24,(ssize_t) length);
1889 for (i=0; i < 3; i++)
1895 yy=(size_t) ((int) ReadPropertyMSBLong(&blob,&length));
1896 xx=(size_t) ((int) ReadPropertyMSBLong(&blob,&length));
1898 if (xx > 2147483647)
1899 x=(ssize_t) xx-4294967295U-1;
1901 if (yy > 2147483647)
1902 y=(ssize_t) yy-4294967295U-1;
1903 point[i].x=(double) x*columns/4096/4096;
1904 point[i].y=(double) y*rows/4096/4096;
1906 if (in_subpath == MagickFalse)
1908 (void) FormatLocaleString(message,MaxTextExtent,"M %g,%g\n",
1909 point[1].x,point[1].y);
1910 for (i=0; i < 3; i++)
1918 if ((last[1].x == last[2].x) && (last[1].y == last[2].y) &&
1919 (point[0].x == point[1].x) && (point[0].y == point[1].y))
1920 (void) FormatLocaleString(message,MaxTextExtent,"L %g,%g\n",
1921 point[1].x,point[1].y);
1923 (void) FormatLocaleString(message,MaxTextExtent,
1924 "C %g,%g %g,%g %g,%g\n",last[2].x,last[2].y,
1925 point[0].x,point[0].y,point[1].x,point[1].y);
1926 for (i=0; i < 3; i++)
1929 (void) ConcatenateString(&path,message);
1930 in_subpath=MagickTrue;
1933 Close the subpath if there are no more knots.
1935 if (knot_count == 0)
1937 if ((last[1].x == last[2].x) && (last[1].y == last[2].y) &&
1938 (first[0].x == first[1].x) && (first[0].y == first[1].y))
1939 (void) FormatLocaleString(message,MaxTextExtent,
1940 "L %g,%g Z\n",first[1].x,first[1].y);
1943 (void) FormatLocaleString(message,MaxTextExtent,
1944 "C %g,%g %g,%g %g,%g Z\n",last[2].x,
1945 last[2].y,first[0].x,first[0].y,first[1].x,first[1].y);
1946 (void) ConcatenateString(&path,message);
1948 in_subpath=MagickFalse;
1958 length-=MagickMin(24,(ssize_t) length);
1964 Return an empty SVG image if the path does not have knots.
1966 (void) FormatLocaleString(message,MaxTextExtent,"\"/>\n");
1967 (void) ConcatenateString(&path,message);
1968 (void) FormatLocaleString(message,MaxTextExtent,"</g>\n");
1969 (void) ConcatenateString(&path,message);
1970 (void) FormatLocaleString(message,MaxTextExtent,"</svg>\n");
1971 (void) ConcatenateString(&path,message);
1972 message=DestroyString(message);
1976 MagickExport const char *GetImageProperty(const Image *image,
1977 const char *property,ExceptionInfo *exception)
1991 assert(image != (Image *) NULL);
1992 assert(image->signature == MagickSignature);
1993 if (image->debug != MagickFalse)
1994 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1995 p=(const char *) NULL;
1996 if (image->properties != (void *) NULL)
1998 if (property == (const char *) NULL)
2000 ResetSplayTreeIterator((SplayTreeInfo *) image->properties);
2001 p=(const char *) GetNextValueInSplayTree((SplayTreeInfo *)
2005 if (LocaleNCompare("fx:",property,3) != 0)
2007 p=(const char *) GetValueFromSplayTree((SplayTreeInfo *)
2008 image->properties,property);
2009 if (p != (const char *) NULL)
2013 if ((property == (const char *) NULL) ||
2014 (strchr(property,':') == (char *) NULL))
2020 if (LocaleNCompare("8bim:",property,5) == 0)
2022 if ((Get8BIMProperty(image,property,exception) != MagickFalse) &&
2023 (image->properties != (void *) NULL))
2025 p=(const char *) GetValueFromSplayTree((SplayTreeInfo *)
2026 image->properties,property);
2035 if (LocaleNCompare("exif:",property,5) == 0)
2037 if ((GetEXIFProperty(image,property,exception) != MagickFalse) &&
2038 (image->properties != (void *) NULL))
2040 p=(const char *) GetValueFromSplayTree((SplayTreeInfo *)
2041 image->properties,property);
2050 if (LocaleNCompare("fx:",property,3) == 0)
2052 fx_info=AcquireFxInfo(image,property+3,exception);
2053 status=FxEvaluateChannelExpression(fx_info,IntensityPixelChannel,0,0,
2055 fx_info=DestroyFxInfo(fx_info);
2056 if (status != MagickFalse)
2059 value[MaxTextExtent];
2061 (void) FormatLocaleString(value,MaxTextExtent,"%.*g",
2062 GetMagickPrecision(),(double) alpha);
2063 (void) SetImageProperty((Image *) image,property,value,exception);
2065 if (image->properties != (void *) NULL)
2067 p=(const char *) GetValueFromSplayTree((SplayTreeInfo *)
2068 image->properties,property);
2077 if (LocaleNCompare("iptc:",property,5) == 0)
2079 if ((GetIPTCProperty(image,property,exception) != MagickFalse) &&
2080 (image->properties != (void *) NULL))
2082 p=(const char *) GetValueFromSplayTree((SplayTreeInfo *)
2083 image->properties,property);
2092 if (LocaleNCompare("pixel:",property,6) == 0)
2097 GetPixelInfo(image,&pixel);
2098 fx_info=AcquireFxInfo(image,property+6,exception);
2099 status=FxEvaluateChannelExpression(fx_info,RedPixelChannel,0,0,
2101 pixel.red=(MagickRealType) QuantumRange*alpha;
2102 status|=FxEvaluateChannelExpression(fx_info,GreenPixelChannel,0,0,
2104 pixel.green=(MagickRealType) QuantumRange*alpha;
2105 status|=FxEvaluateChannelExpression(fx_info,BluePixelChannel,0,0,
2107 pixel.blue=(MagickRealType) QuantumRange*alpha;
2108 if (image->colorspace == CMYKColorspace)
2110 status|=FxEvaluateChannelExpression(fx_info,BlackPixelChannel,0,0,
2112 pixel.black=(MagickRealType) QuantumRange*alpha;
2114 status|=FxEvaluateChannelExpression(fx_info,AlphaPixelChannel,0,0,
2116 pixel.alpha=(MagickRealType) QuantumRange*(1.0-alpha);
2117 fx_info=DestroyFxInfo(fx_info);
2118 if (status != MagickFalse)
2121 name[MaxTextExtent];
2123 (void) QueryColorname(image,&pixel,SVGCompliance,name,
2125 (void) SetImageProperty((Image *) image,property,name,exception);
2126 return(GetImageProperty(image,property,exception));
2134 if (LocaleNCompare("xmp:",property,4) == 0)
2136 if ((GetXMPProperty(image,property) != MagickFalse) &&
2137 (image->properties != (void *) NULL))
2139 p=(const char *) GetValueFromSplayTree((SplayTreeInfo *)
2140 image->properties,property);
2153 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2157 + G e t M a g i c k P r o p e r t y %
2161 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2163 % GetMagickProperty() gets a value associated with an image property.
2165 % The format of the GetMagickProperty method is:
2167 % const char *GetMagickProperty(const ImageInfo *image_info,Image *image,
2168 % const char *key,ExceptionInfo *exception)
2170 % A description of each parameter follows:
2172 % o image_info: the image info.
2174 % o image: the image.
2178 % o exception: return any errors or warnings in this structure.
2181 MagickExport const char *GetMagickProperty(const ImageInfo *image_info,
2182 Image *image,const char *property,ExceptionInfo *exception)
2185 value[MaxTextExtent],
2186 filename[MaxTextExtent];
2193 if (LocaleNCompare("base",property,4) == 0)
2195 GetPathComponent(image->magick_filename,BasePath,filename);
2196 (void) CopyMagickString(value,filename,MaxTextExtent);
2203 if (LocaleNCompare("channels",property,8) == 0)
2208 (void) FormatLocaleString(value,MaxTextExtent,"%s",
2209 CommandOptionToMnemonic(MagickColorspaceOptions,(ssize_t)
2210 image->colorspace));
2212 if (image->matte != MagickFalse)
2213 (void) ConcatenateMagickString(value,"a",MaxTextExtent);
2216 if (LocaleNCompare("colorspace",property,10) == 0)
2222 Image storage class and colorspace.
2224 colorspace=image->colorspace;
2225 if (IsImageGray(image,exception) != MagickFalse)
2226 colorspace=GRAYColorspace;
2227 (void) FormatLocaleString(value,MaxTextExtent,"%s",
2228 CommandOptionToMnemonic(MagickColorspaceOptions,(ssize_t)
2232 if (LocaleNCompare("copyright",property,9) == 0)
2234 (void) CopyMagickString(value,GetMagickCopyright(),MaxTextExtent);
2241 if (LocaleNCompare("depth",property,5) == 0)
2243 (void) FormatLocaleString(value,MaxTextExtent,"%.20g",(double)
2247 if (LocaleNCompare("directory",property,9) == 0)
2249 GetPathComponent(image->magick_filename,HeadPath,filename);
2250 (void) CopyMagickString(value,filename,MaxTextExtent);
2257 if (LocaleNCompare("extension",property,9) == 0)
2259 GetPathComponent(image->magick_filename,ExtensionPath,filename);
2260 (void) CopyMagickString(value,filename,MaxTextExtent);
2267 if (LocaleNCompare("group",property,5) == 0)
2269 (void) FormatLocaleString(value,MaxTextExtent,"0x%lx",
2270 (unsigned long) image_info->group);
2277 if (LocaleNCompare("height",property,6) == 0)
2279 (void) FormatLocaleString(value,MaxTextExtent,"%.20g",
2280 image->magick_rows != 0 ? (double) image->magick_rows : 256.0);
2287 if (LocaleNCompare("input",property,5) == 0)
2289 (void) CopyMagickString(value,image->filename,MaxTextExtent);
2296 if (LocaleNCompare("kurtosis",property,8) == 0)
2302 (void) GetImageKurtosis(image,&kurtosis,&skewness,exception);
2303 (void) FormatLocaleString(value,MaxTextExtent,"%.*g",
2304 GetMagickPrecision(),kurtosis);
2311 if (LocaleNCompare("magick",property,6) == 0)
2313 (void) CopyMagickString(value,image->magick,MaxTextExtent);
2316 if (LocaleNCompare("max",property,3) == 0)
2322 (void) GetImageRange(image,&minimum,&maximum,exception);
2323 (void) FormatLocaleString(value,MaxTextExtent,"%.*g",
2324 GetMagickPrecision(),maximum);
2327 if (LocaleNCompare("mean",property,4) == 0)
2333 (void) GetImageMean(image,&mean,&standard_deviation,
2335 (void) FormatLocaleString(value,MaxTextExtent,"%.*g",
2336 GetMagickPrecision(),mean);
2339 if (LocaleNCompare("min",property,3) == 0)
2345 (void) GetImageRange(image,&minimum,&maximum,exception);
2346 (void) FormatLocaleString(value,MaxTextExtent,"%.*g",
2347 GetMagickPrecision(),minimum);
2354 if (LocaleNCompare("name",property,4) == 0)
2356 (void) CopyMagickString(value,filename,MaxTextExtent);
2363 if (LocaleNCompare("opaque",property,6) == 0)
2368 opaque=IsImageOpaque(image,exception);
2369 (void) CopyMagickString(value,opaque == MagickFalse ? "false" :
2370 "true",MaxTextExtent);
2373 if (LocaleNCompare("orientation",property,11) == 0)
2375 (void) FormatLocaleString(value,MaxTextExtent,"%s",
2376 CommandOptionToMnemonic(MagickOrientationOptions,(ssize_t)
2377 image->orientation));
2380 if (LocaleNCompare("output",property,6) == 0)
2382 (void) CopyMagickString(value,image_info->filename,MaxTextExtent);
2389 if (LocaleNCompare("page",property,4) == 0)
2391 (void) FormatLocaleString(value,MaxTextExtent,"%.20g",(double)
2392 GetImageIndexInList(image)+1);
2399 if (LocaleNCompare("resolution.x",property,11) == 0)
2401 (void) FormatLocaleString(value,MaxTextExtent,"%g",
2402 image->resolution.x);
2405 if (LocaleNCompare("resolution.y",property,11) == 0)
2407 (void) FormatLocaleString(value,MaxTextExtent,"%g",
2408 image->resolution.y);
2415 if (LocaleNCompare("size",property,4) == 0)
2418 format[MaxTextExtent];
2420 (void) FormatMagickSize(GetBlobSize(image),MagickFalse,format);
2421 (void) FormatLocaleString(value,MaxTextExtent,"%sB",format);
2424 if (LocaleNCompare("scenes",property,6) == 0)
2426 (void) FormatLocaleString(value,MaxTextExtent,"%.20g",(double)
2427 GetImageListLength(image));
2430 if (LocaleNCompare("scene",property,5) == 0)
2432 if (image_info->number_scenes != 0)
2433 (void) FormatLocaleString(value,MaxTextExtent,"%.20g",(double)
2436 (void) FormatLocaleString(value,MaxTextExtent,"%.20g",(double)
2440 if (LocaleNCompare("skewness",property,8) == 0)
2446 (void) GetImageKurtosis(image,&kurtosis,&skewness,exception);
2447 (void) FormatLocaleString(value,MaxTextExtent,"%.*g",
2448 GetMagickPrecision(),skewness);
2451 if ((LocaleNCompare("standard-deviation",property,18) == 0) ||
2452 (LocaleNCompare("standard_deviation",property,18) == 0))
2458 (void) GetImageMean(image,&mean,&standard_deviation,
2460 (void) FormatLocaleString(value,MaxTextExtent,"%.*g",
2461 GetMagickPrecision(),standard_deviation);
2468 if (LocaleNCompare("unique",property,6) == 0)
2470 (void) CopyMagickString(filename,image_info->unique,MaxTextExtent);
2471 (void) CopyMagickString(value,filename,MaxTextExtent);
2478 if (LocaleNCompare("version",property,7) == 0)
2480 (void) CopyMagickString(value,GetMagickVersion((size_t *) NULL),
2488 if (LocaleNCompare("width",property,5) == 0)
2490 (void) FormatLocaleString(value,MaxTextExtent,"%.20g",(double)
2491 (image->magick_columns != 0 ? image->magick_columns : 256));
2498 if (LocaleNCompare("xresolution",property,11) == 0)
2500 (void) FormatLocaleString(value,MaxTextExtent,"%g",
2501 image->resolution.x);
2508 if (LocaleNCompare("yresolution",property,11) == 0)
2510 (void) FormatLocaleString(value,MaxTextExtent,"%g",
2511 image->resolution.y);
2518 if (LocaleNCompare("zero",property,4) == 0)
2520 (void) CopyMagickString(filename,image_info->zero,MaxTextExtent);
2521 (void) CopyMagickString(value,filename,MaxTextExtent);
2529 if (image->properties == (void *) NULL)
2530 image->properties=NewSplayTree(CompareSplayTreeString,
2531 RelinquishMagickMemory,RelinquishMagickMemory);
2532 (void) AddValueToSplayTree((SplayTreeInfo *) image->properties,
2533 ConstantString(property),ConstantString(value));
2535 return(GetImageProperty(image,property,exception));
2539 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2543 % G e t N e x t I m a g e P r o p e r t y %
2547 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2549 % GetNextImageProperty() gets the next image property value.
2551 % The format of the GetNextImageProperty method is:
2553 % char *GetNextImageProperty(const Image *image)
2555 % A description of each parameter follows:
2557 % o image: the image.
2560 MagickExport char *GetNextImageProperty(const Image *image)
2562 assert(image != (Image *) NULL);
2563 assert(image->signature == MagickSignature);
2564 if (image->debug != MagickFalse)
2565 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
2567 if (image->properties == (void *) NULL)
2568 return((char *) NULL);
2569 return((char *) GetNextKeyInSplayTree((SplayTreeInfo *) image->properties));
2573 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2577 % I n t e r p r e t I m a g e P r o p e r t i e s %
2581 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2583 % InterpretImageProperties() replaces any embedded formatting characters with
2584 % the appropriate image property and returns the interpreted text. Free with
2585 % DestoryString() or RelinquishMagickMemory().
2587 % The format of the InterpretImageProperties method is:
2589 % char *InterpretImageProperties(const ImageInfo *image_info,Image *image,
2590 % const char *embed_text,ExceptionInfo *exception)
2592 % A description of each parameter follows:
2594 % o image_info: the image info.
2596 % o image: the image.
2598 % o embed_text: the address of a character string containing the embedded
2599 % formatting characters.
2601 % o exception: return any errors or warnings in this structure.
2604 MagickExport char *InterpretImageProperties(const ImageInfo *image_info,
2605 Image *image,const char *embed_text,ExceptionInfo *exception)
2608 filename[MaxTextExtent],
2628 assert(image != (Image *) NULL);
2629 assert(image->signature == MagickSignature);
2630 if (image->debug != MagickFalse)
2631 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
2632 if ((embed_text == (const char *) NULL) || (*embed_text == '\0'))
2633 return((char *) NULL);
2634 text=(char *) embed_text;
2635 if ((*text == '@') && ((*(text+1) == '-') ||
2636 (IsPathAccessible(text+1) != MagickFalse)))
2637 return(FileToString(embed_text+1,~0,exception));
2639 Translate any embedded format characters.
2641 interpret_text=AcquireString(text);
2642 extent=MaxTextExtent;
2644 for (q=interpret_text; *p != '\0'; p++)
2647 if ((size_t) (q-interpret_text+MaxTextExtent) >= extent)
2649 extent+=MaxTextExtent;
2650 interpret_text=(char *) ResizeQuantumMemory(interpret_text,extent+
2651 MaxTextExtent+1,sizeof(*interpret_text));
2652 if (interpret_text == (char *) NULL)
2654 q=interpret_text+strlen(interpret_text);
2657 Process formatting characters in text.
2659 if ((*p == '\\') && (*(p+1) == 'r'))
2665 if ((*p == '\\') && (*(p+1) == 'n'))
2683 /* Handle percent escape */
2686 case '[': /* multi-character percent escape %[....] */
2689 pattern[MaxTextExtent];
2698 /* get the string from parenthesis */
2699 if (strchr(p,']') == (char *) NULL)
2703 /* FUTURE: refactor into sub-routine looking for 'break' character */
2704 for (i=0; (i < (MaxTextExtent-1L)) && (*p != '\0'); i++)
2715 /* Try a Special Image Properity - including fx: and pixel: */
2716 value=GetImageProperty(image,pattern,exception);
2717 if (value != (const char *) NULL)
2719 length=strlen(value);
2720 if ((size_t) (q-interpret_text+length+1) >= extent)
2723 interpret_text=(char *) ResizeQuantumMemory(interpret_text,
2724 extent+MaxTextExtent,sizeof(*interpret_text));
2725 if (interpret_text == (char *) NULL)
2727 q=interpret_text+strlen(interpret_text);
2729 (void) CopyMagickString(q,value,extent);
2733 /* Handle properity 'glob' patterns - by iteration */
2734 if (IsGlob(pattern) != MagickFalse)
2736 ResetImagePropertyIterator(image);
2737 key=GetNextImageProperty(image);
2738 while (key != (const char *) NULL)
2740 if (GlobExpression(key,pattern,MagickTrue) != MagickFalse)
2742 value=GetImageProperty(image,key,exception);
2743 if (value != (const char *) NULL)
2745 length=strlen(key)+strlen(value)+2;
2746 if ((size_t) (q-interpret_text+length+1) >= extent)
2749 interpret_text=(char *) ResizeQuantumMemory(
2750 interpret_text,extent+MaxTextExtent,
2751 sizeof(*interpret_text));
2752 if (interpret_text == (char *) NULL)
2754 q=interpret_text+strlen(interpret_text);
2756 q+=FormatLocaleString(q,extent,"%s=%s\n",key,value);
2759 key=GetNextImageProperty(image);
2763 value=GetMagickProperty(image_info,image,pattern,exception);
2764 if (value != (const 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);
2780 if (image_info == (ImageInfo *) NULL)
2782 value=GetImageOption(image_info,pattern);
2783 if (value != (char *) NULL)
2785 length=strlen(value);
2786 if ((size_t) (q-interpret_text+length+1) >= extent)
2789 interpret_text=(char *) ResizeQuantumMemory(interpret_text,
2790 extent+MaxTextExtent,sizeof(*interpret_text));
2791 if (interpret_text == (char *) NULL)
2793 q=interpret_text+strlen(interpret_text);
2795 (void) CopyMagickString(q,value,extent);
2801 case 'b': /* image size read in - in bytes */
2804 format[MaxTextExtent];
2806 (void) FormatLocaleString(format,MaxTextExtent,"%.20g",(double)
2807 ((MagickOffsetType) image->extent));
2808 if (image->extent != (MagickSizeType) ((size_t) image->extent))
2809 (void) FormatMagickSize(image->extent,MagickFalse,format);
2810 q+=ConcatenateMagickString(q,format,extent);
2811 q+=ConcatenateMagickString(q,"B",extent);
2814 case 'c': /* image comment properity */
2816 value=GetImageProperty(image,"comment",exception);
2817 if (value == (const char *) NULL)
2819 length=strlen(value);
2820 if ((size_t) (q-interpret_text+length+1) >= extent)
2823 interpret_text=(char *) ResizeQuantumMemory(interpret_text,extent+
2824 MaxTextExtent,sizeof(*interpret_text));
2825 if (interpret_text == (char *) NULL)
2827 q=interpret_text+strlen(interpret_text);
2829 (void) CopyMagickString(q,value,extent);
2833 case 'd': /* Directory component of filename */
2835 GetPathComponent(image->magick_filename,HeadPath,filename);
2836 q+=CopyMagickString(q,filename,extent);
2839 case 'e': /* Filename extension (suffix) of image file */
2841 GetPathComponent(image->magick_filename,ExtensionPath,filename);
2842 q+=CopyMagickString(q,filename,extent);
2845 case 'f': /* Filename without directory component */
2847 GetPathComponent(image->magick_filename,TailPath,filename);
2848 q+=CopyMagickString(q,filename,extent);
2851 case 'g': /* Image geometry, canvas and offset */
2853 q+=FormatLocaleString(q,extent,"%.20gx%.20g%+.20g%+.20g",(double)
2854 image->page.width,(double) image->page.height,(double) image->page.x,
2855 (double) image->page.y);
2858 case 'h': /* Image height (current) */
2860 q+=FormatLocaleString(q,extent,"%.20g",(double) (image->rows != 0 ?
2861 image->rows : image->magick_rows));
2864 case 'i': /* Input Filename - for delegate use only */
2866 q+=CopyMagickString(q,image->filename,extent);
2869 case 'k': /* Number of unique colors */
2871 q+=FormatLocaleString(q,extent,"%.20g",(double) GetNumberColors(image,
2872 (FILE *) NULL,exception));
2875 case 'l': /* Image label */
2877 value=GetImageProperty(image,"label",exception);
2878 if (value == (const char *) NULL)
2880 length=strlen(value);
2881 if ((size_t) (q-interpret_text+length+1) >= extent)
2884 interpret_text=(char *) ResizeQuantumMemory(interpret_text,extent+
2885 MaxTextExtent,sizeof(*interpret_text));
2886 if (interpret_text == (char *) NULL)
2888 q=interpret_text+strlen(interpret_text);
2890 q+=CopyMagickString(q,value,extent);
2893 case 'm': /* Image format (file magick) */
2895 q+=CopyMagickString(q,image->magick,extent);
2898 case 'n': /* Number of images in the list. */
2900 q+=FormatLocaleString(q,extent,"%.20g",(double)
2901 GetImageListLength(image));
2904 case 'o': /* Output Filename - for delegate use only */
2906 q+=CopyMagickString(q,image_info->filename,extent);
2909 case 'p': /* Image index in current image list */
2911 q+=FormatLocaleString(q,extent,"%.20g",(double)
2912 GetImageIndexInList(image));
2915 case 'q': /* Quantum depth of image in memory */
2917 q+=FormatLocaleString(q,extent,"%.20g",(double)
2918 MAGICKCORE_QUANTUM_DEPTH);
2921 case 'r': /* Image storage class and colorspace. */
2926 colorspace=image->colorspace;
2927 if (IsImageGray(image,exception) != MagickFalse)
2928 colorspace=GRAYColorspace;
2929 q+=FormatLocaleString(q,extent,"%s%s%s",CommandOptionToMnemonic(
2930 MagickClassOptions,(ssize_t) image->storage_class),
2931 CommandOptionToMnemonic(MagickColorspaceOptions,(ssize_t) colorspace),
2932 image->matte != MagickFalse ? "Matte" : "");
2935 case 's': /* Image scene number */
2937 if (image_info->number_scenes != 0)
2938 q+=FormatLocaleString(q,extent,"%.20g",(double) image_info->scene);
2940 q+=FormatLocaleString(q,extent,"%.20g",(double) image->scene);
2943 case 't': /* Base filename without directory or extention */
2945 GetPathComponent(image->magick_filename,BasePath,filename);
2946 q+=CopyMagickString(q,filename,extent);
2949 case 'u': /* Unique filename */
2951 (void) CopyMagickString(filename,image_info->unique,extent);
2952 q+=CopyMagickString(q,filename,extent);
2955 case 'w': /* Image width (current) */
2957 q+=FormatLocaleString(q,extent,"%.20g",(double) (image->columns != 0 ?
2958 image->columns : image->magick_columns));
2961 case 'x': /* Image horizontal resolution (density). */
2963 q+=FormatLocaleString(q,extent,"%g %s",image->resolution.x,
2964 CommandOptionToMnemonic(MagickResolutionOptions,(ssize_t)
2968 case 'y': /* Image vertical resolution (density) */
2970 q+=FormatLocaleString(q,extent,"%g %s",image->resolution.y,
2971 CommandOptionToMnemonic(MagickResolutionOptions,(ssize_t)
2975 case 'z': /* Image depth as read in */
2977 q+=FormatLocaleString(q,extent,"%.20g",(double) image->depth);
2980 case 'A': /* Image alpha channel */
2982 q+=FormatLocaleString(q,extent,"%s",CommandOptionToMnemonic(
2983 MagickBooleanOptions,(ssize_t) image->matte));
2986 case 'C': /* Image compression method. */
2988 q+=FormatLocaleString(q,extent,"%s",CommandOptionToMnemonic(
2989 MagickCompressOptions,(ssize_t) image->compression));
2992 case 'D': /* Image dispose method. */
2994 q+=FormatLocaleString(q,extent,"%s",CommandOptionToMnemonic(
2995 MagickDisposeOptions,(ssize_t) image->dispose));
2998 case 'G': /* Image size as geometry = "%wx%h" */
3000 q+=FormatLocaleString(q,extent,"%.20gx%.20g",(double)
3001 image->magick_columns,(double) image->magick_rows);
3004 case 'H': /* layer canvas height */
3006 q+=FormatLocaleString(q,extent,"%.20g",(double) image->page.height);
3009 case 'M': /* Magick filename - filename given incl. coder & read mods */
3011 q+=CopyMagickString(q,image->magick_filename,extent);
3014 case 'O': /* layer canvas offset with sign = "+%X+%Y" */
3016 q+=FormatLocaleString(q,extent,"%+ld%+ld",(long) image->page.x,(long)
3020 case 'P': /* layer canvas page size = "%Wx%H" */
3022 q+=FormatLocaleString(q,extent,"%.20gx%.20g",(double) image->page.width,
3023 (double) image->page.height);
3026 case 'Q': /* image compression quality */
3028 q+=FormatLocaleString(q,extent,"%.20g",(double) image->quality);
3031 case 'S': /* Image scenes */
3033 if (image_info->number_scenes == 0)
3034 q+=CopyMagickString(q,"2147483647",extent);
3036 q+=FormatLocaleString(q,extent,"%.20g",(double) (image_info->scene+
3037 image_info->number_scenes));
3040 case 'T': /* image time delay for animations */
3042 q+=FormatLocaleString(q,extent,"%.20g",(double) image->delay);
3045 case 'W': /* layer canvas width */
3047 q+=FormatLocaleString(q,extent,"%.20g",(double) image->page.width);
3050 case 'X': /* layer canvas X offset */
3052 q+=FormatLocaleString(q,extent,"%+.20g",(double) image->page.x);
3055 case 'Y': /* layer canvas Y offset */
3057 q+=FormatLocaleString(q,extent,"%+.20g",(double) image->page.y);
3060 case 'Z': /* Unique filename. */
3062 (void) CopyMagickString(filename,image_info->zero,extent);
3063 q+=CopyMagickString(q,filename,extent);
3066 case '@': /* Image bounding box. */
3071 page=GetImageBoundingBox(image,exception);
3072 q+=FormatLocaleString(q,MaxTextExtent,"%.20gx%.20g%+.20g%+.20g",
3073 (double) page.width,(double) page.height,(double) page.x,(double)
3077 case '#': /* Image signature */
3079 (void) SignatureImage(image,exception);
3080 value=GetImageProperty(image,"signature",exception);
3081 if (value == (const char *) NULL)
3083 q+=CopyMagickString(q,value,extent);
3086 case '%': /* percent escaped */
3091 default: /* percent not expanded */
3100 if (text != (const char *) embed_text)
3101 text=DestroyString(text);
3102 (void) SubstituteString(&interpret_text,"<","<");
3103 (void) SubstituteString(&interpret_text,">",">");
3104 return(interpret_text);
3108 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3112 % R e m o v e I m a g e P r o p e r t y %
3116 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3118 % RemoveImageProperty() removes a property from the image and returns its
3121 % The format of the RemoveImageProperty method is:
3123 % char *RemoveImageProperty(Image *image,const char *property)
3125 % A description of each parameter follows:
3127 % o image: the image.
3129 % o property: the image property.
3132 MagickExport char *RemoveImageProperty(Image *image,
3133 const char *property)
3138 assert(image != (Image *) NULL);
3139 assert(image->signature == MagickSignature);
3140 if (image->debug != MagickFalse)
3141 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
3143 if (image->properties == (void *) NULL)
3144 return((char *) NULL);
3145 value=(char *) RemoveNodeFromSplayTree((SplayTreeInfo *) image->properties,
3151 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3155 % 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 %
3159 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3161 % ResetImagePropertyIterator() resets the image properties iterator. Use it
3162 % in conjunction with GetNextImageProperty() to iterate over all the values
3163 % associated with an image property.
3165 % The format of the ResetImagePropertyIterator method is:
3167 % ResetImagePropertyIterator(Image *image)
3169 % A description of each parameter follows:
3171 % o image: the image.
3174 MagickExport void ResetImagePropertyIterator(const Image *image)
3176 assert(image != (Image *) NULL);
3177 assert(image->signature == MagickSignature);
3178 if (image->debug != MagickFalse)
3179 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
3181 if (image->properties == (void *) NULL)
3183 ResetSplayTreeIterator((SplayTreeInfo *) image->properties);
3187 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3191 % S e t I m a g e P r o p e r t y %
3195 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3197 % SetImageProperty() associates an value with an image property.
3199 % The format of the SetImageProperty method is:
3201 % MagickBooleanType SetImageProperty(Image *image,const char *property,
3202 % const char *value,ExceptionInfo *exception)
3204 % A description of each parameter follows:
3206 % o image: the image.
3208 % o property: the image property.
3210 % o values: the image property values.
3212 % o exception: return any errors or warnings in this structure.
3215 MagickExport MagickBooleanType SetImageProperty(Image *image,
3216 const char *property,const char *value,ExceptionInfo *exception)
3224 assert(image != (Image *) NULL);
3225 assert(image->signature == MagickSignature);
3226 if (image->debug != MagickFalse)
3227 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
3229 if (image->properties == (void *) NULL)
3230 image->properties=NewSplayTree(CompareSplayTreeString,
3231 RelinquishMagickMemory,RelinquishMagickMemory);
3232 if ((value == (const char *) NULL) || (*value == '\0'))
3233 return(DeleteImageProperty(image,property));
3240 if (LocaleCompare(property,"background") == 0)
3242 (void) QueryColorCompliance(value,AllCompliance,
3243 &image->background_color,exception);
3246 status=AddValueToSplayTree((SplayTreeInfo *) image->properties,
3247 ConstantString(property),ConstantString(value));
3253 if (LocaleCompare(property,"colorspace") == 0)
3258 colorspace=ParseCommandOption(MagickColorspaceOptions,MagickFalse,
3262 (void) SetImageColorspace(image,(ColorspaceType) colorspace,
3266 if (LocaleCompare(property,"compose") == 0)
3271 compose=ParseCommandOption(MagickComposeOptions,MagickFalse,value);
3274 image->compose=(CompositeOperator) compose;
3277 if (LocaleCompare(property,"compress") == 0)
3282 compression=ParseCommandOption(MagickCompressOptions,MagickFalse,
3284 if (compression < 0)
3286 image->compression=(CompressionType) compression;
3289 status=AddValueToSplayTree((SplayTreeInfo *) image->properties,
3290 ConstantString(property),ConstantString(value));
3296 if (LocaleCompare(property,"delay") == 0)
3301 flags=ParseGeometry(value,&geometry_info);
3302 if ((flags & GreaterValue) != 0)
3304 if (image->delay > (size_t) floor(geometry_info.rho+0.5))
3305 image->delay=(size_t) floor(geometry_info.rho+0.5);
3308 if ((flags & LessValue) != 0)
3310 if (image->delay < (size_t) floor(geometry_info.rho+0.5))
3311 image->ticks_per_second=(ssize_t)
3312 floor(geometry_info.sigma+0.5);
3315 image->delay=(size_t) floor(geometry_info.rho+0.5);
3316 if ((flags & SigmaValue) != 0)
3317 image->ticks_per_second=(ssize_t) floor(geometry_info.sigma+0.5);
3320 if (LocaleCompare(property,"density") == 0)
3325 flags=ParseGeometry(value,&geometry_info);
3326 image->resolution.x=geometry_info.rho;
3327 image->resolution.y=geometry_info.sigma;
3328 if ((flags & SigmaValue) == 0)
3329 image->resolution.y=image->resolution.x;
3331 if (LocaleCompare(property,"depth") == 0)
3333 image->depth=StringToUnsignedLong(value);
3336 if (LocaleCompare(property,"dispose") == 0)
3341 dispose=ParseCommandOption(MagickDisposeOptions,MagickFalse,value);
3344 image->dispose=(DisposeType) dispose;
3347 status=AddValueToSplayTree((SplayTreeInfo *) image->properties,
3348 ConstantString(property),ConstantString(value));
3354 if (LocaleCompare(property,"gravity") == 0)
3359 gravity=ParseCommandOption(MagickGravityOptions,MagickFalse,value);
3362 image->gravity=(GravityType) gravity;
3365 status=AddValueToSplayTree((SplayTreeInfo *) image->properties,
3366 ConstantString(property),ConstantString(value));
3372 if (LocaleCompare(property,"intent") == 0)
3377 rendering_intent=ParseCommandOption(MagickIntentOptions,MagickFalse,
3379 if (rendering_intent < 0)
3381 image->rendering_intent=(RenderingIntent) rendering_intent;
3384 if (LocaleCompare(property,"interpolate") == 0)
3389 interpolate=ParseCommandOption(MagickInterpolateOptions,MagickFalse,
3391 if (interpolate < 0)
3393 image->interpolate=(PixelInterpolateMethod) interpolate;
3396 status=AddValueToSplayTree((SplayTreeInfo *) image->properties,
3397 ConstantString(property),ConstantString(value));
3403 if (LocaleCompare(property,"loop") == 0)
3405 image->iterations=StringToUnsignedLong(value);
3408 status=AddValueToSplayTree((SplayTreeInfo *) image->properties,
3409 ConstantString(property),ConstantString(value));
3415 if (LocaleCompare(property,"page") == 0)
3420 geometry=GetPageGeometry(value);
3421 flags=ParseAbsoluteGeometry(geometry,&image->page);
3422 geometry=DestroyString(geometry);
3425 if (LocaleCompare(property,"profile") == 0)
3433 image_info=AcquireImageInfo();
3434 (void) CopyMagickString(image_info->filename,value,MaxTextExtent);
3435 (void) SetImageInfo(image_info,1,exception);
3436 profile=FileToStringInfo(image_info->filename,~0UL,exception);
3437 if (profile != (StringInfo *) NULL)
3438 status=SetImageProfile(image,image_info->magick,profile,exception);
3439 image_info=DestroyImageInfo(image_info);
3442 status=AddValueToSplayTree((SplayTreeInfo *) image->properties,
3443 ConstantString(property),ConstantString(value));
3449 if (LocaleCompare(property,"rendering-intent") == 0)
3454 rendering_intent=ParseCommandOption(MagickIntentOptions,MagickFalse,
3456 if (rendering_intent < 0)
3458 image->rendering_intent=(RenderingIntent) rendering_intent;
3461 status=AddValueToSplayTree((SplayTreeInfo *) image->properties,
3462 ConstantString(property),ConstantString(value));
3468 if (LocaleCompare(property,"tile-offset") == 0)
3473 geometry=GetPageGeometry(value);
3474 flags=ParseAbsoluteGeometry(geometry,&image->tile_offset);
3475 geometry=DestroyString(geometry);
3478 status=AddValueToSplayTree((SplayTreeInfo *) image->properties,
3479 ConstantString(property),ConstantString(value));
3485 if (LocaleCompare(property,"units") == 0)
3490 units=ParseCommandOption(MagickResolutionOptions,MagickFalse,value);
3493 image->units=(ResolutionType) units;
3496 status=AddValueToSplayTree((SplayTreeInfo *) image->properties,
3497 ConstantString(property),ConstantString(value));
3502 status=AddValueToSplayTree((SplayTreeInfo *) image->properties,
3503 ConstantString(property),ConstantString(value));