tools: output stream for .gfx 4bpp file
authorRobin Krens <robin@robinkrens.nl>
Sun, 12 Jun 2022 14:00:37 +0000 (16:00 +0200)
committerRobin Krens <robin@robinkrens.nl>
Sun, 12 Jun 2022 14:00:37 +0000 (16:00 +0200)
tools/bmp2tiles/bmp2tiles.c

index 42a8805..25ea7d5 100644 (file)
@@ -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);