Ignore:
Timestamp:
Oct 16, 2010, 11:52:45 PM (10 years ago)
Author:
Sam Hocevar
Message:

Avoid floating-point divisions in the Bresenham resize.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • libpipi/trunk/pipi/resample/bresenham.c

    r4690 r4691  
    3838    pipi_pixels_t *srcp, *dstp;
    3939    int x, y, x0, y0, sw, dw, sh, dh, remy;
     40    float invswsh;
    4041
    4142    srcp = pipi_get_pixels(src, PIPI_PIXELS_RGBA_F32);
     
    4849    sw = src->w; sh = src->h;
    4950    dw = dst->w; dh = dst->h;
     51    invswsh = 1.0f / (sw * sh);
    5052
    5153    aline = malloc(4 * dw * sizeof(float));
     
    115117        for(x = 0; x < dw; x++)
    116118        {
    117             dstdata[(y * dw + x) * 4] = aline[4 * x] / (sw * sh);
    118             dstdata[(y * dw + x) * 4 + 1] = aline[4 * x + 1] / (sw * sh);
    119             dstdata[(y * dw + x) * 4 + 2] = aline[4 * x + 2] / (sw * sh);
    120             dstdata[(y * dw + x) * 4 + 3] = aline[4 * x + 3] / (sw * sh);
     119            dstdata[(y * dw + x) * 4] = aline[4 * x] * invswsh;
     120            dstdata[(y * dw + x) * 4 + 1] = aline[4 * x + 1] * invswsh;
     121            dstdata[(y * dw + x) * 4 + 2] = aline[4 * x + 2] * invswsh;
     122            dstdata[(y * dw + x) * 4 + 3] = aline[4 * x + 3] * invswsh;
    121123        }
    122124    }
Note: See TracChangeset for help on using the changeset viewer.