changeset 1537:776aa43b2c57

Tiny improvement in MC->FLI upconversion.
author Matti Hamalainen <ccr@tnsp.org>
date Sat, 12 May 2018 04:46:08 +0300
parents 064fc2e3ee64
children af729e29a6f6
files tools/gfxconv.c tools/lib64gfx.c tools/lib64gfx.h
diffstat 3 files changed, 27 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/tools/gfxconv.c	Sat May 12 04:12:46 2018 +0300
+++ b/tools/gfxconv.c	Sat May 12 04:46:08 2018 +0300
@@ -1051,16 +1051,35 @@
         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++)
+            for (int i = 0; i < dst->nbanks; i++)
             {
                 memcpy(dst->color[i], src->color[0], dst->screenSize);
                 memcpy(dst->screen[i], src->screen[0], dst->screenSize);
+                memcpy(dst->bitmap[i], src->bitmap[0], dst->bitmapSize);
+                memcpy(dst->charmem[i], src->charmem[0], dst->charmemSize);
             }
 
-            for (int i = 0; i < dst->nbanks; i++)
+            for (int i = 0; i < D64_MAX_ENCDEC_OPS; i++)
             {
-                memcpy(dst->bitmap[i], src->bitmap[i], dst->bitmapSize);
-                memcpy(dst->charmem[i], src->charmem[i], dst->charmemSize);
+                const DMC64EncDecOp *op = &fmt->encdecOps[i];
+                size_t size;
+
+                // Check for last operator
+                if (op->type == DT_LAST)
+                    break;
+
+                // Check size
+                if (!dmC64GetOpSize(op, fmt, &size))
+                    return DMERR_INVALID_DATA;
+
+                // Perform operation
+                switch (op->type)
+                {
+                    case DT_EXTRA_DATA:
+                        dst->extraData[op->bank] = dmMalloc0(size);
+                        dst->extraDataSizes[op->bank] = size;
+                        break;
+                }
             }
         }
     }
--- a/tools/lib64gfx.c	Sat May 12 04:12:46 2018 +0300
+++ b/tools/lib64gfx.c	Sat May 12 04:46:08 2018 +0300
@@ -445,7 +445,7 @@
 }
 
 
-static int dmC64SanityCheckEncDecOp(const int i, const DMC64EncDecOp *op, const DMC64Image *img)
+int dmC64SanityCheckEncDecOp(const int i, const DMC64EncDecOp *op, const DMC64Image *img)
 {
     switch (op->type)
     {
@@ -482,7 +482,7 @@
 }
 
 
-static BOOL dmC64GetOpSize(const DMC64EncDecOp *op, const DMC64ImageFormat *fmt, size_t *size)
+BOOL dmC64GetOpSize(const DMC64EncDecOp *op, const DMC64ImageFormat *fmt, size_t *size)
 {
     switch (op->type)
     {
--- a/tools/lib64gfx.h	Sat May 12 04:12:46 2018 +0300
+++ b/tools/lib64gfx.h	Sat May 12 04:46:08 2018 +0300
@@ -224,6 +224,8 @@
 int       dmC64ConvertCSDataToImage(DMImage *img, int xoffs, int yoffs, const Uint8 *inBuf, int width, int height, BOOL multicolor, int *colors);
 int       dmC64ImageGetNumBanks(const DMC64ImageFormat *fmt);
 BOOL      dmCompareAddr16(const Uint8 *buf, const size_t offs, const Uint16 addr);
+int       dmC64SanityCheckEncDecOp(const int i, const DMC64EncDecOp *op, const DMC64Image *img);
+BOOL      dmC64GetOpSize(const DMC64EncDecOp *op, const DMC64ImageFormat *fmt, size_t *size);
 
 
 // C64 bitmap image allocation/freeing