unify gamma correction concepts (#848)

* unify gamma correction concepts

* fix "gamma correction level" user messages

* pointer constness fix

* fix config help line
This commit is contained in:
Fabian Greffrath 2022-12-19 13:54:06 +01:00 committed by GitHub
parent 65f3da8c84
commit 1956d6e7e4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 24 additions and 45 deletions

View File

@ -1058,29 +1058,34 @@ static void I_RestoreDiskBackground(void)
disk_to_draw = 0; disk_to_draw = 0;
} }
static const float gammalevels[18] = static const float gammalevels[9] =
{ {
// Darker // Darker
0.50f, 0.55f, 0.60f, 0.65f, 0.70f, 0.75f, 0.80f, 0.85f, 0.90f, 0.50f, 0.55f, 0.60f, 0.65f, 0.70f, 0.75f, 0.80f, 0.85f, 0.90f,
// No gamma correction
1.0f,
// Lighter
1.125f, 1.25f, 1.375f, 1.5f, 1.625f, 1.75f, 1.875f, 2.0f,
}; };
static byte gamma2table[18][256]; static byte gamma2table[18][256];
static void I_InitGamma2Table(void) static void I_InitGamma2Table(void)
{ {
int i, j; int i, j, k;
for (i = 0; i < 18; ++i) for (i = 0; i < 9; ++i)
for (j = 0; j < 256; ++j) for (j = 0; j < 256; ++j)
{ {
gamma2table[i][j] = (byte)(pow(j / 255.0, 1.0 / gammalevels[i]) * 255.0 + 0.5); gamma2table[i][j] = (byte)(pow(j / 255.0, 1.0 / gammalevels[i]) * 255.0 + 0.5);
} }
// [crispy] 5 original gamma levels
for (i = 9, k = 0; i < 18 && k < 5; i += 2, k++)
memcpy(gamma2table[i], gammatable[k], 256);
// [crispy] 4 intermediate gamma levels
for (i = 10, k = 0; i < 18 && k < 4; i += 2, k++)
for (j = 0; j < 256; ++j)
{
gamma2table[i][j] = (gammatable[k][j] + gammatable[k + 1][j]) / 2;
}
} }
int gamma2; int gamma2;
@ -1089,21 +1094,12 @@ void I_SetPalette(byte *palette)
{ {
// haleyjd // haleyjd
int i; int i;
byte *gamma; byte *const gamma = gamma2table[gamma2];
SDL_Color colors[256]; SDL_Color colors[256];
if (!in_graphics_mode) // killough 8/11/98 if (!in_graphics_mode) // killough 8/11/98
return; return;
if (gamma2 != 9) // 1.0f
{
gamma = gamma2table[gamma2];
}
else
{
gamma = gammatable[usegamma];
}
for(i = 0; i < 256; ++i) for(i = 0; i < 256; ++i)
{ {
colors[i].r = gamma[*palette++]; colors[i].r = gamma[*palette++];

View File

@ -3888,19 +3888,18 @@ void static M_SmoothLight(void)
static const char *gamma_strings[] = { static const char *gamma_strings[] = {
// Darker // Darker
"0.50", "0.55", "0.60", "0.65", "0.70", "0.75", "0.80", "0.85", "0.90", "-4", "-3.6", "-3.2", "-2.8", "-2.4", "-2.0", "-1.6", "-1.2", "-0.8",
// No gamma correction // No gamma correction
"1.0", "0",
// Lighter // Lighter
"1.125", "1.25", "1.375", "1.5", "1.625", "1.75", "1.875", "2.0", "0.5", "1", "1.5", "2", "2.5", "3", "3.5", "4",
NULL NULL
}; };
static void M_ResetGamma(void) static void M_ResetGamma(void)
{ {
usegamma = 0;
I_SetPalette(W_CacheLumpName("PLAYPAL",PU_CACHE)); I_SetPalette(W_CacheLumpName("PLAYPAL",PU_CACHE));
} }
@ -5518,17 +5517,11 @@ boolean M_Responder (event_t* ev)
if (M_InputActivated(input_gamma)) // gamma toggle if (M_InputActivated(input_gamma)) // gamma toggle
{ {
usegamma++; gamma2++;
if (usegamma > 4) if (gamma2 > 17)
usegamma = 0; gamma2 = 0;
players[consoleplayer].message = doomprintf("Gamma correction level %s", gamma_strings[gamma2]);
usegamma == 0 ? s_GAMMALVL0 : M_ResetGamma();
usegamma == 1 ? s_GAMMALVL1 :
usegamma == 2 ? s_GAMMALVL2 :
usegamma == 3 ? s_GAMMALVL3 :
s_GAMMALVL4;
gamma2 = 9; // 1.0f
I_SetPalette (W_CacheLumpName ("PLAYPAL",PU_CACHE));
return true; return true;
} }

View File

@ -276,7 +276,7 @@ default_t defaults[] = {
"gamma2", "gamma2",
(config_t *) &gamma2, NULL, (config_t *) &gamma2, NULL,
{9}, {0,17}, number, ss_gen, wad_no, {9}, {0,17}, number, ss_gen, wad_no,
"custom gamma level (0 = 0.5, 9 = 1.0, 17 = 2.0)" "custom gamma level (0 = -4, 9 = 0, 17 = 4)"
}, },
{ {
@ -609,13 +609,6 @@ default_t defaults[] = {
"initial play screen size" "initial play screen size"
}, },
{ //jff 3/6/98 fix erroneous upper limit in range
"usegamma",
(config_t *) &usegamma, NULL,
{0}, {0,4}, number, ss_none, wad_no,
"screen brightness (gamma correction)"
},
// killough 10/98: compatibility vector: // killough 10/98: compatibility vector:
{ {

View File

@ -150,8 +150,6 @@ byte gammatable[5][256] =
251,252,252,253,254,254,255,255} 251,252,252,253,254,254,255,255}
}; };
int usegamma;
// //
// V_InitColorTranslation // V_InitColorTranslation
// //

View File

@ -97,7 +97,6 @@ typedef enum
extern byte *screens[5]; extern byte *screens[5];
extern int dirtybox[4]; extern int dirtybox[4];
extern byte gammatable[5][256]; extern byte gammatable[5][256];
extern int usegamma; // killough 11/98
//jff 4/24/98 loads color translation lumps //jff 4/24/98 loads color translation lumps
void V_InitColorTranslation(void); void V_InitColorTranslation(void);