summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSubhransu Mohanty <sub.mohanty@samsung.com>2015-08-17 15:24:50 +0900
committerCedric BAIL <cedric@osg.samsung.com>2015-08-19 15:05:58 +0200
commit48b558a997e5bfe321b401110daa449dc173bbd6 (patch)
treecfddebba3f0e2ede121c9df5bd274861e3f5bd67
parente9896ee363e22e45b658cc5df650bfa0a1406047 (diff)
ector: add alpha field to gradient data.
Signed-off-by: Cedric BAIL <cedric@osg.samsung.com>
-rw-r--r--src/lib/ector/software/ector_software_gradient.c90
-rw-r--r--src/lib/ector/software/ector_software_private.h1
2 files changed, 49 insertions, 42 deletions
diff --git a/src/lib/ector/software/ector_software_gradient.c b/src/lib/ector/software/ector_software_gradient.c
index afd4dd3daf..36829899cb 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)
71 return t; 71 return t;
72} 72}
73 73
74static void 74static Eina_Bool
75_generate_gradient_color_table(Efl_Gfx_Gradient_Stop *gradient_stops, int stop_count, uint *color_table, int size) 75_generate_gradient_color_table(Efl_Gfx_Gradient_Stop *gradient_stops, int stop_count, uint *color_table, int size)
76{ 76{
77 int pos = 0; 77 int dist, idist, pos = 0, i;
78 Efl_Gfx_Gradient_Stop *curr, *next; 78 Eina_Bool alpha = EINA_FALSE;
79 assert(stop_count > 0); 79 Efl_Gfx_Gradient_Stop *curr, *next;
80 80 uint current_color, next_color;
81 curr = gradient_stops; 81 double delta, t, incr, fpos;
82 uint current_color = ECTOR_ARGB_JOIN(curr->a, curr->r, curr->g, curr->b); 82 assert(stop_count > 0);
83 double incr = 1.0 / (double)size; 83
84 double fpos = 1.5 * incr; 84 curr = gradient_stops;
85 85 if (curr->a != 255) alpha = EINA_TRUE;
86 color_table[pos++] = current_color; 86 current_color = ECTOR_ARGB_JOIN(curr->a, curr->r, curr->g, curr->b);
87 87 incr = 1.0 / (double)size;
88 while (fpos <= curr->offset) 88 fpos = 1.5 * incr;
89 { 89
90 color_table[pos] = color_table[pos - 1]; 90 color_table[pos++] = current_color;
91 pos++; 91
92 fpos += incr; 92 while (fpos <= curr->offset)
93 } 93 {
94 color_table[pos] = color_table[pos - 1];
95 pos++;
96 fpos += incr;
97 }
94 98
95 for (int i = 0; i < stop_count - 1; ++i) 99 for (i = 0; i < stop_count - 1; ++i)
96 { 100 {
97 curr = (gradient_stops + i); 101 curr = (gradient_stops + i);
98 next = (gradient_stops + i + 1); 102 next = (gradient_stops + i + 1);
99 double delta = 1/(next->offset - curr->offset); 103 delta = 1/(next->offset - curr->offset);
100 uint next_color = ECTOR_ARGB_JOIN(next->a, next->r, next->g, next->b); 104 if (next->a != 255) alpha = EINA_TRUE;
101 BLEND_FUNC func = &_ease_linear; 105 next_color = ECTOR_ARGB_JOIN(next->a, next->r, next->g, next->b);
102 while (fpos < next->offset && pos < size) 106 BLEND_FUNC func = &_ease_linear;
103 { 107 while (fpos < next->offset && pos < size)
104 double t = func((fpos - curr->offset) * delta); 108 {
105 int dist = (int)(256 * t); 109 t = func((fpos - curr->offset) * delta);
106 int idist = 256 - dist; 110 dist = (int)(256 * t);
107 color_table[pos] = INTERPOLATE_PIXEL_256(current_color, idist, next_color, dist); 111 idist = 256 - dist;
108 ++pos; 112 color_table[pos] = INTERPOLATE_PIXEL_256(current_color, idist, next_color, dist);
109 fpos += incr; 113 ++pos;
110 } 114 fpos += incr;
111 current_color = next_color; 115 }
112 } 116 current_color = next_color;
117 }
113 118
114 for (;pos < size; ++pos) 119 for (;pos < size; ++pos)
115 color_table[pos] = current_color; 120 color_table[pos] = current_color;
116 121
117 // Make sure the last color stop is represented at the end of the table 122 // Make sure the last color stop is represented at the end of the table
118 color_table[size-1] = current_color; 123 color_table[size-1] = current_color;
124 return alpha;
119} 125}
120 126
121 127
122void 128void
123update_color_table(Ector_Renderer_Software_Gradient_Data *gdata) 129update_color_table(Ector_Renderer_Software_Gradient_Data *gdata)
124{ 130{
125 if(gdata->color_table) return; 131 if (gdata->color_table) return;
126 132
127 gdata->color_table = malloc(GRADIENT_STOPTABLE_SIZE * 4); 133 gdata->color_table = malloc(GRADIENT_STOPTABLE_SIZE * 4);
128 _generate_gradient_color_table(gdata->gd->colors, gdata->gd->colors_count, gdata->color_table, GRADIENT_STOPTABLE_SIZE); 134 gdata->alpha = _generate_gradient_color_table(gdata->gd->colors, gdata->gd->colors_count, gdata->color_table, GRADIENT_STOPTABLE_SIZE);
129} 135}
130 136
131void 137void
diff --git a/src/lib/ector/software/ector_software_private.h b/src/lib/ector/software/ector_software_private.h
index 5fefe590aa..a4d12219d0 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
42 Software_Gradient_Linear_Data linear; 42 Software_Gradient_Linear_Data linear;
43 Software_Gradient_Radial_Data radial; 43 Software_Gradient_Radial_Data radial;
44 }; 44 };
45 Eina_Bool alpha;
45 uint* color_table; 46 uint* color_table;
46} Ector_Renderer_Software_Gradient_Data; 47} Ector_Renderer_Software_Gradient_Data;
47 48