diff --git a/include/ui/tileseteditortileselector.h b/include/ui/tileseteditortileselector.h index bfbc4946..7e34d52a 100644 --- a/include/ui/tileseteditortileselector.h +++ b/include/ui/tileseteditortileselector.h @@ -61,6 +61,7 @@ private: QPoint getTileCoords(uint16_t); QList getCurPaletteTable(); QList buildSelectedTiles(int, int, QList); + QImage buildImage(int tileIdStart, int numTiles); void drawUnused(); diff --git a/src/ui/tileseteditortileselector.cpp b/src/ui/tileseteditortileselector.cpp index 2bc80f75..7431e928 100644 --- a/src/ui/tileseteditortileselector.cpp +++ b/src/ui/tileseteditortileselector.cpp @@ -219,54 +219,32 @@ QPoint TilesetEditorTileSelector::getTileCoordsOnWidget(uint16_t tile) { } QImage TilesetEditorTileSelector::buildPrimaryTilesIndexedImage() { - if (!this->primaryTileset || !this->secondaryTileset) { + if (!this->primaryTileset) return QImage(); - } - int primaryLength = this->primaryTileset->tiles.length(); - int height = qCeil(primaryLength / static_cast(this->numTilesWide)); - QImage image(this->numTilesWide * 8, height * 8, QImage::Format_RGBA8888); - image.fill(0); - - QPainter painter(&image); - for (uint16_t tile = 0; tile < primaryLength; tile++) { - QImage tileImage = getGreyscaleTileImage(tile, this->primaryTileset, this->secondaryTileset); - int y = tile / this->numTilesWide; - int x = tile % this->numTilesWide; - QPoint origin = QPoint(x * 8, y * 8); - painter.drawImage(origin, tileImage); - } - - painter.end(); - - // Image is first converted using greyscale so that palettes with duplicate colors - // are properly represented in the final image. - QImage indexedImage = image.convertToFormat(QImage::Format::Format_Indexed8, greyscalePalette.toVector()); - QList palette = Tileset::getPalette(this->paletteId, this->primaryTileset, this->secondaryTileset, true); - indexedImage.setColorTable(palette.toVector()); - return indexedImage; + return buildImage(0, this->primaryTileset->tiles.length()); } QImage TilesetEditorTileSelector::buildSecondaryTilesIndexedImage() { - if (!this->primaryTileset || !this->secondaryTileset) { + if (!this->secondaryTileset) return QImage(); - } - int secondaryLength = this->secondaryTileset->tiles.length(); - int height = qCeil(secondaryLength / static_cast(this->numTilesWide)); + return buildImage(Project::getNumTilesPrimary(), this->secondaryTileset->tiles.length()); +} + +QImage TilesetEditorTileSelector::buildImage(int tileIdStart, int numTiles) { + int height = qCeil(numTiles / static_cast(this->numTilesWide)); QImage image(this->numTilesWide * 8, height * 8, QImage::Format_RGBA8888); image.fill(0); QPainter painter(&image); - uint16_t primaryLength = static_cast(Project::getNumTilesPrimary()); - for (uint16_t tile = 0; tile < secondaryLength; tile++) { - QImage tileImage = getGreyscaleTileImage(tile + primaryLength, this->primaryTileset, this->secondaryTileset); - int y = tile / this->numTilesWide; - int x = tile % this->numTilesWide; + for (int i = 0; i < numTiles; i++) { + QImage tileImage = getGreyscaleTileImage(tileIdStart + i, this->primaryTileset, this->secondaryTileset); + int y = i / this->numTilesWide; + int x = i % this->numTilesWide; QPoint origin = QPoint(x * 8, y * 8); painter.drawImage(origin, tileImage); } - painter.end(); // Image is first converted using greyscale so that palettes with duplicate colors