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/geometry-private.h"
49#include "magick/image-private.h"
50#include "magick/memory_.h"
51#include "magick/pixel-accessor.h"
52#include "magick/string_.h"
53#include "magick/string-private.h"
54#include "magick/token.h"
59#define MagickPagesize(name,geometry) { (name), sizeof(name)-1, (geometry) }
79 MagickPagesize(
"4x6",
"288x432"),
80 MagickPagesize(
"5x7",
"360x504"),
81 MagickPagesize(
"7x9",
"504x648"),
82 MagickPagesize(
"8x10",
"576x720"),
83 MagickPagesize(
"9x11",
"648x792"),
84 MagickPagesize(
"9x12",
"648x864"),
85 MagickPagesize(
"10x13",
"720x936"),
86 MagickPagesize(
"10x14",
"720x1008"),
87 MagickPagesize(
"11x17",
"792x1224"),
88 MagickPagesize(
"4A0",
"4768x6741"),
89 MagickPagesize(
"2A0",
"3370x4768"),
90 MagickPagesize(
"a0",
"2384x3370"),
91 MagickPagesize(
"a10",
"74x105"),
92 MagickPagesize(
"a1",
"1684x2384"),
93 MagickPagesize(
"a2",
"1191x1684"),
94 MagickPagesize(
"a3",
"842x1191"),
95 MagickPagesize(
"a4small",
"595x842"),
96 MagickPagesize(
"a4",
"595x842"),
97 MagickPagesize(
"a5",
"420x595"),
98 MagickPagesize(
"a6",
"298x420"),
99 MagickPagesize(
"a7",
"210x298"),
100 MagickPagesize(
"a8",
"147x210"),
101 MagickPagesize(
"a9",
"105x147"),
102 MagickPagesize(
"archa",
"648x864"),
103 MagickPagesize(
"archb",
"864x1296"),
104 MagickPagesize(
"archC",
"1296x1728"),
105 MagickPagesize(
"archd",
"1728x2592"),
106 MagickPagesize(
"arche",
"2592x3456"),
107 MagickPagesize(
"b0",
"2920x4127"),
108 MagickPagesize(
"b10",
"91x127"),
109 MagickPagesize(
"b1",
"2064x2920"),
110 MagickPagesize(
"b2",
"1460x2064"),
111 MagickPagesize(
"b3",
"1032x1460"),
112 MagickPagesize(
"b4",
"729x1032"),
113 MagickPagesize(
"b5",
"516x729"),
114 MagickPagesize(
"b6",
"363x516"),
115 MagickPagesize(
"b7",
"258x363"),
116 MagickPagesize(
"b8",
"181x258"),
117 MagickPagesize(
"b9",
"127x181"),
118 MagickPagesize(
"c0",
"2599x3676"),
119 MagickPagesize(
"c1",
"1837x2599"),
120 MagickPagesize(
"c2",
"1298x1837"),
121 MagickPagesize(
"c3",
"918x1296"),
122 MagickPagesize(
"c4",
"649x918"),
123 MagickPagesize(
"c5",
"459x649"),
124 MagickPagesize(
"c6",
"323x459"),
125 MagickPagesize(
"c7",
"230x323"),
126 MagickPagesize(
"csheet",
"1224x1584"),
127 MagickPagesize(
"dsheet",
"1584x2448"),
128 MagickPagesize(
"esheet",
"2448x3168"),
129 MagickPagesize(
"executive",
"540x720"),
130 MagickPagesize(
"flsa",
"612x936"),
131 MagickPagesize(
"flse",
"612x936"),
132 MagickPagesize(
"folio",
"612x936"),
133 MagickPagesize(
"halfletter",
"396x612"),
134 MagickPagesize(
"isob0",
"2835x4008"),
135 MagickPagesize(
"isob10",
"88x125"),
136 MagickPagesize(
"isob1",
"2004x2835"),
137 MagickPagesize(
"isob2",
"1417x2004"),
138 MagickPagesize(
"isob3",
"1001x1417"),
139 MagickPagesize(
"isob4",
"709x1001"),
140 MagickPagesize(
"isob5",
"499x709"),
141 MagickPagesize(
"isob6",
"354x499"),
142 MagickPagesize(
"isob7",
"249x354"),
143 MagickPagesize(
"isob8",
"176x249"),
144 MagickPagesize(
"isob9",
"125x176"),
145 MagickPagesize(
"jisb0",
"1030x1456"),
146 MagickPagesize(
"jisb1",
"728x1030"),
147 MagickPagesize(
"jisb2",
"515x728"),
148 MagickPagesize(
"jisb3",
"364x515"),
149 MagickPagesize(
"jisb4",
"257x364"),
150 MagickPagesize(
"jisb5",
"182x257"),
151 MagickPagesize(
"jisb6",
"128x182"),
152 MagickPagesize(
"ledger",
"1224x792"),
153 MagickPagesize(
"legal",
"612x1008"),
154 MagickPagesize(
"lettersmall",
"612x792"),
155 MagickPagesize(
"letter",
"612x792"),
156 MagickPagesize(
"monarch",
"279x540"),
157 MagickPagesize(
"quarto",
"610x780"),
158 MagickPagesize(
"statement",
"396x612"),
159 MagickPagesize(
"tabloid",
"792x1224"),
160 MagickPagesize(
"",
"")
205MagickExport MagickStatusType GetGeometry(
const char *geometry,ssize_t *x,
206 ssize_t *y,
size_t *width,
size_t *height)
210 pedantic_geometry[MaxTextExtent],
226 if ((geometry == (
char *) NULL) || (*geometry ==
'\0'))
228 if (strlen(geometry) >= (MaxTextExtent-1))
230 (void) CopyMagickString(pedantic_geometry,geometry,MaxTextExtent);
231 for (p=pedantic_geometry; *p !=
'\0'; )
233 if (isspace((
int) ((
unsigned char) *p)) != 0)
235 (void) CopyMagickString(p,p+1,MaxTextExtent);
244 (void) CopyMagickString(p,p+1,MaxTextExtent);
250 (void) CopyMagickString(p,p+1,MaxTextExtent);
256 (void) CopyMagickString(p,p+1,MaxTextExtent);
262 (void) CopyMagickString(p,p+1,MaxTextExtent);
268 (void) CopyMagickString(p,p+1,MaxTextExtent);
274 (void) CopyMagickString(p,p+1,MaxTextExtent);
281 (void) CopyMagickString(p,p+1,MaxTextExtent);
286 (void) CopyMagickString(p,p+1,MaxTextExtent);
292 flags|=SeparatorValue;
325 flags|=AspectRatioValue;
339 value=StringToDouble(p,&q);
341 if (LocaleNCompare(p,
"0x",2) == 0)
342 value=(double) strtol(p,&q,10);
343 if ((*p !=
'+') && (*p !=
'-'))
345 c=(int) ((
unsigned char) *q);
346 if ((c == 215) || (*q ==
'x') || (*q ==
'X') || (*q ==
':') ||
353 if (width != (
size_t *) NULL)
355 if (LocaleNCompare(p,
"0x",2) == 0)
356 *width=(size_t) strtol(p,&p,10);
358 *width=CastDoubleToUnsigned(StringToDouble(p,&p)+0.5);
364 if ((*p !=
'+') && (*p !=
'-'))
366 c=(int) ((
unsigned char) *p);
367 if ((c == 215) || (*p ==
'x') || (*p ==
'X') || (*p ==
':'))
370 if ((*p !=
'+') && (*p !=
'-'))
376 if (height != (
size_t *) NULL)
377 *height=CastDoubleToUnsigned(StringToDouble(p,&p)+0.5);
383 if ((*p ==
'+') || (*p ==
'-'))
388 while ((*p ==
'+') || (*p ==
'-'))
395 if (x != (ssize_t *) NULL)
396 *x=CastDoubleToLong(StringToDouble(p,&p));
400 if (((flags & XNegative) != 0) && (x != (ssize_t *) NULL))
401 *x=CastDoubleToLong(-1.0**x);
404 if ((*p ==
'+') || (*p ==
'-'))
409 while ((*p ==
'+') || (*p ==
'-'))
416 if (y != (ssize_t *) NULL)
417 *y=CastDoubleToLong(StringToDouble(p,&p));
421 if (((flags & YNegative) != 0) && (y != (ssize_t *) NULL))
422 *y=CastDoubleToLong(-1.0**y);
425 if ((flags & PercentValue) != 0)
427 if (((flags & SeparatorValue) == 0) && ((flags & HeightValue) == 0))
429 if ((height != (
size_t *) NULL) && (width != (
size_t *) NULL))
433 if (((flags & SeparatorValue) != 0) && ((flags & WidthValue) == 0) &&
434 (height != (
size_t *) NULL) && (width != (
size_t *) NULL))
441 (void) fprintf(stderr,
"GetGeometry...\n");
442 (void) fprintf(stderr,
"Input: %s\n",geometry);
443 (void) fprintf(stderr,
"Flags: %c %c %s %s\n",
444 (flags & WidthValue) ?
'W' :
' ',(flags & HeightValue) ?
'H' :
' ',
445 (flags & XValue) ? ((flags & XNegative) ?
"-X" :
"+X") :
" ",
446 (flags & YValue) ? ((flags & YNegative) ?
"-Y" :
"+Y") :
" ");
447 (void) fprintf(stderr,
"Geometry: %ldx%ld%+ld%+ld\n",(
long) *width,(
long)
448 *height,(
long) *x,(
long) *y);
478MagickExport
char *GetPageGeometry(
const char *page_geometry)
486 assert(page_geometry != (
char *) NULL);
487 if (IsEventLogging() != MagickFalse)
488 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",page_geometry);
489 (void) CopyMagickString(page,page_geometry,MaxTextExtent);
490 for (i=0; *Pagesizes[i].name !=
'\0'; i++)
495 if (Pagesizes[i].extent == 0)
497 status=LocaleNCompare(Pagesizes[i].name,page_geometry,Pagesizes[i].extent);
509 (void) FormatLocaleString(page,MaxTextExtent,
"%s%.80s",
510 Pagesizes[i].geometry,page_geometry+Pagesizes[i].extent);
511 flags=GetGeometry(page,&geometry.x,&geometry.y,&geometry.width,
513 if ((flags & GreaterValue) == 0)
514 (void) ConcatenateMagickString(page,
">",MaxTextExtent);
518 return(AcquireString(page));
552MagickExport
void GravityAdjustGeometry(
const size_t width,
553 const size_t height,
const GravityType gravity,
RectangleInfo *region)
555 if (region->height == 0)
556 region->height=height;
557 if (region->width == 0)
561 case NorthEastGravity:
563 case SouthEastGravity:
565 region->x=CastDoubleToLong((
double) width-region->width-region->x);
573 region->x+=CastDoubleToLong(width/2.0-region->width/2.0);
577 case NorthWestGravity:
579 case SouthWestGravity:
585 case SouthWestGravity:
587 case SouthEastGravity:
589 region->y=CastDoubleToLong((
double) height-region->height-region->y);
597 region->y+=CastDoubleToLong(height/2.0-region->height/2.0);
601 case NorthWestGravity:
603 case NorthEastGravity:
633MagickExport MagickBooleanType IsGeometry(
const char *geometry)
641 if (geometry == (
const char *) NULL)
643 flags=ParseGeometry(geometry,&geometry_info);
644 return(flags != NoValue ? MagickTrue : MagickFalse);
674MagickExport MagickBooleanType IsSceneGeometry(
const char *geometry,
675 const MagickBooleanType pedantic)
683 if (geometry == (
const char *) NULL)
686 value=StringToDouble(geometry,&p);
687 if (IsNaN(value) != 0)
689 if (value > (
double) MAGICK_SSIZE_MAX)
691 if (value < (
double) MAGICK_SSIZE_MIN)
695 if (strspn(geometry,
"0123456789-, ") != strlen(geometry))
697 if ((pedantic != MagickFalse) && (strchr(geometry,
',') != (
char *) NULL))
726MagickExport MagickBooleanType ListPagesizes(FILE *file,
729#define MaxMagickSpaces ((int) sizeof(Pagesizes[0].name))
737 magick_unreferenced(exception);
738 if (file == (FILE *) NULL)
740 (void) FormatLocaleFile(file,
"\nPagesize Geometry \n");
741 (void) FormatLocaleFile(file,
"---------------------\n");
742 for (i=0; *Pagesizes[i].name !=
'\0'; i++)
743 (
void) FormatLocaleFile(file,
"%s%.*s%s\n",Pagesizes[i].name,
744 MaxMagickSpaces-(
int) Pagesizes[i].extent,spacer,Pagesizes[i].geometry);
777MagickExport MagickStatusType ParseAbsoluteGeometry(
const char *geometry,
783 flags=GetGeometry(geometry,®ion_info->x,®ion_info->y,
784 ®ion_info->width,®ion_info->height);
818MagickExport MagickStatusType ParseAffineGeometry(
const char *geometry,
822 token[MaxTextExtent];
836 GetAffineMatrix(affine_matrix);
839 for (i=0; (*p !=
'\0') && (i < 6); i++)
841 (void) GetNextToken(p,&p,MaxTextExtent,token);
843 (void) GetNextToken(p,&p,MaxTextExtent,token);
848 affine_matrix->sx=StringToDouble(token,(
char **) NULL);
853 affine_matrix->rx=StringToDouble(token,(
char **) NULL);
858 affine_matrix->ry=StringToDouble(token,(
char **) NULL);
863 affine_matrix->sy=StringToDouble(token,(
char **) NULL);
868 affine_matrix->tx=StringToDouble(token,(
char **) NULL);
874 affine_matrix->ty=StringToDouble(token,(
char **) NULL);
880 determinant=(affine_matrix->sx*affine_matrix->sy-affine_matrix->rx*
882 if (fabs(determinant) < MagickEpsilon)
883 (void) ThrowMagickException(exception,GetMagickModule(),OptionError,
884 "InvalidArgument",
"'%s' : 'Indeterminate Matrix'",geometry);
927MagickExport MagickStatusType ParseGeometry(
const char *geometry,
932 pedantic_geometry[MaxTextExtent],
948 (void) memset(geometry_info,0,
sizeof(*geometry_info));
950 if ((geometry == (
char *) NULL) || (*geometry ==
'\0'))
952 if (strlen(geometry) >= (MaxTextExtent-1))
954 (void) CopyMagickString(pedantic_geometry,geometry,MaxTextExtent);
955 for (p=pedantic_geometry; *p !=
'\0'; )
957 c=(int) ((
unsigned char) *p);
958 if (isspace((
int) ((
unsigned char) c)) != 0)
960 (void) CopyMagickString(p,p+1,MaxTextExtent);
968 (void) CopyMagickString(p,p+1,MaxTextExtent);
974 (void) CopyMagickString(p,p+1,MaxTextExtent);
980 (void) CopyMagickString(p,p+1,MaxTextExtent);
986 (void) CopyMagickString(p,p+1,MaxTextExtent);
992 (void) CopyMagickString(p,p+1,MaxTextExtent);
998 (void) CopyMagickString(p,p+1,MaxTextExtent);
1005 (void) CopyMagickString(p,p+1,MaxTextExtent);
1010 (void) CopyMagickString(p,p+1,MaxTextExtent);
1016 flags|=SeparatorValue;
1044 flags|=DecimalValue;
1050 flags|=AspectRatioValue;
1060 p=pedantic_geometry;
1064 value=StringToDouble(p,&q);
1065 if (LocaleNCompare(p,
"0x",2) == 0)
1066 (void) strtol(p,&q,10);
1067 c=(int) ((
unsigned char) *q);
1068 if ((c == 215) || (*q ==
'x') || (*q ==
'X') || (*q ==
':') ||
1069 (*q ==
',') || (*q ==
'/') || (*q ==
'\0'))
1075 if (LocaleNCompare(p,
"0x",2) == 0)
1076 value=(double) strtol(p,&p,10);
1078 value=StringToDouble(p,&p);
1082 geometry_info->rho=value;
1086 c=(int) ((
unsigned char) *p);
1087 if ((c == 215) || (*p ==
'x') || (*p ==
'X') || (*p ==
':') || (*p ==
',') ||
1094 while (isspace((
int) ((
unsigned char) *p)) != 0)
1096 c=(int) ((
unsigned char) *q);
1097 if (((c != 215) && (*q !=
'x') && (*q !=
'X') && (*q !=
':')) ||
1098 ((*p !=
'+') && (*p !=
'-')))
1101 value=StringToDouble(p,&p);
1105 geometry_info->sigma=value;
1109 while (isspace((
int) ((
unsigned char) *p)) != 0)
1111 if ((*p ==
'+') || (*p ==
'-') || (*p ==
',') || (*p ==
'/') || (*p ==
':'))
1116 if ((*p ==
',') || (*p ==
'/') || (*p ==
':') )
1118 while ((*p ==
'+') || (*p ==
'-'))
1125 value=StringToDouble(p,&p);
1129 if ((flags & XiNegative) != 0)
1131 geometry_info->xi=value;
1133 while (isspace((
int) ((
unsigned char) *p)) != 0)
1135 if ((*p ==
'+') || (*p ==
'-') || (*p ==
',') || (*p ==
'/') ||
1141 if ((*p ==
',') || (*p ==
'/') || (*p ==
':'))
1143 while ((*p ==
'+') || (*p ==
'-'))
1150 value=StringToDouble(p,&p);
1154 if ((flags & PsiNegative) != 0)
1156 geometry_info->psi=value;
1159 while (isspace((
int) ((
unsigned char) *p)) != 0)
1161 if ((*p ==
'+') || (*p ==
'-') || (*p ==
',') || (*p ==
'/') ||
1167 if ((*p ==
',') || (*p ==
'/') || (*p ==
':'))
1169 while ((*p ==
'+') || (*p ==
'-'))
1176 value=StringToDouble(p,&p);
1180 if ((flags & ChiNegative) != 0)
1182 geometry_info->chi=value;
1186 if (strchr(pedantic_geometry,
':') != (
char *) NULL)
1191 if ((flags & SigmaValue) != 0)
1192 geometry_info->rho*=PerceptibleReciprocal(geometry_info->sigma);
1193 geometry_info->sigma=1.0;
1194 if (((flags & XiValue) != 0) && (geometry_info->xi == 0.0))
1195 geometry_info->sigma=2.0;
1197 if (((flags & RhoValue) != 0) && ((flags & SigmaValue) == 0) &&
1198 ((flags & XiValue) != 0) && ((flags & XiNegative) != 0))
1200 if ((flags & PsiValue) == 0)
1205 geometry_info->sigma=geometry_info->xi;
1206 geometry_info->xi=0.0;
1211 if ((flags & ChiValue) == 0)
1216 geometry_info->sigma=geometry_info->xi;
1217 geometry_info->xi=geometry_info->psi;
1227 geometry_info->sigma=geometry_info->xi;
1228 geometry_info->xi=geometry_info->psi;
1229 geometry_info->psi=geometry_info->chi;
1236 if ((flags & PercentValue) != 0)
1238 if (((flags & SeparatorValue) == 0) && ((flags & SigmaValue) == 0))
1239 geometry_info->sigma=geometry_info->rho;
1240 if (((flags & SeparatorValue) != 0) && ((flags & RhoValue) == 0))
1241 geometry_info->rho=geometry_info->sigma;
1245 (void) fprintf(stderr,
"ParseGeometry...\n");
1246 (void) fprintf(stderr,
"Flags: %c %c %s %s %s\n",
1247 (flags & RhoValue) ?
'W' :
' ',(flags & SigmaValue) ?
'H' :
' ',
1248 (flags & XiValue) ? ((flags & XiNegative) ?
"-X" :
"+X") :
" ",
1249 (flags & PsiValue) ? ((flags & PsiNegative) ?
"-Y" :
"+Y") :
" ",
1250 (flags & ChiValue) ? ((flags & ChiNegative) ?
"-Z" :
"+Z") :
" ");
1251 (void) fprintf(stderr,
"Geometry: %lg,%lg,%lg,%lg,%lg\n",geometry_info->rho,
1252 geometry_info->sigma,geometry_info->xi,geometry_info->psi,
1253 geometry_info->chi);
1295MagickExport MagickStatusType ParseGravityGeometry(
const Image *image,
1305 SetGeometry(image,region_info);
1306 if (image->page.width != 0)
1307 region_info->width=image->page.width;
1308 if (image->page.height != 0)
1309 region_info->height=image->page.height;
1310 flags=ParseAbsoluteGeometry(geometry,region_info);
1311 if (flags == NoValue)
1313 (void) ThrowMagickException(exception,GetMagickModule(),OptionError,
1314 "InvalidGeometry",
"`%s'",geometry);
1317 if ((flags & PercentValue) != 0)
1331 if (image->gravity != UndefinedGravity)
1332 flags|=XValue | YValue;
1333 status=ParseGeometry(geometry,&geometry_info);
1334 scale.x=geometry_info.rho;
1335 if ((status & RhoValue) == 0)
1337 scale.y=geometry_info.sigma;
1338 if ((status & SigmaValue) == 0)
1340 region_info->width=CastDoubleToUnsigned(scale.x*image->columns/100.0+0.5);
1341 region_info->height=CastDoubleToUnsigned(scale.y*image->rows/100.0+0.5);
1343 if ((flags & AspectRatioValue) != 0)
1355 if (image->gravity != UndefinedGravity)
1356 flags|=XValue | YValue;
1357 (void) ParseGeometry(geometry,&geometry_info);
1358 geometry_ratio=geometry_info.rho;
1359 image_ratio=(double) image->columns/image->rows;
1360 if (geometry_ratio >= image_ratio)
1362 region_info->width=image->columns;
1363 region_info->height=CastDoubleToUnsigned((
double) image->rows*
1364 image_ratio/geometry_ratio+0.5);
1368 region_info->width=CastDoubleToUnsigned((
double) image->columns*
1369 geometry_ratio/image_ratio+0.5);
1370 region_info->height=image->rows;
1376 width=region_info->width;
1377 height=region_info->height;
1379 region_info->width=image->page.width | image->columns;
1381 region_info->height=image->page.height | image->rows;
1382 GravityAdjustGeometry(image->columns,image->rows,image->gravity,region_info);
1383 region_info->width=width;
1384 region_info->height=height;
1431MagickExport MagickStatusType ParseMetaGeometry(
const char *geometry,ssize_t *x,
1432 ssize_t *y,
size_t *width,
size_t *height)
1447 assert(x != (ssize_t *) NULL);
1448 assert(y != (ssize_t *) NULL);
1449 assert(width != (
size_t *) NULL);
1450 assert(height != (
size_t *) NULL);
1451 if ((geometry == (
char *) NULL) || (*geometry ==
'\0'))
1453 if (IsEventLogging() != MagickFalse)
1454 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",geometry);
1458 SetGeometryInfo(&geometry_info);
1459 former_width=(*width);
1460 former_height=(*height);
1461 flags=GetGeometry(geometry,x,y,width,height);
1462 if ((flags & PercentValue) != 0)
1473 flags=ParseGeometry(geometry,&geometry_info);
1474 scale.x=geometry_info.rho;
1475 if ((flags & RhoValue) == 0)
1477 scale.y=geometry_info.sigma;
1478 if ((flags & SigmaValue) == 0)
1480 *width=CastDoubleToUnsigned(scale.x*former_width/100.0+0.5);
1481 *height=CastDoubleToUnsigned(scale.y*former_height/100.0+0.5);
1482 former_width=(*width);
1483 former_height=(*height);
1485 if ((flags & AspectRatioValue) != 0)
1497 (void) ParseGeometry(geometry,&geometry_info);
1498 geometry_ratio=geometry_info.rho;
1499 image_ratio=(double) former_width*PerceptibleReciprocal(former_height);
1500 if (geometry_ratio >= image_ratio)
1502 *width=former_width;
1503 *height=CastDoubleToUnsigned(PerceptibleReciprocal(geometry_ratio)*
1504 former_height*image_ratio+0.5);
1508 *width=CastDoubleToUnsigned(PerceptibleReciprocal(image_ratio)*
1509 former_width*geometry_ratio+0.5);
1510 *height=former_height;
1512 former_width=(*width);
1513 former_height=(*height);
1515 if (((flags & AspectValue) != 0) || ((*width == former_width) &&
1516 (*height == former_height)))
1518 if ((flags & RhoValue) == 0)
1519 *width=former_width;
1520 if ((flags & SigmaValue) == 0)
1521 *height=former_height;
1531 if ((former_width == 0) || (former_height == 0))
1534 if (((flags & RhoValue) != 0) && (flags & SigmaValue) != 0)
1536 scale_factor=(double) *width/(
double) former_width;
1537 if ((flags & MinimumValue) == 0)
1539 if (scale_factor > ((
double) *height/(
double) former_height))
1540 scale_factor=(double) *height/(
double) former_height;
1543 if (scale_factor < ((
double) *height/(
double) former_height))
1544 scale_factor=(double) *height/(
double) former_height;
1547 if ((flags & RhoValue) != 0)
1549 scale_factor=(double) *width/(
double) former_width;
1550 if (((flags & MinimumValue) != 0) &&
1551 (scale_factor < ((
double) *width/(
double) former_height)))
1552 scale_factor=(double) *width/(
double) former_height;
1556 scale_factor=(double) *height/(
double) former_height;
1557 if (((flags & MinimumValue) != 0) &&
1558 (scale_factor < ((
double) *height/(
double) former_width)))
1559 scale_factor=(double) *height/(
double) former_width;
1561 *width=CastDoubleToUnsigned(MagickMax(floor(scale_factor*former_width+
1563 *height=CastDoubleToUnsigned(MagickMax(floor(scale_factor*former_height+
1566 if ((flags & GreaterValue) != 0)
1568 if (former_width < *width)
1569 *width=former_width;
1570 if (former_height < *height)
1571 *height=former_height;
1573 if ((flags & LessValue) != 0)
1575 if (former_width > *width)
1576 *width=former_width;
1577 if (former_height > *height)
1578 *height=former_height;
1580 if ((flags & AreaValue) != 0)
1592 (void) ParseGeometry(geometry,&geometry_info);
1593 area=geometry_info.rho+sqrt(MagickEpsilon);
1594 distance=sqrt((
double) former_width*former_height);
1595 scale.x=(double) former_width*PerceptibleReciprocal(distance*
1596 PerceptibleReciprocal(sqrt(area)));
1597 scale.y=(double) former_height*PerceptibleReciprocal(distance*
1598 PerceptibleReciprocal(sqrt(area)));
1599 if ((scale.x < (
double) *width) || (scale.y < (
double) *height))
1601 *width=CastDoubleToUnsigned(former_width*PerceptibleReciprocal(
1602 distance*PerceptibleReciprocal(sqrt(area)))+0.5);
1603 *height=CastDoubleToUnsigned(former_height*PerceptibleReciprocal(
1604 distance*PerceptibleReciprocal(sqrt(area)))+0.5);
1606 former_width=(*width);
1607 former_height=(*height);
1645MagickExport MagickStatusType ParsePageGeometry(
const Image *image,
1651 SetGeometry(image,region_info);
1652 if (image->page.width != 0)
1653 region_info->width=image->page.width;
1654 if (image->page.height != 0)
1655 region_info->height=image->page.height;
1656 flags=ParseAbsoluteGeometry(geometry,region_info);
1657 if (flags == NoValue)
1659 (void) ThrowMagickException(exception,GetMagickModule(),OptionError,
1660 "InvalidGeometry",
"`%s'",geometry);
1663 if ((flags & PercentValue) != 0)
1665 region_info->width=image->columns;
1666 region_info->height=image->rows;
1668 flags=ParseMetaGeometry(geometry,®ion_info->x,®ion_info->y,
1669 ®ion_info->width,®ion_info->height);
1670 if ((((flags & WidthValue) != 0) || ((flags & HeightValue) != 0)) &&
1671 (((flags & PercentValue) != 0) || ((flags & SeparatorValue) == 0)))
1673 if ((flags & WidthValue) == 0)
1674 region_info->width=region_info->height;
1675 if ((flags & HeightValue) == 0)
1676 region_info->height=region_info->width;
1714MagickExport MagickStatusType ParseRegionGeometry(
const Image *image,
1720 SetGeometry(image,region_info);
1721 flags=ParseMetaGeometry(geometry,®ion_info->x,®ion_info->y,
1722 ®ion_info->width,®ion_info->height);
1723 if (flags == NoValue)
1724 (void) ThrowMagickException(exception,GetMagickModule(),OptionError,
1725 "InvalidGeometry",
"`%s'",geometry);
1755 assert(image != (
Image *) NULL);
1756 assert(image->signature == MagickCoreSignature);
1757 if (IsEventLogging() != MagickFalse)
1758 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",image->filename);
1760 (void) memset(geometry,0,
sizeof(*geometry));
1761 geometry->width=image->columns;
1762 geometry->height=image->rows;
1787MagickExport
void SetGeometryInfo(
GeometryInfo *geometry_info)
1790 if (IsEventLogging() != MagickFalse)
1791 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
1792 (void) memset(geometry_info,0,
sizeof(*geometry_info));