diff --git a/src/gamedata/textures/texturemanager.cpp b/src/gamedata/textures/texturemanager.cpp index 8f052222c9e..ee5badce806 100644 --- a/src/gamedata/textures/texturemanager.cpp +++ b/src/gamedata/textures/texturemanager.cpp @@ -1549,7 +1549,7 @@ void FTextureManager::GenerateGlobalBrightmapFromColormap() if (lump == -1) return; FMemLump cmap = Wads.ReadLump(lump); uint8_t palbuffer[768]; - ReadPalette(Wads.CheckNumForName("PLAYPAL"), palbuffer); + ReadPalette(Wads.GetNumForName("PLAYPAL"), palbuffer); const unsigned char *cmapdata = (const unsigned char *)cmap.GetMem(); const uint8_t *paldata = palbuffer; diff --git a/src/gamedata/w_wad.cpp b/src/gamedata/w_wad.cpp index 485ca33ea0a..95926835032 100644 --- a/src/gamedata/w_wad.cpp +++ b/src/gamedata/w_wad.cpp @@ -500,7 +500,7 @@ int FWadCollection::GetNumForName (const char *name, int space) i = CheckNumForName (name, space); if (i == -1) - I_Error ("W_GetNumForName: %s not found!", name); + I_Error ("GetNumForName: %s not found!", name); return i; } diff --git a/src/r_data/r_translate.cpp b/src/r_data/r_translate.cpp index e6a85c929a6..f2240272096 100644 --- a/src/r_data/r_translate.cpp +++ b/src/r_data/r_translate.cpp @@ -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 @@ -1521,16 +1550,30 @@ void R_ParseTrnslate() do { sc.MustGetToken(TK_StringConst); - 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()); } - } while (sc.CheckToken(',')); int trans = NewTranslation.StoreTranslation(TRANSLATION_Custom); diff --git a/src/r_data/r_translate.h b/src/r_data/r_translate.h index 0c52f256d70..bf0d3864642 100644 --- a/src/r_data/r_translate.h +++ b/src/r_data/r_translate.h @@ -78,6 +78,7 @@ struct FRemapTable 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 AddToTranslation(const char * range); + bool AddColors(int start, int count, const uint8_t*); int StoreTranslation(int slot); int GetUniqueIndex(); diff --git a/src/r_data/v_palette.cpp b/src/r_data/v_palette.cpp index 1a6c25b2550..4135fab129d 100644 --- a/src/r_data/v_palette.cpp +++ b/src/r_data/v_palette.cpp @@ -48,6 +48,7 @@ #include "st_stuff.h" #include "x86.h" #include "g_levellocals.h" +#include "m_png.h" uint32_t Col2RGB8[65][256]; 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) { - I_FatalError("Palette not found"); + return 0; } FMemLump lump = Wads.ReadLump(lumpnum); uint8_t *lumpmem = (uint8_t*)lump.GetMem(); 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(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(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; @@ -308,6 +334,12 @@ void ReadPalette(int lumpnum, uint8_t *buffer) } buffer[i] = sc.Number; } + return colors / 3; + } + else + { + memcpy(buffer, lumpmem, MIN(768, lump.GetSize())); + return 256; } } @@ -371,7 +403,7 @@ void InitPalette () { uint8_t pal[768]; - ReadPalette(Wads.CheckNumForName("PLAYPAL"), pal); + ReadPalette(Wads.GetNumForName("PLAYPAL"), pal); GPalette.SetPalette (pal); GPalette.MakeGoodRemap (); diff --git a/src/r_data/v_palette.h b/src/r_data/v_palette.h index e12ba9a8f93..dbabd92e8bc 100644 --- a/src/r_data/v_palette.h +++ b/src/r_data/v_palette.h @@ -63,7 +63,7 @@ extern FPalette GPalette; // The color overlay to use for depleted items #define DIM_OVERLAY MAKEARGB(170,0,0,0) -void ReadPalette(int lumpnum, uint8_t *buffer); +int ReadPalette(int lumpnum, uint8_t *buffer); void InitPalette (); EXTERN_CVAR (Int, paletteflash) diff --git a/src/win32/st_start_util.cpp b/src/win32/st_start_util.cpp index b347a3439fc..72bb3f14a46 100644 --- a/src/win32/st_start_util.cpp +++ b/src/win32/st_start_util.cpp @@ -1031,7 +1031,7 @@ void ST_Util_BitmapColorsFromPlaypal(BitmapInfo* bitmap_info) { uint8_t playpal[768]; - ReadPalette(Wads.CheckNumForName("PLAYPAL"), playpal); + ReadPalette(Wads.GetNumForName("PLAYPAL"), playpal); for (int i = 0; i < 256; ++i) { bitmap_info->bmiColors[i].rgbBlue = playpal[i * 3 + 2]; diff --git a/wadsrc/static/zscript/base.zs b/wadsrc/static/zscript/base.zs index ee8c3fb8936..e8e986aa26d 100644 --- a/wadsrc/static/zscript/base.zs +++ b/wadsrc/static/zscript/base.zs @@ -191,6 +191,8 @@ enum DrawTextureTags DTA_Internal3, DTA_Spacing, // Strings only: Additional spacing between characters DTA_Monospace, // Strings only: Use a fixed distance between characters. + + DTA_FullsceeenEx, // advanced fullscreen control. }; class Shape2DTransform : Object native