im.split method

ImagingSplit function without implementation
This commit is contained in:
Alexander 2017-08-12 03:43:19 +03:00
parent c23b65c670
commit 559836d97d
4 changed files with 42 additions and 3 deletions

View File

@ -1954,9 +1954,7 @@ class Image(object):
if self.im.bands == 1:
ims = [self.copy()]
else:
ims = []
for i in range(self.im.bands):
ims.append(self._new(self.im.getband(i)))
ims = map(self._new, self.im.split())
return tuple(ims)
def tell(self):

View File

@ -1905,6 +1905,32 @@ _putband(ImagingObject* self, PyObject* args)
return Py_None;
}
static PyObject*
_split(ImagingObject* self, PyObject* args)
{
int fails = 0;
Py_ssize_t i;
PyObject* list;
PyObject* imaging_object;
Imaging bands[4] = {NULL, NULL, NULL, NULL};
if ( ! ImagingSplit(self->image, bands))
return NULL;
list = PyTuple_New(self->image->bands);
for (i = 0; i < self->image->bands; i++) {
imaging_object = PyImagingNew(bands[i]);
if ( ! imaging_object)
fails += 1;
PyTuple_SET_ITEM(list, i, imaging_object);
}
if (fails) {
Py_DECREF(list);
list = NULL;
}
return list;
}
/* -------------------------------------------------------------------- */
#ifdef WITH_IMAGECHOPS
@ -2972,6 +2998,7 @@ static struct PyMethodDef methods[] = {
{"getband", (PyCFunction)_getband, 1},
{"putband", (PyCFunction)_putband, 1},
{"split", (PyCFunction)_split, 1},
{"fillband", (PyCFunction)_fillband, 1},
{"setmode", (PyCFunction)im_setmode, 1},

View File

@ -72,6 +72,19 @@ ImagingGetBand(Imaging imIn, int band)
return imOut;
}
int
ImagingSplit(Imaging imIn, Imaging bands[4])
{
int i;
for (i = 0; i < imIn->bands; i++) {
bands[i] = ImagingNew("L", imIn->xsize, imIn->ysize);
}
return imIn->bands;
}
Imaging
ImagingPutBand(Imaging imOut, Imaging imIn, int band)
{

View File

@ -267,6 +267,7 @@ extern Imaging ImagingFlipTopBottom(Imaging imOut, Imaging imIn);
extern Imaging ImagingGaussianBlur(Imaging imOut, Imaging imIn, float radius,
int passes);
extern Imaging ImagingGetBand(Imaging im, int band);
extern int ImagingSplit(Imaging im, Imaging bands[4]);
extern int ImagingGetBBox(Imaging im, int bbox[4]);
typedef struct { int x, y; INT32 count; INT32 pixel; } ImagingColorItem;
extern ImagingColorItem* ImagingGetColors(Imaging im, int maxcolors,