diff tools/lib64gfx.h @ 2129:2129d4ac6f45

Refactor c64 image rendering completely to be more flexible.
author Matti Hamalainen <ccr@tnsp.org>
date Mon, 27 May 2019 11:29:37 +0300
parents 56d4dc81774b
children 6528a1398e8e
line wrap: on
line diff
--- a/tools/lib64gfx.h	Mon May 27 11:28:19 2019 +0300
+++ b/tools/lib64gfx.h	Mon May 27 11:29:37 2019 +0300
@@ -202,9 +202,7 @@
 typedef DMC64EncDecOp DMC64EncDecOpList[D64_MAX_ENCDEC_OPS];
 
 
-typedef Uint8 (*DMC64GetPixelFunc)(
-    const DMC64Image *img, const int bmoffs, const int scroffs,
-    const int shiftX, const int bitmap, const int rasterX, const int rasterY);
+typedef int (*DMC64GetPixelFunc)(Uint8 *col, const DMC64Image *img, const int rasterX, const int rasterY);
 
 
 typedef struct _DMC64ImageCommonFormat
@@ -370,51 +368,58 @@
 
 
 //
+// Macros for defining variables used in getpixel functions
+//
+#define DM_C64_GENERIC_SC_PIXEL_DEFS(ximg) \
+    const int \
+        x = rasterX / 8, \
+        y = rasterY / 8, \
+        yoffs = y * ximg->fmt->chWidth, \
+        bmoffs = yoffs * 8 + (rasterY & 7) + (x * 8), \
+        scroffs = yoffs + x, \
+        vshift = 7 - (rasterX & 7);
+
+
+#define DM_C64_GENERIC_MC_PIXEL_DEFS(ximg) \
+    const int \
+        x = rasterX / 4, \
+        y = rasterY / 8, \
+        yoffs = y * (ximg)->fmt->chWidth, \
+        bmoffs = yoffs * 8 + (rasterY & 7) + (x * 8), \
+        scroffs = yoffs + x, \
+        vshift = 6 - ((rasterX * 2) & 6);
+
+
+//
 // Inline helper functions for pixel format decoding
 //
-static inline Uint8 dmC64GetGenericSCPixel(
+static inline int dmC64GetGenericSCPixel(Uint8 *col,
     const DMC64Image *img, const int bmoffs, const int scroffs,
-    const int shiftX, const int vbank, const int bitmap, const int cbank)
+    const int vshift, const int vbank, const int bitmap)
 {
-    (void) cbank;
-    if ((img->bitmap[bitmap].data[bmoffs] >> shiftX) & 1)
-        return img->screen[vbank].data[scroffs] >> 4;
+    if ((img->bitmap[bitmap].data[bmoffs] >> vshift) & 1)
+        *col = img->screen[vbank].data[scroffs] >> 4;
     else
-        return img->screen[vbank].data[scroffs] & 15;
+        *col = img->screen[vbank].data[scroffs] & 15;
+
+    return DMERR_OK;
 }
 
 
-static inline Uint8 dmC64GetGenericMCPixel(
-    const DMC64Image *img, const int bmoffs, const int scroffs,
-    const int shiftX, const int vbank, const int bitmap, const int cbank, const int bgcolor)
-{
-    switch ((img->bitmap[bitmap].data[bmoffs] >> shiftX) & 3)
-    {
-        case  0: return bgcolor;
-        case  1: return img->screen[vbank].data[scroffs] >> 4;
-        case  2: return img->screen[vbank].data[scroffs] & 15;
-        default: return img->color[cbank].data[scroffs] & 15;
-    }
-}
-
-
-static inline Uint8 fmtGetGenericSCPixel(
+static inline int dmC64GetGenericMCPixel(Uint8 *col,
     const DMC64Image *img, const int bmoffs, const int scroffs,
-    const int shiftX, const int bitmap, const int rasterX, const int rasterY)
+    const int vshift, const int vbank, const int bitmap,
+    const int cbank, const int bgcolor)
 {
-    (void) rasterX;
-    (void) rasterY;
-    return dmC64GetGenericSCPixel(img, bmoffs, scroffs, shiftX, 0, bitmap, 0);
-}
-
+    switch ((img->bitmap[bitmap].data[bmoffs] >> vshift) & 3)
+    {
+        case  0: *col = bgcolor; break;
+        case  1: *col = img->screen[vbank].data[scroffs] >> 4; break;
+        case  2: *col = img->screen[vbank].data[scroffs] & 15; break;
+        default: *col = img->color[cbank].data[scroffs] & 15; break;
+    }
 
-static inline Uint8 fmtGetGenericMCPixel(
-    const DMC64Image *img, const int bmoffs, const int scroffs,
-    const int shiftX, const int bitmap, const int rasterX, const int rasterY)
-{
-    (void) rasterX;
-    (void) rasterY;
-    return dmC64GetGenericMCPixel(img, bmoffs, scroffs, shiftX, 0, bitmap, 0, img->bgcolor);
+    return DMERR_OK;
 }