better mask sizing for lanczos

This commit is contained in:
John Cupitt 2016-04-11 13:19:00 +01:00
parent f58190bccd
commit 269cbb8641
5 changed files with 20 additions and 27 deletions

7
TODO
View File

@ -1,10 +1,3 @@
- have some zero elements in lanczos3 masks, can we improve mask sizing?
eg.
$ vips reducev ~/pics/babe.jpg x.png 1.1
has an extra 0 at the end
- compare lanczos2 vs. 3, any differences? - compare lanczos2 vs. 3, any differences?

View File

@ -70,8 +70,8 @@ GType vips_resample_get_type( void );
#define MAX_POINT (50) #define MAX_POINT (50)
int vips_reduce_get_points( VipsKernel kernel, double shrink ); int vips_reduce_get_points( VipsKernel kernel, double shrink );
void vips_reduce_make_mask( VipsKernel kernel, double shrink, void vips_reduce_make_mask( double *c,
double x, double *c ); VipsKernel kernel, double shrink, double x );
#ifdef __cplusplus #ifdef __cplusplus
} }

View File

@ -112,10 +112,10 @@ vips_reduce_get_points( VipsKernel kernel, double shrink )
case VIPS_KERNEL_LANCZOS2: case VIPS_KERNEL_LANCZOS2:
/* Needs to be in sync with calculate_coefficients_lanczos(). /* Needs to be in sync with calculate_coefficients_lanczos().
*/ */
return( ceil( 2 * 2 * shrink ) + 2 ); return( rint( 2 * 2 * shrink ) + 1 );
case VIPS_KERNEL_LANCZOS3: case VIPS_KERNEL_LANCZOS3:
return( ceil( 2 * 3 * shrink ) + 2 ); return( rint( 2 * 3 * shrink ) + 1 );
default: default:
g_assert_not_reached(); g_assert_not_reached();
@ -126,7 +126,7 @@ vips_reduce_get_points( VipsKernel kernel, double shrink )
/* Calculate a mask element. /* Calculate a mask element.
*/ */
void void
vips_reduce_make_mask( VipsKernel kernel, double shrink, double x, double *c ) vips_reduce_make_mask( double *c, VipsKernel kernel, double shrink, double x )
{ {
switch( kernel ) { switch( kernel ) {
case VIPS_KERNEL_NEAREST: case VIPS_KERNEL_NEAREST:
@ -143,11 +143,11 @@ vips_reduce_make_mask( VipsKernel kernel, double shrink, double x, double *c )
break; break;
case VIPS_KERNEL_LANCZOS2: case VIPS_KERNEL_LANCZOS2:
calculate_coefficients_lanczos( 2, shrink, x, c ); calculate_coefficients_lanczos( c, 2, shrink, x );
break; break;
case VIPS_KERNEL_LANCZOS3: case VIPS_KERNEL_LANCZOS3:
calculate_coefficients_lanczos( 3, shrink, x, c ); calculate_coefficients_lanczos( c, 3, shrink, x );
break; break;
default: default:
@ -276,7 +276,7 @@ reduceh_notab( VipsReduceh *reduceh,
double cx[MAX_POINT]; double cx[MAX_POINT];
vips_reduce_make_mask( reduceh->kernel, reduceh->xshrink, x, cx ); vips_reduce_make_mask( cx, reduceh->kernel, reduceh->xshrink, x );
for( int z = 0; z < bands; z++ ) { for( int z = 0; z < bands; z++ ) {
out[z] = reduce_sum<T, double>( in, bands, cx, n ); out[z] = reduce_sum<T, double>( in, bands, cx, n );
@ -452,9 +452,9 @@ vips_reduceh_build( VipsObject *object )
!reduceh->matrixi[x] ) !reduceh->matrixi[x] )
return( -1 ); return( -1 );
vips_reduce_make_mask( reduceh->kernel, reduceh->xshrink, vips_reduce_make_mask( reduceh->matrixf[x],
(float) x / VIPS_TRANSFORM_SCALE, reduceh->kernel, reduceh->xshrink,
reduceh->matrixf[x] ); (float) x / VIPS_TRANSFORM_SCALE );
for( int i = 0; i < reduceh->n_point; i++ ) for( int i = 0; i < reduceh->n_point; i++ )
reduceh->matrixi[x][i] = reduceh->matrixf[x][i] * reduceh->matrixi[x][i] = reduceh->matrixf[x][i] *

View File

@ -490,7 +490,7 @@ reducev_notab( VipsReducev *reducev,
double cy[MAX_POINT]; double cy[MAX_POINT];
vips_reduce_make_mask( reducev->kernel, reducev->yshrink, y, cy ); vips_reduce_make_mask( cy, reducev->kernel, reducev->yshrink, y );
for( int z = 0; z < ne; z++ ) for( int z = 0; z < ne; z++ )
out[z] = reduce_sum<T, double>( in + z, l1, cy, n ); out[z] = reduce_sum<T, double>( in + z, l1, cy, n );
@ -760,14 +760,14 @@ vips_reducev_raw( VipsReducev *reducev, VipsImage *in )
if( !reducev->matrixf[y] ) if( !reducev->matrixf[y] )
return( -1 ); return( -1 );
vips_reduce_make_mask( reducev->kernel, reducev->yshrink, vips_reduce_make_mask( reducev->matrixf[y],
(float) y / VIPS_TRANSFORM_SCALE, reducev->kernel, reducev->yshrink,
reducev->matrixf[y] ); (float) y / VIPS_TRANSFORM_SCALE );
#ifdef DEBUG #ifdef DEBUG
printf( "%4g ", (double) y / VIPS_TRANSFORM_SCALE ); printf( "%6.2g", (double) y / VIPS_TRANSFORM_SCALE );
for( int i = 0; i < reducev->n_point; i++ ) for( int i = 0; i < reducev->n_point; i++ )
printf( " %4g", reducev->matrixf[y][i] ); printf( ", %6.2g", reducev->matrixf[y][i] );
printf( "\n" ); printf( "\n" );
#endif /*DEBUG*/ #endif /*DEBUG*/
} }

View File

@ -320,12 +320,12 @@ calculate_coefficients_catmull( const double x, double c[4] )
* points for large decimations to avoid aliasing. * points for large decimations to avoid aliasing.
*/ */
static void inline static void inline
calculate_coefficients_lanczos( const int a, const double shrink, calculate_coefficients_lanczos( double *c,
const double x, double *c ) const int a, const double shrink, const double x )
{ {
/* Needs to be in sync with vips_reduce_get_points(). /* Needs to be in sync with vips_reduce_get_points().
*/ */
const int n_points = ceil( 2 * a * shrink ) + 2; const int n_points = rint( 2 * a * shrink ) + 1;
int i; int i;
double sum; double sum;