From a211e7328dfccde2ee4bc625cd84007335f0c3ce Mon Sep 17 00:00:00 2001 From: divverent Date: Fri, 21 Oct 2011 11:09:48 +0000 Subject: [PATCH] use the correct sRGB conversion for the gamma ramps git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@11456 d7cf8633-e32d-0410-b094-e92efae38249 --- vid_shared.c | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/vid_shared.c b/vid_shared.c index 8c417fa5..a50bf725 100644 --- a/vid_shared.c +++ b/vid_shared.c @@ -1,6 +1,7 @@ #include "quakedef.h" #include "cdaudio.h" +#include "image.h" #ifdef SUPPORTD3D #include @@ -1398,18 +1399,24 @@ unsigned int vid_gammatables_serial = 0; // so other subsystems can poll if gamm qboolean vid_gammatables_trivial = true; void VID_BuildGammaTables(unsigned short *ramps, int rampsize) { - float srgbmul = (vid.sRGB2D || vid.sRGB3D) ? 2.2f : 1.0f; if (cachecolorenable) { - BuildGammaTable16(1.0f, invpow(0.5, 1 - cachegrey[0]) * srgbmul, cachewhite[0], cacheblack[0], cachecontrastboost, ramps, rampsize); - BuildGammaTable16(1.0f, invpow(0.5, 1 - cachegrey[1]) * srgbmul, cachewhite[1], cacheblack[1], cachecontrastboost, ramps + rampsize, rampsize); - BuildGammaTable16(1.0f, invpow(0.5, 1 - cachegrey[2]) * srgbmul, cachewhite[2], cacheblack[2], cachecontrastboost, ramps + rampsize*2, rampsize); + BuildGammaTable16(1.0f, invpow(0.5, 1 - cachegrey[0]), cachewhite[0], cacheblack[0], cachecontrastboost, ramps, rampsize); + BuildGammaTable16(1.0f, invpow(0.5, 1 - cachegrey[1]), cachewhite[1], cacheblack[1], cachecontrastboost, ramps + rampsize, rampsize); + BuildGammaTable16(1.0f, invpow(0.5, 1 - cachegrey[2]), cachewhite[2], cacheblack[2], cachecontrastboost, ramps + rampsize*2, rampsize); } else { - BuildGammaTable16(1.0f, cachegamma * srgbmul, cachecontrast, cachebrightness, cachecontrastboost, ramps, rampsize); - BuildGammaTable16(1.0f, cachegamma * srgbmul, cachecontrast, cachebrightness, cachecontrastboost, ramps + rampsize, rampsize); - BuildGammaTable16(1.0f, cachegamma * srgbmul, cachecontrast, cachebrightness, cachecontrastboost, ramps + rampsize*2, rampsize); + BuildGammaTable16(1.0f, cachegamma, cachecontrast, cachebrightness, cachecontrastboost, ramps, rampsize); + BuildGammaTable16(1.0f, cachegamma, cachecontrast, cachebrightness, cachecontrastboost, ramps + rampsize, rampsize); + BuildGammaTable16(1.0f, cachegamma, cachecontrast, cachebrightness, cachecontrastboost, ramps + rampsize*2, rampsize); + } + + if(vid.sRGB2D || vid.sRGB3D) + { + 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); } // LordHavoc: this code came from Ben Winslow and Zinx Verituse, I have -- 2.39.2