mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-07-10 08:12:33 +03:00
divide coefficients before applying
This commit is contained in:
parent
e0f69cb2e1
commit
b6638d8155
|
@ -836,7 +836,7 @@ _filter(ImagingObject* self, PyObject* args)
|
||||||
Py_ssize_t kernelsize;
|
Py_ssize_t kernelsize;
|
||||||
FLOAT32* kerneldata;
|
FLOAT32* kerneldata;
|
||||||
|
|
||||||
int xsize, ysize;
|
int xsize, ysize, i;
|
||||||
float divisor, offset;
|
float divisor, offset;
|
||||||
PyObject* kernel = NULL;
|
PyObject* kernel = NULL;
|
||||||
if (!PyArg_ParseTuple(args, "(ii)ffO", &xsize, &ysize,
|
if (!PyArg_ParseTuple(args, "(ii)ffO", &xsize, &ysize,
|
||||||
|
@ -852,8 +852,12 @@ _filter(ImagingObject* self, PyObject* args)
|
||||||
return ImagingError_ValueError("bad kernel size");
|
return ImagingError_ValueError("bad kernel size");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for (i = 0; i < kernelsize; ++i) {
|
||||||
|
kerneldata[i] /= divisor;
|
||||||
|
}
|
||||||
|
|
||||||
imOut = PyImagingNew(
|
imOut = PyImagingNew(
|
||||||
ImagingFilter(self->image, xsize, ysize, kerneldata, offset, divisor)
|
ImagingFilter(self->image, xsize, ysize, kerneldata, offset)
|
||||||
);
|
);
|
||||||
|
|
||||||
free(kerneldata);
|
free(kerneldata);
|
||||||
|
|
|
@ -73,7 +73,7 @@ ImagingExpand(Imaging imIn, int xmargin, int ymargin, int mode)
|
||||||
|
|
||||||
Imaging
|
Imaging
|
||||||
ImagingFilter(Imaging im, int xsize, int ysize, const FLOAT32* kernel,
|
ImagingFilter(Imaging im, int xsize, int ysize, const FLOAT32* kernel,
|
||||||
FLOAT32 offset, FLOAT32 divisor)
|
FLOAT32 offset)
|
||||||
{
|
{
|
||||||
Imaging imOut;
|
Imaging imOut;
|
||||||
int x, y;
|
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++) {
|
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) + 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)
|
||||||
|
@ -159,7 +159,7 @@ ImagingFilter(Imaging im, int xsize, int ysize, const FLOAT32* kernel,
|
||||||
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) + 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)
|
||||||
|
|
|
@ -261,7 +261,7 @@ extern Imaging ImagingFillLinearGradient(const char* mode);
|
||||||
extern Imaging ImagingFillRadialGradient(const char* mode);
|
extern Imaging ImagingFillRadialGradient(const char* mode);
|
||||||
extern Imaging ImagingFilter(
|
extern Imaging ImagingFilter(
|
||||||
Imaging im, int xsize, int ysize, const FLOAT32* kernel,
|
Imaging im, int xsize, int ysize, const FLOAT32* kernel,
|
||||||
FLOAT32 offset, FLOAT32 divisor);
|
FLOAT32 offset);
|
||||||
extern Imaging ImagingFlipLeftRight(Imaging imOut, Imaging imIn);
|
extern Imaging ImagingFlipLeftRight(Imaging imOut, Imaging imIn);
|
||||||
extern Imaging ImagingFlipTopBottom(Imaging imOut, Imaging imIn);
|
extern Imaging ImagingFlipTopBottom(Imaging imOut, Imaging imIn);
|
||||||
extern Imaging ImagingGaussianBlur(Imaging imOut, Imaging imIn, float radius,
|
extern Imaging ImagingGaussianBlur(Imaging imOut, Imaging imIn, float radius,
|
||||||
|
|
Loading…
Reference in New Issue
Block a user