Ver código fonte

Avoid floating-point divisions in the Bresenham resize.

git-svn-id: file:///srv/caca.zoy.org/var/lib/svn/libpipi/trunk@4691 92316355-f0b4-4df1-b90c-862c8a59935f
master
sam 14 anos atrás
pai
commit
231d51f8e3
1 arquivos alterados com 6 adições e 4 exclusões
  1. +6
    -4
      pipi/resample/bresenham.c

+ 6
- 4
pipi/resample/bresenham.c Ver arquivo

@@ -37,6 +37,7 @@ pipi_image_t *pipi_resize(pipi_image_t *src, int w, int h)
pipi_image_t *dst;
pipi_pixels_t *srcp, *dstp;
int x, y, x0, y0, sw, dw, sh, dh, remy;
float invswsh;

srcp = pipi_get_pixels(src, PIPI_PIXELS_RGBA_F32);
srcdata = (float *)srcp->pixels;
@@ -47,6 +48,7 @@ pipi_image_t *pipi_resize(pipi_image_t *src, int w, int h)

sw = src->w; sh = src->h;
dw = dst->w; dh = dst->h;
invswsh = 1.0f / (sw * sh);

aline = malloc(4 * dw * sizeof(float));
line = malloc(4 * dw * sizeof(float));
@@ -114,10 +116,10 @@ pipi_image_t *pipi_resize(pipi_image_t *src, int w, int h)

for(x = 0; x < dw; x++)
{
dstdata[(y * dw + x) * 4] = aline[4 * x] / (sw * sh);
dstdata[(y * dw + x) * 4 + 1] = aline[4 * x + 1] / (sw * sh);
dstdata[(y * dw + x) * 4 + 2] = aline[4 * x + 2] / (sw * sh);
dstdata[(y * dw + x) * 4 + 3] = aline[4 * x + 3] / (sw * sh);
dstdata[(y * dw + x) * 4] = aline[4 * x] * invswsh;
dstdata[(y * dw + x) * 4 + 1] = aline[4 * x + 1] * invswsh;
dstdata[(y * dw + x) * 4 + 2] = aline[4 * x + 2] * invswsh;
dstdata[(y * dw + x) * 4 + 3] = aline[4 * x + 3] * invswsh;
}
}



Carregando…
Cancelar
Salvar