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=((size_t) floor(StringToDouble(p,&p)+0.5)) & 0x7fffffff;
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=((
size_t) floor(StringToDouble(p,&p)+0.5)) & 0x7fffffff;
383 if ((*p ==
'+') || (*p ==
'-'))
388 while ((*p ==
'+') || (*p ==
'-'))
395 if (x != (ssize_t *) NULL)
396 *x=((ssize_t) ceil(StringToDouble(p,&p)-0.5)) & 0x7fffffff;
400 if (((flags & XNegative) != 0) && (x != (ssize_t *) NULL))
404 if ((*p ==
'+') || (*p ==
'-'))
409 while ((*p ==
'+') || (*p ==
'-'))
416 if (y != (ssize_t *) NULL)
417 *y=((ssize_t) ceil(StringToDouble(p,&p)-0.5)) & 0x7fffffff;
421 if (((flags & YNegative) != 0) && (y != (ssize_t *) NULL))
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; i < (ssize_t) (
sizeof(Pagesizes)/
sizeof(Pagesizes[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=(ssize_t) (width-region->width-region->x);
571 region->x+=(ssize_t) (width/2-region->width/2);
575 case NorthWestGravity:
577 case SouthWestGravity:
583 case SouthWestGravity:
585 case SouthEastGravity:
587 region->y=(ssize_t) (height-region->height-region->y);
595 region->y+=(ssize_t) (height/2-region->height/2);
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 if (file == (FILE *) NULL)
737 (void) FormatLocaleFile(file,
"\nPagesize Geometry \n");
738 (void) FormatLocaleFile(file,
"---------------------\n");
739 for (i=0; *Pagesizes[i].name !=
'\0'; i++)
740 (
void) FormatLocaleFile(file,
"%s%.*s%s\n",Pagesizes[i].name,
741 MaxMagickSpaces-(
int) Pagesizes[i].extent,spacer,Pagesizes[i].geometry);
774 MagickExport MagickStatusType ParseAbsoluteGeometry(
const char *geometry,
780 flags=GetGeometry(geometry,®ion_info->x,®ion_info->y,
781 ®ion_info->width,®ion_info->height);
815 MagickExport MagickStatusType ParseAffineGeometry(
const char *geometry,
819 token[MaxTextExtent];
833 GetAffineMatrix(affine_matrix);
836 for (i=0; (*p !=
'\0') && (i < 6); i++)
838 (void) GetNextToken(p,&p,MaxTextExtent,token);
840 (void) GetNextToken(p,&p,MaxTextExtent,token);
845 affine_matrix->sx=StringToDouble(token,(
char **) NULL);
850 affine_matrix->rx=StringToDouble(token,(
char **) NULL);
855 affine_matrix->ry=StringToDouble(token,(
char **) NULL);
860 affine_matrix->sy=StringToDouble(token,(
char **) NULL);
865 affine_matrix->tx=StringToDouble(token,(
char **) NULL);
871 affine_matrix->ty=StringToDouble(token,(
char **) NULL);
877 determinant=(affine_matrix->sx*affine_matrix->sy-affine_matrix->rx*
879 if (fabs(determinant) < MagickEpsilon)
880 (
void) ThrowMagickException(exception,GetMagickModule(),OptionError,
881 "InvalidArgument",
"'%s' : 'Indeterminate Matrix'",geometry);
924 MagickExport MagickStatusType ParseGeometry(
const char *geometry,
929 pedantic_geometry[MaxTextExtent],
945 (void) memset(geometry_info,0,
sizeof(*geometry_info));
947 if ((geometry == (
char *) NULL) || (*geometry ==
'\0'))
949 if (strlen(geometry) >= (MaxTextExtent-1))
951 (void) CopyMagickString(pedantic_geometry,geometry,MaxTextExtent);
952 for (p=pedantic_geometry; *p !=
'\0'; )
954 c=(int) ((
unsigned char) *p);
955 if (isspace((
int) ((
unsigned char) c)) != 0)
957 (void) CopyMagickString(p,p+1,MaxTextExtent);
965 (void) CopyMagickString(p,p+1,MaxTextExtent);
971 (void) CopyMagickString(p,p+1,MaxTextExtent);
977 (void) CopyMagickString(p,p+1,MaxTextExtent);
983 (void) CopyMagickString(p,p+1,MaxTextExtent);
989 (void) CopyMagickString(p,p+1,MaxTextExtent);
995 (void) CopyMagickString(p,p+1,MaxTextExtent);
1002 (void) CopyMagickString(p,p+1,MaxTextExtent);
1007 (void) CopyMagickString(p,p+1,MaxTextExtent);
1013 flags|=SeparatorValue;
1041 flags|=DecimalValue;
1047 flags|=AspectRatioValue;
1057 p=pedantic_geometry;
1061 value=StringToDouble(p,&q);
1062 if (LocaleNCompare(p,
"0x",2) == 0)
1063 (void) strtol(p,&q,10);
1064 c=(int) ((
unsigned char) *q);
1065 if ((c == 215) || (*q ==
'x') || (*q ==
'X') || (*q ==
':') ||
1066 (*q ==
',') || (*q ==
'/') || (*q ==
'\0'))
1072 if (LocaleNCompare(p,
"0x",2) == 0)
1073 value=(
double) strtol(p,&p,10);
1075 value=StringToDouble(p,&p);
1079 geometry_info->rho=value;
1083 c=(int) ((
unsigned char) *p);
1084 if ((c == 215) || (*p ==
'x') || (*p ==
'X') || (*p ==
':') || (*p ==
',') ||
1091 while (isspace((
int) ((
unsigned char) *p)) != 0)
1093 c=(int) ((
unsigned char) *q);
1094 if (((c != 215) && (*q !=
'x') && (*q !=
'X') && (*q !=
':')) ||
1095 ((*p !=
'+') && (*p !=
'-')))
1098 value=StringToDouble(p,&p);
1102 geometry_info->sigma=value;
1106 while (isspace((
int) ((
unsigned char) *p)) != 0)
1108 if ((*p ==
'+') || (*p ==
'-') || (*p ==
',') || (*p ==
'/') || (*p ==
':'))
1113 if ((*p ==
',') || (*p ==
'/') || (*p ==
':') )
1115 while ((*p ==
'+') || (*p ==
'-'))
1122 value=StringToDouble(p,&p);
1126 if ((flags & XiNegative) != 0)
1128 geometry_info->xi=value;
1130 while (isspace((
int) ((
unsigned char) *p)) != 0)
1132 if ((*p ==
'+') || (*p ==
'-') || (*p ==
',') || (*p ==
'/') ||
1138 if ((*p ==
',') || (*p ==
'/') || (*p ==
':'))
1140 while ((*p ==
'+') || (*p ==
'-'))
1147 value=StringToDouble(p,&p);
1151 if ((flags & PsiNegative) != 0)
1153 geometry_info->psi=value;
1156 while (isspace((
int) ((
unsigned char) *p)) != 0)
1158 if ((*p ==
'+') || (*p ==
'-') || (*p ==
',') || (*p ==
'/') ||
1164 if ((*p ==
',') || (*p ==
'/') || (*p ==
':'))
1166 while ((*p ==
'+') || (*p ==
'-'))
1173 value=StringToDouble(p,&p);
1177 if ((flags & ChiNegative) != 0)
1179 geometry_info->chi=value;
1183 if (strchr(pedantic_geometry,
':') != (
char *) NULL)
1188 if ((flags & SigmaValue) != 0)
1189 geometry_info->rho*=PerceptibleReciprocal(geometry_info->sigma);
1190 geometry_info->sigma=1.0;
1191 if (((flags & XiValue) != 0) && (geometry_info->xi == 0.0))
1192 geometry_info->sigma=2.0;
1194 if (((flags & RhoValue) != 0) && ((flags & SigmaValue) == 0) &&
1195 ((flags & XiValue) != 0) && ((flags & XiNegative) != 0))
1197 if ((flags & PsiValue) == 0)
1202 geometry_info->sigma=geometry_info->xi;
1203 geometry_info->xi=0.0;
1208 if ((flags & ChiValue) == 0)
1213 geometry_info->sigma=geometry_info->xi;
1214 geometry_info->xi=geometry_info->psi;
1224 geometry_info->sigma=geometry_info->xi;
1225 geometry_info->xi=geometry_info->psi;
1226 geometry_info->psi=geometry_info->chi;
1233 if ((flags & PercentValue) != 0)
1235 if (((flags & SeparatorValue) == 0) && ((flags & SigmaValue) == 0))
1236 geometry_info->sigma=geometry_info->rho;
1237 if (((flags & SeparatorValue) != 0) && ((flags & RhoValue) == 0))
1238 geometry_info->rho=geometry_info->sigma;
1242 (void) fprintf(stderr,
"ParseGeometry...\n");
1243 (void) fprintf(stderr,
"Flags: %c %c %s %s %s\n",
1244 (flags & RhoValue) ?
'W' :
' ',(flags & SigmaValue) ?
'H' :
' ',
1245 (flags & XiValue) ? ((flags & XiNegative) ?
"-X" :
"+X") :
" ",
1246 (flags & PsiValue) ? ((flags & PsiNegative) ?
"-Y" :
"+Y") :
" ",
1247 (flags & ChiValue) ? ((flags & ChiNegative) ?
"-Z" :
"+Z") :
" ");
1248 (void) fprintf(stderr,
"Geometry: %lg,%lg,%lg,%lg,%lg\n",geometry_info->rho,
1249 geometry_info->sigma,geometry_info->xi,geometry_info->psi,
1250 geometry_info->chi);
1292 MagickExport MagickStatusType ParseGravityGeometry(
const Image *image,
1302 SetGeometry(image,region_info);
1303 if (image->page.width != 0)
1304 region_info->width=image->page.width;
1305 if (image->page.height != 0)
1306 region_info->height=image->page.height;
1307 flags=ParseAbsoluteGeometry(geometry,region_info);
1308 if (flags == NoValue)
1310 (void) ThrowMagickException(exception,GetMagickModule(),OptionError,
1311 "InvalidGeometry",
"`%s'",geometry);
1314 if ((flags & PercentValue) != 0)
1328 if (image->gravity != UndefinedGravity)
1329 flags|=XValue | YValue;
1330 status=ParseGeometry(geometry,&geometry_info);
1331 scale.x=geometry_info.rho;
1332 if ((status & RhoValue) == 0)
1334 scale.y=geometry_info.sigma;
1335 if ((status & SigmaValue) == 0)
1337 region_info->width=(size_t) floor((scale.x*image->columns/100.0)+0.5);
1338 region_info->height=(size_t) floor((scale.y*image->rows/100.0)+0.5);
1340 if ((flags & AspectRatioValue) != 0)
1352 if (image->gravity != UndefinedGravity)
1353 flags|=XValue | YValue;
1354 (void) ParseGeometry(geometry,&geometry_info);
1355 geometry_ratio=geometry_info.rho;
1356 image_ratio=(double) image->columns/image->rows;
1357 if (geometry_ratio >= image_ratio)
1359 region_info->width=image->columns;
1360 region_info->height=(size_t) floor((
double) (image->rows*image_ratio/
1361 geometry_ratio)+0.5);
1365 region_info->width=(size_t) floor((
double) (image->columns*
1366 geometry_ratio/image_ratio)+0.5);
1367 region_info->height=image->rows;
1373 width=region_info->width;
1374 height=region_info->height;
1376 region_info->width=image->page.width | image->columns;
1378 region_info->height=image->page.height | image->rows;
1379 GravityAdjustGeometry(image->columns,image->rows,image->gravity,region_info);
1380 region_info->width=width;
1381 region_info->height=height;
1428 MagickExport MagickStatusType ParseMetaGeometry(
const char *geometry,ssize_t *x,
1429 ssize_t *y,
size_t *width,
size_t *height)
1444 assert(x != (ssize_t *) NULL);
1445 assert(y != (ssize_t *) NULL);
1446 assert(width != (
size_t *) NULL);
1447 assert(height != (
size_t *) NULL);
1448 if ((geometry == (
char *) NULL) || (*geometry ==
'\0'))
1450 if (IsEventLogging() != MagickFalse)
1451 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",geometry);
1455 SetGeometryInfo(&geometry_info);
1456 former_width=(*width);
1457 former_height=(*height);
1458 flags=GetGeometry(geometry,x,y,width,height);
1459 if ((flags & PercentValue) != 0)
1470 flags=ParseGeometry(geometry,&geometry_info);
1471 scale.x=geometry_info.rho;
1472 if ((flags & RhoValue) == 0)
1474 scale.y=geometry_info.sigma;
1475 if ((flags & SigmaValue) == 0)
1477 *width=(size_t) floor(scale.x*former_width/100.0+0.5);
1478 *height=(size_t) floor(scale.y*former_height/100.0+0.5);
1479 former_width=(*width);
1480 former_height=(*height);
1482 if ((flags & AspectRatioValue) != 0)
1494 (void) ParseGeometry(geometry,&geometry_info);
1495 geometry_ratio=geometry_info.rho;
1496 image_ratio=(double) former_width*PerceptibleReciprocal(former_height);
1497 if (geometry_ratio >= image_ratio)
1499 *width=former_width;
1500 *height=(size_t) floor((
double) (PerceptibleReciprocal(
1501 geometry_ratio)*former_height*image_ratio)+0.5);
1505 *width=(size_t) floor((
double) (PerceptibleReciprocal(
1506 image_ratio)*former_width*geometry_ratio)+0.5);
1507 *height=former_height;
1509 former_width=(*width);
1510 former_height=(*height);
1512 if (((flags & AspectValue) != 0) || ((*width == former_width) &&
1513 (*height == former_height)))
1515 if ((flags & RhoValue) == 0)
1516 *width=former_width;
1517 if ((flags & SigmaValue) == 0)
1518 *height=former_height;
1528 if ((former_width == 0) || (former_height == 0))
1531 if (((flags & RhoValue) != 0) && (flags & SigmaValue) != 0)
1533 scale_factor=(double) *width/(
double) former_width;
1534 if ((flags & MinimumValue) == 0)
1536 if (scale_factor > ((
double) *height/(double) former_height))
1537 scale_factor=(
double) *height/(double) former_height;
1540 if (scale_factor < ((
double) *height/(double) former_height))
1541 scale_factor=(
double) *height/(double) former_height;
1544 if ((flags & RhoValue) != 0)
1546 scale_factor=(double) *width/(
double) former_width;
1547 if (((flags & MinimumValue) != 0) &&
1548 (scale_factor < ((
double) *width/(double) former_height)))
1549 scale_factor=(double) *width/(
double) former_height;
1553 scale_factor=(double) *height/(
double) former_height;
1554 if (((flags & MinimumValue) != 0) &&
1555 (scale_factor < ((
double) *height/(double) former_width)))
1556 scale_factor=(double) *height/(
double) former_width;
1558 *width=MagickMax((
size_t) floor(scale_factor*former_width+0.5),1UL);
1559 *height=MagickMax((
size_t) floor(scale_factor*former_height+0.5),1UL);
1561 if ((flags & GreaterValue) != 0)
1563 if (former_width < *width)
1564 *width=former_width;
1565 if (former_height < *height)
1566 *height=former_height;
1568 if ((flags & LessValue) != 0)
1570 if (former_width > *width)
1571 *width=former_width;
1572 if (former_height > *height)
1573 *height=former_height;
1575 if ((flags & AreaValue) != 0)
1587 (void) ParseGeometry(geometry,&geometry_info);
1588 area=geometry_info.rho+sqrt(MagickEpsilon);
1589 distance=sqrt((
double) former_width*former_height);
1590 scale.x=(double) former_width*PerceptibleReciprocal(distance*
1591 PerceptibleReciprocal(sqrt(area)));
1592 scale.y=(double) former_height*PerceptibleReciprocal(distance*
1593 PerceptibleReciprocal(sqrt(area)));
1594 if ((scale.x < (
double) *width) || (scale.y < (
double) *height))
1596 *width=(
unsigned long) (former_width*PerceptibleReciprocal(
1597 distance*PerceptibleReciprocal(sqrt(area))));
1598 *height=(
unsigned long) (former_height*PerceptibleReciprocal(
1599 distance*PerceptibleReciprocal(sqrt(area))));
1601 former_width=(*width);
1602 former_height=(*height);
1640 MagickExport MagickStatusType ParsePageGeometry(
const Image *image,
1646 SetGeometry(image,region_info);
1647 if (image->page.width != 0)
1648 region_info->width=image->page.width;
1649 if (image->page.height != 0)
1650 region_info->height=image->page.height;
1651 flags=ParseAbsoluteGeometry(geometry,region_info);
1652 if (flags == NoValue)
1654 (void) ThrowMagickException(exception,GetMagickModule(),OptionError,
1655 "InvalidGeometry",
"`%s'",geometry);
1658 if ((flags & PercentValue) != 0)
1660 region_info->width=image->columns;
1661 region_info->height=image->rows;
1663 flags=ParseMetaGeometry(geometry,®ion_info->x,®ion_info->y,
1664 ®ion_info->width,®ion_info->height);
1665 if ((((flags & WidthValue) != 0) || ((flags & HeightValue) != 0)) &&
1666 (((flags & PercentValue) != 0) || ((flags & SeparatorValue) == 0)))
1668 if ((flags & WidthValue) == 0)
1669 region_info->width=region_info->height;
1670 if ((flags & HeightValue) == 0)
1671 region_info->height=region_info->width;
1709 MagickExport MagickStatusType ParseRegionGeometry(
const Image *image,
1715 SetGeometry(image,region_info);
1716 flags=ParseMetaGeometry(geometry,®ion_info->x,®ion_info->y,
1717 ®ion_info->width,®ion_info->height);
1718 if (flags == NoValue)
1719 (void) ThrowMagickException(exception,GetMagickModule(),OptionError,
1720 "InvalidGeometry",
"`%s'",geometry);
1750 assert(image != (
Image *) NULL);
1751 assert(image->signature == MagickCoreSignature);
1752 if (IsEventLogging() != MagickFalse)
1753 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",image->filename);
1755 (void) memset(geometry,0,
sizeof(*geometry));
1756 geometry->width=image->columns;
1757 geometry->height=image->rows;
1782 MagickExport
void SetGeometryInfo(
GeometryInfo *geometry_info)
1785 if (IsEventLogging() != MagickFalse)
1786 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
1787 (void) memset(geometry_info,0,
sizeof(*geometry_info));