aboutsummaryrefslogtreecommitdiffstats
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
parentecore: remove use of efl_main_loop_get from efl_net_dialer_websocket_example. (diff)
downloadefl-d18de6b1b8c3b5832024278df4ad3c594ad2f6af.tar.gz
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 \
lib/efl/interfaces/efl_observer.c \
lib/efl/interfaces/efl_file.c \
lib/efl/interfaces/efl_ui_format.c \
+lib/efl/interfaces/efl_gfx_color_internal.c \
lib/efl/interfaces/efl_gfx_color.c \
lib/efl/interfaces/efl_text_markup_util.c \
$(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 @@
#include "config.h"
#include "Efl.h"
+#include "efl_gfx_color_internal.h"
static int
_format_clean_param(Eina_Tmpstr *s)
@@ -19,83 +20,6 @@ _format_clean_param(Eina_Tmpstr *s)
return len;
}
-static int
-_hex_string_get(char ch, Eina_Bool *ok)
-{
- if ((ch >= '0') && (ch <= '9')) return (ch - '0');
- else if ((ch >= 'A') && (ch <= 'F')) return (ch - 'A' + 10);
- else if ((ch >= 'a') && (ch <= 'f')) return (ch - 'a' + 10);
- *ok = EINA_FALSE;
- return 0;
-}
-
-/**
- * @internal
- * Parses a string of one of the formas:
- * 1. "#RRGGBB"
- * 2. "#RRGGBBAA"
- * 3. "#RGB"
- * 4. "#RGBA"
- * To the rgba values.
- *
- * @param[in] str The string to parse - NOT NULL.
- * @param[out] r The Red value - NOT NULL.
- * @param[out] g The Green value - NOT NULL.
- * @param[out] b The Blue value - NOT NULL.
- * @param[out] a The Alpha value - NOT NULL.
- */
-static Eina_Bool
-_format_color_parse(const char *str, int slen,
- unsigned char *r, unsigned char *g,
- unsigned char *b, unsigned char *a)
-{
- Eina_Bool v = EINA_TRUE;
-
- *r = *g = *b = *a = 0;
-
- if (slen == 7) /* #RRGGBB */
- {
- *r = (_hex_string_get(str[1], &v) << 4) | (_hex_string_get(str[2], &v));
- *g = (_hex_string_get(str[3], &v) << 4) | (_hex_string_get(str[4], &v));
- *b = (_hex_string_get(str[5], &v) << 4) | (_hex_string_get(str[6], &v));
- *a = 0xff;
- }
- else if (slen == 9) /* #RRGGBBAA */
- {
- *r = (_hex_string_get(str[1], &v) << 4) | (_hex_string_get(str[2], &v));
- *g = (_hex_string_get(str[3], &v) << 4) | (_hex_string_get(str[4], &v));
- *b = (_hex_string_get(str[5], &v) << 4) | (_hex_string_get(str[6], &v));
- *a = (_hex_string_get(str[7], &v) << 4) | (_hex_string_get(str[8], &v));
- }
- else if (slen == 4) /* #RGB */
- {
- *r = _hex_string_get(str[1], &v);
- *r = (*r << 4) | *r;
- *g = _hex_string_get(str[2], &v);
- *g = (*g << 4) | *g;
- *b = _hex_string_get(str[3], &v);
- *b = (*b << 4) | *b;
- *a = 0xff;
- }
- else if (slen == 5) /* #RGBA */
- {
- *r = _hex_string_get(str[1], &v);
- *r = (*r << 4) | *r;
- *g = _hex_string_get(str[2], &v);
- *g = (*g << 4) | *g;
- *b = _hex_string_get(str[3], &v);
- *b = (*b << 4) | *b;
- *a = _hex_string_get(str[4], &v);
- *a = (*a << 4) | *a;
- }
- else v = EINA_FALSE;
-
- *r = (*r * *a) / 255;
- *g = (*g * *a) / 255;
- *b = (*b * *a) / 255;
- return v;
-}
-
EOLIAN static void
_efl_gfx_color_color_code_set(Eo *obj, void *_pd EINA_UNUSED, const char *colorcode)
{
@@ -104,7 +28,7 @@ _efl_gfx_color_color_code_set(Eo *obj, void *_pd EINA_UNUSED, const char *colorc
len = _format_clean_param(colorcode);
- _format_color_parse(colorcode, len, &r, &g, &b, &a);
+ _gfx_color_format_color_parse(colorcode, len, &r, &g, &b, &a);
efl_gfx_color_set(obj, r, g, b, a);
}
@@ -126,7 +50,7 @@ _efl_gfx_color_color_class_code_set(Eo *obj, void *_pd EINA_UNUSED, const char *
len = _format_clean_param(colorcode);
- _format_color_parse(colorcode, len, &r, &g, &b, &a);
+ _gfx_color_format_color_parse(colorcode, len, &r, &g, &b, &a);
efl_gfx_color_class_set(obj, color_class, layer, r, g, b, a);
}
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 @@
+#include "efl_gfx_color_internal.h"
+
+static int
+_hex_string_get(char ch, Eina_Bool *ok)
+{
+ if ((ch >= '0') && (ch <= '9')) return (ch - '0');
+ else if ((ch >= 'A') && (ch <= 'F')) return (ch - 'A' + 10);
+ else if ((ch >= 'a') && (ch <= 'f')) return (ch - 'a' + 10);
+ *ok = EINA_FALSE;
+ return 0;
+}
+
+/**
+ * @internal
+ * Parses a string of one of the formas:
+ * 1. "#RRGGBB"
+ * 2. "#RRGGBBAA"
+ * 3. "#RGB"
+ * 4. "#RGBA"
+ * To the rgba values.
+ *
+ * @param[in] str The string to parse - NOT NULL.
+ * @param[out] r The Red value - NOT NULL.
+ * @param[out] g The Green value - NOT NULL.
+ * @param[out] b The Blue value - NOT NULL.
+ * @param[out] a The Alpha value - NOT NULL.
+ */
+Eina_Bool
+_gfx_color_format_color_parse(const char *str, int slen,
+ unsigned char *r, unsigned char *g,
+ unsigned char *b, unsigned char *a)
+{
+ Eina_Bool v = EINA_TRUE;
+
+ *r = *g = *b = *a = 0;
+
+ if (slen == 7) /* #RRGGBB */
+ {
+ *r = (_hex_string_get(str[1], &v) << 4) | (_hex_string_get(str[2], &v));
+ *g = (_hex_string_get(str[3], &v) << 4) | (_hex_string_get(str[4], &v));
+ *b = (_hex_string_get(str[5], &v) << 4) | (_hex_string_get(str[6], &v));
+ *a = 0xff;
+ }
+ else if (slen == 9) /* #RRGGBBAA */
+ {
+ *r = (_hex_string_get(str[1], &v) << 4) | (_hex_string_get(str[2], &v));
+ *g = (_hex_string_get(str[3], &v) << 4) | (_hex_string_get(str[4], &v));
+ *b = (_hex_string_get(str[5], &v) << 4) | (_hex_string_get(str[6], &v));
+ *a = (_hex_string_get(str[7], &v) << 4) | (_hex_string_get(str[8], &v));
+ }
+ else if (slen == 4) /* #RGB */
+ {
+ *r = _hex_string_get(str[1], &v);
+ *r = (*r << 4) | *r;
+ *g = _hex_string_get(str[2], &v);
+ *g = (*g << 4) | *g;
+ *b = _hex_string_get(str[3], &v);
+ *b = (*b << 4) | *b;
+ *a = 0xff;
+ }
+ else if (slen == 5) /* #RGBA */
+ {
+ *r = _hex_string_get(str[1], &v);
+ *r = (*r << 4) | *r;
+ *g = _hex_string_get(str[2], &v);
+ *g = (*g << 4) | *g;
+ *b = _hex_string_get(str[3], &v);
+ *b = (*b << 4) | *b;
+ *a = _hex_string_get(str[4], &v);
+ *a = (*a << 4) | *a;
+ }
+ else v = EINA_FALSE;
+
+ *r = (*r * *a) / 255;
+ *g = (*g * *a) / 255;
+ *b = (*b * *a) / 255;
+ return v;
+}
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 @@
+#ifndef _GFX_COLOR_UTIL_H
+#define _GFX_COLOR_UTIL_H
+
+#include <Eina.h>
+
+Eina_Bool _gfx_color_format_color_parse(const char *str, int slen, unsigned char *r, unsigned char *g, unsigned char *b, unsigned char *a);
+
+#endif \ No newline at end of file