From ca75d63f3a67b2a05be23481ad6745ac1a5677af Mon Sep 17 00:00:00 2001 From: Alexander Date: Sat, 12 Aug 2017 10:13:23 +0300 Subject: [PATCH] ImagingSplit implementation --- libImaging/Bands.c | 57 +++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 56 insertions(+), 1 deletion(-) diff --git a/libImaging/Bands.c b/libImaging/Bands.c index 9614ebd2c..17e1e1f26 100644 --- a/libImaging/Bands.c +++ b/libImaging/Bands.c @@ -76,11 +76,66 @@ ImagingGetBand(Imaging imIn, int band) int ImagingSplit(Imaging imIn, Imaging bands[4]) { - int i; + int i, x, y; + + /* Check arguments */ + if (!imIn || imIn->type != IMAGING_TYPE_UINT8) { + (Imaging) ImagingError_ModeError(); + return 0; + } + + /* Shortcuts */ + if (imIn->bands == 1) { + bands[0] = ImagingCopy(imIn); + return imIn->bands; + } + for (i = 0; i < imIn->bands; i++) { bands[i] = ImagingNew("L", imIn->xsize, imIn->ysize); } + /* Extract bands from image */ + if (imIn->bands == 2) { + for (y = 0; y < imIn->ysize; y++) { + UINT8* in = (UINT8*) imIn->image[y]; + UINT8* out0 = bands[0]->image8[y]; + UINT8* out1 = bands[1]->image8[y]; + for (x = 0; x < imIn->xsize; x++) { + out0[x] = in[0]; + out1[x] = in[3]; + in += 4; + } + } + } else if (imIn->bands == 3) { + for (y = 0; y < imIn->ysize; y++) { + UINT8* in = (UINT8*) imIn->image[y]; + UINT8* out0 = bands[0]->image8[y]; + UINT8* out1 = bands[1]->image8[y]; + UINT8* out2 = bands[2]->image8[y]; + for (x = 0; x < imIn->xsize; x++) { + out0[x] = in[0]; + out1[x] = in[1]; + out2[x] = in[2]; + in += 4; + } + } + } else { + for (y = 0; y < imIn->ysize; y++) { + UINT8* in = (UINT8*) imIn->image[y]; + UINT8* out0 = bands[0]->image8[y]; + UINT8* out1 = bands[1]->image8[y]; + UINT8* out2 = bands[2]->image8[y]; + UINT8* out3 = bands[3]->image8[y]; + for (x = 0; x < imIn->xsize; x++) { + out0[x] = in[0]; + out1[x] = in[1]; + out2[x] = in[2]; + out3[x] = in[3]; + in += 4; + } + } + } + return imIn->bands; }