diff --git a/Tests/test_file_tiff.py b/Tests/test_file_tiff.py index 81872fdc8..6f00afdac 100644 --- a/Tests/test_file_tiff.py +++ b/Tests/test_file_tiff.py @@ -905,6 +905,9 @@ class TestFileTiff: im2 = im.crop((2, 2, 7, 7)) check_image(im2, 5, 5, pixel) + im3 = im.transpose(Image.Transpose.FLIP_LEFT_RIGHT) + check_image(im3, 10, 10, pixel) + @pytest.mark.skipif(not is_win32(), reason="Windows only") class TestFileTiffW32: diff --git a/src/_imaging.c b/src/_imaging.c index 8e2df33ab..efcbf55c2 100644 --- a/src/_imaging.c +++ b/src/_imaging.c @@ -2143,14 +2143,16 @@ _transpose(ImagingObject *self, PyObject *args) { case 1: /* flip top bottom */ case 3: /* rotate 180 */ imOut = ImagingNewDirty( - imIn->mode, (ImagingNewParams){imIn->xsize, imIn->ysize}); + imIn->mode, + (ImagingNewParams){imIn->xsize, imIn->ysize, imIn->depth, imIn->bands}); break; case 2: /* rotate 90 */ case 4: /* rotate 270 */ case 5: /* transpose */ case 6: /* transverse */ imOut = ImagingNewDirty( - imIn->mode, (ImagingNewParams){imIn->ysize, imIn->xsize}); + imIn->mode, + (ImagingNewParams){imIn->ysize, imIn->xsize, imIn->depth, imIn->bands}); break; default: PyErr_SetString(PyExc_ValueError, "No such transpose operation"); diff --git a/src/libImaging/Geometry.c b/src/libImaging/Geometry.c index cf3bc9979..abc91fc1c 100644 --- a/src/libImaging/Geometry.c +++ b/src/libImaging/Geometry.c @@ -17,7 +17,7 @@ Imaging ImagingFlipLeftRight(Imaging imOut, Imaging imIn) { ImagingSectionCookie cookie; - int x, y, xr; + // int x, y, xr; if (!imOut || !imIn || strcmp(imIn->mode, imOut->mode) != 0) { return (Imaging)ImagingError_ModeError(); @@ -28,32 +28,18 @@ ImagingFlipLeftRight(Imaging imOut, Imaging imIn) { ImagingCopyPalette(imOut, imIn); -#define FLIP_LEFT_RIGHT(INT, image) \ - for (y = 0; y < imIn->ysize; y++) { \ - INT *in = (INT *)imIn->image[y]; \ - INT *out = (INT *)imOut->image[y]; \ - xr = imIn->xsize - 1; \ - for (x = 0; x < imIn->xsize; x++, xr--) { \ - out[xr] = in[x]; \ - } \ - } - ImagingSectionEnter(&cookie); - - if (imIn->image8) { - if (strncmp(imIn->mode, "I;16", 4) == 0) { - FLIP_LEFT_RIGHT(UINT16, image8) - } else { - FLIP_LEFT_RIGHT(UINT8, image8) + for (int y = 0; y < imIn->ysize; ++y) { + char *in = imIn->image[y]; + char *out = imOut->image[y]; + int xr = imIn->linesize - imIn->pixelsize; + for (int x = 0; x < imIn->linesize; + x += imIn->pixelsize, xr -= imIn->pixelsize) { + memcpy(out + xr, in + x, imIn->pixelsize); } - } else { - FLIP_LEFT_RIGHT(INT32, image32) } - ImagingSectionLeave(&cookie); -#undef FLIP_LEFT_RIGHT - return imOut; }