1 #include "evas_common.h"
2 #include "evas_blend_private.h"
3 #include "evas_private.h"
6 static void _evas_common_gradient2_stops_free(RGBA_Gradient2 *gr);
7 static void _evas_common_gradient2_stops_scale(RGBA_Gradient2 *gr);
9 static void _evas_common_gradient2_map_argb(RGBA_Draw_Context *dc, RGBA_Gradient2 *gr, int len);
10 static void _evas_common_gradient2_map_ahsv(RGBA_Draw_Context *dc, RGBA_Gradient2 *gr, int len);
12 static int grad_initialised = 0;
15 evas_common_gradient2_init(void)
17 RGBA_Gradient2_Type *geom;
21 geom = evas_common_gradient2_type_linear_get();
24 geom = evas_common_gradient2_type_radial_get();
31 evas_common_gradient2_shutdown(void)
33 RGBA_Gradient2_Type *geom;
35 if (!grad_initialised)
37 geom = evas_common_gradient2_type_linear_get();
40 geom = evas_common_gradient2_type_radial_get();
47 _evas_common_gradient2_stops_free(RGBA_Gradient2 *gr)
54 while (gr->stops.stops)
57 gr->stops.stops = eina_inlist_remove(gr->stops.stops, gr->stops.stops);
60 gr->stops.stops = NULL;
66 evas_common_gradient2_free(RGBA_Gradient2 *gr)
70 if (gr->references > 0) return;
71 #ifdef EVAS_FRAME_QUEUING
72 LKL(gr->ref_fq_add); LKL(gr->ref_fq_del);
73 if (gr->ref_fq[0] != gr->ref_fq[1])
75 LKU(gr->ref_fq_add); LKU(gr->ref_fq_del);
78 LKU(gr->ref_fq_add); LKU(gr->ref_fq_del);
80 evas_common_gradient2_clear(gr);
81 if (gr->stops.cdata) free(gr->stops.cdata);
82 if (gr->stops.adata) free(gr->stops.adata);
83 if (gr->type.geometer && gr->type.gdata)
84 gr->type.geometer->geom_free(gr->type.gdata);
85 if (gr->map.data) free(gr->map.data);
90 evas_common_gradient2_clear(RGBA_Gradient2 *gr)
94 _evas_common_gradient2_stops_free(gr);
99 evas_common_gradient2_color_np_stop_insert(RGBA_Gradient2 *gr, int r, int g, int b, int a, float pos)
101 RGBA_Gradient2_Color_Np_Stop *gc;
105 if (!gr->stops.stops)
107 RGBA_Gradient2_Color_Np_Stop *gc1;
109 gc = malloc(sizeof(RGBA_Gradient2_Color_Np_Stop));
111 gc1 = malloc(sizeof(RGBA_Gradient2_Color_Np_Stop));
112 if (!gc1) { free(gc); return; }
113 gc->r = gc->g = gc->b = gc->a = 255; gc->pos = 0.0; gc->dist = 0;
114 gc1->r = gc1->g = gc1->b = gc1->a = 255; gc1->pos = 1.0; gc1->dist = 0;
116 gr->stops.stops = eina_inlist_append(gr->stops.stops, EINA_INLIST_GET(gc));
117 gr->stops.stops = eina_inlist_append(gr->stops.stops, EINA_INLIST_GET(gc1));
118 gr->stops.nstops = 2;
122 if (r < 0) r = 0; if (r > 255) r = 255;
123 if (g < 0) g = 0; if (g > 255) g = 255;
124 if (b < 0) b = 0; if (b > 255) b = 255;
125 if (a < 0) a = 0; if (a > 255) a = 255;
126 if (pos < 0.0) pos = 0.0;
127 if (pos > 1.0) pos = 1.0;
131 gc = (RGBA_Gradient2_Color_Np_Stop *)gr->stops.stops;
132 gc->r = r; gc->g = g; gc->b = b; gc->a = a; gc->dist = 0;
133 if (a < 255) gr->has_alpha = 1;
138 gc = (RGBA_Gradient2_Color_Np_Stop *)(gr->stops.stops->last);
139 gc->r = r; gc->g = g; gc->b = b; gc->a = a; gc->dist = 0;
140 if (a < 255) gr->has_alpha = 1;
144 l = gr->stops.stops->next;
147 gc = (RGBA_Gradient2_Color_Np_Stop *)l;
152 gc->r = r; gc->g = g; gc->b = b; gc->a = a; gc->dist = 0;
153 if (a < 255) gr->has_alpha = 1;
161 gc = malloc(sizeof(RGBA_Gradient2_Color_Np_Stop));
170 gr->stops.stops = eina_inlist_prepend_relative(gr->stops.stops, EINA_INLIST_GET(gc), l);
177 evas_common_gradient2_fill_transform_set(RGBA_Gradient2 *gr, Evas_Common_Transform *t)
182 gr->fill.transform.mxx = 1; gr->fill.transform.mxy = 0; gr->fill.transform.mxz = 0;
183 gr->fill.transform.myx = 0; gr->fill.transform.myy = 1; gr->fill.transform.myz = 0;
184 gr->fill.transform.mzx = 1; gr->fill.transform.mzy = 0; gr->fill.transform.mzz = 1;
187 gr->fill.transform.mxx = t->mxx; gr->fill.transform.mxy = t->mxy; gr->fill.transform.mxz = t->mxz;
188 gr->fill.transform.myx = t->myx; gr->fill.transform.myy = t->myy; gr->fill.transform.myz = t->myz;
189 gr->fill.transform.mzx = t->mzx; gr->fill.transform.mzy = t->mzy; gr->fill.transform.mzz = t->mzz;
193 evas_common_gradient2_fill_spread_set(RGBA_Gradient2 *gr, int spread)
196 gr->fill.spread = spread;
200 evas_common_gradient2_draw(RGBA_Image *dst, RGBA_Draw_Context *dc,
201 int x, int y, int w, int h, RGBA_Gradient2 *gr)
203 Gfx_Func_Gradient2_Fill gfunc;
204 RGBA_Gfx_Func bfunc = NULL;
206 int xin, yin, xoff, yoff;
207 int clx, cly, clw, clh;
208 DATA32 *pdst, *dst_end, *buf, *map;
209 RGBA_Image *argb_buf = NULL, *alpha_buf = NULL;
212 int direct_copy = 0, buf_step = 0;
214 if (!dst || !dc || !gr || !dst || !dst->image.data)
216 if (!gr->map.data || !gr->type.geometer)
218 if ((w < 1) || (h < 1))
220 clx = 0; cly = 0; clw = dst->cache_entry.w; clh = dst->cache_entry.h;
221 if ((clw < 1) || (clh < 1)) return;
224 RECTS_CLIP_TO_RECT(clx,cly,clw,clh, dc->clip.x,dc->clip.y,dc->clip.w,dc->clip.h);
225 if ((clw < 1) || (clh < 1)) return;
228 RECTS_CLIP_TO_RECT(x,y,w,h, clx,cly,clw,clh);
229 if ((w < 1) || (h < 1)) return;
234 if (!gr->type.geometer->has_mask(gr, dc->render_op))
236 if ((dc->render_op == _EVAS_RENDER_FILL) ||
237 (dc->render_op == _EVAS_RENDER_COPY))
239 direct_copy = 1; buf_step = dst->cache_entry.w;
240 if (gr->type.geometer->has_alpha(gr, dc->render_op))
241 dst->cache_entry.flags.alpha = 1;
243 else if ((dc->render_op == _EVAS_RENDER_BLEND) &&
244 !gr->type.geometer->has_alpha(gr, dc->render_op))
246 direct_copy = 1; buf_step = dst->cache_entry.w;
251 argb_buf = evas_common_image_line_buffer_obtain(w);
254 argb_buf->cache_entry.flags.alpha = gr->type.geometer->has_alpha(gr, dc->render_op) ? 1 : 0;
256 if (gr->type.geometer->has_mask(gr, dc->render_op))
258 alpha_buf = evas_common_image_alpha_line_buffer_obtain(w);
261 evas_common_image_line_buffer_release(argb_buf);
264 bfunc = evas_common_gfx_func_composite_pixel_mask_span_get(argb_buf, dst, w, dc->render_op);
267 bfunc = evas_common_gfx_func_composite_pixel_span_get(argb_buf, dst, w, dc->render_op);
270 gfunc = gr->type.geometer->get_fill_func(gr, dc->render_op);
271 gdata = gr->type.gdata;
276 evas_common_image_line_buffer_release(argb_buf);
278 evas_common_image_alpha_line_buffer_release(alpha_buf);
285 pdst = dst->image.data + (y * dst->cache_entry.w) + x;
286 dst_end = pdst + (h * dst->cache_entry.w);
289 buf = argb_buf->image.data;
291 mask = (DATA8 *)alpha_buf->image.data;
296 while (pdst < dst_end)
299 if ((y % dc->sli.h) == dc->sli.y)
302 gfunc(map, len, buf, mask, w, xoff, yoff, gdata);
304 bfunc(buf, mask, 0, pdst, w);
307 pdst += dst->cache_entry.w;
316 evas_common_image_line_buffer_release(argb_buf);
318 evas_common_image_alpha_line_buffer_release(alpha_buf);
320 evas_common_cpu_end_opt();
324 _evas_common_gradient2_stops_scale(RGBA_Gradient2 *gr)
327 RGBA_Gradient2_Color_Np_Stop *gc, *gc_next;
331 if (!gr || !gr->stops.stops) return;
334 gc = (RGBA_Gradient2_Color_Np_Stop *)gr->stops.stops;
335 l = gr->stops.stops->next;
340 gc_next = (RGBA_Gradient2_Color_Np_Stop *)l;
341 dp = gc_next->pos - gc->pos;
342 if (dp > 0.000030517)
343 scale = MIN(scale, dp);
350 gc = (RGBA_Gradient2_Color_Np_Stop *)gr->stops.stops;
351 l = gr->stops.stops->next;
356 gc_next = (RGBA_Gradient2_Color_Np_Stop *)l;
357 dist = 0.5 + (scale * (gc_next->pos - gc->pos));
372 _evas_common_gradient2_map_argb(RGBA_Draw_Context *dc, RGBA_Gradient2 *gr, int len)
376 if ((len < 1) || (len > 65535))
384 if ((len != gr->map.len) || (!gr->map.data))
385 gr->map.data = realloc(gr->map.data, len * sizeof(DATA32));
387 { gr->map.len = 0; return; }
389 gr->map.has_alpha = gr->has_alpha;
391 if (!gr->stops.stops) return;
393 _evas_common_gradient2_stops_scale(gr);
397 RGBA_Gradient2_Color_Np_Stop *gc, *gc_next;
398 DATA32 *pmap, *map_end;
402 int next_r, next_g, next_b, next_a;
403 int rr, drr, gg, dgg, bb, dbb, aa, daa;
405 gr->stops.cdata = realloc(gr->stops.cdata, gr->stops.len * sizeof(DATA32));
406 if (!gr->stops.cdata) return;
407 pmap = gr->stops.cdata; map_end = pmap + gr->stops.len;
411 gr->stops.adata = realloc(gr->stops.adata, gr->stops.len * sizeof(DATA8));
412 if (!gr->stops.adata)
413 { free(gr->stops.cdata); gr->stops.cdata = NULL; return; }
414 pamap = gr->stops.adata;
417 gc = (RGBA_Gradient2_Color_Np_Stop *)gr->stops.stops;
418 r = gc->r; g = gc->g; b = gc->b; a = gc->a;
419 lc = gr->stops.stops->next;
421 while (pmap < map_end)
427 gc_next = (RGBA_Gradient2_Color_Np_Stop *)lc;
428 next_r = gc_next->r; next_g = gc_next->g; next_b = gc_next->b; next_a = gc_next->a;
429 rr = r << 16; drr = ((next_r - r) * dii);
430 gg = g << 16; dgg = ((next_g - g) * dii);
431 bb = b << 16; dbb = ((next_b - b) * dii);
432 aa = a << 16; daa = ((next_a - a) * dii);
435 r = rr >> 16; r += (rr - (r << 16)) >> 15;
436 g = gg >> 16; g += (gg - (g << 16)) >> 15;
437 b = bb >> 16; b += (bb - (b << 16)) >> 15;
438 *pmap++ = 0xff000000 + RGB_JOIN(r,g,b);
441 a = aa >> 16; a += (aa - (a << 16)) >> 15;
445 rr += drr; gg += dgg; bb += dbb;
448 r = next_r; g = next_g; b = next_b; a = next_a;
453 *pmap++ = 0xff000000 + RGB_JOIN(gc->r,gc->g,gc->b);
454 if (pamap) *pamap++ = gc->a;
459 if (gr->stops.cdata && gr->stops.adata)
461 evas_common_scale_rgba_a8_span(gr->stops.cdata, gr->stops.adata, gr->stops.len,
462 dc->mul.col, gr->map.data, gr->map.len, 1);
466 evas_common_scale_rgba_span(gr->stops.cdata, NULL, gr->stops.len,
467 dc->mul.col, gr->map.data, gr->map.len, 1);
468 gr->map.has_alpha |= (!!(255 - (dc->mul.col >> 24)));
472 _evas_common_gradient2_map_ahsv(RGBA_Draw_Context *dc, RGBA_Gradient2 *gr, int len)
476 if ((len < 1) || (len > 65535))
484 if ((len != gr->map.len) || (!gr->map.data))
485 gr->map.data = realloc(gr->map.data, len * sizeof(DATA32));
487 { gr->map.len = 0; return; }
489 gr->map.has_alpha = gr->has_alpha;
491 if (!gr->stops.stops) return;
493 _evas_common_gradient2_stops_scale(gr);
497 RGBA_Gradient2_Color_Np_Stop *gc, *gc_next;
498 DATA32 *pmap, *map_end;
502 int next_h, next_s, next_v;
503 int hh, dhh, ss, dss, vv, dvv, aa, daa;
505 int next_r, next_g, next_b, next_a;
507 gr->stops.cdata = realloc(gr->stops.cdata, gr->stops.len * sizeof(DATA32));
508 if (!gr->stops.cdata) return;
509 pmap = gr->stops.cdata; map_end = pmap + gr->stops.len;
513 gr->stops.adata = realloc(gr->stops.adata, gr->stops.len * sizeof(DATA8));
514 if (!gr->stops.adata)
515 { free(gr->stops.cdata); gr->stops.cdata = NULL; return; }
516 pamap = gr->stops.adata;
519 gc = (RGBA_Gradient2_Color_Np_Stop *)gr->stops.stops;
520 r = gc->r; g = gc->g; b = gc->b; a = gc->a;
521 evas_common_convert_color_rgb_to_hsv_int(r, g, b, &h, &s, &v);
522 lc = gr->stops.stops->next;
524 while (pmap < map_end)
530 gc_next = (RGBA_Gradient2_Color_Np_Stop *)lc;
532 next_r = gc_next->r; next_g = gc_next->g; next_b = gc_next->b; next_a = gc_next->a;
533 evas_common_convert_color_rgb_to_hsv_int(next_r, next_g, next_b,
534 &next_h, &next_s, &next_v);
535 hh = h << 16; dhh = ((next_h - h) * dii);
536 ss = s << 16; dss = ((next_s - s) * dii);
537 vv = v << 16; dvv = ((next_v - v) * dii);
538 aa = a << 16; daa = ((next_a - a) * dii);
541 h = hh >> 16; h += (hh - (h << 16)) >> 15;
542 s = ss >> 16; s += (ss - (s << 16)) >> 15;
543 v = vv >> 16; v += (vv - (v << 16)) >> 15;
544 evas_common_convert_color_hsv_to_rgb_int(h, s, v, &r, &g, &b);
545 *pmap++ = 0xff000000 + RGB_JOIN(r,g,b);
548 a = aa >> 16; a += (aa - (a << 16)) >> 15;
552 hh += dhh; ss += dss; vv += dvv;
555 h = next_h; s = next_s; v = next_v; a = next_a;
560 *pmap++ = 0xff000000 + RGB_JOIN(gc->r,gc->g,gc->b);
561 if (pamap) *pamap++ = gc->a;
566 if (gr->stops.cdata && gr->stops.adata)
568 evas_common_scale_hsva_a8_span(gr->stops.cdata, gr->stops.adata, gr->stops.len,
569 dc->mul.col, gr->map.data, gr->map.len, 1);
572 evas_common_scale_hsva_span(gr->stops.cdata, NULL, gr->stops.len,
573 dc->mul.col, gr->map.data, gr->map.len, 1);
574 gr->map.has_alpha |= (!!(255 - (dc->mul.col >> 24)));
578 evas_common_gradient2_map(RGBA_Draw_Context *dc, RGBA_Gradient2 *gr, int len)
580 if (!gr || !dc) return;
581 if (dc->interpolation.color_space == _EVAS_COLOR_SPACE_AHSV)
583 _evas_common_gradient2_map_ahsv(dc, gr, len);
586 _evas_common_gradient2_map_argb(dc, gr, len);