瀏覽代碼

* blur.c: support for variable blur radius and Gaussian offset.

git-svn-id: file:///srv/caca.zoy.org/var/lib/svn/libpipi/trunk@2617 92316355-f0b4-4df1-b90c-862c8a59935f
remotes/tiles
sam 16 年之前
父節點
當前提交
4a857277a7
共有 2 個檔案被更改,包括 33 行新增14 行删除
  1. +31
    -14
      pipi/filter/blur.c
  2. +2
    -0
      pipi/pipi.h

+ 31
- 14
pipi/filter/blur.c 查看文件

@@ -28,6 +28,12 @@
#include "pipi_internals.h"

pipi_image_t *pipi_gaussian_blur(pipi_image_t *src, float radius)
{
return pipi_gaussian_blur_ext(src, radius, radius, 0.0, 0.0);
}

pipi_image_t *pipi_gaussian_blur_ext(pipi_image_t *src, float rx, float ry,
float dx, float dy)
{
pipi_image_t *dst;
pipi_pixels_t *srcp, *dstp;
@@ -46,23 +52,23 @@ pipi_image_t *pipi_gaussian_blur(pipi_image_t *src, float radius)
dstp = pipi_getpixels(dst, PIPI_PIXELS_RGBA_F);
dstdata = (float *)dstp->pixels;

kr = (int)(3. * radius + 0.99999);
buffer = malloc(w * h * 4 * sizeof(double));

kr = (int)(3. * rx + 0.99999);
kw = 2 * kr + 1;
K = 1. / (sqrt(2. * M_PI) * radius);
L = -1. / (2. * radius * radius);
K = 1. / (sqrt(2. * M_PI) * rx);
L = -1. / (2. * rx * rx);

kernel = malloc(kw * sizeof(double));
for(i = -kr; i <= kr; i++)
kernel[i + kr] = exp(L * i * i) * K;

buffer = malloc(w * h * 4 * sizeof(double));
kernel[i + kr] = exp(L * ((double)i - dx) * ((double)i - dx)) * K;

for(y = 0; y < h; y++)
{
for(x = 0; x < w; x++)
{
double R = 0., G = 0., B = 0., t = 0.;
int x2;
int x2, off = 4 * (y * w + x);

for(i = -kr; i <= kr; i++)
{
@@ -78,18 +84,29 @@ pipi_image_t *pipi_gaussian_blur(pipi_image_t *src, float radius)
t += f;
}

buffer[(y * w + x) * 4] = R / t;
buffer[(y * w + x) * 4 + 1] = G / t;
buffer[(y * w + x) * 4 + 2] = B / t;
buffer[off] = R / t;
buffer[off + 1] = G / t;
buffer[off + 2] = B / t;
}
}

free(kernel);

kr = (int)(3. * ry + 0.99999);
kw = 2 * kr + 1;
K = 1. / (sqrt(2. * M_PI) * ry);
L = -1. / (2. * ry * ry);

kernel = malloc(kw * sizeof(double));
for(i = -kr; i <= kr; i++)
kernel[i + kr] = exp(L * ((double)i - dy) * ((double)i - dy)) * K;

for(y = 0; y < h; y++)
{
for(x = 0; x < w; x++)
{
double R = 0., G = 0., B = 0., t = 0.;
int y2;
int y2, off = 4 * (y * w + x);

for(i = -kr; i <= kr; i++)
{
@@ -105,9 +122,9 @@ pipi_image_t *pipi_gaussian_blur(pipi_image_t *src, float radius)
t += f;
}

dstdata[(y * w + x) * 4] = R / t;
dstdata[(y * w + x) * 4 + 1] = G / t;
dstdata[(y * w + x) * 4 + 2] = B / t;
dstdata[off] = R / t;
dstdata[off + 1] = G / t;
dstdata[off + 2] = B / t;
}
}



+ 2
- 0
pipi/pipi.h 查看文件

@@ -58,6 +58,8 @@ extern pipi_pixels_t *pipi_getpixels(pipi_image_t *, pipi_format_t);
extern pipi_image_t *pipi_resize(pipi_image_t *, int, int);

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 void pipi_dither_24to16(pipi_image_t *);



Loading…
取消
儲存