% MagickCore Property Methods %
% %
% Software Design %
-% John Cristy %
+% Cristy %
% March 2000 %
% %
% %
-% Copyright 1999-2012 ImageMagick Studio LLC, a non-profit organization %
+% Copyright 1999-2014 ImageMagick Studio LLC, a non-profit organization %
% dedicated to making software imaging solutions freely available. %
% %
% You may not use this file except in compliance with the License. You may %
%
%
*/
-\f
+
+
/*
Include declarations.
*/
#include "MagickCore/studio.h"
+#include "MagickCore/artifact.h"
#include "MagickCore/attribute.h"
#include "MagickCore/cache.h"
+#include "MagickCore/cache-private.h"
#include "MagickCore/color.h"
+#include "MagickCore/color-private.h"
+#include "MagickCore/colorspace-private.h"
#include "MagickCore/compare.h"
#include "MagickCore/constitute.h"
#include "MagickCore/draw.h"
#include "MagickCore/geometry.h"
#include "MagickCore/histogram.h"
#include "MagickCore/image.h"
-#include "MagickCore/image.h"
#include "MagickCore/layer.h"
#include "MagickCore/locale-private.h"
#include "MagickCore/list.h"
#include "MagickCore/version.h"
#include "MagickCore/xml-tree.h"
#include "MagickCore/xml-tree-private.h"
+#if defined(MAGICKCORE_LCMS_DELEGATE)
+#if defined(MAGICKCORE_HAVE_LCMS_LCMS2_H)
+#include <lcms/lcms2.h>
+#elif defined(MAGICKCORE_HAVE_LCMS2_H)
+#include "lcms2.h"
+#elif defined(MAGICKCORE_HAVE_LCMS_LCMS_H)
+#include <lcms/lcms.h>
+#else
+#include "lcms.h"
+#endif
+#endif
+\f
+/*
+ Define declarations.
+*/
+#if defined(MAGICKCORE_LCMS_DELEGATE)
+#if defined(LCMS_VERSION) && (LCMS_VERSION < 2000)
+#define cmsUInt32Number DWORD
+#endif
+#endif
\f
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
-% CloneImageProperties() clones one or more image properties.
+% CloneImageProperties() clones all the image properties to another image.
%
% The format of the CloneImageProperties method is:
%
{
assert(image != (Image *) NULL);
assert(image->signature == MagickSignature);
- if (image->debug != MagickFalse)
+ if( IfMagickTrue(image->debug) )
(void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
assert(clone_image != (const Image *) NULL);
assert(clone_image->signature == MagickSignature);
- if (clone_image->debug != MagickFalse)
+ if( IfMagickTrue(clone_image->debug) )
(void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
clone_image->filename);
(void) CopyMagickString(image->filename,clone_image->filename,MaxTextExtent);
image->page=clone_image->page;
image->tile_offset=clone_image->tile_offset;
image->extract_info=clone_image->extract_info;
- image->bias=clone_image->bias;
image->filter=clone_image->filter;
- image->blur=clone_image->blur;
image->fuzz=clone_image->fuzz;
+ image->intensity=clone_image->intensity;
image->interlace=clone_image->interlace;
image->interpolate=clone_image->interpolate;
image->endian=clone_image->endian;
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
-% DefineImageProperty() associates a key/value pair with an image property.
+% DefineImageProperty() associates an assignment string of the form
+% "key=value" with an artifact or options. It is equivelent to
+% SetImageProperty()
%
% The format of the DefineImageProperty method is:
%
-% MagickBooleanType DefineImageProperty(Image *image,
-% const char *property,ExceptionInfo *exception)
+% MagickBooleanType DefineImageProperty(Image *image,const char *property,
+% ExceptionInfo *exception)
%
% A description of each parameter follows:
%
{
assert(image != (Image *) NULL);
assert(image->signature == MagickSignature);
- if (image->debug != MagickFalse)
+ if( IfMagickTrue(image->debug) )
(void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
image->filename);
if (image->properties == (void *) NULL)
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
-% DestroyImageProperties() releases memory associated with image property
-% values.
+% DestroyImageProperties() destroys all properties and associated memory
+% attached to the given image.
%
% The format of the DestroyDefines method is:
%
{
assert(image != (Image *) NULL);
assert(image->signature == MagickSignature);
- if (image->debug != MagickFalse)
+ if( IfMagickTrue(image->debug) )
(void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
image->filename);
if (image->properties != (void *) NULL)
%
% GetImageProperty() gets a value associated with an image property.
%
+% This includes, profile prefixes, such as "exif:", "iptc:" and "8bim:"
+% It does not handle non-prifile prefixes, such as "fx:", "option:", or
+% "artifact:".
+%
+% The returned string is stored as a properity of the same name for faster
+% lookup later. It should NOT be freed by the caller.
+%
% The format of the GetImageProperty method is:
%
% const char *GetImageProperty(const Image *image,const char *key,
return(y);
}
+static inline ssize_t MagickMin(const ssize_t x,const ssize_t y)
+{
+ if (x < y)
+ return(x);
+ return(y);
+}
+
static inline int ReadPropertyByte(const unsigned char **p,size_t *length)
{
int
value;
if (*length < 2)
- return((unsigned short) ~0U);
+ return((unsigned short) ~0);
for (i=0; i < 2; i++)
{
c=(int) (*(*p)++);
status=MagickFalse;
length=GetStringInfoLength(profile);
info=GetStringInfoDatum(profile);
- while ((length > 0) && (status == MagickFalse))
+ while ((length > 0) && IfMagickFalse(status))
{
if (ReadPropertyByte(&info,&length) != (unsigned char) '8')
continue;
continue;
if (ReadPropertyByte(&info,&length) != (unsigned char) 'M')
continue;
- id=(ssize_t) ReadPropertyMSBShort(&info,&length);
+ id=(ssize_t) ((int) ReadPropertyMSBShort(&info,&length));
if (id < (ssize_t) start)
continue;
if (id > (ssize_t) stop)
if ((count != 0) && ((size_t) count <= length))
{
resource=(char *) NULL;
- if (~(1UL*count) >= (MaxTextExtent-1))
+ if (~((size_t) count) >= (MaxTextExtent-1))
resource=(char *) AcquireQuantumMemory((size_t) count+MaxTextExtent,
sizeof(*resource));
if (resource != (char *) NULL)
No name match, scroll forward and try next.
*/
info+=count;
- length-=count;
+ length-=MagickMin(count,(ssize_t) length);
continue;
}
if ((*name == '#') && (sub_number != 1))
*/
sub_number--;
info+=count;
- length-=count;
+ length-=MagickMin(count,(ssize_t) length);
continue;
}
/*
We have the resource of interest.
*/
attribute=(char *) NULL;
- if (~(1UL*count) >= (MaxTextExtent-1))
+ if (~((size_t) count) >= (MaxTextExtent-1))
attribute=(char *) AcquireQuantumMemory((size_t) count+MaxTextExtent,
sizeof(*attribute));
if (attribute != (char *) NULL)
(void) CopyMagickMemory(attribute,(char *) info,(size_t) count);
attribute[count]='\0';
info+=count;
- length-=count;
+ length-=MagickMin(count,(ssize_t) length);
if ((id <= 1999) || (id >= 2999))
(void) SetImageProperty((Image *) image,key,(const char *)
attribute,exception);
unsigned short
value;
- if (endian == MSBEndian)
+ if (endian == LSBEndian)
{
- value=(unsigned short) ((((unsigned char *) buffer)[0] << 8) |
- ((unsigned char *) buffer)[1]);
+ value=(unsigned short) ((buffer[1] << 8) | buffer[0]);
return((unsigned short) (value & 0xffff));
}
- value=(unsigned short) ((buffer[1] << 8) | buffer[0]);
+ value=(unsigned short) ((((unsigned char *) buffer)[0] << 8) |
+ ((unsigned char *) buffer)[1]);
return((unsigned short) (value & 0xffff));
}
size_t
value;
- if (endian == MSBEndian)
+ if (endian == LSBEndian)
{
- value=(size_t) ((buffer[0] << 24) | (buffer[1] << 16) |
- (buffer[2] << 8) | buffer[3]);
+ value=(size_t) ((buffer[3] << 24) | (buffer[2] << 16) |
+ (buffer[1] << 8 ) | (buffer[0]));
return((size_t) (value & 0xffffffff));
}
- value=(size_t) ((buffer[3] << 24) | (buffer[2] << 16) |
- (buffer[1] << 8 ) | (buffer[0]));
+ value=(size_t) ((buffer[0] << 24) | (buffer[1] << 16) |
+ (buffer[2] << 8) | buffer[3]);
return((size_t) (value & 0xffffffff));
}
for (component=0; component < components; component++) \
{ \
length+=FormatLocaleString(buffer+length,MaxTextExtent-length, \
- format", ",arg1,arg2); \
+ format", ",(arg1),(arg2)); \
if (length >= (MaxTextExtent-1)) \
length=MaxTextExtent-1; \
p1+=size; \
*directory;
size_t
- entry,
+ entry;
+
+ ssize_t
offset;
} DirectoryInfo;
{ 0x1001c, "exif:GPSAreaInformation" },
{ 0x1001d, "exif:GPSDateStamp" },
{ 0x1001e, "exif:GPSDifferential" },
- { 0x0000, NULL}
+ { 0x00000, (const char *) NULL }
};
const StringInfo
entry,
length,
number_entries,
- tag_offset,
tag;
SplayTreeInfo
id,
level,
offset,
+ tag_offset,
tag_value;
static int
This the offset to the first IFD.
*/
offset=(ssize_t) ((int) ReadPropertyLong(endian,exif+4));
- if ((size_t) offset >= length)
+ if ((offset < 0) || (size_t) offset >= length)
return(MagickFalse);
/*
Set the pointer to the first IFD and follow it were it leads.
/*
Determine how many entries there are in the current IFD.
*/
- number_entries=ReadPropertyShort(endian,directory);
+ number_entries=(size_t) ((int) ReadPropertyShort(endian,directory));
for ( ; entry < number_entries; entry++)
{
register unsigned char
*q;
size_t
- format,
- number_bytes;
+ format;
ssize_t
+ number_bytes,
components;
q=(unsigned char *) (directory+(12*entry)+2);
break;
components=(ssize_t) ((int) ReadPropertyLong(endian,q+4));
number_bytes=(size_t) components*tag_bytes[format];
+ if (number_bytes < components)
+ break; /* prevent overflow */
if (number_bytes <= 4)
p=q+8;
else
The directory entry contains an offset.
*/
offset=(ssize_t) ((int) ReadPropertyLong(endian,q+8));
+ if ((ssize_t) (offset+number_bytes) < offset)
+ continue; /* prevent overflow */
if ((size_t) (offset+number_bytes) > length)
continue;
p=(unsigned char *) (exif+offset);
buffer[MaxTextExtent],
*value;
+ value=(char *) NULL;
+ *buffer='\0';
switch (format)
{
case EXIF_FMT_BYTE:
case EXIF_FMT_ULONG:
{
EXIFMultipleValues(4,"%.20g",(double)
- ReadPropertyLong(endian,p1));
+ ((int) ReadPropertyLong(endian,p1)));
break;
}
case EXIF_FMT_SLONG:
case EXIF_FMT_STRING:
{
value=(char *) NULL;
- if (~(1UL*number_bytes) >= 1)
+ if (~((size_t) number_bytes) >= 1)
value=(char *) AcquireQuantumMemory((size_t) number_bytes+1UL,
sizeof(*value));
if (value != (char *) NULL)
if (value != (char *) NULL)
{
char
- key[MaxTextExtent];
+ *key;
register const char
*p;
- (void) CopyMagickString(key,property,MaxTextExtent);
+ key=AcquireString(property);
+ if (level == 2)
+ (void) SubstituteString(&key,"exif:","exif:thumbnail:");
switch (all)
{
case 1:
if (p == (const char *) NULL)
(void) SetImageProperty((Image *) image,key,value,exception);
value=DestroyString(value);
+ key=DestroyString(key);
status=MagickTrue;
}
}
if ((tag_value == TAG_EXIF_OFFSET) ||
- (tag_value == TAG_INTEROP_OFFSET) ||
- (tag_value == TAG_GPS_OFFSET))
+ (tag_value == TAG_INTEROP_OFFSET) || (tag_value == TAG_GPS_OFFSET))
{
- size_t
+ ssize_t
offset;
- offset=(size_t) ((int) ReadPropertyLong(endian,p));
- if ((offset < length) && (level < (MaxDirectoryStack-2)))
+ offset=(ssize_t) ((int) ReadPropertyLong(endian,p));
+ if (((size_t) offset < length) && (level < (MaxDirectoryStack-2)))
{
- size_t
+ ssize_t
tag_offset1;
- tag_offset1=(tag_value == TAG_GPS_OFFSET) ? 0x10000UL : 0UL;
+ tag_offset1=(ssize_t) ((tag_value == TAG_GPS_OFFSET) ? 0x10000 :
+ 0);
directory_stack[level].directory=directory;
entry++;
directory_stack[level].entry=entry;
level++;
if ((directory+2+(12*number_entries)) > (exif+length))
break;
- offset=(size_t) ReadPropertyLong(endian,directory+2+(12*
- number_entries));
- if ((offset != 0) && (offset < length) &&
+ offset=(ssize_t) ((int) ReadPropertyLong(endian,directory+2+(12*
+ number_entries)));
+ if ((offset != 0) && ((size_t) offset < length) &&
(level < (MaxDirectoryStack-2)))
{
directory_stack[level].directory=exif+offset;
return(status);
}
+static MagickBooleanType GetICCProperty(const Image *image,const char *property,
+ ExceptionInfo *exception)
+{
+ const StringInfo
+ *profile;
+
+ magick_unreferenced(property);
+
+ profile=GetImageProfile(image,"icc");
+ if (profile == (StringInfo *) NULL)
+ profile=GetImageProfile(image,"icm");
+ if (profile == (StringInfo *) NULL)
+ return(MagickFalse);
+ if (GetStringInfoLength(profile) < 128)
+ return(MagickFalse); /* minimum ICC profile length */
+#if defined(MAGICKCORE_LCMS_DELEGATE)
+ {
+ cmsHPROFILE
+ icc_profile;
+
+ icc_profile=cmsOpenProfileFromMem(GetStringInfoDatum(profile),
+ (cmsUInt32Number) GetStringInfoLength(profile));
+ if (icc_profile != (cmsHPROFILE *) NULL)
+ {
+#if defined(LCMS_VERSION) && (LCMS_VERSION < 2000)
+ const char
+ *name;
+
+ name=cmsTakeProductName(icc_profile);
+ if (name != (const char *) NULL)
+ (void) SetImageProperty((Image *) image,"icc:name",name,exception);
+#else
+ char
+ info[MaxTextExtent];
+
+ (void) cmsGetProfileInfoASCII(icc_profile,cmsInfoDescription,
+ "en","US",info,MaxTextExtent);
+ (void) SetImageProperty((Image *) image,"icc:description",info,
+ exception);
+ (void) cmsGetProfileInfoASCII(icc_profile,cmsInfoManufacturer,
+ "en","US",info,MaxTextExtent);
+ (void) SetImageProperty((Image *) image,"icc:manufacturer",info,
+ exception);
+ (void) cmsGetProfileInfoASCII(icc_profile,cmsInfoModel,"en",
+ "US",info,MaxTextExtent);
+ (void) SetImageProperty((Image *) image,"icc:model",info,exception);
+ (void) cmsGetProfileInfoASCII(icc_profile,cmsInfoCopyright,
+ "en","US",info,MaxTextExtent);
+ (void) SetImageProperty((Image *) image,"icc:copyright",info,exception);
+#endif
+ (void) cmsCloseProfile(icc_profile);
+ }
+ }
+#endif
+ return(MagickTrue);
+}
+
static MagickBooleanType GetXMPProperty(const Image *image,const char *property)
{
char
in_subpath=MagickFalse;
while (length > 0)
{
- selector=(ssize_t) ReadPropertyMSBShort(&blob,&length);
+ selector=(ssize_t) ((int) ReadPropertyMSBShort(&blob,&length));
switch (selector)
{
case 0:
if (knot_count != 0)
{
blob+=24;
- length-=24;
+ length-=MagickMin(24,(ssize_t) length);
break;
}
/*
Expected subpath length record.
*/
- knot_count=(ssize_t) ReadPropertyMSBShort(&blob,&length);
+ knot_count=(ssize_t) ((int) ReadPropertyMSBShort(&blob,&length));
blob+=22;
- length-=22;
+ length-=MagickMin(22,(ssize_t) length);
break;
}
case 1:
Unexpected subpath knot
*/
blob+=24;
- length-=24;
+ length-=MagickMin(24,(ssize_t) length);
break;
}
/*
xx,
yy;
- yy=ReadPropertyMSBLong(&blob,&length);
- xx=ReadPropertyMSBLong(&blob,&length);
+ yy=(size_t) ((int) ReadPropertyMSBLong(&blob,&length));
+ xx=(size_t) ((int) ReadPropertyMSBLong(&blob,&length));
x=(ssize_t) xx;
if (xx > 2147483647)
x=(ssize_t) xx-4294967295U-1;
point[i].x=(double) x/4096/4096;
point[i].y=1.0-(double) y/4096/4096;
}
- if (in_subpath == MagickFalse)
+ if( IfMagickFalse(in_subpath) )
{
(void) FormatLocaleString(message,MaxTextExtent," %g %g m\n",
point[1].x,point[1].y);
default:
{
blob+=24;
- length-=24;
+ length-=MagickMin(24,(ssize_t) length);
break;
}
}
in_subpath=MagickFalse;
while (length != 0)
{
- selector=(ssize_t) ReadPropertyMSBShort(&blob,&length);
+ selector=(ssize_t) ((int) ReadPropertyMSBShort(&blob,&length));
switch (selector)
{
case 0:
if (knot_count != 0)
{
blob+=24;
- length-=24;
+ length-=MagickMin(24,(ssize_t) length);
break;
}
/*
Expected subpath length record.
*/
- knot_count=(ssize_t) ReadPropertyMSBShort(&blob,&length);
+ knot_count=(ssize_t) ((int) ReadPropertyMSBShort(&blob,&length));
blob+=22;
- length-=22;
+ length-=MagickMin(22,(ssize_t) length);
break;
}
case 1:
Unexpected subpath knot.
*/
blob+=24;
- length-=24;
+ length-=MagickMin(24,(ssize_t) length);
break;
}
/*
xx,
yy;
- yy=ReadPropertyMSBLong(&blob,&length);
- xx=ReadPropertyMSBLong(&blob,&length);
+ yy=(size_t) ((int) ReadPropertyMSBLong(&blob,&length));
+ xx=(size_t) ((int) ReadPropertyMSBLong(&blob,&length));
x=(ssize_t) xx;
if (xx > 2147483647)
x=(ssize_t) xx-4294967295U-1;
}
if (in_subpath == MagickFalse)
{
- (void) FormatLocaleString(message,MaxTextExtent,"M %g,%g\n",
+ (void) FormatLocaleString(message,MaxTextExtent,"M %g %g\n",
point[1].x,point[1].y);
for (i=0; i < 3; i++)
{
}
else
{
+ /*
+ Handle special cases when Bezier curves are used to describe
+ corners and straight lines.
+ */
if ((last[1].x == last[2].x) && (last[1].y == last[2].y) &&
(point[0].x == point[1].x) && (point[0].y == point[1].y))
- (void) FormatLocaleString(message,MaxTextExtent,"L %g,%g\n",
- point[1].x,point[1].y);
- else
(void) FormatLocaleString(message,MaxTextExtent,
- "C %g,%g %g,%g %g,%g\n",last[2].x,last[2].y,
- point[0].x,point[0].y,point[1].x,point[1].y);
+ "L %g %g\n",point[1].x,point[1].y);
+ else
+ if ((last[1].x == last[2].x) && (last[1].y == last[2].y))
+ (void) FormatLocaleString(message,MaxTextExtent,
+ "V %g %g %g %g\n",point[0].x,point[0].y,
+ point[1].x,point[1].y);
+ else
+ if ((point[0].x == point[1].x) && (point[0].y == point[1].y))
+ (void) FormatLocaleString(message,MaxTextExtent,
+ "Y %g %g %g %g\n",last[2].x,last[2].y,
+ point[1].x,point[1].y);
+ else
+ (void) FormatLocaleString(message,MaxTextExtent,
+ "C %g %g %g %g %g %g\n",last[2].x,
+ last[2].y,point[0].x,point[0].y,point[1].x,point[1].y);
for (i=0; i < 3; i++)
last[i]=point[i];
}
*/
if (knot_count == 0)
{
+ /*
+ Same special handling as above except we compare to the
+ first point in the path and close the path.
+ */
if ((last[1].x == last[2].x) && (last[1].y == last[2].y) &&
(first[0].x == first[1].x) && (first[0].y == first[1].y))
(void) FormatLocaleString(message,MaxTextExtent,
- "L %g,%g Z\n",first[1].x,first[1].y);
+ "L %g %g Z\n",first[1].x,first[1].y);
else
- {
+ if ((last[1].x == last[2].x) && (last[1].y == last[2].y))
(void) FormatLocaleString(message,MaxTextExtent,
- "C %g,%g %g,%g %g,%g Z\n",last[2].x,
- last[2].y,first[0].x,first[0].y,first[1].x,first[1].y);
- (void) ConcatenateString(&path,message);
- }
+ "V %g %g %g %g Z\n",first[0].x,first[0].y,
+ first[1].x,first[1].y);
+ else
+ if ((first[0].x == first[1].x) && (first[0].y == first[1].y))
+ (void) FormatLocaleString(message,MaxTextExtent,
+ "Y %g %g %g %g Z\n",last[2].x,last[2].y,
+ first[1].x,first[1].y);
+ else
+ (void) FormatLocaleString(message,MaxTextExtent,
+ "C %g %g %g %g %g %g Z\n",last[2].x,
+ last[2].y,first[0].x,first[0].y,first[1].x,first[1].y);
+ (void) ConcatenateString(&path,message);
in_subpath=MagickFalse;
}
break;
default:
{
blob+=24;
- length-=24;
+ length-=MagickMin(24,(ssize_t) length);
break;
}
}
MagickExport const char *GetImageProperty(const Image *image,
const char *property,ExceptionInfo *exception)
{
- FxInfo
- *fx_info;
-
- MagickRealType
- alpha;
-
- MagickStatusType
- status;
-
register const char
*p;
assert(image != (Image *) NULL);
assert(image->signature == MagickSignature);
- if (image->debug != MagickFalse)
+ if (IfMagickTrue(image->debug))
(void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
p=(const char *) NULL;
if (image->properties != (void *) NULL)
image->properties);
return(p);
}
- if (LocaleNCompare("fx:",property,3) != 0)
- {
- p=(const char *) GetValueFromSplayTree((SplayTreeInfo *)
- image->properties,property);
- if (p != (const char *) NULL)
- return(p);
- }
+ p=(const char *) GetValueFromSplayTree((SplayTreeInfo *)
+ image->properties,property);
+ if (p != (const char *) NULL)
+ return(p);
}
if ((property == (const char *) NULL) ||
(strchr(property,':') == (char *) NULL))
{
if (LocaleNCompare("8bim:",property,5) == 0)
{
- if ((Get8BIMProperty(image,property,exception) != MagickFalse) &&
- (image->properties != (void *) NULL))
- {
- p=(const char *) GetValueFromSplayTree((SplayTreeInfo *)
- image->properties,property);
- return(p);
- }
+ (void) Get8BIMProperty(image,property,exception);
+ break;
}
break;
}
{
if (LocaleNCompare("exif:",property,5) == 0)
{
- if ((GetEXIFProperty(image,property,exception) != MagickFalse) &&
- (image->properties != (void *) NULL))
- {
- p=(const char *) GetValueFromSplayTree((SplayTreeInfo *)
- image->properties,property);
- return(p);
- }
- }
- break;
- }
- case 'F':
- case 'f':
- {
- if (LocaleNCompare("fx:",property,3) == 0)
- {
- fx_info=AcquireFxInfo(image,property+3);
- status=FxEvaluateChannelExpression(fx_info,IntensityPixelChannel,0,0,
- &alpha,exception);
- fx_info=DestroyFxInfo(fx_info);
- if (status != MagickFalse)
- {
- char
- value[MaxTextExtent];
-
- (void) FormatLocaleString(value,MaxTextExtent,"%.*g",
- GetMagickPrecision(),(double) alpha);
- (void) SetImageProperty((Image *) image,property,value,exception);
- }
- if (image->properties != (void *) NULL)
- {
- p=(const char *) GetValueFromSplayTree((SplayTreeInfo *)
- image->properties,property);
- return(p);
- }
+ (void) GetEXIFProperty(image,property,exception);
+ break;
}
break;
}
case 'I':
case 'i':
{
- if (LocaleNCompare("iptc:",property,5) == 0)
+ if ((LocaleNCompare("icc:",property,4) == 0) ||
+ (LocaleNCompare("icm:",property,4) == 0))
{
- if ((GetIPTCProperty(image,property,exception) != MagickFalse) &&
- (image->properties != (void *) NULL))
- {
- p=(const char *) GetValueFromSplayTree((SplayTreeInfo *)
- image->properties,property);
- return(p);
- }
+ (void) GetICCProperty(image,property,exception);
+ break;
}
- break;
- }
- case 'P':
- case 'p':
- {
- if (LocaleNCompare("pixel:",property,6) == 0)
+ if (LocaleNCompare("iptc:",property,5) == 0)
{
- PixelInfo
- pixel;
-
- GetPixelInfo(image,&pixel);
- fx_info=AcquireFxInfo(image,property+6);
- status=FxEvaluateChannelExpression(fx_info,RedPixelChannel,0,0,
- &alpha,exception);
- pixel.red=(MagickRealType) QuantumRange*alpha;
- status|=FxEvaluateChannelExpression(fx_info,GreenPixelChannel,0,0,
- &alpha,exception);
- pixel.green=(MagickRealType) QuantumRange*alpha;
- status|=FxEvaluateChannelExpression(fx_info,BluePixelChannel,0,0,
- &alpha,exception);
- pixel.blue=(MagickRealType) QuantumRange*alpha;
- if (image->colorspace == CMYKColorspace)
- {
- status|=FxEvaluateChannelExpression(fx_info,BlackPixelChannel,0,0,
- &alpha,exception);
- pixel.black=(MagickRealType) QuantumRange*alpha;
- }
- status|=FxEvaluateChannelExpression(fx_info,AlphaPixelChannel,0,0,
- &alpha,exception);
- pixel.alpha=(MagickRealType) QuantumRange*(1.0-alpha);
- fx_info=DestroyFxInfo(fx_info);
- if (status != MagickFalse)
- {
- char
- name[MaxTextExtent];
-
- (void) QueryColorname(image,&pixel,SVGCompliance,name,
- exception);
- (void) SetImageProperty((Image *) image,property,name,exception);
- return(GetImageProperty(image,property,exception));
- }
+ (void) GetIPTCProperty(image,property,exception);
+ break;
}
break;
}
{
if (LocaleNCompare("xmp:",property,4) == 0)
{
- if ((GetXMPProperty(image,property) != MagickFalse) &&
- (image->properties != (void *) NULL))
- {
- p=(const char *) GetValueFromSplayTree((SplayTreeInfo *)
- image->properties,property);
- return(p);
- }
+ (void) GetXMPProperty(image,property);
+ break;
}
break;
}
default:
break;
}
- return(p);
+ if (image->properties != (void *) NULL)
+ {
+ p=(const char *) GetValueFromSplayTree((SplayTreeInfo *)
+ image->properties,property);
+ return(p);
+ }
+ return((const char *) NULL);
}
\f
/*
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
-% GetMagickProperty() gets a value associated with an image property.
+% GetMagickProperty() gets attributes or calculated values that is associated
+% with a fixed known property name, or single letter property. It may be
+% called if no image is defined (IMv7), in which case only global image_info
+% values are available.
+%
+% This routine only handles specifically known properties. It does not
+% handle special prefixed properties, profiles, or expressions. Nor does
+% it return any free-form property strings.
+%
+% The returned string is stored in a structure somewhere, and should not be
+% directly freed. If the string was generated (common) the string will be
+% stored as as either as artifact or option 'get-property'. These may be
+% deleted (cleaned up) when no longer required, but neither artifact or
+% option is guranteed to exist.
%
% The format of the GetMagickProperty method is:
%
-% const char *GetMagickProperty(const ImageInfo *image_info,Image *image,
-% const char *key,ExceptionInfo *exception)
+% const char *GetMagickProperty(ImageInfo *image_info,Image *image,
+% const char *property,ExceptionInfo *exception)
%
% A description of each parameter follows:
%
-% o image_info: the image info.
+% o image_info: the image info (optional)
%
-% o image: the image.
+% o image: the image (optional)
%
% o key: the key.
%
% o exception: return any errors or warnings in this structure.
%
*/
-MagickExport const char *GetMagickProperty(const ImageInfo *image_info,
- Image *image,const char *property,ExceptionInfo *exception)
+#define WarnNoImageReturn(format,arg) \
+ if (image == (Image *) NULL ) { \
+ (void) ThrowMagickException(exception,GetMagickModule(),OptionWarning, \
+ "NoImageForProperty",format,arg); \
+ return((const char *)NULL); \
+ }
+#define WarnNoImageInfoReturn(format,arg) \
+ if (image_info == (ImageInfo *) NULL ) { \
+ (void) ThrowMagickException(exception,GetMagickModule(),OptionWarning, \
+ "NoImageInfoForProperty",format,arg); \
+ return((const char *)NULL); \
+ }
+
+static const char *GetMagickPropertyLetter(ImageInfo *image_info,
+ Image *image,const char letter,ExceptionInfo *exception)
{
char
- value[MaxTextExtent],
- filename[MaxTextExtent];
+ value[MaxTextExtent]; /* formated string to store as a returned artifact */
- *value='\0';
- switch (*property)
+ const char
+ *string; /* return a string already stored somewher */
+
+ if (image != (Image *) NULL && IfMagickTrue(image->debug))
+ (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
+ else if( image_info != (ImageInfo *) NULL && IfMagickTrue(image_info->debug))
+ (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s","no-images");
+
+ *value='\0'; /* formatted string */
+ string=(char *) NULL; /* constant string reference */
+
+ /* Get properities that are directly defined by images */
+ switch (letter)
{
- case 'b':
+ case 'b': /* image size read in - in bytes */
{
- if (LocaleNCompare("base",property,4) == 0)
- {
- GetPathComponent(image->magick_filename,BasePath,filename);
- (void) CopyMagickString(value,filename,MaxTextExtent);
- break;
- }
+ WarnNoImageReturn("\"%%%c\"",letter);
+ (void) FormatLocaleString(value,MaxTextExtent,"%.20g",(double)
+ ((MagickOffsetType) image->extent));
+ if (image->extent != (MagickSizeType) ((size_t) image->extent))
+ (void) FormatMagickSize(image->extent,MagickFalse,value);
+ ConcatenateMagickString(value,"B",MaxTextExtent);
break;
}
- case 'c':
+ case 'c': /* image comment property - empty string by default */
{
- if (LocaleNCompare("channels",property,8) == 0)
- {
- /*
- Image channels.
- */
- (void) FormatLocaleString(value,MaxTextExtent,"%s",
- CommandOptionToMnemonic(MagickColorspaceOptions,(ssize_t)
- image->colorspace));
- LocaleLower(value);
- if (image->matte != MagickFalse)
- (void) ConcatenateMagickString(value,"a",MaxTextExtent);
- break;
- }
- if (LocaleNCompare("colorspace",property,10) == 0)
- {
- ColorspaceType
- colorspace;
-
- /*
- Image storage class and colorspace.
- */
- colorspace=image->colorspace;
- if (IsImageGray(image,exception) != MagickFalse)
- colorspace=GRAYColorspace;
- (void) FormatLocaleString(value,MaxTextExtent,"%s",
- CommandOptionToMnemonic(MagickColorspaceOptions,(ssize_t)
- colorspace));
- break;
- }
- if (LocaleNCompare("copyright",property,9) == 0)
- {
- (void) CopyMagickString(value,GetMagickCopyright(),MaxTextExtent);
- break;
- }
+ WarnNoImageReturn("\"%%%c\"",letter);
+ string=GetImageProperty(image,"comment",exception);
+ if ( string == (const char *) NULL )
+ string="";
break;
}
- case 'd':
+ case 'd': /* Directory component of filename */
{
- if (LocaleNCompare("depth",property,5) == 0)
- {
- (void) FormatLocaleString(value,MaxTextExtent,"%.20g",(double)
- image->depth);
- break;
- }
- if (LocaleNCompare("directory",property,9) == 0)
- {
- GetPathComponent(image->magick_filename,HeadPath,filename);
- (void) CopyMagickString(value,filename,MaxTextExtent);
- break;
- }
+ WarnNoImageReturn("\"%%%c\"",letter);
+ GetPathComponent(image->magick_filename,HeadPath,value);
+ if (*value == '\0') string="";
break;
}
- case 'e':
+ case 'e': /* Filename extension (suffix) of image file */
{
- if (LocaleNCompare("extension",property,9) == 0)
- {
- GetPathComponent(image->magick_filename,ExtensionPath,filename);
- (void) CopyMagickString(value,filename,MaxTextExtent);
- break;
- }
+ WarnNoImageReturn("\"%%%c\"",letter);
+ GetPathComponent(image->magick_filename,ExtensionPath,value);
+ if (*value == '\0') string="";
break;
}
- case 'g':
+ case 'f': /* Filename without directory component */
{
- if (LocaleNCompare("group",property,5) == 0)
- {
- (void) FormatLocaleString(value,MaxTextExtent,"0x%lx",
- (unsigned long) image_info->group);
- break;
- }
+ WarnNoImageReturn("\"%%%c\"",letter);
+ GetPathComponent(image->magick_filename,TailPath,value);
+ if (*value == '\0') string="";
break;
}
- case 'h':
+ case 'g': /* Image geometry, canvas and offset %Wx%H+%X+%Y */
{
- if (LocaleNCompare("height",property,6) == 0)
- {
- (void) FormatLocaleString(value,MaxTextExtent,"%.20g",
- image->magick_rows != 0 ? (double) image->magick_rows : 256.0);
- break;
- }
+ WarnNoImageReturn("\"%%%c\"",letter);
+ (void) FormatLocaleString(value,MaxTextExtent,"%.20gx%.20g%+.20g%+.20g",
+ (double) image->page.width,(double) image->page.height,
+ (double) image->page.x,(double) image->page.y);
break;
}
- case 'i':
+ case 'h': /* Image height (current) */
{
- if (LocaleNCompare("input",property,5) == 0)
- {
- (void) CopyMagickString(value,image->filename,MaxTextExtent);
- break;
- }
+ WarnNoImageReturn("\"%%%c\"",letter);
+ (void) FormatLocaleString(value,MaxTextExtent,"%.20g",(double)
+ (image->rows != 0 ? image->rows : image->magick_rows));
break;
}
- case 'k':
+ case 'i': /* Filename last used for an image (read or write) */
{
- if (LocaleNCompare("kurtosis",property,8) == 0)
- {
- double
- kurtosis,
- skewness;
-
- (void) GetImageKurtosis(image,&kurtosis,&skewness,exception);
- (void) FormatLocaleString(value,MaxTextExtent,"%.*g",
- GetMagickPrecision(),kurtosis);
- break;
- }
+ WarnNoImageReturn("\"%%%c\"",letter);
+ string=image->filename;
break;
}
- case 'm':
+ case 'k': /* Number of unique colors */
{
- if (LocaleNCompare("magick",property,6) == 0)
- {
- (void) CopyMagickString(value,image->magick,MaxTextExtent);
- break;
- }
- if (LocaleNCompare("max",property,3) == 0)
- {
- double
- maximum,
- minimum;
-
- (void) GetImageRange(image,&minimum,&maximum,exception);
- (void) FormatLocaleString(value,MaxTextExtent,"%.*g",
- GetMagickPrecision(),maximum);
- break;
- }
- if (LocaleNCompare("mean",property,4) == 0)
- {
- double
- mean,
- standard_deviation;
-
- (void) GetImageMean(image,&mean,&standard_deviation,
- exception);
- (void) FormatLocaleString(value,MaxTextExtent,"%.*g",
- GetMagickPrecision(),mean);
- break;
- }
- if (LocaleNCompare("min",property,3) == 0)
- {
- double
- maximum,
- minimum;
-
- (void) GetImageRange(image,&minimum,&maximum,exception);
- (void) FormatLocaleString(value,MaxTextExtent,"%.*g",
- GetMagickPrecision(),minimum);
- break;
- }
+ /*
+ FUTURE: ensure this does not generate the formatted comment!
+ */
+ WarnNoImageReturn("\"%%%c\"",letter);
+ (void) FormatLocaleString(value,MaxTextExtent,"%.20g",(double)
+ GetNumberColors(image,(FILE *) NULL,exception));
break;
}
- case 'n':
+ case 'l': /* Image label property - empty string by default */
{
- if (LocaleNCompare("name",property,4) == 0)
- {
- (void) CopyMagickString(value,filename,MaxTextExtent);
- break;
- }
- break;
+ WarnNoImageReturn("\"%%%c\"",letter);
+ string=GetImageProperty(image,"label",exception);
+ if ( string == (const char *) NULL)
+ string="";
+ break;
+ }
+ case 'm': /* Image format (file magick) */
+ {
+ WarnNoImageReturn("\"%%%c\"",letter);
+ string=image->magick;
+ break;
+ }
+ case 'n': /* Number of images in the list. */
+ {
+ if ( image != (Image *) NULL )
+ (void) FormatLocaleString(value,MaxTextExtent,"%.20g",(double)
+ GetImageListLength(image));
+ else
+ string="0"; /* no images or scenes */
+ break;
+ }
+ case 'o': /* Output Filename - for delegate use only */
+ WarnNoImageInfoReturn("\"%%%c\"",letter);
+ string=image_info->filename;
+ break;
+ case 'p': /* Image index in current image list */
+ {
+ WarnNoImageReturn("\"%%%c\"",letter);
+ (void) FormatLocaleString(value,MaxTextExtent,"%.20g",(double)
+ GetImageIndexInList(image));
+ break;
+ }
+ case 'q': /* Quantum depth of image in memory */
+ {
+ WarnNoImageReturn("\"%%%c\"",letter);
+ (void) FormatLocaleString(value,MaxTextExtent,"%.20g",(double)
+ MAGICKCORE_QUANTUM_DEPTH);
+ break;
+ }
+ case 'r': /* Image storage class, colorspace, and alpha enabled. */
+ {
+ ColorspaceType
+ colorspace;
+
+ WarnNoImageReturn("\"%%%c\"",letter);
+ colorspace=image->colorspace;
+ if (IfMagickTrue(IsImageGray(image,exception)))
+ colorspace=GRAYColorspace; /* FUTURE: this is IMv6 not IMv7 */
+ (void) FormatLocaleString(value,MaxTextExtent,"%s %s %s",
+ CommandOptionToMnemonic(MagickClassOptions,(ssize_t) image->storage_class),
+ CommandOptionToMnemonic(MagickColorspaceOptions,(ssize_t) colorspace),
+ image->alpha_trait == BlendPixelTrait ? "Alpha" : "");
+ break;
+ }
+ case 's': /* Image scene number */
+ {
+#if 0 /* this seems non-sensical -- simplifing */
+ if (image_info->number_scenes != 0)
+ (void) FormatLocaleString(value,MaxTextExtent,"%.20g",(double)
+ image_info->scene);
+ else if (image != (Image *)NULL)
+ (void) FormatLocaleString(value,MaxTextExtent,"%.20g",(double)
+ image->scene);
+ else
+ string="0";
+#else
+ WarnNoImageReturn("\"%%%c\"",letter);
+ (void) FormatLocaleString(value,MaxTextExtent,"%.20g",(double)
+ image->scene);
+#endif
+ break;
+ }
+ case 't': /* Base filename without directory or extention */
+ {
+ WarnNoImageReturn("\"%%%c\"",letter);
+ GetPathComponent(image->magick_filename,BasePath,value);
+ if (*value == '\0') string="";
+ break;
+ }
+ case 'u': /* Unique filename */
+ WarnNoImageInfoReturn("\"%%%c\"",letter);
+ string=image_info->unique;
+ break;
+ case 'w': /* Image width (current) */
+ {
+ WarnNoImageReturn("\"%%%c\"",letter);
+ (void) FormatLocaleString(value,MaxTextExtent,"%.20g",(double)
+ (image->columns != 0 ? image->columns : image->magick_columns));
+ break;
+ }
+ case 'x': /* Image horizontal resolution (with units) */
+ {
+ WarnNoImageReturn("\"%%%c\"",letter);
+ (void) FormatLocaleString(value,MaxTextExtent,"%.20g",
+ fabs(image->resolution.x) > MagickEpsilon ? image->resolution.x : 72.0);
+ break;
+ }
+ case 'y': /* Image vertical resolution (with units) */
+ {
+ WarnNoImageReturn("\"%%%c\"",letter);
+ (void) FormatLocaleString(value,MaxTextExtent,"%.20g",
+ fabs(image->resolution.y) > MagickEpsilon ? image->resolution.y : 72.0);
+ break;
+ }
+ case 'z': /* Image depth as read in */
+ {
+ WarnNoImageReturn("\"%%%c\"",letter);
+ (void) FormatLocaleString(value,MaxTextExtent,"%.20g",
+ (double) image->depth);
+ break;
+ }
+ case 'A': /* Image alpha channel */
+ {
+ WarnNoImageReturn("\"%%%c\"",letter);
+ string=CommandOptionToMnemonic(MagickBooleanOptions,
+ (ssize_t) image->alpha_trait);
+ break;
+ }
+ case 'C': /* Image compression method. */
+ {
+ WarnNoImageReturn("\"%%%c\"",letter);
+ string=CommandOptionToMnemonic(MagickCompressOptions,
+ (ssize_t) image->compression);
+ break;
+ }
+ case 'D': /* Image dispose method. */
+ {
+ WarnNoImageReturn("\"%%%c\"",letter);
+ string=CommandOptionToMnemonic(MagickDisposeOptions,
+ (ssize_t) image->dispose);
+ break;
+ }
+ case 'G': /* Image size as geometry = "%wx%h" */
+ {
+ WarnNoImageReturn("\"%%%c\"",letter);
+ (void) FormatLocaleString(value,MaxTextExtent,"%.20gx%.20g",
+ (double)image->magick_columns,(double) image->magick_rows);
+ break;
+ }
+ case 'H': /* layer canvas height */
+ {
+ WarnNoImageReturn("\"%%%c\"",letter);
+ (void) FormatLocaleString(value,MaxTextExtent,"%.20g",
+ (double) image->page.height);
+ break;
+ }
+ case 'M': /* Magick filename - filename given incl. coder & read mods */
+ {
+ WarnNoImageReturn("\"%%%c\"",letter);
+ string=image->magick_filename;
+ break;
+ }
+ case 'O': /* layer canvas offset with sign = "+%X+%Y" */
+ {
+ WarnNoImageReturn("\"%%%c\"",letter);
+ (void) FormatLocaleString(value,MaxTextExtent,"%+ld%+ld",(long)
+ image->page.x,(long) image->page.y);
+ break;
+ }
+ case 'P': /* layer canvas page size = "%Wx%H" */
+ {
+ WarnNoImageReturn("\"%%%c\"",letter);
+ (void) FormatLocaleString(value,MaxTextExtent,"%.20gx%.20g",
+ (double) image->page.width,(double) image->page.height);
+ break;
+ }
+ case 'Q': /* image compression quality */
+ {
+ WarnNoImageReturn("\"%%%c\"",letter);
+ (void) FormatLocaleString(value,MaxTextExtent,"%.20g",(double)
+ (image->quality == 0 ? 92 : image->quality));
+ break;
+ }
+ case 'S': /* Number of scenes in image list. */
+ {
+ WarnNoImageInfoReturn("\"%%%c\"",letter);
+#if 0 /* What is this number? -- it makes no sense - simplifing */
+ if (image_info->number_scenes == 0)
+ string="2147483647";
+ else if ( image != (Image *) NULL )
+ (void) FormatLocaleString(value,MaxTextExtent,"%.20g",(double)
+ image_info->scene+image_info->number_scenes);
+ else
+ string="0";
+#else
+ (void) FormatLocaleString(value,MaxTextExtent,"%.20g",(double)
+ (image_info->number_scenes == 0 ? 2147483647 :
+ image_info->number_scenes));
+#endif
+ break;
+ }
+ case 'T': /* image time delay for animations */
+ {
+ WarnNoImageReturn("\"%%%c\"",letter);
+ (void) FormatLocaleString(value,MaxTextExtent,"%.20g",(double)
+ image->delay);
+ break;
+ }
+ case 'U': /* Image resolution units. */
+ {
+ WarnNoImageReturn("\"%%%c\"",letter);
+ string=CommandOptionToMnemonic(MagickResolutionOptions,
+ (ssize_t) image->units);
+ break;
+ }
+ case 'W': /* layer canvas width */
+ {
+ WarnNoImageReturn("\"%%%c\"",letter);
+ (void) FormatLocaleString(value,MaxTextExtent,"%.20g",(double)
+ image->page.width);
+ break;
+ }
+ case 'X': /* layer canvas X offset */
+ {
+ WarnNoImageReturn("\"%%%c\"",letter);
+ (void) FormatLocaleString(value,MaxTextExtent,"%+.20g",(double)
+ image->page.x);
+ break;
+ }
+ case 'Y': /* layer canvas Y offset */
+ {
+ WarnNoImageReturn("\"%%%c\"",letter);
+ (void) FormatLocaleString(value,MaxTextExtent,"%+.20g",(double)
+ image->page.y);
+ break;
+ }
+ case 'Z': /* Zero filename ??? */
+ WarnNoImageInfoReturn("\"%%%c\"",letter);
+ string=image_info->zero;
+ break;
+ case '%': /* percent escaped */
+ string="%";
+ break;
+ case '@': /* Trim bounding box, without actually Trimming! */
+ {
+ RectangleInfo
+ page;
+
+ WarnNoImageReturn("\"%%%c\"",letter);
+ page=GetImageBoundingBox(image,exception);
+ (void) FormatLocaleString(value,MaxTextExtent,"%.20gx%.20g%+.20g%+.20g",
+ (double) page.width,(double) page.height,(double) page.x,(double)
+ page.y);
+ break;
+ }
+ case '#':
+ {
+ /*
+ Image signature.
+ */
+ WarnNoImageReturn("\"%%%c\"",letter);
+ (void) SignatureImage(image,exception);
+ string=GetImageProperty(image,"signature",exception);
+ break;
+ }
+ }
+ if (string != (char *) NULL)
+ return(string);
+ if (*value != '\0')
+ {
+ /*
+ Create a cloned copy of result.
+ */
+ if (image != (Image *)NULL)
+ {
+ (void) SetImageArtifact(image,"get-property",value);
+ return(GetImageArtifact(image,"get-property"));
+ }
+ else
+ {
+ (void) SetImageOption(image_info,"get-property",value);
+ return(GetImageOption(image_info,"get-property"));
+ }
+ }
+ return((char *)NULL);
+}
+
+MagickExport const char *GetMagickProperty(ImageInfo *image_info,
+ Image *image,const char *property,ExceptionInfo *exception)
+{
+ char
+ value[MaxTextExtent];
+
+ const char
+ *string;
+
+ assert(property[0] != '\0');
+ assert(image != (Image *)NULL || image_info != (ImageInfo *)NULL );
+
+ if (property[1] == '\0') /* single letter property request */
+ return(GetMagickPropertyLetter(image_info,image,*property,exception));
+
+ if (image != (Image *) NULL && IfMagickTrue(image->debug))
+ (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
+ else if( image_info != (ImageInfo *) NULL && IfMagickTrue(image_info->debug))
+ (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s","no-images");
+
+ *value='\0'; /* formated string */
+ string=(char *) NULL; /* constant string reference */
+ switch (*property)
+ {
+ case 'b':
+ {
+ if ((LocaleCompare("base",property) == 0) ||
+ (LocaleCompare("basename",property) == 0) )
+ {
+ WarnNoImageReturn("\"%%[%s]\"",property);
+ GetPathComponent(image->magick_filename,BasePath,value);
+ if (*value == '\0') string="";
+ break;
+ }
+ if (LocaleCompare("bit-depth",property) == 0)
+ {
+ (void) FormatLocaleString(value,MaxTextExtent,"%.20g",(double)
+ GetImageDepth(image, exception));
+ break;
+ }
+ break;
+ }
+ case 'c':
+ {
+ if (LocaleCompare("channels",property) == 0)
+ {
+ WarnNoImageReturn("\"%%[%s]\"",property);
+ /* FUTURE: return actual image channels */
+ (void) FormatLocaleString(value,MaxTextExtent,"%s",
+ CommandOptionToMnemonic(MagickColorspaceOptions,(ssize_t)
+ image->colorspace));
+ LocaleLower(value);
+ if( image->alpha_trait == BlendPixelTrait )
+ (void) ConcatenateMagickString(value,"a",MaxTextExtent);
+ break;
+ }
+ if (LocaleCompare("colorspace",property) == 0)
+ {
+ WarnNoImageReturn("\"%%[%s]\"",property);
+ /* FUTURE: return actual colorspace - no 'gray' stuff */
+ string=CommandOptionToMnemonic(MagickColorspaceOptions,(ssize_t)
+ image->colorspace);
+ break;
+ }
+ if (LocaleCompare("copyright",property) == 0)
+ {
+ (void) CopyMagickString(value,GetMagickCopyright(),MaxTextExtent);
+ break;
+ }
+ break;
+ }
+ case 'd':
+ {
+ if (LocaleCompare("depth",property) == 0)
+ {
+ WarnNoImageReturn("\"%%[%s]\"",property);
+ (void) FormatLocaleString(value,MaxTextExtent,"%.20g",(double)
+ image->depth);
+ break;
+ }
+ if (LocaleCompare("directory",property) == 0)
+ {
+ WarnNoImageReturn("\"%%[%s]\"",property);
+ GetPathComponent(image->magick_filename,HeadPath,value);
+ if (*value == '\0') string="";
+ break;
+ }
+ break;
+ }
+ case 'e':
+ {
+ if (LocaleCompare("extension",property) == 0)
+ {
+ WarnNoImageReturn("\"%%[%s]\"",property);
+ GetPathComponent(image->magick_filename,ExtensionPath,value);
+ if (*value == '\0') string="";
+ break;
+ }
+ break;
+ }
+ case 'g':
+ {
+ if (LocaleCompare("gamma",property) == 0)
+ {
+ WarnNoImageReturn("\"%%[%s]\"",property);
+ (void) FormatLocaleString(value,MaxTextExtent,"%.*g",
+ GetMagickPrecision(),image->gamma);
+ break;
+ }
+ if (LocaleCompare("group",property) == 0)
+ {
+ WarnNoImageInfoReturn("\"%%[%s]\"",property);
+ (void) FormatLocaleString(value,MaxTextExtent,"0x%lx",(unsigned long)
+ image_info->group);
+ break;
+ }
+ break;
+ }
+ case 'h':
+ {
+ if (LocaleCompare("height",property) == 0)
+ {
+ WarnNoImageReturn("\"%%[%s]\"",property);
+ (void) FormatLocaleString(value,MaxTextExtent,"%.20g",
+ image->magick_rows != 0 ? (double) image->magick_rows : 256.0);
+ break;
+ }
+ break;
+ }
+ case 'i':
+ {
+ if (LocaleCompare("input",property) == 0)
+ {
+ WarnNoImageReturn("\"%%[%s]\"",property);
+ string=image->filename;
+ break;
+ }
+ break;
+ }
+ case 'k':
+ {
+ if (LocaleCompare("kurtosis",property) == 0)
+ {
+ double
+ kurtosis,
+ skewness;
+
+ WarnNoImageReturn("\"%%[%s]\"",property);
+ (void) GetImageKurtosis(image,&kurtosis,&skewness,exception);
+ (void) FormatLocaleString(value,MaxTextExtent,"%.*g",
+ GetMagickPrecision(),kurtosis);
+ break;
+ }
+ break;
+ }
+ case 'm':
+ {
+ if (LocaleCompare("magick",property) == 0)
+ {
+ WarnNoImageReturn("\"%%[%s]\"",property);
+ string=image->magick;
+ break;
+ }
+ if (LocaleCompare("max",property) == 0)
+ {
+ double
+ maximum,
+ minimum;
+
+ WarnNoImageReturn("\"%%[%s]\"",property);
+ (void) GetImageRange(image,&minimum,&maximum,exception);
+ (void) FormatLocaleString(value,MaxTextExtent,"%.*g",
+ GetMagickPrecision(),maximum);
+ break;
+ }
+ if (LocaleCompare("mean",property) == 0)
+ {
+ double
+ mean,
+ standard_deviation;
+
+ WarnNoImageReturn("\"%%[%s]\"",property);
+ (void) GetImageMean(image,&mean,&standard_deviation,exception);
+ (void) FormatLocaleString(value,MaxTextExtent,"%.*g",
+ GetMagickPrecision(),mean);
+ break;
+ }
+ if (LocaleCompare("min",property) == 0)
+ {
+ double
+ maximum,
+ minimum;
+
+ WarnNoImageReturn("\"%%[%s]\"",property);
+ (void) GetImageRange(image,&minimum,&maximum,exception);
+ (void) FormatLocaleString(value,MaxTextExtent,"%.*g",
+ GetMagickPrecision(),minimum);
+ break;
+ }
+ break;
}
case 'o':
{
- if (LocaleNCompare("opaque",property,6) == 0)
+ if (LocaleCompare("opaque",property) == 0)
{
- MagickBooleanType
- opaque;
+ WarnNoImageReturn("\"%%[%s]\"",property);
+ string=CommandOptionToMnemonic(MagickBooleanOptions,
+ (ssize_t) IsImageOpaque(image,exception));
+ break;
+ }
+ if (LocaleCompare("orientation",property) == 0)
+ {
+ WarnNoImageReturn("\"%%[%s]\"",property);
+ string=CommandOptionToMnemonic(MagickOrientationOptions,(ssize_t)
+ image->orientation);
+ break;
+ }
+ if (LocaleCompare("output",property) == 0)
+ {
+ WarnNoImageInfoReturn("\"%%[%s]\"",property);
+ (void) CopyMagickString(value,image_info->filename,MaxTextExtent);
+ break;
+ }
+ break;
+ }
+ case 'p':
+ {
+#if defined(MAGICKCORE_LCMS_DELEGATE)
+ if (LocaleCompare("profile:icc",property) == 0 ||
+ LocaleCompare("profile:icm",property) == 0)
+ {
+#if !defined(LCMS_VERSION) || (LCMS_VERSION < 2000)
+#define cmsUInt32Number DWORD
+#endif
+
+ const StringInfo
+ *profile;
+
+ cmsHPROFILE
+ icc_profile;
+
+ profile=GetImageProfile(image,property+8);
+ if (profile == (StringInfo *) NULL)
+ break;
- opaque=IsImageOpaque(image,exception);
- (void) CopyMagickString(value,opaque == MagickFalse ? "false" :
- "true",MaxTextExtent);
+ icc_profile=cmsOpenProfileFromMem(GetStringInfoDatum(profile),
+ (cmsUInt32Number) GetStringInfoLength(profile));
+ if (icc_profile != (cmsHPROFILE *) NULL)
+ {
+#if defined(LCMS_VERSION) && (LCMS_VERSION < 2000)
+ string=cmsTakeProductName(icc_profile);
+#else
+ (void) cmsGetProfileInfoASCII(icc_profile,cmsInfoDescription,
+ "en","US",value,MaxTextExtent);
+#endif
+ (void) cmsCloseProfile(icc_profile);
+ }
+ }
+#endif
+ if (LocaleCompare("profiles",property) == 0)
+ {
+ const char
+ *name;
+
+ ResetImageProfileIterator(image);
+ name=GetNextImageProfile(image);
+ if (name != (char *) NULL)
+ {
+ (void) CopyMagickString(value,name,MaxTextExtent);
+ name=GetNextImageProfile(image);
+ while (name != (char *) NULL)
+ {
+ ConcatenateMagickString(value,",",MaxTextExtent);
+ ConcatenateMagickString(value,name,MaxTextExtent);
+ name=GetNextImageProfile(image);
+ }
+ }
break;
}
- if (LocaleNCompare("output",property,6) == 0)
+ break;
+ }
+ case 'r':
+ {
+ if (LocaleCompare("resolution.x",property) == 0)
{
- (void) CopyMagickString(value,image_info->filename,MaxTextExtent);
+ WarnNoImageReturn("\"%%[%s]\"",property);
+ (void) FormatLocaleString(value,MaxTextExtent,"%g",
+ image->resolution.x);
break;
}
- break;
- }
- case 'p':
- {
- if (LocaleNCompare("page",property,4) == 0)
+ if (LocaleCompare("resolution.y",property) == 0)
{
- (void) FormatLocaleString(value,MaxTextExtent,"%.20g",(double)
- GetImageIndexInList(image)+1);
+ WarnNoImageReturn("\"%%[%s]\"",property);
+ (void) FormatLocaleString(value,MaxTextExtent,"%g",
+ image->resolution.y);
break;
}
break;
}
case 's':
{
- if (LocaleNCompare("size",property,4) == 0)
+ if (LocaleCompare("scene",property) == 0)
{
- char
- format[MaxTextExtent];
-
- (void) FormatMagickSize(GetBlobSize(image),MagickFalse,format);
- (void) FormatLocaleString(value,MaxTextExtent,"%sB",format);
+ WarnNoImageInfoReturn("\"%%[%s]\"",property);
+ if (image_info->number_scenes != 0)
+ (void) FormatLocaleString(value,MaxTextExtent,"%.20g",(double)
+ image_info->scene);
+ else {
+ WarnNoImageReturn("\"%%[%s]\"",property);
+ (void) FormatLocaleString(value,MaxTextExtent,"%.20g",(double)
+ image->scene);
+ }
break;
}
- if (LocaleNCompare("scenes",property,6) == 0)
+ if (LocaleCompare("scenes",property) == 0)
{
+ /* FUTURE: equivelent to %n? */
+ WarnNoImageReturn("\"%%[%s]\"",property);
(void) FormatLocaleString(value,MaxTextExtent,"%.20g",(double)
GetImageListLength(image));
break;
}
- if (LocaleNCompare("scene",property,5) == 0)
+ if (LocaleCompare("size",property) == 0)
{
- /* FUTURE: I am not certain this property return makes sense! */
- (void) FormatLocaleString(value,MaxTextExtent,"%.20g",(double)
- image->scene);
- if (image_info->number_scenes != 0)
- (void) FormatLocaleString(value,MaxTextExtent,"%.20g",(double)
- image_info->scene);
+ char
+ format[MaxTextExtent];
+
+ WarnNoImageReturn("\"%%[%s]\"",property);
+ (void) FormatMagickSize(GetBlobSize(image),MagickFalse,format);
+ (void) FormatLocaleString(value,MaxTextExtent,"%sB",format);
break;
}
- if (LocaleNCompare("skewness",property,8) == 0)
+ if (LocaleCompare("skewness",property) == 0)
{
double
kurtosis,
skewness;
+ WarnNoImageReturn("\"%%[%s]\"",property);
(void) GetImageKurtosis(image,&kurtosis,&skewness,exception);
(void) FormatLocaleString(value,MaxTextExtent,"%.*g",
GetMagickPrecision(),skewness);
break;
}
- if (LocaleNCompare("standard-deviation",property,18) == 0)
+ if ((LocaleCompare("standard-deviation",property) == 0) ||
+ (LocaleCompare("standard_deviation",property) == 0))
{
double
mean,
standard_deviation;
- (void) GetImageMean(image,&mean,&standard_deviation,
- exception);
+ WarnNoImageReturn("\"%%[%s]\"",property);
+ (void) GetImageMean(image,&mean,&standard_deviation,exception);
(void) FormatLocaleString(value,MaxTextExtent,"%.*g",
GetMagickPrecision(),standard_deviation);
break;
}
break;
}
+ case 't':
+ {
+ if (LocaleCompare("type",property) == 0)
+ {
+ WarnNoImageReturn("\"%%[%s]\"",property);
+ string=CommandOptionToMnemonic(MagickTypeOptions,(ssize_t)
+ GetImageType(image,exception));
+ break;
+ }
+ break;
+ }
case 'u':
{
- if (LocaleNCompare("unique",property,6) == 0)
+ if (LocaleCompare("unique",property) == 0)
+ {
+ WarnNoImageInfoReturn("\"%%[%s]\"",property);
+ string=image_info->unique;
+ break;
+ }
+ if (LocaleCompare("units",property) == 0)
{
- (void) CopyMagickString(filename,image_info->unique,MaxTextExtent);
- (void) CopyMagickString(value,filename,MaxTextExtent);
+ WarnNoImageReturn("\"%%[%s]\"",property);
+ string=CommandOptionToMnemonic(MagickResolutionOptions,(ssize_t)
+ image->units);
break;
}
+ if (LocaleCompare("copyright",property) == 0)
break;
}
case 'v':
{
- if (LocaleNCompare("version",property,7) == 0)
+ if (LocaleCompare("version",property) == 0)
{
- (void) CopyMagickString(value,GetMagickVersion((size_t *) NULL),
- MaxTextExtent);
+ string=GetMagickVersion((size_t *) NULL);
break;
}
break;
}
case 'w':
{
- if (LocaleNCompare("width",property,5) == 0)
+ if (LocaleCompare("width",property) == 0)
{
+ WarnNoImageReturn("\"%%[%s]\"",property);
(void) FormatLocaleString(value,MaxTextExtent,"%.20g",(double)
(image->magick_columns != 0 ? image->magick_columns : 256));
break;
}
break;
}
- case 'x':
+ case 'x': /* FUTURE: Obsolete X resolution */
{
- if (LocaleNCompare("xresolution",property,11) == 0)
+ if ((LocaleCompare("xresolution",property) == 0) ||
+ (LocaleCompare("x-resolution",property) == 0) )
{
- (void) FormatLocaleString(value,MaxTextExtent,"%g",
+ WarnNoImageReturn("\"%%[%s]\"",property);
+ (void) FormatLocaleString(value,MaxTextExtent,"%.20g",
image->resolution.x);
break;
}
break;
}
- case 'y':
+ case 'y': /* FUTURE: Obsolete Y resolution */
{
- if (LocaleNCompare("yresolution",property,11) == 0)
+ if ((LocaleCompare("yresolution",property) == 0) ||
+ (LocaleCompare("y-resolution",property) == 0) )
{
- (void) FormatLocaleString(value,MaxTextExtent,"%g",
+ WarnNoImageReturn("\"%%[%s]\"",property);
+ (void) FormatLocaleString(value,MaxTextExtent,"%.20g",
image->resolution.y);
break;
}
}
case 'z':
{
- if (LocaleNCompare("zero",property,4) == 0)
+ if (LocaleCompare("zero",property) == 0)
{
- (void) CopyMagickString(filename,image_info->zero,MaxTextExtent);
- (void) CopyMagickString(value,filename,MaxTextExtent);
+ WarnNoImageInfoReturn("\"%%[%s]\"",property);
+ string=image_info->zero;
break;
}
break;
}
}
+ if (string != (char *) NULL)
+ return(string);
if (*value != '\0')
- {
- if (image->properties == (void *) NULL)
- image->properties=NewSplayTree(CompareSplayTreeString,
- RelinquishMagickMemory,RelinquishMagickMemory);
- (void) AddValueToSplayTree((SplayTreeInfo *) image->properties,
- ConstantString(property),ConstantString(value));
- }
- return(GetImageProperty(image,property,exception));
+ {
+ /* create a cloned copy of result, that will get cleaned up, eventually */
+ if (image != (Image *)NULL)
+ {
+ (void) SetImageArtifact(image,"get-property",value);
+ return(GetImageArtifact(image,"get-property"));
+ }
+ else
+ {
+ (void) SetImageOption(image_info,"get-property",value);
+ return(GetImageOption(image_info,"get-property"));
+ }
+ }
+ return((char *)NULL);
}
+#undef WarnNoImageReturn
\f
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
-% GetNextImageProperty() gets the next image property value.
+% GetNextImageProperty() gets the next free-form string property name.
%
% The format of the GetNextImageProperty method is:
%
{
assert(image != (Image *) NULL);
assert(image->signature == MagickSignature);
- if (image->debug != MagickFalse)
+ if( IfMagickTrue(image->debug) )
(void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
image->filename);
if (image->properties == (void *) NULL)
% InterpretImageProperties() replaces any embedded formatting characters with
% the appropriate image property and returns the interpreted text.
%
+% This searches for and replaces
+% \n \r \% replaced by newline, return, and percent resp.
+% < > & replaced by '<', '>', '&' resp.
+% %% replaced by percent
+%
+% %x %[x] where 'x' is a single letter properity, case sensitive).
+% %[type:name] where 'type' a is special and known prefix.
+% %[name] where 'name' is a specifically known attribute, calculated
+% value, or a per-image property string name, or a per-image
+% 'artifact' (as generated from a global option).
+% It may contain ':' as long as the prefix is not special.
+%
+% Single letter % substitutions will only happen if the character before the
+% percent is NOT a number. But braced substitutions will always be performed.
+% This prevents the typical usage of percent in a interpreted geometry
+% argument from being substituted when the percent is a geometry flag.
+%
+% If 'glob-expresions' ('*' or '?' characters) is used for 'name' it may be
+% used as a search pattern to print multiple lines of "name=value\n" pairs of
+% the associacted set of properties.
+%
+% The returned string must be freed using DestoryString() by the caller.
+%
% The format of the InterpretImageProperties method is:
%
-% char *InterpretImageProperties(const ImageInfo *image_info,Image *image,
-% const char *embed_text,ExceptionInfo *exception)
+% char *InterpretImageProperties(ImageInfo *image_info,
+% Image *image,const char *embed_text,ExceptionInfo *exception)
%
% A description of each parameter follows:
%
-% o image_info: the image info.
+% o image_info: the image info. (required)
%
-% o image: the image.
+% o image: the image. (optional)
%
% o embed_text: the address of a character string containing the embedded
% formatting characters.
% o exception: return any errors or warnings in this structure.
%
*/
-MagickExport char *InterpretImageProperties(const ImageInfo *image_info,
+
+/* common inline code to expand the interpreted text string */
+#define ExtendInterpretText(string_length) do { \
+DisableMSCWarning(4127) \
+ size_t length=(string_length); \
+ if ((size_t) (q-interpret_text+length+1) >= extent) \
+ { extent+=length; \
+ interpret_text=(char *) ResizeQuantumMemory(interpret_text, \
+ extent+MaxTextExtent,sizeof(*interpret_text)); \
+ if (interpret_text == (char *) NULL) \
+ return((char *)NULL); \
+ q=interpret_text+strlen(interpret_text); \
+ } } while (0) /* no trailing ; */ \
+RestoreMSCWarning
+
+/* same but append the given string */
+#define AppendString2Text(string) do { \
+DisableMSCWarning(4127) \
+ size_t length=strlen((string)); \
+ if ((size_t) (q-interpret_text+length+1) >= extent) \
+ { extent+=length; \
+ interpret_text=(char *) ResizeQuantumMemory(interpret_text, \
+ extent+MaxTextExtent,sizeof(*interpret_text)); \
+ if (interpret_text == (char *) NULL) \
+ return((char *)NULL); \
+ q=interpret_text+strlen(interpret_text); \
+ } \
+ (void) CopyMagickString(q,(string),extent); \
+ q+=length; \
+ } while (0) /* no trailing ; */ \
+RestoreMSCWarning
+
+/* same but append a 'key' and 'string' pair */
+#define AppendKeyValue2Text(key,string) do { \
+DisableMSCWarning(4127) \
+ size_t length=strlen(key)+strlen(string)+2; \
+ if ((size_t) (q-interpret_text+length+1) >= extent) \
+ { extent+=length; \
+ interpret_text=(char *) ResizeQuantumMemory(interpret_text, \
+ extent+MaxTextExtent,sizeof(*interpret_text)); \
+ if (interpret_text == (char *) NULL) \
+ return((char *)NULL); \
+ q=interpret_text+strlen(interpret_text); \
+ } \
+ q+=FormatLocaleString(q,extent,"%s=%s\n",(key),(string)); \
+ } while (0) /* no trailing ; */ \
+RestoreMSCWarning
+
+MagickExport char *InterpretImageProperties(ImageInfo *image_info,
Image *image,const char *embed_text,ExceptionInfo *exception)
{
char
- filename[MaxTextExtent],
- *interpret_text,
- *text;
-
- const char
- *value;
+ *interpret_text;
register char
- *q;
+ *q; /* current position in interpret_text */
register const char
- *p;
-
- register ssize_t
- i;
+ *p; /* position in embed_text string being expanded */
size_t
- extent,
- length;
+ extent; /* allocated length of interpret_text */
- assert(image != (Image *) NULL);
- assert(image->signature == MagickSignature);
- if (image->debug != MagickFalse)
+ MagickBooleanType
+ number;
+
+ assert(image == NULL || image->signature == MagickSignature);
+ assert(image_info == NULL || image_info->signature == MagickSignature);
+
+ if (image != (Image *) NULL && IfMagickTrue(image->debug))
(void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
- if ((embed_text == (const char *) NULL) || (*embed_text == '\0'))
+ else if( image_info != (ImageInfo *) NULL && IfMagickTrue(image_info->debug))
+ (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s","no-image");
+
+ if (embed_text == (const char *) NULL)
return((char *) NULL);
- text=(char *) embed_text;
- if ((*text == '@') && ((*(text+1) == '-') ||
- (IsPathAccessible(text+1) != MagickFalse)))
- return(FileToString(embed_text+1,~0,exception));
+ p=embed_text;
+
+ if (*p == '\0')
+ return(ConstantString(""));
+
+ /* handle a '@' replace string from file */
+ if (*p == '@') {
+ p++;
+ if (*p != '-' && IfMagickFalse(IsPathAccessible(p)) ) {
+ (void) ThrowMagickException(exception,GetMagickModule(),
+ OptionError,"UnableToAccessPath","%s",p);
+ return((char *) NULL);
+ }
+ return(FileToString(p,~0UL,exception));
+ }
+
/*
Translate any embedded format characters.
*/
- interpret_text=AcquireString(text);
- extent=MaxTextExtent;
- p=text;
- for (q=interpret_text; *p != '\0'; p++)
+ interpret_text=AcquireString(embed_text); /* new string with extra space */
+ extent=MaxTextExtent; /* allocated space in string */
+ number=MagickFalse; /* is last char a number? */
+ for (q=interpret_text; *p!='\0'; number=IsMagickTrue(isdigit(*p)),p++)
{
*q='\0';
- if ((size_t) (q-interpret_text+MaxTextExtent) >= extent)
- {
- extent+=MaxTextExtent;
- interpret_text=(char *) ResizeQuantumMemory(interpret_text,extent+
- MaxTextExtent+1,sizeof(*interpret_text));
- if (interpret_text == (char *) NULL)
- break;
- q=interpret_text+strlen(interpret_text);
- }
+ ExtendInterpretText(MaxTextExtent);
/*
- Process formatting characters in text.
+ Look for the various escapes, (and handle other specials)
*/
- if ((*p == '\\') && (*(p+1) == 'r'))
- {
- *q++='\r';
- p++;
- continue;
- }
- if ((*p == '\\') && (*(p+1) == 'n'))
- {
- *q++='\n';
- p++;
+ switch (*p) {
+ case '\\':
+ switch (*(p+1)) {
+ case '\0':
+ continue;
+ case 'r': /* convert to RETURN */
+ *q++='\r';
+ p++;
+ continue;
+ case 'n': /* convert to NEWLINE */
+ *q++='\n';
+ p++;
+ continue;
+ case '\n': /* EOL removal UNIX,MacOSX */
+ p++;
+ continue;
+ case '\r': /* EOL removal DOS,Windows */
+ p++;
+ if (*p == '\n') /* return-newline EOL */
+ p++;
+ continue;
+ default:
+ p++;
+ *q++=(*p);
+ }
continue;
- }
- if (*p == '\\')
- {
- p++;
- *q++=(*p);
+ case '&':
+ if (LocaleNCompare("<",p,4) == 0)
+ *q++='<', p+=3;
+ else if (LocaleNCompare(">",p,4) == 0)
+ *q++='>', p+=3;
+ else if (LocaleNCompare("&",p,5) == 0)
+ *q++='&', p+=4;
+ else
+ *q++=(*p);
continue;
- }
- if (*p != '%')
- {
- *q++=(*p);
+ case '%':
+ break; /* continue to next set of handlers */
+ default:
+ *q++=(*p); /* any thing else is 'as normal' */
continue;
- }
- p++;
- switch (*p)
- {
- case '[': /* multi-character substitution */
- {
- char
- pattern[MaxTextExtent];
-
- const char
- *key,
- *value;
-
- ssize_t
- depth;
+ }
+ p++; /* advance beyond the percent */
- /*
- Image value.
- */
- if (strchr(p,']') == (char *) NULL)
- break;
- depth=1;
- p++;
- for (i=0; (i < (MaxTextExtent-1L)) && (*p != '\0'); i++)
- {
- if (*p == '[')
- depth++;
- if (*p == ']')
- depth--;
- if (depth <= 0)
- break;
- pattern[i]=(*p++);
- }
- pattern[i]='\0';
- value=GetImageProperty(image,pattern,exception);
- if (value != (const char *) NULL)
- {
- length=strlen(value);
- if ((size_t) (q-interpret_text+length+1) >= extent)
- {
- extent+=length;
- interpret_text=(char *) ResizeQuantumMemory(interpret_text,
- extent+MaxTextExtent,sizeof(*interpret_text));
- if (interpret_text == (char *) NULL)
- break;
- q=interpret_text+strlen(interpret_text);
- }
- (void) CopyMagickString(q,value,extent);
- q+=length;
- break;
- }
- else
- if (IsGlob(pattern) != MagickFalse)
- {
- /*
- Iterate over image properties.
- */
- ResetImagePropertyIterator(image);
- key=GetNextImageProperty(image);
- while (key != (const char *) NULL)
- {
- if (GlobExpression(key,pattern,MagickTrue) != MagickFalse)
- {
- value=GetImageProperty(image,key,exception);
- if (value != (const char *) NULL)
- {
- length=strlen(key)+strlen(value)+2;
- if ((size_t) (q-interpret_text+length+1) >= extent)
- {
- extent+=length;
- interpret_text=(char *) ResizeQuantumMemory(
- interpret_text,extent+MaxTextExtent,
- sizeof(*interpret_text));
- if (interpret_text == (char *) NULL)
- break;
- q=interpret_text+strlen(interpret_text);
- }
- q+=FormatLocaleString(q,extent,"%s=%s\n",key,value);
- }
- }
- key=GetNextImageProperty(image);
- }
- }
- value=GetMagickProperty(image_info,image,pattern,exception);
- if (value != (const char *) NULL)
- {
- length=strlen(value);
- if ((size_t) (q-interpret_text+length+1) >= extent)
- {
- extent+=length;
- interpret_text=(char *) ResizeQuantumMemory(interpret_text,
- extent+MaxTextExtent,sizeof(*interpret_text));
- if (interpret_text == (char *) NULL)
- break;
- q=interpret_text+strlen(interpret_text);
- }
- (void) CopyMagickString(q,value,extent);
- q+=length;
- break;
- }
- if (image_info == (ImageInfo *) NULL)
- break;
- value=GetImageOption(image_info,pattern);
- if (value != (char *) NULL)
- {
- length=strlen(value);
- if ((size_t) (q-interpret_text+length+1) >= extent)
- {
- extent+=length;
- interpret_text=(char *) ResizeQuantumMemory(interpret_text,
- extent+MaxTextExtent,sizeof(*interpret_text));
- if (interpret_text == (char *) NULL)
- break;
- q=interpret_text+strlen(interpret_text);
- }
- (void) CopyMagickString(q,value,extent);
- q+=length;
- break;
- }
- break;
- }
- case 'b': /* image size as read in */
- {
- char
- format[MaxTextExtent];
-
- (void) FormatLocaleString(format,MaxTextExtent,"%.20g",(double)
- ((MagickOffsetType) image->extent));
- if (image->extent != (MagickSizeType) ((size_t) image->extent))
- (void) FormatMagickSize(image->extent,MagickFalse,format);
- q+=ConcatenateMagickString(q,format,extent);
- q+=ConcatenateMagickString(q,"B",extent);
- break;
- }
- case 'c': /* image comment properity */
- {
- value=GetImageProperty(image,"comment",exception);
- if (value == (const char *) NULL)
- break;
- length=strlen(value);
- if ((size_t) (q-interpret_text+length+1) >= extent)
- {
- extent+=length;
- interpret_text=(char *) ResizeQuantumMemory(interpret_text,extent+
- MaxTextExtent,sizeof(*interpret_text));
- if (interpret_text == (char *) NULL)
- break;
- q=interpret_text+strlen(interpret_text);
- }
- (void) CopyMagickString(q,value,extent);
- q+=length;
- break;
- }
- case 'd': /* Directory component of filename */
- {
- GetPathComponent(image->magick_filename,HeadPath,filename);
- q+=CopyMagickString(q,filename,extent);
- break;
- }
- case 'e': /* Filename extension (suffix) of image file */
- {
- GetPathComponent(image->magick_filename,ExtensionPath,filename);
- q+=CopyMagickString(q,filename,extent);
- break;
- }
- case 'f': /* Filename without directory component */
- {
- GetPathComponent(image->magick_filename,TailPath,filename);
- q+=CopyMagickString(q,filename,extent);
- break;
- }
- case 't': /* Base filename without directory or extention */
- {
- GetPathComponent(image->magick_filename,BasePath,filename);
- q+=CopyMagickString(q,filename,extent);
- break;
- }
- case 'g': /* Image geometry, canvas and offset */
- {
- q+=FormatLocaleString(q,extent,"%.20gx%.20g%+.20g%+.20g",(double)
- image->page.width,(double) image->page.height,(double) image->page.x,
- (double) image->page.y);
- break;
- }
- case 'h': /* Image height */
- {
- q+=FormatLocaleString(q,extent,"%.20g",(double) (image->rows != 0 ?
- image->rows : image->magick_rows));
- break;
- }
- case 'i': /* Images filename - (output filename with "info:" ) */
- {
- q+=CopyMagickString(q,image->filename,extent);
- break;
- }
- case 'k': /* Number of unique colors */
- {
- q+=FormatLocaleString(q,extent,"%.20g",(double) GetNumberColors(image,
- (FILE *) NULL,exception));
- break;
- }
- case 'l': /* Image label */
- {
- value=GetImageProperty(image,"label",exception);
- if (value == (const char *) NULL)
- break;
- length=strlen(value);
- if ((size_t) (q-interpret_text+length+1) >= extent)
- {
- extent+=length;
- interpret_text=(char *) ResizeQuantumMemory(interpret_text,extent+
- MaxTextExtent,sizeof(*interpret_text));
- if (interpret_text == (char *) NULL)
- break;
- q=interpret_text+strlen(interpret_text);
- }
- q+=CopyMagickString(q,value,extent);
- break;
- }
- case 'm': /* Image format (file magick) */
- {
- q+=CopyMagickString(q,image->magick,extent);
- break;
- }
- case 'M': /* Magick filename - exactly as given incl. read mods */
- {
- q+=CopyMagickString(q,image->magick_filename,extent);
- break;
- }
- case 'n': /* Number of images in the list. */
- {
- q+=FormatLocaleString(q,extent,"%.20g",(double)
- GetImageListLength(image));
- break;
- }
- case 'o': /* Image output filename */
- {
- q+=CopyMagickString(q,image_info->filename,extent);
- break;
- }
- case 'p': /* Image index in current image list */
- {
- q+=FormatLocaleString(q,extent,"%.20g",(double)
- GetImageIndexInList(image));
- break;
- }
- case 'q': /* Quantum depth of image in memory */
- {
- q+=FormatLocaleString(q,extent,"%.20g",(double)
- MAGICKCORE_QUANTUM_DEPTH);
- break;
- }
- case 'r': /* Image storage class and colorspace. */
- {
- ColorspaceType
- colorspace;
-
- colorspace=image->colorspace;
- if (IsImageGray(image,exception) != MagickFalse)
- colorspace=GRAYColorspace;
- q+=FormatLocaleString(q,extent,"%s%s%s",CommandOptionToMnemonic(
- MagickClassOptions,(ssize_t) image->storage_class),
- CommandOptionToMnemonic(MagickColorspaceOptions,(ssize_t) colorspace),
- image->matte != MagickFalse ? "Matte" : "");
- break;
- }
- case 's': /* Image scene number */
- {
- if (image_info->number_scenes == 0)
- q+=FormatLocaleString(q,extent,"%.20g",(double) image->scene);
- else
- q+=FormatLocaleString(q,extent,"%.20g",(double) image_info->scene);
- break;
- }
- case 'u': /* Unique filename */
- {
- (void) CopyMagickString(filename,image_info->unique,extent);
- q+=CopyMagickString(q,filename,extent);
- break;
- }
- case 'w': /* Image width */
- {
- q+=FormatLocaleString(q,extent,"%.20g",(double) (image->columns != 0 ?
- image->columns : image->magick_columns));
- break;
- }
- case 'x': /* Image horizontal resolution (density). */
- {
- q+=FormatLocaleString(q,extent,"%g %s",image->resolution.x,
- CommandOptionToMnemonic(MagickResolutionOptions,(ssize_t)
- image->units));
- break;
- }
- case 'y': /* Image vertical resolution (density) */
- {
- q+=FormatLocaleString(q,extent,"%g %s",image->resolution.y,
- CommandOptionToMnemonic(MagickResolutionOptions,(ssize_t)
- image->units));
- break;
- }
- case 'z': /* Image depth as read in */
- {
- q+=FormatLocaleString(q,extent,"%.20g",(double) image->depth);
- break;
- }
- case 'A': /* Image alpha channel */
- {
- q+=FormatLocaleString(q,extent,"%s",CommandOptionToMnemonic(
- MagickBooleanOptions,(ssize_t) image->matte));
- break;
- }
- case 'C': /* Image compression method. */
- {
- q+=FormatLocaleString(q,extent,"%s",CommandOptionToMnemonic(
- MagickCompressOptions,(ssize_t) image->compression));
- break;
- }
- case 'D': /* Image dispose method. */
- {
- q+=FormatLocaleString(q,extent,"%s",CommandOptionToMnemonic(
- MagickDisposeOptions,(ssize_t) image->dispose));
- break;
- }
- case 'G': /* Image size as geometry = "%wx%h" */
- {
- q+=FormatLocaleString(q,extent,"%.20gx%.20g",(double)
- image->magick_columns,(double) image->magick_rows);
- break;
- }
- case 'H': /* layer canvas height */
- {
- q+=FormatLocaleString(q,extent,"%.20g",(double) image->page.height);
- break;
- }
- case 'O': /* layer canvas offset with sign = "+%X+%Y" */
- {
- q+=FormatLocaleString(q,extent,"%+ld%+ld",(long) image->page.x,(long)
- image->page.y);
- break;
- }
- case 'P': /* layer canvas page size = "%Wx%H" */
- {
- q+=FormatLocaleString(q,extent,"%.20gx%.20g",(double) image->page.width,
- (double) image->page.height);
- break;
- }
- case 'Q': /* image compression quality */
- {
- q+=FormatLocaleString(q,extent,"%.20g",(double) image->quality);
- break;
- }
- case 'S': /* Image scenes */
- {
- if (image_info->number_scenes == 0)
- q+=CopyMagickString(q,"2147483647",extent);
- else
- q+=FormatLocaleString(q,extent,"%.20g",(double) (image_info->scene+
- image_info->number_scenes));
- break;
- }
- case 'T': /* image time delay for animations */
- {
- q+=FormatLocaleString(q,extent,"%.20g",(double) image->delay);
- break;
+ /*
+ Doubled Percent - or percent at end of string
+ */
+ if ( *p == '\0' )
+ p--;
+ if ( *p == '%' ) {
+ *q++='%';
+ continue;
}
- case 'W': /* layer canvas width */
- {
- q+=FormatLocaleString(q,extent,"%.20g",(double) image->page.width);
- break;
+
+ /*
+ Single letter escapes %c
+ */
+ if ( *p != '[' ) {
+ const char
+ *string;
+
+ /* But only if not preceeded by a number! */
+ if ( IfMagickTrue(number) ) {
+ *q++='%'; /* do NOT substitute the percent */
+ p--; /* back up one */
+ continue;
}
- case 'X': /* layer canvas X offset */
- {
- q+=FormatLocaleString(q,extent,"%+.20g",(double) image->page.x);
+ string=GetMagickPropertyLetter(image_info,image,*p, exception);
+ if (string != (char *) NULL)
+ {
+ AppendString2Text(string);
+ if (image != (Image *) NULL)
+ (void)DeleteImageArtifact(image,"get-property");
+ if (image_info != (ImageInfo *) NULL)
+ (void)DeleteImageOption(image_info,"get-property");
+ continue;
+ }
+ (void) ThrowMagickException(exception,GetMagickModule(),OptionWarning,
+ "UnknownImageProperty","\"%%%c\"",*p);
+ continue;
+ }
+
+ /*
+ Braced Percent Escape %[...]
+ */
+ {
+ char
+ pattern[MaxTextExtent];
+
+ const char
+ *key,
+ *string;
+
+ register ssize_t
+ len;
+
+ ssize_t
+ depth;
+
+ /* get the property name framed by the %[...] */
+ p++; /* advance p to just inside the opening brace */
+ depth=1;
+ if ( *p == ']' ) {
+ (void) ThrowMagickException(exception,GetMagickModule(),
+ OptionWarning,"UnknownImageProperty","\"%%[]\"");
break;
}
- case 'Y': /* layer canvas Y offset */
+ for (len=0; len<(MaxTextExtent-1L) && (*p != '\0');)
{
- q+=FormatLocaleString(q,extent,"%+.20g",(double) image->page.y);
- break;
+ /* skip escaped braces within braced pattern */
+ if ( (*p == '\\') && (*(p+1) != '\0') ) {
+ pattern[len++]=(*p++);
+ pattern[len++]=(*p++);
+ continue;
+ }
+ if (*p == '[')
+ depth++;
+ if (*p == ']')
+ depth--;
+ if (depth <= 0)
+ break;
+ pattern[len++]=(*p++);
}
- case 'Z': /* Unique filename. */
- {
- (void) CopyMagickString(filename,image_info->zero,extent);
- q+=CopyMagickString(q,filename,extent);
- break;
+ pattern[len]='\0';
+ /* Check for unmatched final ']' for "%[...]" */
+ if ( depth != 0 ) {
+ if (len >= 64) { /* truncate string for error message */
+ pattern[61] = '.';
+ pattern[62] = '.';
+ pattern[63] = '.';
+ pattern[64] = '\0';
+ }
+ (void) ThrowMagickException(exception,GetMagickModule(),
+ OptionError,"UnbalancedBraces","\"%%[%s\"",pattern);
+ interpret_text=DestroyString(interpret_text);
+ return((char *)NULL);
}
- case '@': /* Image bounding box. */
- {
- RectangleInfo
- page;
- page=GetImageBoundingBox(image,exception);
- q+=FormatLocaleString(q,MaxTextExtent,"%.20gx%.20g%+.20g%+.20g",
- (double) page.width,(double) page.height,(double) page.x,(double)
- page.y);
- break;
- }
- case '#': /* Image signature */
+ /*
+ Special Lookup Prefixes %[prefix:...]
+ */
+ /* fx - value calculator */
+ if (LocaleNCompare("fx:",pattern,3) == 0)
+ {
+ FxInfo
+ *fx_info;
+
+ double
+ value;
+
+ MagickBooleanType
+ status;
+
+ if (image == (Image *) NULL ) {
+ (void) ThrowMagickException(exception,GetMagickModule(),
+ OptionWarning,"NoImageForProperty","\"%%[%s]\"",pattern);
+ continue; /* else no image to retrieve artifact */
+ }
+ fx_info=AcquireFxInfo(image,pattern+3,exception);
+ status=FxEvaluateChannelExpression(fx_info,IntensityPixelChannel,0,0,
+ &value,exception);
+ fx_info=DestroyFxInfo(fx_info);
+ if( IfMagickTrue(status) )
+ {
+ char
+ result[MaxTextExtent];
+
+ (void) FormatLocaleString(result,MaxTextExtent,"%.*g",
+ GetMagickPrecision(),(double) value);
+ AppendString2Text(result);
+ }
+ continue;
+ }
+ /* pixel - color value calculator */
+ if (LocaleNCompare("pixel:",pattern,6) == 0)
+ {
+ FxInfo
+ *fx_info;
+
+ double
+ value;
+
+ MagickStatusType
+ status;
+
+ PixelInfo
+ pixel;
+
+ if (image == (Image *) NULL ) {
+ (void) ThrowMagickException(exception,GetMagickModule(),
+ OptionWarning,"NoImageForProperty","\"%%[%s]\"",pattern);
+ continue; /* else no image to retrieve artifact */
+ }
+ GetPixelInfo(image,&pixel);
+ fx_info=AcquireFxInfo(image,pattern+6,exception);
+ status=FxEvaluateChannelExpression(fx_info,RedPixelChannel,0,0,
+ &value,exception);
+ pixel.red=(double) QuantumRange*value;
+ status&=FxEvaluateChannelExpression(fx_info,GreenPixelChannel,0,0,
+ &value,exception);
+ pixel.green=(double) QuantumRange*value;
+ status&=FxEvaluateChannelExpression(fx_info,BluePixelChannel,0,0,
+ &value,exception);
+ pixel.blue=(double) QuantumRange*value;
+ if (image->colorspace == CMYKColorspace)
+ {
+ status&=FxEvaluateChannelExpression(fx_info,BlackPixelChannel,0,0,
+ &value,exception);
+ pixel.black=(double) QuantumRange*value;
+ }
+ status&=FxEvaluateChannelExpression(fx_info,AlphaPixelChannel,0,0,
+ &value,exception);
+ pixel.alpha=(double) QuantumRange*value;
+ fx_info=DestroyFxInfo(fx_info);
+ if( IfMagickTrue(status) )
+ {
+ char
+ name[MaxTextExtent];
+
+ (void) QueryColorname(image,&pixel,SVGCompliance,name,
+ exception);
+ AppendString2Text(name);
+ }
+ continue;
+ }
+ /* option - direct global option lookup (with globbing) */
+ if (LocaleNCompare("option:",pattern,7) == 0)
{
- (void) SignatureImage(image,exception);
- value=GetImageProperty(image,"signature",exception);
- if (value == (const char *) NULL)
- break;
- q+=CopyMagickString(q,value,extent);
- break;
+ if (image_info == (ImageInfo *) NULL ) {
+ (void) ThrowMagickException(exception,GetMagickModule(),
+ OptionWarning,"NoImageForProperty","\"%%[%s]\"",pattern);
+ continue; /* else no image to retrieve artifact */
+ }
+ if( IfMagickTrue(IsGlob(pattern+7)) )
+ {
+ ResetImageOptionIterator(image_info);
+ while ((key=GetNextImageOption(image_info)) != (const char *) NULL)
+ if( IfMagickTrue(GlobExpression(key,pattern+7,MagickTrue)) )
+ {
+ string=GetImageOption(image_info,key);
+ if (string != (const char *) NULL)
+ AppendKeyValue2Text(key,string);
+ /* else - assertion failure? key found but no string value! */
+ }
+ continue;
+ }
+ string=GetImageOption(image_info,pattern+7);
+ if (string == (char *) NULL)
+ goto PropertyLookupFailure; /* no artifact of this specifc name */
+ AppendString2Text(string);
+ continue;
}
- case '%': /* percent escaped */
+ /* artifact - direct image artifact lookup (with glob) */
+ if (LocaleNCompare("artifact:",pattern,9) == 0)
{
- *q++=(*p);
- break;
+ if (image == (Image *) NULL ) {
+ (void) ThrowMagickException(exception,GetMagickModule(),
+ OptionWarning,"NoImageForProperty","\"%%[%s]\"",pattern);
+ continue; /* else no image to retrieve artifact */
+ }
+ if( IfMagickTrue(IsGlob(pattern+9)) )
+ {
+ ResetImageArtifactIterator(image);
+ while ((key=GetNextImageArtifact(image)) != (const char *) NULL)
+ if( IfMagickTrue(GlobExpression(key,pattern+9,MagickTrue)) )
+ {
+ string=GetImageArtifact(image,key);
+ if (string != (const char *) NULL)
+ AppendKeyValue2Text(key,string);
+ /* else - assertion failure? key found but no string value! */
+ }
+ continue;
+ }
+ string=GetImageArtifact(image,pattern+9);
+ if (string == (char *) NULL)
+ goto PropertyLookupFailure; /* no artifact of this specifc name */
+ AppendString2Text(string);
+ continue;
}
- default: /* percent not expanded */
+ /* property - direct image property lookup (with glob) */
+ if (LocaleNCompare("property:",pattern,9) == 0)
{
- *q++='%';
- *q++=(*p);
- break;
+ if (image == (Image *) NULL ) {
+ (void) ThrowMagickException(exception,GetMagickModule(),
+ OptionWarning,"NoImageForProperty","\"%%[%s]\"",pattern);
+ continue; /* else no image to retrieve artifact */
+ }
+ if( IfMagickTrue(IsGlob(pattern+9)) )
+ {
+ ResetImagePropertyIterator(image);
+ while ((key=GetNextImageProperty(image)) != (const char *) NULL)
+ if( IfMagickTrue(GlobExpression(key,pattern,MagickTrue)) )
+ {
+ string=GetImageProperty(image,key,exception);
+ if (string != (const char *) NULL)
+ AppendKeyValue2Text(key,string);
+ /* else - assertion failure? */
+ }
+ continue;
+ }
+ string=GetImageProperty(image,pattern+9,exception);
+ if (string == (char *) NULL)
+ goto PropertyLookupFailure; /* no artifact of this specifc name */
+ AppendString2Text(string);
+ continue;
}
- }
- }
+ /* Properties without special prefix.
+ This handles attributes, properties, and profiles such as %[exif:...]
+ Note the profile properties may also include a glob expansion pattern.
+ */
+ if ( image != (Image *)NULL )
+ {
+ string=GetImageProperty(image,pattern,exception);
+ if (string != (const char *) NULL)
+ {
+ AppendString2Text(string);
+ if (image != (Image *) NULL)
+ (void)DeleteImageArtifact(image,"get-property");
+ if (image_info != (ImageInfo *) NULL)
+ (void)DeleteImageOption(image_info,"get-property");
+ continue;
+ }
+ }
+ /*
+ Handle property 'glob' patterns
+ Such as: %[*] %[user:array_??] %[filename:e*]
+ */
+ if( IfMagickTrue(IsGlob(pattern)) )
+ {
+ if (image == (Image *) NULL)
+ continue; /* else no image to retrieve proprty - no list */
+ ResetImagePropertyIterator(image);
+ while ((key=GetNextImageProperty(image)) != (const char *) NULL)
+ if( IfMagickTrue(GlobExpression(key,pattern,MagickTrue)) )
+ {
+ string=GetImageProperty(image,key,exception);
+ if (string != (const char *) NULL)
+ AppendKeyValue2Text(key,string);
+ /* else - assertion failure? */
+ }
+ continue;
+ }
+ /*
+ Look for a known property or image attribute
+ Such as %[basename] %[denisty] %[delay]
+ Also handles a braced single letter: %[b] %[G] %[g]
+ */
+ string=GetMagickProperty(image_info,image,pattern,exception);
+ if (string != (const char *) NULL)
+ {
+ AppendString2Text(string);
+ continue;
+ }
+ /*
+ Look for a per-image Artifact
+ This includes option lookup (FUTURE: interpreted according to image)
+ */
+ if (image != (Image *)NULL)
+ {
+ string=GetImageArtifact(image,pattern);
+ if (string != (char *) NULL)
+ {
+ AppendString2Text(string);
+ continue;
+ }
+ }
+ else
+ /* no image, so direct 'option' lookup (no delayed percent escapes) */
+ if (image_info != (ImageInfo *) NULL)
+ {
+ string=GetImageOption(image_info,pattern);
+ if (string != (char *) NULL)
+ {
+ AppendString2Text(string);
+ continue;
+ }
+ }
+PropertyLookupFailure:
+ /*
+ Failed to find any match anywhere!
+ */
+ if (len >= 64) { /* truncate string for error message */
+ pattern[61] = '.';
+ pattern[62] = '.';
+ pattern[63] = '.';
+ pattern[64] = '\0';
+ }
+ (void) ThrowMagickException(exception,GetMagickModule(),
+ OptionWarning,"UnknownImageProperty","\"%%[%s]\"",pattern);
+ /* continue */
+ } /* Braced Percent Escape */
+
+ } /* for each char in 'embed_text' */
*q='\0';
- if (text != (const char *) embed_text)
- text=DestroyString(text);
- (void) SubstituteString(&interpret_text,"<","<");
- (void) SubstituteString(&interpret_text,">",">");
return(interpret_text);
}
\f
% RemoveImageProperty() removes a property from the image and returns its
% value.
%
+% In this case the ConstantString() value returned should be freed by the
+% caller when finished.
+%
% The format of the RemoveImageProperty method is:
%
% char *RemoveImageProperty(Image *image,const char *property)
assert(image != (Image *) NULL);
assert(image->signature == MagickSignature);
- if (image->debug != MagickFalse)
+ if( IfMagickTrue(image->debug) )
(void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
image->filename);
if (image->properties == (void *) NULL)
{
assert(image != (Image *) NULL);
assert(image->signature == MagickSignature);
- if (image->debug != MagickFalse)
+ if( IfMagickTrue(image->debug) )
(void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
image->filename);
if (image->properties == (void *) NULL)
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
-% SetImageProperty() associates an value with an image property.
+% SetImageProperty() saves the given string value either to specific known
+% attribute or to a freeform property string.
+%
+% Attempting to set a property that is normally calculated will produce
+% an exception.
%
% The format of the SetImageProperty method is:
%
assert(image != (Image *) NULL);
assert(image->signature == MagickSignature);
- if (image->debug != MagickFalse)
- (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
- image->filename);
+ if( IfMagickTrue(image->debug) )
+ (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
if (image->properties == (void *) NULL)
image->properties=NewSplayTree(CompareSplayTreeString,
- RelinquishMagickMemory,RelinquishMagickMemory);
- if ((value == (const char *) NULL) || (*value == '\0'))
- return(DeleteImageProperty(image,property));
+ RelinquishMagickMemory,RelinquishMagickMemory); /* create splay-tree */
+ if (value == (const char *) NULL)
+ return(DeleteImageProperty(image,property)); /* delete if NULL */
status=MagickTrue;
+ if (strlen(property) <= 1)
+ {
+ /*
+ Do not 'set' single letter properties - read only shorthand.
+ */
+ (void) ThrowMagickException(exception,GetMagickModule(),OptionError,
+ "SetReadOnlyProperty","`%s'",property);
+ return(MagickFalse);
+ }
+
+ /* FUTURE: binary chars or quotes in key should produce a error */
+ /* Set attributes with known names or special prefixes
+ return result is found, or break to set a free form properity
+ */
switch (*property)
{
+#if 0 /* Percent escape's sets values with this prefix: for later use
+ Throwing an exception causes this setting to fail */
+ case '8':
+ {
+ if (LocaleNCompare("8bim:",property,5) == 0)
+ {
+ (void) ThrowMagickException(exception,GetMagickModule(),
+ OptionError,"SetReadOnlyProperty","`%s'",property);
+ return(MagickFalse);
+ }
+ break;
+ }
+#endif
case 'B':
case 'b':
{
- if (LocaleCompare(property,"background") == 0)
+ if (LocaleCompare("background",property) == 0)
{
(void) QueryColorCompliance(value,AllCompliance,
- &image->background_color,exception);
- break;
+ &image->background_color,exception);
+ /* check for FUTURE: value exception?? */
+ /* also add user input to splay tree */
}
- if (LocaleCompare(property,"bias") == 0)
- {
- image->bias=StringToDoubleInterval(value,(double) QuantumRange+1.0);
- break;
- }
- status=AddValueToSplayTree((SplayTreeInfo *) image->properties,
- ConstantString(property),ConstantString(value));
- break;
+ break; /* not an attribute, add as a property */
}
case 'C':
case 'c':
{
- if (LocaleCompare(property,"colorspace") == 0)
+ if (LocaleCompare("channels",property) == 0)
+ {
+ (void) ThrowMagickException(exception,GetMagickModule(),OptionError,
+ "SetReadOnlyProperty","`%s'",property);
+ return(MagickFalse);
+ }
+ if (LocaleCompare("colorspace",property) == 0)
{
ssize_t
colorspace;
colorspace=ParseCommandOption(MagickColorspaceOptions,MagickFalse,
value);
if (colorspace < 0)
- break;
- (void) SetImageColorspace(image,(ColorspaceType) colorspace,
- exception);
- break;
+ return(MagickFalse); /* FUTURE: value exception?? */
+ return(SetImageColorspace(image,(ColorspaceType) colorspace,exception));
}
- if (LocaleCompare(property,"compose") == 0)
+ if (LocaleCompare("compose",property) == 0)
{
ssize_t
compose;
compose=ParseCommandOption(MagickComposeOptions,MagickFalse,value);
if (compose < 0)
- break;
+ return(MagickFalse); /* FUTURE: value exception?? */
image->compose=(CompositeOperator) compose;
- break;
+ return(MagickTrue);
}
- if (LocaleCompare(property,"compress") == 0)
+ if (LocaleCompare("compress",property) == 0)
{
ssize_t
compression;
compression=ParseCommandOption(MagickCompressOptions,MagickFalse,
value);
if (compression < 0)
- break;
+ return(MagickFalse); /* FUTURE: value exception?? */
image->compression=(CompressionType) compression;
- break;
+ return(MagickTrue);
}
- status=AddValueToSplayTree((SplayTreeInfo *) image->properties,
- ConstantString(property),ConstantString(value));
- break;
+ if (LocaleCompare("copyright",property) == 0)
+ {
+ (void) ThrowMagickException(exception,GetMagickModule(),
+ OptionError,"SetReadOnlyProperty","`%s'",property);
+ return(MagickFalse);
+ }
+ break; /* not an attribute, add as a property */
}
case 'D':
case 'd':
{
- if (LocaleCompare(property,"delay") == 0)
+ if (LocaleCompare("delay",property) == 0)
{
GeometryInfo
geometry_info;
if ((flags & LessValue) != 0)
{
if (image->delay < (size_t) floor(geometry_info.rho+0.5))
- image->ticks_per_second=(ssize_t)
+ image->delay=(ssize_t)
floor(geometry_info.sigma+0.5);
}
else
image->delay=(size_t) floor(geometry_info.rho+0.5);
if ((flags & SigmaValue) != 0)
image->ticks_per_second=(ssize_t) floor(geometry_info.sigma+0.5);
- break;
+ return(MagickTrue);
}
- if (LocaleCompare(property,"density") == 0)
+ if (LocaleCompare("delay_units",property) == 0)
+ {
+ (void) ThrowMagickException(exception,GetMagickModule(),
+ OptionError,"SetReadOnlyProperty","`%s'",property);
+ return(MagickFalse);
+ }
+ if (LocaleCompare("density",property) == 0)
{
GeometryInfo
geometry_info;
image->resolution.y=geometry_info.sigma;
if ((flags & SigmaValue) == 0)
image->resolution.y=image->resolution.x;
+ return(MagickTrue);
}
- if (LocaleCompare(property,"depth") == 0)
+ if (LocaleCompare("depth",property) == 0)
{
image->depth=StringToUnsignedLong(value);
- break;
+ return(MagickTrue);
}
- if (LocaleCompare(property,"dispose") == 0)
+ if (LocaleCompare("dispose",property) == 0)
{
ssize_t
dispose;
dispose=ParseCommandOption(MagickDisposeOptions,MagickFalse,value);
if (dispose < 0)
- break;
+ return(MagickFalse); /* FUTURE: value exception?? */
image->dispose=(DisposeType) dispose;
- break;
+ return(MagickTrue);
}
- status=AddValueToSplayTree((SplayTreeInfo *) image->properties,
- ConstantString(property),ConstantString(value));
- break;
+ break; /* not an attribute, add as a property */
+ }
+#if 0 /* Percent escape's sets values with this prefix: for later use
+ Throwing an exception causes this setting to fail */
+ case 'E':
+ case 'e':
+ {
+ if (LocaleNCompare("exif:",property,5) == 0)
+ {
+ (void) ThrowMagickException(exception,GetMagickModule(),
+ OptionError,"SetReadOnlyProperty","`%s'",property);
+ return(MagickFalse);
+ }
+ break; /* not an attribute, add as a property */
+ }
+ case 'F':
+ case 'f':
+ {
+ if (LocaleNCompare("fx:",property,3) == 0)
+ {
+ (void) ThrowMagickException(exception,GetMagickModule(),
+ OptionError,"SetReadOnlyProperty","`%s'",property);
+ return(MagickFalse);
+ }
+ break; /* not an attribute, add as a property */
}
+#endif
case 'G':
case 'g':
{
- if (LocaleCompare(property,"gravity") == 0)
+ if (LocaleCompare("gamma",property) == 0)
+ {
+ image->gamma=StringToDouble(value,(char **) NULL);
+ return(MagickTrue);
+ }
+ if (LocaleCompare("gravity",property) == 0)
{
ssize_t
gravity;
gravity=ParseCommandOption(MagickGravityOptions,MagickFalse,value);
if (gravity < 0)
- break;
+ return(MagickFalse); /* FUTURE: value exception?? */
image->gravity=(GravityType) gravity;
- break;
+ return(MagickTrue);
}
- status=AddValueToSplayTree((SplayTreeInfo *) image->properties,
- ConstantString(property),ConstantString(value));
- break;
+ break; /* not an attribute, add as a property */
+ }
+ case 'H':
+ case 'h':
+ {
+ if (LocaleCompare("height",property) == 0)
+ {
+ (void) ThrowMagickException(exception,GetMagickModule(),
+ OptionError,"SetReadOnlyProperty","`%s'",property);
+ return(MagickFalse);
+ }
+ break; /* not an attribute, add as a property */
}
case 'I':
case 'i':
{
- if (LocaleCompare(property,"intent") == 0)
+ if (LocaleCompare("intensity",property) == 0)
+ {
+ ssize_t
+ intensity;
+
+ intensity=ParseCommandOption(MagickIntentOptions,MagickFalse,
+ value);
+ if (intensity < 0)
+ return(MagickFalse);
+ image->intensity=(PixelIntensityMethod) intensity;
+ return(MagickTrue);
+ }
+ if (LocaleCompare("intent",property) == 0)
{
ssize_t
rendering_intent;
rendering_intent=ParseCommandOption(MagickIntentOptions,MagickFalse,
value);
if (rendering_intent < 0)
- break;
+ return(MagickFalse); /* FUTURE: value exception?? */
image->rendering_intent=(RenderingIntent) rendering_intent;
- break;
+ return(MagickTrue);
}
- if (LocaleCompare(property,"interpolate") == 0)
+ if (LocaleCompare("interpolate",property) == 0)
{
ssize_t
interpolate;
interpolate=ParseCommandOption(MagickInterpolateOptions,MagickFalse,
value);
if (interpolate < 0)
- break;
+ return(MagickFalse); /* FUTURE: value exception?? */
image->interpolate=(PixelInterpolateMethod) interpolate;
- break;
+ return(MagickTrue);
}
- status=AddValueToSplayTree((SplayTreeInfo *) image->properties,
- ConstantString(property),ConstantString(value));
- break;
+#if 0 /* Percent escape's sets values with this prefix: for later use
+ Throwing an exception causes this setting to fail */
+ if (LocaleNCompare("iptc:",property,5) == 0)
+ {
+ (void) ThrowMagickException(exception,GetMagickModule(),
+ OptionError,"SetReadOnlyProperty","`%s'",property);
+ return(MagickFalse);
+ }
+#endif
+ break; /* not an attribute, add as a property */
}
+ case 'K':
+ case 'k':
+ if (LocaleCompare("kurtosis",property) == 0)
+ {
+ (void) ThrowMagickException(exception,GetMagickModule(),
+ OptionError,"SetReadOnlyProperty","`%s'",property);
+ return(MagickFalse);
+ }
+ break; /* not an attribute, add as a property */
case 'L':
case 'l':
{
- if (LocaleCompare(property,"loop") == 0)
+ if (LocaleCompare("loop",property) == 0)
{
image->iterations=StringToUnsignedLong(value);
- break;
+ return(MagickTrue);
}
- status=AddValueToSplayTree((SplayTreeInfo *) image->properties,
- ConstantString(property),ConstantString(value));
- break;
+ break; /* not an attribute, add as a property */
}
+ case 'M':
+ case 'm':
+ if ( (LocaleCompare("magick",property) == 0) ||
+ (LocaleCompare("max",property) == 0) ||
+ (LocaleCompare("mean",property) == 0) ||
+ (LocaleCompare("min",property) == 0) ||
+ (LocaleCompare("min",property) == 0) )
+ {
+ (void) ThrowMagickException(exception,GetMagickModule(),OptionError,
+ "SetReadOnlyProperty","`%s'",property);
+ return(MagickFalse);
+ }
+ break; /* not an attribute, add as a property */
+ case 'O':
+ case 'o':
+ if (LocaleCompare("opaque",property) == 0)
+ {
+ (void) ThrowMagickException(exception,GetMagickModule(),
+ OptionError,"SetReadOnlyProperty","`%s'",property);
+ return(MagickFalse);
+ }
+ break; /* not an attribute, add as a property */
case 'P':
case 'p':
{
- if (LocaleCompare(property,"page") == 0)
+ if (LocaleCompare("page",property) == 0)
{
char
*geometry;
geometry=GetPageGeometry(value);
flags=ParseAbsoluteGeometry(geometry,&image->page);
geometry=DestroyString(geometry);
- break;
+ return(MagickTrue);
+ }
+#if 0 /* Percent escape's sets values with this prefix: for later use
+ Throwing an exception causes this setting to fail */
+ if (LocaleNCompare("pixel:",property,6) == 0)
+ {
+ (void) ThrowMagickException(exception,GetMagickModule(),
+ OptionError,"SetReadOnlyProperty","`%s'",property);
+ return(MagickFalse);
}
- if (LocaleCompare(property,"profile") == 0)
+#endif
+ if (LocaleCompare("profile",property) == 0)
{
ImageInfo
*image_info;
if (profile != (StringInfo *) NULL)
status=SetImageProfile(image,image_info->magick,profile,exception);
image_info=DestroyImageInfo(image_info);
- break;
+ return(MagickTrue);
}
- status=AddValueToSplayTree((SplayTreeInfo *) image->properties,
- ConstantString(property),ConstantString(value));
- break;
+ break; /* not an attribute, add as a property */
}
case 'R':
case 'r':
{
- if (LocaleCompare(property,"rendering-intent") == 0)
+ if (LocaleCompare("rendering-intent",property) == 0)
{
ssize_t
rendering_intent;
rendering_intent=ParseCommandOption(MagickIntentOptions,MagickFalse,
value);
if (rendering_intent < 0)
- break;
+ return(MagickFalse); /* FUTURE: value exception?? */
image->rendering_intent=(RenderingIntent) rendering_intent;
- break;
+ return(MagickTrue);
}
- status=AddValueToSplayTree((SplayTreeInfo *) image->properties,
- ConstantString(property),ConstantString(value));
- break;
+ break; /* not an attribute, add as a property */
}
+ case 'S':
+ case 's':
+ if ( (LocaleCompare("size",property) == 0) ||
+ (LocaleCompare("skewness",property) == 0) ||
+ (LocaleCompare("scenes",property) == 0) ||
+ (LocaleCompare("standard-deviation",property) == 0) )
+ {
+ (void) ThrowMagickException(exception,GetMagickModule(),
+ OptionError,"SetReadOnlyProperty","`%s'",property);
+ return(MagickFalse);
+ }
+ break; /* not an attribute, add as a property */
case 'T':
case 't':
{
- if (LocaleCompare(property,"tile-offset") == 0)
+ if (LocaleCompare("tile-offset",property) == 0)
{
char
*geometry;
geometry=GetPageGeometry(value);
flags=ParseAbsoluteGeometry(geometry,&image->tile_offset);
geometry=DestroyString(geometry);
- break;
+ return(MagickTrue);
}
- status=AddValueToSplayTree((SplayTreeInfo *) image->properties,
- ConstantString(property),ConstantString(value));
- break;
+ break; /* not an attribute, add as a property */
}
case 'U':
case 'u':
{
- if (LocaleCompare(property,"units") == 0)
+ if (LocaleCompare("units",property) == 0)
{
ssize_t
units;
units=ParseCommandOption(MagickResolutionOptions,MagickFalse,value);
if (units < 0)
- break;
+ return(MagickFalse); /* FUTURE: value exception?? */
image->units=(ResolutionType) units;
- break;
+ return(MagickTrue);
}
- status=AddValueToSplayTree((SplayTreeInfo *) image->properties,
- ConstantString(property),ConstantString(value));
- break;
+ break; /* not an attribute, add as a property */
}
- default:
+ case 'V':
+ case 'v':
{
- status=AddValueToSplayTree((SplayTreeInfo *) image->properties,
- ConstantString(property),ConstantString(value));
- break;
+ if (LocaleCompare("version",property) == 0)
+ {
+ (void) ThrowMagickException(exception,GetMagickModule(),
+ OptionError,"SetReadOnlyProperty","`%s'",property);
+ return(MagickFalse);
+ }
+ break; /* not an attribute, add as a property */
+ }
+ case 'W':
+ case 'w':
+ {
+ if (LocaleCompare("width",property) == 0)
+ {
+ (void) ThrowMagickException(exception,GetMagickModule(),
+ OptionError,"SetReadOnlyProperty","`%s'",property);
+ return(MagickFalse);
+ }
+ break; /* not an attribute, add as a property */
+ }
+#if 0 /* Percent escape's sets values with this prefix: for later use
+ Throwing an exception causes this setting to fail */
+ case 'X':
+ case 'x':
+ {
+ if (LocaleNCompare("xmp:",property,4) == 0)
+ {
+ (void) ThrowMagickException(exception,GetMagickModule(),
+ OptionError,"SetReadOnlyProperty","`%s'",property);
+ return(MagickFalse);
+ }
+ break; /* not an attribute, add as a property */
}
+#endif
}
+ /* Default: not an attribute, add as a property */
+ status=AddValueToSplayTree((SplayTreeInfo *) image->properties,
+ ConstantString(property),ConstantString(value));
+ /* FUTURE: error if status is bad? */
return(status);
}