Skip to content

Commit

Permalink
- fix colormap remapping when colormap entries may have fullbright en…
Browse files Browse the repository at this point in the history
…tries 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
  • Loading branch information
madame-rachelle authored and coelckers committed Nov 18, 2022
1 parent ef456a4 commit b082ad9
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 16 deletions.
82 changes: 67 additions & 15 deletions src/common/utility/palette.cpp
Expand Up @@ -424,13 +424,42 @@ 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.
for (i = 1; i < 256; ++i)
if ((lump == -1) || !lastcolormap)
{
if (BaseColors[i] == color0)
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;
}
}
}

Expand All @@ -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;
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/rendering/swrenderer/r_swcolormaps.cpp
Expand Up @@ -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;
Expand Down

0 comments on commit b082ad9

Please sign in to comment.