diff --git a/src/PlatformBackends/X11ImageGrabber.cpp b/src/PlatformBackends/X11ImageGrabber.cpp --- a/src/PlatformBackends/X11ImageGrabber.cpp +++ b/src/PlatformBackends/X11ImageGrabber.cpp @@ -194,8 +194,22 @@ // The RGB32 format requires data format 0xffRRGGBB, ensure that this fourth byte really is 0xff if (format == QImage::Format_RGB32) { quint32 *data = reinterpret_cast(xcbImage->data); - for (int i = 0; i < xcbImage->width * xcbImage->height; i++) { - data[i] |= 0xff000000; + + const auto imageSize = xcbImage->width * xcbImage->height; + + bool sanitationNeeded = false; + // Check the first 1000 pixels. If they don't have any bogus alpha values, assume the entire image to be sane. + for (int i = 0; i < qMin(1000, imageSize); ++i) { + if (data[i] != (data[i] | 0xff000000)) { + sanitationNeeded = true; + break; + } + } + + if (sanitationNeeded) { + for (int i = 0; i < imageSize; ++i) { + data[i] |= 0xff000000; + } } }