changeset 2047:3829c292df02

Add 'cdump' image output format, mainly for debugging purposes.
author Matti Hamalainen <ccr@tnsp.org>
date Mon, 03 Dec 2018 15:22:11 +0200
parents 1662730053d0
children 0a1fe72be4a9
files tools/libgfx.c tools/libgfx.h
diffstat 2 files changed, 42 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- 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,
     }
 };
 
--- 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,
 };