From 6e13f5b154c090581f1be154f746a5e12637038a Mon Sep 17 00:00:00 2001 From: Kelly Rauchenberger Date: Sun, 31 Jan 2021 08:29:25 -0500 Subject: Entire sprite sheet is composited now (weird palette stuff tho) --- tools/sprite_dumper/main.cpp | 60 +++++++++++++++++++++++++++++++++++--------- 1 file changed, 48 insertions(+), 12 deletions(-) (limited to 'tools') diff --git a/tools/sprite_dumper/main.cpp b/tools/sprite_dumper/main.cpp index e84a2d7..4183e43 100644 --- a/tools/sprite_dumper/main.cpp +++ b/tools/sprite_dumper/main.cpp @@ -170,13 +170,21 @@ private: static constexpr int HEIGHTS[3][4] = { { 8, 16, 32, 64 }, { 8, 8, 16, 32 }, { 16, 32, 32, 64 } }; }; +struct FrameOutput { + Magick::Image image; + int width; + int height; + int centerX; + int centerY; +}; + struct Sprite { std::vector subsprites; - Magick::Image render(Rom& m3, const Palette& palette, const int gfxPtr) const { - Magick::Image result; + FrameOutput render(Rom& m3, const Palette& palette, const int gfxPtr) const { + FrameOutput output; - if (subsprites.empty()) return result; + if (subsprites.empty()) return output; int minX = subsprites[0].x; int minY = subsprites[0].y; @@ -197,10 +205,14 @@ struct Sprite { int centerX = -minX; int centerY = -minY; - result = Magick::Image(Magick::Geometry(width, height), "transparent"); - result.modifyImage(); + output.width = width; + output.height = height; + output.centerX = centerX; + output.centerY = centerY; + output.image = Magick::Image(Magick::Geometry(width, height), "transparent"); + output.image.modifyImage(); - Magick::Pixels view(result); + Magick::Pixels view(output.image); for (const Subsprite& o : subsprites) { int tilePointer = o.tile << 5; @@ -235,10 +247,10 @@ struct Sprite { int actualTx = o.flipH ? (7-tx) : tx; if (tileData[actualTx][actualTy] != 0) { - auto& c = palette.Colors().at(tileData[actualTx][actualTy]); - std::cout << c.redQuantum() << "," << c.greenQuantum() << "," << c.blueQuantum() << std::endl; + //auto& c = palette.Colors().at(tileData[actualTx][actualTy]); + //std::cout << c.redQuantum() << "," << c.greenQuantum() << "," << c.blueQuantum() << std::endl; *pixels = palette.Colors().at(tileData[actualTx][actualTy]); - std::cout << tileData[actualTx][actualTy] << std::endl; + //std::cout << tileData[actualTx][actualTy] << std::endl; } pixels++; } @@ -249,7 +261,7 @@ struct Sprite { } } - return result; + return output; } }; @@ -258,13 +270,37 @@ struct SpriteSheet { std::vector sprites; Magick::Image render(Rom& m3, PaletteSet& palettes) const { - + int maxWidth = 0; + int maxHeight = 0; + std::vector frames; for (int i=0; i maxWidth) maxWidth = f.width; + if (f.height > maxHeight) maxHeight = f.height; + frames.push_back(std::move(f)); + } + + const int FRAMES_PER_ROW = 10; + int sheetWidth; + int sheetHeight; + if (frames.size() < FRAMES_PER_ROW) { + sheetWidth = frames.size() * maxWidth; + sheetHeight = maxHeight; + } else { + sheetWidth = FRAMES_PER_ROW * maxWidth; + sheetHeight = (frames.size() / FRAMES_PER_ROW + 1) * maxHeight; + } + + Magick::Image sheet(Magick::Geometry(sheetWidth, sheetHeight), "transparent"); + for (int i=0; i