2 * vim:ts=8:sw=3:sts=8:noexpandtab:cino=>5n-3f0^-2{2
5 #include "evas_common.h"
6 #include "evas_blend_private.h"
10 _evas_draw_point(RGBA_Image *dst, RGBA_Draw_Context *dc, int x, int y);
13 _evas_draw_simple_line(RGBA_Image *dst, RGBA_Draw_Context *dc, int x0, int y0, int x1, int y1);
16 _evas_draw_line(RGBA_Image *dst, RGBA_Draw_Context *dc, int x0, int y0, int x1, int y1);
19 _evas_draw_line_aa(RGBA_Image *dst, RGBA_Draw_Context *dc, int x0, int y0, int x1, int y1);
22 #define IN_RANGE(x, y, w, h) \
23 ( ((unsigned)(x) < (w)) && ((unsigned)(y) < (h)) )
25 #define IN_RECT(x, y, rx, ry, rw, rh) \
26 ( ((unsigned)((x) - (rx)) < (rw)) && ((unsigned)((y) - (ry)) < (rh)) )
28 #define EXCHANGE_POINTS(x0, y0, x1, y1) \
42 evas_common_line_init(void)
47 evas_common_line_draw(RGBA_Image *dst, RGBA_Draw_Context *dc, int x0, int y0, int x1, int y1)
50 int clx, cly, clw, clh;
51 int cuse, cx, cy, cw, ch;
53 if ((x0 == x1) && (y0 == y1))
55 _evas_draw_point(dst, dc, x0, y0);
60 clw = dst->cache_entry.w;
61 clh = dst->cache_entry.h;
63 /* save out clip info */
72 RECTS_CLIP_TO_RECT(clx, cly, clw, clh, cx, cy, cw, ch);
73 if ((clw < 1) || (clh < 1))
79 w = MAX(x0, x1) - x + 1;
80 h = MAX(y0, y1) - y + 1;
82 RECTS_CLIP_TO_RECT(clx, cly, clw, clh, x, y, w, h);
83 if ((clw < 1) || (clh < 1))
93 _evas_draw_line_aa(dst, dc, x0, y0, x1, y1);
95 _evas_draw_line(dst, dc, x0, y0, x1, y1);
97 /* restore clip info */
107 _evas_draw_point(RGBA_Image *dst, RGBA_Draw_Context *dc, int x, int y)
109 RGBA_Gfx_Pt_Func pfunc;
111 if (!IN_RANGE(x, y, dst->cache_entry.w, dst->cache_entry.h))
113 if ((dc->clip.use) && (!IN_RECT(x, y, dc->clip.x, dc->clip.y, dc->clip.w, dc->clip.h)))
115 pfunc = evas_common_gfx_func_composite_color_pt_get(dc->col.col, dst, dc->render_op);
117 pfunc(0, 255, dc->col.col, dst->image.data + (dst->cache_entry.w * y) + x);
121 these functions use the dc->clip data as bounding
122 data. they assume that such data has already been cut
123 back to lie in the dst image rect and the object's
124 (line) bounding rect.
127 _evas_draw_simple_line(RGBA_Image *dst, RGBA_Draw_Context *dc, int x0, int y0, int x1, int y1)
129 int dx, dy, len, lx, ty, rx, by;
130 int clx, cly, clw, clh;
133 RGBA_Gfx_Pt_Func pfunc;
136 dstw = dst->cache_entry.w;
140 EXCHANGE_POINTS(x0, y0, x1, y1)
142 EXCHANGE_POINTS(x0, y0, x1, y1)
160 if (((y0) % dc->sli.h) == dc->sli.y)
163 if ((y0 >= ty) && (y0 <= by))
173 if (x0 < lx) x0 = lx;
174 if (x1 > rx) x1 = rx;
177 p = dst->image.data + (dstw * y0) + x0;
178 sfunc = evas_common_gfx_func_composite_color_span_get(color, dst, len, dc->render_op);
180 sfunc(NULL, NULL, color, p, len);
186 pfunc = evas_common_gfx_func_composite_color_pt_get(color, dst, dc->render_op);
191 if ((x0 >= lx) && (x0 <= rx))
193 if (y0 < ty) y0 = ty;
194 if (y1 > by) y1 = by;
197 p = dst->image.data + (dstw * y0) + x0;
201 if (((y1 + 1 - len) % dc->sli.h) == dc->sli.y)
204 pfunc(0, 255, color, p);
212 if ((dy == dx) || (dy == -dx))
216 p0_in = (IN_RECT(x0, y0, clx, cly, clw, clh) ? 1 : 0);
217 p1_in = (IN_RECT(x1, y1, clx, cly, clw, clh) ? 1 : 0);
230 if ((y0 < ty) || (y0 > by)) return;
242 if ((y1 < ty) || (y1 > by)) return;
257 if ((y0 < ty) || (y0 > by)) return;
269 if ((y1 < ty) || (y1 > by)) return;
275 p = dst->image.data + (dstw * y0) + x0;
283 p = dst->image.data + (dstw * y1) + x1;
291 if (((y1 + 1 - len) % dc->sli.h) == dc->sli.y)
294 pfunc(0, 255, color, p);
302 #define SETUP_LINE_SHALLOW \
305 EXCHANGE_POINTS(x0, y0, x1, y1) \
313 p0_in = (IN_RANGE(x0 , y0 , clw, clh) ? 1 : 0); \
314 p1_in = (IN_RANGE(x1 , y1 , clw, clh) ? 1 : 0); \
324 dyy = ((dy) << 16) / (dx); \
328 dxx = ((dx) << 16) / (dy); \
335 y += (yy - (y << 16)) >> 15; \
337 if ((dely > 0) && (py >= clh)) \
339 else if ((dely < 0) && (py < -1)) \
344 if ((dely > 0) && (py < -1)) \
346 else if ((dely < 0) && (py >= clh)) \
347 y = (clh - 1 - py); \
352 x += (xx - (x << 16)) >> 15; \
354 if (px >= clw) return; \
359 y += (yy - (y << 16)) >> 15; \
361 if ((dely > 0) && (py >= clh)) \
363 else if ((dely < 0) && (py < -1)) \
367 p = data + (dstw * py) + px; \
371 prev_y = (yy >> 16); \
373 rx = MIN(x1 + 1, clw); \
377 #define SETUP_LINE_STEEP \
380 EXCHANGE_POINTS(x0, y0, x1, y1) \
388 p0_in = (IN_RANGE(x0 , y0 , clw, clh) ? 1 : 0); \
389 p1_in = (IN_RANGE(x1 , y1 , clw, clh) ? 1 : 0); \
395 dxx = ((dx) << 16) / (dy); \
399 dyy = ((dy) << 16) / (dx); \
407 x += (xx - (x << 16)) >> 15; \
409 if ((delx > 0) && (px >= clw)) \
411 else if ((delx < 0) && (px < -1)) \
416 if ((delx > 0) && (px < -1)) \
418 else if ((delx < 0) && (px >= clw)) \
419 x = (clw - 1 - px); \
424 y += (yy - (y << 16)) >> 15; \
426 if (py >= clh) return; \
431 x += (xx - (x << 16)) >> 15; \
433 if ((delx > 0) && (px >= clw)) \
435 else if ((delx < 0) && (px < -1)) \
439 p = data + (dstw * py) + px; \
443 prev_x = (xx >> 16); \
445 by = MIN(y1 + 1, clh); \
451 _evas_draw_line(RGBA_Image *dst, RGBA_Draw_Context *dc, int x0, int y0, int x1, int y1)
453 int px, py, x, y, prev_x, prev_y;
454 int dx, dy, rx, by, p0_in, p1_in, dh, a_a = 0;
455 int delx, dely, xx, yy, dxx, dyy;
456 int clx, cly, clw, clh;
458 DATA32 *p, *data, color;
459 RGBA_Gfx_Pt_Func pfunc;
464 if ( (dx == 0) || (dy == 0) || (dx == dy) || (dx == -dy) )
466 _evas_draw_simple_line(dst, dc, x0, y0, x1, y1);
471 pfunc = evas_common_gfx_func_composite_color_pt_get(color, dst, dc->render_op);
479 data = dst->image.data;
480 dstw = dst->cache_entry.w;
482 data += (dstw * cly) + clx;
488 /* shallow: x-parametric */
489 if ((dy < dx) || (dy < -dx))
496 y += ((yy - (y << 16)) >> 15);
505 if ((py < 0) && (dely < 0)) return;
506 if ((py > by) && (dely > 0)) return;
509 if (((py) % dc->sli.h) == dc->sli.y)
512 if (IN_RANGE(px, py, clw, clh))
513 pfunc(0, 255, color, p);
522 /* steep: y-parametric */
529 x += ((xx - (x << 16)) >> 15);
538 if ((px < 0) && (delx < 0)) return;
539 if ((px > rx) && (delx > 0)) return;
542 if (((py) % dc->sli.h) == dc->sli.y)
545 if (IN_RANGE(px, py, clw, clh))
546 pfunc(0, 255, color, p);
556 _evas_draw_line_aa(RGBA_Image *dst, RGBA_Draw_Context *dc, int x0, int y0, int x1, int y1)
558 int px, py, x, y, prev_x, prev_y;
559 int dx, dy, rx, by, p0_in, p1_in, dh, a_a = 1;
560 int delx, dely, xx, yy, dxx, dyy;
561 int clx, cly, clw, clh;
563 DATA32 *p, *data, color;
564 RGBA_Gfx_Pt_Func pfunc;
567 EXCHANGE_POINTS(x0, y0, x1, y1)
571 if ( (dx == 0) || (dy == 0) || (dx == dy) || (dx == -dy) )
573 _evas_draw_simple_line(dst, dc, x0, y0, x1, y1);
578 pfunc = evas_common_gfx_func_composite_mask_color_pt_get(color, dst, dc->render_op);
586 data = dst->image.data;
587 dstw = dst->cache_entry.w;
589 data += (dstw * cly) + clx;
595 /* shallow: x-parametric */
596 if ((dy < dx) || (dy < -dx))
613 if ((py < -1) && (dely < 0)) return;
614 if ((py > by) && (dely > 0)) return;
616 if ((unsigned)(px) < clw)
618 aa = ((yy - (y << 16)) >> 8);
619 if ((unsigned)(py) < clh)
620 pfunc(0, 255 - aa, color, p);
621 if ((unsigned)(py + 1) < clh)
622 pfunc(0, aa, color, p + dstw);
631 /* steep: y-parametric */
648 if ((px < -1) && (delx < 0)) return;
649 if ((px > rx) && (delx > 0)) return;
651 if ((unsigned)(py) < clh)
653 aa = ((xx - (x << 16)) >> 8);
654 if ((unsigned)(px) < clw)
655 pfunc(0, 255 - aa, color, p);
656 if ((unsigned)(px + 1) < clw)
657 pfunc(0, aa, color, p + 1);