mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-06-05 21:53:15 +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)
|
_stretch(ImagingObject* self, PyObject* args)
|
||||||
{
|
{
|
||||||
Imaging imIn;
|
Imaging imIn;
|
||||||
Imaging imTemp;
|
|
||||||
Imaging imOut;
|
Imaging imOut;
|
||||||
|
|
||||||
int xsize, ysize;
|
int xsize, ysize;
|
||||||
|
@ -1623,35 +1622,15 @@ _stretch(ImagingObject* self, PyObject* args)
|
||||||
|
|
||||||
imIn = self->image;
|
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);
|
imOut = ImagingNew(imIn->mode, xsize, ysize);
|
||||||
if (!imOut) {
|
if ( ! imOut)
|
||||||
ImagingDelete(imTemp);
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
|
||||||
|
|
||||||
/* second pass */
|
if (!ImagingStretch(imOut, imIn, filter)) {
|
||||||
if (!ImagingStretch(imOut, imTemp, filter)) {
|
|
||||||
ImagingDelete(imOut);
|
ImagingDelete(imOut);
|
||||||
ImagingDelete(imTemp);
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
ImagingDelete(imTemp);
|
|
||||||
|
|
||||||
return PyImagingNew(imOut);
|
return PyImagingNew(imOut);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -79,7 +79,7 @@ static inline float bicubic_filter(float x)
|
||||||
static struct filter BICUBIC = { bicubic_filter, 2.0 };
|
static struct filter BICUBIC = { bicubic_filter, 2.0 };
|
||||||
|
|
||||||
Imaging
|
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
|
/* FIXME: this is a quick and straightforward translation from a
|
||||||
python prototype. might need some further C-ification... */
|
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)
|
if (!imOut || !imIn || strcmp(imIn->mode, imOut->mode) != 0)
|
||||||
return (Imaging) ImagingError_ModeError();
|
return (Imaging) ImagingError_ModeError();
|
||||||
|
|
||||||
if (strcmp(imIn->mode, "P") == 0 || strcmp(imIn->mode, "1") == 0)
|
|
||||||
return (Imaging) ImagingError_ModeError();
|
|
||||||
|
|
||||||
/* check filter */
|
/* check filter */
|
||||||
switch (filter) {
|
switch (filter) {
|
||||||
case IMAGING_TRANSFORM_NEAREST:
|
case IMAGING_TRANSFORM_NEAREST:
|
||||||
|
@ -305,3 +302,39 @@ ImagingStretch(Imaging imOut, Imaging imIn, int filter)
|
||||||
|
|
||||||
return imOut;
|
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