[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[E-devel] bug in imlib2



imlib_image_draw_line has a bug in which it fails to draw a line correctly
when dx>0, dy<0, and dy>dx.  It mistakenly uses the shallow line code
path, and the resulting line is always drawn as if dy=dx.

I have attached a test case for the bug, and a patch to fix it.

~ John Williams

#include <X11/Xlib.h>
#include <stdio.h>
#include <string.h>
#include <Imlib2.h>

int main(int argc, char **argv)
{
  Imlib_Image image;
  
  image = imlib_create_image(100,100);
  imlib_context_set_image(image);
  imlib_context_set_color(255,255,255,255);
  imlib_image_fill_rectangle(0,0,100,100);
  imlib_context_set_color(0,0,0,255);

/* show the destination point */
  imlib_image_draw_line(74,16,74,16,0);
/* try to draw a line to there */
  imlib_image_draw_line(50,50,74,16,0);

  imlib_save_image("bug.png");
}
Index: line.c
===================================================================
RCS file: /var/cvs/e/e17/libs/imlib2/src/lib/line.c,v
retrieving revision 1.1
diff -u -r1.1 line.c
--- line.c	1 Nov 2004 09:45:31 -0000	1.1
+++ line.c	3 Dec 2006 00:56:37 -0000
@@ -404,7 +404,7 @@
    y1 -= cly;
 
    /* shallow: x-parametric */
-   if ((dy < dx) || (dy < -dx))
+   if (abs(dy) < abs(dx))
      {
 	SETUP_LINE_SHALLOW
 
@@ -513,7 +513,7 @@
    y1 -= cly;
 
    /* shallow: x-parametric */
-   if ((dy < dx) || (dy < -dx))
+   if (abs(dy) < abs(dx))
      {
 	SETUP_LINE_SHALLOW