diff --git a/TODO b/TODO index 68c2d928..70a9f5ac 100644 --- a/TODO +++ b/TODO @@ -2,8 +2,6 @@ test with ~/Desktop/OHHFN.png -- add a test suite test for vips_shrink with non-int args - - we have Vips.leak_set() and Vips.cache_set_trace() ... stupid! make everything Vips.set_thing() diff --git a/libvips/resample/shrink.c b/libvips/resample/shrink.c index 3ac8c8e5..b329daa5 100644 --- a/libvips/resample/shrink.c +++ b/libvips/resample/shrink.c @@ -95,16 +95,17 @@ vips_shrink_build( VipsObject *object ) vips_shrinkh( t[0], &t[1], xshrink_int, NULL ) ) return( -1 ); - xresidual = target_width / t[1]->Xsize; - yresidual = target_height / t[1]->Ysize; + xresidual = (double) target_width / t[1]->Xsize; + yresidual = (double) target_height / t[1]->Ysize; if( vips_affine( t[1], &t[2], - xresidual, 0, 0, yresidual, NULL ) || + xresidual, 0.0, 0.0, yresidual, NULL ) || vips_image_write( t[2], resample->out ) ) return( -1 ); } else { - if( vips_shrinkv( resample->in, &t[0], shrink->yshrink, NULL ) || + if( vips_shrinkv( resample->in, &t[0], + shrink->yshrink, NULL ) || vips_shrinkh( t[0], &t[1], shrink->xshrink, NULL ) || vips_image_write( t[1], resample->out ) ) return( -1 ); diff --git a/test/test_resample.py b/test/test_resample.py index 4006c611..89554351 100755 --- a/test/test_resample.py +++ b/test/test_resample.py @@ -58,6 +58,12 @@ class TestResample(unittest.TestCase): im2 = im.shrink(4, 4) self.assertEqual(im2.width, im.width // 4) self.assertEqual(im2.height, im.height // 4) + self.assertTrue(abs(im.avg() - im2.avg()) < 1) + + im2 = im.shrink(2.5, 2.5) + self.assertEqual(im2.width, im.width // 2.5) + self.assertEqual(im2.height, im.height // 2.5) + self.assertTrue(abs(im.avg() - im2.avg()) < 1) def test_similarity(self): im = Vips.Image.new_from_file("images/IMG_4618.jpg")