From ea6d496484ec212e93353988917706dbd7bed435 Mon Sep 17 00:00:00 2001 From: Lovell Fuller Date: Tue, 3 Oct 2017 19:44:31 +0100 Subject: [PATCH] Upsample integral nearest neighour with zoom for accuracy. This mirrors logic from sharp, allowing it to migrate to resize. See https://github.com/lovell/sharp/issues/752 --- libvips/resample/resize.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/libvips/resample/resize.c b/libvips/resample/resize.c index 1a4fafb9..b991594d 100644 --- a/libvips/resample/resize.c +++ b/libvips/resample/resize.c @@ -238,7 +238,17 @@ vips_resize_build( VipsObject *object ) return( -1 ); vips_object_local( object, interpolate ); - if( hscale > 1.0 && + if( resize->kernel == VIPS_KERNEL_NEAREST && + hscale == VIPS_FLOOR( hscale ) && + vscale == VIPS_FLOOR( vscale ) ) { + /* Fast, integral nearest neighbour enlargement + */ + if( vips_zoom( in, &t[4], VIPS_FLOOR( hscale ), + VIPS_FLOOR( vscale ), NULL ) ) + return( -1 ); + in = t[4]; + } + else if( hscale > 1.0 && vscale > 1.0 ) { g_info( "residual scale %g x %g", hscale, vscale ); if( vips_affine( in, &t[4],