]> granicus.if.org Git - imagemagick/commitdiff
Fix small blur handling in variable blur mapping
authoranthony <anthony@git.imagemagick.org>
Sun, 13 Feb 2011 01:19:17 +0000 (01:19 +0000)
committeranthony <anthony@git.imagemagick.org>
Sun, 13 Feb 2011 01:19:17 +0000 (01:19 +0000)
ChangeLog
magick/composite.c

index 93c4315aef1601b1d30a6e664cd8378a0925831d..79dd47c7939d189485461659a4f84b8d16b1ef94 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+2011-02-13  6.6.7-7 Anthony Thyssen <A.Thyssen@griffith...>
+  * Fixed Variable blur to handle small (< 1.0 sigma) blurs generated
+    by the blur map being used, rather than just 'cutoff' suddenly.
+
 2011-02-08  6.6.7-7 Cristy  <quetzlzacatenango@image...>
   * Support 16-bit per pixel YUV image files.
   * Fix off-by-one error in PosterizeImage().
index a0bded0f6edab2527d34b254cbcc8cc33e81f282..88f7ae17a9cc142af01f77817afbe615350a43c3 100644 (file)
@@ -1730,12 +1730,13 @@ MagickExport MagickBooleanType CompositeImageChannel(Image *image,
           destination_image=DestroyImage(destination_image);
           return(MagickFalse);
         }
-      width=geometry_info.rho;
-      height=geometry_info.sigma;
-      blur.x1=geometry_info.rho;
+      /* Set up ellipse, Scales for blur map values */
+      width=geometry_info.rho*QuantumScale;
+      height=geometry_info.sigma*QuantumScale;
+      blur.x1=1.0;
       blur.x2=0.0;
       blur.y1=0.0;
-      blur.y2=geometry_info.sigma;
+      blur.y2=1.0;
       angle_start=0.0;
       angle_range=0.0;
       if ((flags & HeightValue) == 0)
@@ -1746,10 +1747,12 @@ MagickExport MagickBooleanType CompositeImageChannel(Image *image,
             angle;
 
           angle=DegreesToRadians(geometry_info.xi);
-          blur.x1=width*cos(angle);
-          blur.x2=width*sin(angle);
-          blur.y1=(-height*sin(angle));
-          blur.y2=height*cos(angle);
+          blur.x1=cos(angle);
+          blur.x2=sin(angle);
+          blur.y1=-sin(angle);
+          blur.y2=cos(angle);
+//fprintf(stderr, "y=? angle=%lf, x1=%lf, x2=%lf, y1=%lf, y2=%lf\n",
+//   RadiansToDegrees(angle),blur.x1,blur.x2,blur.y1,blur.y2);
         }
       if ((flags & YValue) != 0 )
         {
@@ -1762,7 +1765,7 @@ MagickExport MagickBooleanType CompositeImageChannel(Image *image,
       pixel=zero;
       exception=(&image->exception);
       resample_filter=AcquireResampleFilter(image,&image->exception);
-      SetResampleFilter(resample_filter,GaussianFilter,2.0);
+      SetResampleFilter(resample_filter,CubicFilter,2.0);
       destination_view=AcquireCacheView(destination_image);
       composite_view=AcquireCacheView(composite_image);
       for (y=0; y < (ssize_t) composite_image->rows; y++)
@@ -1798,6 +1801,18 @@ MagickExport MagickBooleanType CompositeImageChannel(Image *image,
               p++;
               continue;
             }
+          /* if w or h blurs are getting too small,
+           * adjust the filter sigma, rather than the ellipse
+           */
+          MagickRealType
+            w=width*GetRedPixelComponent(p),
+            h=height*GetGreenPixelComponent(p),
+            b=MagickMax(w,h) + MagickEpsilon;
+          if ( b < 1.0 )
+            w /= b, h /= b; /* make sure ellipse does not get too small */
+          else
+            b = 1.0;
+          /* rotate the ellipse */
           if (fabs(angle_range) > MagickEpsilon)
             {
               MagickRealType
@@ -1805,14 +1820,18 @@ MagickExport MagickBooleanType CompositeImageChannel(Image *image,
 
               angle=angle_start+angle_range*QuantumScale*
                 GetBluePixelComponent(p);
-              blur.x1=width*cos(angle);
-              blur.x2=width*sin(angle);
-              blur.y1=(-height*sin(angle));
-              blur.y2=height*cos(angle);
+
+              blur.x1=cos(angle);
+              blur.x2=sin(angle);
+              blur.y1=-sin(angle);
+              blur.y2=cos(angle);
+//if (y == 0);
+//fprintf(stderr, "y=%d angle=%lf, x1=%lf, x2=%lf, y1=%lf, y2=%lf\n",
+//   y, RadiansToDegrees(angle),blur.x1,blur.x2,blur.y1,blur.y2);
             }
-          ScaleResampleFilter(resample_filter,blur.x1*QuantumScale*p->red,
-            blur.y1*QuantumScale*p->green,blur.x2*QuantumScale*p->red,
-            blur.y2*QuantumScale*GetGreenPixelComponent(p));
+          SetResampleFilter(resample_filter,GaussianFilter,2.0*b);
+          ScaleResampleFilter(resample_filter,blur.x1*w,blur.y1*h,
+               blur.x2*w,blur.y2*h);
           (void) ResamplePixelColor(resample_filter,(double) x_offset+x,
             (double) y_offset+y,&pixel);
           SetPixelPacket(destination_image,&pixel,r,destination_indexes+x);