]> git.rm.cloudns.org Git - xonotic/darkplaces.git/commitdiff
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 c891c3cec939b679f4bac92fc4f105211431e78d..f9f5e7505c04af8aad3ceb3426e581ecce58b3a3 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 442b5dc77d516fa3940a16d306cf947af8d3df56..c027f641e28362301440a378600c8a8733499a37 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 a50bf7254641f130f650fc61cba7ed846a2b5a10..87a188effacfc94ef29ed2ab7ea7884c7accba68 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