summaryrefslogtreecommitdiff
path: root/src/lib/evas/common/evas_alpha_main.c
diff options
context:
space:
mode:
authorJean-Philippe Andre <jp.andre@samsung.com>2013-12-09 14:46:12 +0900
committerJean-Philippe Andre <jp.andre@samsung.com>2014-02-07 15:38:42 +0900
commitd8301fae6e650e179cd3046874faabe6909f6531 (patch)
tree7722eeaf5b55339887681687da13de0ca6e8207a /src/lib/evas/common/evas_alpha_main.c
parent71c7d0e9ad87c79a3de203399ad53c5a2b5e9bc6 (diff)
Evas: Add support for Alpha buffers
Evas is an RGBA only engine, BUT we also use some alpha masks, especially in the font rendering pipeline. This commit adds basic support for alpha buffer operations (blend and copy). RGBA_Image can then point to either alpha-only data, if its colorspace is grey.
Diffstat (limited to 'src/lib/evas/common/evas_alpha_main.c')
-rw-r--r--src/lib/evas/common/evas_alpha_main.c90
1 files changed, 90 insertions, 0 deletions
diff --git a/src/lib/evas/common/evas_alpha_main.c b/src/lib/evas/common/evas_alpha_main.c
new file mode 100644
index 0000000000..6bd654cec1
--- /dev/null
+++ b/src/lib/evas/common/evas_alpha_main.c
@@ -0,0 +1,90 @@
1#include "evas_common_private.h"
2#include "evas_blend_private.h"
3
4/** default op: d = d*(1-sa) + s */
5static void
6_alpha_func_blend(DATA8 *src, DATA8 *dst, int len)
7{
8 int k;
9
10 EINA_SAFETY_ON_NULL_RETURN(src);
11 EINA_SAFETY_ON_NULL_RETURN(dst);
12
13 for (k = len; k; k--)
14 {
15 int val = (*dst * (255 - *src)) / 255 + *src;
16 *dst++ = val;
17 src++;
18 }
19}
20
21/** d = s */
22static void
23_alpha_func_copy(DATA8 *src, DATA8 *dst, int len)
24{
25 EINA_SAFETY_ON_NULL_RETURN(src);
26 EINA_SAFETY_ON_NULL_RETURN(dst);
27
28 memcpy(dst, src, len);
29}
30
31/** d = d*s */
32static void
33_alpha_func_mul(DATA8 *src, DATA8 *dst, int len)
34{
35 int k;
36
37 EINA_SAFETY_ON_NULL_RETURN(src);
38 EINA_SAFETY_ON_NULL_RETURN(dst);
39
40 for (k = len; k; k--)
41 {
42 int val = (*dst * *src) / 255;
43 *dst++ = val;
44 src++;
45 }
46}
47
48
49#if 0
50// Reference ops. In case of alpha, s == sa.
51EVAS_RENDER_BLEND = 0, /**< default op: d = d*(1-sa) + s */
52EVAS_RENDER_BLEND_REL = 1, /**< d = d*(1 - sa) + s*da */
53EVAS_RENDER_COPY = 2, /**< d = s */
54EVAS_RENDER_COPY_REL = 3, /**< d = s*da */
55EVAS_RENDER_ADD = 4, /* d = d + s */
56EVAS_RENDER_ADD_REL = 5, /**< d = d + s*da */
57EVAS_RENDER_SUB = 6, /**< d = d - s */
58EVAS_RENDER_SUB_REL = 7, /* d = d - s*da */
59EVAS_RENDER_TINT = 8, /**< d = d*s + d*(1 - sa) + s*(1 - da) */
60EVAS_RENDER_TINT_REL = 9, /**< d = d*(1 - sa + s) */
61EVAS_RENDER_MASK = 10, /**< d = d*sa */
62EVAS_RENDER_MUL = 11, /**< d = d*s */
63#endif
64
65Alpha_Gfx_Func
66evas_common_alpha_func_get(int op)
67{
68 INF("Requesting alpha function with OP %d", op);
69 switch (op)
70 {
71 case EVAS_RENDER_BLEND:
72 return _alpha_func_blend;
73// case EVAS_RENDER_BLEND_REL:
74 case EVAS_RENDER_COPY:
75 return _alpha_func_copy;
76// case EVAS_RENDER_COPY_REL:
77// case EVAS_RENDER_ADD:
78// case EVAS_RENDER_ADD_REL:
79// case EVAS_RENDER_SUB:
80// case EVAS_RENDER_SUB_REL:
81// case EVAS_RENDER_TINT:
82// case EVAS_RENDER_TINT_REL:
83 case EVAS_RENDER_MASK:
84 case EVAS_RENDER_MUL:
85 return _alpha_func_mul;
86 default:
87 ERR("Not implemented yet.");
88 return NULL;
89 }
90}