- cleaned up the gamma correction code.

This had accumulated quite a bit of cruft by now and parts of it should be in non OpenGL code.
This commit is contained in:
Christoph Oelckers 2018-04-29 13:45:53 +02:00
commit 06d20e13b8
7 changed files with 43 additions and 53 deletions

View file

@ -73,6 +73,8 @@
#include "i_time.h"
EXTERN_CVAR(Bool, cl_capfps)
EXTERN_CVAR(Float, vid_brightness)
EXTERN_CVAR(Float, vid_contrast)
CUSTOM_CVAR(Int, vid_maxfps, 200, CVAR_ARCHIVE | CVAR_GLOBALCONFIG)
{
@ -129,7 +131,6 @@ public:
PalEntry *GetPalette() { DBGBREAK; return NULL; }
void GetFlashedPalette(PalEntry palette[256]) { DBGBREAK; }
void UpdatePalette() { DBGBREAK; }
bool SetGamma(float gamma) { Gamma = gamma; return true; }
bool SetFlash(PalEntry rgb, int amount) { DBGBREAK; return false; }
void GetFlash(PalEntry &rgb, int &amount) { DBGBREAK; }
bool IsFullscreen() { DBGBREAK; return 0; }
@ -928,6 +929,31 @@ void DFrameBuffer::GameRestart()
{
}
//==========================================================================
//
//
//
//==========================================================================
void DFrameBuffer::BuildGammaTable(uint16_t *gammaTable)
{
float gamma = clamp<float>(Gamma, 0.1f, 4.f);
float contrast = clamp<float>(vid_contrast, 0.1f, 3.f);
float bright = clamp<float>(vid_brightness, -0.8f, 0.8f);
double invgamma = 1 / gamma;
double norm = pow(255., invgamma - 1);
for (int i = 0; i < 256; i++)
{
double val = i * contrast - (contrast - 1) * 127;
val += bright * 128;
if (gamma != 1) val = pow(val, invgamma) / norm;
gammaTable[i] = gammaTable[i + 256] = gammaTable[i + 512] = (uint16_t)clamp<double>(val * 256, 0, 0xffff);
}
}
//==========================================================================
//
// DFrameBuffer :: GetCaps
@ -986,7 +1012,7 @@ bool V_DoModeSetup (int width, int height, int bits)
}
screen = buff;
screen->SetGamma (Gamma);
screen->SetGamma ();
DisplayBits = bits;
V_UpdateModeSize(screen->GetWidth(), screen->GetHeight());
@ -1264,7 +1290,7 @@ void V_Init2()
else
Printf ("Resolution: %d x %d\n", SCREENWIDTH, SCREENHEIGHT);
screen->SetGamma (gamma);
screen->SetGamma ();
FBaseCVar::ResetColors ();
C_NewModeAdjust();
M_InitVideoModesMenu();