diff tools/libgfx.h @ 1307:43b13dbbdcd1

Moved libgfx to tools/ as it's not really a very generic piece of code that belongs to the engine ..
author Matti Hamalainen <ccr@tnsp.org>
date Sat, 19 Aug 2017 15:18:29 +0300
parents src/libgfx.h@e03f20d0f785
children 5ad7d780a09b
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tools/libgfx.h	Sat Aug 19 15:18:29 2017 +0300
@@ -0,0 +1,131 @@
+/*
+ * Functions for loading and saving bitmap images
+ * Programmed and designed by Matti 'ccr' Hamalainen
+ * (C) Copyright 2012 Tecnic Software productions (TNSP)
+ *
+ * Please read file 'COPYING' for information on license and distribution.
+ */
+#ifndef LIBMGFX_H
+#define LIBMGFX_H 1
+
+#include "dmlib.h"
+
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+
+enum
+{
+    IMGFMT_PNG,
+    IMGFMT_PPM,
+    IMGFMT_PCX,
+    IMGFMT_ILBM,
+    IMGFMT_RAW,
+    IMGFMT_ARAW,
+
+    IMGFMT_LAST
+};
+
+
+enum
+{
+    DM_IFMT_PALETTE,
+    DM_IFMT_RGB,
+    DM_IFMT_RGBA,
+};
+
+
+enum
+{
+    DM_ERRMODE_FAIL     = 0,
+    DM_ERRMODE_RECOV_1,
+    DM_ERRMODE_RECOV_2,
+};
+
+
+// Bitmapped image struct 
+typedef struct
+{
+    int format;     // one of types specified by DM_IFMT_*
+    int width, height;
+    int pitch;      // bytes per scanline
+    int bpp;        // bits per pixel
+
+    int ncolors;    // number of colors in palette, if any
+    int ctransp;    // transparency color index
+    BOOL constpal;  // is the palette a const?
+    DMColor *pal;   // pointer to palette struct, NULL if no palette
+
+    size_t size;
+    Uint8 *data;
+} DMImage;
+
+
+typedef struct
+{
+    int format;
+    int scaleX, scaleY;
+    int nplanes, bpp;
+    BOOL planar, paletted;
+} DMImageConvSpec;
+
+
+typedef struct
+{
+    char *fext;
+    char *desc;
+    int  (*probe)(const Uint8 *buf, const size_t len);
+    int  (*read)(const char *filename, DMImage **pimg);
+    int  (*readFILE)(FILE *fp, DMImage **pimg);
+    int  (*write)(const char *filename, DMImage *pimg, const DMImageConvSpec *spec);
+    int  (*writeFILE)(FILE *fp, DMImage *pimg, const DMImageConvSpec *spec);
+} DMImageFormat;
+
+
+// Probe scores
+#define DM_PROBE_SCORE_MAX     1000
+#define DM_PROBE_SCORE_GOOD    750
+#define DM_PROBE_SCORE_AVG     500
+#define DM_PROBE_SCORE_MAYBE   250
+#define DM_PROBE_SCORE_FALSE   0
+
+
+extern DMImageFormat dmImageFormatList[IMGFMT_LAST];
+extern int dmGFXErrorMode;
+
+
+DMImage * dmImageAlloc(const int width, const int height, const int format, const int bpp);
+void      dmImageFree(DMImage *img);
+int       dmImageGetBytesPerPixel(const int format);
+int       dmImageProbeGeneric(const Uint8 *buf, const size_t len, DMImageFormat **fmt, int *index);
+
+BOOL dmCompareColor(const DMColor *c1, const DMColor *c2, BOOL alpha);
+
+
+int dmWriteImageData(DMImage *img, void *cbdata, int (*writeRowCB)(void *, const Uint8 *, const size_t), const DMImageConvSpec *spec);
+
+int dmWriteIFFMasterRAWPalette(FILE *fp, DMImage *img, int ncolors, const char *indent, const char *type);
+int dmWriteRAWImageFILE(FILE *fp, DMImage *img, const DMImageConvSpec *spec);
+int dmWriteRAWImage(const char *filename, DMImage *img, const DMImageConvSpec *spec);
+
+int dmWritePPMImageFILE(FILE *fp, DMImage *img, const DMImageConvSpec *spec);
+int dmWritePPMImage(const char *filename, DMImage *img, const DMImageConvSpec *spec);
+
+#ifdef DM_USE_LIBPNG
+int dmWritePNGImageFILE(FILE *fp, DMImage *img, const DMImageConvSpec *spec);
+int dmWritePNGImage(const char *filename, DMImage *img, const DMImageConvSpec *spec);
+#endif
+
+int dmWritePCXImageFILE(FILE *fp, DMImage *img, const DMImageConvSpec *spec);
+int dmWritePCXImage(const char *filename, DMImage *img, const DMImageConvSpec *spec);
+int dmReadPCXImageFILE(FILE *fp, DMImage **pimg);
+int dmReadPCXImage(const char *filename, DMImage **pimg);
+
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif // LIBMGFX_H