Skip to content

Commit 0c9f311

Browse files
authored
Merge pull request #1647 from libvips/revise-kernel-calculation
revise kernel mask calculations
2 parents e1835d5 + d64385a commit 0c9f311

File tree

2 files changed

+13
-10
lines changed

2 files changed

+13
-10
lines changed

libvips/resample/reduceh.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -101,19 +101,19 @@ vips_reduce_get_points( VipsKernel kernel, double shrink )
101101
return( 1 );
102102

103103
case VIPS_KERNEL_LINEAR:
104-
return( rint( 2 * shrink ) + 1 );
104+
return( 2 * rint( shrink ) + 1 );
105105

106106
case VIPS_KERNEL_CUBIC:
107107
case VIPS_KERNEL_MITCHELL:
108-
return( rint( 4 * shrink ) + 1 );
108+
return( 2 * rint( 2 * shrink ) + 1 );
109109

110110
case VIPS_KERNEL_LANCZOS2:
111111
/* Needs to be in sync with calculate_coefficients_lanczos().
112112
*/
113-
return( rint( 2 * 2 * shrink ) + 1 );
113+
return( 2 * rint( 2 * shrink ) + 1 );
114114

115115
case VIPS_KERNEL_LANCZOS3:
116-
return( rint( 2 * 3 * shrink ) + 1 );
116+
return( 2 * rint( 3 * shrink ) + 1 );
117117

118118
default:
119119
g_assert_not_reached();

libvips/resample/templates.h

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -321,14 +321,15 @@ calculate_coefficients_triangle( double *c,
321321
{
322322
/* Needs to be in sync with vips_reduce_get_points().
323323
*/
324-
const int n_points = rint( 2 * shrink ) + 1;
324+
const int n_points = 2 * rint( shrink ) + 1;
325+
const double half = x + n_points / 2.0 - 1;
325326

326327
int i;
327328
double sum;
328329

329330
sum = 0;
330331
for( i = 0; i < n_points; i++ ) {
331-
double xp = (i - (shrink - 0.5) - x) / shrink;
332+
const double xp = (i - half) / shrink;
332333

333334
double l;
334335

@@ -358,14 +359,15 @@ calculate_coefficients_cubic( double *c,
358359
{
359360
/* Needs to be in sync with vips_reduce_get_points().
360361
*/
361-
const int n_points = rint( 4 * shrink ) + 1;
362+
const int n_points = 2 * rint( 2 * shrink ) + 1;
363+
const double half = x + n_points / 2.0 - 1;
362364

363365
int i;
364366
double sum;
365367

366368
sum = 0;
367369
for( i = 0; i < n_points; i++ ) {
368-
const double xp = (i - (2 * shrink - 1) - x) / shrink;
370+
const double xp = (i - half) / shrink;
369371
const double axp = VIPS_FABS( xp );
370372
const double axp2 = axp * axp;
371373
const double axp3 = axp2 * axp;
@@ -406,14 +408,15 @@ calculate_coefficients_lanczos( double *c,
406408
{
407409
/* Needs to be in sync with vips_reduce_get_points().
408410
*/
409-
const int n_points = rint( 2 * a * shrink ) + 1;
411+
const int n_points = 2 * rint( a * shrink ) + 1;
412+
const double half = x + n_points / 2.0 - 1;
410413

411414
int i;
412415
double sum;
413416

414417
sum = 0;
415418
for( i = 0; i < n_points; i++ ) {
416-
double xp = (i - (n_points - 2) / 2 - x) / shrink;
419+
double xp = (i - half) / shrink;
417420

418421
double l;
419422

0 commit comments

Comments
 (0)