- allow specifying full palettes in translation definitions.

This commit is contained in:
Christoph Oelckers 2020-03-15 10:22:42 +01:00
parent 27b8284881
commit 0c04cddd28
8 changed files with 92 additions and 14 deletions

View file

@ -1549,7 +1549,7 @@ void FTextureManager::GenerateGlobalBrightmapFromColormap()
if (lump == -1) return; if (lump == -1) return;
FMemLump cmap = Wads.ReadLump(lump); FMemLump cmap = Wads.ReadLump(lump);
uint8_t palbuffer[768]; uint8_t palbuffer[768];
ReadPalette(Wads.CheckNumForName("PLAYPAL"), palbuffer); ReadPalette(Wads.GetNumForName("PLAYPAL"), palbuffer);
const unsigned char *cmapdata = (const unsigned char *)cmap.GetMem(); const unsigned char *cmapdata = (const unsigned char *)cmap.GetMem();
const uint8_t *paldata = palbuffer; const uint8_t *paldata = palbuffer;

View file

@ -500,7 +500,7 @@ int FWadCollection::GetNumForName (const char *name, int space)
i = CheckNumForName (name, space); i = CheckNumForName (name, space);
if (i == -1) if (i == -1)
I_Error ("W_GetNumForName: %s not found!", name); I_Error ("GetNumForName: %s not found!", name);
return i; return i;
} }

View file

@ -770,6 +770,35 @@ bool FRemapTable::AddToTranslation(const char *range)
} }
} }
//----------------------------------------------------------------------------
//
// Adds raw colors to a given translation
//
//----------------------------------------------------------------------------
bool FRemapTable::AddColors(int start, int count, const uint8_t*colors)
{
int end = start + count;
if (IndexOutOfRange(start, end))
{
return false;
}
for (int i = start; i < end; ++i)
{
auto br = colors[0];
auto bg = colors[1];
auto bb = colors[2];
colors += 3;
int j = GPalette.Remap[i];
Palette[j] = PalEntry(j == 0 ? 0 : 255, br, bg, bb);
Remap[j] = ColorMatcher.Pick(Palette[j]);
}
return true;
}
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
// //
// Stores a copy of this translation in the DECORATE translation table // Stores a copy of this translation in the DECORATE translation table
@ -1521,16 +1550,30 @@ void R_ParseTrnslate()
do do
{ {
sc.MustGetToken(TK_StringConst); sc.MustGetToken(TK_StringConst);
try try
{ {
NewTranslation.AddToTranslation(sc.String); int pallump = Wads.CheckNumForFullName(sc.String, true, ns_global);
if (pallump) //
{
int start = 0;
if (sc.CheckToken(','))
{
sc.MustGetValue(false);
start = sc.Number;
}
uint8_t palette[768];
int numcolors = ReadPalette(pallump, palette);
NewTranslation.AddColors(start, numcolors, palette);
}
else
{
NewTranslation.AddToTranslation(sc.String);
}
} }
catch (CRecoverableError &err) catch (CRecoverableError & err)
{ {
sc.ScriptMessage("Error in translation '%s':\n" TEXTCOLOR_YELLOW "%s\n", sc.String, err.GetMessage()); sc.ScriptMessage("Error in translation '%s':\n" TEXTCOLOR_YELLOW "%s\n", sc.String, err.GetMessage());
} }
} while (sc.CheckToken(',')); } while (sc.CheckToken(','));
int trans = NewTranslation.StoreTranslation(TRANSLATION_Custom); int trans = NewTranslation.StoreTranslation(TRANSLATION_Custom);

View file

@ -78,6 +78,7 @@ struct FRemapTable
bool AddColourisation(int start, int end, int r, int g, int b); bool AddColourisation(int start, int end, int r, int g, int b);
bool AddTint(int start, int end, int r, int g, int b, int amount); bool AddTint(int start, int end, int r, int g, int b, int amount);
bool AddToTranslation(const char * range); bool AddToTranslation(const char * range);
bool AddColors(int start, int count, const uint8_t*);
int StoreTranslation(int slot); int StoreTranslation(int slot);
int GetUniqueIndex(); int GetUniqueIndex();

View file

@ -48,6 +48,7 @@
#include "st_stuff.h" #include "st_stuff.h"
#include "x86.h" #include "x86.h"
#include "g_levellocals.h" #include "g_levellocals.h"
#include "m_png.h"
uint32_t Col2RGB8[65][256]; uint32_t Col2RGB8[65][256];
uint32_t *Col2RGB8_LessPrecision[65]; uint32_t *Col2RGB8_LessPrecision[65];
@ -277,20 +278,45 @@ static int sortforremap2 (const void *a, const void *b)
} }
} }
void ReadPalette(int lumpnum, uint8_t *buffer) int ReadPalette(int lumpnum, uint8_t *buffer)
{ {
if (lumpnum < 0) if (lumpnum < 0)
{ {
I_FatalError("Palette not found"); return 0;
} }
FMemLump lump = Wads.ReadLump(lumpnum); FMemLump lump = Wads.ReadLump(lumpnum);
uint8_t *lumpmem = (uint8_t*)lump.GetMem(); uint8_t *lumpmem = (uint8_t*)lump.GetMem();
memset(buffer, 0, 768); memset(buffer, 0, 768);
if (memcmp(lumpmem, "JASC-PAL", 8))
FileReader fr;
fr.OpenMemory(lumpmem, lump.GetSize());
auto png = M_VerifyPNG(fr);
if (png)
{ {
memcpy(buffer, lumpmem, MIN<size_t>(768, lump.GetSize())); 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", Wads.GetLumpFullName(lumpnum));
} }
else if (memcmp(lumpmem, "JASC-PAL", 8) == 0)
{ {
FScanner sc; FScanner sc;
@ -308,6 +334,12 @@ void ReadPalette(int lumpnum, uint8_t *buffer)
} }
buffer[i] = sc.Number; buffer[i] = sc.Number;
} }
return colors / 3;
}
else
{
memcpy(buffer, lumpmem, MIN<size_t>(768, lump.GetSize()));
return 256;
} }
} }
@ -371,7 +403,7 @@ void InitPalette ()
{ {
uint8_t pal[768]; uint8_t pal[768];
ReadPalette(Wads.CheckNumForName("PLAYPAL"), pal); ReadPalette(Wads.GetNumForName("PLAYPAL"), pal);
GPalette.SetPalette (pal); GPalette.SetPalette (pal);
GPalette.MakeGoodRemap (); GPalette.MakeGoodRemap ();

View file

@ -63,7 +63,7 @@ extern FPalette GPalette;
// The color overlay to use for depleted items // The color overlay to use for depleted items
#define DIM_OVERLAY MAKEARGB(170,0,0,0) #define DIM_OVERLAY MAKEARGB(170,0,0,0)
void ReadPalette(int lumpnum, uint8_t *buffer); int ReadPalette(int lumpnum, uint8_t *buffer);
void InitPalette (); void InitPalette ();
EXTERN_CVAR (Int, paletteflash) EXTERN_CVAR (Int, paletteflash)

View file

@ -1031,7 +1031,7 @@ void ST_Util_BitmapColorsFromPlaypal(BitmapInfo* bitmap_info)
{ {
uint8_t playpal[768]; uint8_t playpal[768];
ReadPalette(Wads.CheckNumForName("PLAYPAL"), playpal); ReadPalette(Wads.GetNumForName("PLAYPAL"), playpal);
for (int i = 0; i < 256; ++i) for (int i = 0; i < 256; ++i)
{ {
bitmap_info->bmiColors[i].rgbBlue = playpal[i * 3 + 2]; bitmap_info->bmiColors[i].rgbBlue = playpal[i * 3 + 2];

View file

@ -191,6 +191,8 @@ enum DrawTextureTags
DTA_Internal3, DTA_Internal3,
DTA_Spacing, // Strings only: Additional spacing between characters DTA_Spacing, // Strings only: Additional spacing between characters
DTA_Monospace, // Strings only: Use a fixed distance between characters. DTA_Monospace, // Strings only: Use a fixed distance between characters.
DTA_FullsceeenEx, // advanced fullscreen control.
}; };
class Shape2DTransform : Object native class Shape2DTransform : Object native