1/****************************************************************************
2**
3** Copyright (C) 2016 The Qt Company Ltd.
4** Contact: https://www.qt.io/licensing/
5**
6** This file is part of the QtGui module of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:LGPL$
9** Commercial License Usage
10** Licensees holding valid commercial Qt licenses may use this file in
11** accordance with the commercial license agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and The Qt Company. For licensing terms
14** and conditions see https://www.qt.io/terms-conditions. For further
15** information use the contact form at https://www.qt.io/contact-us.
16**
17** GNU Lesser General Public License Usage
18** Alternatively, this file may be used under the terms of the GNU Lesser
19** General Public License version 3 as published by the Free Software
20** Foundation and appearing in the file LICENSE.LGPL3 included in the
21** packaging of this file. Please review the following information to
22** ensure the GNU Lesser General Public License version 3 requirements
23** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
24**
25** GNU General Public License Usage
26** Alternatively, this file may be used under the terms of the GNU
27** General Public License version 2.0 or (at your option) the GNU General
28** Public license version 3 or any later version approved by the KDE Free
29** Qt Foundation. The licenses are as published by the Free Software
30** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
31** included in the packaging of this file. Please review the following
32** information to ensure the GNU General Public License requirements will
33** be met: https://www.gnu.org/licenses/gpl-2.0.html and
34** https://www.gnu.org/licenses/gpl-3.0.html.
35**
36** $QT_END_LICENSE$
37**
38****************************************************************************/
39
40#ifndef QDRAWHELPER_P_H
41#define QDRAWHELPER_P_H
42
43//
44// W A R N I N G
45// -------------
46//
47// This file is not part of the Qt API. It exists purely as an
48// implementation detail. This header file may change from version to
49// version without notice, or even be removed.
50//
51// We mean it.
52//
53
54#include <QtGui/private/qtguiglobal_p.h>
55#include "QtCore/qmath.h"
56#include "QtGui/qcolor.h"
57#include "QtGui/qpainter.h"
58#include "QtGui/qimage.h"
59#include "QtGui/qrgba64.h"
60#ifndef QT_FT_BEGIN_HEADER
61#define QT_FT_BEGIN_HEADER
62#define QT_FT_END_HEADER
63#endif
64#include "private/qpixellayout_p.h"
65#include "private/qrasterdefs_p.h"
66#include <private/qsimd_p.h>
67
68#include <QtCore/qsharedpointer.h>
69
70QT_BEGIN_NAMESPACE
71
72#if defined(Q_CC_GNU)
73# define Q_DECL_RESTRICT __restrict__
74# if defined(Q_PROCESSOR_X86_32) && defined(Q_CC_GNU) && !defined(Q_CC_CLANG) && !defined(Q_CC_INTEL)
75# define Q_DECL_VECTORCALL __attribute__((sseregparm,regparm(3)))
76# else
77# define Q_DECL_VECTORCALL
78# endif
79#elif defined(Q_CC_MSVC)
80# define Q_DECL_RESTRICT __restrict
81# define Q_DECL_VECTORCALL __vectorcall
82#else
83# define Q_DECL_RESTRICT
84# define Q_DECL_VECTORCALL
85#endif
86
87static const uint AMASK = 0xff000000;
88static const uint RMASK = 0x00ff0000;
89static const uint GMASK = 0x0000ff00;
90static const uint BMASK = 0x000000ff;
91
92/*******************************************************************************
93 * QSpan
94 *
95 * duplicate definition of FT_Span
96 */
97typedef QT_FT_Span QSpan;
98
99struct QSolidData;
100struct QTextureData;
101struct QGradientData;
102struct QLinearGradientData;
103struct QRadialGradientData;
104struct QConicalGradientData;
105struct QSpanData;
106class QGradient;
107class QRasterBuffer;
108class QClipData;
109class QRasterPaintEngineState;
110
111typedef QT_FT_SpanFunc ProcessSpans;
112typedef void (*BitmapBlitFunc)(QRasterBuffer *rasterBuffer,
113 int x, int y, const QRgba64 &color,
114 const uchar *bitmap,
115 int mapWidth, int mapHeight, int mapStride);
116
117typedef void (*AlphamapBlitFunc)(QRasterBuffer *rasterBuffer,
118 int x, int y, const QRgba64 &color,
119 const uchar *bitmap,
120 int mapWidth, int mapHeight, int mapStride,
121 const QClipData *clip, bool useGammaCorrection);
122
123typedef void (*AlphaRGBBlitFunc)(QRasterBuffer *rasterBuffer,
124 int x, int y, const QRgba64 &color,
125 const uint *rgbmask,
126 int mapWidth, int mapHeight, int mapStride,
127 const QClipData *clip, bool useGammaCorrection);
128
129typedef void (*RectFillFunc)(QRasterBuffer *rasterBuffer,
130 int x, int y, int width, int height,
131 const QRgba64 &color);
132
133typedef void (*SrcOverBlendFunc)(uchar *destPixels, int dbpl,
134 const uchar *src, int spbl,
135 int w, int h,
136 int const_alpha);
137
138typedef void (*SrcOverScaleFunc)(uchar *destPixels, int dbpl,
139 const uchar *src, int spbl, int srch,
140 const QRectF &targetRect,
141 const QRectF &sourceRect,
142 const QRect &clipRect,
143 int const_alpha);
144
145typedef void (*SrcOverTransformFunc)(uchar *destPixels, int dbpl,
146 const uchar *src, int spbl,
147 const QRectF &targetRect,
148 const QRectF &sourceRect,
149 const QRect &clipRect,
150 const QTransform &targetRectTransform,
151 int const_alpha);
152
153struct DrawHelper {
154 ProcessSpans blendColor;
155 BitmapBlitFunc bitmapBlit;
156 AlphamapBlitFunc alphamapBlit;
157 AlphaRGBBlitFunc alphaRGBBlit;
158 RectFillFunc fillRect;
159};
160
161extern SrcOverBlendFunc qBlendFunctions[QImage::NImageFormats][QImage::NImageFormats];
162extern SrcOverScaleFunc qScaleFunctions[QImage::NImageFormats][QImage::NImageFormats];
163extern SrcOverTransformFunc qTransformFunctions[QImage::NImageFormats][QImage::NImageFormats];
164
165extern DrawHelper qDrawHelper[QImage::NImageFormats];
166
167struct quint24 {
168 quint24() = default;
169 quint24(uint value)
170 {
171 data[0] = uchar(value >> 16);
172 data[1] = uchar(value >> 8);
173 data[2] = uchar(value);
174 }
175 operator uint() const
176 {
177 return data[2] | (data[1] << 8) | (data[0] << 16);
178 }
179
180 uchar data[3];
181};
182
183void qBlendGradient(int count, const QSpan *spans, void *userData);
184void qBlendTexture(int count, const QSpan *spans, void *userData);
185#ifdef __SSE2__
186extern void (*qt_memfill64)(quint64 *dest, quint64 value, qsizetype count);
187extern void (*qt_memfill32)(quint32 *dest, quint32 value, qsizetype count);
188#else
189extern void qt_memfill64(quint64 *dest, quint64 value, qsizetype count);
190extern void qt_memfill32(quint32 *dest, quint32 value, qsizetype count);
191#endif
192extern void qt_memfill24(quint24 *dest, quint24 value, qsizetype count);
193extern void qt_memfill16(quint16 *dest, quint16 value, qsizetype count);
194
195typedef void (QT_FASTCALL *CompositionFunction)(uint *Q_DECL_RESTRICT dest, const uint *Q_DECL_RESTRICT src, int length, uint const_alpha);
196typedef void (QT_FASTCALL *CompositionFunction64)(QRgba64 *Q_DECL_RESTRICT dest, const QRgba64 *Q_DECL_RESTRICT src, int length, uint const_alpha);
197typedef void (QT_FASTCALL *CompositionFunctionSolid)(uint *dest, int length, uint color, uint const_alpha);
198typedef void (QT_FASTCALL *CompositionFunctionSolid64)(QRgba64 *dest, int length, QRgba64 color, uint const_alpha);
199
200struct LinearGradientValues
201{
202 qreal dx;
203 qreal dy;
204 qreal l;
205 qreal off;
206};
207
208struct RadialGradientValues
209{
210 qreal dx;
211 qreal dy;
212 qreal dr;
213 qreal sqrfr;
214 qreal a;
215 qreal inv2a;
216 bool extended;
217};
218
219struct Operator;
220typedef uint* (QT_FASTCALL *DestFetchProc)(uint *buffer, QRasterBuffer *rasterBuffer, int x, int y, int length);
221typedef QRgba64* (QT_FASTCALL *DestFetchProc64)(QRgba64 *buffer, QRasterBuffer *rasterBuffer, int x, int y, int length);
222typedef void (QT_FASTCALL *DestStoreProc)(QRasterBuffer *rasterBuffer, int x, int y, const uint *buffer, int length);
223typedef void (QT_FASTCALL *DestStoreProc64)(QRasterBuffer *rasterBuffer, int x, int y, const QRgba64 *buffer, int length);
224typedef const uint* (QT_FASTCALL *SourceFetchProc)(uint *buffer, const Operator *o, const QSpanData *data, int y, int x, int length);
225typedef const QRgba64* (QT_FASTCALL *SourceFetchProc64)(QRgba64 *buffer, const Operator *o, const QSpanData *data, int y, int x, int length);
226
227struct Operator
228{
229 QPainter::CompositionMode mode;
230 DestFetchProc destFetch;
231 DestStoreProc destStore;
232 SourceFetchProc srcFetch;
233 CompositionFunctionSolid funcSolid;
234 CompositionFunction func;
235
236 DestFetchProc64 destFetch64;
237 DestStoreProc64 destStore64;
238 SourceFetchProc64 srcFetch64;
239 CompositionFunctionSolid64 funcSolid64;
240 CompositionFunction64 func64;
241
242 union {
243 LinearGradientValues linear;
244 RadialGradientValues radial;
245 };
246};
247
248class QRasterPaintEngine;
249
250struct QLinearGradientData
251{
252 struct {
253 qreal x;
254 qreal y;
255 } origin;
256 struct {
257 qreal x;
258 qreal y;
259 } end;
260};
261
262struct QRadialGradientData
263{
264 struct {
265 qreal x;
266 qreal y;
267 qreal radius;
268 } center;
269 struct {
270 qreal x;
271 qreal y;
272 qreal radius;
273 } focal;
274};
275
276struct QConicalGradientData
277{
278 struct {
279 qreal x;
280 qreal y;
281 } center;
282 qreal angle;
283};
284
285struct QGradientData
286{
287 QGradient::Spread spread;
288
289 union {
290 QLinearGradientData linear;
291 QRadialGradientData radial;
292 QConicalGradientData conical;
293 };
294
295#define GRADIENT_STOPTABLE_SIZE 1024
296#define GRADIENT_STOPTABLE_SIZE_SHIFT 10
297
298#if QT_CONFIG(raster_64bit)
299 const QRgba64 *colorTable64; //[GRADIENT_STOPTABLE_SIZE];
300#endif
301 const QRgb *colorTable32; //[GRADIENT_STOPTABLE_SIZE];
302
303 uint alphaColor : 1;
304};
305
306struct QTextureData
307{
308 const uchar *imageData;
309 const uchar *scanLine(int y) const { return imageData + y*bytesPerLine; }
310
311 int width;
312 int height;
313 // clip rect
314 int x1;
315 int y1;
316 int x2;
317 int y2;
318 qsizetype bytesPerLine;
319 QImage::Format format;
320 const QList<QRgb> *colorTable;
321 bool hasAlpha;
322 enum Type {
323 Plain,
324 Tiled
325 };
326 Type type;
327 int const_alpha;
328};
329
330struct QSpanData
331{
332 QSpanData() : tempImage(nullptr) {}
333 ~QSpanData() { delete tempImage; }
334
335 QRasterBuffer *rasterBuffer;
336 ProcessSpans blend;
337 ProcessSpans unclipped_blend;
338 BitmapBlitFunc bitmapBlit;
339 AlphamapBlitFunc alphamapBlit;
340 AlphaRGBBlitFunc alphaRGBBlit;
341 RectFillFunc fillRect;
342 qreal m11, m12, m13, m21, m22, m23, m33, dx, dy; // inverse xform matrix
343 const QClipData *clip;
344 enum Type {
345 None,
346 Solid,
347 LinearGradient,
348 RadialGradient,
349 ConicalGradient,
350 Texture
351 } type : 8;
352 signed int txop : 8;
353 uint fast_matrix : 1;
354 bool bilinear;
355 QImage *tempImage;
356 QRgba64 solidColor;
357 union {
358 QGradientData gradient;
359 QTextureData texture;
360 };
361 class Pinnable {
362 protected:
363 ~Pinnable() {}
364 }; // QSharedPointer<const void> is not supported
365 QSharedPointer<const Pinnable> cachedGradient;
366
367
368 void init(QRasterBuffer *rb, const QRasterPaintEngine *pe);
369 void setup(const QBrush &brush, int alpha, QPainter::CompositionMode compositionMode);
370 void setupMatrix(const QTransform &matrix, int bilinear);
371 void initTexture(const QImage *image, int alpha, QTextureData::Type = QTextureData::Plain, const QRect &sourceRect = QRect());
372 void adjustSpanMethods();
373};
374
375static inline uint qt_gradient_clamp(const QGradientData *data, int ipos)
376{
377 if (ipos < 0 || ipos >= GRADIENT_STOPTABLE_SIZE) {
378 if (data->spread == QGradient::RepeatSpread) {
379 ipos = ipos % GRADIENT_STOPTABLE_SIZE;
380 ipos = ipos < 0 ? GRADIENT_STOPTABLE_SIZE + ipos : ipos;
381 } else if (data->spread == QGradient::ReflectSpread) {
382 const int limit = GRADIENT_STOPTABLE_SIZE * 2;
383 ipos = ipos % limit;
384 ipos = ipos < 0 ? limit + ipos : ipos;
385 ipos = ipos >= GRADIENT_STOPTABLE_SIZE ? limit - 1 - ipos : ipos;
386 } else {
387 if (ipos < 0)
388 ipos = 0;
389 else if (ipos >= GRADIENT_STOPTABLE_SIZE)
390 ipos = GRADIENT_STOPTABLE_SIZE-1;
391 }
392 }
393
394 Q_ASSERT(ipos >= 0);
395 Q_ASSERT(ipos < GRADIENT_STOPTABLE_SIZE);
396
397 return ipos;
398}
399
400static inline uint qt_gradient_pixel(const QGradientData *data, qreal pos)
401{
402 int ipos = int(pos * (GRADIENT_STOPTABLE_SIZE - 1) + qreal(0.5));
403 return data->colorTable32[qt_gradient_clamp(data, ipos)];
404}
405
406#if QT_CONFIG(raster_64bit)
407static inline const QRgba64& qt_gradient_pixel64(const QGradientData *data, qreal pos)
408{
409 int ipos = int(pos * (GRADIENT_STOPTABLE_SIZE - 1) + qreal(0.5));
410 return data->colorTable64[qt_gradient_clamp(data, ipos)];
411}
412#endif
413
414static inline qreal qRadialDeterminant(qreal a, qreal b, qreal c)
415{
416 return (b * b) - (4 * a * c);
417}
418
419template <class RadialFetchFunc, typename BlendType> static
420const BlendType * QT_FASTCALL qt_fetch_radial_gradient_template(BlendType *buffer, const Operator *op,
421 const QSpanData *data, int y, int x, int length)
422{
423 // avoid division by zero
424 if (qFuzzyIsNull(op->radial.a)) {
425 RadialFetchFunc::memfill(buffer, RadialFetchFunc::null(), length);
426 return buffer;
427 }
428
429 const BlendType *b = buffer;
430 qreal rx = data->m21 * (y + qreal(0.5))
431 + data->dx + data->m11 * (x + qreal(0.5));
432 qreal ry = data->m22 * (y + qreal(0.5))
433 + data->dy + data->m12 * (x + qreal(0.5));
434 bool affine = !data->m13 && !data->m23;
435
436 BlendType *end = buffer + length;
437 if (affine) {
438 rx -= data->gradient.radial.focal.x;
439 ry -= data->gradient.radial.focal.y;
440
441 qreal inv_a = 1 / qreal(2 * op->radial.a);
442
443 const qreal delta_rx = data->m11;
444 const qreal delta_ry = data->m12;
445
446 qreal b = 2*(op->radial.dr*data->gradient.radial.focal.radius + rx * op->radial.dx + ry * op->radial.dy);
447 qreal delta_b = 2*(delta_rx * op->radial.dx + delta_ry * op->radial.dy);
448 const qreal b_delta_b = 2 * b * delta_b;
449 const qreal delta_b_delta_b = 2 * delta_b * delta_b;
450
451 const qreal bb = b * b;
452 const qreal delta_bb = delta_b * delta_b;
453
454 b *= inv_a;
455 delta_b *= inv_a;
456
457 const qreal rxrxryry = rx * rx + ry * ry;
458 const qreal delta_rxrxryry = delta_rx * delta_rx + delta_ry * delta_ry;
459 const qreal rx_plus_ry = 2*(rx * delta_rx + ry * delta_ry);
460 const qreal delta_rx_plus_ry = 2 * delta_rxrxryry;
461
462 inv_a *= inv_a;
463
464 qreal det = (bb - 4 * op->radial.a * (op->radial.sqrfr - rxrxryry)) * inv_a;
465 qreal delta_det = (b_delta_b + delta_bb + 4 * op->radial.a * (rx_plus_ry + delta_rxrxryry)) * inv_a;
466 const qreal delta_delta_det = (delta_b_delta_b + 4 * op->radial.a * delta_rx_plus_ry) * inv_a;
467
468 RadialFetchFunc::fetch(buffer, end, op, data, det, delta_det, delta_delta_det, b, delta_b);
469 } else {
470 qreal rw = data->m23 * (y + qreal(0.5))
471 + data->m33 + data->m13 * (x + qreal(0.5));
472
473 while (buffer < end) {
474 if (rw == 0) {
475 *buffer = 0;
476 } else {
477 qreal invRw = 1 / rw;
478 qreal gx = rx * invRw - data->gradient.radial.focal.x;
479 qreal gy = ry * invRw - data->gradient.radial.focal.y;
480 qreal b = 2*(op->radial.dr*data->gradient.radial.focal.radius + gx*op->radial.dx + gy*op->radial.dy);
481 qreal det = qRadialDeterminant(op->radial.a, b, op->radial.sqrfr - (gx*gx + gy*gy));
482
483 BlendType result = RadialFetchFunc::null();
484 if (det >= 0) {
485 qreal detSqrt = qSqrt(det);
486
487 qreal s0 = (-b - detSqrt) * op->radial.inv2a;
488 qreal s1 = (-b + detSqrt) * op->radial.inv2a;
489
490 qreal s = qMax(s0, s1);
491
492 if (data->gradient.radial.focal.radius + op->radial.dr * s >= 0)
493 result = RadialFetchFunc::fetchSingle(data->gradient, s);
494 }
495
496 *buffer = result;
497 }
498
499 rx += data->m11;
500 ry += data->m12;
501 rw += data->m13;
502
503 ++buffer;
504 }
505 }
506
507 return b;
508}
509
510template <class Simd>
511class QRadialFetchSimd
512{
513public:
514 static uint null() { return 0; }
515 static uint fetchSingle(const QGradientData& gradient, qreal v)
516 {
517 return qt_gradient_pixel(&gradient, v);
518 }
519 static void memfill(uint *buffer, uint fill, int length)
520 {
521 qt_memfill32(buffer, fill, length);
522 }
523 static void fetch(uint *buffer, uint *end, const Operator *op, const QSpanData *data, qreal det,
524 qreal delta_det, qreal delta_delta_det, qreal b, qreal delta_b)
525 {
526 typename Simd::Vect_buffer_f det_vec;
527 typename Simd::Vect_buffer_f delta_det4_vec;
528 typename Simd::Vect_buffer_f b_vec;
529
530 for (int i = 0; i < 4; ++i) {
531 det_vec.f[i] = det;
532 delta_det4_vec.f[i] = 4 * delta_det;
533 b_vec.f[i] = b;
534
535 det += delta_det;
536 delta_det += delta_delta_det;
537 b += delta_b;
538 }
539
540 const typename Simd::Float32x4 v_delta_delta_det16 = Simd::v_dup(16 * delta_delta_det);
541 const typename Simd::Float32x4 v_delta_delta_det6 = Simd::v_dup(6 * delta_delta_det);
542 const typename Simd::Float32x4 v_delta_b4 = Simd::v_dup(4 * delta_b);
543
544 const typename Simd::Float32x4 v_r0 = Simd::v_dup(data->gradient.radial.focal.radius);
545 const typename Simd::Float32x4 v_dr = Simd::v_dup(op->radial.dr);
546
547#if defined(__ARM_NEON__)
548 // NEON doesn't have SIMD sqrt, but uses rsqrt instead that can't be taken of 0.
549 const typename Simd::Float32x4 v_min = Simd::v_dup(std::numeric_limits<float>::epsilon());
550#else
551 const typename Simd::Float32x4 v_min = Simd::v_dup(0.0f);
552#endif
553 const typename Simd::Float32x4 v_max = Simd::v_dup(float(GRADIENT_STOPTABLE_SIZE-1));
554 const typename Simd::Float32x4 v_half = Simd::v_dup(0.5f);
555
556 const typename Simd::Int32x4 v_repeat_mask = Simd::v_dup(~(uint(0xffffff) << GRADIENT_STOPTABLE_SIZE_SHIFT));
557 const typename Simd::Int32x4 v_reflect_mask = Simd::v_dup(~(uint(0xffffff) << (GRADIENT_STOPTABLE_SIZE_SHIFT+1)));
558
559 const typename Simd::Int32x4 v_reflect_limit = Simd::v_dup(2 * GRADIENT_STOPTABLE_SIZE - 1);
560
561 const int extended_mask = op->radial.extended ? 0x0 : ~0x0;
562
563#define FETCH_RADIAL_LOOP_PROLOGUE \
564 while (buffer < end) { \
565 typename Simd::Vect_buffer_i v_buffer_mask; \
566 v_buffer_mask.v = Simd::v_greaterOrEqual(det_vec.v, v_min); \
567 const typename Simd::Float32x4 v_index_local = Simd::v_sub(Simd::v_sqrt(Simd::v_max(v_min, det_vec.v)), b_vec.v); \
568 const typename Simd::Float32x4 v_index = Simd::v_add(Simd::v_mul(v_index_local, v_max), v_half); \
569 v_buffer_mask.v = Simd::v_and(v_buffer_mask.v, Simd::v_greaterOrEqual(Simd::v_add(v_r0, Simd::v_mul(v_dr, v_index_local)), v_min)); \
570 typename Simd::Vect_buffer_i index_vec;
571#define FETCH_RADIAL_LOOP_CLAMP_REPEAT \
572 index_vec.v = Simd::v_and(v_repeat_mask, Simd::v_toInt(v_index));
573#define FETCH_RADIAL_LOOP_CLAMP_REFLECT \
574 const typename Simd::Int32x4 v_index_i = Simd::v_and(v_reflect_mask, Simd::v_toInt(v_index)); \
575 const typename Simd::Int32x4 v_index_i_inv = Simd::v_sub(v_reflect_limit, v_index_i); \
576 index_vec.v = Simd::v_min_16(v_index_i, v_index_i_inv);
577#define FETCH_RADIAL_LOOP_CLAMP_PAD \
578 index_vec.v = Simd::v_toInt(Simd::v_min(v_max, Simd::v_max(v_min, v_index)));
579#define FETCH_RADIAL_LOOP_EPILOGUE \
580 det_vec.v = Simd::v_add(Simd::v_add(det_vec.v, delta_det4_vec.v), v_delta_delta_det6); \
581 delta_det4_vec.v = Simd::v_add(delta_det4_vec.v, v_delta_delta_det16); \
582 b_vec.v = Simd::v_add(b_vec.v, v_delta_b4); \
583 for (int i = 0; i < 4; ++i) \
584 *buffer++ = (extended_mask | v_buffer_mask.i[i]) & data->gradient.colorTable32[index_vec.i[i]]; \
585 }
586
587#define FETCH_RADIAL_LOOP(FETCH_RADIAL_LOOP_CLAMP) \
588 FETCH_RADIAL_LOOP_PROLOGUE \
589 FETCH_RADIAL_LOOP_CLAMP \
590 FETCH_RADIAL_LOOP_EPILOGUE
591
592 switch (data->gradient.spread) {
593 case QGradient::RepeatSpread:
594 FETCH_RADIAL_LOOP(FETCH_RADIAL_LOOP_CLAMP_REPEAT)
595 break;
596 case QGradient::ReflectSpread:
597 FETCH_RADIAL_LOOP(FETCH_RADIAL_LOOP_CLAMP_REFLECT)
598 break;
599 case QGradient::PadSpread:
600 FETCH_RADIAL_LOOP(FETCH_RADIAL_LOOP_CLAMP_PAD)
601 break;
602 default:
603 Q_UNREACHABLE();
604 }
605 }
606};
607
608static inline uint INTERPOLATE_PIXEL_255(uint x, uint a, uint y, uint b) {
609 uint t = (x & 0xff00ff) * a + (y & 0xff00ff) * b;
610 t = (t + ((t >> 8) & 0xff00ff) + 0x800080) >> 8;
611 t &= 0xff00ff;
612
613 x = ((x >> 8) & 0xff00ff) * a + ((y >> 8) & 0xff00ff) * b;
614 x = (x + ((x >> 8) & 0xff00ff) + 0x800080);
615 x &= 0xff00ff00;
616 x |= t;
617 return x;
618}
619
620#if Q_PROCESSOR_WORDSIZE == 8 // 64-bit versions
621
622static inline uint INTERPOLATE_PIXEL_256(uint x, uint a, uint y, uint b) {
623 quint64 t = (((quint64(x)) | ((quint64(x)) << 24)) & 0x00ff00ff00ff00ff) * a;
624 t += (((quint64(y)) | ((quint64(y)) << 24)) & 0x00ff00ff00ff00ff) * b;
625 t >>= 8;
626 t &= 0x00ff00ff00ff00ff;
627 return (uint(t)) | (uint(t >> 24));
628}
629
630static inline uint BYTE_MUL(uint x, uint a) {
631 quint64 t = (((quint64(x)) | ((quint64(x)) << 24)) & 0x00ff00ff00ff00ff) * a;
632 t = (t + ((t >> 8) & 0xff00ff00ff00ff) + 0x80008000800080) >> 8;
633 t &= 0x00ff00ff00ff00ff;
634 return (uint(t)) | (uint(t >> 24));
635}
636
637#else // 32-bit versions
638
639static inline uint INTERPOLATE_PIXEL_256(uint x, uint a, uint y, uint b) {
640 uint t = (x & 0xff00ff) * a + (y & 0xff00ff) * b;
641 t >>= 8;
642 t &= 0xff00ff;
643
644 x = ((x >> 8) & 0xff00ff) * a + ((y >> 8) & 0xff00ff) * b;
645 x &= 0xff00ff00;
646 x |= t;
647 return x;
648}
649
650static inline uint BYTE_MUL(uint x, uint a) {
651 uint t = (x & 0xff00ff) * a;
652 t = (t + ((t >> 8) & 0xff00ff) + 0x800080) >> 8;
653 t &= 0xff00ff;
654
655 x = ((x >> 8) & 0xff00ff) * a;
656 x = (x + ((x >> 8) & 0xff00ff) + 0x800080);
657 x &= 0xff00ff00;
658 x |= t;
659 return x;
660}
661#endif
662
663static inline void blend_pixel(quint32 &dst, const quint32 src)
664{
665 if (src >= 0xff000000)
666 dst = src;
667 else if (src != 0)
668 dst = src + BYTE_MUL(dst, qAlpha(~src));
669}
670
671static inline void blend_pixel(quint32 &dst, const quint32 src, const int const_alpha)
672{
673 if (const_alpha == 255)
674 return blend_pixel(dst, src);
675 if (src != 0) {
676 const quint32 s = BYTE_MUL(src, const_alpha);
677 dst = s + BYTE_MUL(dst, qAlpha(~s));
678 }
679}
680
681#if defined(__SSE2__)
682static inline uint Q_DECL_VECTORCALL interpolate_4_pixels_sse2(__m128i vt, __m128i vb, uint distx, uint disty)
683{
684 // First interpolate top and bottom pixels in parallel.
685 vt = _mm_unpacklo_epi8(vt, _mm_setzero_si128());
686 vb = _mm_unpacklo_epi8(vb, _mm_setzero_si128());
687 vt = _mm_mullo_epi16(vt, _mm_set1_epi16(256 - disty));
688 vb = _mm_mullo_epi16(vb, _mm_set1_epi16(disty));
689 __m128i vlr = _mm_add_epi16(vt, vb);
690 vlr = _mm_srli_epi16(vlr, 8);
691 // vlr now contains the result of the first two interpolate calls vlr = unpacked((xright << 64) | xleft)
692
693 // Now the last interpolate between left and right..
694 const __m128i vidistx = _mm_shufflelo_epi16(_mm_cvtsi32_si128(256 - distx), _MM_SHUFFLE(0, 0, 0, 0));
695 const __m128i vdistx = _mm_shufflelo_epi16(_mm_cvtsi32_si128(distx), _MM_SHUFFLE(0, 0, 0, 0));
696 const __m128i vmulx = _mm_unpacklo_epi16(vidistx, vdistx);
697 vlr = _mm_unpacklo_epi16(vlr, _mm_srli_si128(vlr, 8));
698 // vlr now contains the colors of left and right interleaved { la, ra, lr, rr, lg, rg, lb, rb }
699 vlr = _mm_madd_epi16(vlr, vmulx); // Multiply and horizontal add.
700 vlr = _mm_srli_epi32(vlr, 8);
701 vlr = _mm_packs_epi32(vlr, vlr);
702 vlr = _mm_packus_epi16(vlr, vlr);
703 return _mm_cvtsi128_si32(vlr);
704}
705
706static inline uint interpolate_4_pixels(uint tl, uint tr, uint bl, uint br, uint distx, uint disty)
707{
708 __m128i vt = _mm_unpacklo_epi32(_mm_cvtsi32_si128(tl), _mm_cvtsi32_si128(tr));
709 __m128i vb = _mm_unpacklo_epi32(_mm_cvtsi32_si128(bl), _mm_cvtsi32_si128(br));
710 return interpolate_4_pixels_sse2(vt, vb, distx, disty);
711}
712
713static inline uint interpolate_4_pixels(const uint t[], const uint b[], uint distx, uint disty)
714{
715 __m128i vt = _mm_loadl_epi64((const __m128i*)t);
716 __m128i vb = _mm_loadl_epi64((const __m128i*)b);
717 return interpolate_4_pixels_sse2(vt, vb, distx, disty);
718}
719
720static constexpr inline bool hasFastInterpolate4() { return true; }
721
722#elif defined(__ARM_NEON__)
723static inline uint interpolate_4_pixels_neon(uint32x2_t vt32, uint32x2_t vb32, uint distx, uint disty)
724{
725 uint16x8_t vt16 = vmovl_u8(vreinterpret_u8_u32(vt32));
726 uint16x8_t vb16 = vmovl_u8(vreinterpret_u8_u32(vb32));
727 vt16 = vmulq_n_u16(vt16, 256 - disty);
728 vt16 = vmlaq_n_u16(vt16, vb16, disty);
729 vt16 = vshrq_n_u16(vt16, 8);
730 uint16x4_t vl16 = vget_low_u16(vt16);
731 uint16x4_t vr16 = vget_high_u16(vt16);
732 vl16 = vmul_n_u16(vl16, 256 - distx);
733 vl16 = vmla_n_u16(vl16, vr16, distx);
734 vl16 = vshr_n_u16(vl16, 8);
735 uint8x8_t vr = vmovn_u16(vcombine_u16(vl16, vl16));
736 return vget_lane_u32(vreinterpret_u32_u8(vr), 0);
737}
738
739static inline uint interpolate_4_pixels(uint tl, uint tr, uint bl, uint br, uint distx, uint disty)
740{
741 uint32x2_t vt32 = vmov_n_u32(tl);
742 uint32x2_t vb32 = vmov_n_u32(bl);
743 vt32 = vset_lane_u32(tr, vt32, 1);
744 vb32 = vset_lane_u32(br, vb32, 1);
745 return interpolate_4_pixels_neon(vt32, vb32, distx, disty);
746}
747
748static inline uint interpolate_4_pixels(const uint t[], const uint b[], uint distx, uint disty)
749{
750 uint32x2_t vt32 = vld1_u32(t);
751 uint32x2_t vb32 = vld1_u32(b);
752 return interpolate_4_pixels_neon(vt32, vb32, distx, disty);
753}
754
755static constexpr inline bool hasFastInterpolate4() { return true; }
756
757#else
758static inline uint interpolate_4_pixels(uint tl, uint tr, uint bl, uint br, uint distx, uint disty)
759{
760 uint idistx = 256 - distx;
761 uint idisty = 256 - disty;
762 uint xtop = INTERPOLATE_PIXEL_256(tl, idistx, tr, distx);
763 uint xbot = INTERPOLATE_PIXEL_256(bl, idistx, br, distx);
764 return INTERPOLATE_PIXEL_256(xtop, idisty, xbot, disty);
765}
766
767static inline uint interpolate_4_pixels(const uint t[], const uint b[], uint distx, uint disty)
768{
769 return interpolate_4_pixels(t[0], t[1], b[0], b[1], distx, disty);
770}
771
772static constexpr inline bool hasFastInterpolate4() { return false; }
773
774#endif
775
776static inline QRgba64 multiplyAlpha256(QRgba64 rgba64, uint alpha256)
777{
778 return QRgba64::fromRgba64((rgba64.red() * alpha256) >> 8,
779 (rgba64.green() * alpha256) >> 8,
780 (rgba64.blue() * alpha256) >> 8,
781 (rgba64.alpha() * alpha256) >> 8);
782}
783static inline QRgba64 interpolate256(QRgba64 x, uint alpha1, QRgba64 y, uint alpha2)
784{
785 return QRgba64::fromRgba64(multiplyAlpha256(x, alpha1) + multiplyAlpha256(y, alpha2));
786}
787
788#ifdef __SSE2__
789static inline QRgba64 interpolate_4_pixels_rgb64(const QRgba64 t[], const QRgba64 b[], uint distx, uint disty)
790{
791 __m128i vt = _mm_loadu_si128((const __m128i*)t);
792 if (disty) {
793 __m128i vb = _mm_loadu_si128((const __m128i*)b);
794 vt = _mm_mulhi_epu16(vt, _mm_set1_epi16(0x10000 - disty));
795 vb = _mm_mulhi_epu16(vb, _mm_set1_epi16(disty));
796 vt = _mm_add_epi16(vt, vb);
797 }
798 if (distx) {
799 const __m128i vdistx = _mm_shufflelo_epi16(_mm_cvtsi32_si128(distx), _MM_SHUFFLE(0, 0, 0, 0));
800 const __m128i vidistx = _mm_shufflelo_epi16(_mm_cvtsi32_si128(0x10000 - distx), _MM_SHUFFLE(0, 0, 0, 0));
801 vt = _mm_mulhi_epu16(vt, _mm_unpacklo_epi64(vidistx, vdistx));
802 vt = _mm_add_epi16(vt, _mm_srli_si128(vt, 8));
803 }
804#ifdef Q_PROCESSOR_X86_64
805 return QRgba64::fromRgba64(_mm_cvtsi128_si64(vt));
806#else
807 QRgba64 out;
808 _mm_storel_epi64((__m128i*)&out, vt);
809 return out;
810#endif // Q_PROCESSOR_X86_64
811}
812#elif defined(__ARM_NEON__)
813static inline QRgba64 interpolate_4_pixels_rgb64(const QRgba64 t[], const QRgba64 b[], uint distx, uint disty)
814{
815 uint64x1x2_t vt = vld2_u64(reinterpret_cast<const uint64_t *>(t));
816 if (disty) {
817 uint64x1x2_t vb = vld2_u64(reinterpret_cast<const uint64_t *>(b));
818 uint32x4_t vt0 = vmull_n_u16(vreinterpret_u16_u64(vt.val[0]), 0x10000 - disty);
819 uint32x4_t vt1 = vmull_n_u16(vreinterpret_u16_u64(vt.val[1]), 0x10000 - disty);
820 vt0 = vmlal_n_u16(vt0, vreinterpret_u16_u64(vb.val[0]), disty);
821 vt1 = vmlal_n_u16(vt1, vreinterpret_u16_u64(vb.val[1]), disty);
822 vt.val[0] = vreinterpret_u64_u16(vshrn_n_u32(vt0, 16));
823 vt.val[1] = vreinterpret_u64_u16(vshrn_n_u32(vt1, 16));
824 }
825 if (distx) {
826 uint32x4_t vt0 = vmull_n_u16(vreinterpret_u16_u64(vt.val[0]), 0x10000 - distx);
827 vt0 = vmlal_n_u16(vt0, vreinterpret_u16_u64(vt.val[1]), distx);
828 vt.val[0] = vreinterpret_u64_u16(vshrn_n_u32(vt0, 16));
829 }
830 QRgba64 out;
831 vst1_u64(reinterpret_cast<uint64_t *>(&out), vt.val[0]);
832 return out;
833}
834#else
835static inline QRgba64 interpolate_4_pixels_rgb64(const QRgba64 t[], const QRgba64 b[], uint distx, uint disty)
836{
837 const uint dx = distx>>8;
838 const uint dy = disty>>8;
839 const uint idx = 256 - dx;
840 const uint idy = 256 - dy;
841 QRgba64 xtop = interpolate256(t[0], idx, t[1], dx);
842 QRgba64 xbot = interpolate256(b[0], idx, b[1], dx);
843 return interpolate256(xtop, idy, xbot, dy);
844}
845#endif // __SSE2__
846
847static inline uint BYTE_MUL_RGB16(uint x, uint a) {
848 a += 1;
849 uint t = (((x & 0x07e0)*a) >> 8) & 0x07e0;
850 t |= (((x & 0xf81f)*(a>>2)) >> 6) & 0xf81f;
851 return t;
852}
853
854static inline uint BYTE_MUL_RGB16_32(uint x, uint a) {
855 uint t = (((x & 0xf81f07e0) >> 5)*a) & 0xf81f07e0;
856 t |= (((x & 0x07e0f81f)*a) >> 5) & 0x07e0f81f;
857 return t;
858}
859
860// qt_div_255 is a fast rounded division by 255 using an approximation that is accurate for all positive 16-bit integers
861static constexpr inline int qt_div_255(int x) { return (x + (x>>8) + 0x80) >> 8; }
862static constexpr inline uint qt_div_257_floor(uint x) { return (x - (x >> 8)) >> 8; }
863static constexpr inline uint qt_div_257(uint x) { return qt_div_257_floor(x + 128); }
864static constexpr inline uint qt_div_65535(uint x) { return (x + (x>>16) + 0x8000U) >> 16; }
865
866template <class T> inline void qt_memfill_template(T *dest, T color, qsizetype count)
867{
868 if (!count)
869 return;
870
871 qsizetype n = (count + 7) / 8;
872 switch (count & 0x07)
873 {
874 case 0: do { *dest++ = color; Q_FALLTHROUGH();
875 case 7: *dest++ = color; Q_FALLTHROUGH();
876 case 6: *dest++ = color; Q_FALLTHROUGH();
877 case 5: *dest++ = color; Q_FALLTHROUGH();
878 case 4: *dest++ = color; Q_FALLTHROUGH();
879 case 3: *dest++ = color; Q_FALLTHROUGH();
880 case 2: *dest++ = color; Q_FALLTHROUGH();
881 case 1: *dest++ = color;
882 } while (--n > 0);
883 }
884}
885
886template <class T> inline void qt_memfill(T *dest, T value, qsizetype count)
887{
888 qt_memfill_template(dest, value, count);
889}
890
891template<> inline void qt_memfill(quint64 *dest, quint64 color, qsizetype count)
892{
893 qt_memfill64(dest, color, count);
894}
895
896template<> inline void qt_memfill(quint32 *dest, quint32 color, qsizetype count)
897{
898 qt_memfill32(dest, color, count);
899}
900
901template<> inline void qt_memfill(quint24 *dest, quint24 color, qsizetype count)
902{
903 qt_memfill24(dest, color, count);
904}
905
906template<> inline void qt_memfill(quint16 *dest, quint16 color, qsizetype count)
907{
908 qt_memfill16(dest, color, count);
909}
910
911template<> inline void qt_memfill(quint8 *dest, quint8 color, qsizetype count)
912{
913 memset(dest, color, count);
914}
915
916template <class T> static
917inline void qt_rectfill(T *dest, T value,
918 int x, int y, int width, int height, qsizetype stride)
919{
920 char *d = reinterpret_cast<char*>(dest + x) + y * stride;
921 if (uint(stride) == (width * sizeof(T))) {
922 qt_memfill(reinterpret_cast<T*>(d), value, qsizetype(width) * height);
923 } else {
924 for (int j = 0; j < height; ++j) {
925 dest = reinterpret_cast<T*>(d);
926 qt_memfill(dest, value, width);
927 d += stride;
928 }
929 }
930}
931
932inline ushort qConvertRgb32To16(uint c)
933{
934 return (((c) >> 3) & 0x001f)
935 | (((c) >> 5) & 0x07e0)
936 | (((c) >> 8) & 0xf800);
937}
938
939inline QRgb qConvertRgb16To32(uint c)
940{
941 return 0xff000000
942 | ((((c) << 3) & 0xf8) | (((c) >> 2) & 0x7))
943 | ((((c) << 5) & 0xfc00) | (((c) >> 1) & 0x300))
944 | ((((c) << 8) & 0xf80000) | (((c) << 3) & 0x70000));
945}
946
947const uint qt_bayer_matrix[16][16] = {
948 { 0x1, 0xc0, 0x30, 0xf0, 0xc, 0xcc, 0x3c, 0xfc,
949 0x3, 0xc3, 0x33, 0xf3, 0xf, 0xcf, 0x3f, 0xff},
950 { 0x80, 0x40, 0xb0, 0x70, 0x8c, 0x4c, 0xbc, 0x7c,
951 0x83, 0x43, 0xb3, 0x73, 0x8f, 0x4f, 0xbf, 0x7f},
952 { 0x20, 0xe0, 0x10, 0xd0, 0x2c, 0xec, 0x1c, 0xdc,
953 0x23, 0xe3, 0x13, 0xd3, 0x2f, 0xef, 0x1f, 0xdf},
954 { 0xa0, 0x60, 0x90, 0x50, 0xac, 0x6c, 0x9c, 0x5c,
955 0xa3, 0x63, 0x93, 0x53, 0xaf, 0x6f, 0x9f, 0x5f},
956 { 0x8, 0xc8, 0x38, 0xf8, 0x4, 0xc4, 0x34, 0xf4,
957 0xb, 0xcb, 0x3b, 0xfb, 0x7, 0xc7, 0x37, 0xf7},
958 { 0x88, 0x48, 0xb8, 0x78, 0x84, 0x44, 0xb4, 0x74,
959 0x8b, 0x4b, 0xbb, 0x7b, 0x87, 0x47, 0xb7, 0x77},
960 { 0x28, 0xe8, 0x18, 0xd8, 0x24, 0xe4, 0x14, 0xd4,
961 0x2b, 0xeb, 0x1b, 0xdb, 0x27, 0xe7, 0x17, 0xd7},
962 { 0xa8, 0x68, 0x98, 0x58, 0xa4, 0x64, 0x94, 0x54,
963 0xab, 0x6b, 0x9b, 0x5b, 0xa7, 0x67, 0x97, 0x57},
964 { 0x2, 0xc2, 0x32, 0xf2, 0xe, 0xce, 0x3e, 0xfe,
965 0x1, 0xc1, 0x31, 0xf1, 0xd, 0xcd, 0x3d, 0xfd},
966 { 0x82, 0x42, 0xb2, 0x72, 0x8e, 0x4e, 0xbe, 0x7e,
967 0x81, 0x41, 0xb1, 0x71, 0x8d, 0x4d, 0xbd, 0x7d},
968 { 0x22, 0xe2, 0x12, 0xd2, 0x2e, 0xee, 0x1e, 0xde,
969 0x21, 0xe1, 0x11, 0xd1, 0x2d, 0xed, 0x1d, 0xdd},
970 { 0xa2, 0x62, 0x92, 0x52, 0xae, 0x6e, 0x9e, 0x5e,
971 0xa1, 0x61, 0x91, 0x51, 0xad, 0x6d, 0x9d, 0x5d},
972 { 0xa, 0xca, 0x3a, 0xfa, 0x6, 0xc6, 0x36, 0xf6,
973 0x9, 0xc9, 0x39, 0xf9, 0x5, 0xc5, 0x35, 0xf5},
974 { 0x8a, 0x4a, 0xba, 0x7a, 0x86, 0x46, 0xb6, 0x76,
975 0x89, 0x49, 0xb9, 0x79, 0x85, 0x45, 0xb5, 0x75},
976 { 0x2a, 0xea, 0x1a, 0xda, 0x26, 0xe6, 0x16, 0xd6,
977 0x29, 0xe9, 0x19, 0xd9, 0x25, 0xe5, 0x15, 0xd5},
978 { 0xaa, 0x6a, 0x9a, 0x5a, 0xa6, 0x66, 0x96, 0x56,
979 0xa9, 0x69, 0x99, 0x59, 0xa5, 0x65, 0x95, 0x55}
980};
981
982#define ARGB_COMBINE_ALPHA(argb, alpha) \
983 ((((argb >> 24) * alpha) >> 8) << 24) | (argb & 0x00ffffff)
984
985
986#if Q_PROCESSOR_WORDSIZE == 8 // 64-bit versions
987#define AMIX(mask) (qMin(((quint64(s)&mask) + (quint64(d)&mask)), quint64(mask)))
988#define MIX(mask) (qMin(((quint64(s)&mask) + (quint64(d)&mask)), quint64(mask)))
989#else // 32 bits
990// The mask for alpha can overflow over 32 bits
991#define AMIX(mask) quint32(qMin(((quint64(s)&mask) + (quint64(d)&mask)), quint64(mask)))
992#define MIX(mask) (qMin(((quint32(s)&mask) + (quint32(d)&mask)), quint32(mask)))
993#endif
994
995inline uint comp_func_Plus_one_pixel_const_alpha(uint d, const uint s, const uint const_alpha, const uint one_minus_const_alpha)
996{
997 const uint result = uint(AMIX(AMASK) | MIX(RMASK) | MIX(GMASK) | MIX(BMASK));
998 return INTERPOLATE_PIXEL_255(result, const_alpha, d, one_minus_const_alpha);
999}
1000
1001inline uint comp_func_Plus_one_pixel(uint d, const uint s)
1002{
1003 const uint result = uint(AMIX(AMASK) | MIX(RMASK) | MIX(GMASK) | MIX(BMASK));
1004 return result;
1005}
1006
1007#undef MIX
1008#undef AMIX
1009
1010// must be multiple of 4 for easier SIMD implementations
1011static constexpr int BufferSize = 2048;
1012
1013// A buffer of intermediate results used by simple bilinear scaling.
1014struct IntermediateBuffer
1015{
1016 // The idea is first to do the interpolation between the row s1 and the row s2
1017 // into this intermediate buffer, then later interpolate between two pixel of this buffer.
1018 //
1019 // buffer_rb is a buffer of red-blue component of the pixel, in the form 0x00RR00BB
1020 // buffer_ag is the alpha-green component of the pixel, in the form 0x00AA00GG
1021 // +1 for the last pixel to interpolate with, and +1 for rounding errors.
1022 quint32 buffer_rb[BufferSize+2];
1023 quint32 buffer_ag[BufferSize+2];
1024};
1025
1026template <QPixelLayout::BPP bpp>
1027inline uint QT_FASTCALL qFetchPixel(const uchar *, int)
1028{
1029 Q_UNREACHABLE();
1030 return 0;
1031}
1032
1033template <>
1034inline uint QT_FASTCALL qFetchPixel<QPixelLayout::BPP1LSB>(const uchar *src, int index)
1035{
1036 return (src[index >> 3] >> (index & 7)) & 1;
1037}
1038
1039template <>
1040inline uint QT_FASTCALL qFetchPixel<QPixelLayout::BPP1MSB>(const uchar *src, int index)
1041{
1042 return (src[index >> 3] >> (~index & 7)) & 1;
1043}
1044
1045template <>
1046inline uint QT_FASTCALL qFetchPixel<QPixelLayout::BPP8>(const uchar *src, int index)
1047{
1048 return src[index];
1049}
1050
1051template <>
1052inline uint QT_FASTCALL qFetchPixel<QPixelLayout::BPP16>(const uchar *src, int index)
1053{
1054 return reinterpret_cast<const quint16 *>(src)[index];
1055}
1056
1057template <>
1058inline uint QT_FASTCALL qFetchPixel<QPixelLayout::BPP24>(const uchar *src, int index)
1059{
1060 return reinterpret_cast<const quint24 *>(src)[index];
1061}
1062
1063template <>
1064inline uint QT_FASTCALL qFetchPixel<QPixelLayout::BPP32>(const uchar *src, int index)
1065{
1066 return reinterpret_cast<const uint *>(src)[index];
1067}
1068
1069template <>
1070inline uint QT_FASTCALL qFetchPixel<QPixelLayout::BPP64>(const uchar *src, int index)
1071{
1072 // We have to do the conversion in fetch to fit into a 32bit uint
1073 QRgba64 c = reinterpret_cast<const QRgba64 *>(src)[index];
1074 return c.toArgb32();
1075}
1076
1077typedef uint (QT_FASTCALL *FetchPixelFunc)(const uchar *src, int index);
1078
1079constexpr FetchPixelFunc qFetchPixelTable[QPixelLayout::BPPCount] = {
1080 nullptr, // BPPNone
1081 qFetchPixel<QPixelLayout::BPP1MSB>,
1082 qFetchPixel<QPixelLayout::BPP1LSB>,
1083 qFetchPixel<QPixelLayout::BPP8>,
1084 qFetchPixel<QPixelLayout::BPP16>,
1085 qFetchPixel<QPixelLayout::BPP24>,
1086 qFetchPixel<QPixelLayout::BPP32>,
1087 qFetchPixel<QPixelLayout::BPP64>,
1088};
1089
1090QT_END_NAMESPACE
1091
1092#endif // QDRAWHELPER_P_H
1093