From 4a278923ff6bc3e81e51d3f37d51debe54c845a8 Mon Sep 17 00:00:00 2001 From: sam Date: Sat, 2 Aug 2008 12:12:58 +0000 Subject: [PATCH] * blur.c: adapt the kernel size to large values of dx and/or dy. * blur.c: fix the dx/dy sign meaning. git-svn-id: file:///srv/caca.zoy.org/var/lib/svn/libpipi/trunk@2643 92316355-f0b4-4df1-b90c-862c8a59935f --- pipi/filter/blur.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/pipi/filter/blur.c b/pipi/filter/blur.c index 8396341..3561071 100644 --- a/pipi/filter/blur.c +++ b/pipi/filter/blur.c @@ -66,13 +66,15 @@ pipi_image_t *pipi_gaussian_blur_ext(pipi_image_t *src, float rx, float ry, buffer = malloc(w * h * (gray ? 1 : 4) * sizeof(double)); - kr = (int)(3. * rx + 1.99999); + /* FIXME: the kernel becomes far too big with large values of dx, because + * we grow both left and right. Fix the growing direction. */ + kr = (int)(3. * rx + .99999 + ceil(abs(dx))); kw = 2 * kr + 1; K = -1. / (2. * rx * rx); kernel = malloc(kw * sizeof(double)); for(i = -kr; i <= kr; i++) - kernel[i + kr] = exp(K * ((double)i - dx) * ((double)i - dx)); + kernel[i + kr] = exp(K * ((double)i + dx) * ((double)i + dx)); for(y = 0; y < h; y++) { @@ -125,13 +127,13 @@ pipi_image_t *pipi_gaussian_blur_ext(pipi_image_t *src, float rx, float ry, free(kernel); - kr = (int)(3. * ry + 1.99999); + kr = (int)(3. * ry + .99999 + ceil(abs(dy))); kw = 2 * kr + 1; K = -1. / (2. * ry * ry); kernel = malloc(kw * sizeof(double)); for(i = -kr; i <= kr; i++) - kernel[i + kr] = exp(K * ((double)i - dy) * ((double)i - dy)); + kernel[i + kr] = exp(K * ((double)i + dy) * ((double)i + dy)); for(y = 0; y < h; y++) {