use generic fallback implementation to copy QImage to and from XImage in case of depth mismatch

Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
This commit is contained in:
Ivailo Monev 2021-12-29 08:22:23 +02:00
parent e0f38d149b
commit 429afda051

View file

@ -89,9 +89,10 @@ void QX11Data::copyQImageToXImage(const QImage &image, XImage *ximage)
ximage->data = static_cast<char*>(::malloc(size_t(ximage->bytes_per_line) * image.height()));
Q_CHECK_PTR(ximage->data);
bool checkbyteorder = true;
const int w = image.width();
const int h = image.height();
if (ximage->bits_per_pixel == image.depth()) {
switch(image.format()) {
case QImage::Format_RGB32: {
uint *xidata = (uint *)ximage->data;
@ -128,19 +129,18 @@ void QX11Data::copyQImageToXImage(const QImage &image, XImage *ximage)
::memcpy(ximage->data, image.constBits(), image.byteCount());
break;
}
default: {
checkbyteorder = false;
}
return;
}
for (int h = 0; h < image.height(); h++) {
for (int w = 0; w < image.width(); w++) {
const QRgb pixel = image.pixel(w, h);
XPutPixel(ximage, w, h, pixel);
}
}
break;
}
}
if (checkbyteorder && (ximage->byte_order == MSBFirst) != (Q_BYTE_ORDER == Q_BIG_ENDIAN)) {
if ((ximage->byte_order == MSBFirst) != (Q_BYTE_ORDER == Q_BIG_ENDIAN)) {
uint *xidata = (uint *)ximage->data;
uint *xiend = xidata + w*h;
while (xidata < xiend) {
@ -159,6 +159,7 @@ void QX11Data::copyXImageToQImage(XImage *ximage, QImage &image)
Q_ASSERT(ximage->width == image.width());
Q_ASSERT(ximage->height == image.height());
if (ximage->bits_per_pixel == image.depth()) {
switch (image.format()) {
case QImage::Format_RGB32: {
uchar *imagedata = image.bits();
@ -193,22 +194,22 @@ void QX11Data::copyXImageToQImage(XImage *ximage, QImage &image)
for (int h = 0; h < ximage->height; h++) {
uchar* imageline = QFAST_SCAN_LINE(imagedata, imagebpl, h);
for (int w = 0; w < ximage->width; w++) {
const quint32 xpixel = XGetPixel(ximage, w, h);
((quint16 *)imageline)[w] = qt_colorConvert<quint16, quint32>(xpixel, 0);
const quint16 xpixel = XGetPixel(ximage, w, h);
((quint16 *)imageline)[w] = xpixel;
}
}
break;
}
default: {
}
return;
}
for (int h = 0; h < ximage->height; h++) {
for (int w = 0; w < ximage->width; w++) {
const uint xpixel = XGetPixel(ximage, w, h);
image.setPixel(w, h, xpixel);
}
}
break;
}
}
}
void QX11Data::copyXImageToQImageWithMask(XImage *ximage, QImage &image, const QImage &mask)