changeset 1829:5639142e0b87

Change the order and logic of how we do upconversion fixups in dmConvertC64Bitmap(). This fixes some issues in MC->FLI type conversions.
author Matti Hamalainen <ccr@tnsp.org>
date Fri, 22 Jun 2018 13:43:44 +0300
parents 6e1dd79c6bce
children 3d4bb20f6739
files tools/gfxconv.c
diffstat 1 files changed, 25 insertions(+), 18 deletions(-) [+]
line wrap: on
line diff
--- a/tools/gfxconv.c	Fri Jun 22 13:41:54 2018 +0300
+++ b/tools/gfxconv.c	Fri Jun 22 13:43:44 2018 +0300
@@ -992,6 +992,23 @@
     dst->d023    = src->d023;
     dst->d024    = src->d024;
 
+    // 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 < dst->nbanks; i++)
+        {
+            dmC64MemBlockCopy(&dst->color[i], &src->color[0]);
+            dmC64MemBlockCopy(&dst->screen[i], &src->screen[0]);
+            dmC64MemBlockCopy(&dst->bitmap[i], &src->bitmap[0]);
+        }
+    }
+    else
+    if ((src->type & D64_FMT_FLI) && (dst->type & D64_FMT_FLI) == 0)
+    {
+        dmMsg(1, "Downconverting FLI to multicolor.\n");
+    }
+
     // Do per opcode copies
     for (int i = 0; i < D64_MAX_ENCDEC_OPS; i++)
     {
@@ -1013,11 +1030,17 @@
             case DO_SET_OP:
                 dmC64GetOpMemBlockAndName(src, op->subject, op->bank, (const DMC64MemBlock **) &srcBlk, &blkname);
                 dmC64GetOpMemBlockAndName(dst, op->subject, op->bank, (const DMC64MemBlock **) &dstBlk, &blkname);
+
+                // Skip if we did previous fixups/upconverts
+                if (dstBlk != NULL && dstBlk->data != NULL)
+                    break;
+
                 if (srcBlk != NULL && srcBlk->data != NULL && srcBlk->size >= size)
                 {
                     // The block exists in source and is of sufficient size, so copy it
                     dmMsg(2, "Copying block '%s' op #%d, offs=%d ($%04x), bank=%d, size=%d ($%04x)\n",
                         blkname, i, op->offs, op->offs, op->bank, size, size);
+
                     dmC64MemBlockCopy(dstBlk, srcBlk);
                 }
                 else
@@ -1035,7 +1058,7 @@
                                 "op #%d, offs=%d ($%04x), bank=%d, size=%d ($%04x)\n",
                                 blkname, i, op->offs, op->offs, op->bank, size, size);
                         }
-                        if (srcBlk->data == NULL)
+                        if (srcBlk == NULL || srcBlk->data == NULL)
                         {
                             dmMsg(2, "Creating block '%s' op #%d, offs=%d ($%04x), bank=%d, size=%d ($%04x)\n",
                                 blkname, i, op->offs, op->offs, op->bank, size, size);
@@ -1045,7 +1068,7 @@
                             case DO_COPY:
                                 // If some data exists, copy it. Rest is zero.
                                 // Otherwise just set to zero.
-                                if (srcBlk->data != NULL)
+                                if (srcBlk != NULL && srcBlk->data != NULL)
                                     memcpy(dstBlk->data, srcBlk->data, srcBlk->size);
                                 break;
 
@@ -1069,22 +1092,6 @@
         }
     }
 
-    // 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 < dst->nbanks; i++)
-        {
-            dmC64MemBlockCopy(&dst->color[i], &src->color[0]);
-            dmC64MemBlockCopy(&dst->screen[i], &src->screen[0]);
-            dmC64MemBlockCopy(&dst->bitmap[i], &src->bitmap[0]);
-        }
-    }
-    else
-    if ((src->type & D64_FMT_FLI) && (dst->type & D64_FMT_FLI) == 0)
-    {
-        dmMsg(1, "Downconverting FLI to multicolor.\n");
-    }
 
     return DMERR_OK;
 }