changeset 2224:a36c81c3df85

Make color interlace type generate a mixed palette instead of using special decode functions for it.
author Matti Hamalainen <ccr@tnsp.org>
date Fri, 14 Jun 2019 12:13:23 +0300
parents 5477e792def3
children 837c79747ea4
files tools/64vw.c tools/lib64fmts.c tools/lib64gfx.c tools/lib64gfx.h
diffstat 4 files changed, 28 insertions(+), 53 deletions(-) [+]
line wrap: on
line diff
--- a/tools/64vw.c	Fri Jun 14 12:12:19 2019 +0300
+++ b/tools/64vw.c	Fri Jun 14 12:13:23 2019 +0300
@@ -228,7 +228,7 @@
 int dmDecodeC64Image(DMC64Image *cimage, SDL_Surface *surf, const DMC64ImageConvSpec *spec)
 {
     DMImage bmap;
-    BOOL charDataSet;
+    BOOL charDataSet, mixedPalette;
     int res;
 
     memset(&bmap, 0, sizeof(bmap));
@@ -237,8 +237,9 @@
     bmap.pitch    = surf->pitch;
     bmap.width    = surf->w;
     bmap.height   = surf->h;
-    
-    if ((res = dmPaletteCopy(&bmap.pal, spec->pal)) != DMERR_OK)
+
+    mixedPalette  = (cimage->fmt->type & D64_FMT_ILACE) && cimage->laceType == D64_ILACE_COLOR;
+    if ((res = dmC64SetImagePalette(&bmap, spec, mixedPalette)) != DMERR_OK)
     {
         dmErrorMsg("Could not create copy of palette.\n");
         return res;
--- a/tools/lib64fmts.c	Fri Jun 14 12:12:19 2019 +0300
+++ b/tools/lib64fmts.c	Fri Jun 14 12:13:23 2019 +0300
@@ -745,17 +745,6 @@
 }
 
 
-static int fmtTruePaintGetLaceType(const DMC64EncDecOp *op, DMC64Image *img,
-    const DMGrowBuf *buf, const DMC64ImageCommonFormat *fmt)
-{
-    (void) op;
-    (void) buf;
-    (void) fmt;
-    img->laceType = D64_ILACE_RES;
-    return DMERR_OK;
-}
-
-
 static int fmtGetPixelTruePaint(Uint8 *col,
     const DMC64Image *img, const int rasterX, const int rasterY)
 {
@@ -1512,17 +1501,6 @@
 }
 
 
-static int fmtECIGetLaceType(const DMC64EncDecOp *op, DMC64Image *img,
-    const DMGrowBuf *buf, const DMC64ImageCommonFormat *fmt)
-{
-    (void) op;
-    (void) buf;
-    (void) fmt;
-    img->laceType = D64_ILACE_COLOR;
-    return DMERR_OK;
-}
-
-
 static int fmtGetPixelECI(Uint8 *col,
     const DMC64Image *img, const int rasterX, const int rasterY)
 {
@@ -1540,18 +1518,6 @@
 }
 
 
-static int fmtConvertECIBMP2Image(DMImage *dst, const DMC64Image *src,
-    const DMC64ImageFormat *fmt, const DMC64ImageConvSpec *spec)
-{
-    int res;
-
-    if ((res = dmC64SetImagePalette(dst, spec, TRUE)) != DMERR_OK)
-        return res;
-
-    return dmC64ConvertGenericBMP2Image(dst, src, fmt, spec);
-}
-
-
 static int fmtProbeECIPacked(const DMGrowBuf *buf, const DMC64ImageFormat *fmt)
 {
     int score = DM_PROBE_SCORE_FALSE;
@@ -1720,15 +1686,15 @@
         NULL, NULL,
         fmtGetPixelFunPaint2,
         {
-            DEF_REPEAT_BLOCK_8(DS_SCREEN_RAM, 0x0000, 0, 0x400, 0, DF_NORMAL),
-            { DO_COPY       , DS_BITMAP_RAM  , 0x2000, 0,  0  , 0, NULL, NULL, DF_NORMAL },
-            { DO_COPY       , DS_EXTRA_DATA  , 0x3f48, 0,  100, 0, NULL, NULL, DF_NORMAL },
-            { DO_COPY       , DS_COLOR_RAM   , 0x4000, 0,  0  , 0, NULL, NULL, DF_NORMAL },
-            DEF_REPEAT_BLOCK_8(DS_SCREEN_RAM, 0x43e8, 8, 0x400, 0, DF_NORMAL),
-            { DO_COPY       , DS_BITMAP_RAM  , 0x63e8, 1,  0  , 0, NULL, NULL, DF_NORMAL },
-            { DO_COPY       , DS_EXTRA_DATA  , 0x8328, 0,  100, 100, NULL, NULL, DF_NORMAL },
-            { DO_FUNC       , 0              , 0     , 0,  1  , 0, fmtTruePaintGetLaceType, NULL, DF_NORMAL },
-            { DO_LAST       , 0              , 0     , 0,  0  , 0, NULL, NULL, DF_NORMAL },
+            DEF_REPEAT_BLOCK_8(DS_SCREEN_RAM , 0x0000, 0,  0x400, 0, DF_NORMAL),
+            { DO_COPY       , DS_BITMAP_RAM  , 0x2000, 0,  0    , 0, NULL, NULL, DF_NORMAL },
+            { DO_COPY       , DS_EXTRA_DATA  , 0x3f48, 0,  100  , 0, NULL, NULL, DF_NORMAL },
+            { DO_COPY       , DS_COLOR_RAM   , 0x4000, 0,  0    , 0, NULL, NULL, DF_NORMAL },
+            DEF_REPEAT_BLOCK_8(DS_SCREEN_RAM , 0x43e8, 8,  0x400, 0, DF_NORMAL),
+            { DO_COPY       , DS_BITMAP_RAM  , 0x63e8, 1,  0    , 0, NULL, NULL, DF_NORMAL },
+            { DO_COPY       , DS_EXTRA_DATA  , 0x8328, 0,  100  , 100, NULL, NULL, DF_NORMAL },
+            { DO_SET_OP     , DS_ILACE_TYPE  , D64_ILACE_RES, 0 , 0  , 0, NULL, NULL, DF_DECODE },
+            { DO_LAST       , 0              , 0     , 0,  0    , 0, NULL, NULL, DF_NORMAL },
         }
     },
 
@@ -1780,24 +1746,24 @@
             { DO_COPY       , DS_BITMAP_RAM  , 0x2400, 1,  0,   0, NULL, NULL, DF_NORMAL },
             { DO_COPY       , DS_SCREEN_RAM  , 0x4400, 1,  0,   0, NULL, NULL, DF_NORMAL },
             { DO_COPY       , DS_COLOR_RAM   , 0x4800, 0,  0,   0, NULL, NULL, DF_NORMAL },
-            { DO_FUNC       , 0              , 0x0000, 0,  0,   0, fmtTruePaintGetLaceType, NULL, DF_NORMAL },
+            { DO_SET_OP     , DS_ILACE_TYPE  , D64_ILACE_RES, 0 , 0  , 0, NULL, NULL, DF_DECODE },
             { DO_LAST       , 0              , 0     , 0,  0,   0, NULL, NULL, DF_NORMAL },
         }
     },
 
     { // #7: ECI Graphic Editor Hires FLI
-        D64_FMT_HIRES | D64_FMT_FLI,
+        D64_FMT_HIRES | D64_FMT_FLI | D64_FMT_ILACE,
         D64_SCR_WIDTH,    D64_SCR_HEIGHT,
         D64_SCR_CH_WIDTH, D64_SCR_CH_HEIGHT,
         1, 1,
-        fmtConvertECIBMP2Image, NULL,
+        NULL, NULL,
         fmtGetPixelECI,
         {
             { DO_COPY       , DS_BITMAP_RAM  , 0x0000, 0,  0,   0, NULL, NULL, DF_NORMAL },
             DEF_REPEAT_BLOCK_8(DS_SCREEN_RAM , 0x2000, 0, 0x400, 0, DF_NORMAL),
             { DO_COPY       , DS_BITMAP_RAM  , 0x4000, 1,  0,   0, NULL, NULL, DF_NORMAL },
             DEF_REPEAT_BLOCK_8(DS_SCREEN_RAM , 0x6000, 8, 0x400, 0, DF_NORMAL),
-            { DO_FUNC       , 0              , 0     , 0,  0,   0, fmtECIGetLaceType, NULL, DF_NORMAL },
+            { DO_SET_OP     , DS_ILACE_TYPE  , D64_ILACE_COLOR, 0 , 0  , 0, NULL, NULL, DF_DECODE },
             { DO_LAST       , 0              , 0     , 0,  0,   0, NULL, NULL, DF_NORMAL },
         }
     },
@@ -2463,7 +2429,7 @@
                 // GunPaint does not store the last 3 d021 values .. so set them to black
                 // XXX TODO: According to some, the last 4 should be same ..
                 { DO_SET_MEM    , DS_EXTRA_DATA  , 0     , 0,  3  , 20+177, NULL, NULL, DF_NORMAL },
-                { DO_FUNC       , 0              , 0x2742, 0,  1  , 0, fmtTruePaintGetLaceType, NULL, DF_NORMAL },
+                { DO_SET_OP     , DS_ILACE_TYPE  , D64_ILACE_RES, 0 , 0  , 0, NULL, NULL, DF_DECODE },
                 { DO_FUNC       , 0              , 0     , 0,  0  , 0, NULL, fmtEncodeGunPaint, DF_NORMAL },
                 { DO_LAST       , 0              , 0     , 0,  0  , 0, NULL, NULL, DF_NORMAL },
             }
--- a/tools/lib64gfx.c	Fri Jun 14 12:12:19 2019 +0300
+++ b/tools/lib64gfx.c	Fri Jun 14 12:13:23 2019 +0300
@@ -1043,6 +1043,7 @@
                     case DS_D022:
                     case DS_D023:
                     case DS_D024:
+                    case DS_ILACE_TYPE:
                         switch (op->type)
                         {
                             case DO_COPY:
@@ -1076,6 +1077,7 @@
                             case DS_D022: img->d022 = value; break;
                             case DS_D023: img->d023 = value; break;
                             case DS_D024: img->d024 = value; break;
+                            case DS_ILACE_TYPE: img->laceType = value; break;
                         }
                         break;
 
@@ -1249,6 +1251,7 @@
                     case DS_D022:
                     case DS_D023:
                     case DS_D024:
+                    case DS_ILACE_TYPE:
                         switch (op->subject)
                         {
                             case DS_D020: value = img->d020; break;
@@ -1257,6 +1260,7 @@
                             case DS_D022: value = img->d022; break;
                             case DS_D023: value = img->d023; break;
                             case DS_D024: value = img->d024; break;
+                            case DS_ILACE_TYPE: value = img->laceType; break;
                         }
                         switch (op->type)
                         {
@@ -1434,8 +1438,9 @@
 
 int dmC64ConvertBMP2Image(DMImage **pdst, const DMC64Image *src, const DMC64ImageConvSpec *spec)
 {
+    DMImage *dst;
+    BOOL mixed;
     int res;
-    DMImage *dst;
 
     if (pdst == NULL || src == NULL || spec == NULL)
         return DMERR_NULLPTR;
@@ -1446,7 +1451,8 @@
         return DMERR_MALLOC;
 
     // Set palette information
-    if ((res = dmC64SetImagePalette(dst, spec, FALSE)) != DMERR_OK)
+    mixed = (src->fmt->type & D64_FMT_ILACE) && src->laceType == D64_ILACE_COLOR;
+    if ((res = dmC64SetImagePalette(dst, spec, mixed)) != DMERR_OK)
         return res;
 
     // Convert
--- a/tools/lib64gfx.h	Fri Jun 14 12:12:19 2019 +0300
+++ b/tools/lib64gfx.h	Fri Jun 14 12:13:23 2019 +0300
@@ -132,6 +132,8 @@
     DS_D023,
     DS_D024,
 
+    DS_ILACE_TYPE,
+
     DS_LAST
 };