com php-src: Fix #67325: imagetruecolortopalette: white is duplicated in palette: NEWS ext/gd/libgd/gd_topal.c ext/gd/tests/bug6 7325.jpeg
ext/gd/tests/bug67325.phpt

From: Date: Sat, 03 Sep 2016 17:50:42 +0000
Subject: com php-src: Fix #67325: imagetruecolortopalette: white is duplicated in palette: NEWS ext/gd/libgd/gd_topal.c ext/gd/tests/bug6 7325.jpeg
ext/gd/tests/bug67325.phpt
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-94283@lists.php.net to get a copy of this message
Commit: d58224136801ce93b013079557d1de4d068b9b99 Author: Christoph M. Becker <cmbecker69@gmx.de> Sat, 3 Sep 2016 19:46:38 +0200 Parents: 9513187deec82ffb2f56b86ce5f940d1fb5329f9 Branches: PHP-5.6 PHP-7.0 PHP-7.1 master Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=d58224136801ce93b013079557d1de4d068b9b99 Log: Fix #67325: imagetruecolortopalette: white is duplicated in palette gdImageTrueColorToPalette() is sometimes wasteful by putting multiple white color entries into the palette. This is caused by an obvious typo, where to avoid a division by zero when total is zero, count is checked instead of total. We fix this issue to improve the quality of the color quantization. Cf. <https://github.com/libgd/libgd/commit/24b4550f> Bugs: https://bugs.php.net/67325 Changed paths: M NEWS M ext/gd/libgd/gd_topal.c A ext/gd/tests/bug67325.jpeg A ext/gd/tests/bug67325.phpt Diff: diff --git a/NEWS b/NEWS index ef86525..95d23f2 100644 --- a/NEWS +++ b/NEWS @@ -2,6 +2,10 @@ PHP NEWS ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| ?? ??? 2016, PHP 5.6.27 +- GD: + . Fixed bug #67325 (imagetruecolortopalette: white is duplicated in palette). + (cmb) + 15 Sep 2016, PHP 5.6.26 - Core: diff --git a/ext/gd/libgd/gd_topal.c b/ext/gd/libgd/gd_topal.c index d8dda45..896c3cb 100644 --- a/ext/gd/libgd/gd_topal..c +++ b/ext/gd/libgd/gd_topal.c @@ -760,7 +760,7 @@ LOCAL (void) cinfo->colormap[2][icolor] = (JSAMPLE) ((c2total + (total >> 1)) / total); #else /* 2.0.16: Paul den Dulk found an occasion where total can be 0 */ - if (count) + if (total) { nim->red[icolor] = (int) ((c0total + (total >> 1)) / total); nim->green[icolor] = (int) ((c1total + (total >> 1)) / total); diff --git a/ext/gd/tests/bug67325.jpeg b/ext/gd/tests/bug67325.jpeg new file mode 100644 index 0000000..82e8233 Binary files /dev/null and b/ext/gd/tests/bug67325.jpeg differ diff --git a/ext/gd/tests/bug67325.phpt b/ext/gd/tests/bug67325.phpt new file mode 100644 index 0000000..dabc8b2 --- /dev/null +++ b/ext/gd/tests/bug67325.phpt @@ -0,0 +1,29 @@ +--TEST-- +Bug #67325 (imagetruecolortopalette: white is duplicated in palette) +--SKIPIF-- +<?php +if (!extension_loaded('gd')) die('skip gd extension not available'); +if (!(imagetypes() & IMG_JPG)) die('skip JPEG support not available'); +?> +--FILE-- +<?php +$filename = __DIR__ . DIRECTORY_SEPARATOR . 'bug67325.jpeg'; + +$im = imagecreatefromjpeg($filename); +imagetruecolortopalette($im, 0, 256); + +$white = 0; +for ($i = 0; $i < 256; $i++) { + $components = imagecolorsforindex($im, $i); + if ($components['red'] === 255 && $components['green'] === 255 && $components['blue'] === 255) { + $white++; + } +} +var_dump($white); + +imagedestroy($im); +?> +===DONE=== +--EXPECT-- +int(0) +===DONE===

« previous php.cvs (#94283) next »