mirror of
https://github.com/ZDoom/raze-gles.git
synced 2024-11-10 23:02:03 +00:00
Better gamma ramp adjustment, uses vid_gamma, vid_brightness and vid_contrast cvars
Will be added to menu during upcoming menu redesign git-svn-id: https://svn.eduke32.com/eduke32@870 1a8010ca-5511-0410-912e-c29ae57300e0
This commit is contained in:
parent
fcf3f17e30
commit
b45bb674d1
11 changed files with 109 additions and 39 deletions
|
@ -129,7 +129,8 @@ void showframe(int);
|
|||
|
||||
int setpalette(int start, int num, char *dapal);
|
||||
//int getpalette(int start, int num, char *dapal);
|
||||
int setgamma(float ro, float go, float bo);
|
||||
int setgamma(void);
|
||||
float vid_gamma, vid_contrast, vid_brightness;
|
||||
|
||||
int switchrendermethod(int,int); // 0 = software, 1 = opengl | bool = reinit
|
||||
|
||||
|
|
|
@ -208,6 +208,45 @@ static int osdcmd_vars(const osdfuncparm_t *parm)
|
|||
return OSDCMD_SHOWHELP;
|
||||
}
|
||||
|
||||
static int osdcmd_vid_gamma(const osdfuncparm_t *parm)
|
||||
{
|
||||
if (parm->numparms != 1)
|
||||
{
|
||||
OSD_Printf("\"vid_gamma\" is \"%.1f\"\n",vid_gamma);
|
||||
return OSDCMD_SHOWHELP;
|
||||
}
|
||||
vid_gamma = atof(parm->parms[0]);
|
||||
OSD_Printf("%s\n",parm->raw);
|
||||
setgamma();
|
||||
return OSDCMD_OK;
|
||||
}
|
||||
|
||||
static int osdcmd_vid_brightness(const osdfuncparm_t *parm)
|
||||
{
|
||||
if (parm->numparms != 1)
|
||||
{
|
||||
OSD_Printf("\"vid_brightness\" is \"%.1f\"\n",vid_brightness);
|
||||
return OSDCMD_SHOWHELP;
|
||||
}
|
||||
vid_brightness = atof(parm->parms[0]);
|
||||
OSD_Printf("%s\n",parm->raw);
|
||||
setgamma();
|
||||
return OSDCMD_OK;
|
||||
}
|
||||
|
||||
static int osdcmd_vid_contrast(const osdfuncparm_t *parm)
|
||||
{
|
||||
if (parm->numparms != 1)
|
||||
{
|
||||
OSD_Printf("\"vid_contrast\" is \"%.1f\"\n",vid_contrast);
|
||||
return OSDCMD_SHOWHELP;
|
||||
}
|
||||
vid_contrast = atof(parm->parms[0]);
|
||||
OSD_Printf("%s\n",parm->raw);
|
||||
setgamma();
|
||||
return OSDCMD_OK;
|
||||
}
|
||||
|
||||
int baselayer_init(void)
|
||||
{
|
||||
#ifdef POLYMOST
|
||||
|
@ -234,7 +273,9 @@ int baselayer_init(void)
|
|||
#endif
|
||||
OSD_RegisterFunction("glinfo","glinfo: shows OpenGL information about the current OpenGL mode",osdcmd_glinfo);
|
||||
#endif
|
||||
|
||||
OSD_RegisterFunction("vid_gamma","vid_gamma <gamma>: adjusts gamma ramp",osdcmd_vid_gamma);
|
||||
OSD_RegisterFunction("vid_contrast","vid_contrast <gamma>: adjusts gamma ramp",osdcmd_vid_contrast);
|
||||
OSD_RegisterFunction("vid_brightness","vid_brightness <gamma>: adjusts gamma ramp",osdcmd_vid_brightness);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
@ -78,6 +78,7 @@ int dommxoverlay = 1, beforedrawrooms = 1, indrawroomsandmasks = 0;
|
|||
static int oxdimen = -1, oviewingrange = -1, oxyaspect = -1;
|
||||
|
||||
int curbrightness = 0, gammabrightness = 0;
|
||||
float vid_gamma = 1.0, vid_contrast = 1.0, vid_brightness = 0.0;
|
||||
|
||||
//Textured Map variables
|
||||
static char globalpolytype;
|
||||
|
@ -9985,15 +9986,14 @@ static unsigned int lastpalettesum = 0;
|
|||
void setbrightness(char dabrightness, char *dapal, char noapply)
|
||||
{
|
||||
int i, k, j;
|
||||
float f;
|
||||
unsigned int newpalettesum, lastbright;
|
||||
|
||||
lastbright = curbrightness;
|
||||
if (!(noapply&4))
|
||||
curbrightness = min(max((int)dabrightness,0),15);
|
||||
|
||||
f = 1.0 + ((float)curbrightness / 10.0);
|
||||
if (setgamma(f,f,f)) j = curbrightness; else j = 0;
|
||||
vid_gamma = 1.0 + ((float)curbrightness / 10.0);
|
||||
if (setgamma()) j = curbrightness; else j = 0;
|
||||
|
||||
for (k=i=0;i<256;i++)
|
||||
{
|
||||
|
|
|
@ -814,7 +814,7 @@ int OSD_HandleChar(char ch)
|
|||
lastmatch = symb;
|
||||
symb=findsymbol(osdedittmp, lastmatch->next);
|
||||
}
|
||||
OSD_Printf(OSDTEXT_GREEN "Found %d possible completions for '%s':\n",num,osdedittmp);
|
||||
OSD_Printf(OSDTEXT_RED "Found %d possible completions for '%s':\n",num,osdedittmp);
|
||||
maxwidth += 3;
|
||||
symb = tabc;
|
||||
OSD_Printf(" ");
|
||||
|
|
|
@ -57,7 +57,7 @@ char videomodereset = 0;
|
|||
char nofog=0;
|
||||
static unsigned short sysgamma[3][256];
|
||||
extern int curbrightness, gammabrightness;
|
||||
|
||||
extern float vid_gamma, vid_contrast, vid_brightness;
|
||||
#ifdef USE_OPENGL
|
||||
// OpenGL stuff
|
||||
static char nogl=0;
|
||||
|
@ -1160,12 +1160,12 @@ int setvideomode(int x, int y, int c, int fs)
|
|||
// save the current system gamma to determine if gamma is available
|
||||
if (!gammabrightness)
|
||||
{
|
||||
float f = 1.0 + ((float)curbrightness / 10.0);
|
||||
// float f = 1.0 + ((float)curbrightness / 10.0);
|
||||
if (SDL_GetGammaRamp(sysgamma[0], sysgamma[1], sysgamma[2]) >= 0)
|
||||
gammabrightness = 1;
|
||||
|
||||
// see if gamma really is working by trying to set the brightness
|
||||
if (gammabrightness && SDL_SetGamma(f,f,f) < 0)
|
||||
if (gammabrightness && setgamma() < 0)
|
||||
gammabrightness = 0; // nope
|
||||
}
|
||||
|
||||
|
@ -1363,9 +1363,28 @@ int getpalette(int start, int num, char *dapal)
|
|||
//
|
||||
// setgamma
|
||||
//
|
||||
int setgamma(float ro, float go, float bo)
|
||||
int setgamma(void)
|
||||
{
|
||||
return SDL_SetGamma(ro,go,bo);
|
||||
int i;
|
||||
unsigned short gammaTable[768];
|
||||
float gamma = max(0.1f,min(4.f,vid_gamma));
|
||||
float contrast = max(0.1f,min(3.f,vid_contrast));
|
||||
float bright = max(-0.8f,min(0.8f,vid_brightness));
|
||||
|
||||
double invgamma = 1 / gamma;
|
||||
double norm = pow(255., invgamma - 1);
|
||||
|
||||
// This formula is taken from Doomsday
|
||||
|
||||
for (i = 0; i < 256; i++)
|
||||
{
|
||||
double val = i * contrast - (contrast - 1) * 127;
|
||||
if (gamma != 1) val = pow(val, invgamma) / norm;
|
||||
val += bright * 128;
|
||||
|
||||
gammaTable[i] = gammaTable[i + 256] = gammaTable[i + 512] = (unsigned short)max(0.f,(double)min(0xffff,val*256));
|
||||
}
|
||||
return SDL_SetGammaRamp(&gammaTable[0],&gammaTable[256],&gammaTable[512]);
|
||||
}
|
||||
|
||||
#ifndef __APPLE__
|
||||
|
|
|
@ -62,6 +62,7 @@ int is_vista = 0;
|
|||
|
||||
static WORD sysgamma[3][256];
|
||||
extern int curbrightness, gammabrightness;
|
||||
extern float vid_gamma, vid_contrast, vid_brightness;
|
||||
|
||||
#if defined(USE_OPENGL) && defined(POLYMOST)
|
||||
// OpenGL stuff
|
||||
|
@ -2104,9 +2105,9 @@ int setvideomode(int x, int y, int c, int fs)
|
|||
|
||||
if (!gammabrightness)
|
||||
{
|
||||
float f = 1.0 + ((float)curbrightness / 10.0);
|
||||
// float f = 1.0 + ((float)curbrightness / 10.0);
|
||||
if (getgammaramp(sysgamma) >= 0) gammabrightness = 1;
|
||||
if (gammabrightness && setgamma(f,f,f) < 0) gammabrightness = 0;
|
||||
if (gammabrightness && setgamma() < 0) gammabrightness = 0;
|
||||
}
|
||||
|
||||
for (i=0;i<NUM_INPUTS;i++) if (inp[i]) AcquireInputDevices(1,i);
|
||||
|
@ -2657,22 +2658,30 @@ static int setgammaramp(WORD gt[3][256])
|
|||
}
|
||||
}
|
||||
|
||||
int setgamma(float ro, float go, float bo)
|
||||
int setgamma(void)
|
||||
{
|
||||
int i;
|
||||
WORD gt[3][256];
|
||||
WORD gammaTable[768];
|
||||
float gamma = max(0.1f,min(4.f,vid_gamma));
|
||||
float contrast = max(0.1f,min(3.f,vid_contrast));
|
||||
float bright = max(-0.8f,min(0.8f,vid_brightness));
|
||||
|
||||
double invgamma = 1 / gamma;
|
||||
double norm = pow(255., invgamma - 1);
|
||||
|
||||
if (!hWindow) return -1;
|
||||
|
||||
ro = 1.0 / ro; go = 1.0 / go; bo = 1.0 / bo;
|
||||
for (i=0;i<256;i++)
|
||||
{
|
||||
gt[0][i] = (WORD)min(65535, max(0, (int)(pow((double)i / 256.0, ro) * 65535.0 + 0.5)));
|
||||
gt[1][i] = (WORD)min(65535, max(0, (int)(pow((double)i / 256.0, go) * 65535.0 + 0.5)));
|
||||
gt[2][i] = (WORD)min(65535, max(0, (int)(pow((double)i / 256.0, go) * 65535.0 + 0.5)));
|
||||
}
|
||||
|
||||
return setgammaramp(gt);
|
||||
// This formula is taken from Doomsday
|
||||
|
||||
for (i = 0; i < 256; i++)
|
||||
{
|
||||
double val = i * contrast - (contrast - 1) * 127;
|
||||
if (gamma != 1) val = pow(val, invgamma) / norm;
|
||||
val += bright * 128;
|
||||
|
||||
gammaTable[i] = gammaTable[i + 256] = gammaTable[i + 512] = (WORD)max(0.f,(double)min(0xffff,val*256));
|
||||
}
|
||||
return setgammaramp(gammaTable);
|
||||
}
|
||||
|
||||
static int getgammaramp(WORD gt[3][256])
|
||||
|
|
|
@ -2517,8 +2517,8 @@ void FTA(int q, player_struct *p)
|
|||
if (p->ftq != q)
|
||||
if (p == g_player[screenpeek].ps)
|
||||
{
|
||||
if (cq) OSD_Printf(OSDTEXT_BLUE OSDTEXT_BRIGHT "%s\n",stripcolorcodes(fta_quotes[q]));
|
||||
else OSD_Printf("%s\n",stripcolorcodes(fta_quotes[q]));
|
||||
if (cq) OSD_Printf(OSDTEXT_BLUE "%s\n",fta_quotes[q]);
|
||||
else OSD_Printf("%s\n",fta_quotes[q]);
|
||||
}
|
||||
|
||||
p->ftq = q;
|
||||
|
|
|
@ -555,7 +555,7 @@ const memberlabel_t actorlabels[]=
|
|||
{ "htbposx", ACTOR_HTBPOSX, 0, 0 },
|
||||
{ "htbposy", ACTOR_HTBPOSY, 0, 0 },
|
||||
{ "htbposz", ACTOR_HTBPOSZ, 0, 0 },
|
||||
{ "htg_t", ACTOR_HTG_T, LABEL_HASPARM2, 9 },
|
||||
{ "htg_t", ACTOR_HTG_T, LABEL_HASPARM2, 10 },
|
||||
|
||||
// model flags
|
||||
|
||||
|
@ -598,8 +598,8 @@ const memberlabel_t playerlabels[]=
|
|||
{ "zoom", PLAYER_ZOOM, 0, 0 },
|
||||
{ "exitx", PLAYER_EXITX, 0, 0 },
|
||||
{ "exity", PLAYER_EXITY, 0, 0 },
|
||||
{ "loogiex", PLAYER_LOOGIEX, LABEL_HASPARM2, 63 },
|
||||
{ "loogiey", PLAYER_LOOGIEY, LABEL_HASPARM2, 63 },
|
||||
{ "loogiex", PLAYER_LOOGIEX, LABEL_HASPARM2, 64 },
|
||||
{ "loogiey", PLAYER_LOOGIEY, LABEL_HASPARM2, 64 },
|
||||
{ "numloogs", PLAYER_NUMLOOGS, 0, 0 },
|
||||
{ "loogcnt", PLAYER_LOOGCNT, 0, 0 },
|
||||
{ "posx", PLAYER_POSX, 0, 0 },
|
||||
|
|
|
@ -1165,7 +1165,7 @@ static void DoPlayer(int iSet, int lVar1, int lLabelID, int lVar2, int lParm2)
|
|||
return;
|
||||
}
|
||||
|
||||
if (lParm2 < 0 || lParm2 > playerlabels[lLabelID].maxParm2)
|
||||
if (lParm2 < 0 || lParm2 >= playerlabels[lLabelID].maxParm2)
|
||||
{
|
||||
OSD_Printf(OSDTEXT_DARKRED OSDTEXT_BRIGHT "DoPlayer(): tried to %s invalid %s position %d on player (%d) from spr %d\n",
|
||||
iSet?"set":"get",playerlabels[lLabelID].name,lParm2,iPlayer,g_i);
|
||||
|
@ -2995,7 +2995,7 @@ static void DoActor(int iSet, int lVar1, int lLabelID, int lVar2, int lParm2)
|
|||
return;
|
||||
}
|
||||
|
||||
if (lParm2 < 0 || lParm2 > actorlabels[lLabelID].maxParm2)
|
||||
if (lParm2 < 0 || lParm2 >= actorlabels[lLabelID].maxParm2)
|
||||
{
|
||||
OSD_Printf(OSDTEXT_DARKRED OSDTEXT_BRIGHT "DoActor(): tried to %s invalid %s position %d on sprite (%d) from spr %d\n",
|
||||
iSet?"set":"get",actorlabels[lLabelID].name,lParm2,iActor,g_i);
|
||||
|
|
|
@ -766,16 +766,16 @@ static int osdcmd_sensitivity(const osdfuncparm_t *parm)
|
|||
return OSDCMD_OK;
|
||||
}
|
||||
|
||||
static int osdcmd_gamma(const osdfuncparm_t *parm)
|
||||
static int osdcmd_setbrightness(const osdfuncparm_t *parm)
|
||||
{
|
||||
if (parm->numparms != 1)
|
||||
{
|
||||
OSD_Printf("\"gamma\" \"%d\"\n",ud.brightness>>2);
|
||||
// OSD_Printf("\"setbri\" \"%d\"\n",ud.brightness>>2);
|
||||
return OSDCMD_SHOWHELP;
|
||||
}
|
||||
ud.brightness = atoi(parm->parms[0])<<2;
|
||||
setbrightness(ud.brightness>>2,&g_player[screenpeek].ps->palette[0],0);
|
||||
OSD_Printf("gamma %d\n",ud.brightness>>2);
|
||||
OSD_Printf("setbrightness %d\n",ud.brightness>>2);
|
||||
return OSDCMD_OK;
|
||||
}
|
||||
|
||||
|
@ -1215,7 +1215,7 @@ static int osdcmd_screenshot(const osdfuncparm_t *parm)
|
|||
extern void savemapstate(mapstate_t *save);
|
||||
extern void restoremapstate(mapstate_t *save);
|
||||
|
||||
int osdcmd_savestate(const osdfuncparm_t *parm)
|
||||
static int osdcmd_savestate(const osdfuncparm_t *parm)
|
||||
{
|
||||
UNREFERENCED_PARAMETER(parm);
|
||||
if (map[ud.volume_number*MAXLEVELS+ud.level_number].savedstate == NULL)
|
||||
|
@ -1224,7 +1224,7 @@ int osdcmd_savestate(const osdfuncparm_t *parm)
|
|||
return OSDCMD_OK;
|
||||
}
|
||||
|
||||
int osdcmd_restorestate(const osdfuncparm_t *parm)
|
||||
static int osdcmd_restorestate(const osdfuncparm_t *parm)
|
||||
{
|
||||
UNREFERENCED_PARAMETER(parm);
|
||||
if (map[ud.volume_number*MAXLEVELS+ud.level_number].savedstate)
|
||||
|
@ -1271,7 +1271,7 @@ int registerosdcommands(void)
|
|||
OSD_RegisterFunction(t,Bstrdup(tempbuf),osdcmd_button);
|
||||
}
|
||||
|
||||
OSD_RegisterFunction("gamma","gamma <value>: changes brightness", osdcmd_gamma);
|
||||
OSD_RegisterFunction("setbrightness","setbrightness <value>: changes brightness", osdcmd_setbrightness);
|
||||
OSD_RegisterFunction("give","give <all|health|weapons|ammo|armor|keys|inventory>: gives requested item", osdcmd_give);
|
||||
OSD_RegisterFunction("god","god: toggles god mode", osdcmd_god);
|
||||
|
||||
|
|
|
@ -3583,7 +3583,7 @@ void processinput(int snum)
|
|||
Bsprintf(tempbuf,fta_quotes[PPDEATHSTRINGS+i+(mulscale(krand(), 3, 16)*10)],name1,name2);
|
||||
if (ud.config.ScreenWidth >= 800)
|
||||
adduserquote(tempbuf);
|
||||
else OSD_Printf("%s\n",stripcolorcodes(tempbuf));
|
||||
else OSD_Printf("%s\n",tempbuf);
|
||||
}
|
||||
}
|
||||
else
|
||||
|
@ -3604,7 +3604,7 @@ void processinput(int snum)
|
|||
{
|
||||
if (ud.config.ScreenWidth >= 800)
|
||||
adduserquote(tempbuf);
|
||||
else OSD_Printf("%s\n",stripcolorcodes(tempbuf));
|
||||
else OSD_Printf("%s\n",tempbuf);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue