mirror of
https://github.com/python-pillow/Pillow.git
synced 2024-11-13 13:16:52 +03:00
Merge pull request #3741 from radarhere/transpose
Added support for I;16 modes for remaining transpose operations
This commit is contained in:
commit
fccf229a7c
|
@ -24,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", "I;16", "I;16L", "I;16B"):
|
for mode in self.hopper:
|
||||||
transpose(mode)
|
transpose(mode)
|
||||||
|
|
||||||
def test_flip_top_bottom(self):
|
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((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", "I;16", "I;16L", "I;16B"):
|
for mode in self.hopper:
|
||||||
transpose(mode)
|
transpose(mode)
|
||||||
|
|
||||||
def test_rotate_90(self):
|
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((1, y-2)), out.getpixel((y-2, x-2)))
|
||||||
self.assertEqual(im.getpixel((x-2, y-2)), out.getpixel((y-2, 1)))
|
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)
|
transpose(mode)
|
||||||
|
|
||||||
def test_rotate_180(self):
|
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((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", "I;16", "I;16L", "I;16B"):
|
for mode in self.hopper:
|
||||||
transpose(mode)
|
transpose(mode)
|
||||||
|
|
||||||
def test_rotate_270(self):
|
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((1, y-2)), out.getpixel((1, 1)))
|
||||||
self.assertEqual(im.getpixel((x-2, y-2)), out.getpixel((1, x-2)))
|
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)
|
transpose(mode)
|
||||||
|
|
||||||
def test_transpose(self):
|
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((1, y-2)), out.getpixel((y-2, 1)))
|
||||||
self.assertEqual(im.getpixel((x-2, y-2)), out.getpixel((y-2, x-2)))
|
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)
|
transpose(mode)
|
||||||
|
|
||||||
def test_tranverse(self):
|
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((1, y-2)), out.getpixel((1, x-2)))
|
||||||
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 self.hopper:
|
||||||
transpose(mode)
|
transpose(mode)
|
||||||
|
|
||||||
def test_roundtrip(self):
|
def test_roundtrip(self):
|
||||||
im = self.hopper['L']
|
for mode in self.hopper:
|
||||||
|
im = self.hopper[mode]
|
||||||
|
|
||||||
def transpose(first, second):
|
def transpose(first, second):
|
||||||
return im.transpose(first).transpose(second)
|
return im.transpose(first).transpose(second)
|
||||||
|
|
||||||
self.assert_image_equal(
|
self.assert_image_equal(
|
||||||
im, transpose(FLIP_LEFT_RIGHT, FLIP_LEFT_RIGHT))
|
im, transpose(FLIP_LEFT_RIGHT, FLIP_LEFT_RIGHT))
|
||||||
self.assert_image_equal(
|
self.assert_image_equal(
|
||||||
im, transpose(FLIP_TOP_BOTTOM, FLIP_TOP_BOTTOM))
|
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_90, ROTATE_270))
|
||||||
self.assert_image_equal(im, transpose(ROTATE_180, ROTATE_180))
|
self.assert_image_equal(im, transpose(ROTATE_180, ROTATE_180))
|
||||||
self.assert_image_equal(
|
self.assert_image_equal(
|
||||||
im.transpose(TRANSPOSE), transpose(ROTATE_90, FLIP_TOP_BOTTOM))
|
im.transpose(TRANSPOSE), transpose(ROTATE_90, FLIP_TOP_BOTTOM))
|
||||||
self.assert_image_equal(
|
self.assert_image_equal(
|
||||||
im.transpose(TRANSPOSE), transpose(ROTATE_270, FLIP_LEFT_RIGHT))
|
im.transpose(TRANSPOSE), transpose(ROTATE_270, FLIP_LEFT_RIGHT))
|
||||||
self.assert_image_equal(
|
self.assert_image_equal(
|
||||||
im.transpose(TRANSVERSE), transpose(ROTATE_90, FLIP_LEFT_RIGHT))
|
im.transpose(TRANSVERSE), transpose(ROTATE_90, FLIP_LEFT_RIGHT))
|
||||||
self.assert_image_equal(
|
self.assert_image_equal(
|
||||||
im.transpose(TRANSVERSE), transpose(ROTATE_270, FLIP_TOP_BOTTOM))
|
im.transpose(TRANSVERSE), transpose(ROTATE_270, FLIP_TOP_BOTTOM))
|
||||||
self.assert_image_equal(
|
self.assert_image_equal(
|
||||||
im.transpose(TRANSVERSE), transpose(ROTATE_180, TRANSPOSE))
|
im.transpose(TRANSVERSE), transpose(ROTATE_180, TRANSPOSE))
|
||||||
|
|
|
@ -108,7 +108,8 @@ ImagingRotate90(Imaging imOut, Imaging imIn)
|
||||||
INT* in = imIn->image[yyy]; \
|
INT* in = imIn->image[yyy]; \
|
||||||
xr = imIn->xsize - 1 - xx; \
|
xr = imIn->xsize - 1 - xx; \
|
||||||
for (xxx = xx; xxx < xxxsize; xxx++, xr--) { \
|
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);
|
ImagingSectionEnter(&cookie);
|
||||||
|
|
||||||
if (imIn->image8)
|
if (imIn->image8) {
|
||||||
ROTATE_90(UINT8, image8)
|
if (strncmp(imIn->mode, "I;16", 4) == 0) {
|
||||||
else
|
ROTATE_90(UINT16, image8);
|
||||||
ROTATE_90(INT32, image32)
|
} else {
|
||||||
|
ROTATE_90(UINT8, image8);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
ROTATE_90(INT32, image32);
|
||||||
|
}
|
||||||
|
|
||||||
ImagingSectionLeave(&cookie);
|
ImagingSectionLeave(&cookie);
|
||||||
|
|
||||||
|
@ -157,7 +163,8 @@ ImagingTranspose(Imaging imOut, Imaging imIn)
|
||||||
for (yyy = yy; yyy < yyysize; yyy++) { \
|
for (yyy = yy; yyy < yyysize; yyy++) { \
|
||||||
INT* in = imIn->image[yyy]; \
|
INT* in = imIn->image[yyy]; \
|
||||||
for (xxx = xx; xxx < xxxsize; xxx++) { \
|
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);
|
ImagingSectionEnter(&cookie);
|
||||||
|
|
||||||
if (imIn->image8)
|
if (imIn->image8) {
|
||||||
TRANSPOSE(UINT8, image8)
|
if (strncmp(imIn->mode, "I;16", 4) == 0) {
|
||||||
else
|
TRANSPOSE(UINT16, image8);
|
||||||
TRANSPOSE(INT32, image32)
|
} else {
|
||||||
|
TRANSPOSE(UINT8, image8);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
TRANSPOSE(INT32, image32);
|
||||||
|
}
|
||||||
|
|
||||||
ImagingSectionLeave(&cookie);
|
ImagingSectionLeave(&cookie);
|
||||||
|
|
||||||
|
@ -208,7 +220,8 @@ ImagingTransverse(Imaging imOut, Imaging imIn)
|
||||||
INT* in = imIn->image[yyy]; \
|
INT* in = imIn->image[yyy]; \
|
||||||
xr = imIn->xsize - 1 - xx; \
|
xr = imIn->xsize - 1 - xx; \
|
||||||
for (xxx = xx; xxx < xxxsize; xxx++, xr--) { \
|
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);
|
ImagingSectionEnter(&cookie);
|
||||||
|
|
||||||
if (imIn->image8)
|
if (imIn->image8) {
|
||||||
TRANSVERSE(UINT8, image8)
|
if (strncmp(imIn->mode, "I;16", 4) == 0) {
|
||||||
else
|
TRANSVERSE(UINT16, image8);
|
||||||
TRANSVERSE(INT32, image32)
|
} else {
|
||||||
|
TRANSVERSE(UINT8, image8);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
TRANSVERSE(INT32, image32);
|
||||||
|
}
|
||||||
|
|
||||||
ImagingSectionLeave(&cookie);
|
ImagingSectionLeave(&cookie);
|
||||||
|
|
||||||
|
@ -301,7 +319,8 @@ ImagingRotate270(Imaging imOut, Imaging imIn)
|
||||||
for (yyy = yy; yyy < yyysize; yyy++, yr--) { \
|
for (yyy = yy; yyy < yyysize; yyy++, yr--) { \
|
||||||
INT* in = imIn->image[yyy]; \
|
INT* in = imIn->image[yyy]; \
|
||||||
for (xxx = xx; xxx < xxxsize; xxx++) { \
|
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);
|
ImagingSectionEnter(&cookie);
|
||||||
|
|
||||||
if (imIn->image8)
|
if (imIn->image8) {
|
||||||
ROTATE_270(UINT8, image8)
|
if (strncmp(imIn->mode, "I;16", 4) == 0) {
|
||||||
else
|
ROTATE_270(UINT16, image8);
|
||||||
ROTATE_270(INT32, image32)
|
} else {
|
||||||
|
ROTATE_270(UINT8, image8);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
ROTATE_270(INT32, image32);
|
||||||
|
}
|
||||||
|
|
||||||
ImagingSectionLeave(&cookie);
|
ImagingSectionLeave(&cookie);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user