]> git.xonotic.org Git - xonotic/darkplaces.git/commitdiff
contrastboost: fix a division by zero that can never happen ;)
authordivverent <divverent@d7cf8633-e32d-0410-b094-e92efae38249>
Thu, 11 Jun 2009 10:38:05 +0000 (10:38 +0000)
committerdivverent <divverent@d7cf8633-e32d-0410-b094-e92efae38249>
Thu, 11 Jun 2009 10:38:05 +0000 (10:38 +0000)
git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@9017 d7cf8633-e32d-0410-b094-e92efae38249

palette.c

index 86ffa5a4a20f0e0a57fbfb2713f8db70be8eb5e9..24ee2d00851106fa45eb9c07a6f70aff2371c770 100644 (file)
--- 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);
        }