Combine tile image export functions
This commit is contained in:
parent
81b6cfa537
commit
8f1e112858
2 changed files with 13 additions and 34 deletions
|
@ -61,6 +61,7 @@ private:
|
|||
QPoint getTileCoords(uint16_t);
|
||||
QList<QRgb> getCurPaletteTable();
|
||||
QList<Tile> buildSelectedTiles(int, int, QList<Tile>);
|
||||
QImage buildImage(int tileIdStart, int numTiles);
|
||||
|
||||
void drawUnused();
|
||||
|
||||
|
|
|
@ -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<double>(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<QRgb> 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();
|
||||
|
||||
return buildImage(Project::getNumTilesPrimary(), this->secondaryTileset->tiles.length());
|
||||
}
|
||||
|
||||
int secondaryLength = this->secondaryTileset->tiles.length();
|
||||
int height = qCeil(secondaryLength / static_cast<double>(this->numTilesWide));
|
||||
QImage TilesetEditorTileSelector::buildImage(int tileIdStart, int numTiles) {
|
||||
int height = qCeil(numTiles / static_cast<double>(this->numTilesWide));
|
||||
QImage image(this->numTilesWide * 8, height * 8, QImage::Format_RGBA8888);
|
||||
image.fill(0);
|
||||
|
||||
QPainter painter(&image);
|
||||
uint16_t primaryLength = static_cast<uint16_t>(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
|
||||
|
|
Loading…
Reference in a new issue