Merge pull request #511 from GriffinRichards/fix-tilemap

Support 8BPP images for 4BPP tilemaps
This commit is contained in:
GriffinR 2023-02-05 15:07:07 -05:00 committed by GitHub
commit 63734aec7c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 8 additions and 2 deletions

View file

@ -14,6 +14,7 @@ The **"Breaking Changes"** listed below are changes that have been made in the d
- Fix bug which caused encounter configurator to crash if slots in fields containing groups were deleted.
- Fix bug which caused encounter configurator to crash if last field was deleted.
- Fix map render when collision view was active while map changed.
- Fix the updated pokefirered region map graphics appearing in grayscale.
## [5.1.0] - 2023-01-22
### Added

View file

@ -126,6 +126,12 @@ public:
TilemapTileSelector(QString tilesetFilepath, TilemapFormat format, QString palFilepath): SelectablePixmapItem(8, 8, 1, 1) {
this->tileset = QImage(tilesetFilepath);
this->format = format;
if (this->tileset.format() == QImage::Format::Format_Indexed8 && this->format == TilemapFormat::BPP_4) {
// Squash pixel data to fit 4BPP. Allows project repo to use 8BPP images for 4BPP tilemaps
uchar * pixel = this->tileset.bits();
for (int i = 0; i < this->tileset.sizeInBytes(); i++, pixel++)
*pixel %= 16;
}
bool err;
if (!palFilepath.isEmpty()) {
this->palette = PaletteUtil::parse(palFilepath, &err);

View file

@ -51,8 +51,7 @@ QImage TilemapTileSelector::setPalette(int paletteIndex) {
{
QVector<QRgb> newColorTable;
int palMinLength = paletteIndex * 16 + 16;
if ((this->palette.count() < palMinLength) || (tilesetImage.colorTable().count() != 16)) {
// either a) the palette has less than 256 colors, or b) the image is improperly indexed
if (this->palette.count() < palMinLength) {
for (QRgb color : tilesetImage.colorTable()) {
int gray = qGray(color);
newColorTable.append(qRgb(gray, gray, gray));