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(
"a1",
"1684x2384"),
92 MagickPagesize(
"a2",
"1191x1684"),
93 MagickPagesize(
"a3",
"842x1191"),
94 MagickPagesize(
"a4",
"595x842"),
95 MagickPagesize(
"a4small",
"595x842"),
96 MagickPagesize(
"a5",
"420x595"),
97 MagickPagesize(
"a6",
"298x420"),
98 MagickPagesize(
"a7",
"210x298"),
99 MagickPagesize(
"a8",
"147x210"),
100 MagickPagesize(
"a9",
"105x147"),
101 MagickPagesize(
"a10",
"74x105"),
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(
"b1",
"2064x2920"),
109 MagickPagesize(
"b10",
"91x127"),
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(
"isob1",
"2004x2835"),
136 MagickPagesize(
"isob10",
"88x125"),
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(
"letter",
"612x792"),
155 MagickPagesize(
"lettersmall",
"612x792"),
156 MagickPagesize(
"monarch",
"279x540"),
157 MagickPagesize(
"quarto",
"610x780"),
158 MagickPagesize(
"statement",
"396x612"),
159 MagickPagesize(
"tabloid",
"792x1224"),
160 MagickPagesize(
"",
"")
205 MagickExport 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);
478 MagickExport
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 status=LocaleNCompare(Pagesizes[i].name,page_geometry,Pagesizes[i].extent);
507 (void) FormatLocaleString(page,MaxTextExtent,
"%s%.80s",
508 Pagesizes[i].geometry,page_geometry+Pagesizes[i].extent);
509 flags=GetGeometry(page,&geometry.x,&geometry.y,&geometry.width,
511 if ((flags & GreaterValue) == 0)
512 (void) ConcatenateMagickString(page,
">",MaxTextExtent);
516 return(AcquireString(page));
550 MagickExport
void GravityAdjustGeometry(
const size_t width,
551 const size_t height,
const GravityType gravity,
RectangleInfo *region)
553 if (region->height == 0)
554 region->height=height;
555 if (region->width == 0)
559 case NorthEastGravity:
561 case SouthEastGravity:
563 region->x=CastDoubleToLong((
double) width-region->width-region->x);
571 region->x+=CastDoubleToLong(width/2.0-region->width/2.0);
575 case NorthWestGravity:
577 case SouthWestGravity:
583 case SouthWestGravity:
585 case SouthEastGravity:
587 region->y=CastDoubleToLong((
double) height-region->height-region->y);
595 region->y+=CastDoubleToLong(height/2.0-region->height/2.0);
599 case NorthWestGravity:
601 case NorthEastGravity:
631 MagickExport MagickBooleanType IsGeometry(
const char *geometry)
639 if (geometry == (
const char *) NULL)
641 flags=ParseGeometry(geometry,&geometry_info);
642 return(flags != NoValue ? MagickTrue : MagickFalse);
672 MagickExport MagickBooleanType IsSceneGeometry(
const char *geometry,
673 const MagickBooleanType pedantic)
681 if (geometry == (
const char *) NULL)
684 value=StringToDouble(geometry,&p);
685 if (IsNaN(value) != 0)
687 if (value > (
double) MAGICK_SSIZE_MAX)
689 if (value < (
double) MAGICK_SSIZE_MIN)
693 if (strspn(geometry,
"0123456789-, ") != strlen(geometry))
695 if ((pedantic != MagickFalse) && (strchr(geometry,
',') != (
char *) NULL))
724 MagickExport MagickBooleanType ListPagesizes(FILE *file,
727 #define MaxMagickSpaces ((int) sizeof(Pagesizes[0].name))
735 magick_unreferenced(exception);
736 if (file == (FILE *) NULL)
738 (void) FormatLocaleFile(file,
"\nPagesize Geometry \n");
739 (void) FormatLocaleFile(file,
"---------------------\n");
740 for (i=0; *Pagesizes[i].name !=
'\0'; i++)
741 (
void) FormatLocaleFile(file,
"%s%.*s%s\n",Pagesizes[i].name,
742 MaxMagickSpaces-(
int) Pagesizes[i].extent,spacer,Pagesizes[i].geometry);
775 MagickExport MagickStatusType ParseAbsoluteGeometry(
const char *geometry,
781 flags=GetGeometry(geometry,®ion_info->x,®ion_info->y,
782 ®ion_info->width,®ion_info->height);
816 MagickExport MagickStatusType ParseAffineGeometry(
const char *geometry,
820 token[MaxTextExtent];
834 GetAffineMatrix(affine_matrix);
837 for (i=0; (*p !=
'\0') && (i < 6); i++)
839 (void) GetNextToken(p,&p,MaxTextExtent,token);
841 (void) GetNextToken(p,&p,MaxTextExtent,token);
846 affine_matrix->sx=StringToDouble(token,(
char **) NULL);
851 affine_matrix->rx=StringToDouble(token,(
char **) NULL);
856 affine_matrix->ry=StringToDouble(token,(
char **) NULL);
861 affine_matrix->sy=StringToDouble(token,(
char **) NULL);
866 affine_matrix->tx=StringToDouble(token,(
char **) NULL);
872 affine_matrix->ty=StringToDouble(token,(
char **) NULL);
878 determinant=(affine_matrix->sx*affine_matrix->sy-affine_matrix->rx*
880 if (fabs(determinant) < MagickEpsilon)
881 (
void) ThrowMagickException(exception,GetMagickModule(),OptionError,
882 "InvalidArgument",
"'%s' : 'Indeterminate Matrix'",geometry);
925 MagickExport MagickStatusType ParseGeometry(
const char *geometry,
930 pedantic_geometry[MaxTextExtent],
946 (void) memset(geometry_info,0,
sizeof(*geometry_info));
948 if ((geometry == (
char *) NULL) || (*geometry ==
'\0'))
950 if (strlen(geometry) >= (MaxTextExtent-1))
952 (void) CopyMagickString(pedantic_geometry,geometry,MaxTextExtent);
953 for (p=pedantic_geometry; *p !=
'\0'; )
955 c=(int) ((
unsigned char) *p);
956 if (isspace((
int) ((
unsigned char) c)) != 0)
958 (void) CopyMagickString(p,p+1,MaxTextExtent);
966 (void) CopyMagickString(p,p+1,MaxTextExtent);
972 (void) CopyMagickString(p,p+1,MaxTextExtent);
978 (void) CopyMagickString(p,p+1,MaxTextExtent);
984 (void) CopyMagickString(p,p+1,MaxTextExtent);
990 (void) CopyMagickString(p,p+1,MaxTextExtent);
996 (void) CopyMagickString(p,p+1,MaxTextExtent);
1003 (void) CopyMagickString(p,p+1,MaxTextExtent);
1008 (void) CopyMagickString(p,p+1,MaxTextExtent);
1014 flags|=SeparatorValue;
1042 flags|=DecimalValue;
1048 flags|=AspectRatioValue;
1058 p=pedantic_geometry;
1062 value=StringToDouble(p,&q);
1063 if (LocaleNCompare(p,
"0x",2) == 0)
1064 (void) strtol(p,&q,10);
1065 c=(int) ((
unsigned char) *q);
1066 if ((c == 215) || (*q ==
'x') || (*q ==
'X') || (*q ==
':') ||
1067 (*q ==
',') || (*q ==
'/') || (*q ==
'\0'))
1073 if (LocaleNCompare(p,
"0x",2) == 0)
1074 value=(
double) strtol(p,&p,10);
1076 value=StringToDouble(p,&p);
1080 geometry_info->rho=value;
1084 c=(int) ((
unsigned char) *p);
1085 if ((c == 215) || (*p ==
'x') || (*p ==
'X') || (*p ==
':') || (*p ==
',') ||
1092 while (isspace((
int) ((
unsigned char) *p)) != 0)
1094 c=(int) ((
unsigned char) *q);
1095 if (((c != 215) && (*q !=
'x') && (*q !=
'X') && (*q !=
':')) ||
1096 ((*p !=
'+') && (*p !=
'-')))
1099 value=StringToDouble(p,&p);
1103 geometry_info->sigma=value;
1107 while (isspace((
int) ((
unsigned char) *p)) != 0)
1109 if ((*p ==
'+') || (*p ==
'-') || (*p ==
',') || (*p ==
'/') || (*p ==
':'))
1114 if ((*p ==
',') || (*p ==
'/') || (*p ==
':') )
1116 while ((*p ==
'+') || (*p ==
'-'))
1123 value=StringToDouble(p,&p);
1127 if ((flags & XiNegative) != 0)
1129 geometry_info->xi=value;
1131 while (isspace((
int) ((
unsigned char) *p)) != 0)
1133 if ((*p ==
'+') || (*p ==
'-') || (*p ==
',') || (*p ==
'/') ||
1139 if ((*p ==
',') || (*p ==
'/') || (*p ==
':'))
1141 while ((*p ==
'+') || (*p ==
'-'))
1148 value=StringToDouble(p,&p);
1152 if ((flags & PsiNegative) != 0)
1154 geometry_info->psi=value;
1157 while (isspace((
int) ((
unsigned char) *p)) != 0)
1159 if ((*p ==
'+') || (*p ==
'-') || (*p ==
',') || (*p ==
'/') ||
1165 if ((*p ==
',') || (*p ==
'/') || (*p ==
':'))
1167 while ((*p ==
'+') || (*p ==
'-'))
1174 value=StringToDouble(p,&p);
1178 if ((flags & ChiNegative) != 0)
1180 geometry_info->chi=value;
1184 if (strchr(pedantic_geometry,
':') != (
char *) NULL)
1189 if ((flags & SigmaValue) != 0)
1190 geometry_info->rho*=PerceptibleReciprocal(geometry_info->sigma);
1191 geometry_info->sigma=1.0;
1192 if (((flags & XiValue) != 0) && (geometry_info->xi == 0.0))
1193 geometry_info->sigma=2.0;
1195 if (((flags & RhoValue) != 0) && ((flags & SigmaValue) == 0) &&
1196 ((flags & XiValue) != 0) && ((flags & XiNegative) != 0))
1198 if ((flags & PsiValue) == 0)
1203 geometry_info->sigma=geometry_info->xi;
1204 geometry_info->xi=0.0;
1209 if ((flags & ChiValue) == 0)
1214 geometry_info->sigma=geometry_info->xi;
1215 geometry_info->xi=geometry_info->psi;
1225 geometry_info->sigma=geometry_info->xi;
1226 geometry_info->xi=geometry_info->psi;
1227 geometry_info->psi=geometry_info->chi;
1234 if ((flags & PercentValue) != 0)
1236 if (((flags & SeparatorValue) == 0) && ((flags & SigmaValue) == 0))
1237 geometry_info->sigma=geometry_info->rho;
1238 if (((flags & SeparatorValue) != 0) && ((flags & RhoValue) == 0))
1239 geometry_info->rho=geometry_info->sigma;
1243 (void) fprintf(stderr,
"ParseGeometry...\n");
1244 (void) fprintf(stderr,
"Flags: %c %c %s %s %s\n",
1245 (flags & RhoValue) ?
'W' :
' ',(flags & SigmaValue) ?
'H' :
' ',
1246 (flags & XiValue) ? ((flags & XiNegative) ?
"-X" :
"+X") :
" ",
1247 (flags & PsiValue) ? ((flags & PsiNegative) ?
"-Y" :
"+Y") :
" ",
1248 (flags & ChiValue) ? ((flags & ChiNegative) ?
"-Z" :
"+Z") :
" ");
1249 (void) fprintf(stderr,
"Geometry: %lg,%lg,%lg,%lg,%lg\n",geometry_info->rho,
1250 geometry_info->sigma,geometry_info->xi,geometry_info->psi,
1251 geometry_info->chi);
1293 MagickExport MagickStatusType ParseGravityGeometry(
const Image *image,
1303 SetGeometry(image,region_info);
1304 if (image->page.width != 0)
1305 region_info->width=image->page.width;
1306 if (image->page.height != 0)
1307 region_info->height=image->page.height;
1308 flags=ParseAbsoluteGeometry(geometry,region_info);
1309 if (flags == NoValue)
1311 (void) ThrowMagickException(exception,GetMagickModule(),OptionError,
1312 "InvalidGeometry",
"`%s'",geometry);
1315 if ((flags & PercentValue) != 0)
1329 if (image->gravity != UndefinedGravity)
1330 flags|=XValue | YValue;
1331 status=ParseGeometry(geometry,&geometry_info);
1332 scale.x=geometry_info.rho;
1333 if ((status & RhoValue) == 0)
1335 scale.y=geometry_info.sigma;
1336 if ((status & SigmaValue) == 0)
1338 region_info->width=CastDoubleToUnsigned(scale.x*image->columns/100.0+0.5);
1339 region_info->height=CastDoubleToUnsigned(scale.y*image->rows/100.0+0.5);
1341 if ((flags & AspectRatioValue) != 0)
1353 if (image->gravity != UndefinedGravity)
1354 flags|=XValue | YValue;
1355 (void) ParseGeometry(geometry,&geometry_info);
1356 geometry_ratio=geometry_info.rho;
1357 image_ratio=(double) image->columns/image->rows;
1358 if (geometry_ratio >= image_ratio)
1360 region_info->width=image->columns;
1361 region_info->height=CastDoubleToUnsigned((
double) image->rows*
1362 image_ratio/geometry_ratio+0.5);
1366 region_info->width=CastDoubleToUnsigned((
double) image->columns*
1367 geometry_ratio/image_ratio+0.5);
1368 region_info->height=image->rows;
1374 width=region_info->width;
1375 height=region_info->height;
1377 region_info->width=image->page.width | image->columns;
1379 region_info->height=image->page.height | image->rows;
1380 GravityAdjustGeometry(image->columns,image->rows,image->gravity,region_info);
1381 region_info->width=width;
1382 region_info->height=height;
1429 MagickExport MagickStatusType ParseMetaGeometry(
const char *geometry,ssize_t *x,
1430 ssize_t *y,
size_t *width,
size_t *height)
1445 assert(x != (ssize_t *) NULL);
1446 assert(y != (ssize_t *) NULL);
1447 assert(width != (
size_t *) NULL);
1448 assert(height != (
size_t *) NULL);
1449 if ((geometry == (
char *) NULL) || (*geometry ==
'\0'))
1451 if (IsEventLogging() != MagickFalse)
1452 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",geometry);
1456 SetGeometryInfo(&geometry_info);
1457 former_width=(*width);
1458 former_height=(*height);
1459 flags=GetGeometry(geometry,x,y,width,height);
1460 if ((flags & PercentValue) != 0)
1471 flags=ParseGeometry(geometry,&geometry_info);
1472 scale.x=geometry_info.rho;
1473 if ((flags & RhoValue) == 0)
1475 scale.y=geometry_info.sigma;
1476 if ((flags & SigmaValue) == 0)
1478 *width=CastDoubleToUnsigned(scale.x*former_width/100.0+0.5);
1479 *height=CastDoubleToUnsigned(scale.y*former_height/100.0+0.5);
1480 former_width=(*width);
1481 former_height=(*height);
1483 if ((flags & AspectRatioValue) != 0)
1495 (void) ParseGeometry(geometry,&geometry_info);
1496 geometry_ratio=geometry_info.rho;
1497 image_ratio=(double) former_width*PerceptibleReciprocal(former_height);
1498 if (geometry_ratio >= image_ratio)
1500 *width=former_width;
1501 *height=CastDoubleToUnsigned(PerceptibleReciprocal(geometry_ratio)*
1502 former_height*image_ratio+0.5);
1506 *width=CastDoubleToUnsigned(PerceptibleReciprocal(image_ratio)*
1507 former_width*geometry_ratio+0.5);
1508 *height=former_height;
1510 former_width=(*width);
1511 former_height=(*height);
1513 if (((flags & AspectValue) != 0) || ((*width == former_width) &&
1514 (*height == former_height)))
1516 if ((flags & RhoValue) == 0)
1517 *width=former_width;
1518 if ((flags & SigmaValue) == 0)
1519 *height=former_height;
1529 if ((former_width == 0) || (former_height == 0))
1532 if (((flags & RhoValue) != 0) && (flags & SigmaValue) != 0)
1534 scale_factor=(double) *width/(
double) former_width;
1535 if ((flags & MinimumValue) == 0)
1537 if (scale_factor > ((
double) *height/(
double) former_height))
1538 scale_factor=(
double) *height/(double) former_height;
1541 if (scale_factor < ((
double) *height/(double) former_height))
1542 scale_factor=(
double) *height/(double) former_height;
1545 if ((flags & RhoValue) != 0)
1547 scale_factor=(double) *width/(
double) former_width;
1548 if (((flags & MinimumValue) != 0) &&
1549 (scale_factor < ((
double) *width/(double) former_height)))
1550 scale_factor=(double) *width/(
double) former_height;
1554 scale_factor=(double) *height/(
double) former_height;
1555 if (((flags & MinimumValue) != 0) &&
1556 (scale_factor < ((
double) *height/(double) former_width)))
1557 scale_factor=(double) *height/(
double) former_width;
1559 *width=CastDoubleToUnsigned(MagickMax(floor(scale_factor*former_width+
1561 *height=CastDoubleToUnsigned(MagickMax(floor(scale_factor*former_height+
1564 if ((flags & GreaterValue) != 0)
1566 if (former_width < *width)
1567 *width=former_width;
1568 if (former_height < *height)
1569 *height=former_height;
1571 if ((flags & LessValue) != 0)
1573 if (former_width > *width)
1574 *width=former_width;
1575 if (former_height > *height)
1576 *height=former_height;
1578 if ((flags & AreaValue) != 0)
1590 (void) ParseGeometry(geometry,&geometry_info);
1591 area=geometry_info.rho+sqrt(MagickEpsilon);
1592 distance=sqrt((
double) former_width*former_height);
1593 scale.x=(double) former_width*PerceptibleReciprocal(distance*
1594 PerceptibleReciprocal(sqrt(area)));
1595 scale.y=(double) former_height*PerceptibleReciprocal(distance*
1596 PerceptibleReciprocal(sqrt(area)));
1597 if ((scale.x < (
double) *width) || (scale.y < (
double) *height))
1599 *width=CastDoubleToUnsigned(former_width*PerceptibleReciprocal(
1600 distance*PerceptibleReciprocal(sqrt(area)))+0.5);
1601 *height=CastDoubleToUnsigned(former_height*PerceptibleReciprocal(
1602 distance*PerceptibleReciprocal(sqrt(area)))+0.5);
1604 former_width=(*width);
1605 former_height=(*height);
1643 MagickExport MagickStatusType ParsePageGeometry(
const Image *image,
1649 SetGeometry(image,region_info);
1650 if (image->page.width != 0)
1651 region_info->width=image->page.width;
1652 if (image->page.height != 0)
1653 region_info->height=image->page.height;
1654 flags=ParseAbsoluteGeometry(geometry,region_info);
1655 if (flags == NoValue)
1657 (void) ThrowMagickException(exception,GetMagickModule(),OptionError,
1658 "InvalidGeometry",
"`%s'",geometry);
1661 if ((flags & PercentValue) != 0)
1663 region_info->width=image->columns;
1664 region_info->height=image->rows;
1666 flags=ParseMetaGeometry(geometry,®ion_info->x,®ion_info->y,
1667 ®ion_info->width,®ion_info->height);
1668 if ((((flags & WidthValue) != 0) || ((flags & HeightValue) != 0)) &&
1669 (((flags & PercentValue) != 0) || ((flags & SeparatorValue) == 0)))
1671 if ((flags & WidthValue) == 0)
1672 region_info->width=region_info->height;
1673 if ((flags & HeightValue) == 0)
1674 region_info->height=region_info->width;
1712 MagickExport MagickStatusType ParseRegionGeometry(
const Image *image,
1718 SetGeometry(image,region_info);
1719 flags=ParseMetaGeometry(geometry,®ion_info->x,®ion_info->y,
1720 ®ion_info->width,®ion_info->height);
1721 if (flags == NoValue)
1722 (void) ThrowMagickException(exception,GetMagickModule(),OptionError,
1723 "InvalidGeometry",
"`%s'",geometry);
1753 assert(image != (
Image *) NULL);
1754 assert(image->signature == MagickCoreSignature);
1755 if (IsEventLogging() != MagickFalse)
1756 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",image->filename);
1758 (void) memset(geometry,0,
sizeof(*geometry));
1759 geometry->width=image->columns;
1760 geometry->height=image->rows;
1785 MagickExport
void SetGeometryInfo(
GeometryInfo *geometry_info)
1788 if (IsEventLogging() != MagickFalse)
1789 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
1790 (void) memset(geometry_info,0,
sizeof(*geometry_info));