Support 8BPP images for 4BPP tilemaps

This commit is contained in:
GriffinR 2023-01-25 19:48:07 -05:00
parent 70980f5e42
commit 56ba0a8f77
3 changed files with 8 additions and 2 deletions

View file

@ -10,6 +10,7 @@ The **"Breaking Changes"** listed below are changes that have been made in the d
### Fixed
- Fix events being hidden behind connecting maps.
- Fix some minor visual issues on the Connections tab.
- 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));