Add generic rb swap for RGB64 formats

Will also be needed by half-float formats.

Change-Id: Ia735b29b65287c63da5f1b5ec25428562d743800
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
This commit is contained in:
Allan Sandfeld Jensen 2020-12-04 11:38:06 +01:00
parent a3e5efa8a2
commit 2b9a8b8d69
2 changed files with 25 additions and 33 deletions

View File

@ -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<QRgba64 *>(res.scanLine(i));
const QRgba64 *p = reinterpret_cast<const QRgba64 *>(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<QRgba64 *>(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;

View File

@ -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<const ushort *>(s);
ushort *dest = reinterpret_cast<ushort *>(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<QImage::Format Format> 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