From: Robin Krens Date: Sun, 12 Jun 2022 14:00:37 +0000 (+0200) Subject: tools: output stream for .gfx 4bpp file X-Git-Url: https://robinkrens.nl/gitweb/?a=commitdiff_plain;h=27a517e4e9506a138e4240094ab04856dbc4e3f3;p=swan-dev tools: output stream for .gfx 4bpp file --- diff --git a/tools/bmp2tiles/bmp2tiles.c b/tools/bmp2tiles/bmp2tiles.c index 42a8805..25ea7d5 100644 --- a/tools/bmp2tiles/bmp2tiles.c +++ b/tools/bmp2tiles/bmp2tiles.c @@ -56,7 +56,9 @@ int main(void) { SDL_Surface * rawbmp; SDL_PixelFormat * fmt; + FILE * ostream; char filename[] = "test.bmp"; + char outname[] = "test.gfx"; rawbmp = SDL_LoadBMP(filename); if (!rawbmp) { @@ -71,14 +73,21 @@ int main(void) SDL_UnlockSurface(rawbmp); unsigned char *tile_buf = malloc(sizeof(unsigned char) * TILE_SZ); - - generate_4bpp_tile_packed(tile_buf, rawbmp->userdata, 64); /* if (rawbmp->format->BitsPerPixel != 24) { fprintf(stderr, "format %d not supported\n", rawbmp->format->BitsPerPixel); exit(EXIT_FAILURE); } */ + ostream = fopen(outname, "w"); + if (!ostream) { + fprintf(stderr, "can not open file for writing!\n"); + exit(EXIT_FAILURE); + } + + generate_4bpp_tile_packed(tile_buf, rawbmp->userdata, 64); + int ret = fwrite(tile_buf, sizeof(unsigned char), 32, ostream); + printf("written: %d\n", ret); SDL_FreeSurface(rawbmp);