From: Robin Krens Date: Sun, 12 Jun 2022 15:51:37 +0000 (+0200) Subject: tools: bmp2tiles with cmd line args X-Git-Url: https://robinkrens.nl/gitweb/?a=commitdiff_plain;h=2b0ba2a6947c1879d6c03b784d57919750fcc170;p=swan-dev tools: bmp2tiles with cmd line args --- diff --git a/tools/bmp2tiles/bmp2tiles.c b/tools/bmp2tiles/bmp2tiles.c index 472442a..40db317 100644 --- a/tools/bmp2tiles/bmp2tiles.c +++ b/tools/bmp2tiles/bmp2tiles.c @@ -11,6 +11,8 @@ #include #include #include +#include +#include #include #define TILE_SZ 32 @@ -56,16 +58,47 @@ void generate_4bpp_tile(unsigned char *buf, void * userdata, } } -int main(void) +int main(int argc, char *argv[]) { SDL_Surface * rawbmp; FILE * ostream; - char filename[] = "test.bmp"; - char outname[] = "test.gfx"; - rawbmp = SDL_LoadBMP(filename); - + int opt; + char * infile; + char outfile[256]; + bool bout = false; + + while ((opt = getopt(argc, argv, "po:sv:")) != -1) { + switch (opt) { + case 'p': + printf("include palette"); + break; + case 'o': + printf("output file %s\n", optarg); + strcpy(outfile, optarg); + bout = true; + break; + case 's': + printf("generate gfx per 16x16 tile \n"); + break; + case 'v': + break; + default: /* '?' */ + fprintf(stderr, "Usage: %s [-s] [-o output] file \n", argv[0]); + exit(EXIT_FAILURE); + } + } + + if (optind >= argc) { + fprintf(stderr, "Expected infile\n"); + fprintf(stderr, "Usage: %s [-s] [-o output] [file]\n", argv[0]); + exit(EXIT_FAILURE); + } + + infile = argv[optind]; + + rawbmp = SDL_LoadBMP(infile); if (!rawbmp) { - fprintf(stderr, "can not load .bmp file\n"); + fprintf(stderr, "can not load %s file\n", infile); exit(EXIT_FAILURE); } @@ -80,7 +113,13 @@ int main(void) exit(EXIT_FAILURE); } - ostream = fopen(outname, "w"); + if (!bout) + ostream = fopen("out.gfx", "w"); + else { + printf("opening %s\n", outfile); + ostream = fopen(outfile, "w"); + } + if (!ostream) { fprintf(stderr, "can not open file for writing!\n"); exit(EXIT_FAILURE);