fix ROUND_UP, add a test for felix's corner case

This commit is contained in:
John Cupitt 2016-08-20 13:18:25 +01:00
parent 271d8656e9
commit c4a1ac6310
2 changed files with 7 additions and 1 deletions

View File

@ -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 { \

View File

@ -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)