Fix reversing a tilemapped image with -x trimmed tiles

This commit is contained in:
Rangi
2026-09-12 15:38:34 -04:00
parent a703b8c704
commit 520cc2a80d
8 changed files with 9 additions and 2 deletions
+4 -2
View File
@@ -353,7 +353,7 @@ void reverse() {
}
}
if (nbTilesInBank[0] + nbTilesInBank[1] > nbTiles) {
if (nbTilesInBank[0] + nbTilesInBank[1] > nbTiles + options.trim) {
fatal(
"The tilemap references %" PRIu16 " tiles in bank 0 and %" PRIu16
" in bank 1, but only %zu have been read in total",
@@ -390,7 +390,9 @@ void reverse() {
}
}
} else {
size_t const limit = std::min<size_t>(nbTiles, options.maxNbTiles[0]);
// Tiles trimmed with `-x` were never written to the tile data file, but are
// still referenced by the tilemap.
size_t const limit = std::min<size_t>(nbTiles + options.trim, options.maxNbTiles[0]);
for (size_t index = 0; index < mapSize; ++index) {
size_t tx = index % width, ty = index / width;
uint8_t tileID = (*tilemap)[index];
Binary file not shown.
+2
View File
@@ -0,0 +1,2 @@
-x 1
-t reverse_trimmed.tilemap
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,3 @@
-x 1
-t reverse_trimmed_attributes.tilemap
-a reverse_trimmed_attributes.attrmap
Binary file not shown.