mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-01-12 18:26:17 +03:00
Hide stretch implementation detail in Antialias.c
This commit is contained in:
parent
2d5b74f90a
commit
c8471bcbda
25
_imaging.c
25
_imaging.c
|
@ -1613,7 +1613,6 @@ static PyObject*
|
|||
_stretch(ImagingObject* self, PyObject* args)
|
||||
{
|
||||
Imaging imIn;
|
||||
Imaging imTemp;
|
||||
Imaging imOut;
|
||||
|
||||
int xsize, ysize;
|
||||
|
@ -1623,35 +1622,15 @@ _stretch(ImagingObject* self, PyObject* args)
|
|||
|
||||
imIn = self->image;
|
||||
|
||||
/* two-pass resize: minimize size of intermediate image */
|
||||
if ((Py_ssize_t) imIn->xsize * ysize < (Py_ssize_t) xsize * imIn->ysize)
|
||||
imTemp = ImagingNew(imIn->mode, imIn->xsize, ysize);
|
||||
else
|
||||
imTemp = ImagingNew(imIn->mode, xsize, imIn->ysize);
|
||||
if (!imTemp)
|
||||
return NULL;
|
||||
|
||||
/* first pass */
|
||||
if (!ImagingStretch(imTemp, imIn, filter)) {
|
||||
ImagingDelete(imTemp);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
imOut = ImagingNew(imIn->mode, xsize, ysize);
|
||||
if (!imOut) {
|
||||
ImagingDelete(imTemp);
|
||||
if ( ! imOut)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* second pass */
|
||||
if (!ImagingStretch(imOut, imTemp, filter)) {
|
||||
if (!ImagingStretch(imOut, imIn, filter)) {
|
||||
ImagingDelete(imOut);
|
||||
ImagingDelete(imTemp);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
ImagingDelete(imTemp);
|
||||
|
||||
return PyImagingNew(imOut);
|
||||
}
|
||||
|
||||
|
|
|
@ -79,7 +79,7 @@ static inline float bicubic_filter(float x)
|
|||
static struct filter BICUBIC = { bicubic_filter, 2.0 };
|
||||
|
||||
Imaging
|
||||
ImagingStretch(Imaging imOut, Imaging imIn, int filter)
|
||||
ImagingStretchPass(Imaging imOut, Imaging imIn, int filter)
|
||||
{
|
||||
/* FIXME: this is a quick and straightforward translation from a
|
||||
python prototype. might need some further C-ification... */
|
||||
|
@ -95,9 +95,6 @@ ImagingStretch(Imaging imOut, Imaging imIn, int filter)
|
|||
if (!imOut || !imIn || strcmp(imIn->mode, imOut->mode) != 0)
|
||||
return (Imaging) ImagingError_ModeError();
|
||||
|
||||
if (strcmp(imIn->mode, "P") == 0 || strcmp(imIn->mode, "1") == 0)
|
||||
return (Imaging) ImagingError_ModeError();
|
||||
|
||||
/* check filter */
|
||||
switch (filter) {
|
||||
case IMAGING_TRANSFORM_NEAREST:
|
||||
|
@ -305,3 +302,39 @@ ImagingStretch(Imaging imOut, Imaging imIn, int filter)
|
|||
|
||||
return imOut;
|
||||
}
|
||||
|
||||
|
||||
Imaging
|
||||
ImagingStretch(Imaging imOut, Imaging imIn, int filter)
|
||||
{
|
||||
Imaging imTemp;
|
||||
int xsize = imOut->xsize;
|
||||
int ysize = imOut->ysize;
|
||||
|
||||
if (strcmp(imIn->mode, "P") == 0 || strcmp(imIn->mode, "1") == 0)
|
||||
return (Imaging) ImagingError_ModeError();
|
||||
|
||||
/* two-pass resize: minimize size of intermediate image */
|
||||
if ((Py_ssize_t) imIn->xsize * ysize < (Py_ssize_t) xsize * imIn->ysize)
|
||||
imTemp = ImagingNew(imIn->mode, imIn->xsize, ysize);
|
||||
else
|
||||
imTemp = ImagingNew(imIn->mode, xsize, imIn->ysize);
|
||||
if ( ! imTemp)
|
||||
return NULL;
|
||||
|
||||
/* first pass */
|
||||
if ( ! ImagingStretchPass(imTemp, imIn, filter)) {
|
||||
ImagingDelete(imTemp);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* second pass */
|
||||
if ( ! ImagingStretchPass(imOut, imTemp, filter)) {
|
||||
ImagingDelete(imTemp);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
ImagingDelete(imTemp);
|
||||
|
||||
return imOut;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user