mirror of
https://github.com/python-pillow/Pillow.git
synced 2024-12-27 10:26:19 +03:00
Merge pull request #2670 from uploadcare/threaded-filter
Release GIL in filters
This commit is contained in:
commit
bbe07d4f49
|
@ -31,6 +31,7 @@ ImagingExpand(Imaging imIn, int xmargin, int ymargin, int mode)
|
||||||
{
|
{
|
||||||
Imaging imOut;
|
Imaging imOut;
|
||||||
int x, y;
|
int x, y;
|
||||||
|
ImagingSectionCookie cookie;
|
||||||
|
|
||||||
if (xmargin < 0 && ymargin < 0)
|
if (xmargin < 0 && ymargin < 0)
|
||||||
return (Imaging) ImagingError_ValueError("bad kernel size");
|
return (Imaging) ImagingError_ValueError("bad kernel size");
|
||||||
|
@ -60,11 +61,13 @@ ImagingExpand(Imaging imIn, int xmargin, int ymargin, int mode)
|
||||||
EXPAND_LINE(type, image, imIn->ysize-1, ymargin+imIn->ysize+y);\
|
EXPAND_LINE(type, image, imIn->ysize-1, ymargin+imIn->ysize+y);\
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ImagingSectionEnter(&cookie);
|
||||||
if (imIn->image8) {
|
if (imIn->image8) {
|
||||||
EXPAND(UINT8, image8);
|
EXPAND(UINT8, image8);
|
||||||
} else {
|
} else {
|
||||||
EXPAND(INT32, image32);
|
EXPAND(INT32, image32);
|
||||||
}
|
}
|
||||||
|
ImagingSectionLeave(&cookie);
|
||||||
|
|
||||||
ImagingCopyInfo(imOut, imIn);
|
ImagingCopyInfo(imOut, imIn);
|
||||||
|
|
||||||
|
@ -78,6 +81,7 @@ ImagingFilter(Imaging im, int xsize, int ysize, const FLOAT32* kernel,
|
||||||
Imaging imOut;
|
Imaging imOut;
|
||||||
int x, y;
|
int x, y;
|
||||||
FLOAT32 sum;
|
FLOAT32 sum;
|
||||||
|
ImagingSectionCookie cookie;
|
||||||
|
|
||||||
if (!im || strcmp(im->mode, "L") != 0)
|
if (!im || strcmp(im->mode, "L") != 0)
|
||||||
return (Imaging) ImagingError_ModeError();
|
return (Imaging) ImagingError_ModeError();
|
||||||
|
@ -134,6 +138,7 @@ ImagingFilter(Imaging im, int xsize, int ysize, const FLOAT32* kernel,
|
||||||
(int) image[y-2][x+d] * kernel[23] + \
|
(int) image[y-2][x+d] * kernel[23] + \
|
||||||
(int) image[y-2][x+d+d] * kernel[24])
|
(int) image[y-2][x+d+d] * kernel[24])
|
||||||
|
|
||||||
|
ImagingSectionEnter(&cookie);
|
||||||
if (xsize == 3) {
|
if (xsize == 3) {
|
||||||
/* 3x3 kernel. */
|
/* 3x3 kernel. */
|
||||||
for (x = 0; x < im->xsize; x++)
|
for (x = 0; x < im->xsize; x++)
|
||||||
|
@ -177,6 +182,7 @@ ImagingFilter(Imaging im, int xsize, int ysize, const FLOAT32* kernel,
|
||||||
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];
|
||||||
}
|
}
|
||||||
|
ImagingSectionLeave(&cookie);
|
||||||
return imOut;
|
return imOut;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user