summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAmitesh Singh <amitesh.sh@samsung.com>2018-01-10 15:56:43 +0900
committerAmitesh Singh <amitesh.sh@samsung.com>2018-01-12 12:22:02 +0900
commitd18de6b1b8c3b5832024278df4ad3c594ad2f6af (patch)
tree602781f1d4853e5f6f5b74dd38a135ff6a757862
parentdda427dc51e81fb2455982832b7c726497776659 (diff)
Efl.Gfx.color: move the common code to util file.
color class & other common classes will use it later.
-rw-r--r--src/Makefile_Efl.am1
-rw-r--r--src/lib/efl/interfaces/efl_gfx_color.c82
-rw-r--r--src/lib/efl/interfaces/efl_gfx_color_internal.c78
-rw-r--r--src/lib/efl/interfaces/efl_gfx_color_internal.h8
4 files changed, 90 insertions, 79 deletions
diff --git a/src/Makefile_Efl.am b/src/Makefile_Efl.am
index 30b6cdb040..77a8c28020 100644
--- a/src/Makefile_Efl.am
+++ b/src/Makefile_Efl.am
@@ -139,6 +139,7 @@ lib/efl/interfaces/efl_io_queue.c \
139lib/efl/interfaces/efl_observer.c \ 139lib/efl/interfaces/efl_observer.c \
140lib/efl/interfaces/efl_file.c \ 140lib/efl/interfaces/efl_file.c \
141lib/efl/interfaces/efl_ui_format.c \ 141lib/efl/interfaces/efl_ui_format.c \
142lib/efl/interfaces/efl_gfx_color_internal.c \
142lib/efl/interfaces/efl_gfx_color.c \ 143lib/efl/interfaces/efl_gfx_color.c \
143lib/efl/interfaces/efl_text_markup_util.c \ 144lib/efl/interfaces/efl_text_markup_util.c \
144$(NULL) 145$(NULL)
diff --git a/src/lib/efl/interfaces/efl_gfx_color.c b/src/lib/efl/interfaces/efl_gfx_color.c
index 91f8a4fd32..ab679cdf41 100644
--- a/src/lib/efl/interfaces/efl_gfx_color.c
+++ b/src/lib/efl/interfaces/efl_gfx_color.c
@@ -1,5 +1,6 @@
1#include "config.h" 1#include "config.h"
2#include "Efl.h" 2#include "Efl.h"
3#include "efl_gfx_color_internal.h"
3 4
4static int 5static int
5_format_clean_param(Eina_Tmpstr *s) 6_format_clean_param(Eina_Tmpstr *s)
@@ -19,83 +20,6 @@ _format_clean_param(Eina_Tmpstr *s)
19 return len; 20 return len;
20} 21}
21 22
22static int
23_hex_string_get(char ch, Eina_Bool *ok)
24{
25 if ((ch >= '0') && (ch <= '9')) return (ch - '0');
26 else if ((ch >= 'A') && (ch <= 'F')) return (ch - 'A' + 10);
27 else if ((ch >= 'a') && (ch <= 'f')) return (ch - 'a' + 10);
28 *ok = EINA_FALSE;
29 return 0;
30}
31
32/**
33 * @internal
34 * Parses a string of one of the formas:
35 * 1. "#RRGGBB"
36 * 2. "#RRGGBBAA"
37 * 3. "#RGB"
38 * 4. "#RGBA"
39 * To the rgba values.
40 *
41 * @param[in] str The string to parse - NOT NULL.
42 * @param[out] r The Red value - NOT NULL.
43 * @param[out] g The Green value - NOT NULL.
44 * @param[out] b The Blue value - NOT NULL.
45 * @param[out] a The Alpha value - NOT NULL.
46 */
47static Eina_Bool
48_format_color_parse(const char *str, int slen,
49 unsigned char *r, unsigned char *g,
50 unsigned char *b, unsigned char *a)
51{
52 Eina_Bool v = EINA_TRUE;
53
54 *r = *g = *b = *a = 0;
55
56 if (slen == 7) /* #RRGGBB */
57 {
58 *r = (_hex_string_get(str[1], &v) << 4) | (_hex_string_get(str[2], &v));
59 *g = (_hex_string_get(str[3], &v) << 4) | (_hex_string_get(str[4], &v));
60 *b = (_hex_string_get(str[5], &v) << 4) | (_hex_string_get(str[6], &v));
61 *a = 0xff;
62 }
63 else if (slen == 9) /* #RRGGBBAA */
64 {
65 *r = (_hex_string_get(str[1], &v) << 4) | (_hex_string_get(str[2], &v));
66 *g = (_hex_string_get(str[3], &v) << 4) | (_hex_string_get(str[4], &v));
67 *b = (_hex_string_get(str[5], &v) << 4) | (_hex_string_get(str[6], &v));
68 *a = (_hex_string_get(str[7], &v) << 4) | (_hex_string_get(str[8], &v));
69 }
70 else if (slen == 4) /* #RGB */
71 {
72 *r = _hex_string_get(str[1], &v);
73 *r = (*r << 4) | *r;
74 *g = _hex_string_get(str[2], &v);
75 *g = (*g << 4) | *g;
76 *b = _hex_string_get(str[3], &v);
77 *b = (*b << 4) | *b;
78 *a = 0xff;
79 }
80 else if (slen == 5) /* #RGBA */
81 {
82 *r = _hex_string_get(str[1], &v);
83 *r = (*r << 4) | *r;
84 *g = _hex_string_get(str[2], &v);
85 *g = (*g << 4) | *g;
86 *b = _hex_string_get(str[3], &v);
87 *b = (*b << 4) | *b;
88 *a = _hex_string_get(str[4], &v);
89 *a = (*a << 4) | *a;
90 }
91 else v = EINA_FALSE;
92
93 *r = (*r * *a) / 255;
94 *g = (*g * *a) / 255;
95 *b = (*b * *a) / 255;
96 return v;
97}
98
99EOLIAN static void 23EOLIAN static void
100_efl_gfx_color_color_code_set(Eo *obj, void *_pd EINA_UNUSED, const char *colorcode) 24_efl_gfx_color_color_code_set(Eo *obj, void *_pd EINA_UNUSED, const char *colorcode)
101{ 25{
@@ -104,7 +28,7 @@ _efl_gfx_color_color_code_set(Eo *obj, void *_pd EINA_UNUSED, const char *colorc
104 28
105 len = _format_clean_param(colorcode); 29 len = _format_clean_param(colorcode);
106 30
107 _format_color_parse(colorcode, len, &r, &g, &b, &a); 31 _gfx_color_format_color_parse(colorcode, len, &r, &g, &b, &a);
108 efl_gfx_color_set(obj, r, g, b, a); 32 efl_gfx_color_set(obj, r, g, b, a);
109} 33}
110 34
@@ -126,7 +50,7 @@ _efl_gfx_color_color_class_code_set(Eo *obj, void *_pd EINA_UNUSED, const char *
126 50
127 len = _format_clean_param(colorcode); 51 len = _format_clean_param(colorcode);
128 52
129 _format_color_parse(colorcode, len, &r, &g, &b, &a); 53 _gfx_color_format_color_parse(colorcode, len, &r, &g, &b, &a);
130 efl_gfx_color_class_set(obj, color_class, layer, r, g, b, a); 54 efl_gfx_color_class_set(obj, color_class, layer, r, g, b, a);
131} 55}
132 56
diff --git a/src/lib/efl/interfaces/efl_gfx_color_internal.c b/src/lib/efl/interfaces/efl_gfx_color_internal.c
new file mode 100644
index 0000000000..c877a95e63
--- /dev/null
+++ b/src/lib/efl/interfaces/efl_gfx_color_internal.c
@@ -0,0 +1,78 @@
1#include "efl_gfx_color_internal.h"
2
3static int
4_hex_string_get(char ch, Eina_Bool *ok)
5{
6 if ((ch >= '0') && (ch <= '9')) return (ch - '0');
7 else if ((ch >= 'A') && (ch <= 'F')) return (ch - 'A' + 10);
8 else if ((ch >= 'a') && (ch <= 'f')) return (ch - 'a' + 10);
9 *ok = EINA_FALSE;
10 return 0;
11}
12
13/**
14 * @internal
15 * Parses a string of one of the formas:
16 * 1. "#RRGGBB"
17 * 2. "#RRGGBBAA"
18 * 3. "#RGB"
19 * 4. "#RGBA"
20 * To the rgba values.
21 *
22 * @param[in] str The string to parse - NOT NULL.
23 * @param[out] r The Red value - NOT NULL.
24 * @param[out] g The Green value - NOT NULL.
25 * @param[out] b The Blue value - NOT NULL.
26 * @param[out] a The Alpha value - NOT NULL.
27 */
28Eina_Bool
29_gfx_color_format_color_parse(const char *str, int slen,
30 unsigned char *r, unsigned char *g,
31 unsigned char *b, unsigned char *a)
32{
33 Eina_Bool v = EINA_TRUE;
34
35 *r = *g = *b = *a = 0;
36
37 if (slen == 7) /* #RRGGBB */
38 {
39 *r = (_hex_string_get(str[1], &v) << 4) | (_hex_string_get(str[2], &v));
40 *g = (_hex_string_get(str[3], &v) << 4) | (_hex_string_get(str[4], &v));
41 *b = (_hex_string_get(str[5], &v) << 4) | (_hex_string_get(str[6], &v));
42 *a = 0xff;
43 }
44 else if (slen == 9) /* #RRGGBBAA */
45 {
46 *r = (_hex_string_get(str[1], &v) << 4) | (_hex_string_get(str[2], &v));
47 *g = (_hex_string_get(str[3], &v) << 4) | (_hex_string_get(str[4], &v));
48 *b = (_hex_string_get(str[5], &v) << 4) | (_hex_string_get(str[6], &v));
49 *a = (_hex_string_get(str[7], &v) << 4) | (_hex_string_get(str[8], &v));
50 }
51 else if (slen == 4) /* #RGB */
52 {
53 *r = _hex_string_get(str[1], &v);
54 *r = (*r << 4) | *r;
55 *g = _hex_string_get(str[2], &v);
56 *g = (*g << 4) | *g;
57 *b = _hex_string_get(str[3], &v);
58 *b = (*b << 4) | *b;
59 *a = 0xff;
60 }
61 else if (slen == 5) /* #RGBA */
62 {
63 *r = _hex_string_get(str[1], &v);
64 *r = (*r << 4) | *r;
65 *g = _hex_string_get(str[2], &v);
66 *g = (*g << 4) | *g;
67 *b = _hex_string_get(str[3], &v);
68 *b = (*b << 4) | *b;
69 *a = _hex_string_get(str[4], &v);
70 *a = (*a << 4) | *a;
71 }
72 else v = EINA_FALSE;
73
74 *r = (*r * *a) / 255;
75 *g = (*g * *a) / 255;
76 *b = (*b * *a) / 255;
77 return v;
78}
diff --git a/src/lib/efl/interfaces/efl_gfx_color_internal.h b/src/lib/efl/interfaces/efl_gfx_color_internal.h
new file mode 100644
index 0000000000..076413cc5b
--- /dev/null
+++ b/src/lib/efl/interfaces/efl_gfx_color_internal.h
@@ -0,0 +1,8 @@
1#ifndef _GFX_COLOR_UTIL_H
2#define _GFX_COLOR_UTIL_H
3
4#include <Eina.h>
5
6Eina_Bool _gfx_color_format_color_parse(const char *str, int slen, unsigned char *r, unsigned char *g, unsigned char *b, unsigned char *a);
7
8#endif \ No newline at end of file