2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6 % PPPP RRRR OOO PPPP EEEEE RRRR TTTTT Y Y %
7 % P P R R O O P P E R R T Y Y %
8 % PPPP RRRR O O PPPP EEE RRRR T Y %
9 % P R R O O P E R R T Y %
10 % P R R OOO P EEEEE R R T Y %
13 % MagickCore Property Methods %
20 % Copyright 1999-2011 ImageMagick Studio LLC, a non-profit organization %
21 % dedicated to making software imaging solutions freely available. %
23 % You may not use this file except in compliance with the License. You may %
24 % obtain a copy of the License at %
26 % http://www.imagemagick.org/script/license.php %
28 % Unless required by applicable law or agreed to in writing, software %
29 % distributed under the License is distributed on an "AS IS" BASIS, %
30 % WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. %
31 % See the License for the specific language governing permissions and %
32 % limitations under the License. %
34 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
43 #include "MagickCore/studio.h"
44 #include "MagickCore/attribute.h"
45 #include "MagickCore/cache.h"
46 #include "MagickCore/color.h"
47 #include "MagickCore/compare.h"
48 #include "MagickCore/constitute.h"
49 #include "MagickCore/draw.h"
50 #include "MagickCore/effect.h"
51 #include "MagickCore/exception.h"
52 #include "MagickCore/exception-private.h"
53 #include "MagickCore/fx.h"
54 #include "MagickCore/fx-private.h"
55 #include "MagickCore/gem.h"
56 #include "MagickCore/geometry.h"
57 #include "MagickCore/histogram.h"
58 #include "MagickCore/image.h"
59 #include "MagickCore/image.h"
60 #include "MagickCore/layer.h"
61 #include "MagickCore/list.h"
62 #include "MagickCore/magick.h"
63 #include "MagickCore/memory_.h"
64 #include "MagickCore/monitor.h"
65 #include "MagickCore/montage.h"
66 #include "MagickCore/option.h"
67 #include "MagickCore/profile.h"
68 #include "MagickCore/property.h"
69 #include "MagickCore/quantum.h"
70 #include "MagickCore/resource_.h"
71 #include "MagickCore/splay-tree.h"
72 #include "MagickCore/signature-private.h"
73 #include "MagickCore/statistic.h"
74 #include "MagickCore/string_.h"
75 #include "MagickCore/string-private.h"
76 #include "MagickCore/token.h"
77 #include "MagickCore/utility.h"
78 #include "MagickCore/version.h"
79 #include "MagickCore/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-1))
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-1))
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) (*(unsigned char *) p1));
1301 case EXIF_FMT_SBYTE:
1303 EXIFMultipleValues(1,"%.20g",(double) (*(signed char *) p1));
1306 case EXIF_FMT_SSHORT:
1308 EXIFMultipleValues(2,"%hd",ReadPropertyShort(endian,p1));
1311 case EXIF_FMT_USHORT:
1313 EXIFMultipleValues(2,"%hu",ReadPropertyShort(endian,p1));
1316 case EXIF_FMT_ULONG:
1318 EXIFMultipleValues(4,"%.20g",(double)
1319 ReadPropertyLong(endian,p1));
1322 case EXIF_FMT_SLONG:
1324 EXIFMultipleValues(4,"%.20g",(double)
1325 ReadPropertyLong(endian,p1));
1328 case EXIF_FMT_URATIONAL:
1330 EXIFMultipleFractions(8,"%.20g/%.20g",(double)
1331 ReadPropertyLong(endian,p1),(double)
1332 ReadPropertyLong(endian,p1+4));
1335 case EXIF_FMT_SRATIONAL:
1337 EXIFMultipleFractions(8,"%.20g/%.20g",(double)
1338 ReadPropertyLong(endian,p1),(double)
1339 ReadPropertyLong(endian,p1+4));
1342 case EXIF_FMT_SINGLE:
1344 EXIFMultipleValues(4,"%f",(double) *(float *) p1);
1347 case EXIF_FMT_DOUBLE:
1349 EXIFMultipleValues(8,"%f",*(double *) p1);
1353 case EXIF_FMT_STRING:
1355 value=(char *) NULL;
1356 if (~(1UL*number_bytes) >= 1)
1357 value=(char *) AcquireQuantumMemory((size_t) number_bytes+1UL,
1359 if (value != (char *) NULL)
1364 for (i=0; i < (ssize_t) number_bytes; i++)
1367 if ((isprint((int) p[i]) != 0) || (p[i] == '\0'))
1368 value[i]=(char) p[i];
1375 if (value != (char *) NULL)
1383 (void) CopyMagickString(key,property,MaxTextExtent);
1394 description="unknown";
1397 if (EXIFTag[i].tag == 0)
1399 if ((ssize_t) EXIFTag[i].tag == tag_value)
1401 description=EXIFTag[i].description;
1405 (void) FormatLocaleString(key,MaxTextExtent,"%s",
1411 if (tag_value < 0x10000)
1412 (void) FormatLocaleString(key,MaxTextExtent,"#%04lx",
1413 (unsigned long) tag_value);
1415 if (tag_value < 0x20000)
1416 (void) FormatLocaleString(key,MaxTextExtent,"@%04lx",
1417 (unsigned long) (tag_value & 0xffff));
1419 (void) FormatLocaleString(key,MaxTextExtent,"unknown");
1423 p=(const char *) NULL;
1424 if (image->properties != (void *) NULL)
1425 p=(const char *) GetValueFromSplayTree((SplayTreeInfo *)
1426 image->properties,key);
1427 if (p == (const char *) NULL)
1428 (void) SetImageProperty((Image *) image,key,value);
1429 value=DestroyString(value);
1433 if ((tag_value == TAG_EXIF_OFFSET) ||
1434 (tag_value == TAG_INTEROP_OFFSET) ||
1435 (tag_value == TAG_GPS_OFFSET))
1440 offset=(size_t) ReadPropertyLong(endian,p);
1441 if ((offset < length) && (level < (MaxDirectoryStack-2)))
1446 tag_offset1=(tag_value == TAG_GPS_OFFSET) ? 0x10000UL : 0UL;
1447 directory_stack[level].directory=directory;
1449 directory_stack[level].entry=entry;
1450 directory_stack[level].offset=tag_offset;
1452 directory_stack[level].directory=exif+offset;
1453 directory_stack[level].offset=tag_offset1;
1454 directory_stack[level].entry=0;
1456 if ((directory+2+(12*number_entries)) > (exif+length))
1458 offset=(size_t) ReadPropertyLong(endian,directory+2+(12*
1460 if ((offset != 0) && (offset < length) &&
1461 (level < (MaxDirectoryStack-2)))
1463 directory_stack[level].directory=exif+offset;
1464 directory_stack[level].entry=0;
1465 directory_stack[level].offset=tag_offset1;
1472 } while (level > 0);
1476 static MagickBooleanType GetXMPProperty(const Image *image,const char *property)
1500 profile=GetImageProfile(image,"xmp");
1501 if (profile == (StringInfo *) NULL)
1502 return(MagickFalse);
1503 if ((property == (const char *) NULL) || (*property == '\0'))
1504 return(MagickFalse);
1505 xmp_profile=StringInfoToString(profile);
1506 if (xmp_profile == (char *) NULL)
1507 return(MagickFalse);
1508 for (p=xmp_profile; *p != '\0'; p++)
1509 if ((*p == '<') && (*(p+1) == 'x'))
1511 exception=AcquireExceptionInfo();
1512 xmp=NewXMLTree((char *) p,exception);
1513 xmp_profile=DestroyString(xmp_profile);
1514 exception=DestroyExceptionInfo(exception);
1515 if (xmp == (XMLTreeInfo *) NULL)
1516 return(MagickFalse);
1518 rdf=GetXMLTreeChild(xmp,"rdf:RDF");
1519 if (rdf != (XMLTreeInfo *) NULL)
1521 if (image->properties == (void *) NULL)
1522 ((Image *) image)->properties=NewSplayTree(CompareSplayTreeString,
1523 RelinquishMagickMemory,RelinquishMagickMemory);
1524 description=GetXMLTreeChild(rdf,"rdf:Description");
1525 while (description != (XMLTreeInfo *) NULL)
1527 node=GetXMLTreeChild(description,(const char *) NULL);
1528 while (node != (XMLTreeInfo *) NULL)
1530 child=GetXMLTreeChild(node,(const char *) NULL);
1531 if (child == (XMLTreeInfo *) NULL)
1532 (void) AddValueToSplayTree((SplayTreeInfo *) image->properties,
1533 ConstantString(GetXMLTreeTag(node)),
1534 ConstantString(GetXMLTreeContent(node)));
1535 while (child != (XMLTreeInfo *) NULL)
1537 if (LocaleCompare(GetXMLTreeTag(child),"rdf:Seq") != 0)
1538 (void) AddValueToSplayTree((SplayTreeInfo *) image->properties,
1539 ConstantString(GetXMLTreeTag(child)),
1540 ConstantString(GetXMLTreeContent(child)));
1541 child=GetXMLTreeSibling(child);
1543 node=GetXMLTreeSibling(node);
1545 description=GetNextXMLTreeTag(description);
1548 xmp=DestroyXMLTree(xmp);
1552 static char *TracePSClippath(const unsigned char *blob,size_t length,
1553 const size_t magick_unused(columns),
1554 const size_t magick_unused(rows))
1577 path=AcquireString((char *) NULL);
1578 if (path == (char *) NULL)
1579 return((char *) NULL);
1580 message=AcquireString((char *) NULL);
1581 (void) FormatLocaleString(message,MaxTextExtent,"/ClipImage\n");
1582 (void) ConcatenateString(&path,message);
1583 (void) FormatLocaleString(message,MaxTextExtent,"{\n");
1584 (void) ConcatenateString(&path,message);
1585 (void) FormatLocaleString(message,MaxTextExtent," /c {curveto} bind def\n");
1586 (void) ConcatenateString(&path,message);
1587 (void) FormatLocaleString(message,MaxTextExtent," /l {lineto} bind def\n");
1588 (void) ConcatenateString(&path,message);
1589 (void) FormatLocaleString(message,MaxTextExtent," /m {moveto} bind def\n");
1590 (void) ConcatenateString(&path,message);
1591 (void) FormatLocaleString(message,MaxTextExtent,
1592 " /v {currentpoint 6 2 roll curveto} bind def\n");
1593 (void) ConcatenateString(&path,message);
1594 (void) FormatLocaleString(message,MaxTextExtent,
1595 " /y {2 copy curveto} bind def\n");
1596 (void) ConcatenateString(&path,message);
1597 (void) FormatLocaleString(message,MaxTextExtent,
1598 " /z {closepath} bind def\n");
1599 (void) ConcatenateString(&path,message);
1600 (void) FormatLocaleString(message,MaxTextExtent," newpath\n");
1601 (void) ConcatenateString(&path,message);
1603 The clipping path format is defined in "Adobe Photoshop File
1604 Formats Specification" version 6.0 downloadable from adobe.com.
1606 (void) ResetMagickMemory(point,0,sizeof(point));
1607 (void) ResetMagickMemory(first,0,sizeof(first));
1608 (void) ResetMagickMemory(last,0,sizeof(last));
1610 in_subpath=MagickFalse;
1613 selector=(ssize_t) ReadPropertyMSBShort(&blob,&length);
1619 if (knot_count != 0)
1626 Expected subpath length record.
1628 knot_count=(ssize_t) ReadPropertyMSBShort(&blob,&length);
1638 if (knot_count == 0)
1641 Unexpected subpath knot
1650 for (i=0; i < 3; i++)
1656 yy=ReadPropertyMSBLong(&blob,&length);
1657 xx=ReadPropertyMSBLong(&blob,&length);
1659 if (xx > 2147483647)
1660 x=(ssize_t) xx-4294967295U-1;
1662 if (yy > 2147483647)
1663 y=(ssize_t) yy-4294967295U-1;
1664 point[i].x=(double) x/4096/4096;
1665 point[i].y=1.0-(double) y/4096/4096;
1667 if (in_subpath == MagickFalse)
1669 (void) FormatLocaleString(message,MaxTextExtent," %g %g m\n",
1670 point[1].x,point[1].y);
1671 for (i=0; i < 3; i++)
1680 Handle special cases when Bezier curves are used to describe
1681 corners and straight lines.
1683 if ((last[1].x == last[2].x) && (last[1].y == last[2].y) &&
1684 (point[0].x == point[1].x) && (point[0].y == point[1].y))
1685 (void) FormatLocaleString(message,MaxTextExtent,
1686 " %g %g l\n",point[1].x,point[1].y);
1688 if ((last[1].x == last[2].x) && (last[1].y == last[2].y))
1689 (void) FormatLocaleString(message,MaxTextExtent,
1690 " %g %g %g %g v\n",point[0].x,point[0].y,
1691 point[1].x,point[1].y);
1693 if ((point[0].x == point[1].x) && (point[0].y == point[1].y))
1694 (void) FormatLocaleString(message,MaxTextExtent,
1695 " %g %g %g %g y\n",last[2].x,last[2].y,
1696 point[1].x,point[1].y);
1698 (void) FormatLocaleString(message,MaxTextExtent,
1699 " %g %g %g %g %g %g c\n",last[2].x,
1700 last[2].y,point[0].x,point[0].y,point[1].x,point[1].y);
1701 for (i=0; i < 3; i++)
1704 (void) ConcatenateString(&path,message);
1705 in_subpath=MagickTrue;
1708 Close the subpath if there are no more knots.
1710 if (knot_count == 0)
1713 Same special handling as above except we compare to the
1714 first point in the path and close the path.
1716 if ((last[1].x == last[2].x) && (last[1].y == last[2].y) &&
1717 (first[0].x == first[1].x) && (first[0].y == first[1].y))
1718 (void) FormatLocaleString(message,MaxTextExtent,
1719 " %g %g l z\n",first[1].x,first[1].y);
1721 if ((last[1].x == last[2].x) && (last[1].y == last[2].y))
1722 (void) FormatLocaleString(message,MaxTextExtent,
1723 " %g %g %g %g v z\n",first[0].x,first[0].y,
1724 first[1].x,first[1].y);
1726 if ((first[0].x == first[1].x) && (first[0].y == first[1].y))
1727 (void) FormatLocaleString(message,MaxTextExtent,
1728 " %g %g %g %g y z\n",last[2].x,last[2].y,
1729 first[1].x,first[1].y);
1731 (void) FormatLocaleString(message,MaxTextExtent,
1732 " %g %g %g %g %g %g c z\n",last[2].x,
1733 last[2].y,first[0].x,first[0].y,first[1].x,first[1].y);
1734 (void) ConcatenateString(&path,message);
1735 in_subpath=MagickFalse;
1751 Returns an empty PS path if the path has no knots.
1753 (void) FormatLocaleString(message,MaxTextExtent," eoclip\n");
1754 (void) ConcatenateString(&path,message);
1755 (void) FormatLocaleString(message,MaxTextExtent,"} bind def");
1756 (void) ConcatenateString(&path,message);
1757 message=DestroyString(message);
1761 static char *TraceSVGClippath(const unsigned char *blob,size_t length,
1762 const size_t columns,const size_t rows)
1785 path=AcquireString((char *) NULL);
1786 if (path == (char *) NULL)
1787 return((char *) NULL);
1788 message=AcquireString((char *) NULL);
1789 (void) FormatLocaleString(message,MaxTextExtent,
1790 "<?xml version=\"1.0\" encoding=\"iso-8859-1\"?>\n");
1791 (void) ConcatenateString(&path,message);
1792 (void) FormatLocaleString(message,MaxTextExtent,
1793 "<svg width=\"%.20g\" height=\"%.20g\">\n",(double) columns,(double) rows);
1794 (void) ConcatenateString(&path,message);
1795 (void) FormatLocaleString(message,MaxTextExtent,"<g>\n");
1796 (void) ConcatenateString(&path,message);
1797 (void) FormatLocaleString(message,MaxTextExtent,
1798 "<path style=\"fill:#00000000;stroke:#00000000;");
1799 (void) ConcatenateString(&path,message);
1800 (void) FormatLocaleString(message,MaxTextExtent,
1801 "stroke-width:0;stroke-antialiasing:false\" d=\"\n");
1802 (void) ConcatenateString(&path,message);
1803 (void) ResetMagickMemory(point,0,sizeof(point));
1804 (void) ResetMagickMemory(first,0,sizeof(first));
1805 (void) ResetMagickMemory(last,0,sizeof(last));
1807 in_subpath=MagickFalse;
1810 selector=(ssize_t) ReadPropertyMSBShort(&blob,&length);
1816 if (knot_count != 0)
1823 Expected subpath length record.
1825 knot_count=(ssize_t) ReadPropertyMSBShort(&blob,&length);
1835 if (knot_count == 0)
1838 Unexpected subpath knot.
1847 for (i=0; i < 3; i++)
1853 yy=ReadPropertyMSBLong(&blob,&length);
1854 xx=ReadPropertyMSBLong(&blob,&length);
1856 if (xx > 2147483647)
1857 x=(ssize_t) xx-4294967295U-1;
1859 if (yy > 2147483647)
1860 y=(ssize_t) yy-4294967295U-1;
1861 point[i].x=(double) x*columns/4096/4096;
1862 point[i].y=(double) y*rows/4096/4096;
1864 if (in_subpath == MagickFalse)
1866 (void) FormatLocaleString(message,MaxTextExtent,"M %g,%g\n",
1867 point[1].x,point[1].y);
1868 for (i=0; i < 3; i++)
1876 if ((last[1].x == last[2].x) && (last[1].y == last[2].y) &&
1877 (point[0].x == point[1].x) && (point[0].y == point[1].y))
1878 (void) FormatLocaleString(message,MaxTextExtent,"L %g,%g\n",
1879 point[1].x,point[1].y);
1881 (void) FormatLocaleString(message,MaxTextExtent,
1882 "C %g,%g %g,%g %g,%g\n",last[2].x,last[2].y,
1883 point[0].x,point[0].y,point[1].x,point[1].y);
1884 for (i=0; i < 3; i++)
1887 (void) ConcatenateString(&path,message);
1888 in_subpath=MagickTrue;
1891 Close the subpath if there are no more knots.
1893 if (knot_count == 0)
1895 if ((last[1].x == last[2].x) && (last[1].y == last[2].y) &&
1896 (first[0].x == first[1].x) && (first[0].y == first[1].y))
1897 (void) FormatLocaleString(message,MaxTextExtent,
1898 "L %g,%g Z\n",first[1].x,first[1].y);
1901 (void) FormatLocaleString(message,MaxTextExtent,
1902 "C %g,%g %g,%g %g,%g Z\n",last[2].x,
1903 last[2].y,first[0].x,first[0].y,first[1].x,first[1].y);
1904 (void) ConcatenateString(&path,message);
1906 in_subpath=MagickFalse;
1922 Return an empty SVG image if the path does not have knots.
1924 (void) FormatLocaleString(message,MaxTextExtent,"\"/>\n");
1925 (void) ConcatenateString(&path,message);
1926 (void) FormatLocaleString(message,MaxTextExtent,"</g>\n");
1927 (void) ConcatenateString(&path,message);
1928 (void) FormatLocaleString(message,MaxTextExtent,"</svg>\n");
1929 (void) ConcatenateString(&path,message);
1930 message=DestroyString(message);
1934 MagickExport const char *GetImageProperty(const Image *image,
1935 const char *property)
1952 assert(image != (Image *) NULL);
1953 assert(image->signature == MagickSignature);
1954 if (image->debug != MagickFalse)
1955 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1956 p=(const char *) NULL;
1957 if (image->properties != (void *) NULL)
1959 if (property == (const char *) NULL)
1961 ResetSplayTreeIterator((SplayTreeInfo *) image->properties);
1962 p=(const char *) GetNextValueInSplayTree((SplayTreeInfo *)
1966 if (LocaleNCompare("fx:",property,3) != 0)
1968 p=(const char *) GetValueFromSplayTree((SplayTreeInfo *)
1969 image->properties,property);
1970 if (p != (const char *) NULL)
1974 if ((property == (const char *) NULL) ||
1975 (strchr(property,':') == (char *) NULL))
1977 exception=(&((Image *) image)->exception);
1982 if (LocaleNCompare("8bim:",property,5) == 0)
1984 if ((Get8BIMProperty(image,property) != MagickFalse) &&
1985 (image->properties != (void *) NULL))
1987 p=(const char *) GetValueFromSplayTree((SplayTreeInfo *)
1988 image->properties,property);
1997 if (LocaleNCompare("exif:",property,5) == 0)
1999 if ((GetEXIFProperty(image,property) != MagickFalse) &&
2000 (image->properties != (void *) NULL))
2002 p=(const char *) GetValueFromSplayTree((SplayTreeInfo *)
2003 image->properties,property);
2012 if (LocaleNCompare("fx:",property,3) == 0)
2014 fx_info=AcquireFxInfo(image,property+3);
2015 status=FxEvaluateChannelExpression(fx_info,IntensityPixelChannel,0,0,
2017 fx_info=DestroyFxInfo(fx_info);
2018 if (status != MagickFalse)
2021 value[MaxTextExtent];
2023 (void) FormatLocaleString(value,MaxTextExtent,"%.*g",
2024 GetMagickPrecision(),(double) alpha);
2025 (void) SetImageProperty((Image *) image,property,value);
2027 if (image->properties != (void *) NULL)
2029 p=(const char *) GetValueFromSplayTree((SplayTreeInfo *)
2030 image->properties,property);
2039 if (LocaleNCompare("iptc:",property,5) == 0)
2041 if ((GetIPTCProperty(image,property) != MagickFalse) &&
2042 (image->properties != (void *) NULL))
2044 p=(const char *) GetValueFromSplayTree((SplayTreeInfo *)
2045 image->properties,property);
2054 if (LocaleNCompare("pixel:",property,6) == 0)
2059 GetPixelInfo(image,&pixel);
2060 fx_info=AcquireFxInfo(image,property+6);
2061 status=FxEvaluateChannelExpression(fx_info,RedPixelChannel,0,0,
2063 pixel.red=(MagickRealType) QuantumRange*alpha;
2064 status|=FxEvaluateChannelExpression(fx_info,GreenPixelChannel,0,0,
2066 pixel.green=(MagickRealType) QuantumRange*alpha;
2067 status|=FxEvaluateChannelExpression(fx_info,BluePixelChannel,0,0,
2069 pixel.blue=(MagickRealType) QuantumRange*alpha;
2070 if (image->colorspace == CMYKColorspace)
2072 status|=FxEvaluateChannelExpression(fx_info,BlackPixelChannel,0,0,
2074 pixel.black=(MagickRealType) QuantumRange*alpha;
2076 status|=FxEvaluateChannelExpression(fx_info,AlphaPixelChannel,0,0,
2078 pixel.alpha=(MagickRealType) QuantumRange*(1.0-alpha);
2079 fx_info=DestroyFxInfo(fx_info);
2080 if (status != MagickFalse)
2083 name[MaxTextExtent];
2085 (void) QueryMagickColorname(image,&pixel,SVGCompliance,name,
2087 (void) SetImageProperty((Image *) image,property,name);
2088 return(GetImageProperty(image,property));
2096 if (LocaleNCompare("xmp:",property,4) == 0)
2098 if ((GetXMPProperty(image,property) != MagickFalse) &&
2099 (image->properties != (void *) NULL))
2101 p=(const char *) GetValueFromSplayTree((SplayTreeInfo *)
2102 image->properties,property);
2115 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2119 + G e t M a g i c k P r o p e r t y %
2123 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2125 % GetMagickProperty() gets a value associated with an image property.
2127 % The format of the GetMagickProperty method is:
2129 % const char *GetMagickProperty(const ImageInfo *image_info,Image *image,
2132 % A description of each parameter follows:
2134 % o image_info: the image info.
2136 % o image: the image.
2141 MagickExport const char *GetMagickProperty(const ImageInfo *image_info,
2142 Image *image,const char *property)
2145 value[MaxTextExtent],
2146 filename[MaxTextExtent];
2153 if (LocaleNCompare("base",property,4) == 0)
2155 GetPathComponent(image->magick_filename,BasePath,filename);
2156 (void) CopyMagickString(value,filename,MaxTextExtent);
2163 if (LocaleNCompare("channels",property,8) == 0)
2168 (void) FormatLocaleString(value,MaxTextExtent,"%s",
2169 CommandOptionToMnemonic(MagickColorspaceOptions,(ssize_t)
2170 image->colorspace));
2172 if (image->matte != MagickFalse)
2173 (void) ConcatenateMagickString(value,"a",MaxTextExtent);
2176 if (LocaleNCompare("colorspace",property,10) == 0)
2182 Image storage class and colorspace.
2184 colorspace=image->colorspace;
2185 if (IsImageGray(image,&image->exception) != MagickFalse)
2186 colorspace=GRAYColorspace;
2187 (void) FormatLocaleString(value,MaxTextExtent,"%s",
2188 CommandOptionToMnemonic(MagickColorspaceOptions,(ssize_t)
2192 if (LocaleNCompare("copyright",property,9) == 0)
2194 (void) CopyMagickString(value,GetMagickCopyright(),MaxTextExtent);
2201 if (LocaleNCompare("depth",property,5) == 0)
2203 (void) FormatLocaleString(value,MaxTextExtent,"%.20g",(double)
2207 if (LocaleNCompare("directory",property,9) == 0)
2209 GetPathComponent(image->magick_filename,HeadPath,filename);
2210 (void) CopyMagickString(value,filename,MaxTextExtent);
2217 if (LocaleNCompare("extension",property,9) == 0)
2219 GetPathComponent(image->magick_filename,ExtensionPath,filename);
2220 (void) CopyMagickString(value,filename,MaxTextExtent);
2227 if (LocaleNCompare("group",property,5) == 0)
2229 (void) FormatLocaleString(value,MaxTextExtent,"0x%lx",
2230 (unsigned long) image_info->group);
2237 if (LocaleNCompare("height",property,6) == 0)
2239 (void) FormatLocaleString(value,MaxTextExtent,"%.20g",
2240 image->magick_rows != 0 ? (double) image->magick_rows : 256.0);
2247 if (LocaleNCompare("input",property,5) == 0)
2249 (void) CopyMagickString(value,image->filename,MaxTextExtent);
2256 if (LocaleNCompare("kurtosis",property,8) == 0)
2262 (void) GetImageKurtosis(image,&kurtosis,&skewness,&image->exception);
2263 (void) FormatLocaleString(value,MaxTextExtent,"%.*g",
2264 GetMagickPrecision(),kurtosis);
2271 if (LocaleNCompare("magick",property,6) == 0)
2273 (void) CopyMagickString(value,image->magick,MaxTextExtent);
2276 if (LocaleNCompare("max",property,3) == 0)
2282 (void) GetImageRange(image,&minimum,&maximum,&image->exception);
2283 (void) FormatLocaleString(value,MaxTextExtent,"%.*g",
2284 GetMagickPrecision(),maximum);
2287 if (LocaleNCompare("mean",property,4) == 0)
2293 (void) GetImageMean(image,&mean,&standard_deviation,
2295 (void) FormatLocaleString(value,MaxTextExtent,"%.*g",
2296 GetMagickPrecision(),mean);
2299 if (LocaleNCompare("min",property,3) == 0)
2305 (void) GetImageRange(image,&minimum,&maximum,&image->exception);
2306 (void) FormatLocaleString(value,MaxTextExtent,"%.*g",
2307 GetMagickPrecision(),minimum);
2314 if (LocaleNCompare("name",property,4) == 0)
2316 (void) CopyMagickString(value,filename,MaxTextExtent);
2323 if (LocaleNCompare("opaque",property,6) == 0)
2328 opaque=IsImageOpaque(image,&image->exception);
2329 (void) CopyMagickString(value,opaque == MagickFalse ? "false" :
2330 "true",MaxTextExtent);
2333 if (LocaleNCompare("output",property,6) == 0)
2335 (void) CopyMagickString(value,image_info->filename,MaxTextExtent);
2342 if (LocaleNCompare("page",property,4) == 0)
2344 (void) FormatLocaleString(value,MaxTextExtent,"%.20g",(double)
2345 GetImageIndexInList(image)+1);
2352 if (LocaleNCompare("size",property,4) == 0)
2355 format[MaxTextExtent];
2357 (void) FormatMagickSize(GetBlobSize(image),MagickFalse,format);
2358 (void) FormatLocaleString(value,MaxTextExtent,"%sB",format);
2361 if (LocaleNCompare("scenes",property,6) == 0)
2363 (void) FormatLocaleString(value,MaxTextExtent,"%.20g",(double)
2364 GetImageListLength(image));
2367 if (LocaleNCompare("scene",property,5) == 0)
2369 (void) FormatLocaleString(value,MaxTextExtent,"%.20g",(double)
2371 if (image_info->number_scenes != 0)
2372 (void) FormatLocaleString(value,MaxTextExtent,"%.20g",(double)
2376 if (LocaleNCompare("skewness",property,8) == 0)
2382 (void) GetImageKurtosis(image,&kurtosis,&skewness,&image->exception);
2383 (void) FormatLocaleString(value,MaxTextExtent,"%.*g",
2384 GetMagickPrecision(),skewness);
2387 if (LocaleNCompare("standard-deviation",property,18) == 0)
2393 (void) GetImageMean(image,&mean,&standard_deviation,
2395 (void) FormatLocaleString(value,MaxTextExtent,"%.*g",
2396 GetMagickPrecision(),standard_deviation);
2403 if (LocaleNCompare("unique",property,6) == 0)
2405 (void) CopyMagickString(filename,image_info->unique,MaxTextExtent);
2406 (void) CopyMagickString(value,filename,MaxTextExtent);
2413 if (LocaleNCompare("version",property,7) == 0)
2415 (void) CopyMagickString(value,GetMagickVersion((size_t *) NULL),
2423 if (LocaleNCompare("width",property,5) == 0)
2425 (void) FormatLocaleString(value,MaxTextExtent,"%.20g",(double)
2426 (image->magick_columns != 0 ? image->magick_columns : 256));
2433 if (LocaleNCompare("xresolution",property,11) == 0)
2435 (void) FormatLocaleString(value,MaxTextExtent,"%g",
2436 image->x_resolution);
2443 if (LocaleNCompare("yresolution",property,11) == 0)
2445 (void) FormatLocaleString(value,MaxTextExtent,"%g",
2446 image->y_resolution);
2453 if (LocaleNCompare("zero",property,4) == 0)
2455 (void) CopyMagickString(filename,image_info->zero,MaxTextExtent);
2456 (void) CopyMagickString(value,filename,MaxTextExtent);
2464 if (image->properties == (void *) NULL)
2465 image->properties=NewSplayTree(CompareSplayTreeString,
2466 RelinquishMagickMemory,RelinquishMagickMemory);
2467 (void) AddValueToSplayTree((SplayTreeInfo *) image->properties,
2468 ConstantString(property),ConstantString(value));
2470 return(GetImageProperty(image,property));
2474 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2478 % G e t N e x t I m a g e P r o p e r t y %
2482 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2484 % GetNextImageProperty() gets the next image property value.
2486 % The format of the GetNextImageProperty method is:
2488 % char *GetNextImageProperty(const Image *image)
2490 % A description of each parameter follows:
2492 % o image: the image.
2495 MagickExport char *GetNextImageProperty(const Image *image)
2497 assert(image != (Image *) NULL);
2498 assert(image->signature == MagickSignature);
2499 if (image->debug != MagickFalse)
2500 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
2502 if (image->properties == (void *) NULL)
2503 return((char *) NULL);
2504 return((char *) GetNextKeyInSplayTree((SplayTreeInfo *) image->properties));
2508 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2512 % I n t e r p r e t I m a g e P r o p e r t i e s %
2516 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2518 % InterpretImageProperties() replaces any embedded formatting characters with
2519 % the appropriate image property and returns the interpreted text.
2521 % The format of the InterpretImageProperties method is:
2523 % char *InterpretImageProperties(const ImageInfo *image_info,Image *image,
2524 % const char *embed_text)
2526 % A description of each parameter follows:
2528 % o image_info: the image info.
2530 % o image: the image.
2532 % o embed_text: the address of a character string containing the embedded
2533 % formatting characters.
2536 MagickExport char *InterpretImageProperties(const ImageInfo *image_info,
2537 Image *image,const char *embed_text)
2540 filename[MaxTextExtent],
2560 assert(image != (Image *) NULL);
2561 assert(image->signature == MagickSignature);
2562 if (image->debug != MagickFalse)
2563 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
2564 if ((embed_text == (const char *) NULL) || (*embed_text == '\0'))
2565 return((char *) NULL);
2566 text=(char *) embed_text;
2567 if ((*text == '@') && ((*(text+1) == '-') ||
2568 (IsPathAccessible(text+1) != MagickFalse)))
2569 return(FileToString(embed_text+1,~0,&image->exception));
2571 Translate any embedded format characters.
2573 interpret_text=AcquireString(text);
2574 extent=MaxTextExtent;
2576 for (q=interpret_text; *p != '\0'; p++)
2579 if ((size_t) (q-interpret_text+MaxTextExtent) >= extent)
2581 extent+=MaxTextExtent;
2582 interpret_text=(char *) ResizeQuantumMemory(interpret_text,extent+
2583 MaxTextExtent+1,sizeof(*interpret_text));
2584 if (interpret_text == (char *) NULL)
2586 q=interpret_text+strlen(interpret_text);
2589 Process formatting characters in text.
2591 if ((*p == '\\') && (*(p+1) == 'r'))
2597 if ((*p == '\\') && (*(p+1) == 'n'))
2620 format[MaxTextExtent];
2625 (void) FormatLocaleString(format,MaxTextExtent,"%.20g",(double)
2626 ((MagickOffsetType) image->extent));
2627 if (image->extent != (MagickSizeType) ((size_t) image->extent))
2628 (void) FormatMagickSize(image->extent,MagickFalse,format);
2629 q+=ConcatenateMagickString(q,format,extent);
2630 q+=ConcatenateMagickString(q,"B",extent);
2638 value=GetImageProperty(image,"comment");
2639 if (value == (const char *) NULL)
2641 length=strlen(value);
2642 if ((size_t) (q-interpret_text+length+1) >= extent)
2645 interpret_text=(char *) ResizeQuantumMemory(interpret_text,extent+
2646 MaxTextExtent,sizeof(*interpret_text));
2647 if (interpret_text == (char *) NULL)
2649 q=interpret_text+strlen(interpret_text);
2651 (void) CopyMagickString(q,value,extent);
2661 Label segment is the base of the filename.
2663 if (*image->magick_filename == '\0')
2672 GetPathComponent(image->magick_filename,HeadPath,filename);
2673 q+=CopyMagickString(q,filename,extent);
2681 GetPathComponent(image->magick_filename,ExtensionPath,filename);
2682 q+=CopyMagickString(q,filename,extent);
2690 GetPathComponent(image->magick_filename,TailPath,filename);
2691 q+=CopyMagickString(q,filename,extent);
2699 GetPathComponent(image->magick_filename,BasePath,filename);
2700 q+=CopyMagickString(q,filename,extent);
2711 q+=FormatLocaleString(q,extent,"%.20gx%.20g%+.20g%+.20g",(double)
2712 image->page.width,(double) image->page.height,(double) image->page.x,
2713 (double) image->page.y);
2721 q+=FormatLocaleString(q,extent,"%.20g",(double) (image->rows != 0 ?
2722 image->rows : image->magick_rows));
2730 q+=CopyMagickString(q,image->filename,extent);
2736 Number of unique colors.
2738 q+=FormatLocaleString(q,extent,"%.20g",(double) GetNumberColors(image,
2739 (FILE *) NULL,&image->exception));
2747 value=GetImageProperty(image,"label");
2748 if (value == (const char *) NULL)
2750 length=strlen(value);
2751 if ((size_t) (q-interpret_text+length+1) >= extent)
2754 interpret_text=(char *) ResizeQuantumMemory(interpret_text,extent+
2755 MaxTextExtent,sizeof(*interpret_text));
2756 if (interpret_text == (char *) NULL)
2758 q=interpret_text+strlen(interpret_text);
2760 q+=CopyMagickString(q,value,extent);
2768 q+=CopyMagickString(q,image->magick,extent);
2774 Image magick filename.
2776 q+=CopyMagickString(q,image->magick_filename,extent);
2782 Number of images in the list.
2784 q+=FormatLocaleString(q,extent,"%.20g",(double)
2785 GetImageListLength(image));
2791 Image output filename.
2793 q+=CopyMagickString(q,image_info->filename,extent);
2799 Image index in list.
2801 q+=FormatLocaleString(q,extent,"%.20g",(double)
2802 GetImageIndexInList(image));
2810 q+=FormatLocaleString(q,extent,"%.20g",(double)
2811 MAGICKCORE_QUANTUM_DEPTH);
2820 Image storage class and colorspace.
2822 colorspace=image->colorspace;
2823 if (IsImageGray(image,&image->exception) != MagickFalse)
2824 colorspace=GRAYColorspace;
2825 q+=FormatLocaleString(q,extent,"%s%s%s",CommandOptionToMnemonic(
2826 MagickClassOptions,(ssize_t) image->storage_class),
2827 CommandOptionToMnemonic(MagickColorspaceOptions,(ssize_t) colorspace),
2828 image->matte != MagickFalse ? "Matte" : "");
2836 if (image_info->number_scenes == 0)
2837 q+=FormatLocaleString(q,extent,"%.20g",(double) image->scene);
2839 q+=FormatLocaleString(q,extent,"%.20g",(double) image_info->scene);
2847 (void) CopyMagickString(filename,image_info->unique,extent);
2848 q+=CopyMagickString(q,filename,extent);
2856 q+=FormatLocaleString(q,extent,"%.20g",(double) (image->columns != 0 ?
2857 image->columns : image->magick_columns));
2863 Image horizontal resolution.
2865 q+=FormatLocaleString(q,extent,"%g %s",image->x_resolution,
2866 CommandOptionToMnemonic(MagickResolutionOptions,(ssize_t)
2873 Image vertical resolution.
2875 q+=FormatLocaleString(q,extent,"%g %s",image->y_resolution,
2876 CommandOptionToMnemonic(MagickResolutionOptions,(ssize_t)
2885 q+=FormatLocaleString(q,extent,"%.20g",(double) image->depth);
2891 Image alpha channel.
2893 q+=FormatLocaleString(q,extent,"%s",CommandOptionToMnemonic(
2894 MagickBooleanOptions,(ssize_t) image->matte));
2900 Image compression method.
2902 q+=FormatLocaleString(q,extent,"%s",CommandOptionToMnemonic(
2903 MagickCompressOptions,(ssize_t) image->compression));
2909 Image dispose method.
2911 q+=FormatLocaleString(q,extent,"%s",CommandOptionToMnemonic(
2912 MagickDisposeOptions,(ssize_t) image->dispose));
2917 q+=FormatLocaleString(q,extent,"%.20gx%.20g",(double)
2918 image->magick_columns,(double) image->magick_rows);
2923 q+=FormatLocaleString(q,extent,"%.20g",(double) image->page.height);
2928 q+=FormatLocaleString(q,extent,"%+ld%+ld",(long) image->page.x,(long)
2934 q+=FormatLocaleString(q,extent,"%.20gx%.20g",(double) image->page.width,
2935 (double) image->page.height);
2940 q+=FormatLocaleString(q,extent,"%.20g",(double) image->quality);
2948 if (image_info->number_scenes == 0)
2949 q+=CopyMagickString(q,"2147483647",extent);
2951 q+=FormatLocaleString(q,extent,"%.20g",(double) (image_info->scene+
2952 image_info->number_scenes));
2957 q+=FormatLocaleString(q,extent,"%.20g",(double) image->delay);
2962 q+=FormatLocaleString(q,extent,"%.20g",(double) image->page.width);
2967 q+=FormatLocaleString(q,extent,"%+.20g",(double) image->page.x);
2972 q+=FormatLocaleString(q,extent,"%+.20g",(double) image->page.y);
2980 (void) CopyMagickString(filename,image_info->zero,extent);
2981 q+=CopyMagickString(q,filename,extent);
2987 pattern[MaxTextExtent];
2999 if (strchr(p,']') == (char *) NULL)
3003 for (i=0; (i < (MaxTextExtent-1L)) && (*p != '\0'); i++)
3014 value=GetImageProperty(image,pattern);
3015 if (value != (const char *) NULL)
3017 length=strlen(value);
3018 if ((size_t) (q-interpret_text+length+1) >= extent)
3021 interpret_text=(char *) ResizeQuantumMemory(interpret_text,
3022 extent+MaxTextExtent,sizeof(*interpret_text));
3023 if (interpret_text == (char *) NULL)
3025 q=interpret_text+strlen(interpret_text);
3027 (void) CopyMagickString(q,value,extent);
3032 if (IsGlob(pattern) != MagickFalse)
3035 Iterate over image properties.
3037 ResetImagePropertyIterator(image);
3038 key=GetNextImageProperty(image);
3039 while (key != (const char *) NULL)
3041 if (GlobExpression(key,pattern,MagickTrue) != MagickFalse)
3043 value=GetImageProperty(image,key);
3044 if (value != (const char *) NULL)
3046 length=strlen(key)+strlen(value)+2;
3047 if ((size_t) (q-interpret_text+length+1) >= extent)
3050 interpret_text=(char *) ResizeQuantumMemory(
3051 interpret_text,extent+MaxTextExtent,
3052 sizeof(*interpret_text));
3053 if (interpret_text == (char *) NULL)
3055 q=interpret_text+strlen(interpret_text);
3057 q+=FormatLocaleString(q,extent,"%s=%s\n",key,value);
3060 key=GetNextImageProperty(image);
3063 value=GetMagickProperty(image_info,image,pattern);
3064 if (value != (const char *) NULL)
3066 length=strlen(value);
3067 if ((size_t) (q-interpret_text+length+1) >= extent)
3070 interpret_text=(char *) ResizeQuantumMemory(interpret_text,
3071 extent+MaxTextExtent,sizeof(*interpret_text));
3072 if (interpret_text == (char *) NULL)
3074 q=interpret_text+strlen(interpret_text);
3076 (void) CopyMagickString(q,value,extent);
3080 if (image_info == (ImageInfo *) NULL)
3082 value=GetImageOption(image_info,pattern);
3083 if (value != (char *) NULL)
3085 length=strlen(value);
3086 if ((size_t) (q-interpret_text+length+1) >= extent)
3089 interpret_text=(char *) ResizeQuantumMemory(interpret_text,
3090 extent+MaxTextExtent,sizeof(*interpret_text));
3091 if (interpret_text == (char *) NULL)
3093 q=interpret_text+strlen(interpret_text);
3095 (void) CopyMagickString(q,value,extent);
3109 page=GetImageBoundingBox(image,&image->exception);
3110 q+=FormatLocaleString(q,MaxTextExtent,"%.20gx%.20g%+.20g%+.20g",
3111 (double) page.width,(double) page.height,(double) page.x,(double)
3120 (void) SignatureImage(image);
3121 value=GetImageProperty(image,"signature");
3122 if (value == (const char *) NULL)
3124 q+=CopyMagickString(q,value,extent);
3141 if (text != (const char *) embed_text)
3142 text=DestroyString(text);
3143 (void) SubstituteString(&interpret_text,"<","<");
3144 (void) SubstituteString(&interpret_text,">",">");
3145 return(interpret_text);
3149 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3153 % R e m o v e I m a g e P r o p e r t y %
3157 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3159 % RemoveImageProperty() removes a property from the image and returns its
3162 % The format of the RemoveImageProperty method is:
3164 % char *RemoveImageProperty(Image *image,const char *property)
3166 % A description of each parameter follows:
3168 % o image: the image.
3170 % o property: the image property.
3173 MagickExport char *RemoveImageProperty(Image *image,
3174 const char *property)
3179 assert(image != (Image *) NULL);
3180 assert(image->signature == MagickSignature);
3181 if (image->debug != MagickFalse)
3182 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
3184 if (image->properties == (void *) NULL)
3185 return((char *) NULL);
3186 value=(char *) RemoveNodeFromSplayTree((SplayTreeInfo *) image->properties,
3192 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3196 % 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 %
3200 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3202 % ResetImagePropertyIterator() resets the image properties iterator. Use it
3203 % in conjunction with GetNextImageProperty() to iterate over all the values
3204 % associated with an image property.
3206 % The format of the ResetImagePropertyIterator method is:
3208 % ResetImagePropertyIterator(Image *image)
3210 % A description of each parameter follows:
3212 % o image: the image.
3215 MagickExport void ResetImagePropertyIterator(const Image *image)
3217 assert(image != (Image *) NULL);
3218 assert(image->signature == MagickSignature);
3219 if (image->debug != MagickFalse)
3220 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
3222 if (image->properties == (void *) NULL)
3224 ResetSplayTreeIterator((SplayTreeInfo *) image->properties);
3228 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3232 % S e t I m a g e P r o p e r t y %
3236 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3238 % SetImageProperty() associates an value with an image property.
3240 % The format of the SetImageProperty method is:
3242 % MagickBooleanType SetImageProperty(Image *image,const char *property,
3243 % const char *value)
3245 % A description of each parameter follows:
3247 % o image: the image.
3249 % o property: the image property.
3251 % o values: the image property values.
3254 MagickExport MagickBooleanType SetImageProperty(Image *image,
3255 const char *property,const char *value)
3266 assert(image != (Image *) NULL);
3267 assert(image->signature == MagickSignature);
3268 if (image->debug != MagickFalse)
3269 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
3271 if (image->properties == (void *) NULL)
3272 image->properties=NewSplayTree(CompareSplayTreeString,
3273 RelinquishMagickMemory,RelinquishMagickMemory);
3274 if ((value == (const char *) NULL) || (*value == '\0'))
3275 return(DeleteImageProperty(image,property));
3277 exception=(&image->exception);
3283 if (LocaleCompare(property,"background") == 0)
3285 (void) QueryColorDatabase(value,&image->background_color,exception);
3288 if (LocaleCompare(property,"bias") == 0)
3290 image->bias=SiPrefixToDouble(value,QuantumRange);
3293 status=AddValueToSplayTree((SplayTreeInfo *) image->properties,
3294 ConstantString(property),ConstantString(value));
3300 if (LocaleCompare(property,"colorspace") == 0)
3305 colorspace=ParseCommandOption(MagickColorspaceOptions,MagickFalse,
3309 (void) SetImageColorspace(image,(ColorspaceType) colorspace,
3313 if (LocaleCompare(property,"compose") == 0)
3318 compose=ParseCommandOption(MagickComposeOptions,MagickFalse,value);
3321 image->compose=(CompositeOperator) compose;
3324 if (LocaleCompare(property,"compress") == 0)
3329 compression=ParseCommandOption(MagickCompressOptions,MagickFalse,
3331 if (compression < 0)
3333 image->compression=(CompressionType) compression;
3336 status=AddValueToSplayTree((SplayTreeInfo *) image->properties,
3337 ConstantString(property),ConstantString(value));
3343 if (LocaleCompare(property,"delay") == 0)
3348 flags=ParseGeometry(value,&geometry_info);
3349 if ((flags & GreaterValue) != 0)
3351 if (image->delay > (size_t) floor(geometry_info.rho+0.5))
3352 image->delay=(size_t) floor(geometry_info.rho+0.5);
3355 if ((flags & LessValue) != 0)
3357 if (image->delay < (size_t) floor(geometry_info.rho+0.5))
3358 image->ticks_per_second=(ssize_t)
3359 floor(geometry_info.sigma+0.5);
3362 image->delay=(size_t) floor(geometry_info.rho+0.5);
3363 if ((flags & SigmaValue) != 0)
3364 image->ticks_per_second=(ssize_t) floor(geometry_info.sigma+0.5);
3367 if (LocaleCompare(property,"density") == 0)
3372 flags=ParseGeometry(value,&geometry_info);
3373 image->x_resolution=geometry_info.rho;
3374 image->y_resolution=geometry_info.sigma;
3375 if ((flags & SigmaValue) == 0)
3376 image->y_resolution=image->x_resolution;
3378 if (LocaleCompare(property,"depth") == 0)
3380 image->depth=StringToUnsignedLong(value);
3383 if (LocaleCompare(property,"dispose") == 0)
3388 dispose=ParseCommandOption(MagickDisposeOptions,MagickFalse,value);
3391 image->dispose=(DisposeType) dispose;
3394 status=AddValueToSplayTree((SplayTreeInfo *) image->properties,
3395 ConstantString(property),ConstantString(value));
3401 if (LocaleCompare(property,"gravity") == 0)
3406 gravity=ParseCommandOption(MagickGravityOptions,MagickFalse,value);
3409 image->gravity=(GravityType) gravity;
3412 status=AddValueToSplayTree((SplayTreeInfo *) image->properties,
3413 ConstantString(property),ConstantString(value));
3419 if (LocaleCompare(property,"intent") == 0)
3424 rendering_intent=ParseCommandOption(MagickIntentOptions,MagickFalse,
3426 if (rendering_intent < 0)
3428 image->rendering_intent=(RenderingIntent) rendering_intent;
3431 if (LocaleCompare(property,"interpolate") == 0)
3436 interpolate=ParseCommandOption(MagickInterpolateOptions,MagickFalse,
3438 if (interpolate < 0)
3440 image->interpolate=(InterpolatePixelMethod) interpolate;
3443 status=AddValueToSplayTree((SplayTreeInfo *) image->properties,
3444 ConstantString(property),ConstantString(value));
3450 if (LocaleCompare(property,"loop") == 0)
3452 image->iterations=StringToUnsignedLong(value);
3455 status=AddValueToSplayTree((SplayTreeInfo *) image->properties,
3456 ConstantString(property),ConstantString(value));
3462 if (LocaleCompare(property,"page") == 0)
3467 geometry=GetPageGeometry(value);
3468 flags=ParseAbsoluteGeometry(geometry,&image->page);
3469 geometry=DestroyString(geometry);
3472 if (LocaleCompare(property,"profile") == 0)
3480 image_info=AcquireImageInfo();
3481 (void) CopyMagickString(image_info->filename,value,MaxTextExtent);
3482 (void) SetImageInfo(image_info,1,exception);
3483 profile=FileToStringInfo(image_info->filename,~0UL,exception);
3484 if (profile != (StringInfo *) NULL)
3485 status=SetImageProfile(image,image_info->magick,profile);
3486 image_info=DestroyImageInfo(image_info);
3489 status=AddValueToSplayTree((SplayTreeInfo *) image->properties,
3490 ConstantString(property),ConstantString(value));
3496 if (LocaleCompare(property,"rendering-intent") == 0)
3501 rendering_intent=ParseCommandOption(MagickIntentOptions,MagickFalse,
3503 if (rendering_intent < 0)
3505 image->rendering_intent=(RenderingIntent) rendering_intent;
3508 status=AddValueToSplayTree((SplayTreeInfo *) image->properties,
3509 ConstantString(property),ConstantString(value));
3515 if (LocaleCompare(property,"tile-offset") == 0)
3520 geometry=GetPageGeometry(value);
3521 flags=ParseAbsoluteGeometry(geometry,&image->tile_offset);
3522 geometry=DestroyString(geometry);
3525 status=AddValueToSplayTree((SplayTreeInfo *) image->properties,
3526 ConstantString(property),ConstantString(value));
3532 if (LocaleCompare(property,"units") == 0)
3537 units=ParseCommandOption(MagickResolutionOptions,MagickFalse,value);
3540 image->units=(ResolutionType) units;
3543 status=AddValueToSplayTree((SplayTreeInfo *) image->properties,
3544 ConstantString(property),ConstantString(value));
3549 status=AddValueToSplayTree((SplayTreeInfo *) image->properties,
3550 ConstantString(property),ConstantString(value));