From 76e823c5cd0ff172cb3649655b468b920a861f06 Mon Sep 17 00:00:00 2001 From: Cyril Hrubis Date: Sun, 17 Jun 2012 19:54:12 +0200 Subject: [PATCH] filters: resize NN, fix off-by-one in coordinates mapping. --- libs/filters/GP_ResizeNN.gen.c.t | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/libs/filters/GP_ResizeNN.gen.c.t b/libs/filters/GP_ResizeNN.gen.c.t index 7719efb9..7c7bd512 100644 --- a/libs/filters/GP_ResizeNN.gen.c.t +++ b/libs/filters/GP_ResizeNN.gen.c.t @@ -27,15 +27,14 @@ static int GP_FilterResizeNN_{{ pt.name }}_Raw(const GP_Context *src, 1.00 * dst->w / src->w, 1.00 * dst->h / src->h); /* Pre-compute mapping for interpolation */ - uint32_t xstep = (src->w << 16) / dst->w; - - for (i = 0; i < dst->w + 1; i++) - xmap[i] = ((i * xstep) + (1<<15)) >> 16; - - uint32_t ystep = (src->h << 16) / dst->h; + for (i = 0; i < dst->w; i++) { + xmap[i] = ((((i * (src->w - 1))<<8) + (dst->w - 1)/2) / (dst->w - 1) + (1<<7))>>8; + printf("%i-%i ", i, xmap[i]); + } + printf("\n%i -> %i\n", src->w, dst->w); - for (i = 0; i < dst->h + 1; i++) - ymap[i] = ((i * ystep) + (1<<15)) >> 16; + for (i = 0; i < dst->h; i++) + ymap[i] = ((((i * (src->h - 1))<<8) + (dst->h - 1)/2) / (dst->h - 1) + (1<<7))>>8; /* Interpolate */ for (y = 0; y < (GP_Coord)dst->h; y++) { -- 2.11.4.GIT