mirror of
https://github.com/ZDoom/gzdoom.git
synced 2024-11-22 20:21:26 +00:00
- fix colormap remapping when colormap entries may have fullbright entries which should not be considered duplicates
- this should address the "fullbright teeth" issue with the imps in KDiKDiZD: https://forum.zdoom.org/viewtopic.php?t=76790
This commit is contained in:
parent
ef456a4901
commit
b082ad9cef
2 changed files with 69 additions and 17 deletions
|
@ -424,7 +424,24 @@ void MakeGoodRemap(uint32_t* BaseColors, uint8_t* Remap)
|
|||
PalEntry color0 = BaseColors[0];
|
||||
int i;
|
||||
|
||||
// we have to load the colormap ourselves, because at this stage the colormaps have not yet been loaded
|
||||
int lump = fileSystem.CheckNumForFullName ("COLORMAP", true, ns_colormaps);
|
||||
if (lump == -1)
|
||||
lump = fileSystem.CheckNumForName ("COLORMAP", ns_global);
|
||||
|
||||
FileReader readlump;
|
||||
TArray<uint8_t> maincolormap(8192);
|
||||
uint8_t *lastcolormap = maincolormap.Data() + 7936;
|
||||
|
||||
if (lump != -1)
|
||||
{
|
||||
readlump = fileSystem.OpenFileReader (lump);
|
||||
readlump.Read (maincolormap.Data(), 8192);
|
||||
}
|
||||
|
||||
// First try for an exact match of color 0. Only Hexen does not have one.
|
||||
if ((lump == -1) || !lastcolormap)
|
||||
{
|
||||
for (i = 1; i < 256; ++i)
|
||||
{
|
||||
if (BaseColors[i] == color0)
|
||||
|
@ -433,6 +450,18 @@ void MakeGoodRemap(uint32_t* BaseColors, uint8_t* Remap)
|
|||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for (i = 1; i < 256; ++i)
|
||||
{
|
||||
if ((BaseColors[i] == color0) && (lastcolormap[i] == lastcolormap[0]))
|
||||
{
|
||||
Remap[0] = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// If there is no duplicate of color 0, find the first set of duplicate
|
||||
// colors and make one of them a duplicate of color 0. In Hexen's PLAYPAL
|
||||
|
@ -448,6 +477,8 @@ void MakeGoodRemap(uint32_t* BaseColors, uint8_t* Remap)
|
|||
sortcopy[i] = (BaseColors[i] & 0xffffff) | (i << 24);
|
||||
}
|
||||
qsort(sortcopy, 256, 4, sortforremap);
|
||||
if ((lump == -1) || !lastcolormap)
|
||||
{
|
||||
for (i = 255; i > 0; --i)
|
||||
{
|
||||
if ((sortcopy[i] & 0xFFFFFF) == (sortcopy[i - 1] & 0xFFFFFF))
|
||||
|
@ -466,6 +497,27 @@ void MakeGoodRemap(uint32_t* BaseColors, uint8_t* Remap)
|
|||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for (i = 255; i > 0; --i)
|
||||
{
|
||||
if (((sortcopy[i] & 0xFFFFFF) == (sortcopy[i - 1] & 0xFFFFFF)) && (lastcolormap[sortcopy[i].a] == lastcolormap[sortcopy[i - 1].a]))
|
||||
{
|
||||
int new0 = sortcopy[i].a;
|
||||
int dup = sortcopy[i - 1].a;
|
||||
if (new0 > dup)
|
||||
{
|
||||
// Make the lower-numbered entry a copy of color 0. (Just because.)
|
||||
std::swap(new0, dup);
|
||||
}
|
||||
Remap[0] = new0;
|
||||
Remap[new0] = dup;
|
||||
BaseColors[new0] = color0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// If there were no duplicates, InitPalette() will remap color 0 to the
|
||||
// closest matching color. Hopefully nobody will use a palette where all
|
||||
|
|
|
@ -353,7 +353,7 @@ void SetDefaultColormap (const char *name)
|
|||
// [RH] If using BUILD's palette, generate the colormap
|
||||
if (lump == -1 || fileSystem.CheckNumForFullName("palette.dat") >= 0 || fileSystem.CheckNumForFullName("blood.pal") >= 0)
|
||||
{
|
||||
Printf ("Make colormap\n");
|
||||
DPrintf (DMSG_NOTIFY, "Make colormap\n");
|
||||
FDynamicColormap foo;
|
||||
|
||||
foo.Color = 0xFFFFFF;
|
||||
|
|
Loading…
Reference in a new issue