summary refs log tree commit diff stats
path: root/tools
diff options
context:
space:
mode:
authorKelly Rauchenberger <fefferburbia@gmail.com>2021-01-31 11:43:53 -0500
committerKelly Rauchenberger <fefferburbia@gmail.com>2021-01-31 11:43:53 -0500
commitf648c6776e0a1c5e1e3f6fcf9c81fefcb67a0c3e (patch)
tree9ade8b7da4a4165b6c898a8d18f88bf4a5d6b485 /tools
parent3720e9bcdd15a30058bc5f8a2913a924760796a0 (diff)
downloadtanetane-f648c6776e0a1c5e1e3f6fcf9c81fefcb67a0c3e.tar.gz
tanetane-f648c6776e0a1c5e1e3f6fcf9c81fefcb67a0c3e.tar.bz2
tanetane-f648c6776e0a1c5e1e3f6fcf9c81fefcb67a0c3e.zip
Sprite dumper combines arbitrary sheets now
Diffstat (limited to 'tools')
-rw-r--r--tools/sprite_dumper/main.cpp109
1 files changed, 68 insertions, 41 deletions
diff --git a/tools/sprite_dumper/main.cpp b/tools/sprite_dumper/main.cpp index c8dd956..2ba37c8 100644 --- a/tools/sprite_dumper/main.cpp +++ b/tools/sprite_dumper/main.cpp
@@ -7,6 +7,7 @@
7#include <vector> 7#include <vector>
8#include <iostream> 8#include <iostream>
9#include <Magick++.h> 9#include <Magick++.h>
10#include <sstream>
10 11
11class Rom { 12class Rom {
12public: 13public:
@@ -270,46 +271,12 @@ struct SpriteSheet {
270 int gfxPtr; 271 int gfxPtr;
271 std::vector<Sprite> sprites; 272 std::vector<Sprite> sprites;
272 273
273 Magick::Image render(Rom& m3, PaletteSet& palettes) const { 274 void render(Rom& m3, PaletteSet& palettes, std::vector<FrameOutput>& frames) const {
274 int maxWidth = 0;
275 int maxHeight = 0;
276 std::vector<FrameOutput> frames;
277
278 const Palette& palette = palettes.GetPalette(spriteindex); 275 const Palette& palette = palettes.GetPalette(spriteindex);
279 for (int i=0; i<sprites.size(); i++) { 276 for (int i=0; i<sprites.size(); i++) {
280 FrameOutput f = sprites[i].render(m3, palette, gfxPtr); 277 FrameOutput f = sprites[i].render(m3, palette, gfxPtr);
281
282 if (f.width > maxWidth) maxWidth = f.width;
283 if (f.height > maxHeight) maxHeight = f.height;
284 frames.push_back(std::move(f)); 278 frames.push_back(std::move(f));
285 } 279 }
286
287 const int FRAMES_PER_ROW = 10;
288 int sheetWidth;
289 int sheetHeight;
290
291 std::ofstream datafile("out.txt");
292 datafile << maxWidth << "," << maxHeight << " cell size" << std::endl;
293 datafile << FRAMES_PER_ROW << " frames per row" << std::endl;
294 datafile << frames.size() << " frames" << std::endl;
295 datafile << std::endl;
296
297 if (frames.size() < FRAMES_PER_ROW) {
298 sheetWidth = frames.size() * maxWidth;
299 sheetHeight = maxHeight;
300 } else {
301 sheetWidth = FRAMES_PER_ROW * maxWidth;
302 sheetHeight = (frames.size() / FRAMES_PER_ROW + 1) * maxHeight;
303 }
304
305 Magick::Image sheet(Magick::Geometry(sheetWidth, sheetHeight), "transparent");
306 for (int i=0; i<frames.size(); i++) {
307 const FrameOutput& f = frames.at(i);
308 sheet.composite(f.image, (i%FRAMES_PER_ROW)*maxWidth, (i/FRAMES_PER_ROW)*maxHeight, Magick::OverCompositeOp);
309 datafile << f.width << "," << f.height << "," << f.centerX << "," << f.centerY << std::endl;
310 }
311
312 return sheet;
313 } 280 }
314}; 281};
315 282
@@ -388,8 +355,10 @@ private:
388}; 355};
389 356
390int main(int argc, char** argv) { 357int main(int argc, char** argv) {
391 if (argc != 2) { 358 if (argc < 3) {
392 std::cout << "Usage" << std::endl; 359 std::cout << "Usage: ./sprite_dumper [path to rom] {sheet IDs}" << std::endl;
360 std::cout << "sheet IDs should be space separated references to the sheets to concatenate" << std::endl;
361 std::cout << "the format of the ID is BankNum.SheetNum" << std::endl;
393 return -1; 362 return -1;
394 } 363 }
395 364
@@ -397,14 +366,72 @@ int main(int argc, char** argv) {
397 366
398 Rom m3(argv[1]); 367 Rom m3(argv[1]);
399 PaletteSet palettes(m3); 368 PaletteSet palettes(m3);
400 //const int banks[] = {0x1A442A4, 0x1AE0638, 0x1AEE4C4, 0x1AF1ED0};
401 Bank b1(m3, 0x1A442A4, 0x14383E4); 369 Bank b1(m3, 0x1A442A4, 0x14383E4);
402 Bank b2(m3, 0x1AE0638, 0x194BC30); 370 Bank b2(m3, 0x1AE0638, 0x194BC30);
403 Bank b3(m3, 0x1AEE4C4, 0x1A012B8); 371 Bank b3(m3, 0x1AEE4C4, 0x1A012B8);
404 Bank b4(m3, 0x1AF1ED0, 0x1A36AA0); 372 Bank b4(m3, 0x1AF1ED0, 0x1A36AA0);
405 Magick::Image im = b2.SpriteSheets().at(3).render(m3, palettes); 373
406 im.magick("png"); 374 std::vector<FrameOutput> frames;
407 im.write("out.png"); 375
376 for (int i=2; i<argc; i++) {
377 std::stringstream argfmt;
378 argfmt << argv[i];
379
380 int bankNum;
381 char ch;
382 int sheetNum;
383 argfmt >> bankNum;
384 argfmt >> ch; //.
385 argfmt >> sheetNum;
386
387 const Bank& bankToRead = [&](){
388 switch (bankNum) {
389 case 0: return b1;
390 case 1: return b2;
391 case 2: return b3;
392 case 3: return b4;
393 default: throw std::invalid_argument("Invalid bank num: " + std::to_string(bankNum));
394 }
395 }();
396
397 bankToRead.SpriteSheets().at(sheetNum).render(m3, palettes, frames);
398 }
399
400 int maxWidth = 0;
401 int maxHeight = 0;
402 for (const FrameOutput& f : frames) {
403 if (f.width > maxWidth) maxWidth = f.width;
404 if (f.height > maxHeight) maxHeight = f.height;
405 }
406
407 const int FRAMES_PER_ROW = 10;
408 int sheetWidth;
409 int sheetHeight;
410
411 std::ofstream datafile("out.txt");
412 datafile << maxWidth << "," << maxHeight << " cell size" << std::endl;
413 datafile << FRAMES_PER_ROW << " frames per row" << std::endl;
414 datafile << frames.size() << " frames" << std::endl;
415 datafile << std::endl;
416
417 if (frames.size() < FRAMES_PER_ROW) {
418 sheetWidth = frames.size() * maxWidth;
419 sheetHeight = maxHeight;
420 } else {
421 sheetWidth = FRAMES_PER_ROW * maxWidth;
422 sheetHeight = (frames.size() / FRAMES_PER_ROW + 1) * maxHeight;
423 }
424
425 Magick::Image sheet(Magick::Geometry(sheetWidth, sheetHeight), "transparent");
426 for (int i=0; i<frames.size(); i++) {
427 const FrameOutput& f = frames.at(i);
428 sheet.composite(f.image, (i%FRAMES_PER_ROW)*maxWidth, (i/FRAMES_PER_ROW)*maxHeight, Magick::OverCompositeOp);
429 datafile << f.width << "," << f.height << "," << f.centerX << "," << f.centerY << std::endl;
430 }
431
432 //Magick::Image im = b2.SpriteSheets().at(3).render(m3, palettes);
433 sheet.magick("png");
434 sheet.write("out.png");
408 435
409 return 0; 436 return 0;
410} \ No newline at end of file 437} \ No newline at end of file