diff --git a/libvips/include/vips/util.h b/libvips/include/vips/util.h index a6cc888e..5a8ecc77 100644 --- a/libvips/include/vips/util.h +++ b/libvips/include/vips/util.h @@ -97,7 +97,7 @@ extern "C" { /* Round N down and up to the nearest multiple of P. */ #define VIPS_ROUND_DOWN( N, P ) ((N) - ((N) % (P))) -#define VIPS_ROUND_UP( N, P ) (VIPS_ROUND_DOWN( N, P ) + (P)) +#define VIPS_ROUND_UP( N, P ) (VIPS_ROUND_DOWN( (N) + (P) - 1, (P) )) #define VIPS_SWAP( TYPE, A, B ) \ G_STMT_START { \ diff --git a/test/test_resample.py b/test/test_resample.py index ce9fb5ed..02941666 100755 --- a/test/test_resample.py +++ b/test/test_resample.py @@ -170,6 +170,12 @@ class TestResample(unittest.TestCase): self.assertEqual(im2.width, round(im.width / 4.0)) self.assertEqual(im2.height, round(im.height / 4.0)) + # test geometry rounding corner case + im = Vips.Image.black(100, 1); + x = im.resize(0.5) + self.assertEqual(x.width, 50) + self.assertEqual(x.height, 1) + def test_shrink(self): im = Vips.Image.new_from_file("images/IMG_4618.jpg") im2 = im.shrink(4, 4)