author | eckhart.koppen@nokia.com |
Wed, 31 Mar 2010 11:06:36 +0300 | |
changeset 7 | f7bc934e204c |
parent 3 | 41300fa6a67c |
permissions | -rw-r--r-- |
0 | 1 |
/**************************************************************************** |
2 |
** |
|
7
f7bc934e204c
5cabc75a39ca2f064f70b40f72ed93c74c4dc19b
eckhart.koppen@nokia.com
parents:
3
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 |
#include <private/qdrawhelper_p.h> |
|
43 |
#include <private/qpaintengine_raster_p.h> |
|
44 |
#include <private/qpainter_p.h> |
|
45 |
#include <private/qdrawhelper_x86_p.h> |
|
46 |
#include <private/qdrawhelper_armv6_p.h> |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
47 |
#include <private/qdrawhelper_neon_p.h> |
0 | 48 |
#include <private/qmath_p.h> |
49 |
#include <qmath.h> |
|
50 |
||
51 |
QT_BEGIN_NAMESPACE |
|
52 |
||
53 |
||
54 |
#define MASK(src, a) src = BYTE_MUL(src, a) |
|
55 |
||
56 |
#if defined(Q_OS_IRIX) && defined(Q_CC_GNU) && __GNUC__ == 3 && __GNUC__ < 4 && QT_POINTER_SIZE == 8 |
|
57 |
#define Q_IRIX_GCC3_3_WORKAROUND |
|
58 |
// |
|
59 |
// work around http://gcc.gnu.org/bugzilla/show_bug.cgi?id=14484 |
|
60 |
// |
|
61 |
static uint gccBug(uint value) __attribute__((noinline)); |
|
62 |
static uint gccBug(uint value) |
|
63 |
{ |
|
64 |
return value; |
|
65 |
} |
|
66 |
#endif |
|
67 |
||
68 |
/* |
|
69 |
constants and structures |
|
70 |
*/ |
|
71 |
||
72 |
static const int fixed_scale = 1 << 16; |
|
73 |
static const int half_point = 1 << 15; |
|
74 |
static const int buffer_size = 2048; |
|
75 |
||
76 |
struct LinearGradientValues |
|
77 |
{ |
|
78 |
qreal dx; |
|
79 |
qreal dy; |
|
80 |
qreal l; |
|
81 |
qreal off; |
|
82 |
}; |
|
83 |
||
84 |
struct RadialGradientValues |
|
85 |
{ |
|
86 |
qreal dx; |
|
87 |
qreal dy; |
|
88 |
qreal a; |
|
89 |
}; |
|
90 |
||
91 |
struct Operator; |
|
92 |
typedef uint* (QT_FASTCALL *DestFetchProc)(uint *buffer, QRasterBuffer *rasterBuffer, int x, int y, int length); |
|
93 |
typedef void (QT_FASTCALL *DestStoreProc)(QRasterBuffer *rasterBuffer, int x, int y, const uint *buffer, int length); |
|
94 |
typedef const uint* (QT_FASTCALL *SourceFetchProc)(uint *buffer, const Operator *o, const QSpanData *data, int y, int x, int length); |
|
95 |
||
96 |
||
97 |
struct Operator |
|
98 |
{ |
|
99 |
QPainter::CompositionMode mode; |
|
100 |
DestFetchProc dest_fetch; |
|
101 |
DestStoreProc dest_store; |
|
102 |
SourceFetchProc src_fetch; |
|
103 |
CompositionFunctionSolid funcSolid; |
|
104 |
CompositionFunction func; |
|
105 |
union { |
|
106 |
LinearGradientValues linear; |
|
107 |
RadialGradientValues radial; |
|
108 |
// TextureValues texture; |
|
109 |
}; |
|
110 |
}; |
|
111 |
||
112 |
/* |
|
113 |
Destination fetch. This is simple as we don't have to do bounds checks or |
|
114 |
transformations |
|
115 |
*/ |
|
116 |
||
117 |
static uint * QT_FASTCALL destFetchMono(uint *buffer, QRasterBuffer *rasterBuffer, int x, int y, int length) |
|
118 |
{ |
|
119 |
uchar *data = (uchar *)rasterBuffer->scanLine(y); |
|
120 |
uint *start = buffer; |
|
121 |
const uint *end = buffer + length; |
|
122 |
while (buffer < end) { |
|
123 |
*buffer = data[x>>3] & (0x80 >> (x & 7)) ? rasterBuffer->destColor1 : rasterBuffer->destColor0; |
|
124 |
++buffer; |
|
125 |
++x; |
|
126 |
} |
|
127 |
return start; |
|
128 |
} |
|
129 |
||
130 |
static uint * QT_FASTCALL destFetchMonoLsb(uint *buffer, QRasterBuffer *rasterBuffer, int x, int y, int length) |
|
131 |
{ |
|
132 |
uchar *data = (uchar *)rasterBuffer->scanLine(y); |
|
133 |
uint *start = buffer; |
|
134 |
const uint *end = buffer + length; |
|
135 |
while (buffer < end) { |
|
136 |
*buffer = data[x>>3] & (0x1 << (x & 7)) ? rasterBuffer->destColor1 : rasterBuffer->destColor0; |
|
137 |
++buffer; |
|
138 |
++x; |
|
139 |
} |
|
140 |
return start; |
|
141 |
} |
|
142 |
||
143 |
static uint * QT_FASTCALL destFetchARGB32(uint *buffer, QRasterBuffer *rasterBuffer, int x, int y, int length) |
|
144 |
{ |
|
145 |
const uint *data = (const uint *)rasterBuffer->scanLine(y) + x; |
|
146 |
for (int i = 0; i < length; ++i) |
|
147 |
buffer[i] = PREMUL(data[i]); |
|
148 |
return buffer; |
|
149 |
} |
|
150 |
||
151 |
static uint * QT_FASTCALL destFetchARGB32P(uint *, QRasterBuffer *rasterBuffer, int x, int y, int) |
|
152 |
{ |
|
153 |
return (uint *)rasterBuffer->scanLine(y) + x; |
|
154 |
} |
|
155 |
||
156 |
static uint * QT_FASTCALL destFetchRGB16(uint *buffer, QRasterBuffer *rasterBuffer, int x, int y, int length) |
|
157 |
{ |
|
158 |
const ushort *data = (const ushort *)rasterBuffer->scanLine(y) + x; |
|
159 |
for (int i = 0; i < length; ++i) |
|
160 |
buffer[i] = qConvertRgb16To32(data[i]); |
|
161 |
return buffer; |
|
162 |
} |
|
163 |
||
164 |
template <class DST> |
|
165 |
Q_STATIC_TEMPLATE_FUNCTION uint * QT_FASTCALL destFetch(uint *buffer, QRasterBuffer *rasterBuffer, |
|
166 |
int x, int y, int length) |
|
167 |
{ |
|
168 |
const DST *src = reinterpret_cast<DST*>(rasterBuffer->scanLine(y)) + x; |
|
169 |
quint32 *dest = reinterpret_cast<quint32*>(buffer); |
|
170 |
while (length--) |
|
171 |
*dest++ = *src++; |
|
172 |
return buffer; |
|
173 |
} |
|
174 |
||
175 |
# define SPANFUNC_POINTER_DESTFETCH(Arg) destFetch<Arg> |
|
176 |
||
177 |
static const DestFetchProc destFetchProc[QImage::NImageFormats] = |
|
178 |
{ |
|
179 |
0, // Format_Invalid |
|
180 |
destFetchMono, // Format_Mono, |
|
181 |
destFetchMonoLsb, // Format_MonoLSB |
|
182 |
0, // Format_Indexed8 |
|
183 |
destFetchARGB32P, // Format_RGB32 |
|
184 |
destFetchARGB32, // Format_ARGB32, |
|
185 |
destFetchARGB32P, // Format_ARGB32_Premultiplied |
|
186 |
destFetchRGB16, // Format_RGB16 |
|
187 |
SPANFUNC_POINTER_DESTFETCH(qargb8565), // Format_ARGB8565_Premultiplied |
|
188 |
SPANFUNC_POINTER_DESTFETCH(qrgb666), // Format_RGB666 |
|
189 |
SPANFUNC_POINTER_DESTFETCH(qargb6666), // Format_ARGB6666_Premultiplied |
|
190 |
SPANFUNC_POINTER_DESTFETCH(qrgb555), // Format_RGB555 |
|
191 |
SPANFUNC_POINTER_DESTFETCH(qargb8555), // Format_ARGB8555_Premultiplied |
|
192 |
SPANFUNC_POINTER_DESTFETCH(qrgb888), // Format_RGB888 |
|
193 |
SPANFUNC_POINTER_DESTFETCH(qrgb444), // Format_RGB444 |
|
194 |
SPANFUNC_POINTER_DESTFETCH(qargb4444) // Format_ARGB4444_Premultiplied |
|
195 |
}; |
|
196 |
||
197 |
/* |
|
198 |
Returns the color in the mono destination color table |
|
199 |
that is the "nearest" to /color/. |
|
200 |
*/ |
|
201 |
static inline QRgb findNearestColor(QRgb color, QRasterBuffer *rbuf) |
|
202 |
{ |
|
203 |
QRgb color_0 = PREMUL(rbuf->destColor0); |
|
204 |
QRgb color_1 = PREMUL(rbuf->destColor1); |
|
205 |
color = PREMUL(color); |
|
206 |
||
207 |
int r = qRed(color); |
|
208 |
int g = qGreen(color); |
|
209 |
int b = qBlue(color); |
|
210 |
int rx, gx, bx; |
|
211 |
int dist_0, dist_1; |
|
212 |
||
213 |
rx = r - qRed(color_0); |
|
214 |
gx = g - qGreen(color_0); |
|
215 |
bx = b - qBlue(color_0); |
|
216 |
dist_0 = rx*rx + gx*gx + bx*bx; |
|
217 |
||
218 |
rx = r - qRed(color_1); |
|
219 |
gx = g - qGreen(color_1); |
|
220 |
bx = b - qBlue(color_1); |
|
221 |
dist_1 = rx*rx + gx*gx + bx*bx; |
|
222 |
||
223 |
if (dist_0 < dist_1) |
|
224 |
return color_0; |
|
225 |
return color_1; |
|
226 |
} |
|
227 |
||
228 |
/* |
|
229 |
Destination store. |
|
230 |
*/ |
|
231 |
||
232 |
static void QT_FASTCALL destStoreMono(QRasterBuffer *rasterBuffer, int x, int y, const uint *buffer, int length) |
|
233 |
{ |
|
234 |
uchar *data = (uchar *)rasterBuffer->scanLine(y); |
|
235 |
if (rasterBuffer->monoDestinationWithClut) { |
|
236 |
for (int i = 0; i < length; ++i) { |
|
237 |
if (buffer[i] == rasterBuffer->destColor0) { |
|
238 |
data[x >> 3] &= ~(0x80 >> (x & 7)); |
|
239 |
} else if (buffer[i] == rasterBuffer->destColor1) { |
|
240 |
data[x >> 3] |= 0x80 >> (x & 7); |
|
241 |
} else if (findNearestColor(buffer[i], rasterBuffer) == rasterBuffer->destColor0) { |
|
242 |
data[x >> 3] &= ~(0x80 >> (x & 7)); |
|
243 |
} else { |
|
244 |
data[x >> 3] |= 0x80 >> (x & 7); |
|
245 |
} |
|
246 |
++x; |
|
247 |
} |
|
248 |
} else { |
|
249 |
for (int i = 0; i < length; ++i) { |
|
250 |
if (qGray(buffer[i]) < int(qt_bayer_matrix[y & 15][x & 15])) |
|
251 |
data[x >> 3] |= 0x80 >> (x & 7); |
|
252 |
else |
|
253 |
data[x >> 3] &= ~(0x80 >> (x & 7)); |
|
254 |
++x; |
|
255 |
} |
|
256 |
} |
|
257 |
} |
|
258 |
||
259 |
static void QT_FASTCALL destStoreMonoLsb(QRasterBuffer *rasterBuffer, int x, int y, const uint *buffer, int length) |
|
260 |
{ |
|
261 |
uchar *data = (uchar *)rasterBuffer->scanLine(y); |
|
262 |
if (rasterBuffer->monoDestinationWithClut) { |
|
263 |
for (int i = 0; i < length; ++i) { |
|
264 |
if (buffer[i] == rasterBuffer->destColor0) { |
|
265 |
data[x >> 3] &= ~(1 << (x & 7)); |
|
266 |
} else if (buffer[i] == rasterBuffer->destColor1) { |
|
267 |
data[x >> 3] |= 1 << (x & 7); |
|
268 |
} else if (findNearestColor(buffer[i], rasterBuffer) == rasterBuffer->destColor0) { |
|
269 |
data[x >> 3] &= ~(1 << (x & 7)); |
|
270 |
} else { |
|
271 |
data[x >> 3] |= 1 << (x & 7); |
|
272 |
} |
|
273 |
++x; |
|
274 |
} |
|
275 |
} else { |
|
276 |
for (int i = 0; i < length; ++i) { |
|
277 |
if (qGray(buffer[i]) < int(qt_bayer_matrix[y & 15][x & 15])) |
|
278 |
data[x >> 3] |= 1 << (x & 7); |
|
279 |
else |
|
280 |
data[x >> 3] &= ~(1 << (x & 7)); |
|
281 |
++x; |
|
282 |
} |
|
283 |
} |
|
284 |
} |
|
285 |
||
286 |
static void QT_FASTCALL destStoreARGB32(QRasterBuffer *rasterBuffer, int x, int y, const uint *buffer, int length) |
|
287 |
{ |
|
288 |
uint *data = (uint *)rasterBuffer->scanLine(y) + x; |
|
289 |
for (int i = 0; i < length; ++i) { |
|
290 |
int p = buffer[i]; |
|
291 |
int alpha = qAlpha(p); |
|
292 |
if (alpha == 255) |
|
293 |
data[i] = p; |
|
294 |
else if (alpha == 0) |
|
295 |
data[i] = 0; |
|
296 |
else { |
|
297 |
int inv_alpha = 0xff0000/qAlpha(buffer[i]); |
|
298 |
data[i] = (p & 0xff000000) |
|
299 |
| ((qRed(p)*inv_alpha) & 0xff0000) |
|
300 |
| (((qGreen(p)*inv_alpha) >> 8) & 0xff00) |
|
301 |
| ((qBlue(p)*inv_alpha) >> 16); |
|
302 |
} |
|
303 |
} |
|
304 |
} |
|
305 |
||
306 |
static void QT_FASTCALL destStoreRGB16(QRasterBuffer *rasterBuffer, int x, int y, const uint *buffer, int length) |
|
307 |
{ |
|
308 |
quint16 *data = (quint16*)rasterBuffer->scanLine(y) + x; |
|
309 |
qt_memconvert<quint16, quint32>(data, buffer, length); |
|
310 |
} |
|
311 |
||
312 |
template <class DST> |
|
313 |
Q_STATIC_TEMPLATE_FUNCTION void QT_FASTCALL destStore(QRasterBuffer *rasterBuffer, |
|
314 |
int x, int y, |
|
315 |
const uint *buffer, int length) |
|
316 |
{ |
|
317 |
DST *dest = reinterpret_cast<DST*>(rasterBuffer->scanLine(y)) + x; |
|
318 |
const quint32p *src = reinterpret_cast<const quint32p*>(buffer); |
|
319 |
while (length--) |
|
320 |
*dest++ = DST(*src++); |
|
321 |
} |
|
322 |
||
323 |
# define SPANFUNC_POINTER_DESTSTORE(DEST) destStore<DEST> |
|
324 |
||
325 |
static const DestStoreProc destStoreProc[QImage::NImageFormats] = |
|
326 |
{ |
|
327 |
0, // Format_Invalid |
|
328 |
destStoreMono, // Format_Mono, |
|
329 |
destStoreMonoLsb, // Format_MonoLSB |
|
330 |
0, // Format_Indexed8 |
|
331 |
0, // Format_RGB32 |
|
332 |
destStoreARGB32, // Format_ARGB32, |
|
333 |
0, // Format_ARGB32_Premultiplied |
|
334 |
destStoreRGB16, // Format_RGB16 |
|
335 |
SPANFUNC_POINTER_DESTSTORE(qargb8565), // Format_ARGB8565_Premultiplied |
|
336 |
SPANFUNC_POINTER_DESTSTORE(qrgb666), // Format_RGB666 |
|
337 |
SPANFUNC_POINTER_DESTSTORE(qargb6666), // Format_ARGB6666_Premultiplied |
|
338 |
SPANFUNC_POINTER_DESTSTORE(qrgb555), // Format_RGB555 |
|
339 |
SPANFUNC_POINTER_DESTSTORE(qargb8555), // Format_ARGB8555_Premultiplied |
|
340 |
SPANFUNC_POINTER_DESTSTORE(qrgb888), // Format_RGB888 |
|
341 |
SPANFUNC_POINTER_DESTSTORE(qrgb444), // Format_RGB444 |
|
342 |
SPANFUNC_POINTER_DESTSTORE(qargb4444) // Format_ARGB4444_Premultiplied |
|
343 |
}; |
|
344 |
||
345 |
/* |
|
346 |
Source fetches |
|
347 |
||
348 |
This is a bit more complicated, as we need several fetch routines for every surface type |
|
349 |
||
350 |
We need 5 fetch methods per surface type: |
|
351 |
untransformed |
|
352 |
transformed (tiled and not tiled) |
|
353 |
transformed bilinear (tiled and not tiled) |
|
354 |
||
355 |
We don't need bounds checks for untransformed, but we need them for the other ones. |
|
356 |
||
357 |
The generic implementation does pixel by pixel fetches |
|
358 |
*/ |
|
359 |
||
360 |
template <QImage::Format format> |
|
361 |
Q_STATIC_TEMPLATE_FUNCTION uint QT_FASTCALL qt_fetchPixel(const uchar *scanLine, int x, const QVector<QRgb> *rgb); |
|
362 |
||
363 |
template<> |
|
364 |
Q_STATIC_TEMPLATE_SPECIALIZATION |
|
365 |
uint QT_FASTCALL qt_fetchPixel<QImage::Format_Mono>(const uchar *scanLine, |
|
366 |
int x, const QVector<QRgb> *rgb) |
|
367 |
{ |
|
368 |
bool pixel = scanLine[x>>3] & (0x80 >> (x & 7)); |
|
369 |
if (rgb) return PREMUL(rgb->at(pixel ? 1 : 0)); |
|
370 |
return pixel ? 0xff000000 : 0xffffffff; |
|
371 |
} |
|
372 |
||
373 |
template<> |
|
374 |
Q_STATIC_TEMPLATE_SPECIALIZATION |
|
375 |
uint QT_FASTCALL qt_fetchPixel<QImage::Format_MonoLSB>(const uchar *scanLine, |
|
376 |
int x, const QVector<QRgb> *rgb) |
|
377 |
{ |
|
378 |
bool pixel = scanLine[x>>3] & (0x1 << (x & 7)); |
|
379 |
if (rgb) return PREMUL(rgb->at(pixel ? 1 : 0)); |
|
380 |
return pixel ? 0xff000000 : 0xffffffff; |
|
381 |
} |
|
382 |
||
383 |
template<> |
|
384 |
Q_STATIC_TEMPLATE_SPECIALIZATION |
|
385 |
uint QT_FASTCALL qt_fetchPixel<QImage::Format_Indexed8>(const uchar *scanLine, |
|
386 |
int x, const QVector<QRgb> *rgb) |
|
387 |
{ |
|
388 |
return PREMUL(rgb->at(scanLine[x])); |
|
389 |
} |
|
390 |
||
391 |
template<> |
|
392 |
Q_STATIC_TEMPLATE_SPECIALIZATION |
|
393 |
uint QT_FASTCALL qt_fetchPixel<QImage::Format_ARGB32>(const uchar *scanLine, |
|
394 |
int x, const QVector<QRgb> *) |
|
395 |
{ |
|
396 |
return PREMUL(((const uint *)scanLine)[x]); |
|
397 |
} |
|
398 |
||
399 |
template<> |
|
400 |
Q_STATIC_TEMPLATE_SPECIALIZATION |
|
401 |
uint QT_FASTCALL qt_fetchPixel<QImage::Format_ARGB32_Premultiplied>(const uchar *scanLine, |
|
402 |
int x, const QVector<QRgb> *) |
|
403 |
{ |
|
404 |
return ((const uint *)scanLine)[x]; |
|
405 |
} |
|
406 |
||
407 |
template<> |
|
408 |
Q_STATIC_TEMPLATE_SPECIALIZATION |
|
409 |
uint QT_FASTCALL qt_fetchPixel<QImage::Format_RGB16>(const uchar *scanLine, |
|
410 |
int x, const QVector<QRgb> *) |
|
411 |
{ |
|
412 |
return qConvertRgb16To32(((const ushort *)scanLine)[x]); |
|
413 |
} |
|
414 |
||
415 |
template<> |
|
416 |
Q_STATIC_TEMPLATE_SPECIALIZATION |
|
417 |
uint QT_FASTCALL qt_fetchPixel<QImage::Format_ARGB8565_Premultiplied>(const uchar *scanLine, |
|
418 |
int x, |
|
419 |
const QVector<QRgb> *) |
|
420 |
{ |
|
421 |
const qargb8565 color = reinterpret_cast<const qargb8565*>(scanLine)[x]; |
|
422 |
return qt_colorConvert<quint32, qargb8565>(color, 0); |
|
423 |
} |
|
424 |
||
425 |
template<> |
|
426 |
Q_STATIC_TEMPLATE_SPECIALIZATION |
|
427 |
uint QT_FASTCALL qt_fetchPixel<QImage::Format_RGB666>(const uchar *scanLine, |
|
428 |
int x, |
|
429 |
const QVector<QRgb> *) |
|
430 |
{ |
|
431 |
const qrgb666 color = reinterpret_cast<const qrgb666*>(scanLine)[x]; |
|
432 |
return qt_colorConvert<quint32, qrgb666>(color, 0); |
|
433 |
} |
|
434 |
||
435 |
template<> |
|
436 |
Q_STATIC_TEMPLATE_SPECIALIZATION |
|
437 |
uint QT_FASTCALL qt_fetchPixel<QImage::Format_ARGB6666_Premultiplied>(const uchar *scanLine, |
|
438 |
int x, |
|
439 |
const QVector<QRgb> *) |
|
440 |
{ |
|
441 |
const qargb6666 color = reinterpret_cast<const qargb6666*>(scanLine)[x]; |
|
442 |
return qt_colorConvert<quint32, qargb6666>(color, 0); |
|
443 |
} |
|
444 |
||
445 |
template<> |
|
446 |
Q_STATIC_TEMPLATE_SPECIALIZATION |
|
447 |
uint QT_FASTCALL qt_fetchPixel<QImage::Format_RGB555>(const uchar *scanLine, |
|
448 |
int x, |
|
449 |
const QVector<QRgb> *) |
|
450 |
{ |
|
451 |
const qrgb555 color = reinterpret_cast<const qrgb555*>(scanLine)[x]; |
|
452 |
return qt_colorConvert<quint32, qrgb555>(color, 0); |
|
453 |
} |
|
454 |
||
455 |
template<> |
|
456 |
Q_STATIC_TEMPLATE_SPECIALIZATION |
|
457 |
uint QT_FASTCALL qt_fetchPixel<QImage::Format_ARGB8555_Premultiplied>(const uchar *scanLine, |
|
458 |
int x, |
|
459 |
const QVector<QRgb> *) |
|
460 |
{ |
|
461 |
const qargb8555 color = reinterpret_cast<const qargb8555*>(scanLine)[x]; |
|
462 |
return qt_colorConvert<quint32, qargb8555>(color, 0); |
|
463 |
} |
|
464 |
||
465 |
template<> |
|
466 |
Q_STATIC_TEMPLATE_SPECIALIZATION |
|
467 |
uint QT_FASTCALL qt_fetchPixel<QImage::Format_RGB888>(const uchar *scanLine, |
|
468 |
int x, |
|
469 |
const QVector<QRgb> *) |
|
470 |
{ |
|
471 |
const qrgb888 color = reinterpret_cast<const qrgb888*>(scanLine)[x]; |
|
472 |
return qt_colorConvert<quint32, qrgb888>(color, 0); |
|
473 |
} |
|
474 |
||
475 |
template<> |
|
476 |
Q_STATIC_TEMPLATE_SPECIALIZATION |
|
477 |
uint QT_FASTCALL qt_fetchPixel<QImage::Format_RGB444>(const uchar *scanLine, |
|
478 |
int x, |
|
479 |
const QVector<QRgb> *) |
|
480 |
{ |
|
481 |
const qrgb444 color = reinterpret_cast<const qrgb444*>(scanLine)[x]; |
|
482 |
return qt_colorConvert<quint32, qrgb444>(color, 0); |
|
483 |
} |
|
484 |
||
485 |
template<> |
|
486 |
Q_STATIC_TEMPLATE_SPECIALIZATION |
|
487 |
uint QT_FASTCALL qt_fetchPixel<QImage::Format_ARGB4444_Premultiplied>(const uchar *scanLine, |
|
488 |
int x, |
|
489 |
const QVector<QRgb> *) |
|
490 |
{ |
|
491 |
const qargb4444 color = reinterpret_cast<const qargb4444*>(scanLine)[x]; |
|
492 |
return qt_colorConvert<quint32, qargb4444>(color, 0); |
|
493 |
} |
|
494 |
||
495 |
template<> |
|
496 |
Q_STATIC_TEMPLATE_SPECIALIZATION |
|
497 |
uint QT_FASTCALL qt_fetchPixel<QImage::Format_Invalid>(const uchar *, |
|
498 |
int , |
|
499 |
const QVector<QRgb> *) |
|
500 |
{ |
|
501 |
return 0; |
|
502 |
} |
|
503 |
||
504 |
typedef uint (QT_FASTCALL *FetchPixelProc)(const uchar *scanLine, int x, const QVector<QRgb> *); |
|
505 |
||
506 |
#define SPANFUNC_POINTER_FETCHPIXEL(Arg) qt_fetchPixel<QImage::Arg> |
|
507 |
||
508 |
||
509 |
static const FetchPixelProc fetchPixelProc[QImage::NImageFormats] = |
|
510 |
{ |
|
511 |
0, |
|
512 |
SPANFUNC_POINTER_FETCHPIXEL(Format_Mono), |
|
513 |
SPANFUNC_POINTER_FETCHPIXEL(Format_MonoLSB), |
|
514 |
SPANFUNC_POINTER_FETCHPIXEL(Format_Indexed8), |
|
515 |
SPANFUNC_POINTER_FETCHPIXEL(Format_ARGB32_Premultiplied), |
|
516 |
SPANFUNC_POINTER_FETCHPIXEL(Format_ARGB32), |
|
517 |
SPANFUNC_POINTER_FETCHPIXEL(Format_ARGB32_Premultiplied), |
|
518 |
SPANFUNC_POINTER_FETCHPIXEL(Format_RGB16), |
|
519 |
SPANFUNC_POINTER_FETCHPIXEL(Format_ARGB8565_Premultiplied), |
|
520 |
SPANFUNC_POINTER_FETCHPIXEL(Format_RGB666), |
|
521 |
SPANFUNC_POINTER_FETCHPIXEL(Format_ARGB6666_Premultiplied), |
|
522 |
SPANFUNC_POINTER_FETCHPIXEL(Format_RGB555), |
|
523 |
SPANFUNC_POINTER_FETCHPIXEL(Format_ARGB8555_Premultiplied), |
|
524 |
SPANFUNC_POINTER_FETCHPIXEL(Format_RGB888), |
|
525 |
SPANFUNC_POINTER_FETCHPIXEL(Format_RGB444), |
|
526 |
SPANFUNC_POINTER_FETCHPIXEL(Format_ARGB4444_Premultiplied) |
|
527 |
}; |
|
528 |
||
529 |
enum TextureBlendType { |
|
530 |
BlendUntransformed, |
|
531 |
BlendTiled, |
|
532 |
BlendTransformed, |
|
533 |
BlendTransformedTiled, |
|
534 |
BlendTransformedBilinear, |
|
535 |
BlendTransformedBilinearTiled, |
|
536 |
NBlendTypes |
|
537 |
}; |
|
538 |
||
539 |
template <QImage::Format format> |
|
540 |
Q_STATIC_TEMPLATE_FUNCTION const uint * QT_FASTCALL qt_fetchUntransformed(uint *buffer, const Operator *, const QSpanData *data, |
|
541 |
int y, int x, int length) |
|
542 |
{ |
|
543 |
const uchar *scanLine = data->texture.scanLine(y); |
|
544 |
for (int i = 0; i < length; ++i) |
|
545 |
buffer[i] = qt_fetchPixel<format>(scanLine, x + i, data->texture.colorTable); |
|
546 |
return buffer; |
|
547 |
} |
|
548 |
||
549 |
template <> |
|
550 |
Q_STATIC_TEMPLATE_SPECIALIZATION const uint * QT_FASTCALL |
|
551 |
qt_fetchUntransformed<QImage::Format_ARGB32_Premultiplied>(uint *, const Operator *, |
|
552 |
const QSpanData *data, |
|
553 |
int y, int x, int) |
|
554 |
{ |
|
555 |
const uchar *scanLine = data->texture.scanLine(y); |
|
556 |
return ((const uint *)scanLine) + x; |
|
557 |
} |
|
558 |
||
559 |
template<TextureBlendType blendType> /* either BlendTransformed or BlendTransformedTiled */ |
|
560 |
Q_STATIC_TEMPLATE_FUNCTION |
|
561 |
const uint * QT_FASTCALL fetchTransformed(uint *buffer, const Operator *, const QSpanData *data, |
|
562 |
int y, int x, int length) |
|
563 |
{ |
|
564 |
FetchPixelProc fetch = fetchPixelProc[data->texture.format]; |
|
565 |
||
566 |
int image_width = data->texture.width; |
|
567 |
int image_height = data->texture.height; |
|
568 |
||
569 |
const qreal cx = x + 0.5; |
|
570 |
const qreal cy = y + 0.5; |
|
571 |
||
572 |
const uint *end = buffer + length; |
|
573 |
uint *b = buffer; |
|
574 |
if (data->fast_matrix) { |
|
575 |
// The increment pr x in the scanline |
|
576 |
int fdx = (int)(data->m11 * fixed_scale); |
|
577 |
int fdy = (int)(data->m12 * fixed_scale); |
|
578 |
||
579 |
int fx = int((data->m21 * cy |
|
580 |
+ data->m11 * cx + data->dx) * fixed_scale); |
|
581 |
int fy = int((data->m22 * cy |
|
582 |
+ data->m12 * cx + data->dy) * fixed_scale); |
|
583 |
||
584 |
while (b < end) { |
|
585 |
int px = fx >> 16; |
|
586 |
int py = fy >> 16; |
|
587 |
||
588 |
if (blendType == BlendTransformedTiled) { |
|
589 |
px %= image_width; |
|
590 |
py %= image_height; |
|
591 |
if (px < 0) px += image_width; |
|
592 |
if (py < 0) py += image_height; |
|
593 |
||
594 |
const uchar *scanLine = data->texture.scanLine(py); |
|
595 |
*b = fetch(scanLine, px, data->texture.colorTable); |
|
596 |
} else { |
|
597 |
if ((px < 0) || (px >= image_width) |
|
598 |
|| (py < 0) || (py >= image_height)) { |
|
599 |
*b = uint(0); |
|
600 |
} else { |
|
601 |
const uchar *scanLine = data->texture.scanLine(py); |
|
602 |
*b = fetch(scanLine, px, data->texture.colorTable); |
|
603 |
} |
|
604 |
} |
|
605 |
fx += fdx; |
|
606 |
fy += fdy; |
|
607 |
++b; |
|
608 |
} |
|
609 |
} else { |
|
610 |
const qreal fdx = data->m11; |
|
611 |
const qreal fdy = data->m12; |
|
612 |
const qreal fdw = data->m13; |
|
613 |
||
614 |
qreal fx = data->m21 * cy + data->m11 * cx + data->dx; |
|
615 |
qreal fy = data->m22 * cy + data->m12 * cx + data->dy; |
|
616 |
qreal fw = data->m23 * cy + data->m13 * cx + data->m33; |
|
617 |
||
618 |
while (b < end) { |
|
619 |
const qreal iw = fw == 0 ? 1 : 1 / fw; |
|
620 |
const qreal tx = fx * iw; |
|
621 |
const qreal ty = fy * iw; |
|
622 |
int px = int(tx) - (tx < 0); |
|
623 |
int py = int(ty) - (ty < 0); |
|
624 |
||
625 |
if (blendType == BlendTransformedTiled) { |
|
626 |
px %= image_width; |
|
627 |
py %= image_height; |
|
628 |
if (px < 0) px += image_width; |
|
629 |
if (py < 0) py += image_height; |
|
630 |
||
631 |
const uchar *scanLine = data->texture.scanLine(py); |
|
632 |
*b = fetch(scanLine, px, data->texture.colorTable); |
|
633 |
} else { |
|
634 |
if ((px < 0) || (px >= image_width) |
|
635 |
|| (py < 0) || (py >= image_height)) { |
|
636 |
*b = uint(0); |
|
637 |
} else { |
|
638 |
const uchar *scanLine = data->texture.scanLine(py); |
|
639 |
*b = fetch(scanLine, px, data->texture.colorTable); |
|
640 |
} |
|
641 |
} |
|
642 |
fx += fdx; |
|
643 |
fy += fdy; |
|
644 |
fw += fdw; |
|
645 |
//force increment to avoid /0 |
|
646 |
if (!fw) { |
|
647 |
fw += fdw; |
|
648 |
} |
|
649 |
++b; |
|
650 |
} |
|
651 |
} |
|
652 |
||
653 |
return buffer; |
|
654 |
} |
|
655 |
||
656 |
template<TextureBlendType blendType, QImage::Format format> /* blendType = BlendTransformedBilinear or BlendTransformedBilinearTiled */ |
|
657 |
Q_STATIC_TEMPLATE_FUNCTION |
|
658 |
const uint * QT_FASTCALL fetchTransformedBilinear(uint *buffer, const Operator *, const QSpanData *data, |
|
659 |
int y, int x, int length) |
|
660 |
{ |
|
661 |
#ifdef Q_CC_RVCT // needed to avoid compiler crash in RVCT 2.2 |
|
662 |
FetchPixelProc fetch; |
|
663 |
if (format != QImage::Format_Invalid) |
|
664 |
fetch = qt_fetchPixel<format>; |
|
665 |
else |
|
666 |
fetch = fetchPixelProc[data->texture.format]; |
|
667 |
#else |
|
668 |
FetchPixelProc fetch = (format != QImage::Format_Invalid) ? FetchPixelProc(qt_fetchPixel<format>) : fetchPixelProc[data->texture.format]; |
|
669 |
#endif |
|
670 |
||
671 |
int image_width = data->texture.width; |
|
672 |
int image_height = data->texture.height; |
|
673 |
||
674 |
const qreal cx = x + 0.5; |
|
675 |
const qreal cy = y + 0.5; |
|
676 |
||
677 |
const uint *end = buffer + length; |
|
678 |
uint *b = buffer; |
|
679 |
if (data->fast_matrix) { |
|
680 |
// The increment pr x in the scanline |
|
681 |
int fdx = (int)(data->m11 * fixed_scale); |
|
682 |
int fdy = (int)(data->m12 * fixed_scale); |
|
683 |
||
684 |
int fx = int((data->m21 * cy |
|
685 |
+ data->m11 * cx + data->dx) * fixed_scale); |
|
686 |
int fy = int((data->m22 * cy |
|
687 |
+ data->m12 * cx + data->dy) * fixed_scale); |
|
688 |
||
689 |
fx -= half_point; |
|
690 |
fy -= half_point; |
|
691 |
while (b < end) { |
|
692 |
int x1 = (fx >> 16); |
|
693 |
int x2 = x1 + 1; |
|
694 |
int y1 = (fy >> 16); |
|
695 |
int y2 = y1 + 1; |
|
696 |
||
697 |
int distx = ((fx - (x1 << 16)) >> 8); |
|
698 |
int disty = ((fy - (y1 << 16)) >> 8); |
|
699 |
int idistx = 256 - distx; |
|
700 |
int idisty = 256 - disty; |
|
701 |
||
702 |
if (blendType == BlendTransformedBilinearTiled) { |
|
703 |
x1 %= image_width; |
|
704 |
x2 %= image_width; |
|
705 |
y1 %= image_height; |
|
706 |
y2 %= image_height; |
|
707 |
||
708 |
if (x1 < 0) x1 += image_width; |
|
709 |
if (x2 < 0) x2 += image_width; |
|
710 |
if (y1 < 0) y1 += image_height; |
|
711 |
if (y2 < 0) y2 += image_height; |
|
712 |
||
713 |
Q_ASSERT(x1 >= 0 && x1 < image_width); |
|
714 |
Q_ASSERT(x2 >= 0 && x2 < image_width); |
|
715 |
Q_ASSERT(y1 >= 0 && y1 < image_height); |
|
716 |
Q_ASSERT(y2 >= 0 && y2 < image_height); |
|
717 |
} else { |
|
718 |
x1 = qBound(0, x1, image_width - 1); |
|
719 |
x2 = qBound(0, x2, image_width - 1); |
|
720 |
y1 = qBound(0, y1, image_height - 1); |
|
721 |
y2 = qBound(0, y2, image_height - 1); |
|
722 |
} |
|
723 |
||
724 |
const uchar *s1 = data->texture.scanLine(y1); |
|
725 |
const uchar *s2 = data->texture.scanLine(y2); |
|
726 |
||
727 |
uint tl = fetch(s1, x1, data->texture.colorTable); |
|
728 |
uint tr = fetch(s1, x2, data->texture.colorTable); |
|
729 |
uint bl = fetch(s2, x1, data->texture.colorTable); |
|
730 |
uint br = fetch(s2, x2, data->texture.colorTable); |
|
731 |
||
732 |
uint xtop = INTERPOLATE_PIXEL_256(tl, idistx, tr, distx); |
|
733 |
uint xbot = INTERPOLATE_PIXEL_256(bl, idistx, br, distx); |
|
734 |
*b = INTERPOLATE_PIXEL_256(xtop, idisty, xbot, disty); |
|
735 |
||
736 |
fx += fdx; |
|
737 |
fy += fdy; |
|
738 |
++b; |
|
739 |
} |
|
740 |
} else { |
|
741 |
const qreal fdx = data->m11; |
|
742 |
const qreal fdy = data->m12; |
|
743 |
const qreal fdw = data->m13; |
|
744 |
||
745 |
qreal fx = data->m21 * cy + data->m11 * cx + data->dx; |
|
746 |
qreal fy = data->m22 * cy + data->m12 * cx + data->dy; |
|
747 |
qreal fw = data->m23 * cy + data->m13 * cx + data->m33; |
|
748 |
||
749 |
while (b < end) { |
|
750 |
const qreal iw = fw == 0 ? 1 : 1 / fw; |
|
751 |
const qreal px = fx * iw - 0.5; |
|
752 |
const qreal py = fy * iw - 0.5; |
|
753 |
||
754 |
int x1 = int(px) - (px < 0); |
|
755 |
int x2 = x1 + 1; |
|
756 |
int y1 = int(py) - (py < 0); |
|
757 |
int y2 = y1 + 1; |
|
758 |
||
759 |
int distx = int((px - x1) * 256); |
|
760 |
int disty = int((py - y1) * 256); |
|
761 |
int idistx = 256 - distx; |
|
762 |
int idisty = 256 - disty; |
|
763 |
||
764 |
if (blendType == BlendTransformedBilinearTiled) { |
|
765 |
x1 %= image_width; |
|
766 |
x2 %= image_width; |
|
767 |
y1 %= image_height; |
|
768 |
y2 %= image_height; |
|
769 |
||
770 |
if (x1 < 0) x1 += image_width; |
|
771 |
if (x2 < 0) x2 += image_width; |
|
772 |
if (y1 < 0) y1 += image_height; |
|
773 |
if (y2 < 0) y2 += image_height; |
|
774 |
||
775 |
Q_ASSERT(x1 >= 0 && x1 < image_width); |
|
776 |
Q_ASSERT(x2 >= 0 && x2 < image_width); |
|
777 |
Q_ASSERT(y1 >= 0 && y1 < image_height); |
|
778 |
Q_ASSERT(y2 >= 0 && y2 < image_height); |
|
779 |
} else { |
|
780 |
x1 = qBound(0, x1, image_width - 1); |
|
781 |
x2 = qBound(0, x2, image_width - 1); |
|
782 |
y1 = qBound(0, y1, image_height - 1); |
|
783 |
y2 = qBound(0, y2, image_height - 1); |
|
784 |
} |
|
785 |
||
786 |
const uchar *s1 = data->texture.scanLine(y1); |
|
787 |
const uchar *s2 = data->texture.scanLine(y2); |
|
788 |
||
789 |
uint tl = fetch(s1, x1, data->texture.colorTable); |
|
790 |
uint tr = fetch(s1, x2, data->texture.colorTable); |
|
791 |
uint bl = fetch(s2, x1, data->texture.colorTable); |
|
792 |
uint br = fetch(s2, x2, data->texture.colorTable); |
|
793 |
||
794 |
uint xtop = INTERPOLATE_PIXEL_256(tl, idistx, tr, distx); |
|
795 |
uint xbot = INTERPOLATE_PIXEL_256(bl, idistx, br, distx); |
|
796 |
*b = INTERPOLATE_PIXEL_256(xtop, idisty, xbot, disty); |
|
797 |
||
798 |
fx += fdx; |
|
799 |
fy += fdy; |
|
800 |
fw += fdw; |
|
801 |
//force increment to avoid /0 |
|
802 |
if (!fw) { |
|
803 |
fw += fdw; |
|
804 |
} |
|
805 |
++b; |
|
806 |
} |
|
807 |
} |
|
808 |
||
809 |
return buffer; |
|
810 |
} |
|
811 |
||
812 |
#define SPANFUNC_POINTER_FETCHHUNTRANSFORMED(Arg) qt_fetchUntransformed<QImage::Arg> |
|
813 |
||
814 |
static const SourceFetchProc sourceFetch[NBlendTypes][QImage::NImageFormats] = { |
|
815 |
// Untransformed |
|
816 |
{ |
|
817 |
0, // Invalid |
|
818 |
SPANFUNC_POINTER_FETCHHUNTRANSFORMED(Format_Mono), // Mono |
|
819 |
SPANFUNC_POINTER_FETCHHUNTRANSFORMED(Format_MonoLSB), // MonoLsb |
|
820 |
SPANFUNC_POINTER_FETCHHUNTRANSFORMED(Format_Indexed8), // Indexed8 |
|
821 |
SPANFUNC_POINTER_FETCHHUNTRANSFORMED(Format_ARGB32_Premultiplied), // RGB32 |
|
822 |
SPANFUNC_POINTER_FETCHHUNTRANSFORMED(Format_ARGB32), // ARGB32 |
|
823 |
SPANFUNC_POINTER_FETCHHUNTRANSFORMED(Format_ARGB32_Premultiplied), // ARGB32_Premultiplied |
|
824 |
SPANFUNC_POINTER_FETCHHUNTRANSFORMED(Format_RGB16), // RGB16 |
|
825 |
SPANFUNC_POINTER_FETCHHUNTRANSFORMED(Format_ARGB8565_Premultiplied),// ARGB8565_Premultiplied |
|
826 |
SPANFUNC_POINTER_FETCHHUNTRANSFORMED(Format_RGB666), // RGB666 |
|
827 |
SPANFUNC_POINTER_FETCHHUNTRANSFORMED(Format_ARGB6666_Premultiplied),// ARGB6666_Premultiplied |
|
828 |
SPANFUNC_POINTER_FETCHHUNTRANSFORMED(Format_RGB555), // RGB555 |
|
829 |
SPANFUNC_POINTER_FETCHHUNTRANSFORMED(Format_ARGB8555_Premultiplied),// ARGB8555_Premultiplied |
|
830 |
SPANFUNC_POINTER_FETCHHUNTRANSFORMED(Format_RGB888), // RGB888 |
|
831 |
SPANFUNC_POINTER_FETCHHUNTRANSFORMED(Format_RGB444), // RGB444 |
|
832 |
SPANFUNC_POINTER_FETCHHUNTRANSFORMED(Format_ARGB4444_Premultiplied) // ARGB4444_Premultiplied |
|
833 |
}, |
|
834 |
// Tiled |
|
835 |
{ |
|
836 |
0, // Invalid |
|
837 |
SPANFUNC_POINTER_FETCHHUNTRANSFORMED(Format_Mono), // Mono |
|
838 |
SPANFUNC_POINTER_FETCHHUNTRANSFORMED(Format_MonoLSB), // MonoLsb |
|
839 |
SPANFUNC_POINTER_FETCHHUNTRANSFORMED(Format_Indexed8), // Indexed8 |
|
840 |
SPANFUNC_POINTER_FETCHHUNTRANSFORMED(Format_ARGB32_Premultiplied), // RGB32 |
|
841 |
SPANFUNC_POINTER_FETCHHUNTRANSFORMED(Format_ARGB32), // ARGB32 |
|
842 |
SPANFUNC_POINTER_FETCHHUNTRANSFORMED(Format_ARGB32_Premultiplied), // ARGB32_Premultiplied |
|
843 |
SPANFUNC_POINTER_FETCHHUNTRANSFORMED(Format_RGB16), // RGB16 |
|
844 |
SPANFUNC_POINTER_FETCHHUNTRANSFORMED(Format_ARGB8565_Premultiplied),// ARGB8565_Premultiplied |
|
845 |
SPANFUNC_POINTER_FETCHHUNTRANSFORMED(Format_RGB666), // RGB666 |
|
846 |
SPANFUNC_POINTER_FETCHHUNTRANSFORMED(Format_ARGB6666_Premultiplied),// ARGB6666_Premultiplied |
|
847 |
SPANFUNC_POINTER_FETCHHUNTRANSFORMED(Format_RGB555), // RGB555 |
|
848 |
SPANFUNC_POINTER_FETCHHUNTRANSFORMED(Format_ARGB8555_Premultiplied),// ARGB8555_Premultiplied |
|
849 |
SPANFUNC_POINTER_FETCHHUNTRANSFORMED(Format_RGB888), // RGB888 |
|
850 |
SPANFUNC_POINTER_FETCHHUNTRANSFORMED(Format_RGB444), // RGB444 |
|
851 |
SPANFUNC_POINTER_FETCHHUNTRANSFORMED(Format_ARGB4444_Premultiplied) // ARGB4444_Premultiplied |
|
852 |
}, |
|
853 |
// Transformed |
|
854 |
{ |
|
855 |
0, // Invalid |
|
856 |
fetchTransformed<BlendTransformed>, // Mono |
|
857 |
fetchTransformed<BlendTransformed>, // MonoLsb |
|
858 |
fetchTransformed<BlendTransformed>, // Indexed8 |
|
859 |
fetchTransformed<BlendTransformed>, // RGB32 |
|
860 |
fetchTransformed<BlendTransformed>, // ARGB32 |
|
861 |
fetchTransformed<BlendTransformed>, // ARGB32_Premultiplied |
|
862 |
fetchTransformed<BlendTransformed>, // RGB16 |
|
863 |
fetchTransformed<BlendTransformed>, // ARGB8565_Premultiplied |
|
864 |
fetchTransformed<BlendTransformed>, // RGB666 |
|
865 |
fetchTransformed<BlendTransformed>, // ARGB6666_Premultiplied |
|
866 |
fetchTransformed<BlendTransformed>, // RGB555 |
|
867 |
fetchTransformed<BlendTransformed>, // ARGB8555_Premultiplied |
|
868 |
fetchTransformed<BlendTransformed>, // RGB888 |
|
869 |
fetchTransformed<BlendTransformed>, // RGB444 |
|
870 |
fetchTransformed<BlendTransformed>, // ARGB4444_Premultiplied |
|
871 |
}, |
|
872 |
{ |
|
873 |
0, // TransformedTiled |
|
874 |
fetchTransformed<BlendTransformedTiled>, // Mono |
|
875 |
fetchTransformed<BlendTransformedTiled>, // MonoLsb |
|
876 |
fetchTransformed<BlendTransformedTiled>, // Indexed8 |
|
877 |
fetchTransformed<BlendTransformedTiled>, // RGB32 |
|
878 |
fetchTransformed<BlendTransformedTiled>, // ARGB32 |
|
879 |
fetchTransformed<BlendTransformedTiled>, // ARGB32_Premultiplied |
|
880 |
fetchTransformed<BlendTransformedTiled>, // RGB16 |
|
881 |
fetchTransformed<BlendTransformedTiled>, // ARGB8565_Premultiplied |
|
882 |
fetchTransformed<BlendTransformedTiled>, // RGB666 |
|
883 |
fetchTransformed<BlendTransformedTiled>, // ARGB6666_Premultiplied |
|
884 |
fetchTransformed<BlendTransformedTiled>, // RGB555 |
|
885 |
fetchTransformed<BlendTransformedTiled>, // ARGB8555_Premultiplied |
|
886 |
fetchTransformed<BlendTransformedTiled>, // RGB888 |
|
887 |
fetchTransformed<BlendTransformedTiled>, // RGB444 |
|
888 |
fetchTransformed<BlendTransformedTiled>, // ARGB4444_Premultiplied |
|
889 |
}, |
|
890 |
{ |
|
891 |
0, // Bilinear |
|
892 |
fetchTransformedBilinear<BlendTransformedBilinear, QImage::Format_Invalid>, // Mono |
|
893 |
fetchTransformedBilinear<BlendTransformedBilinear, QImage::Format_Invalid>, // MonoLsb |
|
894 |
fetchTransformedBilinear<BlendTransformedBilinear, QImage::Format_Invalid>, // Indexed8 |
|
895 |
fetchTransformedBilinear<BlendTransformedBilinear, QImage::Format_ARGB32_Premultiplied>, // RGB32 |
|
896 |
fetchTransformedBilinear<BlendTransformedBilinear, QImage::Format_ARGB32>, // ARGB32 |
|
897 |
fetchTransformedBilinear<BlendTransformedBilinear, QImage::Format_ARGB32_Premultiplied>, // ARGB32_Premultiplied |
|
898 |
fetchTransformedBilinear<BlendTransformedBilinear, QImage::Format_Invalid>, // RGB16 |
|
899 |
fetchTransformedBilinear<BlendTransformedBilinear, QImage::Format_Invalid>, // ARGB8565_Premultiplied |
|
900 |
fetchTransformedBilinear<BlendTransformedBilinear, QImage::Format_Invalid>, // RGB666 |
|
901 |
fetchTransformedBilinear<BlendTransformedBilinear, QImage::Format_Invalid>, // ARGB6666_Premultiplied |
|
902 |
fetchTransformedBilinear<BlendTransformedBilinear, QImage::Format_Invalid>, // RGB555 |
|
903 |
fetchTransformedBilinear<BlendTransformedBilinear, QImage::Format_Invalid>, // ARGB8555_Premultiplied |
|
904 |
fetchTransformedBilinear<BlendTransformedBilinear, QImage::Format_Invalid>, // RGB888 |
|
905 |
fetchTransformedBilinear<BlendTransformedBilinear, QImage::Format_Invalid>, // RGB444 |
|
906 |
fetchTransformedBilinear<BlendTransformedBilinear, QImage::Format_Invalid> // ARGB4444_Premultiplied |
|
907 |
}, |
|
908 |
{ |
|
909 |
0, // BilinearTiled |
|
910 |
fetchTransformedBilinear<BlendTransformedBilinearTiled, QImage::Format_Invalid>, // Mono |
|
911 |
fetchTransformedBilinear<BlendTransformedBilinearTiled, QImage::Format_Invalid>, // MonoLsb |
|
912 |
fetchTransformedBilinear<BlendTransformedBilinearTiled, QImage::Format_Invalid>, // Indexed8 |
|
913 |
fetchTransformedBilinear<BlendTransformedBilinearTiled, QImage::Format_ARGB32_Premultiplied>, // RGB32 |
|
914 |
fetchTransformedBilinear<BlendTransformedBilinearTiled, QImage::Format_ARGB32>, // ARGB32 |
|
915 |
fetchTransformedBilinear<BlendTransformedBilinearTiled, QImage::Format_ARGB32_Premultiplied>, // ARGB32_Premultiplied |
|
916 |
fetchTransformedBilinear<BlendTransformedBilinearTiled, QImage::Format_Invalid>, // RGB16 |
|
917 |
fetchTransformedBilinear<BlendTransformedBilinearTiled, QImage::Format_Invalid>, // ARGB8565_Premultiplied |
|
918 |
fetchTransformedBilinear<BlendTransformedBilinearTiled, QImage::Format_Invalid>, // RGB666 |
|
919 |
fetchTransformedBilinear<BlendTransformedBilinearTiled, QImage::Format_Invalid>, // ARGB6666_Premultiplied |
|
920 |
fetchTransformedBilinear<BlendTransformedBilinearTiled, QImage::Format_Invalid>, // RGB555 |
|
921 |
fetchTransformedBilinear<BlendTransformedBilinearTiled, QImage::Format_Invalid>, // ARGB8555_Premultiplied |
|
922 |
fetchTransformedBilinear<BlendTransformedBilinearTiled, QImage::Format_Invalid>, // RGB888 |
|
923 |
fetchTransformedBilinear<BlendTransformedBilinearTiled, QImage::Format_Invalid>, // RGB444 |
|
924 |
fetchTransformedBilinear<BlendTransformedBilinearTiled, QImage::Format_Invalid> // ARGB4444_Premultiplied |
|
925 |
}, |
|
926 |
}; |
|
927 |
||
928 |
||
929 |
static inline uint qt_gradient_pixel(const QGradientData *data, qreal pos) |
|
930 |
{ |
|
931 |
int ipos = int(pos * (GRADIENT_STOPTABLE_SIZE - 1) + 0.5); |
|
932 |
||
933 |
// calculate the actual offset. |
|
934 |
if (ipos < 0 || ipos >= GRADIENT_STOPTABLE_SIZE) { |
|
935 |
if (data->spread == QGradient::RepeatSpread) { |
|
936 |
ipos = ipos % GRADIENT_STOPTABLE_SIZE; |
|
937 |
ipos = ipos < 0 ? GRADIENT_STOPTABLE_SIZE + ipos : ipos; |
|
938 |
||
939 |
} else if (data->spread == QGradient::ReflectSpread) { |
|
940 |
const int limit = GRADIENT_STOPTABLE_SIZE * 2 - 1; |
|
941 |
ipos = ipos % limit; |
|
942 |
ipos = ipos < 0 ? limit + ipos : ipos; |
|
943 |
ipos = ipos >= GRADIENT_STOPTABLE_SIZE ? limit - ipos : ipos; |
|
944 |
||
945 |
} else { |
|
946 |
if (ipos < 0) ipos = 0; |
|
947 |
else if (ipos >= GRADIENT_STOPTABLE_SIZE) ipos = GRADIENT_STOPTABLE_SIZE-1; |
|
948 |
} |
|
949 |
} |
|
950 |
||
951 |
Q_ASSERT(ipos >= 0); |
|
952 |
Q_ASSERT(ipos < GRADIENT_STOPTABLE_SIZE); |
|
953 |
||
954 |
return data->colorTable[ipos]; |
|
955 |
} |
|
956 |
||
957 |
#define FIXPT_BITS 8 |
|
958 |
#define FIXPT_SIZE (1<<FIXPT_BITS) |
|
959 |
||
960 |
static uint qt_gradient_pixel_fixed(const QGradientData *data, int fixed_pos) |
|
961 |
{ |
|
962 |
int ipos = (fixed_pos + (FIXPT_SIZE / 2)) >> FIXPT_BITS; |
|
963 |
||
964 |
// calculate the actual offset. |
|
965 |
if (ipos < 0 || ipos >= GRADIENT_STOPTABLE_SIZE) { |
|
966 |
if (data->spread == QGradient::RepeatSpread) { |
|
967 |
ipos = ipos % GRADIENT_STOPTABLE_SIZE; |
|
968 |
ipos = ipos < 0 ? GRADIENT_STOPTABLE_SIZE + ipos : ipos; |
|
969 |
||
970 |
} else if (data->spread == QGradient::ReflectSpread) { |
|
971 |
const int limit = GRADIENT_STOPTABLE_SIZE * 2 - 1; |
|
972 |
ipos = ipos % limit; |
|
973 |
ipos = ipos < 0 ? limit + ipos : ipos; |
|
974 |
ipos = ipos >= GRADIENT_STOPTABLE_SIZE ? limit - ipos : ipos; |
|
975 |
||
976 |
} else { |
|
977 |
if (ipos < 0) ipos = 0; |
|
978 |
else if (ipos >= GRADIENT_STOPTABLE_SIZE) ipos = GRADIENT_STOPTABLE_SIZE-1; |
|
979 |
} |
|
980 |
} |
|
981 |
||
982 |
Q_ASSERT(ipos >= 0); |
|
983 |
Q_ASSERT(ipos < GRADIENT_STOPTABLE_SIZE); |
|
984 |
||
985 |
return data->colorTable[ipos]; |
|
986 |
} |
|
987 |
||
988 |
static void QT_FASTCALL getLinearGradientValues(LinearGradientValues *v, const QSpanData *data) |
|
989 |
{ |
|
990 |
v->dx = data->gradient.linear.end.x - data->gradient.linear.origin.x; |
|
991 |
v->dy = data->gradient.linear.end.y - data->gradient.linear.origin.y; |
|
992 |
v->l = v->dx * v->dx + v->dy * v->dy; |
|
993 |
v->off = 0; |
|
994 |
if (v->l != 0) { |
|
995 |
v->dx /= v->l; |
|
996 |
v->dy /= v->l; |
|
997 |
v->off = -v->dx * data->gradient.linear.origin.x - v->dy * data->gradient.linear.origin.y; |
|
998 |
} |
|
999 |
} |
|
1000 |
||
1001 |
static const uint * QT_FASTCALL fetchLinearGradient(uint *buffer, const Operator *op, const QSpanData *data, |
|
1002 |
int y, int x, int length) |
|
1003 |
{ |
|
1004 |
const uint *b = buffer; |
|
1005 |
qreal t, inc; |
|
1006 |
||
1007 |
bool affine = true; |
|
1008 |
qreal rx=0, ry=0; |
|
1009 |
if (op->linear.l == 0) { |
|
1010 |
t = inc = 0; |
|
1011 |
} else { |
|
1012 |
rx = data->m21 * (y + 0.5) + data->m11 * (x + 0.5) + data->dx; |
|
1013 |
ry = data->m22 * (y + 0.5) + data->m12 * (x + 0.5) + data->dy; |
|
1014 |
t = op->linear.dx*rx + op->linear.dy*ry + op->linear.off; |
|
1015 |
inc = op->linear.dx * data->m11 + op->linear.dy * data->m12; |
|
1016 |
affine = !data->m13 && !data->m23; |
|
1017 |
||
1018 |
if (affine) { |
|
1019 |
t *= (GRADIENT_STOPTABLE_SIZE - 1); |
|
1020 |
inc *= (GRADIENT_STOPTABLE_SIZE - 1); |
|
1021 |
} |
|
1022 |
} |
|
1023 |
||
1024 |
const uint *end = buffer + length; |
|
1025 |
if (affine) { |
|
1026 |
if (inc > -1e-5 && inc < 1e-5) { |
|
1027 |
QT_MEMFILL_UINT(buffer, length, qt_gradient_pixel_fixed(&data->gradient, int(t * FIXPT_SIZE))); |
|
1028 |
} else { |
|
1029 |
if (t+inc*length < qreal(INT_MAX >> (FIXPT_BITS + 1)) && |
|
1030 |
t+inc*length > qreal(INT_MIN >> (FIXPT_BITS + 1))) { |
|
1031 |
// we can use fixed point math |
|
1032 |
int t_fixed = int(t * FIXPT_SIZE); |
|
1033 |
int inc_fixed = int(inc * FIXPT_SIZE); |
|
1034 |
while (buffer < end) { |
|
1035 |
*buffer = qt_gradient_pixel_fixed(&data->gradient, t_fixed); |
|
1036 |
t_fixed += inc_fixed; |
|
1037 |
++buffer; |
|
1038 |
} |
|
1039 |
} else { |
|
1040 |
// we have to fall back to float math |
|
1041 |
while (buffer < end) { |
|
1042 |
*buffer = qt_gradient_pixel(&data->gradient, t/GRADIENT_STOPTABLE_SIZE); |
|
1043 |
t += inc; |
|
1044 |
++buffer; |
|
1045 |
} |
|
1046 |
} |
|
1047 |
} |
|
1048 |
} else { // fall back to float math here as well |
|
1049 |
qreal rw = data->m23 * (y + 0.5) + data->m13 * (x + 0.5) + data->m33; |
|
1050 |
while (buffer < end) { |
|
1051 |
qreal x = rx/rw; |
|
1052 |
qreal y = ry/rw; |
|
1053 |
t = (op->linear.dx*x + op->linear.dy *y) + op->linear.off; |
|
1054 |
||
1055 |
*buffer = qt_gradient_pixel(&data->gradient, t); |
|
1056 |
rx += data->m11; |
|
1057 |
ry += data->m12; |
|
1058 |
rw += data->m13; |
|
1059 |
if (!rw) { |
|
1060 |
rw += data->m13; |
|
1061 |
} |
|
1062 |
++buffer; |
|
1063 |
} |
|
1064 |
} |
|
1065 |
||
1066 |
return b; |
|
1067 |
} |
|
1068 |
||
1069 |
static inline qreal determinant(qreal a, qreal b, qreal c) |
|
1070 |
{ |
|
1071 |
return (b * b) - (4 * a * c); |
|
1072 |
} |
|
1073 |
||
1074 |
// function to evaluate real roots |
|
1075 |
static inline qreal realRoots(qreal a, qreal b, qreal detSqrt) |
|
1076 |
{ |
|
1077 |
return (-b + detSqrt)/(2 * a); |
|
1078 |
} |
|
1079 |
||
1080 |
static inline qreal qSafeSqrt(qreal x) |
|
1081 |
{ |
|
1082 |
return x > 0 ? qSqrt(x) : 0; |
|
1083 |
} |
|
1084 |
||
1085 |
static void QT_FASTCALL getRadialGradientValues(RadialGradientValues *v, const QSpanData *data) |
|
1086 |
{ |
|
1087 |
v->dx = data->gradient.radial.center.x - data->gradient.radial.focal.x; |
|
1088 |
v->dy = data->gradient.radial.center.y - data->gradient.radial.focal.y; |
|
1089 |
v->a = data->gradient.radial.radius*data->gradient.radial.radius - v->dx*v->dx - v->dy*v->dy; |
|
1090 |
} |
|
1091 |
||
1092 |
static const uint * QT_FASTCALL fetchRadialGradient(uint *buffer, const Operator *op, const QSpanData *data, |
|
1093 |
int y, int x, int length) |
|
1094 |
{ |
|
1095 |
const uint *b = buffer; |
|
1096 |
qreal rx = data->m21 * (y + 0.5) |
|
1097 |
+ data->dx + data->m11 * (x + 0.5); |
|
1098 |
qreal ry = data->m22 * (y + 0.5) |
|
1099 |
+ data->dy + data->m12 * (x + 0.5); |
|
1100 |
bool affine = !data->m13 && !data->m23; |
|
1101 |
//qreal r = data->gradient.radial.radius; |
|
1102 |
||
1103 |
const uint *end = buffer + length; |
|
1104 |
if (affine) { |
|
1105 |
rx -= data->gradient.radial.focal.x; |
|
1106 |
ry -= data->gradient.radial.focal.y; |
|
1107 |
||
1108 |
qreal inv_a = 1 / qreal(2 * op->radial.a); |
|
1109 |
||
1110 |
const qreal delta_rx = data->m11; |
|
1111 |
const qreal delta_ry = data->m12; |
|
1112 |
||
1113 |
qreal b = 2*(rx * op->radial.dx + ry * op->radial.dy); |
|
1114 |
qreal delta_b = 2*(delta_rx * op->radial.dx + delta_ry * op->radial.dy); |
|
1115 |
const qreal b_delta_b = 2 * b * delta_b; |
|
1116 |
const qreal delta_b_delta_b = 2 * delta_b * delta_b; |
|
1117 |
||
1118 |
const qreal bb = b * b; |
|
1119 |
const qreal delta_bb = delta_b * delta_b; |
|
1120 |
||
1121 |
b *= inv_a; |
|
1122 |
delta_b *= inv_a; |
|
1123 |
||
1124 |
const qreal rxrxryry = rx * rx + ry * ry; |
|
1125 |
const qreal delta_rxrxryry = delta_rx * delta_rx + delta_ry * delta_ry; |
|
1126 |
const qreal rx_plus_ry = 2*(rx * delta_rx + ry * delta_ry); |
|
1127 |
const qreal delta_rx_plus_ry = 2 * delta_rxrxryry; |
|
1128 |
||
1129 |
inv_a *= inv_a; |
|
1130 |
||
1131 |
qreal det = (bb + 4 * op->radial.a * rxrxryry) * inv_a; |
|
1132 |
qreal delta_det = (b_delta_b + delta_bb + 4 * op->radial.a * (rx_plus_ry + delta_rxrxryry)) * inv_a; |
|
1133 |
const qreal delta_delta_det = (delta_b_delta_b + 4 * op->radial.a * delta_rx_plus_ry) * inv_a; |
|
1134 |
||
1135 |
while (buffer < end) { |
|
1136 |
*buffer = qt_gradient_pixel(&data->gradient, qSafeSqrt(det) - b); |
|
1137 |
||
1138 |
det += delta_det; |
|
1139 |
delta_det += delta_delta_det; |
|
1140 |
b += delta_b; |
|
1141 |
||
1142 |
++buffer; |
|
1143 |
} |
|
1144 |
} else { |
|
1145 |
qreal rw = data->m23 * (y + 0.5) |
|
1146 |
+ data->m33 + data->m13 * (x + 0.5); |
|
1147 |
if (!rw) |
|
1148 |
rw = 1; |
|
1149 |
while (buffer < end) { |
|
1150 |
qreal gx = rx/rw - data->gradient.radial.focal.x; |
|
1151 |
qreal gy = ry/rw - data->gradient.radial.focal.y; |
|
1152 |
qreal b = 2*(gx*op->radial.dx + gy*op->radial.dy); |
|
1153 |
qreal det = determinant(op->radial.a, b , -(gx*gx + gy*gy)); |
|
1154 |
qreal s = realRoots(op->radial.a, b, qSafeSqrt(det)); |
|
1155 |
||
1156 |
*buffer = qt_gradient_pixel(&data->gradient, s); |
|
1157 |
||
1158 |
rx += data->m11; |
|
1159 |
ry += data->m12; |
|
1160 |
rw += data->m13; |
|
1161 |
if (!rw) { |
|
1162 |
rw += data->m13; |
|
1163 |
} |
|
1164 |
++buffer; |
|
1165 |
} |
|
1166 |
} |
|
1167 |
||
1168 |
return b; |
|
1169 |
} |
|
1170 |
||
1171 |
static const uint * QT_FASTCALL fetchConicalGradient(uint *buffer, const Operator *, const QSpanData *data, |
|
1172 |
int y, int x, int length) |
|
1173 |
{ |
|
1174 |
const uint *b = buffer; |
|
1175 |
qreal rx = data->m21 * (y + 0.5) |
|
1176 |
+ data->dx + data->m11 * (x + 0.5); |
|
1177 |
qreal ry = data->m22 * (y + 0.5) |
|
1178 |
+ data->dy + data->m12 * (x + 0.5); |
|
1179 |
bool affine = !data->m13 && !data->m23; |
|
1180 |
||
1181 |
const uint *end = buffer + length; |
|
1182 |
if (affine) { |
|
1183 |
rx -= data->gradient.conical.center.x; |
|
1184 |
ry -= data->gradient.conical.center.y; |
|
1185 |
while (buffer < end) { |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1186 |
qreal angle = qAtan2(ry, rx) + data->gradient.conical.angle; |
0 | 1187 |
|
1188 |
*buffer = qt_gradient_pixel(&data->gradient, 1 - angle / (2*Q_PI)); |
|
1189 |
||
1190 |
rx += data->m11; |
|
1191 |
ry += data->m12; |
|
1192 |
++buffer; |
|
1193 |
} |
|
1194 |
} else { |
|
1195 |
qreal rw = data->m23 * (y + 0.5) |
|
1196 |
+ data->m33 + data->m13 * (x + 0.5); |
|
1197 |
if (!rw) |
|
1198 |
rw = 1; |
|
1199 |
while (buffer < end) { |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1200 |
qreal angle = qAtan2(ry/rw - data->gradient.conical.center.x, |
0 | 1201 |
rx/rw - data->gradient.conical.center.y) |
1202 |
+ data->gradient.conical.angle; |
|
1203 |
||
1204 |
*buffer = qt_gradient_pixel(&data->gradient, 1. - angle / (2*Q_PI)); |
|
1205 |
||
1206 |
rx += data->m11; |
|
1207 |
ry += data->m12; |
|
1208 |
rw += data->m13; |
|
1209 |
if (!rw) { |
|
1210 |
rw += data->m13; |
|
1211 |
} |
|
1212 |
++buffer; |
|
1213 |
} |
|
1214 |
} |
|
1215 |
return b; |
|
1216 |
} |
|
1217 |
||
1218 |
#if defined(Q_CC_RVCT) |
|
1219 |
// Force ARM code generation for comp_func_* -methods |
|
1220 |
# pragma push |
|
1221 |
# pragma arm |
|
1222 |
# if defined(QT_HAVE_ARMV6) |
|
1223 |
static __forceinline void preload(const uint *start) |
|
1224 |
{ |
|
1225 |
asm( "pld [start]" ); |
|
1226 |
} |
|
1227 |
static const uint L2CacheLineLength = 32; |
|
1228 |
static const uint L2CacheLineLengthInInts = L2CacheLineLength/sizeof(uint); |
|
1229 |
# define PRELOAD_INIT(x) preload(x); |
|
1230 |
# define PRELOAD_INIT2(x,y) PRELOAD_INIT(x) PRELOAD_INIT(y) |
|
1231 |
# define PRELOAD_COND(x) if (((uint)&x[i])%L2CacheLineLength == 0) preload(&x[i] + L2CacheLineLengthInInts); |
|
1232 |
// Two consecutive preloads stall, so space them out a bit by using different modulus. |
|
1233 |
# define PRELOAD_COND2(x,y) if (((uint)&x[i])%L2CacheLineLength == 0) preload(&x[i] + L2CacheLineLengthInInts); \ |
|
1234 |
if (((uint)&y[i])%L2CacheLineLength == 16) preload(&y[i] + L2CacheLineLengthInInts); |
|
1235 |
# endif // QT_HAVE_ARMV6 |
|
1236 |
#endif // Q_CC_RVCT |
|
1237 |
||
1238 |
#if !defined(Q_CC_RVCT) || !defined(QT_HAVE_ARMV6) |
|
1239 |
# define PRELOAD_INIT(x) |
|
1240 |
# define PRELOAD_INIT2(x,y) |
|
1241 |
# define PRELOAD_COND(x) |
|
1242 |
# define PRELOAD_COND2(x,y) |
|
1243 |
#endif |
|
1244 |
||
1245 |
/* The constant alpha factor describes an alpha factor that gets applied |
|
1246 |
to the result of the composition operation combining it with the destination. |
|
1247 |
||
1248 |
The intent is that if const_alpha == 0. we get back dest, and if const_alpha == 1. |
|
1249 |
we get the unmodified operation |
|
1250 |
||
1251 |
result = src op dest |
|
1252 |
dest = result * const_alpha + dest * (1. - const_alpha) |
|
1253 |
||
1254 |
This means that in the comments below, the first line is the const_alpha==255 case, the |
|
1255 |
second line the general one. |
|
1256 |
||
1257 |
In the lines below: |
|
1258 |
s == src, sa == alpha(src), sia = 1 - alpha(src) |
|
1259 |
d == dest, da == alpha(dest), dia = 1 - alpha(dest) |
|
1260 |
ca = const_alpha, cia = 1 - const_alpha |
|
1261 |
||
1262 |
The methods exist in two variants. One where we have a constant source, the other |
|
1263 |
where the source is an array of pixels. |
|
1264 |
*/ |
|
1265 |
||
1266 |
/* |
|
1267 |
result = 0 |
|
1268 |
d = d * cia |
|
1269 |
*/ |
|
7
f7bc934e204c
5cabc75a39ca2f064f70b40f72ed93c74c4dc19b
eckhart.koppen@nokia.com
parents:
3
diff
changeset
|
1270 |
#define comp_func_Clear_impl(dest, length, const_alpha)\ |
f7bc934e204c
5cabc75a39ca2f064f70b40f72ed93c74c4dc19b
eckhart.koppen@nokia.com
parents:
3
diff
changeset
|
1271 |
{\ |
f7bc934e204c
5cabc75a39ca2f064f70b40f72ed93c74c4dc19b
eckhart.koppen@nokia.com
parents:
3
diff
changeset
|
1272 |
if (const_alpha == 255) {\ |
f7bc934e204c
5cabc75a39ca2f064f70b40f72ed93c74c4dc19b
eckhart.koppen@nokia.com
parents:
3
diff
changeset
|
1273 |
QT_MEMFILL_UINT(dest, length, 0);\ |
f7bc934e204c
5cabc75a39ca2f064f70b40f72ed93c74c4dc19b
eckhart.koppen@nokia.com
parents:
3
diff
changeset
|
1274 |
} else {\ |
f7bc934e204c
5cabc75a39ca2f064f70b40f72ed93c74c4dc19b
eckhart.koppen@nokia.com
parents:
3
diff
changeset
|
1275 |
int ialpha = 255 - const_alpha;\ |
f7bc934e204c
5cabc75a39ca2f064f70b40f72ed93c74c4dc19b
eckhart.koppen@nokia.com
parents:
3
diff
changeset
|
1276 |
PRELOAD_INIT(dest)\ |
f7bc934e204c
5cabc75a39ca2f064f70b40f72ed93c74c4dc19b
eckhart.koppen@nokia.com
parents:
3
diff
changeset
|
1277 |
for (int i = 0; i < length; ++i) {\ |
f7bc934e204c
5cabc75a39ca2f064f70b40f72ed93c74c4dc19b
eckhart.koppen@nokia.com
parents:
3
diff
changeset
|
1278 |
PRELOAD_COND(dest)\ |
f7bc934e204c
5cabc75a39ca2f064f70b40f72ed93c74c4dc19b
eckhart.koppen@nokia.com
parents:
3
diff
changeset
|
1279 |
dest[i] = BYTE_MUL(dest[i], ialpha);\ |
f7bc934e204c
5cabc75a39ca2f064f70b40f72ed93c74c4dc19b
eckhart.koppen@nokia.com
parents:
3
diff
changeset
|
1280 |
}\ |
f7bc934e204c
5cabc75a39ca2f064f70b40f72ed93c74c4dc19b
eckhart.koppen@nokia.com
parents:
3
diff
changeset
|
1281 |
}\ |
f7bc934e204c
5cabc75a39ca2f064f70b40f72ed93c74c4dc19b
eckhart.koppen@nokia.com
parents:
3
diff
changeset
|
1282 |
} |
f7bc934e204c
5cabc75a39ca2f064f70b40f72ed93c74c4dc19b
eckhart.koppen@nokia.com
parents:
3
diff
changeset
|
1283 |
|
0 | 1284 |
static void QT_FASTCALL comp_func_solid_Clear(uint *dest, int length, uint, uint const_alpha) |
1285 |
{ |
|
7
f7bc934e204c
5cabc75a39ca2f064f70b40f72ed93c74c4dc19b
eckhart.koppen@nokia.com
parents:
3
diff
changeset
|
1286 |
comp_func_Clear_impl(dest, length, const_alpha); |
0 | 1287 |
} |
1288 |
||
1289 |
static void QT_FASTCALL comp_func_Clear(uint *dest, const uint *, int length, uint const_alpha) |
|
1290 |
{ |
|
7
f7bc934e204c
5cabc75a39ca2f064f70b40f72ed93c74c4dc19b
eckhart.koppen@nokia.com
parents:
3
diff
changeset
|
1291 |
comp_func_Clear_impl(dest, length, const_alpha); |
0 | 1292 |
} |
1293 |
||
1294 |
/* |
|
1295 |
result = s |
|
1296 |
dest = s * ca + d * cia |
|
1297 |
*/ |
|
1298 |
static void QT_FASTCALL comp_func_solid_Source(uint *dest, int length, uint color, uint const_alpha) |
|
1299 |
{ |
|
1300 |
if (const_alpha == 255) { |
|
1301 |
QT_MEMFILL_UINT(dest, length, color); |
|
1302 |
} else { |
|
1303 |
int ialpha = 255 - const_alpha; |
|
1304 |
color = BYTE_MUL(color, const_alpha); |
|
1305 |
PRELOAD_INIT(dest) |
|
1306 |
for (int i = 0; i < length; ++i) { |
|
1307 |
PRELOAD_COND(dest) |
|
1308 |
dest[i] = color + BYTE_MUL(dest[i], ialpha); |
|
1309 |
} |
|
1310 |
} |
|
1311 |
} |
|
1312 |
||
1313 |
static void QT_FASTCALL comp_func_Source(uint *dest, const uint *src, int length, uint const_alpha) |
|
1314 |
{ |
|
1315 |
if (const_alpha == 255) { |
|
1316 |
::memcpy(dest, src, length * sizeof(uint)); |
|
1317 |
} else { |
|
1318 |
int ialpha = 255 - const_alpha; |
|
1319 |
PRELOAD_INIT2(dest, src) |
|
1320 |
for (int i = 0; i < length; ++i) { |
|
1321 |
PRELOAD_COND2(dest, src) |
|
1322 |
dest[i] = INTERPOLATE_PIXEL_255(src[i], const_alpha, dest[i], ialpha); |
|
1323 |
} |
|
1324 |
} |
|
1325 |
} |
|
1326 |
||
1327 |
static void QT_FASTCALL comp_func_solid_Destination(uint *, int, uint, uint) |
|
1328 |
{ |
|
1329 |
} |
|
1330 |
||
1331 |
static void QT_FASTCALL comp_func_Destination(uint *, const uint *, int, uint) |
|
1332 |
{ |
|
1333 |
} |
|
1334 |
||
1335 |
/* |
|
1336 |
result = s + d * sia |
|
1337 |
dest = (s + d * sia) * ca + d * cia |
|
1338 |
= s * ca + d * (sia * ca + cia) |
|
1339 |
= s * ca + d * (1 - sa*ca) |
|
1340 |
*/ |
|
1341 |
static void QT_FASTCALL comp_func_solid_SourceOver(uint *dest, int length, uint color, uint const_alpha) |
|
1342 |
{ |
|
1343 |
if ((const_alpha & qAlpha(color)) == 255) { |
|
1344 |
QT_MEMFILL_UINT(dest, length, color); |
|
1345 |
} else { |
|
1346 |
if (const_alpha != 255) |
|
1347 |
color = BYTE_MUL(color, const_alpha); |
|
1348 |
PRELOAD_INIT(dest) |
|
1349 |
for (int i = 0; i < length; ++i) { |
|
1350 |
PRELOAD_COND(dest) |
|
1351 |
dest[i] = color + BYTE_MUL(dest[i], qAlpha(~color)); |
|
1352 |
} |
|
1353 |
} |
|
1354 |
} |
|
1355 |
||
1356 |
static void QT_FASTCALL comp_func_SourceOver(uint *dest, const uint *src, int length, uint const_alpha) |
|
1357 |
{ |
|
1358 |
PRELOAD_INIT2(dest, src) |
|
1359 |
if (const_alpha == 255) { |
|
1360 |
for (int i = 0; i < length; ++i) { |
|
1361 |
PRELOAD_COND2(dest, src) |
|
1362 |
uint s = src[i]; |
|
7
f7bc934e204c
5cabc75a39ca2f064f70b40f72ed93c74c4dc19b
eckhart.koppen@nokia.com
parents:
3
diff
changeset
|
1363 |
if (s >= 0xff000000) |
f7bc934e204c
5cabc75a39ca2f064f70b40f72ed93c74c4dc19b
eckhart.koppen@nokia.com
parents:
3
diff
changeset
|
1364 |
dest[i] = s; |
f7bc934e204c
5cabc75a39ca2f064f70b40f72ed93c74c4dc19b
eckhart.koppen@nokia.com
parents:
3
diff
changeset
|
1365 |
else if (s != 0) |
f7bc934e204c
5cabc75a39ca2f064f70b40f72ed93c74c4dc19b
eckhart.koppen@nokia.com
parents:
3
diff
changeset
|
1366 |
dest[i] = s + BYTE_MUL(dest[i], qAlpha(~s)); |
0 | 1367 |
} |
1368 |
} else { |
|
1369 |
for (int i = 0; i < length; ++i) { |
|
1370 |
PRELOAD_COND2(dest, src) |
|
1371 |
uint s = BYTE_MUL(src[i], const_alpha); |
|
1372 |
dest[i] = s + BYTE_MUL(dest[i], qAlpha(~s)); |
|
1373 |
} |
|
1374 |
} |
|
1375 |
} |
|
1376 |
||
1377 |
/* |
|
1378 |
result = d + s * dia |
|
1379 |
dest = (d + s * dia) * ca + d * cia |
|
1380 |
= d + s * dia * ca |
|
1381 |
*/ |
|
1382 |
static void QT_FASTCALL comp_func_solid_DestinationOver(uint *dest, int length, uint color, uint const_alpha) |
|
1383 |
{ |
|
1384 |
if (const_alpha != 255) |
|
1385 |
color = BYTE_MUL(color, const_alpha); |
|
1386 |
PRELOAD_INIT(dest) |
|
1387 |
for (int i = 0; i < length; ++i) { |
|
1388 |
PRELOAD_COND(dest) |
|
1389 |
uint d = dest[i]; |
|
1390 |
dest[i] = d + BYTE_MUL(color, qAlpha(~d)); |
|
1391 |
} |
|
1392 |
} |
|
1393 |
||
1394 |
static void QT_FASTCALL comp_func_DestinationOver(uint *dest, const uint *src, int length, uint const_alpha) |
|
1395 |
{ |
|
1396 |
PRELOAD_INIT2(dest, src) |
|
1397 |
if (const_alpha == 255) { |
|
1398 |
for (int i = 0; i < length; ++i) { |
|
1399 |
PRELOAD_COND2(dest, src) |
|
1400 |
uint d = dest[i]; |
|
1401 |
dest[i] = d + BYTE_MUL(src[i], qAlpha(~d)); |
|
1402 |
} |
|
1403 |
} else { |
|
1404 |
for (int i = 0; i < length; ++i) { |
|
1405 |
PRELOAD_COND2(dest, src) |
|
1406 |
uint d = dest[i]; |
|
1407 |
uint s = BYTE_MUL(src[i], const_alpha); |
|
1408 |
dest[i] = d + BYTE_MUL(s, qAlpha(~d)); |
|
1409 |
} |
|
1410 |
} |
|
1411 |
} |
|
1412 |
||
1413 |
/* |
|
1414 |
result = s * da |
|
1415 |
dest = s * da * ca + d * cia |
|
1416 |
*/ |
|
1417 |
static void QT_FASTCALL comp_func_solid_SourceIn(uint *dest, int length, uint color, uint const_alpha) |
|
1418 |
{ |
|
1419 |
PRELOAD_INIT(dest) |
|
1420 |
if (const_alpha == 255) { |
|
1421 |
for (int i = 0; i < length; ++i) { |
|
1422 |
PRELOAD_COND(dest) |
|
1423 |
dest[i] = BYTE_MUL(color, qAlpha(dest[i])); |
|
1424 |
} |
|
1425 |
} else { |
|
1426 |
color = BYTE_MUL(color, const_alpha); |
|
1427 |
uint cia = 255 - const_alpha; |
|
1428 |
for (int i = 0; i < length; ++i) { |
|
1429 |
PRELOAD_COND(dest) |
|
1430 |
uint d = dest[i]; |
|
1431 |
dest[i] = INTERPOLATE_PIXEL_255(color, qAlpha(d), d, cia); |
|
1432 |
} |
|
1433 |
} |
|
1434 |
} |
|
1435 |
||
1436 |
static void QT_FASTCALL comp_func_SourceIn(uint *dest, const uint *src, int length, uint const_alpha) |
|
1437 |
{ |
|
1438 |
PRELOAD_INIT2(dest, src) |
|
1439 |
if (const_alpha == 255) { |
|
1440 |
for (int i = 0; i < length; ++i) { |
|
1441 |
PRELOAD_COND2(dest, src) |
|
1442 |
dest[i] = BYTE_MUL(src[i], qAlpha(dest[i])); |
|
1443 |
} |
|
1444 |
} else { |
|
1445 |
uint cia = 255 - const_alpha; |
|
1446 |
for (int i = 0; i < length; ++i) { |
|
1447 |
PRELOAD_COND2(dest, src) |
|
1448 |
uint d = dest[i]; |
|
1449 |
uint s = BYTE_MUL(src[i], const_alpha); |
|
1450 |
dest[i] = INTERPOLATE_PIXEL_255(s, qAlpha(d), d, cia); |
|
1451 |
} |
|
1452 |
} |
|
1453 |
} |
|
1454 |
||
1455 |
/* |
|
1456 |
result = d * sa |
|
1457 |
dest = d * sa * ca + d * cia |
|
1458 |
= d * (sa * ca + cia) |
|
1459 |
*/ |
|
1460 |
static void QT_FASTCALL comp_func_solid_DestinationIn(uint *dest, int length, uint color, uint const_alpha) |
|
1461 |
{ |
|
1462 |
uint a = qAlpha(color); |
|
1463 |
if (const_alpha != 255) { |
|
1464 |
a = BYTE_MUL(a, const_alpha) + 255 - const_alpha; |
|
1465 |
} |
|
1466 |
PRELOAD_INIT(dest) |
|
1467 |
for (int i = 0; i < length; ++i) { |
|
1468 |
PRELOAD_COND(dest) |
|
1469 |
dest[i] = BYTE_MUL(dest[i], a); |
|
1470 |
} |
|
1471 |
} |
|
1472 |
||
1473 |
static void QT_FASTCALL comp_func_DestinationIn(uint *dest, const uint *src, int length, uint const_alpha) |
|
1474 |
{ |
|
1475 |
PRELOAD_INIT2(dest, src) |
|
1476 |
if (const_alpha == 255) { |
|
1477 |
for (int i = 0; i < length; ++i) { |
|
1478 |
PRELOAD_COND2(dest, src) |
|
1479 |
dest[i] = BYTE_MUL(dest[i], qAlpha(src[i])); |
|
1480 |
} |
|
1481 |
} else { |
|
1482 |
int cia = 255 - const_alpha; |
|
1483 |
for (int i = 0; i < length; ++i) { |
|
1484 |
PRELOAD_COND2(dest, src) |
|
1485 |
uint a = BYTE_MUL(qAlpha(src[i]), const_alpha) + cia; |
|
1486 |
dest[i] = BYTE_MUL(dest[i], a); |
|
1487 |
} |
|
1488 |
} |
|
1489 |
} |
|
1490 |
||
1491 |
/* |
|
1492 |
result = s * dia |
|
1493 |
dest = s * dia * ca + d * cia |
|
1494 |
*/ |
|
1495 |
||
1496 |
static void QT_FASTCALL comp_func_solid_SourceOut(uint *dest, int length, uint color, uint const_alpha) |
|
1497 |
{ |
|
1498 |
PRELOAD_INIT(dest) |
|
1499 |
if (const_alpha == 255) { |
|
1500 |
for (int i = 0; i < length; ++i) { |
|
1501 |
PRELOAD_COND(dest) |
|
1502 |
dest[i] = BYTE_MUL(color, qAlpha(~dest[i])); |
|
1503 |
} |
|
1504 |
} else { |
|
1505 |
color = BYTE_MUL(color, const_alpha); |
|
1506 |
int cia = 255 - const_alpha; |
|
1507 |
for (int i = 0; i < length; ++i) { |
|
1508 |
PRELOAD_COND(dest) |
|
1509 |
uint d = dest[i]; |
|
1510 |
dest[i] = INTERPOLATE_PIXEL_255(color, qAlpha(~d), d, cia); |
|
1511 |
} |
|
1512 |
} |
|
1513 |
} |
|
1514 |
||
1515 |
static void QT_FASTCALL comp_func_SourceOut(uint *dest, const uint *src, int length, uint const_alpha) |
|
1516 |
{ |
|
1517 |
PRELOAD_INIT2(dest, src) |
|
1518 |
if (const_alpha == 255) { |
|
1519 |
for (int i = 0; i < length; ++i) { |
|
1520 |
PRELOAD_COND2(dest, src) |
|
1521 |
dest[i] = BYTE_MUL(src[i], qAlpha(~dest[i])); |
|
1522 |
} |
|
1523 |
} else { |
|
1524 |
int cia = 255 - const_alpha; |
|
1525 |
for (int i = 0; i < length; ++i) { |
|
1526 |
PRELOAD_COND2(dest, src) |
|
1527 |
uint s = BYTE_MUL(src[i], const_alpha); |
|
1528 |
uint d = dest[i]; |
|
1529 |
dest[i] = INTERPOLATE_PIXEL_255(s, qAlpha(~d), d, cia); |
|
1530 |
} |
|
1531 |
} |
|
1532 |
} |
|
1533 |
||
1534 |
/* |
|
1535 |
result = d * sia |
|
1536 |
dest = d * sia * ca + d * cia |
|
1537 |
= d * (sia * ca + cia) |
|
1538 |
*/ |
|
1539 |
static void QT_FASTCALL comp_func_solid_DestinationOut(uint *dest, int length, uint color, uint const_alpha) |
|
1540 |
{ |
|
1541 |
uint a = qAlpha(~color); |
|
1542 |
if (const_alpha != 255) |
|
1543 |
a = BYTE_MUL(a, const_alpha) + 255 - const_alpha; |
|
1544 |
PRELOAD_INIT(dest) |
|
1545 |
for (int i = 0; i < length; ++i) { |
|
1546 |
PRELOAD_COND(dest) |
|
1547 |
dest[i] = BYTE_MUL(dest[i], a); |
|
1548 |
} |
|
1549 |
} |
|
1550 |
||
1551 |
static void QT_FASTCALL comp_func_DestinationOut(uint *dest, const uint *src, int length, uint const_alpha) |
|
1552 |
{ |
|
1553 |
PRELOAD_INIT2(dest, src) |
|
1554 |
if (const_alpha == 255) { |
|
1555 |
for (int i = 0; i < length; ++i) { |
|
1556 |
PRELOAD_COND2(dest, src) |
|
1557 |
dest[i] = BYTE_MUL(dest[i], qAlpha(~src[i])); |
|
1558 |
} |
|
1559 |
} else { |
|
1560 |
int cia = 255 - const_alpha; |
|
1561 |
for (int i = 0; i < length; ++i) { |
|
1562 |
PRELOAD_COND2(dest, src) |
|
1563 |
uint sia = BYTE_MUL(qAlpha(~src[i]), const_alpha) + cia; |
|
1564 |
dest[i] = BYTE_MUL(dest[i], sia); |
|
1565 |
} |
|
1566 |
} |
|
1567 |
} |
|
1568 |
||
1569 |
/* |
|
1570 |
result = s*da + d*sia |
|
1571 |
dest = s*da*ca + d*sia*ca + d *cia |
|
1572 |
= s*ca * da + d * (sia*ca + cia) |
|
1573 |
= s*ca * da + d * (1 - sa*ca) |
|
1574 |
*/ |
|
1575 |
static void QT_FASTCALL comp_func_solid_SourceAtop(uint *dest, int length, uint color, uint const_alpha) |
|
1576 |
{ |
|
1577 |
if (const_alpha != 255) { |
|
1578 |
color = BYTE_MUL(color, const_alpha); |
|
1579 |
} |
|
1580 |
uint sia = qAlpha(~color); |
|
1581 |
PRELOAD_INIT(dest) |
|
1582 |
for (int i = 0; i < length; ++i) { |
|
1583 |
PRELOAD_COND(dest) |
|
1584 |
dest[i] = INTERPOLATE_PIXEL_255(color, qAlpha(dest[i]), dest[i], sia); |
|
1585 |
} |
|
1586 |
} |
|
1587 |
||
1588 |
static void QT_FASTCALL comp_func_SourceAtop(uint *dest, const uint *src, int length, uint const_alpha) |
|
1589 |
{ |
|
1590 |
PRELOAD_INIT2(dest, src) |
|
1591 |
if (const_alpha == 255) { |
|
1592 |
for (int i = 0; i < length; ++i) { |
|
1593 |
PRELOAD_COND2(dest, src) |
|
1594 |
uint s = src[i]; |
|
1595 |
uint d = dest[i]; |
|
1596 |
dest[i] = INTERPOLATE_PIXEL_255(s, qAlpha(d), d, qAlpha(~s)); |
|
1597 |
} |
|
1598 |
} else { |
|
1599 |
for (int i = 0; i < length; ++i) { |
|
1600 |
PRELOAD_COND2(dest, src) |
|
1601 |
uint s = BYTE_MUL(src[i], const_alpha); |
|
1602 |
uint d = dest[i]; |
|
1603 |
dest[i] = INTERPOLATE_PIXEL_255(s, qAlpha(d), d, qAlpha(~s)); |
|
1604 |
} |
|
1605 |
} |
|
1606 |
} |
|
1607 |
||
1608 |
/* |
|
1609 |
result = d*sa + s*dia |
|
1610 |
dest = d*sa*ca + s*dia*ca + d *cia |
|
1611 |
= s*ca * dia + d * (sa*ca + cia) |
|
1612 |
*/ |
|
1613 |
static void QT_FASTCALL comp_func_solid_DestinationAtop(uint *dest, int length, uint color, uint const_alpha) |
|
1614 |
{ |
|
1615 |
uint a = qAlpha(color); |
|
1616 |
if (const_alpha != 255) { |
|
1617 |
color = BYTE_MUL(color, const_alpha); |
|
1618 |
a = qAlpha(color) + 255 - const_alpha; |
|
1619 |
} |
|
1620 |
PRELOAD_INIT(dest) |
|
1621 |
for (int i = 0; i < length; ++i) { |
|
1622 |
PRELOAD_COND(dest) |
|
1623 |
uint d = dest[i]; |
|
1624 |
dest[i] = INTERPOLATE_PIXEL_255(d, a, color, qAlpha(~d)); |
|
1625 |
} |
|
1626 |
} |
|
1627 |
||
1628 |
static void QT_FASTCALL comp_func_DestinationAtop(uint *dest, const uint *src, int length, uint const_alpha) |
|
1629 |
{ |
|
1630 |
PRELOAD_INIT2(dest, src) |
|
1631 |
if (const_alpha == 255) { |
|
1632 |
for (int i = 0; i < length; ++i) { |
|
1633 |
PRELOAD_COND2(dest, src) |
|
1634 |
uint s = src[i]; |
|
1635 |
uint d = dest[i]; |
|
1636 |
dest[i] = INTERPOLATE_PIXEL_255(d, qAlpha(s), s, qAlpha(~d)); |
|
1637 |
} |
|
1638 |
} else { |
|
1639 |
int cia = 255 - const_alpha; |
|
1640 |
for (int i = 0; i < length; ++i) { |
|
1641 |
PRELOAD_COND2(dest, src) |
|
1642 |
uint s = BYTE_MUL(src[i], const_alpha); |
|
1643 |
uint d = dest[i]; |
|
1644 |
uint a = qAlpha(s) + cia; |
|
1645 |
dest[i] = INTERPOLATE_PIXEL_255(d, a, s, qAlpha(~d)); |
|
1646 |
} |
|
1647 |
} |
|
1648 |
} |
|
1649 |
||
1650 |
/* |
|
1651 |
result = d*sia + s*dia |
|
1652 |
dest = d*sia*ca + s*dia*ca + d *cia |
|
1653 |
= s*ca * dia + d * (sia*ca + cia) |
|
1654 |
= s*ca * dia + d * (1 - sa*ca) |
|
1655 |
*/ |
|
1656 |
static void QT_FASTCALL comp_func_solid_XOR(uint *dest, int length, uint color, uint const_alpha) |
|
1657 |
{ |
|
1658 |
if (const_alpha != 255) |
|
1659 |
color = BYTE_MUL(color, const_alpha); |
|
1660 |
uint sia = qAlpha(~color); |
|
1661 |
||
1662 |
PRELOAD_INIT(dest) |
|
1663 |
for (int i = 0; i < length; ++i) { |
|
1664 |
PRELOAD_COND(dest) |
|
1665 |
uint d = dest[i]; |
|
1666 |
dest[i] = INTERPOLATE_PIXEL_255(color, qAlpha(~d), d, sia); |
|
1667 |
} |
|
1668 |
} |
|
1669 |
||
1670 |
static void QT_FASTCALL comp_func_XOR(uint *dest, const uint *src, int length, uint const_alpha) |
|
1671 |
{ |
|
1672 |
PRELOAD_INIT2(dest, src) |
|
1673 |
if (const_alpha == 255) { |
|
1674 |
for (int i = 0; i < length; ++i) { |
|
1675 |
PRELOAD_COND2(dest, src) |
|
1676 |
uint d = dest[i]; |
|
1677 |
uint s = src[i]; |
|
1678 |
dest[i] = INTERPOLATE_PIXEL_255(s, qAlpha(~d), d, qAlpha(~s)); |
|
1679 |
} |
|
1680 |
} else { |
|
1681 |
for (int i = 0; i < length; ++i) { |
|
1682 |
PRELOAD_COND2(dest, src) |
|
1683 |
uint d = dest[i]; |
|
1684 |
uint s = BYTE_MUL(src[i], const_alpha); |
|
1685 |
dest[i] = INTERPOLATE_PIXEL_255(s, qAlpha(~d), d, qAlpha(~s)); |
|
1686 |
} |
|
1687 |
} |
|
1688 |
} |
|
1689 |
||
1690 |
static const uint AMASK = 0xff000000; |
|
1691 |
static const uint RMASK = 0x00ff0000; |
|
1692 |
static const uint GMASK = 0x0000ff00; |
|
1693 |
static const uint BMASK = 0x000000ff; |
|
1694 |
||
1695 |
struct QFullCoverage { |
|
1696 |
inline void store(uint *dest, const uint src) const |
|
1697 |
{ |
|
1698 |
*dest = src; |
|
1699 |
} |
|
1700 |
}; |
|
1701 |
||
1702 |
struct QPartialCoverage { |
|
1703 |
inline QPartialCoverage(uint const_alpha) |
|
1704 |
: ca(const_alpha) |
|
1705 |
, ica(255 - const_alpha) |
|
1706 |
{ |
|
1707 |
} |
|
1708 |
||
1709 |
inline void store(uint *dest, const uint src) const |
|
1710 |
{ |
|
1711 |
*dest = INTERPOLATE_PIXEL_255(src, ca, *dest, ica); |
|
1712 |
} |
|
1713 |
||
1714 |
private: |
|
1715 |
const uint ca; |
|
1716 |
const uint ica; |
|
1717 |
}; |
|
1718 |
||
1719 |
static inline int mix_alpha(int da, int sa) |
|
1720 |
{ |
|
1721 |
return 255 - ((255 - sa) * (255 - da) >> 8); |
|
1722 |
} |
|
1723 |
||
1724 |
/* |
|
1725 |
Dca' = Sca.Da + Dca.Sa + Sca.(1 - Da) + Dca.(1 - Sa) |
|
1726 |
= Sca + Dca |
|
1727 |
*/ |
|
1728 |
template <typename T> |
|
1729 |
Q_STATIC_TEMPLATE_FUNCTION inline void comp_func_solid_Plus_impl(uint *dest, int length, uint color, const T &coverage) |
|
1730 |
{ |
|
1731 |
uint s = color; |
|
1732 |
||
1733 |
PRELOAD_INIT(dest) |
|
1734 |
for (int i = 0; i < length; ++i) { |
|
1735 |
PRELOAD_COND(dest) |
|
1736 |
uint d = dest[i]; |
|
1737 |
#define MIX(mask) (qMin(((qint64(s)&mask) + (qint64(d)&mask)), qint64(mask))) |
|
1738 |
d = (MIX(AMASK) | MIX(RMASK) | MIX(GMASK) | MIX(BMASK)); |
|
1739 |
#undef MIX |
|
1740 |
coverage.store(&dest[i], d); |
|
1741 |
} |
|
1742 |
} |
|
1743 |
||
1744 |
static void QT_FASTCALL comp_func_solid_Plus(uint *dest, int length, uint color, uint const_alpha) |
|
1745 |
{ |
|
1746 |
if (const_alpha == 255) |
|
1747 |
comp_func_solid_Plus_impl(dest, length, color, QFullCoverage()); |
|
1748 |
else |
|
1749 |
comp_func_solid_Plus_impl(dest, length, color, QPartialCoverage(const_alpha)); |
|
1750 |
} |
|
1751 |
||
1752 |
template <typename T> |
|
1753 |
Q_STATIC_TEMPLATE_FUNCTION inline void comp_func_Plus_impl(uint *dest, const uint *src, int length, const T &coverage) |
|
1754 |
{ |
|
1755 |
PRELOAD_INIT2(dest, src) |
|
1756 |
for (int i = 0; i < length; ++i) { |
|
1757 |
PRELOAD_COND2(dest, src) |
|
1758 |
uint d = dest[i]; |
|
1759 |
uint s = src[i]; |
|
1760 |
||
1761 |
#define MIX(mask) (qMin(((qint64(s)&mask) + (qint64(d)&mask)), qint64(mask))) |
|
1762 |
d = (MIX(AMASK) | MIX(RMASK) | MIX(GMASK) | MIX(BMASK)); |
|
1763 |
#undef MIX |
|
1764 |
||
1765 |
coverage.store(&dest[i], d); |
|
1766 |
} |
|
1767 |
} |
|
1768 |
||
1769 |
static void QT_FASTCALL comp_func_Plus(uint *dest, const uint *src, int length, uint const_alpha) |
|
1770 |
{ |
|
1771 |
if (const_alpha == 255) |
|
1772 |
comp_func_Plus_impl(dest, src, length, QFullCoverage()); |
|
1773 |
else |
|
1774 |
comp_func_Plus_impl(dest, src, length, QPartialCoverage(const_alpha)); |
|
1775 |
} |
|
1776 |
||
1777 |
/* |
|
1778 |
Dca' = Sca.Dca + Sca.(1 - Da) + Dca.(1 - Sa) |
|
1779 |
*/ |
|
1780 |
static inline int multiply_op(int dst, int src, int da, int sa) |
|
1781 |
{ |
|
1782 |
return qt_div_255(src * dst + src * (255 - da) + dst * (255 - sa)); |
|
1783 |
} |
|
1784 |
||
1785 |
template <typename T> |
|
1786 |
Q_STATIC_TEMPLATE_FUNCTION inline void comp_func_solid_Multiply_impl(uint *dest, int length, uint color, const T &coverage) |
|
1787 |
{ |
|
1788 |
int sa = qAlpha(color); |
|
1789 |
int sr = qRed(color); |
|
1790 |
int sg = qGreen(color); |
|
1791 |
int sb = qBlue(color); |
|
1792 |
||
1793 |
PRELOAD_INIT(dest) |
|
1794 |
for (int i = 0; i < length; ++i) { |
|
1795 |
PRELOAD_COND(dest) |
|
1796 |
uint d = dest[i]; |
|
1797 |
int da = qAlpha(d); |
|
1798 |
||
1799 |
#define OP(a, b) multiply_op(a, b, da, sa) |
|
1800 |
int r = OP( qRed(d), sr); |
|
1801 |
int b = OP( qBlue(d), sb); |
|
1802 |
int g = OP(qGreen(d), sg); |
|
1803 |
int a = mix_alpha(da, sa); |
|
1804 |
#undef OP |
|
1805 |
||
1806 |
coverage.store(&dest[i], qRgba(r, g, b, a)); |
|
1807 |
} |
|
1808 |
} |
|
1809 |
||
1810 |
static void QT_FASTCALL comp_func_solid_Multiply(uint *dest, int length, uint color, uint const_alpha) |
|
1811 |
{ |
|
1812 |
if (const_alpha == 255) |
|
1813 |
comp_func_solid_Multiply_impl(dest, length, color, QFullCoverage()); |
|
1814 |
else |
|
1815 |
comp_func_solid_Multiply_impl(dest, length, color, QPartialCoverage(const_alpha)); |
|
1816 |
} |
|
1817 |
||
1818 |
template <typename T> |
|
1819 |
Q_STATIC_TEMPLATE_FUNCTION inline void comp_func_Multiply_impl(uint *dest, const uint *src, int length, const T &coverage) |
|
1820 |
{ |
|
1821 |
PRELOAD_INIT2(dest, src) |
|
1822 |
for (int i = 0; i < length; ++i) { |
|
1823 |
PRELOAD_COND2(dest, src) |
|
1824 |
uint d = dest[i]; |
|
1825 |
uint s = src[i]; |
|
1826 |
||
1827 |
int da = qAlpha(d); |
|
1828 |
int sa = qAlpha(s); |
|
1829 |
||
1830 |
#define OP(a, b) multiply_op(a, b, da, sa) |
|
1831 |
int r = OP( qRed(d), qRed(s)); |
|
1832 |
int b = OP( qBlue(d), qBlue(s)); |
|
1833 |
int g = OP(qGreen(d), qGreen(s)); |
|
1834 |
int a = mix_alpha(da, sa); |
|
1835 |
#undef OP |
|
1836 |
||
1837 |
coverage.store(&dest[i], qRgba(r, g, b, a)); |
|
1838 |
} |
|
1839 |
} |
|
1840 |
||
1841 |
static void QT_FASTCALL comp_func_Multiply(uint *dest, const uint *src, int length, uint const_alpha) |
|
1842 |
{ |
|
1843 |
if (const_alpha == 255) |
|
1844 |
comp_func_Multiply_impl(dest, src, length, QFullCoverage()); |
|
1845 |
else |
|
1846 |
comp_func_Multiply_impl(dest, src, length, QPartialCoverage(const_alpha)); |
|
1847 |
} |
|
1848 |
||
1849 |
/* |
|
1850 |
Dca' = (Sca.Da + Dca.Sa - Sca.Dca) + Sca.(1 - Da) + Dca.(1 - Sa) |
|
1851 |
= Sca + Dca - Sca.Dca |
|
1852 |
*/ |
|
1853 |
template <typename T> |
|
1854 |
Q_STATIC_TEMPLATE_FUNCTION inline void comp_func_solid_Screen_impl(uint *dest, int length, uint color, const T &coverage) |
|
1855 |
{ |
|
1856 |
int sa = qAlpha(color); |
|
1857 |
int sr = qRed(color); |
|
1858 |
int sg = qGreen(color); |
|
1859 |
int sb = qBlue(color); |
|
1860 |
||
1861 |
PRELOAD_INIT(dest) |
|
1862 |
for (int i = 0; i < length; ++i) { |
|
1863 |
PRELOAD_COND(dest) |
|
1864 |
uint d = dest[i]; |
|
1865 |
int da = qAlpha(d); |
|
1866 |
||
1867 |
#define OP(a, b) 255 - qt_div_255((255-a) * (255-b)) |
|
1868 |
int r = OP( qRed(d), sr); |
|
1869 |
int b = OP( qBlue(d), sb); |
|
1870 |
int g = OP(qGreen(d), sg); |
|
1871 |
int a = mix_alpha(da, sa); |
|
1872 |
#undef OP |
|
1873 |
||
1874 |
coverage.store(&dest[i], qRgba(r, g, b, a)); |
|
1875 |
} |
|
1876 |
} |
|
1877 |
||
1878 |
static void QT_FASTCALL comp_func_solid_Screen(uint *dest, int length, uint color, uint const_alpha) |
|
1879 |
{ |
|
1880 |
if (const_alpha == 255) |
|
1881 |
comp_func_solid_Screen_impl(dest, length, color, QFullCoverage()); |
|
1882 |
else |
|
1883 |
comp_func_solid_Screen_impl(dest, length, color, QPartialCoverage(const_alpha)); |
|
1884 |
} |
|
1885 |
||
1886 |
template <typename T> |
|
1887 |
Q_STATIC_TEMPLATE_FUNCTION inline void comp_func_Screen_impl(uint *dest, const uint *src, int length, const T &coverage) |
|
1888 |
{ |
|
1889 |
PRELOAD_INIT2(dest, src) |
|
1890 |
for (int i = 0; i < length; ++i) { |
|
1891 |
PRELOAD_COND2(dest, src) |
|
1892 |
uint d = dest[i]; |
|
1893 |
uint s = src[i]; |
|
1894 |
||
1895 |
int da = qAlpha(d); |
|
1896 |
int sa = qAlpha(s); |
|
1897 |
||
1898 |
#define OP(a, b) 255 - (((255-a) * (255-b)) >> 8) |
|
1899 |
int r = OP( qRed(d), qRed(s)); |
|
1900 |
int b = OP( qBlue(d), qBlue(s)); |
|
1901 |
int g = OP(qGreen(d), qGreen(s)); |
|
1902 |
int a = mix_alpha(da, sa); |
|
1903 |
#undef OP |
|
1904 |
||
1905 |
coverage.store(&dest[i], qRgba(r, g, b, a)); |
|
1906 |
} |
|
1907 |
} |
|
1908 |
||
1909 |
static void QT_FASTCALL comp_func_Screen(uint *dest, const uint *src, int length, uint const_alpha) |
|
1910 |
{ |
|
1911 |
if (const_alpha == 255) |
|
1912 |
comp_func_Screen_impl(dest, src, length, QFullCoverage()); |
|
1913 |
else |
|
1914 |
comp_func_Screen_impl(dest, src, length, QPartialCoverage(const_alpha)); |
|
1915 |
} |
|
1916 |
||
1917 |
/* |
|
1918 |
if 2.Dca < Da |
|
1919 |
Dca' = 2.Sca.Dca + Sca.(1 - Da) + Dca.(1 - Sa) |
|
1920 |
otherwise |
|
1921 |
Dca' = Sa.Da - 2.(Da - Dca).(Sa - Sca) + Sca.(1 - Da) + Dca.(1 - Sa) |
|
1922 |
*/ |
|
1923 |
static inline int overlay_op(int dst, int src, int da, int sa) |
|
1924 |
{ |
|
1925 |
const int temp = src * (255 - da) + dst * (255 - sa); |
|
1926 |
if (2 * dst < da) |
|
1927 |
return qt_div_255(2 * src * dst + temp); |
|
1928 |
else |
|
1929 |
return qt_div_255(sa * da - 2 * (da - dst) * (sa - src) + temp); |
|
1930 |
} |
|
1931 |
||
1932 |
template <typename T> |
|
1933 |
Q_STATIC_TEMPLATE_FUNCTION inline void comp_func_solid_Overlay_impl(uint *dest, int length, uint color, const T &coverage) |
|
1934 |
{ |
|
1935 |
int sa = qAlpha(color); |
|
1936 |
int sr = qRed(color); |
|
1937 |
int sg = qGreen(color); |
|
1938 |
int sb = qBlue(color); |
|
1939 |
||
1940 |
PRELOAD_INIT(dest) |
|
1941 |
for (int i = 0; i < length; ++i) { |
|
1942 |
PRELOAD_COND(dest) |
|
1943 |
uint d = dest[i]; |
|
1944 |
int da = qAlpha(d); |
|
1945 |
||
1946 |
#define OP(a, b) overlay_op(a, b, da, sa) |
|
1947 |
int r = OP( qRed(d), sr); |
|
1948 |
int b = OP( qBlue(d), sb); |
|
1949 |
int g = OP(qGreen(d), sg); |
|
1950 |
int a = mix_alpha(da, sa); |
|
1951 |
#undef OP |
|
1952 |
||
1953 |
coverage.store(&dest[i], qRgba(r, g, b, a)); |
|
1954 |
} |
|
1955 |
} |
|
1956 |
||
1957 |
static void QT_FASTCALL comp_func_solid_Overlay(uint *dest, int length, uint color, uint const_alpha) |
|
1958 |
{ |
|
1959 |
if (const_alpha == 255) |
|
1960 |
comp_func_solid_Overlay_impl(dest, length, color, QFullCoverage()); |
|
1961 |
else |
|
1962 |
comp_func_solid_Overlay_impl(dest, length, color, QPartialCoverage(const_alpha)); |
|
1963 |
} |
|
1964 |
||
1965 |
template <typename T> |
|
1966 |
Q_STATIC_TEMPLATE_FUNCTION inline void comp_func_Overlay_impl(uint *dest, const uint *src, int length, const T &coverage) |
|
1967 |
{ |
|
1968 |
PRELOAD_INIT2(dest, src) |
|
1969 |
for (int i = 0; i < length; ++i) { |
|
1970 |
PRELOAD_COND2(dest, src) |
|
1971 |
uint d = dest[i]; |
|
1972 |
uint s = src[i]; |
|
1973 |
||
1974 |
int da = qAlpha(d); |
|
1975 |
int sa = qAlpha(s); |
|
1976 |
||
1977 |
#define OP(a, b) overlay_op(a, b, da, sa) |
|
1978 |
int r = OP( qRed(d), qRed(s)); |
|
1979 |
int b = OP( qBlue(d), qBlue(s)); |
|
1980 |
int g = OP(qGreen(d), qGreen(s)); |
|
1981 |
int a = mix_alpha(da, sa); |
|
1982 |
#undef OP |
|
1983 |
||
1984 |
coverage.store(&dest[i], qRgba(r, g, b, a)); |
|
1985 |
} |
|
1986 |
} |
|
1987 |
||
1988 |
static void QT_FASTCALL comp_func_Overlay(uint *dest, const uint *src, int length, uint const_alpha) |
|
1989 |
{ |
|
1990 |
if (const_alpha == 255) |
|
1991 |
comp_func_Overlay_impl(dest, src, length, QFullCoverage()); |
|
1992 |
else |
|
1993 |
comp_func_Overlay_impl(dest, src, length, QPartialCoverage(const_alpha)); |
|
1994 |
} |
|
1995 |
||
1996 |
/* |
|
1997 |
Dca' = min(Sca.Da, Dca.Sa) + Sca.(1 - Da) + Dca.(1 - Sa) |
|
1998 |
Da' = Sa + Da - Sa.Da |
|
1999 |
*/ |
|
2000 |
static inline int darken_op(int dst, int src, int da, int sa) |
|
2001 |
{ |
|
2002 |
return qt_div_255(qMin(src * da, dst * sa) + src * (255 - da) + dst * (255 - sa)); |
|
2003 |
} |
|
2004 |
||
2005 |
template <typename T> |
|
2006 |
Q_STATIC_TEMPLATE_FUNCTION inline void comp_func_solid_Darken_impl(uint *dest, int length, uint color, const T &coverage) |
|
2007 |
{ |
|
2008 |
int sa = qAlpha(color); |
|
2009 |
int sr = qRed(color); |
|
2010 |
int sg = qGreen(color); |
|
2011 |
int sb = qBlue(color); |
|
2012 |
||
2013 |
PRELOAD_INIT(dest) |
|
2014 |
for (int i = 0; i < length; ++i) { |
|
2015 |
PRELOAD_COND(dest) |
|
2016 |
uint d = dest[i]; |
|
2017 |
int da = qAlpha(d); |
|
2018 |
||
2019 |
#define OP(a, b) darken_op(a, b, da, sa) |
|
2020 |
int r = OP( qRed(d), sr); |
|
2021 |
int b = OP( qBlue(d), sb); |
|
2022 |
int g = OP(qGreen(d), sg); |
|
2023 |
int a = mix_alpha(da, sa); |
|
2024 |
#undef OP |
|
2025 |
||
2026 |
coverage.store(&dest[i], qRgba(r, g, b, a)); |
|
2027 |
} |
|
2028 |
} |
|
2029 |
||
2030 |
static void QT_FASTCALL comp_func_solid_Darken(uint *dest, int length, uint color, uint const_alpha) |
|
2031 |
{ |
|
2032 |
if (const_alpha == 255) |
|
2033 |
comp_func_solid_Darken_impl(dest, length, color, QFullCoverage()); |
|
2034 |
else |
|
2035 |
comp_func_solid_Darken_impl(dest, length, color, QPartialCoverage(const_alpha)); |
|
2036 |
} |
|
2037 |
||
2038 |
template <typename T> |
|
2039 |
Q_STATIC_TEMPLATE_FUNCTION inline void comp_func_Darken_impl(uint *dest, const uint *src, int length, const T &coverage) |
|
2040 |
{ |
|
2041 |
PRELOAD_INIT2(dest, src) |
|
2042 |
for (int i = 0; i < length; ++i) { |
|
2043 |
PRELOAD_COND2(dest, src) |
|
2044 |
uint d = dest[i]; |
|
2045 |
uint s = src[i]; |
|
2046 |
||
2047 |
int da = qAlpha(d); |
|
2048 |
int sa = qAlpha(s); |
|
2049 |
||
2050 |
#define OP(a, b) darken_op(a, b, da, sa) |
|
2051 |
int r = OP( qRed(d), qRed(s)); |
|
2052 |
int b = OP( qBlue(d), qBlue(s)); |
|
2053 |
int g = OP(qGreen(d), qGreen(s)); |
|
2054 |
int a = mix_alpha(da, sa); |
|
2055 |
#undef OP |
|
2056 |
||
2057 |
coverage.store(&dest[i], qRgba(r, g, b, a)); |
|
2058 |
} |
|
2059 |
} |
|
2060 |
||
2061 |
static void QT_FASTCALL comp_func_Darken(uint *dest, const uint *src, int length, uint const_alpha) |
|
2062 |
{ |
|
2063 |
if (const_alpha == 255) |
|
2064 |
comp_func_Darken_impl(dest, src, length, QFullCoverage()); |
|
2065 |
else |
|
2066 |
comp_func_Darken_impl(dest, src, length, QPartialCoverage(const_alpha)); |
|
2067 |
} |
|
2068 |
||
2069 |
/* |
|
2070 |
Dca' = max(Sca.Da, Dca.Sa) + Sca.(1 - Da) + Dca.(1 - Sa) |
|
2071 |
Da' = Sa + Da - Sa.Da |
|
2072 |
*/ |
|
2073 |
static inline int lighten_op(int dst, int src, int da, int sa) |
|
2074 |
{ |
|
2075 |
return qt_div_255(qMax(src * da, dst * sa) + src * (255 - da) + dst * (255 - sa)); |
|
2076 |
} |
|
2077 |
||
2078 |
template <typename T> |
|
2079 |
Q_STATIC_TEMPLATE_FUNCTION inline void comp_func_solid_Lighten_impl(uint *dest, int length, uint color, const T &coverage) |
|
2080 |
{ |
|
2081 |
int sa = qAlpha(color); |
|
2082 |
int sr = qRed(color); |
|
2083 |
int sg = qGreen(color); |
|
2084 |
int sb = qBlue(color); |
|
2085 |
||
2086 |
PRELOAD_INIT(dest) |
|
2087 |
for (int i = 0; i < length; ++i) { |
|
2088 |
PRELOAD_COND(dest) |
|
2089 |
uint d = dest[i]; |
|
2090 |
int da = qAlpha(d); |
|
2091 |
||
2092 |
#define OP(a, b) lighten_op(a, b, da, sa) |
|
2093 |
int r = OP( qRed(d), sr); |
|
2094 |
int b = OP( qBlue(d), sb); |
|
2095 |
int g = OP(qGreen(d), sg); |
|
2096 |
int a = mix_alpha(da, sa); |
|
2097 |
#undef OP |
|
2098 |
||
2099 |
coverage.store(&dest[i], qRgba(r, g, b, a)); |
|
2100 |
} |
|
2101 |
} |
|
2102 |
||
2103 |
static void QT_FASTCALL comp_func_solid_Lighten(uint *dest, int length, uint color, uint const_alpha) |
|
2104 |
{ |
|
2105 |
if (const_alpha == 255) |
|
2106 |
comp_func_solid_Lighten_impl(dest, length, color, QFullCoverage()); |
|
2107 |
else |
|
2108 |
comp_func_solid_Lighten_impl(dest, length, color, QPartialCoverage(const_alpha)); |
|
2109 |
} |
|
2110 |
||
2111 |
template <typename T> |
|
2112 |
Q_STATIC_TEMPLATE_FUNCTION inline void comp_func_Lighten_impl(uint *dest, const uint *src, int length, const T &coverage) |
|
2113 |
{ |
|
2114 |
PRELOAD_INIT2(dest, src) |
|
2115 |
for (int i = 0; i < length; ++i) { |
|
2116 |
PRELOAD_COND2(dest, src) |
|
2117 |
uint d = dest[i]; |
|
2118 |
uint s = src[i]; |
|
2119 |
||
2120 |
int da = qAlpha(d); |
|
2121 |
int sa = qAlpha(s); |
|
2122 |
||
2123 |
#define OP(a, b) lighten_op(a, b, da, sa) |
|
2124 |
int r = OP( qRed(d), qRed(s)); |
|
2125 |
int b = OP( qBlue(d), qBlue(s)); |
|
2126 |
int g = OP(qGreen(d), qGreen(s)); |
|
2127 |
int a = mix_alpha(da, sa); |
|
2128 |
#undef OP |
|
2129 |
||
2130 |
coverage.store(&dest[i], qRgba(r, g, b, a)); |
|
2131 |
} |
|
2132 |
} |
|
2133 |
||
2134 |
static void QT_FASTCALL comp_func_Lighten(uint *dest, const uint *src, int length, uint const_alpha) |
|
2135 |
{ |
|
2136 |
if (const_alpha == 255) |
|
2137 |
comp_func_Lighten_impl(dest, src, length, QFullCoverage()); |
|
2138 |
else |
|
2139 |
comp_func_Lighten_impl(dest, src, length, QPartialCoverage(const_alpha)); |
|
2140 |
} |
|
2141 |
||
2142 |
/* |
|
2143 |
if Sca.Da + Dca.Sa >= Sa.Da |
|
2144 |
Dca' = Sa.Da + Sca.(1 - Da) + Dca.(1 - Sa) |
|
2145 |
otherwise |
|
2146 |
Dca' = Dca.Sa/(1-Sca/Sa) + Sca.(1 - Da) + Dca.(1 - Sa) |
|
2147 |
*/ |
|
2148 |
static inline int color_dodge_op(int dst, int src, int da, int sa) |
|
2149 |
{ |
|
2150 |
const int sa_da = sa * da; |
|
2151 |
const int dst_sa = dst * sa; |
|
2152 |
const int src_da = src * da; |
|
2153 |
||
2154 |
const int temp = src * (255 - da) + dst * (255 - sa); |
|
2155 |
if (src_da + dst_sa >= sa_da) |
|
2156 |
return qt_div_255(sa_da + temp); |
|
2157 |
else |
|
2158 |
return qt_div_255(255 * dst_sa / (255 - 255 * src / sa) + temp); |
|
2159 |
} |
|
2160 |
||
2161 |
template <typename T> |
|
2162 |
Q_STATIC_TEMPLATE_FUNCTION inline void comp_func_solid_ColorDodge_impl(uint *dest, int length, uint color, const T &coverage) |
|
2163 |
{ |
|
2164 |
int sa = qAlpha(color); |
|
2165 |
int sr = qRed(color); |
|
2166 |
int sg = qGreen(color); |
|
2167 |
int sb = qBlue(color); |
|
2168 |
||
2169 |
PRELOAD_INIT(dest) |
|
2170 |
for (int i = 0; i < length; ++i) { |
|
2171 |
PRELOAD_COND(dest) |
|
2172 |
uint d = dest[i]; |
|
2173 |
int da = qAlpha(d); |
|
2174 |
||
2175 |
#define OP(a,b) color_dodge_op(a, b, da, sa) |
|
2176 |
int r = OP( qRed(d), sr); |
|
2177 |
int b = OP( qBlue(d), sb); |
|
2178 |
int g = OP(qGreen(d), sg); |
|
2179 |
int a = mix_alpha(da, sa); |
|
2180 |
#undef OP |
|
2181 |
||
2182 |
coverage.store(&dest[i], qRgba(r, g, b, a)); |
|
2183 |
} |
|
2184 |
} |
|
2185 |
||
2186 |
static void QT_FASTCALL comp_func_solid_ColorDodge(uint *dest, int length, uint color, uint const_alpha) |
|
2187 |
{ |
|
2188 |
if (const_alpha == 255) |
|
2189 |
comp_func_solid_ColorDodge_impl(dest, length, color, QFullCoverage()); |
|
2190 |
else |
|
2191 |
comp_func_solid_ColorDodge_impl(dest, length, color, QPartialCoverage(const_alpha)); |
|
2192 |
} |
|
2193 |
||
2194 |
template <typename T> |
|
2195 |
Q_STATIC_TEMPLATE_FUNCTION inline void comp_func_ColorDodge_impl(uint *dest, const uint *src, int length, const T &coverage) |
|
2196 |
{ |
|
2197 |
PRELOAD_INIT2(dest, src) |
|
2198 |
for (int i = 0; i < length; ++i) { |
|
2199 |
PRELOAD_COND2(dest, src) |
|
2200 |
uint d = dest[i]; |
|
2201 |
uint s = src[i]; |
|
2202 |
||
2203 |
int da = qAlpha(d); |
|
2204 |
int sa = qAlpha(s); |
|
2205 |
||
2206 |
#define OP(a, b) color_dodge_op(a, b, da, sa) |
|
2207 |
int r = OP( qRed(d), qRed(s)); |
|
2208 |
int b = OP( qBlue(d), qBlue(s)); |
|
2209 |
int g = OP(qGreen(d), qGreen(s)); |
|
2210 |
int a = mix_alpha(da, sa); |
|
2211 |
#undef OP |
|
2212 |
||
2213 |
coverage.store(&dest[i], qRgba(r, g, b, a)); |
|
2214 |
} |
|
2215 |
} |
|
2216 |
||
2217 |
static void QT_FASTCALL comp_func_ColorDodge(uint *dest, const uint *src, int length, uint const_alpha) |
|
2218 |
{ |
|
2219 |
if (const_alpha == 255) |
|
2220 |
comp_func_ColorDodge_impl(dest, src, length, QFullCoverage()); |
|
2221 |
else |
|
2222 |
comp_func_ColorDodge_impl(dest, src, length, QPartialCoverage(const_alpha)); |
|
2223 |
} |
|
2224 |
||
2225 |
/* |
|
2226 |
if Sca.Da + Dca.Sa <= Sa.Da |
|
2227 |
Dca' = Sca.(1 - Da) + Dca.(1 - Sa) |
|
2228 |
otherwise |
|
2229 |
Dca' = Sa.(Sca.Da + Dca.Sa - Sa.Da)/Sca + Sca.(1 - Da) + Dca.(1 - Sa) |
|
2230 |
*/ |
|
2231 |
static inline int color_burn_op(int dst, int src, int da, int sa) |
|
2232 |
{ |
|
2233 |
const int src_da = src * da; |
|
2234 |
const int dst_sa = dst * sa; |
|
2235 |
const int sa_da = sa * da; |
|
2236 |
||
2237 |
const int temp = src * (255 - da) + dst * (255 - sa); |
|
2238 |
||
2239 |
if (src == 0 || src_da + dst_sa <= sa_da) |
|
2240 |
return qt_div_255(temp); |
|
2241 |
return qt_div_255(sa * (src_da + dst_sa - sa_da) / src + temp); |
|
2242 |
} |
|
2243 |
||
2244 |
template <typename T> |
|
2245 |
Q_STATIC_TEMPLATE_FUNCTION inline void comp_func_solid_ColorBurn_impl(uint *dest, int length, uint color, const T &coverage) |
|
2246 |
{ |
|
2247 |
int sa = qAlpha(color); |
|
2248 |
int sr = qRed(color); |
|
2249 |
int sg = qGreen(color); |
|
2250 |
int sb = qBlue(color); |
|
2251 |
||
2252 |
PRELOAD_INIT(dest) |
|
2253 |
for (int i = 0; i < length; ++i) { |
|
2254 |
PRELOAD_COND(dest) |
|
2255 |
uint d = dest[i]; |
|
2256 |
int da = qAlpha(d); |
|
2257 |
||
2258 |
#define OP(a, b) color_burn_op(a, b, da, sa) |
|
2259 |
int r = OP( qRed(d), sr); |
|
2260 |
int b = OP( qBlue(d), sb); |
|
2261 |
int g = OP(qGreen(d), sg); |
|
2262 |
int a = mix_alpha(da, sa); |
|
2263 |
#undef OP |
|
2264 |
||
2265 |
coverage.store(&dest[i], qRgba(r, g, b, a)); |
|
2266 |
} |
|
2267 |
} |
|
2268 |
||
2269 |
static void QT_FASTCALL comp_func_solid_ColorBurn(uint *dest, int length, uint color, uint const_alpha) |
|
2270 |
{ |
|
2271 |
if (const_alpha == 255) |
|
2272 |
comp_func_solid_ColorBurn_impl(dest, length, color, QFullCoverage()); |
|
2273 |
else |
|
2274 |
comp_func_solid_ColorBurn_impl(dest, length, color, QPartialCoverage(const_alpha)); |
|
2275 |
} |
|
2276 |
||
2277 |
template <typename T> |
|
2278 |
Q_STATIC_TEMPLATE_FUNCTION inline void comp_func_ColorBurn_impl(uint *dest, const uint *src, int length, const T &coverage) |
|
2279 |
{ |
|
2280 |
PRELOAD_INIT2(dest, src) |
|
2281 |
for (int i = 0; i < length; ++i) { |
|
2282 |
PRELOAD_COND2(dest, src) |
|
2283 |
uint d = dest[i]; |
|
2284 |
uint s = src[i]; |
|
2285 |
||
2286 |
int da = qAlpha(d); |
|
2287 |
int sa = qAlpha(s); |
|
2288 |
||
2289 |
#define OP(a, b) color_burn_op(a, b, da, sa) |
|
2290 |
int r = OP( qRed(d), qRed(s)); |
|
2291 |
int b = OP( qBlue(d), qBlue(s)); |
|
2292 |
int g = OP(qGreen(d), qGreen(s)); |
|
2293 |
int a = mix_alpha(da, sa); |
|
2294 |
#undef OP |
|
2295 |
||
2296 |
coverage.store(&dest[i], qRgba(r, g, b, a)); |
|
2297 |
} |
|
2298 |
} |
|
2299 |
||
2300 |
static void QT_FASTCALL comp_func_ColorBurn(uint *dest, const uint *src, int length, uint const_alpha) |
|
2301 |
{ |
|
2302 |
if (const_alpha == 255) |
|
2303 |
comp_func_ColorBurn_impl(dest, src, length, QFullCoverage()); |
|
2304 |
else |
|
2305 |
comp_func_ColorBurn_impl(dest, src, length, QPartialCoverage(const_alpha)); |
|
2306 |
} |
|
2307 |
||
2308 |
/* |
|
2309 |
if 2.Sca < Sa |
|
2310 |
Dca' = 2.Sca.Dca + Sca.(1 - Da) + Dca.(1 - Sa) |
|
2311 |
otherwise |
|
2312 |
Dca' = Sa.Da - 2.(Da - Dca).(Sa - Sca) + Sca.(1 - Da) + Dca.(1 - Sa) |
|
2313 |
*/ |
|
2314 |
static inline uint hardlight_op(int dst, int src, int da, int sa) |
|
2315 |
{ |
|
2316 |
const uint temp = src * (255 - da) + dst * (255 - sa); |
|
2317 |
||
2318 |
if (2 * src < sa) |
|
2319 |
return qt_div_255(2 * src * dst + temp); |
|
2320 |
else |
|
2321 |
return qt_div_255(sa * da - 2 * (da - dst) * (sa - src) + temp); |
|
2322 |
} |
|
2323 |
||
2324 |
template <typename T> |
|
2325 |
Q_STATIC_TEMPLATE_FUNCTION inline void comp_func_solid_HardLight_impl(uint *dest, int length, uint color, const T &coverage) |
|
2326 |
{ |
|
2327 |
int sa = qAlpha(color); |
|
2328 |
int sr = qRed(color); |
|
2329 |
int sg = qGreen(color); |
|
2330 |
int sb = qBlue(color); |
|
2331 |
||
2332 |
PRELOAD_INIT(dest) |
|
2333 |
for (int i = 0; i < length; ++i) { |
|
2334 |
PRELOAD_COND(dest) |
|
2335 |
uint d = dest[i]; |
|
2336 |
int da = qAlpha(d); |
|
2337 |
||
2338 |
#define OP(a, b) hardlight_op(a, b, da, sa) |
|
2339 |
int r = OP( qRed(d), sr); |
|
2340 |
int b = OP( qBlue(d), sb); |
|
2341 |
int g = OP(qGreen(d), sg); |
|
2342 |
int a = mix_alpha(da, sa); |
|
2343 |
#undef OP |
|
2344 |
||
2345 |
coverage.store(&dest[i], qRgba(r, g, b, a)); |
|
2346 |
} |
|
2347 |
} |
|
2348 |
||
2349 |
static void QT_FASTCALL comp_func_solid_HardLight(uint *dest, int length, uint color, uint const_alpha) |
|
2350 |
{ |
|
2351 |
if (const_alpha == 255) |
|
2352 |
comp_func_solid_HardLight_impl(dest, length, color, QFullCoverage()); |
|
2353 |
else |
|
2354 |
comp_func_solid_HardLight_impl(dest, length, color, QPartialCoverage(const_alpha)); |
|
2355 |
} |
|
2356 |
||
2357 |
template <typename T> |
|
2358 |
Q_STATIC_TEMPLATE_FUNCTION inline void comp_func_HardLight_impl(uint *dest, const uint *src, int length, const T &coverage) |
|
2359 |
{ |
|
2360 |
PRELOAD_INIT2(dest, src) |
|
2361 |
for (int i = 0; i < length; ++i) { |
|
2362 |
PRELOAD_COND2(dest, src) |
|
2363 |
uint d = dest[i]; |
|
2364 |
uint s = src[i]; |
|
2365 |
||
2366 |
int da = qAlpha(d); |
|
2367 |
int sa = qAlpha(s); |
|
2368 |
||
2369 |
#define OP(a, b) hardlight_op(a, b, da, sa) |
|
2370 |
int r = OP( qRed(d), qRed(s)); |
|
2371 |
int b = OP( qBlue(d), qBlue(s)); |
|
2372 |
int g = OP(qGreen(d), qGreen(s)); |
|
2373 |
int a = mix_alpha(da, sa); |
|
2374 |
#undef OP |
|
2375 |
||
2376 |
coverage.store(&dest[i], qRgba(r, g, b, a)); |
|
2377 |
} |
|
2378 |
} |
|
2379 |
||
2380 |
static void QT_FASTCALL comp_func_HardLight(uint *dest, const uint *src, int length, uint const_alpha) |
|
2381 |
{ |
|
2382 |
if (const_alpha == 255) |
|
2383 |
comp_func_HardLight_impl(dest, src, length, QFullCoverage()); |
|
2384 |
else |
|
2385 |
comp_func_HardLight_impl(dest, src, length, QPartialCoverage(const_alpha)); |
|
2386 |
} |
|
2387 |
||
2388 |
/* |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2389 |
if 2.Sca <= Sa |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2390 |
Dca' = Dca.(Sa + (2.Sca - Sa).(1 - Dca/Da)) + Sca.(1 - Da) + Dca.(1 - Sa) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2391 |
otherwise if 2.Sca > Sa and 4.Dca <= Da |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2392 |
Dca' = Dca.Sa + Da.(2.Sca - Sa).(4.Dca/Da.(4.Dca/Da + 1).(Dca/Da - 1) + 7.Dca/Da) + Sca.(1 - Da) + Dca.(1 - Sa) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2393 |
otherwise if 2.Sca > Sa and 4.Dca > Da |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2394 |
Dca' = Dca.Sa + Da.(2.Sca - Sa).((Dca/Da)^0.5 - Dca/Da) + Sca.(1 - Da) + Dca.(1 - Sa) |
0 | 2395 |
*/ |
2396 |
static inline int soft_light_op(int dst, int src, int da, int sa) |
|
2397 |
{ |
|
2398 |
const int src2 = src << 1; |
|
2399 |
const int dst_np = da != 0 ? (255 * dst) / da : 0; |
|
2400 |
const int temp = (src * (255 - da) + dst * (255 - sa)) * 255; |
|
2401 |
||
2402 |
if (src2 < sa) |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2403 |
return (dst * (sa * 255 + (src2 - sa) * (255 - dst_np)) + temp) / 65025; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2404 |
else if (4 * dst <= da) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2405 |
return (dst * sa * 255 + da * (src2 - sa) * ((((16 * dst_np - 12 * 255) * dst_np + 3 * 65025) * dst_np) / 65025) + temp) / 65025; |
0 | 2406 |
else { |
7
f7bc934e204c
5cabc75a39ca2f064f70b40f72ed93c74c4dc19b
eckhart.koppen@nokia.com
parents:
3
diff
changeset
|
2407 |
# ifdef Q_CC_RVCT // needed to avoid compiler crash in RVCT 2.2 |
f7bc934e204c
5cabc75a39ca2f064f70b40f72ed93c74c4dc19b
eckhart.koppen@nokia.com
parents:
3
diff
changeset
|
2408 |
return (dst * sa * 255 + da * (src2 - sa) * (qIntSqrtInt(dst_np * 255) - dst_np) + temp) / 65025; |
f7bc934e204c
5cabc75a39ca2f064f70b40f72ed93c74c4dc19b
eckhart.koppen@nokia.com
parents:
3
diff
changeset
|
2409 |
# else |
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2410 |
return (dst * sa * 255 + da * (src2 - sa) * (int(sqrt(qreal(dst_np * 255))) - dst_np) + temp) / 65025; |
7
f7bc934e204c
5cabc75a39ca2f064f70b40f72ed93c74c4dc19b
eckhart.koppen@nokia.com
parents:
3
diff
changeset
|
2411 |
# endif |
0 | 2412 |
} |
2413 |
} |
|
2414 |
||
2415 |
template <typename T> |
|
2416 |
Q_STATIC_TEMPLATE_FUNCTION inline void comp_func_solid_SoftLight_impl(uint *dest, int length, uint color, const T &coverage) |
|
2417 |
{ |
|
2418 |
int sa = qAlpha(color); |
|
2419 |
int sr = qRed(color); |
|
2420 |
int sg = qGreen(color); |
|
2421 |
int sb = qBlue(color); |
|
2422 |
||
2423 |
PRELOAD_INIT(dest) |
|
2424 |
for (int i = 0; i < length; ++i) { |
|
2425 |
PRELOAD_COND(dest) |
|
2426 |
uint d = dest[i]; |
|
2427 |
int da = qAlpha(d); |
|
2428 |
||
2429 |
#define OP(a, b) soft_light_op(a, b, da, sa) |
|
2430 |
int r = OP( qRed(d), sr); |
|
2431 |
int b = OP( qBlue(d), sb); |
|
2432 |
int g = OP(qGreen(d), sg); |
|
2433 |
int a = mix_alpha(da, sa); |
|
2434 |
#undef OP |
|
2435 |
||
2436 |
coverage.store(&dest[i], qRgba(r, g, b, a)); |
|
2437 |
} |
|
2438 |
} |
|
2439 |
||
2440 |
static void QT_FASTCALL comp_func_solid_SoftLight(uint *dest, int length, uint color, uint const_alpha) |
|
2441 |
{ |
|
2442 |
if (const_alpha == 255) |
|
2443 |
comp_func_solid_SoftLight_impl(dest, length, color, QFullCoverage()); |
|
2444 |
else |
|
2445 |
comp_func_solid_SoftLight_impl(dest, length, color, QPartialCoverage(const_alpha)); |
|
2446 |
} |
|
2447 |
||
2448 |
template <typename T> |
|
2449 |
Q_STATIC_TEMPLATE_FUNCTION inline void comp_func_SoftLight_impl(uint *dest, const uint *src, int length, const T &coverage) |
|
2450 |
{ |
|
2451 |
PRELOAD_INIT2(dest, src) |
|
2452 |
for (int i = 0; i < length; ++i) { |
|
2453 |
PRELOAD_COND2(dest, src) |
|
2454 |
uint d = dest[i]; |
|
2455 |
uint s = src[i]; |
|
2456 |
||
2457 |
int da = qAlpha(d); |
|
2458 |
int sa = qAlpha(s); |
|
2459 |
||
2460 |
#define OP(a, b) soft_light_op(a, b, da, sa) |
|
2461 |
int r = OP( qRed(d), qRed(s)); |
|
2462 |
int b = OP( qBlue(d), qBlue(s)); |
|
2463 |
int g = OP(qGreen(d), qGreen(s)); |
|
2464 |
int a = mix_alpha(da, sa); |
|
2465 |
#undef OP |
|
2466 |
||
2467 |
coverage.store(&dest[i], qRgba(r, g, b, a)); |
|
2468 |
} |
|
2469 |
} |
|
2470 |
||
2471 |
static void QT_FASTCALL comp_func_SoftLight(uint *dest, const uint *src, int length, uint const_alpha) |
|
2472 |
{ |
|
2473 |
if (const_alpha == 255) |
|
2474 |
comp_func_SoftLight_impl(dest, src, length, QFullCoverage()); |
|
2475 |
else |
|
2476 |
comp_func_SoftLight_impl(dest, src, length, QPartialCoverage(const_alpha)); |
|
2477 |
} |
|
2478 |
||
2479 |
/* |
|
2480 |
Dca' = abs(Dca.Sa - Sca.Da) + Sca.(1 - Da) + Dca.(1 - Sa) |
|
2481 |
= Sca + Dca - 2.min(Sca.Da, Dca.Sa) |
|
2482 |
*/ |
|
2483 |
static inline int difference_op(int dst, int src, int da, int sa) |
|
2484 |
{ |
|
2485 |
return src + dst - qt_div_255(2 * qMin(src * da, dst * sa)); |
|
2486 |
} |
|
2487 |
||
2488 |
template <typename T> |
|
2489 |
Q_STATIC_TEMPLATE_FUNCTION inline void comp_func_solid_Difference_impl(uint *dest, int length, uint color, const T &coverage) |
|
2490 |
{ |
|
2491 |
int sa = qAlpha(color); |
|
2492 |
int sr = qRed(color); |
|
2493 |
int sg = qGreen(color); |
|
2494 |
int sb = qBlue(color); |
|
2495 |
||
2496 |
PRELOAD_INIT(dest) |
|
2497 |
for (int i = 0; i < length; ++i) { |
|
2498 |
PRELOAD_COND(dest) |
|
2499 |
uint d = dest[i]; |
|
2500 |
int da = qAlpha(d); |
|
2501 |
||
2502 |
#define OP(a, b) difference_op(a, b, da, sa) |
|
2503 |
int r = OP( qRed(d), sr); |
|
2504 |
int b = OP( qBlue(d), sb); |
|
2505 |
int g = OP(qGreen(d), sg); |
|
2506 |
int a = mix_alpha(da, sa); |
|
2507 |
#undef OP |
|
2508 |
||
2509 |
coverage.store(&dest[i], qRgba(r, g, b, a)); |
|
2510 |
} |
|
2511 |
} |
|
2512 |
||
2513 |
static void QT_FASTCALL comp_func_solid_Difference(uint *dest, int length, uint color, uint const_alpha) |
|
2514 |
{ |
|
2515 |
if (const_alpha == 255) |
|
2516 |
comp_func_solid_Difference_impl(dest, length, color, QFullCoverage()); |
|
2517 |
else |
|
2518 |
comp_func_solid_Difference_impl(dest, length, color, QPartialCoverage(const_alpha)); |
|
2519 |
} |
|
2520 |
||
2521 |
template <typename T> |
|
2522 |
Q_STATIC_TEMPLATE_FUNCTION inline void comp_func_Difference_impl(uint *dest, const uint *src, int length, const T &coverage) |
|
2523 |
{ |
|
2524 |
PRELOAD_INIT2(dest, src) |
|
2525 |
for (int i = 0; i < length; ++i) { |
|
2526 |
PRELOAD_COND2(dest, src) |
|
2527 |
uint d = dest[i]; |
|
2528 |
uint s = src[i]; |
|
2529 |
||
2530 |
int da = qAlpha(d); |
|
2531 |
int sa = qAlpha(s); |
|
2532 |
||
2533 |
#define OP(a, b) difference_op(a, b, da, sa) |
|
2534 |
int r = OP( qRed(d), qRed(s)); |
|
2535 |
int b = OP( qBlue(d), qBlue(s)); |
|
2536 |
int g = OP(qGreen(d), qGreen(s)); |
|
2537 |
int a = mix_alpha(da, sa); |
|
2538 |
#undef OP |
|
2539 |
||
2540 |
coverage.store(&dest[i], qRgba(r, g, b, a)); |
|
2541 |
} |
|
2542 |
} |
|
2543 |
||
2544 |
static void QT_FASTCALL comp_func_Difference(uint *dest, const uint *src, int length, uint const_alpha) |
|
2545 |
{ |
|
2546 |
if (const_alpha == 255) |
|
2547 |
comp_func_Difference_impl(dest, src, length, QFullCoverage()); |
|
2548 |
else |
|
2549 |
comp_func_Difference_impl(dest, src, length, QPartialCoverage(const_alpha)); |
|
2550 |
} |
|
2551 |
||
2552 |
/* |
|
2553 |
Dca' = (Sca.Da + Dca.Sa - 2.Sca.Dca) + Sca.(1 - Da) + Dca.(1 - Sa) |
|
2554 |
*/ |
|
2555 |
template <typename T> |
|
2556 |
Q_STATIC_TEMPLATE_FUNCTION inline void QT_FASTCALL comp_func_solid_Exclusion_impl(uint *dest, int length, uint color, const T &coverage) |
|
2557 |
{ |
|
2558 |
int sa = qAlpha(color); |
|
2559 |
int sr = qRed(color); |
|
2560 |
int sg = qGreen(color); |
|
2561 |
int sb = qBlue(color); |
|
2562 |
||
2563 |
PRELOAD_INIT(dest) |
|
2564 |
for (int i = 0; i < length; ++i) { |
|
2565 |
PRELOAD_COND(dest) |
|
2566 |
uint d = dest[i]; |
|
2567 |
int da = qAlpha(d); |
|
2568 |
||
2569 |
#define OP(a, b) (a + b - qt_div_255(2*(a*b))) |
|
2570 |
int r = OP( qRed(d), sr); |
|
2571 |
int b = OP( qBlue(d), sb); |
|
2572 |
int g = OP(qGreen(d), sg); |
|
2573 |
int a = mix_alpha(da, sa); |
|
2574 |
#undef OP |
|
2575 |
||
2576 |
coverage.store(&dest[i], qRgba(r, g, b, a)); |
|
2577 |
} |
|
2578 |
} |
|
2579 |
||
2580 |
static void QT_FASTCALL comp_func_solid_Exclusion(uint *dest, int length, uint color, uint const_alpha) |
|
2581 |
{ |
|
2582 |
if (const_alpha == 255) |
|
2583 |
comp_func_solid_Exclusion_impl(dest, length, color, QFullCoverage()); |
|
2584 |
else |
|
2585 |
comp_func_solid_Exclusion_impl(dest, length, color, QPartialCoverage(const_alpha)); |
|
2586 |
} |
|
2587 |
||
2588 |
template <typename T> |
|
2589 |
Q_STATIC_TEMPLATE_FUNCTION inline void comp_func_Exclusion_impl(uint *dest, const uint *src, int length, const T &coverage) |
|
2590 |
{ |
|
2591 |
PRELOAD_INIT2(dest, src) |
|
2592 |
for (int i = 0; i < length; ++i) { |
|
2593 |
PRELOAD_COND2(dest, src) |
|
2594 |
uint d = dest[i]; |
|
2595 |
uint s = src[i]; |
|
2596 |
||
2597 |
int da = qAlpha(d); |
|
2598 |
int sa = qAlpha(s); |
|
2599 |
||
2600 |
#define OP(a, b) (a + b - ((a*b) >> 7)) |
|
2601 |
int r = OP( qRed(d), qRed(s)); |
|
2602 |
int b = OP( qBlue(d), qBlue(s)); |
|
2603 |
int g = OP(qGreen(d), qGreen(s)); |
|
2604 |
int a = mix_alpha(da, sa); |
|
2605 |
#undef OP |
|
2606 |
||
2607 |
coverage.store(&dest[i], qRgba(r, g, b, a)); |
|
2608 |
} |
|
2609 |
} |
|
2610 |
||
2611 |
static void QT_FASTCALL comp_func_Exclusion(uint *dest, const uint *src, int length, uint const_alpha) |
|
2612 |
{ |
|
2613 |
if (const_alpha == 255) |
|
2614 |
comp_func_Exclusion_impl(dest, src, length, QFullCoverage()); |
|
2615 |
else |
|
2616 |
comp_func_Exclusion_impl(dest, src, length, QPartialCoverage(const_alpha)); |
|
2617 |
} |
|
2618 |
||
2619 |
#if defined(Q_CC_RVCT) |
|
2620 |
// Restore pragma state from previous #pragma arm |
|
2621 |
# pragma pop |
|
2622 |
#endif |
|
2623 |
||
2624 |
static void QT_FASTCALL rasterop_solid_SourceOrDestination(uint *dest, |
|
2625 |
int length, |
|
2626 |
uint color, |
|
2627 |
uint const_alpha) |
|
2628 |
{ |
|
2629 |
Q_UNUSED(const_alpha); |
|
2630 |
while (length--) |
|
2631 |
*dest++ |= color; |
|
2632 |
} |
|
2633 |
||
2634 |
static void QT_FASTCALL rasterop_SourceOrDestination(uint *dest, |
|
2635 |
const uint *src, |
|
2636 |
int length, |
|
2637 |
uint const_alpha) |
|
2638 |
{ |
|
2639 |
Q_UNUSED(const_alpha); |
|
2640 |
while (length--) |
|
2641 |
*dest++ |= *src++; |
|
2642 |
} |
|
2643 |
||
2644 |
static void QT_FASTCALL rasterop_solid_SourceAndDestination(uint *dest, |
|
2645 |
int length, |
|
2646 |
uint color, |
|
2647 |
uint const_alpha) |
|
2648 |
{ |
|
2649 |
Q_UNUSED(const_alpha); |
|
2650 |
color |= 0xff000000; |
|
2651 |
while (length--) |
|
2652 |
*dest++ &= color; |
|
2653 |
} |
|
2654 |
||
2655 |
static void QT_FASTCALL rasterop_SourceAndDestination(uint *dest, |
|
2656 |
const uint *src, |
|
2657 |
int length, |
|
2658 |
uint const_alpha) |
|
2659 |
{ |
|
2660 |
Q_UNUSED(const_alpha); |
|
2661 |
while (length--) { |
|
2662 |
*dest = (*src & *dest) | 0xff000000; |
|
2663 |
++dest; ++src; |
|
2664 |
} |
|
2665 |
} |
|
2666 |
||
2667 |
static void QT_FASTCALL rasterop_solid_SourceXorDestination(uint *dest, |
|
2668 |
int length, |
|
2669 |
uint color, |
|
2670 |
uint const_alpha) |
|
2671 |
{ |
|
2672 |
Q_UNUSED(const_alpha); |
|
2673 |
color &= 0x00ffffff; |
|
2674 |
while (length--) |
|
2675 |
*dest++ ^= color; |
|
2676 |
} |
|
2677 |
||
2678 |
static void QT_FASTCALL rasterop_SourceXorDestination(uint *dest, |
|
2679 |
const uint *src, |
|
2680 |
int length, |
|
2681 |
uint const_alpha) |
|
2682 |
{ |
|
2683 |
Q_UNUSED(const_alpha); |
|
2684 |
while (length--) { |
|
2685 |
*dest = (*src ^ *dest) | 0xff000000; |
|
2686 |
++dest; ++src; |
|
2687 |
} |
|
2688 |
} |
|
2689 |
||
2690 |
static void QT_FASTCALL rasterop_solid_NotSourceAndNotDestination(uint *dest, |
|
2691 |
int length, |
|
2692 |
uint color, |
|
2693 |
uint const_alpha) |
|
2694 |
{ |
|
2695 |
Q_UNUSED(const_alpha); |
|
2696 |
color = ~color; |
|
2697 |
while (length--) { |
|
2698 |
*dest = (color & ~(*dest)) | 0xff000000; |
|
2699 |
++dest; |
|
2700 |
} |
|
2701 |
} |
|
2702 |
||
2703 |
static void QT_FASTCALL rasterop_NotSourceAndNotDestination(uint *dest, |
|
2704 |
const uint *src, |
|
2705 |
int length, |
|
2706 |
uint const_alpha) |
|
2707 |
{ |
|
2708 |
Q_UNUSED(const_alpha); |
|
2709 |
while (length--) { |
|
2710 |
*dest = (~(*src) & ~(*dest)) | 0xff000000; |
|
2711 |
++dest; ++src; |
|
2712 |
} |
|
2713 |
} |
|
2714 |
||
2715 |
static void QT_FASTCALL rasterop_solid_NotSourceOrNotDestination(uint *dest, |
|
2716 |
int length, |
|
2717 |
uint color, |
|
2718 |
uint const_alpha) |
|
2719 |
{ |
|
2720 |
Q_UNUSED(const_alpha); |
|
2721 |
color = ~color | 0xff000000; |
|
2722 |
while (length--) { |
|
2723 |
*dest = color | ~(*dest); |
|
2724 |
++dest; |
|
2725 |
} |
|
2726 |
} |
|
2727 |
||
2728 |
static void QT_FASTCALL rasterop_NotSourceOrNotDestination(uint *dest, |
|
2729 |
const uint *src, |
|
2730 |
int length, |
|
2731 |
uint const_alpha) |
|
2732 |
{ |
|
2733 |
Q_UNUSED(const_alpha); |
|
2734 |
while (length--) { |
|
2735 |
*dest = ~(*src) | ~(*dest) | 0xff000000; |
|
2736 |
++dest; ++src; |
|
2737 |
} |
|
2738 |
} |
|
2739 |
||
2740 |
static void QT_FASTCALL rasterop_solid_NotSourceXorDestination(uint *dest, |
|
2741 |
int length, |
|
2742 |
uint color, |
|
2743 |
uint const_alpha) |
|
2744 |
{ |
|
2745 |
Q_UNUSED(const_alpha); |
|
2746 |
color = ~color & 0x00ffffff; |
|
2747 |
while (length--) { |
|
2748 |
*dest = color ^ (*dest); |
|
2749 |
++dest; |
|
2750 |
} |
|
2751 |
} |
|
2752 |
||
2753 |
static void QT_FASTCALL rasterop_NotSourceXorDestination(uint *dest, |
|
2754 |
const uint *src, |
|
2755 |
int length, |
|
2756 |
uint const_alpha) |
|
2757 |
{ |
|
2758 |
Q_UNUSED(const_alpha); |
|
2759 |
while (length--) { |
|
2760 |
*dest = ((~(*src)) ^ (*dest)) | 0xff000000; |
|
2761 |
++dest; ++src; |
|
2762 |
} |
|
2763 |
} |
|
2764 |
||
2765 |
static void QT_FASTCALL rasterop_solid_NotSource(uint *dest, int length, |
|
2766 |
uint color, uint const_alpha) |
|
2767 |
{ |
|
2768 |
Q_UNUSED(const_alpha); |
|
2769 |
qt_memfill(dest, ~color | 0xff000000, length); |
|
2770 |
} |
|
2771 |
||
2772 |
static void QT_FASTCALL rasterop_NotSource(uint *dest, const uint *src, |
|
2773 |
int length, uint const_alpha) |
|
2774 |
{ |
|
2775 |
Q_UNUSED(const_alpha); |
|
2776 |
while (length--) |
|
2777 |
*dest++ = ~(*src++) | 0xff000000; |
|
2778 |
} |
|
2779 |
||
2780 |
static void QT_FASTCALL rasterop_solid_NotSourceAndDestination(uint *dest, |
|
2781 |
int length, |
|
2782 |
uint color, |
|
2783 |
uint const_alpha) |
|
2784 |
{ |
|
2785 |
Q_UNUSED(const_alpha); |
|
2786 |
color = ~color | 0xff000000; |
|
2787 |
while (length--) { |
|
2788 |
*dest = color & *dest; |
|
2789 |
++dest; |
|
2790 |
} |
|
2791 |
} |
|
2792 |
||
2793 |
static void QT_FASTCALL rasterop_NotSourceAndDestination(uint *dest, |
|
2794 |
const uint *src, |
|
2795 |
int length, |
|
2796 |
uint const_alpha) |
|
2797 |
{ |
|
2798 |
Q_UNUSED(const_alpha); |
|
2799 |
while (length--) { |
|
2800 |
*dest = (~(*src) & *dest) | 0xff000000; |
|
2801 |
++dest; ++src; |
|
2802 |
} |
|
2803 |
} |
|
2804 |
||
2805 |
static void QT_FASTCALL rasterop_solid_SourceAndNotDestination(uint *dest, |
|
2806 |
int length, |
|
2807 |
uint color, |
|
2808 |
uint const_alpha) |
|
2809 |
{ |
|
2810 |
Q_UNUSED(const_alpha); |
|
2811 |
while (length--) { |
|
2812 |
*dest = (color & ~(*dest)) | 0xff000000; |
|
2813 |
++dest; |
|
2814 |
} |
|
2815 |
} |
|
2816 |
||
2817 |
static void QT_FASTCALL rasterop_SourceAndNotDestination(uint *dest, |
|
2818 |
const uint *src, |
|
2819 |
int length, |
|
2820 |
uint const_alpha) |
|
2821 |
{ |
|
2822 |
Q_UNUSED(const_alpha); |
|
2823 |
while (length--) { |
|
2824 |
*dest = (*src & ~(*dest)) | 0xff000000; |
|
2825 |
++dest; ++src; |
|
2826 |
} |
|
2827 |
} |
|
2828 |
||
2829 |
static const CompositionFunctionSolid functionForModeSolid_C[] = { |
|
2830 |
comp_func_solid_SourceOver, |
|
2831 |
comp_func_solid_DestinationOver, |
|
2832 |
comp_func_solid_Clear, |
|
2833 |
comp_func_solid_Source, |
|
2834 |
comp_func_solid_Destination, |
|
2835 |
comp_func_solid_SourceIn, |
|
2836 |
comp_func_solid_DestinationIn, |
|
2837 |
comp_func_solid_SourceOut, |
|
2838 |
comp_func_solid_DestinationOut, |
|
2839 |
comp_func_solid_SourceAtop, |
|
2840 |
comp_func_solid_DestinationAtop, |
|
2841 |
comp_func_solid_XOR, |
|
2842 |
comp_func_solid_Plus, |
|
2843 |
comp_func_solid_Multiply, |
|
2844 |
comp_func_solid_Screen, |
|
2845 |
comp_func_solid_Overlay, |
|
2846 |
comp_func_solid_Darken, |
|
2847 |
comp_func_solid_Lighten, |
|
2848 |
comp_func_solid_ColorDodge, |
|
2849 |
comp_func_solid_ColorBurn, |
|
2850 |
comp_func_solid_HardLight, |
|
2851 |
comp_func_solid_SoftLight, |
|
2852 |
comp_func_solid_Difference, |
|
2853 |
comp_func_solid_Exclusion, |
|
2854 |
rasterop_solid_SourceOrDestination, |
|
2855 |
rasterop_solid_SourceAndDestination, |
|
2856 |
rasterop_solid_SourceXorDestination, |
|
2857 |
rasterop_solid_NotSourceAndNotDestination, |
|
2858 |
rasterop_solid_NotSourceOrNotDestination, |
|
2859 |
rasterop_solid_NotSourceXorDestination, |
|
2860 |
rasterop_solid_NotSource, |
|
2861 |
rasterop_solid_NotSourceAndDestination, |
|
2862 |
rasterop_solid_SourceAndNotDestination |
|
2863 |
}; |
|
2864 |
||
2865 |
static const CompositionFunctionSolid *functionForModeSolid = functionForModeSolid_C; |
|
2866 |
||
2867 |
static const CompositionFunction functionForMode_C[] = { |
|
2868 |
comp_func_SourceOver, |
|
2869 |
comp_func_DestinationOver, |
|
2870 |
comp_func_Clear, |
|
2871 |
comp_func_Source, |
|
2872 |
comp_func_Destination, |
|
2873 |
comp_func_SourceIn, |
|
2874 |
comp_func_DestinationIn, |
|
2875 |
comp_func_SourceOut, |
|
2876 |
comp_func_DestinationOut, |
|
2877 |
comp_func_SourceAtop, |
|
2878 |
comp_func_DestinationAtop, |
|
2879 |
comp_func_XOR, |
|
2880 |
comp_func_Plus, |
|
2881 |
comp_func_Multiply, |
|
2882 |
comp_func_Screen, |
|
2883 |
comp_func_Overlay, |
|
2884 |
comp_func_Darken, |
|
2885 |
comp_func_Lighten, |
|
2886 |
comp_func_ColorDodge, |
|
2887 |
comp_func_ColorBurn, |
|
2888 |
comp_func_HardLight, |
|
2889 |
comp_func_SoftLight, |
|
2890 |
comp_func_Difference, |
|
2891 |
comp_func_Exclusion, |
|
2892 |
rasterop_SourceOrDestination, |
|
2893 |
rasterop_SourceAndDestination, |
|
2894 |
rasterop_SourceXorDestination, |
|
2895 |
rasterop_NotSourceAndNotDestination, |
|
2896 |
rasterop_NotSourceOrNotDestination, |
|
2897 |
rasterop_NotSourceXorDestination, |
|
2898 |
rasterop_NotSource, |
|
2899 |
rasterop_NotSourceAndDestination, |
|
2900 |
rasterop_SourceAndNotDestination |
|
2901 |
}; |
|
2902 |
||
2903 |
static const CompositionFunction *functionForMode = functionForMode_C; |
|
2904 |
||
2905 |
static TextureBlendType getBlendType(const QSpanData *data) |
|
2906 |
{ |
|
2907 |
TextureBlendType ft; |
|
2908 |
if (data->txop <= QTransform::TxTranslate) |
|
2909 |
if (data->texture.type == QTextureData::Tiled) |
|
2910 |
ft = BlendTiled; |
|
2911 |
else |
|
2912 |
ft = BlendUntransformed; |
|
2913 |
else if (data->bilinear) |
|
2914 |
if (data->texture.type == QTextureData::Tiled) |
|
2915 |
ft = BlendTransformedBilinearTiled; |
|
2916 |
else |
|
2917 |
ft = BlendTransformedBilinear; |
|
2918 |
else |
|
2919 |
if (data->texture.type == QTextureData::Tiled) |
|
2920 |
ft = BlendTransformedTiled; |
|
2921 |
else |
|
2922 |
ft = BlendTransformed; |
|
2923 |
return ft; |
|
2924 |
} |
|
2925 |
||
2926 |
static inline Operator getOperator(const QSpanData *data, const QSpan *spans, int spanCount) |
|
2927 |
{ |
|
2928 |
Operator op; |
|
2929 |
bool solidSource = false; |
|
2930 |
||
2931 |
switch(data->type) { |
|
2932 |
case QSpanData::Solid: |
|
2933 |
solidSource = (qAlpha(data->solid.color) == 255); |
|
2934 |
break; |
|
2935 |
case QSpanData::LinearGradient: |
|
2936 |
solidSource = !data->gradient.alphaColor; |
|
2937 |
getLinearGradientValues(&op.linear, data); |
|
2938 |
op.src_fetch = fetchLinearGradient; |
|
2939 |
break; |
|
2940 |
case QSpanData::RadialGradient: |
|
2941 |
solidSource = !data->gradient.alphaColor; |
|
2942 |
getRadialGradientValues(&op.radial, data); |
|
2943 |
op.src_fetch = fetchRadialGradient; |
|
2944 |
break; |
|
2945 |
case QSpanData::ConicalGradient: |
|
2946 |
solidSource = !data->gradient.alphaColor; |
|
2947 |
op.src_fetch = fetchConicalGradient; |
|
2948 |
break; |
|
2949 |
case QSpanData::Texture: |
|
2950 |
op.src_fetch = sourceFetch[getBlendType(data)][data->texture.format]; |
|
2951 |
solidSource = !data->texture.hasAlpha; |
|
2952 |
default: |
|
2953 |
break; |
|
2954 |
} |
|
2955 |
||
2956 |
op.mode = data->rasterBuffer->compositionMode; |
|
2957 |
if (op.mode == QPainter::CompositionMode_SourceOver && solidSource) |
|
2958 |
op.mode = QPainter::CompositionMode_Source; |
|
2959 |
||
2960 |
op.dest_fetch = destFetchProc[data->rasterBuffer->format]; |
|
2961 |
if (op.mode == QPainter::CompositionMode_Source) { |
|
2962 |
switch (data->rasterBuffer->format) { |
|
2963 |
case QImage::Format_RGB32: |
|
2964 |
case QImage::Format_ARGB32_Premultiplied: |
|
2965 |
// don't clear dest_fetch as it sets up the pointer correctly to save one copy |
|
2966 |
break; |
|
2967 |
default: { |
|
2968 |
const QSpan *lastSpan = spans + spanCount; |
|
2969 |
bool alphaSpans = false; |
|
2970 |
while (spans < lastSpan) { |
|
2971 |
if (spans->coverage != 255) { |
|
2972 |
alphaSpans = true; |
|
2973 |
break; |
|
2974 |
} |
|
2975 |
++spans; |
|
2976 |
} |
|
2977 |
if (!alphaSpans) |
|
2978 |
op.dest_fetch = 0; |
|
2979 |
} |
|
2980 |
} |
|
2981 |
} |
|
2982 |
||
2983 |
op.dest_store = destStoreProc[data->rasterBuffer->format]; |
|
2984 |
||
2985 |
op.funcSolid = functionForModeSolid[op.mode]; |
|
2986 |
op.func = functionForMode[op.mode]; |
|
2987 |
||
2988 |
return op; |
|
2989 |
} |
|
2990 |
||
2991 |
||
2992 |
||
2993 |
// -------------------- blend methods --------------------- |
|
2994 |
||
2995 |
enum SpanMethod { |
|
2996 |
RegularSpans, |
|
2997 |
CallbackSpans |
|
2998 |
}; |
|
2999 |
||
3000 |
#if !defined(Q_CC_SUN) |
|
3001 |
static |
|
3002 |
#endif |
|
3003 |
void drawBufferSpan(QSpanData *data, const uint *buffer, int bufsize, |
|
3004 |
int x, int y, int length, uint const_alpha) |
|
3005 |
{ |
|
3006 |
#if defined (Q_WS_QWS) && !defined(QT_NO_RASTERCALLBACKS) |
|
3007 |
data->rasterEngine->drawBufferSpan(buffer, bufsize, x, y, length, const_alpha); |
|
3008 |
#else |
|
3009 |
Q_UNUSED(data); |
|
3010 |
Q_UNUSED(buffer); |
|
3011 |
Q_UNUSED(bufsize); |
|
3012 |
Q_UNUSED(x); |
|
3013 |
Q_UNUSED(y); |
|
3014 |
Q_UNUSED(length); |
|
3015 |
Q_UNUSED(const_alpha); |
|
3016 |
#endif |
|
3017 |
} |
|
3018 |
||
3019 |
#if !defined(Q_CC_SUN) |
|
3020 |
static |
|
3021 |
#endif |
|
3022 |
void blend_color_generic(int count, const QSpan *spans, void *userData) |
|
3023 |
{ |
|
3024 |
QSpanData *data = reinterpret_cast<QSpanData *>(userData); |
|
3025 |
uint buffer[buffer_size]; |
|
3026 |
Operator op = getOperator(data, spans, count); |
|
3027 |
||
3028 |
while (count--) { |
|
3029 |
int x = spans->x; |
|
3030 |
int length = spans->len; |
|
3031 |
while (length) { |
|
3032 |
int l = qMin(buffer_size, length); |
|
3033 |
uint *dest = op.dest_fetch ? op.dest_fetch(buffer, data->rasterBuffer, x, spans->y, l) : buffer; |
|
3034 |
op.funcSolid(dest, l, data->solid.color, spans->coverage); |
|
3035 |
if (op.dest_store) |
|
3036 |
op.dest_store(data->rasterBuffer, x, spans->y, dest, l); |
|
3037 |
length -= l; |
|
3038 |
x += l; |
|
3039 |
} |
|
3040 |
++spans; |
|
3041 |
} |
|
3042 |
} |
|
3043 |
||
3044 |
#if defined (Q_WS_QWS) && !defined(QT_NO_RASTERCALLBACKS) |
|
3045 |
static void blend_color_generic_callback(int count, const QSpan *spans, void *userData) |
|
3046 |
{ |
|
3047 |
// ### Falcon |
|
3048 |
Q_UNUSED(count); |
|
3049 |
Q_UNUSED(spans); |
|
3050 |
Q_UNUSED(userData); |
|
3051 |
// QSpanData *data = reinterpret_cast<QSpanData*>(userData); |
|
3052 |
// data->rasterEngine->drawColorSpans(spans, count, data->solid.color); |
|
3053 |
} |
|
3054 |
#endif // QT_NO_RASTERCALLBACKS |
|
3055 |
||
3056 |
static void blend_color_argb(int count, const QSpan *spans, void *userData) |
|
3057 |
{ |
|
3058 |
QSpanData *data = reinterpret_cast<QSpanData *>(userData); |
|
3059 |
||
3060 |
Operator op = getOperator(data, spans, count); |
|
3061 |
||
3062 |
if (op.mode == QPainter::CompositionMode_Source) { |
|
3063 |
// inline for performance |
|
3064 |
while (count--) { |
|
3065 |
uint *target = ((uint *)data->rasterBuffer->scanLine(spans->y)) + spans->x; |
|
3066 |
if (spans->coverage == 255) { |
|
3067 |
QT_MEMFILL_UINT(target, spans->len, data->solid.color); |
|
3068 |
} else { |
|
3069 |
uint c = BYTE_MUL(data->solid.color, spans->coverage); |
|
3070 |
int ialpha = 255 - spans->coverage; |
|
3071 |
for (int i = 0; i < spans->len; ++i) |
|
3072 |
target[i] = c + BYTE_MUL(target[i], ialpha); |
|
3073 |
} |
|
3074 |
++spans; |
|
3075 |
} |
|
3076 |
return; |
|
3077 |
} |
|
3078 |
||
3079 |
while (count--) { |
|
3080 |
uint *target = ((uint *)data->rasterBuffer->scanLine(spans->y)) + spans->x; |
|
3081 |
op.funcSolid(target, spans->len, data->solid.color, spans->coverage); |
|
3082 |
++spans; |
|
3083 |
} |
|
3084 |
} |
|
3085 |
||
3086 |
template <class T> |
|
3087 |
Q_STATIC_TEMPLATE_FUNCTION void blendColor(int count, const QSpan *spans, void *userData) |
|
3088 |
{ |
|
3089 |
QSpanData *data = reinterpret_cast<QSpanData *>(userData); |
|
3090 |
Operator op = getOperator(data, spans, count); |
|
3091 |
||
3092 |
if (op.mode == QPainter::CompositionMode_Source) { |
|
3093 |
const T c = qt_colorConvert<T, quint32p>(quint32p::fromRawData(data->solid.color), 0); |
|
3094 |
while (count--) { |
|
3095 |
T *target = ((T*)data->rasterBuffer->scanLine(spans->y)) |
|
3096 |
+ spans->x; |
|
3097 |
if (spans->coverage == 255) { |
|
3098 |
qt_memfill(target, c, spans->len); |
|
3099 |
} else { |
|
3100 |
const quint8 alpha = T::alpha(spans->coverage); |
|
3101 |
const T color = c.byte_mul(alpha); |
|
3102 |
const int ialpha = T::ialpha(spans->coverage); |
|
3103 |
const T *end = target + spans->len; |
|
3104 |
while (target < end) { |
|
3105 |
*target = color + target->byte_mul(ialpha); |
|
3106 |
++target; |
|
3107 |
} |
|
3108 |
} |
|
3109 |
++spans; |
|
3110 |
} |
|
3111 |
return; |
|
3112 |
} |
|
3113 |
||
3114 |
if (op.mode == QPainter::CompositionMode_SourceOver) { |
|
3115 |
while (count--) { |
|
3116 |
const quint32 color = BYTE_MUL(data->solid.color, spans->coverage); |
|
3117 |
const T c = qt_colorConvert<T, quint32p>(quint32p::fromRawData(color), 0); |
|
3118 |
const quint8 ialpha = T::alpha(qAlpha(~color)); |
|
3119 |
T *target = ((T*)data->rasterBuffer->scanLine(spans->y)) + spans->x; |
|
3120 |
const T *end = target + spans->len; |
|
3121 |
while (target != end) { |
|
3122 |
*target = c + target->byte_mul(ialpha); |
|
3123 |
++target; |
|
3124 |
} |
|
3125 |
++spans; |
|
3126 |
} |
|
3127 |
return; |
|
3128 |
} |
|
3129 |
||
3130 |
blend_color_generic(count, spans, userData); |
|
3131 |
} |
|
3132 |
||
3133 |
#define SPANFUNC_POINTER_BLENDCOLOR(DST) blendColor<DST> |
|
3134 |
||
3135 |
static void blend_color_rgb16(int count, const QSpan *spans, void *userData) |
|
3136 |
{ |
|
3137 |
QSpanData *data = reinterpret_cast<QSpanData *>(userData); |
|
3138 |
||
3139 |
/* |
|
3140 |
We duplicate a little logic from getOperator() and calculate the |
|
3141 |
composition mode directly. This allows blend_color_rgb16 to be used |
|
3142 |
from qt_gradient_quint16 with minimal overhead. |
|
3143 |
*/ |
|
3144 |
QPainter::CompositionMode mode = data->rasterBuffer->compositionMode; |
|
3145 |
if (mode == QPainter::CompositionMode_SourceOver && |
|
3146 |
qAlpha(data->solid.color) == 255) |
|
3147 |
mode = QPainter::CompositionMode_Source; |
|
3148 |
||
3149 |
if (mode == QPainter::CompositionMode_Source) { |
|
3150 |
// inline for performance |
|
3151 |
ushort c = qConvertRgb32To16(data->solid.color); |
|
3152 |
while (count--) { |
|
3153 |
ushort *target = ((ushort *)data->rasterBuffer->scanLine(spans->y)) + spans->x; |
|
3154 |
if (spans->coverage == 255) { |
|
3155 |
QT_MEMFILL_USHORT(target, spans->len, c); |
|
3156 |
} else { |
|
3157 |
ushort color = BYTE_MUL_RGB16(c, spans->coverage); |
|
3158 |
int ialpha = 255 - spans->coverage; |
|
3159 |
const ushort *end = target + spans->len; |
|
3160 |
while (target < end) { |
|
3161 |
*target = color + BYTE_MUL_RGB16(*target, ialpha); |
|
3162 |
++target; |
|
3163 |
} |
|
3164 |
} |
|
3165 |
++spans; |
|
3166 |
} |
|
3167 |
return; |
|
3168 |
} |
|
3169 |
||
3170 |
if (mode == QPainter::CompositionMode_SourceOver) { |
|
3171 |
while (count--) { |
|
3172 |
uint color = BYTE_MUL(data->solid.color, spans->coverage); |
|
3173 |
int ialpha = qAlpha(~color); |
|
3174 |
ushort c = qConvertRgb32To16(color); |
|
3175 |
ushort *target = ((ushort *)data->rasterBuffer->scanLine(spans->y)) + spans->x; |
|
3176 |
int len = spans->len; |
|
3177 |
bool pre = (((quintptr)target) & 0x3) != 0; |
|
3178 |
bool post = false; |
|
3179 |
if (pre) { |
|
3180 |
// skip to word boundary |
|
3181 |
*target = c + BYTE_MUL_RGB16(*target, ialpha); |
|
3182 |
++target; |
|
3183 |
--len; |
|
3184 |
} |
|
3185 |
if (len & 0x1) { |
|
3186 |
post = true; |
|
3187 |
--len; |
|
3188 |
} |
|
3189 |
uint *target32 = (uint*)target; |
|
3190 |
uint c32 = c | (c<<16); |
|
3191 |
len >>= 1; |
|
3192 |
uint salpha = (ialpha+1) >> 3; // calculate here rather than in loop |
|
3193 |
while (len--) { |
|
3194 |
// blend full words |
|
3195 |
*target32 = c32 + BYTE_MUL_RGB16_32(*target32, salpha); |
|
3196 |
++target32; |
|
3197 |
target += 2; |
|
3198 |
} |
|
3199 |
if (post) { |
|
3200 |
// one last pixel beyond a full word |
|
3201 |
*target = c + BYTE_MUL_RGB16(*target, ialpha); |
|
3202 |
} |
|
3203 |
++spans; |
|
3204 |
} |
|
3205 |
return; |
|
3206 |
} |
|
3207 |
||
3208 |
blend_color_generic(count, spans, userData); |
|
3209 |
} |
|
3210 |
||
3211 |
template <typename T> |
|
3212 |
void handleSpans(int count, const QSpan *spans, const QSpanData *data, T &handler) |
|
3213 |
{ |
|
3214 |
uint const_alpha = 256; |
|
3215 |
if (data->type == QSpanData::Texture) |
|
3216 |
const_alpha = data->texture.const_alpha; |
|
3217 |
||
3218 |
int coverage = 0; |
|
3219 |
while (count) { |
|
3220 |
int x = spans->x; |
|
3221 |
const int y = spans->y; |
|
3222 |
int right = x + spans->len; |
|
3223 |
||
3224 |
// compute length of adjacent spans |
|
3225 |
for (int i = 1; i < count && spans[i].y == y && spans[i].x == right; ++i) |
|
3226 |
right += spans[i].len; |
|
3227 |
int length = right - x; |
|
3228 |
||
3229 |
while (length) { |
|
3230 |
int l = qMin(buffer_size, length); |
|
3231 |
length -= l; |
|
3232 |
||
3233 |
int process_length = l; |
|
3234 |
int process_x = x; |
|
3235 |
||
3236 |
const uint *src = handler.fetch(process_x, y, process_length); |
|
3237 |
int offset = 0; |
|
3238 |
while (l > 0) { |
|
3239 |
if (x == spans->x) // new span? |
|
3240 |
coverage = (spans->coverage * const_alpha) >> 8; |
|
3241 |
||
3242 |
int right = spans->x + spans->len; |
|
3243 |
int len = qMin(l, right - x); |
|
3244 |
||
3245 |
handler.process(x, y, len, coverage, src, offset); |
|
3246 |
||
3247 |
l -= len; |
|
3248 |
x += len; |
|
3249 |
offset += len; |
|
3250 |
||
3251 |
if (x == right) { // done with current span? |
|
3252 |
++spans; |
|
3253 |
--count; |
|
3254 |
} |
|
3255 |
} |
|
3256 |
handler.store(process_x, y, process_length); |
|
3257 |
} |
|
3258 |
} |
|
3259 |
} |
|
3260 |
||
3261 |
struct QBlendBase |
|
3262 |
{ |
|
3263 |
QBlendBase(QSpanData *d, Operator o) |
|
3264 |
: data(d) |
|
3265 |
, op(o) |
|
3266 |
, dest(0) |
|
3267 |
{ |
|
3268 |
} |
|
3269 |
||
3270 |
QSpanData *data; |
|
3271 |
Operator op; |
|
3272 |
||
3273 |
uint *dest; |
|
3274 |
||
3275 |
uint buffer[buffer_size]; |
|
3276 |
uint src_buffer[buffer_size]; |
|
3277 |
}; |
|
3278 |
||
3279 |
template <SpanMethod spanMethod> |
|
3280 |
class BlendSrcGeneric : public QBlendBase |
|
3281 |
{ |
|
3282 |
public: |
|
3283 |
BlendSrcGeneric(QSpanData *d, Operator o) |
|
3284 |
: QBlendBase(d, o) |
|
3285 |
{ |
|
3286 |
} |
|
3287 |
||
3288 |
const uint *fetch(int x, int y, int len) |
|
3289 |
{ |
|
3290 |
if (spanMethod == RegularSpans) |
|
3291 |
dest = op.dest_fetch ? op.dest_fetch(buffer, data->rasterBuffer, x, y, len) : buffer; |
|
3292 |
||
3293 |
return op.src_fetch(src_buffer, &op, data, y, x, len); |
|
3294 |
} |
|
3295 |
||
3296 |
void process(int x, int y, int len, int coverage, const uint *src, int offset) |
|
3297 |
{ |
|
3298 |
if (spanMethod == RegularSpans) |
|
3299 |
op.func(dest + offset, src + offset, len, coverage); |
|
3300 |
else |
|
3301 |
drawBufferSpan(data, src + offset, len, x, y, len, coverage); |
|
3302 |
} |
|
3303 |
||
3304 |
void store(int x, int y, int len) |
|
3305 |
{ |
|
3306 |
if (spanMethod == RegularSpans && op.dest_store) { |
|
3307 |
op.dest_store(data->rasterBuffer, x, y, dest, len); |
|
3308 |
} |
|
3309 |
} |
|
3310 |
}; |
|
3311 |
||
3312 |
template <SpanMethod spanMethod> |
|
3313 |
Q_STATIC_TEMPLATE_FUNCTION void blend_src_generic(int count, const QSpan *spans, void *userData) |
|
3314 |
{ |
|
3315 |
QSpanData *data = reinterpret_cast<QSpanData *>(userData); |
|
3316 |
BlendSrcGeneric<spanMethod> blend(data, getOperator(data, spans, count)); |
|
3317 |
handleSpans(count, spans, data, blend); |
|
3318 |
} |
|
3319 |
||
3320 |
template <SpanMethod spanMethod> |
|
3321 |
Q_STATIC_TEMPLATE_FUNCTION void blend_untransformed_generic(int count, const QSpan *spans, void *userData) |
|
3322 |
{ |
|
3323 |
QSpanData *data = reinterpret_cast<QSpanData *>(userData); |
|
3324 |
||
3325 |
uint buffer[buffer_size]; |
|
3326 |
uint src_buffer[buffer_size]; |
|
3327 |
Operator op = getOperator(data, spans, count); |
|
3328 |
||
3329 |
const int image_width = data->texture.width; |
|
3330 |
const int image_height = data->texture.height; |
|
3331 |
int xoff = -qRound(-data->dx); |
|
3332 |
int yoff = -qRound(-data->dy); |
|
3333 |
||
3334 |
while (count--) { |
|
3335 |
int x = spans->x; |
|
3336 |
int length = spans->len; |
|
3337 |
int sx = xoff + x; |
|
3338 |
int sy = yoff + spans->y; |
|
3339 |
if (sy >= 0 && sy < image_height && sx < image_width) { |
|
3340 |
if (sx < 0) { |
|
3341 |
x -= sx; |
|
3342 |
length += sx; |
|
3343 |
sx = 0; |
|
3344 |
} |
|
3345 |
if (sx + length > image_width) |
|
3346 |
length = image_width - sx; |
|
3347 |
if (length > 0) { |
|
3348 |
const int coverage = (spans->coverage * data->texture.const_alpha) >> 8; |
|
3349 |
while (length) { |
|
3350 |
int l = qMin(buffer_size, length); |
|
3351 |
const uint *src = op.src_fetch(src_buffer, &op, data, sy, sx, l); |
|
3352 |
if (spanMethod == RegularSpans) { |
|
3353 |
uint *dest = op.dest_fetch ? op.dest_fetch(buffer, data->rasterBuffer, x, spans->y, l) : buffer; |
|
3354 |
op.func(dest, src, l, coverage); |
|
3355 |
if (op.dest_store) |
|
3356 |
op.dest_store(data->rasterBuffer, x, spans->y, dest, l); |
|
3357 |
} else { |
|
3358 |
drawBufferSpan(data, src, l, x, spans->y, |
|
3359 |
l, coverage); |
|
3360 |
} |
|
3361 |
x += l; |
|
3362 |
sx += l; |
|
3363 |
length -= l; |
|
3364 |
} |
|
3365 |
} |
|
3366 |
} |
|
3367 |
++spans; |
|
3368 |
} |
|
3369 |
} |
|
3370 |
||
3371 |
template <SpanMethod spanMethod> |
|
3372 |
Q_STATIC_TEMPLATE_FUNCTION void blend_untransformed_argb(int count, const QSpan *spans, void *userData) |
|
3373 |
{ |
|
3374 |
QSpanData *data = reinterpret_cast<QSpanData *>(userData); |
|
3375 |
if (data->texture.format != QImage::Format_ARGB32_Premultiplied |
|
3376 |
&& data->texture.format != QImage::Format_RGB32) { |
|
3377 |
blend_untransformed_generic<spanMethod>(count, spans, userData); |
|
3378 |
return; |
|
3379 |
} |
|
3380 |
||
3381 |
Operator op = getOperator(data, spans, count); |
|
3382 |
||
3383 |
const int image_width = data->texture.width; |
|
3384 |
const int image_height = data->texture.height; |
|
3385 |
int xoff = -qRound(-data->dx); |
|
3386 |
int yoff = -qRound(-data->dy); |
|
3387 |
||
3388 |
while (count--) { |
|
3389 |
int x = spans->x; |
|
3390 |
int length = spans->len; |
|
3391 |
int sx = xoff + x; |
|
3392 |
int sy = yoff + spans->y; |
|
3393 |
if (sy >= 0 && sy < image_height && sx < image_width) { |
|
3394 |
if (sx < 0) { |
|
3395 |
x -= sx; |
|
3396 |
length += sx; |
|
3397 |
sx = 0; |
|
3398 |
} |
|
3399 |
if (sx + length > image_width) |
|
3400 |
length = image_width - sx; |
|
3401 |
if (length > 0) { |
|
3402 |
const int coverage = (spans->coverage * data->texture.const_alpha) >> 8; |
|
3403 |
const uint *src = (uint *)data->texture.scanLine(sy) + sx; |
|
3404 |
if (spanMethod == RegularSpans) { |
|
3405 |
uint *dest = ((uint *)data->rasterBuffer->scanLine(spans->y)) + x; |
|
3406 |
op.func(dest, src, length, coverage); |
|
3407 |
} else { |
|
3408 |
drawBufferSpan(data, src, length, x, |
|
3409 |
spans->y, length, coverage); |
|
3410 |
} |
|
3411 |
} |
|
3412 |
} |
|
3413 |
++spans; |
|
3414 |
} |
|
3415 |
} |
|
3416 |
||
3417 |
static inline quint16 interpolate_pixel_rgb16_255(quint16 x, quint8 a, |
|
3418 |
quint16 y, quint8 b) |
|
3419 |
{ |
|
3420 |
quint16 t = ((((x & 0x07e0) * a) + ((y & 0x07e0) * b)) >> 5) & 0x07e0; |
|
3421 |
t |= ((((x & 0xf81f) * a) + ((y & 0xf81f) * b)) >> 5) & 0xf81f; |
|
3422 |
||
3423 |
return t; |
|
3424 |
} |
|
3425 |
||
3426 |
static inline quint32 interpolate_pixel_rgb16x2_255(quint32 x, quint8 a, |
|
3427 |
quint32 y, quint8 b) |
|
3428 |
{ |
|
3429 |
uint t; |
|
3430 |
t = ((((x & 0xf81f07e0) >> 5) * a) + (((y & 0xf81f07e0) >> 5) * b)) & 0xf81f07e0; |
|
3431 |
t |= ((((x & 0x07e0f81f) * a) + ((y & 0x07e0f81f) * b)) >> 5) & 0x07e0f81f; |
|
3432 |
return t; |
|
3433 |
} |
|
3434 |
||
3435 |
static inline void blend_sourceOver_rgb16_rgb16(quint16 *dest, |
|
3436 |
const quint16 *src, |
|
3437 |
int length, |
|
3438 |
const quint8 alpha, |
|
3439 |
const quint8 ialpha) |
|
3440 |
{ |
|
3441 |
const int dstAlign = ((quintptr)dest) & 0x3; |
|
3442 |
if (dstAlign) { |
|
3443 |
*dest = interpolate_pixel_rgb16_255(*src, alpha, *dest, ialpha); |
|
3444 |
++dest; |
|
3445 |
++src; |
|
3446 |
--length; |
|
3447 |
} |
|
3448 |
const int srcAlign = ((quintptr)src) & 0x3; |
|
3449 |
int length32 = length >> 1; |
|
3450 |
if (length32 && srcAlign == 0) { |
|
3451 |
while (length32--) { |
|
3452 |
const quint32 *src32 = reinterpret_cast<const quint32*>(src); |
|
3453 |
quint32 *dest32 = reinterpret_cast<quint32*>(dest); |
|
3454 |
*dest32 = interpolate_pixel_rgb16x2_255(*src32, alpha, |
|
3455 |
*dest32, ialpha); |
|
3456 |
dest += 2; |
|
3457 |
src += 2; |
|
3458 |
} |
|
3459 |
length &= 0x1; |
|
3460 |
} |
|
3461 |
while (length--) { |
|
3462 |
*dest = interpolate_pixel_rgb16_255(*src, alpha, *dest, ialpha); |
|
3463 |
++dest; |
|
3464 |
++src; |
|
3465 |
} |
|
3466 |
} |
|
3467 |
||
3468 |
template <class DST, class SRC> |
|
3469 |
Q_STATIC_TEMPLATE_SPECIALIZATION |
|
3470 |
inline void madd_2(DST *dest, const quint16 alpha, const SRC *src) |
|
3471 |
{ |
|
3472 |
Q_ASSERT((quintptr(dest) & 0x3) == 0); |
|
3473 |
Q_ASSERT((quintptr(src) & 0x3) == 0); |
|
3474 |
dest[0] = dest[0].byte_mul(alpha >> 8) + DST(src[0]); |
|
3475 |
dest[1] = dest[1].byte_mul(alpha & 0xff) + DST(src[1]); |
|
3476 |
} |
|
3477 |
||
3478 |
template <class DST, class SRC> |
|
3479 |
Q_STATIC_TEMPLATE_SPECIALIZATION |
|
3480 |
inline void madd_4(DST *dest, const quint32 alpha, const SRC *src) |
|
3481 |
{ |
|
3482 |
Q_ASSERT((quintptr(dest) & 0x3) == 0); |
|
3483 |
Q_ASSERT((quintptr(src) & 0x3) == 0); |
|
3484 |
dest[0] = dest[0].byte_mul(alpha >> 24) + DST(src[0]); |
|
3485 |
dest[1] = dest[1].byte_mul((alpha >> 16) & 0xff) + DST(src[1]); |
|
3486 |
dest[2] = dest[2].byte_mul((alpha >> 8) & 0xff) + DST(src[2]); |
|
3487 |
dest[3] = dest[3].byte_mul(alpha & 0xff) + DST(src[3]); |
|
3488 |
} |
|
3489 |
||
3490 |
#if Q_BYTE_ORDER == Q_LITTLE_ENDIAN |
|
3491 |
template <> |
|
3492 |
Q_STATIC_TEMPLATE_SPECIALIZATION |
|
3493 |
inline void madd_4(qargb8565 *dest, const quint32 a, const qargb8565 *src) |
|
3494 |
{ |
|
3495 |
Q_ASSERT((quintptr(dest) & 0x3) == 0); |
|
3496 |
Q_ASSERT((quintptr(src) & 0x3) == 0); |
|
3497 |
||
3498 |
const quint32 *src32 = reinterpret_cast<const quint32*>(src); |
|
3499 |
quint32 *dest32 = reinterpret_cast<quint32*>(dest); |
|
3500 |
quint32 x, y, t; |
|
3501 |
quint8 a8; |
|
3502 |
||
3503 |
{ |
|
3504 |
x = dest32[0]; |
|
3505 |
y = src32[0]; |
|
3506 |
||
3507 |
a8 = a >> 24; |
|
3508 |
||
3509 |
// a0,g0 |
|
3510 |
t = ((((x & 0x0007e0ff) * a8) >> 5) & 0x0007e0ff) + (y & 0x0007c0f8); |
|
3511 |
||
3512 |
// r0,b0 |
|
3513 |
t |= ((((x & 0x00f81f00) * a8) >> 5) & 0x00f81f00) + (y & 0x00f81f00); |
|
3514 |
||
3515 |
a8 = (a >> 16) & 0xff; |
|
3516 |
||
3517 |
// a1 |
|
3518 |
t |= ((((x & 0xff000000) >> 5) * a8) & 0xff000000) + (y & 0xf8000000); |
|
3519 |
||
3520 |
dest32[0] = t; |
|
3521 |
} |
|
3522 |
{ |
|
3523 |
x = dest32[1]; |
|
3524 |
y = src32[1]; |
|
3525 |
||
3526 |
// r1,b1 |
|
3527 |
t = ((((x & 0x0000f81f) * a8) >> 5) & 0x0000f81f) + (y & 0x0000f81f); |
|
3528 |
||
3529 |
// g1 |
|
3530 |
t |= ((((x & 0x000007e0) * a8) >> 5) & 0x000007e0) + (y & 0x000007c0); |
|
3531 |
||
3532 |
a8 = (a >> 8) & 0xff; |
|
3533 |
||
3534 |
// a2 |
|
3535 |
t |= ((((x & 0x00ff0000) * a8) >> 5) & 0x00ff0000) + (y & 0x00f80000); |
|
3536 |
||
3537 |
{ |
|
3538 |
// rgb2 |
|
3539 |
quint16 x16 = (x >> 24) | ((dest32[2] & 0x000000ff) << 8); |
|
3540 |
quint16 y16 = (y >> 24) | ((src32[2] & 0x000000ff) << 8); |
|
3541 |
quint16 t16; |
|
3542 |
||
3543 |
t16 = ((((x16 & 0xf81f) * a8) >> 5) & 0xf81f) + (y16 & 0xf81f); |
|
3544 |
t16 |= ((((x16 & 0x07e0) * a8) >> 5) & 0x07e0) + (y16 & 0x07c0); |
|
3545 |
||
3546 |
// rg2 |
|
3547 |
t |= ((t16 & 0x00ff) << 24); |
|
3548 |
||
3549 |
dest32[1] = t; |
|
3550 |
||
3551 |
x = dest32[2]; |
|
3552 |
y = src32[2]; |
|
3553 |
||
3554 |
// gb2 |
|
3555 |
t = (t16 >> 8); |
|
3556 |
} |
|
3557 |
} |
|
3558 |
{ |
|
3559 |
a8 = a & 0xff; |
|
3560 |
||
3561 |
// g3,a3 |
|
3562 |
t |= ((((x & 0x07e0ff00) * a8) >> 5) & 0x07e0ff00) + (y & 0x07c0f800); |
|
3563 |
||
3564 |
// r3,b3 |
|
3565 |
t |= ((((x & 0xf81f0000) >> 5) * a8) & 0xf81f0000)+ (y & 0xf81f0000); |
|
3566 |
||
3567 |
dest32[2] = t; |
|
3568 |
} |
|
3569 |
} |
|
3570 |
#endif |
|
3571 |
||
3572 |
#if Q_BYTE_ORDER == Q_LITTLE_ENDIAN |
|
3573 |
template <> |
|
3574 |
Q_STATIC_TEMPLATE_SPECIALIZATION |
|
3575 |
inline void madd_4(qargb8555 *dest, const quint32 a, const qargb8555 *src) |
|
3576 |
{ |
|
3577 |
Q_ASSERT((quintptr(dest) & 0x3) == 0); |
|
3578 |
Q_ASSERT((quintptr(src) & 0x3) == 0); |
|
3579 |
||
3580 |
const quint32 *src32 = reinterpret_cast<const quint32*>(src); |
|
3581 |
quint32 *dest32 = reinterpret_cast<quint32*>(dest); |
|
3582 |
quint32 x, y, t; |
|
3583 |
quint8 a8; |
|
3584 |
||
3585 |
{ |
|
3586 |
x = dest32[0]; |
|
3587 |
y = src32[0]; |
|
3588 |
||
3589 |
a8 = a >> 24; |
|
3590 |
||
3591 |
// a0,g0 |
|
3592 |
t = ((((x & 0x0003e0ff) * a8) >> 5) & 0x0003e0ff) + (y & 0x0003e0f8); |
|
3593 |
||
3594 |
// r0,b0 |
|
3595 |
t |= ((((x & 0x007c1f00) * a8) >> 5) & 0x007c1f00) + (y & 0x007c1f00); |
|
3596 |
||
3597 |
a8 = (a >> 16) & 0xff; |
|
3598 |
||
3599 |
// a1 |
|
3600 |
t |= ((((x & 0xff000000) >> 5) * a8) & 0xff000000) + (y & 0xf8000000); |
|
3601 |
||
3602 |
dest32[0] = t; |
|
3603 |
} |
|
3604 |
{ |
|
3605 |
x = dest32[1]; |
|
3606 |
y = src32[1]; |
|
3607 |
||
3608 |
// r1,b1 |
|
3609 |
t = ((((x & 0x00007c1f) * a8) >> 5) & 0x00007c1f) + (y & 0x00007c1f); |
|
3610 |
||
3611 |
// g1 |
|
3612 |
t |= ((((x & 0x000003e0) * a8) >> 5) & 0x000003e0) + (y & 0x000003e0); |
|
3613 |
||
3614 |
a8 = (a >> 8) & 0xff; |
|
3615 |
||
3616 |
// a2 |
|
3617 |
t |= ((((x & 0x00ff0000) * a8) >> 5) & 0x00ff0000) + (y & 0x00f80000); |
|
3618 |
||
3619 |
{ |
|
3620 |
// rgb2 |
|
3621 |
quint16 x16 = (x >> 24) | ((dest32[2] & 0x000000ff) << 8); |
|
3622 |
quint16 y16 = (y >> 24) | ((src32[2] & 0x000000ff) << 8); |
|
3623 |
quint16 t16; |
|
3624 |
||
3625 |
t16 = ((((x16 & 0x7c1f) * a8) >> 5) & 0x7c1f) + (y16 & 0x7c1f); |
|
3626 |
t16 |= ((((x16 & 0x03e0) * a8) >> 5) & 0x03e0) + (y16 & 0x03e0); |
|
3627 |
||
3628 |
// rg2 |
|
3629 |
t |= ((t16 & 0x00ff) << 24); |
|
3630 |
||
3631 |
dest32[1] = t; |
|
3632 |
||
3633 |
x = dest32[2]; |
|
3634 |
y = src32[2]; |
|
3635 |
||
3636 |
// gb2 |
|
3637 |
t = (t16 >> 8); |
|
3638 |
} |
|
3639 |
} |
|
3640 |
{ |
|
3641 |
a8 = a & 0xff; |
|
3642 |
||
3643 |
// g3,a3 |
|
3644 |
t |= ((((x & 0x03e0ff00) * a8) >> 5) & 0x03e0ff00) + (y & 0x03e0f800); |
|
3645 |
||
3646 |
// r3,b3 |
|
3647 |
t |= ((((x & 0x7c1f0000) >> 5) * a8) & 0x7c1f0000)+ (y & 0x7c1f0000); |
|
3648 |
||
3649 |
dest32[2] = t; |
|
3650 |
} |
|
3651 |
} |
|
3652 |
#endif |
|
3653 |
||
3654 |
template <class T> |
|
3655 |
Q_STATIC_TEMPLATE_SPECIALIZATION |
|
3656 |
inline quint16 alpha_2(const T *src) |
|
3657 |
{ |
|
3658 |
Q_ASSERT((quintptr(src) & 0x3) == 0); |
|
3659 |
||
3660 |
if (T::hasAlpha()) |
|
3661 |
return (src[0].alpha() << 8) | src[1].alpha(); |
|
3662 |
else |
|
3663 |
return 0xffff; |
|
3664 |
} |
|
3665 |
||
3666 |
template <class T> |
|
3667 |
Q_STATIC_TEMPLATE_SPECIALIZATION |
|
3668 |
inline quint32 alpha_4(const T *src) |
|
3669 |
{ |
|
3670 |
Q_ASSERT((quintptr(src) & 0x3) == 0); |
|
3671 |
||
3672 |
if (T::hasAlpha()) { |
|
3673 |
return (src[0].alpha() << 24) | (src[1].alpha() << 16) |
|
3674 |
| (src[2].alpha() << 8) | src[3].alpha(); |
|
3675 |
} else { |
|
3676 |
return 0xffffffff; |
|
3677 |
} |
|
3678 |
} |
|
3679 |
||
3680 |
template <> |
|
3681 |
Q_STATIC_TEMPLATE_SPECIALIZATION |
|
3682 |
inline quint32 alpha_4(const qargb8565 *src) |
|
3683 |
{ |
|
3684 |
const quint8 *src8 = reinterpret_cast<const quint8*>(src); |
|
3685 |
return src8[0] << 24 | src8[3] << 16 | src8[6] << 8 | src8[9]; |
|
3686 |
} |
|
3687 |
||
3688 |
template <> |
|
3689 |
Q_STATIC_TEMPLATE_SPECIALIZATION |
|
3690 |
inline quint32 alpha_4(const qargb6666 *src) |
|
3691 |
{ |
|
3692 |
const quint8 *src8 = reinterpret_cast<const quint8*>(src); |
|
3693 |
return ((src8[2] & 0xfc) | (src8[2] >> 6)) << 24 |
|
3694 |
| ((src8[5] & 0xfc) | (src8[5] >> 6)) << 16 |
|
3695 |
| ((src8[8] & 0xfc) | (src8[8] >> 6)) << 8 |
|
3696 |
| ((src8[11] & 0xfc) | (src8[11] >> 6)); |
|
3697 |
} |
|
3698 |
||
3699 |
template <> |
|
3700 |
Q_STATIC_TEMPLATE_SPECIALIZATION |
|
3701 |
inline quint32 alpha_4(const qargb8555 *src) |
|
3702 |
{ |
|
3703 |
Q_ASSERT((long(src) & 0x3) == 0); |
|
3704 |
const quint8 *src8 = reinterpret_cast<const quint8*>(src); |
|
3705 |
return src8[0] << 24 | src8[3] << 16 | src8[6] << 8 | src8[9]; |
|
3706 |
} |
|
3707 |
||
3708 |
template <> |
|
3709 |
Q_STATIC_TEMPLATE_SPECIALIZATION |
|
3710 |
inline quint16 alpha_2(const qargb4444 *src) |
|
3711 |
{ |
|
3712 |
const quint32 *src32 = reinterpret_cast<const quint32*>(src); |
|
3713 |
const quint32 t = (*src32 & 0xf000f000) | |
|
3714 |
((*src32 & 0xf000f000) >> 4); |
|
3715 |
return (t >> 24) | (t & 0xff00); |
|
3716 |
} |
|
3717 |
||
3718 |
template <class T> |
|
3719 |
Q_STATIC_TEMPLATE_SPECIALIZATION |
|
3720 |
inline quint16 eff_alpha_2(quint16 alpha, const T*) |
|
3721 |
{ |
|
3722 |
return (T::alpha((alpha >> 8) & 0xff) << 8) |
|
3723 |
| T::alpha(alpha & 0xff); |
|
3724 |
} |
|
3725 |
||
3726 |
template <> |
|
3727 |
Q_STATIC_TEMPLATE_SPECIALIZATION |
|
3728 |
inline quint16 eff_alpha_2(quint16 a, const qrgb565*) |
|
3729 |
{ |
|
3730 |
return ((((a & 0xff00) + 0x0100) >> 3) & 0xff00) |
|
3731 |
| ((((a & 0x00ff) + 0x0001) >> 3) & 0x00ff); |
|
3732 |
} |
|
3733 |
||
3734 |
template <> |
|
3735 |
Q_STATIC_TEMPLATE_SPECIALIZATION |
|
3736 |
inline quint16 eff_alpha_2(quint16 a, const qrgb444*) |
|
3737 |
{ |
|
3738 |
return (((a & 0x00ff) + 0x0001) >> 4) |
|
3739 |
| ((((a & 0xff00) + 0x0100) >> 4) & 0xff00); |
|
3740 |
} |
|
3741 |
||
3742 |
template <> |
|
3743 |
Q_STATIC_TEMPLATE_SPECIALIZATION |
|
3744 |
inline quint16 eff_alpha_2(quint16 a, const qargb4444*) |
|
3745 |
{ |
|
3746 |
return (((a & 0x00ff) + 0x0001) >> 4) |
|
3747 |
| ((((a & 0xff00) + 0x0100) >> 4) & 0xff00); |
|
3748 |
} |
|
3749 |
||
3750 |
template <class T> |
|
3751 |
Q_STATIC_TEMPLATE_SPECIALIZATION |
|
3752 |
inline quint16 eff_ialpha_2(quint16 alpha, const T*) |
|
3753 |
{ |
|
3754 |
return (T::ialpha((alpha >> 8) & 0xff) << 8) |
|
3755 |
| T::ialpha(alpha & 0xff); |
|
3756 |
} |
|
3757 |
||
3758 |
template <> |
|
3759 |
Q_STATIC_TEMPLATE_SPECIALIZATION |
|
3760 |
inline quint16 eff_ialpha_2(quint16 a, const qrgb565 *dummy) |
|
3761 |
{ |
|
3762 |
return 0x2020 - eff_alpha_2(a, dummy); |
|
3763 |
} |
|
3764 |
||
3765 |
template <> |
|
3766 |
Q_STATIC_TEMPLATE_SPECIALIZATION |
|
3767 |
inline quint16 eff_ialpha_2(quint16 a, const qargb4444 *dummy) |
|
3768 |
{ |
|
3769 |
return 0x1010 - eff_alpha_2(a, dummy); |
|
3770 |
} |
|
3771 |
||
3772 |
template <> |
|
3773 |
Q_STATIC_TEMPLATE_SPECIALIZATION |
|
3774 |
inline quint16 eff_ialpha_2(quint16 a, const qrgb444 *dummy) |
|
3775 |
{ |
|
3776 |
return 0x1010 - eff_alpha_2(a, dummy); |
|
3777 |
} |
|
3778 |
||
3779 |
template <class T> |
|
3780 |
Q_STATIC_TEMPLATE_SPECIALIZATION |
|
3781 |
inline quint32 eff_alpha_4(quint32 alpha, const T*) |
|
3782 |
{ |
|
3783 |
return (T::alpha(alpha >> 24) << 24) |
|
3784 |
| (T::alpha((alpha >> 16) & 0xff) << 16) |
|
3785 |
| (T::alpha((alpha >> 8) & 0xff) << 8) |
|
3786 |
| T::alpha(alpha & 0xff); |
|
3787 |
} |
|
3788 |
||
3789 |
template <> |
|
3790 |
Q_STATIC_TEMPLATE_SPECIALIZATION |
|
3791 |
inline quint32 eff_alpha_4(quint32 a, const qrgb888*) |
|
3792 |
{ |
|
3793 |
return a; |
|
3794 |
} |
|
3795 |
||
3796 |
template <> |
|
3797 |
Q_STATIC_TEMPLATE_SPECIALIZATION |
|
3798 |
inline quint32 eff_alpha_4(quint32 a, const qargb8565*) |
|
3799 |
{ |
|
3800 |
return ((((a & 0xff00ff00) + 0x01000100) >> 3) & 0xff00ff00) |
|
3801 |
| ((((a & 0x00ff00ff) + 0x00010001) >> 3) & 0x00ff00ff); |
|
3802 |
} |
|
3803 |
||
3804 |
template <> |
|
3805 |
Q_STATIC_TEMPLATE_SPECIALIZATION |
|
3806 |
inline quint32 eff_alpha_4(quint32 a, const qargb6666*) |
|
3807 |
{ |
|
3808 |
return ((((a & 0xff00ff00) >> 2) + 0x00400040) & 0xff00ff00) |
|
3809 |
| ((((a & 0x00ff00ff) + 0x00010001) >> 2) & 0x00ff00ff); |
|
3810 |
} |
|
3811 |
||
3812 |
template <> |
|
3813 |
Q_STATIC_TEMPLATE_SPECIALIZATION |
|
3814 |
inline quint32 eff_alpha_4(quint32 a, const qrgb666*) |
|
3815 |
{ |
|
3816 |
return ((((a & 0xff00ff00) >> 2) + 0x00400040) & 0xff00ff00) |
|
3817 |
| ((((a & 0x00ff00ff) + 0x00010001) >> 2) & 0x00ff00ff); |
|
3818 |
} |
|
3819 |
||
3820 |
template <> |
|
3821 |
Q_STATIC_TEMPLATE_SPECIALIZATION |
|
3822 |
inline quint32 eff_alpha_4(quint32 a, const qargb8555*) |
|
3823 |
{ |
|
3824 |
return ((((a & 0xff00ff00) + 0x01000100) >> 3) & 0xff00ff00) |
|
3825 |
| ((((a & 0x00ff00ff) + 0x00010001) >> 3) & 0x00ff00ff); |
|
3826 |
} |
|
3827 |
||
3828 |
template <class T> |
|
3829 |
Q_STATIC_TEMPLATE_SPECIALIZATION |
|
3830 |
inline quint32 eff_ialpha_4(quint32 alpha, const T*) |
|
3831 |
{ |
|
3832 |
return (T::ialpha(alpha >> 24) << 24) |
|
3833 |
| (T::ialpha((alpha >> 16) & 0xff) << 16) |
|
3834 |
| (T::ialpha((alpha >> 8) & 0xff) << 8) |
|
3835 |
| T::ialpha(alpha & 0xff); |
|
3836 |
} |
|
3837 |
||
3838 |
template <> |
|
3839 |
Q_STATIC_TEMPLATE_SPECIALIZATION |
|
3840 |
inline quint32 eff_ialpha_4(quint32 a, const qrgb888*) |
|
3841 |
{ |
|
3842 |
return ~a; |
|
3843 |
} |
|
3844 |
||
3845 |
template <> |
|
3846 |
Q_STATIC_TEMPLATE_SPECIALIZATION |
|
3847 |
inline quint32 eff_ialpha_4(quint32 a, const qargb8565 *dummy) |
|
3848 |
{ |
|
3849 |
return 0x20202020 - eff_alpha_4(a, dummy); |
|
3850 |
} |
|
3851 |
||
3852 |
template <> |
|
3853 |
Q_STATIC_TEMPLATE_SPECIALIZATION |
|
3854 |
inline quint32 eff_ialpha_4(quint32 a, const qargb6666 *dummy) |
|
3855 |
{ |
|
3856 |
return 0x40404040 - eff_alpha_4(a, dummy); |
|
3857 |
} |
|
3858 |
||
3859 |
template <> |
|
3860 |
Q_STATIC_TEMPLATE_SPECIALIZATION |
|
3861 |
inline quint32 eff_ialpha_4(quint32 a, const qrgb666 *dummy) |
|
3862 |
{ |
|
3863 |
return 0x40404040 - eff_alpha_4(a, dummy); |
|
3864 |
} |
|
3865 |
||
3866 |
template <> |
|
3867 |
Q_STATIC_TEMPLATE_SPECIALIZATION |
|
3868 |
inline quint32 eff_ialpha_4(quint32 a, const qargb8555 *dummy) |
|
3869 |
{ |
|
3870 |
return 0x20202020 - eff_alpha_4(a, dummy); |
|
3871 |
} |
|
3872 |
||
3873 |
template <class DST, class SRC> |
|
3874 |
inline void interpolate_pixel_unaligned_2(DST *dest, const SRC *src, |
|
3875 |
quint16 alpha) |
|
3876 |
{ |
|
3877 |
const quint16 a = eff_alpha_2(alpha, dest); |
|
3878 |
const quint16 ia = eff_ialpha_2(alpha, dest); |
|
3879 |
dest[0] = DST(src[0]).byte_mul(a >> 8) + dest[0].byte_mul(ia >> 8); |
|
3880 |
dest[1] = DST(src[1]).byte_mul(a & 0xff) + dest[1].byte_mul(ia & 0xff); |
|
3881 |
} |
|
3882 |
||
3883 |
template <class DST, class SRC> |
|
3884 |
inline void interpolate_pixel_2(DST *dest, const SRC *src, quint16 alpha) |
|
3885 |
{ |
|
3886 |
Q_ASSERT((long(dest) & 0x3) == 0); |
|
3887 |
Q_ASSERT((long(src) & 0x3) == 0); |
|
3888 |
||
3889 |
const quint16 a = eff_alpha_2(alpha, dest); |
|
3890 |
const quint16 ia = eff_ialpha_2(alpha, dest); |
|
3891 |
||
3892 |
dest[0] = DST(src[0]).byte_mul(a >> 8) + dest[0].byte_mul(ia >> 8); |
|
3893 |
dest[1] = DST(src[1]).byte_mul(a & 0xff) + dest[1].byte_mul(ia & 0xff); |
|
3894 |
} |
|
3895 |
||
3896 |
template <class DST, class SRC> |
|
3897 |
inline void interpolate_pixel(DST &dest, quint8 a, const SRC &src, quint8 b) |
|
3898 |
{ |
|
3899 |
if (SRC::hasAlpha() && !DST::hasAlpha()) |
|
3900 |
interpolate_pixel(dest, a, DST(src), b); |
|
3901 |
else |
|
3902 |
dest = dest.byte_mul(a) + DST(src).byte_mul(b); |
|
3903 |
} |
|
3904 |
||
3905 |
template <> |
|
3906 |
inline void interpolate_pixel(qargb8565 &dest, quint8 a, |
|
3907 |
const qargb8565 &src, quint8 b) |
|
3908 |
{ |
|
3909 |
quint8 *d = reinterpret_cast<quint8*>(&dest); |
|
3910 |
const quint8 *s = reinterpret_cast<const quint8*>(&src); |
|
3911 |
d[0] = (d[0] * a + s[0] * b) >> 5; |
|
3912 |
||
3913 |
const quint16 x = (d[2] << 8) | d[1]; |
|
3914 |
const quint16 y = (s[2] << 8) | s[1]; |
|
3915 |
quint16 t = (((x & 0x07e0) * a + (y & 0x07e0) * b) >> 5) & 0x07e0; |
|
3916 |
t |= (((x & 0xf81f) * a + (y & 0xf81f) * b) >> 5) & 0xf81f; |
|
3917 |
||
3918 |
d[1] = t & 0xff; |
|
3919 |
d[2] = t >> 8; |
|
3920 |
} |
|
3921 |
||
3922 |
template <> |
|
3923 |
inline void interpolate_pixel(qrgb565 &dest, quint8 a, |
|
3924 |
const qrgb565 &src, quint8 b) |
|
3925 |
{ |
|
3926 |
const quint16 x = dest.rawValue(); |
|
3927 |
const quint16 y = src.rawValue(); |
|
3928 |
quint16 t = (((x & 0x07e0) * a + (y & 0x07e0) * b) >> 5) & 0x07e0; |
|
3929 |
t |= (((x & 0xf81f) * a + (y & 0xf81f) * b) >> 5) & 0xf81f; |
|
3930 |
dest = t; |
|
3931 |
} |
|
3932 |
||
3933 |
template <> |
|
3934 |
inline void interpolate_pixel(qrgb555 &dest, quint8 a, |
|
3935 |
const qrgb555 &src, quint8 b) |
|
3936 |
{ |
|
3937 |
const quint16 x = dest.rawValue(); |
|
3938 |
const quint16 y = src.rawValue(); |
|
3939 |
quint16 t = (((x & 0x03e0) * a + (y & 0x03e0) * b) >> 5) & 0x03e0; |
|
3940 |
t |= ((((x & 0x7c1f) * a) + ((y & 0x7c1f) * b)) >> 5) & 0x7c1f; |
|
3941 |
dest = t; |
|
3942 |
} |
|
3943 |
||
3944 |
template <> |
|
3945 |
inline void interpolate_pixel(qrgb444 &dest, quint8 a, |
|
3946 |
const qrgb444 &src, quint8 b) |
|
3947 |
{ |
|
3948 |
const quint16 x = dest.rawValue(); |
|
3949 |
const quint16 y = src.rawValue(); |
|
3950 |
quint16 t = ((x & 0x00f0) * a + (y & 0x00f0) * b) & 0x0f00; |
|
3951 |
t |= ((x & 0x0f0f) * a + (y & 0x0f0f) * b) & 0xf0f0; |
|
3952 |
quint16 *d = reinterpret_cast<quint16*>(&dest); |
|
3953 |
*d = (t >> 4); |
|
3954 |
} |
|
3955 |
||
3956 |
template <class DST, class SRC> |
|
3957 |
inline void interpolate_pixel_2(DST *dest, quint8 a, |
|
3958 |
const SRC *src, quint8 b) |
|
3959 |
{ |
|
3960 |
Q_ASSERT((long(dest) & 0x3) == 0); |
|
3961 |
Q_ASSERT((long(src) & 0x3) == 0); |
|
3962 |
||
3963 |
Q_ASSERT(!SRC::hasAlpha()); |
|
3964 |
||
3965 |
dest[0] = dest[0].byte_mul(a) + DST(src[0]).byte_mul(b); |
|
3966 |
dest[1] = dest[1].byte_mul(a) + DST(src[1]).byte_mul(b); |
|
3967 |
} |
|
3968 |
||
3969 |
template <> |
|
3970 |
inline void interpolate_pixel_2(qrgb565 *dest, quint8 a, |
|
3971 |
const qrgb565 *src, quint8 b) |
|
3972 |
{ |
|
3973 |
quint32 *x = reinterpret_cast<quint32*>(dest); |
|
3974 |
const quint32 *y = reinterpret_cast<const quint32*>(src); |
|
3975 |
quint32 t = (((*x & 0xf81f07e0) >> 5) * a + |
|
3976 |
((*y & 0xf81f07e0) >> 5) * b) & 0xf81f07e0; |
|
3977 |
t |= (((*x & 0x07e0f81f) * a |
|
3978 |
+ (*y & 0x07e0f81f) * b) >> 5) & 0x07e0f81f; |
|
3979 |
*x = t; |
|
3980 |
} |
|
3981 |
||
3982 |
template <> |
|
3983 |
inline void interpolate_pixel_2(qrgb555 *dest, quint8 a, |
|
3984 |
const qrgb555 *src, quint8 b) |
|
3985 |
{ |
|
3986 |
quint32 *x = reinterpret_cast<quint32*>(dest); |
|
3987 |
const quint32 *y = reinterpret_cast<const quint32*>(src); |
|
3988 |
quint32 t = (((*x & 0x7c1f03e0) >> 5) * a + |
|
3989 |
((*y & 0x7c1f03e0) >> 5) * b) & 0x7c1f03e0; |
|
3990 |
t |= (((*x & 0x03e07c1f) * a |
|
3991 |
+ (*y & 0x03e07c1f) * b) >> 5) & 0x03e07c1f; |
|
3992 |
*x = t; |
|
3993 |
} |
|
3994 |
||
3995 |
template <> |
|
3996 |
inline void interpolate_pixel_2(qrgb444 *dest, quint8 a, |
|
3997 |
const qrgb444 *src, quint8 b) |
|
3998 |
{ |
|
3999 |
quint32 *x = reinterpret_cast<quint32*>(dest); |
|
4000 |
const quint32 *y = reinterpret_cast<const quint32*>(src); |
|
4001 |
quint32 t = ((*x & 0x0f0f0f0f) * a + (*y & 0x0f0f0f0f) * b) & 0xf0f0f0f0; |
|
4002 |
t |= ((*x & 0x00f000f0) * a + (*y & 0x00f000f0) * b) & 0x0f000f00; |
|
4003 |
*x = t >> 4; |
|
4004 |
} |
|
4005 |
||
4006 |
template <class DST, class SRC> |
|
4007 |
inline void interpolate_pixel_4(DST *dest, const SRC *src, quint32 alpha) |
|
4008 |
{ |
|
4009 |
Q_ASSERT((long(dest) & 0x3) == 0); |
|
4010 |
Q_ASSERT((long(src) & 0x3) == 0); |
|
4011 |
||
4012 |
const quint32 a = eff_alpha_4(alpha, dest); |
|
4013 |
const quint32 ia = eff_ialpha_4(alpha, dest); |
|
4014 |
dest[0] = DST(src[0]).byte_mul(a >> 24) |
|
4015 |
+ dest[0].byte_mul(ia >> 24); |
|
4016 |
dest[1] = DST(src[1]).byte_mul((a >> 16) & 0xff) |
|
4017 |
+ dest[1].byte_mul((ia >> 16) & 0xff); |
|
4018 |
dest[2] = DST(src[2]).byte_mul((a >> 8) & 0xff) |
|
4019 |
+ dest[2].byte_mul((ia >> 8) & 0xff); |
|
4020 |
dest[3] = DST(src[3]).byte_mul(a & 0xff) |
|
4021 |
+ dest[3].byte_mul(ia & 0xff); |
|
4022 |
} |
|
4023 |
||
4024 |
#if Q_BYTE_ORDER == Q_LITTLE_ENDIAN |
|
4025 |
template <> |
|
4026 |
inline void interpolate_pixel_4(qargb8565 *dest, const qargb8565 *src, |
|
4027 |
quint32 alpha) |
|
4028 |
{ |
|
4029 |
Q_ASSERT((long(dest) & 0x3) == 0); |
|
4030 |
Q_ASSERT((long(src) & 0x3) == 0); |
|
4031 |
||
4032 |
const quint32 a = eff_alpha_4(alpha, dest); |
|
4033 |
const quint32 ia = eff_ialpha_4(alpha, dest); |
|
4034 |
const quint32 *src32 = reinterpret_cast<const quint32*>(src); |
|
4035 |
quint32 *dest32 = reinterpret_cast<quint32*>(dest); |
|
4036 |
||
4037 |
quint32 x, y, t; |
|
4038 |
quint8 a8, ia8; |
|
4039 |
{ |
|
4040 |
x = src32[0]; |
|
4041 |
y = dest32[0]; |
|
4042 |
||
4043 |
a8 = a >> 24; |
|
4044 |
ia8 = ia >> 24; |
|
4045 |
||
4046 |
// a0,g0 |
|
4047 |
t = (((x & 0x0007e0ff) * a8 + (y & 0x0007e0ff) * ia8) >> 5) |
|
4048 |
& 0x0007e0ff; |
|
4049 |
||
4050 |
// r0,b0 |
|
4051 |
t |= (((x & 0x00f81f00) * a8 + (y & 0x00f81f00) * ia8) >> 5) |
|
4052 |
& 0x00f81f00; |
|
4053 |
||
4054 |
a8 = (a >> 16) & 0xff; |
|
4055 |
ia8 = (ia >> 16) & 0xff; |
|
4056 |
||
4057 |
// a1 |
|
4058 |
t |= (((x & 0xff000000) >> 5) * a8 + ((y & 0xff000000) >> 5) * ia8) |
|
4059 |
& 0xff000000; |
|
4060 |
||
4061 |
dest32[0] = t; |
|
4062 |
} |
|
4063 |
{ |
|
4064 |
x = src32[1]; |
|
4065 |
y = dest32[1]; |
|
4066 |
||
4067 |
// r1,b1 |
|
4068 |
t = (((x & 0x0000f81f) * a8 + (y & 0x0000f81f) * ia8) >> 5) |
|
4069 |
& 0x0000f81f; |
|
4070 |
||
4071 |
// g1 |
|
4072 |
t |= (((x & 0x000007e0) * a8 + (y & 0x000007e0) * ia8) >> 5) |
|
4073 |
& 0x000007e0; |
|
4074 |
||
4075 |
a8 = (a >> 8) & 0xff; |
|
4076 |
ia8 = (ia >> 8) & 0xff; |
|
4077 |
||
4078 |
// a2 |
|
4079 |
t |= (((x & 0x00ff0000) * a8 + (y & 0x00ff0000) * ia8) >> 5) |
|
4080 |
& 0x00ff0000; |
|
4081 |
||
4082 |
{ |
|
4083 |
// rgb2 |
|
4084 |
quint16 x16 = (x >> 24) | ((src32[2] & 0x000000ff) << 8); |
|
4085 |
quint16 y16 = (y >> 24) | ((dest32[2] & 0x000000ff) << 8); |
|
4086 |
quint16 t16; |
|
4087 |
||
4088 |
t16 = (((x16 & 0xf81f) * a8 + (y16 & 0xf81f) * ia8) >> 5) & 0xf81f; |
|
4089 |
t16 |= (((x16 & 0x07e0) * a8 + (y16 & 0x07e0) * ia8) >> 5) & 0x07e0; |
|
4090 |
||
4091 |
// rg2 |
|
4092 |
t |= ((t16 & 0x00ff) << 24); |
|
4093 |
||
4094 |
dest32[1] = t; |
|
4095 |
||
4096 |
x = src32[2]; |
|
4097 |
y = dest32[2]; |
|
4098 |
||
4099 |
// gb2 |
|
4100 |
t = (t16 >> 8); |
|
4101 |
} |
|
4102 |
} |
|
4103 |
{ |
|
4104 |
a8 = a & 0xff; |
|
4105 |
ia8 = ia & 0xff; |
|
4106 |
||
4107 |
// g3,a3 |
|
4108 |
t |= (((x & 0x07e0ff00) * a8 + (y & 0x07e0ff00) * ia8) >> 5) |
|
4109 |
& 0x07e0ff00; |
|
4110 |
||
4111 |
// r3,b3 |
|
4112 |
t |= (((x & 0xf81f0000) >> 5) * a8 + ((y & 0xf81f0000) >> 5) * ia8) |
|
4113 |
& 0xf81f0000; |
|
4114 |
||
4115 |
dest32[2] = t; |
|
4116 |
} |
|
4117 |
} |
|
4118 |
#endif |
|
4119 |
||
4120 |
#if Q_BYTE_ORDER == Q_LITTLE_ENDIAN |
|
4121 |
template <> |
|
4122 |
inline void interpolate_pixel_4(qargb8555 *dest, const qargb8555 *src, |
|
4123 |
quint32 alpha) |
|
4124 |
{ |
|
4125 |
Q_ASSERT((long(dest) & 0x3) == 0); |
|
4126 |
Q_ASSERT((long(src) & 0x3) == 0); |
|
4127 |
||
4128 |
||
4129 |
const quint32 a = eff_alpha_4(alpha, dest); |
|
4130 |
const quint32 ia = eff_ialpha_4(alpha, dest); |
|
4131 |
const quint32 *src32 = reinterpret_cast<const quint32*>(src); |
|
4132 |
quint32 *dest32 = reinterpret_cast<quint32*>(dest); |
|
4133 |
||
4134 |
quint32 x, y, t; |
|
4135 |
quint8 a8, ia8; |
|
4136 |
{ |
|
4137 |
x = src32[0]; |
|
4138 |
y = dest32[0]; |
|
4139 |
||
4140 |
a8 = a >> 24; |
|
4141 |
ia8 = ia >> 24; |
|
4142 |
||
4143 |
// a0,g0 |
|
4144 |
t = (((x & 0x0003e0ff) * a8 + (y & 0x0003e0ff) * ia8) >> 5) |
|
4145 |
& 0x0003e0ff; |
|
4146 |
||
4147 |
// r0,b0 |
|
4148 |
t |= (((x & 0x007c1f00) * a8 + (y & 0x007c1f00) * ia8) >> 5) |
|
4149 |
& 0x007c1f00; |
|
4150 |
||
4151 |
a8 = (a >> 16) & 0xff; |
|
4152 |
ia8 = (ia >> 16) & 0xff; |
|
4153 |
||
4154 |
// a1 |
|
4155 |
t |= (((x & 0xff000000) >> 5) * a8 + ((y & 0xff000000) >> 5) * ia8) |
|
4156 |
& 0xff000000; |
|
4157 |
||
4158 |
dest32[0] = t; |
|
4159 |
} |
|
4160 |
{ |
|
4161 |
x = src32[1]; |
|
4162 |
y = dest32[1]; |
|
4163 |
||
4164 |
// r1,b1 |
|
4165 |
t = (((x & 0x00007c1f) * a8 + (y & 0x00007c1f) * ia8) >> 5) |
|
4166 |
& 0x00007c1f; |
|
4167 |
||
4168 |
// g1 |
|
4169 |
t |= (((x & 0x000003e0) * a8 + (y & 0x000003e0) * ia8) >> 5) |
|
4170 |
& 0x000003e0; |
|
4171 |
||
4172 |
a8 = (a >> 8) & 0xff; |
|
4173 |
ia8 = (ia >> 8) & 0xff; |
|
4174 |
||
4175 |
// a2 |
|
4176 |
t |= (((x & 0x00ff0000) * a8 + (y & 0x00ff0000) * ia8) >> 5) |
|
4177 |
& 0x00ff0000; |
|
4178 |
||
4179 |
{ |
|
4180 |
// rgb2 |
|
4181 |
quint16 x16 = (x >> 24) | ((src32[2] & 0x000000ff) << 8); |
|
4182 |
quint16 y16 = (y >> 24) | ((dest32[2] & 0x000000ff) << 8); |
|
4183 |
quint16 t16; |
|
4184 |
||
4185 |
t16 = (((x16 & 0x7c1f) * a8 + (y16 & 0x7c1f) * ia8) >> 5) & 0x7c1f; |
|
4186 |
t16 |= (((x16 & 0x03e0) * a8 + (y16 & 0x03e0) * ia8) >> 5) & 0x03e0; |
|
4187 |
||
4188 |
// rg2 |
|
4189 |
t |= ((t16 & 0x00ff) << 24); |
|
4190 |
||
4191 |
dest32[1] = t; |
|
4192 |
||
4193 |
x = src32[2]; |
|
4194 |
y = dest32[2]; |
|
4195 |
||
4196 |
// gb2 |
|
4197 |
t = (t16 >> 8); |
|
4198 |
} |
|
4199 |
} |
|
4200 |
{ |
|
4201 |
a8 = a & 0xff; |
|
4202 |
ia8 = ia & 0xff; |
|
4203 |
||
4204 |
// g3,a3 |
|
4205 |
t |= (((x & 0x03e0ff00) * a8 + (y & 0x03e0ff00) * ia8) >> 5) |
|
4206 |
& 0x03e0ff00; |
|
4207 |
||
4208 |
// r3,b3 |
|
4209 |
t |= (((x & 0x7c1f0000) >> 5) * a8 + ((y & 0x7c1f0000) >> 5) * ia8) |
|
4210 |
& 0x7c1f0000; |
|
4211 |
||
4212 |
dest32[2] = t; |
|
4213 |
} |
|
4214 |
} |
|
4215 |
#endif |
|
4216 |
||
4217 |
template <> |
|
4218 |
inline void interpolate_pixel_4(qrgb888 *dest, const qrgb888 *src, |
|
4219 |
quint32 alpha) |
|
4220 |
{ |
|
4221 |
Q_ASSERT((long(dest) & 0x3) == 0); |
|
4222 |
Q_ASSERT((long(src) & 0x3) == 0); |
|
4223 |
||
4224 |
const quint32 a = eff_alpha_4(alpha, dest); |
|
4225 |
const quint32 ia = eff_ialpha_4(alpha, dest); |
|
4226 |
const quint32 *src32 = reinterpret_cast<const quint32*>(src); |
|
4227 |
quint32 *dest32 = reinterpret_cast<quint32*>(dest); |
|
4228 |
||
4229 |
{ |
|
4230 |
quint32 x = src32[0]; |
|
4231 |
quint32 y = dest32[0]; |
|
4232 |
||
4233 |
quint32 t; |
|
4234 |
t = ((x >> 8) & 0xff00ff) * (a >> 24) |
|
4235 |
+ ((y >> 8) & 0xff00ff) * (ia >> 24); |
|
4236 |
t = (t + ((t >> 8) & 0xff00ff) + 0x800080); |
|
4237 |
t &= 0xff00ff00; |
|
4238 |
||
4239 |
x = (x & 0xff0000) * (a >> 24) |
|
4240 |
+ (x & 0x0000ff) * ((a >> 16) & 0xff) |
|
4241 |
+ (y & 0xff0000) * (ia >> 24) |
|
4242 |
+ (y & 0x0000ff) * ((ia >> 16) & 0xff); |
|
4243 |
x = (x + ((x >> 8) & 0xff00ff) + 0x800080) >> 8; |
|
4244 |
x &= 0x00ff00ff; |
|
4245 |
||
4246 |
dest32[0] = x | t; |
|
4247 |
} |
|
4248 |
{ |
|
4249 |
quint32 x = src32[1]; |
|
4250 |
quint32 y = dest32[1]; |
|
4251 |
||
4252 |
quint32 t; |
|
4253 |
t = ((x >> 8) & 0xff0000) * ((a >> 16) & 0xff) |
|
4254 |
+ ((x >> 8) & 0x0000ff) * ((a >> 8) & 0xff) |
|
4255 |
+ ((y >> 8) & 0xff0000) * ((ia >> 16) & 0xff) |
|
4256 |
+ ((y >> 8) & 0x0000ff) * ((ia >> 8) & 0xff); |
|
4257 |
t = (t + ((t >> 8) & 0xff00ff) + 0x800080); |
|
4258 |
t &= 0xff00ff00; |
|
4259 |
||
4260 |
x = (x & 0xff0000) * ((a >> 16) & 0xff) |
|
4261 |
+ (x & 0x0000ff) * ((a >> 8) & 0xff) |
|
4262 |
+ (y & 0xff0000) * ((ia >> 16) & 0xff) |
|
4263 |
+ (y & 0x0000ff) * ((ia >> 8) & 0xff); |
|
4264 |
x = (x + ((x >> 8) & 0xff00ff) + 0x800080) >> 8; |
|
4265 |
x &= 0x00ff00ff; |
|
4266 |
||
4267 |
dest32[1] = x | t; |
|
4268 |
} |
|
4269 |
{ |
|
4270 |
quint32 x = src32[2]; |
|
4271 |
quint32 y = dest32[2]; |
|
4272 |
||
4273 |
quint32 t; |
|
4274 |
t = ((x >> 8) & 0xff0000) * ((a >> 8) & 0xff) |
|
4275 |
+ ((x >> 8) & 0x0000ff) * (a & 0xff) |
|
4276 |
+ ((y >> 8) & 0xff0000) * ((ia >> 8) & 0xff) |
|
4277 |
+ ((y >> 8) & 0x0000ff) * (ia & 0xff); |
|
4278 |
t = (t + ((t >> 8) & 0xff00ff) + 0x800080); |
|
4279 |
t &= 0xff00ff00; |
|
4280 |
||
4281 |
x = (x & 0xff00ff) * (a & 0xff) |
|
4282 |
+ (y & 0xff00ff) * (ia & 0xff); |
|
4283 |
x = (x + ((x >> 8) & 0xff00ff) + 0x800080) >> 8; |
|
4284 |
x &= 0x00ff00ff; |
|
4285 |
||
4286 |
dest32[2] = x | t; |
|
4287 |
} |
|
4288 |
} |
|
4289 |
||
4290 |
template <class DST, class SRC> |
|
4291 |
inline void interpolate_pixel_4(DST *dest, quint8 a, |
|
4292 |
const SRC *src, quint8 b) |
|
4293 |
{ |
|
4294 |
Q_ASSERT((long(dest) & 0x3) == 0); |
|
4295 |
Q_ASSERT((long(src) & 0x3) == 0); |
|
4296 |
||
4297 |
dest[0] = dest[0].byte_mul(a) + DST(src[0]).byte_mul(b); |
|
4298 |
dest[1] = dest[1].byte_mul(a) + DST(src[1]).byte_mul(b); |
|
4299 |
dest[2] = dest[2].byte_mul(a) + DST(src[2]).byte_mul(b); |
|
4300 |
dest[3] = dest[3].byte_mul(a) + DST(src[3]).byte_mul(b); |
|
4301 |
} |
|
4302 |
||
4303 |
template <class DST, class SRC> |
|
4304 |
inline void blend_sourceOver_4(DST *dest, const SRC *src) |
|
4305 |
{ |
|
4306 |
Q_ASSERT((long(dest) & 0x3) == 0); |
|
4307 |
Q_ASSERT((long(src) & 0x3) == 0); |
|
4308 |
||
4309 |
const quint32 a = alpha_4(src); |
|
4310 |
if (a == 0xffffffff) { |
|
4311 |
qt_memconvert(dest, src, 4); |
|
4312 |
} else if (a > 0) { |
|
4313 |
quint32 buf[3]; // array of quint32 to get correct alignment |
|
4314 |
qt_memconvert((DST*)(void*)buf, src, 4); |
|
4315 |
madd_4(dest, eff_ialpha_4(a, dest), (DST*)(void*)buf); |
|
4316 |
} |
|
4317 |
} |
|
4318 |
||
4319 |
template <> |
|
4320 |
inline void blend_sourceOver_4(qargb8565 *dest, const qargb8565 *src) |
|
4321 |
{ |
|
4322 |
Q_ASSERT((long(dest) & 0x3) == 0); |
|
4323 |
Q_ASSERT((long(src) & 0x3) == 0); |
|
4324 |
||
4325 |
const quint32 a = alpha_4(src); |
|
4326 |
if (a == 0xffffffff) { |
|
4327 |
qt_memconvert(dest, src, 4); |
|
4328 |
} else if (a > 0) { |
|
4329 |
madd_4(dest, eff_ialpha_4(a, dest), src); |
|
4330 |
} |
|
4331 |
} |
|
4332 |
||
4333 |
template <> |
|
4334 |
inline void blend_sourceOver_4(qargb8555 *dest, const qargb8555 *src) |
|
4335 |
{ |
|
4336 |
Q_ASSERT((long(dest) & 0x3) == 0); |
|
4337 |
Q_ASSERT((long(src) & 0x3) == 0); |
|
4338 |
||
4339 |
const quint32 a = alpha_4(src); |
|
4340 |
if (a == 0xffffffff) { |
|
4341 |
qt_memconvert(dest, src, 4); |
|
4342 |
} else if (a > 0) { |
|
4343 |
madd_4(dest, eff_ialpha_4(a, dest), src); |
|
4344 |
} |
|
4345 |
} |
|
4346 |
||
4347 |
template <> |
|
4348 |
inline void blend_sourceOver_4(qargb6666 *dest, const qargb6666 *src) |
|
4349 |
{ |
|
4350 |
Q_ASSERT((long(dest) & 0x3) == 0); |
|
4351 |
Q_ASSERT((long(src) & 0x3) == 0); |
|
4352 |
||
4353 |
const quint32 a = alpha_4(src); |
|
4354 |
if (a == 0xffffffff) { |
|
4355 |
qt_memconvert(dest, src, 4); |
|
4356 |
} else if (a > 0) { |
|
4357 |
madd_4(dest, eff_ialpha_4(a, dest), src); |
|
4358 |
} |
|
4359 |
} |
|
4360 |
||
4361 |
template <class DST, class SRC> |
|
4362 |
void QT_FASTCALL blendUntransformed_unaligned(DST *dest, const SRC *src, |
|
4363 |
quint8 coverage, int length) |
|
4364 |
{ |
|
4365 |
Q_ASSERT(coverage > 0); |
|
4366 |
||
4367 |
if (coverage < 255) { |
|
4368 |
if (SRC::hasAlpha()) { |
|
4369 |
for (int i = 0; i < length; ++i) { |
|
4370 |
if (src[i].alpha()) { |
|
4371 |
const quint8 alpha = qt_div_255(int(src[i].alpha()) * int(coverage)); |
|
4372 |
interpolate_pixel(dest[i], DST::ialpha(alpha), |
|
4373 |
src[i], DST::alpha(alpha)); |
|
4374 |
} |
|
4375 |
} |
|
4376 |
} else { |
|
4377 |
const quint8 alpha = DST::alpha(coverage); |
|
4378 |
const quint8 ialpha = DST::ialpha(coverage); |
|
4379 |
if (alpha) { |
|
4380 |
for (int i = 0; i < length; ++i) |
|
4381 |
interpolate_pixel(dest[i], ialpha, src[i], alpha); |
|
4382 |
} |
|
4383 |
} |
|
4384 |
return; |
|
4385 |
} |
|
4386 |
||
4387 |
Q_ASSERT(coverage == 0xff); |
|
4388 |
Q_ASSERT(SRC::hasAlpha()); |
|
4389 |
||
4390 |
if (SRC::hasAlpha()) { |
|
4391 |
for (int i = 0; i < length; ++i) { |
|
4392 |
const quint8 a = src->alpha(); |
|
4393 |
if (a == 0xff) |
|
4394 |
*dest = DST(*src); |
|
4395 |
else if (a > 0) { |
|
4396 |
if (DST::hasAlpha()) |
|
4397 |
*dest = DST(*src).truncedAlpha() + dest->byte_mul(DST::ialpha(a)); |
|
4398 |
else |
|
4399 |
*dest = DST(SRC(*src).truncedAlpha()) + dest->byte_mul(DST::ialpha(a)); |
|
4400 |
} |
|
4401 |
++src; |
|
4402 |
++dest; |
|
4403 |
} |
|
4404 |
} |
|
4405 |
} |
|
4406 |
||
4407 |
template <class DST, class SRC> |
|
4408 |
void QT_FASTCALL blendUntransformed_dest16(DST *dest, const SRC *src, |
|
4409 |
quint8 coverage, int length) |
|
4410 |
{ |
|
4411 |
Q_ASSERT(sizeof(DST) == 2); |
|
4412 |
Q_ASSERT(sizeof(SRC) == 2); |
|
4413 |
Q_ASSERT((long(dest) & 0x3) == (long(src) & 0x3)); |
|
4414 |
Q_ASSERT(coverage > 0); |
|
4415 |
||
4416 |
const int align = quintptr(dest) & 0x3; |
|
4417 |
||
4418 |
if (coverage < 255) { |
|
4419 |
// align |
|
4420 |
if (align) { |
|
4421 |
const quint8 alpha = SRC::hasAlpha() |
|
4422 |
? qt_div_255(int(src->alpha()) * int(coverage)) |
|
4423 |
: coverage; |
|
4424 |
if (alpha) { |
|
4425 |
interpolate_pixel(*dest, DST::ialpha(alpha), |
|
4426 |
*src, DST::alpha(alpha)); |
|
4427 |
} |
|
4428 |
++dest; |
|
4429 |
++src; |
|
4430 |
--length; |
|
4431 |
} |
|
4432 |
||
4433 |
if (SRC::hasAlpha()) { |
|
4434 |
while (length >= 2) { |
|
4435 |
const quint16 alpha16 = BYTE_MUL(uint(alpha_2(src)), uint(coverage)); |
|
4436 |
interpolate_pixel_2(dest, src, alpha16); |
|
4437 |
length -= 2; |
|
4438 |
src += 2; |
|
4439 |
dest += 2; |
|
4440 |
} |
|
4441 |
} else { |
|
4442 |
const quint8 alpha = DST::alpha(coverage); |
|
4443 |
const quint8 ialpha = DST::ialpha(coverage); |
|
4444 |
||
4445 |
while (length >= 2) { |
|
4446 |
interpolate_pixel_2(dest, ialpha, src, alpha); |
|
4447 |
length -= 2; |
|
4448 |
src += 2; |
|
4449 |
dest += 2; |
|
4450 |
} |
|
4451 |
} |
|
4452 |
||
4453 |
// tail |
|
4454 |
if (length) { |
|
4455 |
const quint8 alpha = SRC::hasAlpha() |
|
4456 |
? qt_div_255(int(src->alpha()) * int(coverage)) |
|
4457 |
: coverage; |
|
4458 |
if (alpha) { |
|
4459 |
interpolate_pixel(*dest, DST::ialpha(alpha), |
|
4460 |
*src, DST::alpha(alpha)); |
|
4461 |
} |
|
4462 |
} |
|
4463 |
||
4464 |
return; |
|
4465 |
} |
|
4466 |
||
4467 |
Q_ASSERT(SRC::hasAlpha()); |
|
4468 |
if (SRC::hasAlpha()) { |
|
4469 |
if (align) { |
|
4470 |
const quint8 alpha = src->alpha(); |
|
4471 |
if (alpha == 0xff) |
|
4472 |
*dest = DST(*src); |
|
4473 |
else if (alpha > 0) |
|
4474 |
*dest = DST(*src).truncedAlpha() + dest->byte_mul(DST::ialpha(alpha)); |
|
4475 |
++dest; |
|
4476 |
++src; |
|
4477 |
--length; |
|
4478 |
} |
|
4479 |
||
4480 |
while (length >= 2) { |
|
4481 |
Q_ASSERT((long(dest) & 3) == 0); |
|
4482 |
Q_ASSERT((long(src) & 3) == 0); |
|
4483 |
||
4484 |
const quint16 a = alpha_2(src); |
|
4485 |
if (a == 0xffff) { |
|
4486 |
qt_memconvert(dest, src, 2); |
|
4487 |
} else if (a > 0) { |
|
4488 |
quint32 buf; |
|
4489 |
if (sizeof(DST) == 2) |
|
4490 |
qt_memconvert((DST*)(void*)&buf, src, 2); |
|
4491 |
madd_2(dest, eff_ialpha_2(a, dest), (DST*)(void*)&buf); |
|
4492 |
} |
|
4493 |
||
4494 |
length -= 2; |
|
4495 |
src += 2; |
|
4496 |
dest += 2; |
|
4497 |
} |
|
4498 |
||
4499 |
if (length) { |
|
4500 |
const quint8 alpha = src->alpha(); |
|
4501 |
if (alpha == 0xff) |
|
4502 |
*dest = DST(*src); |
|
4503 |
else if (alpha > 0) |
|
4504 |
*dest = DST(*src).truncedAlpha() + dest->byte_mul(DST::ialpha(alpha)); |
|
4505 |
} |
|
4506 |
} |
|
4507 |
} |
|
4508 |
||
4509 |
template <class DST, class SRC> |
|
4510 |
void QT_FASTCALL blendUntransformed_dest24(DST *dest, const SRC *src, |
|
4511 |
quint8 coverage, int length) |
|
4512 |
{ |
|
4513 |
Q_ASSERT((long(dest) & 0x3) == (long(src) & 0x3)); |
|
4514 |
Q_ASSERT(sizeof(DST) == 3); |
|
4515 |
Q_ASSERT(coverage > 0); |
|
4516 |
||
4517 |
const int align = quintptr(dest) & 0x3; |
|
4518 |
||
4519 |
if (coverage < 255) { |
|
4520 |
// align |
|
4521 |
for (int i = 0; i < align; ++i) { |
|
4522 |
if (SRC::hasAlpha()) { |
|
4523 |
const quint8 alpha = qt_div_255(int(src->alpha()) * int(coverage)); |
|
4524 |
if (alpha) |
|
4525 |
interpolate_pixel(*dest, DST::ialpha(alpha), |
|
4526 |
*src, DST::alpha(alpha)); |
|
4527 |
} else { |
|
4528 |
interpolate_pixel(*dest, DST::ialpha(coverage), |
|
4529 |
*src, DST::alpha(coverage)); |
|
4530 |
} |
|
4531 |
++dest; |
|
4532 |
++src; |
|
4533 |
--length; |
|
4534 |
} |
|
4535 |
||
4536 |
if (SRC::hasAlpha()) { |
|
4537 |
while (length >= 4) { |
|
4538 |
const quint32 alpha = BYTE_MUL(uint(alpha_4(src)), uint(coverage)); |
|
4539 |
if (alpha) |
|
4540 |
interpolate_pixel_4(dest, src, alpha); |
|
4541 |
length -= 4; |
|
4542 |
src += 4; |
|
4543 |
dest += 4; |
|
4544 |
} |
|
4545 |
} else { |
|
4546 |
const quint8 alpha = DST::alpha(coverage); |
|
4547 |
const quint8 ialpha = DST::ialpha(coverage); |
|
4548 |
while (length >= 4) { |
|
4549 |
interpolate_pixel_4(dest, ialpha, src, alpha); |
|
4550 |
length -= 4; |
|
4551 |
src += 4; |
|
4552 |
dest += 4; |
|
4553 |
} |
|
4554 |
} |
|
4555 |
||
4556 |
// tail |
|
4557 |
while (length--) { |
|
4558 |
if (SRC::hasAlpha()) { |
|
4559 |
const quint8 alpha = qt_div_255(int(src->alpha()) * int(coverage)); |
|
4560 |
if (alpha) |
|
4561 |
interpolate_pixel(*dest, DST::ialpha(alpha), |
|
4562 |
*src, DST::alpha(alpha)); |
|
4563 |
} else { |
|
4564 |
interpolate_pixel(*dest, DST::ialpha(coverage), |
|
4565 |
*src, DST::alpha(coverage)); |
|
4566 |
} |
|
4567 |
++dest; |
|
4568 |
++src; |
|
4569 |
} |
|
4570 |
||
4571 |
return; |
|
4572 |
} |
|
4573 |
||
4574 |
||
4575 |
Q_ASSERT(coverage == 255); |
|
4576 |
Q_ASSERT(SRC::hasAlpha()); |
|
4577 |
||
4578 |
if (SRC::hasAlpha()) { |
|
4579 |
// align |
|
4580 |
for (int i = 0; i < align; ++i) { |
|
4581 |
const quint8 a = src->alpha(); |
|
4582 |
if (a == 0xff) { |
|
4583 |
*dest = DST(*src); |
|
4584 |
} else if (a > 0) { |
|
4585 |
*dest = DST(*src).truncedAlpha() + dest->byte_mul(DST::ialpha(a)); |
|
4586 |
} |
|
4587 |
++dest; |
|
4588 |
++src; |
|
4589 |
--length; |
|
4590 |
} |
|
4591 |
||
4592 |
while (length >= 4) { |
|
4593 |
blend_sourceOver_4(dest, src); |
|
4594 |
length -= 4; |
|
4595 |
src += 4; |
|
4596 |
dest += 4; |
|
4597 |
} |
|
4598 |
||
4599 |
// tail |
|
4600 |
while (length--) { |
|
4601 |
const quint8 a = src->alpha(); |
|
4602 |
if (a == 0xff) { |
|
4603 |
*dest = DST(*src); |
|
4604 |
} else if (a > 0) { |
|
4605 |
*dest = DST(*src).truncedAlpha() + dest->byte_mul(DST::ialpha(a)); |
|
4606 |
} |
|
4607 |
++dest; |
|
4608 |
++src; |
|
4609 |
} |
|
4610 |
} |
|
4611 |
} |
|
4612 |
||
4613 |
template <class DST, class SRC> |
|
4614 |
Q_STATIC_TEMPLATE_SPECIALIZATION |
|
4615 |
void QT_FASTCALL blendUntransformed(int count, const QSpan *spans, void *userData) |
|
4616 |
{ |
|
4617 |
QSpanData *data = reinterpret_cast<QSpanData*>(userData); |
|
4618 |
QPainter::CompositionMode mode = data->rasterBuffer->compositionMode; |
|
4619 |
||
4620 |
if (mode != QPainter::CompositionMode_SourceOver && |
|
4621 |
mode != QPainter::CompositionMode_Source) |
|
4622 |
{ |
|
4623 |
blend_src_generic<RegularSpans>(count, spans, userData); |
|
4624 |
return; |
|
4625 |
} |
|
4626 |
||
4627 |
const bool modeSource = !SRC::hasAlpha() || |
|
4628 |
mode == QPainter::CompositionMode_Source; |
|
4629 |
const int image_width = data->texture.width; |
|
4630 |
const int image_height = data->texture.height; |
|
4631 |
int xoff = -qRound(-data->dx); |
|
4632 |
int yoff = -qRound(-data->dy); |
|
4633 |
||
4634 |
while (count--) { |
|
4635 |
const quint8 coverage = (data->texture.const_alpha * spans->coverage) >> 8; |
|
4636 |
if (coverage == 0) { |
|
4637 |
++spans; |
|
4638 |
continue; |
|
4639 |
} |
|
4640 |
||
4641 |
int x = spans->x; |
|
4642 |
int length = spans->len; |
|
4643 |
int sx = xoff + x; |
|
4644 |
int sy = yoff + spans->y; |
|
4645 |
if (sy >= 0 && sy < image_height && sx < image_width) { |
|
4646 |
if (sx < 0) { |
|
4647 |
x -= sx; |
|
4648 |
length += sx; |
|
4649 |
sx = 0; |
|
4650 |
} |
|
4651 |
if (sx + length > image_width) |
|
4652 |
length = image_width - sx; |
|
4653 |
if (length > 0) { |
|
4654 |
DST *dest = ((DST*)data->rasterBuffer->scanLine(spans->y)) + x; |
|
4655 |
const SRC *src = (SRC*)data->texture.scanLine(sy) + sx; |
|
4656 |
if (modeSource && coverage == 255) { |
|
4657 |
qt_memconvert<DST, SRC>(dest, src, length); |
|
4658 |
} else if (sizeof(DST) == 3 && sizeof(SRC) == 3 && length >= 3 && |
|
4659 |
(quintptr(dest) & 3) == (quintptr(src) & 3)) |
|
4660 |
{ |
|
4661 |
blendUntransformed_dest24(dest, src, coverage, length); |
|
4662 |
} else if (sizeof(DST) == 2 && sizeof(SRC) == 2 && length >= 3 && |
|
4663 |
(quintptr(dest) & 3) == (quintptr(src) & 3)) |
|
4664 |
{ |
|
4665 |
blendUntransformed_dest16(dest, src, coverage, length); |
|
4666 |
} else { |
|
4667 |
blendUntransformed_unaligned(dest, src, coverage, length); |
|
4668 |
} |
|
4669 |
} |
|
4670 |
} |
|
4671 |
++spans; |
|
4672 |
} |
|
4673 |
} |
|
4674 |
||
4675 |
static void blend_untransformed_rgb888(int count, const QSpan *spans, |
|
4676 |
void *userData) |
|
4677 |
{ |
|
4678 |
#if defined(QT_QWS_DEPTH_24) |
|
4679 |
QSpanData *data = reinterpret_cast<QSpanData *>(userData); |
|
4680 |
||
4681 |
if (data->texture.format == QImage::Format_RGB888) |
|
4682 |
blendUntransformed<qrgb888, qrgb888>(count, spans, userData); |
|
4683 |
else |
|
4684 |
#endif |
|
4685 |
blend_untransformed_generic<RegularSpans>(count, spans, userData); |
|
4686 |
} |
|
4687 |
||
4688 |
static void blend_untransformed_argb6666(int count, const QSpan *spans, |
|
4689 |
void *userData) |
|
4690 |
{ |
|
4691 |
#if defined(QT_QWS_DEPTH_18) |
|
4692 |
QSpanData *data = reinterpret_cast<QSpanData *>(userData); |
|
4693 |
||
4694 |
if (data->texture.format == QImage::Format_ARGB6666_Premultiplied) |
|
4695 |
blendUntransformed<qargb6666, qargb6666>(count, spans, userData); |
|
4696 |
else if (data->texture.format == QImage::Format_RGB666) |
|
4697 |
blendUntransformed<qargb6666, qrgb666>(count, spans, userData); |
|
4698 |
else |
|
4699 |
#endif |
|
4700 |
blend_untransformed_generic<RegularSpans>(count, spans, userData); |
|
4701 |
} |
|
4702 |
||
4703 |
static void blend_untransformed_rgb666(int count, const QSpan *spans, |
|
4704 |
void *userData) |
|
4705 |
{ |
|
4706 |
#if defined(QT_QWS_DEPTH_18) |
|
4707 |
QSpanData *data = reinterpret_cast<QSpanData *>(userData); |
|
4708 |
||
4709 |
if (data->texture.format == QImage::Format_ARGB6666_Premultiplied) |
|
4710 |
blendUntransformed<qrgb666, qargb6666>(count, spans, userData); |
|
4711 |
else if (data->texture.format == QImage::Format_RGB666) |
|
4712 |
blendUntransformed<qrgb666, qrgb666>(count, spans, userData); |
|
4713 |
else |
|
4714 |
#endif |
|
4715 |
blend_untransformed_generic<RegularSpans>(count, spans, userData); |
|
4716 |
} |
|
4717 |
||
4718 |
static void blend_untransformed_argb8565(int count, const QSpan *spans, |
|
4719 |
void *userData) |
|
4720 |
{ |
|
4721 |
#if defined(QT_QWS_DEPTH_16) |
|
4722 |
QSpanData *data = reinterpret_cast<QSpanData *>(userData); |
|
4723 |
||
4724 |
if (data->texture.format == QImage::Format_ARGB8565_Premultiplied) |
|
4725 |
blendUntransformed<qargb8565, qargb8565>(count, spans, userData); |
|
4726 |
else if (data->texture.format == QImage::Format_RGB16) |
|
4727 |
blendUntransformed<qargb8565, qrgb565>(count, spans, userData); |
|
4728 |
else |
|
4729 |
#endif |
|
4730 |
blend_untransformed_generic<RegularSpans>(count, spans, userData); |
|
4731 |
} |
|
4732 |
||
4733 |
static void blend_untransformed_rgb565(int count, const QSpan *spans, |
|
4734 |
void *userData) |
|
4735 |
{ |
|
4736 |
#if defined(QT_QWS_DEPTH_16) |
|
4737 |
QSpanData *data = reinterpret_cast<QSpanData *>(userData); |
|
4738 |
||
4739 |
if (data->texture.format == QImage::Format_ARGB8565_Premultiplied) |
|
4740 |
blendUntransformed<qrgb565, qargb8565>(count, spans, userData); |
|
4741 |
else if (data->texture.format == QImage::Format_RGB16) |
|
4742 |
blendUntransformed<qrgb565, qrgb565>(count, spans, userData); |
|
4743 |
else |
|
4744 |
#endif |
|
4745 |
blend_untransformed_generic<RegularSpans>(count, spans, userData); |
|
4746 |
} |
|
4747 |
||
4748 |
static void blend_untransformed_argb8555(int count, const QSpan *spans, |
|
4749 |
void *userData) |
|
4750 |
{ |
|
4751 |
#if defined(QT_QWS_DEPTH_15) |
|
4752 |
QSpanData *data = reinterpret_cast<QSpanData *>(userData); |
|
4753 |
||
4754 |
if (data->texture.format == QImage::Format_ARGB8555_Premultiplied) |
|
4755 |
blendUntransformed<qargb8555, qargb8555>(count, spans, userData); |
|
4756 |
else if (data->texture.format == QImage::Format_RGB555) |
|
4757 |
blendUntransformed<qargb8555, qrgb555>(count, spans, userData); |
|
4758 |
else |
|
4759 |
#endif |
|
4760 |
blend_untransformed_generic<RegularSpans>(count, spans, userData); |
|
4761 |
} |
|
4762 |
||
4763 |
static void blend_untransformed_rgb555(int count, const QSpan *spans, |
|
4764 |
void *userData) |
|
4765 |
{ |
|
4766 |
#if defined(QT_QWS_DEPTH_15) |
|
4767 |
QSpanData *data = reinterpret_cast<QSpanData *>(userData); |
|
4768 |
||
4769 |
if (data->texture.format == QImage::Format_ARGB8555_Premultiplied) |
|
4770 |
blendUntransformed<qrgb555, qargb8555>(count, spans, userData); |
|
4771 |
else if (data->texture.format == QImage::Format_RGB555) |
|
4772 |
blendUntransformed<qrgb555, qrgb555>(count, spans, userData); |
|
4773 |
else |
|
4774 |
#endif |
|
4775 |
blend_untransformed_generic<RegularSpans>(count, spans, userData); |
|
4776 |
} |
|
4777 |
||
4778 |
static void blend_untransformed_argb4444(int count, const QSpan *spans, |
|
4779 |
void *userData) |
|
4780 |
{ |
|
4781 |
#if defined(QT_QWS_DEPTH_12) |
|
4782 |
QSpanData *data = reinterpret_cast<QSpanData *>(userData); |
|
4783 |
||
4784 |
if (data->texture.format == QImage::Format_ARGB4444_Premultiplied) |
|
4785 |
blendUntransformed<qargb4444, qargb4444>(count, spans, userData); |
|
4786 |
else if (data->texture.format == QImage::Format_RGB444) |
|
4787 |
blendUntransformed<qargb4444, qrgb444>(count, spans, userData); |
|
4788 |
else |
|
4789 |
#endif |
|
4790 |
blend_untransformed_generic<RegularSpans>(count, spans, userData); |
|
4791 |
} |
|
4792 |
||
4793 |
static void blend_untransformed_rgb444(int count, const QSpan *spans, |
|
4794 |
void *userData) |
|
4795 |
{ |
|
4796 |
#if defined(QT_QWS_DEPTH_12) |
|
4797 |
QSpanData *data = reinterpret_cast<QSpanData *>(userData); |
|
4798 |
||
4799 |
if (data->texture.format == QImage::Format_ARGB4444_Premultiplied) |
|
4800 |
blendUntransformed<qrgb444, qargb4444>(count, spans, userData); |
|
4801 |
else if (data->texture.format == QImage::Format_RGB444) |
|
4802 |
blendUntransformed<qrgb444, qrgb444>(count, spans, userData); |
|
4803 |
else |
|
4804 |
#endif |
|
4805 |
blend_untransformed_generic<RegularSpans>(count, spans, userData); |
|
4806 |
} |
|
4807 |
||
4808 |
template <SpanMethod spanMethod> |
|
4809 |
Q_STATIC_TEMPLATE_FUNCTION void blend_tiled_generic(int count, const QSpan *spans, void *userData) |
|
4810 |
{ |
|
4811 |
QSpanData *data = reinterpret_cast<QSpanData *>(userData); |
|
4812 |
||
4813 |
uint buffer[buffer_size]; |
|
4814 |
uint src_buffer[buffer_size]; |
|
4815 |
Operator op = getOperator(data, spans, count); |
|
4816 |
||
4817 |
const int image_width = data->texture.width; |
|
4818 |
const int image_height = data->texture.height; |
|
4819 |
int xoff = -qRound(-data->dx) % image_width; |
|
4820 |
int yoff = -qRound(-data->dy) % image_height; |
|
4821 |
||
4822 |
if (xoff < 0) |
|
4823 |
xoff += image_width; |
|
4824 |
if (yoff < 0) |
|
4825 |
yoff += image_height; |
|
4826 |
||
4827 |
while (count--) { |
|
4828 |
int x = spans->x; |
|
4829 |
int length = spans->len; |
|
4830 |
int sx = (xoff + spans->x) % image_width; |
|
4831 |
int sy = (spans->y + yoff) % image_height; |
|
4832 |
if (sx < 0) |
|
4833 |
sx += image_width; |
|
4834 |
if (sy < 0) |
|
4835 |
sy += image_height; |
|
4836 |
||
4837 |
const int coverage = (spans->coverage * data->texture.const_alpha) >> 8; |
|
4838 |
while (length) { |
|
4839 |
int l = qMin(image_width - sx, length); |
|
4840 |
if (buffer_size < l) |
|
4841 |
l = buffer_size; |
|
4842 |
const uint *src = op.src_fetch(src_buffer, &op, data, sy, sx, l); |
|
4843 |
if (spanMethod == RegularSpans) { |
|
4844 |
uint *dest = op.dest_fetch ? op.dest_fetch(buffer, data->rasterBuffer, x, spans->y, l) : buffer; |
|
4845 |
op.func(dest, src, l, coverage); |
|
4846 |
if (op.dest_store) |
|
4847 |
op.dest_store(data->rasterBuffer, x, spans->y, dest, l); |
|
4848 |
} else { |
|
4849 |
drawBufferSpan(data, src, l, x, spans->y, l, |
|
4850 |
coverage); |
|
4851 |
} |
|
4852 |
x += l; |
|
4853 |
sx += l; |
|
4854 |
length -= l; |
|
4855 |
if (sx >= image_width) |
|
4856 |
sx = 0; |
|
4857 |
} |
|
4858 |
++spans; |
|
4859 |
} |
|
4860 |
} |
|
4861 |
||
4862 |
template <SpanMethod spanMethod> |
|
4863 |
Q_STATIC_TEMPLATE_FUNCTION void blend_tiled_argb(int count, const QSpan *spans, void *userData) |
|
4864 |
{ |
|
4865 |
QSpanData *data = reinterpret_cast<QSpanData *>(userData); |
|
4866 |
if (data->texture.format != QImage::Format_ARGB32_Premultiplied |
|
4867 |
&& data->texture.format != QImage::Format_RGB32) { |
|
4868 |
blend_tiled_generic<spanMethod>(count, spans, userData); |
|
4869 |
return; |
|
4870 |
} |
|
4871 |
||
4872 |
Operator op = getOperator(data, spans, count); |
|
4873 |
||
4874 |
int image_width = data->texture.width; |
|
4875 |
int image_height = data->texture.height; |
|
4876 |
int xoff = -qRound(-data->dx) % image_width; |
|
4877 |
int yoff = -qRound(-data->dy) % image_height; |
|
4878 |
||
4879 |
if (xoff < 0) |
|
4880 |
xoff += image_width; |
|
4881 |
if (yoff < 0) |
|
4882 |
yoff += image_height; |
|
4883 |
||
4884 |
while (count--) { |
|
4885 |
int x = spans->x; |
|
4886 |
int length = spans->len; |
|
4887 |
int sx = (xoff + spans->x) % image_width; |
|
4888 |
int sy = (spans->y + yoff) % image_height; |
|
4889 |
if (sx < 0) |
|
4890 |
sx += image_width; |
|
4891 |
if (sy < 0) |
|
4892 |
sy += image_height; |
|
4893 |
||
4894 |
const int coverage = (spans->coverage * data->texture.const_alpha) >> 8; |
|
4895 |
while (length) { |
|
4896 |
int l = qMin(image_width - sx, length); |
|
4897 |
if (buffer_size < l) |
|
4898 |
l = buffer_size; |
|
4899 |
const uint *src = (uint *)data->texture.scanLine(sy) + sx; |
|
4900 |
if (spanMethod == RegularSpans) { |
|
4901 |
uint *dest = ((uint *)data->rasterBuffer->scanLine(spans->y)) + x; |
|
4902 |
op.func(dest, src, l, coverage); |
|
4903 |
} else { |
|
4904 |
drawBufferSpan(data, src, buffer_size, |
|
4905 |
x, spans->y, l, coverage); |
|
4906 |
} |
|
4907 |
x += l; |
|
4908 |
length -= l; |
|
4909 |
sx = 0; |
|
4910 |
} |
|
4911 |
++spans; |
|
4912 |
} |
|
4913 |
} |
|
4914 |
||
4915 |
template <class DST, class SRC> |
|
4916 |
Q_STATIC_TEMPLATE_FUNCTION void blendTiled(int count, const QSpan *spans, void *userData) |
|
4917 |
{ |
|
4918 |
QSpanData *data = reinterpret_cast<QSpanData*>(userData); |
|
4919 |
QPainter::CompositionMode mode = data->rasterBuffer->compositionMode; |
|
4920 |
||
4921 |
if (mode != QPainter::CompositionMode_SourceOver && |
|
4922 |
mode != QPainter::CompositionMode_Source) |
|
4923 |
{ |
|
4924 |
blend_src_generic<RegularSpans>(count, spans, userData); |
|
4925 |
return; |
|
4926 |
} |
|
4927 |
||
4928 |
const bool modeSource = !SRC::hasAlpha() || |
|
4929 |
mode == QPainter::CompositionMode_Source; |
|
4930 |
const int image_width = data->texture.width; |
|
4931 |
const int image_height = data->texture.height; |
|
4932 |
int xoff = -qRound(-data->dx) % image_width; |
|
4933 |
int yoff = -qRound(-data->dy) % image_height; |
|
4934 |
||
4935 |
if (xoff < 0) |
|
4936 |
xoff += image_width; |
|
4937 |
if (yoff < 0) |
|
4938 |
yoff += image_height; |
|
4939 |
||
4940 |
while (count--) { |
|
4941 |
const quint8 coverage = (data->texture.const_alpha * spans->coverage) >> 8; |
|
4942 |
if (coverage == 0) { |
|
4943 |
++spans; |
|
4944 |
continue; |
|
4945 |
} |
|
4946 |
||
4947 |
int x = spans->x; |
|
4948 |
int length = spans->len; |
|
4949 |
int sx = (xoff + spans->x) % image_width; |
|
4950 |
int sy = (spans->y + yoff) % image_height; |
|
4951 |
if (sx < 0) |
|
4952 |
sx += image_width; |
|
4953 |
if (sy < 0) |
|
4954 |
sy += image_height; |
|
4955 |
||
4956 |
if (modeSource && coverage == 255) { |
|
4957 |
// Copy the first texture block |
|
4958 |
length = qMin(image_width,length); |
|
4959 |
int tx = x; |
|
4960 |
while (length) { |
|
4961 |
int l = qMin(image_width - sx, length); |
|
4962 |
if (buffer_size < l) |
|
4963 |
l = buffer_size; |
|
4964 |
DST *dest = ((DST*)data->rasterBuffer->scanLine(spans->y)) + tx; |
|
4965 |
const SRC *src = (SRC*)data->texture.scanLine(sy) + sx; |
|
4966 |
||
4967 |
qt_memconvert<DST, SRC>(dest, src, l); |
|
4968 |
length -= l; |
|
4969 |
tx += l; |
|
4970 |
sx = 0; |
|
4971 |
} |
|
4972 |
||
4973 |
// Now use the rasterBuffer as the source of the texture, |
|
4974 |
// We can now progressively copy larger blocks |
|
4975 |
// - Less cpu time in code figuring out what to copy |
|
4976 |
// We are dealing with one block of data |
|
4977 |
// - More likely to fit in the cache |
|
4978 |
// - can use memcpy |
|
4979 |
int copy_image_width = qMin(image_width, int(spans->len)); |
|
4980 |
length = spans->len - copy_image_width; |
|
4981 |
DST *src = ((DST*)data->rasterBuffer->scanLine(spans->y)) + x; |
|
4982 |
DST *dest = src + copy_image_width; |
|
4983 |
while (copy_image_width < length) { |
|
4984 |
qt_memconvert(dest, src, copy_image_width); |
|
4985 |
dest += copy_image_width; |
|
4986 |
length -= copy_image_width; |
|
4987 |
copy_image_width *= 2; |
|
4988 |
} |
|
4989 |
qt_memconvert(dest, src, length); |
|
4990 |
} else { |
|
4991 |
while (length) { |
|
4992 |
int l = qMin(image_width - sx, length); |
|
4993 |
if (buffer_size < l) |
|
4994 |
l = buffer_size; |
|
4995 |
DST *dest = ((DST*)data->rasterBuffer->scanLine(spans->y)) + x; |
|
4996 |
const SRC *src = (SRC*)data->texture.scanLine(sy) + sx; |
|
4997 |
if (sizeof(DST) == 3 && sizeof(SRC) == 3 && l >= 4 && |
|
4998 |
(quintptr(dest) & 3) == (quintptr(src) & 3)) |
|
4999 |
{ |
|
5000 |
blendUntransformed_dest24(dest, src, coverage, l); |
|
5001 |
} else if (sizeof(DST) == 2 && sizeof(SRC) == 2 && l >= 2 && |
|
5002 |
(quintptr(dest) & 3) == (quintptr(src) & 3)) |
|
5003 |
{ |
|
5004 |
blendUntransformed_dest16(dest, src, coverage, l); |
|
5005 |
} else { |
|
5006 |
blendUntransformed_unaligned(dest, src, coverage, l); |
|
5007 |
} |
|
5008 |
||
5009 |
x += l; |
|
5010 |
length -= l; |
|
5011 |
sx = 0; |
|
5012 |
} |
|
5013 |
} |
|
5014 |
++spans; |
|
5015 |
} |
|
5016 |
} |
|
5017 |
||
5018 |
static void blend_tiled_rgb888(int count, const QSpan *spans, void *userData) |
|
5019 |
{ |
|
5020 |
#if defined(QT_QWS_DEPTH_24) |
|
5021 |
QSpanData *data = reinterpret_cast<QSpanData *>(userData); |
|
5022 |
||
5023 |
if (data->texture.format == QImage::Format_RGB888) |
|
5024 |
blendTiled<qrgb888, qrgb888>(count, spans, userData); |
|
5025 |
else |
|
5026 |
#endif |
|
5027 |
blend_tiled_generic<RegularSpans>(count, spans, userData); |
|
5028 |
} |
|
5029 |
||
5030 |
static void blend_tiled_argb6666(int count, const QSpan *spans, void *userData) |
|
5031 |
{ |
|
5032 |
#if defined(QT_QWS_DEPTH_18) |
|
5033 |
QSpanData *data = reinterpret_cast<QSpanData *>(userData); |
|
5034 |
||
5035 |
if (data->texture.format == QImage::Format_ARGB6666_Premultiplied) |
|
5036 |
blendTiled<qargb6666, qargb6666>(count, spans, userData); |
|
5037 |
else if (data->texture.format == QImage::Format_RGB666) |
|
5038 |
blendTiled<qargb6666, qrgb666>(count, spans, userData); |
|
5039 |
else |
|
5040 |
#endif |
|
5041 |
blend_tiled_generic<RegularSpans>(count, spans, userData); |
|
5042 |
} |
|
5043 |
||
5044 |
static void blend_tiled_rgb666(int count, const QSpan *spans, void *userData) |
|
5045 |
{ |
|
5046 |
#if defined(QT_QWS_DEPTH_18) |
|
5047 |
QSpanData *data = reinterpret_cast<QSpanData *>(userData); |
|
5048 |
||
5049 |
if (data->texture.format == QImage::Format_ARGB6666_Premultiplied) |
|
5050 |
blendTiled<qrgb666, qargb6666>(count, spans, userData); |
|
5051 |
else if (data->texture.format == QImage::Format_RGB666) |
|
5052 |
blendTiled<qrgb666, qrgb666>(count, spans, userData); |
|
5053 |
else |
|
5054 |
#endif |
|
5055 |
blend_tiled_generic<RegularSpans>(count, spans, userData); |
|
5056 |
} |
|
5057 |
||
5058 |
static void blend_tiled_argb8565(int count, const QSpan *spans, void *userData) |
|
5059 |
{ |
|
5060 |
#if defined(QT_QWS_DEPTH_16) |
|
5061 |
QSpanData *data = reinterpret_cast<QSpanData *>(userData); |
|
5062 |
||
5063 |
if (data->texture.format == QImage::Format_ARGB8565_Premultiplied) |
|
5064 |
blendTiled<qargb8565, qargb8565>(count, spans, userData); |
|
5065 |
else if (data->texture.format == QImage::Format_RGB16) |
|
5066 |
blendTiled<qargb8565, qrgb565>(count, spans, userData); |
|
5067 |
else |
|
5068 |
#endif |
|
5069 |
blend_tiled_generic<RegularSpans>(count, spans, userData); |
|
5070 |
} |
|
5071 |
||
5072 |
static void blend_tiled_rgb565(int count, const QSpan *spans, void *userData) |
|
5073 |
{ |
|
5074 |
#if defined(QT_QWS_DEPTH_16) |
|
5075 |
QSpanData *data = reinterpret_cast<QSpanData *>(userData); |
|
5076 |
||
5077 |
if (data->texture.format == QImage::Format_ARGB8565_Premultiplied) |
|
5078 |
blendTiled<qrgb565, qargb8565>(count, spans, userData); |
|
5079 |
else if (data->texture.format == QImage::Format_RGB16) |
|
5080 |
blendTiled<qrgb565, qrgb565>(count, spans, userData); |
|
5081 |
else |
|
5082 |
#endif |
|
5083 |
blend_tiled_generic<RegularSpans>(count, spans, userData); |
|
5084 |
} |
|
5085 |
||
5086 |
static void blend_tiled_argb8555(int count, const QSpan *spans, void *userData) |
|
5087 |
{ |
|
5088 |
#if defined(QT_QWS_DEPTH_15) |
|
5089 |
QSpanData *data = reinterpret_cast<QSpanData *>(userData); |
|
5090 |
||
5091 |
if (data->texture.format == QImage::Format_ARGB8555_Premultiplied) |
|
5092 |
blendTiled<qargb8555, qargb8555>(count, spans, userData); |
|
5093 |
else if (data->texture.format == QImage::Format_RGB555) |
|
5094 |
blendTiled<qargb8555, qrgb555>(count, spans, userData); |
|
5095 |
else |
|
5096 |
#endif |
|
5097 |
blend_tiled_generic<RegularSpans>(count, spans, userData); |
|
5098 |
} |
|
5099 |
||
5100 |
static void blend_tiled_rgb555(int count, const QSpan *spans, void *userData) |
|
5101 |
{ |
|
5102 |
#if defined(QT_QWS_DEPTH_15) |
|
5103 |
QSpanData *data = reinterpret_cast<QSpanData *>(userData); |
|
5104 |
||
5105 |
if (data->texture.format == QImage::Format_ARGB8555_Premultiplied) |
|
5106 |
blendTiled<qrgb555, qargb8555>(count, spans, userData); |
|
5107 |
else if (data->texture.format == QImage::Format_RGB555) |
|
5108 |
blendTiled<qrgb555, qrgb555>(count, spans, userData); |
|
5109 |
else |
|
5110 |
#endif |
|
5111 |
blend_tiled_generic<RegularSpans>(count, spans, userData); |
|
5112 |
} |
|
5113 |
||
5114 |
static void blend_tiled_argb4444(int count, const QSpan *spans, void *userData) |
|
5115 |
{ |
|
5116 |
#if defined(QT_QWS_DEPTH_12) |
|
5117 |
QSpanData *data = reinterpret_cast<QSpanData *>(userData); |
|
5118 |
||
5119 |
if (data->texture.format == QImage::Format_ARGB4444_Premultiplied) |
|
5120 |
blendTiled<qargb4444, qargb4444>(count, spans, userData); |
|
5121 |
else if (data->texture.format == QImage::Format_RGB444) |
|
5122 |
blendTiled<qargb4444, qrgb444>(count, spans, userData); |
|
5123 |
else |
|
5124 |
#endif |
|
5125 |
blend_tiled_generic<RegularSpans>(count, spans, userData); |
|
5126 |
} |
|
5127 |
||
5128 |
static void blend_tiled_rgb444(int count, const QSpan *spans, void *userData) |
|
5129 |
{ |
|
5130 |
#if defined(QT_QWS_DEPTH_12) |
|
5131 |
QSpanData *data = reinterpret_cast<QSpanData *>(userData); |
|
5132 |
||
5133 |
if (data->texture.format == QImage::Format_ARGB4444_Premultiplied) |
|
5134 |
blendTiled<qrgb444, qargb4444>(count, spans, userData); |
|
5135 |
else if (data->texture.format == QImage::Format_RGB444) |
|
5136 |
blendTiled<qrgb444, qrgb444>(count, spans, userData); |
|
5137 |
else |
|
5138 |
#endif |
|
5139 |
blend_tiled_generic<RegularSpans>(count, spans, userData); |
|
5140 |
} |
|
5141 |
||
5142 |
||
5143 |
template <SpanMethod spanMethod> |
|
5144 |
Q_STATIC_TEMPLATE_FUNCTION void blend_transformed_bilinear_argb(int count, const QSpan *spans, void *userData) |
|
5145 |
{ |
|
5146 |
QSpanData *data = reinterpret_cast<QSpanData *>(userData); |
|
5147 |
if (data->texture.format != QImage::Format_ARGB32_Premultiplied |
|
5148 |
&& data->texture.format != QImage::Format_RGB32) { |
|
5149 |
blend_src_generic<spanMethod>(count, spans, userData); |
|
5150 |
return; |
|
5151 |
} |
|
5152 |
||
5153 |
CompositionFunction func = functionForMode[data->rasterBuffer->compositionMode]; |
|
5154 |
uint buffer[buffer_size]; |
|
5155 |
||
5156 |
int image_x1 = data->texture.x1; |
|
5157 |
int image_y1 = data->texture.y1; |
|
5158 |
int image_x2 = data->texture.x2; |
|
5159 |
int image_y2 = data->texture.y2; |
|
5160 |
const int scanline_offset = data->texture.bytesPerLine / 4; |
|
5161 |
||
5162 |
if (data->fast_matrix) { |
|
5163 |
// The increment pr x in the scanline |
|
5164 |
int fdx = (int)(data->m11 * fixed_scale); |
|
5165 |
int fdy = (int)(data->m12 * fixed_scale); |
|
5166 |
||
5167 |
while (count--) { |
|
5168 |
void *t = data->rasterBuffer->scanLine(spans->y); |
|
5169 |
||
5170 |
uint *target = ((uint *)t) + spans->x; |
|
5171 |
uint *image_bits = (uint *)data->texture.imageData; |
|
5172 |
||
5173 |
const qreal cx = spans->x + 0.5; |
|
5174 |
const qreal cy = spans->y + 0.5; |
|
5175 |
||
5176 |
int x = int((data->m21 * cy |
|
5177 |
+ data->m11 * cx + data->dx) * fixed_scale) - half_point; |
|
5178 |
int y = int((data->m22 * cy |
|
5179 |
+ data->m12 * cx + data->dy) * fixed_scale) - half_point; |
|
5180 |
||
5181 |
int length = spans->len; |
|
5182 |
const int coverage = (data->texture.const_alpha * spans->coverage) >> 8; |
|
5183 |
while (length) { |
|
5184 |
int l = qMin(length, buffer_size); |
|
5185 |
const uint *end = buffer + l; |
|
5186 |
uint *b = buffer; |
|
5187 |
while (b < end) { |
|
5188 |
int x1 = (x >> 16); |
|
5189 |
int x2 = x1 + 1; |
|
5190 |
int y1 = (y >> 16); |
|
5191 |
int y2 = y1 + 1; |
|
5192 |
||
5193 |
int distx = ((x - (x1 << 16)) >> 8); |
|
5194 |
int disty = ((y - (y1 << 16)) >> 8); |
|
5195 |
int idistx = 256 - distx; |
|
5196 |
int idisty = 256 - disty; |
|
5197 |
||
5198 |
x1 = qBound(image_x1, x1, image_x2 - 1); |
|
5199 |
x2 = qBound(image_x1, x2, image_x2 - 1); |
|
5200 |
y1 = qBound(image_y1, y1, image_y2 - 1); |
|
5201 |
y2 = qBound(image_y1, y2, image_y2 - 1); |
|
5202 |
||
5203 |
int y1_offset = y1 * scanline_offset; |
|
5204 |
int y2_offset = y2 * scanline_offset; |
|
5205 |
||
5206 |
#if defined(Q_IRIX_GCC3_3_WORKAROUND) |
|
5207 |
uint tl = gccBug(image_bits[y1_offset + x1]); |
|
5208 |
uint tr = gccBug(image_bits[y1_offset + x2]); |
|
5209 |
uint bl = gccBug(image_bits[y2_offset + x1]); |
|
5210 |
uint br = gccBug(image_bits[y2_offset + x2]); |
|
5211 |
#else |
|
5212 |
uint tl = image_bits[y1_offset + x1]; |
|
5213 |
uint tr = image_bits[y1_offset + x2]; |
|
5214 |
uint bl = image_bits[y2_offset + x1]; |
|
5215 |
uint br = image_bits[y2_offset + x2]; |
|
5216 |
#endif |
|
5217 |
||
5218 |
uint xtop = INTERPOLATE_PIXEL_256(tl, idistx, tr, distx); |
|
5219 |
uint xbot = INTERPOLATE_PIXEL_256(bl, idistx, br, distx); |
|
5220 |
*b = INTERPOLATE_PIXEL_256(xtop, idisty, xbot, disty); |
|
5221 |
++b; |
|
5222 |
||
5223 |
x += fdx; |
|
5224 |
y += fdy; |
|
5225 |
} |
|
5226 |
if (spanMethod == RegularSpans) |
|
5227 |
func(target, buffer, l, coverage); |
|
5228 |
else |
|
5229 |
drawBufferSpan(data, buffer, buffer_size, |
|
5230 |
spans->x + spans->len - length, |
|
5231 |
spans->y, l, coverage); |
|
5232 |
target += l; |
|
5233 |
length -= l; |
|
5234 |
} |
|
5235 |
++spans; |
|
5236 |
} |
|
5237 |
} else { |
|
5238 |
const qreal fdx = data->m11; |
|
5239 |
const qreal fdy = data->m12; |
|
5240 |
const qreal fdw = data->m13; |
|
5241 |
||
5242 |
while (count--) { |
|
5243 |
void *t = data->rasterBuffer->scanLine(spans->y); |
|
5244 |
||
5245 |
uint *target = ((uint *)t) + spans->x; |
|
5246 |
uint *image_bits = (uint *)data->texture.imageData; |
|
5247 |
||
5248 |
const qreal cx = spans->x + 0.5; |
|
5249 |
const qreal cy = spans->y + 0.5; |
|
5250 |
||
5251 |
qreal x = data->m21 * cy + data->m11 * cx + data->dx; |
|
5252 |
qreal y = data->m22 * cy + data->m12 * cx + data->dy; |
|
5253 |
qreal w = data->m23 * cy + data->m13 * cx + data->m33; |
|
5254 |
||
5255 |
int length = spans->len; |
|
5256 |
const int coverage = (data->texture.const_alpha * spans->coverage) >> 8; |
|
5257 |
while (length) { |
|
5258 |
int l = qMin(length, buffer_size); |
|
5259 |
const uint *end = buffer + l; |
|
5260 |
uint *b = buffer; |
|
5261 |
while (b < end) { |
|
5262 |
const qreal iw = w == 0 ? 1 : 1 / w; |
|
5263 |
const qreal px = x * iw - 0.5; |
|
5264 |
const qreal py = y * iw - 0.5; |
|
5265 |
||
5266 |
int x1 = int(px) - (px < 0); |
|
5267 |
int x2 = x1 + 1; |
|
5268 |
int y1 = int(py) - (py < 0); |
|
5269 |
int y2 = y1 + 1; |
|
5270 |
||
5271 |
int distx = int((px - x1) * 256); |
|
5272 |
int disty = int((py - y1) * 256); |
|
5273 |
int idistx = 256 - distx; |
|
5274 |
int idisty = 256 - disty; |
|
5275 |
||
5276 |
x1 = qBound(image_x1, x1, image_x2 - 1); |
|
5277 |
x2 = qBound(image_x1, x2, image_x2 - 1); |
|
5278 |
y1 = qBound(image_y1, y1, image_y2 - 1); |
|
5279 |
y2 = qBound(image_y1, y2, image_y2 - 1); |
|
5280 |
||
5281 |
int y1_offset = y1 * scanline_offset; |
|
5282 |
int y2_offset = y2 * scanline_offset; |
|
5283 |
||
5284 |
#if defined(Q_IRIX_GCC3_3_WORKAROUND) |
|
5285 |
uint tl = gccBug(image_bits[y1_offset + x1]); |
|
5286 |
uint tr = gccBug(image_bits[y1_offset + x2]); |
|
5287 |
uint bl = gccBug(image_bits[y2_offset + x1]); |
|
5288 |
uint br = gccBug(image_bits[y2_offset + x2]); |
|
5289 |
#else |
|
5290 |
uint tl = image_bits[y1_offset + x1]; |
|
5291 |
uint tr = image_bits[y1_offset + x2]; |
|
5292 |
uint bl = image_bits[y2_offset + x1]; |
|
5293 |
uint br = image_bits[y2_offset + x2]; |
|
5294 |
#endif |
|
5295 |
||
5296 |
uint xtop = INTERPOLATE_PIXEL_256(tl, idistx, tr, distx); |
|
5297 |
uint xbot = INTERPOLATE_PIXEL_256(bl, idistx, br, distx); |
|
5298 |
*b = INTERPOLATE_PIXEL_256(xtop, idisty, xbot, disty); |
|
5299 |
++b; |
|
5300 |
||
5301 |
x += fdx; |
|
5302 |
y += fdy; |
|
5303 |
w += fdw; |
|
5304 |
} |
|
5305 |
if (spanMethod == RegularSpans) |
|
5306 |
func(target, buffer, l, coverage); |
|
5307 |
else |
|
5308 |
drawBufferSpan(data, buffer, buffer_size, |
|
5309 |
spans->x + spans->len - length, |
|
5310 |
spans->y, l, coverage); |
|
5311 |
target += l; |
|
5312 |
length -= l; |
|
5313 |
} |
|
5314 |
++spans; |
|
5315 |
} |
|
5316 |
} |
|
5317 |
} |
|
5318 |
||
5319 |
template <class DST, class SRC> |
|
5320 |
Q_STATIC_TEMPLATE_FUNCTION void blendTransformedBilinear(int count, const QSpan *spans, |
|
5321 |
void *userData) |
|
5322 |
{ |
|
5323 |
QSpanData *data = reinterpret_cast<QSpanData*>(userData); |
|
5324 |
QPainter::CompositionMode mode = data->rasterBuffer->compositionMode; |
|
5325 |
||
5326 |
||
5327 |
if (mode != QPainter::CompositionMode_SourceOver) { |
|
5328 |
blend_src_generic<RegularSpans>(count, spans, userData); |
|
5329 |
return; |
|
5330 |
} |
|
5331 |
||
5332 |
SRC buffer[buffer_size]; |
|
5333 |
||
5334 |
const int src_minx = data->texture.x1; |
|
5335 |
const int src_miny = data->texture.y1; |
|
5336 |
const int src_maxx = data->texture.x2 - 1; |
|
5337 |
const int src_maxy = data->texture.y2 - 1; |
|
5338 |
||
5339 |
if (data->fast_matrix) { |
|
5340 |
// The increment pr x in the scanline |
|
5341 |
const int fdx = (int)(data->m11 * fixed_scale); |
|
5342 |
const int fdy = (int)(data->m12 * fixed_scale); |
|
5343 |
||
5344 |
while (count--) { |
|
5345 |
const quint8 coverage = (data->texture.const_alpha * spans->coverage) >> 8; |
|
5346 |
if (coverage == 0) { |
|
5347 |
++spans; |
|
5348 |
continue; |
|
5349 |
} |
|
5350 |
||
5351 |
DST *dest = (DST*)data->rasterBuffer->scanLine(spans->y) |
|
5352 |
+ spans->x; |
|
5353 |
const qreal cx = spans->x + qreal(0.5); |
|
5354 |
const qreal cy = spans->y + qreal(0.5); |
|
5355 |
int x = int((data->m21 * cy |
|
5356 |
+ data->m11 * cx + data->dx) * fixed_scale) - half_point; |
|
5357 |
int y = int((data->m22 * cy |
|
5358 |
+ data->m12 * cx + data->dy) * fixed_scale) - half_point; |
|
5359 |
int length = spans->len; |
|
5360 |
||
5361 |
while (length) { |
|
5362 |
const int l = qMin(length, buffer_size); |
|
5363 |
||
5364 |
const SRC *end = buffer + l; |
|
5365 |
SRC *b = buffer; |
|
5366 |
while (b < end) { |
|
5367 |
int x1 = (x >> 16); |
|
5368 |
int x2 = x1 + 1; |
|
5369 |
int y1 = (y >> 16); |
|
5370 |
int y2 = y1 + 1; |
|
5371 |
||
5372 |
const int distx = ((x - (x1 << 16)) >> 8); |
|
5373 |
const int disty = ((y - (y1 << 16)) >> 8); |
|
5374 |
x1 = qBound(src_minx, x1, src_maxx); |
|
5375 |
x2 = qBound(src_minx, x2, src_maxx); |
|
5376 |
y1 = qBound(src_miny, y1, src_maxy); |
|
5377 |
y2 = qBound(src_miny, y2, src_maxy); |
|
5378 |
||
5379 |
#if 0 |
|
5380 |
if (x1 == x2) { |
|
5381 |
if (y1 == y2) { |
|
5382 |
*b = ((SRC*)data->texture.scanLine(y1))[x1]; |
|
5383 |
} else { |
|
5384 |
*b = ((SRC*)data->texture.scanLine(y1))[x1]; |
|
5385 |
const SRC t = data->texture.scanLine(y2)[x1]; |
|
5386 |
interpolate_pixel(*b, SRC::ialpha(disty), |
|
5387 |
t, SRC::alpha(disty)); |
|
5388 |
} |
|
5389 |
} else if (y1 == y2) { |
|
5390 |
*b = ((SRC*)data->texture.scanLine(y1))[x1]; |
|
5391 |
const SRC t = ((SRC*)data->texture.scanLine(y1))[x2]; |
|
5392 |
interpolate_pixel(*b, SRC::ialpha(distx), |
|
5393 |
t, SRC::alpha(distx)); |
|
5394 |
} else |
|
5395 |
#endif |
|
5396 |
{ |
|
5397 |
const SRC *src1 = (SRC*)data->texture.scanLine(y1); |
|
5398 |
const SRC *src2 = (SRC*)data->texture.scanLine(y2); |
|
5399 |
SRC tl = src1[x1]; |
|
5400 |
const SRC tr = src1[x2]; |
|
5401 |
SRC bl = src2[x1]; |
|
5402 |
const SRC br = src2[x2]; |
|
5403 |
const quint8 ax = SRC::alpha(distx); |
|
5404 |
const quint8 iax = SRC::ialpha(distx); |
|
5405 |
||
5406 |
interpolate_pixel(tl, iax, tr, ax); |
|
5407 |
interpolate_pixel(bl, iax, br, ax); |
|
5408 |
interpolate_pixel(tl, SRC::ialpha(disty), |
|
5409 |
bl, SRC::alpha(disty)); |
|
5410 |
*b = tl; |
|
5411 |
} |
|
5412 |
++b; |
|
5413 |
||
5414 |
x += fdx; |
|
5415 |
y += fdy; |
|
5416 |
} |
|
5417 |
||
5418 |
if (!SRC::hasAlpha() && coverage == 255) { |
|
5419 |
qt_memconvert(dest, buffer, l); |
|
5420 |
} else if (sizeof(DST) == 3 && l >= 4 && |
|
5421 |
(quintptr(dest) & 3) == (quintptr(buffer) & 3)) |
|
5422 |
{ |
|
5423 |
blendUntransformed_dest24(dest, buffer, coverage, l); |
|
5424 |
} else if (sizeof(DST) == 2 && sizeof(SRC) == 2 && l >= 2 && |
|
5425 |
(quintptr(dest) & 3) == (quintptr(buffer) & 3)) { |
|
5426 |
blendUntransformed_dest16(dest, buffer, coverage, l); |
|
5427 |
} else { |
|
5428 |
blendUntransformed_unaligned(dest, buffer, coverage, l); |
|
5429 |
} |
|
5430 |
||
5431 |
dest += l; |
|
5432 |
length -= l; |
|
5433 |
} |
|
5434 |
++spans; |
|
5435 |
} |
|
5436 |
} else { |
|
5437 |
const qreal fdx = data->m11; |
|
5438 |
const qreal fdy = data->m12; |
|
5439 |
const qreal fdw = data->m13; |
|
5440 |
||
5441 |
while (count--) { |
|
5442 |
const quint8 coverage = (data->texture.const_alpha * spans->coverage) >> 8; |
|
5443 |
if (coverage == 0) { |
|
5444 |
++spans; |
|
5445 |
continue; |
|
5446 |
} |
|
5447 |
||
5448 |
DST *dest = (DST*)data->rasterBuffer->scanLine(spans->y) |
|
5449 |
+ spans->x; |
|
5450 |
||
5451 |
const qreal cx = spans->x + qreal(0.5); |
|
5452 |
const qreal cy = spans->y + qreal(0.5); |
|
5453 |
||
5454 |
qreal x = data->m21 * cy + data->m11 * cx + data->dx; |
|
5455 |
qreal y = data->m22 * cy + data->m12 * cx + data->dy; |
|
5456 |
qreal w = data->m23 * cy + data->m13 * cx + data->m33; |
|
5457 |
||
5458 |
int length = spans->len; |
|
5459 |
while (length) { |
|
5460 |
const int l = qMin(length, buffer_size); |
|
5461 |
const SRC *end = buffer + l; |
|
5462 |
SRC *b = buffer; |
|
5463 |
while (b < end) { |
|
5464 |
const qreal iw = w == 0 ? 1 : 1 / w; |
|
5465 |
const qreal px = x * iw - qreal(0.5); |
|
5466 |
const qreal py = y * iw - qreal(0.5); |
|
5467 |
||
5468 |
int x1 = int(px) - (px < 0); |
|
5469 |
int x2 = x1 + 1; |
|
5470 |
int y1 = int(py) - (py < 0); |
|
5471 |
int y2 = y1 + 1; |
|
5472 |
||
5473 |
const int distx = int((px - x1) * 256); |
|
5474 |
const int disty = int((py - y1) * 256); |
|
5475 |
||
5476 |
x1 = qBound(src_minx, x1, src_maxx); |
|
5477 |
x2 = qBound(src_minx, x2, src_maxx); |
|
5478 |
y1 = qBound(src_miny, y1, src_maxy); |
|
5479 |
y2 = qBound(src_miny, y2, src_maxy); |
|
5480 |
||
5481 |
const SRC *src1 = (SRC*)data->texture.scanLine(y1); |
|
5482 |
const SRC *src2 = (SRC*)data->texture.scanLine(y2); |
|
5483 |
SRC tl = src1[x1]; |
|
5484 |
const SRC tr = src1[x2]; |
|
5485 |
SRC bl = src2[x1]; |
|
5486 |
const SRC br = src2[x2]; |
|
5487 |
const quint8 ax = SRC::alpha(distx); |
|
5488 |
const quint8 iax = SRC::ialpha(distx); |
|
5489 |
||
5490 |
interpolate_pixel(tl, iax, tr, ax); |
|
5491 |
interpolate_pixel(bl, iax, br, ax); |
|
5492 |
interpolate_pixel(tl, SRC::ialpha(disty), |
|
5493 |
bl, SRC::alpha(disty)); |
|
5494 |
*b = tl; |
|
5495 |
++b; |
|
5496 |
||
5497 |
x += fdx; |
|
5498 |
y += fdy; |
|
5499 |
w += fdw; |
|
5500 |
} |
|
5501 |
if (!SRC::hasAlpha() && coverage == 255) { |
|
5502 |
qt_memconvert(dest, buffer, l); |
|
5503 |
} else if (sizeof(DST) == 3 && l >= 4 && |
|
5504 |
(quintptr(dest) & 3) == (quintptr(buffer) & 3)) |
|
5505 |
{ |
|
5506 |
blendUntransformed_dest24(dest, buffer, coverage, l); |
|
5507 |
} else if (sizeof(DST) == 2 && sizeof(SRC) == 2 && l >= 2 && |
|
5508 |
(quintptr(dest) & 3) == (quintptr(buffer) & 3)) { |
|
5509 |
blendUntransformed_dest16(dest, buffer, coverage, l); |
|
5510 |
} else { |
|
5511 |
blendUntransformed_unaligned(dest, buffer, coverage, l); |
|
5512 |
} |
|
5513 |
||
5514 |
dest += l; |
|
5515 |
length -= l; |
|
5516 |
} |
|
5517 |
++spans; |
|
5518 |
} |
|
5519 |
} |
|
5520 |
} |
|
5521 |
||
5522 |
static void blend_transformed_bilinear_rgb888(int count, const QSpan *spans, void *userData) |
|
5523 |
{ |
|
5524 |
#if defined(QT_QWS_DEPTH_24) |
|
5525 |
QSpanData *data = reinterpret_cast<QSpanData *>(userData); |
|
5526 |
||
5527 |
if (data->texture.format == QImage::Format_RGB888) |
|
5528 |
blendTransformedBilinear<qrgb888, qrgb888>(count, spans, userData); |
|
5529 |
else |
|
5530 |
#endif |
|
5531 |
blend_src_generic<RegularSpans>(count, spans, userData); |
|
5532 |
} |
|
5533 |
||
5534 |
static void blend_transformed_bilinear_argb6666(int count, const QSpan *spans, void *userData) |
|
5535 |
{ |
|
5536 |
#if defined(QT_QWS_DEPTH_18) |
|
5537 |
QSpanData *data = reinterpret_cast<QSpanData *>(userData); |
|
5538 |
||
5539 |
if (data->texture.format == QImage::Format_ARGB6666_Premultiplied) |
|
5540 |
blendTransformedBilinear<qargb6666, qargb6666>(count, spans, userData); |
|
5541 |
else if (data->texture.format == QImage::Format_RGB666) |
|
5542 |
blendTransformedBilinear<qargb6666, qrgb666>(count, spans, userData); |
|
5543 |
else |
|
5544 |
#endif |
|
5545 |
blend_src_generic<RegularSpans>(count, spans, userData); |
|
5546 |
} |
|
5547 |
||
5548 |
static void blend_transformed_bilinear_rgb666(int count, const QSpan *spans, void *userData) |
|
5549 |
{ |
|
5550 |
#if defined(QT_QWS_DEPTH_18) |
|
5551 |
QSpanData *data = reinterpret_cast<QSpanData *>(userData); |
|
5552 |
||
5553 |
if (data->texture.format == QImage::Format_ARGB6666_Premultiplied) |
|
5554 |
blendTransformedBilinear<qrgb666, qargb6666>(count, spans, userData); |
|
5555 |
else if (data->texture.format == QImage::Format_RGB666) |
|
5556 |
blendTransformedBilinear<qrgb666, qrgb666>(count, spans, userData); |
|
5557 |
else |
|
5558 |
#endif |
|
5559 |
blend_src_generic<RegularSpans>(count, spans, userData); |
|
5560 |
} |
|
5561 |
||
5562 |
static void blend_transformed_bilinear_argb8565(int count, const QSpan *spans, void *userData) |
|
5563 |
{ |
|
5564 |
#if defined(QT_QWS_DEPTH_16) |
|
5565 |
QSpanData *data = reinterpret_cast<QSpanData *>(userData); |
|
5566 |
||
5567 |
if (data->texture.format == QImage::Format_ARGB8565_Premultiplied) |
|
5568 |
blendTransformedBilinear<qargb8565, qargb8565>(count, spans, userData); |
|
5569 |
else if (data->texture.format == QImage::Format_RGB16) |
|
5570 |
blendTransformedBilinear<qargb8565, qrgb565>(count, spans, userData); |
|
5571 |
else |
|
5572 |
#endif |
|
5573 |
blend_src_generic<RegularSpans>(count, spans, userData); |
|
5574 |
} |
|
5575 |
||
5576 |
static void blend_transformed_bilinear_rgb565(int count, const QSpan *spans, |
|
5577 |
void *userData) |
|
5578 |
{ |
|
5579 |
#if defined(QT_QWS_DEPTH_16) |
|
5580 |
QSpanData *data = reinterpret_cast<QSpanData *>(userData); |
|
5581 |
||
5582 |
if (data->texture.format == QImage::Format_RGB16) |
|
5583 |
blendTransformedBilinear<qrgb565, qrgb565>(count, spans, userData); |
|
5584 |
else if (data->texture.format == QImage::Format_ARGB8565_Premultiplied) |
|
5585 |
blendTransformedBilinear<qrgb565, qargb8565>(count, spans, userData); |
|
5586 |
else |
|
5587 |
#endif |
|
5588 |
blend_src_generic<RegularSpans>(count, spans, userData); |
|
5589 |
} |
|
5590 |
||
5591 |
static void blend_transformed_bilinear_argb8555(int count, const QSpan *spans, void *userData) |
|
5592 |
{ |
|
5593 |
#if defined(QT_QWS_DEPTH_15) |
|
5594 |
QSpanData *data = reinterpret_cast<QSpanData *>(userData); |
|
5595 |
||
5596 |
if (data->texture.format == QImage::Format_ARGB8555_Premultiplied) |
|
5597 |
blendTransformedBilinear<qargb8555, qargb8555>(count, spans, userData); |
|
5598 |
else if (data->texture.format == QImage::Format_RGB555) |
|
5599 |
blendTransformedBilinear<qargb8555, qrgb555>(count, spans, userData); |
|
5600 |
else |
|
5601 |
#endif |
|
5602 |
blend_src_generic<RegularSpans>(count, spans, userData); |
|
5603 |
} |
|
5604 |
||
5605 |
static void blend_transformed_bilinear_rgb555(int count, const QSpan *spans, void *userData) |
|
5606 |
{ |
|
5607 |
#if defined(QT_QWS_DEPTH_15) |
|
5608 |
QSpanData *data = reinterpret_cast<QSpanData *>(userData); |
|
5609 |
||
5610 |
if (data->texture.format == QImage::Format_ARGB8555_Premultiplied) |
|
5611 |
blendTransformedBilinear<qrgb555, qargb8555>(count, spans, userData); |
|
5612 |
else if (data->texture.format == QImage::Format_RGB555) |
|
5613 |
blendTransformedBilinear<qrgb555, qrgb555>(count, spans, userData); |
|
5614 |
else |
|
5615 |
#endif |
|
5616 |
blend_src_generic<RegularSpans>(count, spans, userData); |
|
5617 |
} |
|
5618 |
||
5619 |
static void blend_transformed_bilinear_argb4444(int count, const QSpan *spans, void *userData) |
|
5620 |
{ |
|
5621 |
#if defined(QT_QWS_DEPTH_12) |
|
5622 |
QSpanData *data = reinterpret_cast<QSpanData *>(userData); |
|
5623 |
||
5624 |
if (data->texture.format == QImage::Format_ARGB4444_Premultiplied) |
|
5625 |
blendTransformedBilinear<qargb4444, qargb4444>(count, spans, userData); |
|
5626 |
else if (data->texture.format == QImage::Format_RGB444) |
|
5627 |
blendTransformedBilinear<qargb4444, qrgb444>(count, spans, userData); |
|
5628 |
else |
|
5629 |
#endif |
|
5630 |
blend_src_generic<RegularSpans>(count, spans, userData); |
|
5631 |
} |
|
5632 |
||
5633 |
static void blend_transformed_bilinear_rgb444(int count, const QSpan *spans, void *userData) |
|
5634 |
{ |
|
5635 |
#if defined(QT_QWS_DEPTH_12) |
|
5636 |
QSpanData *data = reinterpret_cast<QSpanData *>(userData); |
|
5637 |
||
5638 |
if (data->texture.format == QImage::Format_ARGB4444_Premultiplied) |
|
5639 |
blendTransformedBilinear<qrgb444, qargb4444>(count, spans, userData); |
|
5640 |
else if (data->texture.format == QImage::Format_RGB444) |
|
5641 |
blendTransformedBilinear<qrgb444, qrgb444>(count, spans, userData); |
|
5642 |
else |
|
5643 |
#endif |
|
5644 |
blend_src_generic<RegularSpans>(count, spans, userData); |
|
5645 |
} |
|
5646 |
||
5647 |
template <SpanMethod spanMethod> |
|
5648 |
Q_STATIC_TEMPLATE_FUNCTION void blend_transformed_bilinear_tiled_argb(int count, const QSpan *spans, void *userData) |
|
5649 |
{ |
|
5650 |
QSpanData *data = reinterpret_cast<QSpanData *>(userData); |
|
5651 |
if (data->texture.format != QImage::Format_ARGB32_Premultiplied |
|
5652 |
&& data->texture.format != QImage::Format_RGB32) { |
|
5653 |
blend_src_generic<spanMethod>(count, spans, userData); |
|
5654 |
return; |
|
5655 |
} |
|
5656 |
||
5657 |
CompositionFunction func = functionForMode[data->rasterBuffer->compositionMode]; |
|
5658 |
uint buffer[buffer_size]; |
|
5659 |
||
5660 |
int image_width = data->texture.width; |
|
5661 |
int image_height = data->texture.height; |
|
5662 |
const int scanline_offset = data->texture.bytesPerLine / 4; |
|
5663 |
||
5664 |
if (data->fast_matrix) { |
|
5665 |
// The increment pr x in the scanline |
|
5666 |
int fdx = (int)(data->m11 * fixed_scale); |
|
5667 |
int fdy = (int)(data->m12 * fixed_scale); |
|
5668 |
||
5669 |
while (count--) { |
|
5670 |
void *t = data->rasterBuffer->scanLine(spans->y); |
|
5671 |
||
5672 |
uint *target = ((uint *)t) + spans->x; |
|
5673 |
uint *image_bits = (uint *)data->texture.imageData; |
|
5674 |
||
5675 |
const qreal cx = spans->x + 0.5; |
|
5676 |
const qreal cy = spans->y + 0.5; |
|
5677 |
||
5678 |
int x = int((data->m21 * cy |
|
5679 |
+ data->m11 * cx + data->dx) * fixed_scale) - half_point; |
|
5680 |
int y = int((data->m22 * cy |
|
5681 |
+ data->m12 * cx + data->dy) * fixed_scale) - half_point; |
|
5682 |
||
5683 |
int length = spans->len; |
|
5684 |
const int coverage = (spans->coverage * data->texture.const_alpha) >> 8; |
|
5685 |
while (length) { |
|
5686 |
int l = qMin(length, buffer_size); |
|
5687 |
const uint *end = buffer + l; |
|
5688 |
uint *b = buffer; |
|
5689 |
while (b < end) { |
|
5690 |
int x1 = (x >> 16); |
|
5691 |
int x2 = (x1 + 1); |
|
5692 |
int y1 = (y >> 16); |
|
5693 |
int y2 = (y1 + 1); |
|
5694 |
||
5695 |
int distx = ((x - (x1 << 16)) >> 8); |
|
5696 |
int disty = ((y - (y1 << 16)) >> 8); |
|
5697 |
int idistx = 256 - distx; |
|
5698 |
int idisty = 256 - disty; |
|
5699 |
||
5700 |
x1 %= image_width; |
|
5701 |
x2 %= image_width; |
|
5702 |
y1 %= image_height; |
|
5703 |
y2 %= image_height; |
|
5704 |
||
5705 |
if (x1 < 0) x1 += image_width; |
|
5706 |
if (x2 < 0) x2 += image_width; |
|
5707 |
if (y1 < 0) y1 += image_height; |
|
5708 |
if (y2 < 0) y2 += image_height; |
|
5709 |
||
5710 |
Q_ASSERT(x1 >= 0 && x1 < image_width); |
|
5711 |
Q_ASSERT(x2 >= 0 && x2 < image_width); |
|
5712 |
Q_ASSERT(y1 >= 0 && y1 < image_height); |
|
5713 |
Q_ASSERT(y2 >= 0 && y2 < image_height); |
|
5714 |
||
5715 |
int y1_offset = y1 * scanline_offset; |
|
5716 |
int y2_offset = y2 * scanline_offset; |
|
5717 |
||
5718 |
#if defined(Q_IRIX_GCC3_3_WORKAROUND) |
|
5719 |
uint tl = gccBug(image_bits[y1_offset + x1]); |
|
5720 |
uint tr = gccBug(image_bits[y1_offset + x2]); |
|
5721 |
uint bl = gccBug(image_bits[y2_offset + x1]); |
|
5722 |
uint br = gccBug(image_bits[y2_offset + x2]); |
|
5723 |
#else |
|
5724 |
uint tl = image_bits[y1_offset + x1]; |
|
5725 |
uint tr = image_bits[y1_offset + x2]; |
|
5726 |
uint bl = image_bits[y2_offset + x1]; |
|
5727 |
uint br = image_bits[y2_offset + x2]; |
|
5728 |
#endif |
|
5729 |
||
5730 |
uint xtop = INTERPOLATE_PIXEL_256(tl, idistx, tr, distx); |
|
5731 |
uint xbot = INTERPOLATE_PIXEL_256(bl, idistx, br, distx); |
|
5732 |
*b = INTERPOLATE_PIXEL_256(xtop, idisty, xbot, disty); |
|
5733 |
++b; |
|
5734 |
x += fdx; |
|
5735 |
y += fdy; |
|
5736 |
} |
|
5737 |
if (spanMethod == RegularSpans) |
|
5738 |
func(target, buffer, l, coverage); |
|
5739 |
else |
|
5740 |
drawBufferSpan(data, buffer, buffer_size, |
|
5741 |
spans->x + spans->len - length, |
|
5742 |
spans->y, l, coverage); |
|
5743 |
target += l; |
|
5744 |
length -= l; |
|
5745 |
} |
|
5746 |
++spans; |
|
5747 |
} |
|
5748 |
} else { |
|
5749 |
const qreal fdx = data->m11; |
|
5750 |
const qreal fdy = data->m12; |
|
5751 |
const qreal fdw = data->m13; |
|
5752 |
while (count--) { |
|
5753 |
void *t = data->rasterBuffer->scanLine(spans->y); |
|
5754 |
||
5755 |
uint *target = ((uint *)t) + spans->x; |
|
5756 |
uint *image_bits = (uint *)data->texture.imageData; |
|
5757 |
||
5758 |
const qreal cx = spans->x + 0.5; |
|
5759 |
const qreal cy = spans->y + 0.5; |
|
5760 |
||
5761 |
qreal x = data->m21 * cy + data->m11 * cx + data->dx; |
|
5762 |
qreal y = data->m22 * cy + data->m12 * cx + data->dy; |
|
5763 |
qreal w = data->m23 * cy + data->m13 * cx + data->m33; |
|
5764 |
||
5765 |
int length = spans->len; |
|
5766 |
const int coverage = (spans->coverage * data->texture.const_alpha) >> 8; |
|
5767 |
while (length) { |
|
5768 |
int l = qMin(length, buffer_size); |
|
5769 |
const uint *end = buffer + l; |
|
5770 |
uint *b = buffer; |
|
5771 |
while (b < end) { |
|
5772 |
const qreal iw = w == 0 ? 1 : 1 / w; |
|
5773 |
const qreal px = x * iw - 0.5; |
|
5774 |
const qreal py = y * iw - 0.5; |
|
5775 |
||
5776 |
int x1 = int(px) - (px < 0); |
|
5777 |
int x2 = x1 + 1; |
|
5778 |
int y1 = int(py) - (py < 0); |
|
5779 |
int y2 = y1 + 1; |
|
5780 |
||
5781 |
int distx = int((px - x1) * 256); |
|
5782 |
int disty = int((py - y1) * 256); |
|
5783 |
int idistx = 256 - distx; |
|
5784 |
int idisty = 256 - disty; |
|
5785 |
||
5786 |
x1 %= image_width; |
|
5787 |
x2 %= image_width; |
|
5788 |
y1 %= image_height; |
|
5789 |
y2 %= image_height; |
|
5790 |
||
5791 |
if (x1 < 0) x1 += image_width; |
|
5792 |
if (x2 < 0) x2 += image_width; |
|
5793 |
if (y1 < 0) y1 += image_height; |
|
5794 |
if (y2 < 0) y2 += image_height; |
|
5795 |
||
5796 |
Q_ASSERT(x1 >= 0 && x1 < image_width); |
|
5797 |
Q_ASSERT(x2 >= 0 && x2 < image_width); |
|
5798 |
Q_ASSERT(y1 >= 0 && y1 < image_height); |
|
5799 |
Q_ASSERT(y2 >= 0 && y2 < image_height); |
|
5800 |
||
5801 |
int y1_offset = y1 * scanline_offset; |
|
5802 |
int y2_offset = y2 * scanline_offset; |
|
5803 |
||
5804 |
#if defined(Q_IRIX_GCC3_3_WORKAROUND) |
|
5805 |
uint tl = gccBug(image_bits[y1_offset + x1]); |
|
5806 |
uint tr = gccBug(image_bits[y1_offset + x2]); |
|
5807 |
uint bl = gccBug(image_bits[y2_offset + x1]); |
|
5808 |
uint br = gccBug(image_bits[y2_offset + x2]); |
|
5809 |
#else |
|
5810 |
uint tl = image_bits[y1_offset + x1]; |
|
5811 |
uint tr = image_bits[y1_offset + x2]; |
|
5812 |
uint bl = image_bits[y2_offset + x1]; |
|
5813 |
uint br = image_bits[y2_offset + x2]; |
|
5814 |
#endif |
|
5815 |
||
5816 |
uint xtop = INTERPOLATE_PIXEL_256(tl, idistx, tr, distx); |
|
5817 |
uint xbot = INTERPOLATE_PIXEL_256(bl, idistx, br, distx); |
|
5818 |
*b = INTERPOLATE_PIXEL_256(xtop, idisty, xbot, disty); |
|
5819 |
++b; |
|
5820 |
x += fdx; |
|
5821 |
y += fdy; |
|
5822 |
w += fdw; |
|
5823 |
} |
|
5824 |
if (spanMethod == RegularSpans) |
|
5825 |
func(target, buffer, l, coverage); |
|
5826 |
else |
|
5827 |
drawBufferSpan(data, buffer, buffer_size, |
|
5828 |
spans->x + spans->len - length, |
|
5829 |
spans->y, l, coverage); |
|
5830 |
target += l; |
|
5831 |
length -= l; |
|
5832 |
} |
|
5833 |
++spans; |
|
5834 |
} |
|
5835 |
} |
|
5836 |
} |
|
5837 |
||
5838 |
template <SpanMethod spanMethod> |
|
5839 |
Q_STATIC_TEMPLATE_FUNCTION void blend_transformed_argb(int count, const QSpan *spans, void *userData) |
|
5840 |
{ |
|
5841 |
QSpanData *data = reinterpret_cast<QSpanData *>(userData); |
|
5842 |
if (data->texture.format != QImage::Format_ARGB32_Premultiplied |
|
5843 |
&& data->texture.format != QImage::Format_RGB32) { |
|
5844 |
blend_src_generic<spanMethod>(count, spans, userData); |
|
5845 |
return; |
|
5846 |
} |
|
5847 |
||
5848 |
CompositionFunction func = functionForMode[data->rasterBuffer->compositionMode]; |
|
5849 |
uint buffer[buffer_size]; |
|
5850 |
||
5851 |
int image_width = data->texture.width; |
|
5852 |
int image_height = data->texture.height; |
|
5853 |
const int scanline_offset = data->texture.bytesPerLine / 4; |
|
5854 |
||
5855 |
if (data->fast_matrix) { |
|
5856 |
// The increment pr x in the scanline |
|
5857 |
int fdx = (int)(data->m11 * fixed_scale); |
|
5858 |
int fdy = (int)(data->m12 * fixed_scale); |
|
5859 |
||
5860 |
while (count--) { |
|
5861 |
void *t = data->rasterBuffer->scanLine(spans->y); |
|
5862 |
||
5863 |
uint *target = ((uint *)t) + spans->x; |
|
5864 |
uint *image_bits = (uint *)data->texture.imageData; |
|
5865 |
||
5866 |
const qreal cx = spans->x + 0.5; |
|
5867 |
const qreal cy = spans->y + 0.5; |
|
5868 |
||
5869 |
int x = int((data->m21 * cy |
|
5870 |
+ data->m11 * cx + data->dx) * fixed_scale); |
|
5871 |
int y = int((data->m22 * cy |
|
5872 |
+ data->m12 * cx + data->dy) * fixed_scale); |
|
5873 |
||
5874 |
int length = spans->len; |
|
5875 |
const int coverage = (spans->coverage * data->texture.const_alpha) >> 8; |
|
5876 |
while (length) { |
|
5877 |
int l = qMin(length, buffer_size); |
|
5878 |
const uint *end = buffer + l; |
|
5879 |
uint *b = buffer; |
|
5880 |
while (b < end) { |
|
5881 |
int px = x >> 16; |
|
5882 |
int py = y >> 16; |
|
5883 |
||
5884 |
bool out = (px < 0) || (px >= image_width) |
|
5885 |
|| (py < 0) || (py >= image_height); |
|
5886 |
||
5887 |
int y_offset = py * scanline_offset; |
|
5888 |
*b = out ? uint(0) : image_bits[y_offset + px]; |
|
5889 |
x += fdx; |
|
5890 |
y += fdy; |
|
5891 |
++b; |
|
5892 |
} |
|
5893 |
if (spanMethod == RegularSpans) |
|
5894 |
func(target, buffer, l, coverage); |
|
5895 |
else |
|
5896 |
drawBufferSpan(data, buffer, buffer_size, |
|
5897 |
spans->x + spans->len - length, |
|
5898 |
spans->y, l, coverage); |
|
5899 |
target += l; |
|
5900 |
length -= l; |
|
5901 |
} |
|
5902 |
++spans; |
|
5903 |
} |
|
5904 |
} else { |
|
5905 |
const qreal fdx = data->m11; |
|
5906 |
const qreal fdy = data->m12; |
|
5907 |
const qreal fdw = data->m13; |
|
5908 |
while (count--) { |
|
5909 |
void *t = data->rasterBuffer->scanLine(spans->y); |
|
5910 |
||
5911 |
uint *target = ((uint *)t) + spans->x; |
|
5912 |
uint *image_bits = (uint *)data->texture.imageData; |
|
5913 |
||
5914 |
const qreal cx = spans->x + 0.5; |
|
5915 |
const qreal cy = spans->y + 0.5; |
|
5916 |
||
5917 |
qreal x = data->m21 * cy + data->m11 * cx + data->dx; |
|
5918 |
qreal y = data->m22 * cy + data->m12 * cx + data->dy; |
|
5919 |
qreal w = data->m23 * cy + data->m13 * cx + data->m33; |
|
5920 |
||
5921 |
int length = spans->len; |
|
5922 |
const int coverage = (spans->coverage * data->texture.const_alpha) >> 8; |
|
5923 |
while (length) { |
|
5924 |
int l = qMin(length, buffer_size); |
|
5925 |
const uint *end = buffer + l; |
|
5926 |
uint *b = buffer; |
|
5927 |
while (b < end) { |
|
5928 |
const qreal iw = w == 0 ? 1 : 1 / w; |
|
5929 |
const qreal tx = x * iw; |
|
5930 |
const qreal ty = y * iw; |
|
5931 |
const int px = int(tx) - (tx < 0); |
|
5932 |
const int py = int(ty) - (ty < 0); |
|
5933 |
||
5934 |
bool out = (px < 0) || (px >= image_width) |
|
5935 |
|| (py < 0) || (py >= image_height); |
|
5936 |
||
5937 |
int y_offset = py * scanline_offset; |
|
5938 |
*b = out ? uint(0) : image_bits[y_offset + px]; |
|
5939 |
x += fdx; |
|
5940 |
y += fdy; |
|
5941 |
w += fdw; |
|
5942 |
||
5943 |
++b; |
|
5944 |
} |
|
5945 |
if (spanMethod == RegularSpans) |
|
5946 |
func(target, buffer, l, coverage); |
|
5947 |
else |
|
5948 |
drawBufferSpan(data, buffer, buffer_size, |
|
5949 |
spans->x + spans->len - length, |
|
5950 |
spans->y, l, coverage); |
|
5951 |
target += l; |
|
5952 |
length -= l; |
|
5953 |
} |
|
5954 |
++spans; |
|
5955 |
} |
|
5956 |
} |
|
5957 |
} |
|
5958 |
||
5959 |
template <class DST, class SRC> |
|
5960 |
Q_STATIC_TEMPLATE_FUNCTION void blendTransformed(int count, const QSpan *spans, void *userData) |
|
5961 |
{ |
|
5962 |
QSpanData *data = reinterpret_cast<QSpanData*>(userData); |
|
5963 |
QPainter::CompositionMode mode = data->rasterBuffer->compositionMode; |
|
5964 |
||
5965 |
if (mode != QPainter::CompositionMode_SourceOver) { |
|
5966 |
blend_src_generic<RegularSpans>(count, spans, userData); |
|
5967 |
return; |
|
5968 |
} |
|
5969 |
||
5970 |
SRC buffer[buffer_size]; |
|
5971 |
const int image_width = data->texture.width; |
|
5972 |
const int image_height = data->texture.height; |
|
5973 |
||
5974 |
if (data->fast_matrix) { |
|
5975 |
// The increment pr x in the scanline |
|
5976 |
const int fdx = (int)(data->m11 * fixed_scale); |
|
5977 |
const int fdy = (int)(data->m12 * fixed_scale); |
|
5978 |
||
5979 |
while (count--) { |
|
5980 |
const quint8 coverage = (data->texture.const_alpha * spans->coverage) >> 8; |
|
5981 |
if (coverage == 0) { |
|
5982 |
++spans; |
|
5983 |
continue; |
|
5984 |
} |
|
5985 |
||
5986 |
DST *dest = (DST*)data->rasterBuffer->scanLine(spans->y) |
|
5987 |
+ spans->x; |
|
5988 |
const qreal cx = spans->x + qreal(0.5); |
|
5989 |
const qreal cy = spans->y + qreal(0.5); |
|
5990 |
int x = int((data->m21 * cy |
|
5991 |
+ data->m11 * cx + data->dx) * fixed_scale); |
|
5992 |
int y = int((data->m22 * cy |
|
5993 |
+ data->m12 * cx + data->dy) * fixed_scale); |
|
5994 |
int length = spans->len; |
|
5995 |
||
5996 |
while (length) { |
|
5997 |
const int l = qMin(length, buffer_size); |
|
5998 |
||
5999 |
const SRC *end = buffer + l; |
|
6000 |
SRC *b = buffer; |
|
6001 |
while (b < end) { |
|
6002 |
const int px = (x >> 16); |
|
6003 |
const int py = (y >> 16); |
|
6004 |
||
6005 |
if ((px < 0) || (px >= image_width) || |
|
6006 |
(py < 0) || (py >= image_height)) |
|
6007 |
{ |
|
6008 |
*b = 0; |
|
6009 |
} else { |
|
6010 |
*b = ((SRC*)data->texture.scanLine(py))[px]; |
|
6011 |
} |
|
6012 |
++b; |
|
6013 |
||
6014 |
x += fdx; |
|
6015 |
y += fdy; |
|
6016 |
} |
|
6017 |
||
6018 |
if (!SRC::hasAlpha() && coverage == 255) { |
|
6019 |
qt_memconvert(dest, buffer, l); |
|
6020 |
} else if (sizeof(DST) == 3 && sizeof(SRC) == 3 && l >= 4 && |
|
6021 |
(quintptr(dest) & 3) == (quintptr(buffer) & 3)) |
|
6022 |
{ |
|
6023 |
blendUntransformed_dest24(dest, buffer, coverage, l); |
|
6024 |
} else if (sizeof(DST) == 2 && sizeof(SRC) == 2 && l >= 2 && |
|
6025 |
(quintptr(dest) & 3) == (quintptr(buffer) & 3)) { |
|
6026 |
blendUntransformed_dest16(dest, buffer, coverage, l); |
|
6027 |
} else { |
|
6028 |
blendUntransformed_unaligned(dest, buffer, coverage, l); |
|
6029 |
} |
|
6030 |
||
6031 |
dest += l; |
|
6032 |
length -= l; |
|
6033 |
} |
|
6034 |
++spans; |
|
6035 |
} |
|
6036 |
} else { |
|
6037 |
const qreal fdx = data->m11; |
|
6038 |
const qreal fdy = data->m12; |
|
6039 |
const qreal fdw = data->m13; |
|
6040 |
||
6041 |
while (count--) { |
|
6042 |
const quint8 coverage = (data->texture.const_alpha * spans->coverage) >> 8; |
|
6043 |
if (coverage == 0) { |
|
6044 |
++spans; |
|
6045 |
continue; |
|
6046 |
} |
|
6047 |
||
6048 |
DST *dest = (DST*)data->rasterBuffer->scanLine(spans->y) |
|
6049 |
+ spans->x; |
|
6050 |
||
6051 |
const qreal cx = spans->x + qreal(0.5); |
|
6052 |
const qreal cy = spans->y + qreal(0.5); |
|
6053 |
||
6054 |
qreal x = data->m21 * cy + data->m11 * cx + data->dx; |
|
6055 |
qreal y = data->m22 * cy + data->m12 * cx + data->dy; |
|
6056 |
qreal w = data->m23 * cy + data->m13 * cx + data->m33; |
|
6057 |
||
6058 |
int length = spans->len; |
|
6059 |
while (length) { |
|
6060 |
const int l = qMin(length, buffer_size); |
|
6061 |
const SRC *end = buffer + l; |
|
6062 |
SRC *b = buffer; |
|
6063 |
while (b < end) { |
|
6064 |
const qreal iw = w == 0 ? 1 : 1 / w; |
|
6065 |
const qreal tx = x * iw; |
|
6066 |
const qreal ty = y * iw; |
|
6067 |
||
6068 |
const int px = int(tx) - (tx < 0); |
|
6069 |
const int py = int(ty) - (ty < 0); |
|
6070 |
||
6071 |
if ((px < 0) || (px >= image_width) || |
|
6072 |
(py < 0) || (py >= image_height)) |
|
6073 |
{ |
|
6074 |
*b = 0; |
|
6075 |
} else { |
|
6076 |
*b = ((SRC*)data->texture.scanLine(py))[px]; |
|
6077 |
} |
|
6078 |
++b; |
|
6079 |
||
6080 |
x += fdx; |
|
6081 |
y += fdy; |
|
6082 |
w += fdw; |
|
6083 |
} |
|
6084 |
if (!SRC::hasAlpha() && coverage == 255) { |
|
6085 |
qt_memconvert(dest, buffer, l); |
|
6086 |
} else if (sizeof(DST) == 3 && sizeof(SRC) == 3 && l >= 4 && |
|
6087 |
(quintptr(dest) & 3) == (quintptr(buffer) & 3)) |
|
6088 |
{ |
|
6089 |
blendUntransformed_dest24(dest, buffer, coverage, l); |
|
6090 |
} else if (sizeof(DST) == 2 && sizeof(SRC) == 2 && l >= 2 && |
|
6091 |
(quintptr(dest) & 3) == (quintptr(buffer) & 3)) { |
|
6092 |
blendUntransformed_dest16(dest, buffer, coverage, l); |
|
6093 |
} else { |
|
6094 |
blendUntransformed_unaligned(dest, buffer, coverage, l); |
|
6095 |
} |
|
6096 |
||
6097 |
dest += l; |
|
6098 |
length -= l; |
|
6099 |
} |
|
6100 |
++spans; |
|
6101 |
} |
|
6102 |
} |
|
6103 |
} |
|
6104 |
||
6105 |
static void blend_transformed_rgb888(int count, const QSpan *spans, |
|
6106 |
void *userData) |
|
6107 |
{ |
|
6108 |
#if defined(QT_QWS_DEPTH_24) |
|
6109 |
QSpanData *data = reinterpret_cast<QSpanData *>(userData); |
|
6110 |
||
6111 |
if (data->texture.format == QImage::Format_RGB888) |
|
6112 |
blendTransformed<qrgb888, qrgb888>(count, spans, userData); |
|
6113 |
else |
|
6114 |
#endif |
|
6115 |
blend_src_generic<RegularSpans>(count, spans, userData); |
|
6116 |
} |
|
6117 |
||
6118 |
static void blend_transformed_argb6666(int count, const QSpan *spans, |
|
6119 |
void *userData) |
|
6120 |
{ |
|
6121 |
#if defined(QT_QWS_DEPTH_18) |
|
6122 |
QSpanData *data = reinterpret_cast<QSpanData *>(userData); |
|
6123 |
||
6124 |
if (data->texture.format == QImage::Format_ARGB6666_Premultiplied) |
|
6125 |
blendTransformed<qargb6666, qargb6666>(count, spans, userData); |
|
6126 |
else if (data->texture.format == QImage::Format_RGB666) |
|
6127 |
blendTransformed<qargb6666, qrgb666>(count, spans, userData); |
|
6128 |
else |
|
6129 |
#endif |
|
6130 |
blend_src_generic<RegularSpans>(count, spans, userData); |
|
6131 |
} |
|
6132 |
||
6133 |
static void blend_transformed_rgb666(int count, const QSpan *spans, |
|
6134 |
void *userData) |
|
6135 |
{ |
|
6136 |
#if defined(QT_QWS_DEPTH_18) |
|
6137 |
QSpanData *data = reinterpret_cast<QSpanData *>(userData); |
|
6138 |
||
6139 |
if (data->texture.format == QImage::Format_ARGB6666_Premultiplied) |
|
6140 |
blendTransformed<qrgb666, qargb6666>(count, spans, userData); |
|
6141 |
else if (data->texture.format == QImage::Format_RGB666) |
|
6142 |
blendTransformed<qrgb666, qrgb666>(count, spans, userData); |
|
6143 |
else |
|
6144 |
#endif |
|
6145 |
blend_src_generic<RegularSpans>(count, spans, userData); |
|
6146 |
} |
|
6147 |
||
6148 |
static void blend_transformed_argb8565(int count, const QSpan *spans, |
|
6149 |
void *userData) |
|
6150 |
{ |
|
6151 |
#if defined(QT_QWS_DEPTH_16) |
|
6152 |
QSpanData *data = reinterpret_cast<QSpanData *>(userData); |
|
6153 |
||
6154 |
if (data->texture.format == QImage::Format_ARGB8565_Premultiplied) |
|
6155 |
blendTransformed<qargb8565, qargb8565>(count, spans, userData); |
|
6156 |
else if (data->texture.format == QImage::Format_RGB16) |
|
6157 |
blendTransformed<qargb8565, qrgb565>(count, spans, userData); |
|
6158 |
else |
|
6159 |
#endif |
|
6160 |
blend_src_generic<RegularSpans>(count, spans, userData); |
|
6161 |
} |
|
6162 |
||
6163 |
static void blend_transformed_rgb565(int count, const QSpan *spans, |
|
6164 |
void *userData) |
|
6165 |
{ |
|
6166 |
#if defined(QT_QWS_DEPTH_16) |
|
6167 |
QSpanData *data = reinterpret_cast<QSpanData *>(userData); |
|
6168 |
||
6169 |
if (data->texture.format == QImage::Format_ARGB8565_Premultiplied) |
|
6170 |
blendTransformed<qrgb565, qargb8565>(count, spans, userData); |
|
6171 |
else if (data->texture.format == QImage::Format_RGB16) |
|
6172 |
blendTransformed<qrgb565, qrgb565>(count, spans, userData); |
|
6173 |
else |
|
6174 |
#endif |
|
6175 |
blend_src_generic<RegularSpans>(count, spans, userData); |
|
6176 |
} |
|
6177 |
||
6178 |
static void blend_transformed_argb8555(int count, const QSpan *spans, |
|
6179 |
void *userData) |
|
6180 |
{ |
|
6181 |
#if defined(QT_QWS_DEPTH_15) |
|
6182 |
QSpanData *data = reinterpret_cast<QSpanData *>(userData); |
|
6183 |
||
6184 |
if (data->texture.format == QImage::Format_ARGB8555_Premultiplied) |
|
6185 |
blendTransformed<qargb8555, qargb8555>(count, spans, userData); |
|
6186 |
else if (data->texture.format == QImage::Format_RGB555) |
|
6187 |
blendTransformed<qargb8555, qrgb555>(count, spans, userData); |
|
6188 |
else |
|
6189 |
#endif |
|
6190 |
blend_src_generic<RegularSpans>(count, spans, userData); |
|
6191 |
} |
|
6192 |
||
6193 |
static void blend_transformed_rgb555(int count, const QSpan *spans, |
|
6194 |
void *userData) |
|
6195 |
{ |
|
6196 |
#if defined(QT_QWS_DEPTH_15) |
|
6197 |
QSpanData *data = reinterpret_cast<QSpanData *>(userData); |
|
6198 |
||
6199 |
if (data->texture.format == QImage::Format_ARGB8555_Premultiplied) |
|
6200 |
blendTransformed<qrgb555, qargb8555>(count, spans, userData); |
|
6201 |
else if (data->texture.format == QImage::Format_RGB555) |
|
6202 |
blendTransformed<qrgb555, qrgb555>(count, spans, userData); |
|
6203 |
else |
|
6204 |
#endif |
|
6205 |
blend_src_generic<RegularSpans>(count, spans, userData); |
|
6206 |
} |
|
6207 |
||
6208 |
static void blend_transformed_argb4444(int count, const QSpan *spans, |
|
6209 |
void *userData) |
|
6210 |
{ |
|
6211 |
#if defined(QT_QWS_DEPTH_12) |
|
6212 |
QSpanData *data = reinterpret_cast<QSpanData *>(userData); |
|
6213 |
||
6214 |
if (data->texture.format == QImage::Format_ARGB4444_Premultiplied) |
|
6215 |
blendTransformed<qargb4444, qargb4444>(count, spans, userData); |
|
6216 |
else if (data->texture.format == QImage::Format_RGB444) |
|
6217 |
blendTransformed<qargb4444, qrgb444>(count, spans, userData); |
|
6218 |
else |
|
6219 |
#endif |
|
6220 |
blend_src_generic<RegularSpans>(count, spans, userData); |
|
6221 |
} |
|
6222 |
||
6223 |
static void blend_transformed_rgb444(int count, const QSpan *spans, |
|
6224 |
void *userData) |
|
6225 |
{ |
|
6226 |
#if defined(QT_QWS_DEPTH_12) |
|
6227 |
QSpanData *data = reinterpret_cast<QSpanData *>(userData); |
|
6228 |
||
6229 |
if (data->texture.format == QImage::Format_ARGB4444_Premultiplied) |
|
6230 |
blendTransformed<qrgb444, qargb4444>(count, spans, userData); |
|
6231 |
else if (data->texture.format == QImage::Format_RGB444) |
|
6232 |
blendTransformed<qrgb444, qrgb444>(count, spans, userData); |
|
6233 |
else |
|
6234 |
#endif |
|
6235 |
blend_src_generic<RegularSpans>(count, spans, userData); |
|
6236 |
} |
|
6237 |
||
6238 |
template <SpanMethod spanMethod> |
|
6239 |
Q_STATIC_TEMPLATE_FUNCTION void blend_transformed_tiled_argb(int count, const QSpan *spans, void *userData) |
|
6240 |
{ |
|
6241 |
QSpanData *data = reinterpret_cast<QSpanData *>(userData); |
|
6242 |
if (data->texture.format != QImage::Format_ARGB32_Premultiplied |
|
6243 |
&& data->texture.format != QImage::Format_RGB32) { |
|
6244 |
blend_src_generic<spanMethod>(count, spans, userData); |
|
6245 |
return; |
|
6246 |
} |
|
6247 |
||
6248 |
CompositionFunction func = functionForMode[data->rasterBuffer->compositionMode]; |
|
6249 |
uint buffer[buffer_size]; |
|
6250 |
||
6251 |
int image_width = data->texture.width; |
|
6252 |
int image_height = data->texture.height; |
|
6253 |
const int scanline_offset = data->texture.bytesPerLine / 4; |
|
6254 |
||
6255 |
if (data->fast_matrix) { |
|
6256 |
// The increment pr x in the scanline |
|
6257 |
int fdx = (int)(data->m11 * fixed_scale); |
|
6258 |
int fdy = (int)(data->m12 * fixed_scale); |
|
6259 |
||
6260 |
while (count--) { |
|
6261 |
void *t = data->rasterBuffer->scanLine(spans->y); |
|
6262 |
||
6263 |
uint *target = ((uint *)t) + spans->x; |
|
6264 |
uint *image_bits = (uint *)data->texture.imageData; |
|
6265 |
||
6266 |
const qreal cx = spans->x + 0.5; |
|
6267 |
const qreal cy = spans->y + 0.5; |
|
6268 |
||
6269 |
int x = int((data->m21 * cy |
|
6270 |
+ data->m11 * cx + data->dx) * fixed_scale); |
|
6271 |
int y = int((data->m22 * cy |
|
6272 |
+ data->m12 * cx + data->dy) * fixed_scale); |
|
6273 |
||
6274 |
const int coverage = (spans->coverage * data->texture.const_alpha) >> 8; |
|
6275 |
int length = spans->len; |
|
6276 |
while (length) { |
|
6277 |
int l = qMin(length, buffer_size); |
|
6278 |
const uint *end = buffer + l; |
|
6279 |
uint *b = buffer; |
|
6280 |
while (b < end) { |
|
6281 |
int px = x >> 16; |
|
6282 |
int py = y >> 16; |
|
6283 |
px %= image_width; |
|
6284 |
py %= image_height; |
|
6285 |
if (px < 0) px += image_width; |
|
6286 |
if (py < 0) py += image_height; |
|
6287 |
int y_offset = py * scanline_offset; |
|
6288 |
||
6289 |
Q_ASSERT(px >= 0 && px < image_width); |
|
6290 |
Q_ASSERT(py >= 0 && py < image_height); |
|
6291 |
||
6292 |
*b = image_bits[y_offset + px]; |
|
6293 |
x += fdx; |
|
6294 |
y += fdy; |
|
6295 |
++b; |
|
6296 |
} |
|
6297 |
if (spanMethod == RegularSpans) |
|
6298 |
func(target, buffer, l, coverage); |
|
6299 |
else |
|
6300 |
drawBufferSpan(data, buffer, buffer_size, |
|
6301 |
spans->x + spans->len - length, |
|
6302 |
spans->y, l, coverage); |
|
6303 |
target += l; |
|
6304 |
length -= l; |
|
6305 |
} |
|
6306 |
++spans; |
|
6307 |
} |
|
6308 |
} else { |
|
6309 |
const qreal fdx = data->m11; |
|
6310 |
const qreal fdy = data->m12; |
|
6311 |
const qreal fdw = data->m13; |
|
6312 |
while (count--) { |
|
6313 |
void *t = data->rasterBuffer->scanLine(spans->y); |
|
6314 |
||
6315 |
uint *target = ((uint *)t) + spans->x; |
|
6316 |
uint *image_bits = (uint *)data->texture.imageData; |
|
6317 |
||
6318 |
const qreal cx = spans->x + 0.5; |
|
6319 |
const qreal cy = spans->y + 0.5; |
|
6320 |
||
6321 |
qreal x = data->m21 * cy + data->m11 * cx + data->dx; |
|
6322 |
qreal y = data->m22 * cy + data->m12 * cx + data->dy; |
|
6323 |
qreal w = data->m23 * cy + data->m13 * cx + data->m33; |
|
6324 |
||
6325 |
const int coverage = (spans->coverage * data->texture.const_alpha) >> 8; |
|
6326 |
int length = spans->len; |
|
6327 |
while (length) { |
|
6328 |
int l = qMin(length, buffer_size); |
|
6329 |
const uint *end = buffer + l; |
|
6330 |
uint *b = buffer; |
|
6331 |
while (b < end) { |
|
6332 |
const qreal iw = w == 0 ? 1 : 1 / w; |
|
6333 |
const qreal tx = x * iw; |
|
6334 |
const qreal ty = y * iw; |
|
6335 |
int px = int(tx) - (tx < 0); |
|
6336 |
int py = int(ty) - (ty < 0); |
|
6337 |
||
6338 |
px %= image_width; |
|
6339 |
py %= image_height; |
|
6340 |
if (px < 0) px += image_width; |
|
6341 |
if (py < 0) py += image_height; |
|
6342 |
int y_offset = py * scanline_offset; |
|
6343 |
||
6344 |
Q_ASSERT(px >= 0 && px < image_width); |
|
6345 |
Q_ASSERT(py >= 0 && py < image_height); |
|
6346 |
||
6347 |
*b = image_bits[y_offset + px]; |
|
6348 |
x += fdx; |
|
6349 |
y += fdy; |
|
6350 |
w += fdw; |
|
6351 |
//force increment to avoid /0 |
|
6352 |
if (!w) { |
|
6353 |
w += fdw; |
|
6354 |
} |
|
6355 |
++b; |
|
6356 |
} |
|
6357 |
if (spanMethod == RegularSpans) |
|
6358 |
func(target, buffer, l, coverage); |
|
6359 |
else |
|
6360 |
drawBufferSpan(data, buffer, buffer_size, |
|
6361 |
spans->x + spans->len - length, |
|
6362 |
spans->y, l, coverage); |
|
6363 |
target += l; |
|
6364 |
length -= l; |
|
6365 |
} |
|
6366 |
++spans; |
|
6367 |
} |
|
6368 |
} |
|
6369 |
} |
|
6370 |
||
6371 |
template <class DST, class SRC> |
|
6372 |
Q_STATIC_TEMPLATE_FUNCTION void blendTransformedTiled(int count, const QSpan *spans, void *userData) |
|
6373 |
{ |
|
6374 |
QSpanData *data = reinterpret_cast<QSpanData*>(userData); |
|
6375 |
QPainter::CompositionMode mode = data->rasterBuffer->compositionMode; |
|
6376 |
||
6377 |
if (mode != QPainter::CompositionMode_SourceOver) { |
|
6378 |
blend_src_generic<RegularSpans>(count, spans, userData); |
|
6379 |
return; |
|
6380 |
} |
|
6381 |
||
6382 |
SRC buffer[buffer_size]; |
|
6383 |
const int image_width = data->texture.width; |
|
6384 |
const int image_height = data->texture.height; |
|
6385 |
||
6386 |
if (data->fast_matrix) { |
|
6387 |
// The increment pr x in the scanline |
|
6388 |
const int fdx = (int)(data->m11 * fixed_scale); |
|
6389 |
const int fdy = (int)(data->m12 * fixed_scale); |
|
6390 |
||
6391 |
while (count--) { |
|
6392 |
const quint8 coverage = (data->texture.const_alpha * spans->coverage) >> 8; |
|
6393 |
if (coverage == 0) { |
|
6394 |
++spans; |
|
6395 |
continue; |
|
6396 |
} |
|
6397 |
||
6398 |
DST *dest = (DST*)data->rasterBuffer->scanLine(spans->y) |
|
6399 |
+ spans->x; |
|
6400 |
const qreal cx = spans->x + qreal(0.5); |
|
6401 |
const qreal cy = spans->y + qreal(0.5); |
|
6402 |
int x = int((data->m21 * cy |
|
6403 |
+ data->m11 * cx + data->dx) * fixed_scale); |
|
6404 |
int y = int((data->m22 * cy |
|
6405 |
+ data->m12 * cx + data->dy) * fixed_scale); |
|
6406 |
int length = spans->len; |
|
6407 |
||
6408 |
while (length) { |
|
6409 |
const int l = qMin(length, buffer_size); |
|
6410 |
||
6411 |
const SRC *end = buffer + l; |
|
6412 |
SRC *b = buffer; |
|
6413 |
while (b < end) { |
|
6414 |
int px = (x >> 16) % image_width; |
|
6415 |
int py = (y >> 16) % image_height; |
|
6416 |
||
6417 |
if (px < 0) |
|
6418 |
px += image_width; |
|
6419 |
if (py < 0) |
|
6420 |
py += image_height; |
|
6421 |
||
6422 |
*b = ((SRC*)data->texture.scanLine(py))[px]; |
|
6423 |
++b; |
|
6424 |
||
6425 |
x += fdx; |
|
6426 |
y += fdy; |
|
6427 |
} |
|
6428 |
||
6429 |
if (!SRC::hasAlpha() && coverage == 255) { |
|
6430 |
qt_memconvert(dest, buffer, l); |
|
6431 |
} else if (sizeof(DST) == 3 && sizeof(SRC) == 3 && l >= 4 && |
|
6432 |
(quintptr(dest) & 3) == (quintptr(buffer) & 3)) |
|
6433 |
{ |
|
6434 |
blendUntransformed_dest24(dest, buffer, coverage, l); |
|
6435 |
} else if (sizeof(DST) == 2 && sizeof(SRC) == 2 && l >= 2 && |
|
6436 |
(quintptr(dest) & 3) == (quintptr(buffer) & 3)) { |
|
6437 |
blendUntransformed_dest16(dest, buffer, coverage, l); |
|
6438 |
} else { |
|
6439 |
blendUntransformed_unaligned(dest, buffer, coverage, l); |
|
6440 |
} |
|
6441 |
||
6442 |
dest += l; |
|
6443 |
length -= l; |
|
6444 |
} |
|
6445 |
++spans; |
|
6446 |
} |
|
6447 |
} else { |
|
6448 |
const qreal fdx = data->m11; |
|
6449 |
const qreal fdy = data->m12; |
|
6450 |
const qreal fdw = data->m13; |
|
6451 |
||
6452 |
while (count--) { |
|
6453 |
const quint8 coverage = (data->texture.const_alpha * spans->coverage) >> 8; |
|
6454 |
if (coverage == 0) { |
|
6455 |
++spans; |
|
6456 |
continue; |
|
6457 |
} |
|
6458 |
||
6459 |
DST *dest = (DST*)data->rasterBuffer->scanLine(spans->y) |
|
6460 |
+ spans->x; |
|
6461 |
||
6462 |
const qreal cx = spans->x + qreal(0.5); |
|
6463 |
const qreal cy = spans->y + qreal(0.5); |
|
6464 |
||
6465 |
qreal x = data->m21 * cy + data->m11 * cx + data->dx; |
|
6466 |
qreal y = data->m22 * cy + data->m12 * cx + data->dy; |
|
6467 |
qreal w = data->m23 * cy + data->m13 * cx + data->m33; |
|
6468 |
||
6469 |
int length = spans->len; |
|
6470 |
while (length) { |
|
6471 |
const int l = qMin(length, buffer_size); |
|
6472 |
const SRC *end = buffer + l; |
|
6473 |
SRC *b = buffer; |
|
6474 |
while (b < end) { |
|
6475 |
const qreal iw = w == 0 ? 1 : 1 / w; |
|
6476 |
const qreal tx = x * iw; |
|
6477 |
const qreal ty = y * iw; |
|
6478 |
||
6479 |
int px = int(tx) - (tx < 0); |
|
6480 |
int py = int(ty) - (ty < 0); |
|
6481 |
||
6482 |
if (px < 0) |
|
6483 |
px += image_width; |
|
6484 |
if (py < 0) |
|
6485 |
py += image_height; |
|
6486 |
||
6487 |
*b = ((SRC*)data->texture.scanLine(py))[px]; |
|
6488 |
++b; |
|
6489 |
||
6490 |
x += fdx; |
|
6491 |
y += fdy; |
|
6492 |
w += fdw; |
|
6493 |
// force increment to avoid /0 |
|
6494 |
if (!w) |
|
6495 |
w += fdw; |
|
6496 |
} |
|
6497 |
if (!SRC::hasAlpha() && coverage == 255) { |
|
6498 |
qt_memconvert(dest, buffer, l); |
|
6499 |
} else if (sizeof(DST) == 3 && sizeof(SRC) == 3 && l >= 4 && |
|
6500 |
(quintptr(dest) & 3) == (quintptr(buffer) & 3)) |
|
6501 |
{ |
|
6502 |
blendUntransformed_dest24(dest, buffer, coverage, l); |
|
6503 |
} else if (sizeof(DST) == 2 && sizeof(SRC) == 2 && l >= 2 && |
|
6504 |
(quintptr(dest) & 3) == (quintptr(buffer) & 3)) { |
|
6505 |
blendUntransformed_dest16(dest, buffer, coverage, l); |
|
6506 |
} else { |
|
6507 |
blendUntransformed_unaligned(dest, buffer, coverage, l); |
|
6508 |
} |
|
6509 |
||
6510 |
dest += l; |
|
6511 |
length -= l; |
|
6512 |
} |
|
6513 |
++spans; |
|
6514 |
} |
|
6515 |
} |
|
6516 |
} |
|
6517 |
||
6518 |
static void blend_transformed_tiled_rgb888(int count, const QSpan *spans, |
|
6519 |
void *userData) |
|
6520 |
{ |
|
6521 |
#if defined(QT_QWS_DEPTH_24) |
|
6522 |
QSpanData *data = reinterpret_cast<QSpanData *>(userData); |
|
6523 |
||
6524 |
if (data->texture.format == QImage::Format_RGB888) |
|
6525 |
blendTransformedTiled<qrgb888, qrgb888>(count, spans, userData); |
|
6526 |
else |
|
6527 |
#endif |
|
6528 |
blend_src_generic<RegularSpans>(count, spans, userData); |
|
6529 |
} |
|
6530 |
||
6531 |
static void blend_transformed_tiled_argb6666(int count, const QSpan *spans, |
|
6532 |
void *userData) |
|
6533 |
{ |
|
6534 |
#if defined(QT_QWS_DEPTH_18) |
|
6535 |
QSpanData *data = reinterpret_cast<QSpanData *>(userData); |
|
6536 |
||
6537 |
if (data->texture.format == QImage::Format_ARGB6666_Premultiplied) |
|
6538 |
blendTransformedTiled<qargb6666, qargb6666>(count, spans, userData); |
|
6539 |
else if (data->texture.format == QImage::Format_RGB666) |
|
6540 |
blendTransformedTiled<qargb6666, qrgb666>(count, spans, userData); |
|
6541 |
else |
|
6542 |
#endif |
|
6543 |
blend_src_generic<RegularSpans>(count, spans, userData); |
|
6544 |
} |
|
6545 |
||
6546 |
static void blend_transformed_tiled_rgb666(int count, const QSpan *spans, |
|
6547 |
void *userData) |
|
6548 |
{ |
|
6549 |
#if defined(QT_QWS_DEPTH_18) |
|
6550 |
QSpanData *data = reinterpret_cast<QSpanData *>(userData); |
|
6551 |
||
6552 |
if (data->texture.format == QImage::Format_ARGB6666_Premultiplied) |
|
6553 |
blendTransformedTiled<qrgb666, qargb6666>(count, spans, userData); |
|
6554 |
else if (data->texture.format == QImage::Format_RGB666) |
|
6555 |
blendTransformedTiled<qrgb666, qrgb666>(count, spans, userData); |
|
6556 |
else |
|
6557 |
#endif |
|
6558 |
blend_src_generic<RegularSpans>(count, spans, userData); |
|
6559 |
} |
|
6560 |
||
6561 |
static void blend_transformed_tiled_argb8565(int count, const QSpan *spans, |
|
6562 |
void *userData) |
|
6563 |
{ |
|
6564 |
#if defined(QT_QWS_DEPTH_16) |
|
6565 |
QSpanData *data = reinterpret_cast<QSpanData *>(userData); |
|
6566 |
||
6567 |
if (data->texture.format == QImage::Format_ARGB8565_Premultiplied) |
|
6568 |
blendTransformedTiled<qargb8565, qargb8565>(count, spans, userData); |
|
6569 |
else if (data->texture.format == QImage::Format_RGB16) |
|
6570 |
blendTransformedTiled<qargb8565, qrgb565>(count, spans, userData); |
|
6571 |
else |
|
6572 |
#endif |
|
6573 |
blend_src_generic<RegularSpans>(count, spans, userData); |
|
6574 |
} |
|
6575 |
||
6576 |
static void blend_transformed_tiled_rgb565(int count, const QSpan *spans, |
|
6577 |
void *userData) |
|
6578 |
{ |
|
6579 |
#if defined(QT_QWS_DEPTH_16) |
|
6580 |
QSpanData *data = reinterpret_cast<QSpanData *>(userData); |
|
6581 |
||
6582 |
if (data->texture.format == QImage::Format_ARGB8565_Premultiplied) |
|
6583 |
blendTransformedTiled<qrgb565, qargb8565>(count, spans, userData); |
|
6584 |
else if (data->texture.format == QImage::Format_RGB16) |
|
6585 |
blendTransformedTiled<qrgb565, qrgb565>(count, spans, userData); |
|
6586 |
else |
|
6587 |
#endif |
|
6588 |
blend_src_generic<RegularSpans>(count, spans, userData); |
|
6589 |
} |
|
6590 |
||
6591 |
static void blend_transformed_tiled_argb8555(int count, const QSpan *spans, |
|
6592 |
void *userData) |
|
6593 |
{ |
|
6594 |
#if defined(QT_QWS_DEPTH_15) |
|
6595 |
QSpanData *data = reinterpret_cast<QSpanData *>(userData); |
|
6596 |
||
6597 |
if (data->texture.format == QImage::Format_ARGB8555_Premultiplied) |
|
6598 |
blendTransformedTiled<qargb8555, qargb8555>(count, spans, userData); |
|
6599 |
else if (data->texture.format == QImage::Format_RGB555) |
|
6600 |
blendTransformedTiled<qargb8555, qrgb555>(count, spans, userData); |
|
6601 |
else |
|
6602 |
#endif |
|
6603 |
blend_src_generic<RegularSpans>(count, spans, userData); |
|
6604 |
} |
|
6605 |
||
6606 |
static void blend_transformed_tiled_rgb555(int count, const QSpan *spans, |
|
6607 |
void *userData) |
|
6608 |
{ |
|
6609 |
#if defined(QT_QWS_DEPTH_15) |
|
6610 |
QSpanData *data = reinterpret_cast<QSpanData *>(userData); |
|
6611 |
||
6612 |
if (data->texture.format == QImage::Format_ARGB8555_Premultiplied) |
|
6613 |
blendTransformedTiled<qrgb555, qargb8555>(count, spans, userData); |
|
6614 |
else if (data->texture.format == QImage::Format_RGB555) |
|
6615 |
blendTransformedTiled<qrgb555, qrgb555>(count, spans, userData); |
|
6616 |
else |
|
6617 |
#endif |
|
6618 |
blend_src_generic<RegularSpans>(count, spans, userData); |
|
6619 |
} |
|
6620 |
||
6621 |
static void blend_transformed_tiled_argb4444(int count, const QSpan *spans, |
|
6622 |
void *userData) |
|
6623 |
{ |
|
6624 |
#if defined(QT_QWS_DEPTH_12) |
|
6625 |
QSpanData *data = reinterpret_cast<QSpanData *>(userData); |
|
6626 |
||
6627 |
if (data->texture.format == QImage::Format_ARGB4444_Premultiplied) |
|
6628 |
blendTransformedTiled<qargb4444, qargb4444>(count, spans, userData); |
|
6629 |
else if (data->texture.format == QImage::Format_RGB444) |
|
6630 |
blendTransformedTiled<qargb4444, qrgb444>(count, spans, userData); |
|
6631 |
else |
|
6632 |
#endif |
|
6633 |
blend_src_generic<RegularSpans>(count, spans, userData); |
|
6634 |
} |
|
6635 |
||
6636 |
static void blend_transformed_tiled_rgb444(int count, const QSpan *spans, |
|
6637 |
void *userData) |
|
6638 |
{ |
|
6639 |
#if defined(QT_QWS_DEPTH_12) |
|
6640 |
QSpanData *data = reinterpret_cast<QSpanData *>(userData); |
|
6641 |
||
6642 |
if (data->texture.format == QImage::Format_ARGB4444_Premultiplied) |
|
6643 |
blendTransformedTiled<qrgb444, qargb4444>(count, spans, userData); |
|
6644 |
else if (data->texture.format == QImage::Format_RGB444) |
|
6645 |
blendTransformedTiled<qrgb444, qrgb444>(count, spans, userData); |
|
6646 |
else |
|
6647 |
#endif |
|
6648 |
blend_src_generic<RegularSpans>(count, spans, userData); |
|
6649 |
} |
|
6650 |
||
6651 |
# define SPANFUNC_POINTER(Name, Arg) Name<Arg> |
|
6652 |
||
6653 |
||
6654 |
/* Image formats here are target formats */ |
|
6655 |
static const ProcessSpans processTextureSpans[NBlendTypes][QImage::NImageFormats] = { |
|
6656 |
// Untransformed |
|
6657 |
{ |
|
6658 |
0, // Invalid |
|
6659 |
SPANFUNC_POINTER(blend_untransformed_generic, RegularSpans), // Mono |
|
6660 |
SPANFUNC_POINTER(blend_untransformed_generic, RegularSpans), // MonoLsb |
|
6661 |
SPANFUNC_POINTER(blend_untransformed_generic, RegularSpans), // Indexed8 |
|
6662 |
SPANFUNC_POINTER(blend_untransformed_generic, RegularSpans), // RGB32 |
|
6663 |
SPANFUNC_POINTER(blend_untransformed_generic, RegularSpans), // ARGB32 |
|
6664 |
SPANFUNC_POINTER(blend_untransformed_argb, RegularSpans), // ARGB32_Premultiplied |
|
6665 |
blend_untransformed_rgb565, |
|
6666 |
blend_untransformed_argb8565, |
|
6667 |
blend_untransformed_rgb666, |
|
6668 |
blend_untransformed_argb6666, |
|
6669 |
blend_untransformed_rgb555, |
|
6670 |
blend_untransformed_argb8555, |
|
6671 |
blend_untransformed_rgb888, |
|
6672 |
blend_untransformed_rgb444, |
|
6673 |
blend_untransformed_argb4444, |
|
6674 |
}, |
|
6675 |
// Tiled |
|
6676 |
{ |
|
6677 |
0, // Invalid |
|
6678 |
SPANFUNC_POINTER(blend_tiled_generic, RegularSpans), // Mono |
|
6679 |
SPANFUNC_POINTER(blend_tiled_generic, RegularSpans), // MonoLsb |
|
6680 |
SPANFUNC_POINTER(blend_tiled_generic, RegularSpans), // Indexed8 |
|
6681 |
SPANFUNC_POINTER(blend_tiled_generic, RegularSpans), // RGB32 |
|
6682 |
SPANFUNC_POINTER(blend_tiled_generic, RegularSpans), // ARGB32 |
|
6683 |
SPANFUNC_POINTER(blend_tiled_argb, RegularSpans), // ARGB32_Premultiplied |
|
6684 |
blend_tiled_rgb565, |
|
6685 |
blend_tiled_argb8565, |
|
6686 |
blend_tiled_rgb666, |
|
6687 |
blend_tiled_argb6666, |
|
6688 |
blend_tiled_rgb555, |
|
6689 |
blend_tiled_argb8555, |
|
6690 |
blend_tiled_rgb888, |
|
6691 |
blend_tiled_rgb444, |
|
6692 |
blend_tiled_argb4444, |
|
6693 |
}, |
|
6694 |
// Transformed |
|
6695 |
{ |
|
6696 |
0, // Invalid |
|
6697 |
SPANFUNC_POINTER(blend_src_generic, RegularSpans), // Mono |
|
6698 |
SPANFUNC_POINTER(blend_src_generic, RegularSpans), // MonoLsb |
|
6699 |
SPANFUNC_POINTER(blend_src_generic, RegularSpans), // Indexed8 |
|
6700 |
SPANFUNC_POINTER(blend_src_generic, RegularSpans), // RGB32 |
|
6701 |
SPANFUNC_POINTER(blend_src_generic, RegularSpans), // ARGB32 |
|
6702 |
SPANFUNC_POINTER(blend_transformed_argb, RegularSpans), // ARGB32_Premultiplied |
|
6703 |
blend_transformed_rgb565, |
|
6704 |
blend_transformed_argb8565, |
|
6705 |
blend_transformed_rgb666, |
|
6706 |
blend_transformed_argb6666, |
|
6707 |
blend_transformed_rgb555, |
|
6708 |
blend_transformed_argb8555, |
|
6709 |
blend_transformed_rgb888, |
|
6710 |
blend_transformed_rgb444, |
|
6711 |
blend_transformed_argb4444, |
|
6712 |
}, |
|
6713 |
// TransformedTiled |
|
6714 |
{ |
|
6715 |
0, |
|
6716 |
SPANFUNC_POINTER(blend_src_generic, RegularSpans), // Mono |
|
6717 |
SPANFUNC_POINTER(blend_src_generic, RegularSpans), // MonoLsb |
|
6718 |
SPANFUNC_POINTER(blend_src_generic, RegularSpans), // Indexed8 |
|
6719 |
SPANFUNC_POINTER(blend_src_generic, RegularSpans), // RGB32 |
|
6720 |
SPANFUNC_POINTER(blend_src_generic, RegularSpans), // ARGB32 |
|
6721 |
SPANFUNC_POINTER(blend_transformed_tiled_argb, RegularSpans), // ARGB32_Premultiplied |
|
6722 |
blend_transformed_tiled_rgb565, |
|
6723 |
blend_transformed_tiled_argb8565, |
|
6724 |
blend_transformed_tiled_rgb666, |
|
6725 |
blend_transformed_tiled_argb6666, |
|
6726 |
blend_transformed_tiled_rgb555, |
|
6727 |
blend_transformed_tiled_argb8555, |
|
6728 |
blend_transformed_tiled_rgb888, |
|
6729 |
blend_transformed_tiled_rgb444, |
|
6730 |
blend_transformed_tiled_argb4444 |
|
6731 |
}, |
|
6732 |
// Bilinear |
|
6733 |
{ |
|
6734 |
0, |
|
6735 |
SPANFUNC_POINTER(blend_src_generic, RegularSpans), // Mono |
|
6736 |
SPANFUNC_POINTER(blend_src_generic, RegularSpans), // MonoLsb |
|
6737 |
SPANFUNC_POINTER(blend_src_generic, RegularSpans), // Indexed8 |
|
6738 |
SPANFUNC_POINTER(blend_src_generic, RegularSpans), // RGB32 |
|
6739 |
SPANFUNC_POINTER(blend_src_generic, RegularSpans), // ARGB32 |
|
6740 |
SPANFUNC_POINTER(blend_transformed_bilinear_argb, RegularSpans), // ARGB32_Premultiplied |
|
6741 |
blend_transformed_bilinear_rgb565, |
|
6742 |
blend_transformed_bilinear_argb8565, |
|
6743 |
blend_transformed_bilinear_rgb666, |
|
6744 |
blend_transformed_bilinear_argb6666, |
|
6745 |
blend_transformed_bilinear_rgb555, |
|
6746 |
blend_transformed_bilinear_argb8555, |
|
6747 |
blend_transformed_bilinear_rgb888, |
|
6748 |
blend_transformed_bilinear_rgb444, |
|
6749 |
blend_transformed_bilinear_argb4444, |
|
6750 |
}, |
|
6751 |
// BilinearTiled |
|
6752 |
{ |
|
6753 |
0, |
|
6754 |
SPANFUNC_POINTER(blend_src_generic, RegularSpans), // Mono |
|
6755 |
SPANFUNC_POINTER(blend_src_generic, RegularSpans), // MonoLsb |
|
6756 |
SPANFUNC_POINTER(blend_src_generic, RegularSpans), // Indexed8 |
|
6757 |
SPANFUNC_POINTER(blend_src_generic, RegularSpans), // RGB32 |
|
6758 |
SPANFUNC_POINTER(blend_src_generic, RegularSpans), // ARGB32 |
|
6759 |
SPANFUNC_POINTER(blend_transformed_bilinear_tiled_argb, RegularSpans), // ARGB32_Premultiplied |
|
6760 |
SPANFUNC_POINTER(blend_src_generic, RegularSpans), // RGB16 |
|
6761 |
SPANFUNC_POINTER(blend_src_generic, RegularSpans), // ARGB8565_Premultiplied |
|
6762 |
SPANFUNC_POINTER(blend_src_generic, RegularSpans), // RGB666 |
|
6763 |
SPANFUNC_POINTER(blend_src_generic, RegularSpans), // ARGB6666_Premultiplied |
|
6764 |
SPANFUNC_POINTER(blend_src_generic, RegularSpans), // RGB555 |
|
6765 |
SPANFUNC_POINTER(blend_src_generic, RegularSpans), // ARGB8555_Premultiplied |
|
6766 |
SPANFUNC_POINTER(blend_src_generic, RegularSpans), // RGB888 |
|
6767 |
SPANFUNC_POINTER(blend_src_generic, RegularSpans), // RGB444 |
|
6768 |
SPANFUNC_POINTER(blend_src_generic, RegularSpans), // ARGB4444_Premultiplied |
|
6769 |
} |
|
6770 |
}; |
|
6771 |
||
6772 |
#if defined (Q_WS_QWS) && !defined(QT_NO_RASTERCALLBACKS) |
|
6773 |
static const ProcessSpans processTextureSpansCallback[NBlendTypes][QImage::NImageFormats] = { |
|
6774 |
// Untransformed |
|
6775 |
{ |
|
6776 |
0, // Invalid |
|
6777 |
blend_untransformed_generic<CallbackSpans>, // Mono |
|
6778 |
blend_untransformed_generic<CallbackSpans>, // MonoLsb |
|
6779 |
blend_untransformed_generic<CallbackSpans>, // Indexed8 |
|
6780 |
blend_untransformed_generic<CallbackSpans>, // RGB32 |
|
6781 |
blend_untransformed_generic<CallbackSpans>, // ARGB32 |
|
6782 |
blend_untransformed_argb<CallbackSpans>, // ARGB32_Premultiplied |
|
6783 |
blend_untransformed_generic<CallbackSpans>, // RGB16 |
|
6784 |
blend_untransformed_generic<CallbackSpans>, // ARGB8565_Premultiplied |
|
6785 |
blend_untransformed_generic<CallbackSpans>, // RGB666 |
|
6786 |
blend_untransformed_generic<CallbackSpans>, // ARGB6666_Premultiplied |
|
6787 |
blend_untransformed_generic<CallbackSpans>, // RGB555 |
|
6788 |
blend_untransformed_generic<CallbackSpans>, // ARGB8555_Premultiplied |
|
6789 |
blend_untransformed_generic<CallbackSpans>, // RGB888 |
|
6790 |
blend_untransformed_generic<CallbackSpans>, // RGB444 |
|
6791 |
blend_untransformed_generic<CallbackSpans> // ARGB4444_Premultiplied |
|
6792 |
}, |
|
6793 |
// Tiled |
|
6794 |
{ |
|
6795 |
0, // Invalid |
|
6796 |
blend_tiled_generic<CallbackSpans>, // Mono |
|
6797 |
blend_tiled_generic<CallbackSpans>, // MonoLsb |
|
6798 |
blend_tiled_generic<CallbackSpans>, // Indexed8 |
|
6799 |
blend_tiled_generic<CallbackSpans>, // RGB32 |
|
6800 |
blend_tiled_generic<CallbackSpans>, // ARGB32 |
|
6801 |
blend_tiled_argb<CallbackSpans>, // ARGB32_Premultiplied |
|
6802 |
blend_tiled_generic<CallbackSpans>, // RGB16 |
|
6803 |
blend_tiled_generic<CallbackSpans>, // ARGB8565_Premultiplied |
|
6804 |
blend_tiled_generic<CallbackSpans>, // RGB666 |
|
6805 |
blend_tiled_generic<CallbackSpans>, // ARGB6666_Premultiplied |
|
6806 |
blend_tiled_generic<CallbackSpans>, // RGB555 |
|
6807 |
blend_tiled_generic<CallbackSpans>, // ARGB8555_Premultiplied |
|
6808 |
blend_tiled_generic<CallbackSpans>, // RGB888 |
|
6809 |
blend_tiled_generic<CallbackSpans>, // RGB444 |
|
6810 |
blend_tiled_generic<CallbackSpans> // ARGB4444_Premultiplied |
|
6811 |
}, |
|
6812 |
// Transformed |
|
6813 |
{ |
|
6814 |
0, // Invalid |
|
6815 |
blend_src_generic<CallbackSpans>, // Mono |
|
6816 |
blend_src_generic<CallbackSpans>, // MonoLsb |
|
6817 |
blend_src_generic<CallbackSpans>, // Indexed8 |
|
6818 |
blend_src_generic<CallbackSpans>, // RGB32 |
|
6819 |
blend_src_generic<CallbackSpans>, // ARGB32 |
|
6820 |
blend_transformed_argb<CallbackSpans>, // ARGB32_Premultiplied |
|
6821 |
blend_src_generic<CallbackSpans>, // RGB16 |
|
6822 |
blend_src_generic<CallbackSpans>, // ARGB8565_Premultiplied |
|
6823 |
blend_src_generic<CallbackSpans>, // RGB666 |
|
6824 |
blend_src_generic<CallbackSpans>, // ARGB6666_Premultiplied |
|
6825 |
blend_src_generic<CallbackSpans>, // RGB555 |
|
6826 |
blend_src_generic<CallbackSpans>, // ARGB8555_Premultiplied |
|
6827 |
blend_src_generic<CallbackSpans>, // RGB888 |
|
6828 |
blend_src_generic<CallbackSpans>, // RGB444 |
|
6829 |
blend_src_generic<CallbackSpans>, // ARGB4444_Premultiplied |
|
6830 |
}, |
|
6831 |
// TransformedTiled |
|
6832 |
{ |
|
6833 |
0, |
|
6834 |
blend_src_generic<CallbackSpans>, // Mono |
|
6835 |
blend_src_generic<CallbackSpans>, // MonoLsb |
|
6836 |
blend_src_generic<CallbackSpans>, // Indexed8 |
|
6837 |
blend_src_generic<CallbackSpans>, // RGB32 |
|
6838 |
blend_src_generic<CallbackSpans>, // ARGB32 |
|
6839 |
blend_transformed_tiled_argb<CallbackSpans>, // ARGB32_Premultiplied |
|
6840 |
blend_src_generic<CallbackSpans>, // RGB16 |
|
6841 |
blend_src_generic<CallbackSpans>, // ARGB8565_Premultiplied |
|
6842 |
blend_src_generic<CallbackSpans>, // RGB666 |
|
6843 |
blend_src_generic<CallbackSpans>, // ARGB6666_Premultiplied |
|
6844 |
blend_src_generic<CallbackSpans>, // RGB555 |
|
6845 |
blend_src_generic<CallbackSpans>, // ARGB8555_Premultiplied |
|
6846 |
blend_src_generic<CallbackSpans>, // RGB888 |
|
6847 |
blend_src_generic<CallbackSpans>, // RGB444 |
|
6848 |
blend_src_generic<CallbackSpans> // ARGB4444_Premultiplied |
|
6849 |
}, |
|
6850 |
// Bilinear |
|
6851 |
{ |
|
6852 |
0, |
|
6853 |
blend_src_generic<CallbackSpans>, // Mono |
|
6854 |
blend_src_generic<CallbackSpans>, // MonoLsb |
|
6855 |
blend_src_generic<CallbackSpans>, // Indexed8 |
|
6856 |
blend_src_generic<CallbackSpans>, // RGB32 |
|
6857 |
blend_src_generic<CallbackSpans>, // ARGB32 |
|
6858 |
blend_transformed_bilinear_argb<CallbackSpans>, // ARGB32_Premultiplied |
|
6859 |
blend_src_generic<CallbackSpans>, // RGB16 |
|
6860 |
blend_src_generic<CallbackSpans>, // ARGB8565_Premultiplied |
|
6861 |
blend_src_generic<CallbackSpans>, // RGB666 |
|
6862 |
blend_src_generic<CallbackSpans>, // ARGB6666_Premultiplied |
|
6863 |
blend_src_generic<CallbackSpans>, // RGB555 |
|
6864 |
blend_src_generic<CallbackSpans>, // ARGB8555_Premultiplied |
|
6865 |
blend_src_generic<CallbackSpans>, // RGB888 |
|
6866 |
blend_src_generic<CallbackSpans>, // RGB444 |
|
6867 |
blend_src_generic<CallbackSpans> // ARGB4444_Premultiplied |
|
6868 |
}, |
|
6869 |
// BilinearTiled |
|
6870 |
{ |
|
6871 |
0, |
|
6872 |
blend_src_generic<CallbackSpans>, // Mono |
|
6873 |
blend_src_generic<CallbackSpans>, // MonoLsb |
|
6874 |
blend_src_generic<CallbackSpans>, // Indexed8 |
|
6875 |
blend_src_generic<CallbackSpans>, // RGB32 |
|
6876 |
blend_src_generic<CallbackSpans>, // ARGB32 |
|
6877 |
blend_transformed_bilinear_tiled_argb<CallbackSpans>, // ARGB32_Premultiplied |
|
6878 |
blend_src_generic<CallbackSpans>, // RGB16 |
|
6879 |
blend_src_generic<CallbackSpans>, // ARGB8565_Premultiplied |
|
6880 |
blend_src_generic<CallbackSpans>, // RGB666 |
|
6881 |
blend_src_generic<CallbackSpans>, // ARGB6666_Premultiplied |
|
6882 |
blend_src_generic<CallbackSpans>, // RGB555 |
|
6883 |
blend_src_generic<CallbackSpans>, // ARGB8555_Premultiplied |
|
6884 |
blend_src_generic<CallbackSpans>, // RGB888 |
|
6885 |
blend_src_generic<CallbackSpans>, // RGB444 |
|
6886 |
blend_src_generic<CallbackSpans> // ARGB4444_Premultiplied |
|
6887 |
} |
|
6888 |
}; |
|
6889 |
#endif // QT_NO_RASTERCALLBACKS |
|
6890 |
||
6891 |
void qBlendTexture(int count, const QSpan *spans, void *userData) |
|
6892 |
{ |
|
6893 |
QSpanData *data = reinterpret_cast<QSpanData *>(userData); |
|
6894 |
ProcessSpans proc = processTextureSpans[getBlendType(data)][data->rasterBuffer->format]; |
|
6895 |
proc(count, spans, userData); |
|
6896 |
} |
|
6897 |
||
6898 |
#if defined (Q_WS_QWS) && !defined(QT_NO_RASTERCALLBACKS) |
|
6899 |
void qBlendTextureCallback(int count, const QSpan *spans, void *userData) |
|
6900 |
{ |
|
6901 |
QSpanData *data = reinterpret_cast<QSpanData *>(userData); |
|
6902 |
ProcessSpans proc = processTextureSpansCallback[getBlendType(data)][data->rasterBuffer->format]; |
|
6903 |
proc(count, spans, userData); |
|
6904 |
} |
|
6905 |
#endif // QT_NO_RASTERCALLBACKS |
|
6906 |
||
6907 |
template <class DST> |
|
6908 |
inline void qt_bitmapblit_template(QRasterBuffer *rasterBuffer, |
|
6909 |
int x, int y, quint32 color, |
|
6910 |
const uchar *map, |
|
6911 |
int mapWidth, int mapHeight, int mapStride, |
|
6912 |
DST dummy = 0) |
|
6913 |
{ |
|
6914 |
Q_UNUSED(dummy); |
|
6915 |
const DST c = qt_colorConvert<DST, quint32>(color, 0); |
|
6916 |
DST *dest = reinterpret_cast<DST*>(rasterBuffer->scanLine(y)) + x; |
|
6917 |
const int destStride = rasterBuffer->bytesPerLine() / sizeof(DST); |
|
6918 |
||
6919 |
if (mapWidth > 8) { |
|
6920 |
while (mapHeight--) { |
|
6921 |
int x0 = 0; |
|
6922 |
int n = 0; |
|
6923 |
for (int x = 0; x < mapWidth; x += 8) { |
|
6924 |
uchar s = map[x >> 3]; |
|
6925 |
for (int i = 0; i < 8; ++i) { |
|
6926 |
if (s & 0x80) { |
|
6927 |
++n; |
|
6928 |
} else { |
|
6929 |
if (n) { |
|
6930 |
qt_memfill(dest + x0, c, n); |
|
6931 |
x0 += n + 1; |
|
6932 |
n = 0; |
|
6933 |
} else { |
|
6934 |
++x0; |
|
6935 |
} |
|
6936 |
if (!s) { |
|
6937 |
x0 += 8 - 1 - i; |
|
6938 |
break; |
|
6939 |
} |
|
6940 |
} |
|
6941 |
s <<= 1; |
|
6942 |
} |
|
6943 |
} |
|
6944 |
if (n) |
|
6945 |
qt_memfill(dest + x0, c, n); |
|
6946 |
dest += destStride; |
|
6947 |
map += mapStride; |
|
6948 |
} |
|
6949 |
} else { |
|
6950 |
while (mapHeight--) { |
|
6951 |
int x0 = 0; |
|
6952 |
int n = 0; |
|
6953 |
for (uchar s = *map; s; s <<= 1) { |
|
6954 |
if (s & 0x80) { |
|
6955 |
++n; |
|
6956 |
} else if (n) { |
|
6957 |
qt_memfill(dest + x0, c, n); |
|
6958 |
x0 += n + 1; |
|
6959 |
n = 0; |
|
6960 |
} else { |
|
6961 |
++x0; |
|
6962 |
} |
|
6963 |
} |
|
6964 |
if (n) |
|
6965 |
qt_memfill(dest + x0, c, n); |
|
6966 |
dest += destStride; |
|
6967 |
map += mapStride; |
|
6968 |
} |
|
6969 |
} |
|
6970 |
} |
|
6971 |
||
6972 |
static void qt_gradient_quint32(int count, const QSpan *spans, void *userData) |
|
6973 |
{ |
|
6974 |
QSpanData *data = reinterpret_cast<QSpanData *>(userData); |
|
6975 |
||
6976 |
bool isVerticalGradient = |
|
6977 |
data->txop <= QTransform::TxScale && |
|
6978 |
data->type == QSpanData::LinearGradient && |
|
6979 |
data->gradient.linear.end.x == data->gradient.linear.origin.x; |
|
6980 |
||
6981 |
if (isVerticalGradient) { |
|
6982 |
LinearGradientValues linear; |
|
6983 |
getLinearGradientValues(&linear, data); |
|
6984 |
||
6985 |
CompositionFunctionSolid funcSolid = |
|
6986 |
functionForModeSolid[data->rasterBuffer->compositionMode]; |
|
6987 |
||
6988 |
/* |
|
6989 |
The logic for vertical gradient calculations is a mathematically |
|
6990 |
reduced copy of that in fetchLinearGradient() - which is basically: |
|
6991 |
||
6992 |
qreal ry = data->m22 * (y + 0.5) + data->dy; |
|
6993 |
qreal t = linear.dy*ry + linear.off; |
|
6994 |
t *= (GRADIENT_STOPTABLE_SIZE - 1); |
|
6995 |
quint32 color = |
|
6996 |
qt_gradient_pixel_fixed(&data->gradient, |
|
6997 |
int(t * FIXPT_SIZE)); |
|
6998 |
||
6999 |
This has then been converted to fixed point to improve performance. |
|
7000 |
*/ |
|
7001 |
const int gss = GRADIENT_STOPTABLE_SIZE - 1; |
|
7002 |
int yinc = int((linear.dy * data->m22 * gss) * FIXPT_SIZE); |
|
7003 |
int off = int((((linear.dy * (data->m22 * 0.5 + data->dy) + linear.off) * gss) * FIXPT_SIZE)); |
|
7004 |
||
7005 |
while (count--) { |
|
7006 |
int y = spans->y; |
|
7007 |
int x = spans->x; |
|
7008 |
||
7009 |
quint32 *dst = (quint32 *)(data->rasterBuffer->scanLine(y)) + x; |
|
7010 |
quint32 color = |
|
7011 |
qt_gradient_pixel_fixed(&data->gradient, yinc * y + off); |
|
7012 |
||
7013 |
funcSolid(dst, spans->len, color, spans->coverage); |
|
7014 |
++spans; |
|
7015 |
} |
|
7016 |
||
7017 |
} else { |
|
7018 |
blend_src_generic<RegularSpans>(count, spans, userData); |
|
7019 |
} |
|
7020 |
} |
|
7021 |
||
7022 |
static void qt_gradient_quint16(int count, const QSpan *spans, void *userData) |
|
7023 |
{ |
|
7024 |
QSpanData *data = reinterpret_cast<QSpanData *>(userData); |
|
7025 |
||
7026 |
bool isVerticalGradient = |
|
7027 |
data->txop <= QTransform::TxScale && |
|
7028 |
data->type == QSpanData::LinearGradient && |
|
7029 |
data->gradient.linear.end.x == data->gradient.linear.origin.x; |
|
7030 |
||
7031 |
if (isVerticalGradient) { |
|
7032 |
||
7033 |
LinearGradientValues linear; |
|
7034 |
getLinearGradientValues(&linear, data); |
|
7035 |
||
7036 |
/* |
|
7037 |
The logic for vertical gradient calculations is a mathematically |
|
7038 |
reduced copy of that in fetchLinearGradient() - which is basically: |
|
7039 |
||
7040 |
qreal ry = data->m22 * (y + 0.5) + data->dy; |
|
7041 |
qreal t = linear.dy*ry + linear.off; |
|
7042 |
t *= (GRADIENT_STOPTABLE_SIZE - 1); |
|
7043 |
quint32 color = |
|
7044 |
qt_gradient_pixel_fixed(&data->gradient, |
|
7045 |
int(t * FIXPT_SIZE)); |
|
7046 |
||
7047 |
This has then been converted to fixed point to improve performance. |
|
7048 |
*/ |
|
7049 |
const int gss = GRADIENT_STOPTABLE_SIZE - 1; |
|
7050 |
int yinc = int((linear.dy * data->m22 * gss) * FIXPT_SIZE); |
|
7051 |
int off = int((((linear.dy * (data->m22 * 0.5 + data->dy) + linear.off) * gss) * FIXPT_SIZE)); |
|
7052 |
||
7053 |
uint oldColor = data->solid.color; |
|
7054 |
while (count--) { |
|
7055 |
int y = spans->y; |
|
7056 |
||
7057 |
quint32 color = qt_gradient_pixel_fixed(&data->gradient, yinc * y + off); |
|
7058 |
||
7059 |
data->solid.color = color; |
|
7060 |
blend_color_rgb16(1, spans, userData); |
|
7061 |
++spans; |
|
7062 |
} |
|
7063 |
data->solid.color = oldColor; |
|
7064 |
||
7065 |
} else { |
|
7066 |
blend_src_generic<RegularSpans>(count, spans, userData); |
|
7067 |
} |
|
7068 |
} |
|
7069 |
||
7070 |
inline static void qt_bitmapblit_quint32(QRasterBuffer *rasterBuffer, |
|
7071 |
int x, int y, quint32 color, |
|
7072 |
const uchar *map, |
|
7073 |
int mapWidth, int mapHeight, int mapStride) |
|
7074 |
{ |
|
7075 |
qt_bitmapblit_template<quint32>(rasterBuffer, x, y, color, |
|
7076 |
map, mapWidth, mapHeight, mapStride); |
|
7077 |
} |
|
7078 |
||
7079 |
inline static void qt_bitmapblit_quint16(QRasterBuffer *rasterBuffer, |
|
7080 |
int x, int y, quint32 color, |
|
7081 |
const uchar *map, |
|
7082 |
int mapWidth, int mapHeight, int mapStride) |
|
7083 |
{ |
|
7084 |
qt_bitmapblit_template<quint16>(rasterBuffer, x, y, color, |
|
7085 |
map, mapWidth, mapHeight, mapStride); |
|
7086 |
} |
|
7087 |
||
7088 |
||
7089 |
uchar qt_pow_rgb_gamma[256]; |
|
7090 |
uchar qt_pow_rgb_invgamma[256]; |
|
7091 |
||
7092 |
uint qt_pow_gamma[256]; |
|
7093 |
uchar qt_pow_invgamma[2048]; |
|
7094 |
||
7095 |
static void qt_alphamapblit_quint16(QRasterBuffer *rasterBuffer, |
|
7096 |
int x, int y, quint32 color, |
|
7097 |
const uchar *map, |
|
7098 |
int mapWidth, int mapHeight, int mapStride, |
|
7099 |
const QClipData *) |
|
7100 |
{ |
|
7101 |
const quint16 c = qt_colorConvert<quint16, quint32>(color, 0); |
|
7102 |
quint16 *dest = reinterpret_cast<quint16*>(rasterBuffer->scanLine(y)) + x; |
|
7103 |
const int destStride = rasterBuffer->bytesPerLine() / sizeof(quint16); |
|
7104 |
||
7105 |
while (mapHeight--) { |
|
7106 |
for (int i = 0; i < mapWidth; ++i) { |
|
7107 |
const int coverage = map[i]; |
|
7108 |
||
7109 |
if (coverage == 0) { |
|
7110 |
// nothing |
|
7111 |
} else if (coverage == 255) { |
|
7112 |
dest[i] = c; |
|
7113 |
} else { |
|
7114 |
int ialpha = 255 - coverage; |
|
7115 |
dest[i] = BYTE_MUL_RGB16(c, coverage) |
|
7116 |
+ BYTE_MUL_RGB16(dest[i], ialpha); |
|
7117 |
} |
|
7118 |
} |
|
7119 |
dest += destStride; |
|
7120 |
map += mapStride; |
|
7121 |
} |
|
7122 |
} |
|
7123 |
||
7124 |
void qt_build_pow_tables() { |
|
7125 |
qreal smoothing = qreal(1.7); |
|
7126 |
||
7127 |
#ifdef Q_WS_MAC |
|
7128 |
// decided by testing a few things on an iMac, should probably get this from the |
|
7129 |
// system... |
|
7130 |
smoothing = 2.0; |
|
7131 |
#endif |
|
7132 |
||
7133 |
#ifdef Q_WS_WIN |
|
7134 |
int winSmooth; |
|
7135 |
if (SystemParametersInfo(0x200C /* SPI_GETFONTSMOOTHINGCONTRAST */, 0, &winSmooth, 0)) |
|
7136 |
smoothing = winSmooth / 1000.0; |
|
7137 |
#endif |
|
7138 |
||
7139 |
#ifdef Q_WS_X11 |
|
7140 |
Q_UNUSED(smoothing); |
|
7141 |
for (int i=0; i<256; ++i) { |
|
7142 |
qt_pow_rgb_gamma[i] = uchar(i); |
|
7143 |
qt_pow_rgb_invgamma[i] = uchar(i); |
|
7144 |
} |
|
7145 |
#else |
|
7146 |
for (int i=0; i<256; ++i) { |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
7147 |
qt_pow_rgb_gamma[i] = uchar(qRound(qPow(i / qreal(255.0), smoothing) * 255)); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
7148 |
qt_pow_rgb_invgamma[i] = uchar(qRound(qPow(i / qreal(255.), 1 / smoothing) * 255)); |
0 | 7149 |
} |
7150 |
#endif |
|
7151 |
||
7152 |
#if defined(Q_OS_WIN) && !defined(Q_OS_WINCE) |
|
7153 |
const qreal gray_gamma = 2.31; |
|
7154 |
for (int i=0; i<256; ++i) |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
7155 |
qt_pow_gamma[i] = uint(qRound(qPow(i / qreal(255.), gray_gamma) * 2047)); |
0 | 7156 |
for (int i=0; i<2048; ++i) |
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
7157 |
qt_pow_invgamma[i] = uchar(qRound(qPow(i / 2047.0, 1 / gray_gamma) * 255)); |
0 | 7158 |
#endif |
7159 |
} |
|
7160 |
||
7161 |
static inline void rgbBlendPixel(quint32 *dst, int coverage, int sr, int sg, int sb) |
|
7162 |
{ |
|
7163 |
// Do a gray alphablend... |
|
7164 |
int da = qAlpha(*dst); |
|
7165 |
int dr = qRed(*dst); |
|
7166 |
int dg = qGreen(*dst); |
|
7167 |
int db = qBlue(*dst); |
|
7168 |
||
7169 |
if (da != 255 |
|
7170 |
#if defined (Q_WS_WIN) |
|
7171 |
// Work around GDI messing up alpha channel |
|
7172 |
&& qRed(*dst) <= da && qBlue(*dst) <= da && qGreen(*dst) <= da |
|
7173 |
#endif |
|
7174 |
) { |
|
7175 |
||
7176 |
int a = qGray(coverage); |
|
7
f7bc934e204c
5cabc75a39ca2f064f70b40f72ed93c74c4dc19b
eckhart.koppen@nokia.com
parents:
3
diff
changeset
|
7177 |
sr = qt_div_255(qt_pow_rgb_invgamma[sr] * a); |
f7bc934e204c
5cabc75a39ca2f064f70b40f72ed93c74c4dc19b
eckhart.koppen@nokia.com
parents:
3
diff
changeset
|
7178 |
sg = qt_div_255(qt_pow_rgb_invgamma[sg] * a); |
f7bc934e204c
5cabc75a39ca2f064f70b40f72ed93c74c4dc19b
eckhart.koppen@nokia.com
parents:
3
diff
changeset
|
7179 |
sb = qt_div_255(qt_pow_rgb_invgamma[sb] * a); |
0 | 7180 |
|
7181 |
int ia = 255 - a; |
|
7182 |
dr = qt_div_255(dr * ia); |
|
7183 |
dg = qt_div_255(dg * ia); |
|
7184 |
db = qt_div_255(db * ia); |
|
7185 |
||
7186 |
*dst = ((a + qt_div_255((255 - a) * da)) << 24) |
|
7187 |
| ((sr + dr) << 16) |
|
7188 |
| ((sg + dg) << 8) |
|
7189 |
| ((sb + db)); |
|
7190 |
return; |
|
7191 |
} |
|
7192 |
||
7193 |
int mr = qRed(coverage); |
|
7194 |
int mg = qGreen(coverage); |
|
7195 |
int mb = qBlue(coverage); |
|
7196 |
||
7197 |
dr = qt_pow_rgb_gamma[dr]; |
|
7198 |
dg = qt_pow_rgb_gamma[dg]; |
|
7199 |
db = qt_pow_rgb_gamma[db]; |
|
7200 |
||
7201 |
int nr = qt_div_255((sr - dr) * mr) + dr; |
|
7202 |
int ng = qt_div_255((sg - dg) * mg) + dg; |
|
7203 |
int nb = qt_div_255((sb - db) * mb) + db; |
|
7204 |
||
7205 |
nr = qt_pow_rgb_invgamma[nr]; |
|
7206 |
ng = qt_pow_rgb_invgamma[ng]; |
|
7207 |
nb = qt_pow_rgb_invgamma[nb]; |
|
7208 |
||
7209 |
*dst = qRgb(nr, ng, nb); |
|
7210 |
} |
|
7211 |
||
7212 |
#if defined(Q_OS_WIN) && !defined(Q_OS_WINCE) |
|
7213 |
static inline void grayBlendPixel(quint32 *dst, int coverage, int sr, int sg, int sb) |
|
7214 |
{ |
|
7215 |
// Do a gammacorrected gray alphablend... |
|
7216 |
int dr = qRed(*dst); |
|
7217 |
int dg = qGreen(*dst); |
|
7218 |
int db = qBlue(*dst); |
|
7219 |
||
7220 |
dr = qt_pow_gamma[dr]; |
|
7221 |
dg = qt_pow_gamma[dg]; |
|
7222 |
db = qt_pow_gamma[db]; |
|
7223 |
||
7224 |
int alpha = coverage; |
|
7225 |
int ialpha = 255 - alpha; |
|
7226 |
int nr = (sr * alpha + ialpha * dr) / 255; |
|
7227 |
int ng = (sg * alpha + ialpha * dg) / 255; |
|
7228 |
int nb = (sb * alpha + ialpha * db) / 255; |
|
7229 |
||
7230 |
nr = qt_pow_invgamma[nr]; |
|
7231 |
ng = qt_pow_invgamma[ng]; |
|
7232 |
nb = qt_pow_invgamma[nb]; |
|
7233 |
||
7234 |
*dst = qRgb(nr, ng, nb); |
|
7235 |
} |
|
7236 |
#endif |
|
7237 |
||
7238 |
static void qt_alphamapblit_quint32(QRasterBuffer *rasterBuffer, |
|
7239 |
int x, int y, quint32 color, |
|
7240 |
const uchar *map, |
|
7241 |
int mapWidth, int mapHeight, int mapStride, |
|
7242 |
const QClipData *clip) |
|
7243 |
{ |
|
7244 |
const quint32 c = color; |
|
7245 |
const int destStride = rasterBuffer->bytesPerLine() / sizeof(quint32); |
|
7246 |
||
7247 |
#if defined(Q_OS_WIN) && !defined(Q_OS_WINCE) |
|
7248 |
int sr = qRed(color); |
|
7249 |
int sg = qGreen(color); |
|
7250 |
int sb = qBlue(color); |
|
7251 |
||
7252 |
sr = qt_pow_gamma[sr]; |
|
7253 |
sg = qt_pow_gamma[sg]; |
|
7254 |
sb = qt_pow_gamma[sb]; |
|
7255 |
bool opaque_src = (qAlpha(color) == 255); |
|
7256 |
#endif |
|
7257 |
||
7258 |
if (!clip) { |
|
7259 |
quint32 *dest = reinterpret_cast<quint32*>(rasterBuffer->scanLine(y)) + x; |
|
7260 |
while (mapHeight--) { |
|
7261 |
for (int i = 0; i < mapWidth; ++i) { |
|
7262 |
const int coverage = map[i]; |
|
7263 |
||
7264 |
if (coverage == 0) { |
|
7265 |
// nothing |
|
7266 |
} else if (coverage == 255) { |
|
7267 |
dest[i] = c; |
|
7268 |
} else { |
|
7269 |
#if defined(Q_OS_WIN) && !defined(Q_OS_WINCE) |
|
7270 |
if (QSysInfo::WindowsVersion >= QSysInfo::WV_XP && opaque_src |
|
7271 |
&& qAlpha(dest[i]) == 255) { |
|
7272 |
grayBlendPixel(dest+i, coverage, sr, sg, sb); |
|
7273 |
} else |
|
7274 |
#endif |
|
7275 |
{ |
|
7276 |
int ialpha = 255 - coverage; |
|
7277 |
dest[i] = INTERPOLATE_PIXEL_255(c, coverage, dest[i], ialpha); |
|
7278 |
} |
|
7279 |
} |
|
7280 |
} |
|
7281 |
dest += destStride; |
|
7282 |
map += mapStride; |
|
7283 |
} |
|
7284 |
} else { |
|
7285 |
int bottom = qMin(y + mapHeight, rasterBuffer->height()); |
|
7286 |
||
7287 |
int top = qMax(y, 0); |
|
7288 |
map += (top - y) * mapStride; |
|
7289 |
||
7290 |
const_cast<QClipData *>(clip)->initialize(); |
|
7291 |
for (int yp = top; yp<bottom; ++yp) { |
|
7292 |
const QClipData::ClipLine &line = clip->m_clipLines[yp]; |
|
7293 |
||
7294 |
quint32 *dest = reinterpret_cast<quint32 *>(rasterBuffer->scanLine(yp)); |
|
7295 |
||
7296 |
for (int i=0; i<line.count; ++i) { |
|
7297 |
const QSpan &clip = line.spans[i]; |
|
7298 |
||
7299 |
int start = qMax<int>(x, clip.x); |
|
7300 |
int end = qMin<int>(x + mapWidth, clip.x + clip.len); |
|
7301 |
||
7302 |
for (int xp=start; xp<end; ++xp) { |
|
7303 |
const int coverage = map[xp - x]; |
|
7304 |
||
7305 |
if (coverage == 0) { |
|
7306 |
// nothing |
|
7307 |
} else if (coverage == 255) { |
|
7308 |
dest[xp] = c; |
|
7309 |
} else { |
|
7310 |
#if defined(Q_OS_WIN) && !defined(Q_OS_WINCE) |
|
7311 |
if (QSysInfo::WindowsVersion >= QSysInfo::WV_XP && opaque_src |
|
7312 |
&& qAlpha(dest[xp]) == 255) { |
|
7313 |
grayBlendPixel(dest+xp, coverage, sr, sg, sb); |
|
7314 |
} else |
|
7315 |
#endif |
|
7316 |
{ |
|
7317 |
int ialpha = 255 - coverage; |
|
7318 |
dest[xp] = INTERPOLATE_PIXEL_255(c, coverage, dest[xp], ialpha); |
|
7319 |
} |
|
7320 |
} |
|
7321 |
||
7322 |
} // for (i -> line.count) |
|
7323 |
} // for (yp -> bottom) |
|
7324 |
map += mapStride; |
|
7325 |
} |
|
7326 |
} |
|
7327 |
} |
|
7328 |
||
7329 |
static void qt_alphargbblit_quint32(QRasterBuffer *rasterBuffer, |
|
7330 |
int x, int y, quint32 color, |
|
7331 |
const uint *src, int mapWidth, int mapHeight, int srcStride, |
|
7332 |
const QClipData *clip) |
|
7333 |
{ |
|
7334 |
const quint32 c = color; |
|
7335 |
||
7336 |
int sr = qRed(color); |
|
7337 |
int sg = qGreen(color); |
|
7338 |
int sb = qBlue(color); |
|
7339 |
int sa = qAlpha(color); |
|
7340 |
||
7341 |
sr = qt_pow_rgb_gamma[sr]; |
|
7342 |
sg = qt_pow_rgb_gamma[sg]; |
|
7343 |
sb = qt_pow_rgb_gamma[sb]; |
|
7344 |
||
7345 |
if (sa == 0) |
|
7346 |
return; |
|
7347 |
||
7348 |
if (!clip) { |
|
7349 |
quint32 *dst = reinterpret_cast<quint32*>(rasterBuffer->scanLine(y)) + x; |
|
7350 |
const int destStride = rasterBuffer->bytesPerLine() / sizeof(quint32); |
|
7351 |
while (mapHeight--) { |
|
7352 |
for (int i = 0; i < mapWidth; ++i) { |
|
7353 |
const uint coverage = src[i]; |
|
7354 |
if (coverage == 0xffffffff) { |
|
7355 |
dst[i] = c; |
|
7356 |
} else if (coverage != 0xff000000) { |
|
7357 |
rgbBlendPixel(dst+i, coverage, sr, sg, sb); |
|
7358 |
} |
|
7359 |
} |
|
7360 |
||
7361 |
dst += destStride; |
|
7362 |
src += srcStride; |
|
7363 |
} |
|
7364 |
} else { |
|
7365 |
int bottom = qMin(y + mapHeight, rasterBuffer->height()); |
|
7366 |
||
7367 |
int top = qMax(y, 0); |
|
7368 |
src += (top - y) * srcStride; |
|
7369 |
||
7370 |
const_cast<QClipData *>(clip)->initialize(); |
|
7371 |
for (int yp = top; yp<bottom; ++yp) { |
|
7372 |
const QClipData::ClipLine &line = clip->m_clipLines[yp]; |
|
7373 |
||
7374 |
quint32 *dst = reinterpret_cast<quint32 *>(rasterBuffer->scanLine(yp)); |
|
7375 |
||
7376 |
for (int i=0; i<line.count; ++i) { |
|
7377 |
const QSpan &clip = line.spans[i]; |
|
7378 |
||
7379 |
int start = qMax<int>(x, clip.x); |
|
7380 |
int end = qMin<int>(x + mapWidth, clip.x + clip.len); |
|
7381 |
||
7382 |
for (int xp=start; xp<end; ++xp) { |
|
7383 |
const uint coverage = src[xp - x]; |
|
7384 |
if (coverage == 0xffffffff) { |
|
7385 |
dst[xp] = c; |
|
7386 |
} else if (coverage != 0xff000000) { |
|
7387 |
rgbBlendPixel(dst+xp, coverage, sr, sg, sb); |
|
7388 |
} |
|
7389 |
} |
|
7390 |
} // for (i -> line.count) |
|
7391 |
src += srcStride; |
|
7392 |
} // for (yp -> bottom) |
|
7393 |
||
7394 |
} |
|
7395 |
} |
|
7396 |
||
7397 |
template <class T> |
|
7398 |
inline void qt_rectfill_template(QRasterBuffer *rasterBuffer, |
|
7399 |
int x, int y, int width, int height, |
|
7400 |
quint32 color, T dummy = 0) |
|
7401 |
{ |
|
7402 |
Q_UNUSED(dummy); |
|
7403 |
||
7404 |
qt_rectfill<T>(reinterpret_cast<T*>(rasterBuffer->buffer()), |
|
7405 |
qt_colorConvert<T, quint32p>(quint32p::fromRawData(color), 0), |
|
7406 |
x, y, width, height, rasterBuffer->bytesPerLine()); |
|
7407 |
} |
|
7408 |
||
7409 |
#define QT_RECTFILL(T) \ |
|
7410 |
inline static void qt_rectfill_##T(QRasterBuffer *rasterBuffer, \ |
|
7411 |
int x, int y, int width, int height, \ |
|
7412 |
quint32 color) \ |
|
7413 |
{ \ |
|
7414 |
qt_rectfill_template<T>(rasterBuffer, x, y, width, height, color); \ |
|
7415 |
} |
|
7416 |
||
7417 |
QT_RECTFILL(quint32) |
|
7418 |
QT_RECTFILL(quint16) |
|
7419 |
QT_RECTFILL(qargb8565) |
|
7420 |
QT_RECTFILL(qrgb666) |
|
7421 |
QT_RECTFILL(qargb6666) |
|
7422 |
QT_RECTFILL(qrgb555) |
|
7423 |
QT_RECTFILL(qargb8555) |
|
7424 |
QT_RECTFILL(qrgb888) |
|
7425 |
QT_RECTFILL(qrgb444) |
|
7426 |
QT_RECTFILL(qargb4444) |
|
7427 |
#undef QT_RECTFILL |
|
7428 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
7429 |
inline static void qt_rectfill_nonpremul_quint32(QRasterBuffer *rasterBuffer, |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
7430 |
int x, int y, int width, int height, |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
7431 |
quint32 color) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
7432 |
{ |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
7433 |
qt_rectfill<quint32>(reinterpret_cast<quint32 *>(rasterBuffer->buffer()), |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
7434 |
INV_PREMUL(color), x, y, width, height, rasterBuffer->bytesPerLine()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
7435 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
7436 |
|
0 | 7437 |
|
7438 |
// Map table for destination image format. Contains function pointers |
|
7439 |
// for blends of various types unto the destination |
|
7440 |
||
7441 |
DrawHelper qDrawHelper[QImage::NImageFormats] = |
|
7442 |
{ |
|
7443 |
// Format_Invalid, |
|
7444 |
{ 0, 0, 0, 0, 0, 0 }, |
|
7445 |
// Format_Mono, |
|
7446 |
{ |
|
7447 |
blend_color_generic, |
|
7448 |
SPANFUNC_POINTER(blend_src_generic, RegularSpans), |
|
7449 |
0, 0, 0, 0 |
|
7450 |
}, |
|
7451 |
// Format_MonoLSB, |
|
7452 |
{ |
|
7453 |
blend_color_generic, |
|
7454 |
SPANFUNC_POINTER(blend_src_generic, RegularSpans), |
|
7455 |
0, 0, 0, 0 |
|
7456 |
}, |
|
7457 |
// Format_Indexed8, |
|
7458 |
{ |
|
7459 |
blend_color_generic, |
|
7460 |
SPANFUNC_POINTER(blend_src_generic, RegularSpans), |
|
7461 |
0, 0, 0, 0 |
|
7462 |
}, |
|
7463 |
// Format_RGB32, |
|
7464 |
{ |
|
7465 |
blend_color_argb, |
|
7466 |
qt_gradient_quint32, |
|
7467 |
qt_bitmapblit_quint32, |
|
7468 |
qt_alphamapblit_quint32, |
|
7469 |
qt_alphargbblit_quint32, |
|
7470 |
qt_rectfill_quint32 |
|
7471 |
}, |
|
7472 |
// Format_ARGB32, |
|
7473 |
{ |
|
7474 |
blend_color_generic, |
|
7475 |
qt_gradient_quint32, |
|
7476 |
qt_bitmapblit_quint32, |
|
7477 |
qt_alphamapblit_quint32, |
|
7478 |
qt_alphargbblit_quint32, |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
7479 |
qt_rectfill_nonpremul_quint32 |
0 | 7480 |
}, |
7481 |
// Format_ARGB32_Premultiplied |
|
7482 |
{ |
|
7483 |
blend_color_argb, |
|
7484 |
qt_gradient_quint32, |
|
7485 |
qt_bitmapblit_quint32, |
|
7486 |
qt_alphamapblit_quint32, |
|
7487 |
qt_alphargbblit_quint32, |
|
7488 |
qt_rectfill_quint32 |
|
7489 |
}, |
|
7490 |
// Format_RGB16 |
|
7491 |
{ |
|
7492 |
blend_color_rgb16, |
|
7493 |
qt_gradient_quint16, |
|
7494 |
qt_bitmapblit_quint16, |
|
7495 |
qt_alphamapblit_quint16, |
|
7496 |
0, |
|
7497 |
qt_rectfill_quint16 |
|
7498 |
}, |
|
7499 |
// Format_ARGB8565_Premultiplied |
|
7500 |
{ |
|
7501 |
SPANFUNC_POINTER_BLENDCOLOR(qargb8565), |
|
7502 |
SPANFUNC_POINTER(blend_src_generic, RegularSpans), |
|
7503 |
0, 0, 0, |
|
7504 |
qt_rectfill_qargb8565 |
|
7505 |
}, |
|
7506 |
// Format_RGB666 |
|
7507 |
{ |
|
7508 |
SPANFUNC_POINTER_BLENDCOLOR(qrgb666), |
|
7509 |
SPANFUNC_POINTER(blend_src_generic, RegularSpans), |
|
7510 |
0, 0, 0, |
|
7511 |
qt_rectfill_qrgb666 |
|
7512 |
}, |
|
7513 |
// Format_ARGB6666_Premultiplied |
|
7514 |
{ |
|
7515 |
SPANFUNC_POINTER_BLENDCOLOR(qargb6666), |
|
7516 |
SPANFUNC_POINTER(blend_src_generic, RegularSpans), |
|
7517 |
0, 0, 0, |
|
7518 |
qt_rectfill_qargb6666 |
|
7519 |
}, |
|
7520 |
// Format_RGB555 |
|
7521 |
{ |
|
7522 |
SPANFUNC_POINTER_BLENDCOLOR(qrgb555), |
|
7523 |
SPANFUNC_POINTER(blend_src_generic, RegularSpans), |
|
7524 |
0, 0, 0, |
|
7525 |
qt_rectfill_qrgb555 |
|
7526 |
}, |
|
7527 |
// Format_ARGB8555_Premultiplied |
|
7528 |
{ |
|
7529 |
SPANFUNC_POINTER_BLENDCOLOR(qargb8555), |
|
7530 |
SPANFUNC_POINTER(blend_src_generic, RegularSpans), |
|
7531 |
0, 0, 0, |
|
7532 |
qt_rectfill_qargb8555 |
|
7533 |
}, |
|
7534 |
// Format_RGB888 |
|
7535 |
{ |
|
7536 |
SPANFUNC_POINTER_BLENDCOLOR(qrgb888), |
|
7537 |
SPANFUNC_POINTER(blend_src_generic, RegularSpans), |
|
7538 |
0, 0, 0, |
|
7539 |
qt_rectfill_qrgb888 |
|
7540 |
}, |
|
7541 |
// Format_RGB444 |
|
7542 |
{ |
|
7543 |
SPANFUNC_POINTER_BLENDCOLOR(qrgb444), |
|
7544 |
SPANFUNC_POINTER(blend_src_generic, RegularSpans), |
|
7545 |
0, 0, 0, |
|
7546 |
qt_rectfill_qrgb444 |
|
7547 |
}, |
|
7548 |
// Format_ARGB4444_Premultiplied |
|
7549 |
{ |
|
7550 |
SPANFUNC_POINTER_BLENDCOLOR(qargb4444), |
|
7551 |
SPANFUNC_POINTER(blend_src_generic, RegularSpans), |
|
7552 |
0, 0, 0, |
|
7553 |
qt_rectfill_qargb4444 |
|
7554 |
} |
|
7555 |
}; |
|
7556 |
||
7557 |
#if defined (Q_WS_QWS) && !defined(QT_NO_RASTERCALLBACKS) |
|
7558 |
DrawHelper qDrawHelperCallback[QImage::NImageFormats] = |
|
7559 |
{ |
|
7560 |
// Format_Invalid, |
|
7561 |
{ 0, 0, 0, 0, 0, 0 }, |
|
7562 |
// Format_Mono, |
|
7563 |
{ |
|
7564 |
blend_color_generic_callback, |
|
7565 |
blend_src_generic<CallbackSpans>, |
|
7566 |
0, 0, 0, 0 |
|
7567 |
}, |
|
7568 |
// Format_MonoLSB, |
|
7569 |
{ |
|
7570 |
blend_color_generic_callback, |
|
7571 |
blend_src_generic<CallbackSpans>, |
|
7572 |
0, 0, 0, 0 |
|
7573 |
}, |
|
7574 |
// Format_Indexed8, |
|
7575 |
{ |
|
7576 |
blend_color_generic_callback, |
|
7577 |
blend_src_generic<CallbackSpans>, |
|
7578 |
0, 0, 0, 0 |
|
7579 |
}, |
|
7580 |
// Format_RGB32, |
|
7581 |
{ |
|
7582 |
blend_color_generic_callback, |
|
7583 |
blend_src_generic<CallbackSpans>, |
|
7584 |
0, 0, 0, 0 |
|
7585 |
}, |
|
7586 |
// Format_ARGB32, |
|
7587 |
{ |
|
7588 |
blend_color_generic_callback, |
|
7589 |
blend_src_generic<CallbackSpans>, |
|
7590 |
0, 0, 0, 0 |
|
7591 |
}, |
|
7592 |
// Format_ARGB32_Premultiplied |
|
7593 |
{ |
|
7594 |
blend_color_generic_callback, |
|
7595 |
blend_src_generic<CallbackSpans>, |
|
7596 |
0, 0, 0, 0 |
|
7597 |
}, |
|
7598 |
// Format_RGB16 |
|
7599 |
{ |
|
7600 |
blend_color_generic_callback, |
|
7601 |
blend_src_generic<CallbackSpans>, |
|
7602 |
0, 0, 0, 0 |
|
7603 |
}, |
|
7604 |
// Format_ARGB8565_Premultiplied |
|
7605 |
{ |
|
7606 |
blend_color_generic_callback, |
|
7607 |
blend_src_generic<CallbackSpans>, |
|
7608 |
0, 0, 0, 0 |
|
7609 |
}, |
|
7610 |
// Format_RGB666 |
|
7611 |
{ |
|
7612 |
blend_color_generic_callback, |
|
7613 |
blend_src_generic<CallbackSpans>, |
|
7614 |
0, 0, 0, 0 |
|
7615 |
}, |
|
7616 |
// Format_ARGB6666_Premultiplied |
|
7617 |
{ |
|
7618 |
blend_color_generic_callback, |
|
7619 |
blend_src_generic<CallbackSpans>, |
|
7620 |
0, 0, 0, 0 |
|
7621 |
}, |
|
7622 |
// Format_RGB555 |
|
7623 |
{ |
|
7624 |
blend_color_generic_callback, |
|
7625 |
blend_src_generic<CallbackSpans>, |
|
7626 |
0, 0, 0, 0 |
|
7627 |
}, |
|
7628 |
// Format_ARGB8555_Premultiplied |
|
7629 |
{ |
|
7630 |
blend_color_generic_callback, |
|
7631 |
blend_src_generic<CallbackSpans>, |
|
7632 |
0, 0, 0, 0 |
|
7633 |
}, |
|
7634 |
// Format_RGB888 |
|
7635 |
{ |
|
7636 |
blend_color_generic_callback, |
|
7637 |
blend_src_generic<CallbackSpans>, |
|
7638 |
0, 0, 0, 0 |
|
7639 |
}, |
|
7640 |
// Format_RGB444 |
|
7641 |
{ |
|
7642 |
blend_color_generic_callback, |
|
7643 |
blend_src_generic<CallbackSpans>, |
|
7644 |
0, 0, 0, 0 |
|
7645 |
}, |
|
7646 |
// Format_ARGB4444_Premultiplied |
|
7647 |
{ |
|
7648 |
blend_color_generic_callback, |
|
7649 |
blend_src_generic<CallbackSpans>, |
|
7650 |
0, 0, 0, 0 |
|
7651 |
} |
|
7652 |
}; |
|
7653 |
#endif |
|
7654 |
||
7655 |
||
7656 |
||
7657 |
#if defined(Q_CC_MSVC) && !defined(_MIPS_) |
|
7658 |
template <class DST, class SRC> |
|
7659 |
inline void qt_memfill_template(DST *dest, SRC color, int count) |
|
7660 |
{ |
|
7661 |
const DST c = qt_colorConvert<DST, SRC>(color, 0); |
|
7662 |
while (count--) |
|
7663 |
*dest++ = c; |
|
7664 |
} |
|
7665 |
||
7666 |
#else |
|
7667 |
||
7668 |
template <class DST, class SRC> |
|
7669 |
inline void qt_memfill_template(DST *dest, SRC color, int count) |
|
7670 |
{ |
|
7671 |
const DST c = qt_colorConvert<DST, SRC>(color, 0); |
|
7672 |
int n = (count + 7) / 8; |
|
7673 |
switch (count & 0x07) |
|
7674 |
{ |
|
7675 |
case 0: do { *dest++ = c; |
|
7676 |
case 7: *dest++ = c; |
|
7677 |
case 6: *dest++ = c; |
|
7678 |
case 5: *dest++ = c; |
|
7679 |
case 4: *dest++ = c; |
|
7680 |
case 3: *dest++ = c; |
|
7681 |
case 2: *dest++ = c; |
|
7682 |
case 1: *dest++ = c; |
|
7683 |
} while (--n > 0); |
|
7684 |
} |
|
7685 |
} |
|
7686 |
||
7687 |
template <> |
|
7688 |
inline void qt_memfill_template(quint16 *dest, quint16 value, int count) |
|
7689 |
{ |
|
7690 |
if (count < 3) { |
|
7691 |
switch (count) { |
|
7692 |
case 2: *dest++ = value; |
|
7693 |
case 1: *dest = value; |
|
7694 |
} |
|
7695 |
return; |
|
7696 |
} |
|
7697 |
||
7698 |
const int align = (quintptr)(dest) & 0x3; |
|
7699 |
switch (align) { |
|
7700 |
case 2: *dest++ = value; --count; |
|
7701 |
} |
|
7702 |
||
7703 |
const quint32 value32 = (value << 16) | value; |
|
7704 |
qt_memfill(reinterpret_cast<quint32*>(dest), value32, count / 2); |
|
7705 |
if (count & 0x1) |
|
7706 |
dest[count - 1] = value; |
|
7707 |
} |
|
7708 |
#endif |
|
7709 |
||
7710 |
static void qt_memfill_quint16(quint16 *dest, quint16 color, int count) |
|
7711 |
{ |
|
7712 |
qt_memfill_template<quint16, quint16>(dest, color, count); |
|
7713 |
} |
|
7714 |
||
7715 |
typedef void (*qt_memfill32_func)(quint32 *dest, quint32 value, int count); |
|
7716 |
typedef void (*qt_memfill16_func)(quint16 *dest, quint16 value, int count); |
|
7717 |
static void qt_memfill32_setup(quint32 *dest, quint32 value, int count); |
|
7718 |
static void qt_memfill16_setup(quint16 *dest, quint16 value, int count); |
|
7719 |
||
7720 |
qt_memfill32_func qt_memfill32 = qt_memfill32_setup; |
|
7721 |
qt_memfill16_func qt_memfill16 = qt_memfill16_setup; |
|
7722 |
||
7723 |
enum CPUFeatures { |
|
7724 |
None = 0, |
|
7725 |
MMX = 0x1, |
|
7726 |
MMXEXT = 0x2, |
|
7727 |
MMX3DNOW = 0x4, |
|
7728 |
MMX3DNOWEXT = 0x8, |
|
7729 |
SSE = 0x10, |
|
7730 |
SSE2 = 0x20, |
|
7731 |
CMOV = 0x40, |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
7732 |
IWMMXT = 0x80, |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
7733 |
NEON = 0x100 |
0 | 7734 |
}; |
7735 |
||
7736 |
static uint detectCPUFeatures() |
|
7737 |
{ |
|
7738 |
#if defined (Q_OS_WINCE) |
|
7739 |
#if defined (ARM) |
|
7740 |
if (IsProcessorFeaturePresent(PF_ARM_INTEL_WMMX)) |
|
7741 |
return IWMMXT; |
|
7742 |
#elif defined(_X86_) |
|
7743 |
uint features = 0; |
|
7744 |
#if defined QT_HAVE_MMX |
|
7745 |
if (IsProcessorFeaturePresent(PF_MMX_INSTRUCTIONS_AVAILABLE)) |
|
7746 |
features |= MMX; |
|
7747 |
#endif |
|
7748 |
#if defined QT_HAVE_3DNOW |
|
7749 |
if (IsProcessorFeaturePresent(PF_3DNOW_INSTRUCTIONS_AVAILABLE)) |
|
7750 |
features |= MMX3DNOW; |
|
7751 |
#endif |
|
7752 |
return features; |
|
7753 |
#endif |
|
7754 |
return 0; |
|
7755 |
#elif defined(QT_HAVE_IWMMXT) |
|
7756 |
// runtime detection only available when running as a previlegied process |
|
7757 |
static const bool doIWMMXT = !qgetenv("QT_NO_IWMMXT").toInt(); |
|
7758 |
return doIWMMXT ? IWMMXT : 0; |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
7759 |
#elif defined(QT_HAVE_NEON) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
7760 |
static const bool doNEON = !qgetenv("QT_NO_NEON").toInt(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
7761 |
return doNEON ? NEON : 0; |
0 | 7762 |
#else |
7763 |
uint features = 0; |
|
7764 |
#if defined(__x86_64__) || defined(Q_OS_WIN64) |
|
7765 |
features = MMX|SSE|SSE2|CMOV; |
|
7766 |
#elif defined(__ia64__) |
|
7767 |
features = MMX|SSE|SSE2; |
|
7768 |
#elif defined(__i386__) || defined(_M_IX86) |
|
7769 |
unsigned int extended_result = 0; |
|
7770 |
uint result = 0; |
|
7771 |
/* see p. 118 of amd64 instruction set manual Vol3 */ |
|
7772 |
#if defined(Q_CC_GNU) |
|
7773 |
asm ("push %%ebx\n" |
|
7774 |
"pushf\n" |
|
7775 |
"pop %%eax\n" |
|
7776 |
"mov %%eax, %%ebx\n" |
|
7777 |
"xor $0x00200000, %%eax\n" |
|
7778 |
"push %%eax\n" |
|
7779 |
"popf\n" |
|
7780 |
"pushf\n" |
|
7781 |
"pop %%eax\n" |
|
7782 |
"xor %%edx, %%edx\n" |
|
7783 |
"xor %%ebx, %%eax\n" |
|
7784 |
"jz 1f\n" |
|
7785 |
||
7786 |
"mov $0x00000001, %%eax\n" |
|
7787 |
"cpuid\n" |
|
7788 |
"1:\n" |
|
7789 |
"pop %%ebx\n" |
|
7790 |
"mov %%edx, %0\n" |
|
7791 |
: "=r" (result) |
|
7792 |
: |
|
7793 |
: "%eax", "%ecx", "%edx" |
|
7794 |
); |
|
7795 |
||
7796 |
asm ("push %%ebx\n" |
|
7797 |
"pushf\n" |
|
7798 |
"pop %%eax\n" |
|
7799 |
"mov %%eax, %%ebx\n" |
|
7800 |
"xor $0x00200000, %%eax\n" |
|
7801 |
"push %%eax\n" |
|
7802 |
"popf\n" |
|
7803 |
"pushf\n" |
|
7804 |
"pop %%eax\n" |
|
7805 |
"xor %%edx, %%edx\n" |
|
7806 |
"xor %%ebx, %%eax\n" |
|
7807 |
"jz 2f\n" |
|
7808 |
||
7809 |
"mov $0x80000000, %%eax\n" |
|
7810 |
"cpuid\n" |
|
7811 |
"cmp $0x80000000, %%eax\n" |
|
7812 |
"jbe 2f\n" |
|
7813 |
"mov $0x80000001, %%eax\n" |
|
7814 |
"cpuid\n" |
|
7815 |
"2:\n" |
|
7816 |
"pop %%ebx\n" |
|
7817 |
"mov %%edx, %0\n" |
|
7818 |
: "=r" (extended_result) |
|
7819 |
: |
|
7820 |
: "%eax", "%ecx", "%edx" |
|
7821 |
); |
|
7822 |
#elif defined (Q_OS_WIN) |
|
7823 |
_asm { |
|
7824 |
push eax |
|
7825 |
push ebx |
|
7826 |
push ecx |
|
7827 |
push edx |
|
7828 |
pushfd |
|
7829 |
pop eax |
|
7830 |
mov ebx, eax |
|
7831 |
xor eax, 00200000h |
|
7832 |
push eax |
|
7833 |
popfd |
|
7834 |
pushfd |
|
7835 |
pop eax |
|
7836 |
mov edx, 0 |
|
7837 |
xor eax, ebx |
|
7838 |
jz skip |
|
7839 |
||
7840 |
mov eax, 1 |
|
7841 |
cpuid |
|
7842 |
mov result, edx |
|
7843 |
skip: |
|
7844 |
pop edx |
|
7845 |
pop ecx |
|
7846 |
pop ebx |
|
7847 |
pop eax |
|
7848 |
} |
|
7849 |
||
7850 |
_asm { |
|
7851 |
push eax |
|
7852 |
push ebx |
|
7853 |
push ecx |
|
7854 |
push edx |
|
7855 |
pushfd |
|
7856 |
pop eax |
|
7857 |
mov ebx, eax |
|
7858 |
xor eax, 00200000h |
|
7859 |
push eax |
|
7860 |
popfd |
|
7861 |
pushfd |
|
7862 |
pop eax |
|
7863 |
mov edx, 0 |
|
7864 |
xor eax, ebx |
|
7865 |
jz skip2 |
|
7866 |
||
7867 |
mov eax, 80000000h |
|
7868 |
cpuid |
|
7869 |
cmp eax, 80000000h |
|
7870 |
jbe skip2 |
|
7871 |
mov eax, 80000001h |
|
7872 |
cpuid |
|
7873 |
mov extended_result, edx |
|
7874 |
skip2: |
|
7875 |
pop edx |
|
7876 |
pop ecx |
|
7877 |
pop ebx |
|
7878 |
pop eax |
|
7879 |
} |
|
7880 |
#endif |
|
7881 |
||
7882 |
// result now contains the standard feature bits |
|
7883 |
if (result & (1u << 15)) |
|
7884 |
features |= CMOV; |
|
7885 |
if (result & (1u << 23)) |
|
7886 |
features |= MMX; |
|
7887 |
if (extended_result & (1u << 22)) |
|
7888 |
features |= MMXEXT; |
|
7889 |
if (extended_result & (1u << 31)) |
|
7890 |
features |= MMX3DNOW; |
|
7891 |
if (extended_result & (1u << 30)) |
|
7892 |
features |= MMX3DNOWEXT; |
|
7893 |
if (result & (1u << 25)) |
|
7894 |
features |= SSE; |
|
7895 |
if (result & (1u << 26)) |
|
7896 |
features |= SSE2; |
|
7897 |
#endif // i386 |
|
7898 |
||
7899 |
if (qgetenv("QT_NO_MMX").toInt()) |
|
7900 |
features ^= MMX; |
|
7901 |
if (qgetenv("QT_NO_MMXEXT").toInt()) |
|
7902 |
features ^= MMXEXT; |
|
7903 |
if (qgetenv("QT_NO_3DNOW").toInt()) |
|
7904 |
features ^= MMX3DNOW; |
|
7905 |
if (qgetenv("QT_NO_3DNOWEXT").toInt()) |
|
7906 |
features ^= MMX3DNOWEXT; |
|
7907 |
if (qgetenv("QT_NO_SSE").toInt()) |
|
7908 |
features ^= SSE; |
|
7909 |
if (qgetenv("QT_NO_SSE2").toInt()) |
|
7910 |
features ^= SSE2; |
|
7911 |
||
7912 |
return features; |
|
7913 |
#endif |
|
7914 |
} |
|
7915 |
||
7916 |
#if defined(Q_CC_RVCT) && defined(QT_HAVE_ARMV6) |
|
7917 |
// Move these to qdrawhelper_arm.c when all |
|
7918 |
// functions are implemented using arm assembly. |
|
7919 |
static CompositionFunctionSolid qt_functionForModeSolid_ARMv6[numCompositionFunctions] = { |
|
7920 |
comp_func_solid_SourceOver, |
|
7921 |
comp_func_solid_DestinationOver, |
|
7922 |
comp_func_solid_Clear, |
|
7923 |
comp_func_solid_Source, |
|
7924 |
comp_func_solid_Destination, |
|
7925 |
comp_func_solid_SourceIn, |
|
7926 |
comp_func_solid_DestinationIn, |
|
7927 |
comp_func_solid_SourceOut, |
|
7928 |
comp_func_solid_DestinationOut, |
|
7929 |
comp_func_solid_SourceAtop, |
|
7930 |
comp_func_solid_DestinationAtop, |
|
7931 |
comp_func_solid_XOR, |
|
7932 |
comp_func_solid_Plus, |
|
7933 |
comp_func_solid_Multiply, |
|
7934 |
comp_func_solid_Screen, |
|
7935 |
comp_func_solid_Overlay, |
|
7936 |
comp_func_solid_Darken, |
|
7937 |
comp_func_solid_Lighten, |
|
7938 |
comp_func_solid_ColorDodge, |
|
7939 |
comp_func_solid_ColorBurn, |
|
7940 |
comp_func_solid_HardLight, |
|
7941 |
comp_func_solid_SoftLight, |
|
7942 |
comp_func_solid_Difference, |
|
7943 |
comp_func_solid_Exclusion, |
|
7944 |
rasterop_solid_SourceOrDestination, |
|
7945 |
rasterop_solid_SourceAndDestination, |
|
7946 |
rasterop_solid_SourceXorDestination, |
|
7947 |
rasterop_solid_NotSourceAndNotDestination, |
|
7948 |
rasterop_solid_NotSourceOrNotDestination, |
|
7949 |
rasterop_solid_NotSourceXorDestination, |
|
7950 |
rasterop_solid_NotSource, |
|
7951 |
rasterop_solid_NotSourceAndDestination, |
|
7952 |
rasterop_solid_SourceAndNotDestination |
|
7953 |
}; |
|
7954 |
||
7955 |
static CompositionFunction qt_functionForMode_ARMv6[numCompositionFunctions] = { |
|
7956 |
comp_func_SourceOver_armv6, |
|
7957 |
comp_func_DestinationOver, |
|
7958 |
comp_func_Clear, |
|
7959 |
comp_func_Source_armv6, |
|
7960 |
comp_func_Destination, |
|
7961 |
comp_func_SourceIn, |
|
7962 |
comp_func_DestinationIn, |
|
7963 |
comp_func_SourceOut, |
|
7964 |
comp_func_DestinationOut, |
|
7965 |
comp_func_SourceAtop, |
|
7966 |
comp_func_DestinationAtop, |
|
7967 |
comp_func_XOR, |
|
7968 |
comp_func_Plus, |
|
7969 |
comp_func_Multiply, |
|
7970 |
comp_func_Screen, |
|
7971 |
comp_func_Overlay, |
|
7972 |
comp_func_Darken, |
|
7973 |
comp_func_Lighten, |
|
7974 |
comp_func_ColorDodge, |
|
7975 |
comp_func_ColorBurn, |
|
7976 |
comp_func_HardLight, |
|
7977 |
comp_func_SoftLight, |
|
7978 |
comp_func_Difference, |
|
7979 |
comp_func_Exclusion, |
|
7980 |
rasterop_SourceOrDestination, |
|
7981 |
rasterop_SourceAndDestination, |
|
7982 |
rasterop_SourceXorDestination, |
|
7983 |
rasterop_NotSourceAndNotDestination, |
|
7984 |
rasterop_NotSourceOrNotDestination, |
|
7985 |
rasterop_NotSourceXorDestination, |
|
7986 |
rasterop_NotSource, |
|
7987 |
rasterop_NotSourceAndDestination, |
|
7988 |
rasterop_SourceAndNotDestination |
|
7989 |
}; |
|
7990 |
||
7991 |
static void qt_blend_color_argb_armv6(int count, const QSpan *spans, void *userData) |
|
7992 |
{ |
|
7993 |
QSpanData *data = reinterpret_cast<QSpanData *>(userData); |
|
7994 |
||
7995 |
CompositionFunctionSolid func = qt_functionForModeSolid_ARMv6[data->rasterBuffer->compositionMode]; |
|
7996 |
while (count--) { |
|
7997 |
uint *target = ((uint *)data->rasterBuffer->scanLine(spans->y)) + spans->x; |
|
7998 |
func(target, spans->len, data->solid.color, spans->coverage); |
|
7999 |
++spans; |
|
8000 |
} |
|
8001 |
} |
|
8002 |
||
8003 |
#endif // Q_CC_RVCT && QT_HAVE_ARMV6 |
|
8004 |
||
8005 |
||
8006 |
void qInitDrawhelperAsm() |
|
8007 |
{ |
|
8008 |
static uint features = 0xffffffff; |
|
8009 |
if (features != 0xffffffff) |
|
8010 |
return; |
|
8011 |
features = detectCPUFeatures(); |
|
8012 |
||
8013 |
qt_memfill32 = qt_memfill_template<quint32, quint32>; |
|
8014 |
qt_memfill16 = qt_memfill_quint16; //qt_memfill_template<quint16, quint16>; |
|
8015 |
||
8016 |
CompositionFunction *functionForModeAsm = 0; |
|
8017 |
CompositionFunctionSolid *functionForModeSolidAsm = 0; |
|
8018 |
||
8019 |
#ifdef QT_NO_DEBUG |
|
8020 |
if (false) { |
|
8021 |
#ifdef QT_HAVE_SSE2 |
|
8022 |
} else if (features & SSE2) { |
|
8023 |
qt_memfill32 = qt_memfill32_sse2; |
|
8024 |
qt_memfill16 = qt_memfill16_sse2; |
|
8025 |
qDrawHelper[QImage::Format_RGB32].bitmapBlit = qt_bitmapblit32_sse2; |
|
8026 |
qDrawHelper[QImage::Format_ARGB32].bitmapBlit = qt_bitmapblit32_sse2; |
|
8027 |
qDrawHelper[QImage::Format_ARGB32_Premultiplied].bitmapBlit = qt_bitmapblit32_sse2; |
|
8028 |
qDrawHelper[QImage::Format_RGB16].bitmapBlit = qt_bitmapblit16_sse2; |
|
8029 |
#endif |
|
8030 |
#ifdef QT_HAVE_SSE |
|
8031 |
} else if (features & SSE) { |
|
8032 |
// qt_memfill32 = qt_memfill32_sse; |
|
8033 |
qDrawHelper[QImage::Format_RGB16].bitmapBlit = qt_bitmapblit16_sse; |
|
8034 |
#ifdef QT_HAVE_3DNOW |
|
8035 |
if (features & MMX3DNOW) { |
|
8036 |
qt_memfill32 = qt_memfill32_sse3dnow; |
|
8037 |
qDrawHelper[QImage::Format_RGB16].bitmapBlit = qt_bitmapblit16_sse3dnow; |
|
8038 |
} |
|
8039 |
#endif |
|
8040 |
#endif // SSE |
|
8041 |
#if defined(QT_HAVE_MMXEXT) && defined(QT_HAVE_SSE) |
|
8042 |
} else if (features & MMXEXT) { |
|
8043 |
qt_memfill32 = qt_memfill32_sse; |
|
8044 |
qDrawHelper[QImage::Format_RGB16].bitmapBlit = qt_bitmapblit16_sse; |
|
8045 |
# ifdef QT_HAVE_3DNOW |
|
8046 |
if (features & MMX3DNOW) { |
|
8047 |
qt_memfill32 = qt_memfill32_sse3dnow; |
|
8048 |
qDrawHelper[QImage::Format_RGB16].bitmapBlit = qt_bitmapblit16_sse3dnow; |
|
8049 |
} |
|
8050 |
# endif // 3DNOW |
|
8051 |
#endif // MMXEXT |
|
8052 |
} |
|
8053 |
#ifdef QT_HAVE_MMX |
|
8054 |
if (features & MMX) { |
|
8055 |
functionForModeAsm = qt_functionForMode_MMX; |
|
8056 |
functionForModeSolidAsm = qt_functionForModeSolid_MMX; |
|
8057 |
qDrawHelper[QImage::Format_ARGB32_Premultiplied].blendColor = qt_blend_color_argb_mmx; |
|
8058 |
#ifdef QT_HAVE_3DNOW |
|
8059 |
if (features & MMX3DNOW) { |
|
8060 |
functionForModeAsm = qt_functionForMode_MMX3DNOW; |
|
8061 |
functionForModeSolidAsm = qt_functionForModeSolid_MMX3DNOW; |
|
8062 |
qDrawHelper[QImage::Format_ARGB32_Premultiplied].blendColor = qt_blend_color_argb_mmx3dnow; |
|
8063 |
} |
|
8064 |
#endif // 3DNOW |
|
8065 |
||
8066 |
extern void qt_blend_rgb32_on_rgb32_mmx(uchar *destPixels, int dbpl, |
|
8067 |
const uchar *srcPixels, int sbpl, |
|
8068 |
int w, int h, |
|
8069 |
int const_alpha); |
|
8070 |
extern void qt_blend_argb32_on_argb32_mmx(uchar *destPixels, int dbpl, |
|
8071 |
const uchar *srcPixels, int sbpl, |
|
8072 |
int w, int h, |
|
8073 |
int const_alpha); |
|
8074 |
||
8075 |
qBlendFunctions[QImage::Format_RGB32][QImage::Format_RGB32] = qt_blend_rgb32_on_rgb32_mmx; |
|
8076 |
qBlendFunctions[QImage::Format_ARGB32_Premultiplied][QImage::Format_RGB32] = qt_blend_rgb32_on_rgb32_mmx; |
|
8077 |
qBlendFunctions[QImage::Format_RGB32][QImage::Format_ARGB32_Premultiplied] = qt_blend_argb32_on_argb32_mmx; |
|
8078 |
qBlendFunctions[QImage::Format_ARGB32_Premultiplied][QImage::Format_ARGB32_Premultiplied] = qt_blend_argb32_on_argb32_mmx; |
|
8079 |
||
8080 |
} |
|
8081 |
#endif // MMX |
|
8082 |
||
8083 |
#ifdef QT_HAVE_SSE |
|
8084 |
if (features & SSE) { |
|
8085 |
functionForModeAsm = qt_functionForMode_SSE; |
|
8086 |
functionForModeSolidAsm = qt_functionForModeSolid_SSE; |
|
8087 |
qDrawHelper[QImage::Format_ARGB32_Premultiplied].blendColor = qt_blend_color_argb_sse; |
|
8088 |
#ifdef QT_HAVE_3DNOW |
|
8089 |
if (features & MMX3DNOW) { |
|
8090 |
functionForModeAsm = qt_functionForMode_SSE3DNOW; |
|
8091 |
functionForModeSolidAsm = qt_functionForModeSolid_SSE3DNOW; |
|
8092 |
qDrawHelper[QImage::Format_ARGB32_Premultiplied].blendColor = qt_blend_color_argb_sse3dnow; |
|
8093 |
} |
|
8094 |
#endif // 3DNOW |
|
7
f7bc934e204c
5cabc75a39ca2f064f70b40f72ed93c74c4dc19b
eckhart.koppen@nokia.com
parents:
3
diff
changeset
|
8095 |
|
f7bc934e204c
5cabc75a39ca2f064f70b40f72ed93c74c4dc19b
eckhart.koppen@nokia.com
parents:
3
diff
changeset
|
8096 |
|
f7bc934e204c
5cabc75a39ca2f064f70b40f72ed93c74c4dc19b
eckhart.koppen@nokia.com
parents:
3
diff
changeset
|
8097 |
#ifdef QT_HAVE_SSE2 |
f7bc934e204c
5cabc75a39ca2f064f70b40f72ed93c74c4dc19b
eckhart.koppen@nokia.com
parents:
3
diff
changeset
|
8098 |
if (features & SSE2) { |
f7bc934e204c
5cabc75a39ca2f064f70b40f72ed93c74c4dc19b
eckhart.koppen@nokia.com
parents:
3
diff
changeset
|
8099 |
extern void qt_blend_rgb32_on_rgb32_sse2(uchar *destPixels, int dbpl, |
f7bc934e204c
5cabc75a39ca2f064f70b40f72ed93c74c4dc19b
eckhart.koppen@nokia.com
parents:
3
diff
changeset
|
8100 |
const uchar *srcPixels, int sbpl, |
f7bc934e204c
5cabc75a39ca2f064f70b40f72ed93c74c4dc19b
eckhart.koppen@nokia.com
parents:
3
diff
changeset
|
8101 |
int w, int h, |
f7bc934e204c
5cabc75a39ca2f064f70b40f72ed93c74c4dc19b
eckhart.koppen@nokia.com
parents:
3
diff
changeset
|
8102 |
int const_alpha); |
f7bc934e204c
5cabc75a39ca2f064f70b40f72ed93c74c4dc19b
eckhart.koppen@nokia.com
parents:
3
diff
changeset
|
8103 |
extern void qt_blend_argb32_on_argb32_sse2(uchar *destPixels, int dbpl, |
f7bc934e204c
5cabc75a39ca2f064f70b40f72ed93c74c4dc19b
eckhart.koppen@nokia.com
parents:
3
diff
changeset
|
8104 |
const uchar *srcPixels, int sbpl, |
f7bc934e204c
5cabc75a39ca2f064f70b40f72ed93c74c4dc19b
eckhart.koppen@nokia.com
parents:
3
diff
changeset
|
8105 |
int w, int h, |
f7bc934e204c
5cabc75a39ca2f064f70b40f72ed93c74c4dc19b
eckhart.koppen@nokia.com
parents:
3
diff
changeset
|
8106 |
int const_alpha); |
f7bc934e204c
5cabc75a39ca2f064f70b40f72ed93c74c4dc19b
eckhart.koppen@nokia.com
parents:
3
diff
changeset
|
8107 |
|
f7bc934e204c
5cabc75a39ca2f064f70b40f72ed93c74c4dc19b
eckhart.koppen@nokia.com
parents:
3
diff
changeset
|
8108 |
|
f7bc934e204c
5cabc75a39ca2f064f70b40f72ed93c74c4dc19b
eckhart.koppen@nokia.com
parents:
3
diff
changeset
|
8109 |
qBlendFunctions[QImage::Format_RGB32][QImage::Format_RGB32] = qt_blend_rgb32_on_rgb32_sse2; |
f7bc934e204c
5cabc75a39ca2f064f70b40f72ed93c74c4dc19b
eckhart.koppen@nokia.com
parents:
3
diff
changeset
|
8110 |
qBlendFunctions[QImage::Format_ARGB32_Premultiplied][QImage::Format_RGB32] = qt_blend_rgb32_on_rgb32_sse2; |
f7bc934e204c
5cabc75a39ca2f064f70b40f72ed93c74c4dc19b
eckhart.koppen@nokia.com
parents:
3
diff
changeset
|
8111 |
qBlendFunctions[QImage::Format_RGB32][QImage::Format_ARGB32_Premultiplied] = qt_blend_argb32_on_argb32_sse2; |
f7bc934e204c
5cabc75a39ca2f064f70b40f72ed93c74c4dc19b
eckhart.koppen@nokia.com
parents:
3
diff
changeset
|
8112 |
qBlendFunctions[QImage::Format_ARGB32_Premultiplied][QImage::Format_ARGB32_Premultiplied] = qt_blend_argb32_on_argb32_sse2; |
f7bc934e204c
5cabc75a39ca2f064f70b40f72ed93c74c4dc19b
eckhart.koppen@nokia.com
parents:
3
diff
changeset
|
8113 |
} else |
f7bc934e204c
5cabc75a39ca2f064f70b40f72ed93c74c4dc19b
eckhart.koppen@nokia.com
parents:
3
diff
changeset
|
8114 |
#endif |
f7bc934e204c
5cabc75a39ca2f064f70b40f72ed93c74c4dc19b
eckhart.koppen@nokia.com
parents:
3
diff
changeset
|
8115 |
{ |
f7bc934e204c
5cabc75a39ca2f064f70b40f72ed93c74c4dc19b
eckhart.koppen@nokia.com
parents:
3
diff
changeset
|
8116 |
extern void qt_blend_rgb32_on_rgb32_sse(uchar *destPixels, int dbpl, |
f7bc934e204c
5cabc75a39ca2f064f70b40f72ed93c74c4dc19b
eckhart.koppen@nokia.com
parents:
3
diff
changeset
|
8117 |
const uchar *srcPixels, int sbpl, |
f7bc934e204c
5cabc75a39ca2f064f70b40f72ed93c74c4dc19b
eckhart.koppen@nokia.com
parents:
3
diff
changeset
|
8118 |
int w, int h, |
f7bc934e204c
5cabc75a39ca2f064f70b40f72ed93c74c4dc19b
eckhart.koppen@nokia.com
parents:
3
diff
changeset
|
8119 |
int const_alpha); |
f7bc934e204c
5cabc75a39ca2f064f70b40f72ed93c74c4dc19b
eckhart.koppen@nokia.com
parents:
3
diff
changeset
|
8120 |
extern void qt_blend_argb32_on_argb32_sse(uchar *destPixels, int dbpl, |
f7bc934e204c
5cabc75a39ca2f064f70b40f72ed93c74c4dc19b
eckhart.koppen@nokia.com
parents:
3
diff
changeset
|
8121 |
const uchar *srcPixels, int sbpl, |
f7bc934e204c
5cabc75a39ca2f064f70b40f72ed93c74c4dc19b
eckhart.koppen@nokia.com
parents:
3
diff
changeset
|
8122 |
int w, int h, |
f7bc934e204c
5cabc75a39ca2f064f70b40f72ed93c74c4dc19b
eckhart.koppen@nokia.com
parents:
3
diff
changeset
|
8123 |
int const_alpha); |
f7bc934e204c
5cabc75a39ca2f064f70b40f72ed93c74c4dc19b
eckhart.koppen@nokia.com
parents:
3
diff
changeset
|
8124 |
|
f7bc934e204c
5cabc75a39ca2f064f70b40f72ed93c74c4dc19b
eckhart.koppen@nokia.com
parents:
3
diff
changeset
|
8125 |
|
f7bc934e204c
5cabc75a39ca2f064f70b40f72ed93c74c4dc19b
eckhart.koppen@nokia.com
parents:
3
diff
changeset
|
8126 |
qBlendFunctions[QImage::Format_RGB32][QImage::Format_RGB32] = qt_blend_rgb32_on_rgb32_sse; |
f7bc934e204c
5cabc75a39ca2f064f70b40f72ed93c74c4dc19b
eckhart.koppen@nokia.com
parents:
3
diff
changeset
|
8127 |
qBlendFunctions[QImage::Format_ARGB32_Premultiplied][QImage::Format_RGB32] = qt_blend_rgb32_on_rgb32_sse; |
f7bc934e204c
5cabc75a39ca2f064f70b40f72ed93c74c4dc19b
eckhart.koppen@nokia.com
parents:
3
diff
changeset
|
8128 |
qBlendFunctions[QImage::Format_RGB32][QImage::Format_ARGB32_Premultiplied] = qt_blend_argb32_on_argb32_sse; |
f7bc934e204c
5cabc75a39ca2f064f70b40f72ed93c74c4dc19b
eckhart.koppen@nokia.com
parents:
3
diff
changeset
|
8129 |
qBlendFunctions[QImage::Format_ARGB32_Premultiplied][QImage::Format_ARGB32_Premultiplied] = qt_blend_argb32_on_argb32_sse; |
f7bc934e204c
5cabc75a39ca2f064f70b40f72ed93c74c4dc19b
eckhart.koppen@nokia.com
parents:
3
diff
changeset
|
8130 |
} |
f7bc934e204c
5cabc75a39ca2f064f70b40f72ed93c74c4dc19b
eckhart.koppen@nokia.com
parents:
3
diff
changeset
|
8131 |
} |
0 | 8132 |
#endif // SSE |
8133 |
||
8134 |
#ifdef QT_HAVE_IWMMXT |
|
8135 |
if (features & IWMMXT) { |
|
8136 |
functionForModeAsm = qt_functionForMode_IWMMXT; |
|
8137 |
functionForModeSolidAsm = qt_functionForModeSolid_IWMMXT; |
|
8138 |
qDrawHelper[QImage::Format_ARGB32_Premultiplied].blendColor = qt_blend_color_argb_iwmmxt; |
|
8139 |
} |
|
8140 |
#endif // IWMMXT |
|
8141 |
||
8142 |
#endif // QT_NO_DEBUG |
|
8143 |
||
8144 |
#if defined(Q_CC_RVCT) && defined(QT_HAVE_ARMV6) |
|
8145 |
functionForModeAsm = qt_functionForMode_ARMv6; |
|
8146 |
functionForModeSolidAsm = qt_functionForModeSolid_ARMv6; |
|
8147 |
||
8148 |
qt_memfill32 = qt_memfill32_armv6; |
|
8149 |
||
8150 |
qDrawHelper[QImage::Format_ARGB32_Premultiplied].blendColor = qt_blend_color_argb_armv6; |
|
8151 |
||
8152 |
qBlendFunctions[QImage::Format_RGB32][QImage::Format_RGB32] = qt_blend_rgb32_on_rgb32_armv6; |
|
8153 |
qBlendFunctions[QImage::Format_ARGB32_Premultiplied][QImage::Format_RGB32] = qt_blend_rgb32_on_rgb32_armv6; |
|
8154 |
qBlendFunctions[QImage::Format_RGB32][QImage::Format_ARGB32_Premultiplied] = qt_blend_argb32_on_argb32_armv6; |
|
8155 |
qBlendFunctions[QImage::Format_ARGB32_Premultiplied][QImage::Format_ARGB32_Premultiplied] = qt_blend_argb32_on_argb32_armv6; |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
8156 |
#elif defined(QT_HAVE_NEON) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
8157 |
if (features & NEON) { |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
8158 |
qBlendFunctions[QImage::Format_RGB32][QImage::Format_RGB32] = qt_blend_rgb32_on_rgb32_neon; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
8159 |
qBlendFunctions[QImage::Format_ARGB32_Premultiplied][QImage::Format_RGB32] = qt_blend_rgb32_on_rgb32_neon; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
8160 |
qBlendFunctions[QImage::Format_RGB32][QImage::Format_ARGB32_Premultiplied] = qt_blend_argb32_on_argb32_neon; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
8161 |
qBlendFunctions[QImage::Format_ARGB32_Premultiplied][QImage::Format_ARGB32_Premultiplied] = qt_blend_argb32_on_argb32_neon; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
8162 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
8163 |
#endif |
0 | 8164 |
|
8165 |
if (functionForModeSolidAsm) { |
|
8166 |
const int destinationMode = QPainter::CompositionMode_Destination; |
|
8167 |
functionForModeSolidAsm[destinationMode] = functionForModeSolid_C[destinationMode]; |
|
8168 |
||
8169 |
// use the default qdrawhelper implementation for the |
|
8170 |
// extended composition modes |
|
8171 |
for (int mode = 12; mode < 24; ++mode) |
|
8172 |
functionForModeSolidAsm[mode] = functionForModeSolid_C[mode]; |
|
8173 |
||
8174 |
functionForModeSolid = functionForModeSolidAsm; |
|
8175 |
} |
|
8176 |
if (functionForModeAsm) { |
|
8177 |
const int destinationMode = QPainter::CompositionMode_Destination; |
|
8178 |
functionForModeAsm[destinationMode] = functionForMode_C[destinationMode]; |
|
8179 |
||
8180 |
// use the default qdrawhelper implementation for the |
|
8181 |
// extended composition modes |
|
8182 |
for (int mode = 12; mode < numCompositionFunctions; ++mode) |
|
8183 |
functionForModeAsm[mode] = functionForMode_C[mode]; |
|
8184 |
||
8185 |
functionForMode = functionForModeAsm; |
|
8186 |
} |
|
8187 |
||
8188 |
qt_build_pow_tables(); |
|
8189 |
} |
|
8190 |
||
8191 |
static void qt_memfill32_setup(quint32 *dest, quint32 value, int count) |
|
8192 |
{ |
|
8193 |
qInitDrawhelperAsm(); |
|
8194 |
qt_memfill32(dest, value, count); |
|
8195 |
} |
|
8196 |
||
8197 |
static void qt_memfill16_setup(quint16 *dest, quint16 value, int count) |
|
8198 |
{ |
|
8199 |
qInitDrawhelperAsm(); |
|
8200 |
qt_memfill16(dest, value, count); |
|
8201 |
} |
|
8202 |
||
8203 |
#ifdef QT_QWS_DEPTH_GENERIC |
|
8204 |
||
8205 |
int qrgb::bpp = 0; |
|
8206 |
int qrgb::len_red = 0; |
|
8207 |
int qrgb::len_green = 0; |
|
8208 |
int qrgb::len_blue = 0; |
|
8209 |
int qrgb::len_alpha = 0; |
|
8210 |
int qrgb::off_red = 0; |
|
8211 |
int qrgb::off_green = 0; |
|
8212 |
int qrgb::off_blue = 0; |
|
8213 |
int qrgb::off_alpha = 0; |
|
8214 |
||
8215 |
template <typename SRC> |
|
8216 |
Q_STATIC_TEMPLATE_FUNCTION inline void qt_rectconvert_rgb(qrgb *dest, const SRC *src, |
|
8217 |
int x, int y, int width, int height, |
|
8218 |
int dstStride, int srcStride) |
|
8219 |
{ |
|
8220 |
quint8 *dest8 = reinterpret_cast<quint8*>(dest) |
|
8221 |
+ y * dstStride + x * qrgb::bpp; |
|
8222 |
||
8223 |
srcStride = srcStride / sizeof(SRC) - width; |
|
8224 |
dstStride -= (width * qrgb::bpp); |
|
8225 |
||
8226 |
for (int j = 0; j < height; ++j) { |
|
8227 |
for (int i = 0; i < width; ++i) { |
|
8228 |
const quint32 v = qt_convertToRgb<SRC>(*src++); |
|
8229 |
#if Q_BYTE_ORDER == Q_BIG_ENDIAN |
|
8230 |
for (int j = qrgb::bpp - 1; j >= 0; --j) |
|
8231 |
*dest8++ = (v >> (8 * j)) & 0xff; |
|
8232 |
#else |
|
8233 |
for (int j = 0; j < qrgb::bpp; ++j) |
|
8234 |
*dest8++ = (v >> (8 * j)) & 0xff; |
|
8235 |
#endif |
|
8236 |
} |
|
8237 |
||
8238 |
dest8 += dstStride; |
|
8239 |
src += srcStride; |
|
8240 |
} |
|
8241 |
} |
|
8242 |
||
8243 |
template <> |
|
8244 |
void qt_rectconvert(qrgb *dest, const quint32 *src, |
|
8245 |
int x, int y, int width, int height, |
|
8246 |
int dstStride, int srcStride) |
|
8247 |
{ |
|
8248 |
qt_rectconvert_rgb<quint32>(dest, src, x, y, width, height, |
|
8249 |
dstStride, srcStride); |
|
8250 |
} |
|
8251 |
||
8252 |
template <> |
|
8253 |
void qt_rectconvert(qrgb *dest, const quint16 *src, |
|
8254 |
int x, int y, int width, int height, |
|
8255 |
int dstStride, int srcStride) |
|
8256 |
{ |
|
8257 |
qt_rectconvert_rgb<quint16>(dest, src, x, y, width, height, |
|
8258 |
dstStride, srcStride); |
|
8259 |
} |
|
8260 |
||
8261 |
#endif // QT_QWS_DEPTH_GENERIC |
|
8262 |
||
8263 |
QT_END_NAMESPACE |