1 /****************************************************************************
3 ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
4 ** All rights reserved.
5 ** Contact: Nokia Corporation (qt-info@nokia.com)
7 ** This file is part of the QtGui module of the Qt Toolkit.
9 ** $QT_BEGIN_LICENSE:LGPL$
10 ** No Commercial Usage
11 ** This file contains pre-release code and may not be distributed.
12 ** You may use this file in accordance with the terms and conditions
13 ** contained in the Technology Preview License Agreement accompanying
16 ** GNU Lesser General Public License Usage
17 ** Alternatively, this file may be used under the terms of the GNU Lesser
18 ** General Public License version 2.1 as published by the Free Software
19 ** Foundation and appearing in the file LICENSE.LGPL included in the
20 ** packaging of this file. Please review the following information to
21 ** ensure the GNU Lesser General Public License version 2.1 requirements
22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 ** In addition, as a special exception, Nokia gives you certain additional
25 ** rights. These rights are described in the Nokia Qt LGPL Exception
26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 ** If you have questions regarding the use of this file, please contact
29 ** Nokia at qt-info@nokia.com.
40 ****************************************************************************/
42 #ifndef QDRAWHELPER_P_H
43 #define QDRAWHELPER_P_H
49 // This file is not part of the Qt API. It exists purely as an
50 // implementation detail. This header file may change from version to
51 // version without notice, or even be removed.
56 #include "QtCore/qglobal.h"
57 #include "QtGui/qcolor.h"
58 #include "QtGui/qpainter.h"
59 #include "QtGui/qimage.h"
60 #ifndef QT_FT_BEGIN_HEADER
61 #define QT_FT_BEGIN_HEADER
62 #define QT_FT_END_HEADER
64 #include "private/qrasterdefs_p.h"
65 #include <private/qsimd_p.h>
69 #if defined(Q_CC_MSVC) && _MSCVER <= 1300 && !defined(Q_CC_INTEL)
70 #define Q_STATIC_TEMPLATE_SPECIALIZATION static
72 #define Q_STATIC_TEMPLATE_SPECIALIZATION
75 #if defined(Q_CC_RVCT)
76 // RVCT doesn't like static template functions
77 # define Q_STATIC_TEMPLATE_FUNCTION
78 # define Q_STATIC_INLINE_FUNCTION static __forceinline
80 # define Q_STATIC_TEMPLATE_FUNCTION static
81 # define Q_STATIC_INLINE_FUNCTION static inline
84 static const uint AMASK = 0xff000000;
85 static const uint RMASK = 0x00ff0000;
86 static const uint GMASK = 0x0000ff00;
87 static const uint BMASK = 0x000000ff;
89 /*******************************************************************************
92 * duplicate definition of FT_Span
94 typedef QT_FT_Span QSpan;
99 struct QLinearGradientData;
100 struct QRadialGradientData;
101 struct QConicalGradientData;
106 class QRasterPaintEngineState;
108 typedef QT_FT_SpanFunc ProcessSpans;
109 typedef void (*BitmapBlitFunc)(QRasterBuffer *rasterBuffer,
110 int x, int y, quint32 color,
112 int mapWidth, int mapHeight, int mapStride);
114 typedef void (*AlphamapBlitFunc)(QRasterBuffer *rasterBuffer,
115 int x, int y, quint32 color,
117 int mapWidth, int mapHeight, int mapStride,
118 const QClipData *clip);
120 typedef void (*AlphaRGBBlitFunc)(QRasterBuffer *rasterBuffer,
121 int x, int y, quint32 color,
123 int mapWidth, int mapHeight, int mapStride,
124 const QClipData *clip);
126 typedef void (*RectFillFunc)(QRasterBuffer *rasterBuffer,
127 int x, int y, int width, int height,
130 typedef void (*SrcOverBlendFunc)(uchar *destPixels, int dbpl,
131 const uchar *src, int spbl,
135 typedef void (*SrcOverScaleFunc)(uchar *destPixels, int dbpl,
136 const uchar *src, int spbl,
137 const QRectF &targetRect,
138 const QRectF &sourceRect,
139 const QRect &clipRect,
142 typedef void (*SrcOverTransformFunc)(uchar *destPixels, int dbpl,
143 const uchar *src, int spbl,
144 const QRectF &targetRect,
145 const QRectF &sourceRect,
146 const QRect &clipRect,
147 const QTransform &targetRectTransform,
150 typedef void (*MemRotateFunc)(const uchar *srcPixels, int w, int h, int sbpl, uchar *destPixels, int dbpl);
153 ProcessSpans blendColor;
154 ProcessSpans blendGradient;
155 BitmapBlitFunc bitmapBlit;
156 AlphamapBlitFunc alphamapBlit;
157 AlphaRGBBlitFunc alphaRGBBlit;
158 RectFillFunc fillRect;
161 extern SrcOverBlendFunc qBlendFunctions[QImage::NImageFormats][QImage::NImageFormats];
162 extern SrcOverScaleFunc qScaleFunctions[QImage::NImageFormats][QImage::NImageFormats];
163 extern SrcOverTransformFunc qTransformFunctions[QImage::NImageFormats][QImage::NImageFormats];
164 extern MemRotateFunc qMemRotateFunctions[QImage::NImageFormats][3];
166 extern DrawHelper qDrawHelper[QImage::NImageFormats];
168 void qBlendTexture(int count, const QSpan *spans, void *userData);
170 typedef void (QT_FASTCALL *CompositionFunction)(uint *dest, const uint *src, int length, uint const_alpha);
171 typedef void (QT_FASTCALL *CompositionFunctionSolid)(uint *dest, int length, uint color, uint const_alpha);
173 void qInitDrawhelperAsm();
175 class QRasterPaintEngine;
182 struct QLinearGradientData
194 struct QRadialGradientData
207 struct QConicalGradientData
218 QGradient::Spread spread;
221 QLinearGradientData linear;
222 QRadialGradientData radial;
223 QConicalGradientData conical;
226 #define GRADIENT_STOPTABLE_SIZE 1024
228 uint* colorTable; //[GRADIENT_STOPTABLE_SIZE];
235 const uchar *imageData;
236 const uchar *scanLine(int y) const { return imageData + y*bytesPerLine; }
246 QImage::Format format;
247 const QVector<QRgb> *colorTable;
259 QSpanData() : tempImage(0) {}
260 ~QSpanData() { delete tempImage; }
262 QRasterBuffer *rasterBuffer;
264 ProcessSpans unclipped_blend;
265 BitmapBlitFunc bitmapBlit;
266 AlphamapBlitFunc alphamapBlit;
267 AlphaRGBBlitFunc alphaRGBBlit;
268 RectFillFunc fillRect;
269 qreal m11, m12, m13, m21, m22, m23, m33, dx, dy; // inverse xform matrix
270 const QClipData *clip;
285 QGradientData gradient;
286 QTextureData texture;
289 void init(QRasterBuffer *rb, const QRasterPaintEngine *pe);
290 void setup(const QBrush &brush, int alpha, QPainter::CompositionMode compositionMode);
291 void setupMatrix(const QTransform &matrix, int bilinear);
292 void initTexture(const QImage *image, int alpha, QTextureData::Type = QTextureData::Plain, const QRect &sourceRect = QRect());
293 void adjustSpanMethods();
296 #if defined(Q_CC_RVCT)
300 Q_STATIC_INLINE_FUNCTION uint INTERPOLATE_PIXEL_255(uint x, uint a, uint y, uint b) {
301 uint t = (x & 0xff00ff) * a + (y & 0xff00ff) * b;
302 t = (t + ((t >> 8) & 0xff00ff) + 0x800080) >> 8;
305 x = ((x >> 8) & 0xff00ff) * a + ((y >> 8) & 0xff00ff) * b;
306 x = (x + ((x >> 8) & 0xff00ff) + 0x800080);
311 #if defined(Q_CC_RVCT)
315 #if QT_POINTER_SIZE == 8 // 64-bit versions
317 Q_STATIC_INLINE_FUNCTION uint INTERPOLATE_PIXEL_256(uint x, uint a, uint y, uint b) {
318 quint64 t = (((quint64(x)) | ((quint64(x)) << 24)) & 0x00ff00ff00ff00ff) * a;
319 t += (((quint64(y)) | ((quint64(y)) << 24)) & 0x00ff00ff00ff00ff) * b;
321 t &= 0x00ff00ff00ff00ff;
322 return (uint(t)) | (uint(t >> 24));
325 Q_STATIC_INLINE_FUNCTION uint BYTE_MUL(uint x, uint a) {
326 quint64 t = (((quint64(x)) | ((quint64(x)) << 24)) & 0x00ff00ff00ff00ff) * a;
327 t = (t + ((t >> 8) & 0xff00ff00ff00ff) + 0x80008000800080) >> 8;
328 t &= 0x00ff00ff00ff00ff;
329 return (uint(t)) | (uint(t >> 24));
332 Q_STATIC_INLINE_FUNCTION uint PREMUL(uint x) {
334 quint64 t = (((quint64(x)) | ((quint64(x)) << 24)) & 0x00ff00ff00ff00ff) * a;
335 t = (t + ((t >> 8) & 0xff00ff00ff00ff) + 0x80008000800080) >> 8;
336 t &= 0x000000ff00ff00ff;
337 return (uint(t)) | (uint(t >> 24)) | (a << 24);
340 #else // 32-bit versions
342 Q_STATIC_INLINE_FUNCTION uint INTERPOLATE_PIXEL_256(uint x, uint a, uint y, uint b) {
343 uint t = (x & 0xff00ff) * a + (y & 0xff00ff) * b;
347 x = ((x >> 8) & 0xff00ff) * a + ((y >> 8) & 0xff00ff) * b;
353 #if defined(Q_CC_RVCT)
357 Q_STATIC_INLINE_FUNCTION uint BYTE_MUL(uint x, uint a) {
358 uint t = (x & 0xff00ff) * a;
359 t = (t + ((t >> 8) & 0xff00ff) + 0x800080) >> 8;
362 x = ((x >> 8) & 0xff00ff) * a;
363 x = (x + ((x >> 8) & 0xff00ff) + 0x800080);
368 #if defined(Q_CC_RVCT)
372 Q_STATIC_INLINE_FUNCTION uint PREMUL(uint x) {
374 uint t = (x & 0xff00ff) * a;
375 t = (t + ((t >> 8) & 0xff00ff) + 0x800080) >> 8;
378 x = ((x >> 8) & 0xff) * a;
379 x = (x + ((x >> 8) & 0xff) + 0x80);
387 Q_STATIC_INLINE_FUNCTION uint BYTE_MUL_RGB16(uint x, uint a) {
389 uint t = (((x & 0x07e0)*a) >> 8) & 0x07e0;
390 t |= (((x & 0xf81f)*(a>>2)) >> 6) & 0xf81f;
394 Q_STATIC_INLINE_FUNCTION uint BYTE_MUL_RGB16_32(uint x, uint a) {
395 uint t = (((x & 0xf81f07e0) >> 5)*a) & 0xf81f07e0;
396 t |= (((x & 0x07e0f81f)*a) >> 5) & 0x07e0f81f;
400 #define INV_PREMUL(p) \
401 (qAlpha(p) == 0 ? 0 : \
403 | (((255*qRed(p))/ qAlpha(p)) << 16) \
404 | (((255*qGreen(p)) / qAlpha(p)) << 8) \
405 | ((255*qBlue(p)) / qAlpha(p))))
407 template <class DST, class SRC>
408 inline DST qt_colorConvert(SRC color, DST dummy)
416 inline quint32 qt_colorConvert(quint16 color, quint32 dummy)
419 const int r = (color & 0xf800);
420 const int g = (color & 0x07e0);
421 const int b = (color & 0x001f);
422 const int tr = (r >> 8) | (r >> 13);
423 const int tg = (g >> 3) | (g >> 9);
424 const int tb = (b << 3) | (b >> 2);
426 return qRgb(tr, tg, tb);
430 inline quint16 qt_colorConvert(quint32 color, quint16 dummy)
433 const int r = qRed(color) << 8;
434 const int g = qGreen(color) << 3;
435 const int b = qBlue(color) >> 3;
437 return (r & 0xf800) | (g & 0x07e0)| (b & 0x001f);
443 inline quint32p(quint32 v) : data(PREMUL(v)) {}
445 inline operator quint32() const { return data; }
447 inline operator quint16() const
449 return qt_colorConvert<quint16, quint32>(data, 0);
452 Q_STATIC_INLINE_FUNCTION quint32p fromRawData(quint32 v)
467 inline qabgr8888(quint32 v)
469 data = qRgba(qBlue(v), qGreen(v), qRed(v), qAlpha(v));
472 inline bool operator==(const qabgr8888 &v) const { return data == v.data; }
483 Q_STATIC_INLINE_FUNCTION bool hasAlpha() { return true; }
485 inline qargb8565() {}
486 inline qargb8565(quint32 v);
487 inline explicit qargb8565(quint32p v);
488 inline qargb8565(const qargb8565 &v);
489 inline qargb8565(const qrgb565 &v);
491 inline operator quint32() const;
492 inline operator quint16() const;
494 inline quint8 alpha() const { return data[0]; }
495 inline qargb8565 truncedAlpha() {
500 Q_STATIC_INLINE_FUNCTION quint8 alpha(quint8 a) { return (a + 1) >> 3; }
501 Q_STATIC_INLINE_FUNCTION quint8 ialpha(quint8 a) { return 0x20 - alpha(a); }
503 inline qargb8565 byte_mul(quint8 a) const;
504 inline qargb8565 operator+(qargb8565 v) const;
505 inline bool operator==(const qargb8565 &v) const;
507 inline quint32 rawValue() const;
508 inline quint16 rawValue16() const;
511 friend class qrgb565;
519 Q_STATIC_INLINE_FUNCTION bool hasAlpha() { return false; }
521 qrgb565(int v = 0) : data(v) {}
523 inline explicit qrgb565(quint32p v);
524 inline explicit qrgb565(quint32 v);
525 inline explicit qrgb565(const qargb8565 &v);
527 inline operator quint32() const;
528 inline operator quint16() const;
530 inline qrgb565 operator+(qrgb565 v) const;
532 inline quint8 alpha() const { return 0xff; }
533 inline qrgb565 truncedAlpha() { return *this; }
534 Q_STATIC_INLINE_FUNCTION quint8 alpha(quint8 a) { return (a + 1) >> 3; }
535 Q_STATIC_INLINE_FUNCTION quint8 ialpha(quint8 a) { return 0x20 - alpha(a); }
537 inline qrgb565 byte_mul(quint8 a) const;
539 inline bool operator==(const qrgb565 &v) const;
540 inline quint16 rawValue() const { return data; }
543 friend class qargb8565;
548 qargb8565::qargb8565(quint32 v)
550 *this = qargb8565(quint32p(v));
553 qargb8565::qargb8565(quint32p v)
556 const int r = qRed(v);
557 const int g = qGreen(v);
558 const int b = qBlue(v);
559 data[1] = ((g << 3) & 0xe0) | (b >> 3);
560 data[2] = (r & 0xf8) | (g >> 5);
563 qargb8565::qargb8565(const qargb8565 &v)
570 qargb8565::qargb8565(const qrgb565 &v)
573 data[1] = v.data & 0xff;
574 data[2] = v.data >> 8;
577 qargb8565::operator quint32() const
579 const quint16 rgb = (data[2] << 8) | data[1];
580 const int a = data[0];
581 const int r = (rgb & 0xf800);
582 const int g = (rgb & 0x07e0);
583 const int b = (rgb & 0x001f);
584 const int tr = qMin(a, (r >> 8) | (r >> 13));
585 const int tg = qMin(a, (g >> 3) | (g >> 9));
586 const int tb = qMin(a, (b << 3) | (b >> 2));
587 return qRgba(tr, tg, tb, data[0]);
590 qargb8565::operator quint16() const
592 return (data[2] << 8) | data[1];
595 qargb8565 qargb8565::operator+(qargb8565 v) const
598 t.data[0] = data[0] + v.data[0];
599 const quint16 rgb = ((data[2] + v.data[2]) << 8)
600 + (data[1] + v.data[1]);
601 t.data[1] = rgb & 0xff;
602 t.data[2] = rgb >> 8;
606 qargb8565 qargb8565::byte_mul(quint8 a) const
609 result.data[0] = (data[0] * a) >> 5;
611 const quint16 x = (data[2] << 8) | data[1];
612 const quint16 t = ((((x & 0x07e0) >> 5) * a) & 0x07e0) |
613 ((((x & 0xf81f) * a) >> 5) & 0xf81f);
614 result.data[1] = t & 0xff;
615 result.data[2] = t >> 8;
619 bool qargb8565::operator==(const qargb8565 &v) const
621 return data[0] == v.data[0]
622 && data[1] == v.data[1]
623 && data[2] == v.data[2];
626 quint32 qargb8565::rawValue() const
628 return (data[2] << 16) | (data[1] << 8) | data[0];
631 quint16 qargb8565::rawValue16() const
633 return (data[2] << 8) | data[1];
636 qrgb565::qrgb565(quint32p v)
638 *this = qrgb565(quint32(v));
641 qrgb565::qrgb565(quint32 v)
643 const int r = qRed(v) << 8;
644 const int g = qGreen(v) << 3;
645 const int b = qBlue(v) >> 3;
647 data = (r & 0xf800) | (g & 0x07e0)| (b & 0x001f);
650 qrgb565::qrgb565(const qargb8565 &v)
652 data = (v.data[2] << 8) | v.data[1];
655 qrgb565::operator quint32() const
657 const int r = (data & 0xf800);
658 const int g = (data & 0x07e0);
659 const int b = (data & 0x001f);
660 const int tr = (r >> 8) | (r >> 13);
661 const int tg = (g >> 3) | (g >> 9);
662 const int tb = (b << 3) | (b >> 2);
663 return qRgb(tr, tg, tb);
666 qrgb565::operator quint16() const
671 qrgb565 qrgb565::operator+(qrgb565 v) const
674 t.data = data + v.data;
678 qrgb565 qrgb565::byte_mul(quint8 a) const
681 result.data = ((((data & 0x07e0) >> 5) * a) & 0x07e0) |
682 ((((data & 0xf81f) * a) >> 5) & 0xf81f);
686 bool qrgb565::operator==(const qrgb565 &v) const
688 return data == v.data;
694 inline qbgr565(quint16 v)
696 data = ((v & 0x001f) << 11) |
698 ((v & 0xf800) >> 11);
701 inline bool operator==(const qbgr565 &v) const
703 return data == v.data;
715 Q_STATIC_INLINE_FUNCTION bool hasAlpha() { return true; }
718 inline qargb8555(quint32 v);
719 inline explicit qargb8555(quint32p v);
720 inline qargb8555(const qargb8555 &v);
721 inline qargb8555(const qrgb555 &v);
723 inline operator quint32() const;
725 inline quint8 alpha() const { return data[0]; }
726 inline qargb8555 truncedAlpha() { data[0] &= 0xf8; return *this; }
727 Q_STATIC_INLINE_FUNCTION quint8 alpha(quint8 a) { return (a + 1) >> 3; }
728 Q_STATIC_INLINE_FUNCTION quint8 ialpha(quint8 a) { return 0x20 - alpha(a); }
730 inline qargb8555 operator+(qargb8555 v) const;
731 inline qargb8555 byte_mul(quint8 a) const;
733 inline bool operator==(const qargb8555 &v) const;
735 inline quint32 rawValue() const;
738 friend class qrgb555;
745 Q_STATIC_INLINE_FUNCTION bool hasAlpha() { return false; }
747 inline qrgb555(int v = 0) : data(v) {}
749 inline explicit qrgb555(quint32p v) { *this = qrgb555(quint32(v)); }
751 inline explicit qrgb555(quint32 v)
753 const int r = qRed(v) << 7;
754 const int g = qGreen(v) << 2;
755 const int b = qBlue(v) >> 3;
757 data = (r & 0x7c00) | (g & 0x03e0) | (b & 0x001f);
760 inline explicit qrgb555(quint16 v)
762 data = ((v >> 1) & (0x7c00 | 0x03e0)) |
766 inline explicit qrgb555(const qargb8555 &v);
768 inline operator quint32() const
770 const int r = (data & 0x7c00);
771 const int g = (data & 0x03e0);
772 const int b = (data & 0x001f);
773 const int tr = (r >> 7) | (r >> 12);
774 const int tg = (g >> 2) | (g >> 7);
775 const int tb = (b << 3) | (b >> 2);
777 return qRgb(tr, tg, tb);
780 inline operator quint16() const
782 const int r = ((data & 0x7c00) << 1) & 0xf800;
783 const int g = (((data & 0x03e0) << 1) | ((data >> 4) & 0x0020)) & 0x07e0;
784 const int b = (data & 0x001f);
789 inline qrgb555 operator+(qrgb555 v) const;
790 inline qrgb555 byte_mul(quint8 a) const;
792 inline quint8 alpha() const { return 0xff; }
793 inline qrgb555 truncedAlpha() { return *this; }
794 Q_STATIC_INLINE_FUNCTION quint8 alpha(quint8 a) { return (a + 1) >> 3; }
795 Q_STATIC_INLINE_FUNCTION quint8 ialpha(quint8 a) { return 0x20 - alpha(a); }
797 inline bool operator==(const qrgb555 &v) const { return v.data == data; }
798 inline bool operator!=(const qrgb555 &v) const { return v.data != data; }
800 inline quint16 rawValue() const { return data; }
803 friend class qargb8555;
804 friend class qbgr555;
809 qrgb555::qrgb555(const qargb8555 &v)
811 data = (v.data[2] << 8) | v.data[1];
814 qrgb555 qrgb555::operator+(qrgb555 v) const
817 t.data = data + v.data;
821 qrgb555 qrgb555::byte_mul(quint8 a) const
823 quint16 t = (((data & 0x3e0) * a) >> 5) & 0x03e0;
824 t |= (((data & 0x7c1f) * a) >> 5) & 0x7c1f;
834 inline qbgr555(quint32 v) { *this = qbgr555(qrgb555(v)); }
836 inline qbgr555(qrgb555 v)
838 data = ((v.data & 0x001f) << 10) |
840 ((v.data & 0x7c00) >> 10);
843 inline bool operator==(const qbgr555 &v) const
845 return data == v.data;
852 qargb8555::qargb8555(quint32 v)
856 const int r = qRed(v);
857 const int g = qGreen(v);
858 const int b = qBlue(v);
859 data[1] = ((g << 2) & 0xe0) | (b >> 3);
860 data[2] = ((r >> 1) & 0x7c) | (g >> 6);
864 qargb8555::qargb8555(quint32p v)
867 const int r = qRed(v);
868 const int g = qGreen(v);
869 const int b = qBlue(v);
870 data[1] = ((g << 2) & 0xe0) | (b >> 3);
871 data[2] = ((r >> 1) & 0x7c) | (g >> 6);
874 qargb8555::qargb8555(const qargb8555 &v)
881 qargb8555::qargb8555(const qrgb555 &v)
884 data[1] = v.data & 0xff;
885 data[2] = v.data >> 8;
888 qargb8555::operator quint32() const
890 const quint16 rgb = (data[2] << 8) | data[1];
891 const int r = (rgb & 0x7c00);
892 const int g = (rgb & 0x03e0);
893 const int b = (rgb & 0x001f);
894 const int tr = (r >> 7) | (r >> 12);
895 const int tg = (g >> 2) | (g >> 7);
896 const int tb = (b << 3) | (b >> 2);
898 return qRgba(tr, tg, tb, data[0]);
901 bool qargb8555::operator==(const qargb8555 &v) const
903 return data[0] == v.data[0]
904 && data[1] == v.data[1]
905 && data[2] == v.data[2];
908 quint32 qargb8555::rawValue() const
910 return (data[2] << 16) | (data[1] << 8) | data[0];
913 qargb8555 qargb8555::operator+(qargb8555 v) const
916 t.data[0] = data[0] + v.data[0];
917 const quint16 rgb = ((data[2] + v.data[2]) << 8)
918 + (data[1] + v.data[1]);
919 t.data[1] = rgb & 0xff;
920 t.data[2] = rgb >> 8;
924 qargb8555 qargb8555::byte_mul(quint8 a) const
927 result.data[0] = (data[0] * a) >> 5;
929 const quint16 x = (data[2] << 8) | data[1];
930 quint16 t = (((x & 0x3e0) * a) >> 5) & 0x03e0;
931 t |= (((x & 0x7c1f) * a) >> 5) & 0x7c1f;
932 result.data[1] = t & 0xff;
933 result.data[2] = t >> 8;
943 Q_STATIC_INLINE_FUNCTION bool hasAlpha() { return true; }
945 inline qargb6666() {}
946 inline qargb6666(quint32 v) { *this = qargb6666(quint32p(v)); }
947 inline explicit qargb6666(quint32p v);
948 inline qargb6666(const qargb6666 &v);
949 inline qargb6666(const qrgb666 &v);
951 inline operator quint32 () const;
953 inline quint8 alpha() const;
954 inline qargb6666 truncedAlpha() { return *this; }
955 Q_STATIC_INLINE_FUNCTION quint8 alpha(quint8 a) { return (a + 1) >> 2; }
956 Q_STATIC_INLINE_FUNCTION quint8 ialpha(quint8 a) { return (255 - a + 1) >> 2; }
958 inline qargb6666 byte_mul(quint8 a) const;
959 inline qargb6666 operator+(qargb6666 v) const;
960 inline bool operator==(const qargb6666 &v) const;
962 inline quint32 rawValue() const;
965 friend class qrgb666;
973 Q_STATIC_INLINE_FUNCTION bool hasAlpha() { return false; }
976 inline qrgb666(quint32 v);
977 inline qrgb666(const qargb6666 &v);
979 inline operator quint32 () const;
981 inline quint8 alpha() const { return 0xff; }
982 inline qrgb666 truncedAlpha() { return *this; }
983 Q_STATIC_INLINE_FUNCTION quint8 alpha(quint8 a) { return (a + 1) >> 2; }
984 Q_STATIC_INLINE_FUNCTION quint8 ialpha(quint8 a) { return (255 - a + 1) >> 2; }
986 inline qrgb666 operator+(qrgb666 v) const;
987 inline qrgb666 byte_mul(quint8 a) const;
989 inline bool operator==(const qrgb666 &v) const;
990 inline bool operator!=(const qrgb666 &v) const { return !(*this == v); }
992 inline quint32 rawValue() const
994 return (data[2] << 16) | (data[1] << 8) | data[0];
998 friend class qargb6666;
1003 qrgb666::qrgb666(quint32 v)
1005 const uchar b = qBlue(v);
1006 const uchar g = qGreen(v);
1007 const uchar r = qRed(v);
1008 const uint p = (b >> 2) | ((g >> 2) << 6) | ((r >> 2) << 12);
1010 data[1] = qGreen(p);
1014 qrgb666::qrgb666(const qargb6666 &v)
1016 data[0] = v.data[0];
1017 data[1] = v.data[1];
1018 data[2] = v.data[2] & 0x03;
1021 qrgb666::operator quint32 () const
1023 const uchar r = (data[2] << 6) | ((data[1] & 0xf0) >> 2) | (data[2] & 0x3);
1024 const uchar g = (data[1] << 4) | ((data[0] & 0xc0) >> 4) | ((data[1] & 0x0f) >> 2);
1025 const uchar b = (data[0] << 2) | ((data[0] & 0x3f) >> 4);
1026 return qRgb(r, g, b);
1029 qrgb666 qrgb666::operator+(qrgb666 v) const
1031 const quint32 x1 = (data[2] << 16) | (data[1] << 8) | data[0];
1032 const quint32 x2 = (v.data[2] << 16) | (v.data[1] << 8) | v.data[0];
1033 const quint32 t = x1 + x2;
1035 r.data[0] = t & 0xff;
1036 r.data[1] = (t >> 8) & 0xff;
1037 r.data[2] = (t >> 16) & 0xff;
1041 qrgb666 qrgb666::byte_mul(quint8 a) const
1043 const quint32 x = (data[2] << 16) | (data[1] << 8) | data[0];
1044 const quint32 t = ((((x & 0x03f03f) * a) >> 6) & 0x03f03f) |
1045 ((((x & 0x000fc0) * a) >> 6) & 0x000fc0);
1048 r.data[0] = t & 0xff;
1049 r.data[1] = (t >> 8) & 0xff;
1050 r.data[2] = (t >> 16) & 0xff;
1054 bool qrgb666::operator==(const qrgb666 &v) const
1056 return (data[0] == v.data[0] &&
1057 data[1] == v.data[1] &&
1058 data[2] == v.data[2]);
1061 qargb6666::qargb6666(quint32p v)
1063 const quint8 b = qBlue(v) >> 2;
1064 const quint8 g = qGreen(v) >> 2;
1065 const quint8 r = qRed(v) >> 2;
1066 const quint8 a = qAlpha(v) >> 2;
1067 const uint p = (a << 18) | (r << 12) | (g << 6) | b;
1069 data[1] = qGreen(p);
1073 qargb6666::qargb6666(const qargb6666 &v)
1075 data[0] = v.data[0];
1076 data[1] = v.data[1];
1077 data[2] = v.data[2];
1080 qargb6666::qargb6666(const qrgb666 &v)
1082 data[0] = v.data[0];
1083 data[1] = v.data[1];
1084 data[2] = (v.data[2] | 0xfc);
1087 qargb6666::operator quint32 () const
1089 const quint8 r = (data[2] << 6) | ((data[1] & 0xf0) >> 2) | (data[2] & 0x3);
1090 const quint8 g = (data[1] << 4) | ((data[0] & 0xc0) >> 4) | ((data[1] & 0x0f) >> 2);
1091 const quint8 b = (data[0] << 2) | ((data[0] & 0x3f) >> 4);
1092 const quint8 a = (data[2] & 0xfc) | (data[2] >> 6);
1093 return qRgba(r, g, b, a);
1096 qargb6666 qargb6666::operator+(qargb6666 v) const
1098 const quint32 x1 = (data[2] << 16) | (data[1] << 8) | data[0];
1099 const quint32 x2 = (v.data[2] << 16) | (v.data[1] << 8) | v.data[0];
1100 const quint32 t = x1 + x2;
1102 r.data[0] = t & 0xff;
1103 r.data[1] = (t >> 8) & 0xff;
1104 r.data[2] = (t >> 16) & 0xff;
1108 quint8 qargb6666::alpha() const
1110 return (data[2] & 0xfc) | (data[2] >> 6);
1113 inline qargb6666 qargb6666::byte_mul(quint8 a) const
1115 const quint32 x = (data[2] << 16) | (data[1] << 8) | data[0];
1116 const quint32 t = ((((x & 0x03f03f) * a) >> 6) & 0x03f03f) |
1117 ((((x & 0xfc0fc0) * a) >> 6) & 0xfc0fc0);
1120 r.data[0] = t & 0xff;
1121 r.data[1] = (t >> 8) & 0xff;
1122 r.data[2] = (t >> 16) & 0xff;
1126 bool qargb6666::operator==(const qargb6666 &v) const
1128 return data[0] == v.data[0]
1129 && data[1] == v.data[1]
1130 && data[2] == v.data[2];
1133 quint32 qargb6666::rawValue() const
1135 return (data[2] << 16) | (data[1] << 8) | data[0];
1141 Q_STATIC_INLINE_FUNCTION bool hasAlpha() { return false; }
1144 inline qrgb888(quint32 v);
1146 inline operator quint32() const;
1148 inline quint8 alpha() const { return 0xff; }
1149 inline qrgb888 truncedAlpha() { return *this; }
1150 Q_STATIC_INLINE_FUNCTION quint8 alpha(quint8 a) { return a; }
1151 Q_STATIC_INLINE_FUNCTION quint8 ialpha(quint8 a) { return 255 - a; }
1153 inline qrgb888 byte_mul(quint8 a) const;
1154 inline qrgb888 operator+(qrgb888 v) const;
1155 inline bool operator==(qrgb888 v) const;
1157 inline quint32 rawValue() const;
1164 qrgb888::qrgb888(quint32 v)
1167 data[1] = qGreen(v);
1171 qrgb888::operator quint32() const
1173 return qRgb(data[0], data[1], data[2]);
1176 qrgb888 qrgb888::operator+(qrgb888 v) const
1179 t.data[0] += v.data[0];
1180 t.data[1] += v.data[1];
1181 t.data[2] += v.data[2];
1185 qrgb888 qrgb888::byte_mul(quint8 a) const
1189 quint32 t = (x & 0xff00ff) * a;
1190 t = (t + ((t >> 8) & 0xff00ff) + 0x800080) >> 8;
1193 x = ((x >> 8) & 0xff00ff) * a;
1194 x = (x + ((x >> 8) & 0xff00ff) + 0x800080);
1200 bool qrgb888::operator==(qrgb888 v) const
1202 return (data[0] == v.data[0] &&
1203 data[1] == v.data[1] &&
1204 data[2] == v.data[2]);
1207 quint32 qrgb888::rawValue() const
1209 return (data[2] << 16) | (data[1] << 8) | data[0];
1213 inline qrgb888 qt_colorConvert(quint32 color, qrgb888 dummy)
1216 return qrgb888(color);
1220 inline quint32 qt_colorConvert(qrgb888 color, quint32 dummy)
1223 return quint32(color);
1230 inline quint24(quint32 v)
1233 data[1] = qGreen(v);
1237 inline operator quint32 ()
1239 return qRgb(data[2], data[1], data[0]);
1242 inline bool operator==(const quint24 &v) const
1244 return data[0] == v.data[0]
1245 && data[1] == v.data[1]
1246 && data[2] == v.data[2];
1254 inline quint24 qt_colorConvert(quint32 color, quint24 dummy)
1257 return quint24(color);
1264 inline quint18(quint32 v)
1267 uchar g = qGreen(v);
1269 uint p = (b >> 2) | ((g >> 2) << 6) | ((r >> 2) << 12);
1271 data[1] = qGreen(p);
1275 inline operator quint32 ()
1277 const uchar r = (data[2] << 6) | ((data[1] & 0xf0) >> 2) | (data[2] & 0x3);
1278 const uchar g = (data[1] << 4) | ((data[0] & 0xc0) >> 4) | ((data[1] & 0x0f) >> 2);
1279 const uchar b = (data[0] << 2) | ((data[0] & 0x3f) >> 4);
1280 return qRgb(r, g, b);
1288 inline quint18 qt_colorConvert(quint32 color, quint18 dummy)
1291 return quint18(color);
1299 Q_STATIC_INLINE_FUNCTION bool hasAlpha() { return true; }
1301 inline qargb4444() {}
1302 inline qargb4444(quint32 v) { *this = qargb4444(quint32p(v)); }
1303 inline explicit qargb4444(quint32p v);
1304 inline qargb4444(const qrgb444 &v);
1306 inline operator quint32() const;
1307 inline operator quint8() const;
1309 inline qargb4444 operator+(qargb4444 v) const;
1311 inline quint8 alpha() const { return ((data & 0xf000) >> 8) | ((data & 0xf000) >> 12); }
1312 inline qargb4444 truncedAlpha() { return *this; }
1313 Q_STATIC_INLINE_FUNCTION quint8 alpha(quint8 a) { return (a + 1) >> 4; }
1314 Q_STATIC_INLINE_FUNCTION quint8 ialpha(quint8 a) { return 0x10 - alpha(a); }
1315 inline qargb4444 byte_mul(quint8 a) const;
1317 inline bool operator==(const qargb4444 &v) const { return data == v.data; }
1319 inline quint16 rawValue() const { return data; }
1322 friend class qrgb444;
1330 Q_STATIC_INLINE_FUNCTION bool hasAlpha() { return false; }
1333 inline qrgb444(quint32 v);
1334 inline explicit qrgb444(qargb4444 v);
1336 inline operator quint32() const;
1337 inline operator quint8() const;
1339 inline qrgb444 operator+(qrgb444 v) const;
1340 inline quint8 alpha() const { return 0xff; }
1341 inline qrgb444 truncedAlpha() { return *this; }
1342 Q_STATIC_INLINE_FUNCTION quint8 alpha(quint8 a) { return (a + 1) >> 4; }
1343 Q_STATIC_INLINE_FUNCTION quint8 ialpha(quint8 a) { return 0x10 - alpha(a); }
1344 inline qrgb444 byte_mul(quint8 a) const;
1346 inline bool operator==(const qrgb444 &v) const { return data == v.data; }
1347 inline bool operator!=(const qrgb444 &v) const { return data != v.data; }
1349 inline quint16 rawValue() const { return data; }
1352 friend class qargb4444;
1358 qargb4444::qargb4444(quint32p color)
1362 const int a = qAlpha(v) << 8;
1363 const int r = qRed(v) << 4;
1364 const int g = qGreen(v);
1365 const int b = qBlue(v) >> 4;
1367 data = a | r | g | b;
1370 qargb4444::qargb4444(const qrgb444 &v)
1372 data = v.data | 0xf000;
1375 qargb4444::operator quint32() const
1377 const int a = (data & 0xf000);
1378 const int r = (data & 0x0f00);
1379 const int g = (data & 0x00f0);
1380 const int b = (data & 0x000f);
1381 const int ta = (a >> 8) | (a >> 12);
1382 const int tr = (r >> 4) | (r >> 8);
1383 const int tg = g | (g >> 4);
1384 const int tb = (b << 4) | b;
1386 return qRgba(tr, tg, tb, ta);
1389 qargb4444::operator quint8() const
1392 return qt_colorConvert<quint8, quint32>(operator quint32(), 0);
1395 qargb4444 qargb4444::operator+(qargb4444 v) const
1398 t.data = data + v.data;
1402 qargb4444 qargb4444::byte_mul(quint8 a) const
1404 quint16 t = (((data & 0xf0f0) * a) >> 4) & 0xf0f0;
1405 t |= (((data & 0x0f0f) * a) >> 4) & 0x0f0f;
1412 qrgb444::qrgb444(quint32 v)
1415 const int r = qRed(v) << 4;
1416 const int g = qGreen(v);
1417 const int b = qBlue(v) >> 4;
1422 qrgb444::qrgb444(qargb4444 v)
1424 data = v.data & 0x0fff;
1427 qrgb444::operator quint32() const
1429 const int r = (data & 0x0f00);
1430 const int g = (data & 0x00f0);
1431 const int b = (data & 0x000f);
1432 const int tr = (r >> 4) | (r >> 8);
1433 const int tg = g | (g >> 4);
1434 const int tb = (b << 4) | b;
1436 return qRgb(tr, tg, tb);
1439 qrgb444::operator quint8() const
1442 return qt_colorConvert<quint8, quint32>(operator quint32(), 0);
1445 qrgb444 qrgb444::operator+(qrgb444 v) const
1448 t.data = data + v.data;
1452 qrgb444 qrgb444::byte_mul(quint8 a) const
1454 quint16 t = (((data & 0xf0f0) * a) >> 4) & 0xf0f0;
1455 t |= (((data & 0x0f0f) * a) >> 4) & 0x0f0f;
1463 void qt_memfill(T *dest, T value, int count);
1465 template<> inline void qt_memfill(quint32 *dest, quint32 color, int count)
1467 extern void (*qt_memfill32)(quint32 *dest, quint32 value, int count);
1468 qt_memfill32(dest, color, count);
1471 template<> inline void qt_memfill(quint16 *dest, quint16 color, int count)
1473 extern void (*qt_memfill16)(quint16 *dest, quint16 value, int count);
1474 qt_memfill16(dest, color, count);
1477 template<> inline void qt_memfill(quint8 *dest, quint8 color, int count)
1479 memset(dest, color, count);
1483 inline void qt_memfill(T *dest, T value, int count)
1488 int n = (count + 7) / 8;
1489 switch (count & 0x07)
1491 case 0: do { *dest++ = value;
1492 case 7: *dest++ = value;
1493 case 6: *dest++ = value;
1494 case 5: *dest++ = value;
1495 case 4: *dest++ = value;
1496 case 3: *dest++ = value;
1497 case 2: *dest++ = value;
1498 case 1: *dest++ = value;
1504 inline void qt_rectfill(T *dest, T value,
1505 int x, int y, int width, int height, int stride)
1507 char *d = reinterpret_cast<char*>(dest + x) + y * stride;
1508 if (uint(stride) == (width * sizeof(T))) {
1509 qt_memfill(reinterpret_cast<T*>(d), value, width * height);
1511 for (int j = 0; j < height; ++j) {
1512 dest = reinterpret_cast<T*>(d);
1513 qt_memfill(dest, value, width);
1519 template <class DST, class SRC>
1520 inline void qt_memconvert(DST *dest, const SRC *src, int count)
1522 if (sizeof(DST) == 1) {
1525 const SRC color = *src++;
1526 const DST dstColor = qt_colorConvert<DST, SRC>(color, 0);
1527 while (--count && (*src == color || dstColor == qt_colorConvert<DST, SRC>(*src, 0))) {
1531 qt_memfill(dest, dstColor, n);
1536 int n = (count + 7) / 8;
1537 switch (count & 0x07)
1539 case 0: do { *dest++ = qt_colorConvert<DST, SRC>(*src++, 0);
1540 case 7: *dest++ = qt_colorConvert<DST, SRC>(*src++, 0);
1541 case 6: *dest++ = qt_colorConvert<DST, SRC>(*src++, 0);
1542 case 5: *dest++ = qt_colorConvert<DST, SRC>(*src++, 0);
1543 case 4: *dest++ = qt_colorConvert<DST, SRC>(*src++, 0);
1544 case 3: *dest++ = qt_colorConvert<DST, SRC>(*src++, 0);
1545 case 2: *dest++ = qt_colorConvert<DST, SRC>(*src++, 0);
1546 case 1: *dest++ = qt_colorConvert<DST, SRC>(*src++, 0);
1552 #define QT_TRIVIAL_MEMCONVERT_IMPL(T) \
1554 inline void qt_memconvert(T *dest, const T *src, int count) \
1556 memcpy(dest, src, count * sizeof(T)); \
1558 QT_TRIVIAL_MEMCONVERT_IMPL(quint32)
1559 QT_TRIVIAL_MEMCONVERT_IMPL(qrgb888)
1560 QT_TRIVIAL_MEMCONVERT_IMPL(qargb6666)
1561 QT_TRIVIAL_MEMCONVERT_IMPL(qrgb666)
1562 QT_TRIVIAL_MEMCONVERT_IMPL(quint16)
1563 QT_TRIVIAL_MEMCONVERT_IMPL(qrgb565)
1564 QT_TRIVIAL_MEMCONVERT_IMPL(qargb8565)
1565 QT_TRIVIAL_MEMCONVERT_IMPL(qargb8555)
1566 QT_TRIVIAL_MEMCONVERT_IMPL(qrgb555)
1567 QT_TRIVIAL_MEMCONVERT_IMPL(qargb4444)
1568 QT_TRIVIAL_MEMCONVERT_IMPL(qrgb444)
1569 #undef QT_TRIVIAL_MEMCONVERT_IMPL
1571 #if Q_BYTE_ORDER == Q_LITTLE_ENDIAN
1573 inline void qt_memconvert(qrgb666 *dest, const quint32 *src, int count)
1577 case 2: *dest++ = qrgb666(*src++);
1578 case 1: *dest = qrgb666(*src);
1583 const int align = (quintptr(dest) & 3);
1585 case 1: *dest++ = qrgb666(*src++); --count;
1586 case 2: *dest++ = qrgb666(*src++); --count;
1587 case 3: *dest++ = qrgb666(*src++); --count;
1590 quint32 *dest32 = reinterpret_cast<quint32*>(dest);
1591 int sourceCount = count >> 2;
1592 while (sourceCount--) {
1593 dest32[0] = ((src[1] & 0x00000c00) << 20)
1594 | ((src[1] & 0x000000fc) << 22)
1595 | ((src[0] & 0x00fc0000) >> 6)
1596 | ((src[0] & 0x0000fc00) >> 4)
1597 | ((src[0] & 0x000000fc) >> 2);
1598 dest32[1] = ((src[2] & 0x003c0000) << 10)
1599 | ((src[2] & 0x0000fc00) << 12)
1600 | ((src[2] & 0x000000fc) << 14)
1601 | ((src[1] & 0x00fc0000) >> 14)
1602 | ((src[1] & 0x0000f000) >> 12);
1603 dest32[2] = ((src[3] & 0x00fc0000) << 2)
1604 | ((src[3] & 0x0000fc00) << 4)
1605 | ((src[3] & 0x000000fc) << 6)
1606 | ((src[2] & 0x00c00000) >> 22);
1611 dest = reinterpret_cast<qrgb666*>(dest32);
1612 switch (count & 3) {
1613 case 3: *dest++ = qrgb666(*src++);
1614 case 2: *dest++ = qrgb666(*src++);
1615 case 1: *dest = qrgb666(*src);
1618 #endif // Q_BYTE_ORDER
1621 inline void qt_rectcopy(T *dest, const T *src,
1622 int x, int y, int width, int height,
1623 int dstStride, int srcStride)
1625 char *d = (char*)(dest + x) + y * dstStride;
1626 const char *s = (char*)(src);
1627 for (int i = 0; i < height; ++i) {
1628 ::memcpy(d, s, width * sizeof(T));
1634 template <class DST, class SRC>
1635 inline void qt_rectconvert(DST *dest, const SRC *src,
1636 int x, int y, int width, int height,
1637 int dstStride, int srcStride)
1639 char *d = (char*)(dest + x) + y * dstStride;
1640 const char *s = (char*)(src);
1641 for (int i = 0; i < height; ++i) {
1642 qt_memconvert<DST,SRC>((DST*)d, (const SRC*)s, width);
1648 #define QT_RECTCONVERT_TRIVIAL_IMPL(T) \
1650 inline void qt_rectconvert(T *dest, const T *src, \
1651 int x, int y, int width, int height, \
1652 int dstStride, int srcStride) \
1654 qt_rectcopy(dest, src, x, y, width, height, dstStride, srcStride); \
1656 QT_RECTCONVERT_TRIVIAL_IMPL(quint32)
1657 QT_RECTCONVERT_TRIVIAL_IMPL(qrgb888)
1658 QT_RECTCONVERT_TRIVIAL_IMPL(qargb6666)
1659 QT_RECTCONVERT_TRIVIAL_IMPL(qrgb666)
1660 QT_RECTCONVERT_TRIVIAL_IMPL(qrgb565)
1661 QT_RECTCONVERT_TRIVIAL_IMPL(qargb8565)
1662 QT_RECTCONVERT_TRIVIAL_IMPL(quint16)
1663 QT_RECTCONVERT_TRIVIAL_IMPL(qargb8555)
1664 QT_RECTCONVERT_TRIVIAL_IMPL(qrgb555)
1665 QT_RECTCONVERT_TRIVIAL_IMPL(qargb4444)
1666 QT_RECTCONVERT_TRIVIAL_IMPL(qrgb444)
1667 #undef QT_RECTCONVERT_TRIVIAL_IMPL
1669 #define QT_MEMFILL_UINT(dest, length, color) \
1670 qt_memfill<quint32>(dest, color, length);
1672 #define QT_MEMFILL_USHORT(dest, length, color) \
1673 qt_memfill<quint16>(dest, color, length);
1675 #define QT_MEMCPY_REV_UINT(dest, src, length) \
1677 /* Duff's device */ \
1678 uint *_d = (uint*)(dest) + length; \
1679 const uint *_s = (uint*)(src) + length; \
1680 register int n = ((length) + 7) / 8; \
1681 switch ((length) & 0x07) \
1683 case 0: do { *--_d = *--_s; \
1684 case 7: *--_d = *--_s; \
1685 case 6: *--_d = *--_s; \
1686 case 5: *--_d = *--_s; \
1687 case 4: *--_d = *--_s; \
1688 case 3: *--_d = *--_s; \
1689 case 2: *--_d = *--_s; \
1690 case 1: *--_d = *--_s; \
1691 } while (--n > 0); \
1695 #define QT_MEMCPY_USHORT(dest, src, length) \
1697 /* Duff's device */ \
1698 ushort *_d = (ushort*)(dest); \
1699 const ushort *_s = (ushort*)(src); \
1700 register int n = ((length) + 7) / 8; \
1701 switch ((length) & 0x07) \
1703 case 0: do { *_d++ = *_s++; \
1704 case 7: *_d++ = *_s++; \
1705 case 6: *_d++ = *_s++; \
1706 case 5: *_d++ = *_s++; \
1707 case 4: *_d++ = *_s++; \
1708 case 3: *_d++ = *_s++; \
1709 case 2: *_d++ = *_s++; \
1710 case 1: *_d++ = *_s++; \
1711 } while (--n > 0); \
1715 #if defined(Q_CC_RVCT)
1719 Q_STATIC_INLINE_FUNCTION int qt_div_255(int x) { return (x + (x>>8) + 0x80) >> 8; }
1720 #if defined(Q_CC_RVCT)
1724 inline ushort qConvertRgb32To16(uint c)
1726 return (((c) >> 3) & 0x001f)
1727 | (((c) >> 5) & 0x07e0)
1728 | (((c) >> 8) & 0xf800);
1731 inline QRgb qConvertRgb16To32(uint c)
1734 | ((((c) << 3) & 0xf8) | (((c) >> 2) & 0x7))
1735 | ((((c) << 5) & 0xfc00) | (((c) >> 1) & 0x300))
1736 | ((((c) << 8) & 0xf80000) | (((c) << 3) & 0x70000));
1739 inline int qRed565(quint16 rgb) {
1740 const int r = (rgb & 0xf800);
1741 return (r >> 8) | (r >> 13);
1744 inline int qGreen565(quint16 rgb) {
1745 const int g = (rgb & 0x07e0);
1746 return (g >> 3) | (g >> 9);
1749 inline int qBlue565(quint16 rgb) {
1750 const int b = (rgb & 0x001f);
1751 return (b << 3) | (b >> 2);
1754 const uint qt_bayer_matrix[16][16] = {
1755 { 0x1, 0xc0, 0x30, 0xf0, 0xc, 0xcc, 0x3c, 0xfc,
1756 0x3, 0xc3, 0x33, 0xf3, 0xf, 0xcf, 0x3f, 0xff},
1757 { 0x80, 0x40, 0xb0, 0x70, 0x8c, 0x4c, 0xbc, 0x7c,
1758 0x83, 0x43, 0xb3, 0x73, 0x8f, 0x4f, 0xbf, 0x7f},
1759 { 0x20, 0xe0, 0x10, 0xd0, 0x2c, 0xec, 0x1c, 0xdc,
1760 0x23, 0xe3, 0x13, 0xd3, 0x2f, 0xef, 0x1f, 0xdf},
1761 { 0xa0, 0x60, 0x90, 0x50, 0xac, 0x6c, 0x9c, 0x5c,
1762 0xa3, 0x63, 0x93, 0x53, 0xaf, 0x6f, 0x9f, 0x5f},
1763 { 0x8, 0xc8, 0x38, 0xf8, 0x4, 0xc4, 0x34, 0xf4,
1764 0xb, 0xcb, 0x3b, 0xfb, 0x7, 0xc7, 0x37, 0xf7},
1765 { 0x88, 0x48, 0xb8, 0x78, 0x84, 0x44, 0xb4, 0x74,
1766 0x8b, 0x4b, 0xbb, 0x7b, 0x87, 0x47, 0xb7, 0x77},
1767 { 0x28, 0xe8, 0x18, 0xd8, 0x24, 0xe4, 0x14, 0xd4,
1768 0x2b, 0xeb, 0x1b, 0xdb, 0x27, 0xe7, 0x17, 0xd7},
1769 { 0xa8, 0x68, 0x98, 0x58, 0xa4, 0x64, 0x94, 0x54,
1770 0xab, 0x6b, 0x9b, 0x5b, 0xa7, 0x67, 0x97, 0x57},
1771 { 0x2, 0xc2, 0x32, 0xf2, 0xe, 0xce, 0x3e, 0xfe,
1772 0x1, 0xc1, 0x31, 0xf1, 0xd, 0xcd, 0x3d, 0xfd},
1773 { 0x82, 0x42, 0xb2, 0x72, 0x8e, 0x4e, 0xbe, 0x7e,
1774 0x81, 0x41, 0xb1, 0x71, 0x8d, 0x4d, 0xbd, 0x7d},
1775 { 0x22, 0xe2, 0x12, 0xd2, 0x2e, 0xee, 0x1e, 0xde,
1776 0x21, 0xe1, 0x11, 0xd1, 0x2d, 0xed, 0x1d, 0xdd},
1777 { 0xa2, 0x62, 0x92, 0x52, 0xae, 0x6e, 0x9e, 0x5e,
1778 0xa1, 0x61, 0x91, 0x51, 0xad, 0x6d, 0x9d, 0x5d},
1779 { 0xa, 0xca, 0x3a, 0xfa, 0x6, 0xc6, 0x36, 0xf6,
1780 0x9, 0xc9, 0x39, 0xf9, 0x5, 0xc5, 0x35, 0xf5},
1781 { 0x8a, 0x4a, 0xba, 0x7a, 0x86, 0x46, 0xb6, 0x76,
1782 0x89, 0x49, 0xb9, 0x79, 0x85, 0x45, 0xb5, 0x75},
1783 { 0x2a, 0xea, 0x1a, 0xda, 0x26, 0xe6, 0x16, 0xd6,
1784 0x29, 0xe9, 0x19, 0xd9, 0x25, 0xe5, 0x15, 0xd5},
1785 { 0xaa, 0x6a, 0x9a, 0x5a, 0xa6, 0x66, 0x96, 0x56,
1786 0xa9, 0x69, 0x99, 0x59, 0xa5, 0x65, 0x95, 0x55}
1789 #define ARGB_COMBINE_ALPHA(argb, alpha) \
1790 ((((argb >> 24) * alpha) >> 8) << 24) | (argb & 0x00ffffff)
1793 #if QT_POINTER_SIZE == 8 // 64-bit versions
1794 #define AMIX(mask) (qMin(((qint64(s)&mask) + (qint64(d)&mask)), qint64(mask)))
1795 #define MIX(mask) (qMin(((qint64(s)&mask) + (qint64(d)&mask)), qint64(mask)))
1797 // The mask for alpha can overflow over 32 bits
1798 #define AMIX(mask) quint32(qMin(((qint64(s)&mask) + (qint64(d)&mask)), qint64(mask)))
1799 #define MIX(mask) (qMin(((quint32(s)&mask) + (quint32(d)&mask)), quint32(mask)))
1802 inline int comp_func_Plus_one_pixel_const_alpha(uint d, const uint s, const uint const_alpha, const uint one_minus_const_alpha)
1804 const int result = (AMIX(AMASK) | MIX(RMASK) | MIX(GMASK) | MIX(BMASK));
1805 return INTERPOLATE_PIXEL_255(result, const_alpha, d, one_minus_const_alpha);
1808 inline int comp_func_Plus_one_pixel(uint d, const uint s)
1810 const int result = (AMIX(AMASK) | MIX(RMASK) | MIX(GMASK) | MIX(BMASK));
1817 // prototypes of all the composition functions
1818 void QT_FASTCALL comp_func_SourceOver(uint *dest, const uint *src, int length, uint const_alpha);
1819 void QT_FASTCALL comp_func_DestinationOver(uint *dest, const uint *src, int length, uint const_alpha);
1820 void QT_FASTCALL comp_func_Clear(uint *dest, const uint *, int length, uint const_alpha);
1821 void QT_FASTCALL comp_func_Source(uint *dest, const uint *src, int length, uint const_alpha);
1822 void QT_FASTCALL comp_func_Destination(uint *, const uint *, int, uint);
1823 void QT_FASTCALL comp_func_SourceIn(uint *dest, const uint *src, int length, uint const_alpha);
1824 void QT_FASTCALL comp_func_DestinationIn(uint *dest, const uint *src, int length, uint const_alpha);
1825 void QT_FASTCALL comp_func_SourceOut(uint *dest, const uint *src, int length, uint const_alpha);
1826 void QT_FASTCALL comp_func_DestinationOut(uint *dest, const uint *src, int length, uint const_alpha);
1827 void QT_FASTCALL comp_func_SourceAtop(uint *dest, const uint *src, int length, uint const_alpha);
1828 void QT_FASTCALL comp_func_DestinationAtop(uint *dest, const uint *src, int length, uint const_alpha);
1829 void QT_FASTCALL comp_func_XOR(uint *dest, const uint *src, int length, uint const_alpha);
1830 void QT_FASTCALL comp_func_Plus(uint *dest, const uint *src, int length, uint const_alpha);
1831 void QT_FASTCALL comp_func_Multiply(uint *dest, const uint *src, int length, uint const_alpha);
1832 void QT_FASTCALL comp_func_Screen(uint *dest, const uint *src, int length, uint const_alpha);
1833 void QT_FASTCALL comp_func_Overlay(uint *dest, const uint *src, int length, uint const_alpha);
1834 void QT_FASTCALL comp_func_Darken(uint *dest, const uint *src, int length, uint const_alpha);
1835 void QT_FASTCALL comp_func_Lighten(uint *dest, const uint *src, int length, uint const_alpha);
1836 void QT_FASTCALL comp_func_ColorDodge(uint *dest, const uint *src, int length, uint const_alpha);
1837 void QT_FASTCALL comp_func_ColorBurn(uint *dest, const uint *src, int length, uint const_alpha);
1838 void QT_FASTCALL comp_func_HardLight(uint *dest, const uint *src, int length, uint const_alpha);
1839 void QT_FASTCALL comp_func_SoftLight(uint *dest, const uint *src, int length, uint const_alpha);
1840 void QT_FASTCALL comp_func_Difference(uint *dest, const uint *src, int length, uint const_alpha);
1841 void QT_FASTCALL comp_func_Exclusion(uint *dest, const uint *src, int length, uint const_alpha);
1842 void QT_FASTCALL rasterop_SourceOrDestination(uint *dest, const uint *src, int length, uint const_alpha);
1843 void QT_FASTCALL rasterop_SourceAndDestination(uint *dest, const uint *src, int length, uint const_alpha);
1844 void QT_FASTCALL rasterop_SourceXorDestination(uint *dest, const uint *src, int length, uint const_alpha);
1845 void QT_FASTCALL rasterop_NotSourceAndNotDestination(uint *dest, const uint *src, int length, uint const_alpha);
1846 void QT_FASTCALL rasterop_NotSourceOrNotDestination(uint *dest, const uint *src, int length, uint const_alpha);
1847 void QT_FASTCALL rasterop_NotSourceXorDestination(uint *dest, const uint *src, int length, uint const_alpha);
1848 void QT_FASTCALL rasterop_NotSource(uint *dest, const uint *src, int length, uint const_alpha);
1849 void QT_FASTCALL rasterop_NotSourceAndDestination(uint *dest, const uint *src, int length, uint const_alpha);
1850 void QT_FASTCALL rasterop_SourceAndNotDestination(uint *dest, const uint *src, int length, uint const_alpha);
1852 // prototypes of all the solid composition functions
1853 void QT_FASTCALL comp_func_solid_SourceOver(uint *dest, int length, uint color, uint const_alpha);
1854 void QT_FASTCALL comp_func_solid_DestinationOver(uint *dest, int length, uint color, uint const_alpha);
1855 void QT_FASTCALL comp_func_solid_Clear(uint *dest, int length, uint color, uint const_alpha);
1856 void QT_FASTCALL comp_func_solid_Source(uint *dest, int length, uint color, uint const_alpha);
1857 void QT_FASTCALL comp_func_solid_Destination(uint *dest, int length, uint color, uint const_alpha);
1858 void QT_FASTCALL comp_func_solid_SourceIn(uint *dest, int length, uint color, uint const_alpha);
1859 void QT_FASTCALL comp_func_solid_DestinationIn(uint *dest, int length, uint color, uint const_alpha);
1860 void QT_FASTCALL comp_func_solid_SourceOut(uint *dest, int length, uint color, uint const_alpha);
1861 void QT_FASTCALL comp_func_solid_DestinationOut(uint *dest, int length, uint color, uint const_alpha);
1862 void QT_FASTCALL comp_func_solid_SourceAtop(uint *dest, int length, uint color, uint const_alpha);
1863 void QT_FASTCALL comp_func_solid_DestinationAtop(uint *dest, int length, uint color, uint const_alpha);
1864 void QT_FASTCALL comp_func_solid_XOR(uint *dest, int length, uint color, uint const_alpha);
1865 void QT_FASTCALL comp_func_solid_Plus(uint *dest, int length, uint color, uint const_alpha);
1866 void QT_FASTCALL comp_func_solid_Multiply(uint *dest, int length, uint color, uint const_alpha);
1867 void QT_FASTCALL comp_func_solid_Screen(uint *dest, int length, uint color, uint const_alpha);
1868 void QT_FASTCALL comp_func_solid_Overlay(uint *dest, int length, uint color, uint const_alpha);
1869 void QT_FASTCALL comp_func_solid_Darken(uint *dest, int length, uint color, uint const_alpha);
1870 void QT_FASTCALL comp_func_solid_Lighten(uint *dest, int length, uint color, uint const_alpha);
1871 void QT_FASTCALL comp_func_solid_ColorDodge(uint *dest, int length, uint color, uint const_alpha);
1872 void QT_FASTCALL comp_func_solid_ColorBurn(uint *dest, int length, uint color, uint const_alpha);
1873 void QT_FASTCALL comp_func_solid_HardLight(uint *dest, int length, uint color, uint const_alpha);
1874 void QT_FASTCALL comp_func_solid_SoftLight(uint *dest, int length, uint color, uint const_alpha);
1875 void QT_FASTCALL comp_func_solid_Difference(uint *dest, int length, uint color, uint const_alpha);
1876 void QT_FASTCALL comp_func_solid_Exclusion(uint *dest, int length, uint color, uint const_alpha);
1877 void QT_FASTCALL rasterop_solid_SourceOrDestination(uint *dest, int length, uint color, uint const_alpha);
1878 void QT_FASTCALL rasterop_solid_SourceAndDestination(uint *dest, int length, uint color, uint const_alpha);
1879 void QT_FASTCALL rasterop_solid_SourceXorDestination(uint *dest, int length, uint color, uint const_alpha);
1880 void QT_FASTCALL rasterop_solid_NotSourceAndNotDestination(uint *dest, int length, uint color, uint const_alpha);
1881 void QT_FASTCALL rasterop_solid_NotSourceOrNotDestination(uint *dest, int length, uint color, uint const_alpha);
1882 void QT_FASTCALL rasterop_solid_NotSourceXorDestination(uint *dest, int length, uint color, uint const_alpha);
1883 void QT_FASTCALL rasterop_solid_NotSource(uint *dest, int length, uint color, uint const_alpha);
1884 void QT_FASTCALL rasterop_solid_NotSourceAndDestination(uint *dest, int length, uint color, uint const_alpha);
1885 void QT_FASTCALL rasterop_solid_SourceAndNotDestination(uint *dest, int length, uint color, uint const_alpha);
1889 #endif // QDRAWHELPER_P_H