source: trunk/src/gui/painting/qdrawhelper_p.h@ 139

Last change on this file since 139 was 2, checked in by Dmitry A. Kuminov, 16 years ago

Initially imported qt-all-opensource-src-4.5.1 from Trolltech.

File size: 49.8 KB
Line 
1/****************************************************************************
2**
3** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
4** Contact: Qt Software Information ([email protected])
5**
6** This file is part of the QtGui module of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:LGPL$
9** Commercial Usage
10** Licensees holding valid Qt Commercial licenses may use this file in
11** accordance with the Qt Commercial License Agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and Nokia.
14**
15** GNU Lesser General Public License Usage
16** Alternatively, this file may be used under the terms of the GNU Lesser
17** General Public License version 2.1 as published by the Free Software
18** Foundation and appearing in the file LICENSE.LGPL included in the
19** packaging of this file. Please review the following information to
20** ensure the GNU Lesser General Public License version 2.1 requirements
21** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
22**
23** In addition, as a special exception, Nokia gives you certain
24** additional rights. These rights are described in the Nokia Qt LGPL
25** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
26** package.
27**
28** GNU General Public License Usage
29** Alternatively, this file may be used under the terms of the GNU
30** General Public License version 3.0 as published by the Free Software
31** Foundation and appearing in the file LICENSE.GPL included in the
32** packaging of this file. Please review the following information to
33** ensure the GNU General Public License version 3.0 requirements will be
34** met: http://www.gnu.org/copyleft/gpl.html.
35**
36** If you are unsure which license is appropriate for your use, please
37** contact the sales department at [email protected].
38** $QT_END_LICENSE$
39**
40****************************************************************************/
41
42#ifndef QDRAWHELPER_P_H
43#define QDRAWHELPER_P_H
44
45//
46// W A R N I N G
47// -------------
48//
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.
52//
53// We mean it.
54//
55
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
63#endif
64#include "private/qrasterdefs_p.h"
65
66#ifdef Q_WS_QWS
67#include "QtGui/qscreen_qws.h"
68#endif
69
70// Disable MMX and SSE on Mac/PPC builds, or if the compiler
71// does not support -Xarch argument passing
72#if defined(QT_NO_MAC_XARCH) || (defined(Q_OS_DARWIN) && (defined(__ppc__) || defined(__ppc64__)))
73#undef QT_HAVE_SSE2
74#undef QT_HAVE_SSE
75#undef QT_HAVE_3DNOW
76#undef QT_HAVE_MMX
77#endif
78
79QT_BEGIN_NAMESPACE
80
81#if defined(Q_CC_MSVC) && _MSCVER <= 1300 && !defined(Q_CC_INTEL)
82#define Q_STATIC_TEMPLATE_SPECIALIZATION static
83#else
84#define Q_STATIC_TEMPLATE_SPECIALIZATION
85#endif
86
87#if defined(Q_CC_RVCT)
88// RVCT doesn't like static template functions
89# define Q_STATIC_TEMPLATE_FUNCTION
90# define Q_STATIC_INLINE_FUNCTION inline
91#else
92# define Q_STATIC_TEMPLATE_FUNCTION static
93# define Q_STATIC_INLINE_FUNCTION static inline
94#endif
95
96/*******************************************************************************
97 * QSpan
98 *
99 * duplicate definition of FT_Span
100 */
101typedef QT_FT_Span QSpan;
102
103struct QSolidData;
104struct QTextureData;
105struct QGradientData;
106struct QLinearGradientData;
107struct QRadialGradientData;
108struct QConicalGradientData;
109struct QSpanData;
110class QGradient;
111class QRasterBuffer;
112class QClipData;
113
114typedef QT_FT_SpanFunc ProcessSpans;
115typedef void (*BitmapBlitFunc)(QRasterBuffer *rasterBuffer,
116 int x, int y, quint32 color,
117 const uchar *bitmap,
118 int mapWidth, int mapHeight, int mapStride);
119
120typedef void (*AlphamapBlitFunc)(QRasterBuffer *rasterBuffer,
121 int x, int y, quint32 color,
122 const uchar *bitmap,
123 int mapWidth, int mapHeight, int mapStride,
124 const QClipData *clip);
125
126typedef void (*AlphaRGBBlitFunc)(QRasterBuffer *rasterBuffer,
127 int x, int y, quint32 color,
128 const uint *rgbmask,
129 int mapWidth, int mapHeight, int mapStride,
130 const QClipData *clip);
131
132typedef void (*RectFillFunc)(QRasterBuffer *rasterBuffer,
133 int x, int y, int width, int height,
134 quint32 color);
135
136typedef void (*SrcOverBlendFunc)(uchar *destPixels, int dbpl,
137 const uchar *src, int spbl,
138 int w, int h,
139 int const_alpha);
140
141typedef void (*SrcOverScaleFunc)(uchar *destPixels, int dbpl,
142 const uchar *src, int spbl,
143 const QRectF &targetRect,
144 const QRectF &sourceRect,
145 const QRect &clipRect,
146 int const_alpha);
147
148
149struct DrawHelper {
150 ProcessSpans blendColor;
151 ProcessSpans blendGradient;
152 BitmapBlitFunc bitmapBlit;
153 AlphamapBlitFunc alphamapBlit;
154 AlphaRGBBlitFunc alphaRGBBlit;
155 RectFillFunc fillRect;
156};
157
158extern SrcOverBlendFunc qBlendFunctions[QImage::NImageFormats][QImage::NImageFormats];
159extern SrcOverScaleFunc qScaleFunctions[QImage::NImageFormats][QImage::NImageFormats];
160
161extern DrawHelper qDrawHelper[QImage::NImageFormats];
162
163void qBlendTexture(int count, const QSpan *spans, void *userData);
164#if defined(Q_WS_QWS) && !defined(QT_NO_RASTERCALLBACKS)
165extern DrawHelper qDrawHelperCallback[QImage::NImageFormats];
166void qBlendTextureCallback(int count, const QSpan *spans, void *userData);
167#endif
168
169typedef void (QT_FASTCALL *CompositionFunction)(uint *dest, const uint *src, int length, uint const_alpha);
170typedef void (QT_FASTCALL *CompositionFunctionSolid)(uint *dest, int length, uint color, uint const_alpha);
171
172void qInitDrawhelperAsm();
173
174class QRasterPaintEngine;
175
176struct QSolidData
177{
178 uint color;
179};
180
181struct QLinearGradientData
182{
183 struct {
184 qreal x;
185 qreal y;
186 } origin;
187 struct {
188 qreal x;
189 qreal y;
190 } end;
191};
192
193struct QRadialGradientData
194{
195 struct {
196 qreal x;
197 qreal y;
198 } center;
199 struct {
200 qreal x;
201 qreal y;
202 } focal;
203 qreal radius;
204};
205
206struct QConicalGradientData
207{
208 struct {
209 qreal x;
210 qreal y;
211 } center;
212 qreal angle;
213};
214
215struct QGradientData
216{
217 QGradient::Spread spread;
218
219 union {
220 QLinearGradientData linear;
221 QRadialGradientData radial;
222 QConicalGradientData conical;
223 };
224
225#ifdef Q_WS_QWS
226#define GRADIENT_STOPTABLE_SIZE 256
227#else
228#define GRADIENT_STOPTABLE_SIZE 1024
229#endif
230
231 uint* colorTable; //[GRADIENT_STOPTABLE_SIZE];
232
233 uint alphaColor : 1;
234};
235
236struct QTextureData
237{
238 const uchar *imageData;
239 const uchar *scanLine(int y) const { return imageData + y*bytesPerLine; }
240
241 int width;
242 int height;
243 // clip rect
244 int x1;
245 int y1;
246 int x2;
247 int y2;
248 int bytesPerLine;
249 QImage::Format format;
250 const QVector<QRgb> *colorTable;
251 bool hasAlpha;
252 enum Type {
253 Plain,
254 Tiled
255 };
256 Type type;
257 int const_alpha;
258};
259
260struct QSpanData
261{
262 QSpanData() : tempImage(0) {}
263 ~QSpanData() { delete tempImage; }
264
265 QRasterBuffer *rasterBuffer;
266#ifdef Q_WS_QWS
267 QRasterPaintEngine *rasterEngine;
268#endif
269 ProcessSpans blend;
270 ProcessSpans unclipped_blend;
271 BitmapBlitFunc bitmapBlit;
272 AlphamapBlitFunc alphamapBlit;
273 AlphaRGBBlitFunc alphaRGBBlit;
274 RectFillFunc fillRect;
275 qreal m11, m12, m13, m21, m22, m23, m33, dx, dy; // inverse xform matrix
276 const QClipData *clip;
277 enum Type {
278 None,
279 Solid,
280 LinearGradient,
281 RadialGradient,
282 ConicalGradient,
283 Texture
284 } type : 8;
285 int txop : 8;
286 int fast_matrix : 1;
287 bool bilinear;
288 QImage *tempImage;
289 union {
290 QSolidData solid;
291 QGradientData gradient;
292 QTextureData texture;
293 };
294
295 void init(QRasterBuffer *rb, const QRasterPaintEngine *pe);
296 void setup(const QBrush &brush, int alpha);
297 void setupMatrix(const QTransform &matrix, int bilinear);
298 void initTexture(const QImage *image, int alpha, QTextureData::Type = QTextureData::Plain, const QRect &sourceRect = QRect());
299 void adjustSpanMethods();
300};
301
302
303static inline uint BYTE_MUL_RGB16(uint x, uint a) {
304 a += 1;
305 uint t = (((x & 0x07e0)*a) >> 8) & 0x07e0;
306 t |= (((x & 0xf81f)*(a>>2)) >> 6) & 0xf81f;
307 return t;
308}
309
310static inline uint BYTE_MUL_RGB16_32(uint x, uint a) {
311 uint t = (((x & 0xf81f07e0) >> 5)*a) & 0xf81f07e0;
312 t |= (((x & 0x07e0f81f)*a) >> 5) & 0x07e0f81f;
313 return t;
314}
315
316Q_STATIC_INLINE_FUNCTION uint BYTE_MUL(uint x, uint a) {
317 uint t = (x & 0xff00ff) * a;
318 t = (t + ((t >> 8) & 0xff00ff) + 0x800080) >> 8;
319 t &= 0xff00ff;
320
321 x = ((x >> 8) & 0xff00ff) * a;
322 x = (x + ((x >> 8) & 0xff00ff) + 0x800080);
323 x &= 0xff00ff00;
324 x |= t;
325 return x;
326}
327
328static inline uint PREMUL(uint x) {
329 uint a = x >> 24;
330 uint t = (x & 0xff00ff) * a;
331 t = (t + ((t >> 8) & 0xff00ff) + 0x800080) >> 8;
332 t &= 0xff00ff;
333
334 x = ((x >> 8) & 0xff) * a;
335 x = (x + ((x >> 8) & 0xff) + 0x80);
336 x &= 0xff00;
337 x |= t | (a << 24);
338 return x;
339}
340
341#define INV_PREMUL(p) \
342 (qAlpha(p) == 0 ? 0 : \
343 ((qAlpha(p) << 24) \
344 | (((255*qRed(p))/ qAlpha(p)) << 16) \
345 | (((255*qGreen(p)) / qAlpha(p)) << 8) \
346 | ((255*qBlue(p)) / qAlpha(p))))
347
348template <class DST, class SRC>
349inline DST qt_colorConvert(SRC color, DST dummy)
350{
351 Q_UNUSED(dummy);
352 return DST(color);
353}
354
355
356template <>
357inline quint32 qt_colorConvert(quint16 color, quint32 dummy)
358{
359 Q_UNUSED(dummy);
360 const int r = (color & 0xf800);
361 const int g = (color & 0x07e0);
362 const int b = (color & 0x001f);
363 const int tr = (r >> 8) | (r >> 13);
364 const int tg = (g >> 3) | (g >> 9);
365 const int tb = (b << 3) | (b >> 2);
366
367 return qRgb(tr, tg, tb);
368}
369
370template <>
371inline quint16 qt_colorConvert(quint32 color, quint16 dummy)
372{
373 Q_UNUSED(dummy);
374 const int r = qRed(color) << 8;
375 const int g = qGreen(color) << 3;
376 const int b = qBlue(color) >> 3;
377
378 return (r & 0xf800) | (g & 0x07e0)| (b & 0x001f);
379}
380
381class quint32p
382{
383public:
384 inline quint32p(quint32 v) : data(PREMUL(v)) {}
385
386 inline operator quint32() const { return data; }
387
388 inline operator quint16() const
389 {
390 return qt_colorConvert<quint16, quint32>(data, 0);
391 }
392
393 static inline quint32p fromRawData(quint32 v)
394 {
395 quint32p p;
396 p.data = v;
397 return p;
398 }
399
400private:
401 quint32p() {}
402 quint32 data;
403} Q_PACKED;
404
405class qabgr8888
406{
407public:
408 inline qabgr8888(quint32 v)
409 {
410 data = qRgba(qBlue(v), qGreen(v), qRed(v), qAlpha(v));
411 }
412
413 inline bool operator==(const qabgr8888 &v) const { return data == v.data; }
414
415private:
416 quint32 data;
417} Q_PACKED;
418
419class qrgb565;
420
421class qargb8565
422{
423public:
424 static inline bool hasAlpha() { return true; }
425
426 inline qargb8565() {}
427 inline qargb8565(quint32 v);
428 inline explicit qargb8565(quint32p v);
429 inline qargb8565(const qargb8565 &v);
430 inline qargb8565(const qrgb565 &v);
431
432 inline operator quint32() const;
433 inline operator quint16() const;
434
435 inline quint8 alpha() const { return data[0]; }
436 inline qargb8565 truncedAlpha() {
437 data[0] &= 0xf8;
438 data[1] &= 0xdf;
439 return *this;
440 }
441 static inline quint8 alpha(quint8 a) { return (a + 1) >> 3; }
442 static inline quint8 ialpha(quint8 a) { return 0x20 - alpha(a); }
443
444 inline qargb8565 byte_mul(quint8 a) const;
445 inline qargb8565 operator+(qargb8565 v) const;
446 inline bool operator==(const qargb8565 &v) const;
447
448 inline quint32 rawValue() const;
449
450private:
451 friend class qrgb565;
452
453 quint8 data[3];
454} Q_PACKED;
455
456class qrgb565
457{
458public:
459 static inline bool hasAlpha() { return false; }
460
461 qrgb565(int v = 0) : data(v) {}
462
463 inline explicit qrgb565(quint32p v);
464 inline explicit qrgb565(quint32 v);
465 inline explicit qrgb565(qargb8565 v);
466
467 inline operator quint32() const;
468 inline operator quint16() const;
469
470 inline qrgb565 operator+(qrgb565 v) const;
471
472 inline quint8 alpha() const { return 0xff; }
473 inline qrgb565 truncedAlpha() { return *this; }
474 static inline quint8 alpha(quint8 a) { return (a + 1) >> 3; }
475 static inline quint8 ialpha(quint8 a) { return 0x20 - alpha(a); }
476
477 inline qrgb565 byte_mul(quint8 a) const;
478
479 inline bool operator==(const qrgb565 &v) const;
480 inline quint16 rawValue() const { return data; }
481
482private:
483 friend class qargb8565;
484
485 quint16 data;
486} Q_PACKED;
487
488qargb8565::qargb8565(quint32 v)
489{
490 *this = qargb8565(quint32p(v));
491}
492
493qargb8565::qargb8565(quint32p v)
494{
495 data[0] = qAlpha(v);
496 const int r = qRed(v);
497 const int g = qGreen(v);
498 const int b = qBlue(v);
499 data[1] = ((g << 3) & 0xe0) | (b >> 3);
500 data[2] = (r & 0xf8) | (g >> 5);
501}
502
503qargb8565::qargb8565(const qargb8565 &v)
504{
505 data[0] = v.data[0];
506 data[1] = v.data[1];
507 data[2] = v.data[2];
508}
509
510qargb8565::qargb8565(const qrgb565 &v)
511{
512 data[0] = 0xff;
513 data[1] = v.data & 0xff;
514 data[2] = v.data >> 8;
515}
516
517qargb8565::operator quint32() const
518{
519 const quint16 rgb = (data[2] << 8) | data[1];
520 const int a = data[0];
521 const int r = (rgb & 0xf800);
522 const int g = (rgb & 0x07e0);
523 const int b = (rgb & 0x001f);
524 const int tr = qMin(a, (r >> 8) | (r >> 13));
525 const int tg = qMin(a, (g >> 3) | (g >> 9));
526 const int tb = qMin(a, (b << 3) | (b >> 2));
527 return qRgba(tr, tg, tb, data[0]);
528}
529
530qargb8565::operator quint16() const
531{
532 return (data[2] << 8) | data[1];
533}
534
535qargb8565 qargb8565::operator+(qargb8565 v) const
536{
537 qargb8565 t;
538 t.data[0] = data[0] + v.data[0];
539 const quint16 rgb = ((data[2] + v.data[2]) << 8)
540 + (data[1] + v.data[1]);
541 t.data[1] = rgb & 0xff;
542 t.data[2] = rgb >> 8;
543 return t;
544}
545
546qargb8565 qargb8565::byte_mul(quint8 a) const
547{
548 qargb8565 result;
549 result.data[0] = (data[0] * a) >> 5;
550
551 const quint16 x = (data[2] << 8) | data[1];
552 const quint16 t = ((((x & 0x07e0) >> 5) * a) & 0x07e0) |
553 ((((x & 0xf81f) * a) >> 5) & 0xf81f);
554 result.data[1] = t & 0xff;
555 result.data[2] = t >> 8;
556 return result;
557}
558
559bool qargb8565::operator==(const qargb8565 &v) const
560{
561 return data[0] == v.data[0]
562 && data[1] == v.data[1]
563 && data[2] == v.data[2];
564}
565
566quint32 qargb8565::rawValue() const
567{
568 return (data[2] << 16) | (data[1] << 8) | data[0];
569}
570
571qrgb565::qrgb565(quint32p v)
572{
573 *this = qrgb565(quint32(v));
574}
575
576qrgb565::qrgb565(quint32 v)
577{
578 const int r = qRed(v) << 8;
579 const int g = qGreen(v) << 3;
580 const int b = qBlue(v) >> 3;
581
582 data = (r & 0xf800) | (g & 0x07e0)| (b & 0x001f);
583}
584
585qrgb565::qrgb565(qargb8565 v)
586{
587 data = (v.data[2] << 8) | v.data[1];
588}
589
590qrgb565::operator quint32() const
591{
592 const int r = (data & 0xf800);
593 const int g = (data & 0x07e0);
594 const int b = (data & 0x001f);
595 const int tr = (r >> 8) | (r >> 13);
596 const int tg = (g >> 3) | (g >> 9);
597 const int tb = (b << 3) | (b >> 2);
598 return qRgb(tr, tg, tb);
599}
600
601qrgb565::operator quint16() const
602{
603 return data;
604}
605
606qrgb565 qrgb565::operator+(qrgb565 v) const
607{
608 qrgb565 t;
609 t.data = data + v.data;
610 return t;
611}
612
613qrgb565 qrgb565::byte_mul(quint8 a) const
614{
615 qrgb565 result;
616 result.data = ((((data & 0x07e0) >> 5) * a) & 0x07e0) |
617 ((((data & 0xf81f) * a) >> 5) & 0xf81f);
618 return result;
619}
620
621bool qrgb565::operator==(const qrgb565 &v) const
622{
623 return data == v.data;
624}
625
626class qbgr565
627{
628public:
629 inline qbgr565(quint16 v)
630 {
631 data = ((v & 0x001f) << 11) |
632 (v & 0x07e0) |
633 ((v & 0xf800) >> 11);
634 }
635
636 inline bool operator==(const qbgr565 &v) const
637 {
638 return data == v.data;
639 }
640
641private:
642 quint16 data;
643} Q_PACKED;
644
645class qrgb555;
646
647class qargb8555
648{
649public:
650 static inline bool hasAlpha() { return true; }
651
652 qargb8555() {}
653 inline qargb8555(quint32 v);
654 inline explicit qargb8555(quint32p v);
655 inline qargb8555(const qargb8555 &v);
656 inline qargb8555(const qrgb555 &v);
657
658 inline operator quint32() const;
659
660 inline quint8 alpha() const { return data[0]; }
661 inline qargb8555 truncedAlpha() { data[0] &= 0xf8; return *this; }
662 static inline quint8 alpha(quint8 a) { return (a + 1) >> 3; }
663 static inline quint8 ialpha(quint8 a) { return 0x20 - alpha(a); }
664
665 inline qargb8555 operator+(qargb8555 v) const;
666 inline qargb8555 byte_mul(quint8 a) const;
667
668 inline bool operator==(const qargb8555 &v) const;
669
670 inline quint32 rawValue() const;
671
672private:
673 friend class qrgb555;
674 quint8 data[3];
675} Q_PACKED;
676
677class qrgb555
678{
679public:
680 static inline bool hasAlpha() { return false; }
681
682 inline qrgb555(int v = 0) : data(v) {}
683
684 inline explicit qrgb555(quint32p v) { *this = qrgb555(quint32(v)); }
685
686 inline explicit qrgb555(quint32 v)
687 {
688 const int r = qRed(v) << 7;
689 const int g = qGreen(v) << 2;
690 const int b = qBlue(v) >> 3;
691
692 data = (r & 0x7c00) | (g & 0x03e0) | (b & 0x001f);
693 }
694
695 inline explicit qrgb555(quint16 v)
696 {
697 data = ((v >> 1) & (0x7c00 | 0x03e0)) |
698 (v & 0x001f);
699 }
700
701 inline explicit qrgb555(const qargb8555 &v);
702
703 inline operator quint32() const
704 {
705 const int r = (data & 0x7c00);
706 const int g = (data & 0x03e0);
707 const int b = (data & 0x001f);
708 const int tr = (r >> 7) | (r >> 12);
709 const int tg = (g >> 2) | (g >> 7);
710 const int tb = (b << 3) | (b >> 2);
711
712 return qRgb(tr, tg, tb);
713 }
714
715 inline operator quint16() const
716 {
717 const int r = ((data & 0x7c00) << 1) & 0xf800;
718 const int g = (((data & 0x03e0) << 1) | ((data >> 4) & 0x0020)) & 0x07e0;
719 const int b = (data & 0x001f);
720
721 return r | g | b;
722 }
723
724 inline qrgb555 operator+(qrgb555 v) const;
725 inline qrgb555 byte_mul(quint8 a) const;
726
727 inline quint8 alpha() const { return 0xff; }
728 inline qrgb555 truncedAlpha() { return *this; }
729 static inline quint8 alpha(quint8 a) { return (a + 1) >> 3; }
730 static inline quint8 ialpha(quint8 a) { return 0x20 - alpha(a); }
731
732 inline bool operator==(const qrgb555 &v) const { return v.data == data; }
733 inline bool operator!=(const qrgb555 &v) const { return v.data != data; }
734
735 inline quint16 rawValue() const { return data; }
736
737private:
738 friend class qargb8555;
739 friend class qbgr555;
740 quint16 data;
741
742} Q_PACKED;
743
744qrgb555::qrgb555(const qargb8555 &v)
745{
746 data = (v.data[2] << 8) | v.data[1];
747}
748
749qrgb555 qrgb555::operator+(qrgb555 v) const
750{
751 qrgb555 t;
752 t.data = data + v.data;
753 return t;
754}
755
756qrgb555 qrgb555::byte_mul(quint8 a) const
757{
758 quint16 t = (((data & 0x3e0) * a) >> 5) & 0x03e0;
759 t |= (((data & 0x7c1f) * a) >> 5) & 0x7c1f;
760
761 qrgb555 result;
762 result.data = t;
763 return result;
764}
765
766class qbgr555
767{
768public:
769 inline qbgr555(quint32 v) { *this = qbgr555(qrgb555(v)); }
770
771 inline qbgr555(qrgb555 v)
772 {
773 data = ((v.data & 0x001f) << 10) |
774 (v.data & 0x03e0) |
775 ((v.data & 0x7c00) >> 10);
776 }
777
778 inline bool operator==(const qbgr555 &v) const
779 {
780 return data == v.data;
781 }
782
783private:
784 quint16 data;
785} Q_PACKED;
786
787qargb8555::qargb8555(quint32 v)
788{
789 v = quint32p(v);
790 data[0] = qAlpha(v);
791 const int r = qRed(v);
792 const int g = qGreen(v);
793 const int b = qBlue(v);
794 data[1] = ((g << 2) & 0xe0) | (b >> 3);
795 data[2] = ((r >> 1) & 0x7c) | (g >> 6);
796
797}
798
799qargb8555::qargb8555(quint32p v)
800{
801 data[0] = qAlpha(v);
802 const int r = qRed(v);
803 const int g = qGreen(v);
804 const int b = qBlue(v);
805 data[1] = ((g << 2) & 0xe0) | (b >> 3);
806 data[2] = ((r >> 1) & 0x7c) | (g >> 6);
807}
808
809qargb8555::qargb8555(const qargb8555 &v)
810{
811 data[0] = v.data[0];
812 data[1] = v.data[1];
813 data[2] = v.data[2];
814}
815
816qargb8555::qargb8555(const qrgb555 &v)
817{
818 data[0] = 0xff;
819 data[1] = v.data & 0xff;
820 data[2] = v.data >> 8;
821}
822
823qargb8555::operator quint32() const
824{
825 const quint16 rgb = (data[2] << 8) | data[1];
826 const int r = (rgb & 0x7c00);
827 const int g = (rgb & 0x03e0);
828 const int b = (rgb & 0x001f);
829 const int tr = (r >> 7) | (r >> 12);
830 const int tg = (g >> 2) | (g >> 7);
831 const int tb = (b << 3) | (b >> 2);
832
833 return qRgba(tr, tg, tb, data[0]);
834}
835
836bool qargb8555::operator==(const qargb8555 &v) const
837{
838 return data[0] == v.data[0]
839 && data[1] == v.data[1]
840 && data[2] == v.data[2];
841}
842
843quint32 qargb8555::rawValue() const
844{
845 return (data[2] << 16) | (data[1] << 8) | data[0];
846}
847
848qargb8555 qargb8555::operator+(qargb8555 v) const
849{
850 qargb8555 t;
851 t.data[0] = data[0] + v.data[0];
852 const quint16 rgb = ((data[2] + v.data[2]) << 8)
853 + (data[1] + v.data[1]);
854 t.data[1] = rgb & 0xff;
855 t.data[2] = rgb >> 8;
856 return t;
857}
858
859qargb8555 qargb8555::byte_mul(quint8 a) const
860{
861 qargb8555 result;
862 result.data[0] = (data[0] * a) >> 5;
863
864 const quint16 x = (data[2] << 8) | data[1];
865 quint16 t = (((x & 0x3e0) * a) >> 5) & 0x03e0;
866 t |= (((x & 0x7c1f) * a) >> 5) & 0x7c1f;
867 result.data[1] = t & 0xff;
868 result.data[2] = t >> 8;
869 return result;
870
871}
872
873class qrgb666;
874
875class qargb6666
876{
877public:
878 static inline bool hasAlpha() { return true; }
879
880 inline qargb6666() {}
881 inline qargb6666(quint32 v) { *this = qargb6666(quint32p(v)); }
882 inline explicit qargb6666(quint32p v);
883 inline qargb6666(const qargb6666 &v);
884 inline qargb6666(const qrgb666 &v);
885
886 inline operator quint32 () const;
887
888 inline quint8 alpha() const;
889 inline qargb6666 truncedAlpha() { return *this; }
890 static inline quint8 alpha(quint8 a) { return (a + 1) >> 2; }
891 static inline quint8 ialpha(quint8 a) { return (255 - a + 1) >> 2; }
892
893 inline qargb6666 byte_mul(quint8 a) const;
894 inline qargb6666 operator+(qargb6666 v) const;
895 inline bool operator==(const qargb6666 &v) const;
896
897 inline quint32 rawValue() const;
898
899private:
900 friend class qrgb666;
901 quint8 data[3];
902
903} Q_PACKED;
904
905class qrgb666
906{
907public:
908 static inline bool hasAlpha() { return false; }
909
910 inline qrgb666() {}
911 inline qrgb666(quint32 v);
912 inline qrgb666(const qargb6666 &v);
913
914 inline operator quint32 () const;
915
916 inline quint8 alpha() const { return 0xff; }
917 inline qrgb666 truncedAlpha() { return *this; }
918 static inline quint8 alpha(quint8 a) { return (a + 1) >> 2; }
919 static inline quint8 ialpha(quint8 a) { return (255 - a + 1) >> 2; }
920
921 inline qrgb666 operator+(qrgb666 v) const;
922 inline qrgb666 byte_mul(quint8 a) const;
923
924 inline bool operator==(const qrgb666 &v) const;
925 inline bool operator!=(const qrgb666 &v) const { return !(*this == v); }
926
927 inline quint32 rawValue() const
928 {
929 return (data[2] << 16) | (data[1] << 8) | data[0];
930 }
931
932private:
933 friend class qargb6666;
934
935 quint8 data[3];
936} Q_PACKED;
937
938qrgb666::qrgb666(quint32 v)
939{
940 const uchar b = qBlue(v);
941 const uchar g = qGreen(v);
942 const uchar r = qRed(v);
943 const uint p = (b >> 2) | ((g >> 2) << 6) | ((r >> 2) << 12);
944 data[0] = qBlue(p);
945 data[1] = qGreen(p);
946 data[2] = qRed(p);
947}
948
949qrgb666::qrgb666(const qargb6666 &v)
950{
951 data[0] = v.data[0];
952 data[1] = v.data[1];
953 data[2] = v.data[2] & 0x03;
954}
955
956qrgb666::operator quint32 () const
957{
958 const uchar r = (data[2] << 6) | ((data[1] & 0xf0) >> 2) | (data[2] & 0x3);
959 const uchar g = (data[1] << 4) | ((data[0] & 0xc0) >> 4) | ((data[1] & 0x0f) >> 2);
960 const uchar b = (data[0] << 2) | ((data[0] & 0x3f) >> 4);
961 return qRgb(r, g, b);
962}
963
964qrgb666 qrgb666::operator+(qrgb666 v) const
965{
966 const quint32 x1 = (data[2] << 16) | (data[1] << 8) | data[0];
967 const quint32 x2 = (v.data[2] << 16) | (v.data[1] << 8) | v.data[0];
968 const quint32 t = x1 + x2;
969 qrgb666 r;
970 r.data[0] = t & 0xff;
971 r.data[1] = (t >> 8) & 0xff;
972 r.data[2] = (t >> 16) & 0xff;
973 return r;
974}
975
976qrgb666 qrgb666::byte_mul(quint8 a) const
977{
978 const quint32 x = (data[2] << 16) | (data[1] << 8) | data[0];
979 const quint32 t = ((((x & 0x03f03f) * a) >> 6) & 0x03f03f) |
980 ((((x & 0x000fc0) * a) >> 6) & 0x000fc0);
981
982 qrgb666 r;
983 r.data[0] = t & 0xff;
984 r.data[1] = (t >> 8) & 0xff;
985 r.data[2] = (t >> 16) & 0xff;
986 return r;
987}
988
989bool qrgb666::operator==(const qrgb666 &v) const
990{
991 return (data[0] == v.data[0] &&
992 data[1] == v.data[1] &&
993 data[2] == v.data[2]);
994}
995
996qargb6666::qargb6666(quint32p v)
997{
998 const quint8 b = qBlue(v) >> 2;
999 const quint8 g = qGreen(v) >> 2;
1000 const quint8 r = qRed(v) >> 2;
1001 const quint8 a = qAlpha(v) >> 2;
1002 const uint p = (a << 18) | (r << 12) | (g << 6) | b;
1003 data[0] = qBlue(p);
1004 data[1] = qGreen(p);
1005 data[2] = qRed(p);
1006}
1007
1008qargb6666::qargb6666(const qargb6666 &v)
1009{
1010 data[0] = v.data[0];
1011 data[1] = v.data[1];
1012 data[2] = v.data[2];
1013}
1014
1015qargb6666::qargb6666(const qrgb666 &v)
1016{
1017 data[0] = v.data[0];
1018 data[1] = v.data[1];
1019 data[2] = (v.data[2] | 0xfc);
1020}
1021
1022qargb6666::operator quint32 () const
1023{
1024 const quint8 r = (data[2] << 6) | ((data[1] & 0xf0) >> 2) | (data[2] & 0x3);
1025 const quint8 g = (data[1] << 4) | ((data[0] & 0xc0) >> 4) | ((data[1] & 0x0f) >> 2);
1026 const quint8 b = (data[0] << 2) | ((data[0] & 0x3f) >> 4);
1027 const quint8 a = (data[2] & 0xfc) | (data[2] >> 6);
1028 return qRgba(r, g, b, a);
1029}
1030
1031qargb6666 qargb6666::operator+(qargb6666 v) const
1032{
1033 const quint32 x1 = (data[2] << 16) | (data[1] << 8) | data[0];
1034 const quint32 x2 = (v.data[2] << 16) | (v.data[1] << 8) | v.data[0];
1035 const quint32 t = x1 + x2;
1036 qargb6666 r;
1037 r.data[0] = t & 0xff;
1038 r.data[1] = (t >> 8) & 0xff;
1039 r.data[2] = (t >> 16) & 0xff;
1040 return r;
1041}
1042
1043quint8 qargb6666::alpha() const
1044{
1045 return (data[2] & 0xfc) | (data[2] >> 6);
1046}
1047
1048inline qargb6666 qargb6666::byte_mul(quint8 a) const
1049{
1050 const quint32 x = (data[2] << 16) | (data[1] << 8) | data[0];
1051 const quint32 t = ((((x & 0x03f03f) * a) >> 6) & 0x03f03f) |
1052 ((((x & 0xfc0fc0) * a) >> 6) & 0xfc0fc0);
1053
1054 qargb6666 r;
1055 r.data[0] = t & 0xff;
1056 r.data[1] = (t >> 8) & 0xff;
1057 r.data[2] = (t >> 16) & 0xff;
1058 return r;
1059}
1060
1061bool qargb6666::operator==(const qargb6666 &v) const
1062{
1063 return data[0] == v.data[0]
1064 && data[1] == v.data[1]
1065 && data[2] == v.data[2];
1066}
1067
1068quint32 qargb6666::rawValue() const
1069{
1070 return (data[2] << 16) | (data[1] << 8) | data[0];
1071}
1072
1073class qrgb888
1074{
1075public:
1076 static inline bool hasAlpha() { return false; }
1077
1078 inline qrgb888() {}
1079 inline qrgb888(quint32 v);
1080
1081 inline operator quint32() const;
1082
1083 inline quint8 alpha() const { return 0xff; }
1084 inline qrgb888 truncedAlpha() { return *this; }
1085 static inline quint8 alpha(quint8 a) { return a; }
1086 static inline quint8 ialpha(quint8 a) { return 255 - a; }
1087
1088 inline qrgb888 byte_mul(quint8 a) const;
1089 inline qrgb888 operator+(qrgb888 v) const;
1090 inline bool operator==(qrgb888 v) const;
1091
1092 inline quint32 rawValue() const;
1093
1094private:
1095 uchar data[3];
1096
1097} Q_PACKED;
1098
1099qrgb888::qrgb888(quint32 v)
1100{
1101 data[0] = qRed(v);
1102 data[1] = qGreen(v);
1103 data[2] = qBlue(v);
1104}
1105
1106qrgb888::operator quint32() const
1107{
1108 return qRgb(data[0], data[1], data[2]);
1109}
1110
1111qrgb888 qrgb888::operator+(qrgb888 v) const
1112{
1113 qrgb888 t = *this;
1114 t.data[0] += v.data[0];
1115 t.data[1] += v.data[1];
1116 t.data[2] += v.data[2];
1117 return t;
1118}
1119
1120qrgb888 qrgb888::byte_mul(quint8 a) const
1121{
1122 quint32 x(*this);
1123
1124 quint32 t = (x & 0xff00ff) * a;
1125 t = (t + ((t >> 8) & 0xff00ff) + 0x800080) >> 8;
1126 t &= 0xff00ff;
1127
1128 x = ((x >> 8) & 0xff00ff) * a;
1129 x = (x + ((x >> 8) & 0xff00ff) + 0x800080);
1130 x &= 0xff00ff00;
1131 x |= t;
1132 return qrgb888(x);
1133}
1134
1135bool qrgb888::operator==(qrgb888 v) const
1136{
1137 return (data[0] == v.data[0] &&
1138 data[1] == v.data[1] &&
1139 data[2] == v.data[2]);
1140}
1141
1142quint32 qrgb888::rawValue() const
1143{
1144 return (data[2] << 16) | (data[1] << 8) | data[0];
1145}
1146
1147template <>
1148inline qrgb888 qt_colorConvert(quint32 color, qrgb888 dummy)
1149{
1150 Q_UNUSED(dummy);
1151 return qrgb888(color);
1152}
1153
1154template <>
1155inline quint32 qt_colorConvert(qrgb888 color, quint32 dummy)
1156{
1157 Q_UNUSED(dummy);
1158 return quint32(color);
1159}
1160
1161#ifdef QT_QWS_DEPTH_8
1162template <>
1163inline quint8 qt_colorConvert(quint32 color, quint8 dummy)
1164{
1165 Q_UNUSED(dummy);
1166
1167 uchar r = ((qRed(color) & 0xf8) + 0x19) / 0x33;
1168 uchar g = ((qGreen(color) &0xf8) + 0x19) / 0x33;
1169 uchar b = ((qBlue(color) &0xf8) + 0x19) / 0x33;
1170
1171 return r*6*6 + g*6 + b;
1172}
1173
1174template <>
1175inline quint8 qt_colorConvert(quint16 color, quint8 dummy)
1176{
1177 Q_UNUSED(dummy);
1178
1179 uchar r = (color & 0xf800) >> (11-3);
1180 uchar g = (color & 0x07c0) >> (6-3);
1181 uchar b = (color & 0x001f) << 3;
1182
1183 uchar tr = (r + 0x19) / 0x33;
1184 uchar tg = (g + 0x19) / 0x33;
1185 uchar tb = (b + 0x19) / 0x33;
1186
1187 return tr*6*6 + tg*6 + tb;
1188}
1189
1190#endif // QT_QWS_DEPTH_8
1191
1192// hw: endianess??
1193class quint24
1194{
1195public:
1196 inline quint24(quint32 v)
1197 {
1198 data[0] = qBlue(v);
1199 data[1] = qGreen(v);
1200 data[2] = qRed(v);
1201 }
1202
1203 inline operator quint32 ()
1204 {
1205 return qRgb(data[2], data[1], data[0]);
1206 }
1207
1208 inline bool operator==(const quint24 &v) const
1209 {
1210 return data[0] == v.data[0]
1211 && data[1] == v.data[1]
1212 && data[2] == v.data[2];
1213 }
1214
1215private:
1216 uchar data[3];
1217} Q_PACKED;
1218
1219template <>
1220inline quint24 qt_colorConvert(quint32 color, quint24 dummy)
1221{
1222 Q_UNUSED(dummy);
1223 return quint24(color);
1224}
1225
1226// hw: endianess??
1227class quint18
1228{
1229public:
1230 inline quint18(quint32 v)
1231 {
1232 uchar b = qBlue(v);
1233 uchar g = qGreen(v);
1234 uchar r = qRed(v);
1235 uint p = (b >> 2) | ((g >> 2) << 6) | ((r >> 2) << 12);
1236 data[0] = qBlue(p);
1237 data[1] = qGreen(p);
1238 data[2] = qRed(p);
1239 }
1240
1241 inline operator quint32 ()
1242 {
1243 const uchar r = (data[2] << 6) | ((data[1] & 0xf0) >> 2) | (data[2] & 0x3);
1244 const uchar g = (data[1] << 4) | ((data[0] & 0xc0) >> 4) | ((data[1] & 0x0f) >> 2);
1245 const uchar b = (data[0] << 2) | ((data[0] & 0x3f) >> 4);
1246 return qRgb(r, g, b);
1247 }
1248
1249private:
1250 uchar data[3];
1251} Q_PACKED;
1252
1253template <>
1254inline quint18 qt_colorConvert(quint32 color, quint18 dummy)
1255{
1256 Q_UNUSED(dummy);
1257 return quint18(color);
1258}
1259
1260class qrgb444;
1261
1262class qargb4444
1263{
1264public:
1265 static inline bool hasAlpha() { return true; }
1266
1267 inline qargb4444() {}
1268 inline qargb4444(quint32 v) { *this = qargb4444(quint32p(v)); }
1269 inline explicit qargb4444(quint32p v);
1270 inline qargb4444(const qrgb444 &v);
1271
1272 inline operator quint32() const;
1273 inline operator quint8() const;
1274
1275 inline qargb4444 operator+(qargb4444 v) const;
1276
1277 inline quint8 alpha() const { return ((data & 0xf000) >> 8) | ((data & 0xf000) >> 12); }
1278 inline qargb4444 truncedAlpha() { return *this; }
1279 static inline quint8 alpha(quint8 a) { return (a + 1) >> 4; }
1280 static inline quint8 ialpha(quint8 a) { return 0x10 - alpha(a); }
1281 inline qargb4444 byte_mul(quint8 a) const;
1282
1283 inline bool operator==(const qargb4444 &v) const { return data == v.data; }
1284
1285 inline quint16 rawValue() const { return data; }
1286
1287private:
1288 friend class qrgb444;
1289 quint16 data;
1290
1291} Q_PACKED;
1292
1293class qrgb444
1294{
1295public:
1296 static inline bool hasAlpha() { return false; }
1297
1298 inline qrgb444() {}
1299 inline qrgb444(quint32 v);
1300 inline explicit qrgb444(qargb4444 v);
1301
1302 inline operator quint32() const;
1303 inline operator quint8() const;
1304
1305 inline qrgb444 operator+(qrgb444 v) const;
1306 inline quint8 alpha() const { return 0xff; }
1307 inline qrgb444 truncedAlpha() { return *this; }
1308 static inline quint8 alpha(quint8 a) { return (a + 1) >> 4; }
1309 static inline quint8 ialpha(quint8 a) { return 0x10 - alpha(a); }
1310 inline qrgb444 byte_mul(quint8 a) const;
1311
1312 inline bool operator==(const qrgb444 &v) const { return data == v.data; }
1313 inline bool operator!=(const qrgb444 &v) const { return data != v.data; }
1314
1315 inline quint16 rawValue() const { return data; }
1316
1317private:
1318 friend class qargb4444;
1319 quint16 data;
1320
1321} Q_PACKED;
1322
1323
1324qargb4444::qargb4444(quint32p color)
1325{
1326 quint32 v = color;
1327 v &= 0xf0f0f0f0;
1328 const int a = qAlpha(v) << 8;
1329 const int r = qRed(v) << 4;
1330 const int g = qGreen(v);
1331 const int b = qBlue(v) >> 4;
1332
1333 data = a | r | g | b;
1334}
1335
1336qargb4444::qargb4444(const qrgb444 &v)
1337{
1338 data = v.data | 0xf000;
1339}
1340
1341qargb4444::operator quint32() const
1342{
1343 const int a = (data & 0xf000);
1344 const int r = (data & 0x0f00);
1345 const int g = (data & 0x00f0);
1346 const int b = (data & 0x000f);
1347 const int ta = (a >> 8) | (a >> 12);
1348 const int tr = (r >> 4) | (r >> 8);
1349 const int tg = g | (g >> 4);
1350 const int tb = (b << 4) | b;
1351
1352 return qRgba(tr, tg, tb, ta);
1353}
1354
1355qargb4444::operator quint8() const
1356{
1357 // hw: optimize!
1358 return qt_colorConvert<quint8, quint32>(operator quint32(), 0);
1359}
1360
1361qargb4444 qargb4444::operator+(qargb4444 v) const
1362{
1363 qargb4444 t;
1364 t.data = data + v.data;
1365 return t;
1366}
1367
1368qargb4444 qargb4444::byte_mul(quint8 a) const
1369{
1370 quint16 t = (((data & 0xf0f0) * a) >> 4) & 0xf0f0;
1371 t |= (((data & 0x0f0f) * a) >> 4) & 0x0f0f;
1372
1373 qargb4444 result;
1374 result.data = t;
1375 return result;
1376}
1377
1378qrgb444::qrgb444(quint32 v)
1379{
1380 v &= 0xf0f0f0f0;
1381 const int r = qRed(v) << 4;
1382 const int g = qGreen(v);
1383 const int b = qBlue(v) >> 4;
1384
1385 data = r | g | b;
1386}
1387
1388qrgb444::qrgb444(qargb4444 v)
1389{
1390 data = v.data & 0x0fff;
1391}
1392
1393qrgb444::operator quint32() const
1394{
1395 const int r = (data & 0x0f00);
1396 const int g = (data & 0x00f0);
1397 const int b = (data & 0x000f);
1398 const int tr = (r >> 4) | (r >> 8);
1399 const int tg = g | (g >> 4);
1400 const int tb = (b << 4) | b;
1401
1402 return qRgb(tr, tg, tb);
1403}
1404
1405qrgb444::operator quint8() const
1406{
1407 // hw: optimize!
1408 return qt_colorConvert<quint8, quint32>(operator quint32(), 0);
1409}
1410
1411qrgb444 qrgb444::operator+(qrgb444 v) const
1412{
1413 qrgb444 t;
1414 t.data = data + v.data;
1415 return t;
1416}
1417
1418qrgb444 qrgb444::byte_mul(quint8 a) const
1419{
1420 quint16 t = (((data & 0xf0f0) * a) >> 4) & 0xf0f0;
1421 t |= (((data & 0x0f0f) * a) >> 4) & 0x0f0f;
1422
1423 qrgb444 result;
1424 result.data = t;
1425 return result;
1426}
1427
1428#ifdef QT_QWS_DEPTH_GENERIC
1429
1430struct qrgb
1431{
1432public:
1433 static int bpp;
1434 static int len_red;
1435 static int len_green;
1436 static int len_blue;
1437 static int len_alpha;
1438 static int off_red;
1439 static int off_green;
1440 static int off_blue;
1441 static int off_alpha;
1442} Q_PACKED;
1443
1444template <typename SRC>
1445Q_STATIC_TEMPLATE_FUNCTION inline quint32 qt_convertToRgb(SRC color);
1446
1447template <>
1448inline quint32 qt_convertToRgb(quint32 color)
1449{
1450 const int r = qRed(color) >> (8 - qrgb::len_red);
1451 const int g = qGreen(color) >> (8 - qrgb::len_green);
1452 const int b = qBlue(color) >> (8 - qrgb::len_blue);
1453 const int a = qAlpha(color) >> (8 - qrgb::len_alpha);
1454 const quint32 v = (r << qrgb::off_red)
1455 | (g << qrgb::off_green)
1456 | (b << qrgb::off_blue)
1457 | (a << qrgb::off_alpha);
1458
1459 return v;
1460}
1461
1462template <>
1463inline quint32 qt_convertToRgb(quint16 color)
1464{
1465 return qt_convertToRgb(qt_colorConvert<quint32, quint16>(color, 0));
1466}
1467
1468class qrgb_generic16
1469{
1470public:
1471 inline qrgb_generic16(quint32 color)
1472 {
1473 const int r = qRed(color) >> (8 - qrgb::len_red);
1474 const int g = qGreen(color) >> (8 - qrgb::len_green);
1475 const int b = qBlue(color) >> (8 - qrgb::len_blue);
1476 const int a = qAlpha(color) >> (8 - qrgb::len_alpha);
1477 data = (r << qrgb::off_red)
1478 | (g << qrgb::off_green)
1479 | (b << qrgb::off_blue)
1480 | (a << qrgb::off_alpha);
1481 }
1482
1483 inline operator quint16 () { return data; }
1484 inline quint32 operator<<(int shift) const { return data << shift; }
1485
1486private:
1487 quint16 data;
1488} Q_PACKED;
1489
1490template <>
1491inline qrgb_generic16 qt_colorConvert(quint32 color, qrgb_generic16 dummy)
1492{
1493 Q_UNUSED(dummy);
1494 return qrgb_generic16(color);
1495}
1496
1497template <>
1498inline qrgb_generic16 qt_colorConvert(quint16 color, qrgb_generic16 dummy)
1499{
1500 Q_UNUSED(dummy);
1501 return qrgb_generic16(qt_colorConvert<quint32, quint16>(color, 0));
1502}
1503
1504#endif // QT_QWS_DEPTH_GENERIC
1505
1506template <class T>
1507void qt_memfill(T *dest, T value, int count);
1508
1509template<> inline void qt_memfill(quint32 *dest, quint32 color, int count)
1510{
1511 extern void (*qt_memfill32)(quint32 *dest, quint32 value, int count);
1512 qt_memfill32(dest, color, count);
1513}
1514
1515template<> inline void qt_memfill(quint16 *dest, quint16 color, int count)
1516{
1517 extern void (*qt_memfill16)(quint16 *dest, quint16 value, int count);
1518 qt_memfill16(dest, color, count);
1519}
1520
1521template<> inline void qt_memfill(quint8 *dest, quint8 color, int count)
1522{
1523 memset(dest, color, count);
1524}
1525
1526template <class T>
1527inline void qt_memfill(T *dest, T value, int count)
1528{
1529 int n = (count + 7) / 8;
1530 switch (count & 0x07)
1531 {
1532 case 0: do { *dest++ = value;
1533 case 7: *dest++ = value;
1534 case 6: *dest++ = value;
1535 case 5: *dest++ = value;
1536 case 4: *dest++ = value;
1537 case 3: *dest++ = value;
1538 case 2: *dest++ = value;
1539 case 1: *dest++ = value;
1540 } while (--n > 0);
1541 }
1542}
1543
1544template <class T>
1545inline void qt_rectfill(T *dest, T value,
1546 int x, int y, int width, int height, int stride)
1547{
1548 char *d = reinterpret_cast<char*>(dest + x) + y * stride;
1549 if (uint(stride) == (width * sizeof(T))) {
1550 qt_memfill(reinterpret_cast<T*>(d), value, width * height);
1551 } else {
1552 for (int j = 0; j < height; ++j) {
1553 dest = reinterpret_cast<T*>(d);
1554 qt_memfill(dest, value, width);
1555 d += stride;
1556 }
1557 }
1558}
1559
1560template <class DST, class SRC>
1561inline void qt_memconvert(DST *dest, const SRC *src, int count)
1562{
1563 if (sizeof(DST) == 1) {
1564 while (count) {
1565 int n = 1;
1566 const SRC color = *src++;
1567 const DST dstColor = qt_colorConvert<DST, SRC>(color, 0);
1568 while (--count && (*src == color || dstColor == qt_colorConvert<DST, SRC>(*src, 0))) {
1569 ++n;
1570 ++src;
1571 }
1572 qt_memfill(dest, dstColor, n);
1573 dest += n;
1574 }
1575 } else {
1576 /* Duff's device */
1577 int n = (count + 7) / 8;
1578 switch (count & 0x07)
1579 {
1580 case 0: do { *dest++ = qt_colorConvert<DST, SRC>(*src++, 0);
1581 case 7: *dest++ = qt_colorConvert<DST, SRC>(*src++, 0);
1582 case 6: *dest++ = qt_colorConvert<DST, SRC>(*src++, 0);
1583 case 5: *dest++ = qt_colorConvert<DST, SRC>(*src++, 0);
1584 case 4: *dest++ = qt_colorConvert<DST, SRC>(*src++, 0);
1585 case 3: *dest++ = qt_colorConvert<DST, SRC>(*src++, 0);
1586 case 2: *dest++ = qt_colorConvert<DST, SRC>(*src++, 0);
1587 case 1: *dest++ = qt_colorConvert<DST, SRC>(*src++, 0);
1588 } while (--n > 0);
1589 }
1590 }
1591}
1592
1593#define QT_TRIVIAL_MEMCONVERT_IMPL(T) \
1594 template <> \
1595 inline void qt_memconvert(T *dest, const T *src, int count) \
1596 { \
1597 memcpy(dest, src, count * sizeof(T)); \
1598 }
1599QT_TRIVIAL_MEMCONVERT_IMPL(quint32)
1600QT_TRIVIAL_MEMCONVERT_IMPL(qrgb888)
1601QT_TRIVIAL_MEMCONVERT_IMPL(qargb6666)
1602QT_TRIVIAL_MEMCONVERT_IMPL(qrgb666)
1603QT_TRIVIAL_MEMCONVERT_IMPL(quint16)
1604#ifdef Q_WS_QWS
1605QT_TRIVIAL_MEMCONVERT_IMPL(qrgb565)
1606#endif
1607QT_TRIVIAL_MEMCONVERT_IMPL(qargb8565)
1608QT_TRIVIAL_MEMCONVERT_IMPL(qargb8555)
1609QT_TRIVIAL_MEMCONVERT_IMPL(qrgb555)
1610QT_TRIVIAL_MEMCONVERT_IMPL(qargb4444)
1611QT_TRIVIAL_MEMCONVERT_IMPL(qrgb444)
1612#undef QT_TRIVIAL_MEMCONVERT_IMPL
1613
1614#if Q_BYTE_ORDER == Q_LITTLE_ENDIAN
1615template <>
1616inline void qt_memconvert(qrgb666 *dest, const quint32 *src, int count)
1617{
1618 if (count < 3) {
1619 switch (count) {
1620 case 2: *dest++ = qrgb666(*src++);
1621 case 1: *dest = qrgb666(*src);
1622 }
1623 return;
1624 }
1625
1626 const int align = (long(dest) & 3);
1627 switch (align) {
1628 case 1: *dest++ = qrgb666(*src++); --count;
1629 case 2: *dest++ = qrgb666(*src++); --count;
1630 case 3: *dest++ = qrgb666(*src++); --count;
1631 }
1632
1633 quint32 *dest32 = reinterpret_cast<quint32*>(dest);
1634 int sourceCount = count >> 2;
1635 while (sourceCount--) {
1636 dest32[0] = ((src[1] & 0x00000c00) << 20)
1637 | ((src[1] & 0x000000fc) << 22)
1638 | ((src[0] & 0x00fc0000) >> 6)
1639 | ((src[0] & 0x0000fc00) >> 4)
1640 | ((src[0] & 0x000000fc) >> 2);
1641 dest32[1] = ((src[2] & 0x003c0000) << 10)
1642 | ((src[2] & 0x0000fc00) << 12)
1643 | ((src[2] & 0x000000fc) << 14)
1644 | ((src[1] & 0x00fc0000) >> 14)
1645 | ((src[1] & 0x0000f000) >> 12);
1646 dest32[2] = ((src[3] & 0x00fc0000) << 2)
1647 | ((src[3] & 0x0000fc00) << 4)
1648 | ((src[3] & 0x000000fc) << 6)
1649 | ((src[2] & 0x00c00000) >> 22);
1650 dest32 += 3;
1651 src += 4;
1652 }
1653
1654 dest = reinterpret_cast<qrgb666*>(dest32);
1655 switch (count & 3) {
1656 case 3: *dest++ = qrgb666(*src++);
1657 case 2: *dest++ = qrgb666(*src++);
1658 case 1: *dest = qrgb666(*src);
1659 }
1660}
1661#endif // Q_BYTE_ORDER
1662
1663template <class T>
1664inline void qt_rectcopy(T *dest, const T *src,
1665 int x, int y, int width, int height,
1666 int dstStride, int srcStride)
1667{
1668 char *d = (char*)(dest + x) + y * dstStride;
1669 const char *s = (char*)(src);
1670 for (int i = 0; i < height; ++i) {
1671 ::memcpy(d, s, width * sizeof(T));
1672 d += dstStride;
1673 s += srcStride;
1674 }
1675}
1676
1677template <class DST, class SRC>
1678inline void qt_rectconvert(DST *dest, const SRC *src,
1679 int x, int y, int width, int height,
1680 int dstStride, int srcStride)
1681{
1682 char *d = (char*)(dest + x) + y * dstStride;
1683 const char *s = (char*)(src);
1684 for (int i = 0; i < height; ++i) {
1685 qt_memconvert<DST,SRC>((DST*)d, (const SRC*)s, width);
1686 d += dstStride;
1687 s += srcStride;
1688 }
1689}
1690
1691#define QT_RECTCONVERT_TRIVIAL_IMPL(T) \
1692 template <> \
1693 inline void qt_rectconvert(T *dest, const T *src, \
1694 int x, int y, int width, int height, \
1695 int dstStride, int srcStride) \
1696 { \
1697 qt_rectcopy(dest, src, x, y, width, height, dstStride, srcStride); \
1698 }
1699QT_RECTCONVERT_TRIVIAL_IMPL(quint32)
1700QT_RECTCONVERT_TRIVIAL_IMPL(qrgb888)
1701QT_RECTCONVERT_TRIVIAL_IMPL(qargb6666)
1702QT_RECTCONVERT_TRIVIAL_IMPL(qrgb666)
1703#ifdef Q_WS_QWS
1704QT_RECTCONVERT_TRIVIAL_IMPL(qrgb565)
1705#endif
1706QT_RECTCONVERT_TRIVIAL_IMPL(qargb8565)
1707QT_RECTCONVERT_TRIVIAL_IMPL(quint16)
1708QT_RECTCONVERT_TRIVIAL_IMPL(qargb8555)
1709QT_RECTCONVERT_TRIVIAL_IMPL(qrgb555)
1710QT_RECTCONVERT_TRIVIAL_IMPL(qargb4444)
1711QT_RECTCONVERT_TRIVIAL_IMPL(qrgb444)
1712#undef QT_RECTCONVERT_TRIVIAL_IMPL
1713
1714#ifdef QT_QWS_DEPTH_GENERIC
1715template <> void qt_rectconvert(qrgb *dest, const quint32 *src,
1716 int x, int y, int width, int height,
1717 int dstStride, int srcStride);
1718
1719template <> void qt_rectconvert(qrgb *dest, const quint16 *src,
1720 int x, int y, int width, int height,
1721 int dstStride, int srcStride);
1722#endif // QT_QWS_DEPTH_GENERIC
1723
1724#define QT_MEMFILL_UINT(dest, length, color) \
1725 qt_memfill<quint32>(dest, color, length);
1726
1727#define QT_MEMFILL_USHORT(dest, length, color) \
1728 qt_memfill<quint16>(dest, color, length);
1729
1730#define QT_MEMCPY_REV_UINT(dest, src, length) \
1731do { \
1732 /* Duff's device */ \
1733 uint *_d = (uint*)(dest) + length; \
1734 const uint *_s = (uint*)(src) + length; \
1735 register int n = ((length) + 7) / 8; \
1736 switch ((length) & 0x07) \
1737 { \
1738 case 0: do { *--_d = *--_s; \
1739 case 7: *--_d = *--_s; \
1740 case 6: *--_d = *--_s; \
1741 case 5: *--_d = *--_s; \
1742 case 4: *--_d = *--_s; \
1743 case 3: *--_d = *--_s; \
1744 case 2: *--_d = *--_s; \
1745 case 1: *--_d = *--_s; \
1746 } while (--n > 0); \
1747 } \
1748} while (0)
1749
1750#define QT_MEMCPY_USHORT(dest, src, length) \
1751do { \
1752 /* Duff's device */ \
1753 ushort *_d = (ushort*)(dest); \
1754 const ushort *_s = (ushort*)(src); \
1755 register int n = ((length) + 7) / 8; \
1756 switch ((length) & 0x07) \
1757 { \
1758 case 0: do { *_d++ = *_s++; \
1759 case 7: *_d++ = *_s++; \
1760 case 6: *_d++ = *_s++; \
1761 case 5: *_d++ = *_s++; \
1762 case 4: *_d++ = *_s++; \
1763 case 3: *_d++ = *_s++; \
1764 case 2: *_d++ = *_s++; \
1765 case 1: *_d++ = *_s++; \
1766 } while (--n > 0); \
1767 } \
1768} while (0)
1769
1770Q_STATIC_INLINE_FUNCTION int qt_div_255(int x) { return (x + (x>>8) + 0x80) >> 8; }
1771
1772inline ushort qConvertRgb32To16(uint c)
1773{
1774 return (((c) >> 3) & 0x001f)
1775 | (((c) >> 5) & 0x07e0)
1776 | (((c) >> 8) & 0xf800);
1777}
1778
1779#if defined(Q_WS_QWS) || (QT_VERSION >= 0x040400)
1780inline quint32 qConvertRgb32To16x2(quint64 c)
1781{
1782 c = (((c) >> 3) & Q_UINT64_C(0x001f0000001f))
1783 | (((c) >> 5) & Q_UINT64_C(0x07e0000007e0))
1784 | (((c) >> 8) & Q_UINT64_C(0xf8000000f800));
1785 return c | (c >> 16);
1786}
1787#endif
1788
1789inline QRgb qConvertRgb16To32(uint c)
1790{
1791 return 0xff000000
1792 | ((((c) << 3) & 0xf8) | (((c) >> 2) & 0x7))
1793 | ((((c) << 5) & 0xfc00) | (((c) >> 1) & 0x300))
1794 | ((((c) << 8) & 0xf80000) | (((c) << 3) & 0x70000));
1795}
1796
1797inline int qRed565(quint16 rgb) {
1798 const int r = (rgb & 0xf800);
1799 return (r >> 8) | (r >> 13);
1800}
1801
1802inline int qGreen565(quint16 rgb) {
1803 const int g = (rgb & 0x07e0);
1804 return (g >> 3) | (g >> 9);
1805}
1806
1807inline int qBlue565(quint16 rgb) {
1808 const int b = (rgb & 0x001f);
1809 return (b << 3) | (b >> 2);
1810}
1811
1812#if 1
1813static inline uint INTERPOLATE_PIXEL_256(uint x, uint a, uint y, uint b) {
1814 uint t = (x & 0xff00ff) * a + (y & 0xff00ff) * b;
1815 t >>= 8;
1816 t &= 0xff00ff;
1817
1818 x = ((x >> 8) & 0xff00ff) * a + ((y >> 8) & 0xff00ff) * b;
1819 x &= 0xff00ff00;
1820 x |= t;
1821 return x;
1822}
1823
1824static inline uint INTERPOLATE_PIXEL_255(uint x, uint a, uint y, uint b) {
1825 uint t = (x & 0xff00ff) * a + (y & 0xff00ff) * b;
1826 t = (t + ((t >> 8) & 0xff00ff) + 0x800080) >> 8;
1827 t &= 0xff00ff;
1828
1829 x = ((x >> 8) & 0xff00ff) * a + ((y >> 8) & 0xff00ff) * b;
1830 x = (x + ((x >> 8) & 0xff00ff) + 0x800080);
1831 x &= 0xff00ff00;
1832 x |= t;
1833 return x;
1834}
1835#else
1836// possible implementation for 64 bit
1837static inline uint INTERPOLATE_PIXEL_256(uint x, uint a, uint y, uint b) {
1838 ulong t = (((ulong(x)) | ((ulong(x)) << 24)) & 0x00ff00ff00ff00ff) * a;
1839 t += (((ulong(y)) | ((ulong(y)) << 24)) & 0x00ff00ff00ff00ff) * b;
1840 t >>= 8;
1841 t &= 0x00ff00ff00ff00ff;
1842 return (uint(t)) | (uint(t >> 24));
1843}
1844
1845static inline uint INTERPOLATE_PIXEL_255(uint x, uint a, uint y, uint b) {
1846 ulong t = (((ulong(x)) | ((ulong(x)) << 24)) & 0x00ff00ff00ff00ff) * a;
1847 t += (((ulong(y)) | ((ulong(y)) << 24)) & 0x00ff00ff00ff00ff) * b;
1848 t = (t + ((t >> 8) & 0xff00ff00ff00ff) + 0x80008000800080);
1849 t &= 0x00ff00ff00ff00ff;
1850 return (uint(t)) | (uint(t >> 24));
1851}
1852
1853Q_STATIC_INLINE_FUNCTION uint BYTE_MUL(uint x, uint a) {
1854 ulong t = (((ulong(x)) | ((ulong(x)) << 24)) & 0x00ff00ff00ff00ff) * a;
1855 t = (t + ((t >> 8) & 0xff00ff00ff00ff) + 0x80008000800080);
1856 t &= 0x00ff00ff00ff00ff;
1857 return (uint(t)) | (uint(t >> 24));
1858}
1859
1860static inline uint PREMUL(uint x) {
1861 uint a = x >> 24;
1862 ulong t = (((ulong(x)) | ((ulong(x)) << 24)) & 0x00ff00ff00ff00ff) * a;
1863 t = (t + ((t >> 8) & 0xff00ff00ff00ff) + 0x80008000800080);
1864 t &= 0x00ff00ff00ff00ff;
1865 return (uint(t)) | (uint(t >> 24)) | 0xff000000;
1866}
1867#endif
1868
1869const uint qt_bayer_matrix[16][16] = {
1870 { 0x1, 0xc0, 0x30, 0xf0, 0xc, 0xcc, 0x3c, 0xfc,
1871 0x3, 0xc3, 0x33, 0xf3, 0xf, 0xcf, 0x3f, 0xff},
1872 { 0x80, 0x40, 0xb0, 0x70, 0x8c, 0x4c, 0xbc, 0x7c,
1873 0x83, 0x43, 0xb3, 0x73, 0x8f, 0x4f, 0xbf, 0x7f},
1874 { 0x20, 0xe0, 0x10, 0xd0, 0x2c, 0xec, 0x1c, 0xdc,
1875 0x23, 0xe3, 0x13, 0xd3, 0x2f, 0xef, 0x1f, 0xdf},
1876 { 0xa0, 0x60, 0x90, 0x50, 0xac, 0x6c, 0x9c, 0x5c,
1877 0xa3, 0x63, 0x93, 0x53, 0xaf, 0x6f, 0x9f, 0x5f},
1878 { 0x8, 0xc8, 0x38, 0xf8, 0x4, 0xc4, 0x34, 0xf4,
1879 0xb, 0xcb, 0x3b, 0xfb, 0x7, 0xc7, 0x37, 0xf7},
1880 { 0x88, 0x48, 0xb8, 0x78, 0x84, 0x44, 0xb4, 0x74,
1881 0x8b, 0x4b, 0xbb, 0x7b, 0x87, 0x47, 0xb7, 0x77},
1882 { 0x28, 0xe8, 0x18, 0xd8, 0x24, 0xe4, 0x14, 0xd4,
1883 0x2b, 0xeb, 0x1b, 0xdb, 0x27, 0xe7, 0x17, 0xd7},
1884 { 0xa8, 0x68, 0x98, 0x58, 0xa4, 0x64, 0x94, 0x54,
1885 0xab, 0x6b, 0x9b, 0x5b, 0xa7, 0x67, 0x97, 0x57},
1886 { 0x2, 0xc2, 0x32, 0xf2, 0xe, 0xce, 0x3e, 0xfe,
1887 0x1, 0xc1, 0x31, 0xf1, 0xd, 0xcd, 0x3d, 0xfd},
1888 { 0x82, 0x42, 0xb2, 0x72, 0x8e, 0x4e, 0xbe, 0x7e,
1889 0x81, 0x41, 0xb1, 0x71, 0x8d, 0x4d, 0xbd, 0x7d},
1890 { 0x22, 0xe2, 0x12, 0xd2, 0x2e, 0xee, 0x1e, 0xde,
1891 0x21, 0xe1, 0x11, 0xd1, 0x2d, 0xed, 0x1d, 0xdd},
1892 { 0xa2, 0x62, 0x92, 0x52, 0xae, 0x6e, 0x9e, 0x5e,
1893 0xa1, 0x61, 0x91, 0x51, 0xad, 0x6d, 0x9d, 0x5d},
1894 { 0xa, 0xca, 0x3a, 0xfa, 0x6, 0xc6, 0x36, 0xf6,
1895 0x9, 0xc9, 0x39, 0xf9, 0x5, 0xc5, 0x35, 0xf5},
1896 { 0x8a, 0x4a, 0xba, 0x7a, 0x86, 0x46, 0xb6, 0x76,
1897 0x89, 0x49, 0xb9, 0x79, 0x85, 0x45, 0xb5, 0x75},
1898 { 0x2a, 0xea, 0x1a, 0xda, 0x26, 0xe6, 0x16, 0xd6,
1899 0x29, 0xe9, 0x19, 0xd9, 0x25, 0xe5, 0x15, 0xd5},
1900 { 0xaa, 0x6a, 0x9a, 0x5a, 0xa6, 0x66, 0x96, 0x56,
1901 0xa9, 0x69, 0x99, 0x59, 0xa5, 0x65, 0x95, 0x55}
1902};
1903
1904#define ARGB_COMBINE_ALPHA(argb, alpha) \
1905 ((((argb >> 24) * alpha) >> 8) << 24) | (argb & 0x00ffffff)
1906
1907
1908QT_END_NAMESPACE
1909
1910#endif // QDRAWHELPER_P_H
Note: See TracBrowser for help on using the repository browser.