瀏覽代碼

* 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
remotes/tiles
sam 16 年之前
父節點
當前提交
729fb74fec
共有 1 個文件被更改,包括 40 次插入12 次删除
  1. +40
    -12
      pipi/filter/blur.c

+ 40
- 12
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];


Loading…
取消
儲存