From de82c9e9192d53cec6e6d0b61a5d6998153fa52c Mon Sep 17 00:00:00 2001 From: John Cupitt Date: Mon, 9 Oct 2017 11:48:11 +0100 Subject: [PATCH] allow much larger reduce factors sometimes you want to use lanczos etc. for everything --- libvips/colour/colourspace.c | 2 +- libvips/convolution/convi.c | 4 ++-- libvips/resample/presample.h | 2 +- libvips/resample/reduceh.cpp | 2 +- libvips/resample/reducev.cpp | 4 ++-- libvips/resample/resize.c | 30 +++++++++++++++++------------- 6 files changed, 24 insertions(+), 20 deletions(-) diff --git a/libvips/colour/colourspace.c b/libvips/colour/colourspace.c index 68767cfd..25d15033 100644 --- a/libvips/colour/colourspace.c +++ b/libvips/colour/colourspace.c @@ -601,7 +601,7 @@ vips_colourspace_class_init( VipsColourspaceClass *class ) G_STRUCT_OFFSET( VipsColourspace, space ), VIPS_TYPE_INTERPRETATION, VIPS_INTERPRETATION_sRGB ); - VIPS_ARG_ENUM( class, "source-space", 6, + VIPS_ARG_ENUM( class, "source_space", 6, _( "Source space" ), _( "Source color space" ), VIPS_ARGUMENT_OPTIONAL_INPUT, diff --git a/libvips/convolution/convi.c b/libvips/convolution/convi.c index aa7b7519..893c894b 100644 --- a/libvips/convolution/convi.c +++ b/libvips/convolution/convi.c @@ -938,7 +938,7 @@ vips_convi_build( VipsObject *object ) !intize_to_fixed_point( M, convi->fixed ) && !vips_convi_compile( convi, in ) ) { generate = vips_convi_gen_vector; - g_info( "using vector path" ); + g_info( "convi: using vector path" ); } else vips_convi_compile_free( convi ); @@ -947,7 +947,7 @@ vips_convi_build( VipsObject *object ) /* Make the data for the C path. */ if( generate == vips_convi_gen ) { - g_info( "using C path" ); + g_info( "convi: using C path" ); /* Make an int version of our mask. */ diff --git a/libvips/resample/presample.h b/libvips/resample/presample.h index be563059..0dc98734 100644 --- a/libvips/resample/presample.h +++ b/libvips/resample/presample.h @@ -67,7 +67,7 @@ GType vips_resample_get_type( void ); /* The max size of the vector we use. */ -#define MAX_POINT (50) +#define MAX_POINT (2000) int vips_reduce_get_points( VipsKernel kernel, double shrink ); void vips_reduce_make_mask( double *c, diff --git a/libvips/resample/reduceh.cpp b/libvips/resample/reduceh.cpp index dc41cdfb..a13ad0d6 100644 --- a/libvips/resample/reduceh.cpp +++ b/libvips/resample/reduceh.cpp @@ -454,7 +454,7 @@ vips_reduceh_build( VipsObject *object ) */ reduceh->n_point = vips_reduce_get_points( reduceh->kernel, reduceh->hshrink ); - g_info( "%d point mask", reduceh->n_point ); + g_info( "reduceh: %d point mask", reduceh->n_point ); if( reduceh->n_point > MAX_POINT ) { vips_error( object_class->nickname, "%s", _( "reduce factor too large" ) ); diff --git a/libvips/resample/reducev.cpp b/libvips/resample/reducev.cpp index b74a0d98..d0cf278e 100644 --- a/libvips/resample/reducev.cpp +++ b/libvips/resample/reducev.cpp @@ -781,7 +781,7 @@ vips_reducev_raw( VipsReducev *reducev, VipsImage *in, VipsImage **out ) if( in->BandFmt == VIPS_FORMAT_UCHAR && vips_vector_isenabled() && !vips_reducev_compile( reducev ) ) { - g_info( "using vector path" ); + g_info( "reducev: using vector path" ); generate = vips_reducev_vector_gen; } @@ -848,12 +848,12 @@ vips_reducev_build( VipsObject *object ) reducev->n_point = vips_reduce_get_points( reducev->kernel, reducev->vshrink ); + g_info( "reducev: %d point mask", reducev->n_point ); if( reducev->n_point > MAX_POINT ) { vips_error( object_class->nickname, "%s", _( "reduce factor too large" ) ); return( -1 ); } - g_info( "%d point mask", reducev->n_point ); /* Unpack for processing. */ diff --git a/libvips/resample/resize.c b/libvips/resample/resize.c index b991594d..583cfae7 100644 --- a/libvips/resample/resize.c +++ b/libvips/resample/resize.c @@ -115,22 +115,26 @@ G_DEFINE_TYPE( VipsResize, vips_resize, VIPS_TYPE_RESAMPLE ); static int vips_resize_int_shrink( VipsResize *resize, double scale ) { + int shrink; + if( scale > 1.0 ) - return( 1 ); + shrink = 1; + else + switch( resize->kernel ) { + case VIPS_KERNEL_NEAREST: + shrink = 1; - switch( resize->kernel ) { - case VIPS_KERNEL_NEAREST: - return( 1 ); + case VIPS_KERNEL_LINEAR: + case VIPS_KERNEL_CUBIC: + default: + shrink = VIPS_FLOOR( 1.0 / scale ); - case VIPS_KERNEL_LINEAR: - case VIPS_KERNEL_CUBIC: - default: - return( VIPS_FLOOR( 1.0 / scale ) ); + case VIPS_KERNEL_LANCZOS2: + case VIPS_KERNEL_LANCZOS3: + shrink = VIPS_MAX( 1, VIPS_FLOOR( 1.0 / (scale * 2) ) ); + } - case VIPS_KERNEL_LANCZOS2: - case VIPS_KERNEL_LANCZOS3: - return( VIPS_MAX( 1, VIPS_FLOOR( 1.0 / (scale * 2) ) ) ); - } + return( shrink ); } /* Suggest a VipsInterpolate which corresponds to a VipsKernel. We use @@ -392,7 +396,7 @@ vips_resize_init( VipsResize *resize ) * a #VipsInterpolate selected depending on @kernel. It will use * #VipsInterpolateBicubic for #VIPS_KERNEL_CUBIC and above. * - * vips_resize() normally maintains the image apect ratio. If you set + * vips_resize() normally maintains the image aspect ratio. If you set * @vscale, that factor is used for the vertical scale and @scale for the * horizontal. *