2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6 % PPPP RRRR OOO PPPP EEEEE RRRR TTTTT Y Y %
7 % P P R R O O P P E R R T Y Y %
8 % PPPP RRRR O O PPPP EEE RRRR T Y %
9 % P R R O O P E R R T Y %
10 % P R R OOO P EEEEE R R T Y %
13 % MagickCore Property Methods %
20 % Copyright 1999-2011 ImageMagick Studio LLC, a non-profit organization %
21 % dedicated to making software imaging solutions freely available. %
23 % You may not use this file except in compliance with the License. You may %
24 % obtain a copy of the License at %
26 % http://www.imagemagick.org/script/license.php %
28 % Unless required by applicable law or agreed to in writing, software %
29 % distributed under the License is distributed on an "AS IS" BASIS, %
30 % WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. %
31 % See the License for the specific language governing permissions and %
32 % limitations under the License. %
34 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
43 #include "magick/studio.h"
44 #include "magick/attribute.h"
45 #include "magick/cache.h"
46 #include "magick/color.h"
47 #include "magick/compare.h"
48 #include "magick/constitute.h"
49 #include "magick/draw.h"
50 #include "magick/effect.h"
51 #include "magick/exception.h"
52 #include "magick/exception-private.h"
53 #include "magick/fx.h"
54 #include "magick/fx-private.h"
55 #include "magick/gem.h"
56 #include "magick/geometry.h"
57 #include "magick/histogram.h"
58 #include "magick/image.h"
59 #include "magick/image.h"
60 #include "magick/layer.h"
61 #include "magick/list.h"
62 #include "magick/magick.h"
63 #include "magick/memory_.h"
64 #include "magick/monitor.h"
65 #include "magick/montage.h"
66 #include "magick/option.h"
67 #include "magick/profile.h"
68 #include "magick/property.h"
69 #include "magick/quantum.h"
70 #include "magick/resource_.h"
71 #include "magick/splay-tree.h"
72 #include "magick/signature-private.h"
73 #include "magick/statistic.h"
74 #include "magick/string_.h"
75 #include "magick/string-private.h"
76 #include "magick/token.h"
77 #include "magick/utility.h"
78 #include "magick/version.h"
79 #include "magick/xml-tree.h"
82 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
86 % C l o n e I m a g e P r o p e r t i e s %
90 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
92 % CloneImageProperties() clones one or more image properties.
94 % The format of the CloneImageProperties method is:
96 % MagickBooleanType CloneImageProperties(Image *image,
97 % const Image *clone_image)
99 % A description of each parameter follows:
101 % o image: the image.
103 % o clone_image: the clone image.
106 MagickExport MagickBooleanType CloneImageProperties(Image *image,
107 const Image *clone_image)
109 assert(image != (Image *) NULL);
110 assert(image->signature == MagickSignature);
111 if (image->debug != MagickFalse)
112 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
113 assert(clone_image != (const Image *) NULL);
114 assert(clone_image->signature == MagickSignature);
115 if (clone_image->debug != MagickFalse)
116 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
117 clone_image->filename);
118 (void) CopyMagickString(image->filename,clone_image->filename,MaxTextExtent);
119 (void) CopyMagickString(image->magick_filename,clone_image->magick_filename,
121 image->compression=clone_image->compression;
122 image->quality=clone_image->quality;
123 image->depth=clone_image->depth;
124 image->background_color=clone_image->background_color;
125 image->border_color=clone_image->border_color;
126 image->matte_color=clone_image->matte_color;
127 image->transparent_color=clone_image->transparent_color;
128 image->gamma=clone_image->gamma;
129 image->chromaticity=clone_image->chromaticity;
130 image->rendering_intent=clone_image->rendering_intent;
131 image->black_point_compensation=clone_image->black_point_compensation;
132 image->units=clone_image->units;
133 image->montage=(char *) NULL;
134 image->directory=(char *) NULL;
135 (void) CloneString(&image->geometry,clone_image->geometry);
136 image->offset=clone_image->offset;
137 image->x_resolution=clone_image->x_resolution;
138 image->y_resolution=clone_image->y_resolution;
139 image->page=clone_image->page;
140 image->tile_offset=clone_image->tile_offset;
141 image->extract_info=clone_image->extract_info;
142 image->bias=clone_image->bias;
143 image->filter=clone_image->filter;
144 image->blur=clone_image->blur;
145 image->fuzz=clone_image->fuzz;
146 image->interlace=clone_image->interlace;
147 image->interpolate=clone_image->interpolate;
148 image->endian=clone_image->endian;
149 image->gravity=clone_image->gravity;
150 image->compose=clone_image->compose;
151 image->scene=clone_image->scene;
152 image->orientation=clone_image->orientation;
153 image->dispose=clone_image->dispose;
154 image->delay=clone_image->delay;
155 image->ticks_per_second=clone_image->ticks_per_second;
156 image->iterations=clone_image->iterations;
157 image->total_colors=clone_image->total_colors;
158 image->taint=clone_image->taint;
159 image->progress_monitor=clone_image->progress_monitor;
160 image->client_data=clone_image->client_data;
161 image->start_loop=clone_image->start_loop;
162 image->error=clone_image->error;
163 image->signature=clone_image->signature;
164 if (clone_image->properties != (void *) NULL)
166 if (image->properties != (void *) NULL)
167 DestroyImageProperties(image);
168 image->properties=CloneSplayTree((SplayTreeInfo *)
169 clone_image->properties,(void *(*)(void *)) ConstantString,
170 (void *(*)(void *)) ConstantString);
176 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
180 % D e f i n e I m a g e P r o p e r t y %
184 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
186 % DefineImageProperty() associates a key/value pair with an image property.
188 % The format of the DefineImageProperty method is:
190 % MagickBooleanType DefineImageProperty(Image *image,
191 % const char *property)
193 % A description of each parameter follows:
195 % o image: the image.
197 % o property: the image property.
200 MagickExport MagickBooleanType DefineImageProperty(Image *image,
201 const char *property)
205 value[MaxTextExtent];
210 assert(image != (Image *) NULL);
211 assert(property != (const char *) NULL);
212 (void) CopyMagickString(key,property,MaxTextExtent-1);
213 for (p=key; *p != '\0'; p++)
218 (void) CopyMagickString(value,p+1,MaxTextExtent);
220 return(SetImageProperty(image,key,value));
224 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
228 % D e l e t e I m a g e P r o p e r t y %
232 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
234 % DeleteImageProperty() deletes an image property.
236 % The format of the DeleteImageProperty method is:
238 % MagickBooleanType DeleteImageProperty(Image *image,const char *property)
240 % A description of each parameter follows:
242 % o image: the image.
244 % o property: the image property.
247 MagickExport MagickBooleanType DeleteImageProperty(Image *image,
248 const char *property)
250 assert(image != (Image *) NULL);
251 assert(image->signature == MagickSignature);
252 if (image->debug != MagickFalse)
253 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
255 if (image->properties == (void *) NULL)
257 return(DeleteNodeFromSplayTree((SplayTreeInfo *) image->properties,property));
261 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
265 % D e s t r o y I m a g e P r o p e r t i e s %
269 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
271 % DestroyImageProperties() releases memory associated with image property
274 % The format of the DestroyDefines method is:
276 % void DestroyImageProperties(Image *image)
278 % A description of each parameter follows:
280 % o image: the image.
283 MagickExport void DestroyImageProperties(Image *image)
285 assert(image != (Image *) NULL);
286 assert(image->signature == MagickSignature);
287 if (image->debug != MagickFalse)
288 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
290 if (image->properties != (void *) NULL)
291 image->properties=(void *) DestroySplayTree((SplayTreeInfo *)
296 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
300 % F o r m a t I m a g e P r o p e r t y %
304 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
306 % FormatImageProperty() permits formatted property/value pairs to be saved as
309 % The format of the FormatImageProperty method is:
311 % MagickBooleanType FormatImageProperty(Image *image,const char *property,
312 % const char *format,...)
314 % A description of each parameter follows.
316 % o image: The image.
318 % o property: The attribute property.
320 % o format: A string describing the format to use to write the remaining
324 MagickExport MagickBooleanType FormatImageProperty(Image *image,
325 const char *property,const char *format,...)
328 value[MaxTextExtent];
336 va_start(operands,format);
337 n=FormatLocaleStringList(value,MaxTextExtent,format,operands);
340 return(SetImageProperty(image,property,value));
344 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
348 % G e t I m a g e P r o p e r t y %
352 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
354 % GetImageProperty() gets a value associated with an image property.
356 % The format of the GetImageProperty method is:
358 % const char *GetImageProperty(const Image *image,const char *key)
360 % A description of each parameter follows:
362 % o image: the image.
369 *TracePSClippath(const unsigned char *,size_t,const size_t,
371 *TraceSVGClippath(const unsigned char *,size_t,const size_t,
374 static MagickBooleanType GetIPTCProperty(const Image *image,const char *key)
394 profile=GetImageProfile(image,"iptc");
395 if (profile == (StringInfo *) NULL)
396 profile=GetImageProfile(image,"8bim");
397 if (profile == (StringInfo *) NULL)
399 count=sscanf(key,"IPTC:%ld:%ld",&dataset,&record);
402 attribute=(char *) NULL;
403 for (i=0; i < (ssize_t) GetStringInfoLength(profile); i+=(ssize_t) length)
406 if ((ssize_t) GetStringInfoDatum(profile)[i] != 0x1c)
408 length=(size_t) (GetStringInfoDatum(profile)[i+3] << 8);
409 length|=GetStringInfoDatum(profile)[i+4];
410 if (((long) GetStringInfoDatum(profile)[i+1] == dataset) &&
411 ((long) GetStringInfoDatum(profile)[i+2] == record))
413 message=(char *) NULL;
415 message=(char *) AcquireQuantumMemory(length+1UL,sizeof(*message));
416 if (message != (char *) NULL)
418 (void) CopyMagickString(message,(char *) GetStringInfoDatum(
419 profile)+i+5,length+1);
420 (void) ConcatenateString(&attribute,message);
421 (void) ConcatenateString(&attribute,";");
422 message=DestroyString(message);
427 if ((attribute == (char *) NULL) || (*attribute == ';'))
429 if (attribute != (char *) NULL)
430 attribute=DestroyString(attribute);
433 attribute[strlen(attribute)-1]='\0';
434 (void) SetImageProperty((Image *) image,key,(const char *) attribute);
435 attribute=DestroyString(attribute);
439 static inline ssize_t MagickMax(const ssize_t x,const ssize_t y)
446 static inline int ReadPropertyByte(const unsigned char **p,size_t *length)
458 static inline size_t ReadPropertyMSBLong(const unsigned char **p,
475 for (i=0; i < 4; i++)
479 buffer[i]=(unsigned char) c;
481 value=(size_t) (buffer[0] << 24);
482 value|=buffer[1] << 16;
483 value|=buffer[2] << 8;
485 return(value & 0xffffffff);
488 static inline unsigned short ReadPropertyMSBShort(const unsigned char **p,
504 return((unsigned short) ~0U);
505 for (i=0; i < 2; i++)
509 buffer[i]=(unsigned char) c;
511 value=(unsigned short) (buffer[0] << 8);
513 return((unsigned short) (value & 0xffff));
516 static MagickBooleanType Get8BIMProperty(const Image *image,const char *key)
520 format[MaxTextExtent],
549 There are no newlines in path names, so it's safe as terminator.
551 profile=GetImageProfile(image,"8bim");
552 if (profile == (StringInfo *) NULL)
554 count=(ssize_t) sscanf(key,"8BIM:%ld,%ld:%[^\n]\n%[^\n]",&start,&stop,name,
556 if ((count != 2) && (count != 3) && (count != 4))
559 (void) CopyMagickString(format,"SVG",MaxTextExtent);
564 sub_number=(ssize_t) StringToLong(&name[1]);
565 sub_number=MagickMax(sub_number,1L);
566 resource=(char *) NULL;
568 length=GetStringInfoLength(profile);
569 info=GetStringInfoDatum(profile);
570 while ((length > 0) && (status == MagickFalse))
572 if (ReadPropertyByte(&info,&length) != (unsigned char) '8')
574 if (ReadPropertyByte(&info,&length) != (unsigned char) 'B')
576 if (ReadPropertyByte(&info,&length) != (unsigned char) 'I')
578 if (ReadPropertyByte(&info,&length) != (unsigned char) 'M')
580 id=(ssize_t) ReadPropertyMSBShort(&info,&length);
581 if (id < (ssize_t) start)
583 if (id > (ssize_t) stop)
585 if (resource != (char *) NULL)
586 resource=DestroyString(resource);
587 count=(ssize_t) ReadPropertyByte(&info,&length);
588 if ((count != 0) && ((size_t) count <= length))
590 resource=(char *) NULL;
591 if (~(1UL*count) >= MaxTextExtent)
592 resource=(char *) AcquireQuantumMemory((size_t) count+MaxTextExtent,
594 if (resource != (char *) NULL)
596 for (i=0; i < (ssize_t) count; i++)
597 resource[i]=(char) ReadPropertyByte(&info,&length);
598 resource[count]='\0';
601 if ((count & 0x01) == 0)
602 (void) ReadPropertyByte(&info,&length);
603 count=(ssize_t) ((int) ReadPropertyMSBLong(&info,&length));
604 if ((*name != '\0') && (*name != '#'))
605 if ((resource == (char *) NULL) || (LocaleCompare(name,resource) != 0))
608 No name match, scroll forward and try next.
614 if ((*name == '#') && (sub_number != 1))
617 No numbered match, scroll forward and try next.
625 We have the resource of interest.
627 attribute=(char *) NULL;
628 if (~(1UL*count) >= MaxTextExtent)
629 attribute=(char *) AcquireQuantumMemory((size_t) count+MaxTextExtent,
631 if (attribute != (char *) NULL)
633 (void) CopyMagickMemory(attribute,(char *) info,(size_t) count);
634 attribute[count]='\0';
637 if ((id <= 1999) || (id >= 2999))
638 (void) SetImageProperty((Image *) image,key,(const char *)
645 if (LocaleCompare(format,"svg") == 0)
646 path=TraceSVGClippath((unsigned char *) attribute,(size_t) count,
647 image->columns,image->rows);
649 path=TracePSClippath((unsigned char *) attribute,(size_t) count,
650 image->columns,image->rows);
651 (void) SetImageProperty((Image *) image,key,(const char *) path);
652 path=DestroyString(path);
654 attribute=DestroyString(attribute);
658 if (resource != (char *) NULL)
659 resource=DestroyString(resource);
663 static inline unsigned short ReadPropertyShort(const EndianType endian,
664 const unsigned char *buffer)
669 if (endian == MSBEndian)
671 value=(unsigned short) ((((unsigned char *) buffer)[0] << 8) |
672 ((unsigned char *) buffer)[1]);
673 return((unsigned short) (value & 0xffff));
675 value=(unsigned short) ((buffer[1] << 8) | buffer[0]);
676 return((unsigned short) (value & 0xffff));
679 static inline size_t ReadPropertyLong(const EndianType endian,
680 const unsigned char *buffer)
685 if (endian == MSBEndian)
687 value=(size_t) ((buffer[0] << 24) | (buffer[1] << 16) |
688 (buffer[2] << 8) | buffer[3]);
689 return((size_t) (value & 0xffffffff));
691 value=(size_t) ((buffer[3] << 24) | (buffer[2] << 16) |
692 (buffer[1] << 8 ) | (buffer[0]));
693 return((size_t) (value & 0xffffffff));
696 static MagickBooleanType GetEXIFProperty(const Image *image,
697 const char *property)
699 #define MaxDirectoryStack 16
700 #define EXIF_DELIMITER "\n"
701 #define EXIF_NUM_FORMATS 12
702 #define EXIF_FMT_BYTE 1
703 #define EXIF_FMT_STRING 2
704 #define EXIF_FMT_USHORT 3
705 #define EXIF_FMT_ULONG 4
706 #define EXIF_FMT_URATIONAL 5
707 #define EXIF_FMT_SBYTE 6
708 #define EXIF_FMT_UNDEFINED 7
709 #define EXIF_FMT_SSHORT 8
710 #define EXIF_FMT_SLONG 9
711 #define EXIF_FMT_SRATIONAL 10
712 #define EXIF_FMT_SINGLE 11
713 #define EXIF_FMT_DOUBLE 12
714 #define TAG_EXIF_OFFSET 0x8769
715 #define TAG_GPS_OFFSET 0x8825
716 #define TAG_INTEROP_OFFSET 0xa005
718 #define EXIFMultipleValues(size, format, arg) \
731 for (component=0; component < components; component++) \
733 length+=FormatLocaleString(buffer+length,MaxTextExtent-length, \
735 if (length >= MaxTextExtent - 1) \
736 length=MaxTextExtent-1; \
740 buffer[length-2]='\0'; \
741 value=AcquireString(buffer); \
744 #define EXIFMultipleFractions(size, format, arg1, arg2) \
757 for (component=0; component < components; component++) \
759 length+=FormatLocaleString(buffer+length,MaxTextExtent-length, \
760 format", ",arg1, arg2); \
761 if (length >= MaxTextExtent - 1) \
762 length=MaxTextExtent-1; \
766 buffer[length-2]='\0'; \
767 value=AcquireString(buffer); \
770 typedef struct _DirectoryInfo
780 typedef struct _TagInfo
792 { 0x001, "exif:InteroperabilityIndex" },
793 { 0x002, "exif:InteroperabilityVersion" },
794 { 0x100, "exif:ImageWidth" },
795 { 0x101, "exif:ImageLength" },
796 { 0x102, "exif:BitsPerSample" },
797 { 0x103, "exif:Compression" },
798 { 0x106, "exif:PhotometricInterpretation" },
799 { 0x10a, "exif:FillOrder" },
800 { 0x10d, "exif:DocumentName" },
801 { 0x10e, "exif:ImageDescription" },
802 { 0x10f, "exif:Make" },
803 { 0x110, "exif:Model" },
804 { 0x111, "exif:StripOffsets" },
805 { 0x112, "exif:Orientation" },
806 { 0x115, "exif:SamplesPerPixel" },
807 { 0x116, "exif:RowsPerStrip" },
808 { 0x117, "exif:StripByteCounts" },
809 { 0x11a, "exif:XResolution" },
810 { 0x11b, "exif:YResolution" },
811 { 0x11c, "exif:PlanarConfiguration" },
812 { 0x11d, "exif:PageName" },
813 { 0x11e, "exif:XPosition" },
814 { 0x11f, "exif:YPosition" },
815 { 0x118, "exif:MinSampleValue" },
816 { 0x119, "exif:MaxSampleValue" },
817 { 0x120, "exif:FreeOffsets" },
818 { 0x121, "exif:FreeByteCounts" },
819 { 0x122, "exif:GrayResponseUnit" },
820 { 0x123, "exif:GrayResponseCurve" },
821 { 0x124, "exif:T4Options" },
822 { 0x125, "exif:T6Options" },
823 { 0x128, "exif:ResolutionUnit" },
824 { 0x12d, "exif:TransferFunction" },
825 { 0x131, "exif:Software" },
826 { 0x132, "exif:DateTime" },
827 { 0x13b, "exif:Artist" },
828 { 0x13e, "exif:WhitePoint" },
829 { 0x13f, "exif:PrimaryChromaticities" },
830 { 0x140, "exif:ColorMap" },
831 { 0x141, "exif:HalfToneHints" },
832 { 0x142, "exif:TileWidth" },
833 { 0x143, "exif:TileLength" },
834 { 0x144, "exif:TileOffsets" },
835 { 0x145, "exif:TileByteCounts" },
836 { 0x14a, "exif:SubIFD" },
837 { 0x14c, "exif:InkSet" },
838 { 0x14d, "exif:InkNames" },
839 { 0x14e, "exif:NumberOfInks" },
840 { 0x150, "exif:DotRange" },
841 { 0x151, "exif:TargetPrinter" },
842 { 0x152, "exif:ExtraSample" },
843 { 0x153, "exif:SampleFormat" },
844 { 0x154, "exif:SMinSampleValue" },
845 { 0x155, "exif:SMaxSampleValue" },
846 { 0x156, "exif:TransferRange" },
847 { 0x157, "exif:ClipPath" },
848 { 0x158, "exif:XClipPathUnits" },
849 { 0x159, "exif:YClipPathUnits" },
850 { 0x15a, "exif:Indexed" },
851 { 0x15b, "exif:JPEGTables" },
852 { 0x15f, "exif:OPIProxy" },
853 { 0x200, "exif:JPEGProc" },
854 { 0x201, "exif:JPEGInterchangeFormat" },
855 { 0x202, "exif:JPEGInterchangeFormatLength" },
856 { 0x203, "exif:JPEGRestartInterval" },
857 { 0x205, "exif:JPEGLosslessPredictors" },
858 { 0x206, "exif:JPEGPointTransforms" },
859 { 0x207, "exif:JPEGQTables" },
860 { 0x208, "exif:JPEGDCTables" },
861 { 0x209, "exif:JPEGACTables" },
862 { 0x211, "exif:YCbCrCoefficients" },
863 { 0x212, "exif:YCbCrSubSampling" },
864 { 0x213, "exif:YCbCrPositioning" },
865 { 0x214, "exif:ReferenceBlackWhite" },
866 { 0x2bc, "exif:ExtensibleMetadataPlatform" },
867 { 0x301, "exif:Gamma" },
868 { 0x302, "exif:ICCProfileDescriptor" },
869 { 0x303, "exif:SRGBRenderingIntent" },
870 { 0x320, "exif:ImageTitle" },
871 { 0x5001, "exif:ResolutionXUnit" },
872 { 0x5002, "exif:ResolutionYUnit" },
873 { 0x5003, "exif:ResolutionXLengthUnit" },
874 { 0x5004, "exif:ResolutionYLengthUnit" },
875 { 0x5005, "exif:PrintFlags" },
876 { 0x5006, "exif:PrintFlagsVersion" },
877 { 0x5007, "exif:PrintFlagsCrop" },
878 { 0x5008, "exif:PrintFlagsBleedWidth" },
879 { 0x5009, "exif:PrintFlagsBleedWidthScale" },
880 { 0x500A, "exif:HalftoneLPI" },
881 { 0x500B, "exif:HalftoneLPIUnit" },
882 { 0x500C, "exif:HalftoneDegree" },
883 { 0x500D, "exif:HalftoneShape" },
884 { 0x500E, "exif:HalftoneMisc" },
885 { 0x500F, "exif:HalftoneScreen" },
886 { 0x5010, "exif:JPEGQuality" },
887 { 0x5011, "exif:GridSize" },
888 { 0x5012, "exif:ThumbnailFormat" },
889 { 0x5013, "exif:ThumbnailWidth" },
890 { 0x5014, "exif:ThumbnailHeight" },
891 { 0x5015, "exif:ThumbnailColorDepth" },
892 { 0x5016, "exif:ThumbnailPlanes" },
893 { 0x5017, "exif:ThumbnailRawBytes" },
894 { 0x5018, "exif:ThumbnailSize" },
895 { 0x5019, "exif:ThumbnailCompressedSize" },
896 { 0x501a, "exif:ColorTransferFunction" },
897 { 0x501b, "exif:ThumbnailData" },
898 { 0x5020, "exif:ThumbnailImageWidth" },
899 { 0x5021, "exif:ThumbnailImageHeight" },
900 { 0x5022, "exif:ThumbnailBitsPerSample" },
901 { 0x5023, "exif:ThumbnailCompression" },
902 { 0x5024, "exif:ThumbnailPhotometricInterp" },
903 { 0x5025, "exif:ThumbnailImageDescription" },
904 { 0x5026, "exif:ThumbnailEquipMake" },
905 { 0x5027, "exif:ThumbnailEquipModel" },
906 { 0x5028, "exif:ThumbnailStripOffsets" },
907 { 0x5029, "exif:ThumbnailOrientation" },
908 { 0x502a, "exif:ThumbnailSamplesPerPixel" },
909 { 0x502b, "exif:ThumbnailRowsPerStrip" },
910 { 0x502c, "exif:ThumbnailStripBytesCount" },
911 { 0x502d, "exif:ThumbnailResolutionX" },
912 { 0x502e, "exif:ThumbnailResolutionY" },
913 { 0x502f, "exif:ThumbnailPlanarConfig" },
914 { 0x5030, "exif:ThumbnailResolutionUnit" },
915 { 0x5031, "exif:ThumbnailTransferFunction" },
916 { 0x5032, "exif:ThumbnailSoftwareUsed" },
917 { 0x5033, "exif:ThumbnailDateTime" },
918 { 0x5034, "exif:ThumbnailArtist" },
919 { 0x5035, "exif:ThumbnailWhitePoint" },
920 { 0x5036, "exif:ThumbnailPrimaryChromaticities" },
921 { 0x5037, "exif:ThumbnailYCbCrCoefficients" },
922 { 0x5038, "exif:ThumbnailYCbCrSubsampling" },
923 { 0x5039, "exif:ThumbnailYCbCrPositioning" },
924 { 0x503A, "exif:ThumbnailRefBlackWhite" },
925 { 0x503B, "exif:ThumbnailCopyRight" },
926 { 0x5090, "exif:LuminanceTable" },
927 { 0x5091, "exif:ChrominanceTable" },
928 { 0x5100, "exif:FrameDelay" },
929 { 0x5101, "exif:LoopCount" },
930 { 0x5110, "exif:PixelUnit" },
931 { 0x5111, "exif:PixelPerUnitX" },
932 { 0x5112, "exif:PixelPerUnitY" },
933 { 0x5113, "exif:PaletteHistogram" },
934 { 0x1000, "exif:RelatedImageFileFormat" },
935 { 0x1001, "exif:RelatedImageLength" },
936 { 0x1002, "exif:RelatedImageWidth" },
937 { 0x800d, "exif:ImageID" },
938 { 0x80e3, "exif:Matteing" },
939 { 0x80e4, "exif:DataType" },
940 { 0x80e5, "exif:ImageDepth" },
941 { 0x80e6, "exif:TileDepth" },
942 { 0x828d, "exif:CFARepeatPatternDim" },
943 { 0x828e, "exif:CFAPattern2" },
944 { 0x828f, "exif:BatteryLevel" },
945 { 0x8298, "exif:Copyright" },
946 { 0x829a, "exif:ExposureTime" },
947 { 0x829d, "exif:FNumber" },
948 { 0x83bb, "exif:IPTC/NAA" },
949 { 0x84e3, "exif:IT8RasterPadding" },
950 { 0x84e5, "exif:IT8ColorTable" },
951 { 0x8649, "exif:ImageResourceInformation" },
952 { 0x8769, "exif:ExifOffset" },
953 { 0x8773, "exif:InterColorProfile" },
954 { 0x8822, "exif:ExposureProgram" },
955 { 0x8824, "exif:SpectralSensitivity" },
956 { 0x8825, "exif:GPSInfo" },
957 { 0x8827, "exif:ISOSpeedRatings" },
958 { 0x8828, "exif:OECF" },
959 { 0x8829, "exif:Interlace" },
960 { 0x882a, "exif:TimeZoneOffset" },
961 { 0x882b, "exif:SelfTimerMode" },
962 { 0x9000, "exif:ExifVersion" },
963 { 0x9003, "exif:DateTimeOriginal" },
964 { 0x9004, "exif:DateTimeDigitized" },
965 { 0x9101, "exif:ComponentsConfiguration" },
966 { 0x9102, "exif:CompressedBitsPerPixel" },
967 { 0x9201, "exif:ShutterSpeedValue" },
968 { 0x9202, "exif:ApertureValue" },
969 { 0x9203, "exif:BrightnessValue" },
970 { 0x9204, "exif:ExposureBiasValue" },
971 { 0x9205, "exif:MaxApertureValue" },
972 { 0x9206, "exif:SubjectDistance" },
973 { 0x9207, "exif:MeteringMode" },
974 { 0x9208, "exif:LightSource" },
975 { 0x9209, "exif:Flash" },
976 { 0x920a, "exif:FocalLength" },
977 { 0x920b, "exif:FlashEnergy" },
978 { 0x920c, "exif:SpatialFrequencyResponse" },
979 { 0x920d, "exif:Noise" },
980 { 0x9211, "exif:ImageNumber" },
981 { 0x9212, "exif:SecurityClassification" },
982 { 0x9213, "exif:ImageHistory" },
983 { 0x9214, "exif:SubjectArea" },
984 { 0x9215, "exif:ExposureIndex" },
985 { 0x9216, "exif:TIFF-EPStandardID" },
986 { 0x927c, "exif:MakerNote" },
987 { 0x9C9b, "exif:WinXP-Title" },
988 { 0x9C9c, "exif:WinXP-Comments" },
989 { 0x9C9d, "exif:WinXP-Author" },
990 { 0x9C9e, "exif:WinXP-Keywords" },
991 { 0x9C9f, "exif:WinXP-Subject" },
992 { 0x9286, "exif:UserComment" },
993 { 0x9290, "exif:SubSecTime" },
994 { 0x9291, "exif:SubSecTimeOriginal" },
995 { 0x9292, "exif:SubSecTimeDigitized" },
996 { 0xa000, "exif:FlashPixVersion" },
997 { 0xa001, "exif:ColorSpace" },
998 { 0xa002, "exif:ExifImageWidth" },
999 { 0xa003, "exif:ExifImageLength" },
1000 { 0xa004, "exif:RelatedSoundFile" },
1001 { 0xa005, "exif:InteroperabilityOffset" },
1002 { 0xa20b, "exif:FlashEnergy" },
1003 { 0xa20c, "exif:SpatialFrequencyResponse" },
1004 { 0xa20d, "exif:Noise" },
1005 { 0xa20e, "exif:FocalPlaneXResolution" },
1006 { 0xa20f, "exif:FocalPlaneYResolution" },
1007 { 0xa210, "exif:FocalPlaneResolutionUnit" },
1008 { 0xa214, "exif:SubjectLocation" },
1009 { 0xa215, "exif:ExposureIndex" },
1010 { 0xa216, "exif:TIFF/EPStandardID" },
1011 { 0xa217, "exif:SensingMethod" },
1012 { 0xa300, "exif:FileSource" },
1013 { 0xa301, "exif:SceneType" },
1014 { 0xa302, "exif:CFAPattern" },
1015 { 0xa401, "exif:CustomRendered" },
1016 { 0xa402, "exif:ExposureMode" },
1017 { 0xa403, "exif:WhiteBalance" },
1018 { 0xa404, "exif:DigitalZoomRatio" },
1019 { 0xa405, "exif:FocalLengthIn35mmFilm" },
1020 { 0xa406, "exif:SceneCaptureType" },
1021 { 0xa407, "exif:GainControl" },
1022 { 0xa408, "exif:Contrast" },
1023 { 0xa409, "exif:Saturation" },
1024 { 0xa40a, "exif:Sharpness" },
1025 { 0xa40b, "exif:DeviceSettingDescription" },
1026 { 0xa40c, "exif:SubjectDistanceRange" },
1027 { 0xa420, "exif:ImageUniqueID" },
1028 { 0xc4a5, "exif:PrintImageMatching" },
1029 { 0xa500, "exif:Gamma" },
1030 { 0xc640, "exif:CR2Slice" },
1031 { 0x10000, "exif:GPSVersionID" },
1032 { 0x10001, "exif:GPSLatitudeRef" },
1033 { 0x10002, "exif:GPSLatitude" },
1034 { 0x10003, "exif:GPSLongitudeRef" },
1035 { 0x10004, "exif:GPSLongitude" },
1036 { 0x10005, "exif:GPSAltitudeRef" },
1037 { 0x10006, "exif:GPSAltitude" },
1038 { 0x10007, "exif:GPSTimeStamp" },
1039 { 0x10008, "exif:GPSSatellites" },
1040 { 0x10009, "exif:GPSStatus" },
1041 { 0x1000a, "exif:GPSMeasureMode" },
1042 { 0x1000b, "exif:GPSDop" },
1043 { 0x1000c, "exif:GPSSpeedRef" },
1044 { 0x1000d, "exif:GPSSpeed" },
1045 { 0x1000e, "exif:GPSTrackRef" },
1046 { 0x1000f, "exif:GPSTrack" },
1047 { 0x10010, "exif:GPSImgDirectionRef" },
1048 { 0x10011, "exif:GPSImgDirection" },
1049 { 0x10012, "exif:GPSMapDatum" },
1050 { 0x10013, "exif:GPSDestLatitudeRef" },
1051 { 0x10014, "exif:GPSDestLatitude" },
1052 { 0x10015, "exif:GPSDestLongitudeRef" },
1053 { 0x10016, "exif:GPSDestLongitude" },
1054 { 0x10017, "exif:GPSDestBearingRef" },
1055 { 0x10018, "exif:GPSDestBearing" },
1056 { 0x10019, "exif:GPSDestDistanceRef" },
1057 { 0x1001a, "exif:GPSDestDistance" },
1058 { 0x1001b, "exif:GPSProcessingMethod" },
1059 { 0x1001c, "exif:GPSAreaInformation" },
1060 { 0x1001d, "exif:GPSDateStamp" },
1061 { 0x1001e, "exif:GPSDifferential" },
1073 directory_stack[MaxDirectoryStack];
1099 tag_bytes[] = {0, 1, 1, 2, 4, 8, 1, 1, 2, 4, 8, 4, 8};
1102 If EXIF data exists, then try to parse the request for a tag.
1104 profile=GetImageProfile(image,"exif");
1105 if (profile == (StringInfo *) NULL)
1106 return(MagickFalse);
1107 if ((property == (const char *) NULL) || (*property == '\0'))
1108 return(MagickFalse);
1109 while (isspace((int) ((unsigned char) *property)) != 0)
1113 switch (*(property+5))
1118 Caller has asked for all the tags in the EXIF data.
1121 all=1; /* return the data in description=value format */
1127 all=2; /* return the data in tagid=value format */
1140 Check for a hex based tag specification first.
1142 tag=(*(property+5) == '@') ? 1UL : 0UL;
1146 return(MagickFalse);
1148 Parse tag specification as a hex number.
1153 for (i=(ssize_t) n-1L; i >= 0; i--)
1157 if ((c >= '0') && (c <= '9'))
1160 if ((c >= 'A') && (c <= 'F'))
1163 if ((c >= 'a') && (c <= 'f'))
1166 return(MagickFalse);
1168 } while (*property != '\0');
1174 Try to match the text with a tag name instead.
1178 if (EXIFTag[i].tag == 0)
1180 if (LocaleCompare(EXIFTag[i].description,property) == 0)
1182 tag=(size_t) EXIFTag[i].tag;
1190 return(MagickFalse);
1191 length=GetStringInfoLength(profile);
1192 exif=GetStringInfoDatum(profile);
1195 if (ReadPropertyByte(&exif,&length) != 0x45)
1197 if (ReadPropertyByte(&exif,&length) != 0x78)
1199 if (ReadPropertyByte(&exif,&length) != 0x69)
1201 if (ReadPropertyByte(&exif,&length) != 0x66)
1203 if (ReadPropertyByte(&exif,&length) != 0x00)
1205 if (ReadPropertyByte(&exif,&length) != 0x00)
1210 return(MagickFalse);
1211 id=(ssize_t) ReadPropertyShort(LSBEndian,exif);
1219 return(MagickFalse);
1220 if (ReadPropertyShort(endian,exif+2) != 0x002a)
1221 return(MagickFalse);
1223 This the offset to the first IFD.
1225 offset=(ssize_t) ((int) ReadPropertyLong(endian,exif+4));
1226 if ((size_t) offset >= length)
1227 return(MagickFalse);
1229 Set the pointer to the first IFD and follow it were it leads.
1232 directory=exif+offset;
1239 If there is anything on the stack then pop it off.
1244 directory=directory_stack[level].directory;
1245 entry=directory_stack[level].entry;
1246 tag_offset=directory_stack[level].offset;
1249 Determine how many entries there are in the current IFD.
1251 number_entries=ReadPropertyShort(endian,directory);
1252 for ( ; entry < number_entries; entry++)
1254 register unsigned char
1265 q=(unsigned char *) (directory+2+(12*entry));
1266 tag_value=(ssize_t) (ReadPropertyShort(endian,q)+tag_offset);
1267 format=(size_t) ReadPropertyShort(endian,q+2);
1268 if (format >= (sizeof(tag_bytes)/sizeof(*tag_bytes)))
1270 components=(ssize_t) ((int) ReadPropertyLong(endian,q+4));
1271 number_bytes=(size_t) components*tag_bytes[format];
1272 if (number_bytes <= 4)
1280 The directory entry contains an offset.
1282 offset=(ssize_t) ((int) ReadPropertyLong(endian,q+8));
1283 if ((size_t) (offset+number_bytes) > length)
1285 p=(unsigned char *) (exif+offset);
1287 if ((all != 0) || (tag == (size_t) tag_value))
1290 buffer[MaxTextExtent],
1296 case EXIF_FMT_UNDEFINED:
1298 EXIFMultipleValues(1,"%.20g",(double)
1299 (*(unsigned char *) p1));
1302 case EXIF_FMT_SBYTE:
1304 EXIFMultipleValues(1,"%.20g",(double) (*(signed char *) p1));
1307 case EXIF_FMT_SSHORT:
1309 EXIFMultipleValues(2,"%hd",ReadPropertyShort(endian,p1));
1312 case EXIF_FMT_USHORT:
1314 EXIFMultipleValues(2,"%hu",ReadPropertyShort(endian,p1));
1317 case EXIF_FMT_ULONG:
1319 EXIFMultipleValues(4,"%.20g",(double)
1320 ReadPropertyLong(endian,p1));
1323 case EXIF_FMT_SLONG:
1325 EXIFMultipleValues(4,"%.20g",(double)
1326 ReadPropertyLong(endian,p1));
1329 case EXIF_FMT_URATIONAL:
1331 EXIFMultipleFractions(8,"%.20g/%.20g",(double)
1332 ReadPropertyLong(endian,p1),(double)
1333 ReadPropertyLong(endian,p1+4));
1336 case EXIF_FMT_SRATIONAL:
1338 EXIFMultipleFractions(8,"%.20g/%.20g",(double)
1339 ReadPropertyLong(endian,p1),(double)
1340 ReadPropertyLong(endian,p1+4));
1343 case EXIF_FMT_SINGLE:
1345 EXIFMultipleValues(4,"%f",(double) *(float *) p1);
1348 case EXIF_FMT_DOUBLE:
1350 EXIFMultipleValues(8,"%f",*(double *) p1);
1354 case EXIF_FMT_STRING:
1356 value=(char *) NULL;
1357 if (~(1UL*number_bytes) >= 1)
1358 value=(char *) AcquireQuantumMemory((size_t) number_bytes+1UL,
1360 if (value != (char *) NULL)
1365 for (i=0; i < (ssize_t) number_bytes; i++)
1368 if ((isprint((int) p[i]) != 0) || (p[i] == '\0'))
1369 value[i]=(char) p[i];
1376 if (value != (char *) NULL)
1384 (void) CopyMagickString(key,property,MaxTextExtent);
1395 description="unknown";
1398 if (EXIFTag[i].tag == 0)
1400 if ((ssize_t) EXIFTag[i].tag == tag_value)
1402 description=EXIFTag[i].description;
1406 (void) FormatLocaleString(key,MaxTextExtent,"%s",
1412 if (tag_value < 0x10000)
1413 (void) FormatLocaleString(key,MaxTextExtent,"#%04lx",
1414 (unsigned long) tag_value);
1416 if (tag_value < 0x20000)
1417 (void) FormatLocaleString(key,MaxTextExtent,"@%04lx",
1418 (unsigned long) (tag_value & 0xffff));
1420 (void) FormatLocaleString(key,MaxTextExtent,"unknown");
1424 p=(const char *) NULL;
1425 if (image->properties != (void *) NULL)
1426 p=(const char *) GetValueFromSplayTree((SplayTreeInfo *)
1427 image->properties,key);
1428 if (p == (const char *) NULL)
1429 (void) SetImageProperty((Image *) image,key,value);
1430 value=DestroyString(value);
1434 if ((tag_value == TAG_EXIF_OFFSET) ||
1435 (tag_value == TAG_INTEROP_OFFSET) ||
1436 (tag_value == TAG_GPS_OFFSET))
1441 offset=(size_t) ReadPropertyLong(endian,p);
1442 if ((offset < length) && (level < (MaxDirectoryStack-2)))
1447 tag_offset1=(tag_value == TAG_GPS_OFFSET) ? 0x10000UL : 0UL;
1448 directory_stack[level].directory=directory;
1450 directory_stack[level].entry=entry;
1451 directory_stack[level].offset=tag_offset;
1453 directory_stack[level].directory=exif+offset;
1454 directory_stack[level].offset=tag_offset1;
1455 directory_stack[level].entry=0;
1457 if ((directory+2+(12*number_entries)) > (exif+length))
1459 offset=(size_t) ReadPropertyLong(endian,directory+2+(12*
1461 if ((offset != 0) && (offset < length) &&
1462 (level < (MaxDirectoryStack-2)))
1464 directory_stack[level].directory=exif+offset;
1465 directory_stack[level].entry=0;
1466 directory_stack[level].offset=tag_offset1;
1473 } while (level > 0);
1477 static MagickBooleanType GetXMPProperty(const Image *image,
1478 const char *property)
1502 profile=GetImageProfile(image,"xmp");
1503 if (profile == (StringInfo *) NULL)
1504 return(MagickFalse);
1505 if ((property == (const char *) NULL) || (*property == '\0'))
1506 return(MagickFalse);
1507 xmp_profile=StringInfoToString(profile);
1508 if (xmp_profile == (char *) NULL)
1509 return(MagickFalse);
1510 for (p=xmp_profile; *p != '\0'; p++)
1511 if ((*p == '<') && (*(p+1) == 'x'))
1513 exception=AcquireExceptionInfo();
1514 xmp=NewXMLTree((char *) p,exception);
1515 xmp_profile=DestroyString(xmp_profile);
1516 exception=DestroyExceptionInfo(exception);
1517 if (xmp == (XMLTreeInfo *) NULL)
1518 return(MagickFalse);
1520 rdf=GetXMLTreeChild(xmp,"rdf:RDF");
1521 if (rdf != (XMLTreeInfo *) NULL)
1523 if (image->properties == (void *) NULL)
1524 ((Image *) image)->properties=NewSplayTree(CompareSplayTreeString,
1525 RelinquishMagickMemory,RelinquishMagickMemory);
1526 description=GetXMLTreeChild(rdf,"rdf:Description");
1527 while (description != (XMLTreeInfo *) NULL)
1529 node=GetXMLTreeChild(description,(const char *) NULL);
1530 while (node != (XMLTreeInfo *) NULL)
1532 child=GetXMLTreeChild(node,(const char *) NULL);
1533 if (child == (XMLTreeInfo *) NULL)
1534 (void) AddValueToSplayTree((SplayTreeInfo *) image->properties,
1535 ConstantString(GetXMLTreeTag(node)),
1536 ConstantString(GetXMLTreeContent(node)));
1537 while (child != (XMLTreeInfo *) NULL)
1539 if (LocaleCompare(GetXMLTreeTag(child),"rdf:Seq") != 0)
1540 (void) AddValueToSplayTree((SplayTreeInfo *) image->properties,
1541 ConstantString(GetXMLTreeTag(child)),
1542 ConstantString(GetXMLTreeContent(child)));
1543 child=GetXMLTreeSibling(child);
1545 node=GetXMLTreeSibling(node);
1547 description=GetNextXMLTreeTag(description);
1550 xmp=DestroyXMLTree(xmp);
1554 static char *TracePSClippath(const unsigned char *blob,size_t length,
1555 const size_t magick_unused(columns),
1556 const size_t magick_unused(rows))
1579 path=AcquireString((char *) NULL);
1580 if (path == (char *) NULL)
1581 return((char *) NULL);
1582 message=AcquireString((char *) NULL);
1583 (void) FormatLocaleString(message,MaxTextExtent,"/ClipImage\n");
1584 (void) ConcatenateString(&path,message);
1585 (void) FormatLocaleString(message,MaxTextExtent,"{\n");
1586 (void) ConcatenateString(&path,message);
1587 (void) FormatLocaleString(message,MaxTextExtent," /c {curveto} bind def\n");
1588 (void) ConcatenateString(&path,message);
1589 (void) FormatLocaleString(message,MaxTextExtent," /l {lineto} bind def\n");
1590 (void) ConcatenateString(&path,message);
1591 (void) FormatLocaleString(message,MaxTextExtent," /m {moveto} bind def\n");
1592 (void) ConcatenateString(&path,message);
1593 (void) FormatLocaleString(message,MaxTextExtent,
1594 " /v {currentpoint 6 2 roll curveto} bind def\n");
1595 (void) ConcatenateString(&path,message);
1596 (void) FormatLocaleString(message,MaxTextExtent,
1597 " /y {2 copy curveto} bind def\n");
1598 (void) ConcatenateString(&path,message);
1599 (void) FormatLocaleString(message,MaxTextExtent,
1600 " /z {closepath} bind def\n");
1601 (void) ConcatenateString(&path,message);
1602 (void) FormatLocaleString(message,MaxTextExtent," newpath\n");
1603 (void) ConcatenateString(&path,message);
1605 The clipping path format is defined in "Adobe Photoshop File
1606 Formats Specification" version 6.0 downloadable from adobe.com.
1608 (void) ResetMagickMemory(point,0,sizeof(point));
1609 (void) ResetMagickMemory(first,0,sizeof(first));
1610 (void) ResetMagickMemory(last,0,sizeof(last));
1612 in_subpath=MagickFalse;
1615 selector=(ssize_t) ReadPropertyMSBShort(&blob,&length);
1621 if (knot_count != 0)
1628 Expected subpath length record.
1630 knot_count=(ssize_t) ReadPropertyMSBShort(&blob,&length);
1640 if (knot_count == 0)
1643 Unexpected subpath knot
1652 for (i=0; i < 3; i++)
1658 yy=ReadPropertyMSBLong(&blob,&length);
1659 xx=ReadPropertyMSBLong(&blob,&length);
1661 if (xx > 2147483647)
1662 x=(ssize_t) xx-4294967295-1;
1664 if (yy > 2147483647)
1665 y=(ssize_t) yy-4294967295-1;
1666 point[i].x=(double) x/4096/4096;
1667 point[i].y=1.0-(double) y/4096/4096;
1669 if (in_subpath == MagickFalse)
1671 (void) FormatLocaleString(message,MaxTextExtent," %g %g m\n",
1672 point[1].x,point[1].y);
1673 for (i=0; i < 3; i++)
1682 Handle special cases when Bezier curves are used to describe
1683 corners and straight lines.
1685 if ((last[1].x == last[2].x) && (last[1].y == last[2].y) &&
1686 (point[0].x == point[1].x) && (point[0].y == point[1].y))
1687 (void) FormatLocaleString(message,MaxTextExtent,
1688 " %g %g l\n",point[1].x,point[1].y);
1690 if ((last[1].x == last[2].x) && (last[1].y == last[2].y))
1691 (void) FormatLocaleString(message,MaxTextExtent,
1692 " %g %g %g %g v\n",point[0].x,point[0].y,
1693 point[1].x,point[1].y);
1695 if ((point[0].x == point[1].x) && (point[0].y == point[1].y))
1696 (void) FormatLocaleString(message,MaxTextExtent,
1697 " %g %g %g %g y\n",last[2].x,last[2].y,
1698 point[1].x,point[1].y);
1700 (void) FormatLocaleString(message,MaxTextExtent,
1701 " %g %g %g %g %g %g c\n",last[2].x,
1702 last[2].y,point[0].x,point[0].y,point[1].x,point[1].y);
1703 for (i=0; i < 3; i++)
1706 (void) ConcatenateString(&path,message);
1707 in_subpath=MagickTrue;
1710 Close the subpath if there are no more knots.
1712 if (knot_count == 0)
1715 Same special handling as above except we compare to the
1716 first point in the path and close the path.
1718 if ((last[1].x == last[2].x) && (last[1].y == last[2].y) &&
1719 (first[0].x == first[1].x) && (first[0].y == first[1].y))
1720 (void) FormatLocaleString(message,MaxTextExtent,
1721 " %g %g l z\n",first[1].x,first[1].y);
1723 if ((last[1].x == last[2].x) && (last[1].y == last[2].y))
1724 (void) FormatLocaleString(message,MaxTextExtent,
1725 " %g %g %g %g v z\n",first[0].x,first[0].y,
1726 first[1].x,first[1].y);
1728 if ((first[0].x == first[1].x) && (first[0].y == first[1].y))
1729 (void) FormatLocaleString(message,MaxTextExtent,
1730 " %g %g %g %g y z\n",last[2].x,last[2].y,
1731 first[1].x,first[1].y);
1733 (void) FormatLocaleString(message,MaxTextExtent,
1734 " %g %g %g %g %g %g c z\n",last[2].x,
1735 last[2].y,first[0].x,first[0].y,first[1].x,first[1].y);
1736 (void) ConcatenateString(&path,message);
1737 in_subpath=MagickFalse;
1753 Returns an empty PS path if the path has no knots.
1755 (void) FormatLocaleString(message,MaxTextExtent," eoclip\n");
1756 (void) ConcatenateString(&path,message);
1757 (void) FormatLocaleString(message,MaxTextExtent,"} bind def");
1758 (void) ConcatenateString(&path,message);
1759 message=DestroyString(message);
1763 static char *TraceSVGClippath(const unsigned char *blob,size_t length,
1764 const size_t columns,const size_t rows)
1787 path=AcquireString((char *) NULL);
1788 if (path == (char *) NULL)
1789 return((char *) NULL);
1790 message=AcquireString((char *) NULL);
1791 (void) FormatLocaleString(message,MaxTextExtent,
1792 "<?xml version=\"1.0\" encoding=\"iso-8859-1\"?>\n");
1793 (void) ConcatenateString(&path,message);
1794 (void) FormatLocaleString(message,MaxTextExtent,
1795 "<svg width=\"%.20g\" height=\"%.20g\">\n",(double) columns,(double) rows);
1796 (void) ConcatenateString(&path,message);
1797 (void) FormatLocaleString(message,MaxTextExtent,"<g>\n");
1798 (void) ConcatenateString(&path,message);
1799 (void) FormatLocaleString(message,MaxTextExtent,
1800 "<path style=\"fill:#00000000;stroke:#00000000;");
1801 (void) ConcatenateString(&path,message);
1802 (void) FormatLocaleString(message,MaxTextExtent,
1803 "stroke-width:0;stroke-antialiasing:false\" d=\"\n");
1804 (void) ConcatenateString(&path,message);
1805 (void) ResetMagickMemory(point,0,sizeof(point));
1806 (void) ResetMagickMemory(first,0,sizeof(first));
1807 (void) ResetMagickMemory(last,0,sizeof(last));
1809 in_subpath=MagickFalse;
1812 selector=(ssize_t) ReadPropertyMSBShort(&blob,&length);
1818 if (knot_count != 0)
1825 Expected subpath length record.
1827 knot_count=(ssize_t) ReadPropertyMSBShort(&blob,&length);
1837 if (knot_count == 0)
1840 Unexpected subpath knot.
1849 for (i=0; i < 3; i++)
1855 yy=ReadPropertyMSBLong(&blob,&length);
1856 xx=ReadPropertyMSBLong(&blob,&length);
1858 if (xx > 2147483647)
1859 x=(ssize_t) xx-4294967295-1;
1861 if (yy > 2147483647)
1862 y=(ssize_t) yy-4294967295-1;
1863 point[i].x=(double) x*columns/4096/4096;
1864 point[i].y=(double) y*rows/4096/4096;
1866 if (in_subpath == MagickFalse)
1868 (void) FormatLocaleString(message,MaxTextExtent,"M %g,%g\n",
1869 point[1].x,point[1].y);
1870 for (i=0; i < 3; i++)
1878 if ((last[1].x == last[2].x) && (last[1].y == last[2].y) &&
1879 (point[0].x == point[1].x) && (point[0].y == point[1].y))
1880 (void) FormatLocaleString(message,MaxTextExtent,"L %g,%g\n",
1881 point[1].x,point[1].y);
1883 (void) FormatLocaleString(message,MaxTextExtent,
1884 "C %g,%g %g,%g %g,%g\n",last[2].x,last[2].y,
1885 point[0].x,point[0].y,point[1].x,point[1].y);
1886 for (i=0; i < 3; i++)
1889 (void) ConcatenateString(&path,message);
1890 in_subpath=MagickTrue;
1893 Close the subpath if there are no more knots.
1895 if (knot_count == 0)
1897 if ((last[1].x == last[2].x) && (last[1].y == last[2].y) &&
1898 (first[0].x == first[1].x) && (first[0].y == first[1].y))
1899 (void) FormatLocaleString(message,MaxTextExtent,
1900 "L %g,%g Z\n",first[1].x,first[1].y);
1903 (void) FormatLocaleString(message,MaxTextExtent,
1904 "C %g,%g %g,%g %g,%g Z\n",last[2].x,
1905 last[2].y,first[0].x,first[0].y,first[1].x,first[1].y);
1906 (void) ConcatenateString(&path,message);
1908 in_subpath=MagickFalse;
1924 Return an empty SVG image if the path does not have knots.
1926 (void) FormatLocaleString(message,MaxTextExtent,"\"/>\n");
1927 (void) ConcatenateString(&path,message);
1928 (void) FormatLocaleString(message,MaxTextExtent,"</g>\n");
1929 (void) ConcatenateString(&path,message);
1930 (void) FormatLocaleString(message,MaxTextExtent,"</svg>\n");
1931 (void) ConcatenateString(&path,message);
1932 message=DestroyString(message);
1936 MagickExport const char *GetImageProperty(const Image *image,
1937 const char *property)
1954 assert(image != (Image *) NULL);
1955 assert(image->signature == MagickSignature);
1956 if (image->debug != MagickFalse)
1957 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1958 p=(const char *) NULL;
1959 if (image->properties != (void *) NULL)
1961 if (property == (const char *) NULL)
1963 ResetSplayTreeIterator((SplayTreeInfo *) image->properties);
1964 p=(const char *) GetNextValueInSplayTree((SplayTreeInfo *)
1968 if (LocaleNCompare("fx:",property,3) != 0)
1970 p=(const char *) GetValueFromSplayTree((SplayTreeInfo *)
1971 image->properties,property);
1972 if (p != (const char *) NULL)
1976 if ((property == (const char *) NULL) ||
1977 (strchr(property,':') == (char *) NULL))
1979 exception=(&((Image *) image)->exception);
1984 if (LocaleNCompare("8bim:",property,5) == 0)
1986 if ((Get8BIMProperty(image,property) != MagickFalse) &&
1987 (image->properties != (void *) NULL))
1989 p=(const char *) GetValueFromSplayTree((SplayTreeInfo *)
1990 image->properties,property);
1999 if (LocaleNCompare("exif:",property,5) == 0)
2001 if ((GetEXIFProperty(image,property) != MagickFalse) &&
2002 (image->properties != (void *) NULL))
2004 p=(const char *) GetValueFromSplayTree((SplayTreeInfo *)
2005 image->properties,property);
2014 if (LocaleNCompare("fx:",property,3) == 0)
2016 fx_info=AcquireFxInfo(image,property+3);
2017 status=FxEvaluateChannelExpression(fx_info,DefaultChannels,0,0,&alpha,
2019 fx_info=DestroyFxInfo(fx_info);
2020 if (status != MagickFalse)
2023 value[MaxTextExtent];
2025 (void) FormatLocaleString(value,MaxTextExtent,"%.*g",
2026 GetMagickPrecision(),(double) alpha);
2027 (void) SetImageProperty((Image *) image,property,value);
2029 if (image->properties != (void *) NULL)
2031 p=(const char *) GetValueFromSplayTree((SplayTreeInfo *)
2032 image->properties,property);
2041 if (LocaleNCompare("iptc:",property,5) == 0)
2043 if ((GetIPTCProperty(image,property) != MagickFalse) &&
2044 (image->properties != (void *) NULL))
2046 p=(const char *) GetValueFromSplayTree((SplayTreeInfo *)
2047 image->properties,property);
2056 if (LocaleNCompare("pixel:",property,6) == 0)
2061 GetMagickPixelPacket(image,&pixel);
2062 fx_info=AcquireFxInfo(image,property+6);
2063 status=FxEvaluateChannelExpression(fx_info,RedChannel,0,0,&alpha,
2065 pixel.red=(MagickRealType) QuantumRange*alpha;
2066 status|=FxEvaluateChannelExpression(fx_info,GreenChannel,0,0,&alpha,
2068 pixel.green=(MagickRealType) QuantumRange*alpha;
2069 status|=FxEvaluateChannelExpression(fx_info,BlueChannel,0,0,&alpha,
2071 pixel.blue=(MagickRealType) QuantumRange*alpha;
2072 status|=FxEvaluateChannelExpression(fx_info,OpacityChannel,0,0,&alpha,
2074 pixel.opacity=(MagickRealType) QuantumRange*(1.0-alpha);
2075 if (image->colorspace == CMYKColorspace)
2077 status|=FxEvaluateChannelExpression(fx_info,BlackChannel,0,0,
2079 pixel.index=(MagickRealType) QuantumRange*alpha;
2081 fx_info=DestroyFxInfo(fx_info);
2082 if (status != MagickFalse)
2085 name[MaxTextExtent];
2087 (void) QueryMagickColorname(image,&pixel,SVGCompliance,name,
2089 (void) SetImageProperty((Image *) image,property,name);
2090 return(GetImageProperty(image,property));
2098 if (LocaleNCompare("xmp:",property,4) == 0)
2100 if ((GetXMPProperty(image,property) != MagickFalse) &&
2101 (image->properties != (void *) NULL))
2103 p=(const char *) GetValueFromSplayTree((SplayTreeInfo *)
2104 image->properties,property);
2117 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2121 + G e t M a g i c k P r o p e r t y %
2125 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2127 % GetMagickProperty() gets a value associated with an image property.
2129 % The format of the GetMagickProperty method is:
2131 % const char *GetMagickProperty(const ImageInfo *image_info,
2132 % Image *image,const char *key)
2134 % A description of each parameter follows:
2136 % o image_info: the image info.
2138 % o image: the image.
2143 MagickExport const char *GetMagickProperty(const ImageInfo *image_info,
2144 Image *image,const char *property)
2147 value[MaxTextExtent],
2148 filename[MaxTextExtent];
2155 if (LocaleNCompare("base",property,4) == 0)
2157 GetPathComponent(image->magick_filename,BasePath,filename);
2158 (void) CopyMagickString(value,filename,MaxTextExtent);
2165 if (LocaleNCompare("channels",property,8) == 0)
2170 (void) FormatLocaleString(value,MaxTextExtent,"%s",
2171 CommandOptionToMnemonic(MagickColorspaceOptions,(ssize_t)
2172 image->colorspace));
2174 if (image->matte != MagickFalse)
2175 (void) ConcatenateMagickString(value,"a",MaxTextExtent);
2178 if (LocaleNCompare("colorspace",property,10) == 0)
2184 Image storage class and colorspace.
2186 colorspace=image->colorspace;
2187 if (IsGrayImage(image,&image->exception) != MagickFalse)
2188 colorspace=GRAYColorspace;
2189 (void) FormatLocaleString(value,MaxTextExtent,"%s",
2190 CommandOptionToMnemonic(MagickColorspaceOptions,(ssize_t)
2194 if (LocaleNCompare("copyright",property,9) == 0)
2196 (void) CopyMagickString(value,GetMagickCopyright(),MaxTextExtent);
2203 if (LocaleNCompare("depth",property,5) == 0)
2205 (void) FormatLocaleString(value,MaxTextExtent,"%.20g",(double)
2209 if (LocaleNCompare("directory",property,9) == 0)
2211 GetPathComponent(image->magick_filename,HeadPath,filename);
2212 (void) CopyMagickString(value,filename,MaxTextExtent);
2219 if (LocaleNCompare("extension",property,9) == 0)
2221 GetPathComponent(image->magick_filename,ExtensionPath,filename);
2222 (void) CopyMagickString(value,filename,MaxTextExtent);
2229 if (LocaleNCompare("group",property,5) == 0)
2231 (void) FormatLocaleString(value,MaxTextExtent,"0x%lx",
2232 (unsigned long) image_info->group);
2239 if (LocaleNCompare("height",property,6) == 0)
2241 (void) FormatLocaleString(value,MaxTextExtent,"%.20g",
2242 image->magick_rows != 0 ? (double) image->magick_rows : 256.0);
2249 if (LocaleNCompare("input",property,5) == 0)
2251 (void) CopyMagickString(value,image->filename,MaxTextExtent);
2258 if (LocaleNCompare("kurtosis",property,8) == 0)
2264 (void) GetImageChannelKurtosis(image,image_info->channel,&kurtosis,
2265 &skewness,&image->exception);
2266 (void) FormatLocaleString(value,MaxTextExtent,"%.*g",
2267 GetMagickPrecision(),kurtosis);
2274 if (LocaleNCompare("magick",property,6) == 0)
2276 (void) CopyMagickString(value,image->magick,MaxTextExtent);
2279 if (LocaleNCompare("max",property,3) == 0)
2285 (void) GetImageChannelRange(image,image_info->channel,&minimum,
2286 &maximum,&image->exception);
2287 (void) FormatLocaleString(value,MaxTextExtent,"%.*g",
2288 GetMagickPrecision(),maximum);
2291 if (LocaleNCompare("mean",property,4) == 0)
2297 (void) GetImageChannelMean(image,image_info->channel,&mean,
2298 &standard_deviation,&image->exception);
2299 (void) FormatLocaleString(value,MaxTextExtent,"%.*g",
2300 GetMagickPrecision(),mean);
2303 if (LocaleNCompare("min",property,3) == 0)
2309 (void) GetImageChannelRange(image,image_info->channel,&minimum,
2310 &maximum,&image->exception);
2311 (void) FormatLocaleString(value,MaxTextExtent,"%.*g",
2312 GetMagickPrecision(),minimum);
2319 if (LocaleNCompare("name",property,4) == 0)
2321 (void) CopyMagickString(value,filename,MaxTextExtent);
2328 if (LocaleNCompare("opaque",property,6) == 0)
2333 opaque=IsOpaqueImage(image,&image->exception);
2334 (void) CopyMagickString(value,opaque == MagickFalse ? "false" :
2335 "true",MaxTextExtent);
2338 if (LocaleNCompare("output",property,6) == 0)
2340 (void) CopyMagickString(value,image_info->filename,MaxTextExtent);
2347 if (LocaleNCompare("page",property,4) == 0)
2349 (void) FormatLocaleString(value,MaxTextExtent,"%.20g",(double)
2350 GetImageIndexInList(image)+1);
2357 if (LocaleNCompare("size",property,4) == 0)
2360 format[MaxTextExtent];
2362 (void) FormatMagickSize(GetBlobSize(image),MagickFalse,format);
2363 (void) FormatLocaleString(value,MaxTextExtent,"%sB",format);
2366 if (LocaleNCompare("scenes",property,6) == 0)
2368 (void) FormatLocaleString(value,MaxTextExtent,"%.20g",(double)
2369 GetImageListLength(image));
2372 if (LocaleNCompare("scene",property,5) == 0)
2374 (void) FormatLocaleString(value,MaxTextExtent,"%.20g",(double)
2376 if (image_info->number_scenes != 0)
2377 (void) FormatLocaleString(value,MaxTextExtent,"%.20g",(double)
2381 if (LocaleNCompare("skewness",property,8) == 0)
2387 (void) GetImageChannelKurtosis(image,image_info->channel,&kurtosis,
2388 &skewness,&image->exception);
2389 (void) FormatLocaleString(value,MaxTextExtent,"%.*g",
2390 GetMagickPrecision(),skewness);
2393 if ((LocaleNCompare("standard-deviation",property,18) == 0) ||
2394 (LocaleNCompare("standard_deviation",property,18) == 0))
2400 (void) GetImageChannelMean(image,image_info->channel,&mean,
2401 &standard_deviation,&image->exception);
2402 (void) FormatLocaleString(value,MaxTextExtent,"%.*g",
2403 GetMagickPrecision(),standard_deviation);
2410 if (LocaleNCompare("unique",property,6) == 0)
2412 (void) CopyMagickString(filename,image_info->unique,MaxTextExtent);
2413 (void) CopyMagickString(value,filename,MaxTextExtent);
2420 if (LocaleNCompare("version",property,7) == 0)
2422 (void) CopyMagickString(value,GetMagickVersion((size_t *) NULL),
2430 if (LocaleNCompare("width",property,5) == 0)
2432 (void) FormatLocaleString(value,MaxTextExtent,"%.20g",(double)
2433 (image->magick_columns != 0 ? image->magick_columns : 256));
2440 if (LocaleNCompare("xresolution",property,11) == 0)
2442 (void) FormatLocaleString(value,MaxTextExtent,"%g",
2443 image->x_resolution);
2450 if (LocaleNCompare("yresolution",property,11) == 0)
2452 (void) FormatLocaleString(value,MaxTextExtent,"%g",
2453 image->y_resolution);
2460 if (LocaleNCompare("zero",property,4) == 0)
2462 (void) CopyMagickString(filename,image_info->zero,MaxTextExtent);
2463 (void) CopyMagickString(value,filename,MaxTextExtent);
2471 if (image->properties == (void *) NULL)
2472 image->properties=NewSplayTree(CompareSplayTreeString,
2473 RelinquishMagickMemory,RelinquishMagickMemory);
2474 (void) AddValueToSplayTree((SplayTreeInfo *) image->properties,
2475 ConstantString(property),ConstantString(value));
2477 return(GetImageProperty(image,property));
2481 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2485 % G e t N e x t I m a g e P r o p e r t y %
2489 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2491 % GetNextImageProperty() gets the next image property value.
2493 % The format of the GetNextImageProperty method is:
2495 % char *GetNextImageProperty(const Image *image)
2497 % A description of each parameter follows:
2499 % o image: the image.
2502 MagickExport char *GetNextImageProperty(const Image *image)
2504 assert(image != (Image *) NULL);
2505 assert(image->signature == MagickSignature);
2506 if (image->debug != MagickFalse)
2507 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
2509 if (image->properties == (void *) NULL)
2510 return((char *) NULL);
2511 return((char *) GetNextKeyInSplayTree((SplayTreeInfo *) image->properties));
2515 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2519 % I n t e r p r e t I m a g e P r o p e r t i e s %
2523 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2525 % InterpretImageProperties() replaces any embedded formatting characters with
2526 % the appropriate image property and returns the interpretted text.
2528 % The format of the InterpretImageProperties method is:
2530 % char *InterpretImageProperties(const ImageInfo *image_info,Image *image,
2531 % const char *embed_text)
2533 % A description of each parameter follows:
2535 % o image_info: the image info.
2537 % o image: the image.
2539 % o embed_text: the address of a character string containing the embedded
2540 % formatting characters.
2543 MagickExport char *InterpretImageProperties(const ImageInfo *image_info,
2544 Image *image,const char *embed_text)
2547 filename[MaxTextExtent],
2567 assert(image != (Image *) NULL);
2568 assert(image->signature == MagickSignature);
2569 if (image->debug != MagickFalse)
2570 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
2571 if ((embed_text == (const char *) NULL) || (*embed_text == '\0'))
2572 return((char *) NULL);
2573 text=(char *) embed_text;
2574 if ((*text == '@') && ((*(text+1) == '-') ||
2575 (IsPathAccessible(text+1) != MagickFalse)))
2576 return(FileToString(embed_text+1,~0,&image->exception));
2578 Translate any embedded format characters.
2580 interpret_text=AcquireString(text);
2581 extent=MaxTextExtent;
2583 for (q=interpret_text; *p != '\0'; p++)
2586 if ((size_t) (q-interpret_text+MaxTextExtent) >= extent)
2588 extent+=MaxTextExtent;
2589 interpret_text=(char *) ResizeQuantumMemory(interpret_text,extent+
2590 MaxTextExtent+1,sizeof(*interpret_text));
2591 if (interpret_text == (char *) NULL)
2593 q=interpret_text+strlen(interpret_text);
2596 Process formatting characters in text.
2598 if ((*p == '\\') && (*(p+1) == 'r'))
2604 if ((*p == '\\') && (*(p+1) == 'n'))
2627 format[MaxTextExtent];
2632 (void) FormatLocaleString(format,MaxTextExtent,"%.20g",(double)
2634 if (image->extent != (MagickSizeType) ((size_t) image->extent))
2635 (void) FormatMagickSize(image->extent,MagickFalse,format);
2636 q+=ConcatenateMagickString(q,format,extent);
2637 q+=ConcatenateMagickString(q,"B",extent);
2645 value=GetImageProperty(image,"comment");
2646 if (value == (const char *) NULL)
2648 length=strlen(value);
2649 if ((size_t) (q-interpret_text+length+1) >= extent)
2652 interpret_text=(char *) ResizeQuantumMemory(interpret_text,extent+
2653 MaxTextExtent,sizeof(*interpret_text));
2654 if (interpret_text == (char *) NULL)
2656 q=interpret_text+strlen(interpret_text);
2658 (void) CopyMagickString(q,value,extent);
2668 Label segment is the base of the filename.
2670 if (*image->magick_filename == '\0')
2679 GetPathComponent(image->magick_filename,HeadPath,filename);
2680 q+=CopyMagickString(q,filename,extent);
2688 GetPathComponent(image->magick_filename,ExtensionPath,filename);
2689 q+=CopyMagickString(q,filename,extent);
2697 GetPathComponent(image->magick_filename,TailPath,filename);
2698 q+=CopyMagickString(q,filename,extent);
2706 GetPathComponent(image->magick_filename,BasePath,filename);
2707 q+=CopyMagickString(q,filename,extent);
2718 q+=FormatLocaleString(q,extent,"%.20gx%.20g%+.20g%+.20g",(double)
2719 image->page.width,(double) image->page.height,(double) image->page.x,
2720 (double) image->page.y);
2728 q+=FormatLocaleString(q,extent,"%.20g",(double) (image->rows != 0 ?
2729 image->rows : image->magick_rows));
2737 q+=CopyMagickString(q,image->filename,extent);
2743 Number of unique colors.
2745 q+=FormatLocaleString(q,extent,"%.20g",(double) GetNumberColors(image,
2746 (FILE *) NULL,&image->exception));
2754 value=GetImageProperty(image,"label");
2755 if (value == (const char *) NULL)
2757 length=strlen(value);
2758 if ((size_t) (q-interpret_text+length+1) >= extent)
2761 interpret_text=(char *) ResizeQuantumMemory(interpret_text,extent+
2762 MaxTextExtent,sizeof(*interpret_text));
2763 if (interpret_text == (char *) NULL)
2765 q=interpret_text+strlen(interpret_text);
2767 q+=CopyMagickString(q,value,extent);
2775 q+=CopyMagickString(q,image->magick,extent);
2781 Image magick filename.
2783 q+=CopyMagickString(q,image->magick_filename,extent);
2789 Number of images in the list.
2791 q+=FormatLocaleString(q,extent,"%.20g",(double)
2792 GetImageListLength(image));
2798 Image output filename.
2800 q+=CopyMagickString(q,image_info->filename,extent);
2806 Image index in list.
2808 q+=FormatLocaleString(q,extent,"%.20g",(double)
2809 GetImageIndexInList(image));
2817 q+=FormatLocaleString(q,extent,"%.20g",(double)
2818 MAGICKCORE_QUANTUM_DEPTH);
2827 Image storage class and colorspace.
2829 colorspace=image->colorspace;
2830 if (IsGrayImage(image,&image->exception) != MagickFalse)
2831 colorspace=GRAYColorspace;
2832 q+=FormatLocaleString(q,extent,"%s%s%s",CommandOptionToMnemonic(
2833 MagickClassOptions,(ssize_t) image->storage_class),
2834 CommandOptionToMnemonic(MagickColorspaceOptions,(ssize_t) colorspace),
2835 image->matte != MagickFalse ? "Matte" : "");
2843 if (image_info->number_scenes == 0)
2844 q+=FormatLocaleString(q,extent,"%.20g",(double) image->scene);
2846 q+=FormatLocaleString(q,extent,"%.20g",(double) image_info->scene);
2854 (void) CopyMagickString(filename,image_info->unique,extent);
2855 q+=CopyMagickString(q,filename,extent);
2863 q+=FormatLocaleString(q,extent,"%.20g",(double) (image->columns != 0 ?
2864 image->columns : image->magick_columns));
2870 Image horizontal resolution.
2872 q+=FormatLocaleString(q,extent,"%g %s",image->x_resolution,
2873 CommandOptionToMnemonic(MagickResolutionOptions,(ssize_t)
2880 Image vertical resolution.
2882 q+=FormatLocaleString(q,extent,"%g %s",image->y_resolution,
2883 CommandOptionToMnemonic(MagickResolutionOptions,(ssize_t)
2892 q+=FormatLocaleString(q,extent,"%.20g",(double) image->depth);
2898 Image alpha channel.
2900 q+=FormatLocaleString(q,extent,"%s",CommandOptionToMnemonic(
2901 MagickBooleanOptions,(ssize_t) image->matte));
2907 Image compression method.
2909 q+=FormatLocaleString(q,extent,"%s",CommandOptionToMnemonic(
2910 MagickCompressOptions,(ssize_t) image->compression));
2916 Image dispose method.
2918 q+=FormatLocaleString(q,extent,"%s",CommandOptionToMnemonic(
2919 MagickDisposeOptions,(ssize_t) image->dispose));
2924 q+=FormatLocaleString(q,extent,"%.20gx%.20g",(double)
2925 image->magick_columns,(double) image->magick_rows);
2930 q+=FormatLocaleString(q,extent,"%.20g",(double) image->page.height);
2935 q+=FormatLocaleString(q,extent,"%+ld%+ld",(long) image->page.x,(long)
2941 q+=FormatLocaleString(q,extent,"%.20gx%.20g",(double) image->page.width,
2942 (double) image->page.height);
2947 q+=FormatLocaleString(q,extent,"%.20g",(double) image->quality);
2955 if (image_info->number_scenes == 0)
2956 q+=CopyMagickString(q,"2147483647",extent);
2958 q+=FormatLocaleString(q,extent,"%.20g",(double) (image_info->scene+
2959 image_info->number_scenes));
2964 q+=FormatLocaleString(q,extent,"%.20g",(double) image->delay);
2969 q+=FormatLocaleString(q,extent,"%.20g",(double) image->page.width);
2974 q+=FormatLocaleString(q,extent,"%+.20g",(double) image->page.x);
2979 q+=FormatLocaleString(q,extent,"%+.20g",(double) image->page.y);
2987 (void) CopyMagickString(filename,image_info->zero,extent);
2988 q+=CopyMagickString(q,filename,extent);
2994 pattern[MaxTextExtent];
3006 if (strchr(p,']') == (char *) NULL)
3010 for (i=0; (i < (MaxTextExtent-1L)) && (*p != '\0'); i++)
3021 value=GetImageProperty(image,pattern);
3022 if (value != (const char *) NULL)
3024 length=strlen(value);
3025 if ((size_t) (q-interpret_text+length+1) >= extent)
3028 interpret_text=(char *) ResizeQuantumMemory(interpret_text,
3029 extent+MaxTextExtent,sizeof(*interpret_text));
3030 if (interpret_text == (char *) NULL)
3032 q=interpret_text+strlen(interpret_text);
3034 (void) CopyMagickString(q,value,extent);
3039 if (IsGlob(pattern) != MagickFalse)
3042 Iterate over image properties.
3044 ResetImagePropertyIterator(image);
3045 key=GetNextImageProperty(image);
3046 while (key != (const char *) NULL)
3048 if (GlobExpression(key,pattern,MagickTrue) != MagickFalse)
3050 value=GetImageProperty(image,key);
3051 if (value != (const char *) NULL)
3053 length=strlen(key)+strlen(value)+2;
3054 if ((size_t) (q-interpret_text+length+1) >= extent)
3057 interpret_text=(char *) ResizeQuantumMemory(
3058 interpret_text,extent+MaxTextExtent,
3059 sizeof(*interpret_text));
3060 if (interpret_text == (char *) NULL)
3062 q=interpret_text+strlen(interpret_text);
3064 q+=FormatLocaleString(q,extent,"%s=%s\n",key,value);
3067 key=GetNextImageProperty(image);
3070 value=GetMagickProperty(image_info,image,pattern);
3071 if (value != (const char *) NULL)
3073 length=strlen(value);
3074 if ((size_t) (q-interpret_text+length+1) >= extent)
3077 interpret_text=(char *) ResizeQuantumMemory(interpret_text,
3078 extent+MaxTextExtent,sizeof(*interpret_text));
3079 if (interpret_text == (char *) NULL)
3081 q=interpret_text+strlen(interpret_text);
3083 (void) CopyMagickString(q,value,extent);
3087 if (image_info == (ImageInfo *) NULL)
3089 value=GetImageOption(image_info,pattern);
3090 if (value != (char *) NULL)
3092 length=strlen(value);
3093 if ((size_t) (q-interpret_text+length+1) >= extent)
3096 interpret_text=(char *) ResizeQuantumMemory(interpret_text,
3097 extent+MaxTextExtent,sizeof(*interpret_text));
3098 if (interpret_text == (char *) NULL)
3100 q=interpret_text+strlen(interpret_text);
3102 (void) CopyMagickString(q,value,extent);
3116 page=GetImageBoundingBox(image,&image->exception);
3117 q+=FormatLocaleString(q,MaxTextExtent,"%.20gx%.20g%+.20g%+.20g",
3118 (double) page.width,(double) page.height,(double) page.x,(double)
3127 (void) SignatureImage(image);
3128 value=GetImageProperty(image,"signature");
3129 if (value == (const char *) NULL)
3131 q+=CopyMagickString(q,value,extent);
3148 if (text != (const char *) embed_text)
3149 text=DestroyString(text);
3150 (void) SubstituteString(&interpret_text,"<","<");
3151 (void) SubstituteString(&interpret_text,">",">");
3152 return(interpret_text);
3156 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3160 % R e m o v e I m a g e P r o p e r t y %
3164 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3166 % RemoveImageProperty() removes a property from the image and returns its
3169 % The format of the RemoveImageProperty method is:
3171 % char *RemoveImageProperty(Image *image,const char *property)
3173 % A description of each parameter follows:
3175 % o image: the image.
3177 % o property: the image property.
3180 MagickExport char *RemoveImageProperty(Image *image,
3181 const char *property)
3186 assert(image != (Image *) NULL);
3187 assert(image->signature == MagickSignature);
3188 if (image->debug != MagickFalse)
3189 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
3191 if (image->properties == (void *) NULL)
3192 return((char *) NULL);
3193 value=(char *) RemoveNodeFromSplayTree((SplayTreeInfo *) image->properties,
3199 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3203 % 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 %
3207 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3209 % ResetImagePropertyIterator() resets the image properties iterator. Use it
3210 % in conjunction with GetNextImageProperty() to iterate over all the values
3211 % associated with an image property.
3213 % The format of the ResetImagePropertyIterator method is:
3215 % ResetImagePropertyIterator(Image *image)
3217 % A description of each parameter follows:
3219 % o image: the image.
3222 MagickExport void ResetImagePropertyIterator(const Image *image)
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)
3231 ResetSplayTreeIterator((SplayTreeInfo *) image->properties);
3235 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3239 % S e t I m a g e P r o p e r t y %
3243 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3245 % SetImageProperty() associates an value with an image property.
3247 % The format of the SetImageProperty method is:
3249 % MagickBooleanType SetImageProperty(Image *image,const char *property,
3250 % const char *value)
3252 % A description of each parameter follows:
3254 % o image: the image.
3256 % o property: the image property.
3258 % o values: the image property values.
3261 MagickExport MagickBooleanType SetImageProperty(Image *image,
3262 const char *property,const char *value)
3273 assert(image != (Image *) NULL);
3274 assert(image->signature == MagickSignature);
3275 if (image->debug != MagickFalse)
3276 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
3278 if (image->properties == (void *) NULL)
3279 image->properties=NewSplayTree(CompareSplayTreeString,
3280 RelinquishMagickMemory,RelinquishMagickMemory);
3281 if ((value == (const char *) NULL) || (*value == '\0'))
3282 return(DeleteImageProperty(image,property));
3284 exception=(&image->exception);
3290 if (LocaleCompare(property,"background") == 0)
3292 (void) QueryColorDatabase(value,&image->background_color,exception);
3295 if (LocaleCompare(property,"bias") == 0)
3297 image->bias=SiPrefixToDouble(value,QuantumRange);
3300 status=AddValueToSplayTree((SplayTreeInfo *) image->properties,
3301 ConstantString(property),ConstantString(value));
3307 if (LocaleCompare(property,"colorspace") == 0)
3312 colorspace=ParseCommandOption(MagickColorspaceOptions,MagickFalse,
3316 (void) SetImageColorspace(image,(ColorspaceType) colorspace);
3319 if (LocaleCompare(property,"compose") == 0)
3324 compose=ParseCommandOption(MagickComposeOptions,MagickFalse,value);
3327 image->compose=(CompositeOperator) compose;
3330 if (LocaleCompare(property,"compress") == 0)
3335 compression=ParseCommandOption(MagickCompressOptions,MagickFalse,
3337 if (compression < 0)
3339 image->compression=(CompressionType) compression;
3342 status=AddValueToSplayTree((SplayTreeInfo *) image->properties,
3343 ConstantString(property),ConstantString(value));
3349 if (LocaleCompare(property,"delay") == 0)
3354 flags=ParseGeometry(value,&geometry_info);
3355 if ((flags & GreaterValue) != 0)
3357 if (image->delay > (size_t) floor(geometry_info.rho+0.5))
3358 image->delay=(size_t) floor(geometry_info.rho+0.5);
3361 if ((flags & LessValue) != 0)
3363 if (image->delay < (size_t) floor(geometry_info.rho+0.5))
3364 image->ticks_per_second=(ssize_t)
3365 floor(geometry_info.sigma+0.5);
3368 image->delay=(size_t) floor(geometry_info.rho+0.5);
3369 if ((flags & SigmaValue) != 0)
3370 image->ticks_per_second=(ssize_t) floor(geometry_info.sigma+0.5);
3373 if (LocaleCompare(property,"density") == 0)
3378 flags=ParseGeometry(value,&geometry_info);
3379 image->x_resolution=geometry_info.rho;
3380 image->y_resolution=geometry_info.sigma;
3381 if ((flags & SigmaValue) == 0)
3382 image->y_resolution=image->x_resolution;
3384 if (LocaleCompare(property,"depth") == 0)
3386 image->depth=StringToUnsignedLong(value);
3389 if (LocaleCompare(property,"dispose") == 0)
3394 dispose=ParseCommandOption(MagickDisposeOptions,MagickFalse,value);
3397 image->dispose=(DisposeType) dispose;
3400 status=AddValueToSplayTree((SplayTreeInfo *) image->properties,
3401 ConstantString(property),ConstantString(value));
3407 if (LocaleCompare(property,"gravity") == 0)
3412 gravity=ParseCommandOption(MagickGravityOptions,MagickFalse,value);
3415 image->gravity=(GravityType) gravity;
3418 status=AddValueToSplayTree((SplayTreeInfo *) image->properties,
3419 ConstantString(property),ConstantString(value));
3425 if (LocaleCompare(property,"intent") == 0)
3430 rendering_intent=ParseCommandOption(MagickIntentOptions,MagickFalse,
3432 if (rendering_intent < 0)
3434 image->rendering_intent=(RenderingIntent) rendering_intent;
3437 if (LocaleCompare(property,"interpolate") == 0)
3442 interpolate=ParseCommandOption(MagickInterpolateOptions,MagickFalse,
3444 if (interpolate < 0)
3446 image->interpolate=(InterpolatePixelMethod) interpolate;
3449 status=AddValueToSplayTree((SplayTreeInfo *) image->properties,
3450 ConstantString(property),ConstantString(value));
3456 if (LocaleCompare(property,"loop") == 0)
3458 image->iterations=StringToUnsignedLong(value);
3461 status=AddValueToSplayTree((SplayTreeInfo *) image->properties,
3462 ConstantString(property),ConstantString(value));
3468 if (LocaleCompare(property,"page") == 0)
3473 geometry=GetPageGeometry(value);
3474 flags=ParseAbsoluteGeometry(geometry,&image->page);
3475 geometry=DestroyString(geometry);
3478 if (LocaleCompare(property,"profile") == 0)
3486 image_info=AcquireImageInfo();
3487 (void) CopyMagickString(image_info->filename,value,MaxTextExtent);
3488 (void) SetImageInfo(image_info,1,exception);
3489 profile=FileToStringInfo(image_info->filename,~0UL,exception);
3490 if (profile != (StringInfo *) NULL)
3491 status=SetImageProfile(image,image_info->magick,profile);
3492 image_info=DestroyImageInfo(image_info);
3495 status=AddValueToSplayTree((SplayTreeInfo *) image->properties,
3496 ConstantString(property),ConstantString(value));
3502 if (LocaleCompare(property,"rendering-intent") == 0)
3507 rendering_intent=ParseCommandOption(MagickIntentOptions,MagickFalse,
3509 if (rendering_intent < 0)
3511 image->rendering_intent=(RenderingIntent) rendering_intent;
3514 status=AddValueToSplayTree((SplayTreeInfo *) image->properties,
3515 ConstantString(property),ConstantString(value));
3521 if (LocaleCompare(property,"tile-offset") == 0)
3526 geometry=GetPageGeometry(value);
3527 flags=ParseAbsoluteGeometry(geometry,&image->tile_offset);
3528 geometry=DestroyString(geometry);
3531 status=AddValueToSplayTree((SplayTreeInfo *) image->properties,
3532 ConstantString(property),ConstantString(value));
3538 if (LocaleCompare(property,"units") == 0)
3543 units=ParseCommandOption(MagickResolutionOptions,MagickFalse,value);
3546 image->units=(ResolutionType) units;
3549 status=AddValueToSplayTree((SplayTreeInfo *) image->properties,
3550 ConstantString(property),ConstantString(value));
3555 status=AddValueToSplayTree((SplayTreeInfo *) image->properties,
3556 ConstantString(property),ConstantString(value));