diff --git a/src/common/engine/palettecontainer.cpp b/src/common/engine/palettecontainer.cpp index ce7b5df1f..b45bfc70d 100644 --- a/src/common/engine/palettecontainer.cpp +++ b/src/common/engine/palettecontainer.cpp @@ -43,6 +43,8 @@ #include "v_palette.h" +PaletteContainer GPalette; + //---------------------------------------------------------------------------- // // @@ -60,6 +62,22 @@ void PaletteContainer::Init(int numslots) // This cannot be a constructor!!! TranslationTables.Resize(numslots); } +void PaletteContainer::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); +} + + //---------------------------------------------------------------------------- // // @@ -168,7 +186,7 @@ int PaletteContainer::StoreTranslation(int slot, FRemapTable *remap) auto size = NumTranslations(slot); for (i = 0; i < size; i++) { - if (*remap == *palMgr.TranslationToTable(TRANSLATION(slot, i))) + if (*remap == *TranslationToTable(TRANSLATION(slot, i))) { // A duplicate of this translation already exists return TRANSLATION(slot, i); diff --git a/src/common/engine/palettecontainer.h b/src/common/engine/palettecontainer.h index 2737f9f89..86c87cd5e 100644 --- a/src/common/engine/palettecontainer.h +++ b/src/common/engine/palettecontainer.h @@ -67,11 +67,19 @@ inline int GetTranslationIndex(uint32_t trans) class PaletteContainer { +public: + 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 +private: FMemArena remapArena; TArray uniqueRemaps; TArray> TranslationTables; public: void Init(int numslots); // This cannot be a constructor!!! + void SetPalette(const uint8_t* colors); void Clear(); FRemapTable* AddRemap(FRemapTable* remap); void UpdateTranslation(int trans, FRemapTable* remap); @@ -102,5 +110,5 @@ public: }; -extern PaletteContainer palMgr; +extern PaletteContainer GPalette; diff --git a/src/common/utility/palette.cpp b/src/common/utility/palette.cpp index 0e4b67d4a..5be3f6a45 100644 --- a/src/common/utility/palette.cpp +++ b/src/common/utility/palette.cpp @@ -40,6 +40,7 @@ #include "filesystem.h" #include "printf.h" #include "templates.h" +#include "m_png.h" /****************************/ /* Palette management stuff */ @@ -703,6 +704,7 @@ int V_GetColor(const uint32_t* palette, FScanner& sc) TArray SpecialColormaps; +uint8_t DesaturateColormap[31][256]; // These default tables are needed for texture composition. static FSpecialColormapParameters SpecialColormapParms[] = @@ -820,5 +822,91 @@ void InitSpecialColormaps(PalEntry *pe) SpecialColormapParms[i].Start[2], SpecialColormapParms[i].End[0], SpecialColormapParms[i].End[1], SpecialColormapParms[i].End[2]); } + + // 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 = pe[c].Luminance(); + + int r = (pe[c].r * (31 - m) + intensity * m) / 31; + int g = (pe[c].g * (31 - m) + intensity * m) / 31; + int b = (pe[c].b * (31 - m) + intensity * m) / 31; + shade[c] = BestColor((uint32_t*)pe, r, g, b); + } + } +} + +//========================================================================== +// +// +// +//========================================================================== + +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(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(768, lump.GetSize())); + return 256; + } } diff --git a/src/common/utility/palutil.h b/src/common/utility/palutil.h index 84e0f7d78..7e6e966cf 100644 --- a/src/common/utility/palutil.h +++ b/src/common/utility/palutil.h @@ -55,7 +55,9 @@ struct FSpecialColormap }; extern TArray SpecialColormaps; +extern uint8_t DesaturateColormap[31][256]; int AddSpecialColormap(PalEntry *pe, float r1, float g1, float b1, float r2, float g2, float b2); void InitSpecialColormaps(PalEntry* pe); void UpdateSpecialColormap(PalEntry* BaseColors, unsigned int index, float r1, float g1, float b1, float r2, float g2, float b2); +int ReadPalette(int lumpnum, uint8_t* buffer); diff --git a/src/d_main.cpp b/src/d_main.cpp index 088b17c2f..cbfdb86b7 100644 --- a/src/d_main.cpp +++ b/src/d_main.cpp @@ -2872,7 +2872,7 @@ static int D_DoomMain_Internal (void) C_InitConback(); StartScreen->Progress(); - palMgr.Init(NUM_TRANSLATION_TABLES); + GPalette.Init(NUM_TRANSLATION_TABLES); V_InitFonts(); // [CW] Parse any TEAMINFO lumps. diff --git a/src/g_game.cpp b/src/g_game.cpp index 78780fafb..84ac12047 100644 --- a/src/g_game.cpp +++ b/src/g_game.cpp @@ -1634,7 +1634,7 @@ void FLevelLocals::QueueBody (AActor *body) GetTranslationType(body->Translation) == TRANSLATION_PlayersExtra) { // This needs to be able to handle multiple levels, in case a level with dead players is used as a secondary one later. - palMgr.CopyTranslation(TRANSLATION(TRANSLATION_PlayerCorpses, modslot), body->Translation); + GPalette.CopyTranslation(TRANSLATION(TRANSLATION_PlayerCorpses, modslot), body->Translation); body->Translation = TRANSLATION(TRANSLATION_PlayerCorpses, modslot); } diff --git a/src/gamedata/fonts/font.cpp b/src/gamedata/fonts/font.cpp index 914fdeddb..04ec748dd 100644 --- a/src/gamedata/fonts/font.cpp +++ b/src/gamedata/fonts/font.cpp @@ -666,7 +666,7 @@ void FFont::SetDefaultTranslation(uint32_t *othercolors) } } } - Translations[CR_UNTRANSLATED] = palMgr.StoreTranslation(TRANSLATION_Font, &remap); + Translations[CR_UNTRANSLATED] = GPalette.StoreTranslation(TRANSLATION_Font, &remap); forceremap = true; } @@ -797,7 +797,7 @@ void FFont::BuildTranslations (const double *luminosity, const uint8_t *identity remap.Palette[j] = GPalette.BaseColors[identity[j]] | MAKEARGB(255, 0, 0, 0); } } - Translations.Push(palMgr.StoreTranslation(TRANSLATION_Font, &remap)); + Translations.Push(GPalette.StoreTranslation(TRANSLATION_Font, &remap)); } else { @@ -837,7 +837,7 @@ void FFont::BuildTranslations (const double *luminosity, const uint8_t *identity remap.Palette[j] = PalEntry(255,r,g,b); } if (post) post(&remap); - Translations.Push(palMgr.StoreTranslation(TRANSLATION_Font, &remap)); + Translations.Push(GPalette.StoreTranslation(TRANSLATION_Font, &remap)); // Advance to the next color range. while (parmstart[1].RangeStart > parmstart[0].RangeEnd) diff --git a/src/gamedata/fonts/hexfont.cpp b/src/gamedata/fonts/hexfont.cpp index f2462444c..9e15a69ec 100644 --- a/src/gamedata/fonts/hexfont.cpp +++ b/src/gamedata/fonts/hexfont.cpp @@ -417,7 +417,7 @@ public: } } } - Translations[CR_UNTRANSLATED] = palMgr.StoreTranslation(TRANSLATION_Font, &remap); + Translations[CR_UNTRANSLATED] = GPalette.StoreTranslation(TRANSLATION_Font, &remap); forceremap = true; } diff --git a/src/gamedata/textures/formats/buildtexture.cpp b/src/gamedata/textures/formats/buildtexture.cpp index d1e505640..0c170d7b4 100644 --- a/src/gamedata/textures/formats/buildtexture.cpp +++ b/src/gamedata/textures/formats/buildtexture.cpp @@ -84,7 +84,7 @@ FBuildTexture::FBuildTexture(const FString &pathprefix, int tilenum, const uint8 TArray FBuildTexture::CreatePalettedPixels(int conversion) { TArray Pixels(Width * Height, true); - FRemapTable *Remap = palMgr.GetTranslation(TRANSLATION_Standard, Translation); + FRemapTable *Remap = GPalette.GetTranslation(TRANSLATION_Standard, Translation); for (int i = 0; i < Width*Height; i++) { auto c = RawPixels[i]; @@ -95,7 +95,7 @@ TArray FBuildTexture::CreatePalettedPixels(int conversion) int FBuildTexture::CopyPixels(FBitmap *bmp, int conversion) { - PalEntry *Remap = palMgr.GetTranslation(TRANSLATION_Standard, Translation)->Palette; + PalEntry *Remap = GPalette.GetTranslation(TRANSLATION_Standard, Translation)->Palette; bmp->CopyPixelData(0, 0, RawPixels, Width, Height, Height, 1, 0, Remap); return -1; @@ -280,7 +280,7 @@ static int BuildPaletteTranslation(int lump) opal.Remap[255] = 0; // Store the remap table in the translation manager so that we do not need to keep track of it ourselves. // Slot 0 for internal translations is a convenient location because normally it only contains a small number of translations. - return GetTranslationIndex(palMgr.StoreTranslation(TRANSLATION_Standard, &opal)); + return GetTranslationIndex(GPalette.StoreTranslation(TRANSLATION_Standard, &opal)); } diff --git a/src/gamedata/textures/formats/imgztexture.cpp b/src/gamedata/textures/formats/imgztexture.cpp index bcd9b5ac4..428a8eaf6 100644 --- a/src/gamedata/textures/formats/imgztexture.cpp +++ b/src/gamedata/textures/formats/imgztexture.cpp @@ -203,6 +203,6 @@ TArray FIMGZTexture::CreatePalettedPixels(int conversion) int FIMGZTexture::CopyPixels(FBitmap *bmp, int conversion) { if (!isalpha) return FImageSource::CopyPixels(bmp, conversion); - else return CopyTranslatedPixels(bmp, palMgr.GetTranslation(TRANSLATION_Standard, STD_Grayscale)->Palette); + else return CopyTranslatedPixels(bmp, GPalette.GetTranslation(TRANSLATION_Standard, STD_Grayscale)->Palette); } diff --git a/src/gamedata/textures/formats/multipatchtexture.cpp b/src/gamedata/textures/formats/multipatchtexture.cpp index 3dd374820..e7c9a8336 100644 --- a/src/gamedata/textures/formats/multipatchtexture.cpp +++ b/src/gamedata/textures/formats/multipatchtexture.cpp @@ -92,7 +92,7 @@ static uint8_t *GetBlendMap(PalEntry blend, uint8_t *blendwork) switch (blend.a==0 ? int(blend) : -1) { case BLEND_ICEMAP: - return palMgr.TranslationToTable(TRANSLATION(TRANSLATION_Standard, 7))->Remap; + return GPalette.TranslationToTable(TRANSLATION(TRANSLATION_Standard, 7))->Remap; default: if (blend >= BLEND_SPECIALCOLORMAP1 && blend < BLEND_SPECIALCOLORMAP1 + SpecialColormaps.Size()) diff --git a/src/gamedata/textures/formats/patchtexture.cpp b/src/gamedata/textures/formats/patchtexture.cpp index 7cbb3a3eb..efc1766c9 100644 --- a/src/gamedata/textures/formats/patchtexture.cpp +++ b/src/gamedata/textures/formats/patchtexture.cpp @@ -263,7 +263,7 @@ TArray FPatchTexture::CreatePalettedPixels(int conversion) int FPatchTexture::CopyPixels(FBitmap *bmp, int conversion) { if (!isalpha) return FImageSource::CopyPixels(bmp, conversion); - else return CopyTranslatedPixels(bmp, palMgr.GetTranslation(TRANSLATION_Standard, STD_Grayscale)->Palette); + else return CopyTranslatedPixels(bmp, GPalette.GetTranslation(TRANSLATION_Standard, STD_Grayscale)->Palette); } //========================================================================== diff --git a/src/gamedata/textures/formats/shadertexture.cpp b/src/gamedata/textures/formats/shadertexture.cpp index a9d3fd109..5ce85cfc7 100644 --- a/src/gamedata/textures/formats/shadertexture.cpp +++ b/src/gamedata/textures/formats/shadertexture.cpp @@ -122,7 +122,7 @@ public: int CopyPixels(FBitmap *bmp, int conversion) override { - bmp->CopyPixelData(0, 0, Pixels, Width, Height, Height, 1, 0, palMgr.GetTranslation(TRANSLATION_Standard, STD_Gray)->Palette); + bmp->CopyPixelData(0, 0, Pixels, Width, Height, Height, 1, 0, GPalette.GetTranslation(TRANSLATION_Standard, STD_Gray)->Palette); return 0; } diff --git a/src/gamedata/textures/imagehelpers.h b/src/gamedata/textures/imagehelpers.h index 967876508..a26f0d735 100644 --- a/src/gamedata/textures/imagehelpers.h +++ b/src/gamedata/textures/imagehelpers.h @@ -55,7 +55,7 @@ namespace ImageHelpers { if (wantluminance) { - return palMgr.GetTranslation(TRANSLATION_Standard, srcisgrayscale ? STD_Gray : STD_Grayscale)->Remap; + return GPalette.GetTranslation(TRANSLATION_Standard, srcisgrayscale ? STD_Gray : STD_Grayscale)->Remap; } else { diff --git a/src/gamedata/textures/texture.cpp b/src/gamedata/textures/texture.cpp index 1f37223b9..0a2012e9d 100644 --- a/src/gamedata/textures/texture.cpp +++ b/src/gamedata/textures/texture.cpp @@ -701,7 +701,7 @@ FTextureBuffer FTexture::CreateTexBuffer(int translation, int flags) buffer = new unsigned char[W*(H + 1) * 4]; memset(buffer, 0, W * (H + 1) * 4); - auto remap = translation <= 0 ? nullptr : palMgr.TranslationToTable(translation); + auto remap = translation <= 0 ? nullptr : GPalette.TranslationToTable(translation); FBitmap bmp(buffer, W * 4, W, H); int trans; diff --git a/src/p_setup.cpp b/src/p_setup.cpp index 05f31ea23..ccc37a267 100644 --- a/src/p_setup.cpp +++ b/src/p_setup.cpp @@ -406,7 +406,7 @@ void P_SetupLevel(FLevelLocals *Level, int position, bool newGame) { Level->Players[i]->mo = nullptr; } - palMgr.ClearTranslationSlot(TRANSLATION_LevelScripted); + GPalette.ClearTranslationSlot(TRANSLATION_LevelScripted); // Initial height of PointOfView will be set by player think. diff --git a/src/playsim/p_acs.cpp b/src/playsim/p_acs.cpp index 9e598fc92..771fa7fbe 100644 --- a/src/playsim/p_acs.cpp +++ b/src/playsim/p_acs.cpp @@ -9590,7 +9590,7 @@ scriptwait: case PCD_ENDTRANSLATION: if (translation != NULL) { - palMgr.UpdateTranslation(TRANSLATION(TRANSLATION_LevelScripted, transi), translation); + GPalette.UpdateTranslation(TRANSLATION(TRANSLATION_LevelScripted, transi), translation); delete translation; translation = NULL; } diff --git a/src/r_data/colormaps.cpp b/src/r_data/colormaps.cpp index ece9245fa..cc2666b30 100644 --- a/src/r_data/colormaps.cpp +++ b/src/r_data/colormaps.cpp @@ -62,9 +62,6 @@ CUSTOM_CVAR(Color, cl_custominvulmapcolor2, 0xa6a67a, CVAR_ARCHIVE|CVAR_NOINITCA TArray 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); - } - } } //========================================================================== diff --git a/src/r_data/colormaps.h b/src/r_data/colormaps.h index 4d7bbd5f4..e825bfaac 100644 --- a/src/r_data/colormaps.h +++ b/src/r_data/colormaps.h @@ -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. diff --git a/src/r_data/r_translate.cpp b/src/r_data/r_translate.cpp index 21ea1130f..8c6d6e7b0 100644 --- a/src/r_data/r_translate.cpp +++ b/src/r_data/r_translate.cpp @@ -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); } diff --git a/src/r_data/v_palette.cpp b/src/r_data/v_palette.cpp index 27c9f25af..54606899c 100644 --- a/src/r_data/v_palette.cpp +++ b/src/r_data/v_palette.cpp @@ -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(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(768, lump.GetSize())); - return 256; - } -} - //========================================================================== // // BuildTransTable diff --git a/src/r_data/v_palette.h b/src/r_data/v_palette.h index f4e6512ff..07b1f477a 100644 --- a/src/r_data/v_palette.h +++ b/src/r_data/v_palette.h @@ -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) diff --git a/src/rendering/hwrenderer/textures/hw_precache.cpp b/src/rendering/hwrenderer/textures/hw_precache.cpp index ee474fe28..73a0d571b 100644 --- a/src/rendering/hwrenderer/textures/hw_precache.cpp +++ b/src/rendering/hwrenderer/textures/hw_precache.cpp @@ -110,7 +110,7 @@ void hw_PrecacheTexture(uint8_t *texhitlist, TMap &actorhitl while (it.NextPair(pair)) { PClassActor *cls = pair->Key; - auto remap = palMgr.TranslationToTable(GetDefaultByType(cls)->Translation); + auto remap = GPalette.TranslationToTable(GetDefaultByType(cls)->Translation); int gltrans = remap == nullptr ? 0 : remap->Index; for (unsigned i = 0; i < cls->GetStateCount(); i++) diff --git a/src/rendering/hwrenderer/textures/hw_texcontainer.h b/src/rendering/hwrenderer/textures/hw_texcontainer.h index 11cc48172..1eaa57a51 100644 --- a/src/rendering/hwrenderer/textures/hw_texcontainer.h +++ b/src/rendering/hwrenderer/textures/hw_texcontainer.h @@ -44,7 +44,7 @@ private: TranslatedTexture * GetTexID(int translation, bool expanded) { - auto remap = palMgr.TranslationToTable(translation); + auto remap = GPalette.TranslationToTable(translation); translation = remap == nullptr ? 0 : remap->Index; if (translation == 0) diff --git a/src/rendering/swrenderer/viewport/r_spritedrawer.cpp b/src/rendering/swrenderer/viewport/r_spritedrawer.cpp index efa445df9..25710c1f3 100644 --- a/src/rendering/swrenderer/viewport/r_spritedrawer.cpp +++ b/src/rendering/swrenderer/viewport/r_spritedrawer.cpp @@ -474,7 +474,7 @@ namespace swrenderer SetTranslationMap(nullptr); if (translation != 0) { - FRemapTable *table = palMgr.TranslationToTable(translation); + FRemapTable *table = GPalette.TranslationToTable(translation); if (table != NULL && !table->Inactive) { if (viewport->RenderTarget->IsBgra()) diff --git a/src/rendering/v_framebuffer.cpp b/src/rendering/v_framebuffer.cpp index ec693b3af..31b88c067 100644 --- a/src/rendering/v_framebuffer.cpp +++ b/src/rendering/v_framebuffer.cpp @@ -132,7 +132,7 @@ void V_DrawPaletteTester(int paletteno) PalEntry pe; if (t > 1) { - auto palette = palMgr.GetTranslation(TRANSLATION_Standard, t - 2)->Palette; + auto palette = GPalette.GetTranslation(TRANSLATION_Standard, t - 2)->Palette; pe = palette[k]; } else GPalette.BaseColors[k]; diff --git a/src/scripting/thingdef_properties.cpp b/src/scripting/thingdef_properties.cpp index d6988516d..e1f693f18 100644 --- a/src/scripting/thingdef_properties.cpp +++ b/src/scripting/thingdef_properties.cpp @@ -756,7 +756,7 @@ DEFINE_PROPERTY(translation, L, Actor) } } } - defaults->Translation = palMgr.StoreTranslation (TRANSLATION_Decorate, &CurrentTranslation); + defaults->Translation = GPalette.StoreTranslation (TRANSLATION_Decorate, &CurrentTranslation); } } diff --git a/src/win32/i_dijoy.cpp b/src/win32/i_dijoy.cpp index 4374cfca5..0d471ab18 100644 --- a/src/win32/i_dijoy.cpp +++ b/src/win32/i_dijoy.cpp @@ -50,6 +50,8 @@ #include "cmdlib.h" #include "v_text.h" #include "m_argv.h" +#include "keydef.h" +#include "printf.h" #define SAFE_RELEASE(x) { if (x != NULL) { x->Release(); x = NULL; } }