Release the GIL when applying matrix conversion to images

This commit is contained in:
Mark Harfouche 2022-07-05 15:13:39 -04:00
parent 9ac5a70f9e
commit 02e90e21f4

View File

@ -21,6 +21,7 @@ Imaging
ImagingConvertMatrix(Imaging im, const char *mode, float m[]) { ImagingConvertMatrix(Imaging im, const char *mode, float m[]) {
Imaging imOut; Imaging imOut;
int x, y; int x, y;
ImagingSectionCookie cookie;
/* Assume there's enough data in the buffer */ /* Assume there's enough data in the buffer */
if (!im) { if (!im) {
@ -33,6 +34,7 @@ ImagingConvertMatrix(Imaging im, const char *mode, float m[]) {
return NULL; return NULL;
} }
ImagingSectionEnter(&cookie);
for (y = 0; y < im->ysize; y++) { for (y = 0; y < im->ysize; y++) {
UINT8 *in = (UINT8 *)im->image[y]; UINT8 *in = (UINT8 *)im->image[y];
UINT8 *out = (UINT8 *)imOut->image[y]; UINT8 *out = (UINT8 *)imOut->image[y];
@ -43,6 +45,7 @@ ImagingConvertMatrix(Imaging im, const char *mode, float m[]) {
in += 4; in += 4;
} }
} }
ImagingSectionLeave(&cookie);
} else if (strlen(mode) == 3 && im->bands == 3) { } else if (strlen(mode) == 3 && im->bands == 3) {
imOut = ImagingNewDirty(mode, im->xsize, im->ysize); imOut = ImagingNewDirty(mode, im->xsize, im->ysize);
@ -54,6 +57,7 @@ ImagingConvertMatrix(Imaging im, const char *mode, float m[]) {
UINT8 *in = (UINT8 *)im->image[y]; UINT8 *in = (UINT8 *)im->image[y];
UINT8 *out = (UINT8 *)imOut->image[y]; UINT8 *out = (UINT8 *)imOut->image[y];
ImagingSectionEnter(&cookie);
for (x = 0; x < im->xsize; x++) { for (x = 0; x < im->xsize; x++) {
float v0 = m[0] * in[0] + m[1] * in[1] + m[2] * in[2] + m[3] + 0.5; float v0 = m[0] * in[0] + m[1] * in[1] + m[2] * in[2] + m[3] + 0.5;
float v1 = m[4] * in[0] + m[5] * in[1] + m[6] * in[2] + m[7] + 0.5; float v1 = m[4] * in[0] + m[5] * in[1] + m[6] * in[2] + m[7] + 0.5;
@ -64,6 +68,7 @@ ImagingConvertMatrix(Imaging im, const char *mode, float m[]) {
in += 4; in += 4;
out += 4; out += 4;
} }
ImagingSectionLeave(&cookie);
} }
} else { } else {
return (Imaging)ImagingError_ModeError(); return (Imaging)ImagingError_ModeError();