Gamma cleanups. Brightness and contrast are gone from software, since they

won't work with proper gamma control anyway.
This commit is contained in:
Jeff Teunissen 2001-04-13 08:02:11 +00:00
parent 9a2df9a2d5
commit bffe67977c
6 changed files with 78 additions and 110 deletions

View file

@ -202,20 +202,3 @@ V_UpdatePalette (void)
V_CalcBlend ();
}
/*
BuildGammaTable
In software mode, this function gets the palette ready for changing...in
in GL, it does very little as you can see.
*/
void
BuildGammaTable (float b, float c)
{
int i;
for (i = 0; i < 256; i++)
gammatable[i] = i;
return;
}

View file

@ -261,10 +261,8 @@ cshift_t cshift_water = { {130, 80, 50}, 128 };
cshift_t cshift_slime = { {0, 25, 5}, 150 };
cshift_t cshift_lava = { {255, 80, 0}, 150 };
cvar_t *brightness;
cvar_t *contrast;
extern byte gammatable[256]; // palette is sent through this
extern byte gammatable[256]; // palette is sent through this
extern cvar_t *vid_gamma;
/*
V_CheckGamma
@ -272,23 +270,16 @@ extern byte gammatable[256]; // palette is sent through this
qboolean
V_CheckGamma (void)
{
#if 0
static float oldbrightness;
static float oldcontrast;
static float oldgamma;
if ((brightness->value == oldbrightness) && contrast->value == oldcontrast)
if (oldgamma == vid_gamma->value)
return false;
oldbrightness = brightness->value;
oldcontrast = contrast->value;
oldgamma = vid_gamma->value;
BuildGammaTable (brightness->value, contrast->value);
vid.recalc_refdef = 1; // force a surface cache flush
return true;
#else
return false;
#endif
}
/*
@ -741,8 +732,6 @@ V_Init (void)
Cmd_AddCommand ("bf", V_BonusFlash_f, "Background flash, used when you pick up an item");
Cmd_AddCommand ("centerview", V_StartPitchDrift, "Centers the player's view ahead after +lookup or +lookdown \n"
"Will not work while mlook is active or freelook is 1.");
BuildGammaTable (1.0, 1.0); // no gamma yet
}
void
@ -787,9 +776,4 @@ V_Init_Cvars (void)
"How much you lean when hit");
v_kickpitch = Cvar_Get ("v_kickpitch", "0.6", CVAR_NONE, NULL,
"How much you look up when hit");
brightness = Cvar_Get ("brightness", "1", CVAR_ARCHIVE, NULL,
"Brightness level");
contrast = Cvar_Get ("contrast", "1", CVAR_ARCHIVE, NULL, "Contrast level");
}

View file

@ -138,12 +138,9 @@ V_UpdatePalette (void)
basepal += 3;
for (j = 0; j < NUM_CSHIFTS; j++) {
r +=
(cl.cshifts[j].percent * (cl.cshifts[j].destcolor[0] - r)) >> 8;
g +=
(cl.cshifts[j].percent * (cl.cshifts[j].destcolor[1] - g)) >> 8;
b +=
(cl.cshifts[j].percent * (cl.cshifts[j].destcolor[2] - b)) >> 8;
r += (cl.cshifts[j].percent * (cl.cshifts[j].destcolor[0] - r)) >> 8;
g += (cl.cshifts[j].percent * (cl.cshifts[j].destcolor[1] - g)) >> 8;
b += (cl.cshifts[j].percent * (cl.cshifts[j].destcolor[2] - b)) >> 8;
}
newpal[0] = gammatable[r];
@ -153,24 +150,3 @@ V_UpdatePalette (void)
}
VID_ShiftPalette (pal);
}
void
BuildGammaTable (float b, float c)
{
#if 0
int i, inf;
// int p = (int) c;
if ((b == 1.0) && (c == 1.0)) {
for (i = 0; i < 256; i++)
gammatable[i] = i;
return;
}
for (i = 0; i < 256; i++) { // weighted average toward the median, 127
inf = (i * b); // gamma is brightness now, and positive
inf = bound (0, inf, 255);
gammatable[i] = inf + (int) ((127 - inf) * (1 - c));
}
#endif
}

View file

@ -32,23 +32,30 @@
#include <math.h>
#include "QF/compat.h"
#include "QF/console.h"
#include "QF/cvar.h"
#include "vid.h"
#include "view.h"
#include "QF/va.h"
#include "QF/qargs.h"
#include "QF/sys.h"
#include "QF/va.h"
#include "vid.h"
#include "view.h"
extern viddef_t vid; // global video state
cvar_t *vid_system_gamma;
qboolean vid_gamma_avail; // hardware gamma availability
byte gammatable[256];
cvar_t *vid_gamma;
/*
Software and hardware gamma support
*/
byte gammatable[256];
cvar_t *vid_gamma;
cvar_t *vid_system_gamma;
qboolean vid_gamma_avail; // hardware gamma availability
int scr_width, scr_height;
cvar_t *vid_width;
cvar_t *vid_height;
/*
Screen size
*/
int scr_width, scr_height;
cvar_t *vid_width;
cvar_t *vid_height;
void
VID_GetWindowSize (int def_w, int def_h)
@ -98,6 +105,30 @@ VID_GetWindowSize (int def_w, int def_h)
scr_height = vid.height = vid_height->int_val;
}
/****************************************************************************
* GAMMA FUNCTIONS *
****************************************************************************/
void
VID_BuildGammaTable (double gamma)
{
int i;
if (gamma == 1.0) { // linear, don't bother with the math
for (i = 0; i < 256; i++) {
gammatable[i] = i;
}
} else {
double g = 1.0 / gamma;
int v;
for (i = 0; i < 256; i++) { // Build/update gamma lookup table
v = (int) ((255.0 * pow ((double) i / 255.0, g)) + 0.5);
gammatable[i] = bound (0, v, 255);
}
}
}
/*
VID_UpdateGamma
@ -107,33 +138,18 @@ VID_GetWindowSize (int def_w, int def_h)
void
VID_UpdateGamma (cvar_t *vid_gamma)
{
int i;
double gamma = bound (0.1, vid_gamma->value, 9.9);
if (vid_gamma->flags & CVAR_ROM) // System gamma unavailable
return;
Cvar_SetValue (vid_gamma, bound (0.1, vid_gamma->value, 9.9));
if (vid_gamma_avail && vid_system_gamma->int_val) { // Have sys gamma, use it
for (i = 0; i < 256; i++) { // linear, to keep things kosher
gammatable[i] = i;
}
VID_SetGamma (vid_gamma->value);
if (vid_gamma_avail && vid_system_gamma->int_val) { // Have system, use it
Con_DPrintf ("Setting hardware gamma to %g\n", gamma);
VID_BuildGammaTable (1.0); // hardware gamma wants a linear palette
VID_SetGamma (gamma);
} else { // We have to hack the palette
if (vid_gamma->value == 1.0) { // screw the math, 1.0 is linear
for (i = 0; i < 256; i++) {
gammatable[i] = i;
}
} else {
double g = 1.0 / vid_gamma->value;
int v;
for (i = 0; i < 256; i++) { // Update the gamma LUT
v = (int) ((255.0 * pow ((double) i / 255.0, g)) + 0.5);
gammatable[i] = bound (0, v, 255);
}
}
Con_DPrintf ("Setting software gamma to %g\n", gamma);
VID_BuildGammaTable (gamma);
V_UpdatePalette (); // update with the new palette
}
}
@ -141,9 +157,7 @@ VID_UpdateGamma (cvar_t *vid_gamma)
/*
VID_InitGamma
Initialize the gamma lookup table
This function is less complex than the GL version.
Initialize the vid_gamma Cvar, and set up the palette
*/
void
VID_InitGamma (unsigned char *pal)
@ -156,6 +170,8 @@ VID_InitGamma (unsigned char *pal)
}
gamma = bound (0.1, gamma, 9.9);
vid_gamma = Cvar_Get ("vid_gamma", va("%f", gamma), CVAR_ARCHIVE,
vid_gamma = Cvar_Get ("vid_gamma", va ("%f", gamma), CVAR_ARCHIVE,
VID_UpdateGamma, "Gamma correction");
VID_BuildGammaTable (vid_gamma->value);
}

View file

@ -79,14 +79,23 @@ GLenum gl_mtex_enum = GL_TEXTURE0_ARB;
QF_glColorTableEXT qglColorTableEXT = NULL;
qboolean is8bit = false;
cvar_t *vid_use8bit;
cvar_t *vid_gamma;
cvar_t *vid_use8bit;
cvar_t *brightness;
cvar_t *contrast;
extern int gl_filter_min, gl_filter_max;
extern cvar_t *vid_system_gamma;
/*-----------------------------------------------------------------------*/
void
GL_Common_Init_Cvars (void)
{
vid_use8bit = Cvar_Get ("vid_use8bit", "0", CVAR_ROM, NULL, "Use 8-bit shared palettes.");
brightness = Cvar_Get ("brightness", "1", CVAR_ARCHIVE, NULL, "Brightness level");
contrast = Cvar_Get ("contrast", "1", CVAR_ARCHIVE, NULL, "Contrast level");
}
/*
CheckMultiTextureExtensions
@ -208,6 +217,8 @@ VID_SetPalette (unsigned char *palette)
void
GL_Init_Common (void)
{
GL_Common_Init_Cvars ();
gl_vendor = glGetString (GL_VENDOR);
Con_Printf ("GL_VENDOR: %s\n", gl_vendor);
gl_renderer = glGetString (GL_RENDERER);
@ -349,9 +360,6 @@ Shared_Init8bitPalette (void)
void
VID_Init8bitPalette (void)
{
vid_use8bit = Cvar_Get ("vid_use8bit", "0", CVAR_ROM, NULL,
"Use 8-bit shared palettes.");
Con_Printf ("Checking for 8-bit extension: ");
if (vid_use8bit->int_val) {
#ifdef GL_SHARED_TEXTURE_PALETTE_EXT

View file

@ -539,6 +539,7 @@ VID_Init (unsigned char *palette)
X11_CreateNullCursor ();
VID_InitGamma (palette);
VID_SetPalette (palette);
if (x_visinfo->depth == 8) {
/* Create and upload the palette */
if (x_visinfo->class == PseudoColor) {
@ -641,9 +642,9 @@ VID_SetPalette (unsigned char *palette)
for (i = 0; i < 256; i++) {
colors[i].pixel = i;
colors[i].flags = DoRed | DoGreen | DoBlue;
colors[i].red = gammatable[palette[i * 3]];
colors[i].green = gammatable[palette[i * 3 + 1]];
colors[i].blue = gammatable[palette[i * 3 + 2]];
colors[i].red = gammatable[(byte) palette[(i * 3)]];
colors[i].green = gammatable[(byte) palette[(i * 3) + 1]];
colors[i].blue = gammatable[(byte) palette[(i * 3) + 2]];
}
XStoreColors (x_disp, x_cmap, colors, 256);
}