From 865d623846520b210c140d1c8e20157c47c06726 Mon Sep 17 00:00:00 2001 From: Rangi Date: Tue, 7 Apr 2020 18:06:10 -0400 Subject: [PATCH] Remove unused nonmatching files for electro_ball.png and sgb_border.bin electro_ball.png needed to preserve one whitespace tile which tools/gfx would normally remove. Preserving a list of tile indexes has been added as a general feature to tools/gfx. sgb_border.bin needed to remove the 20x18 center area of $00 bytes. This is achievable with the standard tr utility. --- .gitignore | 1 + Makefile | 6 +-- engine/gfx/color.asm | 4 +- gfx/mobile/electro_ball.png | Bin 692 -> 695 bytes gfx/mobile/electro_ball_nonmatching.png | Bin 1401 -> 0 bytes gfx/sgb/sgb_border.bin | Bin 1072 -> 1792 bytes gfx/sgb/sgb_border_nonmatching.bin | Bin 1792 -> 0 bytes tools/gfx.c | 52 ++++++++++++++++++++---- 8 files changed, 50 insertions(+), 13 deletions(-) delete mode 100644 gfx/mobile/electro_ball_nonmatching.png delete mode 100644 gfx/sgb/sgb_border_nonmatching.bin diff --git a/.gitignore b/.gitignore index c23b42e22..c9036fa4b 100644 --- a/.gitignore +++ b/.gitignore @@ -45,6 +45,7 @@ pokecrystal.txt *.1bpp *.lz *.animated.tilemap +*.sgb.tilemap gfx/pokemon/*/bitmask.asm gfx/pokemon/*/frames.asm !gfx/pokemon/unown/bitmask.asm diff --git a/Makefile b/Makefile index 8903a8c3e..4746d399e 100644 --- a/Makefile +++ b/Makefile @@ -51,7 +51,7 @@ crystal-au: pokecrystal-au.gbc clean: rm -f $(roms) $(crystal_obj) $(crystal11_obj) $(crystal_au_obj) $(roms:.gbc=.map) $(roms:.gbc=.sym) - find gfx \( -name "*.[12]bpp" -o -name "*.lz" -o -name "*.gbcpal" \) -delete + find gfx \( -name "*.[12]bpp" -o -name "*.lz" -o -name "*.gbcpal" -o -name "*.sgb.tilemap" \) -delete find gfx/pokemon -mindepth 1 ! -path "gfx/pokemon/unown/*" \( -name "bitmask.asm" -o -name "frames.asm" -o -name "front.animated.tilemap" -o -name "front.dimensions" \) -delete $(MAKE) clean -C tools/ @@ -226,12 +226,12 @@ gfx/battle/dude.2bpp: rgbgfx += -h gfx/font/unused_bold_font.1bpp: tools/gfx += --trim-whitespace gfx/sgb/sgb_border.2bpp: tools/gfx += --trim-whitespace +gfx/sgb/sgb_border.sgb.tilemap: gfx/sgb/sgb_border.bin ; tr < $< -d '\000' > $@ gfx/mobile/ascii_font.2bpp: tools/gfx += --trim-whitespace gfx/mobile/dialpad.2bpp: tools/gfx += --trim-whitespace gfx/mobile/dialpad_cursor.2bpp: tools/gfx += --trim-whitespace -gfx/mobile/electro_ball.2bpp: tools/gfx += --trim-whitespace -gfx/mobile/electro_ball_nonmatching.2bpp: tools/gfx += --remove-duplicates --remove-xflip +gfx/mobile/electro_ball.2bpp: tools/gfx += --remove-duplicates --remove-xflip --preserve=0x39 gfx/mobile/mobile_splash.2bpp: tools/gfx += --remove-duplicates --remove-xflip gfx/mobile/card.2bpp: tools/gfx += --trim-whitespace gfx/mobile/card_2.2bpp: tools/gfx += --trim-whitespace diff --git a/engine/gfx/color.asm b/engine/gfx/color.asm index aa29d413b..35ad66f7f 100644 --- a/engine/gfx/color.asm +++ b/engine/gfx/color.asm @@ -1191,8 +1191,8 @@ PredefPals: INCLUDE "gfx/sgb/predef.pal" SGBBorderMap: -; interleaved tile ids and palette ids -INCBIN "gfx/sgb/sgb_border.bin" +; interleaved tile ids and palette ids, without the center 20x18 screen area +INCBIN "gfx/sgb/sgb_border.sgb.tilemap" SGBBorderPalettes: ; assumed to come after SGBBorderMap diff --git a/gfx/mobile/electro_ball.png b/gfx/mobile/electro_ball.png index 3e1c0bb4689ee59ba8c8d8c928c31086c98114af..b6a9f11c3fedca0da721ce4acf13cec544385a8d 100644 GIT binary patch delta 671 zcmV;Q0$}~L1-Au|B!7NML_t(|+MSfYjuSBu#x13d#H&Q&0eFf{iim7Ug;G(VNHH&g zuAsPnPr9p4Cs@$r0U}X_6i64EfE1J+nq`$Z_AnlMcXR(Zfwf8;`?uqn?;A(aeFNL6 z3SWlYF_5>Ys$VfsuQ@6j8Xy8d7{l&T1BQQdP-Y7`0wsbeQ-2R!lvoh0H6atmc);Wf z%@HUqk3ZThdlX*{2383W_bbf0pXK6AV?KjV{1t4zmrzMHQkIfa;KaT)MbtZ0l zFR+6q)yWNDD}Rd>ZHovv97o`Xh?z$KCNklNCLu|9Cp@QJIi8@e0{q;%02J5ce9WA~ zffVJYNEK@yg)$n9&yaN-l_I9idDkoB&0?uZ%<^uQr<@6!#k!FOtj+R81iM4GEVS>3 zFAn4gw)?0JrCX%2%x)O%4(oS@w>Ct$)yU0&2q67sD1Uln)IjkVzC2Z0m#Gm3ZdPlPK?KHS5Q57oX3s=|Gp~A*1b~}9NXg8{HysabGJnG2dAt`WT`j=3 zp2W;D&UkP+NrT-GTaMG1cNL%EvW(9dz5L!>oCfH1Jh0EQjO^>-$w|045H6+%x?S~I zA~3M-kADXB&8mSzhX>J52Ee{bhR1*;c~G-C1DnlxM%#7LU)}+ps-8s1&j8*ggVT_t zToV!MFjq<w60Z`82jD536cKSrg;G(VNLgM2 zT|sfZPr6j66BsmkfJjs!1=5)&AO*!kW31d}cbFO5iN!gztfF{!=ePfzFGF1mPo}9p zjzSwqPpE0GIB3oS1KXUK@?Md z9yFyeLn@tS!=*-N!AX2v!*QX7YVoTN1An(rbXX(eSFHDV4%DhdheLaTg%Tq{#aZ0000X}T diff --git a/gfx/mobile/electro_ball_nonmatching.png b/gfx/mobile/electro_ball_nonmatching.png deleted file mode 100644 index 52441bd8349908eed0c50730d9c1174e82382d6d..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1401 zcmV-<1%~>GP)Px#1ZP1_K>z@;j|==^1pojABS}O-RCr$Pn*nYcI}Ajf-Z433a>&+$dJ2Ldr6Hwt z*U3J>SX(QSBWf)BJHKzg@7yl7^7Zv~dw+j_yn1bZJ+6m?rp-|1oE@6u%xfuW!wGUU zpP!$PXE~gs%>7?v+A{5DSj(!W!wsScIzwYo^Zw5N_w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!wBV@K|v$i5lMJ z$kW537{bz7)5s`0`o86lb-;_^_zo8zfohV)_Q)n#>5(_d4r7pIgOHI(H0c#hvZ*yw zlbo?PWSc==8E=%MTC($F@>yI4xft>ze<-`qxeRhK;CA~16Ccg_cF-yY00000NkvXX Hu0mjf1evoq diff --git a/gfx/sgb/sgb_border.bin b/gfx/sgb/sgb_border.bin index 362eae9298892c5b8dd0bf01aafc7720d7506bc7..5ad4fb0022c4d13ac84b5adf91ed192fef4fd578 100644 GIT binary patch literal 1792 zcmbW2=~lup5QSxFkAFcIaJHN0d-Zdt=iX4ZeVtl>kM(eR?COgHp%J@0iSy3z8vjtbrA z_s@0YHLyJB{7ZQ4#f;cKh;PGdPpVV<|9OQ=b!z#%!n5i;===s=d!hvG{y8aLqT$7} z#7i{1c$RpHh8NEg|IzRv|9Q6`HOE`fe+rl1;lg?5B_3UFu76$g883LnF3VQ6Gl>7} gxqQveApVm$M-??xUEY@7n14Hi(EBd$J41N<0C&!N1poj5 literal 1072 zcma)5*>1ux5EMt^9<((uKrg8rf!-|yXv=@h|9?xpNzK~Gm5^WJ@$M=+hk;2RV1OY; z7;(q}!E}{D15LEhVv~)irobEvnal;}EW$U2JzezBN1r`*X~QZM*kFq-H(W=!Mc6aJ z6f?{?<%DBbcY;%#;T#=YK>qpK-EVQ{ZXMj?*&$CH61y>a+zA1Obg;(X#<27HNAFZ!>kR6uMoF#;l zoEh5@-iGX|Zt(MKr>M#vuN_dS7tJw{U3C**UnA-b!PQ%;x!~#<)lzWvg6b-GO0N(5 zdE|Ld>grRm!=>}s6`tHqH-9dB!7JXdtG0}jr1~GE;>aYaPYUNiWid{L4PMN@Nz(4a JR7jH2=NHG@dj$Xh diff --git a/gfx/sgb/sgb_border_nonmatching.bin b/gfx/sgb/sgb_border_nonmatching.bin deleted file mode 100644 index 5ad4fb0022c4d13ac84b5adf91ed192fef4fd578..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1792 zcmbW2=~lup5QSxFkAFcIaJHN0d-Zdt=iX4ZeVtl>kM(eR?COgHp%J@0iSy3z8vjtbrA z_s@0YHLyJB{7ZQ4#f;cKh;PGdPpVV<|9OQ=b!z#%!n5i;===s=d!hvG{y8aLqT$7} z#7i{1c$RpHh8NEg|IzRv|9Q6`HOE`fe+rl1;lg?5B_3UFu76$g883LnF3VQ6Gl>7} gxqQveApVm$M-??xUEY@7n14Hi(EBd$J41N<0C&!N1poj5 diff --git a/tools/gfx.c b/tools/gfx.c index 7ef0d2d91..6dad2f1a8 100644 --- a/tools/gfx.c +++ b/tools/gfx.c @@ -8,7 +8,7 @@ #include "common.h" static void usage(void) { - fprintf(stderr, "Usage: gfx [--trim-whitespace] [--remove-whitespace] [--interleave] [--remove-duplicates [--keep-whitespace]] [--remove-xflip] [--remove-yflip] [--png filename] [-d depth] [-h] [-o outfile] infile\n"); + fprintf(stderr, "Usage: gfx [--trim-whitespace] [--remove-whitespace] [--interleave] [--remove-duplicates [--keep-whitespace]] [--remove-xflip] [--remove-yflip] [--preserve indexes] [--png filename] [-d depth] [-h] [-o outfile] infile\n"); } static void error(char *message) { @@ -27,6 +27,8 @@ struct Options { int keep_whitespace; int remove_xflip; int remove_yflip; + int *preserved; + int num_preserved; char *png_file; }; @@ -43,11 +45,13 @@ void get_args(int argc, char *argv[]) { {"keep-whitespace", no_argument, &Options.keep_whitespace, 1}, {"remove-xflip", no_argument, &Options.remove_xflip, 1}, {"remove-yflip", no_argument, &Options.remove_yflip, 1}, + {"preserve", required_argument, 0, 'r'}, {"png", required_argument, 0, 'p'}, {"depth", required_argument, 0, 'd'}, {"help", no_argument, 0, 'h'}, {0} }; + char *token; for (int opt = 0; opt != -1;) { switch (opt = getopt_long(argc, argv, "ho:d:p:", long_options)) { case 'h': @@ -59,6 +63,15 @@ void get_args(int argc, char *argv[]) { case 'd': Options.depth = strtoul(optarg, NULL, 0); break; + case 'r': + token = strtok(optarg, ","); + while (token) { + Options.num_preserved++; + Options.preserved = realloc(Options.preserved, Options.num_preserved * sizeof(int)); + Options.preserved[Options.num_preserved-1] = strtoul(optarg, NULL, 0); + token = strtok(NULL, ","); + } + break; case 'p': Options.png_file = optarg; break; @@ -73,6 +86,23 @@ void get_args(int argc, char *argv[]) { } } +bool is_preserved(int index) { + for (int i = 0; i < Options.num_preserved; i++) { + if (Options.preserved[i] == index) { + return true; + } + } + return false; +} + +void shift_preserved(int removed_index) { + for (int i = 0; i < Options.num_preserved; i++) { + if (Options.preserved[i] >= removed_index) { + Options.preserved[i]--; + } + } +} + struct Graphic { int size; uint8_t *data; @@ -91,7 +121,7 @@ bool is_whitespace(uint8_t *tile, int tile_size) { void trim_whitespace(struct Graphic *graphic) { int tile_size = Options.depth * 8; for (int i = graphic->size - tile_size; i > 0; i -= tile_size) { - if (is_whitespace(&graphic->data[i], tile_size)) { + if (is_whitespace(&graphic->data[i], tile_size) && !is_preserved(i / tile_size)) { graphic->size = i; } else { break; @@ -107,8 +137,10 @@ void remove_whitespace(struct Graphic *graphic) { graphic->size &= ~(tile_size - 1); int i = 0; - for (int j = 0; i < graphic->size && j < graphic->size; i += tile_size, j += tile_size) { - while (j < graphic->size && is_whitespace(&graphic->data[j], tile_size)) { + for (int j = 0, d = 0; i < graphic->size && j < graphic->size; i += tile_size, j += tile_size) { + while (j < graphic->size && is_whitespace(&graphic->data[j], tile_size) && !is_preserved(j / tile_size - d)) { + shift_preserved(j / tile_size); + d++; j += tile_size; } if (j >= graphic->size) { @@ -144,11 +176,13 @@ void remove_duplicates(struct Graphic *graphic) { // Make sure we have a whole number of tiles, round down if required graphic->size &= ~(tile_size - 1); - for (int i = 0, j = 0; i < graphic->size && j < graphic->size; i += tile_size, j += tile_size) { + for (int i = 0, j = 0, d = 0; i < graphic->size && j < graphic->size; i += tile_size, j += tile_size) { while (j < graphic->size && tile_exists(&graphic->data[j], graphic->data, tile_size, num_tiles)) { - if (Options.keep_whitespace && is_whitespace(&graphic->data[j], tile_size)) { + if ((Options.keep_whitespace && is_whitespace(&graphic->data[j], tile_size)) || is_preserved(j / tile_size - d)) { break; } + shift_preserved(j / tile_size); + d++; j += tile_size; } if (j >= graphic->size) { @@ -196,11 +230,13 @@ void remove_flip(struct Graphic *graphic, bool xflip, bool yflip) { // Make sure we have a whole number of tiles, round down if required graphic->size &= ~(tile_size - 1); - for (int i = 0, j = 0; i < graphic->size && j < graphic->size; i += tile_size, j += tile_size) { + for (int i = 0, j = 0, d = 0; i < graphic->size && j < graphic->size; i += tile_size, j += tile_size) { while (j < graphic->size && flip_exists(&graphic->data[j], graphic->data, tile_size, num_tiles, xflip, yflip)) { - if (Options.keep_whitespace && is_whitespace(&graphic->data[j], tile_size)) { + if ((Options.keep_whitespace && is_whitespace(&graphic->data[j], tile_size)) || is_preserved(j / tile_size - d)) { break; } + shift_preserved(j / tile_size); + d++; j += tile_size; } if (j >= graphic->size) {