From d9ee892077b5b0efc1da7d26be399cec622fab93 Mon Sep 17 00:00:00 2001 From: John Cupitt Date: Mon, 29 Sep 2014 21:40:08 +0100 Subject: [PATCH] conversion tests done --- libvips/conversion/conversion.c | 16 ++--- python/test_all.py | 10 ++++ python/test_conversion.py | 103 +++++++++++++++++++++++++++++++- 3 files changed, 118 insertions(+), 11 deletions(-) create mode 100755 python/test_all.py diff --git a/libvips/conversion/conversion.c b/libvips/conversion/conversion.c index 99777271..b1c071d1 100644 --- a/libvips/conversion/conversion.c +++ b/libvips/conversion/conversion.c @@ -86,9 +86,9 @@ /** * VipsAngle: * @VIPS_ANGLE_D0: no rotate - * @VIPS_ANGLE_D90: 90 degrees anti-clockwise + * @VIPS_ANGLE_D90: 90 degrees clockwise * @VIPS_ANGLE_D180: 180 degree rotate - * @VIPS_ANGLE_D270: 90 degrees clockwise + * @VIPS_ANGLE_D270: 90 degrees anti-clockwise * * See vips_rot() and so on. * @@ -100,13 +100,13 @@ /** * VipsAngle45: * @VIPS_ANGLE45_D0: no rotate - * @VIPS_ANGLE45_D45: 45 degrees anti-clockwise - * @VIPS_ANGLE45_D90: 90 degrees anti-clockwise - * @VIPS_ANGLE45_D135: 135 degrees anti-clockwise + * @VIPS_ANGLE45_D45: 45 degrees clockwise + * @VIPS_ANGLE45_D90: 90 degrees clockwise + * @VIPS_ANGLE45_D135: 135 degrees clockwise * @VIPS_ANGLE45_D180: 180 degrees - * @VIPS_ANGLE45_D225: 135 degrees clockwise - * @VIPS_ANGLE45_D270: 90 degrees clockwise - * @VIPS_ANGLE45_D315: 45 degrees clockwise + * @VIPS_ANGLE45_D225: 135 degrees anti-clockwise + * @VIPS_ANGLE45_D270: 90 degrees anti-clockwise + * @VIPS_ANGLE45_D315: 45 degrees anti-clockwise * * See vips_rot45() and so on. * diff --git a/python/test_all.py b/python/test_all.py new file mode 100755 index 00000000..ffc0b69c --- /dev/null +++ b/python/test_all.py @@ -0,0 +1,10 @@ +#!/usr/bin/python + +import unittest + +from test_arithmetic import TestArithmetic +from test_colour import TestColour +from test_conversion import TestConversion + +if __name__ == '__main__': + unittest.main() diff --git a/python/test_conversion.py b/python/test_conversion.py index d60cdaa8..9cfaf32c 100755 --- a/python/test_conversion.py +++ b/python/test_conversion.py @@ -54,6 +54,25 @@ rot45_angles = [Vips.Angle45.D0, Vips.Angle45.D270, Vips.Angle45.D315] +rot45_angle_bonds = [Vips.Angle45.D0, + Vips.Angle45.D315, + Vips.Angle45.D270, + Vips.Angle45.D225, + Vips.Angle45.D180, + Vips.Angle45.D135, + Vips.Angle45.D90, + Vips.Angle45.D45] + +rot_angles = [Vips.Angle.D0, + Vips.Angle.D90, + Vips.Angle.D180, + Vips.Angle.D270] + +rot_angle_bonds = [Vips.Angle.D0, + Vips.Angle.D270, + Vips.Angle.D180, + Vips.Angle.D90] + # an expanding zip ... if either of the args is not a list, duplicate it down # the other def zip_expand(x, y): @@ -487,14 +506,14 @@ class TestConversion(unittest.TestCase): for y in all_formats: main = self.mono.cast(x) sub = self.colour.cast(y) - r = main.insert(sub, 10, 10, expand = True, background = 128) + r = main.insert(sub, 10, 10, expand = True, background = 100) self.assertEqual(r.width, main.width + 10) self.assertEqual(r.height, main.height + 10) self.assertEqual(r.bands, sub.bands) a = r.getpoint(r.width - 5, 5) - self.assertAlmostEqualObjects(a, [128, 128, 128]) + self.assertAlmostEqualObjects(a, [100, 100, 100]) def test_msb(self): for fmt in unsigned_formats: @@ -577,11 +596,89 @@ class TestConversion(unittest.TestCase): self.assertAlmostEqualObjects(before, after) def test_rot45(self): + # test has a quarter-circle in the bottom right test = self.colour.crop(0, 0, 51, 51) for fmt in all_formats: im = test.cast(fmt) - im.write_to_file("x.v") + im2 = im.rot45() + before = im.getpoint(50, 50) + after = im2.getpoint(25, 50) + self.assertAlmostEqualObjects(before, after) + + for a, b in zip(rot45_angles, rot45_angle_bonds): + im2 = im.rot45(angle = a) + after = im2.rot45(angle = b) + diff = (after - im).abs().max() + self.assertEqual(diff, 0) + + def test_rot(self): + # test has a quarter-circle in the bottom right + test = self.colour.crop(0, 0, 51, 51) + for fmt in all_formats: + im = test.cast(fmt) + + im2 = im.rot(Vips.Angle.D90) + before = im.getpoint(50, 50) + after = im2.getpoint(0, 50) + self.assertAlmostEqualObjects(before, after) + + for a, b in zip(rot_angles, rot_angle_bonds): + im2 = im.rot(a) + after = im2.rot(b) + diff = (after - im).abs().max() + self.assertEqual(diff, 0) + + def test_scale(self): + for fmt in noncomplex_formats: + test = self.colour.cast(fmt) + + im = test.scale() + self.assertEqual(im.max(), 255) + self.assertEqual(im.min(), 0) + + im = test.scale(log = True) + self.assertEqual(im.max(), 255) + + def test_subsample(self): + for fmt in all_formats: + test = self.colour.cast(fmt) + + im = test.subsample(3, 3) + self.assertEqual(im.width, test.width / 3) + self.assertEqual(im.height, test.height / 3) + + before = test.getpoint(60, 60) + after = im.getpoint(20, 20) + self.assertAlmostEqualObjects(before, after) + + def test_zoom(self): + for fmt in all_formats: + test = self.colour.cast(fmt) + + im = test.zoom(3, 3) + self.assertEqual(im.width, test.width * 3) + self.assertEqual(im.height, test.height * 3) + + before = test.getpoint(50, 50) + after = im.getpoint(150, 150) + self.assertAlmostEqualObjects(before, after) + + def test_wrap(self): + for fmt in all_formats: + test = self.colour.cast(fmt) + + im = test.wrap() + self.assertEqual(im.width, test.width) + self.assertEqual(im.height, test.height) + + before = test.getpoint(0, 0) + after = im.getpoint(50, 50) + self.assertAlmostEqualObjects(before, after) + + before = test.getpoint(50, 50) + after = im.getpoint(0, 0) + self.assertAlmostEqualObjects(before, after) if __name__ == '__main__': unittest.main()