From: divverent Date: Thu, 11 Jun 2009 10:38:05 +0000 (+0000) Subject: contrastboost: fix a division by zero that can never happen ;) X-Git-Tag: xonotic-v0.1.0preview~1605 X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=a51949900c66ac643b3e439044f692e41074144e;p=xonotic%2Fdarkplaces.git 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 --- 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); }