summaryrefslogtreecommitdiff
path: root/src/static_libs/draw/draw_alpha_main.c
blob: 8424d958594d8336c4e710a5990bb68628133c94 (plain)
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
#include "draw_private.h"

/** default op: d = d*(1-sa) + s */
static void
_alpha_func_blend(uint8_t *dst, const uint8_t *src, int len)
{
   int k;

   EINA_SAFETY_ON_NULL_RETURN(src);
   EINA_SAFETY_ON_NULL_RETURN(dst);

   for (k = len; k; k--)
     {
        int val = (*dst * (255 - *src)) / 255 + *src;
        *dst++ = val;
        src++;
     }
}

/** d = s */
static void
_alpha_func_copy(uint8_t *dst, const uint8_t *src, int len)
{
   EINA_SAFETY_ON_NULL_RETURN(src);
   EINA_SAFETY_ON_NULL_RETURN(dst);

   memcpy(dst, src, len);
}

/** d = d*s */
static void
_alpha_func_mul(uint8_t *dst, const uint8_t *src, int len)
{
   int k;

   EINA_SAFETY_ON_NULL_RETURN(src);
   EINA_SAFETY_ON_NULL_RETURN(dst);

   for (k = len; k; k--)
     {
        int val = (*dst * *src) / 255;
        *dst++ = val;
        src++;
     }
}

Draw_Func_Alpha
efl_draw_alpha_func_get(Efl_Gfx_Render_Op op, Eina_Bool has_mask)
{
   if (!has_mask)
     {
        if (op == EFL_GFX_RENDER_OP_BLEND)
          return _alpha_func_blend;
        else
          return _alpha_func_copy;
     }
   else
     return _alpha_func_mul;
}