From 4cf2f158b674d14693ef1728888e660174384aba Mon Sep 17 00:00:00 2001 From: homm Date: Fri, 7 Nov 2014 11:48:47 +0300 Subject: [PATCH] add test update comment --- Tests/test_image_transpose.py | 116 ++++++++++++++++++++++++++++------ libImaging/Geometry.c | 10 +-- 2 files changed, 103 insertions(+), 23 deletions(-) diff --git a/Tests/test_image_transpose.py b/Tests/test_image_transpose.py index 3e4257bc0..eb61c0c04 100644 --- a/Tests/test_image_transpose.py +++ b/Tests/test_image_transpose.py @@ -1,29 +1,108 @@ from helper import unittest, PillowTestCase, hopper -from PIL import Image - -FLIP_LEFT_RIGHT = Image.FLIP_LEFT_RIGHT -FLIP_TOP_BOTTOM = Image.FLIP_TOP_BOTTOM -ROTATE_90 = Image.ROTATE_90 -ROTATE_180 = Image.ROTATE_180 -ROTATE_270 = Image.ROTATE_270 +from PIL.Image import (FLIP_LEFT_RIGHT, FLIP_TOP_BOTTOM, ROTATE_90, ROTATE_180, + ROTATE_270, TRANSPOSE) class TestImageTranspose(PillowTestCase): - def test_sanity(self): + def test_flip_left_right(self): + def transpose(mode): + im = hopper(mode) + out = im.transpose(FLIP_LEFT_RIGHT) + self.assertEqual(out.mode, mode) + self.assertEqual(out.size, im.size) - im = hopper() + x, y = im.size + self.assertEqual(im.getpixel((1, 1)), out.getpixel((x-2, 1))) + self.assertEqual(im.getpixel((x-2, 1)), out.getpixel((1, 1))) + self.assertEqual(im.getpixel((1, y-2)), out.getpixel((x-2, y-2))) + self.assertEqual(im.getpixel((x-2, y-2)), out.getpixel((1, y-2))) - im.transpose(FLIP_LEFT_RIGHT) - im.transpose(FLIP_TOP_BOTTOM) + for mode in ("L", "RGB"): + transpose(mode) - im.transpose(ROTATE_90) - im.transpose(ROTATE_180) - im.transpose(ROTATE_270) + def test_flip_top_bottom(self): + def transpose(mode): + im = hopper(mode) + out = im.transpose(FLIP_TOP_BOTTOM) + self.assertEqual(out.mode, mode) + self.assertEqual(out.size, im.size) + + x, y = im.size + self.assertEqual(im.getpixel((1, 1)), out.getpixel((1, y-2))) + self.assertEqual(im.getpixel((x-2, 1)), out.getpixel((x-2, y-2))) + self.assertEqual(im.getpixel((1, y-2)), out.getpixel((1, 1))) + self.assertEqual(im.getpixel((x-2, y-2)), out.getpixel((x-2, 1))) + + for mode in ("L", "RGB"): + transpose(mode) + + def test_rotate_90(self): + def transpose(mode): + im = hopper(mode) + out = im.transpose(ROTATE_90) + self.assertEqual(out.mode, mode) + self.assertEqual(out.size, im.size[::-1]) + + x, y = im.size + self.assertEqual(im.getpixel((1, 1)), out.getpixel((1, y-2))) + self.assertEqual(im.getpixel((x-2, 1)), out.getpixel((1, 1))) + self.assertEqual(im.getpixel((1, y-2)), out.getpixel((x-2, y-2))) + self.assertEqual(im.getpixel((x-2, y-2)), out.getpixel((x-2, 1))) + + for mode in ("L", "RGB"): + transpose(mode) + + def test_rotate_180(self): + def transpose(mode): + im = hopper(mode) + out = im.transpose(ROTATE_180) + self.assertEqual(out.mode, mode) + self.assertEqual(out.size, im.size) + + x, y = im.size + self.assertEqual(im.getpixel((1, 1)), out.getpixel((x-2, y-2))) + self.assertEqual(im.getpixel((x-2, 1)), out.getpixel((1, y-2))) + self.assertEqual(im.getpixel((1, y-2)), out.getpixel((x-2, 1))) + self.assertEqual(im.getpixel((x-2, y-2)), out.getpixel((1, 1))) + + for mode in ("L", "RGB"): + transpose(mode) + + def test_rotate_270(self): + def transpose(mode): + im = hopper(mode) + out = im.transpose(ROTATE_270) + self.assertEqual(out.mode, mode) + self.assertEqual(out.size, im.size[::-1]) + + x, y = im.size + self.assertEqual(im.getpixel((1, 1)), out.getpixel((x-2, 1))) + self.assertEqual(im.getpixel((x-2, 1)), out.getpixel((x-2, y-2))) + self.assertEqual(im.getpixel((1, y-2)), out.getpixel((1, 1))) + self.assertEqual(im.getpixel((x-2, y-2)), out.getpixel((1, y-2))) + + for mode in ("L", "RGB"): + transpose(mode) + + def test_transpose(self): + def transpose(mode): + im = hopper(mode) + out = im.transpose(TRANSPOSE) + self.assertEqual(out.mode, mode) + self.assertEqual(out.size, im.size[::-1]) + + x, y = im.size + self.assertEqual(im.getpixel((1, 1)), out.getpixel((1, 1))) + self.assertEqual(im.getpixel((x-2, 1)), out.getpixel((1, y-2))) + self.assertEqual(im.getpixel((1, y-2)), out.getpixel((x-2, 1))) + self.assertEqual(im.getpixel((x-2, y-2)), out.getpixel((x-2, y-2))) + + for mode in ("L", "RGB"): + transpose(mode) def test_roundtrip(self): - im = hopper() def transpose(first, second): @@ -33,12 +112,13 @@ class TestImageTranspose(PillowTestCase): im, transpose(FLIP_LEFT_RIGHT, FLIP_LEFT_RIGHT)) self.assert_image_equal( im, transpose(FLIP_TOP_BOTTOM, FLIP_TOP_BOTTOM)) - self.assert_image_equal(im, transpose(ROTATE_90, ROTATE_270)) self.assert_image_equal(im, transpose(ROTATE_180, ROTATE_180)) + self.assert_image_equal( + im.transpose(TRANSPOSE), transpose(ROTATE_90, FLIP_TOP_BOTTOM)) + self.assert_image_equal( + im.transpose(TRANSPOSE), transpose(ROTATE_270, FLIP_LEFT_RIGHT)) if __name__ == '__main__': unittest.main() - -# End of file diff --git a/libImaging/Geometry.c b/libImaging/Geometry.c index aca183112..afd162dad 100644 --- a/libImaging/Geometry.c +++ b/libImaging/Geometry.c @@ -30,11 +30,11 @@ /* Undef if you don't need resampling filters */ #define WITH_FILTERS -/* Large images rotation is inefficient operation in terms of CPU cache. - One row in source image affects each column in destination. - Rotating in small chunks can speed up up to 8 times on modern CPU. - Chunk size of 128 requires only 65k of CPU cache and high enougth - for overhead from extra loop have not been manifested. */ +/* For large images rotation is an inefficient operation in terms of CPU cache. + One row in the source image affects each column in destination. + Rotating in chunks that fit in the cache can speed up rotation + 8x on a modern CPU. A chunk size of 128 requires only 65k and is large enough + that the overhead from the extra loops are not apparent. */ #define ROTATE_CHUNK 128 #define COORD(v) ((v) < 0.0 ? -1 : ((int)(v)))