From: divverent Date: Sat, 22 Oct 2011 15:08:47 +0000 (+0000) Subject: more sRGB simplification X-Git-Tag: xonotic-v0.6.0~225 X-Git-Url: http://git.xonotic.org/?a=commitdiff_plain;h=9b89b21c03df84572b3bc9ec4ff4c739417e7c1e;p=xonotic%2Fdarkplaces.git more sRGB simplification git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@11459 d7cf8633-e32d-0410-b094-e92efae38249 ::stable-branch::merge=31e8453b50c34dee486958821aea13401c7675b6 --- diff --git a/image.c b/image.c index c891c3ce..f9f5e750 100644 --- 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 442b5dc7..c027f641 100644 --- 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); diff --git a/vid_shared.c b/vid_shared.c index a50bf725..87a188ef 100644 --- a/vid_shared.c +++ b/vid_shared.c @@ -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