mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-06-27 08:23:23 +03:00
FLIP_LEFT_RIGHT with multi-band format
This commit is contained in:
parent
0df0935bb4
commit
c4434df6a1
|
@ -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:
|
||||
|
|
|
@ -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");
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user