diff options
author | Christoph M. Becker <cmbecker69@gmx.de> | 2016-09-03 19:46:38 +0200 |
---|---|---|
committer | Christoph M. Becker <cmbecker69@gmx.de> | 2016-09-03 19:50:42 +0200 |
commit | d58224136801ce93b013079557d1de4d068b9b99 (patch) | |
tree | fc31b13ed54d7b898d570063c0b170e13f7412b3 | |
parent | 9513187deec82ffb2f56b86ce5f940d1fb5329f9 (diff) | |
download | php-git-d58224136801ce93b013079557d1de4d068b9b99.tar.gz |
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>
-rw-r--r-- | NEWS | 4 | ||||
-rw-r--r-- | ext/gd/libgd/gd_topal.c | 2 | ||||
-rw-r--r-- | ext/gd/tests/bug67325.jpeg | bin | 0 -> 13608 bytes | |||
-rw-r--r-- | ext/gd/tests/bug67325.phpt | 29 |
4 files changed, 34 insertions, 1 deletions
@@ -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 d8dda45cb9..896c3cb948 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 Binary files differnew file mode 100644 index 0000000000..82e8233a76 --- /dev/null +++ b/ext/gd/tests/bug67325.jpeg diff --git a/ext/gd/tests/bug67325.phpt b/ext/gd/tests/bug67325.phpt new file mode 100644 index 0000000000..dabc8b2b30 --- /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=== |