Fix PHP bug #64641: imagefilledpolygon doesn't draw horizontal line

As reported in <https://bugs.php.net/64641> 1-dimensional horizontal
filled polygons are not drawn at all. That is caused by the scanline
algorithm used for drawing filled polygons which skips the drawing of
horizontal edges, because that is normally not necessary. If, however,
the polygon consists of horizontal edges only, that obviously doesn't
work, so we add a special case handling.
master
Christoph M. Becker 2016-06-17 13:14:39 +02:00
parent a61d9f3600
commit f9f10fa9d4
6 changed files with 66 additions and 2 deletions

View File

@ -3142,6 +3142,19 @@ BGD_DECLARE(void) gdImageFilledPolygon (gdImagePtr im, gdPointPtr p, int n, int
maxy = p[i].y;
}
}
/* necessary special case: horizontal line */
if (n > 1 && miny == maxy) {
x1 = x2 = p[0].x;
for (i = 1; (i < n); i++) {
if (p[i].x < x1) {
x1 = p[i].x;
} else if (p[i].x > x2) {
x2 = p[i].x;
}
}
gdImageLine(im, x1, miny, x2, miny, c);
return;
}
pmaxy = maxy;
/* 2.0.16: Optimization by Ilia Chipitsine -- don't waste time offscreen */
/* 2.0.26: clipping rectangle is even better */

View File

@ -3,3 +3,4 @@
/gdimagefilledpolygon1
/gdimagefilledpolygon2
/gdimagefilledpolygon3
/php_bug_64641

View File

@ -4,6 +4,7 @@ LIST(APPEND TESTS_FILES
gdimagefilledpolygon2
gdimagefilledpolygon3
bug00100
php_bug_64641
)
ADD_GD_TESTS()

View File

@ -4,7 +4,8 @@ libgd_test_programs += \
gdimagefilledpolygon/gdimagefilledpolygon0 \
gdimagefilledpolygon/gdimagefilledpolygon1 \
gdimagefilledpolygon/gdimagefilledpolygon2 \
gdimagefilledpolygon/gdimagefilledpolygon3
gdimagefilledpolygon/gdimagefilledpolygon3 \
gdimagefilledpolygon/php_bug_64641
endif
EXTRA_DIST += \
@ -13,4 +14,5 @@ EXTRA_DIST += \
gdimagefilledpolygon/gdimagefilledpolygon0.png \
gdimagefilledpolygon/gdimagefilledpolygon1.png \
gdimagefilledpolygon/gdimagefilledpolygon2.png \
gdimagefilledpolygon/gdimagefilledpolygon3.png
gdimagefilledpolygon/gdimagefilledpolygon3.png \
gdimagefilledpolygon/php_bug_64641.png

View File

@ -0,0 +1,47 @@
/*
Test drawing of 1-dimensional filled polygons
We're drawing a vertical and a horizontal 1-dimensional filled polygon,
which is supposed to result in a vertical and a horizontal line.
See also <https://bugs.php.net/64641>.
*/
#include "gd.h"
#include "gdtest.h"
int main()
{
gdImagePtr im;
gdPointPtr points;
im = gdImageCreateTrueColor(640, 480);
points = (gdPointPtr)calloc(3, sizeof(gdPoint));
gdTestAssert(points != NULL);
/* vertical line */
points[0].x = 100;
points[0].y = 100;
points[1].x = 100;
points[1].y = 200;
points[2].x = 100;
points[2].y = 300;
gdImageFilledPolygon(im, points, 3, 0xFFFF00);
/* horizontal line */
points[0].x = 300;
points[0].y = 200;
points[1].x = 400;
points[1].y = 200;
points[2].x = 500;
points[2].y = 200;
gdImageFilledPolygon(im, points, 3, 0xFFFF00);
gdAssertImageEqualsToFile("gdimagefilledpolygon/php_bug_64641.png", im);
free(points);
gdImageDestroy(im);
return gdNumFailures();
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB