- 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:
Rachael Alexanderson 2022-11-16 15:06:33 -05:00 committed by Christoph Oelckers
parent ef456a4901
commit b082ad9cef
2 changed files with 69 additions and 17 deletions

View file

@ -424,13 +424,42 @@ void MakeGoodRemap(uint32_t* BaseColors, uint8_t* Remap)
PalEntry color0 = BaseColors[0];
int i;
// First try for an exact match of color 0. Only Hexen does not have one.
for (i = 1; i < 256; ++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)
{
if (BaseColors[i] == color0)
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)
{
Remap[0] = i;
break;
if (BaseColors[i] == color0)
{
Remap[0] = i;
break;
}
}
}
else
{
for (i = 1; i < 256; ++i)
{
if ((BaseColors[i] == color0) && (lastcolormap[i] == lastcolormap[0]))
{
Remap[0] = i;
break;
}
}
}
@ -448,21 +477,44 @@ void MakeGoodRemap(uint32_t* BaseColors, uint8_t* Remap)
sortcopy[i] = (BaseColors[i] & 0xffffff) | (i << 24);
}
qsort(sortcopy, 256, 4, sortforremap);
for (i = 255; i > 0; --i)
if ((lump == -1) || !lastcolormap)
{
if ((sortcopy[i] & 0xFFFFFF) == (sortcopy[i - 1] & 0xFFFFFF))
for (i = 255; i > 0; --i)
{
int new0 = sortcopy[i].a;
int dup = sortcopy[i - 1].a;
if (new0 > dup)
if ((sortcopy[i] & 0xFFFFFF) == (sortcopy[i - 1] & 0xFFFFFF))
{
// Make the lower-numbered entry a copy of color 0. (Just because.)
std::swap(new0, dup);
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;
}
}
}
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;
}
Remap[0] = new0;
Remap[new0] = dup;
BaseColors[new0] = color0;
break;
}
}
}

View file

@ -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;