@@ -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];