From 729fb74fec2d588f4b7d3eb420e0efe49e7c5e24 Mon Sep 17 00:00:00 2001 From: sam Date: Fri, 29 Aug 2008 00:03:50 +0000 Subject: [PATCH] * blur.c: support wrap around images in box blur (it's actually support for non-wrap-around images; wrap around was the default behaviour). git-svn-id: file:///srv/caca.zoy.org/var/lib/svn/libpipi/trunk@2802 92316355-f0b4-4df1-b90c-862c8a59935f --- pipi/filter/blur.c | 52 +++++++++++++++++++++++++++++++++++----------- 1 file changed, 40 insertions(+), 12 deletions(-) diff --git a/pipi/filter/blur.c b/pipi/filter/blur.c index 60247f0..bfc8645 100644 --- a/pipi/filter/blur.c +++ b/pipi/filter/blur.c @@ -28,7 +28,7 @@ #include "pipi_internals.h" #if !defined TEMPLATE_FILE /* This file uses the template system */ -#define TEMPLATE_FLAGS SET_FLAG_GRAY +#define TEMPLATE_FLAGS SET_FLAG_GRAY | SET_FLAG_WRAP #define TEMPLATE_FILE "filter/blur.c" #include "pipi_template.h" @@ -131,22 +131,31 @@ pipi_image_t *pipi_box_blur(pipi_image_t *src, int size) pipi_image_t *pipi_box_blur_ext(pipi_image_t *src, int m, int n) { - if(src->last_modified == PIPI_PIXELS_Y_F) - return boxblur_gray(src, m, n); + if(src->wrap) + { + if(src->last_modified == PIPI_PIXELS_Y_F) + return boxblur_gray_wrap(src, m, n); + + return boxblur_wrap(src, m, n); + } + else + { + if(src->last_modified == PIPI_PIXELS_Y_F) + return boxblur_gray(src, m, n); - return boxblur(src, m, n); + return boxblur(src, m, n); + } } #else /* XXX: the following functions use the template system */ -/* FIXME: FLAG_WRAP */ static pipi_image_t *SUFFIX(boxblur)(pipi_image_t *src, int m, int n) { pipi_image_t *dst; pipi_pixels_t *srcp, *dstp; float *srcdata, *dstdata; double *acc; - int x, y, w, h, i, j, size; + int x, y, w, h, i, j, i2, j2, size; w = src->w; h = src->h; @@ -171,7 +180,11 @@ static pipi_image_t *SUFFIX(boxblur)(pipi_image_t *src, int m, int n) for(j = -n; j <= n; j++) { - int j2 = (j < 0) ? h - 1 - ((-j - 1) % h) : j % h; + if(FLAG_WRAP) + j2 = (j < 0) ? h - 1 - ((-j - 1) % h) : j % h; + else + j2 = (j < 0) ? 0 : (j >= h) ? h - 1 : j; + if(FLAG_GRAY) t += srcdata[j2 * w + x]; else @@ -203,7 +216,10 @@ static pipi_image_t *SUFFIX(boxblur)(pipi_image_t *src, int m, int n) /* 2.1: compute the first pixel */ for(i = -m; i <= m; i++) { - int i2 = (i < 0) ? w - 1 - ((-i - 1) % w) : i % w; + if(FLAG_WRAP) + i2 = (i < 0) ? w - 1 - ((-i - 1) % w) : i % w; + else + i2 = (i < 0) ? 0 : (i >= w) ? w - 1 : i; if(FLAG_GRAY) t += acc[i2]; @@ -234,9 +250,15 @@ static pipi_image_t *SUFFIX(boxblur)(pipi_image_t *src, int m, int n) } u = x - m; - u2 = (u < 0) ? w - 1 - ((-u - 1) % w) : u % w; + if(FLAG_WRAP) + u2 = (u < 0) ? w - 1 - ((-u - 1) % w) : u % w; + else + u2 = (u < 0) ? 0 : (u >= w) ? w - 1 : u; v = x + m + 1; - v2 = (v < 0) ? w - 1 - ((-v - 1) % w) : v % w; + if(FLAG_WRAP) + v2 = (v < 0) ? w - 1 - ((-v - 1) % w) : v % w; + else + v2 = (v < 0) ? 0 : (v >= w) ? w - 1 : v; if(FLAG_GRAY) { t = t - acc[u2] + acc[v2]; @@ -256,9 +278,15 @@ static pipi_image_t *SUFFIX(boxblur)(pipi_image_t *src, int m, int n) int u, u2, v, v2; u = y - n; - u2 = (u < 0) ? w - 1 - ((-u - 1) % w) : u % w; + if(FLAG_WRAP) + u2 = (u < 0) ? w - 1 - ((-u - 1) % w) : u % w; + else + u2 = (u < 0) ? 0 : (u >= w) ? w - 1 : u; v = y + n + 1; - v2 = (v < 0) ? w - 1 - ((-v - 1) % w) : v % w; + if(FLAG_WRAP) + v2 = (v < 0) ? w - 1 - ((-v - 1) % w) : v % w; + else + v2 = (v < 0) ? 0 : (v >= w) ? w - 1 : v; if(FLAG_GRAY) { acc[x] += srcdata[v2 * w + x] - srcdata[u2 * w + x];