Skip to content

revise kernel mask calculations #1647

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 11, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions libvips/resample/reduceh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
15 changes: 9 additions & 6 deletions libvips/resample/templates.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;

Expand Down