2016-03-01 15:47:10 +00:00
|
|
|
/*
|
|
|
|
** v_palette.cpp
|
|
|
|
** Automatic colormap generation for "colored lights", etc.
|
|
|
|
**
|
|
|
|
**---------------------------------------------------------------------------
|
|
|
|
** Copyright 1998-2006 Randy Heit
|
|
|
|
** All rights reserved.
|
|
|
|
**
|
|
|
|
** Redistribution and use in source and binary forms, with or without
|
|
|
|
** modification, are permitted provided that the following conditions
|
|
|
|
** are met:
|
|
|
|
**
|
|
|
|
** 1. Redistributions of source code must retain the above copyright
|
|
|
|
** notice, this list of conditions and the following disclaimer.
|
|
|
|
** 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
** notice, this list of conditions and the following disclaimer in the
|
|
|
|
** documentation and/or other materials provided with the distribution.
|
|
|
|
** 3. The name of the author may not be used to endorse or promote products
|
|
|
|
** derived from this software without specific prior written permission.
|
|
|
|
**
|
|
|
|
** THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
|
|
|
** IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
|
|
|
** OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
|
|
|
** IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
|
|
** INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
|
|
|
** NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
|
|
|
** THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
**---------------------------------------------------------------------------
|
|
|
|
**
|
|
|
|
*/
|
|
|
|
|
2017-03-09 22:30:42 +00:00
|
|
|
#include "g_level.h"
|
|
|
|
|
2016-03-01 15:47:10 +00:00
|
|
|
#ifdef _WIN32
|
|
|
|
#include <io.h>
|
|
|
|
#else
|
|
|
|
#define O_BINARY 0
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "templates.h"
|
|
|
|
#include "v_video.h"
|
2020-04-11 11:36:23 +00:00
|
|
|
#include "filesystem.h"
|
2016-03-01 15:47:10 +00:00
|
|
|
#include "i_video.h"
|
|
|
|
#include "c_dispatch.h"
|
|
|
|
#include "st_stuff.h"
|
|
|
|
#include "x86.h"
|
2017-01-08 17:45:30 +00:00
|
|
|
#include "g_levellocals.h"
|
2020-03-15 09:22:42 +00:00
|
|
|
#include "m_png.h"
|
2016-03-01 15:47:10 +00:00
|
|
|
|
|
|
|
/* Current color blending values */
|
|
|
|
int BlendR, BlendG, BlendB, BlendA;
|
|
|
|
|
|
|
|
/**************************/
|
|
|
|
/* Gamma correction stuff */
|
|
|
|
/**************************/
|
|
|
|
|
2017-03-08 17:47:52 +00:00
|
|
|
uint8_t newgamma[256];
|
2016-03-01 15:47:10 +00:00
|
|
|
CUSTOM_CVAR (Float, Gamma, 1.f, CVAR_ARCHIVE|CVAR_GLOBALCONFIG)
|
|
|
|
{
|
|
|
|
if (self == 0.f)
|
|
|
|
{ // Gamma values of 0 are illegal.
|
|
|
|
self = 1.f;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (screen != NULL)
|
|
|
|
{
|
2018-04-29 11:45:53 +00:00
|
|
|
screen->SetGamma ();
|
2016-03-01 15:47:10 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
CCMD (bumpgamma)
|
|
|
|
{
|
2019-01-27 15:59:50 +00:00
|
|
|
// [RH] Gamma correction tables are now generated on the fly for *any* gamma level
|
2016-03-01 15:47:10 +00:00
|
|
|
// Q: What are reasonable limits to use here?
|
|
|
|
|
|
|
|
float newgamma = Gamma + 0.1f;
|
|
|
|
|
|
|
|
if (newgamma > 3.0)
|
|
|
|
newgamma = 1.0;
|
|
|
|
|
|
|
|
Gamma = newgamma;
|
|
|
|
Printf ("Gamma correction level %g\n", *Gamma);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-09-30 22:21:51 +00:00
|
|
|
|
2016-03-01 15:47:10 +00:00
|
|
|
void InitPalette ()
|
|
|
|
{
|
2017-03-08 17:47:52 +00:00
|
|
|
uint8_t pal[768];
|
2018-03-18 12:47:40 +00:00
|
|
|
|
2020-04-11 11:24:34 +00:00
|
|
|
ReadPalette(fileSystem.GetNumForName("PLAYPAL"), pal);
|
2016-03-01 15:47:10 +00:00
|
|
|
|
2020-04-11 16:22:21 +00:00
|
|
|
GPalette.Init(NUM_TRANSLATION_TABLES);
|
2020-04-11 16:58:38 +00:00
|
|
|
GPalette.SetPalette (pal, -1);
|
2020-04-11 16:53:56 +00:00
|
|
|
|
|
|
|
int lump = fileSystem.CheckNumForName("COLORMAP");
|
|
|
|
if (lump == -1) lump = fileSystem.CheckNumForName("COLORMAP", ns_colormaps);
|
|
|
|
if (lump != -1)
|
|
|
|
{
|
|
|
|
FileData cmap = fileSystem.ReadFile(lump);
|
|
|
|
uint8_t palbuffer[768];
|
|
|
|
ReadPalette(fileSystem.GetNumForName("PLAYPAL"), palbuffer);
|
|
|
|
const unsigned char* cmapdata = (const unsigned char*)cmap.GetMem();
|
|
|
|
GPalette.GenerateGlobalBrightmapFromColormap(cmapdata, 32);
|
|
|
|
}
|
|
|
|
|
2020-04-11 11:46:53 +00:00
|
|
|
MakeGoodRemap ((uint32_t*)GPalette.BaseColors, GPalette.Remap);
|
2017-03-08 17:47:52 +00:00
|
|
|
ColorMatcher.SetPalette ((uint32_t *)GPalette.BaseColors);
|
2016-03-01 15:47:10 +00:00
|
|
|
|
2018-03-18 10:57:41 +00:00
|
|
|
if (GPalette.Remap[0] == 0)
|
|
|
|
{ // No duplicates, so settle for something close to color 0
|
|
|
|
GPalette.Remap[0] = BestColor ((uint32_t *)GPalette.BaseColors,
|
|
|
|
GPalette.BaseColors[0].r, GPalette.BaseColors[0].g, GPalette.BaseColors[0].b, 1, 255);
|
2016-03-01 15:47:10 +00:00
|
|
|
}
|
2020-04-11 16:58:38 +00:00
|
|
|
GPalette.BaseColors[0] = 0;
|
2016-03-01 15:47:10 +00:00
|
|
|
|
|
|
|
// Colormaps have to be initialized before actors are loaded,
|
|
|
|
// otherwise Powerup.Colormap will not work.
|
|
|
|
R_InitColormaps ();
|
2019-09-30 22:21:51 +00:00
|
|
|
BuildTransTable (GPalette.BaseColors);
|
|
|
|
|
2016-03-01 15:47:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
CCMD (testblend)
|
|
|
|
{
|
|
|
|
FString colorstring;
|
|
|
|
int color;
|
|
|
|
float amt;
|
|
|
|
|
|
|
|
if (argv.argc() < 3)
|
|
|
|
{
|
|
|
|
Printf ("testblend <color> <amount>\n");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if ( !(colorstring = V_GetColorStringByName (argv[1])).IsEmpty() )
|
|
|
|
{
|
|
|
|
color = V_GetColorFromString (NULL, colorstring);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
color = V_GetColorFromString (NULL, argv[1]);
|
|
|
|
}
|
|
|
|
amt = (float)atof (argv[2]);
|
|
|
|
if (amt > 1.0f)
|
|
|
|
amt = 1.0f;
|
|
|
|
else if (amt < 0.0f)
|
|
|
|
amt = 0.0f;
|
|
|
|
BaseBlendR = RPART(color);
|
|
|
|
BaseBlendG = GPART(color);
|
|
|
|
BaseBlendB = BPART(color);
|
|
|
|
BaseBlendA = amt;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|