tabe                                     Wed, 20 Jan 2010 09:39:06 +0000

Revision: http://svn.php.net/viewvc?view=revision&revision=293762

Log:
fix libgd FS100 (spurious horizontal line drawn by gdImageFilledPolygon)

Changed paths:
    U   php/php-src/branches/PHP_5_2/ext/gd/libgd/gd.c
    A   php/php-src/branches/PHP_5_2/ext/gd/tests/libgd00100.phpt
    U   php/php-src/branches/PHP_5_3/ext/gd/libgd/gd.c
    A   php/php-src/branches/PHP_5_3/ext/gd/tests/libgd00100.phpt
    U   php/php-src/trunk/ext/gd/libgd/gd.c
    A   php/php-src/trunk/ext/gd/tests/libgd00100.phpt

Modified: php/php-src/branches/PHP_5_2/ext/gd/libgd/gd.c
===================================================================
--- php/php-src/branches/PHP_5_2/ext/gd/libgd/gd.c	2010-01-20 08:16:44 UTC (rev 293761)
+++ php/php-src/branches/PHP_5_2/ext/gd/libgd/gd.c	2010-01-20 09:39:06 UTC (rev 293762)
@@ -3241,7 +3241,7 @@
 {
 	int i;
 	int y;
-	int miny, maxy;
+	int miny, maxy, pmaxy;
 	int x1, y1;
 	int x2, y2;
 	int ind1, ind2;
@@ -3285,7 +3285,7 @@
 			maxy = p[i].y;
 		}
 	}
-
+	pmaxy = maxy;
 	/* 2.0.16: Optimization by Ilia Chipitsine -- don't waste time offscreen */
 	if (miny < 0) {
 		miny = 0;
@@ -3327,13 +3327,13 @@
 			 */
 			if (y >= y1 && y < y2) {
 				im->polyInts[ints++] = (float) ((y - y1) * (x2 - x1)) / (float) (y2 - y1) + 0.5 + x1;
-			} else if (y == maxy && y > y1 && y <= y2) {
-				im->polyInts[ints++] = (float) ((y - y1) * (x2 - x1)) / (float) (y2 - y1) + 0.5 + x1;
+			} else if (y == pmaxy && y == y2) {
+				im->polyInts[ints++] = x2;
 			}
 		}
 		qsort(im->polyInts, ints, sizeof(int), gdCompareInt);

-		for (i = 0; i < ints; i += 2) {
+		for (i = 0; i < ints - 1; i += 2) {
 			gdImageLine(im, im->polyInts[i], y, im->polyInts[i + 1], y, fill_color);
 		}
 	}

Added: php/php-src/branches/PHP_5_2/ext/gd/tests/libgd00100.phpt
===================================================================
--- php/php-src/branches/PHP_5_2/ext/gd/tests/libgd00100.phpt	                        (rev 0)
+++ php/php-src/branches/PHP_5_2/ext/gd/tests/libgd00100.phpt	2010-01-20 09:39:06 UTC (rev 293762)
@@ -0,0 +1,119 @@
+--TEST--
+libgd #100 (spurious horizontal line drawn by gdImageFilledPolygon)
+--SKIPIF--
+<?php
+	if (!extension_loaded('gd')) die("skip gd extension not available\n");
+	if (!GD_BUNDLED) die("skip requires bundled GD library\n");
+?>
+--FILE--
+<?php
+$im = imagecreatetruecolor(256, 256);
+
+$white   = imagecolorallocatealpha($im, 255, 255, 255, 10);
+$black   = imagecolorallocatealpha($im,   0,   0,   0, 10);
+$red     = imagecolorallocatealpha($im, 255,   0,   0, 10);
+$green   = imagecolorallocatealpha($im,   0, 255,   0, 10);
+$blue    = imagecolorallocatealpha($im,   0,   0, 255, 10);
+$yellow  = imagecolorallocatealpha($im, 255, 255,   0, 10);
+$cyan    = imagecolorallocatealpha($im,   0, 255, 255, 10);
+$magenta = imagecolorallocatealpha($im, 255,   0, 255, 10);
+$purple  = imagecolorallocatealpha($im, 100,   0, 100, 10);
+
+imagefilledrectangle($im, 0, 0, 255, 255, $white);
+
+// M (bridge)
+$top = 240;
+$bot = 255;
+$d = 30;
+$x = 100;
+$points = array(
+  $x,      $top,
+  $x+2*$d, $top,
+  $x+2*$d, $bot,
+  $x+$d,   ($top+$bot)/2,
+  $x,      $bot
+);
+imagefilledpolygon($im, $points, 5, $yellow);
+
+// left-facing M not on baseline
+$top = 40;
+$bot = 70;
+$left = 120;
+$right = 180;
+$points = array(
+  $left,  $top,
+  $right, $top,
+  $right, $bot,
+  $left,  $bot,
+  ($left+$right)/2, ($top+$bot)/2
+);
+imagefilledpolygon($im, $points, 5, $purple);
+
+// left-facing M on baseline
+$top = 240;
+$bot = 270;
+$left = 20;
+$right = 80;
+$points = array(
+  $left,  $top,
+  $right, $top,
+  $right, $bot,
+  $left,  $bot,
+  ($left+$right)/2, ($top+$bot)/2
+);
+imagefilledpolygon($im, $points, 5, $magenta);
+
+// left-facing M on ceiling
+$top = -15;
+$bot = 15;
+$left = 20;
+$right = 80;
+$points = array(
+  $left,  $top,
+  $right, $top,
+  $right, $bot,
+  $left,  $bot,
+  ($left+$right)/2, ($top+$bot)/2
+);
+imagefilledpolygon($im, $points, 5, $blue);
+
+$d = 30;
+$x = 150;
+$y = 150;
+$diamond = array($x-$d, $y, $x, $y+$d, $x+$d, $y, $x, $y-$d);
+imagefilledpolygon($im, $diamond, 4, $green);
+
+$x = 180;
+$y = 225;
+$diamond = array($x-$d, $y, $x, $y+$d, $x+$d, $y, $x, $y-$d);
+imagefilledpolygon($im, $diamond, 4, $red);
+
+$x = 225;
+$y = 255;
+$diamond = array($x-$d, $y, $x, $y+$d, $x+$d, $y, $x, $y-$d);
+imagefilledpolygon($im, $diamond, 4, $cyan);
+
+// M (bridge) not touching bottom boundary
+$top = 100;
+$bot = 150;
+$x = 30;
+$points = array(
+  $x,      $top,
+  $x+2*$d, $top,
+  $x+2*$d, $bot,
+  $x+$d,   ($top+$bot)/2,
+  $x,      $bot
+);
+imagefilledpolygon($im, $points, 5, $black);
+
+ob_start();
+imagepng($im);
+$png = ob_get_contents();
+ob_end_clean();
+
+echo md5($png);
+
+imagedestroy($im);
+?>
+--EXPECTF--
+2e6cf558bb4dadf60c8b608d5f8cda4e

Modified: php/php-src/branches/PHP_5_3/ext/gd/libgd/gd.c
===================================================================
--- php/php-src/branches/PHP_5_3/ext/gd/libgd/gd.c	2010-01-20 08:16:44 UTC (rev 293761)
+++ php/php-src/branches/PHP_5_3/ext/gd/libgd/gd.c	2010-01-20 09:39:06 UTC (rev 293762)
@@ -2614,7 +2614,7 @@
 {
 	int i;
 	int y;
-	int miny, maxy;
+	int miny, maxy, pmaxy;
 	int x1, y1;
 	int x2, y2;
 	int ind1, ind2;
@@ -2658,7 +2658,7 @@
 			maxy = p[i].y;
 		}
 	}
-
+	pmaxy = maxy;
 	/* 2.0.16: Optimization by Ilia Chipitsine -- don't waste time offscreen */
 	if (miny < 0) {
 		miny = 0;
@@ -2700,13 +2700,13 @@
 			 */
 			if (y >= y1 && y < y2) {
 				im->polyInts[ints++] = (float) ((y - y1) * (x2 - x1)) / (float) (y2 - y1) + 0.5 + x1;
-			} else if (y == maxy && y > y1 && y <= y2) {
-				im->polyInts[ints++] = (float) ((y - y1) * (x2 - x1)) / (float) (y2 - y1) + 0.5 + x1;
+			} else if (y == pmaxy && y == y2) {
+				im->polyInts[ints++] = x2;
 			}
 		}
 		qsort(im->polyInts, ints, sizeof(int), gdCompareInt);

-		for (i = 0; i < ints; i += 2) {
+		for (i = 0; i < ints - 1; i += 2) {
 			gdImageLine(im, im->polyInts[i], y, im->polyInts[i + 1], y, fill_color);
 		}
 	}

Added: php/php-src/branches/PHP_5_3/ext/gd/tests/libgd00100.phpt
===================================================================
--- php/php-src/branches/PHP_5_3/ext/gd/tests/libgd00100.phpt	                        (rev 0)
+++ php/php-src/branches/PHP_5_3/ext/gd/tests/libgd00100.phpt	2010-01-20 09:39:06 UTC (rev 293762)
@@ -0,0 +1,119 @@
+--TEST--
+libgd #100 (spurious horizontal line drawn by gdImageFilledPolygon)
+--SKIPIF--
+<?php
+	if (!extension_loaded('gd')) die("skip gd extension not available\n");
+	if (!GD_BUNDLED) die("skip requires bundled GD library\n");
+?>
+--FILE--
+<?php
+$im = imagecreatetruecolor(256, 256);
+
+$white   = imagecolorallocatealpha($im, 255, 255, 255, 10);
+$black   = imagecolorallocatealpha($im,   0,   0,   0, 10);
+$red     = imagecolorallocatealpha($im, 255,   0,   0, 10);
+$green   = imagecolorallocatealpha($im,   0, 255,   0, 10);
+$blue    = imagecolorallocatealpha($im,   0,   0, 255, 10);
+$yellow  = imagecolorallocatealpha($im, 255, 255,   0, 10);
+$cyan    = imagecolorallocatealpha($im,   0, 255, 255, 10);
+$magenta = imagecolorallocatealpha($im, 255,   0, 255, 10);
+$purple  = imagecolorallocatealpha($im, 100,   0, 100, 10);
+
+imagefilledrectangle($im, 0, 0, 255, 255, $white);
+
+// M (bridge)
+$top = 240;
+$bot = 255;
+$d = 30;
+$x = 100;
+$points = array(
+  $x,      $top,
+  $x+2*$d, $top,
+  $x+2*$d, $bot,
+  $x+$d,   ($top+$bot)/2,
+  $x,      $bot
+);
+imagefilledpolygon($im, $points, 5, $yellow);
+
+// left-facing M not on baseline
+$top = 40;
+$bot = 70;
+$left = 120;
+$right = 180;
+$points = array(
+  $left,  $top,
+  $right, $top,
+  $right, $bot,
+  $left,  $bot,
+  ($left+$right)/2, ($top+$bot)/2
+);
+imagefilledpolygon($im, $points, 5, $purple);
+
+// left-facing M on baseline
+$top = 240;
+$bot = 270;
+$left = 20;
+$right = 80;
+$points = array(
+  $left,  $top,
+  $right, $top,
+  $right, $bot,
+  $left,  $bot,
+  ($left+$right)/2, ($top+$bot)/2
+);
+imagefilledpolygon($im, $points, 5, $magenta);
+
+// left-facing M on ceiling
+$top = -15;
+$bot = 15;
+$left = 20;
+$right = 80;
+$points = array(
+  $left,  $top,
+  $right, $top,
+  $right, $bot,
+  $left,  $bot,
+  ($left+$right)/2, ($top+$bot)/2
+);
+imagefilledpolygon($im, $points, 5, $blue);
+
+$d = 30;
+$x = 150;
+$y = 150;
+$diamond = array($x-$d, $y, $x, $y+$d, $x+$d, $y, $x, $y-$d);
+imagefilledpolygon($im, $diamond, 4, $green);
+
+$x = 180;
+$y = 225;
+$diamond = array($x-$d, $y, $x, $y+$d, $x+$d, $y, $x, $y-$d);
+imagefilledpolygon($im, $diamond, 4, $red);
+
+$x = 225;
+$y = 255;
+$diamond = array($x-$d, $y, $x, $y+$d, $x+$d, $y, $x, $y-$d);
+imagefilledpolygon($im, $diamond, 4, $cyan);
+
+// M (bridge) not touching bottom boundary
+$top = 100;
+$bot = 150;
+$x = 30;
+$points = array(
+  $x,      $top,
+  $x+2*$d, $top,
+  $x+2*$d, $bot,
+  $x+$d,   ($top+$bot)/2,
+  $x,      $bot
+);
+imagefilledpolygon($im, $points, 5, $black);
+
+ob_start();
+imagepng($im);
+$png = ob_get_contents();
+ob_end_clean();
+
+echo md5($png);
+
+imagedestroy($im);
+?>
+--EXPECTF--
+2e6cf558bb4dadf60c8b608d5f8cda4e

Modified: php/php-src/trunk/ext/gd/libgd/gd.c
===================================================================
--- php/php-src/trunk/ext/gd/libgd/gd.c	2010-01-20 08:16:44 UTC (rev 293761)
+++ php/php-src/trunk/ext/gd/libgd/gd.c	2010-01-20 09:39:06 UTC (rev 293762)
@@ -2609,7 +2609,7 @@
 {
 	int i;
 	int y;
-	int miny, maxy;
+	int miny, maxy, pmaxy;
 	int x1, y1;
 	int x2, y2;
 	int ind1, ind2;
@@ -2653,7 +2653,7 @@
 			maxy = p[i].y;
 		}
 	}
-
+	pmaxy = maxy;
 	/* 2.0.16: Optimization by Ilia Chipitsine -- don't waste time offscreen */
 	if (miny < 0) {
 		miny = 0;
@@ -2695,13 +2695,13 @@
 			 */
 			if (y >= y1 && y < y2) {
 				im->polyInts[ints++] = (float) ((y - y1) * (x2 - x1)) / (float) (y2 - y1) + 0.5 + x1;
-			} else if (y == maxy && y > y1 && y <= y2) {
-				im->polyInts[ints++] = (float) ((y - y1) * (x2 - x1)) / (float) (y2 - y1) + 0.5 + x1;
+			} else if (y == pmaxy && y == y2) {
+				im->polyInts[ints++] = x2;
 			}
 		}
 		qsort(im->polyInts, ints, sizeof(int), gdCompareInt);

-		for (i = 0; i < ints; i += 2) {
+		for (i = 0; i < ints - 1; i += 2) {
 			gdImageLine(im, im->polyInts[i], y, im->polyInts[i + 1], y, fill_color);
 		}
 	}

Added: php/php-src/trunk/ext/gd/tests/libgd00100.phpt
===================================================================
--- php/php-src/trunk/ext/gd/tests/libgd00100.phpt	                        (rev 0)
+++ php/php-src/trunk/ext/gd/tests/libgd00100.phpt	2010-01-20 09:39:06 UTC (rev 293762)
@@ -0,0 +1,119 @@
+--TEST--
+libgd #100 (spurious horizontal line drawn by gdImageFilledPolygon)
+--SKIPIF--
+<?php
+	if (!extension_loaded('gd')) die("skip gd extension not available\n");
+	if (!GD_BUNDLED) die("skip requires bundled GD library\n");
+?>
+--FILE--
+<?php
+$im = imagecreatetruecolor(256, 256);
+
+$white   = imagecolorallocatealpha($im, 255, 255, 255, 10);
+$black   = imagecolorallocatealpha($im,   0,   0,   0, 10);
+$red     = imagecolorallocatealpha($im, 255,   0,   0, 10);
+$green   = imagecolorallocatealpha($im,   0, 255,   0, 10);
+$blue    = imagecolorallocatealpha($im,   0,   0, 255, 10);
+$yellow  = imagecolorallocatealpha($im, 255, 255,   0, 10);
+$cyan    = imagecolorallocatealpha($im,   0, 255, 255, 10);
+$magenta = imagecolorallocatealpha($im, 255,   0, 255, 10);
+$purple  = imagecolorallocatealpha($im, 100,   0, 100, 10);
+
+imagefilledrectangle($im, 0, 0, 255, 255, $white);
+
+// M (bridge)
+$top = 240;
+$bot = 255;
+$d = 30;
+$x = 100;
+$points = array(
+  $x,      $top,
+  $x+2*$d, $top,
+  $x+2*$d, $bot,
+  $x+$d,   ($top+$bot)/2,
+  $x,      $bot
+);
+imagefilledpolygon($im, $points, 5, $yellow);
+
+// left-facing M not on baseline
+$top = 40;
+$bot = 70;
+$left = 120;
+$right = 180;
+$points = array(
+  $left,  $top,
+  $right, $top,
+  $right, $bot,
+  $left,  $bot,
+  ($left+$right)/2, ($top+$bot)/2
+);
+imagefilledpolygon($im, $points, 5, $purple);
+
+// left-facing M on baseline
+$top = 240;
+$bot = 270;
+$left = 20;
+$right = 80;
+$points = array(
+  $left,  $top,
+  $right, $top,
+  $right, $bot,
+  $left,  $bot,
+  ($left+$right)/2, ($top+$bot)/2
+);
+imagefilledpolygon($im, $points, 5, $magenta);
+
+// left-facing M on ceiling
+$top = -15;
+$bot = 15;
+$left = 20;
+$right = 80;
+$points = array(
+  $left,  $top,
+  $right, $top,
+  $right, $bot,
+  $left,  $bot,
+  ($left+$right)/2, ($top+$bot)/2
+);
+imagefilledpolygon($im, $points, 5, $blue);
+
+$d = 30;
+$x = 150;
+$y = 150;
+$diamond = array($x-$d, $y, $x, $y+$d, $x+$d, $y, $x, $y-$d);
+imagefilledpolygon($im, $diamond, 4, $green);
+
+$x = 180;
+$y = 225;
+$diamond = array($x-$d, $y, $x, $y+$d, $x+$d, $y, $x, $y-$d);
+imagefilledpolygon($im, $diamond, 4, $red);
+
+$x = 225;
+$y = 255;
+$diamond = array($x-$d, $y, $x, $y+$d, $x+$d, $y, $x, $y-$d);
+imagefilledpolygon($im, $diamond, 4, $cyan);
+
+// M (bridge) not touching bottom boundary
+$top = 100;
+$bot = 150;
+$x = 30;
+$points = array(
+  $x,      $top,
+  $x+2*$d, $top,
+  $x+2*$d, $bot,
+  $x+$d,   ($top+$bot)/2,
+  $x,      $bot
+);
+imagefilledpolygon($im, $points, 5, $black);
+
+ob_start();
+imagepng($im);
+$png = ob_get_contents();
+ob_end_clean();
+
+echo md5($png);
+
+imagedestroy($im);
+?>
+--EXPECTF--
+2e6cf558bb4dadf60c8b608d5f8cda4e
-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to