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

Conversation

radarhere
Copy link
Member

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 minimized.

@hugovk hugovk merged commit 4c297ec into python-pillow:master Mar 14, 2021
@radarhere radarhere deleted the rgb branch March 14, 2021 10:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Qt Qt for Python, PyQt, PySide
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ImageQt does not work as expected in PyQt5
3 participants