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