mirror of
https://github.com/python-pillow/Pillow.git
synced 2024-12-25 09:26:16 +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"):
|
if self.mode in ("1", "P"):
|
||||||
resample = NEAREST
|
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):
|
def save(self, fp, format=None, **params):
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -1,19 +1,23 @@
|
||||||
from helper import unittest, PillowTestCase, hopper
|
from helper import unittest, PillowTestCase, hopper
|
||||||
|
from PIL import Image
|
||||||
|
|
||||||
|
|
||||||
class TestImageRotate(PillowTestCase):
|
class TestImageRotate(PillowTestCase):
|
||||||
|
|
||||||
def test_rotate(self):
|
def test_rotate(self):
|
||||||
def rotate(mode):
|
def rotate(im, mode, angle):
|
||||||
im = hopper(mode)
|
out = im.rotate(angle)
|
||||||
out = im.rotate(45)
|
|
||||||
self.assertEqual(out.mode, mode)
|
self.assertEqual(out.mode, mode)
|
||||||
self.assertEqual(out.size, im.size) # default rotate clips output
|
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.assertEqual(out.mode, mode)
|
||||||
self.assertNotEqual(out.size, im.size)
|
self.assertNotEqual(out.size, im.size)
|
||||||
for mode in "1", "P", "L", "RGB", "I", "F":
|
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__':
|
if __name__ == '__main__':
|
||||||
|
|
|
@ -1550,7 +1550,8 @@ _rotate(ImagingObject* self, PyObject* args)
|
||||||
|
|
||||||
double theta;
|
double theta;
|
||||||
int filter = IMAGING_TRANSFORM_NEAREST;
|
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;
|
return NULL;
|
||||||
|
|
||||||
imIn = self->image;
|
imIn = self->image;
|
||||||
|
@ -1563,7 +1564,8 @@ _rotate(ImagingObject* self, PyObject* args)
|
||||||
/* Rotate with resampling filter */
|
/* Rotate with resampling filter */
|
||||||
imOut = ImagingNew(imIn->mode, imIn->xsize, imIn->ysize);
|
imOut = ImagingNew(imIn->mode, imIn->xsize, imIn->ysize);
|
||||||
(void) ImagingRotate(imOut, imIn, theta, filter);
|
(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 */
|
/* Use fast version */
|
||||||
imOut = ImagingNew(imIn->mode, imIn->ysize, imIn->xsize);
|
imOut = ImagingNew(imIn->mode, imIn->ysize, imIn->xsize);
|
||||||
if (imOut) {
|
if (imOut) {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user