Merge pull request #1647 from libvips/revise-kernel-calculation

revise kernel mask calculations
This commit is contained in:
John Cupitt 2020-05-11 13:55:24 +01:00 committed by GitHub
commit 0c9f311f1e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 10 deletions

View File

@ -101,19 +101,19 @@ vips_reduce_get_points( VipsKernel kernel, double shrink )
return( 1 );
case VIPS_KERNEL_LINEAR:
return( rint( 2 * shrink ) + 1 );
return( 2 * rint( shrink ) + 1 );
case VIPS_KERNEL_CUBIC:
case VIPS_KERNEL_MITCHELL:
return( rint( 4 * shrink ) + 1 );
return( 2 * rint( 2 * shrink ) + 1 );
case VIPS_KERNEL_LANCZOS2:
/* Needs to be in sync with calculate_coefficients_lanczos().
*/
return( rint( 2 * 2 * shrink ) + 1 );
return( 2 * rint( 2 * shrink ) + 1 );
case VIPS_KERNEL_LANCZOS3:
return( rint( 2 * 3 * shrink ) + 1 );
return( 2 * rint( 3 * shrink ) + 1 );
default:
g_assert_not_reached();

View File

@ -321,14 +321,15 @@ calculate_coefficients_triangle( double *c,
{
/* Needs to be in sync with vips_reduce_get_points().
*/
const int n_points = rint( 2 * shrink ) + 1;
const int n_points = 2 * rint( shrink ) + 1;
const double half = x + n_points / 2.0 - 1;
int i;
double sum;
sum = 0;
for( i = 0; i < n_points; i++ ) {
double xp = (i - (shrink - 0.5) - x) / shrink;
const double xp = (i - half) / shrink;
double l;
@ -358,14 +359,15 @@ calculate_coefficients_cubic( double *c,
{
/* Needs to be in sync with vips_reduce_get_points().
*/
const int n_points = rint( 4 * shrink ) + 1;
const int n_points = 2 * rint( 2 * shrink ) + 1;
const double half = x + n_points / 2.0 - 1;
int i;
double sum;
sum = 0;
for( i = 0; i < n_points; i++ ) {
const double xp = (i - (2 * shrink - 1) - x) / shrink;
const double xp = (i - half) / shrink;
const double axp = VIPS_FABS( xp );
const double axp2 = axp * axp;
const double axp3 = axp2 * axp;
@ -406,14 +408,15 @@ calculate_coefficients_lanczos( double *c,
{
/* Needs to be in sync with vips_reduce_get_points().
*/
const int n_points = rint( 2 * a * shrink ) + 1;
const int n_points = 2 * rint( a * shrink ) + 1;
const double half = x + n_points / 2.0 - 1;
int i;
double sum;
sum = 0;
for( i = 0; i < n_points; i++ ) {
double xp = (i - (n_points - 2) / 2 - x) / shrink;
double xp = (i - half) / shrink;
double l;