From 8ba76f9a108a7bdec33c9b795a0ee00453b96ac3 Mon Sep 17 00:00:00 2001 From: Andrew Murray Date: Sat, 23 Mar 2019 14:13:39 +1100 Subject: [PATCH] Added support for I;16 modes for remaining transpose operations --- Tests/test_image_transpose.py | 53 +++++++++++++++-------------- src/libImaging/Geometry.c | 64 ++++++++++++++++++++++++----------- 2 files changed, 71 insertions(+), 46 deletions(-) diff --git a/Tests/test_image_transpose.py b/Tests/test_image_transpose.py index ad8c77126..1cce5e986 100644 --- a/Tests/test_image_transpose.py +++ b/Tests/test_image_transpose.py @@ -24,7 +24,7 @@ class TestImageTranspose(PillowTestCase): 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))) - for mode in ("L", "RGB", "I;16", "I;16L", "I;16B"): + for mode in self.hopper: transpose(mode) def test_flip_top_bottom(self): @@ -40,7 +40,7 @@ class TestImageTranspose(PillowTestCase): 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", "I;16", "I;16L", "I;16B"): + for mode in self.hopper: transpose(mode) def test_rotate_90(self): @@ -56,7 +56,7 @@ class TestImageTranspose(PillowTestCase): self.assertEqual(im.getpixel((1, y-2)), out.getpixel((y-2, x-2))) self.assertEqual(im.getpixel((x-2, y-2)), out.getpixel((y-2, 1))) - for mode in ("L", "RGB"): + for mode in self.hopper: transpose(mode) def test_rotate_180(self): @@ -72,7 +72,7 @@ class TestImageTranspose(PillowTestCase): 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", "I;16", "I;16L", "I;16B"): + for mode in self.hopper: transpose(mode) def test_rotate_270(self): @@ -88,7 +88,7 @@ class TestImageTranspose(PillowTestCase): self.assertEqual(im.getpixel((1, y-2)), out.getpixel((1, 1))) self.assertEqual(im.getpixel((x-2, y-2)), out.getpixel((1, x-2))) - for mode in ("L", "RGB"): + for mode in self.hopper: transpose(mode) def test_transpose(self): @@ -104,7 +104,7 @@ class TestImageTranspose(PillowTestCase): self.assertEqual(im.getpixel((1, y-2)), out.getpixel((y-2, 1))) self.assertEqual(im.getpixel((x-2, y-2)), out.getpixel((y-2, x-2))) - for mode in ("L", "RGB"): + for mode in self.hopper: transpose(mode) def test_tranverse(self): @@ -120,28 +120,29 @@ class TestImageTranspose(PillowTestCase): self.assertEqual(im.getpixel((1, y-2)), out.getpixel((1, x-2))) self.assertEqual(im.getpixel((x-2, y-2)), out.getpixel((1, 1))) - for mode in ("L", "RGB"): + for mode in self.hopper: transpose(mode) def test_roundtrip(self): - im = self.hopper['L'] + for mode in self.hopper: + im = self.hopper[mode] - def transpose(first, second): - return im.transpose(first).transpose(second) + def transpose(first, second): + return im.transpose(first).transpose(second) - self.assert_image_equal( - 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)) - self.assert_image_equal( - im.transpose(TRANSVERSE), transpose(ROTATE_90, FLIP_LEFT_RIGHT)) - self.assert_image_equal( - im.transpose(TRANSVERSE), transpose(ROTATE_270, FLIP_TOP_BOTTOM)) - self.assert_image_equal( - im.transpose(TRANSVERSE), transpose(ROTATE_180, TRANSPOSE)) + self.assert_image_equal( + 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)) + self.assert_image_equal( + im.transpose(TRANSVERSE), transpose(ROTATE_90, FLIP_LEFT_RIGHT)) + self.assert_image_equal( + im.transpose(TRANSVERSE), transpose(ROTATE_270, FLIP_TOP_BOTTOM)) + self.assert_image_equal( + im.transpose(TRANSVERSE), transpose(ROTATE_180, TRANSPOSE)) diff --git a/src/libImaging/Geometry.c b/src/libImaging/Geometry.c index 5358f6eeb..647486eb8 100644 --- a/src/libImaging/Geometry.c +++ b/src/libImaging/Geometry.c @@ -108,7 +108,8 @@ ImagingRotate90(Imaging imOut, Imaging imIn) INT* in = imIn->image[yyy]; \ xr = imIn->xsize - 1 - xx; \ for (xxx = xx; xxx < xxxsize; xxx++, xr--) { \ - imOut->image[xr][yyy] = in[xxx]; \ + INT* out = imOut->image[xr]; \ + out[yyy] = in[xxx]; \ } \ } \ } \ @@ -118,10 +119,15 @@ ImagingRotate90(Imaging imOut, Imaging imIn) ImagingSectionEnter(&cookie); - if (imIn->image8) - ROTATE_90(UINT8, image8) - else - ROTATE_90(INT32, image32) + if (imIn->image8) { + if (strncmp(imIn->mode, "I;16", 4) == 0) { + ROTATE_90(UINT16, image8); + } else { + ROTATE_90(UINT8, image8); + } + } else { + ROTATE_90(INT32, image32); + } ImagingSectionLeave(&cookie); @@ -157,7 +163,8 @@ ImagingTranspose(Imaging imOut, Imaging imIn) for (yyy = yy; yyy < yyysize; yyy++) { \ INT* in = imIn->image[yyy]; \ for (xxx = xx; xxx < xxxsize; xxx++) { \ - imOut->image[xxx][yyy] = in[xxx]; \ + INT* out = imOut->image[xxx]; \ + out[yyy] = in[xxx]; \ } \ } \ } \ @@ -167,10 +174,15 @@ ImagingTranspose(Imaging imOut, Imaging imIn) ImagingSectionEnter(&cookie); - if (imIn->image8) - TRANSPOSE(UINT8, image8) - else - TRANSPOSE(INT32, image32) + if (imIn->image8) { + if (strncmp(imIn->mode, "I;16", 4) == 0) { + TRANSPOSE(UINT16, image8); + } else { + TRANSPOSE(UINT8, image8); + } + } else { + TRANSPOSE(INT32, image32); + } ImagingSectionLeave(&cookie); @@ -208,7 +220,8 @@ ImagingTransverse(Imaging imOut, Imaging imIn) INT* in = imIn->image[yyy]; \ xr = imIn->xsize - 1 - xx; \ for (xxx = xx; xxx < xxxsize; xxx++, xr--) { \ - imOut->image[xr][yr] = in[xxx]; \ + INT* out = imOut->image[xr]; \ + out[yr] = in[xxx]; \ } \ } \ } \ @@ -218,10 +231,15 @@ ImagingTransverse(Imaging imOut, Imaging imIn) ImagingSectionEnter(&cookie); - if (imIn->image8) - TRANSVERSE(UINT8, image8) - else - TRANSVERSE(INT32, image32) + if (imIn->image8) { + if (strncmp(imIn->mode, "I;16", 4) == 0) { + TRANSVERSE(UINT16, image8); + } else { + TRANSVERSE(UINT8, image8); + } + } else { + TRANSVERSE(INT32, image32); + } ImagingSectionLeave(&cookie); @@ -301,7 +319,8 @@ ImagingRotate270(Imaging imOut, Imaging imIn) for (yyy = yy; yyy < yyysize; yyy++, yr--) { \ INT* in = imIn->image[yyy]; \ for (xxx = xx; xxx < xxxsize; xxx++) { \ - imOut->image[xxx][yr] = in[xxx]; \ + INT* out = imOut->image[xxx]; \ + out[yr] = in[xxx]; \ } \ } \ } \ @@ -311,10 +330,15 @@ ImagingRotate270(Imaging imOut, Imaging imIn) ImagingSectionEnter(&cookie); - if (imIn->image8) - ROTATE_270(UINT8, image8) - else - ROTATE_270(INT32, image32) + if (imIn->image8) { + if (strncmp(imIn->mode, "I;16", 4) == 0) { + ROTATE_270(UINT16, image8); + } else { + ROTATE_270(UINT8, image8); + } + } else { + ROTATE_270(INT32, image32); + } ImagingSectionLeave(&cookie);