cvs: gd /libgd gd.c /libgd/tests/gdimageline bug00077.c bug00077_exp.png

[email protected] ("Pierre-Alain Joye")
Newsgroups php.gd.cvs
Message-ID <cvspajoye1178476896@cvsserver>
pajoye		Sun May  6 18:41:36 2007 UTC

  Modified files:              
    /gd/libgd	gd.c 
    /gd/libgd/tests/gdimageline	bug00077.c bug00077_exp.png 
  Log:
  - MFB: #77, gdImageLine does not draw all vertical lines
  
  
http://cvs.php.net/viewvc.cgi/gd/libgd/gd.c?r1=1.52&r2=1.53&diff_format=u
Index: gd/libgd/gd.c
diff -u gd/libgd/gd.c:1.52 gd/libgd/gd.c:1.53
--- gd/libgd/gd.c:1.52	Sun May  6 18:12:48 2007
+++ gd/libgd/gd.c	Sun May  6 18:41:36 2007
@@ -1,4 +1,4 @@
-/* $Id: gd.c,v 1.52 2007/05/06 18:12:48 pajoye Exp $ */
+/* $Id: gd.c,v 1.53 2007/05/06 18:41:36 pajoye Exp $ */
 #ifdef HAVE_CONFIG_H
 #include "config.h"
 #endif
@@ -1000,6 +1000,44 @@
 
 static void gdImageAALine (gdImagePtr im, int x1, int y1, int x2, int y2, int col);
 
+static void gdImageHLine(gdImagePtr im, int y, int x1, int x2, int col)
+{
+	if (im->thick > 1) {
+		int thickhalf = im->thick >> 1;
+		gdImageFilledRectangle(im, x1, y - thickhalf, x2, y + im->thick - thickhalf - 1, col);
+	} else {
+		if (x2 < x1) {
+			int t = x2;
+			x2 = x1;
+			x1 = t;
+		}
+
+		for (;x1 <= x2; x1++) {
+			gdImageSetPixel(im, x1, y, col);
+		}
+	}
+	return;
+}
+
+static void gdImageVLine(gdImagePtr im, int x, int y1, int y2, int col)
+{
+	if (im->thick > 1) {
+		int thickhalf = im->thick >> 1;
+		gdImageFilledRectangle(im, x - thickhalf, y1, x + im->thick - thickhalf - 1, y2, col);
+	} else {
+		if (y2 < y1) {
+			int t = y1;
+			y2 = y1;
+			y1 = t;
+		}
+
+		for (;y1 <= y2; y1++) {
+			gdImageSetPixel(im, x, y1, col);
+		}
+	}
+	return;
+}
+
 /* Bresenham as presented in Foley & Van Dam */
 BGD_DECLARE(void) gdImageLine (gdImagePtr im, int x1, int y1, int x2, int y2, int color)
 {
@@ -1007,6 +1045,7 @@
   int wid;
   int w, wstart;
   int thick;
+
   if (color == gdAntiAliased)
     {
       /* 
@@ -1031,6 +1070,15 @@
 
   dx = abs (x2 - x1);
   dy = abs (y2 - y1);
+
+	if (dx == 0) {
+		gdImageVLine(im, x1, y1, y2, color);
+		return;
+	} else if (dy == 0) {
+		gdImageHLine(im, y1, x1, x2, color);
+		return;
+	}
+
   if (dy <= dx)
     {
       /* More-or-less horizontal. use wid for vertical stroke */
@@ -3383,6 +3431,7 @@
 	/* keep them as 32bits */
 	long x, y, inc;
 	long dx, dy,tmp;
+
 	if (!im->trueColor) {
 		/* TBB: don't crash when the image is of the wrong type */
 		gdImageLine(im, x1, y1, x2, y2, col);
@@ -3396,6 +3445,15 @@
 	dx = x2 - x1;
 	dy = y2 - y1;
 
+	/* Axis aligned lines */
+	if (dx == 0) {
+		gdImageHLine(im, y1, x1, x2, col);
+		return;
+	} else if (dy == 0) {
+		gdImageVLine(im, x1, y1, y2, col);
+		return;
+	}
+
 	if (dx == 0 && dy == 0) {
 		/* TBB: allow setting points */
 		gdImageSetAAPixelColor(im, x1, y1, col, 0xFF);
http://cvs.php.net/viewvc.cgi/gd/libgd/tests/gdimageline/bug00077.c?r1=1.1&r2=1.2&diff_format=u
Index: gd/libgd/tests/gdimageline/bug00077.c
diff -u /dev/null gd/libgd/tests/gdimageline/bug00077.c:1.2
--- /dev/null	Sun May  6 18:41:36 2007
+++ gd/libgd/tests/gdimageline/bug00077.c	Sun May  6 18:41:36 2007
@@ -0,0 +1,34 @@
+#include "gdtest.h"
+#include "gd.h"
+
+int main()
+{
+ 	gdImagePtr im;
+	const char *exp = "test.png";
+	const int files_cnt = 4;
+	FILE *fp;
+	int i = 0;
+	int error = 0;
+
+	char path[1024];
+
+
+	im = gdImageCreateTrueColor(11, 11);
+	gdImageFilledRectangle(im, 0, 0, 10, 10, 0xFFFFFF);
+	gdImageSetThickness(im, 1);
+
+	gdImageLine(im, 0, 10, 0, 0, 0x0);
+	gdImageLine(im, 5, 10, 5, 0, 0x0);
+	gdImageLine(im, 10, 5, 0, 5, 0x0);
+	gdImageLine(im, 10, 10, 0, 10, 0x0);
+
+	sprintf(path, "%s/gdimageline/%s", GDTEST_TOP_DIR, exp);
+
+	if (!gdAssertImageEqualsToFile(path, im)) {
+		error = 1;
+	}
+
+	gdImageDestroy(im);
+
+	return error;
+}
http://cvs.php.net/viewvc.cgi/gd/libgd/tests/gdimageline/bug00077_exp.png?r1=1.1&r2=1.2&diff_format=u
Index: gd/libgd/tests/gdimageline/bug00077_exp.png
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.