From cfe432ea656f28a6ca50cfcdadb7c9d26bbc263c Mon Sep 17 00:00:00 2001 From: ISSOtm Date: Sat, 26 Aug 2023 23:23:28 +0200 Subject: [PATCH] Enforce that transparent colours take slot #0 in all palettes --- src/gfx/main.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/gfx/main.cpp b/src/gfx/main.cpp index a993991c..37730527 100644 --- a/src/gfx/main.cpp +++ b/src/gfx/main.cpp @@ -33,6 +33,7 @@ #include "gfx/pal_spec.hpp" #include "gfx/process.hpp" #include "gfx/reverse.hpp" +#include "gfx/rgba.hpp" using namespace std::literals::string_view_literals; @@ -804,7 +805,9 @@ void Palette::addColor(uint16_t color) { * Returns the ID of the color in the palette, or `size()` if the color is not in */ uint8_t Palette::indexOf(uint16_t color) const { - return std::find(colors.begin(), colors.end(), color) - colors.begin(); + return color == Rgba::transparent + ? 0 + : std::find(begin(), colors.end(), color) - begin() + options.hasTransparentPixels; } auto Palette::begin() -> decltype(colors)::iterator {