From 388f25fc0c2529db64600a2256ab1763b575abbc Mon Sep 17 00:00:00 2001 From: John Cupitt Date: Mon, 14 Jul 2014 14:36:35 +0100 Subject: [PATCH] vips_scale() needs round to nearest or we can get rounding errors in some cases --- ChangeLog | 1 + libvips/conversion/scale.c | 7 ++++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index 5a460c65..6fcca0e8 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,6 +1,7 @@ 4/7/14 started 7.40.4 - fix vips_rawsave_fd(), thanks aferrero2707 - fix im_point() +- vips_scale() now does round to nearest to avoid rounding errors 30/6/14 started 7.40.3 - fix interlaced thumbnails in vipsthumbnail, thanks lovell diff --git a/libvips/conversion/scale.c b/libvips/conversion/scale.c index e08197bb..af9980a9 100644 --- a/libvips/conversion/scale.c +++ b/libvips/conversion/scale.c @@ -20,6 +20,8 @@ * - add log scale and exponent as an option * 14/1/14 * - use linear uchar mode + * 14/7/14 + * - round to nearest on uchar output */ /* @@ -117,7 +119,10 @@ vips_scale_build( VipsObject *object ) } else { double f = 255.0 / (mx - mn); - double a = -(mn * f); + + /* Add .5 to get round-to-nearest. + */ + double a = -(mn * f) + 0.5; if( vips_linear1( scale->in, &t[2], f, a, "uchar", TRUE,