From c8471bcbda68b7d7bd4542bce1da9c21e1aec07d Mon Sep 17 00:00:00 2001 From: homm Date: Sat, 25 Oct 2014 05:03:27 +0400 Subject: [PATCH] Hide stretch implementation detail in Antialias.c --- _imaging.c | 25 ++----------------------- libImaging/Antialias.c | 41 +++++++++++++++++++++++++++++++++++++---- 2 files changed, 39 insertions(+), 27 deletions(-) diff --git a/_imaging.c b/_imaging.c index 4eb878cf7..6cddd913b 100644 --- a/_imaging.c +++ b/_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); } diff --git a/libImaging/Antialias.c b/libImaging/Antialias.c index be49bc827..fc084e952 100644 --- a/libImaging/Antialias.c +++ b/libImaging/Antialias.c @@ -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; +}