Added support for I;16 modes for more transpose operations

This commit is contained in:
Andrew Murray 2019-01-10 07:26:52 +11:00
parent 7bf5246b93
commit 7acaf3d6a6
2 changed files with 16 additions and 9 deletions

View File

@ -7,10 +7,9 @@ from PIL.Image import (FLIP_LEFT_RIGHT, FLIP_TOP_BOTTOM, ROTATE_90, ROTATE_180,
class TestImageTranspose(PillowTestCase): class TestImageTranspose(PillowTestCase):
hopper = { hopper = {mode: helper.hopper(mode).crop((0, 0, 121, 127)).copy() for mode in [
'L': helper.hopper('L').crop((0, 0, 121, 127)).copy(), 'L', 'RGB', 'I;16', 'I;16L', 'I;16B'
'RGB': helper.hopper('RGB').crop((0, 0, 121, 127)).copy(), ]}
}
def test_flip_left_right(self): def test_flip_left_right(self):
def transpose(mode): 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((1, y-2)), out.getpixel((x-2, y-2)))
self.assertEqual(im.getpixel((x-2, y-2)), out.getpixel((1, 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) transpose(mode)
def test_flip_top_bottom(self): 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((1, y-2)), out.getpixel((1, 1)))
self.assertEqual(im.getpixel((x-2, y-2)), out.getpixel((x-2, 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) transpose(mode)
def test_rotate_90(self): 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((1, y-2)), out.getpixel((x-2, 1)))
self.assertEqual(im.getpixel((x-2, y-2)), out.getpixel((1, 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) transpose(mode)
def test_rotate_270(self): def test_rotate_270(self):

View File

@ -39,7 +39,11 @@ ImagingFlipLeftRight(Imaging imOut, Imaging imIn)
ImagingSectionEnter(&cookie); ImagingSectionEnter(&cookie);
if (imIn->image8) { 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 { } else {
FLIP_LEFT_RIGHT(INT32, image32) FLIP_LEFT_RIGHT(INT32, image32)
} }
@ -253,7 +257,11 @@ ImagingRotate180(Imaging imOut, Imaging imIn)
yr = imIn->ysize-1; yr = imIn->ysize-1;
if (imIn->image8) { 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 { } else {
ROTATE_180(INT32, image32) ROTATE_180(INT32, image32)
} }