changeset 1493:d987a4933e1c

Some dabbling work on basic C64 bitmap conversion.
author Matti Hamalainen <ccr@tnsp.org>
date Fri, 11 May 2018 05:46:50 +0300
parents 5f9080d24f3c
children 3b220604ae3c
files tools/gfxconv.c
diffstat 1 files changed, 36 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/tools/gfxconv.c	Fri May 11 05:31:46 2018 +0300
+++ b/tools/gfxconv.c	Fri May 11 05:46:50 2018 +0300
@@ -1028,8 +1028,44 @@
 
 int dmConvertC64Bitmap(DMC64Image **pdst, const DMC64Image *src, const DMC64ImageFormat *fmt)
 {
+    DMC64Image *dst;
+
     if (pdst == NULL || fmt == NULL || src == NULL)
         return DMERR_NULLPTR;
+
+    if ((dst = *pdst = dmC64ImageAlloc(fmt)) == NULL)
+        return DMERR_MALLOC;
+
+    if (src->type == dst->type)
+    {
+        for (int i = 0; i < dst->nbanks; i++)
+        {
+            memcpy(dst->color[i], src->color[i], dst->screenSize);
+            memcpy(dst->bitmap[i], src->bitmap[i], dst->bitmapSize);
+            memcpy(dst->screen[i], src->screen[i], dst->screenSize);
+            memcpy(dst->charmem[i], src->charmem[i], dst->charmemSize);
+        }
+    }
+    else
+    {
+        // Try to do some simple fixups
+        if ((dst->type & D64_FMT_FLI) && (src->type & D64_FMT_FLI) == 0)
+        {
+            dmMsg(1, "Upconverting multicolor to FLI.\n");
+            for (int i = 0; i < src->nbanks; i++)
+            {
+                memcpy(dst->color[i], src->color[0], dst->screenSize);
+                memcpy(dst->screen[i], src->screen[0], dst->screenSize);
+            }
+
+            for (int i = 0; i < dst->nbanks; i++)
+            {
+                memcpy(dst->bitmap[i], src->bitmap[i], dst->bitmapSize);
+                memcpy(dst->charmem[i], src->charmem[i], dst->charmemSize);
+            }
+        }
+    }
+
     return DMERR_OK;
 }