Fix reversing multiple palettes with fewer than 4 colors per palette

Fixes #2073
This commit is contained in:
Rangi
2026-09-12 11:50:47 -04:00
parent 438b943a1a
commit 439a7a1828
6 changed files with 12 additions and 6 deletions
+7 -6
View File
@@ -217,16 +217,17 @@ void reverse() {
palettes.clear();
std::array<uint8_t, sizeof(uint16_t) * 4> buf; // max 4 colors
assume(buf.size() >= sizeof(uint16_t) * options.nbColorsPerPal);
size_t const palSize = sizeof(uint16_t) * options.nbColorsPerPal;
assume(buf.size() >= palSize);
for (;;) {
if (size_t nbRead = file->sgetn(reinterpret_cast<char *>(buf.data()), buf.size());
if (size_t nbRead = file->sgetn(reinterpret_cast<char *>(buf.data()), palSize);
nbRead == 0) {
break;
} else if (nbRead != sizeof(uint16_t) * options.nbColorsPerPal) {
} else if (nbRead != palSize) {
fatal(
"Palette data size (%zu) is not a multiple of %zu bytes\n",
palettes.size() * buf.size() + nbRead,
buf.size()
"Palette data size (%zu) is not a multiple of %zu bytes",
palettes.size() * palSize + nbRead,
palSize
);
}
// Expand the colors
Binary file not shown.
Binary file not shown.
+5
View File
@@ -0,0 +1,5 @@
-s 2
-u
-t reverse_multi_palette.tilemap
-a reverse_multi_palette.attrmap
-p reverse_multi_palette.pal
Binary file not shown.
Binary file not shown.