Merge pull request #2658 from uploadcare/fix-filter-module-indention

Fix Filter.c module indention
This commit is contained in:
Alexander Karpinsky 2017-08-07 00:59:53 +03:00 committed by GitHub
commit e0f69cb2e1

View File

@ -33,13 +33,13 @@ ImagingExpand(Imaging imIn, int xmargin, int ymargin, int mode)
int x, y; int x, y;
if (xmargin < 0 && ymargin < 0) if (xmargin < 0 && ymargin < 0)
return (Imaging) ImagingError_ValueError("bad kernel size"); return (Imaging) ImagingError_ValueError("bad kernel size");
imOut = ImagingNew( imOut = ImagingNew(
imIn->mode, imIn->xsize+2*xmargin, imIn->ysize+2*ymargin imIn->mode, imIn->xsize+2*xmargin, imIn->ysize+2*ymargin
); );
if (!imOut) if (!imOut)
return NULL; return NULL;
#define EXPAND_LINE(type, image, yin, yout) {\ #define EXPAND_LINE(type, image, yin, yout) {\
for (x = 0; x < xmargin; x++)\ for (x = 0; x < xmargin; x++)\
@ -61,9 +61,9 @@ ImagingExpand(Imaging imIn, int xmargin, int ymargin, int mode)
} }
if (imIn->image8) { if (imIn->image8) {
EXPAND(UINT8, image8); EXPAND(UINT8, image8);
} else { } else {
EXPAND(INT32, image32); EXPAND(INT32, image32);
} }
ImagingCopyInfo(imOut, imIn); ImagingCopyInfo(imOut, imIn);
@ -80,20 +80,20 @@ ImagingFilter(Imaging im, int xsize, int ysize, const FLOAT32* kernel,
FLOAT32 sum; FLOAT32 sum;
if (!im || strcmp(im->mode, "L") != 0) if (!im || strcmp(im->mode, "L") != 0)
return (Imaging) ImagingError_ModeError(); return (Imaging) ImagingError_ModeError();
if (im->xsize < xsize || im->ysize < ysize) if (im->xsize < xsize || im->ysize < ysize)
return ImagingCopy(im); return ImagingCopy(im);
if ((xsize != 3 && xsize != 5) || xsize != ysize) if ((xsize != 3 && xsize != 5) || xsize != ysize)
return (Imaging) ImagingError_ValueError("bad kernel size"); return (Imaging) ImagingError_ValueError("bad kernel size");
imOut = ImagingNew(im->mode, im->xsize, im->ysize); imOut = ImagingNew(im->mode, im->xsize, im->ysize);
if (!imOut) if (!imOut)
return NULL; return NULL;
/* brute force kernel implementations */ /* brute force kernel implementations */
#define KERNEL3x3(image, kernel, d) ( \ #define KERNEL3x3(image, kernel, d) ( \
(int) image[y+1][x-d] * kernel[0] + \ (int) image[y+1][x-d] * kernel[0] + \
(int) image[y+1][x] * kernel[1] + \ (int) image[y+1][x] * kernel[1] + \
(int) image[y+1][x+d] * kernel[2] + \ (int) image[y+1][x+d] * kernel[2] + \
@ -104,7 +104,7 @@ ImagingFilter(Imaging im, int xsize, int ysize, const FLOAT32* kernel,
(int) image[y-1][x] * kernel[7] + \ (int) image[y-1][x] * kernel[7] + \
(int) image[y-1][x+d] * kernel[8]) (int) image[y-1][x+d] * kernel[8])
#define KERNEL5x5(image, kernel, d) ( \ #define KERNEL5x5(image, kernel, d) ( \
(int) image[y+2][x-d-d] * kernel[0] + \ (int) image[y+2][x-d-d] * kernel[0] + \
(int) image[y+2][x-d] * kernel[1] + \ (int) image[y+2][x-d] * kernel[1] + \
(int) image[y+2][x] * kernel[2] + \ (int) image[y+2][x] * kernel[2] + \
@ -132,47 +132,47 @@ ImagingFilter(Imaging im, int xsize, int ysize, const FLOAT32* kernel,
(int) image[y-2][x+d+d] * kernel[24]) (int) image[y-2][x+d+d] * kernel[24])
if (xsize == 3) { if (xsize == 3) {
/* 3x3 kernel. */ /* 3x3 kernel. */
for (x = 0; x < im->xsize; x++) for (x = 0; x < im->xsize; x++)
imOut->image[0][x] = im->image8[0][x]; imOut->image[0][x] = im->image8[0][x];
for (y = 1; y < im->ysize-1; y++) { for (y = 1; y < im->ysize-1; y++) {
imOut->image[y][0] = im->image8[y][0]; imOut->image[y][0] = im->image8[y][0];
for (x = 1; x < im->xsize-1; x++) { for (x = 1; x < im->xsize-1; x++) {
sum = KERNEL3x3(im->image8, kernel, 1) / divisor + offset; sum = KERNEL3x3(im->image8, kernel, 1) / divisor + offset;
if (sum <= 0) if (sum <= 0)
imOut->image8[y][x] = 0; imOut->image8[y][x] = 0;
else if (sum >= 255) else if (sum >= 255)
imOut->image8[y][x] = 255; imOut->image8[y][x] = 255;
else else
imOut->image8[y][x] = (UINT8) sum; imOut->image8[y][x] = (UINT8) sum;
} }
imOut->image8[y][x] = im->image8[y][x]; imOut->image8[y][x] = im->image8[y][x];
} }
for (x = 0; x < im->xsize; x++) for (x = 0; x < im->xsize; x++)
imOut->image8[y][x] = im->image8[y][x]; imOut->image8[y][x] = im->image8[y][x];
} else { } else {
/* 5x5 kernel. */ /* 5x5 kernel. */
for (y = 0; y < 2; y++) for (y = 0; y < 2; y++)
for (x = 0; x < im->xsize; x++) for (x = 0; x < im->xsize; x++)
imOut->image8[y][x] = im->image8[y][x]; imOut->image8[y][x] = im->image8[y][x];
for (; y < im->ysize-2; y++) { for (; y < im->ysize-2; y++) {
for (x = 0; x < 2; x++) for (x = 0; x < 2; x++)
imOut->image8[y][x] = im->image8[y][x]; imOut->image8[y][x] = im->image8[y][x];
for (; x < im->xsize-2; x++) { for (; x < im->xsize-2; x++) {
sum = KERNEL5x5(im->image8, kernel, 1) / divisor + offset; sum = KERNEL5x5(im->image8, kernel, 1) / divisor + offset;
if (sum <= 0) if (sum <= 0)
imOut->image8[y][x] = 0; imOut->image8[y][x] = 0;
else if (sum >= 255) else if (sum >= 255)
imOut->image8[y][x] = 255; imOut->image8[y][x] = 255;
else else
imOut->image8[y][x] = (UINT8) sum; imOut->image8[y][x] = (UINT8) sum;
} }
for (; x < im->xsize; x++) for (; x < im->xsize; x++)
imOut->image8[y][x] = im->image8[y][x]; imOut->image8[y][x] = im->image8[y][x];
} }
for (; y < im->ysize; y++) for (; y < im->ysize; y++)
for (x = 0; x < im->xsize; x++) for (x = 0; x < im->xsize; x++)
imOut->image8[y][x] = im->image8[y][x]; imOut->image8[y][x] = im->image8[y][x];
} }
return imOut; return imOut;
} }