From ac4e5ce05908d3354e25d866d626de16a289f576 Mon Sep 17 00:00:00 2001 From: John Cupitt Date: Mon, 14 Mar 2016 14:58:02 +0000 Subject: [PATCH] return of shrink-less-affine-more though a bit less extreme --- libvips/resample/resize.c | 21 ++++++++++++++++----- tools/vipsthumbnail.c | 16 +++++++++++++--- 2 files changed, 29 insertions(+), 8 deletions(-) diff --git a/libvips/resample/resize.c b/libvips/resample/resize.c index fc9651d5..c2e39c0f 100644 --- a/libvips/resample/resize.c +++ b/libvips/resample/resize.c @@ -115,11 +115,22 @@ vips_resize_build( VipsObject *object ) /* If the factor is > 1.0, we need to zoom rather than shrink. * Just set the int part to 1 in this case. */ - int_hshrink = resize->scale > 1.0 ? - 1 : VIPS_FLOOR( 1.0 / resize->scale ); - if( vips_object_argument_isset( object, "vscale" ) ) - int_vshrink = resize->vscale > 1.0 ? - 1 : VIPS_FLOOR( 1.0 / resize->vscale ); + + /* We want the int part of the shrink to leave a bit to do with + * blur/reduce/sharpen, or we'll see strange changes in aliasing on int + * shrink boundaries as we resize. + */ + + if( resize->scale > 1.0 ) + int_hshrink = 1; + else + int_hshrink = VIPS_FLOOR( 1.0 / (resize->scale * 1.1) ); + if( vips_object_argument_isset( object, "vscale" ) ) { + if( resize->vscale > 1.0 ) + int_vshrink = 1; + else + int_vshrink = VIPS_FLOOR( 1.0 / (resize->vscale * 1.1) ); + } else int_vshrink = int_hshrink; diff --git a/tools/vipsthumbnail.c b/tools/vipsthumbnail.c index a507d568..0461a678 100644 --- a/tools/vipsthumbnail.c +++ b/tools/vipsthumbnail.c @@ -223,11 +223,21 @@ thumbnail_find_jpegshrink( VipsImage *im ) if( linear_processing ) return( 1 ); - if( shrink >= 8 ) + /* Shrink-on-load is a simple block shrink and will add quite a bit of + * extra sharpness to the image. We want to block shrink to a size a + * bit above our target, then anti-alias/downsample/sharpen to the + * target. + * + * For example, consider making a 400-pixel-across image from an + * 800-pixel image. If we load at 1/2 size, we could find ourselves + * doing no further processing, which would make a 400-px version look + * very different from a 450-px version. + */ + if( shrink >= 8.5 ) return( 8 ); - else if( shrink >= 4 ) + else if( shrink >= 4.5 ) return( 4 ); - else if( shrink >= 2 ) + else if( shrink >= 2.5 ) return( 2 ); else return( 1 );