divide coefficients before applying

This commit is contained in:
Alexander 2017-08-07 01:11:05 +03:00
parent e0f69cb2e1
commit b6638d8155
3 changed files with 10 additions and 6 deletions

View File

@ -836,7 +836,7 @@ _filter(ImagingObject* self, PyObject* args)
Py_ssize_t kernelsize;
FLOAT32* kerneldata;
int xsize, ysize;
int xsize, ysize, i;
float divisor, offset;
PyObject* kernel = NULL;
if (!PyArg_ParseTuple(args, "(ii)ffO", &xsize, &ysize,
@ -852,8 +852,12 @@ _filter(ImagingObject* self, PyObject* args)
return ImagingError_ValueError("bad kernel size");
}
for (i = 0; i < kernelsize; ++i) {
kerneldata[i] /= divisor;
}
imOut = PyImagingNew(
ImagingFilter(self->image, xsize, ysize, kerneldata, offset, divisor)
ImagingFilter(self->image, xsize, ysize, kerneldata, offset)
);
free(kerneldata);

View File

@ -73,7 +73,7 @@ ImagingExpand(Imaging imIn, int xmargin, int ymargin, int mode)
Imaging
ImagingFilter(Imaging im, int xsize, int ysize, const FLOAT32* kernel,
FLOAT32 offset, FLOAT32 divisor)
FLOAT32 offset)
{
Imaging imOut;
int x, y;
@ -138,7 +138,7 @@ ImagingFilter(Imaging im, int xsize, int ysize, const FLOAT32* kernel,
for (y = 1; y < im->ysize-1; y++) {
imOut->image[y][0] = im->image8[y][0];
for (x = 1; x < im->xsize-1; x++) {
sum = KERNEL3x3(im->image8, kernel, 1) / divisor + offset;
sum = KERNEL3x3(im->image8, kernel, 1) + offset;
if (sum <= 0)
imOut->image8[y][x] = 0;
else if (sum >= 255)
@ -159,7 +159,7 @@ ImagingFilter(Imaging im, int xsize, int ysize, const FLOAT32* kernel,
for (x = 0; x < 2; x++)
imOut->image8[y][x] = im->image8[y][x];
for (; x < im->xsize-2; x++) {
sum = KERNEL5x5(im->image8, kernel, 1) / divisor + offset;
sum = KERNEL5x5(im->image8, kernel, 1) + offset;
if (sum <= 0)
imOut->image8[y][x] = 0;
else if (sum >= 255)

View File

@ -261,7 +261,7 @@ extern Imaging ImagingFillLinearGradient(const char* mode);
extern Imaging ImagingFillRadialGradient(const char* mode);
extern Imaging ImagingFilter(
Imaging im, int xsize, int ysize, const FLOAT32* kernel,
FLOAT32 offset, FLOAT32 divisor);
FLOAT32 offset);
extern Imaging ImagingFlipLeftRight(Imaging imOut, Imaging imIn);
extern Imaging ImagingFlipTopBottom(Imaging imOut, Imaging imIn);
extern Imaging ImagingGaussianBlur(Imaging imOut, Imaging imIn, float radius,