From 0767e4f4c9885e3a6f06081784be4600f68dfda2 Mon Sep 17 00:00:00 2001 From: John Cupitt Date: Mon, 16 Oct 2017 09:38:04 +0100 Subject: [PATCH] remove a 0.5 pixel shift from triangle lines up with cubic and lanczos now --- libvips/resample/templates.h | 62 ++++++++++++++++++------------------ 1 file changed, 31 insertions(+), 31 deletions(-) diff --git a/libvips/resample/templates.h b/libvips/resample/templates.h index ac06dc85..398c3a2c 100644 --- a/libvips/resample/templates.h +++ b/libvips/resample/templates.h @@ -311,6 +311,37 @@ calculate_coefficients_catmull( double c[4], const double x ) c[2] = cthr; } +/* Given an x in [0,1] (we can have x == 1 when building tables), + * calculate c0 .. c(@shrink + 1), the triangle coefficients. This is called + * from the interpolator as well as from the table builder. + */ +static void inline +calculate_coefficients_triangle( double *c, const double shrink, const double x ) +{ + /* Needs to be in sync with vips_reduce_get_points(). + */ + const int n_points = rint( 2 * shrink ) + 1; + + int i; + double sum; + + sum = 0; + for( i = 0; i < n_points; i++ ) { + double xp = (i - (shrink - 0.5) - x) / shrink; + + double l; + + l = 1.0 - VIPS_FABS( xp ); + l = VIPS_MAX( 0.0, l ); + + c[i] = l; + sum += l; + } + + for( i = 0; i < n_points; i++ ) + c[i] /= sum; +} + /* Calculate a catmull kernel for shrinking. */ static void inline @@ -397,37 +428,6 @@ calculate_coefficients_lanczos( double *c, c[i] /= sum; } -/* Given an x in [0,1] (we can have x == 1 when building tables), - * calculate c0 .. c(@shrink + 1), the triangle coefficients. This is called - * from the interpolator as well as from the table builder. - */ -static void inline -calculate_coefficients_triangle( double *c, const double shrink, const double x ) -{ - /* Needs to be in sync with vips_reduce_get_points(). - */ - const int n_points = rint( 2 * shrink ) + 1; - - int i; - double sum; - - sum = 0; - for( i = 0; i < n_points; i++ ) { - double xp = (i - (shrink - 1) - x) / shrink; - - double l; - - l = 1.0 - VIPS_FABS( xp ); - l = VIPS_MAX( 0.0, l ); - - c[i] = l; - sum += l; - } - - for( i = 0; i < n_points; i++ ) - c[i] /= sum; -} - /* Our inner loop for resampling with a convolution. Operate on elements of * type T, gather results in an intermediate of type IT. */