1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
|
/*
* Copyright 2011 Google Inc.
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
// Define NAME_WRAP(x) before including this header to perform name-wrapping
// E.g. for ARM NEON, defined it as 'x ## _neon' to ensure all important
// identifiers have a _neon suffix.
#ifndef NAME_WRAP
#error "Please define NAME_WRAP() before including this file"
#endif
// returns expanded * 5bits
static inline uint32_t Filter_565_Expanded(unsigned x, unsigned y,
uint32_t a00, uint32_t a01,
uint32_t a10, uint32_t a11) {
SkASSERT((unsigned)x <= 0xF);
SkASSERT((unsigned)y <= 0xF);
a00 = SkExpand_rgb_16(a00);
a01 = SkExpand_rgb_16(a01);
a10 = SkExpand_rgb_16(a10);
a11 = SkExpand_rgb_16(a11);
int xy = x * y >> 3;
return a00 * (32 - 2*y - 2*x + xy) +
a01 * (2*x - xy) +
a10 * (2*y - xy) +
a11 * xy;
}
// turn an expanded 565 * 5bits into SkPMColor
// g:11 | r:10 | x:1 | b:10
static inline SkPMColor SkExpanded_565_To_PMColor(uint32_t c) {
unsigned r = (c >> 13) & 0xFF;
unsigned g = (c >> 24);
unsigned b = (c >> 2) & 0xFF;
return SkPackARGB32(0xFF, r, g, b);
}
// returns answer in SkPMColor format
static inline SkPMColor Filter_4444_D32(unsigned x, unsigned y,
uint32_t a00, uint32_t a01,
uint32_t a10, uint32_t a11) {
SkASSERT((unsigned)x <= 0xF);
SkASSERT((unsigned)y <= 0xF);
a00 = SkExpand_4444(a00);
a01 = SkExpand_4444(a01);
a10 = SkExpand_4444(a10);
a11 = SkExpand_4444(a11);
int xy = x * y >> 4;
uint32_t result = a00 * (16 - y - x + xy) +
a01 * (x - xy) +
a10 * (y - xy) +
a11 * xy;
return SkCompact_8888(result);
}
static inline U8CPU Filter_8(unsigned x, unsigned y,
U8CPU a00, U8CPU a01,
U8CPU a10, U8CPU a11) {
SkASSERT((unsigned)x <= 0xF);
SkASSERT((unsigned)y <= 0xF);
int xy = x * y;
unsigned result = a00 * (256 - 16*y - 16*x + xy) +
a01 * (16*x - xy) +
a10 * (16*y - xy) +
a11 * xy;
return result >> 8;
}
/*****************************************************************************
*
* D32 functions
*
*/
// SRC == 8888
#define FILTER_PROC(x, y, a, b, c, d, dst) NAME_WRAP(Filter_32_opaque)(x, y, a, b, c, d, dst)
#define MAKENAME(suffix) NAME_WRAP(S32_opaque_D32 ## suffix)
#define SRCTYPE SkPMColor
#define CHECKSTATE(state) SkASSERT(4 == state.fPixmap.info().bytesPerPixel()); \
SkASSERT(state.fAlphaScale == 256)
#define RETURNDST(src) src
#define SRC_TO_FILTER(src) src
#include "SkBitmapProcState_sample.h"
#undef FILTER_PROC
#define FILTER_PROC(x, y, a, b, c, d, dst) NAME_WRAP(Filter_32_alpha)(x, y, a, b, c, d, dst, alphaScale)
#define MAKENAME(suffix) NAME_WRAP(S32_alpha_D32 ## suffix)
#define SRCTYPE SkPMColor
#define CHECKSTATE(state) SkASSERT(4 == state.fPixmap.info().bytesPerPixel()); \
SkASSERT(state.fAlphaScale < 256)
#define PREAMBLE(state) unsigned alphaScale = state.fAlphaScale
#define RETURNDST(src) SkAlphaMulQ(src, alphaScale)
#define SRC_TO_FILTER(src) src
#include "SkBitmapProcState_sample.h"
// SRC == 565
#undef FILTER_PROC
#define FILTER_PROC(x, y, a, b, c, d, dst) \
do { \
uint32_t tmp = Filter_565_Expanded(x, y, a, b, c, d); \
*(dst) = SkExpanded_565_To_PMColor(tmp); \
} while (0)
#define MAKENAME(suffix) NAME_WRAP(S16_opaque_D32 ## suffix)
#define SRCTYPE uint16_t
#define CHECKSTATE(state) SkASSERT(kRGB_565_SkColorType == state.fPixmap.colorType()); \
SkASSERT(state.fAlphaScale == 256)
#define RETURNDST(src) SkPixel16ToPixel32(src)
#define SRC_TO_FILTER(src) src
#include "SkBitmapProcState_sample.h"
#undef FILTER_PROC
#define FILTER_PROC(x, y, a, b, c, d, dst) \
do { \
uint32_t tmp = Filter_565_Expanded(x, y, a, b, c, d); \
*(dst) = SkAlphaMulQ(SkExpanded_565_To_PMColor(tmp), alphaScale); \
} while (0)
#define MAKENAME(suffix) NAME_WRAP(S16_alpha_D32 ## suffix)
#define SRCTYPE uint16_t
#define CHECKSTATE(state) SkASSERT(kRGB_565_SkColorType == state.fPixmap.colorType()); \
SkASSERT(state.fAlphaScale < 256)
#define PREAMBLE(state) unsigned alphaScale = state.fAlphaScale
#define RETURNDST(src) SkAlphaMulQ(SkPixel16ToPixel32(src), alphaScale)
#define SRC_TO_FILTER(src) src
#include "SkBitmapProcState_sample.h"
// SRC == Index8
#undef FILTER_PROC
#define FILTER_PROC(x, y, a, b, c, d, dst) NAME_WRAP(Filter_32_opaque)(x, y, a, b, c, d, dst)
#define MAKENAME(suffix) NAME_WRAP(SI8_opaque_D32 ## suffix)
#define SRCTYPE uint8_t
#define CHECKSTATE(state) SkASSERT(kIndex_8_SkColorType == state.fPixmap.colorType()); \
SkASSERT(state.fAlphaScale == 256)
#define PREAMBLE(state) const SkPMColor* SK_RESTRICT table = state.fPixmap.ctable()->readColors()
#define RETURNDST(src) table[src]
#define SRC_TO_FILTER(src) table[src]
#define POSTAMBLE(state)
#include "SkBitmapProcState_sample.h"
#undef FILTER_PROC
#define FILTER_PROC(x, y, a, b, c, d, dst) NAME_WRAP(Filter_32_alpha)(x, y, a, b, c, d, dst, alphaScale)
#define MAKENAME(suffix) NAME_WRAP(SI8_alpha_D32 ## suffix)
#define SRCTYPE uint8_t
#define CHECKSTATE(state) SkASSERT(kIndex_8_SkColorType == state.fPixmap.colorType()); \
SkASSERT(state.fAlphaScale < 256)
#define PREAMBLE(state) unsigned alphaScale = state.fAlphaScale; \
const SkPMColor* SK_RESTRICT table = state.fPixmap.ctable()->readColors()
#define RETURNDST(src) SkAlphaMulQ(table[src], alphaScale)
#define SRC_TO_FILTER(src) table[src]
#define POSTAMBLE(state)
#include "SkBitmapProcState_sample.h"
// SRC == 4444
#undef FILTER_PROC
#define FILTER_PROC(x, y, a, b, c, d, dst) *(dst) = Filter_4444_D32(x, y, a, b, c, d)
#define MAKENAME(suffix) NAME_WRAP(S4444_opaque_D32 ## suffix)
#define SRCTYPE SkPMColor16
#define CHECKSTATE(state) SkASSERT(kARGB_4444_SkColorType == state.fPixmap.colorType()); \
SkASSERT(state.fAlphaScale == 256)
#define RETURNDST(src) SkPixel4444ToPixel32(src)
#define SRC_TO_FILTER(src) src
#include "SkBitmapProcState_sample.h"
#undef FILTER_PROC
#define FILTER_PROC(x, y, a, b, c, d, dst) \
do { \
uint32_t tmp = Filter_4444_D32(x, y, a, b, c, d); \
*(dst) = SkAlphaMulQ(tmp, alphaScale); \
} while (0)
#define MAKENAME(suffix) NAME_WRAP(S4444_alpha_D32 ## suffix)
#define SRCTYPE SkPMColor16
#define CHECKSTATE(state) SkASSERT(kARGB_4444_SkColorType == state.fPixmap.colorType()); \
SkASSERT(state.fAlphaScale < 256)
#define PREAMBLE(state) unsigned alphaScale = state.fAlphaScale
#define RETURNDST(src) SkAlphaMulQ(SkPixel4444ToPixel32(src), alphaScale)
#define SRC_TO_FILTER(src) src
#include "SkBitmapProcState_sample.h"
// SRC == A8
#undef FILTER_PROC
#define FILTER_PROC(x, y, a, b, c, d, dst) \
do { \
unsigned tmp = Filter_8(x, y, a, b, c, d); \
*(dst) = SkAlphaMulQ(pmColor, SkAlpha255To256(tmp)); \
} while (0)
#define MAKENAME(suffix) NAME_WRAP(SA8_alpha_D32 ## suffix)
#define SRCTYPE uint8_t
#define CHECKSTATE(state) SkASSERT(kAlpha_8_SkColorType == state.fPixmap.colorType());
#define PREAMBLE(state) const SkPMColor pmColor = state.fPaintPMColor;
#define RETURNDST(src) SkAlphaMulQ(pmColor, SkAlpha255To256(src))
#define SRC_TO_FILTER(src) src
#include "SkBitmapProcState_sample.h"
// SRC == Gray8
#undef FILTER_PROC
#define FILTER_PROC(x, y, a, b, c, d, dst) \
do { \
unsigned tmp = Filter_8(x, y, a, b, c, d); \
SkPMColor color = SkPackARGB32(0xFF, tmp, tmp, tmp); \
*(dst) = SkAlphaMulQ(color, alphaScale); \
} while (0)
#define MAKENAME(suffix) NAME_WRAP(SG8_alpha_D32 ## suffix)
#define SRCTYPE uint8_t
#define CHECKSTATE(state) SkASSERT(kGray_8_SkColorType == state.fPixmap.colorType());
#define PREAMBLE(state) unsigned alphaScale = state.fAlphaScale
#define RETURNDST(src) SkAlphaMulQ(SkPackARGB32(0xFF, src, src, src), alphaScale)
#define SRC_TO_FILTER(src) src
#include "SkBitmapProcState_sample.h"
#define TILEX_PROCF(fx, max) SkClampMax((fx) >> 16, max)
#define TILEY_PROCF(fy, max) SkClampMax((fy) >> 16, max)
#define TILEX_LOW_BITS(fx, max) (((fx) >> 12) & 0xF)
#define TILEY_LOW_BITS(fy, max) (((fy) >> 12) & 0xF)
#undef FILTER_PROC
#define FILTER_PROC(x, y, a, b, c, d, dst) NAME_WRAP(Filter_32_opaque)(x, y, a, b, c, d, dst)
#define MAKENAME(suffix) NAME_WRAP(Clamp_SI8_opaque_D32 ## suffix)
#define SRCTYPE uint8_t
#define CHECKSTATE(state) SkASSERT(kIndex_8_SkColorType == state.fPixmap.colorType())
#define PREAMBLE(state) const SkPMColor* SK_RESTRICT table = state.fPixmap.ctable()->readColors()
#define SRC_TO_FILTER(src) table[src]
#define POSTAMBLE(state)
#include "SkBitmapProcState_shaderproc.h"
#undef NAME_WRAP
|