- merged FPalette and PaletteContainer.

This commit is contained in:
Christoph Oelckers 2020-04-11 18:19:05 +02:00
commit ac610d87e5
28 changed files with 162 additions and 181 deletions

View file

@ -62,9 +62,6 @@ CUSTOM_CVAR(Color, cl_custominvulmapcolor2, 0xa6a67a, CVAR_ARCHIVE|CVAR_NOINITCA
TArray<FakeCmap> fakecmaps;
uint8_t DesaturateColormap[31][256];
static void FreeSpecialLights();
@ -168,23 +165,6 @@ void R_InitColormaps (bool allowCustomColormap)
// build default special maps (e.g. invulnerability)
InitSpecialColormaps(GPalette.BaseColors);
R_UpdateInvulnerabilityColormap();
// desaturated colormaps. These are used for texture composition
for(int m = 0; m < 31; m++)
{
uint8_t *shade = DesaturateColormap[m];
for (int c = 0; c < 256; c++)
{
int intensity = (GPalette.BaseColors[c].r * 77 +
GPalette.BaseColors[c].g * 143 +
GPalette.BaseColors[c].b * 37) / 256;
int r = (GPalette.BaseColors[c].r * (31-m) + intensity *m) / 31;
int g = (GPalette.BaseColors[c].g * (31-m) + intensity *m) / 31;
int b = (GPalette.BaseColors[c].b * (31-m) + intensity *m) / 31;
shade[c] = ColorMatcher.Pick(r, g, b);
}
}
}
//==========================================================================

View file

@ -106,9 +106,6 @@ inline uint32_t MakeSpecialColormap(int index)
return index | SPECIALCOLORMAP_MASK;
}
extern uint8_t DesaturateColormap[31][256];
enum EColorManipulation
{
CM_PLAIN2D = -2, // regular 2D drawing.

View file

@ -54,10 +54,6 @@
#include "gi.h"
PaletteContainer palMgr;
const uint8_t IcePalette[16][3] =
{
{ 10, 8, 18 },
@ -115,10 +111,10 @@ void StaticSerializeTranslations(FSerializer &arc)
int w;
if (arc.isWriting())
{
auto size = palMgr.NumTranslations(TRANSLATION_LevelScripted);
auto size = GPalette.NumTranslations(TRANSLATION_LevelScripted);
for (unsigned int i = 0; i < size; ++i)
{
trans = palMgr.TranslationToTable(TRANSLATION(TRANSLATION_LevelScripted, i));
trans = GPalette.TranslationToTable(TRANSLATION(TRANSLATION_LevelScripted, i));
if (trans != NULL && !trans->IsIdentity())
{
if (arc.BeginObject(nullptr))
@ -137,7 +133,7 @@ void StaticSerializeTranslations(FSerializer &arc)
arc("index", w);
FRemapTable remap;
SerializeRemap(arc, remap);
palMgr.UpdateTranslation(TRANSLATION(TRANSLATION_LevelScripted, w), &remap);
GPalette.UpdateTranslation(TRANSLATION(TRANSLATION_LevelScripted, w), &remap);
arc.EndObject();
}
}
@ -160,7 +156,7 @@ int CreateBloodTranslation(PalEntry color)
if (BloodTranslationColors.Size() == 0)
{
// Don't use the first slot.
palMgr.PushIdentityTable(TRANSLATION_Blood);
GPalette.PushIdentityTable(TRANSLATION_Blood);
BloodTranslationColors.Push(0);
}
@ -190,7 +186,7 @@ int CreateBloodTranslation(PalEntry color)
trans.Palette[i] = pe;
trans.Remap[i] = entry;
}
palMgr.AddTranslation(TRANSLATION_Blood, &trans);
GPalette.AddTranslation(TRANSLATION_Blood, &trans);
return BloodTranslationColors.Push(color);
}
@ -212,12 +208,12 @@ void R_InitTranslationTables ()
// maps until then so they won't be invalid.
for (i = 0; i < MAXPLAYERS; ++i)
{
palMgr.PushIdentityTable(TRANSLATION_Players);
palMgr.PushIdentityTable(TRANSLATION_PlayersExtra);
palMgr.PushIdentityTable(TRANSLATION_RainPillar);
GPalette.PushIdentityTable(TRANSLATION_Players);
GPalette.PushIdentityTable(TRANSLATION_PlayersExtra);
GPalette.PushIdentityTable(TRANSLATION_RainPillar);
}
// The menu player also gets a separate translation table
palMgr.PushIdentityTable(TRANSLATION_Players);
GPalette.PushIdentityTable(TRANSLATION_Players);
// The three standard translations from Doom or Heretic (seven for Strife),
// plus the generic ice translation.
@ -231,7 +227,7 @@ void R_InitTranslationTables ()
// color if the player who created them changes theirs.
for (i = 0; i < FLevelLocals::BODYQUESIZE; ++i)
{
palMgr.PushIdentityTable(TRANSLATION_PlayerCorpses);
GPalette.PushIdentityTable(TRANSLATION_PlayerCorpses);
}
// Create the standard translation tables
@ -367,7 +363,7 @@ void R_InitTranslationTables ()
remap->Remap[i] = v;
remap->Palette[i] = PalEntry(255, v, v, v);
}
palMgr.AddTranslation(TRANSLATION_Standard, stdremaps, 10);
GPalette.AddTranslation(TRANSLATION_Standard, stdremaps, 10);
}
@ -645,9 +641,9 @@ void R_BuildPlayerTranslation (int player)
FRemapTable remaps[3];
R_CreatePlayerTranslation (h, s, v, colorset, &Skins[players[player].userinfo.GetSkin()], &remaps[0], &remaps[1], &remaps[2]);
palMgr.UpdateTranslation(TRANSLATION(TRANSLATION_Players, player), &remaps[0]);
palMgr.UpdateTranslation(TRANSLATION(TRANSLATION_PlayersExtra, player), &remaps[1]);
palMgr.UpdateTranslation(TRANSLATION(TRANSLATION_RainPillar, player), &remaps[2]);
GPalette.UpdateTranslation(TRANSLATION(TRANSLATION_Players, player), &remaps[0]);
GPalette.UpdateTranslation(TRANSLATION(TRANSLATION_PlayersExtra, player), &remaps[1]);
GPalette.UpdateTranslation(TRANSLATION(TRANSLATION_RainPillar, player), &remaps[2]);
}
//----------------------------------------------------------------------------
@ -694,7 +690,7 @@ DEFINE_ACTION_FUNCTION(_Translation, SetPlayerTranslation)
FRemapTable remap;
R_GetPlayerTranslation(PlayerColor, GetColorSet(cls->Type, PlayerColorset),
&Skins[PlayerSkin], &remap);
palMgr.UpdateTranslation(TRANSLATION(tgroup, tnum), &remap);
GPalette.UpdateTranslation(TRANSLATION(tgroup, tnum), &remap);
}
ACTION_RETURN_BOOL(true);
}
@ -758,7 +754,7 @@ DEFINE_ACTION_FUNCTION(_Translation, GetID)
void R_ParseTrnslate()
{
customTranslationMap.Clear();
palMgr.ClearTranslationSlot(TRANSLATION_Custom);
GPalette.ClearTranslationSlot(TRANSLATION_Custom);
int lump;
int lastlump = 0;
@ -781,7 +777,7 @@ void R_ParseTrnslate()
{
sc.ScriptError("Translation must be in the range [0,%d]", max);
}
NewTranslation = *palMgr.TranslationToTable(TRANSLATION(TRANSLATION_Standard, sc.Number));
NewTranslation = *GPalette.TranslationToTable(TRANSLATION(TRANSLATION_Standard, sc.Number));
}
else if (sc.TokenType == TK_Identifier)
{
@ -790,7 +786,7 @@ void R_ParseTrnslate()
{
sc.ScriptError("Base translation '%s' not found in '%s'", sc.String, newtrans.GetChars());
}
NewTranslation = *palMgr.TranslationToTable(tnum);
NewTranslation = *GPalette.TranslationToTable(tnum);
}
else
{
@ -829,7 +825,7 @@ void R_ParseTrnslate()
}
} while (sc.CheckToken(','));
int trans = palMgr.StoreTranslation(TRANSLATION_Custom, &NewTranslation);
int trans = GPalette.StoreTranslation(TRANSLATION_Custom, &NewTranslation);
customTranslationMap[newtrans] = trans;
}
}
@ -856,7 +852,7 @@ DEFINE_ACTION_FUNCTION(_Translation, AddTranslation)
{
NewTranslation.Remap[i] = ColorMatcher.Pick(self->colors[i]);
}
int trans = palMgr.StoreTranslation(TRANSLATION_Custom, &NewTranslation);
int trans = GPalette.StoreTranslation(TRANSLATION_Custom, &NewTranslation);
ACTION_RETURN_INT(trans);
}

View file

@ -57,7 +57,6 @@ uint32_t Col2RGB8_2[63][256]; // this array's second dimension is called up by p
ColorTable32k RGB32k;
ColorTable256k RGB256k;
FPalette GPalette;
FColorMatcher ColorMatcher;
/* Current color blending values */
@ -97,99 +96,6 @@ CCMD (bumpgamma)
}
FPalette::FPalette ()
{
}
FPalette::FPalette (const uint8_t *colors)
{
SetPalette (colors);
}
void FPalette::SetPalette (const uint8_t *colors)
{
for (int i = 0; i < 256; i++, colors += 3)
{
BaseColors[i] = PalEntry (colors[0], colors[1], colors[2]);
Remap[i] = i;
}
// Find white and black from the original palette so that they can be
// used to make an educated guess of the translucency % for a BOOM
// translucency map.
WhiteIndex = BestColor ((uint32_t *)BaseColors, 255, 255, 255, 0, 255);
BlackIndex = BestColor ((uint32_t *)BaseColors, 0, 0, 0, 0, 255);
}
int ReadPalette(int lumpnum, uint8_t *buffer)
{
if (lumpnum < 0)
{
return 0;
}
FileData lump = fileSystem.ReadFile(lumpnum);
uint8_t *lumpmem = (uint8_t*)lump.GetMem();
memset(buffer, 0, 768);
FileReader fr;
fr.OpenMemory(lumpmem, lump.GetSize());
auto png = M_VerifyPNG(fr);
if (png)
{
uint32_t id, len;
fr.Seek(33, FileReader::SeekSet);
fr.Read(&len, 4);
fr.Read(&id, 4);
bool succeeded = false;
while (id != MAKE_ID('I', 'D', 'A', 'T') && id != MAKE_ID('I', 'E', 'N', 'D'))
{
len = BigLong((unsigned int)len);
if (id != MAKE_ID('P', 'L', 'T', 'E'))
fr.Seek(len, FileReader::SeekCur);
else
{
int PaletteSize = MIN<int>(len, 768);
fr.Read(buffer, PaletteSize);
return PaletteSize / 3;
}
fr.Seek(4, FileReader::SeekCur); // Skip CRC
fr.Read(&len, 4);
id = MAKE_ID('I', 'E', 'N', 'D');
fr.Read(&id, 4);
}
I_Error("%s contains no palette", fileSystem.GetFileFullName(lumpnum));
}
if (memcmp(lumpmem, "JASC-PAL", 8) == 0)
{
FScanner sc;
sc.OpenMem(fileSystem.GetFileFullName(lumpnum), (char*)lumpmem, int(lump.GetSize()));
sc.MustGetString();
sc.MustGetNumber(); // version - ignore
sc.MustGetNumber();
int colors = MIN(256, sc.Number) * 3;
for (int i = 0; i < colors; i++)
{
sc.MustGetNumber();
if (sc.Number < 0 || sc.Number > 255)
{
sc.ScriptError("Color %d value out of range.", sc.Number);
}
buffer[i] = sc.Number;
}
return colors / 3;
}
else
{
memcpy(buffer, lumpmem, MIN<size_t>(768, lump.GetSize()));
return 256;
}
}
//==========================================================================
//
// BuildTransTable

View file

@ -38,23 +38,7 @@
#include "c_cvars.h"
#include "palutil.h"
struct FPalette
{
FPalette ();
FPalette (const uint8_t *colors);
void SetPalette (const uint8_t *colors);
void MakeGoodRemap ();
PalEntry BaseColors[256]; // non-gamma corrected palette
uint8_t Remap[256]; // remap original palette indices to in-game indices
uint8_t WhiteIndex; // white in original palette index
uint8_t BlackIndex; // black in original palette index
};
extern FPalette GPalette;
// The color overlay to use for depleted items
#define DIM_OVERLAY MAKEARGB(170,0,0,0)