jpeg pushed a commit to branch master.

http://git.enlightenment.org/core/efl.git/commit/?id=9457411861077d4d286a92a0e02266dfe6c9f668

commit 9457411861077d4d286a92a0e02266dfe6c9f668
Author: Jean-Philippe Andre <jp.an...@samsung.com>
Date:   Fri Dec 4 14:05:20 2015 +0900

    Draw: Add new mask functions
    
    Copy & blend to uint32 with a uint8 mask + color.
---
 src/static_libs/draw/draw.h         | 20 ++++++++++++-------
 src/static_libs/draw/draw_main.c    | 39 +++++++++++++++++++++++++++++++++++++
 src/static_libs/draw/draw_private.h |  1 +
 3 files changed, 53 insertions(+), 7 deletions(-)

diff --git a/src/static_libs/draw/draw.h b/src/static_libs/draw/draw.h
index c25517d..1c15a0d 100644
--- a/src/static_libs/draw/draw.h
+++ b/src/static_libs/draw/draw.h
@@ -9,13 +9,15 @@
 
 typedef void (*RGBA_Comp_Func)       (uint32_t *dest, const uint32_t *src, int 
length, uint32_t mul_col, uint32_t const_alpha);
 typedef void (*RGBA_Comp_Func_Solid) (uint32_t *dest, int length, uint32_t 
color, uint32_t const_alpha);
+typedef void (*RGBA_Comp_Func_Mask)  (uint32_t *dest, uint8_t *mask, int 
length, uint32_t color);
 typedef void (*Alpha_Gfx_Func)       (uint8_t *src, uint8_t *dst, int len);
 
 int efl_draw_init(void);
 
-RGBA_Comp_Func efl_draw_func_span_get(Efl_Gfx_Render_Op op, uint32_t color, 
Eina_Bool src_alpha);
-RGBA_Comp_Func_Solid efl_draw_func_solid_span_get(Efl_Gfx_Render_Op op, 
uint32_t color);
-Alpha_Gfx_Func efl_draw_alpha_func_get(Efl_Gfx_Render_Op op, Eina_Bool 
has_mask);
+RGBA_Comp_Func       efl_draw_func_span_get         (Efl_Gfx_Render_Op op, 
uint32_t color, Eina_Bool src_alpha);
+RGBA_Comp_Func_Solid efl_draw_func_solid_span_get   (Efl_Gfx_Render_Op op, 
uint32_t color);
+RGBA_Comp_Func_Mask  efl_draw_func_mask_span_get    (Efl_Gfx_Render_Op op, 
uint32_t color);
+Alpha_Gfx_Func       efl_draw_alpha_func_get        (Efl_Gfx_Render_Op op, 
Eina_Bool has_mask);
 
 
 /* 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)
    ((((((x) & 0xff00) * ((y) & 0xff00)) + 0xff0000) >> 16) & 0xff00) + \
    (((((x) & 0xff) * ((y) & 0xff)) + 0xff) >> 8) )
 
-#define DRAW_MUL_256(a, c) \
- ( (((((c) >> 8) & 0x00ff00ff) * (a)) & 0xff00ff00) + \
-   (((((c) & 0x00ff00ff) * (a)) >> 8) & 0x00ff00ff) )
+/* alpha from 1 to 256 */
+static inline uint32_t
+draw_mul_256(int a, uint32_t c)
+{
+   return (((((c) >> 8) & 0x00ff00ff) * (a)) & 0xff00ff00) |
+         (((((c) & 0x00ff00ff) * (a)) >> 8) & 0x00ff00ff);
+}
 
 static inline uint32_t
-draw_interpolate_256(uint32_t x, uint32_t a, uint32_t y, uint32_t b)
+draw_interpolate_256(uint32_t x, int a, uint32_t y, int b)
 {
    uint32_t t = (x & 0xff00ff) * a + (y & 0xff00ff) * b;
    t >>= 8;
diff --git a/src/static_libs/draw/draw_main.c b/src/static_libs/draw/draw_main.c
index 1d19de3..915adf1 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
      }
 }
 
+/* s = m * color
+ * d = d * (1-sa) + s * sa
+ */
+static void
+_comp_func_mask_blend(uint32_t *dest, uint8_t *mask, int length, uint32_t 
color)
+{
+   int k;
+
+   for (k = 0; k < length; k++, dest++, mask++)
+     {
+        uint32_t c = draw_mul_256(*mask, color);
+        int a = 256 - (c >> 24);
+        *dest = c + draw_mul_256(a, *dest);
+     }
+}
+
+static void
+_comp_func_mask_copy(uint32_t *dest, uint8_t *mask, int length, uint32_t color)
+{
+   int k;
+
+   for (k = 0; k < length; k++, dest++, mask++)
+     {
+        int a = (*mask & 0x80) ? *mask + 1 : *mask;
+        *dest = draw_mul_256(a, color);
+     }
+}
+
+RGBA_Comp_Func_Mask func_for_mode_mask[EFL_GFX_RENDER_OP_LAST] = {
+   _comp_func_mask_blend,
+   _comp_func_mask_copy
+};
+
 RGBA_Comp_Func_Solid func_for_mode_solid[EFL_GFX_RENDER_OP_LAST] = {
   _comp_func_solid_source_over,
   _comp_func_solid_source
@@ -138,6 +171,12 @@ RGBA_Comp_Func func_for_mode[EFL_GFX_RENDER_OP_LAST] = {
   _comp_func_source
 };
 
+RGBA_Comp_Func_Mask
+efl_draw_func_mask_span_get(Efl_Gfx_Render_Op op, uint32_t color EINA_UNUSED)
+{
+   return func_for_mode_mask[op];
+}
+
 RGBA_Comp_Func_Solid
 efl_draw_func_solid_span_get(Efl_Gfx_Render_Op op, uint32_t color)
 {
diff --git a/src/static_libs/draw/draw_private.h 
b/src/static_libs/draw/draw_private.h
index 8d056a8..cae3b19 100644
--- a/src/static_libs/draw/draw_private.h
+++ b/src/static_libs/draw/draw_private.h
@@ -25,6 +25,7 @@
       } \
    }
 
+/* 255 - alpha */
 static inline int
 alpha_inverse(uint32_t color)
 {

-- 


Reply via email to