accept multiband images in filter (noop)

This commit is contained in:
Alexander 2017-08-13 00:03:50 +03:00
parent 55f153d999
commit b11bba108e
2 changed files with 32 additions and 23 deletions

View File

@ -1112,7 +1112,9 @@ class Image(object):
raise TypeError("filter argument should be ImageFilter.Filter " + raise TypeError("filter argument should be ImageFilter.Filter " +
"instance or class") "instance or class")
if self.im.bands == 1: multiband = getattr(filter, 'is_multiband', False)
if self.im.bands == 1 or multiband:
return self._new(filter.filter(self.im)) return self._new(filter.filter(self.im))
# fix to handle multiband images since _imaging doesn't # fix to handle multiband images since _imaging doesn't
ims = [] ims = []

View File

@ -100,21 +100,26 @@ ImagingFilter3x3(Imaging imOut, Imaging im, const float* kernel,
(UINT8) in_1[x] * kernel[7] + \ (UINT8) in_1[x] * kernel[7] + \
(UINT8) in_1[x+d] * kernel[8]) (UINT8) in_1[x+d] * kernel[8])
int x, y; int x, y = 0;
memcpy(imOut->image[0], im->image[0], im->linesize); memcpy(imOut->image[0], im->image[0], im->linesize);
for (y = 1; y < im->ysize-1; y++) { if (im->bands == 1) {
UINT8* in_1 = (UINT8*) im->image[y-1]; for (y = 1; y < im->ysize-1; y++) {
UINT8* in0 = (UINT8*) im->image[y]; UINT8* in_1 = (UINT8*) im->image[y-1];
UINT8* in1 = (UINT8*) im->image[y+1]; UINT8* in0 = (UINT8*) im->image[y];
UINT8* out = (UINT8*) imOut->image[y]; UINT8* in1 = (UINT8*) im->image[y+1];
UINT8* out = (UINT8*) imOut->image[y];
out[0] = in0[0]; out[0] = in0[0];
for (x = 1; x < im->xsize-1; x++) { for (x = 1; x < im->xsize-1; x++) {
float sum = KERNEL3x3(in_1, in, in1, kernel, 1) + offset; out[x] = clip8(KERNEL3x3(in_1, in, in1, kernel, 1) + offset);
out[x] = clip8(sum); }
} out[x] = in0[x];
out[x] = in0[x]; }
} else if (im->bands == 3) {
printf("%s\n", "hi there");
for (y = 1; y < im->ysize-1; y++) {
}
} }
memcpy(imOut->image[y], im->image[y], im->linesize); memcpy(imOut->image[y], im->image[y], im->linesize);
} }
@ -124,10 +129,10 @@ ImagingFilter(Imaging im, int xsize, int ysize, const FLOAT32* kernel,
FLOAT32 offset) FLOAT32 offset)
{ {
Imaging imOut; Imaging imOut;
int x, y; int x, y = 0;
ImagingSectionCookie cookie; ImagingSectionCookie cookie;
if (!im || strcmp(im->mode, "L") != 0) if ( ! im || im->type != IMAGING_TYPE_UINT8)
return (Imaging) ImagingError_ModeError(); return (Imaging) ImagingError_ModeError();
if (im->xsize < xsize || im->ysize < ysize) if (im->xsize < xsize || im->ysize < ysize)
@ -178,15 +183,17 @@ ImagingFilter(Imaging im, int xsize, int ysize, const FLOAT32* kernel,
/* 5x5 kernel. */ /* 5x5 kernel. */
memcpy(imOut->image[0], im->image[0], im->linesize); memcpy(imOut->image[0], im->image[0], im->linesize);
memcpy(imOut->image[1], im->image[1], im->linesize); memcpy(imOut->image[1], im->image[1], im->linesize);
for (y = 2; y < im->ysize-2; y++) { if (im->bands == 1) {
for (x = 0; x < 2; x++) for (y = 2; y < im->ysize-2; y++) {
imOut->image8[y][x] = im->image8[y][x]; for (x = 0; x < 2; x++)
for (; x < im->xsize-2; x++) { imOut->image8[y][x] = im->image8[y][x];
float sum = KERNEL5x5(im->image8, kernel, 1) + offset; for (; x < im->xsize-2; x++) {
imOut->image8[y][x] = clip8(sum); float sum = KERNEL5x5(im->image8, kernel, 1) + offset;
imOut->image8[y][x] = clip8(sum);
}
for (; x < im->xsize; x++)
imOut->image8[y][x] = im->image8[y][x];
} }
for (; x < im->xsize; x++)
imOut->image8[y][x] = im->image8[y][x];
} }
memcpy(imOut->image[y], im->image[y], im->linesize); memcpy(imOut->image[y], im->image[y], im->linesize);
memcpy(imOut->image[y+1], im->image[y+1], im->linesize); memcpy(imOut->image[y+1], im->image[y+1], im->linesize);