From 3cb3bc122b05fd5d968e1280eaf15e38da0893a5 Mon Sep 17 00:00:00 2001 From: Gary Talent Date: Sat, 1 Jun 2024 13:56:15 -0500 Subject: [PATCH] [nostalgia/core] Add valid and repair functions for PaletteV3 --- .../modules/core/include/nostalgia/core/palette.hpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/nostalgia/modules/core/include/nostalgia/core/palette.hpp b/src/nostalgia/modules/core/include/nostalgia/core/palette.hpp index 99149e65..04523c56 100644 --- a/src/nostalgia/modules/core/include/nostalgia/core/palette.hpp +++ b/src/nostalgia/modules/core/include/nostalgia/core/palette.hpp @@ -74,6 +74,18 @@ constexpr bool valid(Palette const&p) noexcept { }); } +[[nodiscard]] +constexpr bool repair(Palette &p) noexcept { + auto const colors = p.colorInfo.size(); + if (p.pages.size() == 0) { + p.pages.emplace_back(); + } + for (auto &page : p.pages) { + page.resize(colors); + } + return true; +} + [[nodiscard]] constexpr Color16 color(Palette const&pal, size_t page, size_t idx) noexcept { if (page < pal.pages.size() && idx < pal.pages[page].size()) [[likely]] {