better mask sizing for lanczos
This commit is contained in:
parent
f58190bccd
commit
269cbb8641
7
TODO
7
TODO
@ -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?
|
||||
|
||||
|
@ -70,8 +70,8 @@ GType vips_resample_get_type( void );
|
||||
#define MAX_POINT (50)
|
||||
|
||||
int vips_reduce_get_points( VipsKernel kernel, double shrink );
|
||||
void vips_reduce_make_mask( VipsKernel kernel, double shrink,
|
||||
double x, double *c );
|
||||
void vips_reduce_make_mask( double *c,
|
||||
VipsKernel kernel, double shrink, double x );
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
@ -112,10 +112,10 @@ vips_reduce_get_points( VipsKernel kernel, double shrink )
|
||||
case VIPS_KERNEL_LANCZOS2:
|
||||
/* 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:
|
||||
return( ceil( 2 * 3 * shrink ) + 2 );
|
||||
return( rint( 2 * 3 * shrink ) + 1 );
|
||||
|
||||
default:
|
||||
g_assert_not_reached();
|
||||
@ -126,7 +126,7 @@ vips_reduce_get_points( VipsKernel kernel, double shrink )
|
||||
/* Calculate a mask element.
|
||||
*/
|
||||
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 ) {
|
||||
case VIPS_KERNEL_NEAREST:
|
||||
@ -143,11 +143,11 @@ vips_reduce_make_mask( VipsKernel kernel, double shrink, double x, double *c )
|
||||
break;
|
||||
|
||||
case VIPS_KERNEL_LANCZOS2:
|
||||
calculate_coefficients_lanczos( 2, shrink, x, c );
|
||||
calculate_coefficients_lanczos( c, 2, shrink, x );
|
||||
break;
|
||||
|
||||
case VIPS_KERNEL_LANCZOS3:
|
||||
calculate_coefficients_lanczos( 3, shrink, x, c );
|
||||
calculate_coefficients_lanczos( c, 3, shrink, x );
|
||||
break;
|
||||
|
||||
default:
|
||||
@ -276,7 +276,7 @@ reduceh_notab( VipsReduceh *reduceh,
|
||||
|
||||
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++ ) {
|
||||
out[z] = reduce_sum<T, double>( in, bands, cx, n );
|
||||
@ -452,9 +452,9 @@ vips_reduceh_build( VipsObject *object )
|
||||
!reduceh->matrixi[x] )
|
||||
return( -1 );
|
||||
|
||||
vips_reduce_make_mask( reduceh->kernel, reduceh->xshrink,
|
||||
(float) x / VIPS_TRANSFORM_SCALE,
|
||||
reduceh->matrixf[x] );
|
||||
vips_reduce_make_mask( reduceh->matrixf[x],
|
||||
reduceh->kernel, reduceh->xshrink,
|
||||
(float) x / VIPS_TRANSFORM_SCALE );
|
||||
|
||||
for( int i = 0; i < reduceh->n_point; i++ )
|
||||
reduceh->matrixi[x][i] = reduceh->matrixf[x][i] *
|
||||
|
@ -490,7 +490,7 @@ reducev_notab( VipsReducev *reducev,
|
||||
|
||||
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++ )
|
||||
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] )
|
||||
return( -1 );
|
||||
|
||||
vips_reduce_make_mask( reducev->kernel, reducev->yshrink,
|
||||
(float) y / VIPS_TRANSFORM_SCALE,
|
||||
reducev->matrixf[y] );
|
||||
vips_reduce_make_mask( reducev->matrixf[y],
|
||||
reducev->kernel, reducev->yshrink,
|
||||
(float) y / VIPS_TRANSFORM_SCALE );
|
||||
|
||||
#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++ )
|
||||
printf( " %4g", reducev->matrixf[y][i] );
|
||||
printf( ", %6.2g", reducev->matrixf[y][i] );
|
||||
printf( "\n" );
|
||||
#endif /*DEBUG*/
|
||||
}
|
||||
|
@ -320,12 +320,12 @@ calculate_coefficients_catmull( const double x, double c[4] )
|
||||
* points for large decimations to avoid aliasing.
|
||||
*/
|
||||
static void inline
|
||||
calculate_coefficients_lanczos( const int a, const double shrink,
|
||||
const double x, double *c )
|
||||
calculate_coefficients_lanczos( double *c,
|
||||
const int a, const double shrink, const double x )
|
||||
{
|
||||
/* 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;
|
||||
double sum;
|
||||
|
Loading…
Reference in New Issue
Block a user