From caf48cf3ef68f6a5e2aea33369a78433a368ea92 Mon Sep 17 00:00:00 2001 From: nmlgc Date: Sat, 16 Jul 2022 00:46:56 +0200 Subject: [PATCH] [Pipeline] bmp2arr: Move C type generation into a single function Part of P0205, funded by [Anonymous] and Yanga. --- Pipeline/bmp2arrl.c | 43 +++++++++++++++++++------------------------ 1 file changed, 19 insertions(+), 24 deletions(-) diff --git a/Pipeline/bmp2arrl.c b/Pipeline/bmp2arrl.c index 461e91e0..59b078f3 100644 --- a/Pipeline/bmp2arrl.c +++ b/Pipeline/bmp2arrl.c @@ -268,42 +268,37 @@ static int memcpy32to1(unsigned char *dst,unsigned char *src,unsigned int w) { return -1; } +static void saveout_write_c_type(struct rec98_bmp2arr_task *t,struct saveout_ctx *sctx) { + fprintf(sctx->fp,"const unsigned char %s",t->output_symname != NULL ? t->output_symname : "untitled"); + + if (t->flags & PRESHIFT_OUTER) + fprintf(sctx->fp,"[8/*PRESHIFT*/]"); + + fprintf(sctx->fp,"[%d]",sctx->ssrows * sctx->sscols); + + if (t->flags & PRESHIFT_INNER) + fprintf(sctx->fp,"[8/*PRESHIFT*/]"); + + fprintf(sctx->fp,"[%d/*%d bytes x %d rows*/]",sctx->bytesperrow * t->sprite_height,sctx->bytesperrow,t->sprite_height); +} + static int saveout_write_prologue(struct rec98_bmp2arr_task *t,struct saveout_ctx *sctx) { if (t->output_type == REC98_OUT_C) { fprintf(sctx->fp,"/* Generated by bmp2arr from %s, do not modify directly. */\n",t->input_bmp); fprintf(sctx->fp,"/* Sprite sheet: %d sprites (%d x %d) of %d x %d sprites. */\n",sctx->sscols * sctx->ssrows,sctx->sscols,sctx->ssrows,t->sprite_width,t->sprite_height); fprintf(sctx->fp,"\n"); - fprintf(sctx->fp,"const unsigned char %s",t->output_symname != NULL ? t->output_symname : "untitled"); - - if (t->flags & PRESHIFT_OUTER) - fprintf(sctx->fp,"[8/*PRESHIFT*/]"); - - fprintf(sctx->fp,"[%d]",sctx->ssrows * sctx->sscols); - - if (t->flags & PRESHIFT_INNER) - fprintf(sctx->fp,"[8/*PRESHIFT*/]"); - - fprintf(sctx->fp,"[%d/*%d bytes x %d rows*/] = {\n", - sctx->bytesperrow * t->sprite_height,sctx->bytesperrow,t->sprite_height); + saveout_write_c_type(t,sctx); + fprintf(sctx->fp," = {\n"); } else if (t->output_type == REC98_OUT_ASM) { fprintf(sctx->fp,"; Generated by bmp2arr from %s, do not modify directly.\n",t->input_bmp); fprintf(sctx->fp,"; Sprite sheet: %d sprites (%d x %d) of %d x %d sprites.\n",sctx->sscols * sctx->ssrows,sctx->sscols,sctx->ssrows,t->sprite_width,t->sprite_height); fprintf(sctx->fp,"\n"); - fprintf(sctx->fp,"; const unsigned char %s",t->output_symname != NULL ? t->output_symname : "untitled"); - - if (t->flags & PRESHIFT_OUTER) - fprintf(sctx->fp,"[8/*PRESHIFT*/]"); - - fprintf(sctx->fp,"[%d]",sctx->ssrows * sctx->sscols); - - if (t->flags & PRESHIFT_INNER) - fprintf(sctx->fp,"[8/*PRESHIFT*/]"); - - fprintf(sctx->fp,"[%d/*%d bytes x %d rows*/];\n", - sctx->bytesperrow * t->sprite_height,sctx->bytesperrow,t->sprite_height); + fprintf(sctx->fp,"; "); + saveout_write_c_type(t,sctx); + fprintf(sctx->fp,";\n"); fprintf(sctx->fp,"public %s\n",t->output_symname != NULL ? t->output_symname : "untitled"); fprintf(sctx->fp,"label %s byte\n",t->output_symname != NULL ? t->output_symname : "untitled");