diff --git a/src/common/engine/palettecontainer.cpp b/src/common/engine/palettecontainer.cpp index 8d36af246..1f8732db9 100644 --- a/src/common/engine/palettecontainer.cpp +++ b/src/common/engine/palettecontainer.cpp @@ -43,6 +43,7 @@ PaletteContainer GPalette; FColorMatcher ColorMatcher; +extern uint8_t IcePalette[16][3]; //---------------------------------------------------------------------------- // @@ -90,6 +91,58 @@ void PaletteContainer::SetPalette(const uint8_t* colors, int transparent_index) // translucency map. WhiteIndex = BestColor((uint32_t*)RawColors, 255, 255, 255, 0, 255); BlackIndex = BestColor((uint32_t*)RawColors, 0, 0, 0, 0, 255); + + // The alphatexture translation. This is just a standard index as gray mapping and has no association with the palette. + auto remap = &GrayRamp; + remap->Remap[0] = 0; + remap->Palette[0] = 0; + for (int i = 1; i < 256; i++) + { + remap->Remap[i] = i; + remap->Palette[i] = PalEntry(255, i, i, i); + } + + // Palette to grayscale ramp. For internal use only, because the remap does not map to the palette. + remap = &GrayscaleMap; + remap->Remap[0] = 0; + remap->Palette[0] = 0; + for (int i = 1; i < 256; i++) + { + int r = GPalette.BaseColors[i].r; + int g = GPalette.BaseColors[i].g; + int b = GPalette.BaseColors[i].b; + int v = (r * 77 + g * 143 + b * 37) >> 8; + + remap->Remap[i] = v; + remap->Palette[i] = PalEntry(255, v, v, v); + } + + for (int i = 0; i < 256; ++i) + { + GrayMap[i] = ColorMatcher.Pick(i, i, i); + } + + // Create the ice translation table, based on Hexen's. Alas, the standard + // Doom palette has no good substitutes for these bluish-tinted grays, so + // they will just look gray unless you use a different PLAYPAL with Doom. + + uint8_t IcePaletteRemap[16]; + for (int i = 0; i < 16; ++i) + { + IcePaletteRemap[i] = ColorMatcher.Pick(IcePalette[i][0], IcePalette[i][1], IcePalette[i][2]); + } + remap = &IceMap; + remap->Remap[0] = 0; + remap->Palette[0] = 0; + for (int i = 1; i < 256; ++i) + { + int r = GPalette.BaseColors[i].r; + int g = GPalette.BaseColors[i].g; + int b = GPalette.BaseColors[i].b; + int v = (r * 77 + g * 143 + b * 37) >> 12; + remap->Remap[i] = IcePaletteRemap[v]; + remap->Palette[i] = PalEntry(255, IcePalette[v][0], IcePalette[v][1], IcePalette[v][2]); + } } @@ -276,8 +329,6 @@ void PaletteContainer::GenerateGlobalBrightmapFromColormap(const uint8_t *cmapda } } - - //---------------------------------------------------------------------------- // // @@ -768,3 +819,4 @@ bool FRemapTable::AddColors(int start, int count, const uint8_t*colors, int tran } + diff --git a/src/common/engine/palettecontainer.h b/src/common/engine/palettecontainer.h index 0abc00e26..90871863f 100644 --- a/src/common/engine/palettecontainer.h +++ b/src/common/engine/palettecontainer.h @@ -79,6 +79,10 @@ public: bool HasGlobalBrightmap; FRemapTable GlobalBrightmap; + FRemapTable GrayRamp; + FRemapTable GrayscaleMap; + FRemapTable IceMap; // This is used by the texture compositor so it must be globally accessible. + uint8_t GrayMap[256]; private: FMemArena remapArena; diff --git a/src/gamedata/textures/formats/automaptexture.cpp b/src/gamedata/textures/formats/automaptexture.cpp index f9a4b3112..4135f4908 100644 --- a/src/gamedata/textures/formats/automaptexture.cpp +++ b/src/gamedata/textures/formats/automaptexture.cpp @@ -37,7 +37,6 @@ #include "files.h" #include "filesystem.h" -#include "textures/textures.h" #include "imagehelpers.h" #include "image.h" diff --git a/src/gamedata/textures/formats/imgztexture.cpp b/src/gamedata/textures/formats/imgztexture.cpp index f55fd3b7f..5c2e041ac 100644 --- a/src/gamedata/textures/formats/imgztexture.cpp +++ b/src/gamedata/textures/formats/imgztexture.cpp @@ -201,6 +201,6 @@ TArray FIMGZTexture::CreatePalettedPixels(int conversion) int FIMGZTexture::CopyPixels(FBitmap *bmp, int conversion) { if (!isalpha) return FImageSource::CopyPixels(bmp, conversion); - else return CopyTranslatedPixels(bmp, GPalette.GetTranslation(TRANSLATION_Standard, STD_Grayscale)->Palette); + else return CopyTranslatedPixels(bmp, GPalette.GrayscaleMap.Palette); } diff --git a/src/gamedata/textures/formats/multipatchtexture.cpp b/src/gamedata/textures/formats/multipatchtexture.cpp index d6f0d2abc..86c9f8d77 100644 --- a/src/gamedata/textures/formats/multipatchtexture.cpp +++ b/src/gamedata/textures/formats/multipatchtexture.cpp @@ -78,7 +78,7 @@ static uint8_t *GetBlendMap(PalEntry blend, uint8_t *blendwork) switch (blend.a==0 ? int(blend) : -1) { case BLEND_ICEMAP: - return GPalette.TranslationToTable(TRANSLATION(TRANSLATION_Standard, 7))->Remap; + return GPalette.IceMap.Remap; default: if (blend >= BLEND_SPECIALCOLORMAP1 && blend < BLEND_SPECIALCOLORMAP1 + SpecialColormaps.Size()) diff --git a/src/gamedata/textures/formats/multipatchtexture.h b/src/gamedata/textures/formats/multipatchtexture.h index 4aef0c14d..d5c3be0ef 100644 --- a/src/gamedata/textures/formats/multipatchtexture.h +++ b/src/gamedata/textures/formats/multipatchtexture.h @@ -1,8 +1,10 @@ #pragma once #include "sc_man.h" #include "palettecontainer.h" -#include "textures.h" +#include "textureid.h" +#include "vectors.h" +class FImageTexture; //========================================================================== // // TexPart is the data that will get passed to the final texture. diff --git a/src/gamedata/textures/formats/patchtexture.cpp b/src/gamedata/textures/formats/patchtexture.cpp index e46bb82fd..960994b5c 100644 --- a/src/gamedata/textures/formats/patchtexture.cpp +++ b/src/gamedata/textures/formats/patchtexture.cpp @@ -259,7 +259,7 @@ TArray FPatchTexture::CreatePalettedPixels(int conversion) int FPatchTexture::CopyPixels(FBitmap *bmp, int conversion) { if (!isalpha) return FImageSource::CopyPixels(bmp, conversion); - else return CopyTranslatedPixels(bmp, GPalette.GetTranslation(TRANSLATION_Standard, STD_Grayscale)->Palette); + else return CopyTranslatedPixels(bmp, GPalette.GrayscaleMap.Palette); } //========================================================================== diff --git a/src/gamedata/textures/formats/pcxtexture.cpp b/src/gamedata/textures/formats/pcxtexture.cpp index b5ad0133b..a995ec672 100644 --- a/src/gamedata/textures/formats/pcxtexture.cpp +++ b/src/gamedata/textures/formats/pcxtexture.cpp @@ -366,8 +366,8 @@ TArray FPCXTexture::CreatePalettedPixels(int conversion) { default: case 1: - PaletteMap[0] = alphatex? 0 : ImageHelpers::GrayMap[0]; - PaletteMap[1] = alphatex? 255 : ImageHelpers::GrayMap[255]; + PaletteMap[0] = alphatex? 0 : GPalette.GrayMap[0]; + PaletteMap[1] = alphatex? 255 : GPalette.GrayMap[255]; ReadPCX1bit (Pixels.Data(), lump, &header); break; diff --git a/src/gamedata/textures/formats/pngtexture.cpp b/src/gamedata/textures/formats/pngtexture.cpp index 909a62ec8..c6f7f0cf4 100644 --- a/src/gamedata/textures/formats/pngtexture.cpp +++ b/src/gamedata/textures/formats/pngtexture.cpp @@ -248,12 +248,12 @@ FPNGTexture::FPNGTexture (FileReader &lump, int lumpnum, int width, int height, bMasked = true; PaletteSize = 256; PaletteMap = (uint8_t*)ImageArena.Alloc(PaletteSize); - memcpy (PaletteMap, ImageHelpers::GrayMap, 256); + memcpy (PaletteMap, GPalette.GrayMap, 256); PaletteMap[NonPaletteTrans[0]] = 0; } else { - PaletteMap = ImageHelpers::GrayMap; + PaletteMap = GPalette.GrayMap; } break; diff --git a/src/gamedata/textures/formats/shadertexture.cpp b/src/gamedata/textures/formats/shadertexture.cpp index 683500040..9a8f2842e 100644 --- a/src/gamedata/textures/formats/shadertexture.cpp +++ b/src/gamedata/textures/formats/shadertexture.cpp @@ -112,7 +112,7 @@ public: // even if it makes little sense. for (int i = 0; i < 512; i++) { - Pix[i] = ImageHelpers::GrayMap[Pixels[i]]; + Pix[i] = GPalette.GrayMap[Pixels[i]]; } } return Pix; @@ -120,7 +120,7 @@ public: int CopyPixels(FBitmap *bmp, int conversion) override { - bmp->CopyPixelData(0, 0, Pixels, Width, Height, Height, 1, 0, GPalette.GetTranslation(TRANSLATION_Standard, STD_Gray)->Palette); + bmp->CopyPixelData(0, 0, Pixels, Width, Height, Height, 1, 0, GPalette.GrayRamp.Palette); return 0; } diff --git a/src/gamedata/textures/imagehelpers.h b/src/gamedata/textures/imagehelpers.h index a26f0d735..feb5bfcac 100644 --- a/src/gamedata/textures/imagehelpers.h +++ b/src/gamedata/textures/imagehelpers.h @@ -40,26 +40,22 @@ #include #include "tarray.h" #include "colormatcher.h" -#include "v_palette.h" +#include "bitmap.h" +#include "palettecontainer.h" #include "v_colortables.h" -#include "textures/bitmap.h" -#include "r_data/renderstyle.h" -#include "r_data/r_translate.h" namespace ImageHelpers { - extern uint8_t GrayMap[256]; - // Helpers for creating paletted images. inline uint8_t *GetRemap(bool wantluminance, bool srcisgrayscale = false) { if (wantluminance) { - return GPalette.GetTranslation(TRANSLATION_Standard, srcisgrayscale ? STD_Gray : STD_Grayscale)->Remap; + return srcisgrayscale ? GPalette.GrayRamp.Remap : GPalette.GrayscaleMap.Remap; } else { - return srcisgrayscale ? GrayMap : GPalette.Remap; + return srcisgrayscale ? GPalette.GrayMap : GPalette.Remap; } } diff --git a/src/gamedata/textures/texture.cpp b/src/gamedata/textures/texture.cpp index c1923ccff..241dad9b7 100644 --- a/src/gamedata/textures/texture.cpp +++ b/src/gamedata/textures/texture.cpp @@ -64,23 +64,6 @@ CUSTOM_CVAR(Int, r_spriteadjust, 2, CVAR_ARCHIVE | CVAR_GLOBALCONFIG) TexMan.SpriteAdjustChanged(); } -//========================================================================== -// -// -// -//========================================================================== - -uint8_t ImageHelpers::GrayMap[256]; - -void FTexture::InitGrayMap() -{ - for (int i = 0; i < 256; ++i) - { - ImageHelpers::GrayMap[i] = ColorMatcher.Pick(i, i, i); - } -} - - //========================================================================== // // diff --git a/src/gamedata/textures/texturemanager.cpp b/src/gamedata/textures/texturemanager.cpp index 888bb1d5c..2febde077 100644 --- a/src/gamedata/textures/texturemanager.cpp +++ b/src/gamedata/textures/texturemanager.cpp @@ -1154,7 +1154,6 @@ void FTextureManager::Init() DeleteAll(); SpriteFrames.Clear(); //if (BuildTileFiles.Size() == 0) CountBuildTiles (); - FTexture::InitGrayMap(); // Texture 0 is a dummy texture used to indicate "no texture" auto nulltex = new FImageTexture(nullptr, ""); diff --git a/src/gamedata/textures/textures.h b/src/gamedata/textures/textures.h index f78391107..c99461955 100644 --- a/src/gamedata/textures/textures.h +++ b/src/gamedata/textures/textures.h @@ -418,8 +418,6 @@ protected: virtual void ResolvePatches() {} - static void InitGrayMap(); - void SetScale(const DVector2 &scale) { Scale = scale; diff --git a/src/r_data/r_translate.cpp b/src/r_data/r_translate.cpp index 945940c00..3ca546a85 100644 --- a/src/r_data/r_translate.cpp +++ b/src/r_data/r_translate.cpp @@ -202,7 +202,7 @@ void R_InitTranslationTables () // The three standard translations from Doom or Heretic (seven for Strife), // plus the generic ice translation. - FRemapTable stdremaps[10]; + FRemapTable stdremaps[8]; for (i = 0; i < 8; ++i) { stdremaps[i].MakeIdentity(); @@ -302,53 +302,8 @@ void R_InitTranslationTables () } } - // Create the ice translation table, based on Hexen's. Alas, the standard - // Doom palette has no good substitutes for these bluish-tinted grays, so - // they will just look gray unless you use a different PLAYPAL with Doom. - - uint8_t IcePaletteRemap[16]; - for (i = 0; i < 16; ++i) - { - IcePaletteRemap[i] = ColorMatcher.Pick (IcePalette[i][0], IcePalette[i][1], IcePalette[i][2]); - } - FRemapTable *remap = &stdremaps[STD_Ice]; - remap->Remap[0] = 0; - remap->Palette[0] = 0; - for (i = 1; i < 256; ++i) - { - int r = GPalette.BaseColors[i].r; - int g = GPalette.BaseColors[i].g; - int b = GPalette.BaseColors[i].b; - int v = (r*77 + g*143 + b*37) >> 12; - remap->Remap[i] = IcePaletteRemap[v]; - remap->Palette[i] = PalEntry(255, IcePalette[v][0], IcePalette[v][1], IcePalette[v][2]); - } - - // The alphatexture translation. This is just a standard index as gray mapping. - remap = &stdremaps[STD_Gray]; - remap->Remap[0] = 0; - remap->Palette[0] = 0; - for (i = 1; i < 256; i++) - { - remap->Remap[i] = i; - remap->Palette[i] = PalEntry(255, i, i, i); - } - - // Palette to grayscale ramp. For internal use only, because the remap does not map to the palette. - remap = &stdremaps[STD_Grayscale]; - remap->Remap[0] = 0; - remap->Palette[0] = 0; - for (i = 1; i < 256; i++) - { - int r = GPalette.BaseColors[i].r; - int g = GPalette.BaseColors[i].g; - int b = GPalette.BaseColors[i].b; - int v = (r * 77 + g * 143 + b * 37) >> 8; - - remap->Remap[i] = v; - remap->Palette[i] = PalEntry(255, v, v, v); - } - GPalette.AddTranslation(TRANSLATION_Standard, stdremaps, 10); + stdremaps[7] = GPalette.IceMap; // this must also be inserted into the translation manager to be usable by sprites. + GPalette.AddTranslation(TRANSLATION_Standard, stdremaps, 8); } diff --git a/src/r_data/r_translate.h b/src/r_data/r_translate.h index 392041fe7..cca72b8de 100644 --- a/src/r_data/r_translate.h +++ b/src/r_data/r_translate.h @@ -29,8 +29,6 @@ enum enum EStandardTranslations { STD_Ice = 7, - STD_Gray = 8, // a 0-255 gray ramp - STD_Grayscale = 9, // desaturated version of the palette. }; #define MAX_ACS_TRANSLATIONS 65535 @@ -42,8 +40,6 @@ void R_InitTranslationTables (void); void R_BuildPlayerTranslation (int player); // [RH] Actually create a player's translation table. void R_GetPlayerTranslation (int color, const struct FPlayerColorSet *colorset, class FPlayerSkin *skin, struct FRemapTable *table); -extern const uint8_t IcePalette[16][3]; - int CreateBloodTranslation(PalEntry color); int R_FindCustomTranslation(FName name);