summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorShinwoo Kim <cinoo.kim@samsung.com>2019-10-14 11:13:15 +0900
committerShinwoo Kim <cinoo.kim@samsung.com>2019-10-14 11:13:40 +0900
commit431d62d095761eb82236a2e4d65fd62a90bf72c6 (patch)
tree22e8e20779dd5149095f92dcae0888fc0db1fcde
parentf0b8c6b94e13507766212d24575ef791747d9d97 (diff)
evas filter: Implement grayscale filter in SW
Summary: Initial version implementing grayscale filter in SW. Test Plan: 1. Create filter_example with following. efl_gfx_filter_program_set(image, "grayscale ()", "grayscale"); 1. Run. ./filter_example Reviewers: Hermet, jsuya Reviewed By: Hermet Subscribers: cedric, #reviewers, #committers Tags: #efl Differential Revision: https://phab.enlightenment.org/D10219
-rw-r--r--src/lib/evas/software_generic/filters/meson.build1
-rw-r--r--src/modules/evas/engines/software_generic/evas_engine.c1
-rw-r--r--src/modules/evas/engines/software_generic/filters/evas_engine_filter.h1
-rw-r--r--src/modules/evas/engines/software_generic/filters/evas_filter_grayscale.c62
4 files changed, 65 insertions, 0 deletions
diff --git a/src/lib/evas/software_generic/filters/meson.build b/src/lib/evas/software_generic/filters/meson.build
index b23ce09b1d..17c7bce8c2 100644
--- a/src/lib/evas/software_generic/filters/meson.build
+++ b/src/lib/evas/software_generic/filters/meson.build
@@ -10,6 +10,7 @@ raw_evas_src = [
10 'evas_filter_fill.c', 10 'evas_filter_fill.c',
11 'evas_filter_mask.c', 11 'evas_filter_mask.c',
12 'evas_filter_transform.c', 12 'evas_filter_transform.c',
13 'evas_filter_grayscale.c',
13] 14]
14 15
15foreach file : raw_evas_src 16foreach file : raw_evas_src
diff --git a/src/modules/evas/engines/software_generic/evas_engine.c b/src/modules/evas/engines/software_generic/evas_engine.c
index 0dc6c64b52..085f053b1d 100644
--- a/src/modules/evas/engines/software_generic/evas_engine.c
+++ b/src/modules/evas/engines/software_generic/evas_engine.c
@@ -4544,6 +4544,7 @@ _gfx_filter_func_get(Evas_Filter_Command *cmd)
4544 case EVAS_FILTER_MODE_FILL: func = eng_filter_fill_func_get(cmd); break; 4544 case EVAS_FILTER_MODE_FILL: func = eng_filter_fill_func_get(cmd); break;
4545 case EVAS_FILTER_MODE_MASK: func = eng_filter_mask_func_get(cmd); break; 4545 case EVAS_FILTER_MODE_MASK: func = eng_filter_mask_func_get(cmd); break;
4546 case EVAS_FILTER_MODE_TRANSFORM: func = eng_filter_transform_func_get(cmd); break; 4546 case EVAS_FILTER_MODE_TRANSFORM: func = eng_filter_transform_func_get(cmd); break;
4547 case EVAS_FILTER_MODE_GRAYSCALE: func = eng_filter_grayscale_func_get(cmd); break;
4547 default: return NULL; 4548 default: return NULL;
4548 } 4549 }
4549 4550
diff --git a/src/modules/evas/engines/software_generic/filters/evas_engine_filter.h b/src/modules/evas/engines/software_generic/filters/evas_engine_filter.h
index f8bfebdc11..33998f9344 100644
--- a/src/modules/evas/engines/software_generic/filters/evas_engine_filter.h
+++ b/src/modules/evas/engines/software_generic/filters/evas_engine_filter.h
@@ -13,5 +13,6 @@ Software_Filter_Func eng_filter_displace_func_get(Evas_Filter_Command *cmd);
13Software_Filter_Func eng_filter_fill_func_get(Evas_Filter_Command *cmd); 13Software_Filter_Func eng_filter_fill_func_get(Evas_Filter_Command *cmd);
14Software_Filter_Func eng_filter_mask_func_get(Evas_Filter_Command *cmd); 14Software_Filter_Func eng_filter_mask_func_get(Evas_Filter_Command *cmd);
15Software_Filter_Func eng_filter_transform_func_get(Evas_Filter_Command *cmd); 15Software_Filter_Func eng_filter_transform_func_get(Evas_Filter_Command *cmd);
16Software_Filter_Func eng_filter_grayscale_func_get(Evas_Filter_Command *cmd);
16 17
17#endif // EVAS_ENGINE_FILTER_H 18#endif // EVAS_ENGINE_FILTER_H
diff --git a/src/modules/evas/engines/software_generic/filters/evas_filter_grayscale.c b/src/modules/evas/engines/software_generic/filters/evas_filter_grayscale.c
new file mode 100644
index 0000000000..9384639916
--- /dev/null
+++ b/src/modules/evas/engines/software_generic/filters/evas_filter_grayscale.c
@@ -0,0 +1,62 @@
1#include "evas_engine_filter.h"
2
3static Eina_Bool
4_evas_filter_grayscale(Evas_Filter_Command *cmd)
5{
6 int sw, sh, dw, dh, x, y, slen, dlen;
7 unsigned int src_len, src_stride, dst_len, dst_stride;
8 Eina_Bool ret = EINA_FALSE;
9 DATA32 *ts, *td, *src = NULL, *dst = NULL;
10 DATA8 r, g, b, gry;
11
12 ector_buffer_size_get(cmd->input->buffer, &sw, &sh);
13 EINA_SAFETY_ON_FALSE_RETURN_VAL((sw > 0) && (sh > 0), ret);
14
15 ector_buffer_size_get(cmd->output->buffer, &dw, &dh);
16 EINA_SAFETY_ON_FALSE_RETURN_VAL((dw > 0) && (dh > 0), ret);
17
18 src = _buffer_map_all(cmd->input->buffer, &src_len, E_READ, E_ARGB, &src_stride);
19 EINA_SAFETY_ON_FALSE_GOTO(src, end);
20
21 dst = _buffer_map_all(cmd->output->buffer, &dst_len, E_WRITE, E_ARGB, &dst_stride);
22 EINA_SAFETY_ON_FALSE_GOTO(dst, end);
23
24 slen = src_stride / sizeof(*src);
25 dlen = dst_stride / sizeof(*dst);
26
27 ts = src;
28 td = dst;
29 for (y = 0; y < sh ; y++)
30 {
31 for (x = 0; x < sw; x++)
32 {
33 A_VAL(td + x) = A_VAL(ts + x);
34 r = R_VAL(ts + x);
35 g = G_VAL(ts + x);
36 b = B_VAL(ts + x);
37
38 /* formula from evas_common_convert_rgba_to_8bpp_gry_256_dith */
39 gry = ((r * 19596) + (g * 38470) + (b * 7472)) >> 16;
40 R_VAL(td + x) = G_VAL(td + x) = B_VAL(td + x) = gry;
41 }
42 ts += slen;
43 td += dlen;
44 }
45
46 ret = EINA_TRUE;
47
48end:
49 if (src) ector_buffer_unmap(cmd->input->buffer, src, src_len);
50 if (dst) ector_buffer_unmap(cmd->output->buffer, dst, dst_len);
51 return ret;
52}
53
54Software_Filter_Func
55eng_filter_grayscale_func_get(Evas_Filter_Command *cmd)
56{
57 EINA_SAFETY_ON_NULL_RETURN_VAL(cmd, NULL);
58 EINA_SAFETY_ON_NULL_RETURN_VAL(cmd->output, NULL);
59 EINA_SAFETY_ON_NULL_RETURN_VAL(cmd->input, NULL);
60
61 return _evas_filter_grayscale;
62}