changeset 1482:df6dacb48970

Rename some struct members, and sanitize handling of DMC64Image allocation more.
author Matti Hamalainen <ccr@tnsp.org>
date Fri, 11 May 2018 03:29:55 +0300
parents e967e8e3b8c3
children 1e7f7489d3e0
files tools/64vw.c tools/lib64gfx.c tools/lib64gfx.h
diffstat 3 files changed, 31 insertions(+), 22 deletions(-) [+]
line wrap: on
line diff
--- a/tools/64vw.c	Fri May 11 02:49:28 2018 +0300
+++ b/tools/64vw.c	Fri May 11 03:29:55 2018 +0300
@@ -204,7 +204,7 @@
         "Width x Height      : %d x %d\n"
         "CHwidth x CHheight  : %d x %d\n",
         img->width, img->height,
-        img->ch_width, img->ch_height);
+        img->chWidth, img->chHeight);
 }
 
 
--- a/tools/lib64gfx.c	Fri May 11 02:49:28 2018 +0300
+++ b/tools/lib64gfx.c	Fri May 11 03:29:55 2018 +0300
@@ -84,10 +84,14 @@
     // Initialize image information
     img->width     = fmt->width;
     img->height    = fmt->height;
-    img->ch_width  = fmt->ch_width;
-    img->ch_height = fmt->ch_height;
+    img->chWidth   = fmt->chWidth;
+    img->chHeight  = fmt->chHeight;
     img->nbanks    = dmC64ImageGetNumBanks(fmt);
 
+    img->screenSize = img->chWidth * img->chHeight;
+    img->bitmapSize = img->screenSize * 8;
+    img->charmemSize = C64_MAX_CHARS * C64_CHR_SIZE;
+
     // Allocate banks
     if ((img->color = dmCalloc(img->nbanks, sizeof(Uint8 *))) == NULL ||
         (img->bitmap = dmCalloc(img->nbanks, sizeof(Uint8 *))) == NULL ||
@@ -97,16 +101,16 @@
 
     for (int i = 0; i < img->nbanks; i++)
     {
-        if ((img->color[i] = dmMalloc0(img->ch_width * img->ch_height)) == NULL)
+        if ((img->color[i] = dmMalloc0(img->screenSize)) == NULL)
             goto err;
 
-        if ((img->bitmap[i] = dmMalloc0(img->ch_width * img->ch_height * 8)) == NULL)
+        if ((img->bitmap[i] = dmMalloc0(img->bitmapSize)) == NULL)
             goto err;
 
-        if ((img->screen[i] = dmMalloc0(img->ch_width * img->ch_height)) == NULL)
+        if ((img->screen[i] = dmMalloc0(img->screenSize)) == NULL)
             goto err;
 
-        if ((img->charmem[i] = dmMalloc0(C64_MAX_CHARS * C64_CHR_SIZE)) == NULL)
+        if ((img->charmem[i] = dmMalloc0(img->charmemSize)) == NULL)
             goto err;
     }
 
@@ -1220,12 +1224,12 @@
     {
         case DT_SCREEN_RAM:
         case DT_COLOR_RAM:
-            *size = fmt->ch_height * fmt->ch_width;
+            *size = fmt->chHeight * fmt->chWidth;
             check = TRUE;
             break;
 
         case DT_BITMAP:
-            *size = fmt->ch_height * fmt->ch_width * 8;
+            *size = fmt->chHeight * fmt->chWidth * 8;
             check = TRUE;
             break;
 
@@ -1273,8 +1277,8 @@
     img->type      = fmt->type;
     img->width     = fmt->width;
     img->height    = fmt->height;
-    img->ch_width  = fmt->ch_width;
-    img->ch_height = fmt->ch_height;
+    img->chWidth   = fmt->chWidth;
+    img->chHeight  = fmt->chHeight;
     img->nbanks    = dmC64ImageGetNumBanks(fmt);
 
     // Perform decoding
@@ -1381,7 +1385,7 @@
                     case D64_CHCFG_LINEAR:
                         {
                             for (int bank = 0; bank < img->nbanks; bank++)
-                            for (int offs = 0; offs < fmt->ch_height * fmt->ch_width; offs++)
+                            for (int offs = 0; offs < fmt->chHeight * fmt->chWidth; offs++)
                                 img->screen[bank][offs] = offs & 0xff;
                         }
                         break;
@@ -1395,14 +1399,14 @@
                 break;
 
             case DT_DEC_FUNCTION:
-                if (op->decfunction == NULL)
+                if (op->decFunction == NULL)
                 {
                     return dmError(DMERR_INTERNAL,
                         "Decode op is a function, but function ptr is NULL: "
                         "op #%d, offs=%d ($%04x), bank=%d, size=%d ($%04x) @ %d ($%04x)\n",
                         i, op->offs, op->offs, op->bank, size, size, len, len);
                 }
-                if (!op->decfunction(img, op, buf, len))
+                if (!op->decFunction(img, op, buf, len))
                 {
                     return dmError(DMERR_INTERNAL,
                         "Decode op custom function failed: op #%d, "
@@ -1527,7 +1531,7 @@
                 break;
 
             case DT_ENC_FUNCTION:
-                if (op->encfunction == NULL)
+                if (op->encFunction == NULL)
                 {
                     res = dmError(DMERR_INTERNAL,
                         "Encode op is a function, but function ptr is NULL: "
@@ -1536,7 +1540,7 @@
                     goto err;
                 }
                 /*
-                if (!op->encfunction(op, buf, len))
+                if (!op->encFunction(op, buf, len))
                 {
                     res = dmError(DMERR_INTERNAL,
                         "Encode op custom function failed: op #%d, "
@@ -1592,7 +1596,7 @@
     {
         Uint8 *d = dp;
         const int y = yc / 8, yb = yc & 7;
-        const int scroffsy = y * src->ch_width;
+        const int scroffsy = y * src->chWidth;
         int xc;
 
         if (src->type & D64_FMT_CHAR)
@@ -1645,7 +1649,7 @@
         else
         {
             // Perform generic BITMAP conversion
-            const int bmoffsy = y * src->ch_width * 8 + yb;
+            const int bmoffsy = y * src->chWidth * 8 + yb;
 
             if ((src->type & D64_FMT_MC) == D64_FMT_HIRES)
             // Hi-res bitmap
--- a/tools/lib64gfx.h	Fri May 11 02:49:28 2018 +0300
+++ b/tools/lib64gfx.h	Fri May 11 03:29:55 2018 +0300
@@ -106,7 +106,12 @@
         nbanks;
 
     int width, height; // Width and height in pixels
-    int ch_width, ch_height; // Width and height in charblocks
+    int chWidth, chHeight; // Width and height in charblocks
+
+    size_t
+        screenSize,
+        bitmapSize,
+        charmemSize;
 
     Uint8
         **color,
@@ -153,8 +158,8 @@
     size_t offs;
     int    bank;
     size_t size;
-    BOOL   (*decfunction)(DMC64Image *img, const struct _DMC64EncDecOp *op, const Uint8 *buf, const size_t len);
-    BOOL   (*encfunction)(const struct _DMC64EncDecOp *op, Uint8 **buf, size_t *len, const DMC64Image *img);
+    BOOL   (*decFunction)(DMC64Image *img, const struct _DMC64EncDecOp *op, const Uint8 *buf, const size_t len);
+    BOOL   (*encFunction)(const struct _DMC64EncDecOp *op, Uint8 **buf, size_t *len, const DMC64Image *img);
 } DMC64EncDecOp;
 
 
@@ -168,7 +173,7 @@
     size_t size; // Size, including loading address. Only used in encoding, if even there (0 if no static size)
 
     int width, height; // Width and height in pixels
-    int ch_width, ch_height; // Width and height in charblocks
+    int chWidth, chHeight; // Width and height in charblocks
 
     int  (*probe)(const Uint8 *buf, const size_t len, const struct _DMC64ImageFormat *fmt);