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;