]> git.xonotic.org Git - xonotic/darkplaces.git/commitdiff
v_contrastboost, and support for the color control functions to fill the gamma table...
authordivverent <divverent@d7cf8633-e32d-0410-b094-e92efae38249>
Tue, 29 Jan 2008 11:39:41 +0000 (11:39 +0000)
committerdivverent <divverent@d7cf8633-e32d-0410-b094-e92efae38249>
Tue, 29 Jan 2008 11:39:41 +0000 (11:39 +0000)
git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@8040 d7cf8633-e32d-0410-b094-e92efae38249

palette.c
palette.h
vid_shared.c

index 85cd474f86ed049a837a388e5af7578f2c4ee62c..86ffa5a4a20f0e0a57fbfb2713f8db70be8eb5e9 100644 (file)
--- a/palette.c
+++ b/palette.c
@@ -169,30 +169,36 @@ void Palette_SetupSpecialPalettes(void)
        palette_bgra_font[0] = 0;
 }
 
-void BuildGammaTable8(float prescale, float gamma, float scale, float base, unsigned char *out, int rampsize)
+void BuildGammaTable8(float prescale, float gamma, float scale, float base, float contrastboost, unsigned char *out, int rampsize)
 {
        int i, adjusted;
        double invgamma;
+       double t;
 
        invgamma = 1.0 / gamma;
        prescale /= (double) (rampsize - 1);
        for (i = 0;i < rampsize;i++)
        {
-               adjusted = (int) (255.0 * (pow((double) i * prescale, invgamma) * scale + base) + 0.5);
+               t = i * prescale;
+               t = contrastboost * t / ((contrastboost - 1) * t + 1);
+               adjusted = (int) (255.0 * (pow(t, invgamma) * scale + base) + 0.5);
                out[i] = bound(0, adjusted, 255);
        }
 }
 
-void BuildGammaTable16(float prescale, float gamma, float scale, float base, unsigned short *out, int rampsize)
+void BuildGammaTable16(float prescale, float gamma, float scale, float base, float contrastboost, unsigned short *out, int rampsize)
 {
        int i, adjusted;
        double invgamma;
+       double t;
 
        invgamma = 1.0 / gamma;
        prescale /= (double) (rampsize - 1);
        for (i = 0;i < rampsize;i++)
        {
-               adjusted = (int) (65535.0 * (pow((double) i * prescale, invgamma) * scale + base) + 0.5);
+               t = i * prescale;
+               t = contrastboost * t / ((contrastboost - 1) * t + 1);
+               adjusted = (int) (65535.0 * (pow(t, invgamma) * scale + base) + 0.5);
                out[i] = bound(0, adjusted, 65535);
        }
 }
@@ -239,7 +245,7 @@ void Palette_Load(void)
        scale = bound(0.01, scale, 10.0);
        base = bound(0, base, 0.95);
 
-       BuildGammaTable8(1.0f, gamma, scale, base, texturegammaramp, 256);
+       BuildGammaTable8(1.0f, gamma, scale, base, 1, texturegammaramp, 256);
 
        palfile = (unsigned char *)FS_LoadFile ("gfx/palette.lmp", tempmempool, false, &filesize);
        if (palfile && filesize >= 768)
index 11058772baf00f9339c373f79cf18b5265de5052..e534b9c58fd66455cf1190776efa097c05418719 100644 (file)
--- a/palette.h
+++ b/palette.h
@@ -21,8 +21,8 @@ extern unsigned int palette_bgra_transparent[256];
 extern unsigned int palette_bgra_embeddedpic[256];
 
 // used by hardware gamma functions in vid_* files
-void BuildGammaTable8(float prescale, float gamma, float scale, float base, unsigned char *out, int rampsize);
-void BuildGammaTable16(float prescale, float gamma, float scale, float base, unsigned short *out, int rampsize);
+void BuildGammaTable8(float prescale, float gamma, float scale, float base, float contrastboost, unsigned char *out, int rampsize);
+void BuildGammaTable16(float prescale, float gamma, float scale, float base, float contrastboost, unsigned short *out, int rampsize);
 
 void Palette_Init(void);
 
index eae2789e568a926958b40cba2dbc99840e6f4915..2d1a4b77d6085942142e9b3ea0a37e6c32c5d680 100644 (file)
@@ -99,6 +99,7 @@ cvar_t vid_resizable = {CVAR_SAVE, "vid_resizable", "0", "0: window not resizabl
 cvar_t v_gamma = {CVAR_SAVE, "v_gamma", "1", "inverse gamma correction value, a brightness effect that does not affect white or black, and tends to make the image grey and dull"};
 cvar_t v_contrast = {CVAR_SAVE, "v_contrast", "1", "brightness of white (values above 1 give a brighter image with increased color saturation, unlike v_gamma)"};
 cvar_t v_brightness = {CVAR_SAVE, "v_brightness", "0", "brightness of black, useful for monitors that are too dark"};
+cvar_t v_contrastboost = {CVAR_SAVE, "v_contrastboost", "1", "by how much to multiply the contrast in dark areas (1 is no change)"};
 cvar_t v_color_enable = {CVAR_SAVE, "v_color_enable", "0", "enables black-grey-white color correction curve controls"};
 cvar_t v_color_black_r = {CVAR_SAVE, "v_color_black_r", "0", "desired color of black"};
 cvar_t v_color_black_g = {CVAR_SAVE, "v_color_black_g", "0", "desired color of black"};
@@ -821,7 +822,7 @@ void Force_CenterView_f (void)
 }
 
 static int gamma_forcenextframe = false;
-static float cachegamma, cachebrightness, cachecontrast, cacheblack[3], cachegrey[3], cachewhite[3];
+static float cachegamma, cachebrightness, cachecontrast, cacheblack[3], cachegrey[3], cachewhite[3], cachecontrastboost;
 static int cachecolorenable, cachehwgamma;
 void VID_UpdateGamma(qboolean force, int rampsize)
 {
@@ -838,6 +839,7 @@ void VID_UpdateGamma(qboolean force, int rampsize)
        BOUNDCVAR(v_gamma, 0.1, 5);
        BOUNDCVAR(v_contrast, 1, 5);
        BOUNDCVAR(v_brightness, 0, 0.8);
+       BOUNDCVAR(v_contrastboost, 0.0625, 16);
        BOUNDCVAR(v_color_black_r, 0, 0.8);
        BOUNDCVAR(v_color_black_g, 0, 0.8);
        BOUNDCVAR(v_color_black_b, 0, 0.8);
@@ -856,6 +858,7 @@ void VID_UpdateGamma(qboolean force, int rampsize)
        GAMMACHECK(cachegamma      , v_gamma.value);
        GAMMACHECK(cachecontrast   , v_contrast.value);
        GAMMACHECK(cachebrightness , v_brightness.value);
+       GAMMACHECK(cachecontrastboost, v_contrastboost.value);
        GAMMACHECK(cachecolorenable, v_color_enable.integer);
        GAMMACHECK(cacheblack[0]   , v_color_black_r.value);
        GAMMACHECK(cacheblack[1]   , v_color_black_g.value);
@@ -891,15 +894,15 @@ void VID_UpdateGamma(qboolean force, int rampsize)
 
                if (cachecolorenable)
                {
-                       BuildGammaTable16(1.0f, invpow(0.5, 1 - cachegrey[0]), cachewhite[0], cacheblack[0], vid_gammaramps, rampsize);
-                       BuildGammaTable16(1.0f, invpow(0.5, 1 - cachegrey[1]), cachewhite[1], cacheblack[1], vid_gammaramps + vid_gammarampsize, rampsize);
-                       BuildGammaTable16(1.0f, invpow(0.5, 1 - cachegrey[2]), cachewhite[2], cacheblack[2], vid_gammaramps + vid_gammarampsize*2, rampsize);
+                       BuildGammaTable16(1.0f, invpow(0.5, 1 - cachegrey[0]), cachewhite[0], cacheblack[0], cachecontrastboost, vid_gammaramps, rampsize);
+                       BuildGammaTable16(1.0f, invpow(0.5, 1 - cachegrey[1]), cachewhite[1], cacheblack[1], cachecontrastboost, vid_gammaramps + vid_gammarampsize, rampsize);
+                       BuildGammaTable16(1.0f, invpow(0.5, 1 - cachegrey[2]), cachewhite[2], cacheblack[2], cachecontrastboost, vid_gammaramps + vid_gammarampsize*2, rampsize);
                }
                else
                {
-                       BuildGammaTable16(1.0f, cachegamma, cachecontrast, cachebrightness, vid_gammaramps, rampsize);
-                       BuildGammaTable16(1.0f, cachegamma, cachecontrast, cachebrightness, vid_gammaramps + vid_gammarampsize, rampsize);
-                       BuildGammaTable16(1.0f, cachegamma, cachecontrast, cachebrightness, vid_gammaramps + vid_gammarampsize*2, rampsize);
+                       BuildGammaTable16(1.0f, cachegamma, cachecontrast, cachebrightness, cachecontrastboost, vid_gammaramps, rampsize);
+                       BuildGammaTable16(1.0f, cachegamma, cachecontrast, cachebrightness, cachecontrastboost, vid_gammaramps + vid_gammarampsize, rampsize);
+                       BuildGammaTable16(1.0f, cachegamma, cachecontrast, cachebrightness, cachecontrastboost, vid_gammaramps + vid_gammarampsize*2, rampsize);
                }
 
                // LordHavoc: this code came from Ben Winslow and Zinx Verituse, I have
@@ -979,6 +982,7 @@ void VID_Shared_Init(void)
        Cvar_RegisterVariable(&vid_hardwaregammasupported);
        Cvar_RegisterVariable(&v_gamma);
        Cvar_RegisterVariable(&v_brightness);
+       Cvar_RegisterVariable(&v_contrastboost);
        Cvar_RegisterVariable(&v_contrast);
 
        Cvar_RegisterVariable(&v_color_enable);