libvisual  0.5.0
lv_alpha_blend.c
1 #include <config.h>
2 #include "lv_alpha_blend.h"
3 #include "lv_common.h"
4 #include "lv_cpu.h"
5 #include "lv_alpha_blend_orc.h"
6 
7 #pragma pack(1)
8 
9 typedef struct {
10 #if VISUAL_LITTLE_ENDIAN == 1
11  uint16_t b:5, g:6, r:5;
12 #else
13  uint16_t r:5, g:6, b:5;
14 #endif
15 } rgb16_t;
16 
17 #pragma pack()
18 
19 void visual_alpha_blend_8 (uint8_t *LV_RESTRICT dest, const uint8_t *LV_RESTRICT src1, const uint8_t *LV_RESTRICT src2, visual_size_t size, uint8_t alpha)
20 {
21  simd_interpolate_8 (dest, src1, src2, alpha, (int) size);
22 }
23 
24 void visual_alpha_blend_16 (uint8_t *LV_RESTRICT dest, const uint8_t *LV_RESTRICT src1, const uint8_t *LV_RESTRICT src2, visual_size_t size, uint8_t alpha)
25 {
26  rgb16_t *destr = (rgb16_t *) dest;
27  rgb16_t *src1r = (rgb16_t *) src1;
28  rgb16_t *src2r = (rgb16_t *) src2;
29  visual_size_t i;
30 
31  for (i = 0; i < size / 2; i++) {
32  destr[i].r = (alpha * (src2r[i].r - src1r[i].r)) / 255 + src1r[i].r;
33  destr[i].g = (alpha * (src2r[i].g - src1r[i].g)) / 255 + src1r[i].g;
34  destr[i].b = (alpha * (src2r[i].b - src1r[i].b)) / 255 + src1r[i].b;
35  }
36 }
37 
38 void visual_alpha_blend_24 (uint8_t *LV_RESTRICT dest, const uint8_t *LV_RESTRICT src1, const uint8_t *LV_RESTRICT src2, visual_size_t size, uint8_t alpha)
39 {
40  simd_interpolate_8 (dest, src1, src2, alpha, (int) size * 3);
41 }
42 
43 void visual_alpha_blend_32 (uint8_t *LV_RESTRICT dest, const uint8_t *LV_RESTRICT src1, const uint8_t *LV_RESTRICT src2, visual_size_t size, uint8_t alpha)
44 {
45  simd_interpolate_8 (dest, src1, src2, alpha, (int) size * 4);
46 }