Skip to content

Commit

Permalink
XCB platform: Fix crash on X servers with BGR888 display
Browse files Browse the repository at this point in the history
If the native visual was BGR888, the XCB plugin would assert as soon as
it needed to find the corresponding QImage format. Fix by adding the
required mapping in qt_xcb_imageFormatForVisual().

Task-number: QTBUG-62840
Change-Id: Idd9eb01a60f605ad004d5b0c3025ded63ed64271
Reviewed-by: Allan Sandfeld Jensen <[email protected]>
  • Loading branch information
aavit committed Oct 6, 2017
1 parent 7f7d939 commit 248beda
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions src/plugins/platforms/xcb/qxcbimage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,16 @@ QImage::Format qt_xcb_imageFormatForVisual(QXcbConnection *connection, uint8_t d
&& visual->green_mask == 0xff00 && visual->blue_mask == 0xff)
return QImage::Format_RGB32;

if (QSysInfo::ByteOrder == QSysInfo::LittleEndian) {
if (depth == 24 && format->bits_per_pixel == 32 && visual->blue_mask == 0xff0000
&& visual->green_mask == 0xff00 && visual->red_mask == 0xff)
return QImage::Format_RGBX8888;
} else {
if (depth == 24 && format->bits_per_pixel == 32 && visual->blue_mask == 0xff00
&& visual->green_mask == 0xff0000 && visual->red_mask == 0xff000000)
return QImage::Format_RGBX8888;
}

if (depth == 16 && format->bits_per_pixel == 16 && visual->red_mask == 0xf800
&& visual->green_mask == 0x7e0 && visual->blue_mask == 0x1f)
return QImage::Format_RGB16;
Expand Down Expand Up @@ -128,8 +138,9 @@ QPixmap qt_xcb_pixmapFromXPixmap(QXcbConnection *connection, xcb_pixmap_t pixmap
}
break;
}
case QImage::Format_RGB32: // fall-through
case QImage::Format_ARGB32_Premultiplied: {
case QImage::Format_RGB32:
case QImage::Format_ARGB32_Premultiplied:
case QImage::Format_RGBX8888: {
uint *p = (uint*)image.scanLine(i);
uint *end = p + image.width();
while (p < end) {
Expand All @@ -146,7 +157,7 @@ QPixmap qt_xcb_pixmapFromXPixmap(QXcbConnection *connection, xcb_pixmap_t pixmap
}

// fix-up alpha channel
if (format == QImage::Format_RGB32) {
if (format == QImage::Format_RGB32 || format == QImage::Format_RGBX8888) {
QRgb *p = (QRgb *)image.bits();
for (int y = 0; y < height; ++y) {
for (int x = 0; x < width; ++x)
Expand Down

0 comments on commit 248beda

Please sign in to comment.