FLIP_LEFT_RIGHT with multi-band format

This commit is contained in:
Junxiao Shi 2024-06-02 17:38:27 +00:00
parent 0df0935bb4
commit c4434df6a1
3 changed files with 15 additions and 24 deletions

View File

@ -905,6 +905,9 @@ class TestFileTiff:
im2 = im.crop((2, 2, 7, 7)) im2 = im.crop((2, 2, 7, 7))
check_image(im2, 5, 5, pixel) 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") @pytest.mark.skipif(not is_win32(), reason="Windows only")
class TestFileTiffW32: class TestFileTiffW32:

View File

@ -2143,14 +2143,16 @@ _transpose(ImagingObject *self, PyObject *args) {
case 1: /* flip top bottom */ case 1: /* flip top bottom */
case 3: /* rotate 180 */ case 3: /* rotate 180 */
imOut = ImagingNewDirty( imOut = ImagingNewDirty(
imIn->mode, (ImagingNewParams){imIn->xsize, imIn->ysize}); imIn->mode,
(ImagingNewParams){imIn->xsize, imIn->ysize, imIn->depth, imIn->bands});
break; break;
case 2: /* rotate 90 */ case 2: /* rotate 90 */
case 4: /* rotate 270 */ case 4: /* rotate 270 */
case 5: /* transpose */ case 5: /* transpose */
case 6: /* transverse */ case 6: /* transverse */
imOut = ImagingNewDirty( imOut = ImagingNewDirty(
imIn->mode, (ImagingNewParams){imIn->ysize, imIn->xsize}); imIn->mode,
(ImagingNewParams){imIn->ysize, imIn->xsize, imIn->depth, imIn->bands});
break; break;
default: default:
PyErr_SetString(PyExc_ValueError, "No such transpose operation"); PyErr_SetString(PyExc_ValueError, "No such transpose operation");

View File

@ -17,7 +17,7 @@
Imaging Imaging
ImagingFlipLeftRight(Imaging imOut, Imaging imIn) { ImagingFlipLeftRight(Imaging imOut, Imaging imIn) {
ImagingSectionCookie cookie; ImagingSectionCookie cookie;
int x, y, xr; // int x, y, xr;
if (!imOut || !imIn || strcmp(imIn->mode, imOut->mode) != 0) { if (!imOut || !imIn || strcmp(imIn->mode, imOut->mode) != 0) {
return (Imaging)ImagingError_ModeError(); return (Imaging)ImagingError_ModeError();
@ -28,32 +28,18 @@ ImagingFlipLeftRight(Imaging imOut, Imaging imIn) {
ImagingCopyPalette(imOut, 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); ImagingSectionEnter(&cookie);
for (int y = 0; y < imIn->ysize; ++y) {
if (imIn->image8) { char *in = imIn->image[y];
if (strncmp(imIn->mode, "I;16", 4) == 0) { char *out = imOut->image[y];
FLIP_LEFT_RIGHT(UINT16, image8) int xr = imIn->linesize - imIn->pixelsize;
} else { for (int x = 0; x < imIn->linesize;
FLIP_LEFT_RIGHT(UINT8, image8) x += imIn->pixelsize, xr -= imIn->pixelsize) {
memcpy(out + xr, in + x, imIn->pixelsize);
} }
} else {
FLIP_LEFT_RIGHT(INT32, image32)
} }
ImagingSectionLeave(&cookie); ImagingSectionLeave(&cookie);
#undef FLIP_LEFT_RIGHT
return imOut; return imOut;
} }