summaryrefslogtreecommitdiff
path: root/src/static_libs/draw
diff options
context:
space:
mode:
authorJean-Philippe Andre <jp.andre@samsung.com>2015-12-04 14:05:20 +0900
committerJean-Philippe Andre <jp.andre@samsung.com>2015-12-04 16:09:47 +0900
commit9457411861077d4d286a92a0e02266dfe6c9f668 (patch)
tree4ba75d5c88f77d31506aa0e83ad7161c2de9bbb2 /src/static_libs/draw
parent9f1eb3e021d3050367dcb096d2091d91061e33eb (diff)
Draw: Add new mask functions
Copy & blend to uint32 with a uint8 mask + color.
Diffstat (limited to 'src/static_libs/draw')
-rw-r--r--src/static_libs/draw/draw.h20
-rw-r--r--src/static_libs/draw/draw_main.c39
-rw-r--r--src/static_libs/draw/draw_private.h1
3 files changed, 53 insertions, 7 deletions
diff --git a/src/static_libs/draw/draw.h b/src/static_libs/draw/draw.h
index c25517d93e..1c15a0d47f 100644
--- a/src/static_libs/draw/draw.h
+++ b/src/static_libs/draw/draw.h
@@ -9,13 +9,15 @@
9 9
10typedef void (*RGBA_Comp_Func) (uint32_t *dest, const uint32_t *src, int length, uint32_t mul_col, uint32_t const_alpha); 10typedef void (*RGBA_Comp_Func) (uint32_t *dest, const uint32_t *src, int length, uint32_t mul_col, uint32_t const_alpha);
11typedef void (*RGBA_Comp_Func_Solid) (uint32_t *dest, int length, uint32_t color, uint32_t const_alpha); 11typedef void (*RGBA_Comp_Func_Solid) (uint32_t *dest, int length, uint32_t color, uint32_t const_alpha);
12typedef void (*RGBA_Comp_Func_Mask) (uint32_t *dest, uint8_t *mask, int length, uint32_t color);
12typedef void (*Alpha_Gfx_Func) (uint8_t *src, uint8_t *dst, int len); 13typedef void (*Alpha_Gfx_Func) (uint8_t *src, uint8_t *dst, int len);
13 14
14int efl_draw_init(void); 15int efl_draw_init(void);
15 16
16RGBA_Comp_Func efl_draw_func_span_get(Efl_Gfx_Render_Op op, uint32_t color, Eina_Bool src_alpha); 17RGBA_Comp_Func efl_draw_func_span_get (Efl_Gfx_Render_Op op, uint32_t color, Eina_Bool src_alpha);
17RGBA_Comp_Func_Solid efl_draw_func_solid_span_get(Efl_Gfx_Render_Op op, uint32_t color); 18RGBA_Comp_Func_Solid efl_draw_func_solid_span_get (Efl_Gfx_Render_Op op, uint32_t color);
18Alpha_Gfx_Func efl_draw_alpha_func_get(Efl_Gfx_Render_Op op, Eina_Bool has_mask); 19RGBA_Comp_Func_Mask efl_draw_func_mask_span_get (Efl_Gfx_Render_Op op, uint32_t color);
20Alpha_Gfx_Func efl_draw_alpha_func_get (Efl_Gfx_Render_Op op, Eina_Bool has_mask);
19 21
20 22
21/* common sw draw helpers */ 23/* common sw draw helpers */
@@ -57,12 +59,16 @@ Alpha_Gfx_Func efl_draw_alpha_func_get(Efl_Gfx_Render_Op op, Eina_Bool has_mask)
57 ((((((x) & 0xff00) * ((y) & 0xff00)) + 0xff0000) >> 16) & 0xff00) + \ 59 ((((((x) & 0xff00) * ((y) & 0xff00)) + 0xff0000) >> 16) & 0xff00) + \
58 (((((x) & 0xff) * ((y) & 0xff)) + 0xff) >> 8) ) 60 (((((x) & 0xff) * ((y) & 0xff)) + 0xff) >> 8) )
59 61
60#define DRAW_MUL_256(a, c) \ 62/* alpha from 1 to 256 */
61 ( (((((c) >> 8) & 0x00ff00ff) * (a)) & 0xff00ff00) + \ 63static inline uint32_t
62 (((((c) & 0x00ff00ff) * (a)) >> 8) & 0x00ff00ff) ) 64draw_mul_256(int a, uint32_t c)
65{
66 return (((((c) >> 8) & 0x00ff00ff) * (a)) & 0xff00ff00) |
67 (((((c) & 0x00ff00ff) * (a)) >> 8) & 0x00ff00ff);
68}
63 69
64static inline uint32_t 70static inline uint32_t
65draw_interpolate_256(uint32_t x, uint32_t a, uint32_t y, uint32_t b) 71draw_interpolate_256(uint32_t x, int a, uint32_t y, int b)
66{ 72{
67 uint32_t t = (x & 0xff00ff) * a + (y & 0xff00ff) * b; 73 uint32_t t = (x & 0xff00ff) * a + (y & 0xff00ff) * b;
68 t >>= 8; 74 t >>= 8;
diff --git a/src/static_libs/draw/draw_main.c b/src/static_libs/draw/draw_main.c
index 1d19de3a1a..915adf1e44 100644
--- a/src/static_libs/draw/draw_main.c
+++ b/src/static_libs/draw/draw_main.c
@@ -128,6 +128,39 @@ _comp_func_source(uint32_t *dest, const uint32_t *src, int length, uint32_t colo
128 } 128 }
129} 129}
130 130
131/* s = m * color
132 * d = d * (1-sa) + s * sa
133 */
134static void
135_comp_func_mask_blend(uint32_t *dest, uint8_t *mask, int length, uint32_t color)
136{
137 int k;
138
139 for (k = 0; k < length; k++, dest++, mask++)
140 {
141 uint32_t c = draw_mul_256(*mask, color);
142 int a = 256 - (c >> 24);
143 *dest = c + draw_mul_256(a, *dest);
144 }
145}
146
147static void
148_comp_func_mask_copy(uint32_t *dest, uint8_t *mask, int length, uint32_t color)
149{
150 int k;
151
152 for (k = 0; k < length; k++, dest++, mask++)
153 {
154 int a = (*mask & 0x80) ? *mask + 1 : *mask;
155 *dest = draw_mul_256(a, color);
156 }
157}
158
159RGBA_Comp_Func_Mask func_for_mode_mask[EFL_GFX_RENDER_OP_LAST] = {
160 _comp_func_mask_blend,
161 _comp_func_mask_copy
162};
163
131RGBA_Comp_Func_Solid func_for_mode_solid[EFL_GFX_RENDER_OP_LAST] = { 164RGBA_Comp_Func_Solid func_for_mode_solid[EFL_GFX_RENDER_OP_LAST] = {
132 _comp_func_solid_source_over, 165 _comp_func_solid_source_over,
133 _comp_func_solid_source 166 _comp_func_solid_source
@@ -138,6 +171,12 @@ RGBA_Comp_Func func_for_mode[EFL_GFX_RENDER_OP_LAST] = {
138 _comp_func_source 171 _comp_func_source
139}; 172};
140 173
174RGBA_Comp_Func_Mask
175efl_draw_func_mask_span_get(Efl_Gfx_Render_Op op, uint32_t color EINA_UNUSED)
176{
177 return func_for_mode_mask[op];
178}
179
141RGBA_Comp_Func_Solid 180RGBA_Comp_Func_Solid
142efl_draw_func_solid_span_get(Efl_Gfx_Render_Op op, uint32_t color) 181efl_draw_func_solid_span_get(Efl_Gfx_Render_Op op, uint32_t color)
143{ 182{
diff --git a/src/static_libs/draw/draw_private.h b/src/static_libs/draw/draw_private.h
index 8d056a86db..cae3b195fe 100644
--- a/src/static_libs/draw/draw_private.h
+++ b/src/static_libs/draw/draw_private.h
@@ -25,6 +25,7 @@
25 } \ 25 } \
26 } 26 }
27 27
28/* 255 - alpha */
28static inline int 29static inline int
29alpha_inverse(uint32_t color) 30alpha_inverse(uint32_t color)
30{ 31{