From 335f5431dea185ccd1b28f9cca4ef0ab042f87b0 Mon Sep 17 00:00:00 2001 From: Alexander Date: Sun, 24 Nov 2019 04:13:48 +0300 Subject: [PATCH] dummy method --- setup.py | 1 + src/PIL/Image.py | 16 ++++++++++++++++ src/_imaging.c | 25 ++++++++++++++++++++++++- src/libImaging/Imaging.h | 1 + src/libImaging/Reduce.c | 16 ++++++++++++++++ 5 files changed, 58 insertions(+), 1 deletion(-) create mode 100644 src/libImaging/Reduce.c diff --git a/setup.py b/setup.py index 76bdfb159..468f5d48a 100755 --- a/setup.py +++ b/setup.py @@ -39,6 +39,7 @@ _LIB_IMAGING = ( "Access", "AlphaComposite", "Resample", + "Reduce", "Bands", "BcnDecode", "BitDecode", diff --git a/src/PIL/Image.py b/src/PIL/Image.py index 0cdfcc9a9..ae683de3a 100644 --- a/src/PIL/Image.py +++ b/src/PIL/Image.py @@ -1887,6 +1887,22 @@ class Image(object): return self._new(self.im.resize(size, resample, box)) + def reduce(self, factor): + """ + Returns reduced in `factor` times copy of the image. + If the size of the image is not dividable by the `factor`, + the resulting size will be rounded up. + + :param factor: A greater than 0 integer or tuple of two integers + for width and height separately. + """ + if not isinstance(factor, (list, tuple)): + factor = (factor, factor) + + self.load() + + return self._new(self.im.reduce(factor)) + def rotate( self, angle, diff --git a/src/_imaging.c b/src/_imaging.c index 04520b1a1..f54e44522 100644 --- a/src/_imaging.c +++ b/src/_imaging.c @@ -1829,6 +1829,28 @@ _resize(ImagingObject* self, PyObject* args) return PyImagingNew(imOut); } +static PyObject* +_reduce(ImagingObject* self, PyObject* args) +{ + Imaging imIn; + Imaging imOut; + + int xscale, yscale; + + imIn = self->image; + + if (!PyArg_ParseTuple(args, "(ii)", &xscale, &yscale)) + return NULL; + + if (xscale < 1 || yscale < 1) { + return ImagingError_ValueError("scale must be > 0"); + } + + imOut = ImagingReduce(imIn, xscale, yscale); + + return PyImagingNew(imOut); +} + #define IS_RGB(mode)\ (!strcmp(mode, "RGB") || !strcmp(mode, "RGBA") || !strcmp(mode, "RGBX")) @@ -1843,7 +1865,7 @@ im_setmode(ImagingObject* self, PyObject* args) char* mode; Py_ssize_t modelen; if (!PyArg_ParseTuple(args, "s#:setmode", &mode, &modelen)) - return NULL; + return NULL; im = self->image; @@ -3277,6 +3299,7 @@ static struct PyMethodDef methods[] = { {"rankfilter", (PyCFunction)_rankfilter, 1}, #endif {"resize", (PyCFunction)_resize, 1}, + {"reduce", (PyCFunction)_reduce, 1}, {"transpose", (PyCFunction)_transpose, 1}, {"transform2", (PyCFunction)_transform2, 1}, diff --git a/src/libImaging/Imaging.h b/src/libImaging/Imaging.h index 25c15e758..eee20cf6e 100644 --- a/src/libImaging/Imaging.h +++ b/src/libImaging/Imaging.h @@ -313,6 +313,7 @@ extern Imaging ImagingRotate270(Imaging imOut, Imaging imIn); extern Imaging ImagingTranspose(Imaging imOut, Imaging imIn); extern Imaging ImagingTransverse(Imaging imOut, Imaging imIn); extern Imaging ImagingResample(Imaging imIn, int xsize, int ysize, int filter, float box[4]); +extern Imaging ImagingReduce(Imaging imIn, int xscale, int yscale); extern Imaging ImagingTransform( Imaging imOut, Imaging imIn, int method, int x0, int y0, int x1, int y1, double *a, int filter, int fill); diff --git a/src/libImaging/Reduce.c b/src/libImaging/Reduce.c new file mode 100644 index 000000000..c8681d463 --- /dev/null +++ b/src/libImaging/Reduce.c @@ -0,0 +1,16 @@ +#include "Imaging.h" + +#include + +#define ROUND_UP(f) ((int) ((f) >= 0.0 ? (f) + 0.5F : (f) - 0.5F)) + + +Imaging +ImagingReduce(Imaging imIn, int xscale, int yscale) +{ + Imaging imOut = NULL; + + imOut = ImagingNewDirty(imIn->mode, imIn->xsize, imIn->ysize); + + return imOut; +}