mirror of
https://github.com/ZDoom/raze-gles.git
synced 2024-12-28 20:40:47 +00:00
- use a global constant for the transparent palette index instead of hardcoding it to the 255 literal everywhere.
- added the needed glue to allow palettecontainer.cpp to compile.
This commit is contained in:
parent
ac07af7028
commit
4d1d90d712
9 changed files with 140 additions and 8 deletions
|
@ -756,7 +756,7 @@ set (PCH_SOURCES
|
||||||
common/filesystem/file_directory.cpp
|
common/filesystem/file_directory.cpp
|
||||||
common/filesystem/resourcefile.cpp
|
common/filesystem/resourcefile.cpp
|
||||||
common/engine/sc_man.cpp
|
common/engine/sc_man.cpp
|
||||||
#common/engine/palettecontainer.cpp // not yet operational.
|
common/engine/palettecontainer.cpp
|
||||||
common/engine/stringtable.cpp
|
common/engine/stringtable.cpp
|
||||||
|
|
||||||
core/utility/stats.cpp
|
core/utility/stats.cpp
|
||||||
|
|
|
@ -637,7 +637,7 @@ static int32_t loadvox(const char *filnam)
|
||||||
fil.Read(tbuf, voxsiz.z);
|
fil.Read(tbuf, voxsiz.z);
|
||||||
|
|
||||||
for (bssize_t z=voxsiz.z-1; z>=0; z--)
|
for (bssize_t z=voxsiz.z-1; z>=0; z--)
|
||||||
if (tbuf[z] != 255)
|
if (tbuf[z] != TRANSPARENT_INDEX)
|
||||||
{
|
{
|
||||||
const int32_t i = j+z;
|
const int32_t i = j+z;
|
||||||
vbit[i>>5] |= (1<<SHIFTMOD32(i));
|
vbit[i>>5] |= (1<<SHIFTMOD32(i));
|
||||||
|
@ -652,7 +652,7 @@ static int32_t loadvox(const char *filnam)
|
||||||
|
|
||||||
for (bssize_t z=0; z<voxsiz.z; z++)
|
for (bssize_t z=0; z<voxsiz.z; z++)
|
||||||
{
|
{
|
||||||
if (tbuf[z] == 255)
|
if (tbuf[z] == TRANSPARENT_INDEX)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (!x || !y || !z || x == voxsiz.x-1 || y == voxsiz.y-1 || z == voxsiz.z-1)
|
if (!x || !y || !z || x == voxsiz.x-1 || y == voxsiz.y-1 || z == voxsiz.z-1)
|
||||||
|
|
|
@ -40,6 +40,8 @@
|
||||||
#include "templates.h"
|
#include "templates.h"
|
||||||
#include "palettecontainer.h"
|
#include "palettecontainer.h"
|
||||||
|
|
||||||
|
PaletteContainer GPalette;
|
||||||
|
FColorMatcher ColorMatcher;
|
||||||
|
|
||||||
//----------------------------------------------------------------------------
|
//----------------------------------------------------------------------------
|
||||||
//
|
//
|
||||||
|
@ -58,6 +60,22 @@ void PaletteContainer::Init(int numslots) // This cannot be a constructor!!!
|
||||||
TranslationTables.Resize(numslots);
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
//----------------------------------------------------------------------------
|
//----------------------------------------------------------------------------
|
||||||
//
|
//
|
||||||
//
|
//
|
||||||
|
@ -166,7 +184,7 @@ int PaletteContainer::StoreTranslation(int slot, FRemapTable *remap)
|
||||||
auto size = NumTranslations(slot);
|
auto size = NumTranslations(slot);
|
||||||
for (i = 0; i < size; i++)
|
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
|
// A duplicate of this translation already exists
|
||||||
return TRANSLATION(slot, i);
|
return TRANSLATION(slot, i);
|
||||||
|
@ -215,6 +233,21 @@ static bool IndexOutOfRange(const int start1, const int end1, const int start2,
|
||||||
//
|
//
|
||||||
//----------------------------------------------------------------------------
|
//----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
bool FRemapTable::operator==(const FRemapTable& o)
|
||||||
|
{
|
||||||
|
// Two translations are identical when they have the same amount of colors
|
||||||
|
// and the palette values for both are identical.
|
||||||
|
if (&o == this) return true;
|
||||||
|
if (o.NumEntries != NumEntries) return false;
|
||||||
|
return !memcmp(o.Palette, Palette, NumEntries * sizeof(*Palette));
|
||||||
|
}
|
||||||
|
|
||||||
|
//----------------------------------------------------------------------------
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//----------------------------------------------------------------------------
|
||||||
|
|
||||||
void FRemapTable::MakeIdentity()
|
void FRemapTable::MakeIdentity()
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
|
|
@ -67,11 +67,19 @@ inline int GetTranslationIndex(uint32_t trans)
|
||||||
|
|
||||||
class PaletteContainer
|
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;
|
FMemArena remapArena;
|
||||||
TArray<FRemapTable*> uniqueRemaps;
|
TArray<FRemapTable*> uniqueRemaps;
|
||||||
TArray<TAutoGrowArray<FRemapTablePtr, FRemapTable*>> TranslationTables;
|
TArray<TAutoGrowArray<FRemapTablePtr, FRemapTable*>> TranslationTables;
|
||||||
public:
|
public:
|
||||||
void Init(int numslots); // This cannot be a constructor!!!
|
void Init(int numslots); // This cannot be a constructor!!!
|
||||||
|
void SetPalette(const uint8_t* colors);
|
||||||
void Clear();
|
void Clear();
|
||||||
FRemapTable* AddRemap(FRemapTable* remap);
|
FRemapTable* AddRemap(FRemapTable* remap);
|
||||||
void UpdateTranslation(int trans, FRemapTable* remap);
|
void UpdateTranslation(int trans, FRemapTable* remap);
|
||||||
|
@ -102,5 +110,5 @@ public:
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
extern PaletteContainer palMgr;
|
extern PaletteContainer GPalette;
|
||||||
|
|
||||||
|
|
|
@ -40,6 +40,7 @@
|
||||||
#include "filesystem.h"
|
#include "filesystem.h"
|
||||||
#include "printf.h"
|
#include "printf.h"
|
||||||
#include "templates.h"
|
#include "templates.h"
|
||||||
|
#include "m_png.h"
|
||||||
|
|
||||||
/****************************/
|
/****************************/
|
||||||
/* Palette management stuff */
|
/* Palette management stuff */
|
||||||
|
@ -703,6 +704,7 @@ int V_GetColor(const uint32_t* palette, FScanner& sc)
|
||||||
|
|
||||||
|
|
||||||
TArray<FSpecialColormap> SpecialColormaps;
|
TArray<FSpecialColormap> SpecialColormaps;
|
||||||
|
uint8_t DesaturateColormap[31][256];
|
||||||
|
|
||||||
// These default tables are needed for texture composition.
|
// These default tables are needed for texture composition.
|
||||||
static FSpecialColormapParameters SpecialColormapParms[] =
|
static FSpecialColormapParameters SpecialColormapParms[] =
|
||||||
|
@ -820,5 +822,91 @@ void InitSpecialColormaps(PalEntry *pe)
|
||||||
SpecialColormapParms[i].Start[2], SpecialColormapParms[i].End[0],
|
SpecialColormapParms[i].Start[2], SpecialColormapParms[i].End[0],
|
||||||
SpecialColormapParms[i].End[1], SpecialColormapParms[i].End[2]);
|
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<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", 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<size_t>(768, lump.GetSize()));
|
||||||
|
return 256;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -55,7 +55,9 @@ struct FSpecialColormap
|
||||||
};
|
};
|
||||||
|
|
||||||
extern TArray<FSpecialColormap> SpecialColormaps;
|
extern TArray<FSpecialColormap> SpecialColormaps;
|
||||||
|
extern uint8_t DesaturateColormap[31][256];
|
||||||
|
|
||||||
int AddSpecialColormap(PalEntry *pe, float r1, float g1, float b1, float r2, float g2, float b2);
|
int AddSpecialColormap(PalEntry *pe, float r1, float g1, float b1, float r2, float g2, float b2);
|
||||||
void InitSpecialColormaps(PalEntry* pe);
|
void InitSpecialColormaps(PalEntry* pe);
|
||||||
void UpdateSpecialColormap(PalEntry* BaseColors, unsigned int index, float r1, float g1, float b1, float r2, float g2, float b2);
|
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);
|
||||||
|
|
|
@ -148,7 +148,7 @@ int FArtTexture::CopyPixels(FBitmap *bmp, int conversion)
|
||||||
for (int y = 0; y < numpixels; ++y)
|
for (int y = 0; y < numpixels; ++y)
|
||||||
{
|
{
|
||||||
int index = source[y];
|
int index = source[y];
|
||||||
if (index == 255)
|
if (index == TRANSPARENT_INDEX)
|
||||||
{
|
{
|
||||||
hasalpha = true;
|
hasalpha = true;
|
||||||
continue;
|
continue;
|
||||||
|
|
|
@ -41,6 +41,7 @@
|
||||||
#include "image.h"
|
#include "image.h"
|
||||||
#include "palette.h"
|
#include "palette.h"
|
||||||
#include "../glbackend/gl_hwtexture.h"
|
#include "../glbackend/gl_hwtexture.h"
|
||||||
|
#include "build.h"
|
||||||
|
|
||||||
FTexture *CreateBrightmapTexture(FImageSource*);
|
FTexture *CreateBrightmapTexture(FImageSource*);
|
||||||
|
|
||||||
|
@ -207,7 +208,7 @@ void FTexture::CheckTrans(unsigned char * buffer, int size, int trans)
|
||||||
#define SOME_MASK 0x00ffffff
|
#define SOME_MASK 0x00ffffff
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define CHKPIX(ofs) (l1[(ofs)*4+MSB]==255 ? (( ((uint32_t*)l1)[0] = ((uint32_t*)l1)[ofs]&SOME_MASK), trans=true ) : false)
|
#define CHKPIX(ofs) (l1[(ofs)*4+MSB]==TRANSPARENT_INDEX ? (( ((uint32_t*)l1)[0] = ((uint32_t*)l1)[ofs]&SOME_MASK), trans=true ) : false)
|
||||||
|
|
||||||
int FTexture::SmoothEdges(unsigned char * buffer, int w, int h)
|
int FTexture::SmoothEdges(unsigned char * buffer, int w, int h)
|
||||||
{
|
{
|
||||||
|
|
|
@ -1871,7 +1871,7 @@ void sub_54FA4(int a1, int a2)
|
||||||
{
|
{
|
||||||
for (j = 0; j < dword_AA3AC; j++)
|
for (j = 0; j < dword_AA3AC; j++)
|
||||||
{
|
{
|
||||||
if (*ptr1 != 255)
|
if (*ptr1 != TRANSPARENT_INDEX)
|
||||||
{
|
{
|
||||||
*ptr1 = ptr2[i*bytesperline+dword_AA3B0+j];
|
*ptr1 = ptr2[i*bytesperline+dword_AA3B0+j];
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue