Merge pull request #3741 from radarhere/transpose

Added support for I;16 modes for remaining transpose operations
This commit is contained in:
Hugo 2019-03-23 06:19:00 +00:00 committed by GitHub
commit fccf229a7c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 71 additions and 46 deletions

View File

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

View File

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