We decided to improve the line implementation to speed up the use of
evas-lines in python (our case). Yes, we could just use polygons, but we are
trying to reduce processor usage at this point.
Its faster to draw lines (with lines implementation) directly, specially
dealing with vertical/horizontal/45 deg. lines.
Calculating where points of polygons must be drawn relative to width of line
in python-side is a lost of processing too.
Being faster, simpler and without breaking any compatibility, I dont know
why Lines should not to have width support. Specially thinking about how
simpler it makes to work with Lines.
Yes, the code may be optimized, but its working fine and fast here.
Greetings,
Diego B. Contezini
On Sun, May 18, 2008 at 11:51 PM, The Rasterman Carsten Haitzler <
[EMAIL PROTECTED]> wrote:
> On Tue, 13 May 2008 17:20:27 -0300 "Diego Bitencourt Contezini"
> <[EMAIL PROTECTED]> babbled:
>
> any reason you didnt just use polygons? :)
>
> > Hello all.
> > Working with evas+Lines in python, is fast. But if you need a line with
> more
> > then one pixel of width, it gets very slow (in dispositives like N800),
> > because object Line dont have width support, so its needen to use
> Rectangles
> > to make it works.
> >
> > I made a modification to support width in Lines object. It is composed by
> 3
> > patchs.
> > *First*, in evas/lib/*, it changes internal call to engine line drawer,
> > inserting more one argument to the same function. It is a callback, so,
> no
> > modification is needen in any engine module that dosnt support Lines with
> > more then 1 pixel (they will just draw with only 1 pixel). Has added new
> > functions to deal with width, without breaking any compatibility of other
> > functions.
> > *Second*, in evas/engine/software16 to add support to width.
> > *Third,* in python-evas binding, to add support to use the modifications
> > made in evas.
> >
> > If anyone get any bug or suggest any modification to patch, im a
> listener.
> >
> > Thanks all
> >
> > Diego Bitencourt Contezini
> >
>
>
> --
> ------------- Codito, ergo sum - "I code, therefore I am" --------------
> The Rasterman (Carsten Haitzler) [EMAIL PROTECTED]
>
>
--- evas-0.9.9.042/src/lib/canvas/evas_object_line.c 2008-05-07 17:22:34.000000000 -0300
+++ evas-linha/src/lib/canvas/evas_object_line.c 2008-05-20 09:50:03.000000000 -0300
@@ -18,6 +18,7 @@
} object;
} cache;
Evas_Coord x1, y1, x2, y2;
+ int width;
} cur, prev;
void *engine_data;
@@ -86,7 +87,6 @@
evas_object_inject(obj, e);
return obj;
}
-
/**
* Sets the coordinates of the end points of the given evas line object.
* @param obj The given evas line object.
@@ -143,12 +143,12 @@
obj->cur.geometry.y = min_y;
obj->cur.geometry.w = max_x - min_x + 2.0;
obj->cur.geometry.h = max_y - min_y + 2.0;
-//// obj->cur.cache.geometry.validity = 0;
o->cur.x1 = x1 - min_x;
o->cur.y1 = y1 - min_y;
o->cur.x2 = x2 - min_x;
o->cur.y2 = y2 - min_y;
o->changed = 1;
+ o->cur.width = 1;
evas_object_change(obj);
evas_object_coords_recalc(obj);
if (obj->layer->evas->events_frozen <= 0)
@@ -171,6 +171,122 @@
}
/**
+ * Sets the coordinates of the end points of the given evas line object with width param.
+ * @param obj The given evas line object.
+ * @param x1 The X coordinate of the first point.
+ * @param y1 The Y coordinate of the first point.
+ * @param x2 The X coordinate of the second point.
+ * @param y2 The Y coordinate of the second point.
+ * @param width The width of the line.
+ * @ingroup Evas_Line_Group
+ */
+EAPI void
+evas_object_line_xyw_set(Evas_Object *obj, Evas_Coord x1, Evas_Coord y1, Evas_Coord x2, Evas_Coord y2, int width)
+{
+ Evas_Object_Line *o;
+ Evas_Coord min_x, max_x, min_y, max_y;
+ int is, was = 0;
+
+ MAGIC_CHECK(obj, Evas_Object, MAGIC_OBJ);
+ return;
+ MAGIC_CHECK_END();
+ o = (Evas_Object_Line *)(obj->object_data);
+ MAGIC_CHECK(o, Evas_Object_Line, MAGIC_OBJ_LINE);
+ return;
+ MAGIC_CHECK_END();
+ if ((x1 == o->cur.x1) && (y1 == o->cur.y1) &&
+ (x2 == o->cur.x2) && (y2 == o->cur.y2)) return;
+
+ if (obj->layer->evas->events_frozen <= 0)
+ {
+ if (!evas_event_passes_through(obj))
+ was = evas_object_is_in_output_rect(obj,
+ obj->layer->evas->pointer.x,
+ obj->layer->evas->pointer.y, 1, 1);
+ }
+
+ if (x1 < x2)
+ {
+ min_x = x1;
+ max_x = x2;
+ }
+ else
+ {
+ min_x = x2;
+ max_x = x1;
+ }
+
+ if (y1 < y2)
+ {
+ min_y = y1;
+ max_y = y2;
+ }
+ else
+ {
+ min_y = y2;
+ max_y = y1;
+ }
+
+ if(width > 1)
+ {
+ int tsum; // type of Sum (x = 0, y = 1)
+ if(x1 == x2)
+ { // vertical line
+ if(y1 == y2)
+ tsum = 1;
+ else
+ tsum = 0;
+ } else if(y1 == y2) // horizontal line
+ tsum = 1;
+ else if((max_x - min_x) > (max_y - min_y)) // dx > dy
+ tsum = 1;
+ else // dx <= dy
+ tsum = 0;
+
+ if(tsum > 0)
+ {
+ min_y -= (width/2)+1 - width%2;
+ max_y += (width/2);
+ }
+ else
+ {
+ min_x -= (width/2)+1 - width%2;
+ max_x += (width/2);
+ }
+ }
+ obj->cur.geometry.x = min_x;
+ obj->cur.geometry.y = min_y;
+ obj->cur.geometry.w = max_x - min_x + 2.0;
+ obj->cur.geometry.h = max_y - min_y + 2.0;
+ // obj->cur.cache.geometry.validity = 0;
+ o->cur.x1 = x1 - min_x;
+ o->cur.y1 = y1 - min_y;
+ o->cur.x2 = x2 - min_x;
+ o->cur.y2 = y2 - min_y;
+ o->changed = 1;
+ o->cur.width = width;
+ evas_object_change(obj);
+ evas_object_coords_recalc(obj);
+ if (obj->layer->evas->events_frozen <= 0)
+ {
+ is = evas_object_is_in_output_rect(obj,
+ obj->layer->evas->pointer.x,
+ obj->layer->evas->pointer.y, 1, 1);
+ if (!evas_event_passes_through(obj))
+ {
+ if ((is ^ was) && obj->cur.visible)
+ evas_event_feed_mouse_move(obj->layer->evas,
+ obj->layer->evas->pointer.x,
+ obj->layer->evas->pointer.y,
+ obj->layer->evas->last_timestamp,
+ NULL);
+ }
+ }
+ evas_object_inform_call_move(obj);
+ evas_object_inform_call_resize(obj);
+}
+
+/**
* Retrieves the coordinates of the end points of the given evas line object.
* @param obj The given line object.
* @param x1 Pointer to an integer in which to store the X coordinate of the
@@ -248,6 +364,7 @@
o->cur.y1 = 0.0;
o->cur.x2 = 31.0;
o->cur.y2 = 31.0;
+ o->cur.width = 1;
o->prev = o->cur;
return o;
}
@@ -292,7 +409,8 @@
o->cur.cache.x1 + x,
o->cur.cache.y1 + y,
o->cur.cache.x2 + x,
- o->cur.cache.y2 + y);
+ o->cur.cache.y2 + y,
+ o->cur.width);
}
static void
@@ -466,3 +584,53 @@
o->cur.cache.object.w = obj->cur.geometry.w;
o->cur.cache.object.h = obj->cur.geometry.h;
}
+
+/**
+ * Retrieves the width of the given evas line object.
+ * @param obj The given line object.
+ * @param width Pointer to an integer in which to store the width of the line
+ * @ingroup Evas_Line_Group
+ */
+EAPI void
+evas_object_line_width_get(Evas_Object *obj, int *width)
+{
+ Evas_Object_Line *o;
+
+ MAGIC_CHECK(obj, Evas_Object, MAGIC_OBJ);
+ if (width) *width = 0.0;
+ return;
+ MAGIC_CHECK_END();
+ o = (Evas_Object_Line *)(obj->object_data);
+ MAGIC_CHECK(o, Evas_Object_Line, MAGIC_OBJ_LINE);
+ if (width) *width = 0.0;
+ return;
+ MAGIC_CHECK_END();
+ if (width) *width = o->cur.width;
+}
+
+/**
+ * Sets the width of the given evas line object.
+ * @param obj The given line object.
+ * @param width The new line object width
+ * @ingroup Evas_Line_Group
+ */
+EAPI void
+evas_object_line_width_set(Evas_Object *obj, int width)
+{
+ Evas_Object_Line *o;
+ Evas_Coord x1, y1, x2, y2;
+
+ MAGIC_CHECK(obj, Evas_Object, MAGIC_OBJ);
+ return;
+ MAGIC_CHECK_END();
+ o = (Evas_Object_Line *)(obj->object_data);
+ MAGIC_CHECK(o, Evas_Object_Line, MAGIC_OBJ_LINE);
+ return;
+ MAGIC_CHECK_END();
+ if ( width <= 0 )
+ return;
+ evas_object_line_xy_get(obj, &x1, &y1, &x2, &y2);
+ evas_object_line_xyw_set(obj, x1, y1, x2, y2, width);
+
+}
+
--- evas-0.9.9.042/src/lib/Evas.h 2008-05-07 17:22:33.000000000 -0300
+++ evas-linha/src/lib/Evas.h 2008-05-20 09:49:59.000000000 -0300
@@ -450,6 +450,9 @@
EAPI Evas_Object *evas_object_line_add (Evas *e);
EAPI void evas_object_line_xy_set (Evas_Object *obj, Evas_Coord x1, Evas_Coord y1, Evas_Coord x2, Evas_Coord y2);
EAPI void evas_object_line_xy_get (const Evas_Object *obj, Evas_Coord *x1, Evas_Coord *y1, Evas_Coord *x2, Evas_Coord *y2);
+ EAPI void evas_object_line_xyw_set (Evas_Object *obj, Evas_Coord x1, Evas_Coord y1, Evas_Coord x2, Evas_Coord y2, int width);
+ EAPI void evas_object_line_width_set (Evas_Object *obj, int width);
+ EAPI void evas_object_line_width_get (Evas_Object *obj, int *width);
/* gradient objects */
EAPI Evas_Object *evas_object_gradient_add (Evas *e);
--- evas-0.9.9.042/src/lib/include/evas_private.h 2008-05-07 17:22:34.000000000 -0300
+++ evas-linha/src/lib/include/evas_private.h 2008-05-20 09:50:04.000000000 -0300
@@ -569,7 +569,7 @@
void (*rectangle_draw) (void *data, void *context, void *surface, int x, int y, int w, int h);
- void (*line_draw) (void *data, void *context, void *surface, int x1, int y1, int x2, int y2);
+ void (*line_draw) (void *data, void *context, void *surface, int x1, int y1, int x2, int y2, int width);
void *(*polygon_point_add) (void *data, void *context, void *polygon, int x, int y);
void *(*polygon_points_clear) (void *data, void *context, void *polygon);
--- evas-0.9.9.042/src/modules/engines/software_16/evas_engine.c 2008-05-07 17:22:35.000000000 -0300
+++ evas-linha/src/modules/engines/software_16/evas_engine.c 2008-05-20 09:50:07.000000000 -0300
@@ -149,9 +149,9 @@
}
static void
-eng_line_draw(void *data, void *context, void *surface, int x1, int y1, int x2, int y2)
+eng_line_draw(void *data, void *context, void *surface, int x1, int y1, int x2, int y2, int width)
{
- soft16_line_draw(surface, context, x1, y1, x2, y2);
+ soft16_line_draw(surface, context, x1, y1, x2, y2, width);
}
static void *
--- evas-0.9.9.042/src/modules/engines/software_16/evas_soft16.h 2008-05-07 17:22:35.000000000 -0300
+++ evas-linha/src/modules/engines/software_16/evas_soft16.h 2008-05-20 09:50:07.000000000 -0300
@@ -139,7 +139,7 @@
* Line (evas_soft16_line.c)
*/
void
-soft16_line_draw(Soft16_Image *dst, RGBA_Draw_Context *dc, int x0, int y0, int x1, int y1);
+soft16_line_draw(Soft16_Image *dst, RGBA_Draw_Context *dc, int x0, int y0, int x1, int y1, int width);
/**
--- evas-0.9.9.042/src/modules/engines/software_16/evas_soft16_line.c 2008-05-07 17:22:35.000000000 -0300
+++ evas-linha/src/modules/engines/software_16/evas_soft16_line.c 2008-05-20 09:54:36.000000000 -0300
@@ -71,8 +71,8 @@
dst_itr = dst->pixels + (dst->stride * y) + x;
alpha = A_VAL(&dc->col.col) >> 3;
rgb565 = RGB_565_FROM_COMPONENTS(R_VAL(&dc->col.col),
- G_VAL(&dc->col.col),
- B_VAL(&dc->col.col));
+ G_VAL(&dc->col.col),
+ B_VAL(&dc->col.col));
if (alpha == 31)
_soft16_pt_fill_solid_solid(dst_itr, rgb565);
@@ -87,52 +87,60 @@
}
static void
-_soft16_line_horiz(Soft16_Image *dst, RGBA_Draw_Context *dc, int x0, int x1, int y)
+_soft16_line_horiz(Soft16_Image *dst, RGBA_Draw_Context *dc, int x0, int x1, int y, int width)
{
DATA16 rgb565, *dst_itr;
DATA8 alpha;
+ int dx;
int w;
-
- if (!_is_y_inside_clip(y, dc->clip))
- return;
-
if (x0 < dc->clip.x)
x0 = dc->clip.x;
if (x1 >= dc->clip.x + dc->clip.w)
x1 = dc->clip.x + dc->clip.w - 1;
- w = x1 - x0;
- if (w < 1)
+ dx = x1 - x0 + 1;
+ if (dx < 1)
return;
- dst_itr = dst->pixels + (dst->stride * y) + x0;
- alpha = A_VAL(&dc->col.col) >> 3;
- rgb565 = RGB_565_FROM_COMPONENTS(R_VAL(&dc->col.col),
- G_VAL(&dc->col.col),
- B_VAL(&dc->col.col));
-
- if (alpha == 31)
- _soft16_scanline_fill_solid_solid(dst_itr, w, rgb565);
- else if (alpha > 0)
+ for(w = 0; w < width; w++)
{
- DATA32 rgb565_unpack;
+ int ay;
+ if(w%2) // not pair
+ ay = y+(w/2) + 1;
+ else // pair
+ ay = y-(w/2);
+ if (!_is_y_inside_clip(ay, dc->clip))
+ continue;
+
+ dst_itr = dst->pixels + (dst->stride * ay) + x0;
+ alpha = A_VAL(&dc->col.col) >> 3;
+ rgb565 = RGB_565_FROM_COMPONENTS(R_VAL(&dc->col.col),
+ G_VAL(&dc->col.col),
+ B_VAL(&dc->col.col));
+
+ if (alpha == 31)
+ _soft16_scanline_fill_solid_solid(dst_itr, dx, rgb565);
+ else if (alpha > 0)
+ {
+ DATA32 rgb565_unpack;
- rgb565_unpack = RGB_565_UNPACK(rgb565);
- alpha++;
- _soft16_scanline_fill_transp_solid(dst_itr, w, rgb565_unpack, alpha);
+ rgb565_unpack = RGB_565_UNPACK(rgb565);
+ alpha++;
+ _soft16_scanline_fill_transp_solid(dst_itr, dx, rgb565_unpack, alpha);
+ }
}
+ return;
}
static void
-_soft16_line_vert(Soft16_Image *dst, RGBA_Draw_Context *dc, int x, int y0, int y1)
+_soft16_line_vert(Soft16_Image *dst, RGBA_Draw_Context *dc, int x, int y0, int y1, int width)
{
DATA16 rgb565, *dst_itr;
DATA8 alpha;
- int h;
-
- if (!_is_x_inside_clip(x, dc->clip))
- return;
+ int dy;
+ int dx;
+ int x0;
if (y1 < y0)
{
@@ -148,41 +156,110 @@
if (y1 >= dc->clip.y + dc->clip.h)
y1 = dc->clip.y + dc->clip.h - 1;
- h = y1 - y0;
- if (h < 1)
+ dy = y1 - y0;
+ if (dy < 1)
return;
- dst_itr = dst->pixels + (dst->stride * y0) + x;
- alpha = A_VAL(&dc->col.col) >> 3;
- rgb565 = RGB_565_FROM_COMPONENTS(R_VAL(&dc->col.col),
- G_VAL(&dc->col.col),
- B_VAL(&dc->col.col));
- if (alpha == 31)
+ if(width > 1)
{
- for (; h > 0; h--, dst_itr += dst->stride)
- _soft16_pt_fill_solid_solid(dst_itr, rgb565);
+ // checking if lines are inside clip
+ // our width may left it with 1 anyway, by intersecting with clip.
+ int x1;
+ x0 = x-(width/2)+1 - width%2;
+ x1 = x+(width/2);
+ // we need to check both x0 and x1 because our clip may be in center
+ // of our line.
+ if(!_is_x_inside_clip(x0, dc->clip))
+ {
+ int dif = dc->clip.x - x0;
+ x0 += dif;
+ width -= dif;
+ x = x0 + ((x1-x0)/2);
+ if(!(width%2)) // pair
+ x--;
+ }
+ if(width < 1)
+ return;
+ if(!_is_x_inside_clip(x1, dc->clip))
+ {
+ int dif = x1 - dc->clip.x + dc->clip.w - 1;
+ x1 -= dif;
+ width -=dif;
+ x = x0 + ((x1-x0)/2);
+ if(!(width%2)) // pair
+ x--;
+ }
+ if(width < 1)
+ return;
+
+ dx = x1 - x0;
}
- else if (alpha > 0)
+
+ if(width == 1)
{
- DATA32 rgb565_unpack;
+ if (!_is_x_inside_clip(x, dc->clip))
+ return;
- rgb565_unpack = RGB_565_UNPACK(rgb565);
- alpha++;
+ dst_itr = dst->pixels + (dst->stride * y0) + x;
+ alpha = A_VAL(&dc->col.col) >> 3;
+ rgb565 = RGB_565_FROM_COMPONENTS(R_VAL(&dc->col.col),
+ G_VAL(&dc->col.col),
+ B_VAL(&dc->col.col));
+
+ if (alpha == 31)
+ {
+ for (; dy >= 0; dy--, dst_itr += dst->stride)
+ {
+ _soft16_pt_fill_solid_solid(dst_itr, rgb565);
+ }
+ }
+ else if (alpha > 0)
+ {
+ DATA32 rgb565_unpack;
+
+ rgb565_unpack = RGB_565_UNPACK(rgb565);
+ alpha++;
+
+ for (; dy >= 0; dy--, dst_itr += dst->stride)
+ {
+ _soft16_pt_fill_transp_solid(dst_itr, rgb565_unpack, alpha);
+ }
+ }
+ }
+ else
+ {
+ dst_itr = dst->pixels + (dst->stride * y0) + x0;
+ alpha = A_VAL(&dc->col.col) >> 3;
+ rgb565 = RGB_565_FROM_COMPONENTS(R_VAL(&dc->col.col),
+ G_VAL(&dc->col.col),
+ B_VAL(&dc->col.col));
- for (; h > 0; h--, dst_itr += dst->stride)
- _soft16_pt_fill_transp_solid(dst_itr, rgb565_unpack, alpha);
+ if (alpha == 31)
+ {
+ for (; dy >= 0; dy--, dst_itr += dst->stride)
+ _soft16_scanline_fill_solid_solid(dst_itr, dx+1, rgb565);
+ }
+ else if (alpha > 0)
+ {
+ DATA32 rgb565_unpack;
+
+ rgb565_unpack = RGB_565_UNPACK(rgb565);
+ alpha++;
+
+ for (; dy >= 0; dy--, dst_itr += dst->stride)
+ _soft16_scanline_fill_transp_solid(dst_itr, dx+1, rgb565_unpack, alpha);
+ }
}
+ return;
}
-
static inline void
-_soft16_line_45deg_adjust_boundaries(const struct RGBA_Draw_Context_clip clip, int *p_x0, int *p_y0, int *p_x1, int *p_y1)
+_soft16_line_45deg_adjust_boundaries(const struct RGBA_Draw_Context_clip clip, int *p_x0, int *p_y0, int x1, int *p_y1)
{
- int diff, dy, x0, y0, x1, y1;
+ int diff, dy, x0, y0, y1;
x0 = *p_x0;
y0 = *p_y0;
- x1 = *p_x1;
y1 = *p_y1;
dy = y1 - y0;
@@ -197,7 +274,6 @@
diff = x1 - (clip.x + clip.w);
if (diff > 0)
{
- x1 = clip.x + clip.w;
y1 += (dy > 0) ? -diff : diff;
}
@@ -214,7 +290,6 @@
if (diff > 0)
{
y1 = clip.y + clip.h;
- x1 -= diff;
}
}
else
@@ -223,7 +298,6 @@
if (diff > 0)
{
y1 = clip.y;
- x1 -= diff;
}
diff = y0 - (clip.y + clip.h - 1);
@@ -236,48 +310,106 @@
*p_x0 = x0;
*p_y0 = y0;
- *p_x1 = x1;
*p_y1 = y1;
}
static void
-_soft16_line_45deg(Soft16_Image *dst, RGBA_Draw_Context *dc, int x0, int y0, int x1, int y1)
+_soft16_line_45deg(Soft16_Image *dst, RGBA_Draw_Context *dc, int x0, int y0, int x1, int y1, int width)
{
- int dy, step_dst_itr, len;
+ int dy, step_dst_itr, len, w;
DATA8 alpha;
DATA16 *dst_itr, rgb565;
-
alpha = A_VAL(&dc->col.col) >> 3;
if (alpha < 1)
return;
rgb565 = RGB_565_FROM_COMPONENTS(R_VAL(&dc->col.col),
- G_VAL(&dc->col.col),
- B_VAL(&dc->col.col));
+ G_VAL(&dc->col.col),
+ B_VAL(&dc->col.col));
- dy = y1 - y0;
- step_dst_itr = 1 + ((dy > 0) ? dst->stride : -dst->stride);
+ if(width > 1)
+ {
+ int ay0, ay1, ax0, ax1;
+ for(w = 0; w < width; w++)
+ {
+ if(y0 < y1)
+ {
+ ax0 = x0;
+ if(w%2)
+ { // not pair
+ ay0 = y0+(w/2) + 1;
+ ay1 = y1+(w/2) + 1;
+
+ }
+ else
+ { // pair
+ ay0 = y0-(w/2);
+ ay1 = y1-(w/2);
+ }
+ }
+ else
+ {
+ ay0 = y0;
+ ay1 = y1;
+ if(w%2) // not pair
+ ax0 = x0+(w/2) + 1;
+ else // pair
+ ax0 = x0-(w/2);
+ }
- _soft16_line_45deg_adjust_boundaries(dc->clip, &x0, &y0, &x1, &y1);
+ _soft16_line_45deg_adjust_boundaries(dc->clip, &ax0, &ay0, x1, &ay1);
- len = (dy > 0) ? (y1 - y0) : (y0 - y1);
- if (len < 1)
- return;
+ dy = ay1 - ay0;
+ step_dst_itr = 1 + ((dy > 0) ? dst->stride : -dst->stride);
- dst_itr = dst->pixels + dst->stride * y0 + x0;
- if (alpha == 31)
- {
- for (; len > 0; len--, dst_itr += step_dst_itr)
- _soft16_pt_fill_solid_solid(dst_itr, rgb565);
+ len = (dy > 0) ? (ay1 - ay0) : (ay0 - ay1);
+ if (len < 1)
+ return;
+
+ dst_itr = dst->pixels + dst->stride * ay0 + ax0;
+ if (alpha == 31)
+ {
+ for (; len > 0; len--, dst_itr += step_dst_itr)
+ _soft16_pt_fill_solid_solid(dst_itr, rgb565);
+ }
+ else
+ {
+ DATA32 rgb565_unpack;
+
+ rgb565_unpack = RGB_565_UNPACK(rgb565);
+ alpha++;
+ for (; len > 0; len--, dst_itr += step_dst_itr)
+ _soft16_pt_fill_transp_solid(dst_itr, rgb565_unpack, alpha);
+ }
+ }
}
else
{
- DATA32 rgb565_unpack;
+ _soft16_line_45deg_adjust_boundaries(dc->clip, &x0, &y0, x1, &y1);
+
+ dy = y1 - y0;
+ step_dst_itr = 1 + ((dy > 0) ? dst->stride : -dst->stride);
+
+ len = (dy > 0) ? (y1 - y0) : (y0 - y1);
+ if (len < 1)
+ return;
+
+ dst_itr = dst->pixels + dst->stride * y0 + x0;
+ if (alpha == 31)
+ {
+ for (; len > 0; len--, dst_itr += step_dst_itr)
+ _soft16_pt_fill_solid_solid(dst_itr, rgb565);
+ }
+ else
+ {
+ DATA32 rgb565_unpack;
+
+ rgb565_unpack = RGB_565_UNPACK(rgb565);
+ alpha++;
+ for (; len > 0; len--, dst_itr += step_dst_itr)
+ _soft16_pt_fill_transp_solid(dst_itr, rgb565_unpack, alpha);
+ }
- rgb565_unpack = RGB_565_UNPACK(rgb565);
- alpha++;
- for (; len > 0; len--, dst_itr += step_dst_itr)
- _soft16_pt_fill_transp_solid(dst_itr, rgb565_unpack, alpha);
}
}
@@ -291,7 +423,7 @@
}
static void
-_soft16_line_aliased(Soft16_Image *dst, RGBA_Draw_Context *dc, int x0, int y0, int x1, int y1)
+_soft16_line_aliased(Soft16_Image *dst, RGBA_Draw_Context *dc, int x0, int y0, int x1, int y1, int width)
{
int dx, dy, step_y, step_dst_itr;
DATA32 rgb565_unpack;
@@ -304,8 +436,8 @@
alpha++;
rgb565 = RGB_565_FROM_COMPONENTS(R_VAL(&dc->col.col),
- G_VAL(&dc->col.col),
- B_VAL(&dc->col.col));
+ G_VAL(&dc->col.col),
+ B_VAL(&dc->col.col));
rgb565_unpack = RGB_565_UNPACK(rgb565);
dx = x1 - x0;
@@ -331,51 +463,141 @@
e = - (dx / 2);
y = y0;
dst_itr = dst->pixels + dst->stride * y0 + x0;
- for (x=x0; x <= x1; x++, dst_itr++)
+ if(width == 1)
{
- if (_is_xy_inside_clip(x, y, dc->clip))
- _soft16_line_aliased_pt(dst_itr, rgb565, rgb565_unpack, alpha);
-
- e += dy;
- if (e >= 0)
+ for (x=x0; x <= x1; x++, dst_itr++)
{
- dst_itr += step_dst_itr;
- y += step_y;
- e -= dx;
+ if (_is_xy_inside_clip(x, y, dc->clip))
+ _soft16_line_aliased_pt(dst_itr, rgb565, rgb565_unpack, alpha);
+ e += dy;
+ if (e >= 0)
+ {
+ dst_itr += step_dst_itr;
+ y += step_y;
+ e -= dx;
+ }
}
}
- }
- else
- {
- DATA16 *dst_itr;
- int e, x, y;
-
- e = - (dy / 2);
- x = x0;
- dst_itr = dst->pixels + dst->stride * y0 + x0;
- for (y=y0; y != y1; y += step_y, dst_itr += step_dst_itr)
- {
- if (_is_xy_inside_clip(x, y, dc->clip))
- _soft16_line_aliased_pt(dst_itr, rgb565, rgb565_unpack, alpha);
-
- e += dx;
- if (e >= 0)
+ else
+ { // width > 1
+ int w, _y0, _y1;
+ for (x=x0; x <= x1; x++, dst_itr++)
{
- dst_itr++;
- x++;
- e -= dy;
+ if(_is_x_inside_clip(x, dc->clip)) {
+ w = width;
+ _y0 = y-(width/2)+1 - width%2;
+ _y1 = _y0 + width -1;
+ if (_y0 < dc->clip.y)
+ {
+ _y0 = dc->clip.y;
+ w = _y1 - _y0 + 1;
+ }
+ if (_y1 > dc->clip.y + dc->clip.h - 1)
+ {
+ _y1 = dc->clip.y + dc->clip.h - 1;
+ w = _y1 - _y0 + 1;
+ }
+ if(w > 0)
+ {
+ DATA16 *_dst_itr;
+ for(_dst_itr = dst_itr-(y-_y0)*dst->stride;
+ w > 0;
+ w--, _dst_itr += dst->stride) {
+ _soft16_line_aliased_pt(_dst_itr, rgb565, rgb565_unpack, alpha);
+ }
+ }
+ }
+ e += dy;
+ if (e >= 0)
+ {
+ dst_itr += step_dst_itr;
+ y += step_y;
+ e -= dx;
+ }
}
}
+ } else { // dx <= dy
+ DATA16 *dst_itr;
+ int e, x, y;
+
+ e = - (dy / 2);
+ x = x0;
+ dst_itr = dst->pixels + dst->stride * y0 + x0;
+ if(width == 1)
+ {
+ for (y=y0; y != y1; y += step_y, dst_itr += step_dst_itr)
+ {
+ if (_is_xy_inside_clip(x, y, dc->clip))
+ _soft16_line_aliased_pt(dst_itr, rgb565, rgb565_unpack, alpha);
+
+
+ e += dx;
+ if (e >= 0)
+ {
+ dst_itr++;
+ x++;
+ e -= dy;
+ }
+ }
+ }
+ else
+ { // width > 1
+ DATA16 *_dst_itr;
+ int w;
+ dst_itr += -(width/2)+1 - width%2;
+ x += -(width/2)+1 - width%2;
+ for (y=y0; y != y1; y += step_y, dst_itr += step_dst_itr)
+ {
+ if(_is_y_inside_clip(y, dc->clip)) {
+ int _x;
+ _x = x;
+ if (_x < dc->clip.x)
+ {
+ _dst_itr = dst_itr + dc->clip.x - _x;
+ w = width - dc->clip.x - _x;
+ _x = dc->clip.x;
+ }
+ else
+ {
+ _dst_itr = dst_itr;
+ w = width;
+ }
+ if (_x + w > dc->clip.x + dc->clip.w - 1)
+ w = dc->clip.x + dc->clip.w - 1 - _x;
+
+ if(w == 1)
+ _soft16_line_aliased_pt(_dst_itr, rgb565, rgb565_unpack, alpha);
+ else if(w > 1)
+ {
+ if (alpha == 31)
+ _soft16_scanline_fill_solid_solid(_dst_itr, w, rgb565);
+ else if (alpha > 0)
+ _soft16_scanline_fill_transp_solid(_dst_itr, w, rgb565_unpack, alpha);
+ }
+ }
+ e += dx;
+ if (e >= 0)
+ {
+ dst_itr++;
+ x++;
+ e -= dy;
+ }
+ }
+
+ }
}
}
void
-soft16_line_draw(Soft16_Image *dst, RGBA_Draw_Context *dc, int x0, int y0, int x1, int y1)
+soft16_line_draw(Soft16_Image *dst, RGBA_Draw_Context *dc, int x0, int y0, int x1, int y1, int width)
{
struct RGBA_Draw_Context_clip c_bkp, c_tmp;
int dx, dy;
int x, y, w, h;
+ int tsum; // type of Sum (x = 0, y = 1)
+ if(width < 1)
+ return;
c_tmp.use = 1;
c_tmp.x = 0;
c_tmp.y = 0;
@@ -387,15 +609,58 @@
if (c_bkp.use)
{
RECTS_CLIP_TO_RECT(c_tmp.x, c_tmp.y, c_tmp.w, c_tmp.h,
- c_bkp.x, c_bkp.y, c_bkp.w, c_bkp.h);
+ c_bkp.x, c_bkp.y, c_bkp.w, c_bkp.h);
+
if (_is_empty_clip(c_tmp))
return;
}
- x = MIN(x0, x1);
- y = MIN(y0, y1);
- w = MAX(x0, x1) - x + 1;
- h = MAX(y0, y1) - y + 1;
+ if(width > 1)
+ {
+ if(x0 == x1)
+ { // vertical line
+ if(y0 == y1)
+ tsum = 1;
+ else
+ tsum = 0;
+ }
+ else if(y0 == y1)
+ { // horizontal line
+ tsum = 1;
+ }
+ else if( (MAX(x0, x1)-MIN(x0, x1)) > (MAX(y0, y1)-MIN(y0, y1)) )
+ { // dx > dy
+ tsum = 1;
+ }
+ else
+ { // dx <= dy
+ tsum = 0;
+ }
+
+ if(tsum > 0)
+ {
+ y = MIN(y0, y1) - (width/2)+1 - width%2;
+ h = MAX(y0, y1) + (width/2) -y +1;
+
+ x = MIN(x0, x1);
+ w = MAX(x0, x1) - x + 1;
+ }
+ else
+ {
+ x = MIN(x0, x1) - (width/2)+1 - width%2;
+ w = MAX(x0, x1) + (width/2) -x +1;
+
+ y = MIN(y0, y1);
+ h = MAX(y0, y1) - y + 1;
+ }
+ }
+ else
+ {
+ x = MIN(x0, x1);
+ y = MIN(y0, y1);
+ w = MAX(x0, x1) - x + 1;
+ h = MAX(y0, y1) - y + 1;
+ }
RECTS_CLIP_TO_RECT(c_tmp.x, c_tmp.y, c_tmp.w, c_tmp.h, x, y, w, h);
if (_is_empty_clip(c_tmp))
@@ -410,7 +675,6 @@
return;
if (y0 >= c_tmp.y + c_tmp.h && y1 >= c_tmp.y + c_tmp.h)
return;
-
dc->clip = c_tmp;
dx = x1 - x0;
dy = y1 - y0;
@@ -429,16 +693,26 @@
}
if (dx == 0 && dy == 0)
- _soft16_line_point(dst, dc, x0, y0);
- else if (dx == 0)
- _soft16_line_vert(dst, dc, x0, y0, y1);
+ {
+ if(width == 1)
+ _soft16_line_point(dst, dc, x0, y0);
+ else
+ {
+ y = y0;
+ y0 = y-(width/2)+1 - width%2;
+ y1 = y+(width/2);
+
+ _soft16_line_vert(dst, dc, x0, y0, y1, 1);
+ }
+ }
+ else if (dx == 0)
+ _soft16_line_vert(dst, dc, x0, y0, y1, width);
else if (dy == 0)
- _soft16_line_horiz(dst, dc, x0, x1, y0);
+ _soft16_line_horiz(dst, dc, x0, x1, y0, width);
else if (dy == dx || dy == -dx)
- _soft16_line_45deg(dst, dc, x0, y0, x1, y1);
+ _soft16_line_45deg(dst, dc, x0, y0, x1, y1, width);
else
- _soft16_line_aliased(dst, dc, x0, y0, x1, y1);
-
+ _soft16_line_aliased(dst, dc, x0, y0, x1, y1, width);
/* restore clip info */
dc->clip = c_bkp;
}
diff -Naur python-evas-0.2.2/include/evas/c_evas.pxd python-evas-linha/include/evas/c_evas.pxd
--- python-evas-0.2.2/include/evas/c_evas.pxd 2008-03-12 19:21:51.000000000 -0300
+++ python-evas-linha/include/evas/c_evas.pxd 2008-05-13 16:17:15.000000000 -0300
@@ -421,7 +421,10 @@
#
Evas_Object *evas_object_line_add(Evas *e)
void evas_object_line_xy_set(Evas_Object *obj, Evas_Coord x1, Evas_Coord y1, Evas_Coord x2, Evas_Coord y2)
+ void evas_object_line_xyw_set(Evas_Object *obj, Evas_Coord x1, Evas_Coord y1, Evas_Coord x2, Evas_Coord y2, int width)
void evas_object_line_xy_get(Evas_Object *obj, Evas_Coord *x1, Evas_Coord *y1, Evas_Coord *x2, Evas_Coord *y2)
+ void evas_object_line_width_get(Evas_Object *obj, int *width)
+ void evas_object_line_width_set(Evas_Object *obj, int width)
####################################################################
diff -Naur python-evas-0.2.2/evas/evas.c_evas_object_line.pxi python-evas-linha/evas/evas.c_evas_object_line.pxi
--- python-evas-0.2.2/evas/evas.c_evas_object_line.pxi 2008-03-12 19:21:51.000000000 -0300
+++ python-evas-linha/evas/evas.c_evas_object_line.pxi 2008-05-13 16:17:15.000000000 -0300
@@ -9,7 +9,7 @@
self._set_common_params(**kargs)
def _set_common_params(self, start=None, end=None, geometry=None,
- size=None, pos=None, **kargs):
+ size=None, pos=None, width=None, **kargs):
if start and end:
x1 = start[0]
y1 = start[1]
@@ -30,7 +30,10 @@
else:
y = y1
- self.xy_set(x1, y1, x2, y2)
+ if not width:
+ self.xy_set(x1, y1, x2, y2)
+ else:
+ self.xyw_set(x1, y1, x2, y2, width)
if not geometry:
if not size:
@@ -52,6 +55,15 @@
@parm: B{y2}
"""
evas_object_line_xy_set(self.obj, x1, y1, x2, y2)
+
+ def xyw_set(self, int x1, int y1, int x2, int y2, int w):
+ """@parm: B{x1}
+ @parm: B{y1}
+ @parm: B{x2}
+ @parm: B{y2}
+ @parm: B{w}
+ """
+ evas_object_line_xyw_set(self.obj, x1, y1, x2, y2, w)
def xy_get(self):
"""@return: (x1, y1, x2, y2)
@@ -67,7 +79,7 @@
"""
cdef int x2, y2
evas_object_line_xy_get(self.obj, NULL, NULL, &x2, &y2)
- evas_object_line_xy_set(self.obj, x1, y1, x2, y2)
+ evas_object_line_xyw_set(self.obj, x1, y1, x2, y2, self.width)
def start_get(self):
"""@return: (x1, y1)
@@ -80,9 +92,9 @@
property start:
def __set__(self, spec):
cdef int x1, y1, x2, y2
- x1, y1 = spec
evas_object_line_xy_get(self.obj, NULL, NULL, &x2, &y2)
- evas_object_line_xy_set(self.obj, x1, y1, x2, y2)
+ x1, y1 = spec
+ evas_object_line_xyw_set(self.obj, x1, y1, x2, y2, self.width)
def __get__(self):
cdef int x1, y1
@@ -95,7 +107,7 @@
"""
cdef int x1, y1
evas_object_line_xy_get(self.obj, &x1, &y1, NULL, NULL)
- evas_object_line_xy_set(self.obj, x1, y1, x2, y2)
+ evas_object_line_xyw_set(self.obj, x1, y1, x2, y2, self.width)
def end_get(self):
"""@return: (x2, y2)
@@ -108,15 +120,36 @@
property end:
def __set__(self, spec):
cdef int x1, y1, x2, y2
- x2, y2 = spec
evas_object_line_xy_get(self.obj, &x1, &y1, NULL, NULL)
- evas_object_line_xy_set(self.obj, x1, y1, x2, y2)
+ x2, y2 = spec
+ evas_object_line_xyw_set(self.obj, x1, y1, x2, y2, self.width)
def __get__(self):
cdef int x2, y2
evas_object_line_xy_get(self.obj, NULL, NULL, &x2, &y2)
return (x2, y2)
+ property width:
+ def __set__(self, spec):
+ evas_object_line_width_set(self.obj, spec)
+
+ def __get__(self):
+ cdef int width
+ evas_object_line_width_get(self.obj, &width)
+ return width
+
+ def width_set(self, width):
+ """@parm: B{width}
+ """
+ evas_object_line_width_set(self.obj, width)
+
+ def width_get(self):
+ """@return: width
+ @rtype: int
+ """
+ cdef int width
+ evas_object_line_width_get(self.obj, &width)
+ return width
cdef extern from "Python.h":
cdef python.PyTypeObject PyEvasLine_Type # hack to install metaclass
diff -Naur python-evas-0.2.2/evas/evas.c_evas.pxd python-evas-linha/evas/evas.c_evas.pxd
--- python-evas-0.2.2/evas/evas.c_evas.pxd 2008-03-12 19:21:51.000000000 -0300
+++ python-evas-linha/evas/evas.c_evas.pxd 2008-05-13 16:17:15.000000000 -0300
@@ -419,7 +419,10 @@
#
Evas_Object *evas_object_line_add(Evas *e)
void evas_object_line_xy_set(Evas_Object *obj, Evas_Coord x1, Evas_Coord y1, Evas_Coord x2, Evas_Coord y2)
+ void evas_object_line_xyw_set(Evas_Object *obj, Evas_Coord x1, Evas_Coord y1, Evas_Coord x2, Evas_Coord y2, int width)
void evas_object_line_xy_get(Evas_Object *obj, Evas_Coord *x1, Evas_Coord *y1, Evas_Coord *x2, Evas_Coord *y2)
+ void evas_object_line_width_get(Evas_Object *obj, int *width)
+ void evas_object_line_width_set(Evas_Object *obj, int width)
####################################################################
@@ -635,7 +638,6 @@
cdef class Line(Object):
pass
-
cdef class Image(Object):
pass
-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
enlightenment-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/enlightenment-devel