From 2b9a8b8d6973363d35b381bb5ec7e7ceb53cbae4 Mon Sep 17 00:00:00 2001 From: Allan Sandfeld Jensen Date: Fri, 4 Dec 2020 11:38:06 +0100 Subject: [PATCH] Add generic rb swap for RGB64 formats Will also be needed by half-float formats. Change-Id: Ia735b29b65287c63da5f1b5ec25428562d743800 Reviewed-by: Lars Knoll --- src/gui/image/qimage.cpp | 31 +------------------------------ src/gui/painting/qpixellayout.cpp | 27 ++++++++++++++++++++++++--- 2 files changed, 25 insertions(+), 33 deletions(-) diff --git a/src/gui/image/qimage.cpp b/src/gui/image/qimage.cpp index 70b958c177e..2787be53d09 100644 --- a/src/gui/image/qimage.cpp +++ b/src/gui/image/qimage.cpp @@ -3408,25 +3408,9 @@ QImage QImage::rgbSwapped_helper() const } } break; - case Format_RGBX64: - case Format_RGBA64: - case Format_RGBA64_Premultiplied: - res = QImage(d->width, d->height, d->format); - QIMAGE_SANITYCHECK_MEMORY(res); - for (int i = 0; i < d->height; i++) { - QRgba64 *q = reinterpret_cast(res.scanLine(i)); - const QRgba64 *p = reinterpret_cast(constScanLine(i)); - const QRgba64 *end = p + d->width; - while (p < end) { - QRgba64 c = *p; - *q = QRgba64::fromRgba64(c.blue(), c.green(), c.red(), c.alpha()); - p++; - q++; - } - } - break; default: res = QImage(d->width, d->height, d->format); + QIMAGE_SANITYCHECK_MEMORY(res); rgbSwapped_generic(d->width, d->height, this, &res, &qPixelLayouts[d->format]); break; } @@ -3520,19 +3504,6 @@ void QImage::rgbSwapped_inplace() } } break; - case Format_RGBX64: - case Format_RGBA64: - case Format_RGBA64_Premultiplied: - for (int i = 0; i < d->height; i++) { - QRgba64 *p = reinterpret_cast(scanLine(i)); - QRgba64 *end = p + d->width; - while (p < end) { - QRgba64 c = *p; - *p = QRgba64::fromRgba64(c.blue(), c.green(), c.red(), c.alpha()); - p++; - } - } - break; default: rgbSwapped_generic(d->width, d->height, this, this, &qPixelLayouts[d->format]); break; diff --git a/src/gui/painting/qpixellayout.cpp b/src/gui/painting/qpixellayout.cpp index 0b1e736ec86..3bc0d3333dd 100644 --- a/src/gui/painting/qpixellayout.cpp +++ b/src/gui/painting/qpixellayout.cpp @@ -568,6 +568,27 @@ static void QT_FASTCALL rbSwap_rgb30(uchar *d, const uchar *s, int count) UNALIASED_CONVERSION_LOOP(dest, src, count, qRgbSwapRgb30); } +static void QT_FASTCALL rbSwap_4x16(uchar *d, const uchar *s, int count) +{ + const ushort *src = reinterpret_cast(s); + ushort *dest = reinterpret_cast(d); + if (src != dest) { + for (int i = 0; i < count; ++i) { + dest[i * 4 + 0] = src[i * 4 + 2]; + dest[i * 4 + 1] = src[i * 4 + 1]; + dest[i * 4 + 2] = src[i * 4 + 0]; + dest[i * 4 + 3] = src[i * 4 + 3]; + } + } else { + for (int i = 0; i < count; ++i) { + const ushort r = src[i * 4 + 0]; + const ushort b = src[i * 4 + 2]; + dest[i * 4 + 0] = b; + dest[i * 4 + 2] = r; + } + } +} + template constexpr static inline QPixelLayout pixelLayoutRGB() { return QPixelLayout{ @@ -1405,15 +1426,15 @@ QPixelLayout qPixelLayouts[QImage::NImageFormats] = { convertGrayscale8ToRGB32, convertGrayscale8ToRGB64, fetchGrayscale8ToRGB32, fetchGrayscale8ToRGB64, storeGrayscale8FromARGB32PM, storeGrayscale8FromRGB32 }, // Format_Grayscale8 - { false, false, QPixelLayout::BPP64, nullptr, + { false, false, QPixelLayout::BPP64, rbSwap_4x16, convertPassThrough, nullptr, fetchRGB64ToRGB32, fetchPassThrough64, storeRGB64FromRGB32, storeRGB64FromRGB32 }, // Format_RGBX64 - { true, false, QPixelLayout::BPP64, nullptr, + { true, false, QPixelLayout::BPP64, rbSwap_4x16, convertARGB32ToARGB32PM, nullptr, fetchRGBA64ToARGB32PM, fetchRGBA64ToRGBA64PM, storeRGBA64FromARGB32PM, storeRGB64FromRGB32 }, // Format_RGBA64 - { true, true, QPixelLayout::BPP64, nullptr, + { true, true, QPixelLayout::BPP64, rbSwap_4x16, convertPassThrough, nullptr, fetchRGB64ToRGB32, fetchPassThrough64, storeRGB64FromRGB32, storeRGB64FromRGB32 }, // Format_RGBA64_Premultiplied