mirror of
https://github.com/python-pillow/Pillow.git
synced 2024-11-10 19:56:47 +03:00
Merge pull request #1373 from radarhere/rotate
Fix fast rotate operations
This commit is contained in:
commit
d66f9eb7ea
|
@ -1621,7 +1621,7 @@ class Image(object):
|
|||
if self.mode in ("1", "P"):
|
||||
resample = NEAREST
|
||||
|
||||
return self._new(self.im.rotate(angle, resample))
|
||||
return self._new(self.im.rotate(angle, resample, expand))
|
||||
|
||||
def save(self, fp, format=None, **params):
|
||||
"""
|
||||
|
|
|
@ -1,19 +1,23 @@
|
|||
from helper import unittest, PillowTestCase, hopper
|
||||
from PIL import Image
|
||||
|
||||
|
||||
class TestImageRotate(PillowTestCase):
|
||||
|
||||
def test_rotate(self):
|
||||
def rotate(mode):
|
||||
im = hopper(mode)
|
||||
out = im.rotate(45)
|
||||
def rotate(im, mode, angle):
|
||||
out = im.rotate(angle)
|
||||
self.assertEqual(out.mode, mode)
|
||||
self.assertEqual(out.size, im.size) # default rotate clips output
|
||||
out = im.rotate(45, expand=1)
|
||||
out = im.rotate(angle, expand=1)
|
||||
self.assertEqual(out.mode, mode)
|
||||
self.assertNotEqual(out.size, im.size)
|
||||
for mode in "1", "P", "L", "RGB", "I", "F":
|
||||
rotate(mode)
|
||||
im = hopper(mode)
|
||||
rotate(im, mode, 45)
|
||||
for angle in 90, 270:
|
||||
im = Image.open('Tests/images/test-card.png')
|
||||
rotate(im, im.mode, angle)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
|
|
@ -1550,7 +1550,8 @@ _rotate(ImagingObject* self, PyObject* args)
|
|||
|
||||
double theta;
|
||||
int filter = IMAGING_TRANSFORM_NEAREST;
|
||||
if (!PyArg_ParseTuple(args, "d|i", &theta, &filter))
|
||||
int expand;
|
||||
if (!PyArg_ParseTuple(args, "d|i|i", &theta, &filter, &expand))
|
||||
return NULL;
|
||||
|
||||
imIn = self->image;
|
||||
|
@ -1563,7 +1564,8 @@ _rotate(ImagingObject* self, PyObject* args)
|
|||
/* Rotate with resampling filter */
|
||||
imOut = ImagingNew(imIn->mode, imIn->xsize, imIn->ysize);
|
||||
(void) ImagingRotate(imOut, imIn, theta, filter);
|
||||
} else if (theta == 90.0 || theta == 270.0) {
|
||||
} else if ((theta == 90.0 || theta == 270.0)
|
||||
&& (expand || imIn->xsize == imIn->ysize)) {
|
||||
/* Use fast version */
|
||||
imOut = ImagingNew(imIn->mode, imIn->ysize, imIn->xsize);
|
||||
if (imOut) {
|
||||
|
|
Loading…
Reference in New Issue
Block a user