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((
double) width/2.0-region->width/2.0+
572 case NorthWestGravity:
574 case SouthWestGravity:
580 case SouthWestGravity:
582 case SouthEastGravity:
584 region->y=CastDoubleToLong((
double) height-region->height-region->y);
591 region->y=CastDoubleToLong((
double) height/2.0-region->height/2.0+
596 case NorthWestGravity:
598 case NorthEastGravity:
628MagickExport MagickBooleanType IsGeometry(
const char *geometry)
636 if (geometry == (
const char *) NULL)
638 flags=ParseGeometry(geometry,&geometry_info);
639 return(flags != NoValue ? MagickTrue : MagickFalse);
669MagickExport MagickBooleanType IsSceneGeometry(
const char *geometry,
670 const MagickBooleanType pedantic)
678 if (geometry == (
const char *) NULL)
681 value=StringToDouble(geometry,&p);
682 if (IsNaN(value) != 0)
684 if (value > (
double) MAGICK_SSIZE_MAX)
686 if (value < (
double) MAGICK_SSIZE_MIN)
690 if (strspn(geometry,
"0123456789-, ") != strlen(geometry))
692 if ((pedantic != MagickFalse) && (strchr(geometry,
',') != (
char *) NULL))
721MagickExport MagickBooleanType ListPagesizes(FILE *file,
724#define MaxMagickSpaces ((int) sizeof(Pagesizes[0].name))
732 magick_unreferenced(exception);
733 if (file == (FILE *) NULL)
735 (void) FormatLocaleFile(file,
"\nPagesize Geometry \n");
736 (void) FormatLocaleFile(file,
"---------------------\n");
737 for (i=0; *Pagesizes[i].name !=
'\0'; i++)
738 (
void) FormatLocaleFile(file,
"%s%.*s%s\n",Pagesizes[i].name,
739 MaxMagickSpaces-(
int) Pagesizes[i].extent,spacer,Pagesizes[i].geometry);
772MagickExport MagickStatusType ParseAbsoluteGeometry(
const char *geometry,
778 flags=GetGeometry(geometry,®ion_info->x,®ion_info->y,
779 ®ion_info->width,®ion_info->height);
813MagickExport MagickStatusType ParseAffineGeometry(
const char *geometry,
817 token[MagickPathExtent];
831 GetAffineMatrix(affine_matrix);
834 for (i=0; (*p !=
'\0') && (i < 6); i++)
836 (void) GetNextToken(p,&p,MagickPathExtent,token);
838 (void) GetNextToken(p,&p,MagickPathExtent,token);
843 affine_matrix->sx=StringToDouble(token,(
char **) NULL);
848 affine_matrix->rx=StringToDouble(token,(
char **) NULL);
853 affine_matrix->ry=StringToDouble(token,(
char **) NULL);
858 affine_matrix->sy=StringToDouble(token,(
char **) NULL);
863 affine_matrix->tx=StringToDouble(token,(
char **) NULL);
869 affine_matrix->ty=StringToDouble(token,(
char **) NULL);
875 determinant=(affine_matrix->sx*affine_matrix->sy-affine_matrix->rx*
877 if (fabs(determinant) < MagickEpsilon)
878 (void) ThrowMagickException(exception,GetMagickModule(),OptionError,
879 "InvalidArgument",
"'%s' : 'Indeterminate Matrix'",geometry);
922MagickExport MagickStatusType ParseGeometry(
const char *geometry,
927 pedantic_geometry[MagickPathExtent],
946 (void) memset(geometry_info,0,
sizeof(*geometry_info));
948 if ((geometry == (
char *) NULL) || (*geometry ==
'\0'))
950 if (strlen(geometry) >= (MagickPathExtent-1))
952 c=sscanf(geometry,
"%lf%*[ ,]%lf%*[ ,]%lf%*[ ,]%lf",&coordinate.rho,
953 &coordinate.sigma,&coordinate.xi,&coordinate.psi);
959 geometry_info->rho=coordinate.rho;
960 geometry_info->sigma=coordinate.sigma;
961 geometry_info->xi=coordinate.xi;
962 geometry_info->psi=coordinate.psi;
963 flags|=RhoValue | SigmaValue | XiValue | PsiValue;
966 (void) CopyMagickString(pedantic_geometry,geometry,MagickPathExtent);
967 for (p=pedantic_geometry; *p !=
'\0'; )
969 c=(int) ((
unsigned char) *p);
970 if (isspace((
int) ((
unsigned char) c)) != 0)
972 (void) CopyMagickString(p,p+1,MagickPathExtent);
980 (void) CopyMagickString(p,p+1,MagickPathExtent);
986 (void) CopyMagickString(p,p+1,MagickPathExtent);
992 (void) CopyMagickString(p,p+1,MagickPathExtent);
998 (void) CopyMagickString(p,p+1,MagickPathExtent);
1003 flags|=MaximumValue;
1004 (void) CopyMagickString(p,p+1,MagickPathExtent);
1009 flags|=MinimumValue;
1010 (void) CopyMagickString(p,p+1,MagickPathExtent);
1016 (void) CopyMagickString(p,p+1,MagickPathExtent);
1023 (void) CopyMagickString(p,p+1,MagickPathExtent);
1028 (void) CopyMagickString(p,p+1,MagickPathExtent);
1034 flags|=SeparatorValue;
1062 flags|=DecimalValue;
1068 flags|=AspectRatioValue;
1078 p=pedantic_geometry;
1082 value=StringToDouble(p,&q);
1083 if (LocaleNCompare(p,
"0x",2) == 0)
1084 (void) strtol(p,&q,10);
1085 c=(int) ((
unsigned char) *q);
1086 if ((c == 215) || (*q ==
'x') || (*q ==
'X') || (*q ==
':') ||
1087 (*q ==
',') || (*q ==
'/') || (*q ==
'\0'))
1093 if (LocaleNCompare(p,
"0x",2) == 0)
1094 value=(double) strtol(p,&p,10);
1096 value=StringToDouble(p,&p);
1100 geometry_info->rho=value;
1104 c=(int) ((
unsigned char) *p);
1105 if ((c == 215) || (*p ==
'x') || (*p ==
'X') || (*p ==
':') || (*p ==
',') ||
1112 while (isspace((
int) ((
unsigned char) *p)) != 0)
1114 c=(int) ((
unsigned char) *q);
1115 if (((c != 215) && (*q !=
'x') && (*q !=
'X') && (*q !=
':')) ||
1116 ((*p !=
'+') && (*p !=
'-')))
1119 value=StringToDouble(p,&p);
1123 geometry_info->sigma=value;
1127 while (isspace((
int) ((
unsigned char) *p)) != 0)
1129 if ((*p ==
'+') || (*p ==
'-') || (*p ==
',') || (*p ==
'/') || (*p ==
':'))
1134 if ((*p ==
',') || (*p ==
'/') || (*p ==
':') )
1136 while ((*p ==
'+') || (*p ==
'-'))
1143 value=StringToDouble(p,&p);
1147 if ((flags & XiNegative) != 0)
1149 geometry_info->xi=value;
1151 while (isspace((
int) ((
unsigned char) *p)) != 0)
1153 if ((*p ==
'+') || (*p ==
'-') || (*p ==
',') || (*p ==
'/') ||
1159 if ((*p ==
',') || (*p ==
'/') || (*p ==
':'))
1161 while ((*p ==
'+') || (*p ==
'-'))
1168 value=StringToDouble(p,&p);
1172 if ((flags & PsiNegative) != 0)
1174 geometry_info->psi=value;
1177 while (isspace((
int) ((
unsigned char) *p)) != 0)
1179 if ((*p ==
'+') || (*p ==
'-') || (*p ==
',') || (*p ==
'/') ||
1185 if ((*p ==
',') || (*p ==
'/') || (*p ==
':'))
1187 while ((*p ==
'+') || (*p ==
'-'))
1194 value=StringToDouble(p,&p);
1198 if ((flags & ChiNegative) != 0)
1200 geometry_info->chi=value;
1204 if (strchr(pedantic_geometry,
':') != (
char *) NULL)
1209 if ((flags & SigmaValue) != 0)
1210 geometry_info->rho*=PerceptibleReciprocal(geometry_info->sigma);
1211 geometry_info->sigma=1.0;
1212 if (((flags & XiValue) != 0) && (geometry_info->xi == 0.0))
1213 geometry_info->sigma=2.0;
1215 if (((flags & RhoValue) != 0) && ((flags & SigmaValue) == 0) &&
1216 ((flags & XiValue) != 0) && ((flags & XiNegative) != 0))
1218 if ((flags & PsiValue) == 0)
1223 geometry_info->sigma=geometry_info->xi;
1224 geometry_info->xi=0.0;
1226 flags&=(
unsigned int) (~XiValue);
1229 if ((flags & ChiValue) == 0)
1234 geometry_info->sigma=geometry_info->xi;
1235 geometry_info->xi=geometry_info->psi;
1238 flags&=(
unsigned int) (~PsiValue);
1245 geometry_info->sigma=geometry_info->xi;
1246 geometry_info->xi=geometry_info->psi;
1247 geometry_info->psi=geometry_info->chi;
1251 flags&=(
unsigned int) (~ChiValue);
1254 if ((flags & PercentValue) != 0)
1256 if (((flags & SeparatorValue) == 0) && ((flags & SigmaValue) == 0))
1257 geometry_info->sigma=geometry_info->rho;
1258 if (((flags & SeparatorValue) != 0) && ((flags & RhoValue) == 0))
1259 geometry_info->rho=geometry_info->sigma;
1263 (void) fprintf(stderr,
"ParseGeometry...\n");
1264 (void) fprintf(stderr,
"Flags: %c %c %s %s %s\n",
1265 (flags & RhoValue) ?
'W' :
' ',(flags & SigmaValue) ?
'H' :
' ',
1266 (flags & XiValue) ? ((flags & XiNegative) ?
"-X" :
"+X") :
" ",
1267 (flags & PsiValue) ? ((flags & PsiNegative) ?
"-Y" :
"+Y") :
" ",
1268 (flags & ChiValue) ? ((flags & ChiNegative) ?
"-Z" :
"+Z") :
" ");
1269 (void) fprintf(stderr,
"Geometry: %lg,%lg,%lg,%lg,%lg\n",geometry_info->rho,
1270 geometry_info->sigma,geometry_info->xi,geometry_info->psi,
1271 geometry_info->chi);
1313MagickExport MagickStatusType ParseGravityGeometry(
const Image *image,
1323 if (IsEventLogging() != MagickFalse)
1324 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",geometry);
1325 if ((geometry == (
char *) NULL) || (*geometry ==
'\0'))
1327 SetGeometry(image,region_info);
1328 if (image->page.width != 0)
1329 region_info->width=image->page.width;
1330 if (image->page.height != 0)
1331 region_info->height=image->page.height;
1332 flags=ParseAbsoluteGeometry(geometry,region_info);
1333 if (flags == NoValue)
1335 (void) ThrowMagickException(exception,GetMagickModule(),OptionError,
1336 "InvalidGeometry",
"`%s'",geometry);
1339 if ((flags & PercentValue) != 0)
1353 if (image->gravity != UndefinedGravity)
1354 flags|=XValue | YValue;
1355 status=ParseGeometry(geometry,&geometry_info);
1356 scale.x=geometry_info.rho;
1357 if ((status & RhoValue) == 0)
1359 scale.y=geometry_info.sigma;
1360 if ((status & SigmaValue) == 0)
1362 region_info->width=CastDoubleToUnsigned(scale.x*image->columns/100.0+0.5);
1363 region_info->height=CastDoubleToUnsigned(scale.y*image->rows/100.0+0.5);
1365 if ((flags & AspectRatioValue) != 0)
1377 if (image->gravity != UndefinedGravity)
1378 flags|=XValue | YValue;
1379 (void) ParseGeometry(geometry,&geometry_info);
1380 geometry_ratio=geometry_info.rho;
1381 image_ratio=(double) image->columns/image->rows;
1382 region_info->width=image->columns;
1383 region_info->height=image->rows;
1384 if ((flags & MaximumValue) != 0)
1386 if (geometry_ratio < image_ratio)
1387 region_info->height=CastDoubleToUnsigned((
double) image->rows*
1388 image_ratio/geometry_ratio+0.5);
1390 region_info->width=CastDoubleToUnsigned((
double) image->columns*
1391 geometry_ratio/image_ratio+0.5);
1394 if (geometry_ratio >= image_ratio)
1395 region_info->height=CastDoubleToUnsigned((
double) image->rows*
1396 image_ratio/geometry_ratio+0.5);
1398 region_info->width=CastDoubleToUnsigned((
double) image->columns*
1399 geometry_ratio/image_ratio+0.5);
1404 width=region_info->width;
1405 height=region_info->height;
1407 region_info->width=image->page.width | image->columns;
1409 region_info->height=image->page.height | image->rows;
1410 GravityAdjustGeometry(image->columns,image->rows,image->gravity,region_info);
1411 if ((flags & LessValue) != 0)
1412 if ((region_info->width < image->columns) &&
1413 (region_info->height < image->rows))
1415 SetGeometry(image,region_info);
1418 if ((flags & GreaterValue) != 0)
1419 if ((region_info->width > image->columns) &&
1420 (region_info->height > image->rows))
1422 SetGeometry(image,region_info);
1425 region_info->width=width;
1426 region_info->height=height;
1473MagickExport MagickStatusType ParseMetaGeometry(
const char *geometry,ssize_t *x,
1474 ssize_t *y,
size_t *width,
size_t *height)
1489 assert(x != (ssize_t *) NULL);
1490 assert(y != (ssize_t *) NULL);
1491 assert(width != (
size_t *) NULL);
1492 assert(height != (
size_t *) NULL);
1493 if (IsEventLogging() != MagickFalse)
1494 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",geometry);
1495 if ((geometry == (
char *) NULL) || (*geometry ==
'\0'))
1500 stasis_width=(*width);
1501 stasis_height=(*height);
1502 SetGeometryInfo(&geometry_info);
1503 flags=GetGeometry(geometry,x,y,width,height);
1504 if ((flags & PercentValue) != 0)
1515 percent_flags=ParseGeometry(geometry,&geometry_info);
1516 scale.x=geometry_info.rho;
1517 if ((percent_flags & RhoValue) == 0)
1519 scale.y=geometry_info.sigma;
1520 if ((percent_flags & SigmaValue) == 0)
1522 *width=CastDoubleToUnsigned(scale.x*stasis_width/100.0+0.5);
1523 *height=CastDoubleToUnsigned(scale.y*stasis_height/100.0+0.5);
1524 stasis_width=(*width);
1525 stasis_height=(*height);
1527 if ((flags & AspectRatioValue) != 0)
1536 (void) ParseGeometry(geometry,&geometry_info);
1537 geometry_ratio=geometry_info.rho;
1538 image_ratio=(double) stasis_width*PerceptibleReciprocal((
double)
1540 if (geometry_ratio >= image_ratio)
1542 *width=stasis_width;
1543 *height=CastDoubleToUnsigned((
double) (PerceptibleReciprocal(
1544 geometry_ratio)*stasis_height*image_ratio)+0.5);
1548 *width=CastDoubleToUnsigned(PerceptibleReciprocal(image_ratio)*
1549 stasis_width*geometry_ratio+0.5);
1550 *height=stasis_height;
1552 stasis_width=(*width);
1553 stasis_height=(*height);
1555 if (((flags & AspectValue) != 0) || ((*width == stasis_width) &&
1556 (*height == stasis_height)))
1558 if ((flags & RhoValue) == 0)
1559 *width=stasis_width;
1560 if ((flags & SigmaValue) == 0)
1561 *height=stasis_height;
1571 if ((stasis_width == 0) || (stasis_height == 0))
1574 if (((flags & RhoValue) != 0) && (flags & SigmaValue) != 0)
1576 scale_factor=(double) *width/(
double) stasis_width;
1577 if ((flags & MinimumValue) == 0)
1579 if (scale_factor > ((
double) *height/(
double) stasis_height))
1580 scale_factor=(double) *height/(
double) stasis_height;
1583 if (scale_factor < ((
double) *height/(
double) stasis_height))
1584 scale_factor=(double) *height/(
double) stasis_height;
1587 if ((flags & RhoValue) != 0)
1589 scale_factor=(double) *width/(
double) stasis_width;
1590 if (((flags & MinimumValue) != 0) &&
1591 (scale_factor < ((
double) *width/(
double) stasis_height)))
1592 scale_factor=(double) *width/(
double) stasis_height;
1596 scale_factor=(double) *height/(
double) stasis_height;
1597 if (((flags & MinimumValue) != 0) &&
1598 (scale_factor < ((
double) *height/(
double) stasis_width)))
1599 scale_factor=(double) *height/(
double) stasis_width;
1601 *width=CastDoubleToUnsigned(MagickMax(floor(scale_factor*stasis_width+
1603 *height=CastDoubleToUnsigned(MagickMax(floor(scale_factor*stasis_height+
1606 if ((flags & GreaterValue) != 0)
1608 if (stasis_width < *width)
1609 *width=stasis_width;
1610 if (stasis_height < *height)
1611 *height=stasis_height;
1613 if ((flags & LessValue) != 0)
1615 if (stasis_width > *width)
1616 *width=stasis_width;
1617 if (stasis_height > *height)
1618 *height=stasis_height;
1620 if ((flags & AreaValue) != 0)
1632 (void) ParseGeometry(geometry,&geometry_info);
1633 area=geometry_info.rho+sqrt(MagickEpsilon);
1634 distance=sqrt((
double) stasis_width*stasis_height);
1635 scale.x=(double) stasis_width*PerceptibleReciprocal(distance*
1636 PerceptibleReciprocal(sqrt(area)));
1637 scale.y=(double) stasis_height*PerceptibleReciprocal(distance*
1638 PerceptibleReciprocal(sqrt(area)));
1639 if ((scale.x < (
double) *width) || (scale.y < (
double) *height))
1641 *width=CastDoubleToUnsigned((
double) stasis_width*PerceptibleReciprocal(
1642 distance*PerceptibleReciprocal(sqrt(area)))+0.5);
1643 *height=CastDoubleToUnsigned((
double) stasis_height*PerceptibleReciprocal(
1644 distance*PerceptibleReciprocal(sqrt(area)))+0.5);
1683MagickExport MagickStatusType ParsePageGeometry(
const Image *image,
1689 SetGeometry(image,region_info);
1690 if (image->page.width != 0)
1691 region_info->width=image->page.width;
1692 if (image->page.height != 0)
1693 region_info->height=image->page.height;
1694 flags=ParseAbsoluteGeometry(geometry,region_info);
1695 if (flags == NoValue)
1697 (void) ThrowMagickException(exception,GetMagickModule(),OptionError,
1698 "InvalidGeometry",
"`%s'",geometry);
1701 if ((flags & PercentValue) != 0)
1703 region_info->width=image->columns;
1704 region_info->height=image->rows;
1706 flags=ParseMetaGeometry(geometry,®ion_info->x,®ion_info->y,
1707 ®ion_info->width,®ion_info->height);
1708 if ((((flags & WidthValue) != 0) || ((flags & HeightValue) != 0)) &&
1709 (((flags & PercentValue) != 0) || ((flags & SeparatorValue) == 0)))
1711 if ((flags & WidthValue) == 0)
1712 region_info->width=region_info->height;
1713 if ((flags & HeightValue) == 0)
1714 region_info->height=region_info->width;
1752MagickExport MagickStatusType ParseRegionGeometry(
const Image *image,
1758 SetGeometry(image,region_info);
1759 flags=ParseMetaGeometry(geometry,®ion_info->x,®ion_info->y,
1760 ®ion_info->width,®ion_info->height);
1761 if (flags == NoValue)
1762 (void) ThrowMagickException(exception,GetMagickModule(),OptionError,
1763 "InvalidGeometry",
"`%s'",geometry);
1793 assert(image != (
Image *) NULL);
1794 assert(image->signature == MagickCoreSignature);
1795 if (IsEventLogging() != MagickFalse)
1796 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",image->filename);
1798 (void) memset(geometry,0,
sizeof(*geometry));
1799 geometry->width=image->columns;
1800 geometry->height=image->rows;
1825MagickExport
void SetGeometryInfo(
GeometryInfo *geometry_info)
1828 if (IsEventLogging() != MagickFalse)
1829 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
1830 (void) memset(geometry_info,0,
sizeof(*geometry_info));