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-2014 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 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
44 #include "MagickCore/studio.h"
45 #include "MagickCore/artifact.h"
46 #include "MagickCore/attribute.h"
47 #include "MagickCore/cache.h"
48 #include "MagickCore/cache-private.h"
49 #include "MagickCore/color.h"
50 #include "MagickCore/color-private.h"
51 #include "MagickCore/colorspace-private.h"
52 #include "MagickCore/compare.h"
53 #include "MagickCore/constitute.h"
54 #include "MagickCore/draw.h"
55 #include "MagickCore/effect.h"
56 #include "MagickCore/exception.h"
57 #include "MagickCore/exception-private.h"
58 #include "MagickCore/fx.h"
59 #include "MagickCore/fx-private.h"
60 #include "MagickCore/gem.h"
61 #include "MagickCore/geometry.h"
62 #include "MagickCore/histogram.h"
63 #include "MagickCore/image.h"
64 #include "MagickCore/layer.h"
65 #include "MagickCore/locale-private.h"
66 #include "MagickCore/list.h"
67 #include "MagickCore/magick.h"
68 #include "MagickCore/memory_.h"
69 #include "MagickCore/monitor.h"
70 #include "MagickCore/montage.h"
71 #include "MagickCore/option.h"
72 #include "MagickCore/profile.h"
73 #include "MagickCore/property.h"
74 #include "MagickCore/quantum.h"
75 #include "MagickCore/resource_.h"
76 #include "MagickCore/splay-tree.h"
77 #include "MagickCore/signature.h"
78 #include "MagickCore/statistic.h"
79 #include "MagickCore/string_.h"
80 #include "MagickCore/string-private.h"
81 #include "MagickCore/token.h"
82 #include "MagickCore/token-private.h"
83 #include "MagickCore/utility.h"
84 #include "MagickCore/utility-private.h"
85 #include "MagickCore/version.h"
86 #include "MagickCore/xml-tree.h"
87 #include "MagickCore/xml-tree-private.h"
88 #if defined(MAGICKCORE_LCMS_DELEGATE)
89 #if defined(MAGICKCORE_HAVE_LCMS_LCMS2_H)
90 #include <lcms/lcms2.h>
91 #elif defined(MAGICKCORE_HAVE_LCMS2_H)
93 #elif defined(MAGICKCORE_HAVE_LCMS_LCMS_H)
94 #include <lcms/lcms.h>
101 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
105 % C l o n e I m a g e P r o p e r t i e s %
109 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
111 % CloneImageProperties() clones all the image properties to another image.
113 % The format of the CloneImageProperties method is:
115 % MagickBooleanType CloneImageProperties(Image *image,
116 % const Image *clone_image)
118 % A description of each parameter follows:
120 % o image: the image.
122 % o clone_image: the clone image.
125 MagickExport MagickBooleanType CloneImageProperties(Image *image,
126 const Image *clone_image)
128 assert(image != (Image *) NULL);
129 assert(image->signature == MagickSignature);
130 if( IfMagickTrue(image->debug) )
131 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
132 assert(clone_image != (const Image *) NULL);
133 assert(clone_image->signature == MagickSignature);
134 if( IfMagickTrue(clone_image->debug) )
135 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
136 clone_image->filename);
137 (void) CopyMagickString(image->filename,clone_image->filename,MaxTextExtent);
138 (void) CopyMagickString(image->magick_filename,clone_image->magick_filename,
140 image->compression=clone_image->compression;
141 image->quality=clone_image->quality;
142 image->depth=clone_image->depth;
143 image->background_color=clone_image->background_color;
144 image->border_color=clone_image->border_color;
145 image->matte_color=clone_image->matte_color;
146 image->transparent_color=clone_image->transparent_color;
147 image->gamma=clone_image->gamma;
148 image->chromaticity=clone_image->chromaticity;
149 image->rendering_intent=clone_image->rendering_intent;
150 image->black_point_compensation=clone_image->black_point_compensation;
151 image->units=clone_image->units;
152 image->montage=(char *) NULL;
153 image->directory=(char *) NULL;
154 (void) CloneString(&image->geometry,clone_image->geometry);
155 image->offset=clone_image->offset;
156 image->resolution.x=clone_image->resolution.x;
157 image->resolution.y=clone_image->resolution.y;
158 image->page=clone_image->page;
159 image->tile_offset=clone_image->tile_offset;
160 image->extract_info=clone_image->extract_info;
161 image->filter=clone_image->filter;
162 image->fuzz=clone_image->fuzz;
163 image->intensity=clone_image->intensity;
164 image->interlace=clone_image->interlace;
165 image->interpolate=clone_image->interpolate;
166 image->endian=clone_image->endian;
167 image->gravity=clone_image->gravity;
168 image->compose=clone_image->compose;
169 image->scene=clone_image->scene;
170 image->orientation=clone_image->orientation;
171 image->dispose=clone_image->dispose;
172 image->delay=clone_image->delay;
173 image->ticks_per_second=clone_image->ticks_per_second;
174 image->iterations=clone_image->iterations;
175 image->total_colors=clone_image->total_colors;
176 image->taint=clone_image->taint;
177 image->progress_monitor=clone_image->progress_monitor;
178 image->client_data=clone_image->client_data;
179 image->start_loop=clone_image->start_loop;
180 image->error=clone_image->error;
181 image->signature=clone_image->signature;
182 if (clone_image->properties != (void *) NULL)
184 if (image->properties != (void *) NULL)
185 DestroyImageProperties(image);
186 image->properties=CloneSplayTree((SplayTreeInfo *)
187 clone_image->properties,(void *(*)(void *)) ConstantString,
188 (void *(*)(void *)) ConstantString);
194 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
198 % D e f i n e I m a g e P r o p e r t y %
202 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
204 % DefineImageProperty() associates an assignment string of the form
205 % "key=value" with an artifact or options. It is equivelent to
208 % The format of the DefineImageProperty method is:
210 % MagickBooleanType DefineImageProperty(Image *image,const char *property,
211 % ExceptionInfo *exception)
213 % A description of each parameter follows:
215 % o image: the image.
217 % o property: the image property.
219 % o exception: return any errors or warnings in this structure.
222 MagickExport MagickBooleanType DefineImageProperty(Image *image,
223 const char *property,ExceptionInfo *exception)
227 value[MaxTextExtent];
232 assert(image != (Image *) NULL);
233 assert(property != (const char *) NULL);
234 (void) CopyMagickString(key,property,MaxTextExtent-1);
235 for (p=key; *p != '\0'; p++)
240 (void) CopyMagickString(value,p+1,MaxTextExtent);
242 return(SetImageProperty(image,key,value,exception));
246 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
250 % D e l e t e I m a g e P r o p e r t y %
254 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
256 % DeleteImageProperty() deletes an image property.
258 % The format of the DeleteImageProperty method is:
260 % MagickBooleanType DeleteImageProperty(Image *image,const char *property)
262 % A description of each parameter follows:
264 % o image: the image.
266 % o property: the image property.
269 MagickExport MagickBooleanType DeleteImageProperty(Image *image,
270 const char *property)
272 assert(image != (Image *) NULL);
273 assert(image->signature == MagickSignature);
274 if( IfMagickTrue(image->debug) )
275 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
277 if (image->properties == (void *) NULL)
279 return(DeleteNodeFromSplayTree((SplayTreeInfo *) image->properties,property));
283 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
287 % D e s t r o y I m a g e P r o p e r t i e s %
291 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
293 % DestroyImageProperties() destroys all properties and associated memory
294 % attached to the given image.
296 % The format of the DestroyDefines method is:
298 % void DestroyImageProperties(Image *image)
300 % A description of each parameter follows:
302 % o image: the image.
305 MagickExport void DestroyImageProperties(Image *image)
307 assert(image != (Image *) NULL);
308 assert(image->signature == MagickSignature);
309 if( IfMagickTrue(image->debug) )
310 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
312 if (image->properties != (void *) NULL)
313 image->properties=(void *) DestroySplayTree((SplayTreeInfo *)
318 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
322 % F o r m a t I m a g e P r o p e r t y %
326 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
328 % FormatImageProperty() permits formatted property/value pairs to be saved as
331 % The format of the FormatImageProperty method is:
333 % MagickBooleanType FormatImageProperty(Image *image,const char *property,
334 % const char *format,...)
336 % A description of each parameter follows.
338 % o image: The image.
340 % o property: The attribute property.
342 % o format: A string describing the format to use to write the remaining
346 MagickExport MagickBooleanType FormatImageProperty(Image *image,
347 const char *property,const char *format,...)
350 value[MaxTextExtent];
364 va_start(operands,format);
365 n=FormatLocaleStringList(value,MaxTextExtent,format,operands);
368 exception=AcquireExceptionInfo();
369 status=SetImageProperty(image,property,value,exception);
370 exception=DestroyExceptionInfo(exception);
375 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
379 % G e t I m a g e P r o p e r t y %
383 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
385 % GetImageProperty() gets a value associated with an image property.
387 % This includes, profile prefixes, such as "exif:", "iptc:" and "8bim:"
388 % It does not handle non-prifile prefixes, such as "fx:", "option:", or
391 % The returned string is stored as a properity of the same name for faster
392 % lookup later. It should NOT be freed by the caller.
394 % The format of the GetImageProperty method is:
396 % const char *GetImageProperty(const Image *image,const char *key,
397 % ExceptionInfo *exception)
399 % A description of each parameter follows:
401 % o image: the image.
405 % o exception: return any errors or warnings in this structure.
410 *TracePSClippath(const unsigned char *,size_t,const size_t,
412 *TraceSVGClippath(const unsigned char *,size_t,const size_t,
415 static MagickBooleanType GetIPTCProperty(const Image *image,const char *key,
416 ExceptionInfo *exception)
436 profile=GetImageProfile(image,"iptc");
437 if (profile == (StringInfo *) NULL)
438 profile=GetImageProfile(image,"8bim");
439 if (profile == (StringInfo *) NULL)
441 count=sscanf(key,"IPTC:%ld:%ld",&dataset,&record);
444 attribute=(char *) NULL;
445 for (i=0; i < (ssize_t) GetStringInfoLength(profile); i+=(ssize_t) length)
448 if ((ssize_t) GetStringInfoDatum(profile)[i] != 0x1c)
450 length=(size_t) (GetStringInfoDatum(profile)[i+3] << 8);
451 length|=GetStringInfoDatum(profile)[i+4];
452 if (((long) GetStringInfoDatum(profile)[i+1] == dataset) &&
453 ((long) GetStringInfoDatum(profile)[i+2] == record))
455 message=(char *) NULL;
457 message=(char *) AcquireQuantumMemory(length+1UL,sizeof(*message));
458 if (message != (char *) NULL)
460 (void) CopyMagickString(message,(char *) GetStringInfoDatum(
461 profile)+i+5,length+1);
462 (void) ConcatenateString(&attribute,message);
463 (void) ConcatenateString(&attribute,";");
464 message=DestroyString(message);
469 if ((attribute == (char *) NULL) || (*attribute == ';'))
471 if (attribute != (char *) NULL)
472 attribute=DestroyString(attribute);
475 attribute[strlen(attribute)-1]='\0';
476 (void) SetImageProperty((Image *) image,key,(const char *) attribute,
478 attribute=DestroyString(attribute);
482 static inline ssize_t MagickMax(const ssize_t x,const ssize_t y)
489 static inline ssize_t MagickMin(const ssize_t x,const ssize_t y)
496 static inline int ReadPropertyByte(const unsigned char **p,size_t *length)
508 static inline size_t ReadPropertyMSBLong(const unsigned char **p,
525 for (i=0; i < 4; i++)
529 buffer[i]=(unsigned char) c;
531 value=(size_t) (buffer[0] << 24);
532 value|=buffer[1] << 16;
533 value|=buffer[2] << 8;
535 return(value & 0xffffffff);
538 static inline unsigned short ReadPropertyMSBShort(const unsigned char **p,
554 return((unsigned short) ~0);
555 for (i=0; i < 2; i++)
559 buffer[i]=(unsigned char) c;
561 value=(unsigned short) (buffer[0] << 8);
563 return((unsigned short) (value & 0xffff));
566 static MagickBooleanType Get8BIMProperty(const Image *image,const char *key,
567 ExceptionInfo *exception)
571 format[MaxTextExtent],
600 There are no newlines in path names, so it's safe as terminator.
602 profile=GetImageProfile(image,"8bim");
603 if (profile == (StringInfo *) NULL)
605 count=(ssize_t) sscanf(key,"8BIM:%ld,%ld:%[^\n]\n%[^\n]",&start,&stop,name,
607 if ((count != 2) && (count != 3) && (count != 4))
610 (void) CopyMagickString(format,"SVG",MaxTextExtent);
615 sub_number=(ssize_t) StringToLong(&name[1]);
616 sub_number=MagickMax(sub_number,1L);
617 resource=(char *) NULL;
619 length=GetStringInfoLength(profile);
620 info=GetStringInfoDatum(profile);
621 while ((length > 0) && IfMagickFalse(status))
623 if (ReadPropertyByte(&info,&length) != (unsigned char) '8')
625 if (ReadPropertyByte(&info,&length) != (unsigned char) 'B')
627 if (ReadPropertyByte(&info,&length) != (unsigned char) 'I')
629 if (ReadPropertyByte(&info,&length) != (unsigned char) 'M')
631 id=(ssize_t) ((int) ReadPropertyMSBShort(&info,&length));
632 if (id < (ssize_t) start)
634 if (id > (ssize_t) stop)
636 if (resource != (char *) NULL)
637 resource=DestroyString(resource);
638 count=(ssize_t) ReadPropertyByte(&info,&length);
639 if ((count != 0) && ((size_t) count <= length))
641 resource=(char *) NULL;
642 if (~((size_t) count) >= (MaxTextExtent-1))
643 resource=(char *) AcquireQuantumMemory((size_t) count+MaxTextExtent,
645 if (resource != (char *) NULL)
647 for (i=0; i < (ssize_t) count; i++)
648 resource[i]=(char) ReadPropertyByte(&info,&length);
649 resource[count]='\0';
652 if ((count & 0x01) == 0)
653 (void) ReadPropertyByte(&info,&length);
654 count=(ssize_t) ((int) ReadPropertyMSBLong(&info,&length));
655 if ((*name != '\0') && (*name != '#'))
656 if ((resource == (char *) NULL) || (LocaleCompare(name,resource) != 0))
659 No name match, scroll forward and try next.
662 length-=MagickMin(count,(ssize_t) length);
665 if ((*name == '#') && (sub_number != 1))
668 No numbered match, scroll forward and try next.
672 length-=MagickMin(count,(ssize_t) length);
676 We have the resource of interest.
678 attribute=(char *) NULL;
679 if (~((size_t) count) >= (MaxTextExtent-1))
680 attribute=(char *) AcquireQuantumMemory((size_t) count+MaxTextExtent,
682 if (attribute != (char *) NULL)
684 (void) CopyMagickMemory(attribute,(char *) info,(size_t) count);
685 attribute[count]='\0';
687 length-=MagickMin(count,(ssize_t) length);
688 if ((id <= 1999) || (id >= 2999))
689 (void) SetImageProperty((Image *) image,key,(const char *)
690 attribute,exception);
696 if (LocaleCompare(format,"svg") == 0)
697 path=TraceSVGClippath((unsigned char *) attribute,(size_t) count,
698 image->columns,image->rows);
700 path=TracePSClippath((unsigned char *) attribute,(size_t) count,
701 image->columns,image->rows);
702 (void) SetImageProperty((Image *) image,key,(const char *) path,
704 path=DestroyString(path);
706 attribute=DestroyString(attribute);
710 if (resource != (char *) NULL)
711 resource=DestroyString(resource);
715 static inline unsigned short ReadPropertyShort(const EndianType endian,
716 const unsigned char *buffer)
721 if (endian == LSBEndian)
723 value=(unsigned short) ((buffer[1] << 8) | buffer[0]);
724 return((unsigned short) (value & 0xffff));
726 value=(unsigned short) ((((unsigned char *) buffer)[0] << 8) |
727 ((unsigned char *) buffer)[1]);
728 return((unsigned short) (value & 0xffff));
731 static inline size_t ReadPropertyLong(const EndianType endian,
732 const unsigned char *buffer)
737 if (endian == LSBEndian)
739 value=(size_t) ((buffer[3] << 24) | (buffer[2] << 16) |
740 (buffer[1] << 8 ) | (buffer[0]));
741 return((size_t) (value & 0xffffffff));
743 value=(size_t) ((buffer[0] << 24) | (buffer[1] << 16) |
744 (buffer[2] << 8) | buffer[3]);
745 return((size_t) (value & 0xffffffff));
748 static MagickBooleanType GetEXIFProperty(const Image *image,
749 const char *property,ExceptionInfo *exception)
751 #define MaxDirectoryStack 16
752 #define EXIF_DELIMITER "\n"
753 #define EXIF_NUM_FORMATS 12
754 #define EXIF_FMT_BYTE 1
755 #define EXIF_FMT_STRING 2
756 #define EXIF_FMT_USHORT 3
757 #define EXIF_FMT_ULONG 4
758 #define EXIF_FMT_URATIONAL 5
759 #define EXIF_FMT_SBYTE 6
760 #define EXIF_FMT_UNDEFINED 7
761 #define EXIF_FMT_SSHORT 8
762 #define EXIF_FMT_SLONG 9
763 #define EXIF_FMT_SRATIONAL 10
764 #define EXIF_FMT_SINGLE 11
765 #define EXIF_FMT_DOUBLE 12
766 #define TAG_EXIF_OFFSET 0x8769
767 #define TAG_GPS_OFFSET 0x8825
768 #define TAG_INTEROP_OFFSET 0xa005
770 #define EXIFMultipleValues(size,format,arg) \
783 for (component=0; component < components; component++) \
785 length+=FormatLocaleString(buffer+length,MaxTextExtent-length, \
787 if (length >= (MaxTextExtent-1)) \
788 length=MaxTextExtent-1; \
792 buffer[length-2]='\0'; \
793 value=AcquireString(buffer); \
796 #define EXIFMultipleFractions(size,format,arg1,arg2) \
809 for (component=0; component < components; component++) \
811 length+=FormatLocaleString(buffer+length,MaxTextExtent-length, \
812 format", ",(arg1),(arg2)); \
813 if (length >= (MaxTextExtent-1)) \
814 length=MaxTextExtent-1; \
818 buffer[length-2]='\0'; \
819 value=AcquireString(buffer); \
822 typedef struct _DirectoryInfo
834 typedef struct _TagInfo
846 { 0x001, "exif:InteroperabilityIndex" },
847 { 0x002, "exif:InteroperabilityVersion" },
848 { 0x100, "exif:ImageWidth" },
849 { 0x101, "exif:ImageLength" },
850 { 0x102, "exif:BitsPerSample" },
851 { 0x103, "exif:Compression" },
852 { 0x106, "exif:PhotometricInterpretation" },
853 { 0x10a, "exif:FillOrder" },
854 { 0x10d, "exif:DocumentName" },
855 { 0x10e, "exif:ImageDescription" },
856 { 0x10f, "exif:Make" },
857 { 0x110, "exif:Model" },
858 { 0x111, "exif:StripOffsets" },
859 { 0x112, "exif:Orientation" },
860 { 0x115, "exif:SamplesPerPixel" },
861 { 0x116, "exif:RowsPerStrip" },
862 { 0x117, "exif:StripByteCounts" },
863 { 0x11a, "exif:XResolution" },
864 { 0x11b, "exif:YResolution" },
865 { 0x11c, "exif:PlanarConfiguration" },
866 { 0x11d, "exif:PageName" },
867 { 0x11e, "exif:XPosition" },
868 { 0x11f, "exif:YPosition" },
869 { 0x118, "exif:MinSampleValue" },
870 { 0x119, "exif:MaxSampleValue" },
871 { 0x120, "exif:FreeOffsets" },
872 { 0x121, "exif:FreeByteCounts" },
873 { 0x122, "exif:GrayResponseUnit" },
874 { 0x123, "exif:GrayResponseCurve" },
875 { 0x124, "exif:T4Options" },
876 { 0x125, "exif:T6Options" },
877 { 0x128, "exif:ResolutionUnit" },
878 { 0x12d, "exif:TransferFunction" },
879 { 0x131, "exif:Software" },
880 { 0x132, "exif:DateTime" },
881 { 0x13b, "exif:Artist" },
882 { 0x13e, "exif:WhitePoint" },
883 { 0x13f, "exif:PrimaryChromaticities" },
884 { 0x140, "exif:ColorMap" },
885 { 0x141, "exif:HalfToneHints" },
886 { 0x142, "exif:TileWidth" },
887 { 0x143, "exif:TileLength" },
888 { 0x144, "exif:TileOffsets" },
889 { 0x145, "exif:TileByteCounts" },
890 { 0x14a, "exif:SubIFD" },
891 { 0x14c, "exif:InkSet" },
892 { 0x14d, "exif:InkNames" },
893 { 0x14e, "exif:NumberOfInks" },
894 { 0x150, "exif:DotRange" },
895 { 0x151, "exif:TargetPrinter" },
896 { 0x152, "exif:ExtraSample" },
897 { 0x153, "exif:SampleFormat" },
898 { 0x154, "exif:SMinSampleValue" },
899 { 0x155, "exif:SMaxSampleValue" },
900 { 0x156, "exif:TransferRange" },
901 { 0x157, "exif:ClipPath" },
902 { 0x158, "exif:XClipPathUnits" },
903 { 0x159, "exif:YClipPathUnits" },
904 { 0x15a, "exif:Indexed" },
905 { 0x15b, "exif:JPEGTables" },
906 { 0x15f, "exif:OPIProxy" },
907 { 0x200, "exif:JPEGProc" },
908 { 0x201, "exif:JPEGInterchangeFormat" },
909 { 0x202, "exif:JPEGInterchangeFormatLength" },
910 { 0x203, "exif:JPEGRestartInterval" },
911 { 0x205, "exif:JPEGLosslessPredictors" },
912 { 0x206, "exif:JPEGPointTransforms" },
913 { 0x207, "exif:JPEGQTables" },
914 { 0x208, "exif:JPEGDCTables" },
915 { 0x209, "exif:JPEGACTables" },
916 { 0x211, "exif:YCbCrCoefficients" },
917 { 0x212, "exif:YCbCrSubSampling" },
918 { 0x213, "exif:YCbCrPositioning" },
919 { 0x214, "exif:ReferenceBlackWhite" },
920 { 0x2bc, "exif:ExtensibleMetadataPlatform" },
921 { 0x301, "exif:Gamma" },
922 { 0x302, "exif:ICCProfileDescriptor" },
923 { 0x303, "exif:SRGBRenderingIntent" },
924 { 0x320, "exif:ImageTitle" },
925 { 0x5001, "exif:ResolutionXUnit" },
926 { 0x5002, "exif:ResolutionYUnit" },
927 { 0x5003, "exif:ResolutionXLengthUnit" },
928 { 0x5004, "exif:ResolutionYLengthUnit" },
929 { 0x5005, "exif:PrintFlags" },
930 { 0x5006, "exif:PrintFlagsVersion" },
931 { 0x5007, "exif:PrintFlagsCrop" },
932 { 0x5008, "exif:PrintFlagsBleedWidth" },
933 { 0x5009, "exif:PrintFlagsBleedWidthScale" },
934 { 0x500A, "exif:HalftoneLPI" },
935 { 0x500B, "exif:HalftoneLPIUnit" },
936 { 0x500C, "exif:HalftoneDegree" },
937 { 0x500D, "exif:HalftoneShape" },
938 { 0x500E, "exif:HalftoneMisc" },
939 { 0x500F, "exif:HalftoneScreen" },
940 { 0x5010, "exif:JPEGQuality" },
941 { 0x5011, "exif:GridSize" },
942 { 0x5012, "exif:ThumbnailFormat" },
943 { 0x5013, "exif:ThumbnailWidth" },
944 { 0x5014, "exif:ThumbnailHeight" },
945 { 0x5015, "exif:ThumbnailColorDepth" },
946 { 0x5016, "exif:ThumbnailPlanes" },
947 { 0x5017, "exif:ThumbnailRawBytes" },
948 { 0x5018, "exif:ThumbnailSize" },
949 { 0x5019, "exif:ThumbnailCompressedSize" },
950 { 0x501a, "exif:ColorTransferFunction" },
951 { 0x501b, "exif:ThumbnailData" },
952 { 0x5020, "exif:ThumbnailImageWidth" },
953 { 0x5021, "exif:ThumbnailImageHeight" },
954 { 0x5022, "exif:ThumbnailBitsPerSample" },
955 { 0x5023, "exif:ThumbnailCompression" },
956 { 0x5024, "exif:ThumbnailPhotometricInterp" },
957 { 0x5025, "exif:ThumbnailImageDescription" },
958 { 0x5026, "exif:ThumbnailEquipMake" },
959 { 0x5027, "exif:ThumbnailEquipModel" },
960 { 0x5028, "exif:ThumbnailStripOffsets" },
961 { 0x5029, "exif:ThumbnailOrientation" },
962 { 0x502a, "exif:ThumbnailSamplesPerPixel" },
963 { 0x502b, "exif:ThumbnailRowsPerStrip" },
964 { 0x502c, "exif:ThumbnailStripBytesCount" },
965 { 0x502d, "exif:ThumbnailResolutionX" },
966 { 0x502e, "exif:ThumbnailResolutionY" },
967 { 0x502f, "exif:ThumbnailPlanarConfig" },
968 { 0x5030, "exif:ThumbnailResolutionUnit" },
969 { 0x5031, "exif:ThumbnailTransferFunction" },
970 { 0x5032, "exif:ThumbnailSoftwareUsed" },
971 { 0x5033, "exif:ThumbnailDateTime" },
972 { 0x5034, "exif:ThumbnailArtist" },
973 { 0x5035, "exif:ThumbnailWhitePoint" },
974 { 0x5036, "exif:ThumbnailPrimaryChromaticities" },
975 { 0x5037, "exif:ThumbnailYCbCrCoefficients" },
976 { 0x5038, "exif:ThumbnailYCbCrSubsampling" },
977 { 0x5039, "exif:ThumbnailYCbCrPositioning" },
978 { 0x503A, "exif:ThumbnailRefBlackWhite" },
979 { 0x503B, "exif:ThumbnailCopyRight" },
980 { 0x5090, "exif:LuminanceTable" },
981 { 0x5091, "exif:ChrominanceTable" },
982 { 0x5100, "exif:FrameDelay" },
983 { 0x5101, "exif:LoopCount" },
984 { 0x5110, "exif:PixelUnit" },
985 { 0x5111, "exif:PixelPerUnitX" },
986 { 0x5112, "exif:PixelPerUnitY" },
987 { 0x5113, "exif:PaletteHistogram" },
988 { 0x1000, "exif:RelatedImageFileFormat" },
989 { 0x1001, "exif:RelatedImageLength" },
990 { 0x1002, "exif:RelatedImageWidth" },
991 { 0x800d, "exif:ImageID" },
992 { 0x80e3, "exif:Matteing" },
993 { 0x80e4, "exif:DataType" },
994 { 0x80e5, "exif:ImageDepth" },
995 { 0x80e6, "exif:TileDepth" },
996 { 0x828d, "exif:CFARepeatPatternDim" },
997 { 0x828e, "exif:CFAPattern2" },
998 { 0x828f, "exif:BatteryLevel" },
999 { 0x8298, "exif:Copyright" },
1000 { 0x829a, "exif:ExposureTime" },
1001 { 0x829d, "exif:FNumber" },
1002 { 0x83bb, "exif:IPTC/NAA" },
1003 { 0x84e3, "exif:IT8RasterPadding" },
1004 { 0x84e5, "exif:IT8ColorTable" },
1005 { 0x8649, "exif:ImageResourceInformation" },
1006 { 0x8769, "exif:ExifOffset" },
1007 { 0x8773, "exif:InterColorProfile" },
1008 { 0x8822, "exif:ExposureProgram" },
1009 { 0x8824, "exif:SpectralSensitivity" },
1010 { 0x8825, "exif:GPSInfo" },
1011 { 0x8827, "exif:ISOSpeedRatings" },
1012 { 0x8828, "exif:OECF" },
1013 { 0x8829, "exif:Interlace" },
1014 { 0x882a, "exif:TimeZoneOffset" },
1015 { 0x882b, "exif:SelfTimerMode" },
1016 { 0x9000, "exif:ExifVersion" },
1017 { 0x9003, "exif:DateTimeOriginal" },
1018 { 0x9004, "exif:DateTimeDigitized" },
1019 { 0x9101, "exif:ComponentsConfiguration" },
1020 { 0x9102, "exif:CompressedBitsPerPixel" },
1021 { 0x9201, "exif:ShutterSpeedValue" },
1022 { 0x9202, "exif:ApertureValue" },
1023 { 0x9203, "exif:BrightnessValue" },
1024 { 0x9204, "exif:ExposureBiasValue" },
1025 { 0x9205, "exif:MaxApertureValue" },
1026 { 0x9206, "exif:SubjectDistance" },
1027 { 0x9207, "exif:MeteringMode" },
1028 { 0x9208, "exif:LightSource" },
1029 { 0x9209, "exif:Flash" },
1030 { 0x920a, "exif:FocalLength" },
1031 { 0x920b, "exif:FlashEnergy" },
1032 { 0x920c, "exif:SpatialFrequencyResponse" },
1033 { 0x920d, "exif:Noise" },
1034 { 0x9211, "exif:ImageNumber" },
1035 { 0x9212, "exif:SecurityClassification" },
1036 { 0x9213, "exif:ImageHistory" },
1037 { 0x9214, "exif:SubjectArea" },
1038 { 0x9215, "exif:ExposureIndex" },
1039 { 0x9216, "exif:TIFF-EPStandardID" },
1040 { 0x927c, "exif:MakerNote" },
1041 { 0x9C9b, "exif:WinXP-Title" },
1042 { 0x9C9c, "exif:WinXP-Comments" },
1043 { 0x9C9d, "exif:WinXP-Author" },
1044 { 0x9C9e, "exif:WinXP-Keywords" },
1045 { 0x9C9f, "exif:WinXP-Subject" },
1046 { 0x9286, "exif:UserComment" },
1047 { 0x9290, "exif:SubSecTime" },
1048 { 0x9291, "exif:SubSecTimeOriginal" },
1049 { 0x9292, "exif:SubSecTimeDigitized" },
1050 { 0xa000, "exif:FlashPixVersion" },
1051 { 0xa001, "exif:ColorSpace" },
1052 { 0xa002, "exif:ExifImageWidth" },
1053 { 0xa003, "exif:ExifImageLength" },
1054 { 0xa004, "exif:RelatedSoundFile" },
1055 { 0xa005, "exif:InteroperabilityOffset" },
1056 { 0xa20b, "exif:FlashEnergy" },
1057 { 0xa20c, "exif:SpatialFrequencyResponse" },
1058 { 0xa20d, "exif:Noise" },
1059 { 0xa20e, "exif:FocalPlaneXResolution" },
1060 { 0xa20f, "exif:FocalPlaneYResolution" },
1061 { 0xa210, "exif:FocalPlaneResolutionUnit" },
1062 { 0xa214, "exif:SubjectLocation" },
1063 { 0xa215, "exif:ExposureIndex" },
1064 { 0xa216, "exif:TIFF/EPStandardID" },
1065 { 0xa217, "exif:SensingMethod" },
1066 { 0xa300, "exif:FileSource" },
1067 { 0xa301, "exif:SceneType" },
1068 { 0xa302, "exif:CFAPattern" },
1069 { 0xa401, "exif:CustomRendered" },
1070 { 0xa402, "exif:ExposureMode" },
1071 { 0xa403, "exif:WhiteBalance" },
1072 { 0xa404, "exif:DigitalZoomRatio" },
1073 { 0xa405, "exif:FocalLengthIn35mmFilm" },
1074 { 0xa406, "exif:SceneCaptureType" },
1075 { 0xa407, "exif:GainControl" },
1076 { 0xa408, "exif:Contrast" },
1077 { 0xa409, "exif:Saturation" },
1078 { 0xa40a, "exif:Sharpness" },
1079 { 0xa40b, "exif:DeviceSettingDescription" },
1080 { 0xa40c, "exif:SubjectDistanceRange" },
1081 { 0xa420, "exif:ImageUniqueID" },
1082 { 0xc4a5, "exif:PrintImageMatching" },
1083 { 0xa500, "exif:Gamma" },
1084 { 0xc640, "exif:CR2Slice" },
1085 { 0x10000, "exif:GPSVersionID" },
1086 { 0x10001, "exif:GPSLatitudeRef" },
1087 { 0x10002, "exif:GPSLatitude" },
1088 { 0x10003, "exif:GPSLongitudeRef" },
1089 { 0x10004, "exif:GPSLongitude" },
1090 { 0x10005, "exif:GPSAltitudeRef" },
1091 { 0x10006, "exif:GPSAltitude" },
1092 { 0x10007, "exif:GPSTimeStamp" },
1093 { 0x10008, "exif:GPSSatellites" },
1094 { 0x10009, "exif:GPSStatus" },
1095 { 0x1000a, "exif:GPSMeasureMode" },
1096 { 0x1000b, "exif:GPSDop" },
1097 { 0x1000c, "exif:GPSSpeedRef" },
1098 { 0x1000d, "exif:GPSSpeed" },
1099 { 0x1000e, "exif:GPSTrackRef" },
1100 { 0x1000f, "exif:GPSTrack" },
1101 { 0x10010, "exif:GPSImgDirectionRef" },
1102 { 0x10011, "exif:GPSImgDirection" },
1103 { 0x10012, "exif:GPSMapDatum" },
1104 { 0x10013, "exif:GPSDestLatitudeRef" },
1105 { 0x10014, "exif:GPSDestLatitude" },
1106 { 0x10015, "exif:GPSDestLongitudeRef" },
1107 { 0x10016, "exif:GPSDestLongitude" },
1108 { 0x10017, "exif:GPSDestBearingRef" },
1109 { 0x10018, "exif:GPSDestBearing" },
1110 { 0x10019, "exif:GPSDestDistanceRef" },
1111 { 0x1001a, "exif:GPSDestDistance" },
1112 { 0x1001b, "exif:GPSProcessingMethod" },
1113 { 0x1001c, "exif:GPSAreaInformation" },
1114 { 0x1001d, "exif:GPSDateStamp" },
1115 { 0x1001e, "exif:GPSDifferential" },
1116 { 0x00000, (const char *) NULL }
1127 directory_stack[MaxDirectoryStack];
1156 tag_bytes[] = {0, 1, 1, 2, 4, 8, 1, 1, 2, 4, 8, 4, 8};
1159 If EXIF data exists, then try to parse the request for a tag.
1161 profile=GetImageProfile(image,"exif");
1162 if (profile == (StringInfo *) NULL)
1163 return(MagickFalse);
1164 if ((property == (const char *) NULL) || (*property == '\0'))
1165 return(MagickFalse);
1166 while (isspace((int) ((unsigned char) *property)) != 0)
1170 switch (*(property+5))
1175 Caller has asked for all the tags in the EXIF data.
1178 all=1; /* return the data in description=value format */
1184 all=2; /* return the data in tagid=value format */
1197 Check for a hex based tag specification first.
1199 tag=(*(property+5) == '@') ? 1UL : 0UL;
1203 return(MagickFalse);
1205 Parse tag specification as a hex number.
1210 for (i=(ssize_t) n-1L; i >= 0; i--)
1214 if ((c >= '0') && (c <= '9'))
1217 if ((c >= 'A') && (c <= 'F'))
1220 if ((c >= 'a') && (c <= 'f'))
1223 return(MagickFalse);
1225 } while (*property != '\0');
1231 Try to match the text with a tag name instead.
1235 if (EXIFTag[i].tag == 0)
1237 if (LocaleCompare(EXIFTag[i].description,property) == 0)
1239 tag=(size_t) EXIFTag[i].tag;
1247 return(MagickFalse);
1248 length=GetStringInfoLength(profile);
1249 exif=GetStringInfoDatum(profile);
1252 if (ReadPropertyByte(&exif,&length) != 0x45)
1254 if (ReadPropertyByte(&exif,&length) != 0x78)
1256 if (ReadPropertyByte(&exif,&length) != 0x69)
1258 if (ReadPropertyByte(&exif,&length) != 0x66)
1260 if (ReadPropertyByte(&exif,&length) != 0x00)
1262 if (ReadPropertyByte(&exif,&length) != 0x00)
1267 return(MagickFalse);
1268 id=(ssize_t) ((int) ReadPropertyShort(LSBEndian,exif));
1276 return(MagickFalse);
1277 if (ReadPropertyShort(endian,exif+2) != 0x002a)
1278 return(MagickFalse);
1280 This the offset to the first IFD.
1282 offset=(ssize_t) ((int) ReadPropertyLong(endian,exif+4));
1283 if ((offset < 0) || (size_t) offset >= length)
1284 return(MagickFalse);
1286 Set the pointer to the first IFD and follow it were it leads.
1289 directory=exif+offset;
1293 exif_resources=NewSplayTree((int (*)(const void *,const void *)) NULL,
1294 (void *(*)(void *)) NULL,(void *(*)(void *)) NULL);
1298 If there is anything on the stack then pop it off.
1303 directory=directory_stack[level].directory;
1304 entry=directory_stack[level].entry;
1305 tag_offset=directory_stack[level].offset;
1308 Determine how many entries there are in the current IFD.
1310 number_entries=(size_t) ((int) ReadPropertyShort(endian,directory));
1311 for ( ; entry < number_entries; entry++)
1313 register unsigned char
1324 q=(unsigned char *) (directory+(12*entry)+2);
1325 if (GetValueFromSplayTree(exif_resources,q) == q)
1327 (void) AddValueToSplayTree(exif_resources,q,q);
1328 tag_value=(ssize_t) ((int) ReadPropertyShort(endian,q)+tag_offset);
1329 format=(size_t) ((int) ReadPropertyShort(endian,q+2));
1330 if (format >= (sizeof(tag_bytes)/sizeof(*tag_bytes)))
1332 components=(ssize_t) ((int) ReadPropertyLong(endian,q+4));
1333 number_bytes=(size_t) components*tag_bytes[format];
1334 if (number_bytes < components)
1335 break; /* prevent overflow */
1336 if (number_bytes <= 4)
1344 The directory entry contains an offset.
1346 offset=(ssize_t) ((int) ReadPropertyLong(endian,q+8));
1347 if ((ssize_t) (offset+number_bytes) < offset)
1348 continue; /* prevent overflow */
1349 if ((size_t) (offset+number_bytes) > length)
1351 p=(unsigned char *) (exif+offset);
1353 if ((all != 0) || (tag == (size_t) tag_value))
1356 buffer[MaxTextExtent],
1359 value=(char *) NULL;
1364 case EXIF_FMT_UNDEFINED:
1366 EXIFMultipleValues(1,"%.20g",(double) (*(unsigned char *) p1));
1369 case EXIF_FMT_SBYTE:
1371 EXIFMultipleValues(1,"%.20g",(double) (*(signed char *) p1));
1374 case EXIF_FMT_SSHORT:
1376 EXIFMultipleValues(2,"%hd",ReadPropertyShort(endian,p1));
1379 case EXIF_FMT_USHORT:
1381 EXIFMultipleValues(2,"%hu",ReadPropertyShort(endian,p1));
1384 case EXIF_FMT_ULONG:
1386 EXIFMultipleValues(4,"%.20g",(double)
1387 ((int) ReadPropertyLong(endian,p1)));
1390 case EXIF_FMT_SLONG:
1392 EXIFMultipleValues(4,"%.20g",(double)
1393 ((int) ReadPropertyLong(endian,p1)));
1396 case EXIF_FMT_URATIONAL:
1398 EXIFMultipleFractions(8,"%.20g/%.20g",(double)
1399 ((int) ReadPropertyLong(endian,p1)),(double)
1400 ((int) ReadPropertyLong(endian,p1+4)));
1403 case EXIF_FMT_SRATIONAL:
1405 EXIFMultipleFractions(8,"%.20g/%.20g",(double)
1406 ((int) ReadPropertyLong(endian,p1)),(double)
1407 ((int) ReadPropertyLong(endian,p1+4)));
1410 case EXIF_FMT_SINGLE:
1412 EXIFMultipleValues(4,"%f",(double) *(float *) p1);
1415 case EXIF_FMT_DOUBLE:
1417 EXIFMultipleValues(8,"%f",*(double *) p1);
1421 case EXIF_FMT_STRING:
1423 value=(char *) NULL;
1424 if (~((size_t) number_bytes) >= 1)
1425 value=(char *) AcquireQuantumMemory((size_t) number_bytes+1UL,
1427 if (value != (char *) NULL)
1432 for (i=0; i < (ssize_t) number_bytes; i++)
1435 if ((isprint((int) p[i]) != 0) || (p[i] == '\0'))
1436 value[i]=(char) p[i];
1443 if (value != (char *) NULL)
1451 key=AcquireString(property);
1453 (void) SubstituteString(&key,"exif:","exif:thumbnail:");
1464 description="unknown";
1467 if (EXIFTag[i].tag == 0)
1469 if ((ssize_t) EXIFTag[i].tag == tag_value)
1471 description=EXIFTag[i].description;
1475 (void) FormatLocaleString(key,MaxTextExtent,"%s",description);
1480 if (tag_value < 0x10000)
1481 (void) FormatLocaleString(key,MaxTextExtent,"#%04lx",
1482 (unsigned long) tag_value);
1484 if (tag_value < 0x20000)
1485 (void) FormatLocaleString(key,MaxTextExtent,"@%04lx",
1486 (unsigned long) (tag_value & 0xffff));
1488 (void) FormatLocaleString(key,MaxTextExtent,"unknown");
1492 p=(const char *) NULL;
1493 if (image->properties != (void *) NULL)
1494 p=(const char *) GetValueFromSplayTree((SplayTreeInfo *)
1495 image->properties,key);
1496 if (p == (const char *) NULL)
1497 (void) SetImageProperty((Image *) image,key,value,exception);
1498 value=DestroyString(value);
1499 key=DestroyString(key);
1503 if ((tag_value == TAG_EXIF_OFFSET) ||
1504 (tag_value == TAG_INTEROP_OFFSET) || (tag_value == TAG_GPS_OFFSET))
1509 offset=(ssize_t) ((int) ReadPropertyLong(endian,p));
1510 if (((size_t) offset < length) && (level < (MaxDirectoryStack-2)))
1515 tag_offset1=(ssize_t) ((tag_value == TAG_GPS_OFFSET) ? 0x10000 :
1517 directory_stack[level].directory=directory;
1519 directory_stack[level].entry=entry;
1520 directory_stack[level].offset=tag_offset;
1522 directory_stack[level].directory=exif+offset;
1523 directory_stack[level].offset=tag_offset1;
1524 directory_stack[level].entry=0;
1526 if ((directory+2+(12*number_entries)) > (exif+length))
1528 offset=(ssize_t) ((int) ReadPropertyLong(endian,directory+2+(12*
1530 if ((offset != 0) && ((size_t) offset < length) &&
1531 (level < (MaxDirectoryStack-2)))
1533 directory_stack[level].directory=exif+offset;
1534 directory_stack[level].entry=0;
1535 directory_stack[level].offset=tag_offset1;
1542 } while (level > 0);
1543 exif_resources=DestroySplayTree(exif_resources);
1547 static MagickBooleanType GetXMPProperty(const Image *image,const char *property)
1571 profile=GetImageProfile(image,"xmp");
1572 if (profile == (StringInfo *) NULL)
1573 return(MagickFalse);
1574 if ((property == (const char *) NULL) || (*property == '\0'))
1575 return(MagickFalse);
1576 xmp_profile=StringInfoToString(profile);
1577 if (xmp_profile == (char *) NULL)
1578 return(MagickFalse);
1579 for (p=xmp_profile; *p != '\0'; p++)
1580 if ((*p == '<') && (*(p+1) == 'x'))
1582 exception=AcquireExceptionInfo();
1583 xmp=NewXMLTree((char *) p,exception);
1584 xmp_profile=DestroyString(xmp_profile);
1585 exception=DestroyExceptionInfo(exception);
1586 if (xmp == (XMLTreeInfo *) NULL)
1587 return(MagickFalse);
1589 rdf=GetXMLTreeChild(xmp,"rdf:RDF");
1590 if (rdf != (XMLTreeInfo *) NULL)
1592 if (image->properties == (void *) NULL)
1593 ((Image *) image)->properties=NewSplayTree(CompareSplayTreeString,
1594 RelinquishMagickMemory,RelinquishMagickMemory);
1595 description=GetXMLTreeChild(rdf,"rdf:Description");
1596 while (description != (XMLTreeInfo *) NULL)
1598 node=GetXMLTreeChild(description,(const char *) NULL);
1599 while (node != (XMLTreeInfo *) NULL)
1601 child=GetXMLTreeChild(node,(const char *) NULL);
1602 if (child == (XMLTreeInfo *) NULL)
1603 (void) AddValueToSplayTree((SplayTreeInfo *) image->properties,
1604 ConstantString(GetXMLTreeTag(node)),
1605 ConstantString(GetXMLTreeContent(node)));
1606 while (child != (XMLTreeInfo *) NULL)
1608 if (LocaleCompare(GetXMLTreeTag(child),"rdf:Seq") != 0)
1609 (void) AddValueToSplayTree((SplayTreeInfo *) image->properties,
1610 ConstantString(GetXMLTreeTag(child)),
1611 ConstantString(GetXMLTreeContent(child)));
1612 child=GetXMLTreeSibling(child);
1614 node=GetXMLTreeSibling(node);
1616 description=GetNextXMLTreeTag(description);
1619 xmp=DestroyXMLTree(xmp);
1623 static char *TracePSClippath(const unsigned char *blob,size_t length,
1624 const size_t magick_unused(columns),const size_t magick_unused(rows))
1647 path=AcquireString((char *) NULL);
1648 if (path == (char *) NULL)
1649 return((char *) NULL);
1650 message=AcquireString((char *) NULL);
1651 (void) FormatLocaleString(message,MaxTextExtent,"/ClipImage\n");
1652 (void) ConcatenateString(&path,message);
1653 (void) FormatLocaleString(message,MaxTextExtent,"{\n");
1654 (void) ConcatenateString(&path,message);
1655 (void) FormatLocaleString(message,MaxTextExtent," /c {curveto} bind def\n");
1656 (void) ConcatenateString(&path,message);
1657 (void) FormatLocaleString(message,MaxTextExtent," /l {lineto} bind def\n");
1658 (void) ConcatenateString(&path,message);
1659 (void) FormatLocaleString(message,MaxTextExtent," /m {moveto} bind def\n");
1660 (void) ConcatenateString(&path,message);
1661 (void) FormatLocaleString(message,MaxTextExtent,
1662 " /v {currentpoint 6 2 roll curveto} bind def\n");
1663 (void) ConcatenateString(&path,message);
1664 (void) FormatLocaleString(message,MaxTextExtent,
1665 " /y {2 copy curveto} bind def\n");
1666 (void) ConcatenateString(&path,message);
1667 (void) FormatLocaleString(message,MaxTextExtent,
1668 " /z {closepath} bind def\n");
1669 (void) ConcatenateString(&path,message);
1670 (void) FormatLocaleString(message,MaxTextExtent," newpath\n");
1671 (void) ConcatenateString(&path,message);
1673 The clipping path format is defined in "Adobe Photoshop File
1674 Formats Specification" version 6.0 downloadable from adobe.com.
1676 (void) ResetMagickMemory(point,0,sizeof(point));
1677 (void) ResetMagickMemory(first,0,sizeof(first));
1678 (void) ResetMagickMemory(last,0,sizeof(last));
1680 in_subpath=MagickFalse;
1683 selector=(ssize_t) ((int) ReadPropertyMSBShort(&blob,&length));
1689 if (knot_count != 0)
1692 length-=MagickMin(24,(ssize_t) length);
1696 Expected subpath length record.
1698 knot_count=(ssize_t) ((int) ReadPropertyMSBShort(&blob,&length));
1700 length-=MagickMin(22,(ssize_t) length);
1708 if (knot_count == 0)
1711 Unexpected subpath knot
1714 length-=MagickMin(24,(ssize_t) length);
1720 for (i=0; i < 3; i++)
1726 yy=(size_t) ((int) ReadPropertyMSBLong(&blob,&length));
1727 xx=(size_t) ((int) ReadPropertyMSBLong(&blob,&length));
1729 if (xx > 2147483647)
1730 x=(ssize_t) xx-4294967295U-1;
1732 if (yy > 2147483647)
1733 y=(ssize_t) yy-4294967295U-1;
1734 point[i].x=(double) x/4096/4096;
1735 point[i].y=1.0-(double) y/4096/4096;
1737 if( IfMagickFalse(in_subpath) )
1739 (void) FormatLocaleString(message,MaxTextExtent," %g %g m\n",
1740 point[1].x,point[1].y);
1741 for (i=0; i < 3; i++)
1750 Handle special cases when Bezier curves are used to describe
1751 corners and straight lines.
1753 if ((last[1].x == last[2].x) && (last[1].y == last[2].y) &&
1754 (point[0].x == point[1].x) && (point[0].y == point[1].y))
1755 (void) FormatLocaleString(message,MaxTextExtent,
1756 " %g %g l\n",point[1].x,point[1].y);
1758 if ((last[1].x == last[2].x) && (last[1].y == last[2].y))
1759 (void) FormatLocaleString(message,MaxTextExtent,
1760 " %g %g %g %g v\n",point[0].x,point[0].y,
1761 point[1].x,point[1].y);
1763 if ((point[0].x == point[1].x) && (point[0].y == point[1].y))
1764 (void) FormatLocaleString(message,MaxTextExtent,
1765 " %g %g %g %g y\n",last[2].x,last[2].y,
1766 point[1].x,point[1].y);
1768 (void) FormatLocaleString(message,MaxTextExtent,
1769 " %g %g %g %g %g %g c\n",last[2].x,
1770 last[2].y,point[0].x,point[0].y,point[1].x,point[1].y);
1771 for (i=0; i < 3; i++)
1774 (void) ConcatenateString(&path,message);
1775 in_subpath=MagickTrue;
1778 Close the subpath if there are no more knots.
1780 if (knot_count == 0)
1783 Same special handling as above except we compare to the
1784 first point in the path and close the path.
1786 if ((last[1].x == last[2].x) && (last[1].y == last[2].y) &&
1787 (first[0].x == first[1].x) && (first[0].y == first[1].y))
1788 (void) FormatLocaleString(message,MaxTextExtent,
1789 " %g %g l z\n",first[1].x,first[1].y);
1791 if ((last[1].x == last[2].x) && (last[1].y == last[2].y))
1792 (void) FormatLocaleString(message,MaxTextExtent,
1793 " %g %g %g %g v z\n",first[0].x,first[0].y,
1794 first[1].x,first[1].y);
1796 if ((first[0].x == first[1].x) && (first[0].y == first[1].y))
1797 (void) FormatLocaleString(message,MaxTextExtent,
1798 " %g %g %g %g y z\n",last[2].x,last[2].y,
1799 first[1].x,first[1].y);
1801 (void) FormatLocaleString(message,MaxTextExtent,
1802 " %g %g %g %g %g %g c z\n",last[2].x,
1803 last[2].y,first[0].x,first[0].y,first[1].x,first[1].y);
1804 (void) ConcatenateString(&path,message);
1805 in_subpath=MagickFalse;
1815 length-=MagickMin(24,(ssize_t) length);
1821 Returns an empty PS path if the path has no knots.
1823 (void) FormatLocaleString(message,MaxTextExtent," eoclip\n");
1824 (void) ConcatenateString(&path,message);
1825 (void) FormatLocaleString(message,MaxTextExtent,"} bind def");
1826 (void) ConcatenateString(&path,message);
1827 message=DestroyString(message);
1831 static char *TraceSVGClippath(const unsigned char *blob,size_t length,
1832 const size_t columns,const size_t rows)
1855 path=AcquireString((char *) NULL);
1856 if (path == (char *) NULL)
1857 return((char *) NULL);
1858 message=AcquireString((char *) NULL);
1859 (void) FormatLocaleString(message,MaxTextExtent,
1860 "<?xml version=\"1.0\" encoding=\"iso-8859-1\"?>\n");
1861 (void) ConcatenateString(&path,message);
1862 (void) FormatLocaleString(message,MaxTextExtent,
1863 "<svg width=\"%.20g\" height=\"%.20g\">\n",(double) columns,(double) rows);
1864 (void) ConcatenateString(&path,message);
1865 (void) FormatLocaleString(message,MaxTextExtent,"<g>\n");
1866 (void) ConcatenateString(&path,message);
1867 (void) FormatLocaleString(message,MaxTextExtent,
1868 "<path style=\"fill:#00000000;stroke:#00000000;");
1869 (void) ConcatenateString(&path,message);
1870 (void) FormatLocaleString(message,MaxTextExtent,
1871 "stroke-width:0;stroke-antialiasing:false\" d=\"\n");
1872 (void) ConcatenateString(&path,message);
1873 (void) ResetMagickMemory(point,0,sizeof(point));
1874 (void) ResetMagickMemory(first,0,sizeof(first));
1875 (void) ResetMagickMemory(last,0,sizeof(last));
1877 in_subpath=MagickFalse;
1880 selector=(ssize_t) ((int) ReadPropertyMSBShort(&blob,&length));
1886 if (knot_count != 0)
1889 length-=MagickMin(24,(ssize_t) length);
1893 Expected subpath length record.
1895 knot_count=(ssize_t) ((int) ReadPropertyMSBShort(&blob,&length));
1897 length-=MagickMin(22,(ssize_t) length);
1905 if (knot_count == 0)
1908 Unexpected subpath knot.
1911 length-=MagickMin(24,(ssize_t) length);
1917 for (i=0; i < 3; i++)
1923 yy=(size_t) ((int) ReadPropertyMSBLong(&blob,&length));
1924 xx=(size_t) ((int) ReadPropertyMSBLong(&blob,&length));
1926 if (xx > 2147483647)
1927 x=(ssize_t) xx-4294967295U-1;
1929 if (yy > 2147483647)
1930 y=(ssize_t) yy-4294967295U-1;
1931 point[i].x=(double) x*columns/4096/4096;
1932 point[i].y=(double) y*rows/4096/4096;
1934 if (in_subpath == MagickFalse)
1936 (void) FormatLocaleString(message,MaxTextExtent,"M %g %g\n",
1937 point[1].x,point[1].y);
1938 for (i=0; i < 3; i++)
1947 Handle special cases when Bezier curves are used to describe
1948 corners and straight lines.
1950 if ((last[1].x == last[2].x) && (last[1].y == last[2].y) &&
1951 (point[0].x == point[1].x) && (point[0].y == point[1].y))
1952 (void) FormatLocaleString(message,MaxTextExtent,
1953 "L %g %g\n",point[1].x,point[1].y);
1955 if ((last[1].x == last[2].x) && (last[1].y == last[2].y))
1956 (void) FormatLocaleString(message,MaxTextExtent,
1957 "V %g %g %g %g\n",point[0].x,point[0].y,
1958 point[1].x,point[1].y);
1960 if ((point[0].x == point[1].x) && (point[0].y == point[1].y))
1961 (void) FormatLocaleString(message,MaxTextExtent,
1962 "Y %g %g %g %g\n",last[2].x,last[2].y,
1963 point[1].x,point[1].y);
1965 (void) FormatLocaleString(message,MaxTextExtent,
1966 "C %g %g %g %g %g %g\n",last[2].x,
1967 last[2].y,point[0].x,point[0].y,point[1].x,point[1].y);
1968 for (i=0; i < 3; i++)
1971 (void) ConcatenateString(&path,message);
1972 in_subpath=MagickTrue;
1975 Close the subpath if there are no more knots.
1977 if (knot_count == 0)
1980 Same special handling as above except we compare to the
1981 first point in the path and close the path.
1983 if ((last[1].x == last[2].x) && (last[1].y == last[2].y) &&
1984 (first[0].x == first[1].x) && (first[0].y == first[1].y))
1985 (void) FormatLocaleString(message,MaxTextExtent,
1986 "L %g %g Z\n",first[1].x,first[1].y);
1988 if ((last[1].x == last[2].x) && (last[1].y == last[2].y))
1989 (void) FormatLocaleString(message,MaxTextExtent,
1990 "V %g %g %g %g Z\n",first[0].x,first[0].y,
1991 first[1].x,first[1].y);
1993 if ((first[0].x == first[1].x) && (first[0].y == first[1].y))
1994 (void) FormatLocaleString(message,MaxTextExtent,
1995 "Y %g %g %g %g Z\n",last[2].x,last[2].y,
1996 first[1].x,first[1].y);
1998 (void) FormatLocaleString(message,MaxTextExtent,
1999 "C %g %g %g %g %g %g Z\n",last[2].x,
2000 last[2].y,first[0].x,first[0].y,first[1].x,first[1].y);
2001 (void) ConcatenateString(&path,message);
2002 in_subpath=MagickFalse;
2012 length-=MagickMin(24,(ssize_t) length);
2018 Return an empty SVG image if the path does not have knots.
2020 (void) FormatLocaleString(message,MaxTextExtent,"\"/>\n");
2021 (void) ConcatenateString(&path,message);
2022 (void) FormatLocaleString(message,MaxTextExtent,"</g>\n");
2023 (void) ConcatenateString(&path,message);
2024 (void) FormatLocaleString(message,MaxTextExtent,"</svg>\n");
2025 (void) ConcatenateString(&path,message);
2026 message=DestroyString(message);
2030 MagickExport const char *GetImageProperty(const Image *image,
2031 const char *property,ExceptionInfo *exception)
2036 assert(image != (Image *) NULL);
2037 assert(image->signature == MagickSignature);
2038 if( IfMagickTrue(image->debug) )
2039 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
2041 p=(const char *) NULL;
2042 /* if property is in splay tree - return it and we are done */
2043 if (image->properties != (void *) NULL)
2045 if (property == (const char *) NULL)
2047 ResetSplayTreeIterator((SplayTreeInfo *) image->properties);
2048 p=(const char *) GetNextValueInSplayTree((SplayTreeInfo *)
2052 p=(const char *) GetValueFromSplayTree((SplayTreeInfo *)
2053 image->properties,property);
2054 if (p != (const char *) NULL)
2057 if ((property == (const char *) NULL) ||
2058 (strchr(property,':') == (char *) NULL))
2064 if (LocaleNCompare("8bim:",property,5) == 0)
2066 if( IfMagickTrue(Get8BIMProperty(image,property,exception)) &&
2067 (image->properties != (void *) NULL))
2069 p=(const char *) GetValueFromSplayTree((SplayTreeInfo *)
2070 image->properties,property);
2079 if (LocaleNCompare("exif:",property,5) == 0)
2081 if( IfMagickTrue(GetEXIFProperty(image,property,exception)) &&
2082 (image->properties != (void *) NULL))
2084 p=(const char *) GetValueFromSplayTree((SplayTreeInfo *)
2085 image->properties,property);
2094 if (LocaleNCompare("iptc:",property,5) == 0)
2096 if( IfMagickTrue(GetIPTCProperty(image,property,exception)) &&
2097 (image->properties != (void *) NULL))
2099 p=(const char *) GetValueFromSplayTree((SplayTreeInfo *)
2100 image->properties,property);
2109 if (LocaleNCompare("xmp:",property,4) == 0)
2111 if( IfMagickTrue(GetXMPProperty(image,property)) &&
2112 (image->properties != (void *) NULL))
2114 p=(const char *) GetValueFromSplayTree((SplayTreeInfo *)
2115 image->properties,property);
2128 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2132 + G e t M a g i c k P r o p e r t y %
2136 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2138 % GetMagickProperty() gets attributes or calculated values that is associated
2139 % with a fixed known property name, or single letter property. It may be
2140 % called if no image is defined (IMv7), in which case only global image_info
2141 % values are available.
2143 % This routine only handles specifically known properties. It does not
2144 % handle special prefixed properties, profiles, or expressions. Nor does
2145 % it return any free-form property strings.
2147 % The returned string is stored in a structure somewhere, and should not be
2148 % directly freed. If the string was generated (common) the string will be
2149 % stored as as either as artifact or option 'get-property'. These may be
2150 % deleted (cleaned up) when no longer required, but neither artifact or
2151 % option is guranteed to exist.
2153 % The format of the GetMagickProperty method is:
2155 % const char *GetMagickProperty(ImageInfo *image_info,Image *image,
2156 % const char *property,ExceptionInfo *exception)
2158 % A description of each parameter follows:
2160 % o image_info: the image info (optional)
2162 % o image: the image (optional)
2166 % o exception: return any errors or warnings in this structure.
2169 #define WarnNoImageReturn(format,arg) \
2170 if (image == (Image *) NULL ) { \
2171 (void) ThrowMagickException(exception,GetMagickModule(),OptionWarning, \
2172 "NoImageForProperty",format,arg); \
2173 return((const char *)NULL); \
2175 #define WarnNoImageInfoReturn(format,arg) \
2176 if (image_info == (ImageInfo *) NULL ) { \
2177 (void) ThrowMagickException(exception,GetMagickModule(),OptionWarning, \
2178 "NoImageInfoForProperty",format,arg); \
2179 return((const char *)NULL); \
2182 static const char *GetMagickPropertyLetter(ImageInfo *image_info,
2183 Image *image,const char letter,ExceptionInfo *exception)
2186 value[MaxTextExtent]; /* formated string to store as a returned artifact */
2189 *string; /* return a string already stored somewher */
2191 if (image != (Image *) NULL && IfMagickTrue(image->debug))
2192 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
2193 else if( image_info != (ImageInfo *) NULL && IfMagickTrue(image_info->debug))
2194 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s","no-images");
2196 *value='\0'; /* formatted string */
2197 string=(char *) NULL; /* constant string reference */
2199 /* Get properities that are directly defined by images */
2202 case 'b': /* image size read in - in bytes */
2204 WarnNoImageReturn("\"%%%c\"",letter);
2205 (void) FormatLocaleString(value,MaxTextExtent,"%.20g",(double)
2206 ((MagickOffsetType) image->extent));
2207 if (image->extent != (MagickSizeType) ((size_t) image->extent))
2208 (void) FormatMagickSize(image->extent,MagickFalse,value);
2209 ConcatenateMagickString(value,"B",MaxTextExtent);
2212 case 'c': /* image comment property - empty string by default */
2214 WarnNoImageReturn("\"%%%c\"",letter);
2215 string=GetImageProperty(image,"comment",exception);
2216 if ( string == (const char *) NULL )
2220 case 'd': /* Directory component of filename */
2222 WarnNoImageReturn("\"%%%c\"",letter);
2223 GetPathComponent(image->magick_filename,HeadPath,value);
2224 if (*value == '\0') string="";
2227 case 'e': /* Filename extension (suffix) of image file */
2229 WarnNoImageReturn("\"%%%c\"",letter);
2230 GetPathComponent(image->magick_filename,ExtensionPath,value);
2231 if (*value == '\0') string="";
2234 case 'f': /* Filename without directory component */
2236 WarnNoImageReturn("\"%%%c\"",letter);
2237 GetPathComponent(image->magick_filename,TailPath,value);
2238 if (*value == '\0') string="";
2241 case 'g': /* Image geometry, canvas and offset %Wx%H+%X+%Y */
2243 WarnNoImageReturn("\"%%%c\"",letter);
2244 (void) FormatLocaleString(value,MaxTextExtent,"%.20gx%.20g%+.20g%+.20g",
2245 (double) image->page.width,(double) image->page.height,
2246 (double) image->page.x,(double) image->page.y);
2249 case 'h': /* Image height (current) */
2251 WarnNoImageReturn("\"%%%c\"",letter);
2252 (void) FormatLocaleString(value,MaxTextExtent,"%.20g",(double)
2253 (image->rows != 0 ? image->rows : image->magick_rows));
2256 case 'i': /* Filename last used for an image (read or write) */
2258 WarnNoImageReturn("\"%%%c\"",letter);
2259 string=image->filename;
2262 case 'k': /* Number of unique colors */
2265 FUTURE: ensure this does not generate the formatted comment!
2267 WarnNoImageReturn("\"%%%c\"",letter);
2268 (void) FormatLocaleString(value,MaxTextExtent,"%.20g",(double)
2269 GetNumberColors(image,(FILE *) NULL,exception));
2272 case 'l': /* Image label property - empty string by default */
2274 WarnNoImageReturn("\"%%%c\"",letter);
2275 string=GetImageProperty(image,"label",exception);
2276 if ( string == (const char *) NULL)
2280 case 'm': /* Image format (file magick) */
2282 WarnNoImageReturn("\"%%%c\"",letter);
2283 string=image->magick;
2286 case 'n': /* Number of images in the list. */
2288 if ( image != (Image *) NULL )
2289 (void) FormatLocaleString(value,MaxTextExtent,"%.20g",(double)
2290 GetImageListLength(image));
2292 string="0"; /* no images or scenes */
2295 case 'o': /* Output Filename - for delegate use only */
2296 WarnNoImageInfoReturn("\"%%%c\"",letter);
2297 string=image_info->filename;
2299 case 'p': /* Image index in current image list */
2301 WarnNoImageReturn("\"%%%c\"",letter);
2302 (void) FormatLocaleString(value,MaxTextExtent,"%.20g",(double)
2303 GetImageIndexInList(image));
2306 case 'q': /* Quantum depth of image in memory */
2308 WarnNoImageReturn("\"%%%c\"",letter);
2309 (void) FormatLocaleString(value,MaxTextExtent,"%.20g",(double)
2310 MAGICKCORE_QUANTUM_DEPTH);
2313 case 'r': /* Image storage class, colorspace, and alpha enabled. */
2318 WarnNoImageReturn("\"%%%c\"",letter);
2319 colorspace=image->colorspace;
2320 if (IfMagickTrue(IsImageGray(image,exception)))
2321 colorspace=GRAYColorspace; /* FUTURE: this is IMv6 not IMv7 */
2322 (void) FormatLocaleString(value,MaxTextExtent,"%s %s %s",
2323 CommandOptionToMnemonic(MagickClassOptions,(ssize_t) image->storage_class),
2324 CommandOptionToMnemonic(MagickColorspaceOptions,(ssize_t) colorspace),
2325 image->alpha_trait == BlendPixelTrait ? "Alpha" : "");
2328 case 's': /* Image scene number */
2330 #if 0 /* this seems non-sensical -- simplifing */
2331 if (image_info->number_scenes != 0)
2332 (void) FormatLocaleString(value,MaxTextExtent,"%.20g",(double)
2334 else if (image != (Image *)NULL)
2335 (void) FormatLocaleString(value,MaxTextExtent,"%.20g",(double)
2340 WarnNoImageReturn("\"%%%c\"",letter);
2341 (void) FormatLocaleString(value,MaxTextExtent,"%.20g",(double)
2346 case 't': /* Base filename without directory or extention */
2348 WarnNoImageReturn("\"%%%c\"",letter);
2349 GetPathComponent(image->magick_filename,BasePath,value);
2350 if (*value == '\0') string="";
2353 case 'u': /* Unique filename */
2354 WarnNoImageInfoReturn("\"%%%c\"",letter);
2355 string=image_info->unique;
2357 case 'w': /* Image width (current) */
2359 WarnNoImageReturn("\"%%%c\"",letter);
2360 (void) FormatLocaleString(value,MaxTextExtent,"%.20g",(double)
2361 (image->columns != 0 ? image->columns : image->magick_columns));
2364 case 'x': /* Image horizontal resolution (with units) */
2366 WarnNoImageReturn("\"%%%c\"",letter);
2367 (void) FormatLocaleString(value,MaxTextExtent,"%.20g",
2368 fabs(image->resolution.x) > MagickEpsilon ? image->resolution.x : 72.0);
2371 case 'y': /* Image vertical resolution (with units) */
2373 WarnNoImageReturn("\"%%%c\"",letter);
2374 (void) FormatLocaleString(value,MaxTextExtent,"%.20g",
2375 fabs(image->resolution.y) > MagickEpsilon ? image->resolution.y : 72.0);
2378 case 'z': /* Image depth as read in */
2380 WarnNoImageReturn("\"%%%c\"",letter);
2381 (void) FormatLocaleString(value,MaxTextExtent,"%.20g",
2382 (double) image->depth);
2385 case 'A': /* Image alpha channel */
2387 WarnNoImageReturn("\"%%%c\"",letter);
2388 string=CommandOptionToMnemonic(MagickBooleanOptions,
2389 (ssize_t) image->alpha_trait);
2392 case 'C': /* Image compression method. */
2394 WarnNoImageReturn("\"%%%c\"",letter);
2395 string=CommandOptionToMnemonic(MagickCompressOptions,
2396 (ssize_t) image->compression);
2399 case 'D': /* Image dispose method. */
2401 WarnNoImageReturn("\"%%%c\"",letter);
2402 string=CommandOptionToMnemonic(MagickDisposeOptions,
2403 (ssize_t) image->dispose);
2406 case 'G': /* Image size as geometry = "%wx%h" */
2408 WarnNoImageReturn("\"%%%c\"",letter);
2409 (void) FormatLocaleString(value,MaxTextExtent,"%.20gx%.20g",
2410 (double)image->magick_columns,(double) image->magick_rows);
2413 case 'H': /* layer canvas height */
2415 WarnNoImageReturn("\"%%%c\"",letter);
2416 (void) FormatLocaleString(value,MaxTextExtent,"%.20g",
2417 (double) image->page.height);
2420 case 'M': /* Magick filename - filename given incl. coder & read mods */
2422 WarnNoImageReturn("\"%%%c\"",letter);
2423 string=image->magick_filename;
2426 case 'O': /* layer canvas offset with sign = "+%X+%Y" */
2428 WarnNoImageReturn("\"%%%c\"",letter);
2429 (void) FormatLocaleString(value,MaxTextExtent,"%+ld%+ld",(long)
2430 image->page.x,(long) image->page.y);
2433 case 'P': /* layer canvas page size = "%Wx%H" */
2435 WarnNoImageReturn("\"%%%c\"",letter);
2436 (void) FormatLocaleString(value,MaxTextExtent,"%.20gx%.20g",
2437 (double) image->page.width,(double) image->page.height);
2440 case 'Q': /* image compression quality */
2442 WarnNoImageReturn("\"%%%c\"",letter);
2443 (void) FormatLocaleString(value,MaxTextExtent,"%.20g",(double)
2444 (image->quality == 0 ? 92 : image->quality));
2447 case 'S': /* Number of scenes in image list. */
2449 WarnNoImageInfoReturn("\"%%%c\"",letter);
2450 #if 0 /* What is this number? -- it makes no sense - simplifing */
2451 if (image_info->number_scenes == 0)
2452 string="2147483647";
2453 else if ( image != (Image *) NULL )
2454 (void) FormatLocaleString(value,MaxTextExtent,"%.20g",(double)
2455 image_info->scene+image_info->number_scenes);
2459 (void) FormatLocaleString(value,MaxTextExtent,"%.20g",(double)
2460 (image_info->number_scenes == 0 ? 2147483647 :
2461 image_info->number_scenes));
2465 case 'T': /* image time delay for animations */
2467 WarnNoImageReturn("\"%%%c\"",letter);
2468 (void) FormatLocaleString(value,MaxTextExtent,"%.20g",(double)
2472 case 'U': /* Image resolution units. */
2474 WarnNoImageReturn("\"%%%c\"",letter);
2475 string=CommandOptionToMnemonic(MagickResolutionOptions,
2476 (ssize_t) image->units);
2479 case 'W': /* layer canvas width */
2481 WarnNoImageReturn("\"%%%c\"",letter);
2482 (void) FormatLocaleString(value,MaxTextExtent,"%.20g",(double)
2486 case 'X': /* layer canvas X offset */
2488 WarnNoImageReturn("\"%%%c\"",letter);
2489 (void) FormatLocaleString(value,MaxTextExtent,"%+.20g",(double)
2493 case 'Y': /* layer canvas Y offset */
2495 WarnNoImageReturn("\"%%%c\"",letter);
2496 (void) FormatLocaleString(value,MaxTextExtent,"%+.20g",(double)
2500 case 'Z': /* Zero filename ??? */
2501 WarnNoImageInfoReturn("\"%%%c\"",letter);
2502 string=image_info->zero;
2504 case '%': /* percent escaped */
2507 case '@': /* Trim bounding box, without actually Trimming! */
2512 WarnNoImageReturn("\"%%%c\"",letter);
2513 page=GetImageBoundingBox(image,exception);
2514 (void) FormatLocaleString(value,MaxTextExtent,"%.20gx%.20g%+.20g%+.20g",
2515 (double) page.width,(double) page.height,(double) page.x,(double)
2519 case '#': /* Image signature */
2521 WarnNoImageReturn("\"%%%c\"",letter);
2522 (void) SignatureImage(image,exception);
2523 string=GetImageProperty(image,"signature",exception);
2527 if (string != (char *) NULL)
2531 /* create a cloned copy of result, that will get cleaned up, eventually */
2532 if (image != (Image *)NULL)
2534 (void) SetImageArtifact(image,"get-property",value);
2535 return(GetImageArtifact(image,"get-property"));
2539 (void) SetImageOption(image_info,"get-property",value);
2540 return(GetImageOption(image_info,"get-property"));
2543 return((char *)NULL);
2546 MagickExport const char *GetMagickProperty(ImageInfo *image_info,
2547 Image *image,const char *property,ExceptionInfo *exception)
2550 value[MaxTextExtent];
2555 assert(property[0] != '\0');
2556 assert(image != (Image *)NULL || image_info != (ImageInfo *)NULL );
2558 if (property[1] == '\0') /* single letter property request */
2559 return(GetMagickPropertyLetter(image_info,image,*property,exception));
2561 if (image != (Image *) NULL && IfMagickTrue(image->debug))
2562 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
2563 else if( image_info != (ImageInfo *) NULL && IfMagickTrue(image_info->debug))
2564 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s","no-images");
2566 *value='\0'; /* formated string */
2567 string=(char *) NULL; /* constant string reference */
2572 if ((LocaleCompare("base",property) == 0) ||
2573 (LocaleCompare("basename",property) == 0) )
2575 WarnNoImageReturn("\"%%[%s]\"",property);
2576 GetPathComponent(image->magick_filename,BasePath,value);
2577 if (*value == '\0') string="";
2580 if (LocaleCompare("bit-depth",property) == 0)
2582 (void) FormatLocaleString(value,MaxTextExtent,"%.20g",(double)
2583 GetImageDepth(image, exception));
2590 if (LocaleCompare("channels",property) == 0)
2592 WarnNoImageReturn("\"%%[%s]\"",property);
2593 /* FUTURE: return actual image channels */
2594 (void) FormatLocaleString(value,MaxTextExtent,"%s",
2595 CommandOptionToMnemonic(MagickColorspaceOptions,(ssize_t)
2596 image->colorspace));
2598 if( image->alpha_trait == BlendPixelTrait )
2599 (void) ConcatenateMagickString(value,"a",MaxTextExtent);
2602 if (LocaleCompare("colorspace",property) == 0)
2604 WarnNoImageReturn("\"%%[%s]\"",property);
2605 /* FUTURE: return actual colorspace - no 'gray' stuff */
2606 string=CommandOptionToMnemonic(MagickColorspaceOptions,(ssize_t)
2610 if (LocaleCompare("copyright",property) == 0)
2612 (void) CopyMagickString(value,GetMagickCopyright(),MaxTextExtent);
2619 if (LocaleCompare("depth",property) == 0)
2621 WarnNoImageReturn("\"%%[%s]\"",property);
2622 (void) FormatLocaleString(value,MaxTextExtent,"%.20g",(double)
2626 if (LocaleCompare("directory",property) == 0)
2628 WarnNoImageReturn("\"%%[%s]\"",property);
2629 GetPathComponent(image->magick_filename,HeadPath,value);
2630 if (*value == '\0') string="";
2637 if (LocaleCompare("extension",property) == 0)
2639 WarnNoImageReturn("\"%%[%s]\"",property);
2640 GetPathComponent(image->magick_filename,ExtensionPath,value);
2641 if (*value == '\0') string="";
2648 if (LocaleCompare("gamma",property) == 0)
2650 WarnNoImageReturn("\"%%[%s]\"",property);
2651 (void) FormatLocaleString(value,MaxTextExtent,"%.*g",
2652 GetMagickPrecision(),image->gamma);
2655 if (LocaleCompare("group",property) == 0)
2657 WarnNoImageInfoReturn("\"%%[%s]\"",property);
2658 (void) FormatLocaleString(value,MaxTextExtent,"0x%lx",(unsigned long)
2666 if (LocaleCompare("height",property) == 0)
2668 WarnNoImageReturn("\"%%[%s]\"",property);
2669 (void) FormatLocaleString(value,MaxTextExtent,"%.20g",
2670 image->magick_rows != 0 ? (double) image->magick_rows : 256.0);
2677 if (LocaleCompare("input",property) == 0)
2679 WarnNoImageReturn("\"%%[%s]\"",property);
2680 string=image->filename;
2687 if (LocaleCompare("kurtosis",property) == 0)
2693 WarnNoImageReturn("\"%%[%s]\"",property);
2694 (void) GetImageKurtosis(image,&kurtosis,&skewness,exception);
2695 (void) FormatLocaleString(value,MaxTextExtent,"%.*g",
2696 GetMagickPrecision(),kurtosis);
2703 if (LocaleCompare("magick",property) == 0)
2705 WarnNoImageReturn("\"%%[%s]\"",property);
2706 string=image->magick;
2709 if (LocaleCompare("max",property) == 0)
2715 WarnNoImageReturn("\"%%[%s]\"",property);
2716 (void) GetImageRange(image,&minimum,&maximum,exception);
2717 (void) FormatLocaleString(value,MaxTextExtent,"%.*g",
2718 GetMagickPrecision(),maximum);
2721 if (LocaleCompare("mean",property) == 0)
2727 WarnNoImageReturn("\"%%[%s]\"",property);
2728 (void) GetImageMean(image,&mean,&standard_deviation,exception);
2729 (void) FormatLocaleString(value,MaxTextExtent,"%.*g",
2730 GetMagickPrecision(),mean);
2733 if (LocaleCompare("min",property) == 0)
2739 WarnNoImageReturn("\"%%[%s]\"",property);
2740 (void) GetImageRange(image,&minimum,&maximum,exception);
2741 (void) FormatLocaleString(value,MaxTextExtent,"%.*g",
2742 GetMagickPrecision(),minimum);
2749 if (LocaleCompare("opaque",property) == 0)
2751 WarnNoImageReturn("\"%%[%s]\"",property);
2752 string=CommandOptionToMnemonic(MagickBooleanOptions,
2753 (ssize_t) IsImageOpaque(image,exception));
2756 if (LocaleCompare("orientation",property) == 0)
2758 WarnNoImageReturn("\"%%[%s]\"",property);
2759 string=CommandOptionToMnemonic(MagickOrientationOptions,(ssize_t)
2760 image->orientation);
2763 if (LocaleCompare("output",property) == 0)
2765 WarnNoImageInfoReturn("\"%%[%s]\"",property);
2766 (void) CopyMagickString(value,image_info->filename,MaxTextExtent);
2773 #if defined(MAGICKCORE_LCMS_DELEGATE)
2774 if (LocaleCompare("profile:icc",property) == 0 ||
2775 LocaleCompare("profile:icm",property) == 0)
2777 #if !defined(LCMS_VERSION) || (LCMS_VERSION < 2000)
2778 #define cmsUInt32Number DWORD
2787 profile=GetImageProfile(image,property+8);
2788 if (profile == (StringInfo *) NULL)
2791 icc_profile=cmsOpenProfileFromMem(GetStringInfoDatum(profile),
2792 (cmsUInt32Number) GetStringInfoLength(profile));
2793 if (icc_profile != (cmsHPROFILE *) NULL)
2795 #if defined(LCMS_VERSION) && (LCMS_VERSION < 2000)
2796 string=cmsTakeProductName(icc_profile);
2798 (void) cmsGetProfileInfoASCII(icc_profile,cmsInfoDescription,
2799 "en","US",value,MaxTextExtent);
2801 (void) cmsCloseProfile(icc_profile);
2805 if (LocaleCompare("profiles",property) == 0)
2810 ResetImageProfileIterator(image);
2811 name=GetNextImageProfile(image);
2812 if (name != (char *) NULL)
2814 (void) CopyMagickString(value,name,MaxTextExtent);
2815 name=GetNextImageProfile(image);
2816 while (name != (char *) NULL)
2818 ConcatenateMagickString(value,",",MaxTextExtent);
2819 ConcatenateMagickString(value,name,MaxTextExtent);
2820 name=GetNextImageProfile(image);
2829 if (LocaleCompare("resolution.x",property) == 0)
2831 WarnNoImageReturn("\"%%[%s]\"",property);
2832 (void) FormatLocaleString(value,MaxTextExtent,"%g",
2833 image->resolution.x);
2836 if (LocaleCompare("resolution.y",property) == 0)
2838 WarnNoImageReturn("\"%%[%s]\"",property);
2839 (void) FormatLocaleString(value,MaxTextExtent,"%g",
2840 image->resolution.y);
2847 if (LocaleCompare("scene",property) == 0)
2849 WarnNoImageInfoReturn("\"%%[%s]\"",property);
2850 if (image_info->number_scenes != 0)
2851 (void) FormatLocaleString(value,MaxTextExtent,"%.20g",(double)
2854 WarnNoImageReturn("\"%%[%s]\"",property);
2855 (void) FormatLocaleString(value,MaxTextExtent,"%.20g",(double)
2860 if (LocaleCompare("scenes",property) == 0)
2862 /* FUTURE: equivelent to %n? */
2863 WarnNoImageReturn("\"%%[%s]\"",property);
2864 (void) FormatLocaleString(value,MaxTextExtent,"%.20g",(double)
2865 GetImageListLength(image));
2868 if (LocaleCompare("size",property) == 0)
2871 format[MaxTextExtent];
2873 WarnNoImageReturn("\"%%[%s]\"",property);
2874 (void) FormatMagickSize(GetBlobSize(image),MagickFalse,format);
2875 (void) FormatLocaleString(value,MaxTextExtent,"%sB",format);
2878 if (LocaleCompare("skewness",property) == 0)
2884 WarnNoImageReturn("\"%%[%s]\"",property);
2885 (void) GetImageKurtosis(image,&kurtosis,&skewness,exception);
2886 (void) FormatLocaleString(value,MaxTextExtent,"%.*g",
2887 GetMagickPrecision(),skewness);
2890 if ((LocaleCompare("standard-deviation",property) == 0) ||
2891 (LocaleCompare("standard_deviation",property) == 0))
2897 WarnNoImageReturn("\"%%[%s]\"",property);
2898 (void) GetImageMean(image,&mean,&standard_deviation,exception);
2899 (void) FormatLocaleString(value,MaxTextExtent,"%.*g",
2900 GetMagickPrecision(),standard_deviation);
2907 if (LocaleCompare("type",property) == 0)
2909 WarnNoImageReturn("\"%%[%s]\"",property);
2910 string=CommandOptionToMnemonic(MagickTypeOptions,(ssize_t)
2911 GetImageType(image,exception));
2918 if (LocaleCompare("unique",property) == 0)
2920 WarnNoImageInfoReturn("\"%%[%s]\"",property);
2921 string=image_info->unique;
2924 if (LocaleCompare("units",property) == 0)
2926 WarnNoImageReturn("\"%%[%s]\"",property);
2927 string=CommandOptionToMnemonic(MagickResolutionOptions,(ssize_t)
2931 if (LocaleCompare("copyright",property) == 0)
2936 if (LocaleCompare("version",property) == 0)
2938 string=GetMagickVersion((size_t *) NULL);
2945 if (LocaleCompare("width",property) == 0)
2947 WarnNoImageReturn("\"%%[%s]\"",property);
2948 (void) FormatLocaleString(value,MaxTextExtent,"%.20g",(double)
2949 (image->magick_columns != 0 ? image->magick_columns : 256));
2954 case 'x': /* FUTURE: Obsolete X resolution */
2956 if ((LocaleCompare("xresolution",property) == 0) ||
2957 (LocaleCompare("x-resolution",property) == 0) )
2959 WarnNoImageReturn("\"%%[%s]\"",property);
2960 (void) FormatLocaleString(value,MaxTextExtent,"%.20g",
2961 image->resolution.x);
2966 case 'y': /* FUTURE: Obsolete Y resolution */
2968 if ((LocaleCompare("yresolution",property) == 0) ||
2969 (LocaleCompare("y-resolution",property) == 0) )
2971 WarnNoImageReturn("\"%%[%s]\"",property);
2972 (void) FormatLocaleString(value,MaxTextExtent,"%.20g",
2973 image->resolution.y);
2980 if (LocaleCompare("zero",property) == 0)
2982 WarnNoImageInfoReturn("\"%%[%s]\"",property);
2983 string=image_info->zero;
2989 if (string != (char *) NULL)
2993 /* create a cloned copy of result, that will get cleaned up, eventually */
2994 if (image != (Image *)NULL)
2996 (void) SetImageArtifact(image,"get-property",value);
2997 return(GetImageArtifact(image,"get-property"));
3001 (void) SetImageOption(image_info,"get-property",value);
3002 return(GetImageOption(image_info,"get-property"));
3005 return((char *)NULL);
3007 #undef WarnNoImageReturn
3010 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3014 % G e t N e x t I m a g e P r o p e r t y %
3018 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3020 % GetNextImageProperty() gets the next free-form string property name.
3022 % The format of the GetNextImageProperty method is:
3024 % char *GetNextImageProperty(const Image *image)
3026 % A description of each parameter follows:
3028 % o image: the image.
3031 MagickExport char *GetNextImageProperty(const Image *image)
3033 assert(image != (Image *) NULL);
3034 assert(image->signature == MagickSignature);
3035 if( IfMagickTrue(image->debug) )
3036 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
3038 if (image->properties == (void *) NULL)
3039 return((char *) NULL);
3040 return((char *) GetNextKeyInSplayTree((SplayTreeInfo *) image->properties));
3044 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3048 % I n t e r p r e t I m a g e P r o p e r t i e s %
3052 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3054 % InterpretImageProperties() replaces any embedded formatting characters with
3055 % the appropriate image property and returns the interpreted text.
3057 % This searches for and replaces
3058 % \n \r \% replaced by newline, return, and percent resp.
3059 % < > & replaced by '<', '>', '&' resp.
3060 % %% replaced by percent
3062 % %x %[x] where 'x' is a single letter properity, case sensitive).
3063 % %[type:name] where 'type' a is special and known prefix.
3064 % %[name] where 'name' is a specifically known attribute, calculated
3065 % value, or a per-image property string name, or a per-image
3066 % 'artifact' (as generated from a global option).
3067 % It may contain ':' as long as the prefix is not special.
3069 % Single letter % substitutions will only happen if the character before the
3070 % percent is NOT a number. But braced substitutions will always be performed.
3071 % This prevents the typical usage of percent in a interpreted geometry
3072 % argument from being substituted when the percent is a geometry flag.
3074 % If 'glob-expresions' ('*' or '?' characters) is used for 'name' it may be
3075 % used as a search pattern to print multiple lines of "name=value\n" pairs of
3076 % the associacted set of properties.
3078 % The returned string must be freed using DestoryString() by the caller.
3080 % The format of the InterpretImageProperties method is:
3082 % char *InterpretImageProperties(ImageInfo *image_info,
3083 % Image *image,const char *embed_text,ExceptionInfo *exception)
3085 % A description of each parameter follows:
3087 % o image_info: the image info. (required)
3089 % o image: the image. (optional)
3091 % o embed_text: the address of a character string containing the embedded
3092 % formatting characters.
3094 % o exception: return any errors or warnings in this structure.
3098 /* common inline code to expand the interpreted text string */
3099 #define ExtendInterpretText(string_length) do { \
3100 DisableMSCWarning(4127) \
3101 size_t length=(string_length); \
3102 if ((size_t) (q-interpret_text+length+1) >= extent) \
3104 interpret_text=(char *) ResizeQuantumMemory(interpret_text, \
3105 extent+MaxTextExtent,sizeof(*interpret_text)); \
3106 if (interpret_text == (char *) NULL) \
3107 return((char *)NULL); \
3108 q=interpret_text+strlen(interpret_text); \
3109 } } while (0) /* no trailing ; */ \
3112 /* same but append the given string */
3113 #define AppendString2Text(string) do { \
3114 DisableMSCWarning(4127) \
3115 size_t length=strlen((string)); \
3116 if ((size_t) (q-interpret_text+length+1) >= extent) \
3118 interpret_text=(char *) ResizeQuantumMemory(interpret_text, \
3119 extent+MaxTextExtent,sizeof(*interpret_text)); \
3120 if (interpret_text == (char *) NULL) \
3121 return((char *)NULL); \
3122 q=interpret_text+strlen(interpret_text); \
3124 (void) CopyMagickString(q,(string),extent); \
3126 } while (0) /* no trailing ; */ \
3129 /* same but append a 'key' and 'string' pair */
3130 #define AppendKeyValue2Text(key,string) do { \
3131 DisableMSCWarning(4127) \
3132 size_t length=strlen(key)+strlen(string)+2; \
3133 if ((size_t) (q-interpret_text+length+1) >= extent) \
3135 interpret_text=(char *) ResizeQuantumMemory(interpret_text, \
3136 extent+MaxTextExtent,sizeof(*interpret_text)); \
3137 if (interpret_text == (char *) NULL) \
3138 return((char *)NULL); \
3139 q=interpret_text+strlen(interpret_text); \
3141 q+=FormatLocaleString(q,extent,"%s=%s\n",(key),(string)); \
3142 } while (0) /* no trailing ; */ \
3145 MagickExport char *InterpretImageProperties(ImageInfo *image_info,
3146 Image *image,const char *embed_text,ExceptionInfo *exception)
3152 *q; /* current position in interpret_text */
3155 *p; /* position in embed_text string being expanded */
3158 extent; /* allocated length of interpret_text */
3163 assert(image == NULL || image->signature == MagickSignature);
3164 assert(image_info == NULL || image_info->signature == MagickSignature);
3166 if (image != (Image *) NULL && IfMagickTrue(image->debug))
3167 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
3168 else if( image_info != (ImageInfo *) NULL && IfMagickTrue(image_info->debug))
3169 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s","no-image");
3171 if (embed_text == (const char *) NULL)
3172 return((char *) NULL);
3176 return(ConstantString(""));
3178 /* handle a '@' replace string from file */
3181 if (*p != '-' && IfMagickFalse(IsPathAccessible(p)) ) {
3182 (void) ThrowMagickException(exception,GetMagickModule(),
3183 OptionError,"UnableToAccessPath","%s",p);
3184 return((char *) NULL);
3186 return(FileToString(p,~0UL,exception));
3190 Translate any embedded format characters.
3192 interpret_text=AcquireString(embed_text); /* new string with extra space */
3193 extent=MaxTextExtent; /* allocated space in string */
3194 number=MagickFalse; /* is last char a number? */
3195 for (q=interpret_text; *p!='\0'; number=IsMagickTrue(isdigit(*p)),p++)
3198 ExtendInterpretText(MaxTextExtent);
3200 Look for the various escapes, (and handle other specials)
3207 case 'r': /* convert to RETURN */
3211 case 'n': /* convert to NEWLINE */
3215 case '\n': /* EOL removal UNIX,MacOSX */
3218 case '\r': /* EOL removal DOS,Windows */
3220 if (*p == '\n') /* return-newline EOL */
3228 continue; /* never reached! */
3230 if (LocaleNCompare("<",p,4) == 0)
3232 else if (LocaleNCompare(">",p,4) == 0)
3234 else if (LocaleNCompare("&",p,5) == 0)
3240 break; /* continue to next set of handlers */
3242 *q++=(*p); /* any thing else is 'as normal' */
3245 p++; /* advance beyond the percent */
3248 Doubled Percent - or percent at end of string
3258 Single letter escapes %c
3264 /* But only if not preceeded by a number! */
3265 if ( IfMagickTrue(number) ) {
3266 *q++='%'; /* do NOT substitute the percent */
3267 p--; /* back up one */
3270 string=GetMagickPropertyLetter(image_info,image,*p, exception);
3271 if (string != (char *) NULL)
3273 AppendString2Text(string);
3274 if (image != (Image *) NULL)
3275 (void)DeleteImageArtifact(image,"get-property");
3276 if (image_info != (ImageInfo *) NULL)
3277 (void)DeleteImageOption(image_info,"get-property");
3280 (void) ThrowMagickException(exception,GetMagickModule(),OptionWarning,
3281 "UnknownImageProperty","\"%%%c\"",*p);
3286 Braced Percent Escape %[...]
3290 pattern[MaxTextExtent];
3302 /* get the property name framed by the %[...] */
3303 p++; /* advance p to just inside the opening brace */
3306 (void) ThrowMagickException(exception,GetMagickModule(),
3307 OptionWarning,"UnknownImageProperty","\"%%[]\"");
3310 for (len=0; len<(MaxTextExtent-1L) && (*p != '\0');)
3312 /* skip escaped braces within braced pattern */
3313 if ( (*p == '\\') && (*(p+1) != '\0') ) {
3314 pattern[len++]=(*p++);
3315 pattern[len++]=(*p++);
3324 pattern[len++]=(*p++);
3327 /* Check for unmatched final ']' for "%[...]" */
3329 if (len >= 64) { /* truncate string for error message */
3335 (void) ThrowMagickException(exception,GetMagickModule(),
3336 OptionError,"UnbalancedBraces","\"%%[%s\"",pattern);
3337 interpret_text=DestroyString(interpret_text);
3338 return((char *)NULL);
3342 Special Lookup Prefixes %[prefix:...]
3344 /* fx - value calculator */
3345 if (LocaleNCompare("fx:",pattern,3) == 0)
3356 if (image == (Image *) NULL ) {
3357 (void) ThrowMagickException(exception,GetMagickModule(),
3358 OptionWarning,"NoImageForProperty","\"%%[%s]\"",pattern);
3359 continue; /* else no image to retrieve artifact */
3361 fx_info=AcquireFxInfo(image,pattern+3,exception);
3362 status=FxEvaluateChannelExpression(fx_info,IntensityPixelChannel,0,0,
3364 fx_info=DestroyFxInfo(fx_info);
3365 if( IfMagickTrue(status) )
3368 result[MaxTextExtent];
3370 (void) FormatLocaleString(result,MaxTextExtent,"%.*g",
3371 GetMagickPrecision(),(double) value);
3372 AppendString2Text(result);
3376 /* pixel - color value calculator */
3377 if (LocaleNCompare("pixel:",pattern,6) == 0)
3391 if (image == (Image *) NULL ) {
3392 (void) ThrowMagickException(exception,GetMagickModule(),
3393 OptionWarning,"NoImageForProperty","\"%%[%s]\"",pattern);
3394 continue; /* else no image to retrieve artifact */
3396 GetPixelInfo(image,&pixel);
3397 fx_info=AcquireFxInfo(image,pattern+6,exception);
3398 status=FxEvaluateChannelExpression(fx_info,RedPixelChannel,0,0,
3400 pixel.red=(double) QuantumRange*value;
3401 status&=FxEvaluateChannelExpression(fx_info,GreenPixelChannel,0,0,
3403 pixel.green=(double) QuantumRange*value;
3404 status&=FxEvaluateChannelExpression(fx_info,BluePixelChannel,0,0,
3406 pixel.blue=(double) QuantumRange*value;
3407 if (image->colorspace == CMYKColorspace)
3409 status&=FxEvaluateChannelExpression(fx_info,BlackPixelChannel,0,0,
3411 pixel.black=(double) QuantumRange*value;
3413 status&=FxEvaluateChannelExpression(fx_info,AlphaPixelChannel,0,0,
3415 pixel.alpha=(double) QuantumRange*value;
3416 fx_info=DestroyFxInfo(fx_info);
3417 if( IfMagickTrue(status) )
3420 name[MaxTextExtent];
3422 (void) QueryColorname(image,&pixel,SVGCompliance,name,
3424 AppendString2Text(name);
3428 /* option - direct global option lookup (with globbing) */
3429 if (LocaleNCompare("option:",pattern,7) == 0)
3431 if (image_info == (ImageInfo *) NULL ) {
3432 (void) ThrowMagickException(exception,GetMagickModule(),
3433 OptionWarning,"NoImageForProperty","\"%%[%s]\"",pattern);
3434 continue; /* else no image to retrieve artifact */
3436 if( IfMagickTrue(IsGlob(pattern+7)) )
3438 ResetImageOptionIterator(image_info);
3439 while ((key=GetNextImageOption(image_info)) != (const char *) NULL)
3440 if( IfMagickTrue(GlobExpression(key,pattern+7,MagickTrue)) )
3442 string=GetImageOption(image_info,key);
3443 if (string != (const char *) NULL)
3444 AppendKeyValue2Text(key,string);
3445 /* else - assertion failure? key found but no string value! */
3449 string=GetImageOption(image_info,pattern+7);
3450 if (string == (char *) NULL)
3451 goto PropertyLookupFailure; /* no artifact of this specifc name */
3452 AppendString2Text(string);
3455 /* artifact - direct image artifact lookup (with glob) */
3456 if (LocaleNCompare("artifact:",pattern,9) == 0)
3458 if (image == (Image *) NULL ) {
3459 (void) ThrowMagickException(exception,GetMagickModule(),
3460 OptionWarning,"NoImageForProperty","\"%%[%s]\"",pattern);
3461 continue; /* else no image to retrieve artifact */
3463 if( IfMagickTrue(IsGlob(pattern+9)) )
3465 ResetImageArtifactIterator(image);
3466 while ((key=GetNextImageArtifact(image)) != (const char *) NULL)
3467 if( IfMagickTrue(GlobExpression(key,pattern+9,MagickTrue)) )
3469 string=GetImageArtifact(image,key);
3470 if (string != (const char *) NULL)
3471 AppendKeyValue2Text(key,string);
3472 /* else - assertion failure? key found but no string value! */
3476 string=GetImageArtifact(image,pattern+9);
3477 if (string == (char *) NULL)
3478 goto PropertyLookupFailure; /* no artifact of this specifc name */
3479 AppendString2Text(string);
3482 /* property - direct image property lookup (with glob) */
3483 if (LocaleNCompare("property:",pattern,9) == 0)
3485 if (image == (Image *) NULL ) {
3486 (void) ThrowMagickException(exception,GetMagickModule(),
3487 OptionWarning,"NoImageForProperty","\"%%[%s]\"",pattern);
3488 continue; /* else no image to retrieve artifact */
3490 if( IfMagickTrue(IsGlob(pattern+9)) )
3492 ResetImagePropertyIterator(image);
3493 while ((key=GetNextImageProperty(image)) != (const char *) NULL)
3494 if( IfMagickTrue(GlobExpression(key,pattern,MagickTrue)) )
3496 string=GetImageProperty(image,key,exception);
3497 if (string != (const char *) NULL)
3498 AppendKeyValue2Text(key,string);
3499 /* else - assertion failure? */
3503 string=GetImageProperty(image,pattern+9,exception);
3504 if (string == (char *) NULL)
3505 goto PropertyLookupFailure; /* no artifact of this specifc name */
3506 AppendString2Text(string);
3509 /* Properties without special prefix.
3510 This handles attributes, properties, and profiles such as %[exif:...]
3511 Note the profile properties may also include a glob expansion pattern.
3513 if ( image != (Image *)NULL )
3515 string=GetImageProperty(image,pattern,exception);
3516 if (string != (const char *) NULL)
3518 AppendString2Text(string);
3519 if (image != (Image *) NULL)
3520 (void)DeleteImageArtifact(image,"get-property");
3521 if (image_info != (ImageInfo *) NULL)
3522 (void)DeleteImageOption(image_info,"get-property");
3527 Handle property 'glob' patterns
3528 Such as: %[*] %[user:array_??] %[filename:e*]
3530 if( IfMagickTrue(IsGlob(pattern)) )
3532 if (image == (Image *) NULL)
3533 continue; /* else no image to retrieve proprty - no list */
3534 ResetImagePropertyIterator(image);
3535 while ((key=GetNextImageProperty(image)) != (const char *) NULL)
3536 if( IfMagickTrue(GlobExpression(key,pattern,MagickTrue)) )
3538 string=GetImageProperty(image,key,exception);
3539 if (string != (const char *) NULL)
3540 AppendKeyValue2Text(key,string);
3541 /* else - assertion failure? */
3546 Look for a known property or image attribute
3547 Such as %[basename] %[denisty] %[delay]
3548 Also handles a braced single letter: %[b] %[G] %[g]
3550 string=GetMagickProperty(image_info,image,pattern,exception);
3551 if (string != (const char *) NULL)
3553 AppendString2Text(string);
3557 Look for a per-image Artifact
3558 This includes option lookup (FUTURE: interpreted according to image)
3560 if (image != (Image *)NULL)
3562 string=GetImageArtifact(image,pattern);
3563 if (string != (char *) NULL)
3565 AppendString2Text(string);
3570 /* no image, so direct 'option' lookup (no delayed percent escapes) */
3571 if (image_info != (ImageInfo *) NULL)
3573 string=GetImageOption(image_info,pattern);
3574 if (string != (char *) NULL)
3576 AppendString2Text(string);
3580 PropertyLookupFailure:
3582 Failed to find any match anywhere!
3584 if (len >= 64) { /* truncate string for error message */
3590 (void) ThrowMagickException(exception,GetMagickModule(),
3591 OptionWarning,"UnknownImageProperty","\"%%[%s]\"",pattern);
3593 } /* Braced Percent Escape */
3595 } /* for each char in 'embed_text' */
3597 return(interpret_text);
3601 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3605 % R e m o v e I m a g e P r o p e r t y %
3609 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3611 % RemoveImageProperty() removes a property from the image and returns its
3614 % In this case the ConstantString() value returned should be freed by the
3615 % caller when finished.
3617 % The format of the RemoveImageProperty method is:
3619 % char *RemoveImageProperty(Image *image,const char *property)
3621 % A description of each parameter follows:
3623 % o image: the image.
3625 % o property: the image property.
3628 MagickExport char *RemoveImageProperty(Image *image,
3629 const char *property)
3634 assert(image != (Image *) NULL);
3635 assert(image->signature == MagickSignature);
3636 if( IfMagickTrue(image->debug) )
3637 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
3639 if (image->properties == (void *) NULL)
3640 return((char *) NULL);
3641 value=(char *) RemoveNodeFromSplayTree((SplayTreeInfo *) image->properties,
3647 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3651 % 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 %
3655 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3657 % ResetImagePropertyIterator() resets the image properties iterator. Use it
3658 % in conjunction with GetNextImageProperty() to iterate over all the values
3659 % associated with an image property.
3661 % The format of the ResetImagePropertyIterator method is:
3663 % ResetImagePropertyIterator(Image *image)
3665 % A description of each parameter follows:
3667 % o image: the image.
3670 MagickExport void ResetImagePropertyIterator(const Image *image)
3672 assert(image != (Image *) NULL);
3673 assert(image->signature == MagickSignature);
3674 if( IfMagickTrue(image->debug) )
3675 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
3677 if (image->properties == (void *) NULL)
3679 ResetSplayTreeIterator((SplayTreeInfo *) image->properties);
3683 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3687 % S e t I m a g e P r o p e r t y %
3691 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3693 % SetImageProperty() saves the given string value either to specific known
3694 % attribute or to a freeform property string.
3696 % Attempting to set a property that is normally calculated will produce
3699 % The format of the SetImageProperty method is:
3701 % MagickBooleanType SetImageProperty(Image *image,const char *property,
3702 % const char *value,ExceptionInfo *exception)
3704 % A description of each parameter follows:
3706 % o image: the image.
3708 % o property: the image property.
3710 % o values: the image property values.
3712 % o exception: return any errors or warnings in this structure.
3715 MagickExport MagickBooleanType SetImageProperty(Image *image,
3716 const char *property,const char *value,ExceptionInfo *exception)
3724 assert(image != (Image *) NULL);
3725 assert(image->signature == MagickSignature);
3726 if( IfMagickTrue(image->debug) )
3727 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
3729 /* Create splay-tree */
3730 if (image->properties == (void *) NULL)
3731 image->properties=NewSplayTree(CompareSplayTreeString,
3732 RelinquishMagickMemory,RelinquishMagickMemory);
3734 /* Delete property if NULL -- empty string values are valid! */
3735 if (value == (const char *) NULL)
3736 return(DeleteImageProperty(image,property));
3739 /* Do not 'set' single letter properties - read only shorthand */
3740 if (strlen(property) <= 1)
3742 (void) ThrowMagickException(exception,GetMagickModule(),
3743 OptionError,"SetReadOnlyProperty","`%s'",property);
3744 return(MagickFalse);
3747 /* FUTURE: binary chars or quotes in key should produce a error */
3750 /* Set attributes with known names or special prefixes
3751 return result is found, or break to set a free form properity
3755 #if 0 /* Percent escape's sets values with this prefix: for later use
3756 Throwing an exception causes this setting to fail */
3759 if (LocaleNCompare("8bim:",property,5) == 0)
3761 (void) ThrowMagickException(exception,GetMagickModule(),
3762 OptionError,"SetReadOnlyProperty","`%s'",property);
3763 return(MagickFalse);
3771 if (LocaleCompare("background",property) == 0)
3773 (void) QueryColorCompliance(value,AllCompliance,
3774 &image->background_color,exception);
3775 /* check for FUTURE: value exception?? */
3776 /* also add user input to splay tree */
3778 break; /* not an attribute, add as a property */
3783 if (LocaleCompare("channels",property) == 0)
3785 (void) ThrowMagickException(exception,GetMagickModule(),
3786 OptionError,"SetReadOnlyProperty","`%s'",property);
3787 return(MagickFalse);
3789 if (LocaleCompare("colorspace",property) == 0)
3794 colorspace=ParseCommandOption(MagickColorspaceOptions,MagickFalse,
3797 return(MagickFalse); /* FUTURE: value exception?? */
3798 return(SetImageColorspace(image,(ColorspaceType) colorspace,exception));
3800 if (LocaleCompare("compose",property) == 0)
3805 compose=ParseCommandOption(MagickComposeOptions,MagickFalse,value);
3807 return(MagickFalse); /* FUTURE: value exception?? */
3808 image->compose=(CompositeOperator) compose;
3811 if (LocaleCompare("compress",property) == 0)
3816 compression=ParseCommandOption(MagickCompressOptions,MagickFalse,
3818 if (compression < 0)
3819 return(MagickFalse); /* FUTURE: value exception?? */
3820 image->compression=(CompressionType) compression;
3823 if (LocaleCompare("copyright",property) == 0)
3825 (void) ThrowMagickException(exception,GetMagickModule(),
3826 OptionError,"SetReadOnlyProperty","`%s'",property);
3827 return(MagickFalse);
3829 break; /* not an attribute, add as a property */
3834 if (LocaleCompare("delay",property) == 0)
3839 flags=ParseGeometry(value,&geometry_info);
3840 if ((flags & GreaterValue) != 0)
3842 if (image->delay > (size_t) floor(geometry_info.rho+0.5))
3843 image->delay=(size_t) floor(geometry_info.rho+0.5);
3846 if ((flags & LessValue) != 0)
3848 if (image->delay < (size_t) floor(geometry_info.rho+0.5))
3849 image->delay=(ssize_t)
3850 floor(geometry_info.sigma+0.5);
3853 image->delay=(size_t) floor(geometry_info.rho+0.5);
3854 if ((flags & SigmaValue) != 0)
3855 image->ticks_per_second=(ssize_t) floor(geometry_info.sigma+0.5);
3858 if (LocaleCompare("delay_units",property) == 0)
3860 (void) ThrowMagickException(exception,GetMagickModule(),
3861 OptionError,"SetReadOnlyProperty","`%s'",property);
3862 return(MagickFalse);
3864 if (LocaleCompare("density",property) == 0)
3869 flags=ParseGeometry(value,&geometry_info);
3870 image->resolution.x=geometry_info.rho;
3871 image->resolution.y=geometry_info.sigma;
3872 if ((flags & SigmaValue) == 0)
3873 image->resolution.y=image->resolution.x;
3876 if (LocaleCompare("depth",property) == 0)
3878 image->depth=StringToUnsignedLong(value);
3881 if (LocaleCompare("dispose",property) == 0)
3886 dispose=ParseCommandOption(MagickDisposeOptions,MagickFalse,value);
3888 return(MagickFalse); /* FUTURE: value exception?? */
3889 image->dispose=(DisposeType) dispose;
3892 break; /* not an attribute, add as a property */
3894 #if 0 /* Percent escape's sets values with this prefix: for later use
3895 Throwing an exception causes this setting to fail */
3899 if (LocaleNCompare("exif:",property,5) == 0)
3901 (void) ThrowMagickException(exception,GetMagickModule(),
3902 OptionError,"SetReadOnlyProperty","`%s'",property);
3903 return(MagickFalse);
3905 break; /* not an attribute, add as a property */
3910 if (LocaleNCompare("fx:",property,3) == 0)
3912 (void) ThrowMagickException(exception,GetMagickModule(),
3913 OptionError,"SetReadOnlyProperty","`%s'",property);
3914 return(MagickFalse);
3916 break; /* not an attribute, add as a property */
3922 if (LocaleCompare("gamma",property) == 0)
3924 image->gamma=StringToDouble(value,(char **) NULL);
3927 if (LocaleCompare("gravity",property) == 0)
3932 gravity=ParseCommandOption(MagickGravityOptions,MagickFalse,value);
3934 return(MagickFalse); /* FUTURE: value exception?? */
3935 image->gravity=(GravityType) gravity;
3938 break; /* not an attribute, add as a property */
3943 if (LocaleCompare("height",property) == 0)
3945 (void) ThrowMagickException(exception,GetMagickModule(),
3946 OptionError,"SetReadOnlyProperty","`%s'",property);
3947 return(MagickFalse);
3949 break; /* not an attribute, add as a property */
3954 if (LocaleCompare("intensity",property) == 0)
3959 intensity=ParseCommandOption(MagickIntentOptions,MagickFalse,
3962 return(MagickFalse);
3963 image->intensity=(PixelIntensityMethod) intensity;
3966 if (LocaleCompare("intent",property) == 0)
3971 rendering_intent=ParseCommandOption(MagickIntentOptions,MagickFalse,
3973 if (rendering_intent < 0)
3974 return(MagickFalse); /* FUTURE: value exception?? */
3975 image->rendering_intent=(RenderingIntent) rendering_intent;
3978 if (LocaleCompare("interpolate",property) == 0)
3983 interpolate=ParseCommandOption(MagickInterpolateOptions,MagickFalse,
3985 if (interpolate < 0)
3986 return(MagickFalse); /* FUTURE: value exception?? */
3987 image->interpolate=(PixelInterpolateMethod) interpolate;
3990 #if 0 /* Percent escape's sets values with this prefix: for later use
3991 Throwing an exception causes this setting to fail */
3992 if (LocaleNCompare("iptc:",property,5) == 0)
3994 (void) ThrowMagickException(exception,GetMagickModule(),
3995 OptionError,"SetReadOnlyProperty","`%s'",property);
3996 return(MagickFalse);
3999 break; /* not an attribute, add as a property */
4003 if (LocaleCompare("kurtosis",property) == 0)
4005 (void) ThrowMagickException(exception,GetMagickModule(),
4006 OptionError,"SetReadOnlyProperty","`%s'",property);
4007 return(MagickFalse);
4009 break; /* not an attribute, add as a property */
4013 if (LocaleCompare("loop",property) == 0)
4015 image->iterations=StringToUnsignedLong(value);
4018 break; /* not an attribute, add as a property */
4022 if ( (LocaleCompare("magick",property) == 0) ||
4023 (LocaleCompare("max",property) == 0) ||
4024 (LocaleCompare("mean",property) == 0) ||
4025 (LocaleCompare("min",property) == 0) ||
4026 (LocaleCompare("min",property) == 0) )
4028 (void) ThrowMagickException(exception,GetMagickModule(),OptionError,
4029 "SetReadOnlyProperty","`%s'",property);
4030 return(MagickFalse);
4032 break; /* not an attribute, add as a property */
4035 if (LocaleCompare("opaque",property) == 0)
4037 (void) ThrowMagickException(exception,GetMagickModule(),
4038 OptionError,"SetReadOnlyProperty","`%s'",property);
4039 return(MagickFalse);
4041 break; /* not an attribute, add as a property */
4045 if (LocaleCompare("page",property) == 0)
4050 geometry=GetPageGeometry(value);
4051 flags=ParseAbsoluteGeometry(geometry,&image->page);
4052 geometry=DestroyString(geometry);
4055 #if 0 /* Percent escape's sets values with this prefix: for later use
4056 Throwing an exception causes this setting to fail */
4057 if (LocaleNCompare("pixel:",property,6) == 0)
4059 (void) ThrowMagickException(exception,GetMagickModule(),
4060 OptionError,"SetReadOnlyProperty","`%s'",property);
4061 return(MagickFalse);
4064 if (LocaleCompare("profile",property) == 0)
4072 image_info=AcquireImageInfo();
4073 (void) CopyMagickString(image_info->filename,value,MaxTextExtent);
4074 (void) SetImageInfo(image_info,1,exception);
4075 profile=FileToStringInfo(image_info->filename,~0UL,exception);
4076 if (profile != (StringInfo *) NULL)
4077 status=SetImageProfile(image,image_info->magick,profile,exception);
4078 image_info=DestroyImageInfo(image_info);
4081 break; /* not an attribute, add as a property */
4086 if (LocaleCompare("rendering-intent",property) == 0)
4091 rendering_intent=ParseCommandOption(MagickIntentOptions,MagickFalse,
4093 if (rendering_intent < 0)
4094 return(MagickFalse); /* FUTURE: value exception?? */
4095 image->rendering_intent=(RenderingIntent) rendering_intent;
4098 break; /* not an attribute, add as a property */
4102 if ( (LocaleCompare("size",property) == 0) ||
4103 (LocaleCompare("skewness",property) == 0) ||
4104 (LocaleCompare("scenes",property) == 0) ||
4105 (LocaleCompare("standard-deviation",property) == 0) )
4107 (void) ThrowMagickException(exception,GetMagickModule(),
4108 OptionError,"SetReadOnlyProperty","`%s'",property);
4109 return(MagickFalse);
4111 break; /* not an attribute, add as a property */
4115 if (LocaleCompare("tile-offset",property) == 0)
4120 geometry=GetPageGeometry(value);
4121 flags=ParseAbsoluteGeometry(geometry,&image->tile_offset);
4122 geometry=DestroyString(geometry);
4125 break; /* not an attribute, add as a property */
4130 if (LocaleCompare("units",property) == 0)
4135 units=ParseCommandOption(MagickResolutionOptions,MagickFalse,value);
4137 return(MagickFalse); /* FUTURE: value exception?? */
4138 image->units=(ResolutionType) units;
4141 break; /* not an attribute, add as a property */
4146 if (LocaleCompare("version",property) == 0)
4148 (void) ThrowMagickException(exception,GetMagickModule(),
4149 OptionError,"SetReadOnlyProperty","`%s'",property);
4150 return(MagickFalse);
4152 break; /* not an attribute, add as a property */
4157 if (LocaleCompare("width",property) == 0)
4159 (void) ThrowMagickException(exception,GetMagickModule(),
4160 OptionError,"SetReadOnlyProperty","`%s'",property);
4161 return(MagickFalse);
4163 break; /* not an attribute, add as a property */
4165 #if 0 /* Percent escape's sets values with this prefix: for later use
4166 Throwing an exception causes this setting to fail */
4170 if (LocaleNCompare("xmp:",property,4) == 0)
4172 (void) ThrowMagickException(exception,GetMagickModule(),
4173 OptionError,"SetReadOnlyProperty","`%s'",property);
4174 return(MagickFalse);
4176 break; /* not an attribute, add as a property */
4180 /* Default: not an attribute, add as a property */
4181 status=AddValueToSplayTree((SplayTreeInfo *) image->properties,
4182 ConstantString(property),ConstantString(value));
4183 /* FUTURE: error if status is bad? */