From a51949900c66ac643b3e439044f692e41074144e Mon Sep 17 00:00:00 2001 From: divverent Date: Thu, 11 Jun 2009 10:38:05 +0000 Subject: [PATCH] contrastboost: fix a division by zero that can never happen ;) git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@9017 d7cf8633-e32d-0410-b094-e92efae38249 --- palette.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/palette.c b/palette.c index 86ffa5a4..24ee2d00 100644 --- a/palette.c +++ b/palette.c @@ -173,14 +173,18 @@ void BuildGammaTable8(float prescale, float gamma, float scale, float base, floa { int i, adjusted; double invgamma; - double t; + double t, d; invgamma = 1.0 / gamma; prescale /= (double) (rampsize - 1); for (i = 0;i < rampsize;i++) { t = i * prescale; - t = contrastboost * t / ((contrastboost - 1) * t + 1); + d = ((contrastboost - 1) * t + 1); + if(d == 0) + t = 0; // we could just as well assume 1 here, depending on which side of the division by zero we want to be + else + t = contrastboost * t / d; adjusted = (int) (255.0 * (pow(t, invgamma) * scale + base) + 0.5); out[i] = bound(0, adjusted, 255); } -- 2.39.2