From 7acaf3d6a692acdd350ee36cd0881f5f822d02f0 Mon Sep 17 00:00:00 2001 From: Andrew Murray Date: Thu, 10 Jan 2019 07:26:52 +1100 Subject: [PATCH] Added support for I;16 modes for more transpose operations --- Tests/test_image_transpose.py | 13 ++++++------- src/libImaging/Geometry.c | 12 ++++++++++-- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/Tests/test_image_transpose.py b/Tests/test_image_transpose.py index a6b1191db..01501bc18 100644 --- a/Tests/test_image_transpose.py +++ b/Tests/test_image_transpose.py @@ -7,10 +7,9 @@ from PIL.Image import (FLIP_LEFT_RIGHT, FLIP_TOP_BOTTOM, ROTATE_90, ROTATE_180, class TestImageTranspose(PillowTestCase): - hopper = { - 'L': helper.hopper('L').crop((0, 0, 121, 127)).copy(), - 'RGB': helper.hopper('RGB').crop((0, 0, 121, 127)).copy(), - } + hopper = {mode: helper.hopper(mode).crop((0, 0, 121, 127)).copy() for mode in [ + 'L', 'RGB', 'I;16', 'I;16L', 'I;16B' + ]} def test_flip_left_right(self): def transpose(mode): @@ -25,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"): + for mode in ("L", "RGB", "I;16", "I;16L", "I;16B"): transpose(mode) def test_flip_top_bottom(self): @@ -41,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"): + for mode in ("L", "RGB", "I;16", "I;16L", "I;16B"): transpose(mode) def test_rotate_90(self): @@ -73,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"): + for mode in ("L", "RGB", "I;16", "I;16L", "I;16B"): transpose(mode) def test_rotate_270(self): diff --git a/src/libImaging/Geometry.c b/src/libImaging/Geometry.c index 1d08728da..5358f6eeb 100644 --- a/src/libImaging/Geometry.c +++ b/src/libImaging/Geometry.c @@ -39,7 +39,11 @@ ImagingFlipLeftRight(Imaging imOut, Imaging imIn) ImagingSectionEnter(&cookie); if (imIn->image8) { - FLIP_LEFT_RIGHT(UINT8, image8) + if (strncmp(imIn->mode, "I;16", 4) == 0) { + FLIP_LEFT_RIGHT(UINT16, image8) + } else { + FLIP_LEFT_RIGHT(UINT8, image8) + } } else { FLIP_LEFT_RIGHT(INT32, image32) } @@ -253,7 +257,11 @@ ImagingRotate180(Imaging imOut, Imaging imIn) yr = imIn->ysize-1; if (imIn->image8) { - ROTATE_180(UINT8, image8) + if (strncmp(imIn->mode, "I;16", 4) == 0) { + ROTATE_180(UINT16, image8) + } else { + ROTATE_180(UINT8, image8) + } } else { ROTATE_180(INT32, image32) }