mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-01-13 18:56:17 +03:00
Do not make unnecessary passes on resizing
This commit is contained in:
parent
b3591351f6
commit
78fad0f819
|
@ -254,5 +254,25 @@ class CoreResampleAlphaCorrectTest(PillowTestCase):
|
||||||
self.run_dity_case(case.resize((20, 20), Image.LANCZOS), (255,))
|
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__':
|
if __name__ == '__main__':
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
|
|
@ -494,8 +494,8 @@ ImagingResampleVertical_32bpc(Imaging imIn, int ysize, struct filter *filterp)
|
||||||
Imaging
|
Imaging
|
||||||
ImagingResample(Imaging imIn, int xsize, int ysize, int filter)
|
ImagingResample(Imaging imIn, int xsize, int ysize, int filter)
|
||||||
{
|
{
|
||||||
Imaging imTemp;
|
Imaging imTemp = NULL;
|
||||||
Imaging imOut;
|
Imaging imOut = NULL;
|
||||||
struct filter *filterp;
|
struct filter *filterp;
|
||||||
Imaging (*ResampleHorizontal)(Imaging imIn, int xsize, struct filter *filterp);
|
Imaging (*ResampleHorizontal)(Imaging imIn, int xsize, struct filter *filterp);
|
||||||
Imaging (*ResampleVertical)(Imaging imIn, int xsize, struct filter *filterp);
|
Imaging (*ResampleVertical)(Imaging imIn, int xsize, struct filter *filterp);
|
||||||
|
@ -542,15 +542,28 @@ ImagingResample(Imaging imIn, int xsize, int ysize, int filter)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* two-pass resize, first pass */
|
/* two-pass resize, first pass */
|
||||||
imTemp = ResampleHorizontal(imIn, xsize, filterp);
|
if (imIn->xsize != xsize) {
|
||||||
if ( ! imTemp)
|
imTemp = ResampleHorizontal(imIn, xsize, filterp);
|
||||||
return NULL;
|
if ( ! imTemp)
|
||||||
|
return NULL;
|
||||||
|
imOut = imIn = imTemp;
|
||||||
|
}
|
||||||
|
|
||||||
/* second pass */
|
/* second pass */
|
||||||
imOut = ResampleVertical(imTemp, ysize, filterp);
|
if (imIn->ysize != ysize) {
|
||||||
ImagingDelete(imTemp);
|
/* imIn can be the original image or horizontally resampled one */
|
||||||
if ( ! imOut)
|
imOut = ResampleVertical(imIn, ysize, filterp);
|
||||||
return NULL;
|
/* 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;
|
return imOut;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user