From 1f81d1851f5283eefa03e068a3925d2a960f67b4 Mon Sep 17 00:00:00 2001 From: yenatch Date: Fri, 23 Jun 2017 19:56:24 -0400 Subject: [PATCH] pngs in gfx/ --- Makefile | 5 + gfx/{pc.2bpp.lz => pc.2bpp.lz.2201c1aa} | Bin gfx/pc.png | Bin 0 -> 115 bytes gfx/pc_mail.2bpp | Bin 64 -> 0 bytes gfx/pc_mail.png | Bin 0 -> 114 bytes ...rink1.2bpp.lz => shrink1.2bpp.lz.d4443930} | Bin gfx/shrink1.png | Bin 0 -> 188 bytes ...rink2.2bpp.lz => shrink2.2bpp.lz.3f58480a} | Bin gfx/shrink2.png | Bin 0 -> 156 bytes ...ots_1.2bpp.lz => slots_1.2bpp.lz.b22ddc13} | Bin gfx/slots_1.png | Bin 0 -> 446 bytes ...ots_2.2bpp.lz => slots_2.2bpp.lz.b28f76e3} | Bin gfx/slots_2.png | Bin 0 -> 664 bytes ...ots_3.2bpp.lz => slots_3.2bpp.lz.70c2984c} | Bin gfx/slots_3.png | Bin 0 -> 1916 bytes tools/gfx.c | 113 +++++++++++++++++- 16 files changed, 114 insertions(+), 4 deletions(-) rename gfx/{pc.2bpp.lz => pc.2bpp.lz.2201c1aa} (100%) create mode 100644 gfx/pc.png delete mode 100644 gfx/pc_mail.2bpp create mode 100644 gfx/pc_mail.png rename gfx/{shrink1.2bpp.lz => shrink1.2bpp.lz.d4443930} (100%) create mode 100644 gfx/shrink1.png rename gfx/{shrink2.2bpp.lz => shrink2.2bpp.lz.3f58480a} (100%) create mode 100644 gfx/shrink2.png rename gfx/{slots_1.2bpp.lz => slots_1.2bpp.lz.b22ddc13} (100%) create mode 100644 gfx/slots_1.png rename gfx/{slots_2.2bpp.lz => slots_2.2bpp.lz.b28f76e3} (100%) create mode 100644 gfx/slots_2.png rename gfx/{slots_3.2bpp.lz => slots_3.2bpp.lz.70c2984c} (100%) create mode 100755 gfx/slots_3.png diff --git a/Makefile b/Makefile index fb9e75a42..ed74afe5c 100644 --- a/Makefile +++ b/Makefile @@ -130,6 +130,11 @@ gfx/title/logo.2bpp: rgbgfx += -x 4 gfx/trade/ball.2bpp: tools/gfx += --remove-whitespace +gfx/slots_2.2bpp: tools/gfx += --interleave --width=16 +gfx/slots_3.2bpp: tools/gfx += --interleave --width=24 --remove-duplicates --keep-whitespace --remove-xflip +gfx/slots_3a.2bpp: tools/gfx += --interleave --width=16 +gfx/slots_3b.2bpp: tools/gfx += --interleave --width=24 --remove-duplicates --keep-whitespace --remove-xflip + %.bin: ; %.blk: ; diff --git a/gfx/pc.2bpp.lz b/gfx/pc.2bpp.lz.2201c1aa similarity index 100% rename from gfx/pc.2bpp.lz rename to gfx/pc.2bpp.lz.2201c1aa diff --git a/gfx/pc.png b/gfx/pc.png new file mode 100644 index 0000000000000000000000000000000000000000..ce8fed73b3c3fc3ead5feb04f834ec4f1abf39d8 GIT binary patch literal 115 zcmeAS@N?(olHy`uVBq!ia0vp^0zj<51SA+rg7$9&QdXWWjv*DdYELP2A#DHv diff --git a/gfx/pc_mail.png b/gfx/pc_mail.png new file mode 100644 index 0000000000000000000000000000000000000000..fd4b2892f337e264b693dd2ac38e42203095fdd1 GIT binary patch literal 114 zcmeAS@N?(olHy`uVBq!ia0vp^0wBx;Bp3=bcE|uJOHUWakcwN$2@H&DMHeaZ#Bew0 zEah7$#>UIbDApk{gQ5Aq!+{S6|MA-&X8*_U(Daj`hoRU}NI{k1SH0vL-D}7HfDH3= L^>bP0l+XkK)ZrjF literal 0 HcmV?d00001 diff --git a/gfx/shrink1.2bpp.lz b/gfx/shrink1.2bpp.lz.d4443930 similarity index 100% rename from gfx/shrink1.2bpp.lz rename to gfx/shrink1.2bpp.lz.d4443930 diff --git a/gfx/shrink1.png b/gfx/shrink1.png new file mode 100644 index 0000000000000000000000000000000000000000..6cf5b80771956af61967e99cdd19cc115fb148b6 GIT binary patch literal 188 zcmeAS@N?(olHy`uVBq!ia0vp^79h+7Bp8mz)+7U|W=|K#kcwM-FP-LWFyLVbILIh- zZ1sezt#Peuf=-wU{N5_xvtUK5T-+=(#gYkWyz-Nex3w));|NO;T;-v-NbvC2@QTl=2NQF|kAF?F2zFj3t&-RF ln9ot2>%|s@*Y@%ekNINnzUwftxBL%smZz(q%Q~loCIBi}NKF6$ literal 0 HcmV?d00001 diff --git a/gfx/shrink2.2bpp.lz b/gfx/shrink2.2bpp.lz.3f58480a similarity index 100% rename from gfx/shrink2.2bpp.lz rename to gfx/shrink2.2bpp.lz.3f58480a diff --git a/gfx/shrink2.png b/gfx/shrink2.png new file mode 100644 index 0000000000000000000000000000000000000000..276b4e7c709540d7ee76e65404d1cc199e3f500b GIT binary patch literal 156 zcmeAS@N?(olHy`uVBq!ia0vp^79h+7Bp8mz)+7U|WKS2zkcwN$Kl+&@+;&Rb;s2u% z^N;_;9sB?PZz~r9$$B~S?=}%FHhOiF8}lByUpxJuF><}_jky*(>K)=X96!lAv**FT z=Rg17Z>R|WyV1SuYWg!~jV}B7?$7=`{GVW7GMS5^IsJ!mSYbmo$XZWVKbLh*2~7ZZ CJwYJ= literal 0 HcmV?d00001 diff --git a/gfx/slots_1.2bpp.lz b/gfx/slots_1.2bpp.lz.b22ddc13 similarity index 100% rename from gfx/slots_1.2bpp.lz rename to gfx/slots_1.2bpp.lz.b22ddc13 diff --git a/gfx/slots_1.png b/gfx/slots_1.png new file mode 100644 index 0000000000000000000000000000000000000000..a10340844165a9ba0aefac896741d99f5f0abcf1 GIT binary patch literal 446 zcmV;v0YUzWP)>m0004nNkl|%I0zP$H-m%BF!YX@{H_ob*c}LyE&;|NX>4>|2kyLAnR{Nzt;c$NRZySzBSRdn8D2Nd-!tXZE9mq#vFfg zY|dEp>G<^I$TsQ<)zMUxrmCok$1#nbiRFu@FZyrvZJteIF_VvkCNwN=Ml?3*PQb-= zDMeb0XOqq3{9bVmdudNRJyeb)pldH)=*$bOTfj;3NLH?^4c ztY0o>I$cb>8ELF5>QHw$bvSoYUA3S^*e1LseBi<1&f(0Vyh($ literal 0 HcmV?d00001 diff --git a/gfx/slots_2.2bpp.lz b/gfx/slots_2.2bpp.lz.b28f76e3 similarity index 100% rename from gfx/slots_2.2bpp.lz rename to gfx/slots_2.2bpp.lz.b28f76e3 diff --git a/gfx/slots_2.png b/gfx/slots_2.png new file mode 100644 index 0000000000000000000000000000000000000000..aa1292ccbcad5b10f133086d33e3b7cdbe0a455b GIT binary patch literal 664 zcmV;J0%!e+P))lv*$K;;k?R6(pC{=-?rh{0Yq^=Ll)eIknJJO}8!9f1+!Q z4J-vu`9H>80trkyeKV`Z)-?3gVfipW-g~^A`2h35$B{yDul))|A!gV=-vy7vF7QD3 zpiP4oMW4^1H5P`Z0e!hj=-?ZE0?(lUhD%4TLZ(s7***$w|<7`HpYpX24HwY+K zCOqiiWCJRbcQ7d@IL?H{BNro4Y+%ydYfw?qpp3L@a`|#SZ8}vwqMt(onGFQ}-Vwt5 zV~+64#{&fKdmg^`Kf84BmDB8#HX#~e$J0=p{Z>z!WwJ&GLU2qfb$1FOT&P--L#CSy zqs;vVMl0P0WOs!@<$Dyo(xtdslH!=0b*eZabO{rK({;MAhi@2yYSzOjTcy9uRw*Nw z<4~K&gsnp=)ujKOlm;#&S8TCATThM&DY{7&MI6ysjS(?9hO8wSPK8*tY)h?Kbsyy`$rq-Lt1Q z&Su29|LC6tsW*&47W<|*X+TmtrZe_8|1=y;&kg!;(&_e$T%Pgo$oR*Ne+R}t&-mvW z|M(sL-8}N3L`XNMCaOw(hIEt1)>;3oiL&2kxBGXugqz1CVJr;@>YtJWGdp4P*rX0000{y8xK literal 0 HcmV?d00001 diff --git a/gfx/slots_3.2bpp.lz b/gfx/slots_3.2bpp.lz.70c2984c similarity index 100% rename from gfx/slots_3.2bpp.lz rename to gfx/slots_3.2bpp.lz.70c2984c diff --git a/gfx/slots_3.png b/gfx/slots_3.png new file mode 100755 index 0000000000000000000000000000000000000000..456e9b6bffa01903e93efab1c5d281d789e6a42f GIT binary patch literal 1916 zcmaKtX*3&%7RM7IltigDk*Mt{Q=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|o)NW@WRp#LuS!)#Zy&8X8Q*dMsS`XT^rOHqQ z9f>gDp|g|<6f$pUz=W%0umoS%nXz$07u7zR8CSwXSyNbE1l!j4lO%zk1tY2Kq5vYE zs+l5xVJniNvp{H#FpCa`2G~3z%nDXPMWnbzx4=SYC04w+>A3he%GC);sG;mDrdYpf z(7rF?9gKtwoZl#RyEgCx1V1YVGfvc#}bU(~k#fUswOS|!WZ zx8i_(z@`?vtltGO{D5}izECfwkg{&J=#Htz9`DmL861v{@dZMcL70psg?~`siORcF`p7_Mk+EEbou6X5 zlct#*in2KU9;ND+3#SIkZx$Gv0^Vx*>&oKE#FzyGpDFX)nr3cwp4Tn^MyHtsJ`zf2 zV_ngx54Y#xBuP==h;=Zv|K7RKw=X_)La`>a=b1AedtniDQ z1LGATK+}QdDqfEM$`w{O%l~U$*r~A#S<)&rPjc-L?M+cBpCQ0h{b}e(FWivwfEt={ z8xEU3wMFM`VV`Sx=qQ}F$_TCN?eYAN2$3Lf%IPXNExZFXnL6E6CI>!u5>G~FWh;#_RmHiQR%1N-@p?EnA( literal 0 HcmV?d00001 diff --git a/tools/gfx.c b/tools/gfx.c index bfad43c0e..8283d9e73 100644 --- a/tools/gfx.c +++ b/tools/gfx.c @@ -7,7 +7,7 @@ #include "common.h" static void usage(void) { - fprintf(stderr, "Usage: gfx [--trim-whitespace] [--remove-whitespace] [--interleave] [-w width] [-d depth] [-h] [-o outfile] infile\n"); + fprintf(stderr, "Usage: gfx [--trim-whitespace] [--remove-whitespace] [--interleave] [--remove-duplicates [--keep-whitespace]] [--remove-xflip] [-w width] [-d depth] [-h] [-o outfile] infile\n"); } static void error(char *message) { @@ -23,6 +23,9 @@ struct Options { int depth; int interleave; int width; + int remove_duplicates; + int keep_whitespace; + int remove_xflip; }; struct Options Options = { @@ -34,6 +37,9 @@ void get_args(int argc, char *argv[]) { {"remove-whitespace", no_argument, &Options.remove_whitespace, 1}, {"trim-whitespace", no_argument, &Options.trim_whitespace, 1}, {"interleave", no_argument, &Options.interleave, 1}, + {"remove-duplicates", no_argument, &Options.remove_duplicates, 1}, + {"keep-whitespace", no_argument, &Options.keep_whitespace, 1}, + {"remove-xflip", no_argument, &Options.remove_xflip, 1}, {"width", required_argument, 0, 'w'}, {"depth", required_argument, 0, 'd'}, {"help", no_argument, 0, 'h'}, @@ -92,11 +98,15 @@ void trim_whitespace(struct Graphic *graphic) { void remove_whitespace(struct Graphic *graphic) { int tile_size = Options.depth * 8; + if (Options.interleave) tile_size *= 2; int i = 0; for (int j = 0; i < graphic->size && j < graphic->size; i += tile_size, j += tile_size) { while (is_whitespace(&graphic->data[j], tile_size)) { j += tile_size; } + if (j >= graphic->size) { + break; + } if (j > i) { memcpy(&graphic->data[i], &graphic->data[j], tile_size); } @@ -104,6 +114,94 @@ void remove_whitespace(struct Graphic *graphic) { graphic->size = i; } +bool tile_exists(uint8_t *tile, uint8_t *tiles, int tile_size, int num_tiles) { + for (int i = 0; i < num_tiles; i++) { + bool match = true; + for (int j = 0; j < tile_size; j++) { + if (tile[j] != tiles[i * tile_size + j]) { + match = false; + } + } + if (match) { + return true; + } + } + return false; +} + +void remove_duplicates(struct Graphic *graphic) { + int tile_size = Options.depth * 8; + if (Options.interleave) tile_size *= 2; + int num_tiles = 0; + for (int i = 0, j = 0; i < graphic->size && j < graphic->size; i += tile_size, j += tile_size) { + while (tile_exists(&graphic->data[j], graphic->data, tile_size, num_tiles)) { + if (Options.keep_whitespace && is_whitespace(&graphic->data[j], tile_size)) { + break; + } + j += tile_size; + } + if (j >= graphic->size) { + break; + } + if (j > i) { + memcpy(&graphic->data[i], &graphic->data[j], tile_size); + } + num_tiles++; + } + graphic->size = num_tiles * tile_size; +} + +bool flip_exists(uint8_t *tile, uint8_t *tiles, int tile_size, int num_tiles, bool xflip, bool yflip) { + uint8_t *flip = calloc(tile_size, 1); + int half_size = tile_size / 2; + for (int i = 0; i < tile_size; i++) { + int byte = i; + if (yflip) { + byte = tile_size - 1 - i; + if (Options.interleave && i < half_size) { + byte = half_size - 1 - i; + } + } + if (flip) { + for (int bit = 0; bit < 8; bit++) { + flip[byte] |= ((tile[i] >> bit) & 1) << (7 - bit); + } + } else { + flip[byte] = tile[i]; + } + } + if (tile_exists(flip, tiles, tile_size, num_tiles)) { + return true; + } + return false; +} + +bool xflip_exists(uint8_t *tile, uint8_t *tiles, int tile_size, int num_tiles) { + return flip_exists(tile, tiles, tile_size, num_tiles, true, false); +} + +void remove_xflip(struct Graphic *graphic) { + int tile_size = Options.depth * 8; + if (Options.interleave) tile_size *= 2; + int num_tiles = 0; + for (int i = 0, j = 0; i < graphic->size && j < graphic->size; i += tile_size, j += tile_size) { + while (xflip_exists(&graphic->data[j], graphic->data, tile_size, num_tiles)) { + if (Options.keep_whitespace && is_whitespace(&graphic->data[j], tile_size)) { + break; + } + j += tile_size; + } + if (j >= graphic->size) { + break; + } + if (j > i) { + memcpy(&graphic->data[i], &graphic->data[j], tile_size); + } + num_tiles++; + } + graphic->size = num_tiles * tile_size; +} + void interleave(struct Graphic *graphic, int width) { int tile_size = Options.depth * 8; int width_tiles = width / 8; @@ -119,6 +217,7 @@ void interleave(struct Graphic *graphic, int width) { } memcpy(&interleaved[tile * tile_size], &graphic->data[i * tile_size], tile_size); } + graphic->size = num_tiles * tile_size; memcpy(graphic->data, interleaved, graphic->size); free(interleaved); } @@ -139,9 +238,6 @@ int main(int argc, char *argv[]) { char *infile = argv[0]; struct Graphic graphic; graphic.data = read_u8(infile, &graphic.size); - if (Options.remove_whitespace) { - remove_whitespace(&graphic); - } if (Options.trim_whitespace) { trim_whitespace(&graphic); } @@ -153,6 +249,15 @@ int main(int argc, char *argv[]) { } interleave(&graphic, Options.width); } + if (Options.remove_duplicates) { + remove_duplicates(&graphic); + } + if (Options.remove_xflip) { + remove_xflip(&graphic); + } + if (Options.remove_whitespace) { + remove_whitespace(&graphic); + } if (Options.outfile) { write_u8(Options.outfile, graphic.data, graphic.size); }