| 1 | // Copyright (C) 2021 The Qt Company Ltd. |
| 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only |
| 3 | |
| 4 | #include <qglobal.h> |
| 5 | |
| 6 | #include "qdrawhelper_p.h" |
| 7 | #include "qpixellayout_p.h" |
| 8 | #include "qrgba64_p.h" |
| 9 | #include <QtCore/private/qsimd_p.h> |
| 10 | #include <QtGui/private/qcmyk_p.h> |
| 11 | |
| 12 | QT_BEGIN_NAMESPACE |
| 13 | |
| 14 | template<QImage::Format> constexpr uint redWidth(); |
| 15 | template<QImage::Format> constexpr uint redShift(); |
| 16 | template<QImage::Format> constexpr uint greenWidth(); |
| 17 | template<QImage::Format> constexpr uint greenShift(); |
| 18 | template<QImage::Format> constexpr uint blueWidth(); |
| 19 | template<QImage::Format> constexpr uint blueShift(); |
| 20 | template<QImage::Format> constexpr uint alphaWidth(); |
| 21 | template<QImage::Format> constexpr uint alphaShift(); |
| 22 | |
| 23 | template<> constexpr uint redWidth<QImage::Format_RGB32>() { return 8; } |
| 24 | template<> constexpr uint redWidth<QImage::Format_ARGB32>() { return 8; } |
| 25 | template<> constexpr uint redWidth<QImage::Format_ARGB32_Premultiplied>() { return 8; } |
| 26 | template<> constexpr uint redWidth<QImage::Format_RGB16>() { return 5; } |
| 27 | template<> constexpr uint redWidth<QImage::Format_RGB444>() { return 4; } |
| 28 | template<> constexpr uint redWidth<QImage::Format_RGB555>() { return 5; } |
| 29 | template<> constexpr uint redWidth<QImage::Format_RGB666>() { return 6; } |
| 30 | template<> constexpr uint redWidth<QImage::Format_RGB888>() { return 8; } |
| 31 | template<> constexpr uint redWidth<QImage::Format_BGR888>() { return 8; } |
| 32 | template<> constexpr uint redWidth<QImage::Format_ARGB4444_Premultiplied>() { return 4; } |
| 33 | template<> constexpr uint redWidth<QImage::Format_ARGB8555_Premultiplied>() { return 5; } |
| 34 | template<> constexpr uint redWidth<QImage::Format_ARGB8565_Premultiplied>() { return 5; } |
| 35 | template<> constexpr uint redWidth<QImage::Format_ARGB6666_Premultiplied>() { return 6; } |
| 36 | template<> constexpr uint redWidth<QImage::Format_RGBX8888>() { return 8; } |
| 37 | template<> constexpr uint redWidth<QImage::Format_RGBA8888>() { return 8; } |
| 38 | template<> constexpr uint redWidth<QImage::Format_RGBA8888_Premultiplied>() { return 8; } |
| 39 | |
| 40 | template<> constexpr uint redShift<QImage::Format_RGB32>() { return 16; } |
| 41 | template<> constexpr uint redShift<QImage::Format_ARGB32>() { return 16; } |
| 42 | template<> constexpr uint redShift<QImage::Format_ARGB32_Premultiplied>() { return 16; } |
| 43 | template<> constexpr uint redShift<QImage::Format_RGB16>() { return 11; } |
| 44 | template<> constexpr uint redShift<QImage::Format_RGB444>() { return 8; } |
| 45 | template<> constexpr uint redShift<QImage::Format_RGB555>() { return 10; } |
| 46 | template<> constexpr uint redShift<QImage::Format_RGB666>() { return 12; } |
| 47 | template<> constexpr uint redShift<QImage::Format_RGB888>() { return 16; } |
| 48 | template<> constexpr uint redShift<QImage::Format_BGR888>() { return 0; } |
| 49 | template<> constexpr uint redShift<QImage::Format_ARGB4444_Premultiplied>() { return 8; } |
| 50 | template<> constexpr uint redShift<QImage::Format_ARGB8555_Premultiplied>() { return 18; } |
| 51 | template<> constexpr uint redShift<QImage::Format_ARGB8565_Premultiplied>() { return 19; } |
| 52 | template<> constexpr uint redShift<QImage::Format_ARGB6666_Premultiplied>() { return 12; } |
| 53 | #if Q_BYTE_ORDER == Q_BIG_ENDIAN |
| 54 | template<> constexpr uint redShift<QImage::Format_RGBX8888>() { return 24; } |
| 55 | template<> constexpr uint redShift<QImage::Format_RGBA8888>() { return 24; } |
| 56 | template<> constexpr uint redShift<QImage::Format_RGBA8888_Premultiplied>() { return 24; } |
| 57 | #else |
| 58 | template<> constexpr uint redShift<QImage::Format_RGBX8888>() { return 0; } |
| 59 | template<> constexpr uint redShift<QImage::Format_RGBA8888>() { return 0; } |
| 60 | template<> constexpr uint redShift<QImage::Format_RGBA8888_Premultiplied>() { return 0; } |
| 61 | #endif |
| 62 | template<> constexpr uint greenWidth<QImage::Format_RGB32>() { return 8; } |
| 63 | template<> constexpr uint greenWidth<QImage::Format_ARGB32>() { return 8; } |
| 64 | template<> constexpr uint greenWidth<QImage::Format_ARGB32_Premultiplied>() { return 8; } |
| 65 | template<> constexpr uint greenWidth<QImage::Format_RGB16>() { return 6; } |
| 66 | template<> constexpr uint greenWidth<QImage::Format_RGB444>() { return 4; } |
| 67 | template<> constexpr uint greenWidth<QImage::Format_RGB555>() { return 5; } |
| 68 | template<> constexpr uint greenWidth<QImage::Format_RGB666>() { return 6; } |
| 69 | template<> constexpr uint greenWidth<QImage::Format_RGB888>() { return 8; } |
| 70 | template<> constexpr uint greenWidth<QImage::Format_BGR888>() { return 8; } |
| 71 | template<> constexpr uint greenWidth<QImage::Format_ARGB4444_Premultiplied>() { return 4; } |
| 72 | template<> constexpr uint greenWidth<QImage::Format_ARGB8555_Premultiplied>() { return 5; } |
| 73 | template<> constexpr uint greenWidth<QImage::Format_ARGB8565_Premultiplied>() { return 6; } |
| 74 | template<> constexpr uint greenWidth<QImage::Format_ARGB6666_Premultiplied>() { return 6; } |
| 75 | template<> constexpr uint greenWidth<QImage::Format_RGBX8888>() { return 8; } |
| 76 | template<> constexpr uint greenWidth<QImage::Format_RGBA8888>() { return 8; } |
| 77 | template<> constexpr uint greenWidth<QImage::Format_RGBA8888_Premultiplied>() { return 8; } |
| 78 | |
| 79 | template<> constexpr uint greenShift<QImage::Format_RGB32>() { return 8; } |
| 80 | template<> constexpr uint greenShift<QImage::Format_ARGB32>() { return 8; } |
| 81 | template<> constexpr uint greenShift<QImage::Format_ARGB32_Premultiplied>() { return 8; } |
| 82 | template<> constexpr uint greenShift<QImage::Format_RGB16>() { return 5; } |
| 83 | template<> constexpr uint greenShift<QImage::Format_RGB444>() { return 4; } |
| 84 | template<> constexpr uint greenShift<QImage::Format_RGB555>() { return 5; } |
| 85 | template<> constexpr uint greenShift<QImage::Format_RGB666>() { return 6; } |
| 86 | template<> constexpr uint greenShift<QImage::Format_RGB888>() { return 8; } |
| 87 | template<> constexpr uint greenShift<QImage::Format_BGR888>() { return 8; } |
| 88 | template<> constexpr uint greenShift<QImage::Format_ARGB4444_Premultiplied>() { return 4; } |
| 89 | template<> constexpr uint greenShift<QImage::Format_ARGB8555_Premultiplied>() { return 13; } |
| 90 | template<> constexpr uint greenShift<QImage::Format_ARGB8565_Premultiplied>() { return 13; } |
| 91 | template<> constexpr uint greenShift<QImage::Format_ARGB6666_Premultiplied>() { return 6; } |
| 92 | #if Q_BYTE_ORDER == Q_BIG_ENDIAN |
| 93 | template<> constexpr uint greenShift<QImage::Format_RGBX8888>() { return 16; } |
| 94 | template<> constexpr uint greenShift<QImage::Format_RGBA8888>() { return 16; } |
| 95 | template<> constexpr uint greenShift<QImage::Format_RGBA8888_Premultiplied>() { return 16; } |
| 96 | #else |
| 97 | template<> constexpr uint greenShift<QImage::Format_RGBX8888>() { return 8; } |
| 98 | template<> constexpr uint greenShift<QImage::Format_RGBA8888>() { return 8; } |
| 99 | template<> constexpr uint greenShift<QImage::Format_RGBA8888_Premultiplied>() { return 8; } |
| 100 | #endif |
| 101 | template<> constexpr uint blueWidth<QImage::Format_RGB32>() { return 8; } |
| 102 | template<> constexpr uint blueWidth<QImage::Format_ARGB32>() { return 8; } |
| 103 | template<> constexpr uint blueWidth<QImage::Format_ARGB32_Premultiplied>() { return 8; } |
| 104 | template<> constexpr uint blueWidth<QImage::Format_RGB16>() { return 5; } |
| 105 | template<> constexpr uint blueWidth<QImage::Format_RGB444>() { return 4; } |
| 106 | template<> constexpr uint blueWidth<QImage::Format_RGB555>() { return 5; } |
| 107 | template<> constexpr uint blueWidth<QImage::Format_RGB666>() { return 6; } |
| 108 | template<> constexpr uint blueWidth<QImage::Format_RGB888>() { return 8; } |
| 109 | template<> constexpr uint blueWidth<QImage::Format_BGR888>() { return 8; } |
| 110 | template<> constexpr uint blueWidth<QImage::Format_ARGB4444_Premultiplied>() { return 4; } |
| 111 | template<> constexpr uint blueWidth<QImage::Format_ARGB8555_Premultiplied>() { return 5; } |
| 112 | template<> constexpr uint blueWidth<QImage::Format_ARGB8565_Premultiplied>() { return 5; } |
| 113 | template<> constexpr uint blueWidth<QImage::Format_ARGB6666_Premultiplied>() { return 6; } |
| 114 | template<> constexpr uint blueWidth<QImage::Format_RGBX8888>() { return 8; } |
| 115 | template<> constexpr uint blueWidth<QImage::Format_RGBA8888>() { return 8; } |
| 116 | template<> constexpr uint blueWidth<QImage::Format_RGBA8888_Premultiplied>() { return 8; } |
| 117 | |
| 118 | template<> constexpr uint blueShift<QImage::Format_RGB32>() { return 0; } |
| 119 | template<> constexpr uint blueShift<QImage::Format_ARGB32>() { return 0; } |
| 120 | template<> constexpr uint blueShift<QImage::Format_ARGB32_Premultiplied>() { return 0; } |
| 121 | template<> constexpr uint blueShift<QImage::Format_RGB16>() { return 0; } |
| 122 | template<> constexpr uint blueShift<QImage::Format_RGB444>() { return 0; } |
| 123 | template<> constexpr uint blueShift<QImage::Format_RGB555>() { return 0; } |
| 124 | template<> constexpr uint blueShift<QImage::Format_RGB666>() { return 0; } |
| 125 | template<> constexpr uint blueShift<QImage::Format_RGB888>() { return 0; } |
| 126 | template<> constexpr uint blueShift<QImage::Format_BGR888>() { return 16; } |
| 127 | template<> constexpr uint blueShift<QImage::Format_ARGB4444_Premultiplied>() { return 0; } |
| 128 | template<> constexpr uint blueShift<QImage::Format_ARGB8555_Premultiplied>() { return 8; } |
| 129 | template<> constexpr uint blueShift<QImage::Format_ARGB8565_Premultiplied>() { return 8; } |
| 130 | template<> constexpr uint blueShift<QImage::Format_ARGB6666_Premultiplied>() { return 0; } |
| 131 | #if Q_BYTE_ORDER == Q_BIG_ENDIAN |
| 132 | template<> constexpr uint blueShift<QImage::Format_RGBX8888>() { return 8; } |
| 133 | template<> constexpr uint blueShift<QImage::Format_RGBA8888>() { return 8; } |
| 134 | template<> constexpr uint blueShift<QImage::Format_RGBA8888_Premultiplied>() { return 8; } |
| 135 | #else |
| 136 | template<> constexpr uint blueShift<QImage::Format_RGBX8888>() { return 16; } |
| 137 | template<> constexpr uint blueShift<QImage::Format_RGBA8888>() { return 16; } |
| 138 | template<> constexpr uint blueShift<QImage::Format_RGBA8888_Premultiplied>() { return 16; } |
| 139 | #endif |
| 140 | template<> constexpr uint alphaWidth<QImage::Format_RGB32>() { return 0; } |
| 141 | template<> constexpr uint alphaWidth<QImage::Format_ARGB32>() { return 8; } |
| 142 | template<> constexpr uint alphaWidth<QImage::Format_ARGB32_Premultiplied>() { return 8; } |
| 143 | template<> constexpr uint alphaWidth<QImage::Format_RGB16>() { return 0; } |
| 144 | template<> constexpr uint alphaWidth<QImage::Format_RGB444>() { return 0; } |
| 145 | template<> constexpr uint alphaWidth<QImage::Format_RGB555>() { return 0; } |
| 146 | template<> constexpr uint alphaWidth<QImage::Format_RGB666>() { return 0; } |
| 147 | template<> constexpr uint alphaWidth<QImage::Format_RGB888>() { return 0; } |
| 148 | template<> constexpr uint alphaWidth<QImage::Format_BGR888>() { return 0; } |
| 149 | template<> constexpr uint alphaWidth<QImage::Format_ARGB4444_Premultiplied>() { return 4; } |
| 150 | template<> constexpr uint alphaWidth<QImage::Format_ARGB8555_Premultiplied>() { return 8; } |
| 151 | template<> constexpr uint alphaWidth<QImage::Format_ARGB8565_Premultiplied>() { return 8; } |
| 152 | template<> constexpr uint alphaWidth<QImage::Format_ARGB6666_Premultiplied>() { return 6; } |
| 153 | template<> constexpr uint alphaWidth<QImage::Format_RGBX8888>() { return 0; } |
| 154 | template<> constexpr uint alphaWidth<QImage::Format_RGBA8888>() { return 8; } |
| 155 | template<> constexpr uint alphaWidth<QImage::Format_RGBA8888_Premultiplied>() { return 8; } |
| 156 | |
| 157 | template<> constexpr uint alphaShift<QImage::Format_RGB32>() { return 24; } |
| 158 | template<> constexpr uint alphaShift<QImage::Format_ARGB32>() { return 24; } |
| 159 | template<> constexpr uint alphaShift<QImage::Format_ARGB32_Premultiplied>() { return 24; } |
| 160 | template<> constexpr uint alphaShift<QImage::Format_RGB16>() { return 0; } |
| 161 | template<> constexpr uint alphaShift<QImage::Format_RGB444>() { return 0; } |
| 162 | template<> constexpr uint alphaShift<QImage::Format_RGB555>() { return 0; } |
| 163 | template<> constexpr uint alphaShift<QImage::Format_RGB666>() { return 0; } |
| 164 | template<> constexpr uint alphaShift<QImage::Format_RGB888>() { return 0; } |
| 165 | template<> constexpr uint alphaShift<QImage::Format_BGR888>() { return 0; } |
| 166 | template<> constexpr uint alphaShift<QImage::Format_ARGB4444_Premultiplied>() { return 12; } |
| 167 | template<> constexpr uint alphaShift<QImage::Format_ARGB8555_Premultiplied>() { return 0; } |
| 168 | template<> constexpr uint alphaShift<QImage::Format_ARGB8565_Premultiplied>() { return 0; } |
| 169 | template<> constexpr uint alphaShift<QImage::Format_ARGB6666_Premultiplied>() { return 18; } |
| 170 | #if Q_BYTE_ORDER == Q_BIG_ENDIAN |
| 171 | template<> constexpr uint alphaShift<QImage::Format_RGBX8888>() { return 0; } |
| 172 | template<> constexpr uint alphaShift<QImage::Format_RGBA8888>() { return 0; } |
| 173 | template<> constexpr uint alphaShift<QImage::Format_RGBA8888_Premultiplied>() { return 0; } |
| 174 | #else |
| 175 | template<> constexpr uint alphaShift<QImage::Format_RGBX8888>() { return 24; } |
| 176 | template<> constexpr uint alphaShift<QImage::Format_RGBA8888>() { return 24; } |
| 177 | template<> constexpr uint alphaShift<QImage::Format_RGBA8888_Premultiplied>() { return 24; } |
| 178 | #endif |
| 179 | |
| 180 | template<QImage::Format> constexpr QPixelLayout::BPP bitsPerPixel(); |
| 181 | template<> constexpr QPixelLayout::BPP bitsPerPixel<QImage::Format_RGB32>() { return QPixelLayout::BPP32; } |
| 182 | template<> constexpr QPixelLayout::BPP bitsPerPixel<QImage::Format_ARGB32>() { return QPixelLayout::BPP32; } |
| 183 | template<> constexpr QPixelLayout::BPP bitsPerPixel<QImage::Format_ARGB32_Premultiplied>() { return QPixelLayout::BPP32; } |
| 184 | template<> constexpr QPixelLayout::BPP bitsPerPixel<QImage::Format_RGB16>() { return QPixelLayout::BPP16; } |
| 185 | template<> constexpr QPixelLayout::BPP bitsPerPixel<QImage::Format_RGB444>() { return QPixelLayout::BPP16; } |
| 186 | template<> constexpr QPixelLayout::BPP bitsPerPixel<QImage::Format_RGB555>() { return QPixelLayout::BPP16; } |
| 187 | template<> constexpr QPixelLayout::BPP bitsPerPixel<QImage::Format_RGB666>() { return QPixelLayout::BPP24; } |
| 188 | template<> constexpr QPixelLayout::BPP bitsPerPixel<QImage::Format_RGB888>() { return QPixelLayout::BPP24; } |
| 189 | template<> constexpr QPixelLayout::BPP bitsPerPixel<QImage::Format_BGR888>() { return QPixelLayout::BPP24; } |
| 190 | template<> constexpr QPixelLayout::BPP bitsPerPixel<QImage::Format_ARGB4444_Premultiplied>() { return QPixelLayout::BPP16; } |
| 191 | template<> constexpr QPixelLayout::BPP bitsPerPixel<QImage::Format_ARGB8555_Premultiplied>() { return QPixelLayout::BPP24; } |
| 192 | template<> constexpr QPixelLayout::BPP bitsPerPixel<QImage::Format_ARGB8565_Premultiplied>() { return QPixelLayout::BPP24; } |
| 193 | template<> constexpr QPixelLayout::BPP bitsPerPixel<QImage::Format_ARGB6666_Premultiplied>() { return QPixelLayout::BPP24; } |
| 194 | template<> constexpr QPixelLayout::BPP bitsPerPixel<QImage::Format_RGBX8888>() { return QPixelLayout::BPP32; } |
| 195 | template<> constexpr QPixelLayout::BPP bitsPerPixel<QImage::Format_RGBA8888>() { return QPixelLayout::BPP32; } |
| 196 | template<> constexpr QPixelLayout::BPP bitsPerPixel<QImage::Format_RGBA8888_Premultiplied>() { return QPixelLayout::BPP32; } |
| 197 | |
| 198 | template <QPixelLayout::BPP width> static |
| 199 | void QT_FASTCALL storePixel(uchar *dest, int index, uint pixel); |
| 200 | |
| 201 | template <> |
| 202 | inline void QT_FASTCALL storePixel<QPixelLayout::BPP16>(uchar *dest, int index, uint pixel) |
| 203 | { |
| 204 | reinterpret_cast<quint16 *>(dest)[index] = quint16(pixel); |
| 205 | } |
| 206 | |
| 207 | template <> |
| 208 | inline void QT_FASTCALL storePixel<QPixelLayout::BPP24>(uchar *dest, int index, uint pixel) |
| 209 | { |
| 210 | reinterpret_cast<quint24 *>(dest)[index] = quint24(pixel); |
| 211 | } |
| 212 | |
| 213 | template <QPixelLayout::BPP bpp> static |
| 214 | inline uint QT_FASTCALL fetchPixel(const uchar *, int) |
| 215 | { |
| 216 | Q_UNREACHABLE_RETURN(0); |
| 217 | } |
| 218 | |
| 219 | template <> |
| 220 | inline uint QT_FASTCALL fetchPixel<QPixelLayout::BPP1LSB>(const uchar *src, int index) |
| 221 | { |
| 222 | return (src[index >> 3] >> (index & 7)) & 1; |
| 223 | } |
| 224 | |
| 225 | template <> |
| 226 | inline uint QT_FASTCALL fetchPixel<QPixelLayout::BPP1MSB>(const uchar *src, int index) |
| 227 | { |
| 228 | return (src[index >> 3] >> (~index & 7)) & 1; |
| 229 | } |
| 230 | |
| 231 | template <> |
| 232 | inline uint QT_FASTCALL fetchPixel<QPixelLayout::BPP8>(const uchar *src, int index) |
| 233 | { |
| 234 | return src[index]; |
| 235 | } |
| 236 | |
| 237 | template <> |
| 238 | inline uint QT_FASTCALL fetchPixel<QPixelLayout::BPP16>(const uchar *src, int index) |
| 239 | { |
| 240 | return reinterpret_cast<const quint16 *>(src)[index]; |
| 241 | } |
| 242 | |
| 243 | template <> |
| 244 | inline uint QT_FASTCALL fetchPixel<QPixelLayout::BPP24>(const uchar *src, int index) |
| 245 | { |
| 246 | return reinterpret_cast<const quint24 *>(src)[index]; |
| 247 | } |
| 248 | |
| 249 | template <> |
| 250 | inline uint QT_FASTCALL fetchPixel<QPixelLayout::BPP32>(const uchar *src, int index) |
| 251 | { |
| 252 | return reinterpret_cast<const uint *>(src)[index]; |
| 253 | } |
| 254 | |
| 255 | template <> |
| 256 | [[maybe_unused]] |
| 257 | inline uint QT_FASTCALL fetchPixel<QPixelLayout::BPP64>(const uchar *src, int index) |
| 258 | { |
| 259 | // We have to do the conversion in fetch to fit into a 32bit uint |
| 260 | QRgba64 c = reinterpret_cast<const QRgba64 *>(src)[index]; |
| 261 | return c.toArgb32(); |
| 262 | } |
| 263 | |
| 264 | template <> |
| 265 | [[maybe_unused]] |
| 266 | inline uint QT_FASTCALL fetchPixel<QPixelLayout::BPP16FPx4>(const uchar *src, int index) |
| 267 | { |
| 268 | // We have to do the conversion in fetch to fit into a 32bit uint |
| 269 | QRgbaFloat16 c = reinterpret_cast<const QRgbaFloat16 *>(src)[index]; |
| 270 | return c.toArgb32(); |
| 271 | } |
| 272 | |
| 273 | template <> |
| 274 | [[maybe_unused]] |
| 275 | inline uint QT_FASTCALL fetchPixel<QPixelLayout::BPP32FPx4>(const uchar *src, int index) |
| 276 | { |
| 277 | // We have to do the conversion in fetch to fit into a 32bit uint |
| 278 | QRgbaFloat32 c = reinterpret_cast<const QRgbaFloat32 *>(src)[index]; |
| 279 | return c.toArgb32(); |
| 280 | } |
| 281 | |
| 282 | template<QImage::Format Format> |
| 283 | static inline uint convertPixelToRGB32(uint s) |
| 284 | { |
| 285 | constexpr uint redMask = ((1 << redWidth<Format>()) - 1); |
| 286 | constexpr uint greenMask = ((1 << greenWidth<Format>()) - 1); |
| 287 | constexpr uint blueMask = ((1 << blueWidth<Format>()) - 1); |
| 288 | |
| 289 | constexpr uchar redLeftShift = 8 - redWidth<Format>(); |
| 290 | constexpr uchar greenLeftShift = 8 - greenWidth<Format>(); |
| 291 | constexpr uchar blueLeftShift = 8 - blueWidth<Format>(); |
| 292 | |
| 293 | constexpr uchar redRightShift = 2 * redWidth<Format>() - 8; |
| 294 | constexpr uchar greenRightShift = 2 * greenWidth<Format>() - 8; |
| 295 | constexpr uchar blueRightShift = 2 * blueWidth<Format>() - 8; |
| 296 | |
| 297 | uint red = (s >> redShift<Format>()) & redMask; |
| 298 | uint green = (s >> greenShift<Format>()) & greenMask; |
| 299 | uint blue = (s >> blueShift<Format>()) & blueMask; |
| 300 | |
| 301 | red = ((red << redLeftShift) | (red >> redRightShift)) << 16; |
| 302 | green = ((green << greenLeftShift) | (green >> greenRightShift)) << 8; |
| 303 | blue = (blue << blueLeftShift) | (blue >> blueRightShift); |
| 304 | return 0xff000000 | red | green | blue; |
| 305 | } |
| 306 | |
| 307 | template<QImage::Format Format> |
| 308 | static void QT_FASTCALL convertToRGB32(uint *buffer, int count, const QList<QRgb> *) |
| 309 | { |
| 310 | for (int i = 0; i < count; ++i) |
| 311 | buffer[i] = convertPixelToRGB32<Format>(buffer[i]); |
| 312 | } |
| 313 | |
| 314 | #if defined(__SSE2__) && !defined(__SSSE3__) && QT_COMPILER_SUPPORTS_SSSE3 |
| 315 | extern const uint * QT_FASTCALL fetchPixelsBPP24_ssse3(uint *dest, const uchar*src, int index, int count); |
| 316 | #endif |
| 317 | |
| 318 | template<QImage::Format Format> |
| 319 | static const uint *QT_FASTCALL fetchRGBToRGB32(uint *buffer, const uchar *src, int index, int count, |
| 320 | const QList<QRgb> *, QDitherInfo *) |
| 321 | { |
| 322 | constexpr QPixelLayout::BPP BPP = bitsPerPixel<Format>(); |
| 323 | #if defined(__SSE2__) && !defined(__SSSE3__) && QT_COMPILER_SUPPORTS_SSSE3 |
| 324 | if (BPP == QPixelLayout::BPP24 && qCpuHasFeature(SSSE3)) { |
| 325 | // With SSE2 can convertToRGB32 be vectorized, but it takes SSSE3 |
| 326 | // to vectorize the deforested version below. |
| 327 | fetchPixelsBPP24_ssse3(dest: buffer, src, index, count); |
| 328 | convertToRGB32<Format>(buffer, count, nullptr); |
| 329 | return buffer; |
| 330 | } |
| 331 | #endif |
| 332 | for (int i = 0; i < count; ++i) |
| 333 | buffer[i] = convertPixelToRGB32<Format>(fetchPixel<BPP>(src, index + i)); |
| 334 | return buffer; |
| 335 | } |
| 336 | |
| 337 | template<QImage::Format Format> |
| 338 | static inline QRgba64 convertPixelToRGB64(uint s) |
| 339 | { |
| 340 | return QRgba64::fromArgb32(rgb: convertPixelToRGB32<Format>(s)); |
| 341 | } |
| 342 | |
| 343 | template<QImage::Format Format> |
| 344 | static const QRgba64 *QT_FASTCALL convertToRGB64(QRgba64 *buffer, const uint *src, int count, |
| 345 | const QList<QRgb> *, QDitherInfo *) |
| 346 | { |
| 347 | for (int i = 0; i < count; ++i) |
| 348 | buffer[i] = convertPixelToRGB64<Format>(src[i]); |
| 349 | return buffer; |
| 350 | } |
| 351 | |
| 352 | template<QImage::Format Format> |
| 353 | static const QRgba64 *QT_FASTCALL fetchRGBToRGB64(QRgba64 *buffer, const uchar *src, int index, int count, |
| 354 | const QList<QRgb> *, QDitherInfo *) |
| 355 | { |
| 356 | for (int i = 0; i < count; ++i) |
| 357 | buffer[i] = convertPixelToRGB64<Format>(fetchPixel<bitsPerPixel<Format>()>(src, index + i)); |
| 358 | return buffer; |
| 359 | } |
| 360 | |
| 361 | template<QImage::Format Format> |
| 362 | static Q_ALWAYS_INLINE QRgbaFloat32 convertPixelToRGB32F(uint s) |
| 363 | { |
| 364 | return QRgbaFloat32::fromArgb32(rgb: convertPixelToRGB32<Format>(s)); |
| 365 | } |
| 366 | |
| 367 | template<QImage::Format Format> |
| 368 | static const QRgbaFloat32 *QT_FASTCALL fetchRGBToRGB32F(QRgbaFloat32 *buffer, const uchar *src, int index, int count, |
| 369 | const QList<QRgb> *, QDitherInfo *) |
| 370 | { |
| 371 | for (int i = 0; i < count; ++i) |
| 372 | buffer[i] = convertPixelToRGB32F<Format>(fetchPixel<bitsPerPixel<Format>()>(src, index + i)); |
| 373 | return buffer; |
| 374 | } |
| 375 | |
| 376 | template<QImage::Format Format> |
| 377 | static inline uint convertPixelToARGB32PM(uint s) |
| 378 | { |
| 379 | constexpr uint alphaMask = ((1 << alphaWidth<Format>()) - 1); |
| 380 | constexpr uint redMask = ((1 << redWidth<Format>()) - 1); |
| 381 | constexpr uint greenMask = ((1 << greenWidth<Format>()) - 1); |
| 382 | constexpr uint blueMask = ((1 << blueWidth<Format>()) - 1); |
| 383 | |
| 384 | constexpr uchar alphaLeftShift = 8 - alphaWidth<Format>(); |
| 385 | constexpr uchar redLeftShift = 8 - redWidth<Format>(); |
| 386 | constexpr uchar greenLeftShift = 8 - greenWidth<Format>(); |
| 387 | constexpr uchar blueLeftShift = 8 - blueWidth<Format>(); |
| 388 | |
| 389 | constexpr uchar alphaRightShift = 2 * alphaWidth<Format>() - 8; |
| 390 | constexpr uchar redRightShift = 2 * redWidth<Format>() - 8; |
| 391 | constexpr uchar greenRightShift = 2 * greenWidth<Format>() - 8; |
| 392 | constexpr uchar blueRightShift = 2 * blueWidth<Format>() - 8; |
| 393 | |
| 394 | constexpr bool mustMin = (alphaWidth<Format>() != redWidth<Format>()) || |
| 395 | (alphaWidth<Format>() != greenWidth<Format>()) || |
| 396 | (alphaWidth<Format>() != blueWidth<Format>()); |
| 397 | |
| 398 | uint alpha = (s >> alphaShift<Format>()) & alphaMask; |
| 399 | uint red = (s >> redShift<Format>()) & redMask; |
| 400 | uint green = (s >> greenShift<Format>()) & greenMask; |
| 401 | uint blue = (s >> blueShift<Format>()) & blueMask; |
| 402 | |
| 403 | alpha = (alpha << alphaLeftShift) | (alpha >> alphaRightShift); |
| 404 | red = (red << redLeftShift) | (red >> redRightShift); |
| 405 | green = (green << greenLeftShift) | (green >> greenRightShift); |
| 406 | blue = (blue << blueLeftShift) | (blue >> blueRightShift); |
| 407 | |
| 408 | if (mustMin) { |
| 409 | red = qMin(a: alpha, b: red); |
| 410 | green = qMin(a: alpha, b: green); |
| 411 | blue = qMin(a: alpha, b: blue); |
| 412 | } |
| 413 | |
| 414 | return (alpha << 24) | (red << 16) | (green << 8) | blue; |
| 415 | } |
| 416 | |
| 417 | template<QImage::Format Format> |
| 418 | static void QT_FASTCALL convertARGBPMToARGB32PM(uint *buffer, int count, const QList<QRgb> *) |
| 419 | { |
| 420 | for (int i = 0; i < count; ++i) |
| 421 | buffer[i] = convertPixelToARGB32PM<Format>(buffer[i]); |
| 422 | } |
| 423 | |
| 424 | template<QImage::Format Format> |
| 425 | static const uint *QT_FASTCALL fetchARGBPMToARGB32PM(uint *buffer, const uchar *src, int index, int count, |
| 426 | const QList<QRgb> *, QDitherInfo *) |
| 427 | { |
| 428 | constexpr QPixelLayout::BPP BPP = bitsPerPixel<Format>(); |
| 429 | #if defined(__SSE2__) && !defined(__SSSE3__) && QT_COMPILER_SUPPORTS_SSSE3 |
| 430 | if (BPP == QPixelLayout::BPP24 && qCpuHasFeature(SSSE3)) { |
| 431 | // With SSE2 can convertToRGB32 be vectorized, but it takes SSSE3 |
| 432 | // to vectorize the deforested version below. |
| 433 | fetchPixelsBPP24_ssse3(dest: buffer, src, index, count); |
| 434 | convertARGBPMToARGB32PM<Format>(buffer, count, nullptr); |
| 435 | return buffer; |
| 436 | } |
| 437 | #endif |
| 438 | for (int i = 0; i < count; ++i) |
| 439 | buffer[i] = convertPixelToARGB32PM<Format>(fetchPixel<BPP>(src, index + i)); |
| 440 | return buffer; |
| 441 | } |
| 442 | |
| 443 | template<QImage::Format Format> |
| 444 | static inline QRgba64 convertPixelToRGBA64PM(uint s) |
| 445 | { |
| 446 | return QRgba64::fromArgb32(rgb: convertPixelToARGB32PM<Format>(s)); |
| 447 | } |
| 448 | |
| 449 | template<QImage::Format Format> |
| 450 | static const QRgba64 *QT_FASTCALL convertARGBPMToRGBA64PM(QRgba64 *buffer, const uint *src, int count, |
| 451 | const QList<QRgb> *, QDitherInfo *) |
| 452 | { |
| 453 | for (int i = 0; i < count; ++i) |
| 454 | buffer[i] = convertPixelToRGB64<Format>(src[i]); |
| 455 | return buffer; |
| 456 | } |
| 457 | |
| 458 | template<QImage::Format Format> |
| 459 | static const QRgba64 *QT_FASTCALL fetchARGBPMToRGBA64PM(QRgba64 *buffer, const uchar *src, int index, int count, |
| 460 | const QList<QRgb> *, QDitherInfo *) |
| 461 | { |
| 462 | constexpr QPixelLayout::BPP bpp = bitsPerPixel<Format>(); |
| 463 | for (int i = 0; i < count; ++i) |
| 464 | buffer[i] = convertPixelToRGBA64PM<Format>(fetchPixel<bpp>(src, index + i)); |
| 465 | return buffer; |
| 466 | } |
| 467 | |
| 468 | template<QImage::Format Format> |
| 469 | static Q_ALWAYS_INLINE QRgbaFloat32 convertPixelToRGBA32F(uint s) |
| 470 | { |
| 471 | return QRgbaFloat32::fromArgb32(rgb: convertPixelToARGB32PM<Format>(s)); |
| 472 | } |
| 473 | |
| 474 | template<QImage::Format Format> |
| 475 | static const QRgbaFloat32 *QT_FASTCALL fetchARGBPMToRGBA32F(QRgbaFloat32 *buffer, const uchar *src, int index, int count, |
| 476 | const QList<QRgb> *, QDitherInfo *) |
| 477 | { |
| 478 | constexpr QPixelLayout::BPP bpp = bitsPerPixel<Format>(); |
| 479 | for (int i = 0; i < count; ++i) |
| 480 | buffer[i] = convertPixelToRGBA32F<Format>(fetchPixel<bpp>(src, index + i)); |
| 481 | return buffer; |
| 482 | } |
| 483 | |
| 484 | template<QImage::Format Format> |
| 485 | static const QRgbaFloat32 *QT_FASTCALL fetchARGBToRGBA32F(QRgbaFloat32 *buffer, const uchar *src, int index, int count, |
| 486 | const QList<QRgb> *, QDitherInfo *) |
| 487 | { |
| 488 | constexpr QPixelLayout::BPP bpp = bitsPerPixel<Format>(); |
| 489 | for (int i = 0; i < count; ++i) |
| 490 | buffer[i] = convertPixelToRGBA32F<Format>(fetchPixel<bpp>(src, index + i)).premultiplied(); |
| 491 | return buffer; |
| 492 | } |
| 493 | |
| 494 | template<QImage::Format Format, bool fromRGB> |
| 495 | static void QT_FASTCALL storeRGBFromARGB32PM(uchar *dest, const uint *src, int index, int count, |
| 496 | const QList<QRgb> *, QDitherInfo *dither) |
| 497 | { |
| 498 | constexpr uchar rWidth = redWidth<Format>(); |
| 499 | constexpr uchar gWidth = greenWidth<Format>(); |
| 500 | constexpr uchar bWidth = blueWidth<Format>(); |
| 501 | constexpr QPixelLayout::BPP BPP = bitsPerPixel<Format>(); |
| 502 | |
| 503 | // RGB32 -> RGB888 is not a precision loss. |
| 504 | if (!dither || (rWidth == 8 && gWidth == 8 && bWidth == 8)) { |
| 505 | constexpr uint rMask = (1 << redWidth<Format>()) - 1; |
| 506 | constexpr uint gMask = (1 << greenWidth<Format>()) - 1; |
| 507 | constexpr uint bMask = (1 << blueWidth<Format>()) - 1; |
| 508 | constexpr uchar rRightShift = 24 - redWidth<Format>(); |
| 509 | constexpr uchar gRightShift = 16 - greenWidth<Format>(); |
| 510 | constexpr uchar bRightShift = 8 - blueWidth<Format>(); |
| 511 | |
| 512 | for (int i = 0; i < count; ++i) { |
| 513 | const uint c = fromRGB ? src[i] : qUnpremultiply(p: src[i]); |
| 514 | const uint r = ((c >> rRightShift) & rMask) << redShift<Format>(); |
| 515 | const uint g = ((c >> gRightShift) & gMask) << greenShift<Format>(); |
| 516 | const uint b = ((c >> bRightShift) & bMask) << blueShift<Format>(); |
| 517 | storePixel<BPP>(dest, index + i, r | g | b); |
| 518 | }; |
| 519 | } else { |
| 520 | // We do ordered dither by using a rounding conversion, but instead of |
| 521 | // adding half of input precision, we add the adjusted result from the |
| 522 | // bayer matrix before narrowing. |
| 523 | // Note: Rounding conversion in itself is different from the naive |
| 524 | // conversion we do above for non-dithering. |
| 525 | const uint *bayer_line = qt_bayer_matrix[dither->y & 15]; |
| 526 | for (int i = 0; i < count; ++i) { |
| 527 | const uint c = fromRGB ? src[i] : qUnpremultiply(p: src[i]); |
| 528 | const int d = bayer_line[(dither->x + i) & 15]; |
| 529 | const int dr = d - ((d + 1) >> rWidth); |
| 530 | const int dg = d - ((d + 1) >> gWidth); |
| 531 | const int db = d - ((d + 1) >> bWidth); |
| 532 | int r = qRed(rgb: c); |
| 533 | int g = qGreen(rgb: c); |
| 534 | int b = qBlue(rgb: c); |
| 535 | r = (r + ((dr - r) >> rWidth) + 1) >> (8 - rWidth); |
| 536 | g = (g + ((dg - g) >> gWidth) + 1) >> (8 - gWidth); |
| 537 | b = (b + ((db - b) >> bWidth) + 1) >> (8 - bWidth); |
| 538 | const uint s = (r << redShift<Format>()) |
| 539 | | (g << greenShift<Format>()) |
| 540 | | (b << blueShift<Format>()); |
| 541 | storePixel<BPP>(dest, index + i, s); |
| 542 | } |
| 543 | } |
| 544 | } |
| 545 | |
| 546 | template<QImage::Format Format, bool fromRGB> |
| 547 | static void QT_FASTCALL storeARGBPMFromARGB32PM(uchar *dest, const uint *src, int index, int count, |
| 548 | const QList<QRgb> *, QDitherInfo *dither) |
| 549 | { |
| 550 | constexpr QPixelLayout::BPP BPP = bitsPerPixel<Format>(); |
| 551 | if (!dither) { |
| 552 | constexpr uint aMask = (1 << alphaWidth<Format>()) - 1; |
| 553 | constexpr uint rMask = (1 << redWidth<Format>()) - 1; |
| 554 | constexpr uint gMask = (1 << greenWidth<Format>()) - 1; |
| 555 | constexpr uint bMask = (1 << blueWidth<Format>()) - 1; |
| 556 | |
| 557 | constexpr uchar aRightShift = 32 - alphaWidth<Format>(); |
| 558 | constexpr uchar rRightShift = 24 - redWidth<Format>(); |
| 559 | constexpr uchar gRightShift = 16 - greenWidth<Format>(); |
| 560 | constexpr uchar bRightShift = 8 - blueWidth<Format>(); |
| 561 | |
| 562 | constexpr uint aOpaque = aMask << alphaShift<Format>(); |
| 563 | for (int i = 0; i < count; ++i) { |
| 564 | const uint c = src[i]; |
| 565 | const uint a = fromRGB ? aOpaque : (((c >> aRightShift) & aMask) << alphaShift<Format>()); |
| 566 | const uint r = ((c >> rRightShift) & rMask) << redShift<Format>(); |
| 567 | const uint g = ((c >> gRightShift) & gMask) << greenShift<Format>(); |
| 568 | const uint b = ((c >> bRightShift) & bMask) << blueShift<Format>(); |
| 569 | storePixel<BPP>(dest, index + i, a | r | g | b); |
| 570 | }; |
| 571 | } else { |
| 572 | constexpr uchar aWidth = alphaWidth<Format>(); |
| 573 | constexpr uchar rWidth = redWidth<Format>(); |
| 574 | constexpr uchar gWidth = greenWidth<Format>(); |
| 575 | constexpr uchar bWidth = blueWidth<Format>(); |
| 576 | |
| 577 | const uint *bayer_line = qt_bayer_matrix[dither->y & 15]; |
| 578 | for (int i = 0; i < count; ++i) { |
| 579 | const uint c = src[i]; |
| 580 | const int d = bayer_line[(dither->x + i) & 15]; |
| 581 | const int da = d - ((d + 1) >> aWidth); |
| 582 | const int dr = d - ((d + 1) >> rWidth); |
| 583 | const int dg = d - ((d + 1) >> gWidth); |
| 584 | const int db = d - ((d + 1) >> bWidth); |
| 585 | int a = qAlpha(rgb: c); |
| 586 | int r = qRed(rgb: c); |
| 587 | int g = qGreen(rgb: c); |
| 588 | int b = qBlue(rgb: c); |
| 589 | if (fromRGB) |
| 590 | a = (1 << aWidth) - 1; |
| 591 | else |
| 592 | a = (a + ((da - a) >> aWidth) + 1) >> (8 - aWidth); |
| 593 | r = (r + ((dr - r) >> rWidth) + 1) >> (8 - rWidth); |
| 594 | g = (g + ((dg - g) >> gWidth) + 1) >> (8 - gWidth); |
| 595 | b = (b + ((db - b) >> bWidth) + 1) >> (8 - bWidth); |
| 596 | uint s = (a << alphaShift<Format>()) |
| 597 | | (r << redShift<Format>()) |
| 598 | | (g << greenShift<Format>()) |
| 599 | | (b << blueShift<Format>()); |
| 600 | storePixel<BPP>(dest, index + i, s); |
| 601 | } |
| 602 | } |
| 603 | } |
| 604 | |
| 605 | template<QImage::Format Format> |
| 606 | static void QT_FASTCALL rbSwap(uchar *dst, const uchar *src, int count) |
| 607 | { |
| 608 | constexpr uchar aWidth = alphaWidth<Format>(); |
| 609 | constexpr uchar aShift = alphaShift<Format>(); |
| 610 | constexpr uchar rWidth = redWidth<Format>(); |
| 611 | constexpr uchar rShift = redShift<Format>(); |
| 612 | constexpr uchar gWidth = greenWidth<Format>(); |
| 613 | constexpr uchar gShift = greenShift<Format>(); |
| 614 | constexpr uchar bWidth = blueWidth<Format>(); |
| 615 | constexpr uchar bShift = blueShift<Format>(); |
| 616 | static_assert(rWidth == bWidth); |
| 617 | constexpr uint redBlueMask = (1 << rWidth) - 1; |
| 618 | constexpr uint alphaGreenMask = (((1 << aWidth) - 1) << aShift) |
| 619 | | (((1 << gWidth) - 1) << gShift); |
| 620 | constexpr QPixelLayout::BPP bpp = bitsPerPixel<Format>(); |
| 621 | |
| 622 | for (int i = 0; i < count; ++i) { |
| 623 | const uint c = fetchPixel<bpp>(src, i); |
| 624 | const uint r = (c >> rShift) & redBlueMask; |
| 625 | const uint b = (c >> bShift) & redBlueMask; |
| 626 | const uint t = (c & alphaGreenMask) |
| 627 | | (r << bShift) |
| 628 | | (b << rShift); |
| 629 | storePixel<bpp>(dst, i, t); |
| 630 | } |
| 631 | } |
| 632 | |
| 633 | static void QT_FASTCALL rbSwap_rgb32(uchar *d, const uchar *s, int count) |
| 634 | { |
| 635 | const uint *src = reinterpret_cast<const uint *>(s); |
| 636 | uint *dest = reinterpret_cast<uint *>(d); |
| 637 | for (int i = 0; i < count; ++i) { |
| 638 | const uint c = src[i]; |
| 639 | const uint ag = c & 0xff00ff00; |
| 640 | const uint rb = c & 0x00ff00ff; |
| 641 | dest[i] = ag | (rb << 16) | (rb >> 16); |
| 642 | } |
| 643 | } |
| 644 | |
| 645 | #if Q_BYTE_ORDER == Q_LITTLE_ENDIAN |
| 646 | template<> |
| 647 | void QT_FASTCALL rbSwap<QImage::Format_RGBA8888>(uchar *d, const uchar *s, int count) |
| 648 | { |
| 649 | return rbSwap_rgb32(d, s, count); |
| 650 | } |
| 651 | #else |
| 652 | template<> |
| 653 | void QT_FASTCALL rbSwap<QImage::Format_RGBA8888>(uchar *d, const uchar *s, int count) |
| 654 | { |
| 655 | const uint *src = reinterpret_cast<const uint *>(s); |
| 656 | uint *dest = reinterpret_cast<uint *>(d); |
| 657 | for (int i = 0; i < count; ++i) { |
| 658 | const uint c = src[i]; |
| 659 | const uint rb = c & 0xff00ff00; |
| 660 | const uint ga = c & 0x00ff00ff; |
| 661 | dest[i] = ga | (rb << 16) | (rb >> 16); |
| 662 | } |
| 663 | } |
| 664 | #endif |
| 665 | |
| 666 | static void QT_FASTCALL rbSwap_rgb30(uchar *d, const uchar *s, int count) |
| 667 | { |
| 668 | const uint *src = reinterpret_cast<const uint *>(s); |
| 669 | uint *dest = reinterpret_cast<uint *>(d); |
| 670 | UNALIASED_CONVERSION_LOOP(dest, src, count, qRgbSwapRgb30); |
| 671 | } |
| 672 | |
| 673 | static void QT_FASTCALL rbSwap_4x16(uchar *d, const uchar *s, int count) |
| 674 | { |
| 675 | const ushort *src = reinterpret_cast<const ushort *>(s); |
| 676 | ushort *dest = reinterpret_cast<ushort *>(d); |
| 677 | if (src != dest) { |
| 678 | for (int i = 0; i < count; ++i) { |
| 679 | dest[i * 4 + 0] = src[i * 4 + 2]; |
| 680 | dest[i * 4 + 1] = src[i * 4 + 1]; |
| 681 | dest[i * 4 + 2] = src[i * 4 + 0]; |
| 682 | dest[i * 4 + 3] = src[i * 4 + 3]; |
| 683 | } |
| 684 | } else { |
| 685 | for (int i = 0; i < count; ++i) { |
| 686 | const ushort r = src[i * 4 + 0]; |
| 687 | const ushort b = src[i * 4 + 2]; |
| 688 | dest[i * 4 + 0] = b; |
| 689 | dest[i * 4 + 2] = r; |
| 690 | } |
| 691 | } |
| 692 | } |
| 693 | |
| 694 | static void QT_FASTCALL rbSwap_4x32(uchar *d, const uchar *s, int count) |
| 695 | { |
| 696 | const uint *src = reinterpret_cast<const uint *>(s); |
| 697 | uint *dest = reinterpret_cast<uint *>(d); |
| 698 | if (src != dest) { |
| 699 | for (int i = 0; i < count; ++i) { |
| 700 | dest[i * 4 + 0] = src[i * 4 + 2]; |
| 701 | dest[i * 4 + 1] = src[i * 4 + 1]; |
| 702 | dest[i * 4 + 2] = src[i * 4 + 0]; |
| 703 | dest[i * 4 + 3] = src[i * 4 + 3]; |
| 704 | } |
| 705 | } else { |
| 706 | for (int i = 0; i < count; ++i) { |
| 707 | const uint r = src[i * 4 + 0]; |
| 708 | const uint b = src[i * 4 + 2]; |
| 709 | dest[i * 4 + 0] = b; |
| 710 | dest[i * 4 + 2] = r; |
| 711 | } |
| 712 | } |
| 713 | } |
| 714 | |
| 715 | template<QImage::Format Format> constexpr static inline QPixelLayout pixelLayoutRGB() |
| 716 | { |
| 717 | return QPixelLayout{ |
| 718 | false, |
| 719 | false, |
| 720 | bitsPerPixel<Format>(), |
| 721 | rbSwap<Format>, |
| 722 | convertToRGB32<Format>, |
| 723 | convertToRGB64<Format>, |
| 724 | fetchRGBToRGB32<Format>, |
| 725 | fetchRGBToRGB64<Format>, |
| 726 | storeRGBFromARGB32PM<Format, false>, |
| 727 | storeRGBFromARGB32PM<Format, true> |
| 728 | }; |
| 729 | } |
| 730 | |
| 731 | template<QImage::Format Format> constexpr static inline QPixelLayout pixelLayoutARGBPM() |
| 732 | { |
| 733 | return QPixelLayout{ |
| 734 | true, |
| 735 | true, |
| 736 | bitsPerPixel<Format>(), |
| 737 | rbSwap<Format>, |
| 738 | convertARGBPMToARGB32PM<Format>, |
| 739 | convertARGBPMToRGBA64PM<Format>, |
| 740 | fetchARGBPMToARGB32PM<Format>, |
| 741 | fetchARGBPMToRGBA64PM<Format>, |
| 742 | storeARGBPMFromARGB32PM<Format, false>, |
| 743 | storeARGBPMFromARGB32PM<Format, true> |
| 744 | }; |
| 745 | } |
| 746 | |
| 747 | static void QT_FASTCALL convertIndexedToARGB32PM(uint *buffer, int count, const QList<QRgb> *clut) |
| 748 | { |
| 749 | for (int i = 0; i < count; ++i) |
| 750 | buffer[i] = qPremultiply(x: clut->at(i: buffer[i])); |
| 751 | } |
| 752 | |
| 753 | template<QPixelLayout::BPP BPP> |
| 754 | static const uint *QT_FASTCALL fetchIndexedToARGB32PM(uint *buffer, const uchar *src, int index, int count, |
| 755 | const QList<QRgb> *clut, QDitherInfo *) |
| 756 | { |
| 757 | for (int i = 0; i < count; ++i) { |
| 758 | const uint s = fetchPixel<BPP>(src, index + i); |
| 759 | buffer[i] = qPremultiply(x: clut->at(i: s)); |
| 760 | } |
| 761 | return buffer; |
| 762 | } |
| 763 | |
| 764 | template<QPixelLayout::BPP BPP> |
| 765 | static const QRgba64 *QT_FASTCALL fetchIndexedToRGBA64PM(QRgba64 *buffer, const uchar *src, int index, int count, |
| 766 | const QList<QRgb> *clut, QDitherInfo *) |
| 767 | { |
| 768 | for (int i = 0; i < count; ++i) { |
| 769 | const uint s = fetchPixel<BPP>(src, index + i); |
| 770 | buffer[i] = QRgba64::fromArgb32(rgb: clut->at(i: s)).premultiplied(); |
| 771 | } |
| 772 | return buffer; |
| 773 | } |
| 774 | |
| 775 | template<QPixelLayout::BPP BPP> |
| 776 | static const QRgbaFloat32 *QT_FASTCALL fetchIndexedToRGBA32F(QRgbaFloat32 *buffer, const uchar *src, int index, int count, |
| 777 | const QList<QRgb> *clut, QDitherInfo *) |
| 778 | { |
| 779 | for (int i = 0; i < count; ++i) { |
| 780 | const uint s = fetchPixel<BPP>(src, index + i); |
| 781 | buffer[i] = QRgbaFloat32::fromArgb32(rgb: clut->at(i: s)).premultiplied(); |
| 782 | } |
| 783 | return buffer; |
| 784 | } |
| 785 | |
| 786 | template<typename QRgba> |
| 787 | static const QRgba *QT_FASTCALL convertIndexedTo(QRgba *buffer, const uint *src, int count, |
| 788 | const QList<QRgb> *clut, QDitherInfo *) |
| 789 | { |
| 790 | for (int i = 0; i < count; ++i) |
| 791 | buffer[i] = QRgba::fromArgb32(clut->at(i: src[i])).premultiplied(); |
| 792 | return buffer; |
| 793 | } |
| 794 | |
| 795 | static void QT_FASTCALL convertPassThrough(uint *, int, const QList<QRgb> *) |
| 796 | { |
| 797 | } |
| 798 | |
| 799 | static const uint *QT_FASTCALL fetchPassThrough(uint *, const uchar *src, int index, int, |
| 800 | const QList<QRgb> *, QDitherInfo *) |
| 801 | { |
| 802 | return reinterpret_cast<const uint *>(src) + index; |
| 803 | } |
| 804 | |
| 805 | static const QRgba64 *QT_FASTCALL fetchPassThrough64(QRgba64 *, const uchar *src, int index, int, |
| 806 | const QList<QRgb> *, QDitherInfo *) |
| 807 | { |
| 808 | return reinterpret_cast<const QRgba64 *>(src) + index; |
| 809 | } |
| 810 | |
| 811 | static void QT_FASTCALL storePassThrough(uchar *dest, const uint *src, int index, int count, |
| 812 | const QList<QRgb> *, QDitherInfo *) |
| 813 | { |
| 814 | uint *d = reinterpret_cast<uint *>(dest) + index; |
| 815 | if (d != src) |
| 816 | memcpy(dest: d, src: src, n: count * sizeof(uint)); |
| 817 | } |
| 818 | |
| 819 | static void QT_FASTCALL convertARGB32ToARGB32PM(uint *buffer, int count, const QList<QRgb> *) |
| 820 | { |
| 821 | qt_convertARGB32ToARGB32PM(buffer, src: buffer, count); |
| 822 | } |
| 823 | |
| 824 | static const uint *QT_FASTCALL fetchARGB32ToARGB32PM(uint *buffer, const uchar *src, int index, int count, |
| 825 | const QList<QRgb> *, QDitherInfo *) |
| 826 | { |
| 827 | return qt_convertARGB32ToARGB32PM(buffer, src: reinterpret_cast<const uint *>(src) + index, count); |
| 828 | } |
| 829 | |
| 830 | static void QT_FASTCALL convertRGBA8888PMToARGB32PM(uint *buffer, int count, const QList<QRgb> *) |
| 831 | { |
| 832 | for (int i = 0; i < count; ++i) |
| 833 | buffer[i] = RGBA2ARGB(x: buffer[i]); |
| 834 | } |
| 835 | |
| 836 | static const uint *QT_FASTCALL fetchRGBA8888PMToARGB32PM(uint *buffer, const uchar *src, int index, int count, |
| 837 | const QList<QRgb> *, QDitherInfo *) |
| 838 | { |
| 839 | const uint *s = reinterpret_cast<const uint *>(src) + index; |
| 840 | UNALIASED_CONVERSION_LOOP(buffer, s, count, RGBA2ARGB); |
| 841 | return buffer; |
| 842 | } |
| 843 | |
| 844 | static void QT_FASTCALL convertRGBA8888ToARGB32PM(uint *buffer, int count, const QList<QRgb> *) |
| 845 | { |
| 846 | qt_convertRGBA8888ToARGB32PM(buffer, src: buffer, count); |
| 847 | } |
| 848 | |
| 849 | static const uint *QT_FASTCALL fetchRGBA8888ToARGB32PM(uint *buffer, const uchar *src, int index, int count, |
| 850 | const QList<QRgb> *, QDitherInfo *) |
| 851 | { |
| 852 | return qt_convertRGBA8888ToARGB32PM(buffer, src: reinterpret_cast<const uint *>(src) + index, count); |
| 853 | } |
| 854 | |
| 855 | static void QT_FASTCALL convertAlpha8ToRGB32(uint *buffer, int count, const QList<QRgb> *) |
| 856 | { |
| 857 | for (int i = 0; i < count; ++i) |
| 858 | buffer[i] = qRgba(r: 0, g: 0, b: 0, a: buffer[i]); |
| 859 | } |
| 860 | |
| 861 | static const uint *QT_FASTCALL fetchAlpha8ToRGB32(uint *buffer, const uchar *src, int index, int count, |
| 862 | const QList<QRgb> *, QDitherInfo *) |
| 863 | { |
| 864 | for (int i = 0; i < count; ++i) |
| 865 | buffer[i] = qRgba(r: 0, g: 0, b: 0, a: src[index + i]); |
| 866 | return buffer; |
| 867 | } |
| 868 | |
| 869 | template<typename QRgba> |
| 870 | static const QRgba *QT_FASTCALL convertAlpha8To(QRgba *buffer, const uint *src, int count, |
| 871 | const QList<QRgb> *, QDitherInfo *) |
| 872 | { |
| 873 | for (int i = 0; i < count; ++i) |
| 874 | buffer[i] = QRgba::fromRgba(0, 0, 0, src[i]); |
| 875 | return buffer; |
| 876 | } |
| 877 | |
| 878 | template<typename QRgba> |
| 879 | static const QRgba *QT_FASTCALL fetchAlpha8To(QRgba *buffer, const uchar *src, int index, int count, |
| 880 | const QList<QRgb> *, QDitherInfo *) |
| 881 | { |
| 882 | for (int i = 0; i < count; ++i) |
| 883 | buffer[i] = QRgba::fromRgba(0, 0, 0, src[index + i]); |
| 884 | return buffer; |
| 885 | } |
| 886 | |
| 887 | static void QT_FASTCALL convertGrayscale8ToRGB32(uint *buffer, int count, const QList<QRgb> *) |
| 888 | { |
| 889 | for (int i = 0; i < count; ++i) { |
| 890 | const uint s = buffer[i]; |
| 891 | buffer[i] = qRgb(r: s, g: s, b: s); |
| 892 | } |
| 893 | } |
| 894 | |
| 895 | static const uint *QT_FASTCALL fetchGrayscale8ToRGB32(uint *buffer, const uchar *src, int index, int count, |
| 896 | const QList<QRgb> *, QDitherInfo *) |
| 897 | { |
| 898 | for (int i = 0; i < count; ++i) { |
| 899 | const uint s = src[index + i]; |
| 900 | buffer[i] = qRgb(r: s, g: s, b: s); |
| 901 | } |
| 902 | return buffer; |
| 903 | } |
| 904 | |
| 905 | template<typename QRgba> |
| 906 | static const QRgba *QT_FASTCALL convertGrayscale8To(QRgba *buffer, const uint *src, int count, |
| 907 | const QList<QRgb> *, QDitherInfo *) |
| 908 | { |
| 909 | for (int i = 0; i < count; ++i) |
| 910 | buffer[i] = QRgba::fromRgba(src[i], src[i], src[i], 255); |
| 911 | return buffer; |
| 912 | } |
| 913 | |
| 914 | template<typename QRgba> |
| 915 | static const QRgba *QT_FASTCALL fetchGrayscale8To(QRgba *buffer, const uchar *src, int index, int count, |
| 916 | const QList<QRgb> *, QDitherInfo *) |
| 917 | { |
| 918 | for (int i = 0; i < count; ++i) { |
| 919 | const uint s = src[index + i]; |
| 920 | buffer[i] = QRgba::fromRgba(s, s, s, 255); |
| 921 | } |
| 922 | return buffer; |
| 923 | } |
| 924 | |
| 925 | static void QT_FASTCALL convertGrayscale16ToRGB32(uint *buffer, int count, const QList<QRgb> *) |
| 926 | { |
| 927 | for (int i = 0; i < count; ++i) { |
| 928 | const uint x = qt_div_257(x: buffer[i]); |
| 929 | buffer[i] = qRgb(r: x, g: x, b: x); |
| 930 | } |
| 931 | } |
| 932 | static const uint *QT_FASTCALL fetchGrayscale16ToRGB32(uint *buffer, const uchar *src, int index, int count, |
| 933 | const QList<QRgb> *, QDitherInfo *) |
| 934 | { |
| 935 | const unsigned short *s = reinterpret_cast<const unsigned short *>(src) + index; |
| 936 | for (int i = 0; i < count; ++i) { |
| 937 | const uint x = qt_div_257(x: s[i]); |
| 938 | buffer[i] = qRgb(r: x, g: x, b: x); |
| 939 | } |
| 940 | return buffer; |
| 941 | } |
| 942 | |
| 943 | template<typename QRgba> |
| 944 | static const QRgba *QT_FASTCALL convertGrayscale16To(QRgba *buffer, const uint *src, int count, |
| 945 | const QList<QRgb> *, QDitherInfo *) |
| 946 | { |
| 947 | for (int i = 0; i < count; ++i) |
| 948 | buffer[i] = QRgba::fromRgba64(src[i], src[i], src[i], 65535); |
| 949 | return buffer; |
| 950 | } |
| 951 | |
| 952 | template<typename QRgba> |
| 953 | static const QRgba *QT_FASTCALL fetchGrayscale16To(QRgba *buffer, const uchar *src, int index, int count, |
| 954 | const QList<QRgb> *, QDitherInfo *) |
| 955 | { |
| 956 | const unsigned short *s = reinterpret_cast<const unsigned short *>(src) + index; |
| 957 | for (int i = 0; i < count; ++i) { |
| 958 | buffer[i] = QRgba::fromRgba64(s[i], s[i], s[i], 65535); |
| 959 | } |
| 960 | return buffer; |
| 961 | } |
| 962 | |
| 963 | static void QT_FASTCALL storeARGB32FromARGB32PM(uchar *dest, const uint *src, int index, int count, |
| 964 | const QList<QRgb> *, QDitherInfo *) |
| 965 | { |
| 966 | uint *d = reinterpret_cast<uint *>(dest) + index; |
| 967 | UNALIASED_CONVERSION_LOOP(d, src, count, [](uint c) { return qUnpremultiply(c); }); |
| 968 | } |
| 969 | |
| 970 | static void QT_FASTCALL storeRGBA8888PMFromARGB32PM(uchar *dest, const uint *src, int index, int count, |
| 971 | const QList<QRgb> *, QDitherInfo *) |
| 972 | { |
| 973 | uint *d = reinterpret_cast<uint *>(dest) + index; |
| 974 | UNALIASED_CONVERSION_LOOP(d, src, count, ARGB2RGBA); |
| 975 | } |
| 976 | |
| 977 | #ifdef __SSE2__ |
| 978 | template<bool RGBA, bool maskAlpha> |
| 979 | static inline void qConvertARGB32PMToRGBA64PM_sse2(QRgba64 *buffer, const uint *src, int count) |
| 980 | { |
| 981 | if (count <= 0) |
| 982 | return; |
| 983 | |
| 984 | const __m128i amask = _mm_set1_epi32(i: 0xff000000); |
| 985 | int i = 0; |
| 986 | for (; ((uintptr_t)buffer & 0xf) && i < count; ++i) { |
| 987 | uint s = *src++; |
| 988 | if (maskAlpha) |
| 989 | s = s | 0xff000000; |
| 990 | if (RGBA) |
| 991 | s = RGBA2ARGB(x: s); |
| 992 | *buffer++ = QRgba64::fromArgb32(rgb: s); |
| 993 | } |
| 994 | for (; i < count-3; i += 4) { |
| 995 | __m128i vs = _mm_loadu_si128(p: (const __m128i*)src); |
| 996 | if (maskAlpha) |
| 997 | vs = _mm_or_si128(a: vs, b: amask); |
| 998 | src += 4; |
| 999 | __m128i v1 = _mm_unpacklo_epi8(a: vs, b: vs); |
| 1000 | __m128i v2 = _mm_unpackhi_epi8(a: vs, b: vs); |
| 1001 | if (!RGBA) { |
| 1002 | v1 = _mm_shufflelo_epi16(v1, _MM_SHUFFLE(3, 0, 1, 2)); |
| 1003 | v2 = _mm_shufflelo_epi16(v2, _MM_SHUFFLE(3, 0, 1, 2)); |
| 1004 | v1 = _mm_shufflehi_epi16(v1, _MM_SHUFFLE(3, 0, 1, 2)); |
| 1005 | v2 = _mm_shufflehi_epi16(v2, _MM_SHUFFLE(3, 0, 1, 2)); |
| 1006 | } |
| 1007 | _mm_store_si128(p: (__m128i*)(buffer), b: v1); |
| 1008 | buffer += 2; |
| 1009 | _mm_store_si128(p: (__m128i*)(buffer), b: v2); |
| 1010 | buffer += 2; |
| 1011 | } |
| 1012 | |
| 1013 | SIMD_EPILOGUE(i, count, 3) { |
| 1014 | uint s = *src++; |
| 1015 | if (maskAlpha) |
| 1016 | s = s | 0xff000000; |
| 1017 | if (RGBA) |
| 1018 | s = RGBA2ARGB(x: s); |
| 1019 | *buffer++ = QRgba64::fromArgb32(rgb: s); |
| 1020 | } |
| 1021 | } |
| 1022 | |
| 1023 | template<QtPixelOrder PixelOrder> |
| 1024 | static inline void qConvertRGBA64PMToA2RGB30PM_sse2(uint *dest, const QRgba64 *buffer, int count) |
| 1025 | { |
| 1026 | const __m128i gmask = _mm_set1_epi32(i: 0x000ffc00); |
| 1027 | const __m128i cmask = _mm_set1_epi32(i: 0x000003ff); |
| 1028 | int i = 0; |
| 1029 | __m128i vr, vg, vb, va; |
| 1030 | for (; i < count && uintptr_t(buffer) & 0xF; ++i) { |
| 1031 | *dest++ = qConvertRgb64ToRgb30<PixelOrder>(*buffer++); |
| 1032 | } |
| 1033 | |
| 1034 | for (; i < count-15; i += 16) { |
| 1035 | // Repremultiplying is really expensive and hard to do in SIMD without AVX2, |
| 1036 | // so we try to avoid it by checking if it is needed 16 samples at a time. |
| 1037 | __m128i vOr = _mm_set1_epi32(i: 0); |
| 1038 | __m128i vAnd = _mm_set1_epi32(i: 0xffffffff); |
| 1039 | for (int j = 0; j < 16; j += 2) { |
| 1040 | __m128i vs = _mm_load_si128(p: (const __m128i*)(buffer + j)); |
| 1041 | vOr = _mm_or_si128(a: vOr, b: vs); |
| 1042 | vAnd = _mm_and_si128(a: vAnd, b: vs); |
| 1043 | } |
| 1044 | const quint16 orAlpha = ((uint)_mm_extract_epi16(vOr, 3)) | ((uint)_mm_extract_epi16(vOr, 7)); |
| 1045 | const quint16 andAlpha = ((uint)_mm_extract_epi16(vAnd, 3)) & ((uint)_mm_extract_epi16(vAnd, 7)); |
| 1046 | |
| 1047 | if (andAlpha == 0xffff) { |
| 1048 | for (int j = 0; j < 16; j += 2) { |
| 1049 | __m128i vs = _mm_load_si128(p: (const __m128i*)buffer); |
| 1050 | buffer += 2; |
| 1051 | vr = _mm_srli_epi64(a: vs, count: 6); |
| 1052 | vg = _mm_srli_epi64(a: vs, count: 16 + 6 - 10); |
| 1053 | vb = _mm_srli_epi64(a: vs, count: 32 + 6); |
| 1054 | vr = _mm_and_si128(a: vr, b: cmask); |
| 1055 | vg = _mm_and_si128(a: vg, b: gmask); |
| 1056 | vb = _mm_and_si128(a: vb, b: cmask); |
| 1057 | va = _mm_srli_epi64(a: vs, count: 48 + 14); |
| 1058 | if (PixelOrder == PixelOrderRGB) |
| 1059 | vr = _mm_slli_epi32(a: vr, count: 20); |
| 1060 | else |
| 1061 | vb = _mm_slli_epi32(a: vb, count: 20); |
| 1062 | va = _mm_slli_epi32(a: va, count: 30); |
| 1063 | __m128i vd = _mm_or_si128(a: _mm_or_si128(a: vr, b: vg), b: _mm_or_si128(a: vb, b: va)); |
| 1064 | vd = _mm_shuffle_epi32(vd, _MM_SHUFFLE(3, 1, 2, 0)); |
| 1065 | _mm_storel_epi64(p: (__m128i*)dest, a: vd); |
| 1066 | dest += 2; |
| 1067 | } |
| 1068 | } else if (orAlpha == 0) { |
| 1069 | for (int j = 0; j < 16; ++j) { |
| 1070 | *dest++ = 0; |
| 1071 | buffer++; |
| 1072 | } |
| 1073 | } else { |
| 1074 | for (int j = 0; j < 16; ++j) |
| 1075 | *dest++ = qConvertRgb64ToRgb30<PixelOrder>(*buffer++); |
| 1076 | } |
| 1077 | } |
| 1078 | |
| 1079 | SIMD_EPILOGUE(i, count, 15) |
| 1080 | *dest++ = qConvertRgb64ToRgb30<PixelOrder>(*buffer++); |
| 1081 | } |
| 1082 | #elif defined(__ARM_NEON__) |
| 1083 | template<bool RGBA, bool maskAlpha> |
| 1084 | static inline void qConvertARGB32PMToRGBA64PM_neon(QRgba64 *buffer, const uint *src, int count) |
| 1085 | { |
| 1086 | if (count <= 0) |
| 1087 | return; |
| 1088 | |
| 1089 | const uint32x4_t amask = vdupq_n_u32(0xff000000); |
| 1090 | #if defined(Q_PROCESSOR_ARM_64) |
| 1091 | const uint8x16_t rgbaMask = qvsetq_n_u8(2, 1, 0, 3, 6, 5, 4, 7, 10, 9, 8, 11, 14, 13, 12, 15); |
| 1092 | #else |
| 1093 | const uint8x8_t rgbaMask = qvset_n_u8(2, 1, 0, 3, 6, 5, 4, 7); |
| 1094 | #endif |
| 1095 | int i = 0; |
| 1096 | for (; i < count-3; i += 4) { |
| 1097 | uint32x4_t vs32 = vld1q_u32(src); |
| 1098 | src += 4; |
| 1099 | if (maskAlpha) |
| 1100 | vs32 = vorrq_u32(vs32, amask); |
| 1101 | uint8x16_t vs8 = vreinterpretq_u8_u32(vs32); |
| 1102 | if (!RGBA) { |
| 1103 | #if defined(Q_PROCESSOR_ARM_64) |
| 1104 | vs8 = vqtbl1q_u8(vs8, rgbaMask); |
| 1105 | #else |
| 1106 | // no vqtbl1q_u8 |
| 1107 | const uint8x8_t vlo = vtbl1_u8(vget_low_u8(vs8), rgbaMask); |
| 1108 | const uint8x8_t vhi = vtbl1_u8(vget_high_u8(vs8), rgbaMask); |
| 1109 | vs8 = vcombine_u8(vlo, vhi); |
| 1110 | #endif |
| 1111 | } |
| 1112 | uint8x16x2_t v = vzipq_u8(vs8, vs8); |
| 1113 | |
| 1114 | vst1q_u16((uint16_t *)buffer, vreinterpretq_u16_u8(v.val[0])); |
| 1115 | buffer += 2; |
| 1116 | vst1q_u16((uint16_t *)buffer, vreinterpretq_u16_u8(v.val[1])); |
| 1117 | buffer += 2; |
| 1118 | } |
| 1119 | |
| 1120 | SIMD_EPILOGUE(i, count, 3) { |
| 1121 | uint s = *src++; |
| 1122 | if (maskAlpha) |
| 1123 | s = s | 0xff000000; |
| 1124 | if (RGBA) |
| 1125 | s = RGBA2ARGB(s); |
| 1126 | *buffer++ = QRgba64::fromArgb32(s); |
| 1127 | } |
| 1128 | } |
| 1129 | #endif |
| 1130 | |
| 1131 | static const QRgba64 *QT_FASTCALL convertRGB32ToRGB64(QRgba64 *buffer, const uint *src, int count, |
| 1132 | const QList<QRgb> *, QDitherInfo *) |
| 1133 | { |
| 1134 | #ifdef __SSE2__ |
| 1135 | qConvertARGB32PMToRGBA64PM_sse2<false, true>(buffer, src, count); |
| 1136 | #elif defined(__ARM_NEON__) |
| 1137 | qConvertARGB32PMToRGBA64PM_neon<false, true>(buffer, src, count); |
| 1138 | #else |
| 1139 | for (int i = 0; i < count; ++i) |
| 1140 | buffer[i] = QRgba64::fromArgb32(0xff000000 | src[i]); |
| 1141 | #endif |
| 1142 | return buffer; |
| 1143 | } |
| 1144 | |
| 1145 | static const QRgba64 *QT_FASTCALL fetchRGB32ToRGB64(QRgba64 *buffer, const uchar *src, int index, int count, |
| 1146 | const QList<QRgb> *, QDitherInfo *) |
| 1147 | { |
| 1148 | return convertRGB32ToRGB64(buffer, src: reinterpret_cast<const uint *>(src) + index, count, nullptr, nullptr); |
| 1149 | } |
| 1150 | |
| 1151 | static const QRgba64 *QT_FASTCALL convertARGB32ToRGBA64PM(QRgba64 *buffer, const uint *src, int count, |
| 1152 | const QList<QRgb> *, QDitherInfo *) |
| 1153 | { |
| 1154 | for (int i = 0; i < count; ++i) |
| 1155 | buffer[i] = QRgba64::fromArgb32(rgb: src[i]).premultiplied(); |
| 1156 | return buffer; |
| 1157 | } |
| 1158 | |
| 1159 | static const QRgba64 *QT_FASTCALL fetchARGB32ToRGBA64PM(QRgba64 *buffer, const uchar *src, int index, int count, |
| 1160 | const QList<QRgb> *, QDitherInfo *) |
| 1161 | { |
| 1162 | return convertARGB32ToRGBA64PM(buffer, src: reinterpret_cast<const uint *>(src) + index, count, nullptr, nullptr); |
| 1163 | } |
| 1164 | |
| 1165 | static const QRgba64 *QT_FASTCALL convertARGB32PMToRGBA64PM(QRgba64 *buffer, const uint *src, int count, |
| 1166 | const QList<QRgb> *, QDitherInfo *) |
| 1167 | { |
| 1168 | #ifdef __SSE2__ |
| 1169 | qConvertARGB32PMToRGBA64PM_sse2<false, false>(buffer, src, count); |
| 1170 | #elif defined(__ARM_NEON__) |
| 1171 | qConvertARGB32PMToRGBA64PM_neon<false, false>(buffer, src, count); |
| 1172 | #else |
| 1173 | for (int i = 0; i < count; ++i) |
| 1174 | buffer[i] = QRgba64::fromArgb32(src[i]); |
| 1175 | #endif |
| 1176 | return buffer; |
| 1177 | } |
| 1178 | |
| 1179 | static const QRgba64 *QT_FASTCALL fetchARGB32PMToRGBA64PM(QRgba64 *buffer, const uchar *src, int index, int count, |
| 1180 | const QList<QRgb> *, QDitherInfo *) |
| 1181 | { |
| 1182 | return convertARGB32PMToRGBA64PM(buffer, src: reinterpret_cast<const uint *>(src) + index, count, nullptr, nullptr); |
| 1183 | } |
| 1184 | |
| 1185 | static const QRgba64 *QT_FASTCALL fetchRGBA64ToRGBA64PM(QRgba64 *buffer, const uchar *src, int index, int count, |
| 1186 | const QList<QRgb> *, QDitherInfo *) |
| 1187 | { |
| 1188 | const QRgba64 *s = reinterpret_cast<const QRgba64 *>(src) + index; |
| 1189 | #ifdef __SSE2__ |
| 1190 | for (int i = 0; i < count; ++i) { |
| 1191 | const auto a = s[i].alpha(); |
| 1192 | __m128i vs = _mm_loadl_epi64(p: (const __m128i *)(s + i)); |
| 1193 | __m128i va = _mm_shufflelo_epi16(vs, _MM_SHUFFLE(3, 3, 3, 3)); |
| 1194 | vs = multiplyAlpha65535(rgba64: vs, va); |
| 1195 | _mm_storel_epi64(p: (__m128i *)(buffer + i), a: vs); |
| 1196 | buffer[i].setAlpha(a); |
| 1197 | } |
| 1198 | #else |
| 1199 | for (int i = 0; i < count; ++i) |
| 1200 | buffer[i] = QRgba64::fromRgba64(s[i]).premultiplied(); |
| 1201 | #endif |
| 1202 | return buffer; |
| 1203 | } |
| 1204 | |
| 1205 | static const QRgba64 *QT_FASTCALL convertRGBA8888ToRGBA64PM(QRgba64 *buffer, const uint *src, int count, |
| 1206 | const QList<QRgb> *, QDitherInfo *) |
| 1207 | { |
| 1208 | for (int i = 0; i < count; ++i) |
| 1209 | buffer[i] = QRgba64::fromArgb32(rgb: RGBA2ARGB(x: src[i])).premultiplied(); |
| 1210 | return buffer; |
| 1211 | } |
| 1212 | |
| 1213 | static const QRgba64 *QT_FASTCALL fetchRGBA8888ToRGBA64PM(QRgba64 *buffer, const uchar *src, int index, int count, |
| 1214 | const QList<QRgb> *, QDitherInfo *) |
| 1215 | { |
| 1216 | return convertRGBA8888ToRGBA64PM(buffer, src: reinterpret_cast<const uint *>(src) + index, count, nullptr, nullptr); |
| 1217 | } |
| 1218 | |
| 1219 | static const QRgba64 *QT_FASTCALL convertRGBA8888PMToRGBA64PM(QRgba64 *buffer, const uint *src, int count, |
| 1220 | const QList<QRgb> *, QDitherInfo *) |
| 1221 | { |
| 1222 | #ifdef __SSE2__ |
| 1223 | qConvertARGB32PMToRGBA64PM_sse2<true, false>(buffer, src, count); |
| 1224 | #elif defined(__ARM_NEON__) |
| 1225 | qConvertARGB32PMToRGBA64PM_neon<true, false>(buffer, src, count); |
| 1226 | #else |
| 1227 | for (int i = 0; i < count; ++i) |
| 1228 | buffer[i] = QRgba64::fromArgb32(RGBA2ARGB(src[i])); |
| 1229 | #endif |
| 1230 | return buffer; |
| 1231 | } |
| 1232 | |
| 1233 | static const QRgba64 *QT_FASTCALL fetchRGBA8888PMToRGBA64PM(QRgba64 *buffer, const uchar *src, int index, int count, |
| 1234 | const QList<QRgb> *, QDitherInfo *) |
| 1235 | { |
| 1236 | return convertRGBA8888PMToRGBA64PM(buffer, src: reinterpret_cast<const uint *>(src) + index, count, nullptr, nullptr); |
| 1237 | } |
| 1238 | |
| 1239 | static void QT_FASTCALL storeRGBA8888FromARGB32PM(uchar *dest, const uint *src, int index, int count, |
| 1240 | const QList<QRgb> *, QDitherInfo *) |
| 1241 | { |
| 1242 | uint *d = reinterpret_cast<uint *>(dest) + index; |
| 1243 | UNALIASED_CONVERSION_LOOP(d, src, count, [](uint c) { return ARGB2RGBA(qUnpremultiply(c)); }); |
| 1244 | } |
| 1245 | |
| 1246 | static void QT_FASTCALL storeRGBXFromRGB32(uchar *dest, const uint *src, int index, int count, |
| 1247 | const QList<QRgb> *, QDitherInfo *) |
| 1248 | { |
| 1249 | uint *d = reinterpret_cast<uint *>(dest) + index; |
| 1250 | UNALIASED_CONVERSION_LOOP(d, src, count, [](uint c) { return ARGB2RGBA(0xff000000 | c); }); |
| 1251 | } |
| 1252 | |
| 1253 | static void QT_FASTCALL storeRGBXFromARGB32PM(uchar *dest, const uint *src, int index, int count, |
| 1254 | const QList<QRgb> *, QDitherInfo *) |
| 1255 | { |
| 1256 | uint *d = reinterpret_cast<uint *>(dest) + index; |
| 1257 | UNALIASED_CONVERSION_LOOP(d, src, count, [](uint c) { return ARGB2RGBA(0xff000000 | qUnpremultiply(c)); }); |
| 1258 | } |
| 1259 | |
| 1260 | template<QtPixelOrder PixelOrder> |
| 1261 | static void QT_FASTCALL convertA2RGB30PMToARGB32PM(uint *buffer, int count, const QList<QRgb> *) |
| 1262 | { |
| 1263 | for (int i = 0; i < count; ++i) |
| 1264 | buffer[i] = qConvertA2rgb30ToArgb32<PixelOrder>(buffer[i]); |
| 1265 | } |
| 1266 | |
| 1267 | template<QtPixelOrder PixelOrder> |
| 1268 | static const uint *QT_FASTCALL fetchA2RGB30PMToARGB32PM(uint *buffer, const uchar *s, int index, int count, |
| 1269 | const QList<QRgb> *, QDitherInfo *dither) |
| 1270 | { |
| 1271 | const uint *src = reinterpret_cast<const uint *>(s) + index; |
| 1272 | if (!dither) { |
| 1273 | UNALIASED_CONVERSION_LOOP(buffer, src, count, qConvertA2rgb30ToArgb32<PixelOrder>); |
| 1274 | } else { |
| 1275 | for (int i = 0; i < count; ++i) { |
| 1276 | const uint c = src[i]; |
| 1277 | short d10 = (qt_bayer_matrix[dither->y & 15][(dither->x + i) & 15] << 2); |
| 1278 | short a10 = (c >> 30) * 0x155; |
| 1279 | short r10 = ((c >> 20) & 0x3ff); |
| 1280 | short g10 = ((c >> 10) & 0x3ff); |
| 1281 | short b10 = (c & 0x3ff); |
| 1282 | if (PixelOrder == PixelOrderBGR) |
| 1283 | std::swap(a&: r10, b&: b10); |
| 1284 | short a8 = (a10 + ((d10 - a10) >> 8)) >> 2; |
| 1285 | short r8 = (r10 + ((d10 - r10) >> 8)) >> 2; |
| 1286 | short g8 = (g10 + ((d10 - g10) >> 8)) >> 2; |
| 1287 | short b8 = (b10 + ((d10 - b10) >> 8)) >> 2; |
| 1288 | buffer[i] = qRgba(r: r8, g: g8, b: b8, a: a8); |
| 1289 | } |
| 1290 | } |
| 1291 | return buffer; |
| 1292 | } |
| 1293 | |
| 1294 | #ifdef __SSE2__ |
| 1295 | template<QtPixelOrder PixelOrder> |
| 1296 | static inline void qConvertA2RGB30PMToRGBA64PM_sse2(QRgba64 *buffer, const uint *src, int count) |
| 1297 | { |
| 1298 | if (count <= 0) |
| 1299 | return; |
| 1300 | |
| 1301 | const __m128i rmask = _mm_set1_epi32(i: 0x3ff00000); |
| 1302 | const __m128i gmask = _mm_set1_epi32(i: 0x000ffc00); |
| 1303 | const __m128i bmask = _mm_set1_epi32(i: 0x000003ff); |
| 1304 | const __m128i afactor = _mm_set1_epi16(w: 0x5555); |
| 1305 | int i = 0; |
| 1306 | |
| 1307 | for (; ((uintptr_t)buffer & 0xf) && i < count; ++i) |
| 1308 | *buffer++ = qConvertA2rgb30ToRgb64<PixelOrder>(*src++); |
| 1309 | |
| 1310 | for (; i < count-3; i += 4) { |
| 1311 | __m128i vs = _mm_loadu_si128(p: (const __m128i*)src); |
| 1312 | src += 4; |
| 1313 | __m128i va = _mm_srli_epi32(a: vs, count: 30); |
| 1314 | __m128i vr = _mm_and_si128(a: vs, b: rmask); |
| 1315 | __m128i vb = _mm_and_si128(a: vs, b: bmask); |
| 1316 | __m128i vg = _mm_and_si128(a: vs, b: gmask); |
| 1317 | va = _mm_mullo_epi16(a: va, b: afactor); |
| 1318 | vr = _mm_or_si128(a: _mm_srli_epi32(a: vr, count: 14), b: _mm_srli_epi32(a: vr, count: 24)); |
| 1319 | vg = _mm_or_si128(a: _mm_srli_epi32(a: vg, count: 4), b: _mm_srli_epi32(a: vg, count: 14)); |
| 1320 | vb = _mm_or_si128(a: _mm_slli_epi32(a: vb, count: 6), b: _mm_srli_epi32(a: vb, count: 4)); |
| 1321 | __m128i vrb; |
| 1322 | if (PixelOrder == PixelOrderRGB) |
| 1323 | vrb = _mm_or_si128(a: vr, _mm_slli_si128(vb, 2)); |
| 1324 | else |
| 1325 | vrb = _mm_or_si128(a: vb, _mm_slli_si128(vr, 2)); |
| 1326 | __m128i vga = _mm_or_si128(a: vg, _mm_slli_si128(va, 2)); |
| 1327 | _mm_store_si128(p: (__m128i*)(buffer), b: _mm_unpacklo_epi16(a: vrb, b: vga)); |
| 1328 | buffer += 2; |
| 1329 | _mm_store_si128(p: (__m128i*)(buffer), b: _mm_unpackhi_epi16(a: vrb, b: vga)); |
| 1330 | buffer += 2; |
| 1331 | } |
| 1332 | |
| 1333 | SIMD_EPILOGUE(i, count, 3) |
| 1334 | *buffer++ = qConvertA2rgb30ToRgb64<PixelOrder>(*src++); |
| 1335 | } |
| 1336 | #endif |
| 1337 | |
| 1338 | template<QtPixelOrder PixelOrder> |
| 1339 | static const QRgba64 *QT_FASTCALL convertA2RGB30PMToRGBA64PM(QRgba64 *buffer, const uint *src, int count, |
| 1340 | const QList<QRgb> *, QDitherInfo *) |
| 1341 | { |
| 1342 | #ifdef __SSE2__ |
| 1343 | qConvertA2RGB30PMToRGBA64PM_sse2<PixelOrder>(buffer, src, count); |
| 1344 | #else |
| 1345 | for (int i = 0; i < count; ++i) |
| 1346 | buffer[i] = qConvertA2rgb30ToRgb64<PixelOrder>(src[i]); |
| 1347 | #endif |
| 1348 | return buffer; |
| 1349 | } |
| 1350 | |
| 1351 | template<QtPixelOrder PixelOrder> |
| 1352 | static const QRgba64 *QT_FASTCALL fetchA2RGB30PMToRGBA64PM(QRgba64 *buffer, const uchar *src, int index, int count, |
| 1353 | const QList<QRgb> *, QDitherInfo *) |
| 1354 | { |
| 1355 | return convertA2RGB30PMToRGBA64PM<PixelOrder>(buffer, reinterpret_cast<const uint *>(src) + index, count, nullptr, nullptr); |
| 1356 | } |
| 1357 | |
| 1358 | template<enum QtPixelOrder> inline QRgbaFloat32 qConvertA2rgb30ToRgbaFP(uint rgb); |
| 1359 | |
| 1360 | template<> |
| 1361 | inline QRgbaFloat32 qConvertA2rgb30ToRgbaFP<PixelOrderBGR>(uint rgb) |
| 1362 | { |
| 1363 | float alpha = (rgb >> 30) * (1.f/3.f); |
| 1364 | float blue = ((rgb >> 20) & 0x3ff) * (1.f/1023.f); |
| 1365 | float green = ((rgb >> 10) & 0x3ff) * (1.f/1023.f); |
| 1366 | float red = (rgb & 0x3ff) * (1.f/1023.f); |
| 1367 | return QRgbaFloat32{ .r: red, .g: green, .b: blue, .a: alpha }; |
| 1368 | } |
| 1369 | |
| 1370 | template<> |
| 1371 | inline QRgbaFloat32 qConvertA2rgb30ToRgbaFP<PixelOrderRGB>(uint rgb) |
| 1372 | { |
| 1373 | float alpha = (rgb >> 30) * (1.f/3.f); |
| 1374 | float red = ((rgb >> 20) & 0x3ff) * (1.f/1023.f); |
| 1375 | float green = ((rgb >> 10) & 0x3ff) * (1.f/1023.f); |
| 1376 | float blue = (rgb & 0x3ff) * (1.f/1023.f); |
| 1377 | return QRgbaFloat32{ .r: red, .g: green, .b: blue, .a: alpha }; |
| 1378 | } |
| 1379 | |
| 1380 | template<QtPixelOrder PixelOrder> |
| 1381 | static const QRgbaFloat32 *QT_FASTCALL convertA2RGB30PMToRGBA32F(QRgbaFloat32 *buffer, const uint *src, int count, |
| 1382 | const QList<QRgb> *, QDitherInfo *) |
| 1383 | { |
| 1384 | for (int i = 0; i < count; ++i) |
| 1385 | buffer[i] = qConvertA2rgb30ToRgbaFP<PixelOrder>(src[i]); |
| 1386 | return buffer; |
| 1387 | } |
| 1388 | |
| 1389 | template<QtPixelOrder PixelOrder> |
| 1390 | static const QRgbaFloat32 *QT_FASTCALL fetchRGB30ToRGBA32F(QRgbaFloat32 *buffer, const uchar *src, int index, int count, |
| 1391 | const QList<QRgb> *, QDitherInfo *) |
| 1392 | { |
| 1393 | return convertA2RGB30PMToRGBA32F<PixelOrder>(buffer, reinterpret_cast<const uint *>(src) + index, count, nullptr, nullptr); |
| 1394 | } |
| 1395 | |
| 1396 | template<QtPixelOrder PixelOrder> |
| 1397 | static void QT_FASTCALL storeA2RGB30PMFromARGB32PM(uchar *dest, const uint *src, int index, int count, |
| 1398 | const QList<QRgb> *, QDitherInfo *) |
| 1399 | { |
| 1400 | uint *d = reinterpret_cast<uint *>(dest) + index; |
| 1401 | UNALIASED_CONVERSION_LOOP(d, src, count, qConvertArgb32ToA2rgb30<PixelOrder>); |
| 1402 | } |
| 1403 | |
| 1404 | template<QtPixelOrder PixelOrder> |
| 1405 | static void QT_FASTCALL storeRGB30FromRGB32(uchar *dest, const uint *src, int index, int count, |
| 1406 | const QList<QRgb> *, QDitherInfo *) |
| 1407 | { |
| 1408 | uint *d = reinterpret_cast<uint *>(dest) + index; |
| 1409 | UNALIASED_CONVERSION_LOOP(d, src, count, qConvertRgb32ToRgb30<PixelOrder>); |
| 1410 | } |
| 1411 | |
| 1412 | template<QtPixelOrder PixelOrder> |
| 1413 | static void QT_FASTCALL storeRGB30FromARGB32PM(uchar *dest, const uint *src, int index, int count, |
| 1414 | const QList<QRgb> *, QDitherInfo *) |
| 1415 | { |
| 1416 | uint *d = reinterpret_cast<uint *>(dest) + index; |
| 1417 | UNALIASED_CONVERSION_LOOP(d, src, count, qConvertRgb32ToRgb30<PixelOrder>); |
| 1418 | } |
| 1419 | |
| 1420 | template<bool RGBA> |
| 1421 | void qt_convertRGBA64ToARGB32(uint *dst, const QRgba64 *src, int count) |
| 1422 | { |
| 1423 | int i = 0; |
| 1424 | #ifdef __SSE2__ |
| 1425 | if (((uintptr_t)dst & 0x7) && count > 0) { |
| 1426 | uint s = (*src++).toArgb32(); |
| 1427 | if (RGBA) |
| 1428 | s = ARGB2RGBA(x: s); |
| 1429 | *dst++ = s; |
| 1430 | i++; |
| 1431 | } |
| 1432 | const __m128i vhalf = _mm_set1_epi32(i: 0x80); |
| 1433 | const __m128i vzero = _mm_setzero_si128(); |
| 1434 | for (; i < count-1; i += 2) { |
| 1435 | __m128i vs = _mm_loadu_si128(p: (const __m128i*)src); |
| 1436 | src += 2; |
| 1437 | if (!RGBA) { |
| 1438 | vs = _mm_shufflelo_epi16(vs, _MM_SHUFFLE(3, 0, 1, 2)); |
| 1439 | vs = _mm_shufflehi_epi16(vs, _MM_SHUFFLE(3, 0, 1, 2)); |
| 1440 | } |
| 1441 | __m128i v1 = _mm_unpacklo_epi16(a: vs, b: vzero); |
| 1442 | __m128i v2 = _mm_unpackhi_epi16(a: vs, b: vzero); |
| 1443 | v1 = _mm_add_epi32(a: v1, b: vhalf); |
| 1444 | v2 = _mm_add_epi32(a: v2, b: vhalf); |
| 1445 | v1 = _mm_sub_epi32(a: v1, b: _mm_srli_epi32(a: v1, count: 8)); |
| 1446 | v2 = _mm_sub_epi32(a: v2, b: _mm_srli_epi32(a: v2, count: 8)); |
| 1447 | v1 = _mm_srli_epi32(a: v1, count: 8); |
| 1448 | v2 = _mm_srli_epi32(a: v2, count: 8); |
| 1449 | v1 = _mm_packs_epi32(a: v1, b: v2); |
| 1450 | v1 = _mm_packus_epi16(a: v1, b: vzero); |
| 1451 | _mm_storel_epi64(p: (__m128i*)(dst), a: v1); |
| 1452 | dst += 2; |
| 1453 | } |
| 1454 | #endif |
| 1455 | for (; i < count; i++) { |
| 1456 | uint s = (*src++).toArgb32(); |
| 1457 | if (RGBA) |
| 1458 | s = ARGB2RGBA(x: s); |
| 1459 | *dst++ = s; |
| 1460 | } |
| 1461 | } |
| 1462 | template void qt_convertRGBA64ToARGB32<false>(uint *dst, const QRgba64 *src, int count); |
| 1463 | template void qt_convertRGBA64ToARGB32<true>(uint *dst, const QRgba64 *src, int count); |
| 1464 | |
| 1465 | |
| 1466 | static void QT_FASTCALL storeAlpha8FromARGB32PM(uchar *dest, const uint *src, int index, int count, |
| 1467 | const QList<QRgb> *, QDitherInfo *) |
| 1468 | { |
| 1469 | for (int i = 0; i < count; ++i) |
| 1470 | dest[index + i] = qAlpha(rgb: src[i]); |
| 1471 | } |
| 1472 | |
| 1473 | static void QT_FASTCALL storeGrayscale8FromRGB32(uchar *dest, const uint *src, int index, int count, |
| 1474 | const QList<QRgb> *, QDitherInfo *) |
| 1475 | { |
| 1476 | for (int i = 0; i < count; ++i) |
| 1477 | dest[index + i] = qGray(rgb: src[i]); |
| 1478 | } |
| 1479 | |
| 1480 | static void QT_FASTCALL storeGrayscale8FromARGB32PM(uchar *dest, const uint *src, int index, int count, |
| 1481 | const QList<QRgb> *, QDitherInfo *) |
| 1482 | { |
| 1483 | for (int i = 0; i < count; ++i) |
| 1484 | dest[index + i] = qGray(rgb: qUnpremultiply(p: src[i])); |
| 1485 | } |
| 1486 | |
| 1487 | static void QT_FASTCALL storeGrayscale16FromRGB32(uchar *dest, const uint *src, int index, int count, |
| 1488 | const QList<QRgb> *, QDitherInfo *) |
| 1489 | { |
| 1490 | unsigned short *d = reinterpret_cast<unsigned short *>(dest) + index; |
| 1491 | for (int i = 0; i < count; ++i) |
| 1492 | d[i] = qGray(rgb: src[i]) * 257; |
| 1493 | } |
| 1494 | |
| 1495 | static void QT_FASTCALL storeGrayscale16FromARGB32PM(uchar *dest, const uint *src, int index, int count, |
| 1496 | const QList<QRgb> *, QDitherInfo *) |
| 1497 | { |
| 1498 | unsigned short *d = reinterpret_cast<unsigned short *>(dest) + index; |
| 1499 | for (int i = 0; i < count; ++i) |
| 1500 | d[i] = qGray(rgb: qUnpremultiply(p: src[i])) * 257; |
| 1501 | } |
| 1502 | |
| 1503 | static const uint *QT_FASTCALL fetchRGB64ToRGB32(uint *buffer, const uchar *src, int index, int count, |
| 1504 | const QList<QRgb> *, QDitherInfo *) |
| 1505 | { |
| 1506 | const QRgba64 *s = reinterpret_cast<const QRgba64 *>(src) + index; |
| 1507 | for (int i = 0; i < count; ++i) |
| 1508 | buffer[i] = toArgb32(rgba64: s[i]); |
| 1509 | return buffer; |
| 1510 | } |
| 1511 | |
| 1512 | static void QT_FASTCALL storeRGB64FromRGB32(uchar *dest, const uint *src, int index, int count, |
| 1513 | const QList<QRgb> *, QDitherInfo *) |
| 1514 | { |
| 1515 | QRgba64 *d = reinterpret_cast<QRgba64 *>(dest) + index; |
| 1516 | for (int i = 0; i < count; ++i) |
| 1517 | d[i] = QRgba64::fromArgb32(rgb: src[i] | 0xff000000); |
| 1518 | } |
| 1519 | |
| 1520 | static const uint *QT_FASTCALL fetchRGBA64ToARGB32PM(uint *buffer, const uchar *src, int index, int count, |
| 1521 | const QList<QRgb> *, QDitherInfo *) |
| 1522 | { |
| 1523 | const QRgba64 *s = reinterpret_cast<const QRgba64 *>(src) + index; |
| 1524 | for (int i = 0; i < count; ++i) |
| 1525 | buffer[i] = toArgb32(rgba64: s[i].premultiplied()); |
| 1526 | return buffer; |
| 1527 | } |
| 1528 | |
| 1529 | template<bool Mask> |
| 1530 | static void QT_FASTCALL storeRGBA64FromARGB32PM(uchar *dest, const uint *src, int index, int count, |
| 1531 | const QList<QRgb> *, QDitherInfo *) |
| 1532 | { |
| 1533 | QRgba64 *d = reinterpret_cast<QRgba64 *>(dest) + index; |
| 1534 | for (int i = 0; i < count; ++i) { |
| 1535 | d[i] = QRgba64::fromArgb32(rgb: src[i]).unpremultiplied(); |
| 1536 | if (Mask) |
| 1537 | d[i].setAlpha(65535); |
| 1538 | } |
| 1539 | } |
| 1540 | |
| 1541 | static void QT_FASTCALL storeRGBA64FromARGB32(uchar *dest, const uint *src, int index, int count, |
| 1542 | const QList<QRgb> *, QDitherInfo *) |
| 1543 | { |
| 1544 | QRgba64 *d = reinterpret_cast<QRgba64 *>(dest) + index; |
| 1545 | for (int i = 0; i < count; ++i) |
| 1546 | d[i] = QRgba64::fromArgb32(rgb: src[i]); |
| 1547 | } |
| 1548 | |
| 1549 | static const uint *QT_FASTCALL fetchRGB16FToRGB32(uint *buffer, const uchar *src, int index, int count, |
| 1550 | const QList<QRgb> *, QDitherInfo *) |
| 1551 | { |
| 1552 | const QRgbaFloat16 *s = reinterpret_cast<const QRgbaFloat16 *>(src) + index; |
| 1553 | for (int i = 0; i < count; ++i) |
| 1554 | buffer[i] = s[i].toArgb32(); |
| 1555 | return buffer; |
| 1556 | } |
| 1557 | |
| 1558 | static void QT_FASTCALL storeRGB16FFromRGB32(uchar *dest, const uint *src, int index, int count, |
| 1559 | const QList<QRgb> *, QDitherInfo *) |
| 1560 | { |
| 1561 | QRgbaFloat16 *d = reinterpret_cast<QRgbaFloat16 *>(dest) + index; |
| 1562 | for (int i = 0; i < count; ++i) |
| 1563 | d[i] = QRgbaFloat16::fromArgb32(rgb: src[i]); |
| 1564 | } |
| 1565 | |
| 1566 | static const uint *QT_FASTCALL fetchRGBA16FToARGB32PM(uint *buffer, const uchar *src, int index, int count, |
| 1567 | const QList<QRgb> *, QDitherInfo *) |
| 1568 | { |
| 1569 | const QRgbaFloat16 *s = reinterpret_cast<const QRgbaFloat16 *>(src) + index; |
| 1570 | for (int i = 0; i < count; ++i) |
| 1571 | buffer[i] = s[i].premultiplied().toArgb32(); |
| 1572 | return buffer; |
| 1573 | } |
| 1574 | |
| 1575 | static const QRgba64 *QT_FASTCALL fetchRGBA16FToRGBA64PM(QRgba64 *buffer, const uchar *src, int index, int count, |
| 1576 | const QList<QRgb> *, QDitherInfo *) |
| 1577 | { |
| 1578 | const QRgbaFloat16 *s = reinterpret_cast<const QRgbaFloat16 *>(src) + index; |
| 1579 | for (int i = 0; i < count; ++i) { |
| 1580 | QRgbaFloat16 c = s[i].premultiplied(); |
| 1581 | buffer[i] = QRgba64::fromRgba64(red: c.red16(), green: c.green16(), blue: c.blue16(), alpha: c.alpha16()); |
| 1582 | } |
| 1583 | return buffer; |
| 1584 | } |
| 1585 | |
| 1586 | static void QT_FASTCALL storeRGBA16FFromARGB32PM(uchar *dest, const uint *src, int index, int count, |
| 1587 | const QList<QRgb> *, QDitherInfo *) |
| 1588 | { |
| 1589 | QRgbaFloat16 *d = reinterpret_cast<QRgbaFloat16 *>(dest) + index; |
| 1590 | for (int i = 0; i < count; ++i) |
| 1591 | d[i] = QRgbaFloat16::fromArgb32(rgb: src[i]).unpremultiplied(); |
| 1592 | } |
| 1593 | |
| 1594 | static const QRgba64 *QT_FASTCALL fetchRGBA16FPMToRGBA64PM(QRgba64 *buffer, const uchar *src, int index, int count, |
| 1595 | const QList<QRgb> *, QDitherInfo *) |
| 1596 | { |
| 1597 | const QRgbaFloat16 *s = reinterpret_cast<const QRgbaFloat16 *>(src) + index; |
| 1598 | for (int i = 0; i < count; ++i) { |
| 1599 | QRgbaFloat16 c = s[i]; |
| 1600 | buffer[i] = QRgba64::fromRgba64(red: c.red16(), green: c.green16(), blue: c.blue16(), alpha: c.alpha16()); |
| 1601 | } |
| 1602 | return buffer; |
| 1603 | } |
| 1604 | |
| 1605 | static const uint *QT_FASTCALL fetchRGB32FToRGB32(uint *buffer, const uchar *src, int index, int count, |
| 1606 | const QList<QRgb> *, QDitherInfo *) |
| 1607 | { |
| 1608 | const QRgbaFloat32 *s = reinterpret_cast<const QRgbaFloat32 *>(src) + index; |
| 1609 | for (int i = 0; i < count; ++i) |
| 1610 | buffer[i] = s[i].toArgb32(); |
| 1611 | return buffer; |
| 1612 | } |
| 1613 | |
| 1614 | static void QT_FASTCALL storeRGB32FFromRGB32(uchar *dest, const uint *src, int index, int count, |
| 1615 | const QList<QRgb> *, QDitherInfo *) |
| 1616 | { |
| 1617 | QRgbaFloat32 *d = reinterpret_cast<QRgbaFloat32 *>(dest) + index; |
| 1618 | for (int i = 0; i < count; ++i) |
| 1619 | d[i] = QRgbaFloat32::fromArgb32(rgb: src[i]); |
| 1620 | } |
| 1621 | |
| 1622 | static const uint *QT_FASTCALL fetchRGBA32FToARGB32PM(uint *buffer, const uchar *src, int index, int count, |
| 1623 | const QList<QRgb> *, QDitherInfo *) |
| 1624 | { |
| 1625 | const QRgbaFloat32 *s = reinterpret_cast<const QRgbaFloat32 *>(src) + index; |
| 1626 | for (int i = 0; i < count; ++i) |
| 1627 | buffer[i] = s[i].premultiplied().toArgb32(); |
| 1628 | return buffer; |
| 1629 | } |
| 1630 | |
| 1631 | static const QRgba64 *QT_FASTCALL fetchRGBA32FToRGBA64PM(QRgba64 *buffer, const uchar *src, int index, int count, |
| 1632 | const QList<QRgb> *, QDitherInfo *) |
| 1633 | { |
| 1634 | const QRgbaFloat32 *s = reinterpret_cast<const QRgbaFloat32 *>(src) + index; |
| 1635 | for (int i = 0; i < count; ++i) { |
| 1636 | QRgbaFloat32 c = s[i].premultiplied(); |
| 1637 | buffer[i] = QRgba64::fromRgba64(red: c.red16(), green: c.green16(), blue: c.blue16(), alpha: c.alpha16()); |
| 1638 | } |
| 1639 | return buffer; |
| 1640 | } |
| 1641 | |
| 1642 | static void QT_FASTCALL storeRGBA32FFromARGB32PM(uchar *dest, const uint *src, int index, int count, |
| 1643 | const QList<QRgb> *, QDitherInfo *) |
| 1644 | { |
| 1645 | QRgbaFloat32 *d = reinterpret_cast<QRgbaFloat32 *>(dest) + index; |
| 1646 | for (int i = 0; i < count; ++i) |
| 1647 | d[i] = QRgbaFloat32::fromArgb32(rgb: src[i]).unpremultiplied(); |
| 1648 | } |
| 1649 | |
| 1650 | static const QRgba64 *QT_FASTCALL fetchRGBA32FPMToRGBA64PM(QRgba64 *buffer, const uchar *src, int index, int count, |
| 1651 | const QList<QRgb> *, QDitherInfo *) |
| 1652 | { |
| 1653 | const QRgbaFloat32 *s = reinterpret_cast<const QRgbaFloat32 *>(src) + index; |
| 1654 | for (int i = 0; i < count; ++i) { |
| 1655 | QRgbaFloat32 c = s[i]; |
| 1656 | buffer[i] = QRgba64::fromRgba64(red: c.red16(), green: c.green16(), blue: c.blue16(), alpha: c.alpha16()); |
| 1657 | } |
| 1658 | return buffer; |
| 1659 | } |
| 1660 | |
| 1661 | inline const uint *qt_convertCMYK8888ToARGB32PM(uint *buffer, const uint *src, int count) |
| 1662 | { |
| 1663 | UNALIASED_CONVERSION_LOOP(buffer, src, count, [](uint s) { |
| 1664 | const QColor color = QCmyk32::fromCmyk32(s).toColor(); |
| 1665 | return color.rgba(); |
| 1666 | }); |
| 1667 | return buffer; |
| 1668 | } |
| 1669 | |
| 1670 | static void QT_FASTCALL convertCMYK8888ToARGB32PM(uint *buffer, int count, const QList<QRgb> *) |
| 1671 | { |
| 1672 | qt_convertCMYK8888ToARGB32PM(buffer, src: buffer, count); |
| 1673 | } |
| 1674 | |
| 1675 | static const QRgba64 *QT_FASTCALL convertCMYK8888ToToRGBA64PM(QRgba64 *buffer, const uint *src, int count, |
| 1676 | const QList<QRgb> *, QDitherInfo *) |
| 1677 | { |
| 1678 | for (int i = 0; i < count; ++i) |
| 1679 | buffer[i] = QCmyk32::fromCmyk32(cmyk: src[i]).toColor().rgba64(); |
| 1680 | return buffer; |
| 1681 | } |
| 1682 | |
| 1683 | static const uint *QT_FASTCALL fetchCMYK8888ToARGB32PM(uint *buffer, const uchar *src, int index, int count, |
| 1684 | const QList<QRgb> *, QDitherInfo *) |
| 1685 | { |
| 1686 | const uint *s = reinterpret_cast<const uint *>(src) + index; |
| 1687 | for (int i = 0; i < count; ++i) |
| 1688 | buffer[i] = QCmyk32::fromCmyk32(cmyk: s[i]).toColor().rgba(); |
| 1689 | return buffer; |
| 1690 | } |
| 1691 | |
| 1692 | static const QRgba64 *QT_FASTCALL fetchCMYK8888ToRGBA64PM(QRgba64 *buffer, const uchar *src, int index, int count, |
| 1693 | const QList<QRgb> *, QDitherInfo *) |
| 1694 | { |
| 1695 | const uint *s = reinterpret_cast<const uint *>(src) + index; |
| 1696 | for (int i = 0; i < count; ++i) |
| 1697 | buffer[i] = QCmyk32::fromCmyk32(cmyk: s[i]).toColor().rgba64(); |
| 1698 | return buffer; |
| 1699 | } |
| 1700 | |
| 1701 | static void QT_FASTCALL storeCMYK8888FromARGB32PM(uchar *dest, const uint *src, int index, int count, |
| 1702 | const QList<QRgb> *, QDitherInfo *) |
| 1703 | { |
| 1704 | uint *d = reinterpret_cast<uint *>(dest) + index; |
| 1705 | for (int i = 0; i < count; ++i) { |
| 1706 | QColor c = qUnpremultiply(p: src[i]); |
| 1707 | d[i] = QCmyk32::fromColor(color: c).toUint(); |
| 1708 | } |
| 1709 | } |
| 1710 | |
| 1711 | static void QT_FASTCALL storeCMYK8888FromRGB32(uchar *dest, const uint *src, int index, int count, |
| 1712 | const QList<QRgb> *, QDitherInfo *) |
| 1713 | { |
| 1714 | uint *d = reinterpret_cast<uint *>(dest) + index; |
| 1715 | for (int i = 0; i < count; ++i) { |
| 1716 | QColor c = src[i]; |
| 1717 | d[i] = QCmyk32::fromColor(color: c).toUint(); |
| 1718 | } |
| 1719 | } |
| 1720 | |
| 1721 | // Note: |
| 1722 | // convertToArgb32() assumes that no color channel is less than 4 bits. |
| 1723 | // storeRGBFromARGB32PM() assumes that no color channel is more than 8 bits. |
| 1724 | // QImage::rgbSwapped() assumes that the red and blue color channels have the same number of bits. |
| 1725 | QPixelLayout qPixelLayouts[] = { |
| 1726 | { .hasAlphaChannel: false, .premultiplied: false, .bpp: QPixelLayout::BPPNone, .rbSwap: nullptr, .convertToARGB32PM: nullptr, .convertToRGBA64PM: nullptr, .fetchToARGB32PM: nullptr, .fetchToRGBA64PM: nullptr, .storeFromARGB32PM: nullptr, .storeFromRGB32: nullptr }, // Format_Invalid |
| 1727 | { .hasAlphaChannel: false, .premultiplied: false, .bpp: QPixelLayout::BPP1MSB, .rbSwap: nullptr, |
| 1728 | .convertToARGB32PM: convertIndexedToARGB32PM, .convertToRGBA64PM: convertIndexedTo<QRgba64>, |
| 1729 | .fetchToARGB32PM: fetchIndexedToARGB32PM<QPixelLayout::BPP1MSB>, .fetchToRGBA64PM: fetchIndexedToRGBA64PM<QPixelLayout::BPP1MSB>, |
| 1730 | .storeFromARGB32PM: nullptr, .storeFromRGB32: nullptr }, // Format_Mono |
| 1731 | { .hasAlphaChannel: false, .premultiplied: false, .bpp: QPixelLayout::BPP1LSB, .rbSwap: nullptr, |
| 1732 | .convertToARGB32PM: convertIndexedToARGB32PM, .convertToRGBA64PM: convertIndexedTo<QRgba64>, |
| 1733 | .fetchToARGB32PM: fetchIndexedToARGB32PM<QPixelLayout::BPP1LSB>, .fetchToRGBA64PM: fetchIndexedToRGBA64PM<QPixelLayout::BPP1LSB>, |
| 1734 | .storeFromARGB32PM: nullptr, .storeFromRGB32: nullptr }, // Format_MonoLSB |
| 1735 | { .hasAlphaChannel: false, .premultiplied: false, .bpp: QPixelLayout::BPP8, .rbSwap: nullptr, |
| 1736 | .convertToARGB32PM: convertIndexedToARGB32PM, .convertToRGBA64PM: convertIndexedTo<QRgba64>, |
| 1737 | .fetchToARGB32PM: fetchIndexedToARGB32PM<QPixelLayout::BPP8>, .fetchToRGBA64PM: fetchIndexedToRGBA64PM<QPixelLayout::BPP8>, |
| 1738 | .storeFromARGB32PM: nullptr, .storeFromRGB32: nullptr }, // Format_Indexed8 |
| 1739 | // Technically using convertPassThrough to convert from ARGB32PM to RGB32 is wrong, |
| 1740 | // but everywhere this generic conversion would be wrong is currently overloaded. |
| 1741 | { .hasAlphaChannel: false, .premultiplied: false, .bpp: QPixelLayout::BPP32, .rbSwap: rbSwap_rgb32, .convertToARGB32PM: convertPassThrough, |
| 1742 | .convertToRGBA64PM: convertRGB32ToRGB64, .fetchToARGB32PM: fetchPassThrough, .fetchToRGBA64PM: fetchRGB32ToRGB64, .storeFromARGB32PM: storePassThrough, .storeFromRGB32: storePassThrough }, // Format_RGB32 |
| 1743 | { .hasAlphaChannel: true, .premultiplied: false, .bpp: QPixelLayout::BPP32, .rbSwap: rbSwap_rgb32, .convertToARGB32PM: convertARGB32ToARGB32PM, |
| 1744 | .convertToRGBA64PM: convertARGB32ToRGBA64PM, .fetchToARGB32PM: fetchARGB32ToARGB32PM, .fetchToRGBA64PM: fetchARGB32ToRGBA64PM, .storeFromARGB32PM: storeARGB32FromARGB32PM, .storeFromRGB32: storePassThrough }, // Format_ARGB32 |
| 1745 | { .hasAlphaChannel: true, .premultiplied: true, .bpp: QPixelLayout::BPP32, .rbSwap: rbSwap_rgb32, .convertToARGB32PM: convertPassThrough, |
| 1746 | .convertToRGBA64PM: convertARGB32PMToRGBA64PM, .fetchToARGB32PM: fetchPassThrough, .fetchToRGBA64PM: fetchARGB32PMToRGBA64PM, .storeFromARGB32PM: storePassThrough, .storeFromRGB32: storePassThrough }, // Format_ARGB32_Premultiplied |
| 1747 | pixelLayoutRGB<QImage::Format_RGB16>(), |
| 1748 | pixelLayoutARGBPM<QImage::Format_ARGB8565_Premultiplied>(), |
| 1749 | pixelLayoutRGB<QImage::Format_RGB666>(), |
| 1750 | pixelLayoutARGBPM<QImage::Format_ARGB6666_Premultiplied>(), |
| 1751 | pixelLayoutRGB<QImage::Format_RGB555>(), |
| 1752 | pixelLayoutARGBPM<QImage::Format_ARGB8555_Premultiplied>(), |
| 1753 | pixelLayoutRGB<QImage::Format_RGB888>(), |
| 1754 | pixelLayoutRGB<QImage::Format_RGB444>(), |
| 1755 | pixelLayoutARGBPM<QImage::Format_ARGB4444_Premultiplied>(), |
| 1756 | { .hasAlphaChannel: false, .premultiplied: false, .bpp: QPixelLayout::BPP32, .rbSwap: rbSwap<QImage::Format_RGBA8888>, .convertToARGB32PM: convertRGBA8888PMToARGB32PM, |
| 1757 | .convertToRGBA64PM: convertRGBA8888PMToRGBA64PM, .fetchToARGB32PM: fetchRGBA8888PMToARGB32PM, .fetchToRGBA64PM: fetchRGBA8888PMToRGBA64PM, .storeFromARGB32PM: storeRGBXFromARGB32PM, .storeFromRGB32: storeRGBXFromRGB32 }, // Format_RGBX8888 |
| 1758 | { .hasAlphaChannel: true, .premultiplied: false, .bpp: QPixelLayout::BPP32, .rbSwap: rbSwap<QImage::Format_RGBA8888>, .convertToARGB32PM: convertRGBA8888ToARGB32PM, |
| 1759 | .convertToRGBA64PM: convertRGBA8888ToRGBA64PM, .fetchToARGB32PM: fetchRGBA8888ToARGB32PM, .fetchToRGBA64PM: fetchRGBA8888ToRGBA64PM, .storeFromARGB32PM: storeRGBA8888FromARGB32PM, .storeFromRGB32: storeRGBXFromRGB32 }, // Format_RGBA8888 |
| 1760 | { .hasAlphaChannel: true, .premultiplied: true, .bpp: QPixelLayout::BPP32, .rbSwap: rbSwap<QImage::Format_RGBA8888>, .convertToARGB32PM: convertRGBA8888PMToARGB32PM, |
| 1761 | .convertToRGBA64PM: convertRGBA8888PMToRGBA64PM, .fetchToARGB32PM: fetchRGBA8888PMToARGB32PM, .fetchToRGBA64PM: fetchRGBA8888PMToRGBA64PM, .storeFromARGB32PM: storeRGBA8888PMFromARGB32PM, .storeFromRGB32: storeRGBXFromRGB32 }, // Format_RGBA8888_Premultiplied |
| 1762 | { .hasAlphaChannel: false, .premultiplied: false, .bpp: QPixelLayout::BPP32, .rbSwap: rbSwap_rgb30, |
| 1763 | .convertToARGB32PM: convertA2RGB30PMToARGB32PM<PixelOrderBGR>, |
| 1764 | .convertToRGBA64PM: convertA2RGB30PMToRGBA64PM<PixelOrderBGR>, |
| 1765 | .fetchToARGB32PM: fetchA2RGB30PMToARGB32PM<PixelOrderBGR>, |
| 1766 | .fetchToRGBA64PM: fetchA2RGB30PMToRGBA64PM<PixelOrderBGR>, |
| 1767 | .storeFromARGB32PM: storeRGB30FromARGB32PM<PixelOrderBGR>, |
| 1768 | .storeFromRGB32: storeRGB30FromRGB32<PixelOrderBGR> |
| 1769 | }, // Format_BGR30 |
| 1770 | { .hasAlphaChannel: true, .premultiplied: true, .bpp: QPixelLayout::BPP32, .rbSwap: rbSwap_rgb30, |
| 1771 | .convertToARGB32PM: convertA2RGB30PMToARGB32PM<PixelOrderBGR>, |
| 1772 | .convertToRGBA64PM: convertA2RGB30PMToRGBA64PM<PixelOrderBGR>, |
| 1773 | .fetchToARGB32PM: fetchA2RGB30PMToARGB32PM<PixelOrderBGR>, |
| 1774 | .fetchToRGBA64PM: fetchA2RGB30PMToRGBA64PM<PixelOrderBGR>, |
| 1775 | .storeFromARGB32PM: storeA2RGB30PMFromARGB32PM<PixelOrderBGR>, |
| 1776 | .storeFromRGB32: storeRGB30FromRGB32<PixelOrderBGR> |
| 1777 | }, // Format_A2BGR30_Premultiplied |
| 1778 | { .hasAlphaChannel: false, .premultiplied: false, .bpp: QPixelLayout::BPP32, .rbSwap: rbSwap_rgb30, |
| 1779 | .convertToARGB32PM: convertA2RGB30PMToARGB32PM<PixelOrderRGB>, |
| 1780 | .convertToRGBA64PM: convertA2RGB30PMToRGBA64PM<PixelOrderRGB>, |
| 1781 | .fetchToARGB32PM: fetchA2RGB30PMToARGB32PM<PixelOrderRGB>, |
| 1782 | .fetchToRGBA64PM: fetchA2RGB30PMToRGBA64PM<PixelOrderRGB>, |
| 1783 | .storeFromARGB32PM: storeRGB30FromARGB32PM<PixelOrderRGB>, |
| 1784 | .storeFromRGB32: storeRGB30FromRGB32<PixelOrderRGB> |
| 1785 | }, // Format_RGB30 |
| 1786 | { .hasAlphaChannel: true, .premultiplied: true, .bpp: QPixelLayout::BPP32, .rbSwap: rbSwap_rgb30, |
| 1787 | .convertToARGB32PM: convertA2RGB30PMToARGB32PM<PixelOrderRGB>, |
| 1788 | .convertToRGBA64PM: convertA2RGB30PMToRGBA64PM<PixelOrderRGB>, |
| 1789 | .fetchToARGB32PM: fetchA2RGB30PMToARGB32PM<PixelOrderRGB>, |
| 1790 | .fetchToRGBA64PM: fetchA2RGB30PMToRGBA64PM<PixelOrderRGB>, |
| 1791 | .storeFromARGB32PM: storeA2RGB30PMFromARGB32PM<PixelOrderRGB>, |
| 1792 | .storeFromRGB32: storeRGB30FromRGB32<PixelOrderRGB> |
| 1793 | }, // Format_A2RGB30_Premultiplied |
| 1794 | { .hasAlphaChannel: true, .premultiplied: true, .bpp: QPixelLayout::BPP8, .rbSwap: nullptr, |
| 1795 | .convertToARGB32PM: convertAlpha8ToRGB32, .convertToRGBA64PM: convertAlpha8To<QRgba64>, |
| 1796 | .fetchToARGB32PM: fetchAlpha8ToRGB32, .fetchToRGBA64PM: fetchAlpha8To<QRgba64>, |
| 1797 | .storeFromARGB32PM: storeAlpha8FromARGB32PM, .storeFromRGB32: nullptr }, // Format_Alpha8 |
| 1798 | { .hasAlphaChannel: false, .premultiplied: false, .bpp: QPixelLayout::BPP8, .rbSwap: nullptr, |
| 1799 | .convertToARGB32PM: convertGrayscale8ToRGB32, .convertToRGBA64PM: convertGrayscale8To<QRgba64>, |
| 1800 | .fetchToARGB32PM: fetchGrayscale8ToRGB32, .fetchToRGBA64PM: fetchGrayscale8To<QRgba64>, |
| 1801 | .storeFromARGB32PM: storeGrayscale8FromARGB32PM, .storeFromRGB32: storeGrayscale8FromRGB32 }, // Format_Grayscale8 |
| 1802 | { .hasAlphaChannel: false, .premultiplied: false, .bpp: QPixelLayout::BPP64, .rbSwap: rbSwap_4x16, |
| 1803 | .convertToARGB32PM: convertPassThrough, .convertToRGBA64PM: nullptr, |
| 1804 | .fetchToARGB32PM: fetchRGB64ToRGB32, .fetchToRGBA64PM: fetchPassThrough64, |
| 1805 | .storeFromARGB32PM: storeRGBA64FromARGB32PM<true>, .storeFromRGB32: storeRGB64FromRGB32 }, // Format_RGBX64 |
| 1806 | { .hasAlphaChannel: true, .premultiplied: false, .bpp: QPixelLayout::BPP64, .rbSwap: rbSwap_4x16, |
| 1807 | .convertToARGB32PM: convertARGB32ToARGB32PM, .convertToRGBA64PM: nullptr, |
| 1808 | .fetchToARGB32PM: fetchRGBA64ToARGB32PM, .fetchToRGBA64PM: fetchRGBA64ToRGBA64PM, |
| 1809 | .storeFromARGB32PM: storeRGBA64FromARGB32PM<false>, .storeFromRGB32: storeRGB64FromRGB32 }, // Format_RGBA64 |
| 1810 | { .hasAlphaChannel: true, .premultiplied: true, .bpp: QPixelLayout::BPP64, .rbSwap: rbSwap_4x16, |
| 1811 | .convertToARGB32PM: convertPassThrough, .convertToRGBA64PM: nullptr, |
| 1812 | .fetchToARGB32PM: fetchRGB64ToRGB32, .fetchToRGBA64PM: fetchPassThrough64, |
| 1813 | .storeFromARGB32PM: storeRGBA64FromARGB32, .storeFromRGB32: storeRGB64FromRGB32 }, // Format_RGBA64_Premultiplied |
| 1814 | { .hasAlphaChannel: false, .premultiplied: false, .bpp: QPixelLayout::BPP16, .rbSwap: nullptr, |
| 1815 | .convertToARGB32PM: convertGrayscale16ToRGB32, .convertToRGBA64PM: convertGrayscale16To<QRgba64>, |
| 1816 | .fetchToARGB32PM: fetchGrayscale16ToRGB32, .fetchToRGBA64PM: fetchGrayscale16To<QRgba64>, |
| 1817 | .storeFromARGB32PM: storeGrayscale16FromARGB32PM, .storeFromRGB32: storeGrayscale16FromRGB32 }, // Format_Grayscale16 |
| 1818 | pixelLayoutRGB<QImage::Format_BGR888>(), |
| 1819 | { .hasAlphaChannel: false, .premultiplied: false, .bpp: QPixelLayout::BPP16FPx4, .rbSwap: rbSwap_4x16, |
| 1820 | .convertToARGB32PM: convertPassThrough, .convertToRGBA64PM: nullptr, |
| 1821 | .fetchToARGB32PM: fetchRGB16FToRGB32, .fetchToRGBA64PM: fetchRGBA16FPMToRGBA64PM, |
| 1822 | .storeFromARGB32PM: storeRGB16FFromRGB32, .storeFromRGB32: storeRGB16FFromRGB32 }, // Format_RGBX16FPx4 |
| 1823 | { .hasAlphaChannel: true, .premultiplied: false, .bpp: QPixelLayout::BPP16FPx4, .rbSwap: rbSwap_4x16, |
| 1824 | .convertToARGB32PM: convertARGB32ToARGB32PM, .convertToRGBA64PM: nullptr, |
| 1825 | .fetchToARGB32PM: fetchRGBA16FToARGB32PM, .fetchToRGBA64PM: fetchRGBA16FToRGBA64PM, |
| 1826 | .storeFromARGB32PM: storeRGBA16FFromARGB32PM, .storeFromRGB32: storeRGB16FFromRGB32 }, // Format_RGBA16FPx4 |
| 1827 | { .hasAlphaChannel: true, .premultiplied: true, .bpp: QPixelLayout::BPP16FPx4, .rbSwap: rbSwap_4x16, |
| 1828 | .convertToARGB32PM: convertPassThrough, .convertToRGBA64PM: nullptr, |
| 1829 | .fetchToARGB32PM: fetchRGB16FToRGB32, .fetchToRGBA64PM: fetchRGBA16FPMToRGBA64PM, |
| 1830 | .storeFromARGB32PM: storeRGB16FFromRGB32, .storeFromRGB32: storeRGB16FFromRGB32 }, // Format_RGBA16FPx4_Premultiplied |
| 1831 | { .hasAlphaChannel: false, .premultiplied: false, .bpp: QPixelLayout::BPP32FPx4, .rbSwap: rbSwap_4x32, |
| 1832 | .convertToARGB32PM: convertPassThrough, .convertToRGBA64PM: nullptr, |
| 1833 | .fetchToARGB32PM: fetchRGB32FToRGB32, .fetchToRGBA64PM: fetchRGBA32FPMToRGBA64PM, |
| 1834 | .storeFromARGB32PM: storeRGB32FFromRGB32, .storeFromRGB32: storeRGB32FFromRGB32 }, // Format_RGBX32FPx4 |
| 1835 | { .hasAlphaChannel: true, .premultiplied: false, .bpp: QPixelLayout::BPP32FPx4, .rbSwap: rbSwap_4x32, |
| 1836 | .convertToARGB32PM: convertARGB32ToARGB32PM, .convertToRGBA64PM: nullptr, |
| 1837 | .fetchToARGB32PM: fetchRGBA32FToARGB32PM, .fetchToRGBA64PM: fetchRGBA32FToRGBA64PM, |
| 1838 | .storeFromARGB32PM: storeRGBA32FFromARGB32PM, .storeFromRGB32: storeRGB32FFromRGB32 }, // Format_RGBA32FPx4 |
| 1839 | { .hasAlphaChannel: true, .premultiplied: true, .bpp: QPixelLayout::BPP32FPx4, .rbSwap: rbSwap_4x32, |
| 1840 | .convertToARGB32PM: convertPassThrough, .convertToRGBA64PM: nullptr, |
| 1841 | .fetchToARGB32PM: fetchRGB32FToRGB32, .fetchToRGBA64PM: fetchRGBA32FPMToRGBA64PM, |
| 1842 | .storeFromARGB32PM: storeRGB32FFromRGB32, .storeFromRGB32: storeRGB32FFromRGB32 }, // Format_RGBA32FPx4_Premultiplied |
| 1843 | { .hasAlphaChannel: false, .premultiplied: false, .bpp: QPixelLayout::BPP32, .rbSwap: nullptr, |
| 1844 | .convertToARGB32PM: convertCMYK8888ToARGB32PM, .convertToRGBA64PM: convertCMYK8888ToToRGBA64PM, |
| 1845 | .fetchToARGB32PM: fetchCMYK8888ToARGB32PM, .fetchToRGBA64PM: fetchCMYK8888ToRGBA64PM, |
| 1846 | .storeFromARGB32PM: storeCMYK8888FromARGB32PM, .storeFromRGB32: storeCMYK8888FromRGB32 }, // Format_CMYK8888 |
| 1847 | }; |
| 1848 | |
| 1849 | static_assert(std::size(qPixelLayouts) == QImage::NImageFormats); |
| 1850 | |
| 1851 | static void QT_FASTCALL convertFromRgb64(uint *dest, const QRgba64 *src, int length) |
| 1852 | { |
| 1853 | for (int i = 0; i < length; ++i) { |
| 1854 | dest[i] = toArgb32(rgba64: src[i]); |
| 1855 | } |
| 1856 | } |
| 1857 | |
| 1858 | template<QImage::Format format> |
| 1859 | static void QT_FASTCALL storeGenericFromRGBA64PM(uchar *dest, const QRgba64 *src, int index, int count, |
| 1860 | const QList<QRgb> *clut, QDitherInfo *dither) |
| 1861 | { |
| 1862 | Q_DECL_UNINITIALIZED uint buffer[BufferSize]; |
| 1863 | convertFromRgb64(dest: buffer, src, length: count); |
| 1864 | qPixelLayouts[format].storeFromARGB32PM(dest, buffer, index, count, clut, dither); |
| 1865 | } |
| 1866 | |
| 1867 | static void QT_FASTCALL storeARGB32FromRGBA64PM(uchar *dest, const QRgba64 *src, int index, int count, |
| 1868 | const QList<QRgb> *, QDitherInfo *) |
| 1869 | { |
| 1870 | uint *d = (uint*)dest + index; |
| 1871 | for (int i = 0; i < count; ++i) |
| 1872 | d[i] = toArgb32(rgba64: src[i].unpremultiplied()); |
| 1873 | } |
| 1874 | |
| 1875 | static void QT_FASTCALL storeRGBA8888FromRGBA64PM(uchar *dest, const QRgba64 *src, int index, int count, |
| 1876 | const QList<QRgb> *, QDitherInfo *) |
| 1877 | { |
| 1878 | uint *d = (uint*)dest + index; |
| 1879 | for (int i = 0; i < count; ++i) |
| 1880 | d[i] = toRgba8888(rgba64: src[i].unpremultiplied()); |
| 1881 | } |
| 1882 | |
| 1883 | template<QtPixelOrder PixelOrder> |
| 1884 | static void QT_FASTCALL storeRGB30FromRGBA64PM(uchar *dest, const QRgba64 *src, int index, int count, |
| 1885 | const QList<QRgb> *, QDitherInfo *) |
| 1886 | { |
| 1887 | uint *d = (uint*)dest + index; |
| 1888 | #ifdef __SSE2__ |
| 1889 | qConvertRGBA64PMToA2RGB30PM_sse2<PixelOrder>(d, src, count); |
| 1890 | #else |
| 1891 | for (int i = 0; i < count; ++i) |
| 1892 | d[i] = qConvertRgb64ToRgb30<PixelOrder>(src[i]); |
| 1893 | #endif |
| 1894 | } |
| 1895 | |
| 1896 | static void QT_FASTCALL storeRGBX64FromRGBA64PM(uchar *dest, const QRgba64 *src, int index, int count, |
| 1897 | const QList<QRgb> *, QDitherInfo *) |
| 1898 | { |
| 1899 | QRgba64 *d = reinterpret_cast<QRgba64*>(dest) + index; |
| 1900 | for (int i = 0; i < count; ++i) { |
| 1901 | d[i] = src[i].unpremultiplied(); |
| 1902 | d[i].setAlpha(65535); |
| 1903 | } |
| 1904 | } |
| 1905 | |
| 1906 | static void QT_FASTCALL storeRGBA64FromRGBA64PM(uchar *dest, const QRgba64 *src, int index, int count, |
| 1907 | const QList<QRgb> *, QDitherInfo *) |
| 1908 | { |
| 1909 | QRgba64 *d = reinterpret_cast<QRgba64*>(dest) + index; |
| 1910 | for (int i = 0; i < count; ++i) |
| 1911 | d[i] = src[i].unpremultiplied(); |
| 1912 | } |
| 1913 | |
| 1914 | static void QT_FASTCALL storeRGBA64PMFromRGBA64PM(uchar *dest, const QRgba64 *src, int index, int count, |
| 1915 | const QList<QRgb> *, QDitherInfo *) |
| 1916 | { |
| 1917 | QRgba64 *d = reinterpret_cast<QRgba64*>(dest) + index; |
| 1918 | if (d != src) |
| 1919 | memcpy(dest: d, src: src, n: count * sizeof(QRgba64)); |
| 1920 | } |
| 1921 | |
| 1922 | static void QT_FASTCALL storeGray16FromRGBA64PM(uchar *dest, const QRgba64 *src, int index, int count, |
| 1923 | const QList<QRgb> *, QDitherInfo *) |
| 1924 | { |
| 1925 | quint16 *d = reinterpret_cast<quint16*>(dest) + index; |
| 1926 | for (int i = 0; i < count; ++i) { |
| 1927 | QRgba64 s = src[i].unpremultiplied(); |
| 1928 | d[i] = qGray(r: s.red(), g: s.green(), b: s.blue()); |
| 1929 | } |
| 1930 | } |
| 1931 | |
| 1932 | static void QT_FASTCALL storeRGBX16FFromRGBA64PM(uchar *dest, const QRgba64 *src, int index, int count, |
| 1933 | const QList<QRgb> *, QDitherInfo *) |
| 1934 | { |
| 1935 | QRgbaFloat16 *d = reinterpret_cast<QRgbaFloat16 *>(dest) + index; |
| 1936 | for (int i = 0; i < count; ++i) { |
| 1937 | d[i] = qConvertRgb64ToRgbaF16(c: src[i]).unpremultiplied(); |
| 1938 | d[i].setAlpha(1.0); |
| 1939 | } |
| 1940 | } |
| 1941 | |
| 1942 | static void QT_FASTCALL storeRGBA16FFromRGBA64PM(uchar *dest, const QRgba64 *src, int index, int count, |
| 1943 | const QList<QRgb> *, QDitherInfo *) |
| 1944 | { |
| 1945 | QRgbaFloat16 *d = reinterpret_cast<QRgbaFloat16 *>(dest) + index; |
| 1946 | for (int i = 0; i < count; ++i) |
| 1947 | d[i] = qConvertRgb64ToRgbaF16(c: src[i]).unpremultiplied(); |
| 1948 | } |
| 1949 | |
| 1950 | static void QT_FASTCALL storeRGBA16FPMFromRGBA64PM(uchar *dest, const QRgba64 *src, int index, int count, |
| 1951 | const QList<QRgb> *, QDitherInfo *) |
| 1952 | { |
| 1953 | QRgbaFloat16 *d = reinterpret_cast<QRgbaFloat16 *>(dest) + index; |
| 1954 | for (int i = 0; i < count; ++i) |
| 1955 | d[i] = qConvertRgb64ToRgbaF16(c: src[i]); |
| 1956 | } |
| 1957 | |
| 1958 | static void QT_FASTCALL storeRGBX32FFromRGBA64PM(uchar *dest, const QRgba64 *src, int index, int count, |
| 1959 | const QList<QRgb> *, QDitherInfo *) |
| 1960 | { |
| 1961 | QRgbaFloat32 *d = reinterpret_cast<QRgbaFloat32 *>(dest) + index; |
| 1962 | for (int i = 0; i < count; ++i) { |
| 1963 | d[i] = qConvertRgb64ToRgbaF32(c: src[i]).unpremultiplied(); |
| 1964 | d[i].setAlpha(1.0); |
| 1965 | } |
| 1966 | } |
| 1967 | |
| 1968 | static void QT_FASTCALL storeRGBA32FFromRGBA64PM(uchar *dest, const QRgba64 *src, int index, int count, |
| 1969 | const QList<QRgb> *, QDitherInfo *) |
| 1970 | { |
| 1971 | QRgbaFloat32 *d = reinterpret_cast<QRgbaFloat32 *>(dest) + index; |
| 1972 | for (int i = 0; i < count; ++i) |
| 1973 | d[i] = qConvertRgb64ToRgbaF32(c: src[i]).unpremultiplied(); |
| 1974 | } |
| 1975 | |
| 1976 | static void QT_FASTCALL storeRGBA32FPMFromRGBA64PM(uchar *dest, const QRgba64 *src, int index, int count, |
| 1977 | const QList<QRgb> *, QDitherInfo *) |
| 1978 | { |
| 1979 | QRgbaFloat32 *d = reinterpret_cast<QRgbaFloat32 *>(dest) + index; |
| 1980 | for (int i = 0; i < count; ++i) |
| 1981 | d[i] = qConvertRgb64ToRgbaF32(c: src[i]); |
| 1982 | } |
| 1983 | |
| 1984 | static void QT_FASTCALL storeCMYKFromRGBA64PM(uchar *dest, const QRgba64 *src, int index, int count, |
| 1985 | const QList<QRgb> *, QDitherInfo *) |
| 1986 | { |
| 1987 | uint *d = reinterpret_cast<uint *>(dest) + index; |
| 1988 | for (int i = 0; i < count; ++i) |
| 1989 | d[i] = QCmyk32::fromColor(color: QColor(src[i])).toUint(); |
| 1990 | } |
| 1991 | |
| 1992 | ConvertAndStorePixelsFunc64 qStoreFromRGBA64PM[] = { |
| 1993 | nullptr, |
| 1994 | nullptr, |
| 1995 | nullptr, |
| 1996 | nullptr, |
| 1997 | storeGenericFromRGBA64PM<QImage::Format_RGB32>, |
| 1998 | storeARGB32FromRGBA64PM, |
| 1999 | storeGenericFromRGBA64PM<QImage::Format_ARGB32_Premultiplied>, |
| 2000 | storeGenericFromRGBA64PM<QImage::Format_RGB16>, |
| 2001 | storeGenericFromRGBA64PM<QImage::Format_ARGB8565_Premultiplied>, |
| 2002 | storeGenericFromRGBA64PM<QImage::Format_RGB666>, |
| 2003 | storeGenericFromRGBA64PM<QImage::Format_ARGB6666_Premultiplied>, |
| 2004 | storeGenericFromRGBA64PM<QImage::Format_RGB555>, |
| 2005 | storeGenericFromRGBA64PM<QImage::Format_ARGB8555_Premultiplied>, |
| 2006 | storeGenericFromRGBA64PM<QImage::Format_RGB888>, |
| 2007 | storeGenericFromRGBA64PM<QImage::Format_RGB444>, |
| 2008 | storeGenericFromRGBA64PM<QImage::Format_ARGB4444_Premultiplied>, |
| 2009 | storeGenericFromRGBA64PM<QImage::Format_RGBX8888>, |
| 2010 | storeRGBA8888FromRGBA64PM, |
| 2011 | storeGenericFromRGBA64PM<QImage::Format_RGBA8888_Premultiplied>, |
| 2012 | storeRGB30FromRGBA64PM<PixelOrderBGR>, |
| 2013 | storeRGB30FromRGBA64PM<PixelOrderBGR>, |
| 2014 | storeRGB30FromRGBA64PM<PixelOrderRGB>, |
| 2015 | storeRGB30FromRGBA64PM<PixelOrderRGB>, |
| 2016 | storeGenericFromRGBA64PM<QImage::Format_Alpha8>, |
| 2017 | storeGenericFromRGBA64PM<QImage::Format_Grayscale8>, |
| 2018 | storeRGBX64FromRGBA64PM, |
| 2019 | storeRGBA64FromRGBA64PM, |
| 2020 | storeRGBA64PMFromRGBA64PM, |
| 2021 | storeGray16FromRGBA64PM, |
| 2022 | storeGenericFromRGBA64PM<QImage::Format_BGR888>, |
| 2023 | storeRGBX16FFromRGBA64PM, |
| 2024 | storeRGBA16FFromRGBA64PM, |
| 2025 | storeRGBA16FPMFromRGBA64PM, |
| 2026 | storeRGBX32FFromRGBA64PM, |
| 2027 | storeRGBA32FFromRGBA64PM, |
| 2028 | storeRGBA32FPMFromRGBA64PM, |
| 2029 | storeCMYKFromRGBA64PM, |
| 2030 | }; |
| 2031 | |
| 2032 | static_assert(std::size(qStoreFromRGBA64PM) == QImage::NImageFormats); |
| 2033 | |
| 2034 | #if QT_CONFIG(raster_fp) |
| 2035 | static void QT_FASTCALL convertToRgbaF32(QRgbaFloat32 *dest, const uint *src, int length) |
| 2036 | { |
| 2037 | for (int i = 0; i < length; ++i) |
| 2038 | dest[i] = QRgbaFloat32::fromArgb32(rgb: src[i]); |
| 2039 | } |
| 2040 | |
| 2041 | template<QImage::Format format> |
| 2042 | static const QRgbaFloat32 * QT_FASTCALL convertGenericToRGBA32F(QRgbaFloat32 *buffer, const uint *src, int count, |
| 2043 | const QList<QRgb> *clut, QDitherInfo *) |
| 2044 | { |
| 2045 | Q_DECL_UNINITIALIZED uint buffer32[BufferSize]; |
| 2046 | memcpy(dest: buffer32, src: src, n: count * sizeof(uint)); |
| 2047 | qPixelLayouts[format].convertToARGB32PM(buffer32, count, clut); |
| 2048 | convertToRgbaF32(dest: buffer, src: buffer32, length: count); |
| 2049 | return buffer; |
| 2050 | } |
| 2051 | |
| 2052 | static const QRgbaFloat32 * QT_FASTCALL convertARGB32ToRGBA32F(QRgbaFloat32 *buffer, const uint *src, int count, |
| 2053 | const QList<QRgb> *, QDitherInfo *) |
| 2054 | { |
| 2055 | for (int i = 0; i < count; ++i) |
| 2056 | buffer[i] = QRgbaFloat32::fromArgb32(rgb: src[i]).premultiplied(); |
| 2057 | return buffer; |
| 2058 | } |
| 2059 | |
| 2060 | static const QRgbaFloat32 * QT_FASTCALL convertRGBA8888ToRGBA32F(QRgbaFloat32 *buffer, const uint *src, int count, |
| 2061 | const QList<QRgb> *, QDitherInfo *) |
| 2062 | { |
| 2063 | for (int i = 0; i < count; ++i) |
| 2064 | buffer[i] = QRgbaFloat32::fromArgb32(rgb: RGBA2ARGB(x: src[i])).premultiplied(); |
| 2065 | return buffer; |
| 2066 | } |
| 2067 | |
| 2068 | template<QtPixelOrder PixelOrder> |
| 2069 | static const QRgbaFloat32 * QT_FASTCALL convertRGB30ToRGBA32F(QRgbaFloat32 *buffer, const uint *src, int count, |
| 2070 | const QList<QRgb> *, QDitherInfo *) |
| 2071 | { |
| 2072 | for (int i = 0; i < count; ++i) { |
| 2073 | QRgba64 s = qConvertA2rgb30ToRgb64<PixelOrder>(src[i]); |
| 2074 | buffer[i] = QRgbaFloat32::fromRgba64(red: s.red(), green: s.green(), blue: s.blue(), alpha: s.alpha()); |
| 2075 | } |
| 2076 | return buffer; |
| 2077 | } |
| 2078 | |
| 2079 | static const QRgbaFloat32 * QT_FASTCALL convertCMYKToRGBA32F(QRgbaFloat32 *buffer, const uint *src, int count, |
| 2080 | const QList<QRgb> *, QDitherInfo *) |
| 2081 | { |
| 2082 | for (int i = 0; i < count; ++i) |
| 2083 | buffer[i] = QRgbaFloat32::fromArgb32(rgb: QCmyk32::fromCmyk32(cmyk: src[i]).toColor().rgba()); |
| 2084 | |
| 2085 | return buffer; |
| 2086 | } |
| 2087 | |
| 2088 | ConvertToFPFunc qConvertToRGBA32F[] = { |
| 2089 | nullptr, |
| 2090 | convertIndexedTo<QRgbaFloat32>, |
| 2091 | convertIndexedTo<QRgbaFloat32>, |
| 2092 | convertIndexedTo<QRgbaFloat32>, |
| 2093 | convertGenericToRGBA32F<QImage::Format_RGB32>, |
| 2094 | convertARGB32ToRGBA32F, |
| 2095 | convertGenericToRGBA32F<QImage::Format_ARGB32_Premultiplied>, |
| 2096 | convertGenericToRGBA32F<QImage::Format_RGB16>, |
| 2097 | convertGenericToRGBA32F<QImage::Format_ARGB8565_Premultiplied>, |
| 2098 | convertGenericToRGBA32F<QImage::Format_RGB666>, |
| 2099 | convertGenericToRGBA32F<QImage::Format_ARGB6666_Premultiplied>, |
| 2100 | convertGenericToRGBA32F<QImage::Format_RGB555>, |
| 2101 | convertGenericToRGBA32F<QImage::Format_ARGB8555_Premultiplied>, |
| 2102 | convertGenericToRGBA32F<QImage::Format_RGB888>, |
| 2103 | convertGenericToRGBA32F<QImage::Format_RGB444>, |
| 2104 | convertGenericToRGBA32F<QImage::Format_ARGB4444_Premultiplied>, |
| 2105 | convertGenericToRGBA32F<QImage::Format_RGBX8888>, |
| 2106 | convertRGBA8888ToRGBA32F, |
| 2107 | convertGenericToRGBA32F<QImage::Format_RGBA8888_Premultiplied>, |
| 2108 | convertRGB30ToRGBA32F<PixelOrderBGR>, |
| 2109 | convertRGB30ToRGBA32F<PixelOrderBGR>, |
| 2110 | convertRGB30ToRGBA32F<PixelOrderRGB>, |
| 2111 | convertRGB30ToRGBA32F<PixelOrderRGB>, |
| 2112 | convertAlpha8To<QRgbaFloat32>, |
| 2113 | convertGrayscale8To<QRgbaFloat32>, |
| 2114 | nullptr, |
| 2115 | nullptr, |
| 2116 | nullptr, |
| 2117 | convertGrayscale16To<QRgbaFloat32>, |
| 2118 | convertGenericToRGBA32F<QImage::Format_BGR888>, |
| 2119 | nullptr, |
| 2120 | nullptr, |
| 2121 | nullptr, |
| 2122 | nullptr, |
| 2123 | nullptr, |
| 2124 | nullptr, |
| 2125 | convertCMYKToRGBA32F, |
| 2126 | }; |
| 2127 | |
| 2128 | static_assert(std::size(qConvertToRGBA32F) == QImage::NImageFormats); |
| 2129 | |
| 2130 | static const QRgbaFloat32 *QT_FASTCALL fetchRGBX64ToRGBA32F(QRgbaFloat32 *buffer, const uchar *src, int index, int count, |
| 2131 | const QList<QRgb> *, QDitherInfo *) |
| 2132 | { |
| 2133 | const QRgba64 *s = reinterpret_cast<const QRgba64 *>(src) + index; |
| 2134 | for (int i = 0; i < count; ++i) { |
| 2135 | QRgba64 c = s[i]; |
| 2136 | buffer[i] = QRgbaFloat32::fromRgba64(red: c.red(), green: c.green(), blue: c.blue(), alpha: 65535); |
| 2137 | } |
| 2138 | return buffer; |
| 2139 | } |
| 2140 | |
| 2141 | static const QRgbaFloat32 *QT_FASTCALL fetchRGBA64ToRGBA32F(QRgbaFloat32 *buffer, const uchar *src, int index, int count, |
| 2142 | const QList<QRgb> *, QDitherInfo *) |
| 2143 | { |
| 2144 | const QRgba64 *s = reinterpret_cast<const QRgba64 *>(src) + index; |
| 2145 | for (int i = 0; i < count; ++i) |
| 2146 | buffer[i] = qConvertRgb64ToRgbaF32(c: s[i]).premultiplied(); |
| 2147 | return buffer; |
| 2148 | } |
| 2149 | |
| 2150 | static const QRgbaFloat32 *QT_FASTCALL fetchRGBA64PMToRGBA32F(QRgbaFloat32 *buffer, const uchar *src, int index, int count, |
| 2151 | const QList<QRgb> *, QDitherInfo *) |
| 2152 | { |
| 2153 | const QRgba64 *s = reinterpret_cast<const QRgba64 *>(src) + index; |
| 2154 | for (int i = 0; i < count; ++i) |
| 2155 | buffer[i] = qConvertRgb64ToRgbaF32(c: s[i]); |
| 2156 | return buffer; |
| 2157 | } |
| 2158 | |
| 2159 | static const QRgbaFloat32 *QT_FASTCALL fetchRGBA16FToRGBA32F(QRgbaFloat32 *buffer, const uchar *src, int index, int count, |
| 2160 | const QList<QRgb> *, QDitherInfo *) |
| 2161 | { |
| 2162 | const QRgbaFloat16 *s = reinterpret_cast<const QRgbaFloat16 *>(src) + index; |
| 2163 | for (int i = 0; i < count; ++i) { |
| 2164 | auto c = s[i].premultiplied(); |
| 2165 | buffer[i] = QRgbaFloat32 { .r: c.r, .g: c.g, .b: c.b, .a: c.a}; |
| 2166 | } |
| 2167 | return buffer; |
| 2168 | } |
| 2169 | |
| 2170 | static const QRgbaFloat32 *QT_FASTCALL fetchRGBA16F(QRgbaFloat32 *buffer, const uchar *src, int index, int count, |
| 2171 | const QList<QRgb> *, QDitherInfo *) |
| 2172 | { |
| 2173 | const QRgbaFloat16 *s = reinterpret_cast<const QRgbaFloat16 *>(src) + index; |
| 2174 | qFloatFromFloat16((float *)buffer, (const qfloat16 *)s, length: count * 4); |
| 2175 | return buffer; |
| 2176 | } |
| 2177 | |
| 2178 | static const QRgbaFloat32 *QT_FASTCALL fetchRGBA32FToRGBA32F(QRgbaFloat32 *buffer, const uchar *src, int index, int count, |
| 2179 | const QList<QRgb> *, QDitherInfo *) |
| 2180 | { |
| 2181 | const QRgbaFloat32 *s = reinterpret_cast<const QRgbaFloat32 *>(src) + index; |
| 2182 | for (int i = 0; i < count; ++i) |
| 2183 | buffer[i] = s[i].premultiplied(); |
| 2184 | return buffer; |
| 2185 | } |
| 2186 | |
| 2187 | static const QRgbaFloat32 *QT_FASTCALL fetchRGBA32F(QRgbaFloat32 *, const uchar *src, int index, int, |
| 2188 | const QList<QRgb> *, QDitherInfo *) |
| 2189 | { |
| 2190 | const QRgbaFloat32 *s = reinterpret_cast<const QRgbaFloat32 *>(src) + index; |
| 2191 | return s; |
| 2192 | } |
| 2193 | |
| 2194 | static const QRgbaFloat32 *QT_FASTCALL fetchCMYKToRGBA32F(QRgbaFloat32 *buffer, const uchar *src, int index, int count, |
| 2195 | const QList<QRgb> *, QDitherInfo *) |
| 2196 | { |
| 2197 | const uint *s = reinterpret_cast<const uint *>(src) + index; |
| 2198 | for (int i = 0; i < count; ++i) |
| 2199 | buffer[i] = QRgbaFloat32::fromArgb32(rgb: QCmyk32::fromCmyk32(cmyk: s[i]).toColor().rgba()); |
| 2200 | |
| 2201 | return buffer; |
| 2202 | } |
| 2203 | |
| 2204 | FetchAndConvertPixelsFuncFP qFetchToRGBA32F[] = { |
| 2205 | nullptr, |
| 2206 | fetchIndexedToRGBA32F<QPixelLayout::BPP1MSB>, |
| 2207 | fetchIndexedToRGBA32F<QPixelLayout::BPP1LSB>, |
| 2208 | fetchIndexedToRGBA32F<QPixelLayout::BPP8>, |
| 2209 | fetchRGBToRGB32F<QImage::Format_RGB32>, |
| 2210 | fetchARGBToRGBA32F<QImage::Format_ARGB32>, |
| 2211 | fetchARGBPMToRGBA32F<QImage::Format_ARGB32_Premultiplied>, |
| 2212 | fetchRGBToRGB32F<QImage::Format_RGB16>, |
| 2213 | fetchARGBToRGBA32F<QImage::Format_ARGB8565_Premultiplied>, |
| 2214 | fetchRGBToRGB32F<QImage::Format_RGB666>, |
| 2215 | fetchARGBToRGBA32F<QImage::Format_ARGB6666_Premultiplied>, |
| 2216 | fetchRGBToRGB32F<QImage::Format_RGB555>, |
| 2217 | fetchARGBToRGBA32F<QImage::Format_ARGB8555_Premultiplied>, |
| 2218 | fetchRGBToRGB32F<QImage::Format_RGB888>, |
| 2219 | fetchRGBToRGB32F<QImage::Format_RGB444>, |
| 2220 | fetchARGBToRGBA32F<QImage::Format_ARGB4444_Premultiplied>, |
| 2221 | fetchRGBToRGB32F<QImage::Format_RGBX8888>, |
| 2222 | fetchARGBToRGBA32F<QImage::Format_RGBA8888>, |
| 2223 | fetchARGBPMToRGBA32F<QImage::Format_RGBA8888_Premultiplied>, |
| 2224 | fetchRGB30ToRGBA32F<PixelOrderBGR>, |
| 2225 | fetchRGB30ToRGBA32F<PixelOrderBGR>, |
| 2226 | fetchRGB30ToRGBA32F<PixelOrderRGB>, |
| 2227 | fetchRGB30ToRGBA32F<PixelOrderRGB>, |
| 2228 | fetchAlpha8To<QRgbaFloat32>, |
| 2229 | fetchGrayscale8To<QRgbaFloat32>, |
| 2230 | fetchRGBX64ToRGBA32F, |
| 2231 | fetchRGBA64ToRGBA32F, |
| 2232 | fetchRGBA64PMToRGBA32F, |
| 2233 | fetchGrayscale16To<QRgbaFloat32>, |
| 2234 | fetchRGBToRGB32F<QImage::Format_BGR888>, |
| 2235 | fetchRGBA16F, |
| 2236 | fetchRGBA16FToRGBA32F, |
| 2237 | fetchRGBA16F, |
| 2238 | fetchRGBA32F, |
| 2239 | fetchRGBA32FToRGBA32F, |
| 2240 | fetchRGBA32F, |
| 2241 | fetchCMYKToRGBA32F, |
| 2242 | }; |
| 2243 | |
| 2244 | static_assert(std::size(qFetchToRGBA32F) == QImage::NImageFormats); |
| 2245 | |
| 2246 | static void QT_FASTCALL convertFromRgba32f(uint *dest, const QRgbaFloat32 *src, int length) |
| 2247 | { |
| 2248 | for (int i = 0; i < length; ++i) |
| 2249 | dest[i] = src[i].toArgb32(); |
| 2250 | } |
| 2251 | |
| 2252 | template<QImage::Format format> |
| 2253 | static void QT_FASTCALL storeGenericFromRGBA32F(uchar *dest, const QRgbaFloat32 *src, int index, int count, |
| 2254 | const QList<QRgb> *clut, QDitherInfo *dither) |
| 2255 | { |
| 2256 | Q_DECL_UNINITIALIZED uint buffer[BufferSize]; |
| 2257 | convertFromRgba32f(dest: buffer, src, length: count); |
| 2258 | qPixelLayouts[format].storeFromARGB32PM(dest, buffer, index, count, clut, dither); |
| 2259 | } |
| 2260 | |
| 2261 | static void QT_FASTCALL storeARGB32FromRGBA32F(uchar *dest, const QRgbaFloat32 *src, int index, int count, |
| 2262 | const QList<QRgb> *, QDitherInfo *) |
| 2263 | { |
| 2264 | uint *d = (uint*)dest + index; |
| 2265 | for (int i = 0; i < count; ++i) |
| 2266 | d[i] = src[i].unpremultiplied().toArgb32(); |
| 2267 | } |
| 2268 | |
| 2269 | static void QT_FASTCALL storeRGBA8888FromRGBA32F(uchar *dest, const QRgbaFloat32 *src, int index, int count, |
| 2270 | const QList<QRgb> *, QDitherInfo *) |
| 2271 | { |
| 2272 | uint *d = (uint*)dest + index; |
| 2273 | for (int i = 0; i < count; ++i) |
| 2274 | d[i] = ARGB2RGBA(x: src[i].unpremultiplied().toArgb32()); |
| 2275 | } |
| 2276 | |
| 2277 | template<QtPixelOrder PixelOrder> |
| 2278 | static void QT_FASTCALL storeRGB30FromRGBA32F(uchar *dest, const QRgbaFloat32 *src, int index, int count, |
| 2279 | const QList<QRgb> *, QDitherInfo *) |
| 2280 | { |
| 2281 | uint *d = (uint*)dest + index; |
| 2282 | for (int i = 0; i < count; ++i) { |
| 2283 | const auto s = src[i]; |
| 2284 | d[i] = qConvertRgb64ToRgb30<PixelOrder>(QRgba64::fromRgba64(red: s.red16(), green: s.green16(), blue: s.blue16(), alpha: s.alpha16())); |
| 2285 | } |
| 2286 | } |
| 2287 | |
| 2288 | static void QT_FASTCALL storeRGBX64FromRGBA32F(uchar *dest, const QRgbaFloat32 *src, int index, int count, |
| 2289 | const QList<QRgb> *, QDitherInfo *) |
| 2290 | { |
| 2291 | QRgba64 *d = reinterpret_cast<QRgba64 *>(dest) + index; |
| 2292 | for (int i = 0; i < count; ++i) { |
| 2293 | const auto s = src[i].unpremultiplied(); |
| 2294 | d[i] = QRgba64::fromRgba64(red: s.red16(), green: s.green16(), blue: s.blue16(), alpha: 65535); |
| 2295 | } |
| 2296 | } |
| 2297 | |
| 2298 | static void QT_FASTCALL storeRGBA64FromRGBA32F(uchar *dest, const QRgbaFloat32 *src, int index, int count, |
| 2299 | const QList<QRgb> *, QDitherInfo *) |
| 2300 | { |
| 2301 | QRgba64 *d = reinterpret_cast<QRgba64 *>(dest) + index; |
| 2302 | for (int i = 0; i < count; ++i) { |
| 2303 | const auto s = src[i].unpremultiplied(); |
| 2304 | d[i] = QRgba64::fromRgba64(red: s.red16(), green: s.green16(), blue: s.blue16(), alpha: s.alpha16()); |
| 2305 | } |
| 2306 | } |
| 2307 | |
| 2308 | static void QT_FASTCALL storeRGBA64PMFromRGBA32F(uchar *dest, const QRgbaFloat32 *src, int index, int count, |
| 2309 | const QList<QRgb> *, QDitherInfo *) |
| 2310 | { |
| 2311 | QRgba64 *d = reinterpret_cast<QRgba64 *>(dest) + index; |
| 2312 | for (int i = 0; i < count; ++i) |
| 2313 | d[i] = QRgba64::fromRgba64(red: src[i].red16(), green: src[i].green16(), blue: src[i].blue16(), alpha: src[i].alpha16()); |
| 2314 | } |
| 2315 | |
| 2316 | static void QT_FASTCALL storeGray16FromRGBA32F(uchar *dest, const QRgbaFloat32 *src, int index, int count, |
| 2317 | const QList<QRgb> *, QDitherInfo *) |
| 2318 | { |
| 2319 | quint16 *d = reinterpret_cast<quint16 *>(dest) + index; |
| 2320 | for (int i = 0; i < count; ++i) { |
| 2321 | auto s = src[i].unpremultiplied(); |
| 2322 | d[i] = qGray(r: s.red16(), g: s.green16(), b: s.blue16()); |
| 2323 | } |
| 2324 | } |
| 2325 | |
| 2326 | static void QT_FASTCALL storeRGBX16FFromRGBA32F(uchar *dest, const QRgbaFloat32 *src, int index, int count, |
| 2327 | const QList<QRgb> *, QDitherInfo *) |
| 2328 | { |
| 2329 | QRgbaFloat16 *d = reinterpret_cast<QRgbaFloat16 *>(dest) + index; |
| 2330 | for (int i = 0; i < count; ++i) { |
| 2331 | auto s = src[i].unpremultiplied(); |
| 2332 | d[i] = QRgbaFloat16{ .r: qfloat16(s.r), .g: qfloat16(s.g), .b: qfloat16(s.b), .a: qfloat16(1.0f) }; |
| 2333 | } |
| 2334 | } |
| 2335 | |
| 2336 | static void QT_FASTCALL storeRGBA16FFromRGBA32F(uchar *dest, const QRgbaFloat32 *src, int index, int count, |
| 2337 | const QList<QRgb> *, QDitherInfo *) |
| 2338 | { |
| 2339 | QRgbaFloat16 *d = reinterpret_cast<QRgbaFloat16 *>(dest) + index; |
| 2340 | for (int i = 0; i < count; ++i) { |
| 2341 | auto s = src[i].unpremultiplied(); |
| 2342 | d[i] = QRgbaFloat16{ .r: qfloat16(s.r), .g: qfloat16(s.g), .b: qfloat16(s.b), .a: qfloat16(s.a) }; |
| 2343 | } |
| 2344 | } |
| 2345 | |
| 2346 | static void QT_FASTCALL storeRGBA16FPMFromRGBA32F(uchar *dest, const QRgbaFloat32 *src, int index, int count, |
| 2347 | const QList<QRgb> *, QDitherInfo *) |
| 2348 | { |
| 2349 | QRgbaFloat16 *d = reinterpret_cast<QRgbaFloat16 *>(dest) + index; |
| 2350 | qFloatToFloat16((qfloat16 *)d, (const float *)src, length: count * 4); |
| 2351 | } |
| 2352 | |
| 2353 | static void QT_FASTCALL storeRGBX32FFromRGBA32F(uchar *dest, const QRgbaFloat32 *src, int index, int count, |
| 2354 | const QList<QRgb> *, QDitherInfo *) |
| 2355 | { |
| 2356 | QRgbaFloat32 *d = reinterpret_cast<QRgbaFloat32 *>(dest) + index; |
| 2357 | for (int i = 0; i < count; ++i) { |
| 2358 | auto s = src[i].unpremultiplied(); |
| 2359 | s.a = 1.0f; |
| 2360 | d[i] = s; |
| 2361 | } |
| 2362 | } |
| 2363 | |
| 2364 | static void QT_FASTCALL storeRGBA32FFromRGBA32F(uchar *dest, const QRgbaFloat32 *src, int index, int count, |
| 2365 | const QList<QRgb> *, QDitherInfo *) |
| 2366 | { |
| 2367 | QRgbaFloat32 *d = reinterpret_cast<QRgbaFloat32 *>(dest) + index; |
| 2368 | for (int i = 0; i < count; ++i) |
| 2369 | d[i] = src[i].unpremultiplied(); |
| 2370 | } |
| 2371 | |
| 2372 | static void QT_FASTCALL storeRGBA32FPMFromRGBA32F(uchar *dest, const QRgbaFloat32 *src, int index, int count, |
| 2373 | const QList<QRgb> *, QDitherInfo *) |
| 2374 | { |
| 2375 | QRgbaFloat32 *d = reinterpret_cast<QRgbaFloat32 *>(dest) + index; |
| 2376 | if (d != src) { |
| 2377 | for (int i = 0; i < count; ++i) |
| 2378 | d[i] = src[i]; |
| 2379 | } |
| 2380 | } |
| 2381 | |
| 2382 | static void QT_FASTCALL storeCMYKFromRGBA32F(uchar *dest, const QRgbaFloat32 *src, int index, int count, |
| 2383 | const QList<QRgb> *, QDitherInfo *) |
| 2384 | { |
| 2385 | uint *d = reinterpret_cast<uint *>(dest) + index; |
| 2386 | for (int i = 0; i < count; ++i) { |
| 2387 | // Yikes, this really needs enablers in QColor and friends |
| 2388 | d[i] = QCmyk32::fromColor(color: QColor(src[i].toArgb32())).toUint(); |
| 2389 | } |
| 2390 | } |
| 2391 | |
| 2392 | ConvertAndStorePixelsFuncFP qStoreFromRGBA32F[] = { |
| 2393 | nullptr, |
| 2394 | nullptr, |
| 2395 | nullptr, |
| 2396 | nullptr, |
| 2397 | storeGenericFromRGBA32F<QImage::Format_RGB32>, |
| 2398 | storeARGB32FromRGBA32F, |
| 2399 | storeGenericFromRGBA32F<QImage::Format_ARGB32_Premultiplied>, |
| 2400 | storeGenericFromRGBA32F<QImage::Format_RGB16>, |
| 2401 | storeGenericFromRGBA32F<QImage::Format_ARGB8565_Premultiplied>, |
| 2402 | storeGenericFromRGBA32F<QImage::Format_RGB666>, |
| 2403 | storeGenericFromRGBA32F<QImage::Format_ARGB6666_Premultiplied>, |
| 2404 | storeGenericFromRGBA32F<QImage::Format_RGB555>, |
| 2405 | storeGenericFromRGBA32F<QImage::Format_ARGB8555_Premultiplied>, |
| 2406 | storeGenericFromRGBA32F<QImage::Format_RGB888>, |
| 2407 | storeGenericFromRGBA32F<QImage::Format_RGB444>, |
| 2408 | storeGenericFromRGBA32F<QImage::Format_ARGB4444_Premultiplied>, |
| 2409 | storeGenericFromRGBA32F<QImage::Format_RGBX8888>, |
| 2410 | storeRGBA8888FromRGBA32F, |
| 2411 | storeGenericFromRGBA32F<QImage::Format_RGBA8888_Premultiplied>, |
| 2412 | storeRGB30FromRGBA32F<PixelOrderBGR>, |
| 2413 | storeRGB30FromRGBA32F<PixelOrderBGR>, |
| 2414 | storeRGB30FromRGBA32F<PixelOrderRGB>, |
| 2415 | storeRGB30FromRGBA32F<PixelOrderRGB>, |
| 2416 | storeGenericFromRGBA32F<QImage::Format_Alpha8>, |
| 2417 | storeGenericFromRGBA32F<QImage::Format_Grayscale8>, |
| 2418 | storeRGBX64FromRGBA32F, |
| 2419 | storeRGBA64FromRGBA32F, |
| 2420 | storeRGBA64PMFromRGBA32F, |
| 2421 | storeGray16FromRGBA32F, |
| 2422 | storeGenericFromRGBA32F<QImage::Format_BGR888>, |
| 2423 | storeRGBX16FFromRGBA32F, |
| 2424 | storeRGBA16FFromRGBA32F, |
| 2425 | storeRGBA16FPMFromRGBA32F, |
| 2426 | storeRGBX32FFromRGBA32F, |
| 2427 | storeRGBA32FFromRGBA32F, |
| 2428 | storeRGBA32FPMFromRGBA32F, |
| 2429 | storeCMYKFromRGBA32F, |
| 2430 | }; |
| 2431 | |
| 2432 | static_assert(std::size(qStoreFromRGBA32F) == QImage::NImageFormats); |
| 2433 | |
| 2434 | #endif // QT_CONFIG(raster_fp) |
| 2435 | |
| 2436 | QT_END_NAMESPACE |
| 2437 | |