Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release Python GIL when converting images using matrix operations #6418

Merged
merged 1 commit into from Oct 25, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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