summaryrefslogtreecommitdiff
path: root/src/static_libs
diff options
context:
space:
mode:
authorsubhransu mohanty <sub.mohanty@samsung.com>2017-10-26 11:12:42 +0900
committerJean-Philippe Andre <jp.andre@samsung.com>2017-11-10 11:20:38 +0900
commit76e75dc105ce98b29d5fd9026a0bc2fd18e41acd (patch)
tree397f1fe9b924bd3390070f570d11e02a1d2c40e3 /src/static_libs
parent5f9c54a1b2724abcb02ba0a70640a927a1f67ccc (diff)
ector: move gradient generation api to draw library for reuse.
Diffstat (limited to 'src/static_libs')
-rw-r--r--src/static_libs/draw/draw.h2
-rw-r--r--src/static_libs/draw/draw_main.c58
2 files changed, 60 insertions, 0 deletions
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,
29int efl_draw_argb_premul(uint32_t *data, unsigned int len); 29int efl_draw_argb_premul(uint32_t *data, unsigned int len);
30void efl_draw_argb_unpremul(uint32_t *data, unsigned int len); 30void efl_draw_argb_unpremul(uint32_t *data, unsigned int len);
31 31
32Eina_Bool efl_draw_generate_gradient_color_table(Efl_Gfx_Gradient_Stop *gradient_stops, int stop_count, uint32_t *color_table, int size);
33
32 34
33/* common sw draw helpers */ 35/* common sw draw helpers */
34 36
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
276 return func_for_mode[op]; 276 return func_for_mode[op];
277} 277}
278 278
279static double
280_ease_linear(double t)
281{
282 return t;
283}
284
285Eina_Bool
286efl_draw_generate_gradient_color_table(Efl_Gfx_Gradient_Stop *gradient_stops, int stop_count, uint32_t *color_table, int size)
287{
288 int dist, idist, pos = 0, i;
289 Eina_Bool alpha = EINA_FALSE;
290 Efl_Gfx_Gradient_Stop *curr, *next;
291 uint32_t current_color, next_color;
292 double delta, t, incr, fpos;
293
294 curr = gradient_stops;
295 if (curr->a != 255) alpha = EINA_TRUE;
296 current_color = DRAW_ARGB_JOIN(curr->a, curr->r, curr->g, curr->b);
297 incr = 1.0 / (double)size;
298 fpos = 1.5 * incr;
299
300 color_table[pos++] = current_color;
301
302 while (fpos <= curr->offset)
303 {
304 color_table[pos] = color_table[pos - 1];
305 pos++;
306 fpos += incr;
307 }
308
309 for (i = 0; i < stop_count - 1; ++i)
310 {
311 curr = (gradient_stops + i);
312 next = (gradient_stops + i + 1);
313 delta = 1/(next->offset - curr->offset);
314 if (next->a != 255) alpha = EINA_TRUE;
315 next_color = DRAW_ARGB_JOIN(next->a, next->r, next->g, next->b);
316 while (fpos < next->offset && pos < size)
317 {
318 t = _ease_linear((fpos - curr->offset) * delta);
319 dist = (int)(256 * t);
320 idist = 256 - dist;
321 color_table[pos] = draw_interpolate_256(current_color, idist, next_color, dist);
322 ++pos;
323 fpos += incr;
324 }
325 current_color = next_color;
326 }
327
328 for (;pos < size; ++pos)
329 color_table[pos] = current_color;
330
331 // Make sure the last color stop is represented at the end of the table
332 color_table[size-1] = current_color;
333 return alpha;
334}
335
336
279int 337int
280efl_draw_init(void) 338efl_draw_init(void)
281{ 339{