noop core.merge

This commit is contained in:
Alexander 2017-08-12 19:08:07 +03:00
parent 5f5ac09158
commit 91b08b7daa
4 changed files with 67 additions and 5 deletions

View File

@ -2612,11 +2612,9 @@ def merge(mode, bands):
raise ValueError("mode mismatch")
if im.size != bands[0].size:
raise ValueError("size mismatch")
im = core.new(mode, bands[0].size)
for i in range(getmodebands(mode)):
bands[i].load()
im.putband(bands[i].im, i)
return bands[0]._new(im)
for band in bands:
band.load()
return bands[0]._new(core.merge(mode, *[b.im for b in bands]))
# --------------------------------------------------------------------

View File

@ -1905,6 +1905,29 @@ _putband(ImagingObject* self, PyObject* args)
return Py_None;
}
static PyObject*
_merge(PyObject* self, PyObject* args)
{
char* mode;
ImagingObject *band0 = NULL;
ImagingObject *band1 = NULL;
ImagingObject *band2 = NULL;
ImagingObject *band3 = NULL;
Imaging bands[4] = {NULL, NULL, NULL, NULL};
if (!PyArg_ParseTuple(args, "sO!|O!O!O!", &mode,
&Imaging_Type, &band0, &Imaging_Type, &band1,
&Imaging_Type, &band2, &Imaging_Type, &band3))
return NULL;
if (band0) bands[0] = band0->image;
if (band1) bands[1] = band1->image;
if (band2) bands[2] = band2->image;
if (band3) bands[3] = band3->image;
return PyImagingNew(ImagingMerge(mode, bands));
}
/* -------------------------------------------------------------------- */
#ifdef WITH_IMAGECHOPS
@ -3316,6 +3339,7 @@ static PyMethodDef functions[] = {
{"blend", (PyCFunction)_blend, 1},
{"fill", (PyCFunction)_fill, 1},
{"new", (PyCFunction)_new, 1},
{"merge", (PyCFunction)_merge, 1},
{"getcount", (PyCFunction)_getcount, 1},

View File

@ -127,3 +127,42 @@ ImagingFillBand(Imaging imOut, int band, int color)
return imOut;
}
Imaging
ImagingMerge(const char* mode, Imaging bands[4])
{
int i;
int bandsCount = 0;
Imaging imOut;
Imaging firstBand;
firstBand = bands[0];
if ( ! firstBand) {
return (Imaging) ImagingError_ValueError("At least one band required");
}
for (i = 0; i < 4; ++i) {
if ( ! bands[i]) {
break;
}
if (bands[i]->bands != 1 || bands[i]->type != IMAGING_TYPE_UINT8) {
return (Imaging) ImagingError_ModeError();
}
if (bands[i]->xsize != firstBand->xsize
|| bands[i]->ysize != firstBand->ysize) {
return (Imaging) ImagingError_Mismatch();
}
}
bandsCount = i;
imOut = ImagingNew(mode, firstBand->xsize, firstBand->ysize);
if ( ! imOut)
return NULL;
if (imOut->bands != bandsCount) {
ImagingDelete(imOut);
return (Imaging) ImagingError_ValueError("wrong number of bands");
}
return imOut;
}

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 Imaging ImagingMerge(const char* mode, 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,