diff options
Diffstat (limited to 'ext/gd/libgd/gd_topal.c')
-rw-r--r-- | ext/gd/libgd/gd_topal.c | 15 |
1 files changed, 11 insertions, 4 deletions
diff --git a/ext/gd/libgd/gd_topal.c b/ext/gd/libgd/gd_topal.c index 77fb4139b2..b60a055aef 100644 --- a/ext/gd/libgd/gd_topal.c +++ b/ext/gd/libgd/gd_topal.c @@ -703,7 +703,7 @@ LOCAL (void) histptr histp; int c0, c1, c2; int c0min, c0max, c1min, c1max, c2min, c2max; - long count; + long count = 0; long total = 0; long c0total = 0; long c1total = 0; @@ -735,9 +735,16 @@ LOCAL (void) cinfo->colormap[1][icolor] = (JSAMPLE) ((c1total + (total >> 1)) / total); cinfo->colormap[2][icolor] = (JSAMPLE) ((c2total + (total >> 1)) / total); #else - im->red[icolor] = (int) ((c0total + (total >> 1)) / total); - im->green[icolor] = (int) ((c1total + (total >> 1)) / total); - im->blue[icolor] = (int) ((c2total + (total >> 1)) / total); + /* 2.0.16: Paul den Dulk found an occasion where total can be 0 */ + if (count) { + im->red[icolor] = (int) ((c0total + (total >> 1)) / total); + im->green[icolor] = (int) ((c1total + (total >> 1)) / total); + im->blue[icolor] = (int) ((c2total + (total >> 1)) / total); + } else { + im->red[icolor] = 255; + im->green[icolor] = 255; + im->blue[icolor] = 255; + } #endif } |