From e8c4188936a840a181d0b5fd95bf1de7be2c3b2c Mon Sep 17 00:00:00 2001 From: John Cupitt Date: Tue, 10 Dec 2013 14:56:14 +0000 Subject: [PATCH] be more forgiving about x values buildlut() would fail if rounding moved some of your x values away from ints --- libvips/create/buildlut.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/libvips/create/buildlut.c b/libvips/create/buildlut.c index a8a4d56b..da2b1000 100644 --- a/libvips/create/buildlut.c +++ b/libvips/create/buildlut.c @@ -14,6 +14,8 @@ * - gtkdoc * 2/7/13 * - convert to a class + * 10/12/13 + * - be more forgiving about x vales not quite integers */ /* @@ -125,12 +127,16 @@ vips_buildlut_build_init( VipsBuildlut *lut ) for( y = 0; y < lut->mat->Ysize; y++ ) { double v = *VIPS_MATRIX( lut->mat, 0, y ); - if( floor( v ) != v ) { + /* Allow for being a bit off. + */ + if( abs( v - VIPS_RINT( v ) ) > 0.001 ) { vips_error( class->nickname, - "%s", _( "x value not an int" ) ); + _( "x value row %d not an int" ), y ); return( -1 ); } + v = VIPS_RINT( v ); + if( v < xlow ) xlow = v; if( v > xhigh ) @@ -189,8 +195,8 @@ vips_buildlut_build_create( VipsBuildlut *lut ) */ for( b = 0; b < bands; b++ ) { for( i = 0; i < ysize - 1; i++ ) { - const int x1 = lut->data[i][0]; - const int x2 = lut->data[i + 1][0]; + const int x1 = VIPS_RINT( lut->data[i][0] ); + const int x2 = VIPS_RINT( lut->data[i + 1][0] ); const int dx = x2 - x1; const double y1 = lut->data[i][b + 1]; const double y2 = lut->data[i + 1][b + 1];