replace resize implementation

This commit is contained in:
homm 2014-11-04 12:31:36 +03:00
parent d781d56aa5
commit aba798af25
4 changed files with 22 additions and 39 deletions

View File

@ -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):
"""

View File

@ -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);
}

View File

@ -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)
{

View File

@ -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);