From: Subhransu Mohanty Date: Mon, 17 Aug 2015 06:24:50 +0000 (+0900) Subject: ector: add alpha field to gradient data. X-Git-Tag: v1.16.0-alpha1~319 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=48b558a997e5bfe321b401110daa449dc173bbd6;p=platform%2Fupstream%2Fefl.git ector: add alpha field to gradient data. Signed-off-by: Cedric BAIL --- diff --git a/src/lib/ector/software/ector_software_gradient.c b/src/lib/ector/software/ector_software_gradient.c index afd4dd3..3682989 100644 --- a/src/lib/ector/software/ector_software_gradient.c +++ b/src/lib/ector/software/ector_software_gradient.c @@ -71,61 +71,67 @@ _ease_linear(double t) return t; } -static void +static Eina_Bool _generate_gradient_color_table(Efl_Gfx_Gradient_Stop *gradient_stops, int stop_count, uint *color_table, int size) { - int pos = 0; - Efl_Gfx_Gradient_Stop *curr, *next; - assert(stop_count > 0); - - curr = gradient_stops; - uint current_color = ECTOR_ARGB_JOIN(curr->a, curr->r, curr->g, curr->b); - double incr = 1.0 / (double)size; - double fpos = 1.5 * incr; - - color_table[pos++] = current_color; - - while (fpos <= curr->offset) - { - color_table[pos] = color_table[pos - 1]; - pos++; - fpos += incr; - } + int dist, idist, pos = 0, i; + Eina_Bool alpha = EINA_FALSE; + Efl_Gfx_Gradient_Stop *curr, *next; + uint 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 = ECTOR_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 (int i = 0; i < stop_count - 1; ++i) - { - curr = (gradient_stops + i); - next = (gradient_stops + i + 1); - double delta = 1/(next->offset - curr->offset); - uint next_color = ECTOR_ARGB_JOIN(next->a, next->r, next->g, next->b); - BLEND_FUNC func = &_ease_linear; - while (fpos < next->offset && pos < size) - { - double t = func((fpos - curr->offset) * delta); - int dist = (int)(256 * t); - int idist = 256 - dist; - color_table[pos] = INTERPOLATE_PIXEL_256(current_color, idist, next_color, dist); - ++pos; - fpos += incr; - } - current_color = next_color; - } + 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 = ECTOR_ARGB_JOIN(next->a, next->r, next->g, next->b); + BLEND_FUNC func = &_ease_linear; + while (fpos < next->offset && pos < size) + { + t = func((fpos - curr->offset) * delta); + dist = (int)(256 * t); + idist = 256 - dist; + color_table[pos] = INTERPOLATE_PIXEL_256(current_color, idist, next_color, dist); + ++pos; + fpos += incr; + } + current_color = next_color; + } - for (;pos < size; ++pos) - color_table[pos] = current_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; + // Make sure the last color stop is represented at the end of the table + color_table[size-1] = current_color; + return alpha; } void update_color_table(Ector_Renderer_Software_Gradient_Data *gdata) { - if(gdata->color_table) return; + if (gdata->color_table) return; gdata->color_table = malloc(GRADIENT_STOPTABLE_SIZE * 4); - _generate_gradient_color_table(gdata->gd->colors, gdata->gd->colors_count, gdata->color_table, GRADIENT_STOPTABLE_SIZE); + gdata->alpha = _generate_gradient_color_table(gdata->gd->colors, gdata->gd->colors_count, gdata->color_table, GRADIENT_STOPTABLE_SIZE); } void diff --git a/src/lib/ector/software/ector_software_private.h b/src/lib/ector/software/ector_software_private.h index 5fefe59..a4d1221 100644 --- a/src/lib/ector/software/ector_software_private.h +++ b/src/lib/ector/software/ector_software_private.h @@ -42,6 +42,7 @@ typedef struct _Ector_Renderer_Software_Gradient_Data Software_Gradient_Linear_Data linear; Software_Gradient_Radial_Data radial; }; + Eina_Bool alpha; uint* color_table; } Ector_Renderer_Software_Gradient_Data;