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