mirror of
https://github.com/ZDoom/gzdoom.git
synced 2025-03-13 22:42:07 +00:00
- moved some data needed by the texture system into palettecontainer.cpp.
This commit is contained in:
parent
be24023722
commit
1ed170d955
16 changed files with 77 additions and 93 deletions
|
@ -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
|
|||
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -37,7 +37,6 @@
|
|||
|
||||
#include "files.h"
|
||||
#include "filesystem.h"
|
||||
#include "textures/textures.h"
|
||||
#include "imagehelpers.h"
|
||||
#include "image.h"
|
||||
|
||||
|
|
|
@ -201,6 +201,6 @@ TArray<uint8_t> 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);
|
||||
}
|
||||
|
||||
|
|
|
@ -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())
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -259,7 +259,7 @@ TArray<uint8_t> 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);
|
||||
}
|
||||
|
||||
//==========================================================================
|
||||
|
|
|
@ -366,8 +366,8 @@ TArray<uint8_t> 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;
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -40,26 +40,22 @@
|
|||
#include <stdint.h>
|
||||
#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;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//==========================================================================
|
||||
//
|
||||
//
|
||||
|
|
|
@ -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, "");
|
||||
|
|
|
@ -418,8 +418,6 @@ protected:
|
|||
|
||||
virtual void ResolvePatches() {}
|
||||
|
||||
static void InitGrayMap();
|
||||
|
||||
void SetScale(const DVector2 &scale)
|
||||
{
|
||||
Scale = scale;
|
||||
|
|
|
@ -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);
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in a new issue