Skip to content

Commit

Permalink
Add reverse_1bit RGBGFX test (gbdev#1555)
Browse files Browse the repository at this point in the history
Fixes a bug to always use 2bpp `_data` in `TileData`
  • Loading branch information
Rangi42 authored Nov 25, 2024
1 parent cb546f0 commit e0ee9dc
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 4 deletions.
16 changes: 12 additions & 4 deletions src/gfx/process.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -712,6 +712,9 @@ static void hashBitplanes(uint16_t bitplanes, uint16_t &hash) {
}

class TileData {
// Importantly, `TileData` is **always** 2bpp.
// If the active bit depth is 1bpp, all tiles are processed as 2bpp nonetheless, but emitted as 1bpp.
// This massively simplifies internal processing, since bit depth is always identical outside of I/O / serialization boundaries.
std::array<uint8_t, 16> _data;
// The hash is a bit lax: it's the XOR of all lines, and every other nibble is identical
// if horizontal mirroring is in effect. It should still be a reasonable tie-breaker in
Expand Down Expand Up @@ -755,9 +758,7 @@ class TileData {
hashBitplanes(bitplanes, _hash);

_data[writeIndex++] = bitplanes & 0xFF;
if (options.bitDepth == 2) {
_data[writeIndex++] = bitplanes >> 8;
}
_data[writeIndex++] = bitplanes >> 8;
}
}

Expand Down Expand Up @@ -1032,7 +1033,14 @@ static void outputTileData(UniqueTiles const &tiles) {
TileData const *tile = *iter;
assume(tile->tileID == tileID);
++tileID;
output->sputn(reinterpret_cast<char const *>(tile->data().data()), options.bitDepth * 8);
if (options.bitDepth == 2) {
output->sputn(reinterpret_cast<char const *>(tile->data().data()), 16);
} else {
assume(options.bitDepth == 1);
for (size_t y = 0; y < 8; ++y) {
output->sputc(tile->data()[y * 2]);
}
}
}
}

Expand Down
1 change: 1 addition & 0 deletions test/gfx/reverse_1bit.1bpp
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
 @L������F@ 
Binary file added test/gfx/reverse_1bit.attrmap
Binary file not shown.
3 changes: 3 additions & 0 deletions test/gfx/reverse_1bit.flags
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
-m
-t reverse_1bit.tilemap
-a reverse_1bit.attrmap
Binary file added test/gfx/reverse_1bit.tilemap
Binary file not shown.

0 comments on commit e0ee9dc

Please sign in to comment.