Make QRegion not need to be friends with QVector
[profile/ivi/qtbase.git] / src / gui / painting / qdrawhelper_mips_dsp.cpp
1 /****************************************************************************
2 **
3 ** Copyright (C) 2012 MIPS Technologies, www.mips.com, author Damir Tatalovic <dtatalovic@mips.com>
4 ** Contact: http://www.qt-project.org/
5 **
6 ** This file is part of the QtGui module of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** GNU Lesser General Public License Usage
10 ** This file may be used under the terms of the GNU Lesser General Public
11 ** License version 2.1 as published by the Free Software Foundation and
12 ** appearing in the file LICENSE.LGPL included in the packaging of this
13 ** file. Please review the following information to ensure the GNU Lesser
14 ** General Public License version 2.1 requirements will be met:
15 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
16 **
17 ** In addition, as a special exception, Nokia gives you certain additional
18 ** rights. These rights are described in the Nokia Qt LGPL Exception
19 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
20 **
21 ** GNU General Public License Usage
22 ** Alternatively, this file may be used under the terms of the GNU General
23 ** Public License version 3.0 as published by the Free Software Foundation
24 ** and appearing in the file LICENSE.GPL included in the packaging of this
25 ** file. Please review the following information to ensure the GNU General
26 ** Public License version 3.0 requirements will be met:
27 ** http://www.gnu.org/copyleft/gpl.html.
28 **
29 ** Other Usage
30 ** Alternatively, this file may be used in accordance with the terms and
31 ** conditions contained in a signed written agreement between you and Nokia.
32 **
33 **
34 **
35 **
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41
42 #include <private/qdrawhelper_p.h>
43 #include <private/qdrawhelper_mips_dsp_p.h>
44 #include <private/qpaintengine_raster_p.h>
45
46 QT_BEGIN_NAMESPACE
47
48 #if defined(QT_COMPILER_SUPPORTS_MIPS_DSP)
49
50 extern "C" uint INTERPOLATE_PIXEL_255_asm_mips_dsp(uint x, uint a, uint y, uint b);
51
52 extern "C"  uint BYTE_MUL_asm_mips_dsp(uint x, uint a);
53
54 extern "C" uint * destfetchARGB32_asm_mips_dsp(uint *buffer, const uint *data, int length);
55
56 extern "C" uint * qt_destStoreARGB32_asm_mips_dsp(uint *buffer, const uint *data, int length);
57
58 #if defined(QT_COMPILER_SUPPORTS_MIPS_DSPR2)
59
60 extern "C" uint INTERPOLATE_PIXEL_255_asm_mips_dspr2(uint x, uint a, uint y, uint b);
61
62 extern "C" uint BYTE_MUL_asm_mips_dspr2(uint x, uint a);
63
64 #endif // QT_COMPILER_SUPPORTS_MIPS_DSPR2
65
66 void qt_blend_argb32_on_argb32_mips_dsp(uchar *destPixels, int dbpl,
67                                       const uchar *srcPixels, int sbpl,
68                                       int w, int h,
69                                       int const_alpha)
70
71 {
72 #ifdef QT_DEBUG_DRAW
73     fprintf(stdout,
74             "qt_blend_argb32_on_argb32: dst=(%p, %d), src=(%p, %d), dim=(%d, %d) alpha=%d\n",
75             destPixels, dbpl, srcPixels, sbpl, w, h, const_alpha);
76     fflush(stdout);
77 #endif
78
79     const uint *src = (const uint *) srcPixels;
80     uint *dst = (uint *) destPixels;
81     if (const_alpha == 256) {
82         for (int y=0; y<h; ++y) {
83             for (int x=0; x<w; ++x) {
84                 uint s = src[x];
85                 if (s >= 0xff000000)
86                     dst[x] = s;
87                 else if (s != 0)
88 #if !defined(QT_COMPILER_SUPPORTS_MIPS_DSPR2)
89                     dst[x] = s + BYTE_MUL_asm_mips_dsp(dst[x], qAlpha(~s));
90 #else
91                     dst[x] = s + BYTE_MUL_asm_mips_dspr2(dst[x], qAlpha(~s));
92 #endif
93             }
94             dst = (quint32 *)(((uchar *) dst) + dbpl);
95             src = (const quint32 *)(((const uchar *) src) + sbpl);
96         }
97     } else if (const_alpha != 0) {
98         const_alpha = (const_alpha * 255) >> 8;
99         for (int y=0; y<h; ++y) {
100             for (int x=0; x<w; ++x) {
101 #if !defined(QT_COMPILER_SUPPORTS_MIPS_DSPR2)
102                 uint s = BYTE_MUL_asm_mips_dsp(src[x], const_alpha);
103                 dst[x] = s + BYTE_MUL_asm_mips_dsp(dst[x], qAlpha(~s));
104 #else
105                 uint s = BYTE_MUL_asm_mips_dspr2(src[x], const_alpha);
106                 dst[x] = s + BYTE_MUL_asm_mips_dspr2(dst[x], qAlpha(~s));
107 #endif
108             }
109             dst = (quint32 *)(((uchar *) dst) + dbpl);
110             src = (const quint32 *)(((const uchar *) src) + sbpl);
111         }
112     }
113 }
114
115 void qt_blend_rgb32_on_rgb32_mips_dsp(uchar *destPixels, int dbpl,
116                                     const uchar *srcPixels, int sbpl,
117                                     int w, int h,
118                                     int const_alpha)
119 {
120 #ifdef QT_DEBUG_DRAW
121     fprintf(stdout,
122             "qt_blend_rgb32_on_rgb32: dst=(%p, %d), src=(%p, %d), dim=(%d, %d) alpha=%d\n",
123             destPixels, dbpl, srcPixels, sbpl, w, h, const_alpha);
124     fflush(stdout);
125 #endif
126
127     if (const_alpha != 256) {
128         qt_blend_argb32_on_argb32_mips_dsp(destPixels, dbpl, srcPixels, sbpl, w, h, const_alpha);
129         return;
130     }
131
132     const uint *src = (const uint *) srcPixels;
133     uint *dst = (uint *) destPixels;
134     int len = w * 4;
135     for (int y=0; y<h; ++y) {
136         memcpy(dst, src, len);
137         dst = (quint32 *)(((uchar *) dst) + dbpl);
138         src = (const quint32 *)(((const uchar *) src) + sbpl);
139     }
140 }
141
142 void comp_func_Source_mips_dsp(uint *dest, const uint *src, int length, uint const_alpha)
143 {
144     if (const_alpha == 255) {
145         ::memcpy(dest, src, length * sizeof(uint));
146     } else {
147         int ialpha = 255 - const_alpha;
148         for (int i = 0; i < length; ++i) {
149 #if !defined(QT_COMPILER_SUPPORTS_MIPS_DSPR2)
150             dest[i] = INTERPOLATE_PIXEL_255_asm_mips_dsp(src[i], const_alpha, dest[i], ialpha);
151 #else
152             dest[i] = INTERPOLATE_PIXEL_255_asm_mips_dspr2(src[i], const_alpha, dest[i], ialpha);
153 #endif
154         }
155     }
156 }
157
158 uint * QT_FASTCALL qt_destFetchARGB32_mips_dsp(uint *buffer,
159                                           QRasterBuffer *rasterBuffer,
160                                           int x, int y, int length)
161 {
162     const uint *data = (const uint *)rasterBuffer->scanLine(y) + x;
163     buffer = destfetchARGB32_asm_mips_dsp(buffer, data, length);
164     return buffer;
165 }
166
167 void QT_FASTCALL qt_destStoreARGB32_mips_dsp(QRasterBuffer *rasterBuffer, int x, int y,
168                                              const uint *buffer, int length)
169 {
170     uint *data = (uint *)rasterBuffer->scanLine(y) + x;
171     qt_destStoreARGB32_asm_mips_dsp(data, buffer, length);
172 }
173
174 #endif // QT_COMPILER_SUPPORTS_MIPS_DSP
175
176 QT_END_NAMESPACE