From aba798af259718e5a164aa42460d905fa87fb215 Mon Sep 17 00:00:00 2001 From: homm Date: Tue, 4 Nov 2014 12:31:36 +0300 Subject: [PATCH] replace resize implementation --- PIL/Image.py | 13 ++----------- _imaging.c | 23 ++++++++++++++++++++--- libImaging/Geometry.c | 24 ------------------------ libImaging/Imaging.h | 1 - 4 files changed, 22 insertions(+), 39 deletions(-) diff --git a/PIL/Image.py b/PIL/Image.py index 922fe36a8..8e7140847 100644 --- a/PIL/Image.py +++ b/PIL/Image.py @@ -876,7 +876,7 @@ class Image: elif self.mode == 'P' and mode == 'RGBA': t = self.info['transparency'] delete_trns = True - + if isinstance(t, bytes): self.im.putpalettealphas(t) elif isinstance(t, int): @@ -1539,16 +1539,7 @@ class Image: if self.mode == 'RGBA': return self.convert('RGBa').resize(size, resample).convert('RGBA') - if resample == ANTIALIAS: - # requires stretch support (imToolkit & PIL 1.1.3) - try: - im = self.im.stretch(size, resample) - except AttributeError: - raise ValueError("unsupported resampling filter") - else: - im = self.im.resize(size, resample) - - return self._new(im) + return self._new(self.im.resize(size, resample)) def rotate(self, angle, resample=NEAREST, expand=0): """ diff --git a/_imaging.c b/_imaging.c index f7ea510bc..280db9fdb 100644 --- a/_imaging.c +++ b/_imaging.c @@ -1513,9 +1513,26 @@ _resize(ImagingObject* self, PyObject* args) imIn = self->image; - imOut = ImagingNew(imIn->mode, xsize, ysize); - if (imOut) - (void) ImagingResize(imOut, imIn, filter); + if (imIn->xsize == xsize && imIn->ysize == ysize) { + imOut = ImagingCopy(imIn); + } + else if ( ! filter) { + double a[6]; + + memset(a, 0, sizeof a); + a[1] = (double) imIn->xsize / xsize; + a[5] = (double) imIn->ysize / ysize; + + imOut = ImagingNew(imIn->mode, xsize, ysize); + + imOut = ImagingTransformAffine( + imOut, imIn, + 0, 0, xsize, ysize, + a, filter, 1); + } + else { + imOut = ImagingStretch(imIn, xsize, ysize, filter); + } return PyImagingNew(imOut); } diff --git a/libImaging/Geometry.c b/libImaging/Geometry.c index b987a5616..f586974c3 100644 --- a/libImaging/Geometry.c +++ b/libImaging/Geometry.c @@ -979,30 +979,6 @@ ImagingTransformQuad(Imaging imOut, Imaging imIn, /* -------------------------------------------------------------------- */ /* Convenience functions */ -Imaging -ImagingResize(Imaging imOut, Imaging imIn, int filterid) -{ - double a[6]; - - if (imOut->xsize == imIn->xsize && imOut->ysize == imIn->ysize) - return ImagingCopy2(imOut, imIn); - - memset(a, 0, sizeof a); - a[1] = (double) imIn->xsize / imOut->xsize; - a[5] = (double) imIn->ysize / imOut->ysize; - - if (!filterid && imIn->type != IMAGING_TYPE_SPECIAL) - return ImagingScaleAffine( - imOut, imIn, - 0, 0, imOut->xsize, imOut->ysize, - a, 1); - - return ImagingTransformAffine( - imOut, imIn, - 0, 0, imOut->xsize, imOut->ysize, - a, filterid, 1); -} - Imaging ImagingRotate(Imaging imOut, Imaging imIn, double theta, int filterid) { diff --git a/libImaging/Imaging.h b/libImaging/Imaging.h index 6c91958ec..694a15c21 100644 --- a/libImaging/Imaging.h +++ b/libImaging/Imaging.h @@ -285,7 +285,6 @@ extern Imaging ImagingPointTransform( Imaging imIn, double scale, double offset); extern Imaging ImagingPutBand(Imaging im, Imaging imIn, int band); extern Imaging ImagingRankFilter(Imaging im, int size, int rank); -extern Imaging ImagingResize(Imaging imOut, Imaging imIn, int filter); extern Imaging ImagingRotate( Imaging imOut, Imaging imIn, double theta, int filter); extern Imaging ImagingRotate90(Imaging imOut, Imaging imIn);