1 /** NOTE: This file is meant to be included by users **/
3 /** NOTE2: r, g, b parameters are 16bits, so you can pass 0 to 256 inclusive.
4 ** this is due our division by 256 when multiplying the color.
7 /*****************************************************************************
10 * _soft16_scanline_<description>_<src>_<dst>[_<modifier>]()
12 ****************************************************************************/
14 static always_inline void
15 _soft16_pt_blend_transp_solid(DATA16 *p_dst, DATA16 src, DATA8 alpha)
17 if (alpha == 31) *p_dst = src;
22 a = RGB_565_UNPACK(src);
23 b = RGB_565_UNPACK(*p_dst);
24 b = RGB_565_UNPACKED_BLEND(a, b, alpha);
25 *p_dst = RGB_565_PACK(b);
29 /***********************************************************************
30 * Regular blend operations
33 _soft16_scanline_blend_transp_solid(DATA16 *src, DATA8 *alpha, DATA16 *dst, int size)
38 end = start + (size & ~7);
43 /* work on 8 pixels per time, do data preload */
51 /* empirical tests show these give the best performance */
59 _soft16_pt_blend_transp_solid(start - 8, src[-8], alpha1);
62 _soft16_pt_blend_transp_solid(start - 7, src[-7], alpha2);
65 _soft16_pt_blend_transp_solid(start - 6, src[-6], alpha1);
68 _soft16_pt_blend_transp_solid(start - 5, src[-5], alpha2);
71 _soft16_pt_blend_transp_solid(start - 4, src[-4], alpha1);
74 _soft16_pt_blend_transp_solid(start - 3, src[-3], alpha2);
77 _soft16_pt_blend_transp_solid(start - 2, src[-2], alpha1);
79 _soft16_pt_blend_transp_solid(start - 1, src[-1], alpha2);
82 /* remaining pixels (up to 7) */
83 end = start + (size & 7);
84 for (; start < end; start++, src++, alpha++)
85 _soft16_pt_blend_transp_solid(start, *src, *alpha);
88 static always_inline void
89 _soft16_pt_blend_solid_solid(DATA16 *p_dst, DATA16 src)
95 _soft16_scanline_blend_solid_solid(DATA16 *src, DATA16 *dst, int size)
97 memcpy(dst, src, size * sizeof(DATA16));
100 /***********************************************************************
101 * Blend operations taking an extra alpha (fade in, out)
105 _soft16_pt_blend_transp_solid_mul_alpha(DATA16 *p_dst, DATA16 src, DATA8 alpha, DATA8 rel_alpha)
109 alpha = (alpha * rel_alpha) >> 5;
115 a = ((RGB_565_UNPACK(src) * rel_alpha) >> 5) & RGB_565_UNPACKED_MASK;
116 b = RGB_565_UNPACK(*p_dst);
117 b = RGB_565_UNPACKED_BLEND(a, b, alpha);
118 *p_dst = RGB_565_PACK(b);
122 _soft16_scanline_blend_transp_solid_mul_alpha(DATA16 *src, DATA8 *alpha, DATA16 *dst, int size, const DATA8 rel_alpha)
127 end = start + (size & ~7);
134 DATA8 alpha1, alpha2;
146 _soft16_pt_blend_transp_solid_mul_alpha
147 (start - 8, src[-8], alpha1, rel_alpha);
150 _soft16_pt_blend_transp_solid_mul_alpha
151 (start - 7, src[-7], alpha2, rel_alpha);
154 _soft16_pt_blend_transp_solid_mul_alpha
155 (start - 6, src[-6], alpha1, rel_alpha);
158 _soft16_pt_blend_transp_solid_mul_alpha
159 (start - 5, src[-5], alpha2, rel_alpha);
162 _soft16_pt_blend_transp_solid_mul_alpha
163 (start - 4, src[-4], alpha1, rel_alpha);
166 _soft16_pt_blend_transp_solid_mul_alpha
167 (start - 3, src[-3], alpha2, rel_alpha);
170 _soft16_pt_blend_transp_solid_mul_alpha
171 (start - 2, src[-2], alpha1, rel_alpha);
173 _soft16_pt_blend_transp_solid_mul_alpha
174 (start - 1, src[-1], alpha2, rel_alpha);
177 end = start + (size & 7);
178 for (; start < end; start++, src++, alpha++)
179 _soft16_pt_blend_transp_solid_mul_alpha(start, *src, *alpha, rel_alpha);
182 static always_inline void
183 _soft16_pt_blend_solid_solid_mul_alpha(DATA16 *p_dst, DATA16 src, DATA8 rel_alpha)
186 a = RGB_565_UNPACK(src);
187 b = RGB_565_UNPACK(*p_dst);
188 b = RGB_565_UNPACKED_BLEND_UNMUL(a, b, rel_alpha);
189 *p_dst = RGB_565_PACK(b);
193 _soft16_scanline_blend_solid_solid_mul_alpha(DATA16 *src, DATA16 *dst, int size, DATA8 rel_alpha)
198 end = start + (size & ~7);
206 _soft16_pt_blend_solid_solid_mul_alpha(start, *src, rel_alpha);
212 end = start + (size & 7);
213 for (; start < end; start++, src++)
214 _soft16_pt_blend_solid_solid_mul_alpha(start, *src, rel_alpha);
217 /***********************************************************************
218 * Blend operations with extra alpha and multiply color
221 static always_inline void
222 _soft16_pt_blend_transp_solid_mul_color_transp(DATA16 *p_dst, DATA16 src, DATA8 alpha, DATA8 rel_alpha, DATA16 r, DATA16 g, DATA16 b)
227 alpha = (alpha * rel_alpha) >> 5;
233 r1 = ((((src) >> 11) & 0x1f) * r) >> 5;
234 g1 = ((((src) >> 5) & 0x3f) * g) >> 6;
235 b1 = (((src) & 0x1f) * b) >> 5;
236 rgb = ((r1 << 11) | (g1 << 21) | b1) & RGB_565_UNPACKED_MASK;
237 d = RGB_565_UNPACK(*p_dst);
238 d = RGB_565_UNPACKED_BLEND(rgb, d, alpha);
240 *p_dst = RGB_565_PACK(d);
244 _soft16_scanline_blend_transp_solid_mul_color_transp(DATA16 *src, DATA8 *alpha, DATA16 *dst, int size, DATA8 rel_alpha, DATA16 r, DATA16 g, DATA16 b)
249 end = start + (size & ~7);
256 DATA8 alpha1, alpha2;
268 _soft16_pt_blend_transp_solid_mul_color_transp
269 (start - 8, src[-8], alpha1, rel_alpha, r, g, b);
272 _soft16_pt_blend_transp_solid_mul_color_transp
273 (start - 7, src[-7], alpha2, rel_alpha, r, g, b);
276 _soft16_pt_blend_transp_solid_mul_color_transp
277 (start - 6, src[-6], alpha1, rel_alpha, r, g, b);
280 _soft16_pt_blend_transp_solid_mul_color_transp
281 (start - 5, src[-5], alpha2, rel_alpha, r, g, b);
284 _soft16_pt_blend_transp_solid_mul_color_transp
285 (start - 4, src[-4], alpha1, rel_alpha, r, g, b);
288 _soft16_pt_blend_transp_solid_mul_color_transp
289 (start - 3, src[-3], alpha2, rel_alpha, r, g, b);
292 _soft16_pt_blend_transp_solid_mul_color_transp
293 (start - 2, src[-2], alpha1, rel_alpha, r, g, b);
295 _soft16_pt_blend_transp_solid_mul_color_transp
296 (start - 1, src[-1], alpha2, rel_alpha, r, g, b);
299 end = start + (size & 7);
300 for (; start < end; start++, src++, alpha++)
301 _soft16_pt_blend_transp_solid_mul_color_transp
302 (start, *src, *alpha, rel_alpha, r, g, b);
305 static always_inline void
306 _soft16_pt_blend_solid_solid_mul_color_transp(DATA16 *p_dst, DATA16 src, DATA8 rel_alpha, DATA16 r, DATA16 g, DATA16 b)
311 r1 = ((((src) >> 11) & 0x1f) * r) >> 5;
312 g1 = ((((src) >> 5) & 0x3f) * g) >> 6;
313 b1 = (((src) & 0x1f) * b) >> 5;
315 rgb = ((r1 << 11) | (g1 << 21) | b1) & RGB_565_UNPACKED_MASK;
316 d = RGB_565_UNPACK(*p_dst);
317 d = RGB_565_UNPACKED_BLEND(rgb, d, rel_alpha);
318 *p_dst = RGB_565_PACK(d);
322 _soft16_scanline_blend_solid_solid_mul_color_transp(DATA16 *src, DATA16 *dst, int size, DATA8 rel_alpha, DATA16 r, DATA16 g, DATA16 b)
327 end = start + (size & ~7);
335 _soft16_pt_blend_solid_solid_mul_color_transp
336 (start, *src, rel_alpha, r, g, b);
342 end = start + (size & 7);
343 for (; start < end; start++, src++)
344 _soft16_pt_blend_solid_solid_mul_color_transp
345 (start, *src, rel_alpha, r, g, b);
348 /***********************************************************************
349 * Blend operations with extra multiply color
351 static always_inline void
352 _soft16_pt_blend_transp_solid_mul_color_solid(DATA16 *p_dst, DATA16 src, DATA8 alpha, DATA8 r, DATA8 g, DATA8 b)
356 if (alpha == 0) return;
358 r1 = ((((src >> 11) & 0x1f) * r) >> 5) & 0x1f;
359 g1 = ((((src >> 5) & 0x3f) * g) >> 6) & 0x3f;
360 b1 = (((src & 0x1f) * b) >> 5) & 0x1f;
362 if (alpha == 31) *p_dst = (r1 << 11) | (g1 << 5) | b1;
365 DATA32 rgb_unpack, d;
367 rgb_unpack = ((r1 << 11) | (g1 << 21) | b1) & RGB_565_UNPACKED_MASK;
368 d = RGB_565_UNPACK(*p_dst);
369 d = RGB_565_UNPACKED_BLEND(rgb_unpack, d, alpha);
370 *p_dst = RGB_565_PACK(d);
375 _soft16_scanline_blend_transp_solid_mul_color_solid(DATA16 *src, DATA8 *alpha, DATA16 *dst, int size, DATA16 r, DATA16 g, DATA16 b)
380 end = start + (size & ~7);
387 DATA8 alpha1, alpha2;
399 _soft16_pt_blend_transp_solid_mul_color_solid
400 (start - 8, src[-8], alpha1, r, g, b);
403 _soft16_pt_blend_transp_solid_mul_color_solid
404 (start - 7, src[-7], alpha2, r, g, b);
407 _soft16_pt_blend_transp_solid_mul_color_solid
408 (start - 6, src[-6], alpha1, r, g, b);
411 _soft16_pt_blend_transp_solid_mul_color_solid
412 (start - 5, src[-5], alpha2, r, g, b);
415 _soft16_pt_blend_transp_solid_mul_color_solid
416 (start - 4, src[-4], alpha1, r, g, b);
419 _soft16_pt_blend_transp_solid_mul_color_solid
420 (start - 3, src[-3], alpha2, r, g, b);
423 _soft16_pt_blend_transp_solid_mul_color_solid
424 (start - 2, src[-2], alpha1, r, g, b);
426 _soft16_pt_blend_transp_solid_mul_color_solid
427 (start - 1, src[-1], alpha2, r, g, b);
430 end = start + (size & 7);
431 for (; start < end; start++, src++, alpha++)
432 _soft16_pt_blend_transp_solid_mul_color_solid
433 (start, *src, *alpha, r, g, b);
436 static always_inline void
437 _soft16_pt_blend_solid_solid_mul_color_solid(DATA16 *p_dst, DATA16 src, DATA16 r, DATA16 g, DATA16 b)
441 r1 = ((((src >> 11) & 0x1f) * r) >> 5) & 0x1f;
442 g1 = ((((src >> 5) & 0x3f) * g) >> 6) & 0x3f;
443 b1 = (((src & 0x1f) * b) >> 5) & 0x1f;
445 *p_dst = (r1 << 11) | (g1 << 5) | b1;
449 _soft16_scanline_blend_solid_solid_mul_color_solid(DATA16 *src, DATA16 *dst, int size, DATA8 r, DATA8 g, DATA8 b)
454 end = start + (size & ~7);
462 _soft16_pt_blend_solid_solid_mul_color_solid(start, *src, r, g, b);
468 end = start + (size & 7);
469 for (; start < end; start++, src++)
470 _soft16_pt_blend_solid_solid_mul_color_solid(start, *src, r, g, b);