Merge pull request #3563 from radarhere/transpose

Added support for I;16 modes for more transpose operations
This commit is contained in:
Hugo 2019-02-27 23:22:52 +02:00 committed by GitHub
commit 2f5f80f47e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
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):
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):

View File

@ -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)
}