From dbd33e6f52a4fb07d1e1852ee6d089dd2d4abdd1 Mon Sep 17 00:00:00 2001 From: staphen Date: Mon, 16 Sep 2024 07:36:10 -0400 Subject: [PATCH] Update optimized transparency lookup when cycling colors --- Source/engine/palette.cpp | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/Source/engine/palette.cpp b/Source/engine/palette.cpp index bdcca1e04..b6875cec7 100644 --- a/Source/engine/palette.cpp +++ b/Source/engine/palette.cpp @@ -114,6 +114,20 @@ void GenerateBlendedLookupTable(std::array &palette, int skipFro #endif } +#if DEVILUTIONX_PALETTE_TRANSPARENCY_BLACK_16_LUT +void UpdateTransparencyLookupBlack16(int from, int to) +{ + for (int i = from; i <= to; i++) { + for (int j = 0; j < 256; j++) { + const std::uint16_t index = i | (j << 8); + const std::uint16_t reverseIndex = j | (i << 8); + paletteTransparencyLookupBlack16[index] = paletteTransparencyLookup[0][i] | (paletteTransparencyLookup[0][j] << 8); + paletteTransparencyLookupBlack16[reverseIndex] = paletteTransparencyLookup[0][j] | (paletteTransparencyLookup[0][i] << 8); + } + } +} +#endif + /** * @brief Cycle the given range of colors in the palette * @param from First color index of the range @@ -128,6 +142,10 @@ void CycleColors(int from, int to) } std::rotate(&paletteTransparencyLookup[from][0], &paletteTransparencyLookup[from + 1][0], &paletteTransparencyLookup[to + 1][0]); + +#if DEVILUTIONX_PALETTE_TRANSPARENCY_BLACK_16_LUT + UpdateTransparencyLookupBlack16(from, to); +#endif } /** @@ -144,6 +162,10 @@ void CycleColorsReverse(int from, int to) } std::rotate(&paletteTransparencyLookup[from][0], &paletteTransparencyLookup[to][0], &paletteTransparencyLookup[to + 1][0]); + +#if DEVILUTIONX_PALETTE_TRANSPARENCY_BLACK_16_LUT + UpdateTransparencyLookupBlack16(from, to); +#endif } } // namespace @@ -426,6 +448,10 @@ void palette_update_quest_palette(int n) Uint8 best = FindBestMatchForColor(logical_palette, blendedColor, 1, 31); paletteTransparencyLookup[i][j] = paletteTransparencyLookup[j][i] = best; } + +#if DEVILUTIONX_PALETTE_TRANSPARENCY_BLACK_16_LUT + UpdateTransparencyLookupBlack16(i, i); +#endif } } // namespace devilution