expose @kernel setting for vips_resize()

a new optional arg lets you pick the downsizing kernel
This commit is contained in:
John Cupitt 2016-05-01 12:33:49 +01:00
parent c2d1de9a26
commit 02821ae9e3
2 changed files with 26 additions and 6 deletions

View File

@ -4,6 +4,7 @@
- fix magickload @page with GraphicsMagick - fix magickload @page with GraphicsMagick
- add giflib5 support - add giflib5 support
- allow resize >1 on one axis, <1 on the other - allow resize >1 on one axis, <1 on the other
- vips_resize has an optional @kernel argument
29/1/16 started 8.3 29/1/16 started 8.3
- add vips_reduce*() ... a fast path for affine downsize - add vips_reduce*() ... a fast path for affine downsize

View File

@ -12,6 +12,7 @@
* - revise again, using new vips_reduce() code * - revise again, using new vips_reduce() code
* 1/5/16 * 1/5/16
* - allow >1 on one axis, <1 on the other * - allow >1 on one axis, <1 on the other
* - expose @kernel setting
*/ */
/* /*
@ -69,6 +70,7 @@ typedef struct _VipsResize {
double scale; double scale;
double vscale; double vscale;
VipsKernel kernel;
/* Deprecated. /* Deprecated.
*/ */
@ -207,7 +209,9 @@ vips_resize_build( VipsObject *object )
if( vresidual < 1.0 ) { if( vresidual < 1.0 ) {
vips_info( class->nickname, "residual reducev by %g", vips_info( class->nickname, "residual reducev by %g",
vresidual ); vresidual );
if( vips_reducev( in, &t[2], 1.0 / vresidual, NULL ) ) if( vips_reducev( in, &t[2], 1.0 / vresidual,
"kernel", resize->kernel,
NULL ) )
return( -1 ); return( -1 );
in = t[2]; in = t[2];
} }
@ -215,7 +219,9 @@ vips_resize_build( VipsObject *object )
if( hresidual < 1.0 ) { if( hresidual < 1.0 ) {
vips_info( class->nickname, "residual reduceh by %g", vips_info( class->nickname, "residual reduceh by %g",
hresidual ); hresidual );
if( vips_reduceh( in, &t[3], 1.0 / hresidual, NULL ) ) if( vips_reduceh( in, &t[3], 1.0 / hresidual,
"kernel", resize->kernel,
NULL ) )
return( -1 ); return( -1 );
in = t[3]; in = t[3];
} }
@ -279,6 +285,13 @@ vips_resize_class_init( VipsResizeClass *class )
G_STRUCT_OFFSET( VipsResize, vscale ), G_STRUCT_OFFSET( VipsResize, vscale ),
0, 10000000, 0 ); 0, 10000000, 0 );
VIPS_ARG_ENUM( class, "kernel", 3,
_( "Kernel" ),
_( "Resampling kernel" ),
VIPS_ARGUMENT_OPTIONAL_INPUT,
G_STRUCT_OFFSET( VipsResize, kernel ),
VIPS_TYPE_KERNEL, VIPS_KERNEL_LANCZOS3 );
/* We used to let people set the input offset so you could pick centre /* We used to let people set the input offset so you could pick centre
* or corner interpolation, but it's not clear this was useful. * or corner interpolation, but it's not clear this was useful.
*/ */
@ -311,6 +324,7 @@ vips_resize_class_init( VipsResizeClass *class )
static void static void
vips_resize_init( VipsResize *resize ) vips_resize_init( VipsResize *resize )
{ {
resize->kernel = VIPS_KERNEL_LANCZOS3;
} }
/** /**
@ -323,21 +337,26 @@ vips_resize_init( VipsResize *resize )
* Optional arguments: * Optional arguments:
* *
* @vscale: vertical scale factor * @vscale: vertical scale factor
* @kernel: #VipsKernel to reduce with
* *
* Resize an image. When upsizing (@scale > 1), the image is simply block * Resize an image. When upsizing (@scale > 1), the image is simply block
* upsized. When downsizing, the * upsized. When downsizing, the
* image is block-shrunk with vips_shrink(), then an anti-alias blur is * image is block-shrunk with vips_shrink(),
* applied with vips_gaussblur(), then the image is shrunk again to the * then the image is shrunk again to the
* target size with vips_reduce(). * target size with vips_reduce(). The operation will leave at least the final
* x2 to be done with vips_reduce().
* *
* vips_resize() normally maintains the image apect ratio. If you set * vips_resize() normally maintains the image apect ratio. If you set
* @vscale, that factor is used for the vertical scale and @scale for the * @vscale, that factor is used for the vertical scale and @scale for the
* horizontal. * horizontal.
* *
* vips_resize() normally uses #VIPS_KERNEL_LANCZOS3 for thre final shrink, you
* can change this with @kernel.
*
* This operation does not change xres or yres. The image resolution needs to * This operation does not change xres or yres. The image resolution needs to
* be updated by the application. * be updated by the application.
* *
* See also: vips_shrink(), vips_reduce(), vips_gaussblur(). * See also: vips_shrink(), vips_reduce().
* *
* Returns: 0 on success, -1 on error * Returns: 0 on success, -1 on error
*/ */