From 30704f157c63a7c796d488bae9622c9d72b7f35f Mon Sep 17 00:00:00 2001 From: Robin Krens Date: Tue, 14 Jun 2022 20:28:41 +0200 Subject: [PATCH] tools: bmp2tiles multiple tiles one palette --- tools/bmp2tiles/bmp2tiles.c | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/tools/bmp2tiles/bmp2tiles.c b/tools/bmp2tiles/bmp2tiles.c index abc8576..b005365 100644 --- a/tools/bmp2tiles/bmp2tiles.c +++ b/tools/bmp2tiles/bmp2tiles.c @@ -68,6 +68,7 @@ void generate_4bpp_tile(unsigned char *buf, swan_gfx_t * gfx, for (int i = 0; i < TILE_SZ; i+=4) { for (int j = 0; j < 4; ++j) { if (packed) { /* packed format */ + //printf("%d %d ", ptr[0], ptr[1]); if (ptr[0] >= 8 || ptr[1] >= 8) fprintf(stdout, "warning: too many colors detected\n"); gfx->outpal[ptr[0]] = (gfx->palette[ptr[0]].r >> 4) << 8 | @@ -76,7 +77,7 @@ void generate_4bpp_tile(unsigned char *buf, swan_gfx_t * gfx, buf[i+j] = ptr[0] << 4; buf[i+j] |= ptr[1]; ptr += 2; - } else { /* planar format */ + } else { /* TODO: planar format */ for (int x = 0; x < 8; ++x) { if (ptr[x] >= 8) fprintf(stdout, "warning: too many colors detected\n"); @@ -86,6 +87,9 @@ void generate_4bpp_tile(unsigned char *buf, swan_gfx_t * gfx, } if (!packed) ptr += 8; + else { + ptr += (8 * (gfx->row_tiles-1)); + } } } @@ -154,15 +158,19 @@ int main(int argc, char *argv[]) goto close; } - unsigned nr_tiles = 1; - - for (int i = 0; i < nr_tiles; ++i) { - generate_4bpp_tile(tile_buf, gfx, true); - int ret = fwrite(tile_buf, sizeof(unsigned char), TILE_SZ, gfxstream); - if (ret != TILE_SZ) { - fprintf(stderr, "failed to convert, only write %d instead of %d\n", ret, TILE_SZ); - goto cleanup; + for (int i = 0; i < gfx->row_tiles; ++i) { + for (int j = 0; j < gfx->col_tiles; ++j) { + //printf("row[%d]col[%d]\n",i,j); + generate_4bpp_tile(tile_buf, gfx, true); + int ret = fwrite(tile_buf, sizeof(unsigned char), TILE_SZ, gfxstream); + if (ret != TILE_SZ) { + fprintf(stderr, "failed to convert, only write %d instead of %d\n", ret, TILE_SZ); + goto cleanup; + } + gfx->data += 8; /* next column */ + //printf("\n"); } + gfx->data += (gfx->col_tiles * 64) - 16; } palstream = fopen("out.pal", "w"); -- 2.7.4