summaryrefslogtreecommitdiff
path: root/src/gd_topal.c
diff options
context:
space:
mode:
authorChristoph M. Becker <cmbecker69@gmx.de>2016-09-03 17:01:56 +0200
committerChristoph M. Becker <cmbecker69@gmx.de>2016-09-03 17:48:03 +0200
commit24b4550fa808bec2bfcf139ee109cb145a172412 (patch)
treea8531ad29beee902b3e33da660e9f5f585e54384 /src/gd_topal.c
parentb53cebfab8e7e37d86f978c6a85bd16fdd96afa5 (diff)
downloadlibgd-24b4550fa808bec2bfcf139ee109cb145a172412.tar.gz
Fix PHP bug #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.
Diffstat (limited to 'src/gd_topal.c')
-rw-r--r--src/gd_topal.c2
1 files changed, 1 insertions, 1 deletions
diff --git a/src/gd_topal.c b/src/gd_topal.c
index 7ff835a..c732ba1 100644
--- a/src/gd_topal.c
+++ b/src/gd_topal.c
@@ -659,7 +659,7 @@ compute_color (gdImagePtr oim, gdImagePtr nim, my_cquantize_ptr cquantize,
}
/* 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);
nim->blue[icolor] = (int) ((c2total + (total >> 1)) / total);