diff tools/libgfx.h @ 2207:1ea48084055e

Add functionality for separate palette file handling, reading, writing and probing similarly to image formats. For now, we only support ".ACT" palettes.
author Matti Hamalainen <ccr@tnsp.org>
date Fri, 14 Jun 2019 03:28:46 +0300
parents 455a3849b8ac
children 7a0af15fbe97
line wrap: on
line diff
--- a/tools/libgfx.h	Fri Jun 14 03:27:50 2019 +0300
+++ b/tools/libgfx.h	Fri Jun 14 03:28:46 2019 +0300
@@ -17,6 +17,7 @@
 #endif
 
 
+// Image formats
 enum
 {
     DM_IMGFMT_PNG,
@@ -31,6 +32,13 @@
 };
 
 
+// Palette formats
+enum
+{
+    DM_PALFMT_ACT,
+};
+
+
 // Color formats (these can be used along with DM_FMT_*)
 enum
 {
@@ -124,8 +132,23 @@
 } DMImageFormat;
 
 
+typedef struct
+{
+    char *fext;  // Typical filename extension
+    char *name;  // Format name / description
+    int  fmtid;  // DM_PALFMT_*
+    int  flags;  // DM_FMT_*
+
+    int  (*probe)(const Uint8 *buf, const size_t len);
+    int  (*read)(DMResource *fp, DMPalette **ppal);
+    int  (*write)(DMResource *fp, const DMPalette *ppal);
+} DMPaletteFormat;
+
+
 extern const DMImageFormat dmImageFormatList[];
 extern const int ndmImageFormatList;
+extern const DMPaletteFormat dmPaletteFormatList[];
+extern const int ndmPaletteFormatList;
 extern int dmGFXErrorMode;
 
 
@@ -136,11 +159,16 @@
 int       dmImageProbeGeneric(const Uint8 *buf, const size_t len, const DMImageFormat **fmt, int *index);
 int       dmGetNPlanesFromNColors(const int ncolors);
 
-BOOL dmCompareColor(const DMColor *c1, const DMColor *c2, const BOOL alpha);
-int  dmPaletteAlloc(DMPalette **ppal, const int ncolors, const int ctransp);
-int  dmPaletteResize(DMPalette **ppal, const int ncolors);
-void dmPaletteFree(DMPalette *pal);
-int  dmPaletteCopy(DMPalette **pdst, const DMPalette *src);
+BOOL      dmCompareColor(const DMColor *c1, const DMColor *c2, const BOOL alpha);
+int       dmPaletteAlloc(DMPalette **ppal, const int ncolors, const int ctransp);
+int       dmPaletteResize(DMPalette **ppal, const int ncolors);
+void      dmPaletteFree(DMPalette *pal);
+int       dmPaletteCopy(DMPalette **pdst, const DMPalette *src);
+int       dmPaletteProbeGeneric(const Uint8 *buf, const size_t len, const DMPaletteFormat **fmt, int *index);
+
+
+int dmReadACTPalette(DMResource *fp, DMPalette **pdst);
+int dmWriteACTPalette(DMResource *fp, const DMPalette *pdst);
 
 
 int dmWriteImageData(const DMImage *img, void *cbdata,