diff tools/lib64gfx.h @ 1503:c7b9ef56319b

Factor all the c64 file format specific things into lib64fmt.c
author Matti Hamalainen <ccr@tnsp.org>
date Fri, 11 May 2018 07:41:55 +0300
parents 32640e1934d5
children 3265175b24d2
line wrap: on
line diff
--- a/tools/lib64gfx.h	Fri May 11 07:20:58 2018 +0300
+++ b/tools/lib64gfx.h	Fri May 11 07:41:55 2018 +0300
@@ -51,6 +51,14 @@
 #define C64_MAX_CHARS          256
 
 
+#define DM_RLE_MARKER    1
+#define DM_RLE_MASK      2
+
+
+#define DM_GET_ADDR_LO(addr) ((addr) & 0xff)
+#define DM_GET_ADDR_HI(addr) (((addr) >> 8) & 0xff)
+
+
 // Different supported C64 bitmap "modes"
 enum
 {
@@ -190,22 +198,31 @@
 } DMC64ImageFormat;
 
 
+//
+// Global variables
+//
 extern DMColor           dmDefaultC64Palette[C64_NCOLORS];
 extern const DMC64ImageFormat  dmC64ImageFormats[];
 extern const int         ndmC64ImageFormats;
 
 
+//
+// Miscellaneous functions
+//
 void      dmC64ImageDump(FILE *fh, const DMC64Image *img, const DMC64ImageFormat *fmt);
 void      dmSetDefaultC64Palette(DMImage *img);
 char *    dmC64GetImageTypeString(char *buf, const size_t len, const int type, const BOOL lng);
+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);
 
 
+// C64 bitmap image allocation/freeing
 DMC64Image *dmC64ImageAlloc(const DMC64ImageFormat *fmt);
 void      dmC64ImageFree(DMC64Image *img);
 
 
-int       dmC64ConvertCSDataToImage(DMImage *img, int xoffs, int yoffs, const Uint8 *inBuf, int width, int height, BOOL multicolor, int *colors);
-
+// Encoding and decoding of formats and images
 int       dmC64ProbeBMP(const Uint8 *buf, const size_t len, const DMC64ImageFormat **fmt);
 
 int       dmC64DecodeGenericBMP(DMC64Image *img, const Uint8 *buf, const size_t len, const DMC64ImageFormat *fmt);
@@ -220,6 +237,65 @@
 int       dmC64ConvertGenericBMP2Image(DMImage *dst, const DMC64Image *src, const DMC64ImageFormat *fmt);
 int       dmC64ConvertGenericImage2BMP(DMC64Image *dst, const DMImage *src, const DMC64ImageFormat *fmt);
 
+void dmGenericRLEAnalyze(const DMGrowBuf *buf, Uint8 *rleMarker, const int rleType);
+
+int dmDecodeGenericRLE(DMGrowBuf *dst, const Uint8 *src, const Uint8 *srcEnd,
+    const Uint8 rleMarker, const Uint8 rleMask1, const Uint8 rleMask2, const int rleType);
+int dmDecodeGenericRLEAlloc(DMGrowBuf *dst, const Uint8 *src, const Uint8 *srcEnd,
+    const Uint8 rleMarker, const Uint8 rleMask1, const Uint8 rleMask2, const int rleType);
+
+int dmEncodeGenericRLE(DMGrowBuf *dst, const Uint8 *src, const Uint8 *srcEnd,
+    const Uint8 rleMarker, const Uint8 rleMinCount, const Uint8 rleMaxCount, const int rleType);
+int dmEncodeGenericRLEAlloc(DMGrowBuf *dst, const Uint8 *src, const Uint8 *srcEnd,
+    const Uint8 rleMarker, const Uint8 rleMinCount, const Uint8 rleMaxCount, const int rleType);
+
+
+//
+// Inline helper functions for pixel format decoding
+//
+static inline Uint8 dmC64GetGenericSCPixel(
+    const DMC64Image *img, const int bmoffs, const int scroffs,
+    const int vshift, const int vbank, const int vbitmap, const int cbank)
+{
+    (void) cbank;
+    if ((img->bitmap[vbitmap][bmoffs] >> vshift) & 1)
+        return img->screen[vbank][scroffs] >> 4;
+    else
+        return img->screen[vbank][scroffs] & 15;
+}
+
+
+static inline Uint8 dmC64GetGenericMCPixel(
+    const DMC64Image *img, const int bmoffs, const int scroffs,
+    const int vshift, const int vbank, const int vbitmap, const int cbank)
+{
+    switch ((img->bitmap[vbitmap][bmoffs] >> vshift) & 3)
+    {
+        case  0: return img->bgcolor; break;
+        case  1: return img->screen[vbank][scroffs] >> 4; break;
+        case  2: return img->screen[vbank][scroffs] & 15; break;
+        default: return img->color[cbank][scroffs] & 15; break;
+    }
+}
+
+
+static inline Uint8 fmtGetGenericSCPixel(
+    const DMC64Image *img, const int bmoffs, const int scroffs,
+    const int vshift, const int vbitmap, const int raster)
+{
+    (void) raster;
+    return dmC64GetGenericSCPixel(img, bmoffs, scroffs, vshift, 0, vbitmap, 0);
+}
+
+
+static inline Uint8 fmtGetGenericMCPixel(
+    const DMC64Image *img, const int bmoffs, const int scroffs,
+    const int vshift, const int vbitmap, const int raster)
+{
+    (void) raster;
+    return dmC64GetGenericMCPixel(img, bmoffs, scroffs, vshift, 0, vbitmap, 0);
+}
+
 
 #ifdef __cplusplus
 }