mirror of
https://github.com/python-pillow/Pillow.git
synced 2024-12-26 01:46:18 +03:00
Merge pull request #1954 from uploadcare/skip-resampling-passes
Do not do unnecessary passes on resizing
This commit is contained in:
commit
291c00c58a
|
@ -254,5 +254,25 @@ class CoreResampleAlphaCorrectTest(PillowTestCase):
|
|||
self.run_dity_case(case.resize((20, 20), Image.LANCZOS), (255,))
|
||||
|
||||
|
||||
class CoreResamplePassesTest(PillowTestCase):
|
||||
def test_horizontal(self):
|
||||
im = hopper('L')
|
||||
count = Image.core.getcount()
|
||||
im.resize((im.size[0] + 10, im.size[1]), Image.BILINEAR)
|
||||
self.assertEqual(Image.core.getcount(), count + 1)
|
||||
|
||||
def test_vertical(self):
|
||||
im = hopper('L')
|
||||
count = Image.core.getcount()
|
||||
im.resize((im.size[0], im.size[1] + 10), Image.BILINEAR)
|
||||
self.assertEqual(Image.core.getcount(), count + 1)
|
||||
|
||||
def test_both(self):
|
||||
im = hopper('L')
|
||||
count = Image.core.getcount()
|
||||
im.resize((im.size[0] + 10, im.size[1] + 10), Image.BILINEAR)
|
||||
self.assertEqual(Image.core.getcount(), count + 2)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
|
|
@ -492,8 +492,8 @@ ImagingResampleVertical_32bpc(Imaging imIn, int ysize, struct filter *filterp)
|
|||
Imaging
|
||||
ImagingResample(Imaging imIn, int xsize, int ysize, int filter)
|
||||
{
|
||||
Imaging imTemp;
|
||||
Imaging imOut;
|
||||
Imaging imTemp = NULL;
|
||||
Imaging imOut = NULL;
|
||||
struct filter *filterp;
|
||||
Imaging (*ResampleHorizontal)(Imaging imIn, int xsize, struct filter *filterp);
|
||||
Imaging (*ResampleVertical)(Imaging imIn, int xsize, struct filter *filterp);
|
||||
|
@ -540,15 +540,28 @@ ImagingResample(Imaging imIn, int xsize, int ysize, int filter)
|
|||
}
|
||||
|
||||
/* two-pass resize, first pass */
|
||||
if (imIn->xsize != xsize) {
|
||||
imTemp = ResampleHorizontal(imIn, xsize, filterp);
|
||||
if ( ! imTemp)
|
||||
return NULL;
|
||||
imOut = imIn = imTemp;
|
||||
}
|
||||
|
||||
/* second pass */
|
||||
imOut = ResampleVertical(imTemp, ysize, filterp);
|
||||
if (imIn->ysize != ysize) {
|
||||
/* imIn can be the original image or horizontally resampled one */
|
||||
imOut = ResampleVertical(imIn, ysize, filterp);
|
||||
/* it's safe to call ImagingDelete with empty value
|
||||
if there was no previous step. */
|
||||
ImagingDelete(imTemp);
|
||||
if ( ! imOut)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* none of the previous steps are performed, copying */
|
||||
if ( ! imOut) {
|
||||
imOut = ImagingCopy(imIn);
|
||||
}
|
||||
|
||||
return imOut;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user