Skip to content

Commit

Permalink
Release the GIL when applying matrix conversion to images
Browse files Browse the repository at this point in the history
  • Loading branch information
hmaarrfk committed Jul 5, 2022
1 parent 9ac5a70 commit 02e90e2
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/libImaging/Matrix.c
Expand Up @@ -21,6 +21,7 @@ Imaging
ImagingConvertMatrix(Imaging im, const char *mode, float m[]) {
Imaging imOut;
int x, y;
ImagingSectionCookie cookie;

/* Assume there's enough data in the buffer */
if (!im) {
Expand All @@ -33,6 +34,7 @@ ImagingConvertMatrix(Imaging im, const char *mode, float m[]) {
return NULL;
}

ImagingSectionEnter(&cookie);
for (y = 0; y < im->ysize; y++) {
UINT8 *in = (UINT8 *)im->image[y];
UINT8 *out = (UINT8 *)imOut->image[y];
Expand All @@ -43,6 +45,7 @@ ImagingConvertMatrix(Imaging im, const char *mode, float m[]) {
in += 4;
}
}
ImagingSectionLeave(&cookie);

} else if (strlen(mode) == 3 && im->bands == 3) {
imOut = ImagingNewDirty(mode, im->xsize, im->ysize);
Expand All @@ -54,6 +57,7 @@ ImagingConvertMatrix(Imaging im, const char *mode, float m[]) {
UINT8 *in = (UINT8 *)im->image[y];
UINT8 *out = (UINT8 *)imOut->image[y];

ImagingSectionEnter(&cookie);
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 v1 = m[4] * in[0] + m[5] * in[1] + m[6] * in[2] + m[7] + 0.5;
Expand All @@ -64,6 +68,7 @@ ImagingConvertMatrix(Imaging im, const char *mode, float m[]) {
in += 4;
out += 4;
}
ImagingSectionLeave(&cookie);
}
} else {
return (Imaging)ImagingError_ModeError();
Expand Down

0 comments on commit 02e90e2

Please sign in to comment.