diff options
-rw-r--r-- | Makefile | 5 | ||||
-rw-r--r-- | gfx/pc.2bpp.lz.2201c1aa (renamed from gfx/pc.2bpp.lz) | bin | 132 -> 132 bytes | |||
-rw-r--r-- | gfx/pc.png | bin | 0 -> 115 bytes | |||
-rw-r--r-- | gfx/pc_mail.2bpp | bin | 64 -> 0 bytes | |||
-rw-r--r-- | gfx/pc_mail.png | bin | 0 -> 114 bytes | |||
-rw-r--r-- | gfx/shrink1.2bpp.lz.d4443930 (renamed from gfx/shrink1.2bpp.lz) | bin | 144 -> 144 bytes | |||
-rw-r--r-- | gfx/shrink1.png | bin | 0 -> 188 bytes | |||
-rw-r--r-- | gfx/shrink2.2bpp.lz.3f58480a (renamed from gfx/shrink2.2bpp.lz) | bin | 64 -> 64 bytes | |||
-rw-r--r-- | gfx/shrink2.png | bin | 0 -> 156 bytes | |||
-rw-r--r-- | gfx/slots_1.2bpp.lz.b22ddc13 (renamed from gfx/slots_1.2bpp.lz) | bin | 384 -> 384 bytes | |||
-rw-r--r-- | gfx/slots_1.png | bin | 0 -> 446 bytes | |||
-rw-r--r-- | gfx/slots_2.2bpp.lz.b28f76e3 (renamed from gfx/slots_2.2bpp.lz) | bin | 608 -> 608 bytes | |||
-rw-r--r-- | gfx/slots_2.png | bin | 0 -> 664 bytes | |||
-rw-r--r-- | gfx/slots_3.2bpp.lz.70c2984c (renamed from gfx/slots_3.2bpp.lz) | bin | 528 -> 528 bytes | |||
-rwxr-xr-x | gfx/slots_3.png | bin | 0 -> 1916 bytes | |||
-rw-r--r-- | tools/gfx.c | 113 |
16 files changed, 114 insertions, 4 deletions
@@ -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 Binary files differindex 996cfadc9..996cfadc9 100644 --- a/gfx/pc.2bpp.lz +++ b/gfx/pc.2bpp.lz.2201c1aa diff --git a/gfx/pc.png b/gfx/pc.png Binary files differnew file mode 100644 index 000000000..ce8fed73b --- /dev/null +++ b/gfx/pc.png diff --git a/gfx/pc_mail.2bpp b/gfx/pc_mail.2bpp Binary files differdeleted file mode 100644 index 9a6d66ab9..000000000 --- a/gfx/pc_mail.2bpp +++ /dev/null diff --git a/gfx/pc_mail.png b/gfx/pc_mail.png Binary files differnew file mode 100644 index 000000000..fd4b2892f --- /dev/null +++ b/gfx/pc_mail.png diff --git a/gfx/shrink1.2bpp.lz b/gfx/shrink1.2bpp.lz.d4443930 Binary files differindex 284bee8c2..284bee8c2 100644 --- a/gfx/shrink1.2bpp.lz +++ b/gfx/shrink1.2bpp.lz.d4443930 diff --git a/gfx/shrink1.png b/gfx/shrink1.png Binary files differnew file mode 100644 index 000000000..6cf5b8077 --- /dev/null +++ b/gfx/shrink1.png diff --git a/gfx/shrink2.2bpp.lz b/gfx/shrink2.2bpp.lz.3f58480a Binary files differindex df14d5ed4..df14d5ed4 100644 --- a/gfx/shrink2.2bpp.lz +++ b/gfx/shrink2.2bpp.lz.3f58480a diff --git a/gfx/shrink2.png b/gfx/shrink2.png Binary files differnew file mode 100644 index 000000000..276b4e7c7 --- /dev/null +++ b/gfx/shrink2.png diff --git a/gfx/slots_1.2bpp.lz b/gfx/slots_1.2bpp.lz.b22ddc13 Binary files differindex 90d3ce139..90d3ce139 100644 --- a/gfx/slots_1.2bpp.lz +++ b/gfx/slots_1.2bpp.lz.b22ddc13 diff --git a/gfx/slots_1.png b/gfx/slots_1.png Binary files differnew file mode 100644 index 000000000..a10340844 --- /dev/null +++ b/gfx/slots_1.png diff --git a/gfx/slots_2.2bpp.lz b/gfx/slots_2.2bpp.lz.b28f76e3 Binary files differindex 638c68055..638c68055 100644 --- a/gfx/slots_2.2bpp.lz +++ b/gfx/slots_2.2bpp.lz.b28f76e3 diff --git a/gfx/slots_2.png b/gfx/slots_2.png Binary files differnew file mode 100644 index 000000000..aa1292ccb --- /dev/null +++ b/gfx/slots_2.png diff --git a/gfx/slots_3.2bpp.lz b/gfx/slots_3.2bpp.lz.70c2984c Binary files differindex 858b6e464..858b6e464 100644 --- a/gfx/slots_3.2bpp.lz +++ b/gfx/slots_3.2bpp.lz.70c2984c diff --git a/gfx/slots_3.png b/gfx/slots_3.png Binary files differnew file mode 100755 index 000000000..456e9b6bf --- /dev/null +++ b/gfx/slots_3.png 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); } |