39#include "MagickCore/studio.h"
40#include "MagickCore/constitute.h"
41#include "MagickCore/draw.h"
42#include "MagickCore/exception.h"
43#include "MagickCore/exception-private.h"
44#include "MagickCore/geometry.h"
45#include "MagickCore/geometry-private.h"
46#include "MagickCore/image-private.h"
47#include "MagickCore/memory_.h"
48#include "MagickCore/pixel-accessor.h"
49#include "MagickCore/string_.h"
50#include "MagickCore/string-private.h"
51#include "MagickCore/token.h"
56#define MagickPagesize(name,geometry) { name, sizeof(name)-1, geometry }
76 MagickPagesize(
"4x6",
"288x432"),
77 MagickPagesize(
"5x7",
"360x504"),
78 MagickPagesize(
"7x9",
"504x648"),
79 MagickPagesize(
"8x10",
"576x720"),
80 MagickPagesize(
"9x11",
"648x792"),
81 MagickPagesize(
"9x12",
"648x864"),
82 MagickPagesize(
"10x13",
"720x936"),
83 MagickPagesize(
"10x14",
"720x1008"),
84 MagickPagesize(
"11x17",
"792x1224"),
85 MagickPagesize(
"4A0",
"4768x6741"),
86 MagickPagesize(
"2A0",
"3370x4768"),
87 MagickPagesize(
"a0",
"2384x3370"),
88 MagickPagesize(
"a10",
"74x105"),
89 MagickPagesize(
"a1",
"1684x2384"),
90 MagickPagesize(
"a2",
"1191x1684"),
91 MagickPagesize(
"a3",
"842x1191"),
92 MagickPagesize(
"a4small",
"595x842"),
93 MagickPagesize(
"a4",
"595x842"),
94 MagickPagesize(
"a5",
"420x595"),
95 MagickPagesize(
"a6",
"298x420"),
96 MagickPagesize(
"a7",
"210x298"),
97 MagickPagesize(
"a8",
"147x210"),
98 MagickPagesize(
"a9",
"105x147"),
99 MagickPagesize(
"archa",
"648x864"),
100 MagickPagesize(
"archb",
"864x1296"),
101 MagickPagesize(
"archC",
"1296x1728"),
102 MagickPagesize(
"archd",
"1728x2592"),
103 MagickPagesize(
"arche",
"2592x3456"),
104 MagickPagesize(
"b0",
"2920x4127"),
105 MagickPagesize(
"b10",
"91x127"),
106 MagickPagesize(
"b1",
"2064x2920"),
107 MagickPagesize(
"b2",
"1460x2064"),
108 MagickPagesize(
"b3",
"1032x1460"),
109 MagickPagesize(
"b4",
"729x1032"),
110 MagickPagesize(
"b5",
"516x729"),
111 MagickPagesize(
"b6",
"363x516"),
112 MagickPagesize(
"b7",
"258x363"),
113 MagickPagesize(
"b8",
"181x258"),
114 MagickPagesize(
"b9",
"127x181"),
115 MagickPagesize(
"c0",
"2599x3676"),
116 MagickPagesize(
"c1",
"1837x2599"),
117 MagickPagesize(
"c2",
"1298x1837"),
118 MagickPagesize(
"c3",
"918x1296"),
119 MagickPagesize(
"c4",
"649x918"),
120 MagickPagesize(
"c5",
"459x649"),
121 MagickPagesize(
"c6",
"323x459"),
122 MagickPagesize(
"c7",
"230x323"),
123 MagickPagesize(
"csheet",
"1224x1584"),
124 MagickPagesize(
"dsheet",
"1584x2448"),
125 MagickPagesize(
"esheet",
"2448x3168"),
126 MagickPagesize(
"executive",
"540x720"),
127 MagickPagesize(
"flsa",
"612x936"),
128 MagickPagesize(
"flse",
"612x936"),
129 MagickPagesize(
"folio",
"612x936"),
130 MagickPagesize(
"halfletter",
"396x612"),
131 MagickPagesize(
"isob0",
"2835x4008"),
132 MagickPagesize(
"isob10",
"88x125"),
133 MagickPagesize(
"isob1",
"2004x2835"),
134 MagickPagesize(
"isob2",
"1417x2004"),
135 MagickPagesize(
"isob3",
"1001x1417"),
136 MagickPagesize(
"isob4",
"709x1001"),
137 MagickPagesize(
"isob5",
"499x709"),
138 MagickPagesize(
"isob6",
"354x499"),
139 MagickPagesize(
"isob7",
"249x354"),
140 MagickPagesize(
"isob8",
"176x249"),
141 MagickPagesize(
"isob9",
"125x176"),
142 MagickPagesize(
"jisb0",
"1030x1456"),
143 MagickPagesize(
"jisb1",
"728x1030"),
144 MagickPagesize(
"jisb2",
"515x728"),
145 MagickPagesize(
"jisb3",
"364x515"),
146 MagickPagesize(
"jisb4",
"257x364"),
147 MagickPagesize(
"jisb5",
"182x257"),
148 MagickPagesize(
"jisb6",
"128x182"),
149 MagickPagesize(
"ledger",
"1224x792"),
150 MagickPagesize(
"legal",
"612x1008"),
151 MagickPagesize(
"lettersmall",
"612x792"),
152 MagickPagesize(
"letter",
"612x792"),
153 MagickPagesize(
"monarch",
"279x540"),
154 MagickPagesize(
"quarto",
"610x780"),
155 MagickPagesize(
"statement",
"396x612"),
156 MagickPagesize(
"tabloid",
"792x1224"),
157 MagickPagesize(
"",
"")
202MagickExport MagickStatusType GetGeometry(
const char *geometry,ssize_t *x,
203 ssize_t *y,
size_t *width,
size_t *height)
207 pedantic_geometry[MagickPathExtent],
223 if ((geometry == (
char *) NULL) || (*geometry ==
'\0'))
225 if (strlen(geometry) >= (MagickPathExtent-1))
227 (void) CopyMagickString(pedantic_geometry,geometry,MagickPathExtent);
228 for (p=pedantic_geometry; *p !=
'\0'; )
230 if (isspace((
int) ((
unsigned char) *p)) != 0)
232 (void) CopyMagickString(p,p+1,MagickPathExtent);
241 (void) CopyMagickString(p,p+1,MagickPathExtent);
247 (void) CopyMagickString(p,p+1,MagickPathExtent);
253 (void) CopyMagickString(p,p+1,MagickPathExtent);
259 (void) CopyMagickString(p,p+1,MagickPathExtent);
265 (void) CopyMagickString(p,p+1,MagickPathExtent);
271 (void) CopyMagickString(p,p+1,MagickPathExtent);
277 (void) CopyMagickString(p,p+1,MagickPathExtent);
283 (void) CopyMagickString(p,p+1,MagickPathExtent);
289 flags|=SeparatorValue;
322 flags|=AspectRatioValue;
336 value=StringToDouble(p,&q);
338 if (LocaleNCompare(p,
"0x",2) == 0)
339 value=(double) strtol(p,&q,10);
340 if ((*p !=
'+') && (*p !=
'-'))
342 c=(int) ((
unsigned char) *q);
343 if ((c == 215) || (*q ==
'x') || (*q ==
'X') || (*q ==
':') ||
350 if (width != (
size_t *) NULL)
352 if (LocaleNCompare(p,
"0x",2) == 0)
353 *width=(size_t) strtol(p,&p,10);
355 *width=CastDoubleToUnsigned(StringToDouble(p,&p)+0.5);
361 if ((*p !=
'+') && (*p !=
'-'))
363 c=(int) ((
unsigned char) *p);
364 if ((c == 215) || (*p ==
'x') || (*p ==
'X') || (*p ==
':'))
367 if ((*p !=
'+') && (*p !=
'-'))
373 if (height != (
size_t *) NULL)
374 *height=CastDoubleToUnsigned(StringToDouble(p,&p)+0.5);
380 if ((*p ==
'+') || (*p ==
'-'))
385 while ((*p ==
'+') || (*p ==
'-'))
392 if (x != (ssize_t *) NULL)
393 *x=CastDoubleToLong(StringToDouble(p,&p));
397 if (((flags & XNegative) != 0) && (x != (ssize_t *) NULL))
398 *x=CastDoubleToLong(-1.0**x);
401 if ((*p ==
'+') || (*p ==
'-'))
406 while ((*p ==
'+') || (*p ==
'-'))
413 if (y != (ssize_t *) NULL)
414 *y=CastDoubleToLong(StringToDouble(p,&p));
418 if (((flags & YNegative) != 0) && (y != (ssize_t *) NULL))
419 *y=CastDoubleToLong(-1.0**y);
422 if ((flags & PercentValue) != 0)
424 if (((flags & SeparatorValue) == 0) && ((flags & HeightValue) == 0))
426 if ((height != (
size_t *) NULL) && (width != (
size_t *) NULL))
430 if (((flags & SeparatorValue) != 0) && ((flags & WidthValue) == 0) &&
431 (height != (
size_t *) NULL) && (width != (
size_t *) NULL))
436 (void) fprintf(stderr,
"GetGeometry...\n");
437 (void) fprintf(stderr,
"Input: %s\n",geometry);
438 (void) fprintf(stderr,
"Flags: %c %c %s %s\n",
439 (flags & WidthValue) ?
'W' :
' ',(flags & HeightValue) ?
'H' :
' ',
440 (flags & XValue) ? ((flags & XNegative) ?
"-X" :
"+X") :
" ",
441 (flags & YValue) ? ((flags & YNegative) ?
"-Y" :
"+Y") :
" ");
442 (void) fprintf(stderr,
"Geometry: %ldx%ld%+ld%+ld\n",(
long) *width,(
long)
443 *height,(
long) *x,(
long) *y);
473MagickExport
char *GetPageGeometry(
const char *page_geometry)
476 page[MagickPathExtent];
481 assert(page_geometry != (
char *) NULL);
482 if (IsEventLogging() != MagickFalse)
483 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",page_geometry);
484 (void) CopyMagickString(page,page_geometry,MagickPathExtent);
485 for (i=0; *Pagesizes[i].name !=
'\0'; i++)
490 if (Pagesizes[i].extent == 0)
492 status=LocaleNCompare(Pagesizes[i].name,page_geometry,Pagesizes[i].extent);
504 (void) FormatLocaleString(page,MagickPathExtent,
"%s%.80s",
505 Pagesizes[i].geometry,page_geometry+Pagesizes[i].extent);
506 flags=GetGeometry(page,&geometry.x,&geometry.y,&geometry.width,
508 if ((flags & GreaterValue) == 0)
509 (void) ConcatenateMagickString(page,
">",MagickPathExtent);
513 return(AcquireString(page));
547MagickExport
void GravityAdjustGeometry(
const size_t width,
548 const size_t height,
const GravityType gravity,
RectangleInfo *region)
550 if (region->height == 0)
551 region->height=height;
552 if (region->width == 0)
556 case NorthEastGravity:
558 case SouthEastGravity:
560 region->x=CastDoubleToLong((
double) width-region->width-region->x);
567 region->x=CastDoubleToLong(width/2.0-region->width/2.0+region->x);
571 case NorthWestGravity:
573 case SouthWestGravity:
579 case SouthWestGravity:
581 case SouthEastGravity:
583 region->y=CastDoubleToLong((
double) height-region->height-region->y);
590 region->y=CastDoubleToLong(height/2.0-region->height/2.0+region->y);
594 case NorthWestGravity:
596 case NorthEastGravity:
626MagickExport MagickBooleanType IsGeometry(
const char *geometry)
634 if (geometry == (
const char *) NULL)
636 flags=ParseGeometry(geometry,&geometry_info);
637 return(flags != NoValue ? MagickTrue : MagickFalse);
667MagickExport MagickBooleanType IsSceneGeometry(
const char *geometry,
668 const MagickBooleanType pedantic)
676 if (geometry == (
const char *) NULL)
679 value=StringToDouble(geometry,&p);
680 if (IsNaN(value) != 0)
682 if (value > (
double) MAGICK_SSIZE_MAX)
684 if (value < (
double) MAGICK_SSIZE_MIN)
688 if (strspn(geometry,
"0123456789-, ") != strlen(geometry))
690 if ((pedantic != MagickFalse) && (strchr(geometry,
',') != (
char *) NULL))
719MagickExport MagickBooleanType ListPagesizes(FILE *file,
722#define MaxMagickSpaces ((int) sizeof(Pagesizes[0].name))
730 magick_unreferenced(exception);
731 if (file == (FILE *) NULL)
733 (void) FormatLocaleFile(file,
"\nPagesize Geometry \n");
734 (void) FormatLocaleFile(file,
"---------------------\n");
735 for (i=0; *Pagesizes[i].name !=
'\0'; i++)
736 (
void) FormatLocaleFile(file,
"%s%.*s%s\n",Pagesizes[i].name,
737 MaxMagickSpaces-(
int) Pagesizes[i].extent,spacer,Pagesizes[i].geometry);
770MagickExport MagickStatusType ParseAbsoluteGeometry(
const char *geometry,
776 flags=GetGeometry(geometry,®ion_info->x,®ion_info->y,
777 ®ion_info->width,®ion_info->height);
811MagickExport MagickStatusType ParseAffineGeometry(
const char *geometry,
815 token[MagickPathExtent];
829 GetAffineMatrix(affine_matrix);
832 for (i=0; (*p !=
'\0') && (i < 6); i++)
834 (void) GetNextToken(p,&p,MagickPathExtent,token);
836 (void) GetNextToken(p,&p,MagickPathExtent,token);
841 affine_matrix->sx=StringToDouble(token,(
char **) NULL);
846 affine_matrix->rx=StringToDouble(token,(
char **) NULL);
851 affine_matrix->ry=StringToDouble(token,(
char **) NULL);
856 affine_matrix->sy=StringToDouble(token,(
char **) NULL);
861 affine_matrix->tx=StringToDouble(token,(
char **) NULL);
867 affine_matrix->ty=StringToDouble(token,(
char **) NULL);
873 determinant=(affine_matrix->sx*affine_matrix->sy-affine_matrix->rx*
875 if (fabs(determinant) < MagickEpsilon)
876 (void) ThrowMagickException(exception,GetMagickModule(),OptionError,
877 "InvalidArgument",
"'%s' : 'Indeterminate Matrix'",geometry);
920MagickExport MagickStatusType ParseGeometry(
const char *geometry,
925 pedantic_geometry[MagickPathExtent],
944 (void) memset(geometry_info,0,
sizeof(*geometry_info));
946 if ((geometry == (
char *) NULL) || (*geometry ==
'\0'))
948 if (strlen(geometry) >= (MagickPathExtent-1))
950 c=sscanf(geometry,
"%lf%*[ ,]%lf%*[ ,]%lf%*[ ,]%lf",&coordinate.rho,
951 &coordinate.sigma,&coordinate.xi,&coordinate.psi);
957 geometry_info->rho=coordinate.rho;
958 geometry_info->sigma=coordinate.sigma;
959 geometry_info->xi=coordinate.xi;
960 geometry_info->psi=coordinate.psi;
961 flags|=RhoValue | SigmaValue | XiValue | PsiValue;
964 (void) CopyMagickString(pedantic_geometry,geometry,MagickPathExtent);
965 for (p=pedantic_geometry; *p !=
'\0'; )
967 c=(int) ((
unsigned char) *p);
968 if (isspace((
int) ((
unsigned char) c)) != 0)
970 (void) CopyMagickString(p,p+1,MagickPathExtent);
978 (void) CopyMagickString(p,p+1,MagickPathExtent);
984 (void) CopyMagickString(p,p+1,MagickPathExtent);
990 (void) CopyMagickString(p,p+1,MagickPathExtent);
996 (void) CopyMagickString(p,p+1,MagickPathExtent);
1001 flags|=MaximumValue;
1002 (void) CopyMagickString(p,p+1,MagickPathExtent);
1007 flags|=MinimumValue;
1008 (void) CopyMagickString(p,p+1,MagickPathExtent);
1014 (void) CopyMagickString(p,p+1,MagickPathExtent);
1021 (void) CopyMagickString(p,p+1,MagickPathExtent);
1026 (void) CopyMagickString(p,p+1,MagickPathExtent);
1032 flags|=SeparatorValue;
1060 flags|=DecimalValue;
1066 flags|=AspectRatioValue;
1076 p=pedantic_geometry;
1080 value=StringToDouble(p,&q);
1081 if (LocaleNCompare(p,
"0x",2) == 0)
1082 (void) strtol(p,&q,10);
1083 c=(int) ((
unsigned char) *q);
1084 if ((c == 215) || (*q ==
'x') || (*q ==
'X') || (*q ==
':') ||
1085 (*q ==
',') || (*q ==
'/') || (*q ==
'\0'))
1091 if (LocaleNCompare(p,
"0x",2) == 0)
1092 value=(double) strtol(p,&p,10);
1094 value=StringToDouble(p,&p);
1098 geometry_info->rho=value;
1102 c=(int) ((
unsigned char) *p);
1103 if ((c == 215) || (*p ==
'x') || (*p ==
'X') || (*p ==
':') || (*p ==
',') ||
1110 while (isspace((
int) ((
unsigned char) *p)) != 0)
1112 c=(int) ((
unsigned char) *q);
1113 if (((c != 215) && (*q !=
'x') && (*q !=
'X') && (*q !=
':')) ||
1114 ((*p !=
'+') && (*p !=
'-')))
1117 value=StringToDouble(p,&p);
1121 geometry_info->sigma=value;
1125 while (isspace((
int) ((
unsigned char) *p)) != 0)
1127 if ((*p ==
'+') || (*p ==
'-') || (*p ==
',') || (*p ==
'/') || (*p ==
':'))
1132 if ((*p ==
',') || (*p ==
'/') || (*p ==
':') )
1134 while ((*p ==
'+') || (*p ==
'-'))
1141 value=StringToDouble(p,&p);
1145 if ((flags & XiNegative) != 0)
1147 geometry_info->xi=value;
1149 while (isspace((
int) ((
unsigned char) *p)) != 0)
1151 if ((*p ==
'+') || (*p ==
'-') || (*p ==
',') || (*p ==
'/') ||
1157 if ((*p ==
',') || (*p ==
'/') || (*p ==
':'))
1159 while ((*p ==
'+') || (*p ==
'-'))
1166 value=StringToDouble(p,&p);
1170 if ((flags & PsiNegative) != 0)
1172 geometry_info->psi=value;
1175 while (isspace((
int) ((
unsigned char) *p)) != 0)
1177 if ((*p ==
'+') || (*p ==
'-') || (*p ==
',') || (*p ==
'/') ||
1183 if ((*p ==
',') || (*p ==
'/') || (*p ==
':'))
1185 while ((*p ==
'+') || (*p ==
'-'))
1192 value=StringToDouble(p,&p);
1196 if ((flags & ChiNegative) != 0)
1198 geometry_info->chi=value;
1202 if (strchr(pedantic_geometry,
':') != (
char *) NULL)
1207 if ((flags & SigmaValue) != 0)
1208 geometry_info->rho*=PerceptibleReciprocal(geometry_info->sigma);
1209 geometry_info->sigma=1.0;
1210 if (((flags & XiValue) != 0) && (geometry_info->xi == 0.0))
1211 geometry_info->sigma=2.0;
1213 if (((flags & RhoValue) != 0) && ((flags & SigmaValue) == 0) &&
1214 ((flags & XiValue) != 0) && ((flags & XiNegative) != 0))
1216 if ((flags & PsiValue) == 0)
1221 geometry_info->sigma=geometry_info->xi;
1222 geometry_info->xi=0.0;
1224 flags&=(
unsigned int) (~XiValue);
1227 if ((flags & ChiValue) == 0)
1232 geometry_info->sigma=geometry_info->xi;
1233 geometry_info->xi=geometry_info->psi;
1236 flags&=(
unsigned int) (~PsiValue);
1243 geometry_info->sigma=geometry_info->xi;
1244 geometry_info->xi=geometry_info->psi;
1245 geometry_info->psi=geometry_info->chi;
1249 flags&=(
unsigned int) (~ChiValue);
1252 if ((flags & PercentValue) != 0)
1254 if (((flags & SeparatorValue) == 0) && ((flags & SigmaValue) == 0))
1255 geometry_info->sigma=geometry_info->rho;
1256 if (((flags & SeparatorValue) != 0) && ((flags & RhoValue) == 0))
1257 geometry_info->rho=geometry_info->sigma;
1261 (void) fprintf(stderr,
"ParseGeometry...\n");
1262 (void) fprintf(stderr,
"Flags: %c %c %s %s %s\n",
1263 (flags & RhoValue) ?
'W' :
' ',(flags & SigmaValue) ?
'H' :
' ',
1264 (flags & XiValue) ? ((flags & XiNegative) ?
"-X" :
"+X") :
" ",
1265 (flags & PsiValue) ? ((flags & PsiNegative) ?
"-Y" :
"+Y") :
" ",
1266 (flags & ChiValue) ? ((flags & ChiNegative) ?
"-Z" :
"+Z") :
" ");
1267 (void) fprintf(stderr,
"Geometry: %lg,%lg,%lg,%lg,%lg\n",geometry_info->rho,
1268 geometry_info->sigma,geometry_info->xi,geometry_info->psi,
1269 geometry_info->chi);
1311MagickExport MagickStatusType ParseGravityGeometry(
const Image *image,
1321 if (IsEventLogging() != MagickFalse)
1322 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",geometry);
1323 if ((geometry == (
char *) NULL) || (*geometry ==
'\0'))
1325 SetGeometry(image,region_info);
1326 if (image->page.width != 0)
1327 region_info->width=image->page.width;
1328 if (image->page.height != 0)
1329 region_info->height=image->page.height;
1330 flags=ParseAbsoluteGeometry(geometry,region_info);
1331 if (flags == NoValue)
1333 (void) ThrowMagickException(exception,GetMagickModule(),OptionError,
1334 "InvalidGeometry",
"`%s'",geometry);
1337 if ((flags & PercentValue) != 0)
1351 if (image->gravity != UndefinedGravity)
1352 flags|=XValue | YValue;
1353 status=ParseGeometry(geometry,&geometry_info);
1354 scale.x=geometry_info.rho;
1355 if ((status & RhoValue) == 0)
1357 scale.y=geometry_info.sigma;
1358 if ((status & SigmaValue) == 0)
1360 region_info->width=CastDoubleToUnsigned(scale.x*image->columns/100.0+0.5);
1361 region_info->height=CastDoubleToUnsigned(scale.y*image->rows/100.0+0.5);
1363 if ((flags & AspectRatioValue) != 0)
1375 if (image->gravity != UndefinedGravity)
1376 flags|=XValue | YValue;
1377 (void) ParseGeometry(geometry,&geometry_info);
1378 geometry_ratio=geometry_info.rho;
1379 image_ratio=(double) image->columns/image->rows;
1380 region_info->width=image->columns;
1381 region_info->height=image->rows;
1382 if ((flags & MaximumValue) != 0)
1384 if (geometry_ratio < image_ratio)
1385 region_info->height=CastDoubleToUnsigned((
double) image->rows*
1386 image_ratio/geometry_ratio+0.5);
1388 region_info->width=CastDoubleToUnsigned((
double) image->columns*
1389 geometry_ratio/image_ratio+0.5);
1392 if (geometry_ratio >= image_ratio)
1393 region_info->height=CastDoubleToUnsigned((
double) image->rows*
1394 image_ratio/geometry_ratio+0.5);
1396 region_info->width=CastDoubleToUnsigned((
double) image->columns*
1397 geometry_ratio/image_ratio+0.5);
1402 width=region_info->width;
1403 height=region_info->height;
1405 region_info->width=image->page.width | image->columns;
1407 region_info->height=image->page.height | image->rows;
1408 GravityAdjustGeometry(image->columns,image->rows,image->gravity,region_info);
1409 if ((flags & LessValue) != 0)
1410 if ((region_info->width < image->columns) &&
1411 (region_info->height < image->rows))
1413 SetGeometry(image,region_info);
1416 if ((flags & GreaterValue) != 0)
1417 if ((region_info->width > image->columns) &&
1418 (region_info->height > image->rows))
1420 SetGeometry(image,region_info);
1423 region_info->width=width;
1424 region_info->height=height;
1471MagickExport MagickStatusType ParseMetaGeometry(
const char *geometry,ssize_t *x,
1472 ssize_t *y,
size_t *width,
size_t *height)
1487 assert(x != (ssize_t *) NULL);
1488 assert(y != (ssize_t *) NULL);
1489 assert(width != (
size_t *) NULL);
1490 assert(height != (
size_t *) NULL);
1491 if (IsEventLogging() != MagickFalse)
1492 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",geometry);
1493 if ((geometry == (
char *) NULL) || (*geometry ==
'\0'))
1498 stasis_width=(*width);
1499 stasis_height=(*height);
1500 SetGeometryInfo(&geometry_info);
1501 flags=GetGeometry(geometry,x,y,width,height);
1502 if ((flags & PercentValue) != 0)
1513 percent_flags=ParseGeometry(geometry,&geometry_info);
1514 scale.x=geometry_info.rho;
1515 if ((percent_flags & RhoValue) == 0)
1517 scale.y=geometry_info.sigma;
1518 if ((percent_flags & SigmaValue) == 0)
1520 *width=CastDoubleToUnsigned(scale.x*stasis_width/100.0+0.5);
1521 *height=CastDoubleToUnsigned(scale.y*stasis_height/100.0+0.5);
1522 stasis_width=(*width);
1523 stasis_height=(*height);
1525 if ((flags & AspectRatioValue) != 0)
1534 (void) ParseGeometry(geometry,&geometry_info);
1535 geometry_ratio=geometry_info.rho;
1536 image_ratio=(double) stasis_width*PerceptibleReciprocal((
double)
1538 if (geometry_ratio >= image_ratio)
1540 *width=stasis_width;
1541 *height=CastDoubleToUnsigned((
double) (PerceptibleReciprocal(
1542 geometry_ratio)*stasis_height*image_ratio)+0.5);
1546 *width=CastDoubleToUnsigned(PerceptibleReciprocal(image_ratio)*
1547 stasis_width*geometry_ratio+0.5);
1548 *height=stasis_height;
1550 stasis_width=(*width);
1551 stasis_height=(*height);
1553 if (((flags & AspectValue) != 0) || ((*width == stasis_width) &&
1554 (*height == stasis_height)))
1556 if ((flags & RhoValue) == 0)
1557 *width=stasis_width;
1558 if ((flags & SigmaValue) == 0)
1559 *height=stasis_height;
1569 if ((stasis_width == 0) || (stasis_height == 0))
1572 if (((flags & RhoValue) != 0) && (flags & SigmaValue) != 0)
1574 scale_factor=(double) *width/(
double) stasis_width;
1575 if ((flags & MinimumValue) == 0)
1577 if (scale_factor > ((
double) *height/(
double) stasis_height))
1578 scale_factor=(double) *height/(
double) stasis_height;
1581 if (scale_factor < ((
double) *height/(
double) stasis_height))
1582 scale_factor=(double) *height/(
double) stasis_height;
1585 if ((flags & RhoValue) != 0)
1587 scale_factor=(double) *width/(
double) stasis_width;
1588 if (((flags & MinimumValue) != 0) &&
1589 (scale_factor < ((
double) *width/(
double) stasis_height)))
1590 scale_factor=(double) *width/(
double) stasis_height;
1594 scale_factor=(double) *height/(
double) stasis_height;
1595 if (((flags & MinimumValue) != 0) &&
1596 (scale_factor < ((
double) *height/(
double) stasis_width)))
1597 scale_factor=(double) *height/(
double) stasis_width;
1599 *width=CastDoubleToUnsigned(MagickMax(floor(scale_factor*stasis_width+
1601 *height=CastDoubleToUnsigned(MagickMax(floor(scale_factor*stasis_height+
1604 if ((flags & GreaterValue) != 0)
1606 if (stasis_width < *width)
1607 *width=stasis_width;
1608 if (stasis_height < *height)
1609 *height=stasis_height;
1611 if ((flags & LessValue) != 0)
1613 if (stasis_width > *width)
1614 *width=stasis_width;
1615 if (stasis_height > *height)
1616 *height=stasis_height;
1618 if ((flags & AreaValue) != 0)
1630 (void) ParseGeometry(geometry,&geometry_info);
1631 area=geometry_info.rho+sqrt(MagickEpsilon);
1632 distance=sqrt((
double) stasis_width*stasis_height);
1633 scale.x=(double) stasis_width*PerceptibleReciprocal(distance*
1634 PerceptibleReciprocal(sqrt(area)));
1635 scale.y=(double) stasis_height*PerceptibleReciprocal(distance*
1636 PerceptibleReciprocal(sqrt(area)));
1637 if ((scale.x < (
double) *width) || (scale.y < (
double) *height))
1639 *width=CastDoubleToUnsigned(stasis_width*PerceptibleReciprocal(
1640 distance*PerceptibleReciprocal(sqrt(area)))+0.5);
1641 *height=CastDoubleToUnsigned(stasis_height*PerceptibleReciprocal(
1642 distance*PerceptibleReciprocal(sqrt(area)))+0.5);
1681MagickExport MagickStatusType ParsePageGeometry(
const Image *image,
1687 SetGeometry(image,region_info);
1688 if (image->page.width != 0)
1689 region_info->width=image->page.width;
1690 if (image->page.height != 0)
1691 region_info->height=image->page.height;
1692 flags=ParseAbsoluteGeometry(geometry,region_info);
1693 if (flags == NoValue)
1695 (void) ThrowMagickException(exception,GetMagickModule(),OptionError,
1696 "InvalidGeometry",
"`%s'",geometry);
1699 if ((flags & PercentValue) != 0)
1701 region_info->width=image->columns;
1702 region_info->height=image->rows;
1704 flags=ParseMetaGeometry(geometry,®ion_info->x,®ion_info->y,
1705 ®ion_info->width,®ion_info->height);
1706 if ((((flags & WidthValue) != 0) || ((flags & HeightValue) != 0)) &&
1707 (((flags & PercentValue) != 0) || ((flags & SeparatorValue) == 0)))
1709 if ((flags & WidthValue) == 0)
1710 region_info->width=region_info->height;
1711 if ((flags & HeightValue) == 0)
1712 region_info->height=region_info->width;
1750MagickExport MagickStatusType ParseRegionGeometry(
const Image *image,
1756 SetGeometry(image,region_info);
1757 flags=ParseMetaGeometry(geometry,®ion_info->x,®ion_info->y,
1758 ®ion_info->width,®ion_info->height);
1759 if (flags == NoValue)
1760 (void) ThrowMagickException(exception,GetMagickModule(),OptionError,
1761 "InvalidGeometry",
"`%s'",geometry);
1791 assert(image != (
Image *) NULL);
1792 assert(image->signature == MagickCoreSignature);
1793 if (IsEventLogging() != MagickFalse)
1794 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",image->filename);
1796 (void) memset(geometry,0,
sizeof(*geometry));
1797 geometry->width=image->columns;
1798 geometry->height=image->rows;
1823MagickExport
void SetGeometryInfo(
GeometryInfo *geometry_info)
1826 if (IsEventLogging() != MagickFalse)
1827 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
1828 (void) memset(geometry_info,0,
sizeof(*geometry_info));