From b565f2fc683820d5016abc2a136612994cd828f1 Mon Sep 17 00:00:00 2001 From: John Cupitt Date: Wed, 27 Feb 2019 20:33:31 +0000 Subject: [PATCH] more accurate bilinear use double, not float, for coefficient calculation, or we get overshoots in some cases see https://github.com/libvips/libvips/issues/1239 --- libvips/resample/interpolate.c | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/libvips/resample/interpolate.c b/libvips/resample/interpolate.c index a002070d..ffa4f476 100644 --- a/libvips/resample/interpolate.c +++ b/libvips/resample/interpolate.c @@ -16,6 +16,8 @@ * - gtk-doc * 16/12/15 * - faster bilinear + * 27/2/19 s-sajid-ali + * - more accurate bilinear */ /* @@ -471,20 +473,21 @@ G_DEFINE_TYPE( VipsInterpolateBilinear, vips_interpolate_bilinear, } /* Interpolate a pel ... int32 and float types, no tables, float - * arithmetic. + * arithmetic. Use float, not double, for coefficient calculation, or we can + * get small over/undershoots. */ #define BILINEAR_FLOAT( TYPE ) { \ TYPE * restrict tq = (TYPE *) out; \ \ - float Y = y - iy; \ - float X = x - ix; \ + double Y = y - iy; \ + double X = x - ix; \ \ - float Yd = 1.0f - Y; \ + double Yd = 1.0f - Y; \ \ - float c4 = Y * X; \ - float c2 = Yd * X; \ - float c3 = Y - c4; \ - float c1 = Yd - c2; \ + double c4 = Y * X; \ + double c2 = Yd * X; \ + double c3 = Y - c4; \ + double c1 = Yd - c2; \ \ const TYPE * restrict tp1 = (TYPE *) p1; \ const TYPE * restrict tp2 = (TYPE *) p2; \