From 5278f9fd73d67f6f893f658d93a175be27f808e5 Mon Sep 17 00:00:00 2001 From: Bill Currie Date: Thu, 12 Apr 2001 23:44:56 +0000 Subject: [PATCH] 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 --- qw/source/vid.c | 78 ++++++++++++++++++++++++-------- qw/source/vid_common_gl.c | 50 --------------------- qw/source/vid_common_sw.c | 94 --------------------------------------- qw/source/vid_fbdev.c | 6 +++ qw/source/vid_glx.c | 11 ----- qw/source/vid_sgl.c | 11 ----- 6 files changed, 66 insertions(+), 184 deletions(-) diff --git a/qw/source/vid.c b/qw/source/vid.c index 08c5e32db..9b7384a64 100644 --- a/qw/source/vid.c +++ b/qw/source/vid.c @@ -29,21 +29,27 @@ #ifdef HAVE_CONFIG_H # include "config.h" #endif +#include +#include "QF/compat.h" #include "QF/cvar.h" #include "vid.h" +#include "view.h" #include "QF/va.h" #include "QF/qargs.h" #include "QF/sys.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; + int scr_width, scr_height; cvar_t *vid_width; cvar_t *vid_height; -byte gammatable[256]; - void 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; } -#if 0 +/* + VID_UpdateGamma + + This is a callback to update the palette or system gamma whenever the + vid_gamma Cvar is changed. +*/ void -VID_CalcGamma (double gamma) +VID_UpdateGamma (cvar_t *vid_gamma) { int i; - int v; - double g = bound (0.3, gamma, 3); + + if (vid_gamma->flags & CVAR_ROM) // System gamma unavailable + return; - Cvar_SetValue (gamma, g); + Cvar_SetValue (vid_gamma, bound (0.1, vid_gamma->value, 9.9)); - if (!(gamma_flipped->int_val)) - g = 1.0 / g; - - if (g == 1.0) { - for (i = 0; i < 256; i++) { + 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; } - } - - for (i = 0; i < 256; i++) { - v = (int) (255.0 * pow ((double) i / 255.0, g)); - gammatable[i] = bound (0, v, 255); + 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 } } -#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"); +} diff --git a/qw/source/vid_common_gl.c b/qw/source/vid_common_gl.c index 3d6ffddbd..d45992522 100644 --- a/qw/source/vid_common_gl.c +++ b/qw/source/vid_common_gl.c @@ -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 VID_SetPalette (unsigned char *palette) { diff --git a/qw/source/vid_common_sw.c b/qw/source/vid_common_sw.c index 32a01b5c3..0ef6340ba 100644 --- a/qw/source/vid_common_sw.c +++ b/qw/source/vid_common_sw.c @@ -37,97 +37,3 @@ #include "QF/qargs.h" #include "vid.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 - } -} diff --git a/qw/source/vid_fbdev.c b/qw/source/vid_fbdev.c index b12275076..18b872b32 100644 --- a/qw/source/vid_fbdev.c +++ b/qw/source/vid_fbdev.c @@ -702,3 +702,9 @@ void VID_SetCaption (char *text) { } + +qboolean +VID_SetGamma (double gamma) +{ + return false; +} diff --git a/qw/source/vid_glx.c b/qw/source/vid_glx.c index d6abee889..83bcdabfa 100644 --- a/qw/source/vid_glx.c +++ b/qw/source/vid_glx.c @@ -248,14 +248,3 @@ VID_SetGamma (double 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); -} diff --git a/qw/source/vid_sgl.c b/qw/source/vid_sgl.c index d3ccdc281..7f64a064e 100644 --- a/qw/source/vid_sgl.c +++ b/qw/source/vid_sgl.c @@ -253,14 +253,3 @@ VID_SetGamma (double 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); -}