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);
}
}
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)
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"};
}
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)
{
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);
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);
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
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);