42 #include "magick/studio.h"
43 #include "magick/constitute.h"
44 #include "magick/draw.h"
45 #include "magick/exception.h"
46 #include "magick/exception-private.h"
47 #include "magick/geometry.h"
48 #include "magick/image-private.h"
49 #include "magick/memory_.h"
50 #include "magick/pixel-accessor.h"
51 #include "magick/string_.h"
52 #include "magick/string-private.h"
53 #include "magick/token.h"
97 MagickExport MagickStatusType GetGeometry(
const char *geometry,ssize_t *x,
98 ssize_t *y,
size_t *width,
size_t *height)
102 pedantic_geometry[MaxTextExtent],
118 if ((geometry == (
char *) NULL) || (*geometry ==
'\0'))
120 if (strlen(geometry) >= (MaxTextExtent-1))
122 (void) CopyMagickString(pedantic_geometry,geometry,MaxTextExtent);
123 for (p=pedantic_geometry; *p !=
'\0'; )
125 if (isspace((
int) ((
unsigned char) *p)) != 0)
127 (void) CopyMagickString(p,p+1,MaxTextExtent);
136 (void) CopyMagickString(p,p+1,MaxTextExtent);
142 (void) CopyMagickString(p,p+1,MaxTextExtent);
148 (void) CopyMagickString(p,p+1,MaxTextExtent);
154 (void) CopyMagickString(p,p+1,MaxTextExtent);
160 (void) CopyMagickString(p,p+1,MaxTextExtent);
166 (void) CopyMagickString(p,p+1,MaxTextExtent);
173 (void) CopyMagickString(p,p+1,MaxTextExtent);
178 (void) CopyMagickString(p,p+1,MaxTextExtent);
184 flags|=SeparatorValue;
217 flags|=AspectRatioValue;
231 value=StringToDouble(p,&q);
233 if (LocaleNCompare(p,
"0x",2) == 0)
234 value=(
double) strtol(p,&q,10);
235 if ((*p !=
'+') && (*p !=
'-'))
237 c=(int) ((
unsigned char) *q);
238 if ((c == 215) || (*q ==
'x') || (*q ==
'X') || (*q ==
':') ||
245 if (width != (
size_t *) NULL)
247 if (LocaleNCompare(p,
"0x",2) == 0)
248 *width=(
size_t) strtol(p,&p,10);
250 *width=((size_t) floor(StringToDouble(p,&p)+0.5)) & 0x7fffffff;
256 if ((*p !=
'+') && (*p !=
'-'))
258 c=(int) ((
unsigned char) *p);
259 if ((c == 215) || (*p ==
'x') || (*p ==
'X') || (*p ==
':'))
262 if ((*p !=
'+') && (*p !=
'-'))
268 if (height != (
size_t *) NULL)
269 *height=((
size_t) floor(StringToDouble(p,&p)+0.5)) & 0x7fffffff;
275 if ((*p ==
'+') || (*p ==
'-'))
280 while ((*p ==
'+') || (*p ==
'-'))
287 if (x != (ssize_t *) NULL)
288 *x=((ssize_t) ceil(StringToDouble(p,&p)-0.5)) & 0x7fffffff;
292 if (((flags & XNegative) != 0) && (x != (ssize_t *) NULL))
296 if ((*p ==
'+') || (*p ==
'-'))
301 while ((*p ==
'+') || (*p ==
'-'))
308 if (y != (ssize_t *) NULL)
309 *y=((ssize_t) ceil(StringToDouble(p,&p)-0.5)) & 0x7fffffff;
313 if (((flags & YNegative) != 0) && (y != (ssize_t *) NULL))
317 if ((flags & PercentValue) != 0)
319 if (((flags & SeparatorValue) == 0) && ((flags & HeightValue) == 0))
321 if ((height != (
size_t *) NULL) && (width != (
size_t *) NULL))
325 if (((flags & SeparatorValue) != 0) && ((flags & WidthValue) == 0) &&
326 (height != (
size_t *) NULL) && (width != (
size_t *) NULL))
333 (void) fprintf(stderr,
"GetGeometry...\n");
334 (void) fprintf(stderr,
"Input: %s\n",geometry);
335 (void) fprintf(stderr,
"Flags: %c %c %s %s\n",
336 (flags & WidthValue) ?
'W' :
' ',(flags & HeightValue) ?
'H' :
' ',
337 (flags & XValue) ? ((flags & XNegative) ?
"-X" :
"+X") :
" ",
338 (flags & YValue) ? ((flags & YNegative) ?
"-Y" :
"+Y") :
" ");
339 (void) fprintf(stderr,
"Geometry: %ldx%ld%+ld%+ld\n",(
long) *width,(long)
340 *height,(
long) *x,(long) *y);
370 MagickExport
char *GetPageGeometry(
const char *page_geometry)
372 #define MagickPageSize(name,geometry) { (name), sizeof(name)-1, (geometry) }
374 typedef struct _PageInfo
386 static const PageInfo
389 MagickPageSize(
"4x6",
"288x432"),
390 MagickPageSize(
"5x7",
"360x504"),
391 MagickPageSize(
"7x9",
"504x648"),
392 MagickPageSize(
"8x10",
"576x720"),
393 MagickPageSize(
"9x11",
"648x792"),
394 MagickPageSize(
"9x12",
"648x864"),
395 MagickPageSize(
"10x13",
"720x936"),
396 MagickPageSize(
"10x14",
"720x1008"),
397 MagickPageSize(
"11x17",
"792x1224"),
398 MagickPageSize(
"4A0",
"4768x6741"),
399 MagickPageSize(
"2A0",
"3370x4768"),
400 MagickPageSize(
"a0",
"2384x3370"),
401 MagickPageSize(
"a1",
"1684x2384"),
402 MagickPageSize(
"a2",
"1191x1684"),
403 MagickPageSize(
"a3",
"842x1191"),
404 MagickPageSize(
"a4",
"595x842"),
405 MagickPageSize(
"a4small",
"595x842"),
406 MagickPageSize(
"a5",
"420x595"),
407 MagickPageSize(
"a6",
"298x420"),
408 MagickPageSize(
"a7",
"210x298"),
409 MagickPageSize(
"a8",
"147x210"),
410 MagickPageSize(
"a9",
"105x147"),
411 MagickPageSize(
"a10",
"74x105"),
412 MagickPageSize(
"archa",
"648x864"),
413 MagickPageSize(
"archb",
"864x1296"),
414 MagickPageSize(
"archC",
"1296x1728"),
415 MagickPageSize(
"archd",
"1728x2592"),
416 MagickPageSize(
"arche",
"2592x3456"),
417 MagickPageSize(
"b0",
"2920x4127"),
418 MagickPageSize(
"b1",
"2064x2920"),
419 MagickPageSize(
"b10",
"91x127"),
420 MagickPageSize(
"b2",
"1460x2064"),
421 MagickPageSize(
"b3",
"1032x1460"),
422 MagickPageSize(
"b4",
"729x1032"),
423 MagickPageSize(
"b5",
"516x729"),
424 MagickPageSize(
"b6",
"363x516"),
425 MagickPageSize(
"b7",
"258x363"),
426 MagickPageSize(
"b8",
"181x258"),
427 MagickPageSize(
"b9",
"127x181"),
428 MagickPageSize(
"c0",
"2599x3676"),
429 MagickPageSize(
"c1",
"1837x2599"),
430 MagickPageSize(
"c2",
"1298x1837"),
431 MagickPageSize(
"c3",
"918x1296"),
432 MagickPageSize(
"c4",
"649x918"),
433 MagickPageSize(
"c5",
"459x649"),
434 MagickPageSize(
"c6",
"323x459"),
435 MagickPageSize(
"c7",
"230x323"),
436 MagickPageSize(
"csheet",
"1224x1584"),
437 MagickPageSize(
"dsheet",
"1584x2448"),
438 MagickPageSize(
"esheet",
"2448x3168"),
439 MagickPageSize(
"executive",
"540x720"),
440 MagickPageSize(
"flsa",
"612x936"),
441 MagickPageSize(
"flse",
"612x936"),
442 MagickPageSize(
"folio",
"612x936"),
443 MagickPageSize(
"halfletter",
"396x612"),
444 MagickPageSize(
"isob0",
"2835x4008"),
445 MagickPageSize(
"isob1",
"2004x2835"),
446 MagickPageSize(
"isob10",
"88x125"),
447 MagickPageSize(
"isob2",
"1417x2004"),
448 MagickPageSize(
"isob3",
"1001x1417"),
449 MagickPageSize(
"isob4",
"709x1001"),
450 MagickPageSize(
"isob5",
"499x709"),
451 MagickPageSize(
"isob6",
"354x499"),
452 MagickPageSize(
"isob7",
"249x354"),
453 MagickPageSize(
"isob8",
"176x249"),
454 MagickPageSize(
"isob9",
"125x176"),
455 MagickPageSize(
"jisb0",
"1030x1456"),
456 MagickPageSize(
"jisb1",
"728x1030"),
457 MagickPageSize(
"jisb2",
"515x728"),
458 MagickPageSize(
"jisb3",
"364x515"),
459 MagickPageSize(
"jisb4",
"257x364"),
460 MagickPageSize(
"jisb5",
"182x257"),
461 MagickPageSize(
"jisb6",
"128x182"),
462 MagickPageSize(
"ledger",
"1224x792"),
463 MagickPageSize(
"legal",
"612x1008"),
464 MagickPageSize(
"letter",
"612x792"),
465 MagickPageSize(
"lettersmall",
"612x792"),
466 MagickPageSize(
"monarch",
"279x540"),
467 MagickPageSize(
"quarto",
"610x780"),
468 MagickPageSize(
"statement",
"396x612"),
469 MagickPageSize(
"tabloid",
"792x1224")
478 assert(page_geometry != (
char *) NULL);
479 if (IsEventLogging() != MagickFalse)
480 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",page_geometry);
481 (void) CopyMagickString(page,page_geometry,MaxTextExtent);
482 for (i=0; i < (ssize_t) (
sizeof(PageSizes)/
sizeof(PageSizes[0])); i++)
487 status=LocaleNCompare(PageSizes[i].name,page_geometry,PageSizes[i].extent);
499 (void) FormatLocaleString(page,MaxTextExtent,
"%s%.80s",
500 PageSizes[i].geometry,page_geometry+PageSizes[i].extent);
501 flags=GetGeometry(page,&geometry.x,&geometry.y,&geometry.width,
503 if ((flags & GreaterValue) == 0)
504 (void) ConcatenateMagickString(page,
">",MaxTextExtent);
508 return(AcquireString(page));
542 MagickExport
void GravityAdjustGeometry(
const size_t width,
543 const size_t height,
const GravityType gravity,
RectangleInfo *region)
545 if (region->height == 0)
546 region->height=height;
547 if (region->width == 0)
551 case NorthEastGravity:
553 case SouthEastGravity:
555 region->x=(ssize_t) (width-region->width-region->x);
563 region->x+=(ssize_t) (width/2-region->width/2);
567 case NorthWestGravity:
569 case SouthWestGravity:
575 case SouthWestGravity:
577 case SouthEastGravity:
579 region->y=(ssize_t) (height-region->height-region->y);
587 region->y+=(ssize_t) (height/2-region->height/2);
591 case NorthWestGravity:
593 case NorthEastGravity:
623 MagickExport MagickBooleanType IsGeometry(
const char *geometry)
631 if (geometry == (
const char *) NULL)
633 flags=ParseGeometry(geometry,&geometry_info);
634 return(flags != NoValue ? MagickTrue : MagickFalse);
664 MagickExport MagickBooleanType IsSceneGeometry(
const char *geometry,
665 const MagickBooleanType pedantic)
673 if (geometry == (
const char *) NULL)
676 value=StringToDouble(geometry,&p);
677 if (IsNaN(value) != 0)
679 if (value > (
double) MAGICK_SSIZE_MAX)
681 if (value < (
double) MAGICK_SSIZE_MIN)
685 if (strspn(geometry,
"0123456789-, ") != strlen(geometry))
687 if ((pedantic != MagickFalse) && (strchr(geometry,
',') != (
char *) NULL))
721 MagickExport MagickStatusType ParseAbsoluteGeometry(
const char *geometry,
727 flags=GetGeometry(geometry,®ion_info->x,®ion_info->y,
728 ®ion_info->width,®ion_info->height);
762 MagickExport MagickStatusType ParseAffineGeometry(
const char *geometry,
766 token[MaxTextExtent];
780 GetAffineMatrix(affine_matrix);
783 for (i=0; (*p !=
'\0') && (i < 6); i++)
785 (void) GetNextToken(p,&p,MaxTextExtent,token);
787 (void) GetNextToken(p,&p,MaxTextExtent,token);
792 affine_matrix->sx=StringToDouble(token,(
char **) NULL);
797 affine_matrix->rx=StringToDouble(token,(
char **) NULL);
802 affine_matrix->ry=StringToDouble(token,(
char **) NULL);
807 affine_matrix->sy=StringToDouble(token,(
char **) NULL);
812 affine_matrix->tx=StringToDouble(token,(
char **) NULL);
818 affine_matrix->ty=StringToDouble(token,(
char **) NULL);
824 determinant=(affine_matrix->sx*affine_matrix->sy-affine_matrix->rx*
826 if (fabs(determinant) < MagickEpsilon)
827 (
void) ThrowMagickException(exception,GetMagickModule(),OptionError,
828 "InvalidArgument",
"'%s' : 'Indeterminate Matrix'",geometry);
871 MagickExport MagickStatusType ParseGeometry(
const char *geometry,
876 pedantic_geometry[MaxTextExtent],
892 (void) memset(geometry_info,0,
sizeof(*geometry_info));
894 if ((geometry == (
char *) NULL) || (*geometry ==
'\0'))
896 if (strlen(geometry) >= (MaxTextExtent-1))
898 (void) CopyMagickString(pedantic_geometry,geometry,MaxTextExtent);
899 for (p=pedantic_geometry; *p !=
'\0'; )
901 c=(int) ((
unsigned char) *p);
902 if (isspace((
int) ((
unsigned char) c)) != 0)
904 (void) CopyMagickString(p,p+1,MaxTextExtent);
912 (void) CopyMagickString(p,p+1,MaxTextExtent);
918 (void) CopyMagickString(p,p+1,MaxTextExtent);
924 (void) CopyMagickString(p,p+1,MaxTextExtent);
930 (void) CopyMagickString(p,p+1,MaxTextExtent);
936 (void) CopyMagickString(p,p+1,MaxTextExtent);
942 (void) CopyMagickString(p,p+1,MaxTextExtent);
949 (void) CopyMagickString(p,p+1,MaxTextExtent);
954 (void) CopyMagickString(p,p+1,MaxTextExtent);
960 flags|=SeparatorValue;
994 flags|=AspectRatioValue;
1004 p=pedantic_geometry;
1008 value=StringToDouble(p,&q);
1009 if (LocaleNCompare(p,
"0x",2) == 0)
1010 (void) strtol(p,&q,10);
1011 c=(int) ((
unsigned char) *q);
1012 if ((c == 215) || (*q ==
'x') || (*q ==
'X') || (*q ==
':') ||
1013 (*q ==
',') || (*q ==
'/') || (*q ==
'\0'))
1019 if (LocaleNCompare(p,
"0x",2) == 0)
1020 value=(
double) strtol(p,&p,10);
1022 value=StringToDouble(p,&p);
1026 geometry_info->rho=value;
1030 c=(int) ((
unsigned char) *p);
1031 if ((c == 215) || (*p ==
'x') || (*p ==
'X') || (*p ==
':') || (*p ==
',') ||
1038 while (isspace((
int) ((
unsigned char) *p)) != 0)
1040 c=(int) ((
unsigned char) *q);
1041 if (((c != 215) && (*q !=
'x') && (*q !=
'X') && (*q !=
':')) ||
1042 ((*p !=
'+') && (*p !=
'-')))
1045 value=StringToDouble(p,&p);
1049 geometry_info->sigma=value;
1053 while (isspace((
int) ((
unsigned char) *p)) != 0)
1055 if ((*p ==
'+') || (*p ==
'-') || (*p ==
',') || (*p ==
'/') || (*p ==
':'))
1060 if ((*p ==
',') || (*p ==
'/') || (*p ==
':') )
1062 while ((*p ==
'+') || (*p ==
'-'))
1069 value=StringToDouble(p,&p);
1073 if ((flags & XiNegative) != 0)
1075 geometry_info->xi=value;
1077 while (isspace((
int) ((
unsigned char) *p)) != 0)
1079 if ((*p ==
'+') || (*p ==
'-') || (*p ==
',') || (*p ==
'/') ||
1085 if ((*p ==
',') || (*p ==
'/') || (*p ==
':'))
1087 while ((*p ==
'+') || (*p ==
'-'))
1094 value=StringToDouble(p,&p);
1098 if ((flags & PsiNegative) != 0)
1100 geometry_info->psi=value;
1103 while (isspace((
int) ((
unsigned char) *p)) != 0)
1105 if ((*p ==
'+') || (*p ==
'-') || (*p ==
',') || (*p ==
'/') ||
1111 if ((*p ==
',') || (*p ==
'/') || (*p ==
':'))
1113 while ((*p ==
'+') || (*p ==
'-'))
1120 value=StringToDouble(p,&p);
1124 if ((flags & ChiNegative) != 0)
1126 geometry_info->chi=value;
1130 if (strchr(pedantic_geometry,
':') != (
char *) NULL)
1135 if ((flags & SigmaValue) != 0)
1136 geometry_info->rho*=PerceptibleReciprocal(geometry_info->sigma);
1137 geometry_info->sigma=1.0;
1138 if (((flags & XiValue) != 0) && (geometry_info->xi == 0.0))
1139 geometry_info->sigma=2.0;
1141 if (((flags & RhoValue) != 0) && ((flags & SigmaValue) == 0) &&
1142 ((flags & XiValue) != 0) && ((flags & XiNegative) != 0))
1144 if ((flags & PsiValue) == 0)
1149 geometry_info->sigma=geometry_info->xi;
1150 geometry_info->xi=0.0;
1155 if ((flags & ChiValue) == 0)
1160 geometry_info->sigma=geometry_info->xi;
1161 geometry_info->xi=geometry_info->psi;
1171 geometry_info->sigma=geometry_info->xi;
1172 geometry_info->xi=geometry_info->psi;
1173 geometry_info->psi=geometry_info->chi;
1180 if ((flags & PercentValue) != 0)
1182 if (((flags & SeparatorValue) == 0) && ((flags & SigmaValue) == 0))
1183 geometry_info->sigma=geometry_info->rho;
1184 if (((flags & SeparatorValue) != 0) && ((flags & RhoValue) == 0))
1185 geometry_info->rho=geometry_info->sigma;
1189 (void) fprintf(stderr,
"ParseGeometry...\n");
1190 (void) fprintf(stderr,
"Flags: %c %c %s %s %s\n",
1191 (flags & RhoValue) ?
'W' :
' ',(flags & SigmaValue) ?
'H' :
' ',
1192 (flags & XiValue) ? ((flags & XiNegative) ?
"-X" :
"+X") :
" ",
1193 (flags & PsiValue) ? ((flags & PsiNegative) ?
"-Y" :
"+Y") :
" ",
1194 (flags & ChiValue) ? ((flags & ChiNegative) ?
"-Z" :
"+Z") :
" ");
1195 (void) fprintf(stderr,
"Geometry: %lg,%lg,%lg,%lg,%lg\n",geometry_info->rho,
1196 geometry_info->sigma,geometry_info->xi,geometry_info->psi,
1197 geometry_info->chi);
1239 MagickExport MagickStatusType ParseGravityGeometry(
const Image *image,
1249 SetGeometry(image,region_info);
1250 if (image->page.width != 0)
1251 region_info->width=image->page.width;
1252 if (image->page.height != 0)
1253 region_info->height=image->page.height;
1254 flags=ParseAbsoluteGeometry(geometry,region_info);
1255 if (flags == NoValue)
1257 (void) ThrowMagickException(exception,GetMagickModule(),OptionError,
1258 "InvalidGeometry",
"`%s'",geometry);
1261 if ((flags & PercentValue) != 0)
1275 if (image->gravity != UndefinedGravity)
1276 flags|=XValue | YValue;
1277 status=ParseGeometry(geometry,&geometry_info);
1278 scale.x=geometry_info.rho;
1279 if ((status & RhoValue) == 0)
1281 scale.y=geometry_info.sigma;
1282 if ((status & SigmaValue) == 0)
1284 region_info->width=(size_t) floor((scale.x*image->columns/100.0)+0.5);
1285 region_info->height=(size_t) floor((scale.y*image->rows/100.0)+0.5);
1287 if ((flags & AspectRatioValue) != 0)
1299 if (image->gravity != UndefinedGravity)
1300 flags|=XValue | YValue;
1301 (void) ParseGeometry(geometry,&geometry_info);
1302 geometry_ratio=geometry_info.rho;
1303 image_ratio=(double) image->columns/image->rows;
1304 if (geometry_ratio >= image_ratio)
1306 region_info->width=image->columns;
1307 region_info->height=(size_t) floor((
double) (image->rows*image_ratio/
1308 geometry_ratio)+0.5);
1312 region_info->width=(size_t) floor((
double) (image->columns*
1313 geometry_ratio/image_ratio)+0.5);
1314 region_info->height=image->rows;
1320 width=region_info->width;
1321 height=region_info->height;
1323 region_info->width=image->page.width | image->columns;
1325 region_info->height=image->page.height | image->rows;
1326 GravityAdjustGeometry(image->columns,image->rows,image->gravity,region_info);
1327 region_info->width=width;
1328 region_info->height=height;
1375 MagickExport MagickStatusType ParseMetaGeometry(
const char *geometry,ssize_t *x,
1376 ssize_t *y,
size_t *width,
size_t *height)
1391 assert(x != (ssize_t *) NULL);
1392 assert(y != (ssize_t *) NULL);
1393 assert(width != (
size_t *) NULL);
1394 assert(height != (
size_t *) NULL);
1395 if ((geometry == (
char *) NULL) || (*geometry ==
'\0'))
1397 if (IsEventLogging() != MagickFalse)
1398 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",geometry);
1402 SetGeometryInfo(&geometry_info);
1403 former_width=(*width);
1404 former_height=(*height);
1405 flags=GetGeometry(geometry,x,y,width,height);
1406 if ((flags & PercentValue) != 0)
1417 flags=ParseGeometry(geometry,&geometry_info);
1418 scale.x=geometry_info.rho;
1419 if ((flags & RhoValue) == 0)
1421 scale.y=geometry_info.sigma;
1422 if ((flags & SigmaValue) == 0)
1424 *width=(size_t) floor(scale.x*former_width/100.0+0.5);
1425 *height=(size_t) floor(scale.y*former_height/100.0+0.5);
1426 former_width=(*width);
1427 former_height=(*height);
1429 if ((flags & AspectRatioValue) != 0)
1441 (void) ParseGeometry(geometry,&geometry_info);
1442 geometry_ratio=geometry_info.rho;
1443 image_ratio=(double) former_width*PerceptibleReciprocal(former_height);
1444 if (geometry_ratio >= image_ratio)
1446 *width=former_width;
1447 *height=(size_t) floor((
double) (PerceptibleReciprocal(
1448 geometry_ratio)*former_height*image_ratio)+0.5);
1452 *width=(size_t) floor((
double) (PerceptibleReciprocal(
1453 image_ratio)*former_width*geometry_ratio)+0.5);
1454 *height=former_height;
1456 former_width=(*width);
1457 former_height=(*height);
1459 if (((flags & AspectValue) != 0) || ((*width == former_width) &&
1460 (*height == former_height)))
1462 if ((flags & RhoValue) == 0)
1463 *width=former_width;
1464 if ((flags & SigmaValue) == 0)
1465 *height=former_height;
1475 if ((former_width == 0) || (former_height == 0))
1478 if (((flags & RhoValue) != 0) && (flags & SigmaValue) != 0)
1480 scale_factor=(double) *width/(
double) former_width;
1481 if ((flags & MinimumValue) == 0)
1483 if (scale_factor > ((
double) *height/(double) former_height))
1484 scale_factor=(
double) *height/(double) former_height;
1487 if (scale_factor < ((
double) *height/(double) former_height))
1488 scale_factor=(
double) *height/(double) former_height;
1491 if ((flags & RhoValue) != 0)
1493 scale_factor=(double) *width/(
double) former_width;
1494 if (((flags & MinimumValue) != 0) &&
1495 (scale_factor < ((
double) *width/(double) former_height)))
1496 scale_factor=(double) *width/(
double) former_height;
1500 scale_factor=(double) *height/(
double) former_height;
1501 if (((flags & MinimumValue) != 0) &&
1502 (scale_factor < ((
double) *height/(double) former_width)))
1503 scale_factor=(double) *height/(
double) former_width;
1505 *width=MagickMax((
size_t) floor(scale_factor*former_width+0.5),1UL);
1506 *height=MagickMax((
size_t) floor(scale_factor*former_height+0.5),1UL);
1508 if ((flags & GreaterValue) != 0)
1510 if (former_width < *width)
1511 *width=former_width;
1512 if (former_height < *height)
1513 *height=former_height;
1515 if ((flags & LessValue) != 0)
1517 if (former_width > *width)
1518 *width=former_width;
1519 if (former_height > *height)
1520 *height=former_height;
1522 if ((flags & AreaValue) != 0)
1534 (void) ParseGeometry(geometry,&geometry_info);
1535 area=geometry_info.rho+sqrt(MagickEpsilon);
1536 distance=sqrt((
double) former_width*former_height);
1537 scale.x=(double) former_width*PerceptibleReciprocal(distance*
1538 PerceptibleReciprocal(sqrt(area)));
1539 scale.y=(double) former_height*PerceptibleReciprocal(distance*
1540 PerceptibleReciprocal(sqrt(area)));
1541 if ((scale.x < (
double) *width) || (scale.y < (
double) *height))
1543 *width=(
unsigned long) (former_width*PerceptibleReciprocal(
1544 distance*PerceptibleReciprocal(sqrt(area))));
1545 *height=(
unsigned long) (former_height*PerceptibleReciprocal(
1546 distance*PerceptibleReciprocal(sqrt(area))));
1548 former_width=(*width);
1549 former_height=(*height);
1587 MagickExport MagickStatusType ParsePageGeometry(
const Image *image,
1593 SetGeometry(image,region_info);
1594 if (image->page.width != 0)
1595 region_info->width=image->page.width;
1596 if (image->page.height != 0)
1597 region_info->height=image->page.height;
1598 flags=ParseAbsoluteGeometry(geometry,region_info);
1599 if (flags == NoValue)
1601 (void) ThrowMagickException(exception,GetMagickModule(),OptionError,
1602 "InvalidGeometry",
"`%s'",geometry);
1605 if ((flags & PercentValue) != 0)
1607 region_info->width=image->columns;
1608 region_info->height=image->rows;
1610 flags=ParseMetaGeometry(geometry,®ion_info->x,®ion_info->y,
1611 ®ion_info->width,®ion_info->height);
1612 if ((((flags & WidthValue) != 0) || ((flags & HeightValue) != 0)) &&
1613 (((flags & PercentValue) != 0) || ((flags & SeparatorValue) == 0)))
1615 if ((flags & WidthValue) == 0)
1616 region_info->width=region_info->height;
1617 if ((flags & HeightValue) == 0)
1618 region_info->height=region_info->width;
1656 MagickExport MagickStatusType ParseRegionGeometry(
const Image *image,
1662 SetGeometry(image,region_info);
1663 flags=ParseMetaGeometry(geometry,®ion_info->x,®ion_info->y,
1664 ®ion_info->width,®ion_info->height);
1665 if (flags == NoValue)
1666 (void) ThrowMagickException(exception,GetMagickModule(),OptionError,
1667 "InvalidGeometry",
"`%s'",geometry);
1697 assert(image != (
Image *) NULL);
1698 assert(image->signature == MagickCoreSignature);
1699 if (IsEventLogging() != MagickFalse)
1700 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",image->filename);
1702 (void) memset(geometry,0,
sizeof(*geometry));
1703 geometry->width=image->columns;
1704 geometry->height=image->rows;
1729 MagickExport
void SetGeometryInfo(
GeometryInfo *geometry_info)
1732 if (IsEventLogging() != MagickFalse)
1733 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
1734 (void) memset(geometry_info,0,
sizeof(*geometry_info));