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

Moved RGB fix inside ImageQt class #5268

Merged
merged 1 commit into from Mar 14, 2021
Merged

Moved RGB fix inside ImageQt class #5268

merged 1 commit into from Mar 14, 2021

Conversation

@radarhere
Copy link
Member

@radarhere radarhere commented Feb 16, 2021

Resolves #5266. A workaround suggested in that issue is to change the user code. This PR causes the original code mentioned there to work.

Pillow/src/PIL/ImageQt.py

Lines 203 to 205 in fdd8b68

# Fix some strange bug that causes
if im.mode == "RGB":
im = im.convert("RGBA")

This 'strange bug' is because at https://doc.qt.io/qt-5/qimage.html

QImage::Format_RGB32... is stored using a 32-bit RGB format (0xffRRGGBB).

QImage is expecting the 4th channel to be populated with 0xff (255). Calling convert("RGBA") in Pillow does this.

static void
rgb2rgba(UINT8 *out, const UINT8 *in, int xsize) {
int x;
for (x = 0; x < xsize; x++) {
*out++ = *in++;
*out++ = *in++;
*out++ = *in++;
*out++ = 255;
in++;
}
}

Without 255 values, as seen in the issue, the display in Qt is very washed out.

This PR just documents the fix slightly better, and moves it from toqpixmap() to _toqclass_helper(), so that it is also run when calling the ImageQt.ImageQt class (toqixmap() still works, since toqpixmap() calls toqimage(), which returns an instance of the ImageQt.ImageQt class).

@nulano

This comment has been hidden.

@radarhere radarhere force-pushed the rgb branch 5 times, most recently from 3c4eb4e to 6f33a74 Feb 21, 2021
@hugovk hugovk merged commit 4c297ec into python-pillow:master Mar 14, 2021
48 of 50 checks passed
@radarhere radarhere deleted the rgb branch Mar 14, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

3 participants