~oif-team/ubuntu/natty/qt4-x11/xi2.1

« back to all changes in this revision

Viewing changes to src/gui/painting/qdrawhelper_p.h

  • Committer: Bazaar Package Importer
  • Author(s): Adam Conrad
  • Date: 2005-08-24 04:09:09 UTC
  • Revision ID: james.westby@ubuntu.com-20050824040909-xmxe9jfr4a0w5671
Tags: upstream-4.0.0
ImportĀ upstreamĀ versionĀ 4.0.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#ifndef QDRAWHELPER_H
 
2
#define QDRAWHELPER_H
 
3
 
 
4
#include <qglobal.h>
 
5
#include <qcolor.h>
 
6
#include <qpainter.h>
 
7
 
 
8
/*******************************************************************************
 
9
 * QSpan
 
10
 *
 
11
 * duplicate definition of FT_Span
 
12
 */
 
13
struct QSpan
 
14
{
 
15
    short x;
 
16
    ushort len;
 
17
    uchar coverage;
 
18
};
 
19
 
 
20
struct GradientData;
 
21
struct LinearGradientData;
 
22
struct RadialGradientData;
 
23
struct ConicalGradientData;
 
24
extern uint qt_gradient_pixel(const GradientData *data, double pos);
 
25
 
 
26
struct BlendColorData {
 
27
    int y;
 
28
    uint color;
 
29
};
 
30
 
 
31
typedef void (*BlendColor)(void *target, const QSpan *span, QPainter::CompositionMode mode, const BlendColorData *data);
 
32
 
 
33
typedef void (*Blend)(void *target, const QSpan *span,
 
34
                      const qreal dx, const qreal dy,
 
35
                      const void *image_bits, const int image_width, const int image_height,
 
36
                      QPainter::CompositionMode mode);
 
37
 
 
38
typedef void (*BlendTransformed)(void *target, const QSpan *span,
 
39
                                 const qreal ix, const qreal iy,
 
40
                                 const qreal dx, const qreal dy,
 
41
                                 const void *image_bits,
 
42
                                 const int image_width, const int image_height,
 
43
                                 QPainter::CompositionMode mode);
 
44
 
 
45
typedef void (*BlendLinearGradient)(void *target,
 
46
                                    const QSpan *span,
 
47
                                    LinearGradientData *data,
 
48
                                    qreal ybase, int y,
 
49
                                    QPainter::CompositionMode mode);
 
50
 
 
51
typedef void (*BlendRadialGradient)(void *target,
 
52
                                    const QSpan *span,
 
53
                                    RadialGradientData *data,
 
54
                                    int y,
 
55
                                    QPainter::CompositionMode mode);
 
56
 
 
57
typedef void (*BlendConicalGradient)(void *target,
 
58
                                     const QSpan *span,
 
59
                                     ConicalGradientData *data,
 
60
                                     int y,
 
61
                                     QPainter::CompositionMode mode);
 
62
 
 
63
struct DrawHelper {
 
64
    enum Layout {
 
65
        Layout_ARGB,
 
66
        Layout_RGB32,
 
67
        Layout_Mono,
 
68
        Layout_MonoLSB,
 
69
        Layout_Count
 
70
    };
 
71
    BlendColor blendColor;
 
72
    Blend blend;
 
73
    Blend blendTiled;
 
74
    BlendTransformed blendTransformed;
 
75
    BlendTransformed blendTransformedTiled;
 
76
    BlendTransformed blendTransformedBilinear;
 
77
    BlendTransformed blendTransformedBilinearTiled;
 
78
    BlendLinearGradient blendLinearGradient;
 
79
    BlendRadialGradient blendRadialGradient;
 
80
    BlendConicalGradient blendConicalGradient;
 
81
};
 
82
 
 
83
extern DrawHelper qDrawHelper[DrawHelper::Layout_Count];
 
84
 
 
85
void qInitDrawhelperAsm();
 
86
 
 
87
class QRasterBuffer;
 
88
 
 
89
struct GradientData
 
90
{
 
91
    QRasterBuffer *rasterBuffer;
 
92
    QGradient::Spread spread;
 
93
 
 
94
    int stopCount;
 
95
    qreal *stopPoints;
 
96
    uint *stopColors;
 
97
 
 
98
#define GRADIENT_STOPTABLE_SIZE 1024
 
99
    uint colorTable[GRADIENT_STOPTABLE_SIZE];
 
100
 
 
101
    uint alphaColor : 1;
 
102
 
 
103
    void initColorTable();
 
104
};
 
105
 
 
106
struct LinearGradientData : public GradientData
 
107
{
 
108
    QPointF origin;
 
109
    QPointF end;
 
110
 
 
111
    void init();
 
112
 
 
113
    qreal xincr;
 
114
    qreal yincr;
 
115
    BlendLinearGradient blendFunc;
 
116
 
 
117
    QPainter::CompositionMode compositionMode;
 
118
    QMatrix brushMatrix;
 
119
};
 
120
 
 
121
struct RadialGradientData : public GradientData
 
122
{
 
123
    QPointF center;
 
124
    qreal radius;
 
125
    QPointF focal;
 
126
 
 
127
    BlendRadialGradient blendFunc;
 
128
    QPainter::CompositionMode compositionMode;
 
129
    QMatrix imatrix;
 
130
};
 
131
 
 
132
struct ConicalGradientData : public GradientData
 
133
{
 
134
    QPointF center;
 
135
    qreal angle;
 
136
    QMatrix imatrix;
 
137
    void init(const QPointF &center, qreal angle, const QMatrix &matrix);
 
138
    BlendConicalGradient blendFunc;
 
139
    QPainter::CompositionMode compositionMode;
 
140
};
 
141
 
 
142
 
 
143
inline int qt_div_255(int x) { return (x + (x>>8) + 0x80) >> 8; }
 
144
 
 
145
 
 
146
#if 1
 
147
inline uint INTERPOLATE_PIXEL_256(uint x, uint a, uint y, uint b) {
 
148
    uint t = (x & 0xff00ff) * a + (y & 0xff00ff) * b;
 
149
    t >>= 8;
 
150
    t &= 0xff00ff;
 
151
 
 
152
    x = ((x >> 8) & 0xff00ff) * a + ((y >> 8) & 0xff00ff) * b;
 
153
    x &= 0xff00ff00;
 
154
    x |= t;
 
155
    return x;
 
156
}
 
157
 
 
158
inline uint INTERPOLATE_PIXEL_255(uint x, uint a, uint y, uint b) {
 
159
    uint t = (x & 0xff00ff) * a + (y & 0xff00ff) * b;
 
160
    t = (t + ((t >> 8) & 0xff00ff) + 0x800080) >> 8;
 
161
    t &= 0xff00ff;
 
162
 
 
163
    x = ((x >> 8) & 0xff00ff) * a + ((y >> 8) & 0xff00ff) * b;
 
164
    x = (x + ((x >> 8) & 0xff00ff) + 0x800080);
 
165
    x &= 0xff00ff00;
 
166
    x |= t;
 
167
    return x;
 
168
}
 
169
 
 
170
inline uint BYTE_MUL(uint x, uint a) {
 
171
    uint t = (x & 0xff00ff) * a;
 
172
    t = (t + ((t >> 8) & 0xff00ff) + 0x800080) >> 8;
 
173
    t &= 0xff00ff;
 
174
 
 
175
    x = ((x >> 8) & 0xff00ff) * a;
 
176
    x = (x + ((x >> 8) & 0xff00ff) + 0x800080);
 
177
    x &= 0xff00ff00;
 
178
    x |= t;
 
179
    return x;
 
180
}
 
181
 
 
182
inline uint PREMUL(uint x) {
 
183
    uint a = x >> 24;
 
184
    uint t = (x & 0xff00ff) * a;
 
185
    t = (t + ((t >> 8) & 0xff00ff) + 0x800080) >> 8;
 
186
    t &= 0xff00ff;
 
187
 
 
188
    x = ((x >> 8) & 0xff) * a;
 
189
    x = (x + ((x >> 8) & 0xff) + 0x80);
 
190
    x &= 0xff00;
 
191
    x |= t | (a << 24);
 
192
    return x;
 
193
}
 
194
#else
 
195
// possible implementation for 64 bit
 
196
inline uint INTERPOLATE_PIXEL_256(uint x, uint a, uint y, uint b) {
 
197
    ulong t = (((ulong(x)) | ((ulong(x)) << 24)) & 0x00ff00ff00ff00ff) * a;
 
198
    t += (((ulong(y)) | ((ulong(y)) << 24)) & 0x00ff00ff00ff00ff) * b;
 
199
    t >>= 8;
 
200
    t &= 0x00ff00ff00ff00ff;
 
201
    return (uint(t)) | (uint(t >> 24));
 
202
}
 
203
 
 
204
inline uint INTERPOLATE_PIXEL_255(uint x, uint a, uint y, uint b) {
 
205
    ulong t = (((ulong(x)) | ((ulong(x)) << 24)) & 0x00ff00ff00ff00ff) * a;
 
206
    t += (((ulong(y)) | ((ulong(y)) << 24)) & 0x00ff00ff00ff00ff) * b;
 
207
    t = (t + ((t >> 8) & 0xff00ff00ff00ff) + 0x80008000800080);
 
208
    t &= 0x00ff00ff00ff00ff;
 
209
    return (uint(t)) | (uint(t >> 24));
 
210
}
 
211
 
 
212
inline uint BYTE_MUL(uint x, uint a) {
 
213
    ulong t = (((ulong(x)) | ((ulong(x)) << 24)) & 0x00ff00ff00ff00ff) * a;
 
214
    t = (t + ((t >> 8) & 0xff00ff00ff00ff) + 0x80008000800080);
 
215
    t &= 0x00ff00ff00ff00ff;
 
216
    return (uint(t)) | (uint(t >> 24));
 
217
}
 
218
 
 
219
inline uint PREMUL(uint x) {
 
220
    uint a = x >> 24;
 
221
    ulong t = (((ulong(x)) | ((ulong(x)) << 24)) & 0x00ff00ff00ff00ff) * a;
 
222
    t = (t + ((t >> 8) & 0xff00ff00ff00ff) + 0x80008000800080);
 
223
    t &= 0x00ff00ff00ff00ff;
 
224
    return (uint(t)) | (uint(t >> 24)) | 0xff000000;
 
225
}
 
226
 
 
227
#endif
 
228
 
 
229
#define INV_PREMUL(p)                                   \
 
230
    (qAlpha(p) == 0 ? 0 :                               \
 
231
    ((qAlpha(p) << 24)                                  \
 
232
     | (((255*qRed(p))/ qAlpha(p)) << 16)               \
 
233
     | (((255*qGreen(p)) / qAlpha(p))  << 8)            \
 
234
     | ((255*qBlue(p)) / qAlpha(p))))
 
235
 
 
236
 
 
237
const uint qt_bayer_matrix[16][16] = {
 
238
    { 0x1, 0xc0, 0x30, 0xf0, 0xc, 0xcc, 0x3c, 0xfc,
 
239
      0x3, 0xc3, 0x33, 0xf3, 0xf, 0xcf, 0x3f, 0xff},
 
240
    { 0x80, 0x40, 0xb0, 0x70, 0x8c, 0x4c, 0xbc, 0x7c,
 
241
      0x83, 0x43, 0xb3, 0x73, 0x8f, 0x4f, 0xbf, 0x7f},
 
242
    { 0x20, 0xe0, 0x10, 0xd0, 0x2c, 0xec, 0x1c, 0xdc,
 
243
      0x23, 0xe3, 0x13, 0xd3, 0x2f, 0xef, 0x1f, 0xdf},
 
244
    { 0xa0, 0x60, 0x90, 0x50, 0xac, 0x6c, 0x9c, 0x5c,
 
245
      0xa3, 0x63, 0x93, 0x53, 0xaf, 0x6f, 0x9f, 0x5f},
 
246
    { 0x8, 0xc8, 0x38, 0xf8, 0x4, 0xc4, 0x34, 0xf4,
 
247
      0xb, 0xcb, 0x3b, 0xfb, 0x7, 0xc7, 0x37, 0xf7},
 
248
    { 0x88, 0x48, 0xb8, 0x78, 0x84, 0x44, 0xb4, 0x74,
 
249
      0x8b, 0x4b, 0xbb, 0x7b, 0x87, 0x47, 0xb7, 0x77},
 
250
    { 0x28, 0xe8, 0x18, 0xd8, 0x24, 0xe4, 0x14, 0xd4,
 
251
      0x2b, 0xeb, 0x1b, 0xdb, 0x27, 0xe7, 0x17, 0xd7},
 
252
    { 0xa8, 0x68, 0x98, 0x58, 0xa4, 0x64, 0x94, 0x54,
 
253
      0xab, 0x6b, 0x9b, 0x5b, 0xa7, 0x67, 0x97, 0x57},
 
254
    { 0x2, 0xc2, 0x32, 0xf2, 0xe, 0xce, 0x3e, 0xfe,
 
255
      0x1, 0xc1, 0x31, 0xf1, 0xd, 0xcd, 0x3d, 0xfd},
 
256
    { 0x82, 0x42, 0xb2, 0x72, 0x8e, 0x4e, 0xbe, 0x7e,
 
257
      0x81, 0x41, 0xb1, 0x71, 0x8d, 0x4d, 0xbd, 0x7d},
 
258
    { 0x22, 0xe2, 0x12, 0xd2, 0x2e, 0xee, 0x1e, 0xde,
 
259
      0x21, 0xe1, 0x11, 0xd1, 0x2d, 0xed, 0x1d, 0xdd},
 
260
    { 0xa2, 0x62, 0x92, 0x52, 0xae, 0x6e, 0x9e, 0x5e,
 
261
      0xa1, 0x61, 0x91, 0x51, 0xad, 0x6d, 0x9d, 0x5d},
 
262
    { 0xa, 0xca, 0x3a, 0xfa, 0x6, 0xc6, 0x36, 0xf6,
 
263
      0x9, 0xc9, 0x39, 0xf9, 0x5, 0xc5, 0x35, 0xf5},
 
264
    { 0x8a, 0x4a, 0xba, 0x7a, 0x86, 0x46, 0xb6, 0x76,
 
265
      0x89, 0x49, 0xb9, 0x79, 0x85, 0x45, 0xb5, 0x75},
 
266
    { 0x2a, 0xea, 0x1a, 0xda, 0x26, 0xe6, 0x16, 0xd6,
 
267
      0x29, 0xe9, 0x19, 0xd9, 0x25, 0xe5, 0x15, 0xd5},
 
268
    { 0xaa, 0x6a, 0x9a, 0x5a, 0xa6, 0x66, 0x96, 0x56,
 
269
      0xa9, 0x69, 0x99, 0x59, 0xa5, 0x65, 0x95, 0x55}
 
270
};
 
271
 
 
272
#endif