Hide stretch implementation detail in Antialias.c

This commit is contained in:
homm 2014-10-25 05:03:27 +04:00
parent 2d5b74f90a
commit c8471bcbda
2 changed files with 39 additions and 27 deletions

View File

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

View File

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