]> granicus.if.org Git - imagemagick/commitdiff
...
authorCristy <urban-warrior@imagemagick.org>
Sat, 6 Jan 2018 22:31:25 +0000 (17:31 -0500)
committerCristy <urban-warrior@imagemagick.org>
Sat, 6 Jan 2018 22:31:25 +0000 (17:31 -0500)
MagickCore/geometry.c
MagickCore/geometry.h

index 2a78203b738f071732a7266409c74e8aa138b7e0..7c792d76b33bdd167d1374f440a6124688ddf1fa 100644 (file)
@@ -129,6 +129,12 @@ MagickExport MagickStatusType GetGeometry(const char *geometry,ssize_t *x,
     c=(int)*p;
     switch (c)
     {
+      case '~':
+      {
+        flags|=TildeValue;
+        (void) CopyMagickString(p,p+1,MagickPathExtent);
+        break;
+      }
       case '%':
       {
         flags|=PercentValue;
@@ -887,6 +893,12 @@ MagickExport MagickStatusType ParseGeometry(const char *geometry,
       }
     switch (c)
     {
+      case '~':
+      {
+        flags|=TildeValue;
+        (void) CopyMagickString(p,p+1,MagickPathExtent);
+        break;
+      }
       case '%':
       {
         flags|=PercentValue;
@@ -1225,6 +1237,43 @@ MagickExport MagickStatusType ParseGravityGeometry(const Image *image,
       region_info->width=(size_t) floor((scale.x*image->columns/100.0)+0.5);
       region_info->height=(size_t) floor((scale.y*image->rows/100.0)+0.5);
     }
+  if ((flags & TildeValue) != 0)
+    {
+      double
+        geometry_aspect,
+        image_aspect;
+
+      GeometryInfo
+        geometry_info;
+
+      MagickStatusType
+        status;
+
+      PointInfo
+        scale;
+
+      /*
+        Geometry is a relative to image size and aspect ratio.
+      */
+      if (image->gravity != UndefinedGravity)
+        flags|=XValue | YValue;
+      status=ParseGeometry(geometry,&geometry_info);
+      scale.x=geometry_info.rho;
+      scale.y=geometry_info.sigma;
+      if ((status & SigmaValue) == 0)
+        scale.y=scale.x;
+      geometry_aspect=scale.x/scale.y;
+      image_aspect=image->columns/(double) image->rows;
+      region_info->width=image->columns;
+      region_info->height=image->rows;
+      if (geometry_aspect >= image_aspect)
+        {
+          region_info->width=(size_t) floor((image->columns*geometry_aspect/
+            image_aspect)+0.5);
+          region_info->height=(size_t) floor((image->rows*image_aspect/
+            geometry_aspect)+0.5);
+        }
+    }
   /*
     Adjust offset according to gravity setting.
   */
@@ -1336,6 +1385,43 @@ MagickExport MagickStatusType ParseMetaGeometry(const char *geometry,ssize_t *x,
       former_width=(*width);
       former_height=(*height);
     }
+  if ((flags & TildeValue) != 0)
+    {
+      double
+        geometry_aspect,
+        image_aspect;
+
+      GeometryInfo
+        geometry_info;
+
+      MagickStatusType
+        status;
+
+      PointInfo
+        scale;
+
+      /*
+        Geometry is a relative to image size and aspect ratio.
+      */
+      status=ParseGeometry(geometry,&geometry_info);
+      scale.x=geometry_info.rho;
+      scale.y=geometry_info.sigma;
+      if ((status & SigmaValue) == 0)
+        scale.y=scale.x;
+      geometry_aspect=scale.x/scale.y;
+      image_aspect=former_width/(double) former_height;
+      *width=former_width;
+      *height=former_height;
+      if (geometry_aspect >= image_aspect)
+        {
+          *width=(size_t) floor((former_width*geometry_aspect/
+            image_aspect)+0.5);
+          *height=(size_t) floor((former_height*image_aspect/
+            geometry_aspect)+0.5);
+        }
+      former_width=(*width);
+      former_height=(*height);
+    }
   if (((flags & AspectValue) != 0) || ((*width == former_width) &&
       (*height == former_height)))
     {
index e882dfaa359c3915fca64bbd0f432088e72ae2d5..e90ac8ee829b09cc933d7bfa23159d3bd4ca78b8 100644 (file)
@@ -46,16 +46,17 @@ typedef enum
 #undef YNegative
   YNegative = 0x0040,
   ChiNegative = 0x0080,
-  PercentValue = 0x1000,   /* '%'  percentage of something */
-  AspectValue = 0x2000,    /* '!'  resize no-aspect - special use flag */
-  NormalizeValue = 0x2000, /* '!'  ScaleKernelValue() in morphology.c */
-  LessValue = 0x4000,      /* '<'  resize smaller - special use flag */
-  GreaterValue = 0x8000,   /* '>'  resize larger - spacial use flag */
-  MinimumValue = 0x10000,  /* '^'  special handling needed */
+  PercentValue = 0x1000,    /* '%'  percentage of something */
+  AspectValue = 0x2000,     /* '!'  resize no-aspect - special use flag */
+  NormalizeValue = 0x2000,  /* '!'  ScaleKernelValue() in morphology.c */
+  LessValue = 0x4000,       /* '<'  resize smaller - special use flag */
+  GreaterValue = 0x8000,    /* '>'  resize larger - spacial use flag */
+  MinimumValue = 0x10000,   /* '^'  special handling needed */
   CorrelateNormalizeValue = 0x10000, /* '^' see ScaleKernelValue() */
-  AreaValue = 0x20000,     /* '@'  resize to area - special use flag */
-  DecimalValue = 0x40000,  /* '.'  floating point numbers found */
-  SeparatorValue = 0x80000,  /* 'x'  separator found  */
+  AreaValue = 0x20000,      /* '@'  resize to area - special use flag */
+  DecimalValue = 0x40000,   /* '.'  floating point numbers found */
+  SeparatorValue = 0x80000, /* 'x'  separator found  */
+  TildeValue = 0x100000,    /* '~'  special handling needed  */
 #undef AllValues
   AllValues = 0x7fffffff
 } GeometryFlags;