% January 2003 %
% %
% %
-% Copyright 1999-2011 ImageMagick Studio LLC, a non-profit organization %
+% Copyright 1999-2012 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 %
% whether the x or y values are negative. In addition, there are flags to
% report any meta characters (%, !, <, or >).
%
+% The value must form a proper geometry style specification of WxH+X+Y
+% of integers only, and values can not be separated by comma, colon, or
+% slash charcaters. See ParseGeometry() below.
+%
+% Offsets may be prefixed by multiple signs to make offset string
+% substitutions easier to handle from shell scripts.
+% For example: "-10-10", "-+10-+10", or "+-10+-10" will generate negtive
+% offsets, while "+10+10", "++10++10", or "--10--10" will generate positive
+% offsets.
+%
% The format of the GetGeometry method is:
%
% MagickStatusType GetGeometry(const char *geometry,ssize_t *x,ssize_t *y,
(void) CopyMagickString(p,p+1,MaxTextExtent);
continue;
}
- c=(int) ((unsigned int) *p);
+ c=(int)*p;
switch (c)
{
case '%':
(void) CopyMagickString(p,p+1,MaxTextExtent);
break;
}
+ case 'x':
+ case 'X':
+ {
+ flags|=SeparatorValue;
+ p++;
+ break;
+ }
case '-':
case '.':
case ',':
case '7':
case '8':
case '9':
- case 'x':
- case 'X':
case 215:
{
p++;
if (*p == '\0')
return(flags);
q=p;
- value=InterpretLocaleValue(p,&q);
+ value=StringToDouble(p,&q);
(void) value;
if (LocaleNCompare(p,"0x",2) == 0)
value=(double) strtol(p,&q,10);
- c=(int) ((unsigned char) *q);
- if ((c == 215) || (*q == 'x') || (*q == 'X') || (*q == '\0'))
+ if ((*p != '+') && (*p != '-'))
{
- /*
- Parse width.
- */
- q=p;
- if (LocaleNCompare(p,"0x",2) == 0)
- *width=(size_t) strtol(p,&p,10);
- else
- *width=(size_t) floor(InterpretLocaleValue(p,&p)+0.5);
- if (p != q)
- flags|=WidthValue;
- }
- c=(*p);
- c=(int) ((unsigned char) *p);
- if ((c == 215) || (*p == 'x') || (*p == 'X'))
- {
- p++;
- if ((*p != '+') && (*p != '-'))
+ c=(int) ((unsigned char) *q);
+ if ((c == 215) || (*q == 'x') || (*q == 'X') || (*q == '\0'))
{
/*
- Parse height.
+ Parse width.
*/
q=p;
- *height=(size_t) floor(InterpretLocaleValue(p,&p)+0.5);
+ if (LocaleNCompare(p,"0x",2) == 0)
+ *width=(size_t) strtol(p,&p,10);
+ else
+ *width=(size_t) floor(StringToDouble(p,&p)+0.5);
if (p != q)
- flags|=HeightValue;
+ flags|=WidthValue;
+ }
+ }
+ if ((*p != '+') && (*p != '-'))
+ {
+ c=(int) ((unsigned char) *p);
+ if ((c == 215) || (*p == 'x') || (*p == 'X'))
+ {
+ p++;
+ if ((*p != '+') && (*p != '-'))
+ {
+ /*
+ Parse height.
+ */
+ q=p;
+ *height=(size_t) floor(StringToDouble(p,&p)+0.5);
+ if (p != q)
+ flags|=HeightValue;
+ }
}
}
if ((*p == '+') || (*p == '-'))
/*
Parse x value.
*/
- if (*p == '-')
- flags|=XNegative;
+ while ((*p == '+') || (*p == '-'))
+ {
+ if (*p == '-')
+ flags^=XNegative; /* negate sign */
+ p++;
+ }
q=p;
- *x=(ssize_t) ceil(InterpretLocaleValue(p,&p)-0.5);
+ *x=(ssize_t) ceil(StringToDouble(p,&p)-0.5);
if (p != q)
- flags|=XValue;
- if ((*p == '+') || (*p == '-'))
{
- /*
- Parse y value.
- */
- if (*p == '-')
- flags|=YNegative;
- q=p;
- *y=(ssize_t) ceil(InterpretLocaleValue(p,&p)-0.5);
- if (p != q)
- flags|=YValue;
+ flags|=XValue;
+ if ((flags & XNegative) != 0)
+ *x=(-*x);
+ }
+ }
+ if ((*p == '+') || (*p == '-'))
+ {
+ /*
+ Parse y value.
+ */
+ while ((*p == '+') || (*p == '-'))
+ {
+ if (*p == '-')
+ flags^=YNegative; /* negate sign */
+ p++;
+ }
+ q=p;
+ *y=(ssize_t) ceil(StringToDouble(p,&p)-0.5);
+ if (p != q)
+ {
+ flags|=YValue;
+ if ((flags & YNegative) != 0)
+ *y=(-*y);
+ }
+ }
+ if ((flags & PercentValue) != 0)
+ {
+ if (((flags & SeparatorValue) == 0) && ((flags & HeightValue) == 0))
+ {
+ *height=(*width);
+ flags|=HeightValue;
}
+ if (((flags & SeparatorValue) != 0) && ((flags & WidthValue) == 0))
+ *width=(*height);
}
+#if 0
+ /* Debugging Geometry */
+ (void) fprintf(stderr,"GetGeometry...\n");
+ (void) fprintf(stderr,"Input: %s\n",geometry);
+ (void) fprintf(stderr,"Flags: %c %c %s %s\n",
+ (flags & WidthValue) ? 'W' : ' ',(flags & HeightValue) ? 'H' : ' ',
+ (flags & XValue) ? ((flags & XNegative) ? "-X" : "+X") : " ",
+ (flags & YValue) ? ((flags & YNegative) ? "-Y" : "+Y") : " ");
+ (void) fprintf(stderr,"Geometry: %ldx%ld%+ld%+ld\n",(long) *width,(long)
+ *height,(long) *x,(long) *y);
+#endif
return(flags);
}
\f
case NorthGravity:
case SouthGravity:
case CenterGravity:
- case StaticGravity:
{
region->x+=(ssize_t) (width/2-region->width/2);
break;
case EastGravity:
case WestGravity:
case CenterGravity:
- case StaticGravity:
{
region->y+=(ssize_t) (height/2-region->height/2);
break;
if (geometry == (const char *) NULL)
return(MagickFalse);
flags=ParseGeometry(geometry,&geometry_info);
- if (flags == NoValue)
- flags=ParseGeometry(geometry+1,&geometry_info); /* i.e. +-4+-4 */
return(flags != NoValue ? MagickTrue : MagickFalse);
}
\f
if (geometry == (const char *) NULL)
return(MagickFalse);
p=(char *) geometry;
- value=InterpretLocaleValue(geometry,&p);
+ value=StringToDouble(geometry,&p);
(void) value;
if (p == geometry)
return(MagickFalse);
{
case 0:
{
- affine_matrix->sx=InterpretLocaleValue(token,(char **) NULL);
+ affine_matrix->sx=StringToDouble(token,(char **) NULL);
break;
}
case 1:
{
- affine_matrix->rx=InterpretLocaleValue(token,(char **) NULL);
+ affine_matrix->rx=StringToDouble(token,(char **) NULL);
break;
}
case 2:
{
- affine_matrix->ry=InterpretLocaleValue(token,(char **) NULL);
+ affine_matrix->ry=StringToDouble(token,(char **) NULL);
break;
}
case 3:
{
- affine_matrix->sy=InterpretLocaleValue(token,(char **) NULL);
+ affine_matrix->sy=StringToDouble(token,(char **) NULL);
break;
}
case 4:
{
- affine_matrix->tx=InterpretLocaleValue(token,(char **) NULL);
+ affine_matrix->tx=StringToDouble(token,(char **) NULL);
flags|=XValue;
break;
}
case 5:
{
- affine_matrix->ty=InterpretLocaleValue(token,(char **) NULL);
+ affine_matrix->ty=StringToDouble(token,(char **) NULL);
flags|=YValue;
break;
}
affine_matrix->ry);
if (fabs(determinant) < MagickEpsilon)
(void) ThrowMagickException(exception,GetMagickModule(),OptionError,
- "InvalidGeometry","`%s'",geometry);
+ "InvalidArgument","'%s' : 'Indeterminate Matrix'",geometry);
return(flags);
}
\f
% and ^) flags present. It does not report the location of the percentage
% relative to the values.
%
+% Values may also be seperated by commas, colons, or slashes, and offsets.
+% Offsets may be prefixed by multiple signs to make offset string
+% substitutions easier to handle from shell scripts.
+% For example: "-10-10", "-+10-+10", or "+-10+-10" will generate negtive
+% offsets, while "+10+10", "++10++10", or "--10--10" will generate positive
+% offsets.
+%
% The format of the ParseGeometry method is:
%
% MagickStatusType ParseGeometry(const char *geometry,
(void) CopyMagickString(p,p+1,MaxTextExtent);
break;
}
+ case 'x':
+ case 'X':
+ {
+ flags|=SeparatorValue;
+ p++;
+ break;
+ }
case '-':
case '+':
case ',':
case '7':
case '8':
case '9':
- case 'x':
- case 'X':
case '/':
case ':':
case 215:
if (*p == '\0')
return(flags);
q=p;
- value=InterpretLocaleValue(p,&q);
+ value=StringToDouble(p,&q);
if (LocaleNCompare(p,"0x",2) == 0)
value=(double) strtol(p,&q,10);
c=(int) ((unsigned char) *q);
if (LocaleNCompare(p,"0x",2) == 0)
value=(double) strtol(p,&p,10);
else
- value=InterpretLocaleValue(p,&p);
+ value=StringToDouble(p,&p);
if (p != q)
{
flags|=RhoValue;
(*p != '-')))
{
q=p;
- value=InterpretLocaleValue(p,&p);
+ value=StringToDouble(p,&p);
if (p != q)
{
flags|=SigmaValue;
/*
Parse xi value.
*/
- if ((*p == ',') || (*p == '/') || (*p == ':'))
+ if ((*p == ',') || (*p == '/') || (*p == ':') )
p++;
+ while ((*p == '+') || (*p == '-'))
+ {
+ if (*p == '-')
+ flags^=XiNegative; /* negate sign */
+ p++;
+ }
q=p;
- value=InterpretLocaleValue(p,&p);
+ value=StringToDouble(p,&p);
if (p != q)
{
flags|=XiValue;
- if (*q == '-')
- flags|=XiNegative;
+ if ((flags & XiNegative) != 0)
+ value=(-value);
geometry_info->xi=value;
}
while (isspace((int) ((unsigned char) *p)) != 0)
*/
if ((*p == ',') || (*p == '/') || (*p == ':'))
p++;
+ while ((*p == '+') || (*p == '-'))
+ {
+ if (*p == '-')
+ flags^=PsiNegative; /* negate sign */
+ p++;
+ }
q=p;
- value=InterpretLocaleValue(p,&p);
+ value=StringToDouble(p,&p);
if (p != q)
{
flags|=PsiValue;
- if (*q == '-')
- flags|=PsiNegative;
+ if ((flags & PsiNegative) != 0)
+ value=(-value);
geometry_info->psi=value;
}
- }
+ }
while (isspace((int) ((unsigned char) *p)) != 0)
p++;
if ((*p == '+') || (*p == '-') || (*p == ',') || (*p == '/') ||
*/
if ((*p == ',') || (*p == '/') || (*p == ':'))
p++;
+ while ((*p == '+') || (*p == '-'))
+ {
+ if (*p == '-')
+ flags^=ChiNegative; /* negate sign */
+ p++;
+ }
q=p;
- value=InterpretLocaleValue(p,&p);
+ value=StringToDouble(p,&p);
if (p != q)
{
flags|=ChiValue;
- if (*q == '-')
- flags|=ChiNegative;
+ if ((flags & ChiNegative) != 0)
+ value=(-value);
geometry_info->chi=value;
}
}
flags|=SigmaValue;
flags&=(~XiValue);
}
+ if ((flags & PercentValue) != 0)
+ {
+ if (((flags & SeparatorValue) == 0) && ((flags & SigmaValue) == 0))
+ geometry_info->sigma=geometry_info->rho;
+ if (((flags & SeparatorValue) != 0) && ((flags & RhoValue) == 0))
+ geometry_info->rho=geometry_info->sigma;
+ }
+#if 0
+ /* Debugging Geometry */
+ (void) fprintf(stderr,"ParseGeometry...\n");
+ (void) fprintf(stderr,"Flags: %c %c %s %s %s\n",
+ (flags & RhoValue) ? 'W' : ' ',(flags & SigmaValue) ? 'H' : ' ',
+ (flags & XiValue) ? ((flags & XiNegative) ? "-X" : "+X") : " ",
+ (flags & PsiValue) ? ((flags & PsiNegative) ? "-Y" : "+Y") : " ",
+ (flags & ChiValue) ? ((flags & ChiNegative) ? "-Z" : "+Z") : " ");
+ (void) fprintf(stderr,"Geometry: %lg,%lg,%lg,%lg,%lg\n",geometry_info->rho,
+ geometry_info->sigma,geometry_info->xi,geometry_info->psi,
+ geometry_info->chi);
+#endif
return(flags);
}
\f
if (flags == NoValue)
{
(void) ThrowMagickException(exception,GetMagickModule(),OptionError,
- "InvalidGeometry","`%s'",geometry);
+ "InvalidGeometry","'%s'",geometry);
return(flags);
}
if ((flags & PercentValue) != 0)
% image within the specified geometry width and height.
%
% Flags are interpreted...
-% % geometry size is given percentage of original image size
+% % geometry size is given percentage of original width and height given
% ! do not try to preserve aspect ratio
% < only enlarge images smaller that geometry
% > only shrink images larger than geometry
if ((flags & SigmaValue) == 0)
scale.y=scale.x;
*width=(size_t) floor(scale.x*former_width/100.0+0.5);
- if (*width == 0)
- *width=1;
*height=(size_t) floor(scale.y*former_height/100.0+0.5);
- if (*height == 0)
- *height=1;
former_width=(*width);
former_height=(*height);
}
- if (((flags & AspectValue) == 0) && ((*width != former_width) ||
- (*height != former_height)))
+ if (((flags & AspectValue) != 0) || ((*width == former_width) &&
+ (*height == former_height)))
+ {
+ if ((flags & RhoValue) == 0)
+ *width=former_width;
+ if ((flags & SigmaValue) == 0)
+ *height=former_height;
+ }
+ else
{
- MagickRealType
+ double
scale_factor;
/*
else
if (((flags & RhoValue) != 0) && (flags & SigmaValue) != 0)
{
- scale_factor=(MagickRealType) *width/(MagickRealType) former_width;
+ scale_factor=(double) *width/(double) former_width;
if ((flags & MinimumValue) == 0)
{
- if (scale_factor > ((MagickRealType) *height/(MagickRealType)
- former_height))
- scale_factor=(MagickRealType) *height/(MagickRealType)
- former_height;
+ if (scale_factor > ((double) *height/(double) former_height))
+ scale_factor=(double) *height/(double) former_height;
}
else
- if (scale_factor < ((MagickRealType) *height/(MagickRealType)
- former_height))
- scale_factor=(MagickRealType) *height/(MagickRealType)
- former_height;
+ if (scale_factor < ((double) *height/(double) former_height))
+ scale_factor=(double) *height/(double) former_height;
}
else
if ((flags & RhoValue) != 0)
{
- scale_factor=(MagickRealType) *width/(MagickRealType)
- former_width;
+ scale_factor=(double) *width/(double) former_width;
if (((flags & MinimumValue) != 0) &&
- (scale_factor < ((MagickRealType) *width/(MagickRealType)
- former_height)))
- scale_factor=(MagickRealType) *width/(MagickRealType)
- former_height;
+ (scale_factor < ((double) *width/(double) former_height)))
+ scale_factor=(double) *width/(double) former_height;
}
else
{
- scale_factor=(MagickRealType) *height/(MagickRealType)
- former_height;
+ scale_factor=(double) *height/(double) former_height;
if (((flags & MinimumValue) != 0) &&
- (scale_factor < ((MagickRealType) *height/(MagickRealType)
- former_width)))
- scale_factor=(MagickRealType) *height/(MagickRealType)
- former_width;
+ (scale_factor < ((double) *height/(double) former_width)))
+ scale_factor=(double) *height/(double) former_width;
}
*width=MagickMax((size_t) floor(scale_factor*former_width+0.5),1UL);
*height=MagickMax((size_t) floor(scale_factor*former_height+0.5),1UL);
}
if ((flags & AreaValue) != 0)
{
- MagickRealType
+ double
area,
distance;
(void) ParseGeometry(geometry,&geometry_info);
area=geometry_info.rho;
distance=sqrt((double) former_width*former_height);
- scale.x=(double) former_width/(double) (distance/sqrt((double) area));
- scale.y=(double) former_height/(double) (distance/sqrt((double) area));
+ scale.x=(double) former_width/(distance/sqrt((double) area));
+ scale.y=(double) former_height/(distance/sqrt((double) area));
if ((scale.x < (double) *width) || (scale.y < (double) *height))
{
- *width=(size_t) (former_width/(distance/sqrt((double) area)));
- *height=(size_t) (former_height/(distance/sqrt((double) area)));
+ *width=(size_t) (former_width/(distance/sqrt(area))+0.5);
+ *height=(size_t) (former_height/(distance/sqrt(area))+0.5);
}
former_width=(*width);
former_height=(*height);
if (flags == NoValue)
{
(void) ThrowMagickException(exception,GetMagickModule(),OptionError,
- "InvalidGeometry","`%s'",geometry);
+ "InvalidGeometry","'%s'",geometry);
return(flags);
}
if ((flags & PercentValue) != 0)
}
flags=ParseMetaGeometry(geometry,®ion_info->x,®ion_info->y,
®ion_info->width,®ion_info->height);
+ if ((((flags & WidthValue) != 0) || ((flags & HeightValue) != 0)) &&
+ (((flags & PercentValue) != 0) || ((flags & SeparatorValue) == 0)))
+ {
+ if ((flags & WidthValue) == 0)
+ region_info->width=region_info->height;
+ if ((flags & HeightValue) == 0)
+ region_info->height=region_info->width;
+ }
return(flags);
}
\f
®ion_info->width,®ion_info->height);
if (flags == NoValue)
(void) ThrowMagickException(exception,GetMagickModule(),OptionError,
- "InvalidGeometry","`%s'",geometry);
+ "InvalidGeometry","'%s'",geometry);
return(flags);
}
\f