changeset 1490:665a0b917d22

Begin restructuring how C64 bitmaps are converted.
author Matti Hamalainen <ccr@tnsp.org>
date Fri, 11 May 2018 05:25:46 +0300
parents 71e847ea9d22
children b329fea6f013
files tools/gfxconv.c
diffstat 1 files changed, 17 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/tools/gfxconv.c	Fri May 11 05:23:52 2018 +0300
+++ b/tools/gfxconv.c	Fri May 11 05:25:46 2018 +0300
@@ -1026,10 +1026,17 @@
 }
 
 
-int dmWriteBitmap(const char *filename, const DMC64Image *image)
+int dmConvertC64Bitmap(DMC64Image **pdst, const DMC64Image *src, const DMC64ImageFormat *fmt)
+{
+    if (pdst == NULL || fmt == NULL || src == NULL)
+        return DMERR_NULLPTR;
+    return DMERR_OK;
+}
+
+
+int dmWriteBitmap(const char *filename, const DMC64Image *image, const DMC64ImageFormat *fmt)
 {
     int res = DMERR_OK;
-    const DMC64ImageFormat *fmt = &dmC64ImageFormats[image->type];
     DMGrowBuf buf;
 
     // Encode to target format
@@ -1553,7 +1560,7 @@
 {
     FILE *inFile = NULL;
     const DMC64ImageFormat *inC64Fmt = NULL;
-    DMC64Image *inC64Image = NULL;
+    DMC64Image *inC64Image = NULL, *outC64Image = NULL;
     Uint8 *dataBuf = NULL, *dataBufOrig = NULL;
     size_t dataSize, dataSizeOrig;
     int i;
@@ -1727,7 +1734,12 @@
                         break;
 
                     case FFMT_BITMAP:
-                        res = dmWriteBitmap(optOutFilename, inC64Image);
+                        if ((res = dmConvertC64Bitmap(&outC64Image, inC64Image, &dmC64ImageFormats[optOutSubFormat])) != DMERR_OK)
+                        {
+                            dmErrorMsg("Error in bitmap format conversion.\n");
+                            goto error;
+                        }
+                        res = dmWriteBitmap(optOutFilename, outC64Image, &dmC64ImageFormats[optOutSubFormat]);
                         break;
 
                     case FFMT_CHAR:
@@ -1807,6 +1819,7 @@
 
     dmFree(dataBufOrig);
     dmC64ImageFree(inC64Image);
+    dmC64ImageFree(outC64Image);
 
     return 0;
 }