cvs: gd(GD_2_0) /libgd gd.c /libgd/tests/gdimageline bug00072.c bug00072_exp.png
[email protected] ("Pierre-Alain Joye")
| Newsgroups | php.gd.cvs |
|---|---|
| Message-ID | <cvspajoye1176135523@cvsserver> |
pajoye Mon Apr 9 16:18:43 2007 UTC
Added files: (Branch: GD_2_0)
/gd/libgd/tests/gdimageline bug00072.c bug00072_exp.png
Modified files:
/gd/libgd gd.c
Log:
- #72, gdImageAALine draws axis aligned lines two pixels large
. add gdImageVLine and HLine, not exported (will be 2.1.0)
http://cvs.php.net/viewvc.cgi/gd/libgd/gd.c?r1=1.49.2.4&r2=1.49.2.5&diff_format=u
Index: gd/libgd/gd.c
diff -u gd/libgd/gd.c:1.49.2.4 gd/libgd/gd.c:1.49.2.5
--- gd/libgd/gd.c:1.49.2.4 Sun Apr 1 20:41:01 2007
+++ gd/libgd/gd.c Mon Apr 9 16:18:43 2007
@@ -1,4 +1,4 @@
-/* $Id: gd.c,v 1.49.2.4 2007/04/01 20:41:01 pajoye Exp $ */
+/* $Id: gd.c,v 1.49.2.5 2007/04/09 16:18:43 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 */
@@ -3372,6 +3420,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);
@@ -3385,6 +3434,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/bug00072.c?view=markup&rev=1.1
Index: gd/libgd/tests/gdimageline/bug00072.c
+++ gd/libgd/tests/gdimageline/bug00072.c