Repository navigation
Expand file tree
/
Copy pathBlendSpans.cpp
More file actions
412 lines (403 loc) · 19.6 KB
/
Copy pathBlendSpans.cpp
File metadata and controls
412 lines (403 loc) · 19.6 KB
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
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
#include "BlendSpans.hpp"
#include "FastMath.hpp"
#include <algorithm>
namespace Renderer {
namespace {
inline uint16_t swap565(uint16_t p) { return (uint16_t)((p << 8) | (p >> 8)); }
// Packed lane factors for the S3 kernel. Values and sums stay below 32768,
// so signed saturating addition is exact even for full-strength additive G6.
struct alignas(16) KernelParams {
// flags: public bits 0..2, then opaque copy, unaligned source,
// unscaled additive, and constant foreground in bits 3..6.
uint32_t sourceWeight, destWeight, normalizer, shift, flags, key;
uint32_t padding[2];
uint32_t normalizationLanes[4];
};
inline uint32_t repeat16(uint32_t v) { return v | (v << 16); }
#ifdef _MSC_VER
#define JET_BLEND_INLINE __forceinline
#else
#define JET_BLEND_INLINE inline __attribute__((always_inline))
#endif
template<RGB565BlendMode Mode>
static JET_BLEND_INLINE void scalarRangeImpl(
uint16_t* dst, const uint16_t* src, int count, uint16_t col,
uint8_t alpha, uint8_t flags, uint16_t key) {
constexpr bool add = Mode == RGB565BlendMode::Add;
constexpr bool scaledAdd = Mode == RGB565BlendMode::AddAlpha256;
constexpr bool div255 = Mode == RGB565BlendMode::Alpha255;
const unsigned sw = add ? 1u : scaledAdd ? (unsigned)alpha + 1 : alpha;
const unsigned dw = add ? 1u : scaledAdd ? 256u : (div255 ? 255u : 256u) - alpha;
while (count--) {
const uint16_t s = src ? *src++ : col;
if ((flags & BlendColorKey) && s == key) { ++dst; continue; }
const uint16_t d = flags & BlendConstantBackground ? col :
flags & BlendSwapDestination ? swap565(*dst) : *dst;
unsigned r = (s >> 11) * sw + (d >> 11) * dw;
unsigned g = ((s >> 5) & 63) * sw + ((d >> 5) & 63) * dw;
unsigned b = (s & 31) * sw + (d & 31) * dw;
if constexpr (div255) { r /= 255; g /= 255; b /= 255; }
else if constexpr (!add) { r >>= 8; g >>= 8; b >>= 8; }
if constexpr (add || scaledAdd) {
r = std::min(r, 31u); g = std::min(g, 63u); b = std::min(b, 31u);
}
const uint16_t out = (uint16_t)((r << 11) | (g << 5) | b);
*dst++ = flags & BlendSwapDestination ? swap565(out) : out;
}
}
#if defined(CONFIG_IDF_TARGET_ESP32S3)
alignas(16) static const DRAM_ATTR uint32_t channelMasks[8] = {
0x001f001f, 0x001f001f, 0x001f001f, 0x001f001f,
0x003f003f, 0x003f003f, 0x003f003f, 0x003f003f
};
#define JET_BROADCAST(Q) \
"ee.movi.32.q " Q ", %[tmp], 0\n\t" \
"ee.movi.32.q " Q ", %[tmp], 1\n\t" \
"ee.movi.32.q " Q ", %[tmp], 2\n\t" \
"ee.movi.32.q " Q ", %[tmp], 3\n\t"
#define JET_SHIFT(N) "movi %[tmp], " N "\n\twsr %[tmp], sar\n\t"
// q0/q1 retain input pixels; q2/q3 retain weights; q7 accumulates output.
// Mask after the 32-bit shift isolates each 16-bit lane, including sign fill.
#define JET_CHANNEL(SHIFT, MASK_OFFSET) \
JET_SHIFT(SHIFT) \
"ee.vsr.32 q5, q0\n\tee.vsr.32 q6, q1\n\t" \
"addi %[tmp], %[masks], " MASK_OFFSET "\n\tee.vld.128.ip q4, %[tmp], 0\n\t" \
"ee.andq q5, q5, q4\n\tee.andq q6, q6, q4\n\t" \
"l32i %[tmp], %[params], 16\n\tbbsi %[tmp], 5, 6f\n\t" \
JET_SHIFT("0") \
"ee.vmul.u16 q5, q5, q2\n\tee.vmul.u16 q6, q6, q3\n\t" \
"addi %[tmp], %[params], 32\n\t" \
"ee.vadds.s16.ld.incp q6, %[tmp], q5, q5, q6\n\t" \
"l32i %[tmp], %[params], 12\n\twsr %[tmp], sar\n\t" \
"ee.vmul.u16 q5, q5, q6\n\t" \
"j 7f\n\t6:\n\tee.vadds.s16 q5, q5, q6\n\t7:\n\t" \
"ee.vmin.s16 q5, q5, q4\n\t" \
JET_SHIFT(SHIFT) \
"ee.vsl.32 q5, q5\n\t"
static inline __attribute__((always_inline)) void blendBlocks(
uint16_t* dst, const uint16_t* src, const uint16_t* background,
const KernelParams& p, int blocks) {
uint32_t savedSar, tmp;
// One asm block owns all QR/SAR state. Restore SAR because scalar GCC
// may keep a shift count there across the call site. No hidden QR state
// escapes to another function or across a scalar fallback.
__asm__ volatile (
"rsr %[saved], sar\n\t"
"l32i %[tmp], %[params], 0\n\t" JET_BROADCAST("q2")
"l32i %[tmp], %[params], 4\n\t" JET_BROADCAST("q3")
"9:\n\t"
"ee.vld.128.ip q0, %[src], 0\n\t"
"l32i %[tmp], %[params], 16\n\tbbci %[tmp], 4, 1f\n\t"
"addi %[tmp], %[src], 16\n\tee.vld.128.ip q5, %[tmp], 0\n\t"
"addi %[tmp], %[src], -1\n\tee.srcxxp.2q q5, q0, %[tmp], %[tmp]\n\t"
"1:\n\t"
"ee.vld.128.ip q1, %[bg], 0\n\t"
"l32i %[tmp], %[params], 16\n\t"
"bbci %[tmp], 0, 1f\n\t"
"ee.orq q5, q1, q1\n\tee.vunzip.8 q1, q5\n\tee.vzip.8 q5, q1\n\t"
"1:\n\t"
"l32i %[tmp], %[params], 16\n\tbbci %[tmp], 3, 5f\n\t"
"ee.orq q7, q0, q0\n\tj 4f\n\t5:\n\t"
JET_CHANNEL("11", "0")
"ee.orq q7, q5, q5\n\t"
JET_CHANNEL("5", "16")
"ee.orq q7, q7, q5\n\t"
JET_CHANNEL("0", "0")
"ee.orq q7, q7, q5\n\t"
"4:\n\t"
"l32i %[tmp], %[params], 16\n\t"
"bbci %[tmp], 1, 2f\n\t"
"l32i %[tmp], %[params], 20\n\t" JET_BROADCAST("q4")
"ee.vcmp.eq.s16 q4, q0, q4\n\t"
"ee.andq q5, q1, q4\n\tee.notq q4, q4\n\t"
"ee.andq q7, q7, q4\n\tee.orq q7, q7, q5\n\t"
"2:\n\t"
"l32i %[tmp], %[params], 16\n\t"
"bbci %[tmp], 0, 3f\n\t"
"ee.orq q5, q7, q7\n\tee.vunzip.8 q7, q5\n\tee.vzip.8 q5, q7\n\t"
"3:\n\t"
"ee.vst.128.ip q7, %[dst], 0\n\t"
"addi %[dst], %[dst], 16\n\t"
"l32i %[tmp], %[params], 16\n\t"
"bbsi %[tmp], 6, 8f\n\taddi %[src], %[src], 16\n\t8:\n\t"
"bbsi %[tmp], 2, 8f\n\taddi %[bg], %[bg], 16\n\t8:\n\t"
"addi %[blocks], %[blocks], -1\n\tbnez %[blocks], 9b\n\t"
"wsr %[saved], sar\n\t"
: [saved] "=&r"(savedSar), [tmp] "=&r"(tmp), [blocks] "+&r"(blocks),
[src] "+&r"(src), [bg] "+&r"(background), [dst] "+&r"(dst)
: [params] "r"(&p), [masks] "r"(channelMasks) : "memory"
);
}
// Sprite additive blending needs no weights or normalization. Keep both
// channel masks and the colour key in QR registers for the entire span.
// Each channel sum is <=126, so signed saturating add cannot alter it.
static inline __attribute__((always_inline)) void addBlocks(
uint16_t* dst, const uint16_t* src, const uint16_t* background,
const KernelParams& p, int blocks) {
uint32_t savedSar, tmp;
#define JET_ADD_CHANNEL(SHIFT, MASK) \
JET_SHIFT(SHIFT) \
"ee.vsr.32 q5, q0\n\tee.vsr.32 q6, q1\n\t" \
"ee.andq q5, q5, " MASK "\n\tee.andq q6, q6, " MASK "\n\t" \
"ee.vadds.s16 q5, q5, q6\n\tee.vmin.s16 q5, q5, " MASK "\n\t" \
"ee.vsl.32 q5, q5\n\t"
__asm__ volatile (
"rsr %[saved], sar\n\t"
"mov %[tmp], %[masks]\n\tee.vld.128.ip q2, %[tmp], 16\n\t"
"ee.vld.128.ip q3, %[tmp], 0\n\t"
"l32i %[tmp], %[params], 20\n\t" JET_BROADCAST("q4")
"9:\n\tee.vld.128.ip q0, %[src], 0\n\t"
"l32i %[tmp], %[params], 16\n\tbbci %[tmp], 4, 1f\n\t"
"addi %[tmp], %[src], 16\n\tee.vld.128.ip q5, %[tmp], 0\n\t"
"addi %[tmp], %[src], -1\n\tee.srcxxp.2q q5, q0, %[tmp], %[tmp]\n\t"
"1:\n\tee.vld.128.ip q1, %[bg], 0\n\t"
"l32i %[tmp], %[params], 16\n\tbbci %[tmp], 0, 1f\n\t"
"ee.orq q5, q1, q1\n\tee.vunzip.8 q1, q5\n\tee.vzip.8 q5, q1\n\t"
"1:\n\t"
JET_ADD_CHANNEL("11", "q2")
"ee.orq q7, q5, q5\n\t"
JET_ADD_CHANNEL("5", "q3")
"ee.orq q7, q7, q5\n\t"
// Blue is already in the low five bits; no shifts are needed.
"ee.andq q5, q0, q2\n\tee.andq q6, q1, q2\n\t"
"ee.vadds.s16 q5, q5, q6\n\tee.vmin.s16 q5, q5, q2\n\t"
"ee.orq q7, q7, q5\n\t"
"l32i %[tmp], %[params], 16\n\tbbci %[tmp], 1, 2f\n\t"
"ee.vcmp.eq.s16 q5, q0, q4\n\tee.andq q6, q1, q5\n\t"
"ee.notq q5, q5\n\tee.andq q7, q7, q5\n\tee.orq q7, q7, q6\n\t"
"2:\n\tbbci %[tmp], 0, 3f\n\t"
"ee.orq q5, q7, q7\n\tee.vunzip.8 q7, q5\n\tee.vzip.8 q5, q7\n\t"
"3:\n\tee.vst.128.ip q7, %[dst], 16\n\t"
"bbsi %[tmp], 6, 8f\n\taddi %[src], %[src], 16\n\t8:\n\t"
"bbsi %[tmp], 2, 8f\n\taddi %[bg], %[bg], 16\n\t8:\n\t"
"addi %[blocks], %[blocks], -1\n\tbnez %[blocks], 9b\n\t"
"wsr %[saved], sar\n\t"
: [saved] "=&r"(savedSar), [tmp] "=&r"(tmp), [blocks] "+&r"(blocks),
[src] "+&r"(src), [bg] "+&r"(background), [dst] "+&r"(dst)
: [params] "r"(&p), [masks] "r"(channelMasks) : "memory");
#undef JET_ADD_CHANNEL
}
#undef JET_CHANNEL
#undef JET_SHIFT
#undef JET_BROADCAST
#endif
} // namespace
void PERF_CRITICAL blendRGB565Span(uint16_t* dst, const uint16_t* src, int count,
uint16_t solidColor, uint8_t alpha,
RGB565BlendMode mode, uint8_t flags, uint16_t key) {
if (count <= 0) return;
const bool swapped = (flags & BlendSwapDestination) != 0;
const bool keyed = (flags & BlendColorKey) != 0;
const bool constantBG = (flags & BlendConstantBackground) != 0;
const bool add = mode == RGB565BlendMode::Add;
const bool scaledAdd = mode == RGB565BlendMode::AddAlpha256;
const bool divide255 = mode == RGB565BlendMode::Alpha255;
const bool copy = divide255 && alpha == 255;
const unsigned sw = add ? 1u : scaledAdd ? (unsigned)alpha + 1 : alpha;
const unsigned dw = add ? 1u : scaledAdd ? 256u : (divide255 ? 255u : 256u) - alpha;
auto scalarPixel = [&]() {
const uint16_t s = src ? *src++ : solidColor;
if (!keyed || s != key) {
if (copy) {
*dst = swapped ? swap565(s) : s;
++dst; --count;
return;
}
const uint16_t d = constantBG ? solidColor : swapped ? swap565(*dst) : *dst;
auto channel = [&](unsigned shift, unsigned mask) {
unsigned v = ((s >> shift) & mask) * sw + ((d >> shift) & mask) * dw;
if (!add) v = divide255 ? v / 255 : v / 256;
return std::min(v, mask) << shift;
};
const uint16_t out = (uint16_t)(channel(11, 31) | channel(5, 63) | channel(0, 31));
*dst = swapped ? swap565(out) : out;
}
++dst; --count;
};
#if defined(CONFIG_IDF_TARGET_ESP32S3)
const uintptr_t s = (uintptr_t)src, d = (uintptr_t)dst;
// Forward overlapping reads can depend on earlier writes (current-frame
// water). Preserve scalar ordering in that case. Other spans may peel
// a few pixels to align both streams, without reading outside the span.
const bool feedback = src && s < d && d - s < (uintptr_t)count * 2;
const bool matchingAlignment = !src || ((s ^ d) & 15) == 0;
if (count >= (matchingAlignment ? 16 : 32) && !feedback && !(constantBG && (swapped || keyed))) {
// Unaligned vector loads round down. Consume a complete block first
// and leave a complete block at the end, keeping both loads within
// the caller's source range even for tightly allocated sprite rows.
if (!matchingAlignment) for (int i = 0; i < 8; ++i) scalarPixel();
while (count && ((uintptr_t)dst & 15)) scalarPixel();
alignas(16) uint16_t constant[8];
if (!src || constantBG) std::fill(constant, constant + 8, solidColor);
// floor(x/255) == (x*32897)>>23 for every 16-bit x. Products here
// are at most 32256, so /255 and /256 exactly match scalar rounding.
KernelParams p = {repeat16(sw), repeat16(dw),
repeat16(add ? 1u : divide255 ? 32897u : 256u),
add ? 0u : divide255 ? 23u : 16u,
(uint32_t)flags | (copy ? 8u : 0u) | (!matchingAlignment ? 16u : 0u) |
(add ? 32u : 0u) | (!src ? 64u : 0u), repeat16(key), {}, {}};
std::fill(p.normalizationLanes, p.normalizationLanes + 4, p.normalizer);
const int pixels = (count - (matchingAlignment ? 0 : 8)) & ~7;
if (add) addBlocks(dst, src ? src : constant, constantBG ? constant : dst, p, pixels / 8);
else blendBlocks(dst, src ? src : constant, constantBG ? constant : dst, p, pixels / 8);
dst += pixels; if (src) src += pixels; count -= pixels;
}
#endif
if (copy) { while (count) scalarPixel(); return; }
switch (mode) {
case RGB565BlendMode::Alpha255:
scalarRangeImpl<RGB565BlendMode::Alpha255>(dst, src, count, solidColor, alpha, flags, key); break;
case RGB565BlendMode::Alpha256:
scalarRangeImpl<RGB565BlendMode::Alpha256>(dst, src, count, solidColor, alpha, flags, key); break;
case RGB565BlendMode::Add:
scalarRangeImpl<RGB565BlendMode::Add>(dst, src, count, solidColor, alpha, flags, key); break;
default:
scalarRangeImpl<RGB565BlendMode::AddAlpha256>(dst, src, count, solidColor, alpha, flags, key); break;
}
}
void RGB565ConstantBlend::prepare(uint16_t solidColor, uint8_t a, bool constantBackground) {
color = solidColor; alpha = a; background = constantBackground;
const unsigned fixedWeight = background ? 256u - a : a;
const unsigned variableWeight = background ? a : 256u - a;
// Preweight the constant operand, so each block only unpacks/multiplies
// its variable pixels. Even G6 sums stay <= 63*256, below signed16 max.
for (int i = 0; i < 4; ++i) {
lanes[i] = repeat16(variableWeight);
lanes[4+i] = repeat16((color >> 11) * fixedWeight);
lanes[8+i] = repeat16(((color >> 5) & 63) * fixedWeight);
lanes[12+i] = repeat16((color & 31) * fixedWeight);
lanes[16+i] = repeat16(256);
}
}
void PERF_CRITICAL RGB565ConstantBlend::blend(uint16_t* dst, const uint16_t* src, int count) const {
if (count <= 0) return;
const uint16_t* input = background ? src : dst;
#if defined(CONFIG_IDF_TARGET_ESP32S3)
const auto s = (uintptr_t)input, d = (uintptr_t)dst;
// Equal alignment permits direct vector loads. Forward feedback and
// mismatched alignment use the existing helper with its scalar guards.
if (count >= 16 && ((s ^ d) & 15) == 0 && !(s < d && d - s < (uintptr_t)count * 2)) {
auto scalar = [&]() {
const unsigned v = *input++;
const unsigned sw = background ? alpha : 256u - alpha;
const unsigned cw = 256u - sw;
*dst++=(uint16_t)(((((v>>11)*sw+(color>>11)*cw)>>8)<<11)
| (((((v>>5)&63)*sw+((color>>5)&63)*cw)>>8)<<5)
| (((v&31)*sw+(color&31)*cw)>>8));
--count;
};
while (count && ((uintptr_t)dst & 15)) scalar();
int blocks = count / 8;
const int pixels = blocks * 8;
uint32_t saved, tmp;
#define CSHIFT(N) "movi %[tmp], " N "\n\twsr %[tmp], sar\n\t"
#define CWEIGHT(OFF) \
"addi %[tmp], %[params], " OFF "\n\t" \
"ee.vmul.u16.ld.incp q3, %[tmp], q5, q5, q2\n\t" \
CSHIFT("16") "ee.vadds.s16 q5, q5, q3\n\t" \
"ee.vmul.u16 q5, q5, q6\n\t"
#define CCHANNEL(SH,OFF,MASK) \
CSHIFT(SH) "ee.vsr.32 q5, q0\n\t" \
CSHIFT("0") "ee.andq q5, q5, " MASK "\n\t" \
CWEIGHT(OFF) CSHIFT(SH) "ee.vsl.32 q5, q5\n\t"
// Own all vector state inside this block; restore the scalar shift
// register before returning to C++. Keep both channel masks live
// across the span and fuse each multiply with its constant load.
// The signed add is exact: every weighted sum is <= 63*256.
// No QR state crosses calls; this must not nest in a hardware loop.
__asm__ volatile (
"rsr %[saved], sar\n\t"
"mov %[tmp], %[params]\n\tee.vld.128.ip q2, %[tmp], 0\n\t"
"addi %[tmp], %[params], 64\n\tee.vld.128.ip q6, %[tmp], 0\n\t"
"mov %[tmp], %[masks]\n\tee.vld.128.ip q1, %[tmp], 16\n\t"
"ee.vld.128.ip q4, %[tmp], 0\n\t"
"loopnez %[blocks], .Lconstant_end%=\n\t"
"ee.vld.128.ip q0, %[input], 16\n\t"
CCHANNEL("11","16","q1") "ee.orq q7, q5, q5\n\t"
CCHANNEL("5","32","q4") "ee.orq q7, q7, q5\n\t"
// Blue occupies the low bits of each halfword already.
CSHIFT("0") "ee.andq q5, q0, q1\n\t"
CWEIGHT("48") "ee.orq q7, q7, q5\n\t"
"ee.vst.128.ip q7, %[dst], 16\n\t"
".Lconstant_end%=:\n\t"
"wsr %[saved], sar\n\t"
: [saved] "=&r"(saved), [tmp] "=&r"(tmp), [blocks] "+&r"(blocks),
[input] "+&r"(input), [dst] "+&r"(dst)
: [params] "r"(lanes), [masks] "r"(channelMasks) : "memory");
#undef CCHANNEL
#undef CWEIGHT
#undef CSHIFT
count -= pixels;
while (count) scalar();
return;
}
#endif
blendRGB565Span(dst, background ? src : nullptr, count, color, alpha,
RGB565BlendMode::Alpha256, background ? BlendConstantBackground : 0);
}
namespace {
template<bool Mirror>
JET_BLEND_INLINE void scaledSpan(uint16_t* dst, const uint16_t* src, int count,
int sourceX256, int step256, uint8_t alpha,
RGB565BlendMode mode, uint8_t flags, uint16_t key,
int sourceWidth = 0) {
if (count <= 0) return;
int firstX = sourceX256 >> 8;
int lastX = (int)(((int64_t)sourceX256 + (int64_t)(count - 1) * step256) >> 8);
if constexpr (Mirror) {
// Conservative bounds also cover a span that crosses the symmetry
// axis. Framebuffer-backed textures must preserve write feedback.
firstX = 0;
lastX = sourceWidth - 1;
}
const uintptr_t first = (uintptr_t)(src + std::min(firstX, lastX));
const uintptr_t last = (uintptr_t)(src + std::max(firstX, lastX) + 1);
if (first < (uintptr_t)(dst + count) && (uintptr_t)dst < last) {
for (int i = 0; i < count; ++i, sourceX256 += step256) {
int x = sourceX256 >> 8;
if constexpr (Mirror) {
if (x >= sourceWidth) x = 2 * sourceWidth - 1 - x;
}
blendRGB565Span(dst + i, src + x, 1, 0, alpha, mode, flags, key);
}
return;
}
// Stage a small row fragment in internal stack RAM. Matching the
// destination phase keeps full vector loads/stores aligned. Mirrored
// halves share the same tile to avoid two SIMD setups per row.
alignas(16) uint16_t tile[128 + 8];
while (count > 0) {
const int n = std::min(count, 128);
uint16_t* pixels = tile + (((uintptr_t)dst & 15) / 2);
if constexpr (Mirror) {
const int edge256 = sourceWidth << 8;
int forward = 0;
if (sourceX256 < edge256)
forward = step256 ? std::min(n, (edge256 - sourceX256 + step256 - 1) / step256) : n;
int x256 = sourceX256;
for (int i = 0; i < forward; ++i, x256 += step256)
pixels[i] = src[x256 >> 8];
x256 = 2 * edge256 - 1 - x256;
for (int i = forward; i < n; ++i, x256 -= step256)
pixels[i] = src[x256 >> 8];
sourceX256 += n * step256;
} else {
for (int i = 0; i < n; ++i, sourceX256 += step256)
pixels[i] = src[sourceX256 >> 8];
}
blendRGB565Span(dst, pixels, n, 0, alpha, mode, flags, key);
dst += n; count -= n;
}
}
} // namespace
void PERF_CRITICAL blendRGB565ScaledSpan(uint16_t* dst, const uint16_t* src, int count,
int sourceX256, int step256, uint8_t alpha,
RGB565BlendMode mode, uint8_t flags, uint16_t key) {
scaledSpan<false>(dst, src, count, sourceX256, step256, alpha, mode, flags, key);
}
void PERF_CRITICAL blendRGB565MirroredSpan(uint16_t* dst, const uint16_t* src, int sourceWidth,
int count, int sourceX256, int step256, uint8_t alpha,
RGB565BlendMode mode, uint8_t flags, uint16_t key) {
scaledSpan<true>(dst, src, count, sourceX256, step256, alpha, mode, flags, key, sourceWidth);
}
} // namespace Renderer