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-2013 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/artifact.h"
45 #include "MagickCore/attribute.h"
46 #include "MagickCore/cache.h"
47 #include "MagickCore/color.h"
48 #include "MagickCore/color-private.h"
49 #include "MagickCore/colorspace-private.h"
50 #include "MagickCore/compare.h"
51 #include "MagickCore/constitute.h"
52 #include "MagickCore/draw.h"
53 #include "MagickCore/effect.h"
54 #include "MagickCore/exception.h"
55 #include "MagickCore/exception-private.h"
56 #include "MagickCore/fx.h"
57 #include "MagickCore/fx-private.h"
58 #include "MagickCore/gem.h"
59 #include "MagickCore/geometry.h"
60 #include "MagickCore/histogram.h"
61 #include "MagickCore/image.h"
62 #include "MagickCore/layer.h"
63 #include "MagickCore/locale-private.h"
64 #include "MagickCore/list.h"
65 #include "MagickCore/magick.h"
66 #include "MagickCore/memory_.h"
67 #include "MagickCore/monitor.h"
68 #include "MagickCore/montage.h"
69 #include "MagickCore/option.h"
70 #include "MagickCore/profile.h"
71 #include "MagickCore/property.h"
72 #include "MagickCore/quantum.h"
73 #include "MagickCore/resource_.h"
74 #include "MagickCore/splay-tree.h"
75 #include "MagickCore/signature.h"
76 #include "MagickCore/statistic.h"
77 #include "MagickCore/string_.h"
78 #include "MagickCore/string-private.h"
79 #include "MagickCore/token.h"
80 #include "MagickCore/token-private.h"
81 #include "MagickCore/utility.h"
82 #include "MagickCore/utility-private.h"
83 #include "MagickCore/version.h"
84 #include "MagickCore/xml-tree.h"
85 #include "MagickCore/xml-tree-private.h"
88 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
92 % C l o n e I m a g e P r o p e r t i e s %
96 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
98 % CloneImageProperties() clones all the image properties to another image.
100 % The format of the CloneImageProperties method is:
102 % MagickBooleanType CloneImageProperties(Image *image,
103 % const Image *clone_image)
105 % A description of each parameter follows:
107 % o image: the image.
109 % o clone_image: the clone image.
112 MagickExport MagickBooleanType CloneImageProperties(Image *image,
113 const Image *clone_image)
115 assert(image != (Image *) NULL);
116 assert(image->signature == MagickSignature);
117 if( IfMagickTrue(image->debug) )
118 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
119 assert(clone_image != (const Image *) NULL);
120 assert(clone_image->signature == MagickSignature);
121 if( IfMagickTrue(clone_image->debug) )
122 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
123 clone_image->filename);
124 (void) CopyMagickString(image->filename,clone_image->filename,MaxTextExtent);
125 (void) CopyMagickString(image->magick_filename,clone_image->magick_filename,
127 image->compression=clone_image->compression;
128 image->quality=clone_image->quality;
129 image->depth=clone_image->depth;
130 image->background_color=clone_image->background_color;
131 image->border_color=clone_image->border_color;
132 image->matte_color=clone_image->matte_color;
133 image->transparent_color=clone_image->transparent_color;
134 image->gamma=clone_image->gamma;
135 image->chromaticity=clone_image->chromaticity;
136 image->rendering_intent=clone_image->rendering_intent;
137 image->black_point_compensation=clone_image->black_point_compensation;
138 image->units=clone_image->units;
139 image->montage=(char *) NULL;
140 image->directory=(char *) NULL;
141 (void) CloneString(&image->geometry,clone_image->geometry);
142 image->offset=clone_image->offset;
143 image->resolution.x=clone_image->resolution.x;
144 image->resolution.y=clone_image->resolution.y;
145 image->page=clone_image->page;
146 image->tile_offset=clone_image->tile_offset;
147 image->extract_info=clone_image->extract_info;
148 image->filter=clone_image->filter;
149 image->fuzz=clone_image->fuzz;
150 image->intensity=clone_image->intensity;
151 image->interlace=clone_image->interlace;
152 image->interpolate=clone_image->interpolate;
153 image->endian=clone_image->endian;
154 image->gravity=clone_image->gravity;
155 image->compose=clone_image->compose;
156 image->scene=clone_image->scene;
157 image->orientation=clone_image->orientation;
158 image->dispose=clone_image->dispose;
159 image->delay=clone_image->delay;
160 image->ticks_per_second=clone_image->ticks_per_second;
161 image->iterations=clone_image->iterations;
162 image->total_colors=clone_image->total_colors;
163 image->taint=clone_image->taint;
164 image->progress_monitor=clone_image->progress_monitor;
165 image->client_data=clone_image->client_data;
166 image->start_loop=clone_image->start_loop;
167 image->error=clone_image->error;
168 image->signature=clone_image->signature;
169 if (clone_image->properties != (void *) NULL)
171 if (image->properties != (void *) NULL)
172 DestroyImageProperties(image);
173 image->properties=CloneSplayTree((SplayTreeInfo *)
174 clone_image->properties,(void *(*)(void *)) ConstantString,
175 (void *(*)(void *)) ConstantString);
181 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
185 % D e f i n e I m a g e P r o p e r t y %
189 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
191 % DefineImageProperty() associates an assignment string of the form
192 % "key=value" with an artifact or options. It is equivelent to
195 % The format of the DefineImageProperty method is:
197 % MagickBooleanType DefineImageProperty(Image *image,const char *property,
198 % ExceptionInfo *exception)
200 % A description of each parameter follows:
202 % o image: the image.
204 % o property: the image property.
206 % o exception: return any errors or warnings in this structure.
209 MagickExport MagickBooleanType DefineImageProperty(Image *image,
210 const char *property,ExceptionInfo *exception)
214 value[MaxTextExtent];
219 assert(image != (Image *) NULL);
220 assert(property != (const char *) NULL);
221 (void) CopyMagickString(key,property,MaxTextExtent-1);
222 for (p=key; *p != '\0'; p++)
227 (void) CopyMagickString(value,p+1,MaxTextExtent);
229 return(SetImageProperty(image,key,value,exception));
233 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
237 % D e l e t e I m a g e P r o p e r t y %
241 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
243 % DeleteImageProperty() deletes an image property.
245 % The format of the DeleteImageProperty method is:
247 % MagickBooleanType DeleteImageProperty(Image *image,const char *property)
249 % A description of each parameter follows:
251 % o image: the image.
253 % o property: the image property.
256 MagickExport MagickBooleanType DeleteImageProperty(Image *image,
257 const char *property)
259 assert(image != (Image *) NULL);
260 assert(image->signature == MagickSignature);
261 if( IfMagickTrue(image->debug) )
262 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
264 if (image->properties == (void *) NULL)
266 return(DeleteNodeFromSplayTree((SplayTreeInfo *) image->properties,property));
270 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
274 % D e s t r o y I m a g e P r o p e r t i e s %
278 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
280 % DestroyImageProperties() destroys all properties and associated memory
281 % attached to the given image.
283 % The format of the DestroyDefines method is:
285 % void DestroyImageProperties(Image *image)
287 % A description of each parameter follows:
289 % o image: the image.
292 MagickExport void DestroyImageProperties(Image *image)
294 assert(image != (Image *) NULL);
295 assert(image->signature == MagickSignature);
296 if( IfMagickTrue(image->debug) )
297 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
299 if (image->properties != (void *) NULL)
300 image->properties=(void *) DestroySplayTree((SplayTreeInfo *)
305 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
309 % F o r m a t I m a g e P r o p e r t y %
313 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
315 % FormatImageProperty() permits formatted property/value pairs to be saved as
318 % The format of the FormatImageProperty method is:
320 % MagickBooleanType FormatImageProperty(Image *image,const char *property,
321 % const char *format,...)
323 % A description of each parameter follows.
325 % o image: The image.
327 % o property: The attribute property.
329 % o format: A string describing the format to use to write the remaining
333 MagickExport MagickBooleanType FormatImageProperty(Image *image,
334 const char *property,const char *format,...)
337 value[MaxTextExtent];
351 va_start(operands,format);
352 n=FormatLocaleStringList(value,MaxTextExtent,format,operands);
355 exception=AcquireExceptionInfo();
356 status=SetImageProperty(image,property,value,exception);
357 exception=DestroyExceptionInfo(exception);
362 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
366 % G e t I m a g e P r o p e r t y %
370 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
372 % GetImageProperty() gets a value associated with an image property.
374 % This includes, profile prefixes, such as "exif:", "iptc:" and "8bim:"
375 % It does not handle non-prifile prefixes, such as "fx:", "option:", or
378 % The returned string is stored as a properity of the same name for faster
379 % lookup later. It should NOT be freed by the caller.
381 % The format of the GetImageProperty method is:
383 % const char *GetImageProperty(const Image *image,const char *key,
384 % ExceptionInfo *exception)
386 % A description of each parameter follows:
388 % o image: the image.
392 % o exception: return any errors or warnings in this structure.
397 *TracePSClippath(const unsigned char *,size_t,const size_t,
399 *TraceSVGClippath(const unsigned char *,size_t,const size_t,
402 static MagickBooleanType GetIPTCProperty(const Image *image,const char *key,
403 ExceptionInfo *exception)
423 profile=GetImageProfile(image,"iptc");
424 if (profile == (StringInfo *) NULL)
425 profile=GetImageProfile(image,"8bim");
426 if (profile == (StringInfo *) NULL)
428 count=sscanf(key,"IPTC:%ld:%ld",&dataset,&record);
431 attribute=(char *) NULL;
432 for (i=0; i < (ssize_t) GetStringInfoLength(profile); i+=(ssize_t) length)
435 if ((ssize_t) GetStringInfoDatum(profile)[i] != 0x1c)
437 length=(size_t) (GetStringInfoDatum(profile)[i+3] << 8);
438 length|=GetStringInfoDatum(profile)[i+4];
439 if (((long) GetStringInfoDatum(profile)[i+1] == dataset) &&
440 ((long) GetStringInfoDatum(profile)[i+2] == record))
442 message=(char *) NULL;
444 message=(char *) AcquireQuantumMemory(length+1UL,sizeof(*message));
445 if (message != (char *) NULL)
447 (void) CopyMagickString(message,(char *) GetStringInfoDatum(
448 profile)+i+5,length+1);
449 (void) ConcatenateString(&attribute,message);
450 (void) ConcatenateString(&attribute,";");
451 message=DestroyString(message);
456 if ((attribute == (char *) NULL) || (*attribute == ';'))
458 if (attribute != (char *) NULL)
459 attribute=DestroyString(attribute);
462 attribute[strlen(attribute)-1]='\0';
463 (void) SetImageProperty((Image *) image,key,(const char *) attribute,
465 attribute=DestroyString(attribute);
469 static inline ssize_t MagickMax(const ssize_t x,const ssize_t y)
476 static inline ssize_t MagickMin(const ssize_t x,const ssize_t y)
483 static inline int ReadPropertyByte(const unsigned char **p,size_t *length)
495 static inline size_t ReadPropertyMSBLong(const unsigned char **p,
512 for (i=0; i < 4; i++)
516 buffer[i]=(unsigned char) c;
518 value=(size_t) (buffer[0] << 24);
519 value|=buffer[1] << 16;
520 value|=buffer[2] << 8;
522 return(value & 0xffffffff);
525 static inline unsigned short ReadPropertyMSBShort(const unsigned char **p,
541 return((unsigned short) ~0U);
542 for (i=0; i < 2; i++)
546 buffer[i]=(unsigned char) c;
548 value=(unsigned short) (buffer[0] << 8);
550 return((unsigned short) (value & 0xffff));
553 static MagickBooleanType Get8BIMProperty(const Image *image,const char *key,
554 ExceptionInfo *exception)
558 format[MaxTextExtent],
587 There are no newlines in path names, so it's safe as terminator.
589 profile=GetImageProfile(image,"8bim");
590 if (profile == (StringInfo *) NULL)
592 count=(ssize_t) sscanf(key,"8BIM:%ld,%ld:%[^\n]\n%[^\n]",&start,&stop,name,
594 if ((count != 2) && (count != 3) && (count != 4))
597 (void) CopyMagickString(format,"SVG",MaxTextExtent);
602 sub_number=(ssize_t) StringToLong(&name[1]);
603 sub_number=MagickMax(sub_number,1L);
604 resource=(char *) NULL;
606 length=GetStringInfoLength(profile);
607 info=GetStringInfoDatum(profile);
608 while ((length > 0) && IfMagickFalse(status))
610 if (ReadPropertyByte(&info,&length) != (unsigned char) '8')
612 if (ReadPropertyByte(&info,&length) != (unsigned char) 'B')
614 if (ReadPropertyByte(&info,&length) != (unsigned char) 'I')
616 if (ReadPropertyByte(&info,&length) != (unsigned char) 'M')
618 id=(ssize_t) ((int) ReadPropertyMSBShort(&info,&length));
619 if (id < (ssize_t) start)
621 if (id > (ssize_t) stop)
623 if (resource != (char *) NULL)
624 resource=DestroyString(resource);
625 count=(ssize_t) ReadPropertyByte(&info,&length);
626 if ((count != 0) && ((size_t) count <= length))
628 resource=(char *) NULL;
629 if (~((size_t) count) >= (MaxTextExtent-1))
630 resource=(char *) AcquireQuantumMemory((size_t) count+MaxTextExtent,
632 if (resource != (char *) NULL)
634 for (i=0; i < (ssize_t) count; i++)
635 resource[i]=(char) ReadPropertyByte(&info,&length);
636 resource[count]='\0';
639 if ((count & 0x01) == 0)
640 (void) ReadPropertyByte(&info,&length);
641 count=(ssize_t) ((int) ReadPropertyMSBLong(&info,&length));
642 if ((*name != '\0') && (*name != '#'))
643 if ((resource == (char *) NULL) || (LocaleCompare(name,resource) != 0))
646 No name match, scroll forward and try next.
649 length-=MagickMin(count,(ssize_t) length);
652 if ((*name == '#') && (sub_number != 1))
655 No numbered match, scroll forward and try next.
659 length-=MagickMin(count,(ssize_t) length);
663 We have the resource of interest.
665 attribute=(char *) NULL;
666 if (~((size_t) count) >= (MaxTextExtent-1))
667 attribute=(char *) AcquireQuantumMemory((size_t) count+MaxTextExtent,
669 if (attribute != (char *) NULL)
671 (void) CopyMagickMemory(attribute,(char *) info,(size_t) count);
672 attribute[count]='\0';
674 length-=MagickMin(count,(ssize_t) length);
675 if ((id <= 1999) || (id >= 2999))
676 (void) SetImageProperty((Image *) image,key,(const char *)
677 attribute,exception);
683 if (LocaleCompare(format,"svg") == 0)
684 path=TraceSVGClippath((unsigned char *) attribute,(size_t) count,
685 image->columns,image->rows);
687 path=TracePSClippath((unsigned char *) attribute,(size_t) count,
688 image->columns,image->rows);
689 (void) SetImageProperty((Image *) image,key,(const char *) path,
691 path=DestroyString(path);
693 attribute=DestroyString(attribute);
697 if (resource != (char *) NULL)
698 resource=DestroyString(resource);
702 static inline unsigned short ReadPropertyShort(const EndianType endian,
703 const unsigned char *buffer)
708 if (endian == LSBEndian)
710 value=(unsigned short) ((buffer[1] << 8) | buffer[0]);
711 return((unsigned short) (value & 0xffff));
713 value=(unsigned short) ((((unsigned char *) buffer)[0] << 8) |
714 ((unsigned char *) buffer)[1]);
715 return((unsigned short) (value & 0xffff));
718 static inline size_t ReadPropertyLong(const EndianType endian,
719 const unsigned char *buffer)
724 if (endian == LSBEndian)
726 value=(size_t) ((buffer[3] << 24) | (buffer[2] << 16) |
727 (buffer[1] << 8 ) | (buffer[0]));
728 return((size_t) (value & 0xffffffff));
730 value=(size_t) ((buffer[0] << 24) | (buffer[1] << 16) |
731 (buffer[2] << 8) | buffer[3]);
732 return((size_t) (value & 0xffffffff));
735 static MagickBooleanType GetEXIFProperty(const Image *image,
736 const char *property,ExceptionInfo *exception)
738 #define MaxDirectoryStack 16
739 #define EXIF_DELIMITER "\n"
740 #define EXIF_NUM_FORMATS 12
741 #define EXIF_FMT_BYTE 1
742 #define EXIF_FMT_STRING 2
743 #define EXIF_FMT_USHORT 3
744 #define EXIF_FMT_ULONG 4
745 #define EXIF_FMT_URATIONAL 5
746 #define EXIF_FMT_SBYTE 6
747 #define EXIF_FMT_UNDEFINED 7
748 #define EXIF_FMT_SSHORT 8
749 #define EXIF_FMT_SLONG 9
750 #define EXIF_FMT_SRATIONAL 10
751 #define EXIF_FMT_SINGLE 11
752 #define EXIF_FMT_DOUBLE 12
753 #define TAG_EXIF_OFFSET 0x8769
754 #define TAG_GPS_OFFSET 0x8825
755 #define TAG_INTEROP_OFFSET 0xa005
757 #define EXIFMultipleValues(size,format,arg) \
770 for (component=0; component < components; component++) \
772 length+=FormatLocaleString(buffer+length,MaxTextExtent-length, \
774 if (length >= (MaxTextExtent-1)) \
775 length=MaxTextExtent-1; \
779 buffer[length-2]='\0'; \
780 value=AcquireString(buffer); \
783 #define EXIFMultipleFractions(size,format,arg1,arg2) \
796 for (component=0; component < components; component++) \
798 length+=FormatLocaleString(buffer+length,MaxTextExtent-length, \
799 format", ",(arg1),(arg2)); \
800 if (length >= (MaxTextExtent-1)) \
801 length=MaxTextExtent-1; \
805 buffer[length-2]='\0'; \
806 value=AcquireString(buffer); \
809 typedef struct _DirectoryInfo
821 typedef struct _TagInfo
833 { 0x001, "exif:InteroperabilityIndex" },
834 { 0x002, "exif:InteroperabilityVersion" },
835 { 0x100, "exif:ImageWidth" },
836 { 0x101, "exif:ImageLength" },
837 { 0x102, "exif:BitsPerSample" },
838 { 0x103, "exif:Compression" },
839 { 0x106, "exif:PhotometricInterpretation" },
840 { 0x10a, "exif:FillOrder" },
841 { 0x10d, "exif:DocumentName" },
842 { 0x10e, "exif:ImageDescription" },
843 { 0x10f, "exif:Make" },
844 { 0x110, "exif:Model" },
845 { 0x111, "exif:StripOffsets" },
846 { 0x112, "exif:Orientation" },
847 { 0x115, "exif:SamplesPerPixel" },
848 { 0x116, "exif:RowsPerStrip" },
849 { 0x117, "exif:StripByteCounts" },
850 { 0x11a, "exif:XResolution" },
851 { 0x11b, "exif:YResolution" },
852 { 0x11c, "exif:PlanarConfiguration" },
853 { 0x11d, "exif:PageName" },
854 { 0x11e, "exif:XPosition" },
855 { 0x11f, "exif:YPosition" },
856 { 0x118, "exif:MinSampleValue" },
857 { 0x119, "exif:MaxSampleValue" },
858 { 0x120, "exif:FreeOffsets" },
859 { 0x121, "exif:FreeByteCounts" },
860 { 0x122, "exif:GrayResponseUnit" },
861 { 0x123, "exif:GrayResponseCurve" },
862 { 0x124, "exif:T4Options" },
863 { 0x125, "exif:T6Options" },
864 { 0x128, "exif:ResolutionUnit" },
865 { 0x12d, "exif:TransferFunction" },
866 { 0x131, "exif:Software" },
867 { 0x132, "exif:DateTime" },
868 { 0x13b, "exif:Artist" },
869 { 0x13e, "exif:WhitePoint" },
870 { 0x13f, "exif:PrimaryChromaticities" },
871 { 0x140, "exif:ColorMap" },
872 { 0x141, "exif:HalfToneHints" },
873 { 0x142, "exif:TileWidth" },
874 { 0x143, "exif:TileLength" },
875 { 0x144, "exif:TileOffsets" },
876 { 0x145, "exif:TileByteCounts" },
877 { 0x14a, "exif:SubIFD" },
878 { 0x14c, "exif:InkSet" },
879 { 0x14d, "exif:InkNames" },
880 { 0x14e, "exif:NumberOfInks" },
881 { 0x150, "exif:DotRange" },
882 { 0x151, "exif:TargetPrinter" },
883 { 0x152, "exif:ExtraSample" },
884 { 0x153, "exif:SampleFormat" },
885 { 0x154, "exif:SMinSampleValue" },
886 { 0x155, "exif:SMaxSampleValue" },
887 { 0x156, "exif:TransferRange" },
888 { 0x157, "exif:ClipPath" },
889 { 0x158, "exif:XClipPathUnits" },
890 { 0x159, "exif:YClipPathUnits" },
891 { 0x15a, "exif:Indexed" },
892 { 0x15b, "exif:JPEGTables" },
893 { 0x15f, "exif:OPIProxy" },
894 { 0x200, "exif:JPEGProc" },
895 { 0x201, "exif:JPEGInterchangeFormat" },
896 { 0x202, "exif:JPEGInterchangeFormatLength" },
897 { 0x203, "exif:JPEGRestartInterval" },
898 { 0x205, "exif:JPEGLosslessPredictors" },
899 { 0x206, "exif:JPEGPointTransforms" },
900 { 0x207, "exif:JPEGQTables" },
901 { 0x208, "exif:JPEGDCTables" },
902 { 0x209, "exif:JPEGACTables" },
903 { 0x211, "exif:YCbCrCoefficients" },
904 { 0x212, "exif:YCbCrSubSampling" },
905 { 0x213, "exif:YCbCrPositioning" },
906 { 0x214, "exif:ReferenceBlackWhite" },
907 { 0x2bc, "exif:ExtensibleMetadataPlatform" },
908 { 0x301, "exif:Gamma" },
909 { 0x302, "exif:ICCProfileDescriptor" },
910 { 0x303, "exif:SRGBRenderingIntent" },
911 { 0x320, "exif:ImageTitle" },
912 { 0x5001, "exif:ResolutionXUnit" },
913 { 0x5002, "exif:ResolutionYUnit" },
914 { 0x5003, "exif:ResolutionXLengthUnit" },
915 { 0x5004, "exif:ResolutionYLengthUnit" },
916 { 0x5005, "exif:PrintFlags" },
917 { 0x5006, "exif:PrintFlagsVersion" },
918 { 0x5007, "exif:PrintFlagsCrop" },
919 { 0x5008, "exif:PrintFlagsBleedWidth" },
920 { 0x5009, "exif:PrintFlagsBleedWidthScale" },
921 { 0x500A, "exif:HalftoneLPI" },
922 { 0x500B, "exif:HalftoneLPIUnit" },
923 { 0x500C, "exif:HalftoneDegree" },
924 { 0x500D, "exif:HalftoneShape" },
925 { 0x500E, "exif:HalftoneMisc" },
926 { 0x500F, "exif:HalftoneScreen" },
927 { 0x5010, "exif:JPEGQuality" },
928 { 0x5011, "exif:GridSize" },
929 { 0x5012, "exif:ThumbnailFormat" },
930 { 0x5013, "exif:ThumbnailWidth" },
931 { 0x5014, "exif:ThumbnailHeight" },
932 { 0x5015, "exif:ThumbnailColorDepth" },
933 { 0x5016, "exif:ThumbnailPlanes" },
934 { 0x5017, "exif:ThumbnailRawBytes" },
935 { 0x5018, "exif:ThumbnailSize" },
936 { 0x5019, "exif:ThumbnailCompressedSize" },
937 { 0x501a, "exif:ColorTransferFunction" },
938 { 0x501b, "exif:ThumbnailData" },
939 { 0x5020, "exif:ThumbnailImageWidth" },
940 { 0x5021, "exif:ThumbnailImageHeight" },
941 { 0x5022, "exif:ThumbnailBitsPerSample" },
942 { 0x5023, "exif:ThumbnailCompression" },
943 { 0x5024, "exif:ThumbnailPhotometricInterp" },
944 { 0x5025, "exif:ThumbnailImageDescription" },
945 { 0x5026, "exif:ThumbnailEquipMake" },
946 { 0x5027, "exif:ThumbnailEquipModel" },
947 { 0x5028, "exif:ThumbnailStripOffsets" },
948 { 0x5029, "exif:ThumbnailOrientation" },
949 { 0x502a, "exif:ThumbnailSamplesPerPixel" },
950 { 0x502b, "exif:ThumbnailRowsPerStrip" },
951 { 0x502c, "exif:ThumbnailStripBytesCount" },
952 { 0x502d, "exif:ThumbnailResolutionX" },
953 { 0x502e, "exif:ThumbnailResolutionY" },
954 { 0x502f, "exif:ThumbnailPlanarConfig" },
955 { 0x5030, "exif:ThumbnailResolutionUnit" },
956 { 0x5031, "exif:ThumbnailTransferFunction" },
957 { 0x5032, "exif:ThumbnailSoftwareUsed" },
958 { 0x5033, "exif:ThumbnailDateTime" },
959 { 0x5034, "exif:ThumbnailArtist" },
960 { 0x5035, "exif:ThumbnailWhitePoint" },
961 { 0x5036, "exif:ThumbnailPrimaryChromaticities" },
962 { 0x5037, "exif:ThumbnailYCbCrCoefficients" },
963 { 0x5038, "exif:ThumbnailYCbCrSubsampling" },
964 { 0x5039, "exif:ThumbnailYCbCrPositioning" },
965 { 0x503A, "exif:ThumbnailRefBlackWhite" },
966 { 0x503B, "exif:ThumbnailCopyRight" },
967 { 0x5090, "exif:LuminanceTable" },
968 { 0x5091, "exif:ChrominanceTable" },
969 { 0x5100, "exif:FrameDelay" },
970 { 0x5101, "exif:LoopCount" },
971 { 0x5110, "exif:PixelUnit" },
972 { 0x5111, "exif:PixelPerUnitX" },
973 { 0x5112, "exif:PixelPerUnitY" },
974 { 0x5113, "exif:PaletteHistogram" },
975 { 0x1000, "exif:RelatedImageFileFormat" },
976 { 0x1001, "exif:RelatedImageLength" },
977 { 0x1002, "exif:RelatedImageWidth" },
978 { 0x800d, "exif:ImageID" },
979 { 0x80e3, "exif:Matteing" },
980 { 0x80e4, "exif:DataType" },
981 { 0x80e5, "exif:ImageDepth" },
982 { 0x80e6, "exif:TileDepth" },
983 { 0x828d, "exif:CFARepeatPatternDim" },
984 { 0x828e, "exif:CFAPattern2" },
985 { 0x828f, "exif:BatteryLevel" },
986 { 0x8298, "exif:Copyright" },
987 { 0x829a, "exif:ExposureTime" },
988 { 0x829d, "exif:FNumber" },
989 { 0x83bb, "exif:IPTC/NAA" },
990 { 0x84e3, "exif:IT8RasterPadding" },
991 { 0x84e5, "exif:IT8ColorTable" },
992 { 0x8649, "exif:ImageResourceInformation" },
993 { 0x8769, "exif:ExifOffset" },
994 { 0x8773, "exif:InterColorProfile" },
995 { 0x8822, "exif:ExposureProgram" },
996 { 0x8824, "exif:SpectralSensitivity" },
997 { 0x8825, "exif:GPSInfo" },
998 { 0x8827, "exif:ISOSpeedRatings" },
999 { 0x8828, "exif:OECF" },
1000 { 0x8829, "exif:Interlace" },
1001 { 0x882a, "exif:TimeZoneOffset" },
1002 { 0x882b, "exif:SelfTimerMode" },
1003 { 0x9000, "exif:ExifVersion" },
1004 { 0x9003, "exif:DateTimeOriginal" },
1005 { 0x9004, "exif:DateTimeDigitized" },
1006 { 0x9101, "exif:ComponentsConfiguration" },
1007 { 0x9102, "exif:CompressedBitsPerPixel" },
1008 { 0x9201, "exif:ShutterSpeedValue" },
1009 { 0x9202, "exif:ApertureValue" },
1010 { 0x9203, "exif:BrightnessValue" },
1011 { 0x9204, "exif:ExposureBiasValue" },
1012 { 0x9205, "exif:MaxApertureValue" },
1013 { 0x9206, "exif:SubjectDistance" },
1014 { 0x9207, "exif:MeteringMode" },
1015 { 0x9208, "exif:LightSource" },
1016 { 0x9209, "exif:Flash" },
1017 { 0x920a, "exif:FocalLength" },
1018 { 0x920b, "exif:FlashEnergy" },
1019 { 0x920c, "exif:SpatialFrequencyResponse" },
1020 { 0x920d, "exif:Noise" },
1021 { 0x9211, "exif:ImageNumber" },
1022 { 0x9212, "exif:SecurityClassification" },
1023 { 0x9213, "exif:ImageHistory" },
1024 { 0x9214, "exif:SubjectArea" },
1025 { 0x9215, "exif:ExposureIndex" },
1026 { 0x9216, "exif:TIFF-EPStandardID" },
1027 { 0x927c, "exif:MakerNote" },
1028 { 0x9C9b, "exif:WinXP-Title" },
1029 { 0x9C9c, "exif:WinXP-Comments" },
1030 { 0x9C9d, "exif:WinXP-Author" },
1031 { 0x9C9e, "exif:WinXP-Keywords" },
1032 { 0x9C9f, "exif:WinXP-Subject" },
1033 { 0x9286, "exif:UserComment" },
1034 { 0x9290, "exif:SubSecTime" },
1035 { 0x9291, "exif:SubSecTimeOriginal" },
1036 { 0x9292, "exif:SubSecTimeDigitized" },
1037 { 0xa000, "exif:FlashPixVersion" },
1038 { 0xa001, "exif:ColorSpace" },
1039 { 0xa002, "exif:ExifImageWidth" },
1040 { 0xa003, "exif:ExifImageLength" },
1041 { 0xa004, "exif:RelatedSoundFile" },
1042 { 0xa005, "exif:InteroperabilityOffset" },
1043 { 0xa20b, "exif:FlashEnergy" },
1044 { 0xa20c, "exif:SpatialFrequencyResponse" },
1045 { 0xa20d, "exif:Noise" },
1046 { 0xa20e, "exif:FocalPlaneXResolution" },
1047 { 0xa20f, "exif:FocalPlaneYResolution" },
1048 { 0xa210, "exif:FocalPlaneResolutionUnit" },
1049 { 0xa214, "exif:SubjectLocation" },
1050 { 0xa215, "exif:ExposureIndex" },
1051 { 0xa216, "exif:TIFF/EPStandardID" },
1052 { 0xa217, "exif:SensingMethod" },
1053 { 0xa300, "exif:FileSource" },
1054 { 0xa301, "exif:SceneType" },
1055 { 0xa302, "exif:CFAPattern" },
1056 { 0xa401, "exif:CustomRendered" },
1057 { 0xa402, "exif:ExposureMode" },
1058 { 0xa403, "exif:WhiteBalance" },
1059 { 0xa404, "exif:DigitalZoomRatio" },
1060 { 0xa405, "exif:FocalLengthIn35mmFilm" },
1061 { 0xa406, "exif:SceneCaptureType" },
1062 { 0xa407, "exif:GainControl" },
1063 { 0xa408, "exif:Contrast" },
1064 { 0xa409, "exif:Saturation" },
1065 { 0xa40a, "exif:Sharpness" },
1066 { 0xa40b, "exif:DeviceSettingDescription" },
1067 { 0xa40c, "exif:SubjectDistanceRange" },
1068 { 0xa420, "exif:ImageUniqueID" },
1069 { 0xc4a5, "exif:PrintImageMatching" },
1070 { 0xa500, "exif:Gamma" },
1071 { 0xc640, "exif:CR2Slice" },
1072 { 0x10000, "exif:GPSVersionID" },
1073 { 0x10001, "exif:GPSLatitudeRef" },
1074 { 0x10002, "exif:GPSLatitude" },
1075 { 0x10003, "exif:GPSLongitudeRef" },
1076 { 0x10004, "exif:GPSLongitude" },
1077 { 0x10005, "exif:GPSAltitudeRef" },
1078 { 0x10006, "exif:GPSAltitude" },
1079 { 0x10007, "exif:GPSTimeStamp" },
1080 { 0x10008, "exif:GPSSatellites" },
1081 { 0x10009, "exif:GPSStatus" },
1082 { 0x1000a, "exif:GPSMeasureMode" },
1083 { 0x1000b, "exif:GPSDop" },
1084 { 0x1000c, "exif:GPSSpeedRef" },
1085 { 0x1000d, "exif:GPSSpeed" },
1086 { 0x1000e, "exif:GPSTrackRef" },
1087 { 0x1000f, "exif:GPSTrack" },
1088 { 0x10010, "exif:GPSImgDirectionRef" },
1089 { 0x10011, "exif:GPSImgDirection" },
1090 { 0x10012, "exif:GPSMapDatum" },
1091 { 0x10013, "exif:GPSDestLatitudeRef" },
1092 { 0x10014, "exif:GPSDestLatitude" },
1093 { 0x10015, "exif:GPSDestLongitudeRef" },
1094 { 0x10016, "exif:GPSDestLongitude" },
1095 { 0x10017, "exif:GPSDestBearingRef" },
1096 { 0x10018, "exif:GPSDestBearing" },
1097 { 0x10019, "exif:GPSDestDistanceRef" },
1098 { 0x1001a, "exif:GPSDestDistance" },
1099 { 0x1001b, "exif:GPSProcessingMethod" },
1100 { 0x1001c, "exif:GPSAreaInformation" },
1101 { 0x1001d, "exif:GPSDateStamp" },
1102 { 0x1001e, "exif:GPSDifferential" },
1103 { 0x00000, (const char *) NULL }
1114 directory_stack[MaxDirectoryStack];
1143 tag_bytes[] = {0, 1, 1, 2, 4, 8, 1, 1, 2, 4, 8, 4, 8};
1146 If EXIF data exists, then try to parse the request for a tag.
1148 profile=GetImageProfile(image,"exif");
1149 if (profile == (StringInfo *) NULL)
1150 return(MagickFalse);
1151 if ((property == (const char *) NULL) || (*property == '\0'))
1152 return(MagickFalse);
1153 while (isspace((int) ((unsigned char) *property)) != 0)
1157 switch (*(property+5))
1162 Caller has asked for all the tags in the EXIF data.
1165 all=1; /* return the data in description=value format */
1171 all=2; /* return the data in tagid=value format */
1184 Check for a hex based tag specification first.
1186 tag=(*(property+5) == '@') ? 1UL : 0UL;
1190 return(MagickFalse);
1192 Parse tag specification as a hex number.
1197 for (i=(ssize_t) n-1L; i >= 0; i--)
1201 if ((c >= '0') && (c <= '9'))
1204 if ((c >= 'A') && (c <= 'F'))
1207 if ((c >= 'a') && (c <= 'f'))
1210 return(MagickFalse);
1212 } while (*property != '\0');
1218 Try to match the text with a tag name instead.
1222 if (EXIFTag[i].tag == 0)
1224 if (LocaleCompare(EXIFTag[i].description,property) == 0)
1226 tag=(size_t) EXIFTag[i].tag;
1234 return(MagickFalse);
1235 length=GetStringInfoLength(profile);
1236 exif=GetStringInfoDatum(profile);
1239 if (ReadPropertyByte(&exif,&length) != 0x45)
1241 if (ReadPropertyByte(&exif,&length) != 0x78)
1243 if (ReadPropertyByte(&exif,&length) != 0x69)
1245 if (ReadPropertyByte(&exif,&length) != 0x66)
1247 if (ReadPropertyByte(&exif,&length) != 0x00)
1249 if (ReadPropertyByte(&exif,&length) != 0x00)
1254 return(MagickFalse);
1255 id=(ssize_t) ((int) ReadPropertyShort(LSBEndian,exif));
1263 return(MagickFalse);
1264 if (ReadPropertyShort(endian,exif+2) != 0x002a)
1265 return(MagickFalse);
1267 This the offset to the first IFD.
1269 offset=(ssize_t) ((int) ReadPropertyLong(endian,exif+4));
1270 if ((offset < 0) || (size_t) offset >= length)
1271 return(MagickFalse);
1273 Set the pointer to the first IFD and follow it were it leads.
1276 directory=exif+offset;
1280 exif_resources=NewSplayTree((int (*)(const void *,const void *)) NULL,
1281 (void *(*)(void *)) NULL,(void *(*)(void *)) NULL);
1285 If there is anything on the stack then pop it off.
1290 directory=directory_stack[level].directory;
1291 entry=directory_stack[level].entry;
1292 tag_offset=directory_stack[level].offset;
1295 Determine how many entries there are in the current IFD.
1297 number_entries=(size_t) ((int) ReadPropertyShort(endian,directory));
1298 for ( ; entry < number_entries; entry++)
1300 register unsigned char
1311 q=(unsigned char *) (directory+(12*entry)+2);
1312 if (GetValueFromSplayTree(exif_resources,q) == q)
1314 (void) AddValueToSplayTree(exif_resources,q,q);
1315 tag_value=(ssize_t) ((int) ReadPropertyShort(endian,q)+tag_offset);
1316 format=(size_t) ((int) ReadPropertyShort(endian,q+2));
1317 if (format >= (sizeof(tag_bytes)/sizeof(*tag_bytes)))
1319 components=(ssize_t) ((int) ReadPropertyLong(endian,q+4));
1320 number_bytes=(size_t) components*tag_bytes[format];
1321 if (number_bytes < components)
1322 break; /* prevent overflow */
1323 if (number_bytes <= 4)
1331 The directory entry contains an offset.
1333 offset=(ssize_t) ((int) ReadPropertyLong(endian,q+8));
1334 if ((ssize_t) (offset+number_bytes) < offset)
1335 continue; /* prevent overflow */
1336 if ((size_t) (offset+number_bytes) > length)
1338 p=(unsigned char *) (exif+offset);
1340 if ((all != 0) || (tag == (size_t) tag_value))
1343 buffer[MaxTextExtent],
1346 value=(char *) NULL;
1351 case EXIF_FMT_UNDEFINED:
1353 EXIFMultipleValues(1,"%.20g",(double) (*(unsigned char *) p1));
1356 case EXIF_FMT_SBYTE:
1358 EXIFMultipleValues(1,"%.20g",(double) (*(signed char *) p1));
1361 case EXIF_FMT_SSHORT:
1363 EXIFMultipleValues(2,"%hd",ReadPropertyShort(endian,p1));
1366 case EXIF_FMT_USHORT:
1368 EXIFMultipleValues(2,"%hu",ReadPropertyShort(endian,p1));
1371 case EXIF_FMT_ULONG:
1373 EXIFMultipleValues(4,"%.20g",(double)
1374 ((int) ReadPropertyLong(endian,p1)));
1377 case EXIF_FMT_SLONG:
1379 EXIFMultipleValues(4,"%.20g",(double)
1380 ((int) ReadPropertyLong(endian,p1)));
1383 case EXIF_FMT_URATIONAL:
1385 EXIFMultipleFractions(8,"%.20g/%.20g",(double)
1386 ((int) ReadPropertyLong(endian,p1)),(double)
1387 ((int) ReadPropertyLong(endian,p1+4)));
1390 case EXIF_FMT_SRATIONAL:
1392 EXIFMultipleFractions(8,"%.20g/%.20g",(double)
1393 ((int) ReadPropertyLong(endian,p1)),(double)
1394 ((int) ReadPropertyLong(endian,p1+4)));
1397 case EXIF_FMT_SINGLE:
1399 EXIFMultipleValues(4,"%f",(double) *(float *) p1);
1402 case EXIF_FMT_DOUBLE:
1404 EXIFMultipleValues(8,"%f",*(double *) p1);
1408 case EXIF_FMT_STRING:
1410 value=(char *) NULL;
1411 if (~((size_t) number_bytes) >= 1)
1412 value=(char *) AcquireQuantumMemory((size_t) number_bytes+1UL,
1414 if (value != (char *) NULL)
1419 for (i=0; i < (ssize_t) number_bytes; i++)
1422 if ((isprint((int) p[i]) != 0) || (p[i] == '\0'))
1423 value[i]=(char) p[i];
1430 if (value != (char *) NULL)
1438 key=AcquireString(property);
1440 (void) SubstituteString(&key,"exif:","exif:thumbnail:");
1451 description="unknown";
1454 if (EXIFTag[i].tag == 0)
1456 if ((ssize_t) EXIFTag[i].tag == tag_value)
1458 description=EXIFTag[i].description;
1462 (void) FormatLocaleString(key,MaxTextExtent,"%s",description);
1467 if (tag_value < 0x10000)
1468 (void) FormatLocaleString(key,MaxTextExtent,"#%04lx",
1469 (unsigned long) tag_value);
1471 if (tag_value < 0x20000)
1472 (void) FormatLocaleString(key,MaxTextExtent,"@%04lx",
1473 (unsigned long) (tag_value & 0xffff));
1475 (void) FormatLocaleString(key,MaxTextExtent,"unknown");
1479 p=(const char *) NULL;
1480 if (image->properties != (void *) NULL)
1481 p=(const char *) GetValueFromSplayTree((SplayTreeInfo *)
1482 image->properties,key);
1483 if (p == (const char *) NULL)
1484 (void) SetImageProperty((Image *) image,key,value,exception);
1485 value=DestroyString(value);
1486 key=DestroyString(key);
1490 if ((tag_value == TAG_EXIF_OFFSET) ||
1491 (tag_value == TAG_INTEROP_OFFSET) || (tag_value == TAG_GPS_OFFSET))
1496 offset=(ssize_t) ((int) ReadPropertyLong(endian,p));
1497 if (((size_t) offset < length) && (level < (MaxDirectoryStack-2)))
1502 tag_offset1=(ssize_t) ((tag_value == TAG_GPS_OFFSET) ? 0x10000 :
1504 directory_stack[level].directory=directory;
1506 directory_stack[level].entry=entry;
1507 directory_stack[level].offset=tag_offset;
1509 directory_stack[level].directory=exif+offset;
1510 directory_stack[level].offset=tag_offset1;
1511 directory_stack[level].entry=0;
1513 if ((directory+2+(12*number_entries)) > (exif+length))
1515 offset=(ssize_t) ((int) ReadPropertyLong(endian,directory+2+(12*
1517 if ((offset != 0) && ((size_t) offset < length) &&
1518 (level < (MaxDirectoryStack-2)))
1520 directory_stack[level].directory=exif+offset;
1521 directory_stack[level].entry=0;
1522 directory_stack[level].offset=tag_offset1;
1529 } while (level > 0);
1530 exif_resources=DestroySplayTree(exif_resources);
1534 static MagickBooleanType GetXMPProperty(const Image *image,const char *property)
1558 profile=GetImageProfile(image,"xmp");
1559 if (profile == (StringInfo *) NULL)
1560 return(MagickFalse);
1561 if ((property == (const char *) NULL) || (*property == '\0'))
1562 return(MagickFalse);
1563 xmp_profile=StringInfoToString(profile);
1564 if (xmp_profile == (char *) NULL)
1565 return(MagickFalse);
1566 for (p=xmp_profile; *p != '\0'; p++)
1567 if ((*p == '<') && (*(p+1) == 'x'))
1569 exception=AcquireExceptionInfo();
1570 xmp=NewXMLTree((char *) p,exception);
1571 xmp_profile=DestroyString(xmp_profile);
1572 exception=DestroyExceptionInfo(exception);
1573 if (xmp == (XMLTreeInfo *) NULL)
1574 return(MagickFalse);
1576 rdf=GetXMLTreeChild(xmp,"rdf:RDF");
1577 if (rdf != (XMLTreeInfo *) NULL)
1579 if (image->properties == (void *) NULL)
1580 ((Image *) image)->properties=NewSplayTree(CompareSplayTreeString,
1581 RelinquishMagickMemory,RelinquishMagickMemory);
1582 description=GetXMLTreeChild(rdf,"rdf:Description");
1583 while (description != (XMLTreeInfo *) NULL)
1585 node=GetXMLTreeChild(description,(const char *) NULL);
1586 while (node != (XMLTreeInfo *) NULL)
1588 child=GetXMLTreeChild(node,(const char *) NULL);
1589 if (child == (XMLTreeInfo *) NULL)
1590 (void) AddValueToSplayTree((SplayTreeInfo *) image->properties,
1591 ConstantString(GetXMLTreeTag(node)),
1592 ConstantString(GetXMLTreeContent(node)));
1593 while (child != (XMLTreeInfo *) NULL)
1595 if (LocaleCompare(GetXMLTreeTag(child),"rdf:Seq") != 0)
1596 (void) AddValueToSplayTree((SplayTreeInfo *) image->properties,
1597 ConstantString(GetXMLTreeTag(child)),
1598 ConstantString(GetXMLTreeContent(child)));
1599 child=GetXMLTreeSibling(child);
1601 node=GetXMLTreeSibling(node);
1603 description=GetNextXMLTreeTag(description);
1606 xmp=DestroyXMLTree(xmp);
1610 static char *TracePSClippath(const unsigned char *blob,size_t length,
1611 const size_t magick_unused(columns),const size_t magick_unused(rows))
1634 path=AcquireString((char *) NULL);
1635 if (path == (char *) NULL)
1636 return((char *) NULL);
1637 message=AcquireString((char *) NULL);
1638 (void) FormatLocaleString(message,MaxTextExtent,"/ClipImage\n");
1639 (void) ConcatenateString(&path,message);
1640 (void) FormatLocaleString(message,MaxTextExtent,"{\n");
1641 (void) ConcatenateString(&path,message);
1642 (void) FormatLocaleString(message,MaxTextExtent," /c {curveto} bind def\n");
1643 (void) ConcatenateString(&path,message);
1644 (void) FormatLocaleString(message,MaxTextExtent," /l {lineto} bind def\n");
1645 (void) ConcatenateString(&path,message);
1646 (void) FormatLocaleString(message,MaxTextExtent," /m {moveto} bind def\n");
1647 (void) ConcatenateString(&path,message);
1648 (void) FormatLocaleString(message,MaxTextExtent,
1649 " /v {currentpoint 6 2 roll curveto} bind def\n");
1650 (void) ConcatenateString(&path,message);
1651 (void) FormatLocaleString(message,MaxTextExtent,
1652 " /y {2 copy curveto} bind def\n");
1653 (void) ConcatenateString(&path,message);
1654 (void) FormatLocaleString(message,MaxTextExtent,
1655 " /z {closepath} bind def\n");
1656 (void) ConcatenateString(&path,message);
1657 (void) FormatLocaleString(message,MaxTextExtent," newpath\n");
1658 (void) ConcatenateString(&path,message);
1660 The clipping path format is defined in "Adobe Photoshop File
1661 Formats Specification" version 6.0 downloadable from adobe.com.
1663 (void) ResetMagickMemory(point,0,sizeof(point));
1664 (void) ResetMagickMemory(first,0,sizeof(first));
1665 (void) ResetMagickMemory(last,0,sizeof(last));
1667 in_subpath=MagickFalse;
1670 selector=(ssize_t) ((int) ReadPropertyMSBShort(&blob,&length));
1676 if (knot_count != 0)
1679 length-=MagickMin(24,(ssize_t) length);
1683 Expected subpath length record.
1685 knot_count=(ssize_t) ((int) ReadPropertyMSBShort(&blob,&length));
1687 length-=MagickMin(22,(ssize_t) length);
1695 if (knot_count == 0)
1698 Unexpected subpath knot
1701 length-=MagickMin(24,(ssize_t) length);
1707 for (i=0; i < 3; i++)
1713 yy=(size_t) ((int) ReadPropertyMSBLong(&blob,&length));
1714 xx=(size_t) ((int) ReadPropertyMSBLong(&blob,&length));
1716 if (xx > 2147483647)
1717 x=(ssize_t) xx-4294967295U-1;
1719 if (yy > 2147483647)
1720 y=(ssize_t) yy-4294967295U-1;
1721 point[i].x=(double) x/4096/4096;
1722 point[i].y=1.0-(double) y/4096/4096;
1724 if( IfMagickFalse(in_subpath) )
1726 (void) FormatLocaleString(message,MaxTextExtent," %g %g m\n",
1727 point[1].x,point[1].y);
1728 for (i=0; i < 3; i++)
1737 Handle special cases when Bezier curves are used to describe
1738 corners and straight lines.
1740 if ((last[1].x == last[2].x) && (last[1].y == last[2].y) &&
1741 (point[0].x == point[1].x) && (point[0].y == point[1].y))
1742 (void) FormatLocaleString(message,MaxTextExtent,
1743 " %g %g l\n",point[1].x,point[1].y);
1745 if ((last[1].x == last[2].x) && (last[1].y == last[2].y))
1746 (void) FormatLocaleString(message,MaxTextExtent,
1747 " %g %g %g %g v\n",point[0].x,point[0].y,
1748 point[1].x,point[1].y);
1750 if ((point[0].x == point[1].x) && (point[0].y == point[1].y))
1751 (void) FormatLocaleString(message,MaxTextExtent,
1752 " %g %g %g %g y\n",last[2].x,last[2].y,
1753 point[1].x,point[1].y);
1755 (void) FormatLocaleString(message,MaxTextExtent,
1756 " %g %g %g %g %g %g c\n",last[2].x,
1757 last[2].y,point[0].x,point[0].y,point[1].x,point[1].y);
1758 for (i=0; i < 3; i++)
1761 (void) ConcatenateString(&path,message);
1762 in_subpath=MagickTrue;
1765 Close the subpath if there are no more knots.
1767 if (knot_count == 0)
1770 Same special handling as above except we compare to the
1771 first point in the path and close the path.
1773 if ((last[1].x == last[2].x) && (last[1].y == last[2].y) &&
1774 (first[0].x == first[1].x) && (first[0].y == first[1].y))
1775 (void) FormatLocaleString(message,MaxTextExtent,
1776 " %g %g l z\n",first[1].x,first[1].y);
1778 if ((last[1].x == last[2].x) && (last[1].y == last[2].y))
1779 (void) FormatLocaleString(message,MaxTextExtent,
1780 " %g %g %g %g v z\n",first[0].x,first[0].y,
1781 first[1].x,first[1].y);
1783 if ((first[0].x == first[1].x) && (first[0].y == first[1].y))
1784 (void) FormatLocaleString(message,MaxTextExtent,
1785 " %g %g %g %g y z\n",last[2].x,last[2].y,
1786 first[1].x,first[1].y);
1788 (void) FormatLocaleString(message,MaxTextExtent,
1789 " %g %g %g %g %g %g c z\n",last[2].x,
1790 last[2].y,first[0].x,first[0].y,first[1].x,first[1].y);
1791 (void) ConcatenateString(&path,message);
1792 in_subpath=MagickFalse;
1802 length-=MagickMin(24,(ssize_t) length);
1808 Returns an empty PS path if the path has no knots.
1810 (void) FormatLocaleString(message,MaxTextExtent," eoclip\n");
1811 (void) ConcatenateString(&path,message);
1812 (void) FormatLocaleString(message,MaxTextExtent,"} bind def");
1813 (void) ConcatenateString(&path,message);
1814 message=DestroyString(message);
1818 static char *TraceSVGClippath(const unsigned char *blob,size_t length,
1819 const size_t columns,const size_t rows)
1842 path=AcquireString((char *) NULL);
1843 if (path == (char *) NULL)
1844 return((char *) NULL);
1845 message=AcquireString((char *) NULL);
1846 (void) FormatLocaleString(message,MaxTextExtent,
1847 "<?xml version=\"1.0\" encoding=\"iso-8859-1\"?>\n");
1848 (void) ConcatenateString(&path,message);
1849 (void) FormatLocaleString(message,MaxTextExtent,
1850 "<svg width=\"%.20g\" height=\"%.20g\">\n",(double) columns,(double) rows);
1851 (void) ConcatenateString(&path,message);
1852 (void) FormatLocaleString(message,MaxTextExtent,"<g>\n");
1853 (void) ConcatenateString(&path,message);
1854 (void) FormatLocaleString(message,MaxTextExtent,
1855 "<path style=\"fill:#00000000;stroke:#00000000;");
1856 (void) ConcatenateString(&path,message);
1857 (void) FormatLocaleString(message,MaxTextExtent,
1858 "stroke-width:0;stroke-antialiasing:false\" d=\"\n");
1859 (void) ConcatenateString(&path,message);
1860 (void) ResetMagickMemory(point,0,sizeof(point));
1861 (void) ResetMagickMemory(first,0,sizeof(first));
1862 (void) ResetMagickMemory(last,0,sizeof(last));
1864 in_subpath=MagickFalse;
1867 selector=(ssize_t) ((int) ReadPropertyMSBShort(&blob,&length));
1873 if (knot_count != 0)
1876 length-=MagickMin(24,(ssize_t) length);
1880 Expected subpath length record.
1882 knot_count=(ssize_t) ((int) ReadPropertyMSBShort(&blob,&length));
1884 length-=MagickMin(22,(ssize_t) length);
1892 if (knot_count == 0)
1895 Unexpected subpath knot.
1898 length-=MagickMin(24,(ssize_t) length);
1904 for (i=0; i < 3; i++)
1910 yy=(size_t) ((int) ReadPropertyMSBLong(&blob,&length));
1911 xx=(size_t) ((int) ReadPropertyMSBLong(&blob,&length));
1913 if (xx > 2147483647)
1914 x=(ssize_t) xx-4294967295U-1;
1916 if (yy > 2147483647)
1917 y=(ssize_t) yy-4294967295U-1;
1918 point[i].x=(double) x*columns/4096/4096;
1919 point[i].y=(double) y*rows/4096/4096;
1921 if( IfMagickFalse(in_subpath) )
1923 (void) FormatLocaleString(message,MaxTextExtent,"M %g,%g\n",
1924 point[1].x,point[1].y);
1925 for (i=0; i < 3; i++)
1933 if ((last[1].x == last[2].x) && (last[1].y == last[2].y) &&
1934 (point[0].x == point[1].x) && (point[0].y == point[1].y))
1935 (void) FormatLocaleString(message,MaxTextExtent,"L %g,%g\n",
1936 point[1].x,point[1].y);
1938 (void) FormatLocaleString(message,MaxTextExtent,
1939 "C %g,%g %g,%g %g,%g\n",last[2].x,last[2].y,
1940 point[0].x,point[0].y,point[1].x,point[1].y);
1941 for (i=0; i < 3; i++)
1944 (void) ConcatenateString(&path,message);
1945 in_subpath=MagickTrue;
1948 Close the subpath if there are no more knots.
1950 if (knot_count == 0)
1952 if ((last[1].x == last[2].x) && (last[1].y == last[2].y) &&
1953 (first[0].x == first[1].x) && (first[0].y == first[1].y))
1954 (void) FormatLocaleString(message,MaxTextExtent,
1955 "L %g,%g Z\n",first[1].x,first[1].y);
1958 (void) FormatLocaleString(message,MaxTextExtent,
1959 "C %g,%g %g,%g %g,%g Z\n",last[2].x,
1960 last[2].y,first[0].x,first[0].y,first[1].x,first[1].y);
1961 (void) ConcatenateString(&path,message);
1963 in_subpath=MagickFalse;
1973 length-=MagickMin(24,(ssize_t) length);
1979 Return an empty SVG image if the path does not have knots.
1981 (void) FormatLocaleString(message,MaxTextExtent,"\"/>\n");
1982 (void) ConcatenateString(&path,message);
1983 (void) FormatLocaleString(message,MaxTextExtent,"</g>\n");
1984 (void) ConcatenateString(&path,message);
1985 (void) FormatLocaleString(message,MaxTextExtent,"</svg>\n");
1986 (void) ConcatenateString(&path,message);
1987 message=DestroyString(message);
1991 MagickExport const char *GetImageProperty(const Image *image,
1992 const char *property,ExceptionInfo *exception)
1997 assert(image != (Image *) NULL);
1998 assert(image->signature == MagickSignature);
1999 if( IfMagickTrue(image->debug) )
2000 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
2002 p=(const char *) NULL;
2003 /* if property is in splay tree - return it and we are done */
2004 if (image->properties != (void *) NULL)
2006 if (property == (const char *) NULL)
2008 ResetSplayTreeIterator((SplayTreeInfo *) image->properties);
2009 p=(const char *) GetNextValueInSplayTree((SplayTreeInfo *)
2013 p=(const char *) GetValueFromSplayTree((SplayTreeInfo *)
2014 image->properties,property);
2015 if (p != (const char *) NULL)
2018 if ((property == (const char *) NULL) ||
2019 (strchr(property,':') == (char *) NULL))
2025 if (LocaleNCompare("8bim:",property,5) == 0)
2027 if( IfMagickTrue(Get8BIMProperty(image,property,exception)) &&
2028 (image->properties != (void *) NULL))
2030 p=(const char *) GetValueFromSplayTree((SplayTreeInfo *)
2031 image->properties,property);
2040 if (LocaleNCompare("exif:",property,5) == 0)
2042 if( IfMagickTrue(GetEXIFProperty(image,property,exception)) &&
2043 (image->properties != (void *) NULL))
2045 p=(const char *) GetValueFromSplayTree((SplayTreeInfo *)
2046 image->properties,property);
2055 if (LocaleNCompare("iptc:",property,5) == 0)
2057 if( IfMagickTrue(GetIPTCProperty(image,property,exception)) &&
2058 (image->properties != (void *) NULL))
2060 p=(const char *) GetValueFromSplayTree((SplayTreeInfo *)
2061 image->properties,property);
2070 if (LocaleNCompare("xmp:",property,4) == 0)
2072 if( IfMagickTrue(GetXMPProperty(image,property)) &&
2073 (image->properties != (void *) NULL))
2075 p=(const char *) GetValueFromSplayTree((SplayTreeInfo *)
2076 image->properties,property);
2089 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2093 + G e t M a g i c k P r o p e r t y %
2097 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2099 % GetMagickProperty() gets attributes or calculated values that is associated
2100 % with a fixed known property name, or single letter property. It may be
2101 % called if no image is defined (IMv7), in which case only global image_info
2102 % values are available.
2104 % This routine only handles specifically known properties. It does not
2105 % handle special prefixed properties, profiles, or expressions. Nor does
2106 % it return any free-form property strings.
2108 % The returned string is stored in a structure somewhere, and should not be
2109 % directly freed. If the string was generated (common) the string will be
2110 % stored as as either as artifact or option 'get-property'. These may be
2111 % deleted (cleaned up) when no longer required, but neither artifact or
2112 % option is guranteed to exist.
2114 % The format of the GetMagickProperty method is:
2116 % const char *GetMagickProperty(ImageInfo *image_info,Image *image,
2117 % const char *property,ExceptionInfo *exception)
2119 % A description of each parameter follows:
2121 % o image_info: the image info (optional)
2123 % o image: the image (optional)
2127 % o exception: return any errors or warnings in this structure.
2130 #define WarnNoImageReturn(format,arg) \
2131 if (image == (Image *) NULL ) { \
2132 (void) ThrowMagickException(exception,GetMagickModule(),OptionWarning, \
2133 "NoImageForProperty",format,arg); \
2134 return((const char *)NULL); \
2136 #define WarnNoImageInfoReturn(format,arg) \
2137 if (image == (Image *) NULL ) { \
2138 (void) ThrowMagickException(exception,GetMagickModule(),OptionWarning, \
2139 "NoImageInfoForProperty",format,arg); \
2140 return((const char *)NULL); \
2143 static const char *GetMagickPropertyLetter(ImageInfo *image_info,
2144 Image *image,const char letter,ExceptionInfo *exception)
2147 value[MaxTextExtent]; /* formated string to store as a returned artifact */
2150 *string; /* return a string already stored somewher */
2152 if (image != (Image *) NULL && IfMagickTrue(image->debug))
2153 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
2154 else if( image_info != (ImageInfo *) NULL && IfMagickTrue(image_info->debug))
2155 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s","no-images");
2157 *value='\0'; /* formatted string */
2158 string=(char *) NULL; /* constant string reference */
2160 /* Get properities that are directly defined by images */
2163 case 'b': /* image size read in - in bytes */
2165 WarnNoImageReturn("\"%%%c\"",letter);
2166 (void) FormatLocaleString(value,MaxTextExtent,"%.20g",(double)
2167 ((MagickOffsetType) image->extent));
2168 if (image->extent != (MagickSizeType) ((size_t) image->extent))
2169 (void) FormatMagickSize(image->extent,MagickFalse,value);
2170 ConcatenateMagickString(value,"B",MaxTextExtent);
2173 case 'c': /* image comment property - empty string by default */
2175 WarnNoImageReturn("\"%%%c\"",letter);
2176 string=GetImageProperty(image,"comment",exception);
2177 if ( string == (const char *) NULL )
2181 case 'd': /* Directory component of filename */
2183 WarnNoImageReturn("\"%%%c\"",letter);
2184 GetPathComponent(image->magick_filename,HeadPath,value);
2185 if (*value == '\0') string="";
2188 case 'e': /* Filename extension (suffix) of image file */
2190 WarnNoImageReturn("\"%%%c\"",letter);
2191 GetPathComponent(image->magick_filename,ExtensionPath,value);
2192 if (*value == '\0') string="";
2195 case 'f': /* Filename without directory component */
2197 WarnNoImageReturn("\"%%%c\"",letter);
2198 GetPathComponent(image->magick_filename,TailPath,value);
2199 if (*value == '\0') string="";
2202 case 'g': /* Image geometry, canvas and offset %Wx%H+%X+%Y */
2204 WarnNoImageReturn("\"%%%c\"",letter);
2205 (void) FormatLocaleString(value,MaxTextExtent,"%.20gx%.20g%+.20g%+.20g",
2206 (double) image->page.width,(double) image->page.height,
2207 (double) image->page.x,(double) image->page.y);
2210 case 'h': /* Image height (current) */
2212 WarnNoImageReturn("\"%%%c\"",letter);
2213 (void) FormatLocaleString(value,MaxTextExtent,"%.20g",(double)
2214 (image->rows != 0 ? image->rows : image->magick_rows));
2217 case 'i': /* Filename last used for an image (read or write) */
2219 WarnNoImageReturn("\"%%%c\"",letter);
2220 string=image->filename;
2223 case 'k': /* Number of unique colors */
2226 FUTURE: ensure this does not generate the formatted comment!
2228 WarnNoImageReturn("\"%%%c\"",letter);
2229 (void) FormatLocaleString(value,MaxTextExtent,"%.20g",(double)
2230 GetNumberColors(image,(FILE *) NULL,exception));
2233 case 'l': /* Image label property - empty string by default */
2235 WarnNoImageReturn("\"%%%c\"",letter);
2236 string=GetImageProperty(image,"label",exception);
2237 if ( string == (const char *) NULL)
2241 case 'm': /* Image format (file magick) */
2243 WarnNoImageReturn("\"%%%c\"",letter);
2244 string=image->magick;
2247 case 'n': /* Number of images in the list. */
2249 if ( image != (Image *) NULL )
2250 (void) FormatLocaleString(value,MaxTextExtent,"%.20g",(double)
2251 GetImageListLength(image));
2253 string="0"; /* no images or scenes */
2256 case 'o': /* Output Filename - for delegate use only */
2257 WarnNoImageInfoReturn("\"%%%c\"",letter);
2258 string=image_info->filename;
2260 case 'p': /* Image index in current image list */
2262 WarnNoImageReturn("\"%%%c\"",letter);
2263 (void) FormatLocaleString(value,MaxTextExtent,"%.20g",(double)
2264 GetImageIndexInList(image));
2267 case 'q': /* Quantum depth of image in memory */
2269 WarnNoImageReturn("\"%%%c\"",letter);
2270 (void) FormatLocaleString(value,MaxTextExtent,"%.20g",(double)
2271 MAGICKCORE_QUANTUM_DEPTH);
2274 case 'r': /* Image storage class, colorspace, and alpha enabled. */
2279 WarnNoImageReturn("\"%%%c\"",letter);
2280 colorspace=image->colorspace;
2281 if (IfMagickTrue(IsImageGray(image,exception)))
2282 colorspace=GRAYColorspace; /* FUTURE: this is IMv6 not IMv7 */
2283 (void) FormatLocaleString(value,MaxTextExtent,"%s %s %s",
2284 CommandOptionToMnemonic(MagickClassOptions,(ssize_t) image->storage_class),
2285 CommandOptionToMnemonic(MagickColorspaceOptions,(ssize_t) colorspace),
2286 image->alpha_trait == BlendPixelTrait ? "Alpha" : "");
2289 case 's': /* Image scene number */
2291 #if 0 /* this seems non-sensical -- simplifing */
2292 if (image_info->number_scenes != 0)
2293 (void) FormatLocaleString(value,MaxTextExtent,"%.20g",(double)
2295 else if (image != (Image *)NULL)
2296 (void) FormatLocaleString(value,MaxTextExtent,"%.20g",(double)
2301 WarnNoImageReturn("\"%%%c\"",letter);
2302 (void) FormatLocaleString(value,MaxTextExtent,"%.20g",(double)
2307 case 't': /* Base filename without directory or extention */
2309 WarnNoImageReturn("\"%%%c\"",letter);
2310 GetPathComponent(image->magick_filename,BasePath,value);
2311 if (*value == '\0') string="";
2314 case 'u': /* Unique filename */
2315 WarnNoImageInfoReturn("\"%%%c\"",letter);
2316 string=image_info->unique;
2318 case 'w': /* Image width (current) */
2320 WarnNoImageReturn("\"%%%c\"",letter);
2321 (void) FormatLocaleString(value,MaxTextExtent,"%.20g",(double)
2322 (image->columns != 0 ? image->columns : image->magick_columns));
2325 case 'x': /* Image horizontal resolution (with units) */
2327 WarnNoImageReturn("\"%%%c\"",letter);
2328 (void) FormatLocaleString(value,MaxTextExtent,"%g %s",
2329 image->resolution.x,CommandOptionToMnemonic(
2330 MagickResolutionOptions,(ssize_t)image->units));
2333 case 'y': /* Image vertical resolution (with units) */
2335 WarnNoImageReturn("\"%%%c\"",letter);
2336 (void) FormatLocaleString(value,MaxTextExtent,"%g %s",
2337 image->resolution.y,CommandOptionToMnemonic(MagickResolutionOptions,
2338 (ssize_t) image->units));
2341 case 'z': /* Image depth as read in */
2343 WarnNoImageReturn("\"%%%c\"",letter);
2344 (void) FormatLocaleString(value,MaxTextExtent,"%.20g",
2345 (double) image->depth);
2348 case 'A': /* Image alpha channel */
2350 WarnNoImageReturn("\"%%%c\"",letter);
2351 string=CommandOptionToMnemonic(MagickBooleanOptions,
2352 (ssize_t) image->alpha_trait);
2355 case 'C': /* Image compression method. */
2357 WarnNoImageReturn("\"%%%c\"",letter);
2358 string=CommandOptionToMnemonic(MagickCompressOptions,
2359 (ssize_t) image->compression);
2362 case 'D': /* Image dispose method. */
2364 WarnNoImageReturn("\"%%%c\"",letter);
2365 string=CommandOptionToMnemonic(MagickDisposeOptions,
2366 (ssize_t) image->dispose);
2369 case 'G': /* Image size as geometry = "%wx%h" */
2371 WarnNoImageReturn("\"%%%c\"",letter);
2372 (void) FormatLocaleString(value,MaxTextExtent,"%.20gx%.20g",
2373 (double)image->magick_columns,(double) image->magick_rows);
2376 case 'H': /* layer canvas height */
2378 WarnNoImageReturn("\"%%%c\"",letter);
2379 (void) FormatLocaleString(value,MaxTextExtent,"%.20g",
2380 (double) image->page.height);
2383 case 'M': /* Magick filename - filename given incl. coder & read mods */
2385 WarnNoImageReturn("\"%%%c\"",letter);
2386 string=image->magick_filename;
2389 case 'O': /* layer canvas offset with sign = "+%X+%Y" */
2391 WarnNoImageReturn("\"%%%c\"",letter);
2392 (void) FormatLocaleString(value,MaxTextExtent,"%+ld%+ld",(long)
2393 image->page.x,(long) image->page.y);
2396 case 'P': /* layer canvas page size = "%Wx%H" */
2398 WarnNoImageReturn("\"%%%c\"",letter);
2399 (void) FormatLocaleString(value,MaxTextExtent,"%.20gx%.20g",
2400 (double) image->page.width,(double) image->page.height);
2403 case 'Q': /* image compression quality */
2405 WarnNoImageReturn("\"%%%c\"",letter);
2406 (void) FormatLocaleString(value,MaxTextExtent,"%.20g",(double)
2410 case 'S': /* Number of scenes in image list. */
2412 WarnNoImageInfoReturn("\"%%%c\"",letter);
2413 #if 0 /* What is this number? -- it makes no sense - simplifing */
2414 if (image_info->number_scenes == 0)
2415 string="2147483647";
2416 else if ( image != (Image *) NULL )
2417 (void) FormatLocaleString(value,MaxTextExtent,"%.20g",(double)
2418 image_info->scene+image_info->number_scenes);
2422 (void) FormatLocaleString(value,MaxTextExtent,"%.20g",(double)
2423 (image_info->number_scenes == 0 ? 2147483647 :
2424 image_info->number_scenes));
2428 case 'T': /* image time delay for animations */
2430 WarnNoImageReturn("\"%%%c\"",letter);
2431 (void) FormatLocaleString(value,MaxTextExtent,"%.20g",(double)
2435 case 'W': /* layer canvas width */
2437 WarnNoImageReturn("\"%%%c\"",letter);
2438 (void) FormatLocaleString(value,MaxTextExtent,"%.20g",(double)
2442 case 'X': /* layer canvas X offset */
2444 WarnNoImageReturn("\"%%%c\"",letter);
2445 (void) FormatLocaleString(value,MaxTextExtent,"%+.20g",(double)
2449 case 'Y': /* layer canvas Y offset */
2451 WarnNoImageReturn("\"%%%c\"",letter);
2452 (void) FormatLocaleString(value,MaxTextExtent,"%+.20g",(double)
2456 case 'Z': /* Zero filename ??? */
2457 WarnNoImageInfoReturn("\"%%%c\"",letter);
2458 string=image_info->zero;
2460 case '%': /* percent escaped */
2463 case '@': /* Trim bounding box, without actually Trimming! */
2468 WarnNoImageReturn("\"%%%c\"",letter);
2469 page=GetImageBoundingBox(image,exception);
2470 (void) FormatLocaleString(value,MaxTextExtent,"%.20gx%.20g%+.20g%+.20g",
2471 (double) page.width,(double) page.height,(double) page.x,(double)
2475 case '#': /* Image signature */
2477 WarnNoImageReturn("\"%%%c\"",letter);
2478 (void) SignatureImage(image,exception);
2479 string=GetImageProperty(image,"signature",exception);
2483 if (string != (char *) NULL)
2487 /* create a cloned copy of result, that will get cleaned up, eventually */
2488 if (image != (Image *)NULL)
2490 (void) SetImageArtifact(image,"get-property",value);
2491 return(GetImageArtifact(image,"get-property"));
2495 (void) SetImageOption(image_info,"get-property",value);
2496 return(GetImageOption(image_info,"get-property"));
2499 return((char *)NULL);
2502 MagickExport const char *GetMagickProperty(ImageInfo *image_info,
2503 Image *image,const char *property,ExceptionInfo *exception)
2506 value[MaxTextExtent];
2511 assert(property[0] != '\0');
2512 assert(image != (Image *)NULL || image_info != (ImageInfo *)NULL );
2514 if (property[1] == '\0') /* single letter property request */
2515 return(GetMagickPropertyLetter(image_info,image,*property,exception));
2517 if (image != (Image *) NULL && IfMagickTrue(image->debug))
2518 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
2519 else if( image_info != (ImageInfo *) NULL && IfMagickTrue(image_info->debug))
2520 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s","no-images");
2522 *value='\0'; /* formated string */
2523 string=(char *) NULL; /* constant string reference */
2528 if ((LocaleCompare("base",property) == 0) ||
2529 (LocaleCompare("basename",property) == 0) )
2531 WarnNoImageReturn("\"%%[%s]\"",property);
2532 GetPathComponent(image->magick_filename,BasePath,value);
2533 if (*value == '\0') string="";
2540 if (LocaleCompare("channels",property) == 0)
2542 WarnNoImageReturn("\"%%[%s]\"",property);
2543 /* FUTURE: return actual image channels */
2544 (void) FormatLocaleString(value,MaxTextExtent,"%s",
2545 CommandOptionToMnemonic(MagickColorspaceOptions,(ssize_t)
2546 image->colorspace));
2548 if( image->alpha_trait == BlendPixelTrait )
2549 (void) ConcatenateMagickString(value,"a",MaxTextExtent);
2552 if (LocaleCompare("colorspace",property) == 0)
2554 WarnNoImageReturn("\"%%[%s]\"",property);
2555 /* FUTURE: return actual colorspace - no 'gray' stuff */
2556 string=CommandOptionToMnemonic(MagickColorspaceOptions,(ssize_t)
2560 if (LocaleCompare("copyright",property) == 0)
2562 (void) CopyMagickString(value,GetMagickCopyright(),MaxTextExtent);
2569 if (LocaleCompare("depth",property) == 0)
2571 WarnNoImageReturn("\"%%[%s]\"",property);
2572 (void) FormatLocaleString(value,MaxTextExtent,"%.20g",(double)
2576 if (LocaleCompare("directory",property) == 0)
2578 WarnNoImageReturn("\"%%[%s]\"",property);
2579 GetPathComponent(image->magick_filename,HeadPath,value);
2580 if (*value == '\0') string="";
2587 if (LocaleCompare("extension",property) == 0)
2589 WarnNoImageReturn("\"%%[%s]\"",property);
2590 GetPathComponent(image->magick_filename,ExtensionPath,value);
2591 if (*value == '\0') string="";
2598 if (LocaleCompare("gamma",property) == 0)
2600 WarnNoImageReturn("\"%%[%s]\"",property);
2601 (void) FormatLocaleString(value,MaxTextExtent,"%.*g",
2602 GetMagickPrecision(),image->gamma);
2605 if (LocaleCompare("group",property) == 0)
2607 WarnNoImageInfoReturn("\"%%[%s]\"",property);
2608 (void) FormatLocaleString(value,MaxTextExtent,"0x%lx",(unsigned long)
2616 if (LocaleCompare("height",property) == 0)
2618 WarnNoImageReturn("\"%%[%s]\"",property);
2619 (void) FormatLocaleString(value,MaxTextExtent,"%.20g",
2620 image->magick_rows != 0 ? (double) image->magick_rows : 256.0);
2627 if (LocaleCompare("input",property) == 0)
2629 WarnNoImageReturn("\"%%[%s]\"",property);
2630 string=image->filename;
2637 if (LocaleCompare("kurtosis",property) == 0)
2643 WarnNoImageReturn("\"%%[%s]\"",property);
2644 (void) GetImageKurtosis(image,&kurtosis,&skewness,exception);
2645 (void) FormatLocaleString(value,MaxTextExtent,"%.*g",
2646 GetMagickPrecision(),kurtosis);
2653 if (LocaleCompare("magick",property) == 0)
2655 WarnNoImageReturn("\"%%[%s]\"",property);
2656 string=image->magick;
2659 if (LocaleCompare("max",property) == 0)
2665 WarnNoImageReturn("\"%%[%s]\"",property);
2666 (void) GetImageRange(image,&minimum,&maximum,exception);
2667 (void) FormatLocaleString(value,MaxTextExtent,"%.*g",
2668 GetMagickPrecision(),maximum);
2671 if (LocaleCompare("mean",property) == 0)
2677 WarnNoImageReturn("\"%%[%s]\"",property);
2678 (void) GetImageMean(image,&mean,&standard_deviation,exception);
2679 (void) FormatLocaleString(value,MaxTextExtent,"%.*g",
2680 GetMagickPrecision(),mean);
2683 if (LocaleCompare("min",property) == 0)
2689 WarnNoImageReturn("\"%%[%s]\"",property);
2690 (void) GetImageRange(image,&minimum,&maximum,exception);
2691 (void) FormatLocaleString(value,MaxTextExtent,"%.*g",
2692 GetMagickPrecision(),minimum);
2699 if (LocaleCompare("opaque",property) == 0)
2701 WarnNoImageReturn("\"%%[%s]\"",property);
2702 string=CommandOptionToMnemonic(MagickBooleanOptions,
2703 (ssize_t) IsImageOpaque(image,exception));
2706 if (LocaleCompare("orientation",property) == 0)
2708 WarnNoImageReturn("\"%%[%s]\"",property);
2709 string=CommandOptionToMnemonic(MagickOrientationOptions,(ssize_t)
2710 image->orientation);
2713 if (LocaleCompare("output",property) == 0)
2715 WarnNoImageInfoReturn("\"%%[%s]\"",property);
2716 (void) CopyMagickString(value,image_info->filename,MaxTextExtent);
2721 /* OBSOLETE The 'page' of a image, is just the images index
2722 This conficts with the -set page option that sets virtual canvas info
2725 if (LocaleCompare("page",property) == 0)
2727 WarnNoImageReturn("\"%%[%s]\"",property);
2728 (void) FormatLocaleString(value,MaxTextExtent,"%.20g",(double)
2729 GetImageIndexInList(image)+1);
2737 if (LocaleCompare("resolution.x",property) == 0)
2739 WarnNoImageReturn("\"%%[%s]\"",property);
2740 (void) FormatLocaleString(value,MaxTextExtent,"%g",
2741 image->resolution.x);
2744 if (LocaleCompare("resolution.y",property) == 0)
2746 WarnNoImageReturn("\"%%[%s]\"",property);
2747 (void) FormatLocaleString(value,MaxTextExtent,"%g",
2748 image->resolution.y);
2755 if (LocaleCompare("scene",property) == 0)
2757 WarnNoImageInfoReturn("\"%%[%s]\"",property);
2758 if (image_info->number_scenes != 0)
2759 (void) FormatLocaleString(value,MaxTextExtent,"%.20g",(double)
2762 WarnNoImageReturn("\"%%[%s]\"",property);
2763 (void) FormatLocaleString(value,MaxTextExtent,"%.20g",(double)
2768 if (LocaleCompare("scenes",property) == 0)
2770 /* FUTURE: equivelent to %n? */
2771 WarnNoImageReturn("\"%%[%s]\"",property);
2772 (void) FormatLocaleString(value,MaxTextExtent,"%.20g",(double)
2773 GetImageListLength(image));
2776 if (LocaleCompare("size",property) == 0)
2779 format[MaxTextExtent];
2781 WarnNoImageReturn("\"%%[%s]\"",property);
2782 (void) FormatMagickSize(GetBlobSize(image),MagickFalse,format);
2783 (void) FormatLocaleString(value,MaxTextExtent,"%sB",format);
2786 if (LocaleCompare("skewness",property) == 0)
2792 WarnNoImageReturn("\"%%[%s]\"",property);
2793 (void) GetImageKurtosis(image,&kurtosis,&skewness,exception);
2794 (void) FormatLocaleString(value,MaxTextExtent,"%.*g",
2795 GetMagickPrecision(),skewness);
2798 if (LocaleCompare("standard-deviation",property) == 0)
2804 WarnNoImageReturn("\"%%[%s]\"",property);
2805 (void) GetImageMean(image,&mean,&standard_deviation,exception);
2806 (void) FormatLocaleString(value,MaxTextExtent,"%.*g",
2807 GetMagickPrecision(),standard_deviation);
2814 if (LocaleCompare("type",property) == 0)
2816 WarnNoImageReturn("\"%%[%s]\"",property);
2817 string=CommandOptionToMnemonic(MagickTypeOptions,(ssize_t)
2818 GetImageType(image,exception));
2825 if (LocaleCompare("unique",property) == 0)
2827 WarnNoImageInfoReturn("\"%%[%s]\"",property);
2828 string=image_info->unique;
2835 if (LocaleCompare("version",property) == 0)
2837 string=GetMagickVersion((size_t *) NULL);
2844 if (LocaleCompare("width",property) == 0)
2846 WarnNoImageReturn("\"%%[%s]\"",property);
2847 (void) FormatLocaleString(value,MaxTextExtent,"%.20g",(double)
2848 (image->magick_columns != 0 ? image->magick_columns : 256));
2853 case 'x': /* FUTURE: Obsolete X resolution */
2855 if ((LocaleCompare("xresolution",property) == 0) ||
2856 (LocaleCompare("x-resolution",property) == 0) )
2858 WarnNoImageReturn("\"%%[%s]\"",property);
2859 (void) FormatLocaleString(value,MaxTextExtent,"%.20g",
2860 image->resolution.x);
2865 case 'y': /* FUTURE: Obsolete Y resolution */
2867 if ((LocaleCompare("yresolution",property) == 0) ||
2868 (LocaleCompare("y-resolution",property) == 0) )
2870 WarnNoImageReturn("\"%%[%s]\"",property);
2871 (void) FormatLocaleString(value,MaxTextExtent,"%.20g",
2872 image->resolution.y);
2879 if (LocaleCompare("zero",property) == 0)
2881 WarnNoImageInfoReturn("\"%%[%s]\"",property);
2882 string=image_info->zero;
2888 if (string != (char *) NULL)
2892 /* create a cloned copy of result, that will get cleaned up, eventually */
2893 if (image != (Image *)NULL)
2895 (void) SetImageArtifact(image,"get-property",value);
2896 return(GetImageArtifact(image,"get-property"));
2900 (void) SetImageOption(image_info,"get-property",value);
2901 return(GetImageOption(image_info,"get-property"));
2904 return((char *)NULL);
2906 #undef WarnNoImageRteurn
2909 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2913 % G e t N e x t I m a g e P r o p e r t y %
2917 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2919 % GetNextImageProperty() gets the next free-form string property name.
2921 % The format of the GetNextImageProperty method is:
2923 % char *GetNextImageProperty(const Image *image)
2925 % A description of each parameter follows:
2927 % o image: the image.
2930 MagickExport char *GetNextImageProperty(const Image *image)
2932 assert(image != (Image *) NULL);
2933 assert(image->signature == MagickSignature);
2934 if( IfMagickTrue(image->debug) )
2935 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
2937 if (image->properties == (void *) NULL)
2938 return((char *) NULL);
2939 return((char *) GetNextKeyInSplayTree((SplayTreeInfo *) image->properties));
2943 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2947 % I n t e r p r e t I m a g e P r o p e r t i e s %
2951 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2953 % InterpretImageProperties() replaces any embedded formatting characters with
2954 % the appropriate image property and returns the interpreted text.
2956 % This searches for and replaces
2957 % \n \r \% replaced by newline, return, and percent resp.
2958 % < > & replaced by '<', '>', '&' resp.
2959 % %% replaced by percent
2961 % %x %[x] where 'x' is a single letter properity, case sensitive).
2962 % %[type:name] where 'type' a is special and known prefix.
2963 % %[name] where 'name' is a specifically known attribute, calculated
2964 % value, or a per-image property string name, or a per-image
2965 % 'artifact' (as generated from a global option).
2966 % It may contain ':' as long as the prefix is not special.
2968 % Single letter % substitutions will only happen if the character before the
2969 % percent is NOT a number. But braced substitutions will always be performed.
2970 % This prevents the typical usage of percent in a interpreted geometry
2971 % argument from being substituted when the percent is a geometry flag.
2973 % If 'glob-expresions' ('*' or '?' characters) is used for 'name' it may be
2974 % used as a search pattern to print multiple lines of "name=value\n" pairs of
2975 % the associacted set of properties.
2977 % The returned string must be freed using DestoryString() by the caller.
2979 % The format of the InterpretImageProperties method is:
2981 % char *InterpretImageProperties(ImageInfo *image_info,
2982 % Image *image,const char *embed_text,ExceptionInfo *exception)
2984 % A description of each parameter follows:
2986 % o image_info: the image info. (required)
2988 % o image: the image. (optional)
2990 % o embed_text: the address of a character string containing the embedded
2991 % formatting characters.
2993 % o exception: return any errors or warnings in this structure.
2997 /* common inline code to expand the interpreted text string */
2998 #define ExtendInterpretText(string_length) do { \
2999 size_t length=(string_length); \
3000 if ((size_t) (q-interpret_text+length+1) >= extent) \
3002 interpret_text=(char *) ResizeQuantumMemory(interpret_text, \
3003 extent+MaxTextExtent,sizeof(*interpret_text)); \
3004 if (interpret_text == (char *) NULL) \
3005 return((char *)NULL); \
3006 q=interpret_text+strlen(interpret_text); \
3007 } } while (0) /* no trailing ; */
3009 /* same but append the given string */
3010 #define AppendString2Text(string) do { \
3011 size_t length=strlen((string)); \
3012 if ((size_t) (q-interpret_text+length+1) >= extent) \
3014 interpret_text=(char *) ResizeQuantumMemory(interpret_text, \
3015 extent+MaxTextExtent,sizeof(*interpret_text)); \
3016 if (interpret_text == (char *) NULL) \
3017 return((char *)NULL); \
3018 q=interpret_text+strlen(interpret_text); \
3020 (void) CopyMagickString(q,(string),extent); \
3022 } while (0) /* no trailing ; */
3024 /* same but append a 'key' and 'string' pair */
3025 #define AppendKeyValue2Text(key,string) do { \
3026 size_t length=strlen(key)+strlen(string)+2; \
3027 if ((size_t) (q-interpret_text+length+1) >= extent) \
3029 interpret_text=(char *) ResizeQuantumMemory(interpret_text, \
3030 extent+MaxTextExtent,sizeof(*interpret_text)); \
3031 if (interpret_text == (char *) NULL) \
3032 return((char *)NULL); \
3033 q=interpret_text+strlen(interpret_text); \
3035 q+=FormatLocaleString(q,extent,"%s=%s\n",(key),(string)); \
3036 } while (0) /* no trailing ; */
3038 MagickExport char *InterpretImageProperties(ImageInfo *image_info,
3039 Image *image,const char *embed_text,ExceptionInfo *exception)
3045 *q; /* current position in interpret_text */
3048 *p; /* position in embed_text string being expanded */
3051 extent; /* allocated length of interpret_text */
3056 assert(image == NULL || image->signature == MagickSignature);
3057 assert(image_info == NULL || image_info->signature == MagickSignature);
3059 if (image != (Image *) NULL && IfMagickTrue(image->debug))
3060 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
3061 else if( image_info != (ImageInfo *) NULL && IfMagickTrue(image_info->debug))
3062 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s","no-image");
3064 if (embed_text == (const char *) NULL)
3065 return((char *) NULL);
3069 return(ConstantString(""));
3071 /* handle a '@' replace string from file */
3074 if (*p != '-' && IfMagickFalse(IsPathAccessible(p)) ) {
3075 (void) ThrowMagickException(exception,GetMagickModule(),
3076 OptionError,"UnableToAccessPath","%s",p);
3077 return((char *) NULL);
3079 return(FileToString(p,~0,exception));
3083 Translate any embedded format characters.
3085 interpret_text=AcquireString(embed_text); /* new string with extra space */
3086 extent=MaxTextExtent; /* allocated space in string */
3087 number=MagickFalse; /* is last char a number? */
3088 for (q=interpret_text; *p!='\0'; number=IsMagickTrue(isdigit(*p)),p++)
3091 ExtendInterpretText(MaxTextExtent);
3093 Look for the various escapes, (and handle other specials)
3100 case 'r': /* convert to RETURN */
3104 case 'n': /* convert to NEWLINE */
3108 case '\n': /* EOL removal UNIX,MacOSX */
3111 case '\r': /* EOL removal DOS,Windows */
3113 if (*p == '\n') /* return-newline EOL */
3121 continue; /* never reached! */
3123 if (LocaleNCompare("<",p,4) == 0)
3125 else if (LocaleNCompare(">",p,4) == 0)
3127 else if (LocaleNCompare("&",p,5) == 0)
3133 break; /* continue to next set of handlers */
3135 *q++=(*p); /* any thing else is 'as normal' */
3138 p++; /* advance beyond the percent */
3141 Doubled Percent - or percent at end of string
3151 Single letter escapes %c
3157 /* But only if not preceeded by a number! */
3158 if ( IfMagickTrue(number) ) {
3159 *q++='%'; /* do NOT substitute the percent */
3160 p--; /* back up one */
3163 string=GetMagickPropertyLetter(image_info,image,*p, exception);
3164 if (string != (char *) NULL)
3166 AppendString2Text(string);
3167 if (image != (Image *) NULL)
3168 (void)DeleteImageArtifact(image,"get-property");
3169 if (image_info != (ImageInfo *) NULL)
3170 (void)DeleteImageOption(image_info,"get-property");
3173 (void) ThrowMagickException(exception,GetMagickModule(),OptionWarning,
3174 "UnknownImageProperty","\"%%%c\"",*p);
3179 Braced Percent Escape %[...]
3183 pattern[MaxTextExtent];
3195 /* get the property name framed by the %[...] */
3196 p++; /* advance p to just inside the opening brace */
3199 (void) ThrowMagickException(exception,GetMagickModule(),
3200 OptionWarning,"UnknownImageProperty","\"%%[]\"");
3203 for (len=0; len<(MaxTextExtent-1L) && (*p != '\0');)
3205 /* skip escaped braces within braced pattern */
3206 if ( (*p == '\\') && (*(p+1) != '\0') ) {
3207 pattern[len++]=(*p++);
3208 pattern[len++]=(*p++);
3217 pattern[len++]=(*p++);
3220 /* Check for unmatched final ']' for "%[...]" */
3222 if (len >= 64) { /* truncate string for error message */
3228 (void) ThrowMagickException(exception,GetMagickModule(),
3229 OptionError,"UnbalancedBraces","\"%%[%s\"",pattern);
3230 interpret_text=DestroyString(interpret_text);
3231 return((char *)NULL);
3235 Special Lookup Prefixes %[prefix:...]
3237 /* fx - value calculator */
3238 if (LocaleNCompare("fx:",pattern,3) == 0)
3249 if (image == (Image *) NULL ) {
3250 (void) ThrowMagickException(exception,GetMagickModule(),
3251 OptionWarning,"NoImageForProperty","\"%%[%s]\"",pattern);
3252 continue; /* else no image to retrieve artifact */
3254 fx_info=AcquireFxInfo(image,pattern+3,exception);
3255 status=FxEvaluateChannelExpression(fx_info,IntensityPixelChannel,0,0,
3257 fx_info=DestroyFxInfo(fx_info);
3258 if( IfMagickTrue(status) )
3261 result[MaxTextExtent];
3263 (void) FormatLocaleString(result,MaxTextExtent,"%.*g",
3264 GetMagickPrecision(),(double) value);
3265 AppendString2Text(result);
3269 /* pixel - color value calculator */
3270 if (LocaleNCompare("pixel:",pattern,6) == 0)
3284 if (image == (Image *) NULL ) {
3285 (void) ThrowMagickException(exception,GetMagickModule(),
3286 OptionWarning,"NoImageForProperty","\"%%[%s]\"",pattern);
3287 continue; /* else no image to retrieve artifact */
3289 GetPixelInfo(image,&pixel);
3290 fx_info=AcquireFxInfo(image,pattern+6,exception);
3291 status=FxEvaluateChannelExpression(fx_info,RedPixelChannel,
3292 0,0,&value,exception);
3293 pixel.red=(double) QuantumRange*value;
3294 status|=FxEvaluateChannelExpression(fx_info,GreenPixelChannel,
3295 0,0,&value,exception);
3296 pixel.green=(double) QuantumRange*value;
3297 status|=FxEvaluateChannelExpression(fx_info,BluePixelChannel,
3298 0,0,&value,exception);
3299 pixel.blue=(double) QuantumRange*value;
3300 if (image->colorspace == CMYKColorspace)
3302 status|=FxEvaluateChannelExpression(fx_info,BlackPixelChannel,
3303 0,0,&value,exception);
3304 pixel.black=(double) QuantumRange*value;
3306 status|=FxEvaluateChannelExpression(fx_info,AlphaPixelChannel,
3307 0,0,&value,exception);
3308 pixel.alpha=(double) QuantumRange*value;
3309 fx_info=DestroyFxInfo(fx_info);
3310 if( IfMagickTrue(status) )
3313 name[MaxTextExtent];
3315 (void) QueryColorname(image,&pixel,SVGCompliance,name,
3317 AppendString2Text(name);
3321 /* option - direct global option lookup (with globbing) */
3322 if (LocaleNCompare("option:",pattern,7) == 0)
3324 if (image_info == (ImageInfo *) NULL ) {
3325 (void) ThrowMagickException(exception,GetMagickModule(),
3326 OptionWarning,"NoImageForProperty","\"%%[%s]\"",pattern);
3327 continue; /* else no image to retrieve artifact */
3329 if( IfMagickTrue(IsGlob(pattern+7)) )
3331 ResetImageOptionIterator(image_info);
3332 while ((key=GetNextImageOption(image_info)) != (const char *) NULL)
3333 if( IfMagickTrue(GlobExpression(key,pattern+7,MagickTrue)) )
3335 string=GetImageOption(image_info,key);
3336 if (string != (const char *) NULL)
3337 AppendKeyValue2Text(key,string);
3338 /* else - assertion failure? key found but no string value! */
3342 string=GetImageOption(image_info,pattern+7);
3343 if (string == (char *) NULL)
3344 goto PropertyLookupFailure; /* no artifact of this specifc name */
3345 AppendString2Text(string);
3348 /* artifact - direct image artifact lookup (with glob) */
3349 if (LocaleNCompare("artifact:",pattern,9) == 0)
3351 if (image == (Image *) NULL ) {
3352 (void) ThrowMagickException(exception,GetMagickModule(),
3353 OptionWarning,"NoImageForProperty","\"%%[%s]\"",pattern);
3354 continue; /* else no image to retrieve artifact */
3356 if( IfMagickTrue(IsGlob(pattern+9)) )
3358 ResetImageArtifactIterator(image);
3359 while ((key=GetNextImageArtifact(image)) != (const char *) NULL)
3360 if( IfMagickTrue(GlobExpression(key,pattern+9,MagickTrue)) )
3362 string=GetImageArtifact(image,key);
3363 if (string != (const char *) NULL)
3364 AppendKeyValue2Text(key,string);
3365 /* else - assertion failure? key found but no string value! */
3369 string=GetImageArtifact(image,pattern+9);
3370 if (string == (char *) NULL)
3371 goto PropertyLookupFailure; /* no artifact of this specifc name */
3372 AppendString2Text(string);
3375 /* property - direct image property lookup (with glob) */
3376 if (LocaleNCompare("property:",pattern,9) == 0)
3378 if (image == (Image *) NULL ) {
3379 (void) ThrowMagickException(exception,GetMagickModule(),
3380 OptionWarning,"NoImageForProperty","\"%%[%s]\"",pattern);
3381 continue; /* else no image to retrieve artifact */
3383 if( IfMagickTrue(IsGlob(pattern+9)) )
3385 ResetImagePropertyIterator(image);
3386 while ((key=GetNextImageProperty(image)) != (const char *) NULL)
3387 if( IfMagickTrue(GlobExpression(key,pattern,MagickTrue)) )
3389 string=GetImageProperty(image,key,exception);
3390 if (string != (const char *) NULL)
3391 AppendKeyValue2Text(key,string);
3392 /* else - assertion failure? */
3396 string=GetImageProperty(image,pattern+9,exception);
3397 if (string == (char *) NULL)
3398 goto PropertyLookupFailure; /* no artifact of this specifc name */
3399 AppendString2Text(string);
3402 /* Properties without special prefix.
3403 This handles attributes, properties, and profiles such as %[exif:...]
3404 Note the profile properties may also include a glob expansion pattern.
3406 if ( image != (Image *)NULL )
3408 string=GetImageProperty(image,pattern,exception);
3409 if (string != (const char *) NULL)
3411 AppendString2Text(string);
3412 if (image != (Image *) NULL)
3413 (void)DeleteImageArtifact(image,"get-property");
3414 if (image_info != (ImageInfo *) NULL)
3415 (void)DeleteImageOption(image_info,"get-property");
3420 Handle property 'glob' patterns
3421 Such as: %[*] %[user:array_??] %[filename:e*]
3423 if( IfMagickTrue(IsGlob(pattern)) )
3425 if (image == (Image *) NULL)
3426 continue; /* else no image to retrieve proprty - no list */
3427 ResetImagePropertyIterator(image);
3428 while ((key=GetNextImageProperty(image)) != (const char *) NULL)
3429 if( IfMagickTrue(GlobExpression(key,pattern,MagickTrue)) )
3431 string=GetImageProperty(image,key,exception);
3432 if (string != (const char *) NULL)
3433 AppendKeyValue2Text(key,string);
3434 /* else - assertion failure? */
3439 Look for a known property or image attribute
3440 Such as %[basename] %[denisty] %[delay]
3441 Also handles a braced single letter: %[b] %[G] %[g]
3443 string=GetMagickProperty(image_info,image,pattern,exception);
3444 if (string != (const char *) NULL)
3446 AppendString2Text(string);
3450 Look for a per-image Artifact
3451 This includes option lookup (FUTURE: interpreted according to image)
3453 if (image != (Image *)NULL)
3455 string=GetImageArtifact(image,pattern);
3456 if (string != (char *) NULL)
3458 AppendString2Text(string);
3463 /* no image, so direct 'option' lookup (no delayed percent escapes) */
3464 if (image_info != (ImageInfo *) NULL)
3466 string=GetImageOption(image_info,pattern);
3467 if (string != (char *) NULL)
3469 AppendString2Text(string);
3473 PropertyLookupFailure:
3475 Failed to find any match anywhere!
3477 if (len >= 64) { /* truncate string for error message */
3483 (void) ThrowMagickException(exception,GetMagickModule(),
3484 OptionWarning,"UnknownImageProperty","\"%%[%s]\"",pattern);
3486 } /* Braced Percent Escape */
3488 } /* for each char in 'embed_text' */
3490 return(interpret_text);
3494 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3498 % R e m o v e I m a g e P r o p e r t y %
3502 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3504 % RemoveImageProperty() removes a property from the image and returns its
3507 % In this case the ConstantString() value returned should be freed by the
3508 % caller when finished.
3510 % The format of the RemoveImageProperty method is:
3512 % char *RemoveImageProperty(Image *image,const char *property)
3514 % A description of each parameter follows:
3516 % o image: the image.
3518 % o property: the image property.
3521 MagickExport char *RemoveImageProperty(Image *image,
3522 const char *property)
3527 assert(image != (Image *) NULL);
3528 assert(image->signature == MagickSignature);
3529 if( IfMagickTrue(image->debug) )
3530 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
3532 if (image->properties == (void *) NULL)
3533 return((char *) NULL);
3534 value=(char *) RemoveNodeFromSplayTree((SplayTreeInfo *) image->properties,
3540 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3544 % 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 %
3548 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3550 % ResetImagePropertyIterator() resets the image properties iterator. Use it
3551 % in conjunction with GetNextImageProperty() to iterate over all the values
3552 % associated with an image property.
3554 % The format of the ResetImagePropertyIterator method is:
3556 % ResetImagePropertyIterator(Image *image)
3558 % A description of each parameter follows:
3560 % o image: the image.
3563 MagickExport void ResetImagePropertyIterator(const Image *image)
3565 assert(image != (Image *) NULL);
3566 assert(image->signature == MagickSignature);
3567 if( IfMagickTrue(image->debug) )
3568 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
3570 if (image->properties == (void *) NULL)
3572 ResetSplayTreeIterator((SplayTreeInfo *) image->properties);
3576 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3580 % S e t I m a g e P r o p e r t y %
3584 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3586 % SetImageProperty() saves the given string value either to specific known
3587 % attribute or to a freeform property string.
3589 % Attempting to set a property that is normally calculated will produce
3592 % The format of the SetImageProperty method is:
3594 % MagickBooleanType SetImageProperty(Image *image,const char *property,
3595 % const char *value,ExceptionInfo *exception)
3597 % A description of each parameter follows:
3599 % o image: the image.
3601 % o property: the image property.
3603 % o values: the image property values.
3605 % o exception: return any errors or warnings in this structure.
3608 MagickExport MagickBooleanType SetImageProperty(Image *image,
3609 const char *property,const char *value,ExceptionInfo *exception)
3617 assert(image != (Image *) NULL);
3618 assert(image->signature == MagickSignature);
3619 if( IfMagickTrue(image->debug) )
3620 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
3622 /* Create splay-tree */
3623 if (image->properties == (void *) NULL)
3624 image->properties=NewSplayTree(CompareSplayTreeString,
3625 RelinquishMagickMemory,RelinquishMagickMemory);
3627 /* Delete property if NULL -- empty string values are valid! */
3628 if (value == (const char *) NULL)
3629 return(DeleteImageProperty(image,property));
3632 /* Do not 'set' single letter properties - read only shorthand */
3633 if (strlen(property) <= 1)
3635 (void) ThrowMagickException(exception,GetMagickModule(),
3636 OptionError,"SetReadOnlyProperty","`%s'",property);
3637 return(MagickFalse);
3640 /* FUTURE: binary chars or quotes in key should produce a error */
3643 /* Set attributes with known names or special prefixes
3644 return result is found, or break to set a free form properity
3648 #if 0 /* Percent escape's sets values with this prefix: for later use
3649 Throwing an exception causes this setting to fail */
3652 if (LocaleNCompare("8bim:",property,5) == 0)
3654 (void) ThrowMagickException(exception,GetMagickModule(),
3655 OptionError,"SetReadOnlyProperty","`%s'",property);
3656 return(MagickFalse);
3664 if (LocaleCompare("background",property) == 0)
3666 (void) QueryColorCompliance(value,AllCompliance,
3667 &image->background_color,exception);
3668 /* check for FUTURE: value exception?? */
3669 /* also add user input to splay tree */
3671 break; /* not an attribute, add as a property */
3676 if (LocaleCompare("channels",property) == 0)
3678 (void) ThrowMagickException(exception,GetMagickModule(),
3679 OptionError,"SetReadOnlyProperty","`%s'",property);
3680 return(MagickFalse);
3682 if (LocaleCompare("colorspace",property) == 0)
3687 colorspace=ParseCommandOption(MagickColorspaceOptions,MagickFalse,
3690 return(MagickFalse); /* FUTURE: value exception?? */
3691 image->colorspace=(ColorspaceType) colorspace;
3692 image->rendering_intent=UndefinedIntent;
3693 image->gamma=1.000f;
3694 ResetMagickMemory(&image->chromaticity,0,sizeof(image->chromaticity));
3695 if (IssRGBColorspace(image->colorspace) != MagickFalse)
3697 image->rendering_intent=PerceptualIntent;
3698 image->gamma=1.000f/2.200f;
3699 image->chromaticity.red_primary.x=0.6400f;
3700 image->chromaticity.red_primary.y=0.3300f;
3701 image->chromaticity.red_primary.z=0.0300f;
3702 image->chromaticity.green_primary.x=0.3000f;
3703 image->chromaticity.green_primary.y=0.6000f;
3704 image->chromaticity.green_primary.z=0.1000f;
3705 image->chromaticity.blue_primary.x=0.1500f;
3706 image->chromaticity.blue_primary.y=0.0600f;
3707 image->chromaticity.blue_primary.z=0.7900f;
3708 image->chromaticity.white_point.x=0.3127f;
3709 image->chromaticity.white_point.y=0.3290f;
3710 image->chromaticity.white_point.z=0.3583f;
3714 if (LocaleCompare("compose",property) == 0)
3719 compose=ParseCommandOption(MagickComposeOptions,MagickFalse,value);
3721 return(MagickFalse); /* FUTURE: value exception?? */
3722 image->compose=(CompositeOperator) compose;
3725 if (LocaleCompare("compress",property) == 0)
3730 compression=ParseCommandOption(MagickCompressOptions,MagickFalse,
3732 if (compression < 0)
3733 return(MagickFalse); /* FUTURE: value exception?? */
3734 image->compression=(CompressionType) compression;
3737 if (LocaleCompare("copyright",property) == 0)
3739 (void) ThrowMagickException(exception,GetMagickModule(),
3740 OptionError,"SetReadOnlyProperty","`%s'",property);
3741 return(MagickFalse);
3743 break; /* not an attribute, add as a property */
3748 if (LocaleCompare("delay",property) == 0)
3753 flags=ParseGeometry(value,&geometry_info);
3754 if ((flags & GreaterValue) != 0)
3756 if (image->delay > (size_t) floor(geometry_info.rho+0.5))
3757 image->delay=(size_t) floor(geometry_info.rho+0.5);
3760 if ((flags & LessValue) != 0)
3762 if (image->delay < (size_t) floor(geometry_info.rho+0.5))
3763 image->delay=(ssize_t)
3764 floor(geometry_info.sigma+0.5);
3767 image->delay=(size_t) floor(geometry_info.rho+0.5);
3768 if ((flags & SigmaValue) != 0)
3769 image->ticks_per_second=(ssize_t) floor(geometry_info.sigma+0.5);
3772 if (LocaleCompare("delay_units",property) == 0)
3774 (void) ThrowMagickException(exception,GetMagickModule(),
3775 OptionError,"SetReadOnlyProperty","`%s'",property);
3776 return(MagickFalse);
3778 if (LocaleCompare("density",property) == 0)
3783 flags=ParseGeometry(value,&geometry_info);
3784 image->resolution.x=geometry_info.rho;
3785 image->resolution.y=geometry_info.sigma;
3786 if ((flags & SigmaValue) == 0)
3787 image->resolution.y=image->resolution.x;
3790 if (LocaleCompare("depth",property) == 0)
3792 image->depth=StringToUnsignedLong(value);
3795 if (LocaleCompare("dispose",property) == 0)
3800 dispose=ParseCommandOption(MagickDisposeOptions,MagickFalse,value);
3802 return(MagickFalse); /* FUTURE: value exception?? */
3803 image->dispose=(DisposeType) dispose;
3806 break; /* not an attribute, add as a property */
3808 #if 0 /* Percent escape's sets values with this prefix: for later use
3809 Throwing an exception causes this setting to fail */
3813 if (LocaleNCompare("exif:",property,5) == 0)
3815 (void) ThrowMagickException(exception,GetMagickModule(),
3816 OptionError,"SetReadOnlyProperty","`%s'",property);
3817 return(MagickFalse);
3819 break; /* not an attribute, add as a property */
3824 if (LocaleNCompare("fx:",property,3) == 0)
3826 (void) ThrowMagickException(exception,GetMagickModule(),
3827 OptionError,"SetReadOnlyProperty","`%s'",property);
3828 return(MagickFalse);
3830 break; /* not an attribute, add as a property */
3836 if (LocaleCompare("gamma",property) == 0)
3838 image->gamma=StringToDouble(value,(char **) NULL);
3841 if (LocaleCompare("gravity",property) == 0)
3846 gravity=ParseCommandOption(MagickGravityOptions,MagickFalse,value);
3848 return(MagickFalse); /* FUTURE: value exception?? */
3849 image->gravity=(GravityType) gravity;
3852 break; /* not an attribute, add as a property */
3857 if (LocaleCompare("height",property) == 0)
3859 (void) ThrowMagickException(exception,GetMagickModule(),
3860 OptionError,"SetReadOnlyProperty","`%s'",property);
3861 return(MagickFalse);
3863 break; /* not an attribute, add as a property */
3868 if (LocaleCompare("intensity",property) == 0)
3873 intensity=ParseCommandOption(MagickIntentOptions,MagickFalse,
3876 return(MagickFalse);
3877 image->intensity=(PixelIntensityMethod) intensity;
3880 if (LocaleCompare("intent",property) == 0)
3885 rendering_intent=ParseCommandOption(MagickIntentOptions,MagickFalse,
3887 if (rendering_intent < 0)
3888 return(MagickFalse); /* FUTURE: value exception?? */
3889 image->rendering_intent=(RenderingIntent) rendering_intent;
3892 if (LocaleCompare("interpolate",property) == 0)
3897 interpolate=ParseCommandOption(MagickInterpolateOptions,MagickFalse,
3899 if (interpolate < 0)
3900 return(MagickFalse); /* FUTURE: value exception?? */
3901 image->interpolate=(PixelInterpolateMethod) interpolate;
3904 #if 0 /* Percent escape's sets values with this prefix: for later use
3905 Throwing an exception causes this setting to fail */
3906 if (LocaleNCompare("iptc:",property,5) == 0)
3908 (void) ThrowMagickException(exception,GetMagickModule(),
3909 OptionError,"SetReadOnlyProperty","`%s'",property);
3910 return(MagickFalse);
3913 break; /* not an attribute, add as a property */
3917 if (LocaleCompare("kurtosis",property) == 0)
3919 (void) ThrowMagickException(exception,GetMagickModule(),
3920 OptionError,"SetReadOnlyProperty","`%s'",property);
3921 return(MagickFalse);
3923 break; /* not an attribute, add as a property */
3927 if (LocaleCompare("loop",property) == 0)
3929 image->iterations=StringToUnsignedLong(value);
3932 break; /* not an attribute, add as a property */
3936 if ( (LocaleCompare("magick",property) == 0) ||
3937 (LocaleCompare("max",property) == 0) ||
3938 (LocaleCompare("mean",property) == 0) ||
3939 (LocaleCompare("min",property) == 0) ||
3940 (LocaleCompare("min",property) == 0) )
3942 (void) ThrowMagickException(exception,GetMagickModule(),OptionError,
3943 "SetReadOnlyProperty","`%s'",property);
3944 return(MagickFalse);
3946 break; /* not an attribute, add as a property */
3949 if (LocaleCompare("opaque",property) == 0)
3951 (void) ThrowMagickException(exception,GetMagickModule(),
3952 OptionError,"SetReadOnlyProperty","`%s'",property);
3953 return(MagickFalse);
3955 break; /* not an attribute, add as a property */
3959 if (LocaleCompare("page",property) == 0)
3964 geometry=GetPageGeometry(value);
3965 flags=ParseAbsoluteGeometry(geometry,&image->page);
3966 geometry=DestroyString(geometry);
3969 #if 0 /* Percent escape's sets values with this prefix: for later use
3970 Throwing an exception causes this setting to fail */
3971 if (LocaleNCompare("pixel:",property,6) == 0)
3973 (void) ThrowMagickException(exception,GetMagickModule(),
3974 OptionError,"SetReadOnlyProperty","`%s'",property);
3975 return(MagickFalse);
3978 if (LocaleCompare("profile",property) == 0)
3986 image_info=AcquireImageInfo();
3987 (void) CopyMagickString(image_info->filename,value,MaxTextExtent);
3988 (void) SetImageInfo(image_info,1,exception);
3989 profile=FileToStringInfo(image_info->filename,~0UL,exception);
3990 if (profile != (StringInfo *) NULL)
3991 status=SetImageProfile(image,image_info->magick,profile,exception);
3992 image_info=DestroyImageInfo(image_info);
3995 break; /* not an attribute, add as a property */
4000 if (LocaleCompare("rendering-intent",property) == 0)
4005 rendering_intent=ParseCommandOption(MagickIntentOptions,MagickFalse,
4007 if (rendering_intent < 0)
4008 return(MagickFalse); /* FUTURE: value exception?? */
4009 image->rendering_intent=(RenderingIntent) rendering_intent;
4012 break; /* not an attribute, add as a property */
4016 if ( (LocaleCompare("size",property) == 0) ||
4017 (LocaleCompare("skewness",property) == 0) ||
4018 (LocaleCompare("scenes",property) == 0) ||
4019 (LocaleCompare("standard-deviation",property) == 0) )
4021 (void) ThrowMagickException(exception,GetMagickModule(),
4022 OptionError,"SetReadOnlyProperty","`%s'",property);
4023 return(MagickFalse);
4025 break; /* not an attribute, add as a property */
4029 if (LocaleCompare("tile-offset",property) == 0)
4034 geometry=GetPageGeometry(value);
4035 flags=ParseAbsoluteGeometry(geometry,&image->tile_offset);
4036 geometry=DestroyString(geometry);
4039 break; /* not an attribute, add as a property */
4044 if (LocaleCompare("units",property) == 0)
4049 units=ParseCommandOption(MagickResolutionOptions,MagickFalse,value);
4051 return(MagickFalse); /* FUTURE: value exception?? */
4052 image->units=(ResolutionType) units;
4055 break; /* not an attribute, add as a property */
4060 if (LocaleCompare("version",property) == 0)
4062 (void) ThrowMagickException(exception,GetMagickModule(),
4063 OptionError,"SetReadOnlyProperty","`%s'",property);
4064 return(MagickFalse);
4066 break; /* not an attribute, add as a property */
4071 if (LocaleCompare("width",property) == 0)
4073 (void) ThrowMagickException(exception,GetMagickModule(),
4074 OptionError,"SetReadOnlyProperty","`%s'",property);
4075 return(MagickFalse);
4077 break; /* not an attribute, add as a property */
4079 #if 0 /* Percent escape's sets values with this prefix: for later use
4080 Throwing an exception causes this setting to fail */
4084 if (LocaleNCompare("xmp:",property,4) == 0)
4086 (void) ThrowMagickException(exception,GetMagickModule(),
4087 OptionError,"SetReadOnlyProperty","`%s'",property);
4088 return(MagickFalse);
4090 break; /* not an attribute, add as a property */
4094 /* Default: not an attribute, add as a property */
4095 status=AddValueToSplayTree((SplayTreeInfo *) image->properties,
4096 ConstantString(property),ConstantString(value));
4097 /* FUTURE: error if status is bad? */