@@ -34,27 +34,34 @@
pipi_image_t *pipi_gaussian_blur(pipi_image_t *src, float radius)
{
return pipi_gaussian_blur_ext(src, radius, radius, 0.0, 0.0);
return pipi_gaussian_blur_ext(src, radius, radius, 0.0, 0.0, 0.0 );
}
pipi_image_t *pipi_gaussian_blur_ext(pipi_image_t *src, float rx, float ry,
float dx, float dy)
float angle, float dx, float dy)
{
pipi_image_t *ret;
double *kernel;
double Kx, Ky, t = 0.0;
double Kx, Ky, t = 0.0, sint, cost, bbx, bby ;
int i, j, krx, kry, m, n;
if(rx < BLUR_EPSILON) rx = BLUR_EPSILON;
if(ry < BLUR_EPSILON) ry = BLUR_EPSILON;
sint = sin(angle * M_PI / 180.);
cost = cos(angle * M_PI / 180.);
/* Compute the final ellipse's bounding box */
bbx = sqrt(rx * rx * cost * cost + ry * ry * sint * sint);
bby = sqrt(ry * ry * cost * cost + rx * rx * sint * sint);
/* FIXME: the kernel becomes far too big with large values of dx, because
* we grow both left and right. Fix the growing direction. */
krx = (int)(3. * rx + .99999 + ceil(abs(dx)));
krx = (int)(3. * bb x + .99999 + ceil(abs(dx)));
m = 2 * krx + 1;
Kx = -1. / (2. * rx * rx);
kry = (int)(3. * ry + .99999 + ceil(abs(dy)));
kry = (int)(3. * bb y + .99999 + ceil(abs(dy)));
n = 2 * kry + 1;
Ky = -1. / (2. * ry * ry);
@@ -62,11 +69,12 @@ pipi_image_t *pipi_gaussian_blur_ext(pipi_image_t *src, float rx, float ry,
for(j = -kry; j <= kry; j++)
{
double ey = Ky * ((double)j + dy) * ((double)j + dy);
for(i = -krx; i <= krx; i++)
{
double ex = Kx * ((double)i + dx) * ((double)i + dx);
double u = (double)i * cost - (double)j * sint + dx;
double v = (double)j * cost + (double)i * sint + dy;
double ex = Kx * u * u;
double ey = Ky * v * v;
double d = exp(ex + ey);
kernel[(j + kry) * m + i + krx] = d;