Changeset 2715


Ignore:
Timestamp:
Aug 14, 2008, 8:34:44 PM (12 years ago)
Author:
Sam Hocevar
Message:
  • blur.c: add an argument to the gaussian convolution to specify an angle. Of course since the kernel is no longer separable, it becomes awfully slow with large images. Here is a tileable brushed metal texture: # pipi pipi:random512x512 --wrap --blur 20x0r25 -o image.png
Location:
libpipi/trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • libpipi/trunk/examples/edd.c

    r2666 r2715  
    6262
    6363    /* Compute the fast error */
    64     tmp = pipi_gaussian_blur_ext(dither, sigma, sigma, 0.16, 0.26);
     64    tmp = pipi_gaussian_blur_ext(dither, sigma, sigma, 0.0, 0.16, 0.26);
    6565    e1 = pipi_measure_msd(gauss, tmp);
    6666    pipi_free(tmp);
     
    7272            for(dx = 0; dx <= Z; dx++)
    7373            {
    74                 tmp = pipi_gaussian_blur_ext(dither, sigma, sigma,
     74                tmp = pipi_gaussian_blur_ext(dither, sigma, sigma, 0.0,
    7575                                             fx + step * dx / Z,
    7676                                             fy + step * dy / Z);
  • libpipi/trunk/pipi/context.c

    r2713 r2715  
    119119        char const *arg;
    120120        va_list ap;
    121         double w, h;
     121        double w, h, a = 0.0;
    122122
    123123        if(ctx->nimages < 1)
     
    129129        arg = strchr(arg, 'x');
    130130        if(arg)
     131        {
    131132            h = atof(arg + 1);
     133            arg = strchr(arg, 'r');
     134            if(arg)
     135                a = atof(arg + 1);
     136        }
    132137        src = ctx->images[ctx->nimages - 1];
    133         dst = pipi_gaussian_blur_ext(src, w, h, 0.0, 0.0);
     138        dst = pipi_gaussian_blur_ext(src, w, h, a, 0.0, 0.0);
    134139        if(dst == NULL)
    135140            return -1;
  • libpipi/trunk/pipi/filter/blur.c

    r2681 r2715  
    3535pipi_image_t *pipi_gaussian_blur(pipi_image_t *src, float radius)
    3636{
    37     return pipi_gaussian_blur_ext(src, radius, radius, 0.0, 0.0);
     37    return pipi_gaussian_blur_ext(src, radius, radius, 0.0, 0.0, 0.0);
    3838}
    3939
    4040pipi_image_t *pipi_gaussian_blur_ext(pipi_image_t *src, float rx, float ry,
    41                                      float dx, float dy)
     41                                     float angle, float dx, float dy)
    4242{
    4343    pipi_image_t *ret;
    4444    double *kernel;
    45     double Kx, Ky, t = 0.0;
     45    double Kx, Ky, t = 0.0, sint, cost, bbx, bby;
    4646    int i, j, krx, kry, m, n;
    4747
     
    4949    if(ry < BLUR_EPSILON) ry = BLUR_EPSILON;
    5050
     51    sint = sin(angle * M_PI / 180.);
     52    cost = cos(angle * M_PI / 180.);
     53
     54    /* Compute the final ellipse's bounding box */
     55    bbx = sqrt(rx * rx * cost * cost + ry * ry * sint * sint);
     56    bby = sqrt(ry * ry * cost * cost + rx * rx * sint * sint);
     57
    5158    /* FIXME: the kernel becomes far too big with large values of dx, because
    5259     * we grow both left and right. Fix the growing direction. */
    53     krx = (int)(3. * rx + .99999 + ceil(abs(dx)));
     60    krx = (int)(3. * bbx + .99999 + ceil(abs(dx)));
    5461    m = 2 * krx + 1;
    5562    Kx = -1. / (2. * rx * rx);
    5663
    57     kry = (int)(3. * ry + .99999 + ceil(abs(dy)));
     64    kry = (int)(3. * bby + .99999 + ceil(abs(dy)));
    5865    n = 2 * kry + 1;
    5966    Ky = -1. / (2. * ry * ry);
     
    6370    for(j = -kry; j <= kry; j++)
    6471    {
    65         double ey = Ky * ((double)j + dy) * ((double)j + dy);
    66 
    6772        for(i = -krx; i <= krx; i++)
    6873        {
    69             double ex = Kx * ((double)i + dx) * ((double)i + dx);
     74            double u = (double)i * cost - (double)j * sint + dx;
     75            double v = (double)j * cost + (double)i * sint + dy;
     76            double ex = Kx * u * u;
     77            double ey = Ky * v * v;
    7078            double d = exp(ex + ey);
    7179
  • libpipi/trunk/pipi/pipi.h

    r2711 r2715  
    100100extern pipi_image_t *pipi_gaussian_blur(pipi_image_t *, float);
    101101extern pipi_image_t *pipi_gaussian_blur_ext(pipi_image_t *,
    102                                             float, float, float, float);
     102                                            float, float, float, float, float);
    103103extern pipi_image_t *pipi_box_blur(pipi_image_t *, int);
    104104extern pipi_image_t *pipi_box_blur_ext(pipi_image_t *, int, int);
Note: See TracChangeset for help on using the changeset viewer.