# HG changeset patch # User Matti Hamalainen # Date 1543843331 -7200 # Node ID 3829c292df02853e1cf1bac09eb6a2b26be6990e # Parent 1662730053d079b3ef8799b2ddcfefef2c1c8c34 Add 'cdump' image output format, mainly for debugging purposes. diff -r 1662730053d0 -r 3829c292df02 tools/libgfx.c --- a/tools/libgfx.c Fri Nov 30 08:01:46 2018 +0200 +++ b/tools/libgfx.c Mon Dec 03 15:22:11 2018 +0200 @@ -396,6 +396,42 @@ } +static int dmWriteCDumpRow(void *cbdata, const Uint8 *row, const size_t len) +{ + DMResource *fp = (DMResource *) cbdata; + for (size_t n = 0; n < len; n++) + { + dmfprintf(fp, "0x%02x, ", row[n]); + } + + dmfprintf(fp, "\n"); + + return DMERR_OK; +} + + +int dmWriteCDumpImage(DMResource *fp, const DMImage *img, const DMImageConvSpec *spec) +{ + int res; + + dmfprintf(fp, + "#define SET_WIDTH %d\n" + "#define SET_HEIGHT %d\n" + "\n" + "Uint8 img_data[] = {\n", + + img->width * spec->scaleX, + img->height * spec->scaleY); + + res = dmWriteImageData(img, (void *) fp, dmWriteCDumpRow, spec); + + dmfprintf(fp, + "};\n"); + + return res; +} + + static int dmWritePPMRow(void *cbdata, const Uint8 *row, const size_t len) { if (dmf_write_str((DMResource *) cbdata, row, len)) @@ -2311,6 +2347,11 @@ "araw", "IFFMaster Amiga RAW", DM_IMGFMT_ARAW, DM_FMT_WR, NULL, NULL, dmWriteRAWImage, + }, + { + "cdump", "'C' dump (8-bit indexed image data only)", + DM_IMGFMT_CDUMP, DM_FMT_WR, + NULL, NULL, dmWriteCDumpImage, } }; diff -r 1662730053d0 -r 3829c292df02 tools/libgfx.h --- a/tools/libgfx.h Fri Nov 30 08:01:46 2018 +0200 +++ b/tools/libgfx.h Mon Dec 03 15:22:11 2018 +0200 @@ -25,6 +25,7 @@ DM_IMGFMT_IFF, DM_IMGFMT_RAW, DM_IMGFMT_ARAW, + DM_IMGFMT_CDUMP, };