put the gamma code into vid.c where (IMO) it should have been.

give vid_fbdev VID_SetGamma
mame vid_common_gl and vid_common_sw of their gamma code (vid_common_sw is
now empty:/)
rewrite VID_InitGamma to do the right thing with cvars with callbacks
gl clients have [temporarily?] lost the CVAR_ROM on vid_gamma
This commit is contained in:
Bill Currie 2001-04-12 23:44:56 +00:00
parent f37b007da2
commit 5278f9fd73
6 changed files with 66 additions and 184 deletions

View file

@ -29,21 +29,27 @@
#ifdef HAVE_CONFIG_H #ifdef HAVE_CONFIG_H
# include "config.h" # include "config.h"
#endif #endif
#include <math.h>
#include "QF/compat.h"
#include "QF/cvar.h" #include "QF/cvar.h"
#include "vid.h" #include "vid.h"
#include "view.h"
#include "QF/va.h" #include "QF/va.h"
#include "QF/qargs.h" #include "QF/qargs.h"
#include "QF/sys.h" #include "QF/sys.h"
extern viddef_t vid; // global video state 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;
int scr_width, scr_height; int scr_width, scr_height;
cvar_t *vid_width; cvar_t *vid_width;
cvar_t *vid_height; cvar_t *vid_height;
byte gammatable[256];
void void
VID_GetWindowSize (int def_w, int def_h) VID_GetWindowSize (int def_w, int def_h)
{ {
@ -92,28 +98,64 @@ VID_GetWindowSize (int def_w, int def_h)
scr_height = vid.height = vid_height->int_val; scr_height = vid.height = vid_height->int_val;
} }
#if 0 /*
VID_UpdateGamma
This is a callback to update the palette or system gamma whenever the
vid_gamma Cvar is changed.
*/
void void
VID_CalcGamma (double gamma) VID_UpdateGamma (cvar_t *vid_gamma)
{ {
int i; int i;
int v;
double g = bound (0.3, gamma, 3);
Cvar_SetValue (gamma, g); if (vid_gamma->flags & CVAR_ROM) // System gamma unavailable
return;
if (!(gamma_flipped->int_val)) Cvar_SetValue (vid_gamma, bound (0.1, vid_gamma->value, 9.9));
g = 1.0 / g;
if (g == 1.0) { if (vid_gamma_avail && vid_system_gamma->int_val) { // Have sys gamma, use it
for (i = 0; i < 256; i++) { for (i = 0; i < 256; i++) { // linear, to keep things kosher
gammatable[i] = i; gammatable[i] = i;
} }
} VID_SetGamma (vid_gamma->value);
} 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++) { for (i = 0; i < 256; i++) { // Update the gamma LUT
v = (int) (255.0 * pow ((double) i / 255.0, g)); v = (int) ((255.0 * pow ((double) i / 255.0, g)) + 0.5);
gammatable[i] = bound (0, v, 255); gammatable[i] = bound (0, v, 255);
}
}
V_UpdatePalette (); // update with the new palette
} }
} }
#endif
/*
VID_InitGamma
Initialize the gamma lookup table
This function is less complex than the GL version.
*/
void
VID_InitGamma (unsigned char *pal)
{
int i;
double gamma = 1.45;
if ((i = COM_CheckParm ("-gamma"))) {
gamma = atof (com_argv[i + 1]);
}
gamma = bound (0.1, gamma, 9.9);
vid_gamma = Cvar_Get ("vid_gamma", va("%f", gamma), CVAR_ARCHIVE,
VID_UpdateGamma, "Gamma correction");
}

View file

@ -120,56 +120,6 @@ CheckMultiTextureExtensions (void)
} }
} }
/*
VID_InitGamma
Initialize the gamma lookup table
This function does some nasty things to Cvars, but at least we have the
excuse that it has to.
*/
void
VID_InitGamma (unsigned char *pal)
{
int i;
double gamma;
vid_gamma = Cvar_Get ("vid_gamma", "1.45", CVAR_ARCHIVE, VID_UpdateGamma,
"Gamma correction");
if ((i = COM_CheckParm ("-gamma"))) {
gamma = atof (com_argv[i + 1]);
} else {
gamma = vid_gamma->value;
}
gamma = bound (0.1, gamma, 9.9);
Cvar_SetValue (vid_gamma, gamma);
if (gamma == 1.0) { // screw the math, 1.0 is linear
for (i = 0; i < 256; i++) {
gammatable[i] = i;
}
} else {
if (vid_system_gamma->int_val) {
VID_SetGamma (gamma);
} else {
double g = 1.0 / gamma;
int v;
Cvar_SetFlags (vid_gamma, vid_gamma->flags | CVAR_ROM);
for (i = 0; i < 256; i++) { // Create the gamma-correction table
v = (int) (255.0 * pow ((double) i / 255.0, g) + 0.5);
gammatable[i] = bound (0, v, 255);
}
}
}
for (i = 0; i < 768; i++) { // correct the palette
pal[i] = gammatable[pal[i]];
}
}
void void
VID_SetPalette (unsigned char *palette) VID_SetPalette (unsigned char *palette)
{ {

View file

@ -37,97 +37,3 @@
#include "QF/qargs.h" #include "QF/qargs.h"
#include "vid.h" #include "vid.h"
#include "view.h" #include "view.h"
extern byte gammatable[256];
extern cvar_t *vid_system_gamma;
extern qboolean vid_gamma_avail; // hardware gamma availability
cvar_t *vid_gamma;
/*
VID_InitGamma
Initialize the gamma lookup table
This function is less complex than the GL version.
*/
void
VID_InitGamma (unsigned char *pal)
{
int i;
double gamma;
vid_gamma = Cvar_Get ("vid_gamma", "1.45", CVAR_ARCHIVE, VID_UpdateGamma,
"Gamma correction");
if ((i = COM_CheckParm ("-gamma"))) {
gamma = atof (com_argv[i + 1]);
} else {
gamma = vid_gamma->value;
}
gamma = bound (0.1, gamma, 9.9);
Cvar_SetValue (vid_gamma, gamma);
if (gamma == 1.0) { // screw the math, 1.0 is linear
for (i = 0; i < 256; i++) {
gammatable[i] = i;
}
} else {
if (vid_system_gamma->int_val) {
VID_SetGamma (gamma);
} else {
double g = 1.0 / gamma;
int v;
for (i = 0; i < 256; i++) { // Create the gamma-correction table
v = (int) ((255.0 * pow ((double) i / 255.0, g)) + 0.5);
gammatable[i] = bound (0, v, 255);
}
}
}
for (i = 0; i < 768; i++) { // correct the palette
pal[i] = gammatable[pal[i]];
}
}
/*
VID_UpdateGamma
This is a callback to update the palette or system gamma whenever the
vid_gamma Cvar is changed.
*/
void
VID_UpdateGamma (cvar_t *vid_gamma)
{
int i;
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);
} 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);
}
}
V_UpdatePalette (); // update with the new palette
}
}

View file

@ -702,3 +702,9 @@ void
VID_SetCaption (char *text) VID_SetCaption (char *text)
{ {
} }
qboolean
VID_SetGamma (double gamma)
{
return false;
}

View file

@ -248,14 +248,3 @@ VID_SetGamma (double gamma)
{ {
return X11_SetGamma (gamma); return X11_SetGamma (gamma);
} }
void
VID_UpdateGamma (cvar_t *vid_gamma)
{
if (vid_gamma->flags & CVAR_ROM) // System gamma unavailable
return;
Cvar_SetValue (vid_gamma, bound (0.1, vid_gamma->value, 9.9));
X11_SetGamma (vid_gamma->value);
}

View file

@ -253,14 +253,3 @@ VID_SetGamma (double gamma)
{ {
return SDL_SetGamma((float) gamma, (float) gamma, (float) gamma); return SDL_SetGamma((float) gamma, (float) gamma, (float) gamma);
} }
void
VID_UpdateGamma (cvar_t *vid_gamma)
{
if (vid_gamma->flags & CVAR_ROM) // System gamma unavailable
return;
Cvar_SetValue (vid_gamma, bound (0.1, vid_gamma->value, 9.9));
VID_SetGamma (vid_gamma->value);
}