cvs: gd /libgd ISSUES gd.c /libgd/tests bug00003.c

[email protected] ("Pierre-Alain Joye")
Newsgroups php.gd.cvs
Message-ID <cvspajoye1159431390@cvsserver>
pajoye		Thu Sep 28 08:16:30 2006 UTC

  Added files:                 
    /gd/libgd/tests	bug00003.c 

  Modified files:              
    /gd/libgd	ISSUES gd.c 
  Log:
  - #3, gdImageRectanle draws the corners twice
  
  
http://cvs.php.net/viewvc.cgi/gd/libgd/ISSUES?r1=1.2&r2=1.3&diff_format=u
Index: gd/libgd/ISSUES
diff -u gd/libgd/ISSUES:1.2 gd/libgd/ISSUES:1.3
--- gd/libgd/ISSUES:1.2	Thu Sep 28 00:01:37 2006
+++ gd/libgd/ISSUES	Thu Sep 28 08:16:30 2006
@@ -2,5 +2,7 @@
 |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
 #1, Initialize values this also provides a 5x speedup in the imagefttext.phpt 
     test, because without this patch it never got cache hits (Nuno Lopes)
-#2, imagefill, multiple segfaults with complex patterns, transparent colors
+#2, gdImageFill, multiple segfaults with complex patterns, transparent colors
   or invalid color index
+#3, gdImageRectangle draws corners twice (affects rectangles with alpha 
+    channel)
http://cvs.php.net/viewvc.cgi/gd/libgd/gd.c?r1=1.32&r2=1.33&diff_format=u
Index: gd/libgd/gd.c
diff -u gd/libgd/gd.c:1.32 gd/libgd/gd.c:1.33
--- gd/libgd/gd.c:1.32	Wed Sep 27 23:58:50 2006
+++ gd/libgd/gd.c	Thu Sep 28 08:16:30 2006
@@ -1871,33 +1871,75 @@
 	gdFree(stack);
 }
 
-
 BGD_DECLARE(void) gdImageRectangle (gdImagePtr im, int x1, int y1, int x2, int y2, int color)
 {
-  int x1h = x1, x1v = x1, y1h = y1, y1v = y1, x2h = x2, x2v = x2, y2h = y2,
-    y2v = y2;
-  int thick = im->thick;
-  if (thick > 1)
-    {
-      int half = thick / 2;
-      int half1 = thick - half;
+	int x1h = x1, x1v = x1, y1h = y1, y1v = y1, x2h = x2, x2v = x2, y2h = y2, y2v = y2;
+	int thick = im->thick;
+	int half1 = 1;
+	int t;
+
+	if (y2 < y1) {
+		t=y1;
+		y1 = y2;
+		y2 = t;
+
+		t = x1;
+		x1 = x2;
+		x2 = t;
+	}
+
+	x1h = x1; x1v = x1; y1h = y1; y1v = y1; x2h = x2; x2v = x2; y2h = y2; y2v = y2;
+	if (thick > 1) {
+		int cx, cy, x1ul, y1ul, x2lr, y2lr;
+		int half = thick >> 1;
+		half1 = thick - half;
+		x1ul = x1 - half;
+		y1ul = y1 - half;
+		
+		x2lr = x2 + half;
+		y2lr = y2 + half;
+
+		cy = y1ul + thick;
+		while (cy-- > y1ul) {
+			cx = x1ul - 1;
+			while (cx++ < x2lr) {
+				gdImageSetPixel(im, cx, cy, color);
+			}
+		}
 
-      if (y1 < y2)
-	{
-	  y1v = y1h - half;
-	  y2v = y2h + half1 - 1;
-	}
-      else
-	{
-	  y1v = y1h + half1 - 1;
-	  y2v = y2h - half;
-	}
-    }
+		cy = y2lr - thick;
+		while (cy++ < y2lr) {
+			cx = x1ul - 1;
+			while (cx++ < x2lr) {
+				gdImageSetPixel(im, cx, cy, color);
+			}
+		}
+
+		cy = y1ul + thick - 1;
+		while (cy++ < y2lr -thick) {
+			cx = x1ul - 1;
+			while (cx++ < x1ul + thick) {
+				gdImageSetPixel(im, cx, cy, color);
+			}
+		}
+
+		cy = y1ul + thick - 1;
+		while (cy++ < y2lr -thick) {
+			cx = x2lr - thick - 1;
+			while (cx++ < x2lr) {
+				gdImageSetPixel(im, cx, cy, color);
+			}
+		}
 
-  gdImageLine (im, x1h, y1h, x2h, y1h, color);
-  gdImageLine (im, x1h, y2h, x2h, y2h, color);
-  gdImageLine (im, x1v, y1v, x1v, y2v, color);
-  gdImageLine (im, x2v, y1v, x2v, y2v, color);
+		return;
+	} else {
+		y1v = y1h + 1;
+		y2v = y2h - 1;
+		gdImageLine(im, x1h, y1h, x2h, y1h, color);
+		gdImageLine(im, x1h, y2h, x2h, y2h, color);
+		gdImageLine(im, x1v, y1v, x1v, y2v, color);
+		gdImageLine(im, x2v, y1v, x2v, y2v, color);
+	}
 }
 
 BGD_DECLARE(void) gdImageFilledRectangle (gdImagePtr im, int x1, int y1, int x2, int y2,

http://cvs.php.net/viewvc.cgi/gd/libgd/tests/bug00003.c?view=markup&rev=1.1
Index: gd/libgd/tests/bug00003.c
+++ gd/libgd/tests/bug00003.c
#include "gd.h"

int main()
{
 	gdImagePtr im;
	FILE *fp;


	im = gdImageCreateTrueColor(100,100);
	gdImageRectangle(im, 2,2, 80,95, 0x50FFFFFF);
	fp = fopen("a.png", "wb");
 	/* Write img to stdout */
 	gdImagePng(im,fp);
	fclose(fp);

 	/* Destroy it */
 	gdImageDestroy(im);

 	return 0;
}
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.