]> granicus.if.org Git - php/commitdiff
Fix #64641: imagefilledpolygon doesn't draw horizontal line
authorChristoph M. Becker <cmbecker69@gmx.de>
Sun, 19 Jun 2016 11:54:55 +0000 (13:54 +0200)
committerChristoph M. Becker <cmb@php.net>
Mon, 20 Jun 2016 13:17:52 +0000 (15:17 +0200)
As has been reported, 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.

That has also been fixed in libgd with
<https://github.com/libgd/libgd/commit/f9f10fa9>.

ext/gd/libgd/gd.c
ext/gd/tests/bug64641.phpt [new file with mode: 0644]
ext/gd/tests/bug64641.png [new file with mode: 0644]
ext/gd/tests/imagecolorallocatealpha_basic.phpt
ext/gd/tests/imagefilledarc_basic.phpt
ext/gd/tests/imagefilledarc_variation1.phpt
ext/gd/tests/imagefilledarc_variation2.phpt
ext/gd/tests/imagegammacorrect_basic.phpt
ext/gd/tests/imagegammacorrect_variation1.phpt
ext/gd/tests/imagetruecolortopalette_basic.phpt

index 89c7dbdd5852c843017eb63949e82ef324ff1f47..7ba4e0c91190fb6c746aac6bef6b6e495465e6a3 100644 (file)
@@ -2717,6 +2717,19 @@ void gdImageFilledPolygon (gdImagePtr im, gdPointPtr p, int n, int c)
                        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 */
        if (miny < 0) {
diff --git a/ext/gd/tests/bug64641.phpt b/ext/gd/tests/bug64641.phpt
new file mode 100644 (file)
index 0000000..d8dae9a
--- /dev/null
@@ -0,0 +1,38 @@
+--TEST--
+Bug #64641 (imagefilledpolygon doesn't draw horizontal line)
+--SKIPIF--
+<?php
+if (!extension_loaded('gd')) die("skip gd extension not available\n");
+?>
+--FILE--
+<?php
+require_once __DIR__ . '/similarity.inc';
+
+$im = imagecreatetruecolor(640, 480);
+
+$points = array(
+       100, 100,
+       100, 200,
+       100, 300
+);
+imagefilledpolygon($im, $points, 3, 0xFFFF00);
+
+$points = array(
+       300, 200,
+       400, 200,
+       500, 200
+);
+imagefilledpolygon($im, $points, 3, 0xFFFF00);
+
+$ex = imagecreatefrompng(__DIR__ . '/bug64641.png');
+if (($diss = calc_image_dissimilarity($ex, $im)) < 1e-5) {
+       echo "IDENTICAL";
+} else {
+       echo "DISSIMILARITY: $diss";
+}
+imagedestroy($ex);
+
+imagedestroy($im);
+?>
+--EXPECT--
+IDENTICAL
diff --git a/ext/gd/tests/bug64641.png b/ext/gd/tests/bug64641.png
new file mode 100644 (file)
index 0000000..8376262
Binary files /dev/null and b/ext/gd/tests/bug64641.png differ
index 720c50098a9dc8db8248db96ff19ce73d39c5d2e..bdc417387fe7f4eba5252d78998e73d18106799a 100644 (file)
@@ -26,5 +26,5 @@ var_dump(md5(base64_encode($imgsrc)));
 var_dump($corA);
 ?>
 --EXPECT--
-string(32) "b856a0b1a15efe0f79551ebbb5651fe8"
+string(32) "2a6424e4cb4e1b7391dfff74bf136bde"
 int(842163455)
\ No newline at end of file
index 9ff9bd37168390da8ad93c22637abf4a78e36e19..3357dd75aaddd4055aac660345055df0d60d0969 100644 (file)
@@ -25,4 +25,4 @@ ob_end_clean();
 echo md5(base64_encode($img));
 ?>
 --EXPECT--
-894f394c7f2e2364642ef27fea6bfc33
+beffeaf5231adaaff1f21a2108fb6f7e
index 2dec1ead2cb08f81dc04bdb1c3642d260e8c8872..2254b0910ff0952c8002369ee31407c82f3296d0 100644 (file)
@@ -25,4 +25,4 @@ ob_end_clean();
 echo md5(base64_encode($img));
 ?>
 --EXPECT--
-b77bbb8207e5adbebfcc8bd1c4074305
+b467492b806001c3720b3f18cfbde5b0
index 5c8ffba0014d1942ebad2d52f21328a63cd6a961..57686ab64ce1c1d60db2bb7fabc46f7c8061c617 100644 (file)
@@ -25,4 +25,4 @@ ob_end_clean();
 echo md5(base64_encode($img));
 ?>
 --EXPECT--
-b8b572812b3c85678f6c38c4ecca7619
+cfad369fc6d863785d3c95b4b4788225
index b568728e7140b0979611d5fa2c1eb4be8f553961..33d6b1ad6c93d0fe33ba26efd0dfad4d820086e4 100644 (file)
@@ -29,4 +29,4 @@ if ($gamma){
 echo md5(base64_encode($img));
 ?>
 --EXPECT--
-30639772903913594bc665743e1b9ab8
+e79553115df689ea5df18a4636380569
index cda96c62876c61b7c3cd4bb889a79faeaefd25a6..7a321f89d87ef50520e373e2061682f91c420239 100644 (file)
@@ -29,4 +29,4 @@ if ($gamma){
 echo md5(base64_encode($img));
 ?>
 --EXPECT--
-7716c0905ae08bd84b4d6cba8969a42e
+b017b1ddc8bda00e82aa8cbfb54c35d4
index b0a0394b55ce69b9401d0b6f55700e11621bd335..3bd0d3102e13d46f775f1e6c674cea64bfd4dad4 100644 (file)
@@ -28,4 +28,4 @@ echo md5(base64_encode($img));
 ?>
 --EXPECT--
 bool(true)
-0843f63ab2f9fddedd69b0b421686bc5
\ No newline at end of file
+1d41787ff70aa0c7eea5ee9304afa36b
\ No newline at end of file