changeset 1947:8896d5676f1b

Architectural change: remove some duplicated variables from DMC64Image structure and replace them with a pointer to DMC64ImageCommonFormat.
author Matti Hamalainen <ccr@tnsp.org>
date Fri, 29 Jun 2018 17:17:14 +0300
parents c30dfd5e3227
children 5790b52c339e
files tools/64vw.c tools/gfxconv.c tools/lib64gfx.c tools/lib64gfx.h
diffstat 4 files changed, 40 insertions(+), 47 deletions(-) [+]
line wrap: on
line diff
--- a/tools/64vw.c	Fri Jun 29 04:05:32 2018 +0300
+++ b/tools/64vw.c	Fri Jun 29 17:17:14 2018 +0300
@@ -464,7 +464,8 @@
 
             // Create surface (we are lazy and ugly)
             if ((surf = SDL_CreateRGBSurfaceWithFormat(0,
-                cimage->width, cimage->height, 8, SDL_PIXELFORMAT_INDEX8)) == NULL)
+                cimage->fmt->width, cimage->fmt->height,
+                8, SDL_PIXELFORMAT_INDEX8)) == NULL)
             {
                 dmC64ImageFree(cimage);
                 dmErrorMsg("Could not allocate surface.\n");
@@ -478,7 +479,7 @@
                     currIndex + 1,
                     noptFilenames2,
                     filename,
-                    cimage->width, cimage->height,
+                    cimage->fmt->width, cimage->fmt->height,
                     fmt->name);
 
                 if (dmVerbosity >= 1)
--- a/tools/gfxconv.c	Fri Jun 29 04:05:32 2018 +0300
+++ b/tools/gfxconv.c	Fri Jun 29 17:17:14 2018 +0300
@@ -1137,7 +1137,7 @@
     dst->d024    = src->d024;
 
     // Try to do some simple fixups
-    if ((dst->type & D64_FMT_FLI) && (src->type & D64_FMT_FLI) == 0)
+    if ((dst->fmt->type & D64_FMT_FLI) && (src->fmt->type & D64_FMT_FLI) == 0)
     {
         dmMsg(1, "Upconverting multicolor to FLI.\n");
         for (int i = 0; i < dst->nbanks; i++)
@@ -1153,7 +1153,7 @@
         }
     }
     else
-    if ((src->type & D64_FMT_FLI) && (dst->type & D64_FMT_FLI) == 0)
+    if ((src->fmt->type & D64_FMT_FLI) && (dst->fmt->type & D64_FMT_FLI) == 0)
     {
         dmMsg(1, "Downconverting FLI to multicolor.\n");
     }
--- a/tools/lib64gfx.c	Fri Jun 29 04:05:32 2018 +0300
+++ b/tools/lib64gfx.c	Fri Jun 29 17:17:14 2018 +0300
@@ -50,9 +50,7 @@
 
 void dmC64ImageDump(FILE *fh, const DMC64Image *img, const DMC64ImageFormat *fmt, const char *indent)
 {
-    char typeStr[64], typeStr2[64];
-
-    dmC64GetImageTypeString(typeStr, sizeof(typeStr), fmt->format->type, TRUE);
+    char typeStr[64];
 
     if (fmt != NULL)
     {
@@ -63,15 +61,15 @@
 
     if (img != NULL)
     {
-        dmC64GetImageTypeString(typeStr2, sizeof(typeStr2), img->type, TRUE);
+        dmC64GetImageTypeString(typeStr, sizeof(typeStr), img->fmt->type, TRUE);
 
         fprintf(fh,
-            "%sType                : %s [%s]\n"
+            "%sType                : %s\n"
             "%sBanks               : %d\n",
-            indent, typeStr, typeStr2,
+            indent, typeStr,
             indent, img->nbanks);
 
-        if (img->type & D64_FMT_ILACE)
+        if (img->fmt->type & D64_FMT_ILACE)
         {
             char *tmps;
             switch (img->laceType)
@@ -86,15 +84,15 @@
         }
 
         fprintf(fh,
-            "%sWidth x Height      : %d x %d [%d x %d]\n"
-            "%sCHwidth x CHheight  : %d x %d [%d x %d]\n",
-            indent, img->width, img->height,
-            fmt->format->width, fmt->format->height,
-            indent, img->chWidth, img->chHeight,
-            fmt->format->chWidth, fmt->format->chHeight);
+            "%sWidth x Height      : %d x %d\n"
+            "%sCHwidth x CHheight  : %d x %d\n",
+            indent, img->fmt->width, img->fmt->height,
+            indent, img->fmt->chWidth, img->fmt->chHeight);
     }
     else
+    if (fmt != NULL)
     {
+        dmC64GetImageTypeString(typeStr, sizeof(typeStr), fmt->format->type, TRUE);
         fprintf(fh,
             "%sType                : %s\n"
             "%sWidth x Height      : %d x %d\n"
@@ -224,11 +222,7 @@
         return NULL;
 
     // Initialize image information
-    img->type        = fmt->format->type;
-    img->width       = fmt->format->width;
-    img->height      = fmt->format->height;
-    img->chWidth     = fmt->format->chWidth;
-    img->chHeight    = fmt->format->chHeight;
+    img->fmt         = fmt->format;
     img->nbanks      = dmC64ImageGetNumBanks(fmt);
 
     // Allocate banks
@@ -861,11 +855,6 @@
         return DMERR_NULLPTR;
 
     // Clear the image structure, set basics
-    img->type      = fmt->format->type;
-    img->width     = fmt->format->width;
-    img->height    = fmt->format->height;
-    img->chWidth   = fmt->format->chWidth;
-    img->chHeight  = fmt->format->chHeight;
     img->nbanks    = dmC64ImageGetNumBanks(fmt);
 
     // Perform decoding
@@ -1238,39 +1227,40 @@
     if (dst == NULL || src == NULL || fmt == NULL || spec == NULL)
         return DMERR_NULLPTR;
 
-    if (dst->width < src->width || dst->height < src->height)
+    if (dst->width != src->fmt->width || dst->height != src->fmt->height)
     {
         return dmError(DMERR_INVALID_DATA,
             "Invalid src vs. dst width/height %d x %d <-> %d x %d\n",
-            src->width, src->height, dst->width, dst->height);
+            src->fmt->width, src->fmt->height, dst->width, dst->height);
     }
 
     dmMemset(dst->data, 0, dst->size);
 
     // Check pixel getter function
-    if (fmt->format->getPixel != NULL)
-        getPixel = fmt->format->getPixel;
+    if (src->fmt->getPixel != NULL)
+        getPixel = src->fmt->getPixel;
     else
-        getPixel = (fmt->format->type & D64_FMT_MC) ? fmtGetGenericMCPixel : fmtGetGenericSCPixel;
+        getPixel = (src->fmt->type & D64_FMT_MC) ? fmtGetGenericMCPixel : fmtGetGenericSCPixel;
 
     // Resolution interlaced pics need to halve the source width
-    int rwidth = src->width;
-    if ((src->type & D64_FMT_ILACE) && src->laceType == D64_ILACE_RES)
+    int rwidth = dst->width, rheight = dst->height;
+    if ((src->fmt->type & D64_FMT_ILACE) &&
+        src->laceType == D64_ILACE_RES)
         rwidth /= 2;
 
     // Perform conversion
-    for (int yc = 0; yc < src->height; yc++)
+    for (int yc = 0; yc < rheight; yc++)
     {
         Uint8 *dp = dst->data + (yc * dst->pitch);
         const int y = yc / 8, yb = yc & 7;
-        const int scroffsy = y * src->chWidth;
-        const int bmoffsy = y * src->chWidth * 8 + yb;
+        const int scroffsy = y * src->fmt->chWidth;
+        const int bmoffsy = y * src->fmt->chWidth * 8 + yb;
 
         for (int xc = 0; xc < rwidth; xc++)
-        if (src->type & D64_FMT_CHAR)
+        if (src->fmt->type & D64_FMT_CHAR)
         {
             // Charmode conversion
-            if ((src->type & D64_FMT_MC) == D64_FMT_HIRES)
+            if ((src->fmt->type & D64_FMT_MC) == D64_FMT_HIRES)
             {
                 // Hi-res charmap
                 const int x = xc / 8;
@@ -1315,7 +1305,7 @@
         else
         {
             // Perform generic BITMAP conversion
-            if ((src->type & D64_FMT_MC) == D64_FMT_HIRES)
+            if ((src->fmt->type & D64_FMT_MC) == D64_FMT_HIRES)
             {
                 // Hi-res bitmap
                 const int x = xc / 8;
@@ -1333,7 +1323,7 @@
                 const int bmoffs = bmoffsy + (x * 8);
                 const int vshift = 6 - ((xc * 2) & 6);
 
-                if (src->type & D64_FMT_ILACE)
+                if (src->fmt->type & D64_FMT_ILACE)
                 {
                     switch (src->laceType)
                     {
@@ -1348,7 +1338,10 @@
                 }
                 else
                 {
-                    *dp++ = getPixel(src, bmoffs, scroffs, vshift, 0, xc, yc);
+                    const Uint8 col = getPixel(src, bmoffs, scroffs, vshift, 0, xc, yc);
+                    *dp++ = col;
+                    if (spec->aspect)
+                        *dp++ = col;
                 }
             }
         }
@@ -1368,7 +1361,8 @@
         return DMERR_NULLPTR;
 
     // Allocate image structure
-    if ((*pdst = dst = dmImageAlloc(src->width, src->height, DM_COLFMT_PALETTE, -1)) == NULL)
+    if ((*pdst = dst = dmImageAlloc(
+        src->fmt->width, src->fmt->height, DM_COLFMT_PALETTE, -1)) == NULL)
         return DMERR_MALLOC;
 
     // Set partial palette information
--- a/tools/lib64gfx.h	Fri Jun 29 04:05:32 2018 +0300
+++ b/tools/lib64gfx.h	Fri Jun 29 17:17:14 2018 +0300
@@ -151,10 +151,8 @@
 
 typedef struct _DMC64Image
 {
-    int type,                // Image type (D64_FMT_*)
-        width, height,       // Width and height in pixels
-        chWidth, chHeight,   // Width and height in charblocks
-        laceType,            // Interlace type (D64_ILACE_*)
+    DMC64ImageCommonFormat *fmt;
+    int laceType,            // Interlace type (D64_ILACE_*)
         nbanks;              // Number of video banks used
 
     // Bitmaps, color RAM, screen, etc. blocks * nbanks