add sharpening step to vips_resize()
This commit is contained in:
parent
589e15b8a4
commit
77d5bd8d08
4
TODO
4
TODO
@ -2,6 +2,10 @@
|
|||||||
|
|
||||||
- test building without python
|
- test building without python
|
||||||
|
|
||||||
|
- use vips_resize() in vipsthumbnail?
|
||||||
|
|
||||||
|
should the sharpening filter be selectable?
|
||||||
|
|
||||||
- test other cpp arg types
|
- test other cpp arg types
|
||||||
|
|
||||||
input int works
|
input int works
|
||||||
|
@ -2,6 +2,8 @@
|
|||||||
*
|
*
|
||||||
* 13/8/14
|
* 13/8/14
|
||||||
* - from affine.c
|
* - from affine.c
|
||||||
|
* 18/11/14
|
||||||
|
* - add the fancier algorithm from vipsthumbnail
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -75,7 +77,7 @@ vips_resize_build( VipsObject *object )
|
|||||||
VipsResize *resize = (VipsResize *) object;
|
VipsResize *resize = (VipsResize *) object;
|
||||||
|
|
||||||
VipsImage **t = (VipsImage **)
|
VipsImage **t = (VipsImage **)
|
||||||
vips_object_local_array( object, 4 );
|
vips_object_local_array( object, 6 );
|
||||||
|
|
||||||
VipsImage *in;
|
VipsImage *in;
|
||||||
int window_size;
|
int window_size;
|
||||||
@ -128,6 +130,43 @@ vips_resize_build( VipsObject *object )
|
|||||||
return( -1 );
|
return( -1 );
|
||||||
in = t[0];
|
in = t[0];
|
||||||
|
|
||||||
|
/* We want to make sure we read the image sequentially.
|
||||||
|
* However, the convolution we may be doing later will force us
|
||||||
|
* into SMALLTILE or maybe FATSTRIP mode and that will break
|
||||||
|
* sequentiality.
|
||||||
|
*
|
||||||
|
* So ... read into a cache where tiles are scanlines, and make sure
|
||||||
|
* we keep enough scanlines to be able to serve a line of tiles.
|
||||||
|
*
|
||||||
|
* We use a threaded tilecache to avoid a deadlock: suppose thread1,
|
||||||
|
* evaluating the top block of the output, is delayed, and thread2,
|
||||||
|
* evaluating the second block, gets here first (this can happen on
|
||||||
|
* a heavily-loaded system).
|
||||||
|
*
|
||||||
|
* With an unthreaded tilecache (as we had before), thread2 will get
|
||||||
|
* the cache lock and start evaling the second block of the shrink.
|
||||||
|
* When it reaches the png reader it will stall until the first block
|
||||||
|
* has been used ... but it never will, since thread1 will block on
|
||||||
|
* this cache lock.
|
||||||
|
*/
|
||||||
|
if( int_shrink > 1 ) {
|
||||||
|
int tile_width;
|
||||||
|
int tile_height;
|
||||||
|
int nlines;
|
||||||
|
|
||||||
|
vips_get_tile_size( in,
|
||||||
|
&tile_width, &tile_height, &nlines );
|
||||||
|
if( vips_tilecache( in, &t[6],
|
||||||
|
"tile_width", in->Xsize,
|
||||||
|
"tile_height", 10,
|
||||||
|
"max_tiles", 1 + (nlines * 2) / 10,
|
||||||
|
"access", VIPS_ACCESS_SEQUENTIAL,
|
||||||
|
"threaded", TRUE,
|
||||||
|
NULL ) )
|
||||||
|
return( -1 );
|
||||||
|
in = t[6];
|
||||||
|
}
|
||||||
|
|
||||||
/* If the final affine will be doing a large downsample, we can get
|
/* If the final affine will be doing a large downsample, we can get
|
||||||
* nasty aliasing on hard edges. Blur before affine to smooth this out.
|
* nasty aliasing on hard edges. Blur before affine to smooth this out.
|
||||||
*
|
*
|
||||||
@ -154,6 +193,20 @@ vips_resize_build( VipsObject *object )
|
|||||||
return( -1 );
|
return( -1 );
|
||||||
in = t[3];
|
in = t[3];
|
||||||
|
|
||||||
|
/* If we are upsampling, don't sharpen.
|
||||||
|
*/
|
||||||
|
if( int_shrink > 1 ) {
|
||||||
|
t[5] = vips_image_new_matrixv( 3, 3,
|
||||||
|
-1.0, -1.0, -1.0,
|
||||||
|
-1.0, 32.0, -1.0,
|
||||||
|
-1.0, -1.0, -1.0 );
|
||||||
|
vips_image_set_double( t[5], "scale", 24 );
|
||||||
|
|
||||||
|
if( vips_conv( in, &t[4], t[5], NULL ) )
|
||||||
|
return( -1 );
|
||||||
|
in = t[4];
|
||||||
|
}
|
||||||
|
|
||||||
if( vips_image_write( in, resample->out ) )
|
if( vips_image_write( in, resample->out ) )
|
||||||
return( -1 );
|
return( -1 );
|
||||||
|
|
||||||
@ -224,9 +277,16 @@ vips_resize_init( VipsResize *resize )
|
|||||||
* @idx: input horizontal offset
|
* @idx: input horizontal offset
|
||||||
* @idy: input vertical offset
|
* @idy: input vertical offset
|
||||||
*
|
*
|
||||||
* @interpolate defaults to bilinear.
|
* Resize an image. When upsizing (@scale > 1), the image is simply resized
|
||||||
|
* with vips_affine() and the supplied @interpolate. When downsizing, the
|
||||||
|
* image is block-shrunk with vips_shrink() to roughly half the interpolator
|
||||||
|
* window size above the target size, then blurred with an anti-alias filter,
|
||||||
|
* then resampled with vips_affine() and the supplied interpolator, then
|
||||||
|
* sharpened.
|
||||||
*
|
*
|
||||||
* @idx, @idy default to zero.
|
* @interpolate defaults to bucubic, or bilinear if that is not available.
|
||||||
|
*
|
||||||
|
* @idx, @idy default to zero. Adjust them by 0.5 to get pixel-centre sampling.
|
||||||
*
|
*
|
||||||
* See also: vips_shrink(), vips_affine(), #VipsInterpolate.
|
* See also: vips_shrink(), vips_affine(), #VipsInterpolate.
|
||||||
*
|
*
|
||||||
|
Loading…
Reference in New Issue
Block a user