diff options
| author | Kelly Rauchenberger <fefferburbia@gmail.com> | 2021-01-31 08:29:25 -0500 |
|---|---|---|
| committer | Kelly Rauchenberger <fefferburbia@gmail.com> | 2021-01-31 08:29:25 -0500 |
| commit | 6e13f5b154c090581f1be154f746a5e12637038a (patch) | |
| tree | 4b5bb066bb23edb6c93bf069f7a3d5abda3cffff | |
| parent | 39cc01d386bc765f43d00118599846fc7273eaaf (diff) | |
| download | tanetane-6e13f5b154c090581f1be154f746a5e12637038a.tar.gz tanetane-6e13f5b154c090581f1be154f746a5e12637038a.tar.bz2 tanetane-6e13f5b154c090581f1be154f746a5e12637038a.zip | |
Entire sprite sheet is composited now (weird palette stuff tho)
| -rw-r--r-- | tools/sprite_dumper/main.cpp | 60 |
1 files changed, 48 insertions, 12 deletions
| 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: | |||
| 170 | static constexpr int HEIGHTS[3][4] = { { 8, 16, 32, 64 }, { 8, 8, 16, 32 }, { 16, 32, 32, 64 } }; | 170 | static constexpr int HEIGHTS[3][4] = { { 8, 16, 32, 64 }, { 8, 8, 16, 32 }, { 16, 32, 32, 64 } }; |
| 171 | }; | 171 | }; |
| 172 | 172 | ||
| 173 | struct FrameOutput { | ||
| 174 | Magick::Image image; | ||
| 175 | int width; | ||
| 176 | int height; | ||
| 177 | int centerX; | ||
| 178 | int centerY; | ||
| 179 | }; | ||
| 180 | |||
| 173 | struct Sprite { | 181 | struct Sprite { |
| 174 | std::vector<Subsprite> subsprites; | 182 | std::vector<Subsprite> subsprites; |
| 175 | 183 | ||
| 176 | Magick::Image render(Rom& m3, const Palette& palette, const int gfxPtr) const { | 184 | FrameOutput render(Rom& m3, const Palette& palette, const int gfxPtr) const { |
| 177 | Magick::Image result; | 185 | FrameOutput output; |
| 178 | 186 | ||
| 179 | if (subsprites.empty()) return result; | 187 | if (subsprites.empty()) return output; |
| 180 | 188 | ||
| 181 | int minX = subsprites[0].x; | 189 | int minX = subsprites[0].x; |
| 182 | int minY = subsprites[0].y; | 190 | int minY = subsprites[0].y; |
| @@ -197,10 +205,14 @@ struct Sprite { | |||
| 197 | int centerX = -minX; | 205 | int centerX = -minX; |
| 198 | int centerY = -minY; | 206 | int centerY = -minY; |
| 199 | 207 | ||
| 200 | result = Magick::Image(Magick::Geometry(width, height), "transparent"); | 208 | output.width = width; |
| 201 | result.modifyImage(); | 209 | output.height = height; |
| 210 | output.centerX = centerX; | ||
| 211 | output.centerY = centerY; | ||
| 212 | output.image = Magick::Image(Magick::Geometry(width, height), "transparent"); | ||
| 213 | output.image.modifyImage(); | ||
| 202 | 214 | ||
| 203 | Magick::Pixels view(result); | 215 | Magick::Pixels view(output.image); |
| 204 | 216 | ||
| 205 | for (const Subsprite& o : subsprites) { | 217 | for (const Subsprite& o : subsprites) { |
| 206 | int tilePointer = o.tile << 5; | 218 | int tilePointer = o.tile << 5; |
| @@ -235,10 +247,10 @@ struct Sprite { | |||
| 235 | int actualTx = o.flipH ? (7-tx) : tx; | 247 | int actualTx = o.flipH ? (7-tx) : tx; |
| 236 | 248 | ||
| 237 | if (tileData[actualTx][actualTy] != 0) { | 249 | if (tileData[actualTx][actualTy] != 0) { |
| 238 | auto& c = palette.Colors().at(tileData[actualTx][actualTy]); | 250 | //auto& c = palette.Colors().at(tileData[actualTx][actualTy]); |
| 239 | std::cout << c.redQuantum() << "," << c.greenQuantum() << "," << c.blueQuantum() << std::endl; | 251 | //std::cout << c.redQuantum() << "," << c.greenQuantum() << "," << c.blueQuantum() << std::endl; |
| 240 | *pixels = palette.Colors().at(tileData[actualTx][actualTy]); | 252 | *pixels = palette.Colors().at(tileData[actualTx][actualTy]); |
| 241 | std::cout << tileData[actualTx][actualTy] << std::endl; | 253 | //std::cout << tileData[actualTx][actualTy] << std::endl; |
| 242 | } | 254 | } |
| 243 | pixels++; | 255 | pixels++; |
| 244 | } | 256 | } |
| @@ -249,7 +261,7 @@ struct Sprite { | |||
| 249 | } | 261 | } |
| 250 | } | 262 | } |
| 251 | 263 | ||
| 252 | return result; | 264 | return output; |
| 253 | } | 265 | } |
| 254 | }; | 266 | }; |
| 255 | 267 | ||
| @@ -258,13 +270,37 @@ struct SpriteSheet { | |||
| 258 | std::vector<Sprite> sprites; | 270 | std::vector<Sprite> sprites; |
| 259 | 271 | ||
| 260 | Magick::Image render(Rom& m3, PaletteSet& palettes) const { | 272 | Magick::Image render(Rom& m3, PaletteSet& palettes) const { |
| 261 | 273 | int maxWidth = 0; | |
| 274 | int maxHeight = 0; | ||
| 275 | std::vector<FrameOutput> frames; | ||
| 262 | 276 | ||
| 263 | for (int i=0; i<sprites.size(); i++) { | 277 | for (int i=0; i<sprites.size(); i++) { |
| 264 | const Palette& palette = palettes.GetPalette(i); | 278 | const Palette& palette = palettes.GetPalette(i); |
| 265 | return sprites[0].render(m3, palette, gfxPtr); | 279 | FrameOutput f = sprites[i].render(m3, palette, gfxPtr); |
| 280 | if (f.width > maxWidth) maxWidth = f.width; | ||
| 281 | if (f.height > maxHeight) maxHeight = f.height; | ||
| 282 | frames.push_back(std::move(f)); | ||
| 283 | } | ||
| 284 | |||
| 285 | const int FRAMES_PER_ROW = 10; | ||
| 286 | int sheetWidth; | ||
| 287 | int sheetHeight; | ||
| 266 | 288 | ||
| 289 | if (frames.size() < FRAMES_PER_ROW) { | ||
| 290 | sheetWidth = frames.size() * maxWidth; | ||
| 291 | sheetHeight = maxHeight; | ||
| 292 | } else { | ||
| 293 | sheetWidth = FRAMES_PER_ROW * maxWidth; | ||
| 294 | sheetHeight = (frames.size() / FRAMES_PER_ROW + 1) * maxHeight; | ||
| 295 | } | ||
| 296 | |||
| 297 | Magick::Image sheet(Magick::Geometry(sheetWidth, sheetHeight), "transparent"); | ||
| 298 | for (int i=0; i<frames.size(); i++) { | ||
| 299 | const FrameOutput& f = frames.at(i); | ||
| 300 | sheet.composite(f.image, (i%FRAMES_PER_ROW)*maxWidth, (i/FRAMES_PER_ROW)*maxHeight, Magick::OverCompositeOp); | ||
| 267 | } | 301 | } |
| 302 | |||
| 303 | return sheet; | ||
| 268 | } | 304 | } |
| 269 | }; | 305 | }; |
| 270 | 306 | ||
