diff --git a/pipi/filter/blur.c b/pipi/filter/blur.c index 2a61940..f01727f 100644 --- a/pipi/filter/blur.c +++ b/pipi/filter/blur.c @@ -85,3 +85,27 @@ pipi_image_t *pipi_gaussian_blur_ext(pipi_image_t *src, float rx, float ry, return ret; } +/* FIXME: box blur would be incredibly faster using an accumulator instead + * of a convolution filter... */ +pipi_image_t *pipi_box_blur(pipi_image_t *src, int size) +{ + return pipi_box_blur_ext(src, size, size); +} + +pipi_image_t *pipi_box_blur_ext(pipi_image_t *src, int m, int n) +{ + pipi_image_t *ret; + double *kernel; + int i; + + kernel = malloc(m * n * sizeof(double)); + for(i = 0; i < m * n; i++) + kernel[i] = 1. / (m * n); + + ret = pipi_convolution(src, m, n, kernel); + + free(kernel); + + return ret; +} + diff --git a/pipi/pipi.h b/pipi/pipi.h index d9187fc..fec1bad 100644 --- a/pipi/pipi.h +++ b/pipi/pipi.h @@ -81,6 +81,8 @@ extern pipi_image_t *pipi_convolution(pipi_image_t *, int, int, double[]); extern pipi_image_t *pipi_gaussian_blur(pipi_image_t *, float); extern pipi_image_t *pipi_gaussian_blur_ext(pipi_image_t *, float, float, float, float); +extern pipi_image_t *pipi_box_blur(pipi_image_t *, int); +extern pipi_image_t *pipi_box_blur_ext(pipi_image_t *, int, int); extern pipi_image_t *pipi_autocontrast(pipi_image_t *); extern int pipi_flood_fill(pipi_image_t *,