From 76e75dc105ce98b29d5fd9026a0bc2fd18e41acd Mon Sep 17 00:00:00 2001 From: subhransu mohanty Date: Thu, 26 Oct 2017 11:12:42 +0900 Subject: [PATCH] ector: move gradient generation api to draw library for reuse. --- src/lib/ector/software/ector_software_gradient.c | 63 +----------------------- src/static_libs/draw/draw.h | 2 + src/static_libs/draw/draw_main.c | 58 ++++++++++++++++++++++ 3 files changed, 62 insertions(+), 61 deletions(-) diff --git a/src/lib/ector/software/ector_software_gradient.c b/src/lib/ector/software/ector_software_gradient.c index 2656a1d..7f4e916 100644 --- a/src/lib/ector/software/ector_software_gradient.c +++ b/src/lib/ector/software/ector_software_gradient.c @@ -280,73 +280,14 @@ _linear_helper_sse3(uint32_t *buffer, int length, Ector_Renderer_Software_Gradie #endif -static inline double -_ease_linear(double t) -{ - return t; -} - -static Eina_Bool -_generate_gradient_color_table(Efl_Gfx_Gradient_Stop *gradient_stops, int stop_count, uint32_t *color_table, int size) -{ - int dist, idist, pos = 0, i; - Eina_Bool alpha = EINA_FALSE; - Efl_Gfx_Gradient_Stop *curr, *next; - uint32_t current_color, next_color; - double delta, t, incr, fpos; - - assert(stop_count > 0); - - curr = gradient_stops; - if (curr->a != 255) alpha = EINA_TRUE; - current_color = DRAW_ARGB_JOIN(curr->a, curr->r, curr->g, curr->b); - incr = 1.0 / (double)size; - fpos = 1.5 * incr; - - color_table[pos++] = current_color; - - while (fpos <= curr->offset) - { - color_table[pos] = color_table[pos - 1]; - pos++; - fpos += incr; - } - - for (i = 0; i < stop_count - 1; ++i) - { - curr = (gradient_stops + i); - next = (gradient_stops + i + 1); - delta = 1/(next->offset - curr->offset); - if (next->a != 255) alpha = EINA_TRUE; - next_color = DRAW_ARGB_JOIN(next->a, next->r, next->g, next->b); - while (fpos < next->offset && pos < size) - { - t = _ease_linear((fpos - curr->offset) * delta); - dist = (int)(256 * t); - idist = 256 - dist; - color_table[pos] = draw_interpolate_256(current_color, idist, next_color, dist); - ++pos; - fpos += incr; - } - current_color = next_color; - } - - for (;pos < size; ++pos) - color_table[pos] = current_color; - - // Make sure the last color stop is represented at the end of the table - color_table[size-1] = current_color; - return alpha; -} - static void _update_color_table(void *data, Ector_Software_Thread *t EINA_UNUSED) { Ector_Renderer_Software_Gradient_Data *gdata = data; gdata->color_table = malloc(GRADIENT_STOPTABLE_SIZE * 4); - gdata->alpha = _generate_gradient_color_table(gdata->gd->colors, gdata->gd->colors_count, - gdata->color_table, GRADIENT_STOPTABLE_SIZE); + gdata->alpha = efl_draw_generate_gradient_color_table(gdata->gd->colors, gdata->gd->colors_count, + gdata->color_table, GRADIENT_STOPTABLE_SIZE); } static void diff --git a/src/static_libs/draw/draw.h b/src/static_libs/draw/draw.h index e4f6434..825d633 100644 --- a/src/static_libs/draw/draw.h +++ b/src/static_libs/draw/draw.h @@ -29,6 +29,8 @@ Cspace_Convert_Func efl_draw_convert_func_get (Efl_Gfx_Colorspace origcs, int efl_draw_argb_premul(uint32_t *data, unsigned int len); void efl_draw_argb_unpremul(uint32_t *data, unsigned int len); +Eina_Bool efl_draw_generate_gradient_color_table(Efl_Gfx_Gradient_Stop *gradient_stops, int stop_count, uint32_t *color_table, int size); + /* common sw draw helpers */ diff --git a/src/static_libs/draw/draw_main.c b/src/static_libs/draw/draw_main.c index 92d2044..2731514 100644 --- a/src/static_libs/draw/draw_main.c +++ b/src/static_libs/draw/draw_main.c @@ -276,6 +276,64 @@ efl_draw_func_span_get(Efl_Gfx_Render_Op op, uint32_t color, Eina_Bool src_alpha return func_for_mode[op]; } +static double +_ease_linear(double t) +{ + return t; +} + +Eina_Bool +efl_draw_generate_gradient_color_table(Efl_Gfx_Gradient_Stop *gradient_stops, int stop_count, uint32_t *color_table, int size) +{ + int dist, idist, pos = 0, i; + Eina_Bool alpha = EINA_FALSE; + Efl_Gfx_Gradient_Stop *curr, *next; + uint32_t current_color, next_color; + double delta, t, incr, fpos; + + curr = gradient_stops; + if (curr->a != 255) alpha = EINA_TRUE; + current_color = DRAW_ARGB_JOIN(curr->a, curr->r, curr->g, curr->b); + incr = 1.0 / (double)size; + fpos = 1.5 * incr; + + color_table[pos++] = current_color; + + while (fpos <= curr->offset) + { + color_table[pos] = color_table[pos - 1]; + pos++; + fpos += incr; + } + + for (i = 0; i < stop_count - 1; ++i) + { + curr = (gradient_stops + i); + next = (gradient_stops + i + 1); + delta = 1/(next->offset - curr->offset); + if (next->a != 255) alpha = EINA_TRUE; + next_color = DRAW_ARGB_JOIN(next->a, next->r, next->g, next->b); + while (fpos < next->offset && pos < size) + { + t = _ease_linear((fpos - curr->offset) * delta); + dist = (int)(256 * t); + idist = 256 - dist; + color_table[pos] = draw_interpolate_256(current_color, idist, next_color, dist); + ++pos; + fpos += incr; + } + current_color = next_color; + } + + for (;pos < size; ++pos) + color_table[pos] = current_color; + + // Make sure the last color stop is represented at the end of the table + color_table[size-1] = current_color; + return alpha; +} + + int efl_draw_init(void) { -- 2.7.4