more sRGB simplification
authordivverent <divverent@d7cf8633-e32d-0410-b094-e92efae38249>
Sat, 22 Oct 2011 15:08:47 +0000 (15:08 +0000)
committerdivverent <divverent@d7cf8633-e32d-0410-b094-e92efae38249>
Sat, 22 Oct 2011 15:08:47 +0000 (15:08 +0000)
git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@11459 d7cf8633-e32d-0410-b094-e92efae38249

image.c
image.h
vid_shared.c

diff --git a/image.c b/image.c
index c891c3c..f9f5e75 100644 (file)
--- a/image.c
+++ b/image.c
@@ -805,7 +805,7 @@ void Image_MakeLinearColorsFromsRGB(unsigned char *pout, const unsigned char *pi
        // this math from http://www.opengl.org/registry/specs/EXT/texture_sRGB.txt
        if (!image_linearfromsrgb[255])
                for (i = 0;i < 256;i++)
-                       image_linearfromsrgb[i] = (unsigned char)(Image_LinearFloatFromsRGB(i) * 256.0f);
+                       image_linearfromsrgb[i] = (unsigned char)floor(Image_LinearFloatFromsRGB(i) * 255.0f + 0.5f);
        for (i = 0;i < numpixels;i++)
        {
                pout[i*4+0] = image_linearfromsrgb[pin[i*4+0]];
@@ -821,7 +821,7 @@ void Image_MakesRGBColorsFromLinear_Lightmap(unsigned char *pout, const unsigned
        // this math from http://www.opengl.org/registry/specs/EXT/texture_sRGB.txt
        if (!image_srgbfromlinear_lightmap[255])
                for (i = 0;i < 256;i++)
-                       image_srgbfromlinear_lightmap[i] = (unsigned char)bound(0, Image_sRGBFloatFromLinear_Lightmap(i) * 256.0f, 255);
+                       image_srgbfromlinear_lightmap[i] = (unsigned char)floor(bound(0.0f, Image_sRGBFloatFromLinear_Lightmap(i), 1.0f) * 255.0f + 0.5f);
        for (i = 0;i < numpixels;i++)
        {
                pout[i*4+0] = image_srgbfromlinear_lightmap[pin[i*4+0]];
diff --git a/image.h b/image.h
index 442b5dc..c027f64 100644 (file)
--- a/image.h
+++ b/image.h
@@ -55,7 +55,7 @@ extern cvar_t r_fixtrans_auto;
 #define Image_LinearFloatFromsRGB(c) Image_LinearFloatFromsRGBFloat((c) * (1.0f / 255.0f))
 #define Image_sRGBFloatFromLinear(c) Image_sRGBFloatFromLinearFloat((c) * (1.0f / 255.0f))
 
-#define Image_sRGBFloatFromLinear_Lightmap(c) (Image_sRGBFloatFromLinear(c*2.0f)*0.5f)
+#define Image_sRGBFloatFromLinear_Lightmap(c) Image_sRGBFloatFromLinearFloat((c) * (2.0f / 255.0f)) * 0.5f
 
 void Image_MakeLinearColorsFromsRGB(unsigned char *pout, const unsigned char *pin, int numpixels);
 void Image_MakesRGBColorsFromLinear_Lightmap(unsigned char *pout, const unsigned char *pin, int numpixels);
index a50bf72..87a188e 100644 (file)
@@ -1416,7 +1416,7 @@ void VID_BuildGammaTables(unsigned short *ramps, int rampsize)
        {
                int i;
                for(i = 0; i < 3*rampsize; ++i)
-                       ramps[i] = bound(0, (int)floor(Image_sRGBFloatFromLinear(ramps[i] / 256.0) * 65535.0 + 0.5), 65535);
+                       ramps[i] = (int)floor(bound(0.0f, Image_sRGBFloatFromLinearFloat(ramps[i] / 65535.0), 1.0f) * 65535.0 + 0.5);
        }
 
        // LordHavoc: this code came from Ben Winslow and Zinx Verituse, I have