From ffb34c943cc28a5f31b9bf68117c66a6d4402758 Mon Sep 17 00:00:00 2001 From: John Cupitt Date: Mon, 26 Mar 2012 09:35:22 +0100 Subject: [PATCH] nearest0neighbor now rounds to nearest before it just truncated x/y downs, now it rounds to nearest ... this removes a 0.5 shift compared to the other interpolators thanks Nicolas --- ChangeLog | 2 ++ libvips/resample/interpolate.c | 9 +++------ 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/ChangeLog b/ChangeLog index 72168e31..31c30359 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,6 +1,8 @@ 19/3/12 started 7.29.0 - better PNG alpha handling - sanity-check PNG read geometry +- nearest-neighbor interpolation rounds coordinates to nearest instead of + rounding down (thanks Nicolas) 13/3/12 started 7.28.2 - xres/yres tiffsave args were broken diff --git a/libvips/resample/interpolate.c b/libvips/resample/interpolate.c index 6c191d08..65ee20d5 100644 --- a/libvips/resample/interpolate.c +++ b/libvips/resample/interpolate.c @@ -331,15 +331,12 @@ static void vips_interpolate_nearest_interpolate( VipsInterpolate *interpolate, void *out, REGION *in, double x, double y ) { - /* Pel size and line size. - */ const int ps = IM_IMAGE_SIZEOF_PEL( in->im ); - /* Top left corner we interpolate from. We know x/y are always - * positive, so we can just (int) them. + /* We know x/y are always positive, so we can just (int) them. */ - const int xi = (int) x; - const int yi = (int) y; + const int xi = (int) (x + 0.5); + const int yi = (int) (y + 0.5); const VipsPel *p = IM_REGION_ADDR( in, xi, yi ); VipsPel *q = (VipsPel *) out;