dummy method

This commit is contained in:
Alexander 2019-11-24 04:13:48 +03:00
parent 8a30d13537
commit 335f5431de
5 changed files with 58 additions and 1 deletions

View File

@ -39,6 +39,7 @@ _LIB_IMAGING = (
"Access",
"AlphaComposite",
"Resample",
"Reduce",
"Bands",
"BcnDecode",
"BitDecode",

View File

@ -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,

View File

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

View File

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

16
src/libImaging/Reduce.c Normal file
View File

@ -0,0 +1,16 @@
#include "Imaging.h"
#include <math.h>
#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;
}