Mercurial > hg > dmlib
comparison 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 |
comparison
equal
deleted
inserted
replaced
1306:696c58784635 | 1307:43b13dbbdcd1 |
---|---|
1 /* | |
2 * Functions for loading and saving bitmap images | |
3 * Programmed and designed by Matti 'ccr' Hamalainen | |
4 * (C) Copyright 2012 Tecnic Software productions (TNSP) | |
5 * | |
6 * Please read file 'COPYING' for information on license and distribution. | |
7 */ | |
8 #ifndef LIBMGFX_H | |
9 #define LIBMGFX_H 1 | |
10 | |
11 #include "dmlib.h" | |
12 | |
13 | |
14 #ifdef __cplusplus | |
15 extern "C" { | |
16 #endif | |
17 | |
18 | |
19 enum | |
20 { | |
21 IMGFMT_PNG, | |
22 IMGFMT_PPM, | |
23 IMGFMT_PCX, | |
24 IMGFMT_ILBM, | |
25 IMGFMT_RAW, | |
26 IMGFMT_ARAW, | |
27 | |
28 IMGFMT_LAST | |
29 }; | |
30 | |
31 | |
32 enum | |
33 { | |
34 DM_IFMT_PALETTE, | |
35 DM_IFMT_RGB, | |
36 DM_IFMT_RGBA, | |
37 }; | |
38 | |
39 | |
40 enum | |
41 { | |
42 DM_ERRMODE_FAIL = 0, | |
43 DM_ERRMODE_RECOV_1, | |
44 DM_ERRMODE_RECOV_2, | |
45 }; | |
46 | |
47 | |
48 // Bitmapped image struct | |
49 typedef struct | |
50 { | |
51 int format; // one of types specified by DM_IFMT_* | |
52 int width, height; | |
53 int pitch; // bytes per scanline | |
54 int bpp; // bits per pixel | |
55 | |
56 int ncolors; // number of colors in palette, if any | |
57 int ctransp; // transparency color index | |
58 BOOL constpal; // is the palette a const? | |
59 DMColor *pal; // pointer to palette struct, NULL if no palette | |
60 | |
61 size_t size; | |
62 Uint8 *data; | |
63 } DMImage; | |
64 | |
65 | |
66 typedef struct | |
67 { | |
68 int format; | |
69 int scaleX, scaleY; | |
70 int nplanes, bpp; | |
71 BOOL planar, paletted; | |
72 } DMImageConvSpec; | |
73 | |
74 | |
75 typedef struct | |
76 { | |
77 char *fext; | |
78 char *desc; | |
79 int (*probe)(const Uint8 *buf, const size_t len); | |
80 int (*read)(const char *filename, DMImage **pimg); | |
81 int (*readFILE)(FILE *fp, DMImage **pimg); | |
82 int (*write)(const char *filename, DMImage *pimg, const DMImageConvSpec *spec); | |
83 int (*writeFILE)(FILE *fp, DMImage *pimg, const DMImageConvSpec *spec); | |
84 } DMImageFormat; | |
85 | |
86 | |
87 // Probe scores | |
88 #define DM_PROBE_SCORE_MAX 1000 | |
89 #define DM_PROBE_SCORE_GOOD 750 | |
90 #define DM_PROBE_SCORE_AVG 500 | |
91 #define DM_PROBE_SCORE_MAYBE 250 | |
92 #define DM_PROBE_SCORE_FALSE 0 | |
93 | |
94 | |
95 extern DMImageFormat dmImageFormatList[IMGFMT_LAST]; | |
96 extern int dmGFXErrorMode; | |
97 | |
98 | |
99 DMImage * dmImageAlloc(const int width, const int height, const int format, const int bpp); | |
100 void dmImageFree(DMImage *img); | |
101 int dmImageGetBytesPerPixel(const int format); | |
102 int dmImageProbeGeneric(const Uint8 *buf, const size_t len, DMImageFormat **fmt, int *index); | |
103 | |
104 BOOL dmCompareColor(const DMColor *c1, const DMColor *c2, BOOL alpha); | |
105 | |
106 | |
107 int dmWriteImageData(DMImage *img, void *cbdata, int (*writeRowCB)(void *, const Uint8 *, const size_t), const DMImageConvSpec *spec); | |
108 | |
109 int dmWriteIFFMasterRAWPalette(FILE *fp, DMImage *img, int ncolors, const char *indent, const char *type); | |
110 int dmWriteRAWImageFILE(FILE *fp, DMImage *img, const DMImageConvSpec *spec); | |
111 int dmWriteRAWImage(const char *filename, DMImage *img, const DMImageConvSpec *spec); | |
112 | |
113 int dmWritePPMImageFILE(FILE *fp, DMImage *img, const DMImageConvSpec *spec); | |
114 int dmWritePPMImage(const char *filename, DMImage *img, const DMImageConvSpec *spec); | |
115 | |
116 #ifdef DM_USE_LIBPNG | |
117 int dmWritePNGImageFILE(FILE *fp, DMImage *img, const DMImageConvSpec *spec); | |
118 int dmWritePNGImage(const char *filename, DMImage *img, const DMImageConvSpec *spec); | |
119 #endif | |
120 | |
121 int dmWritePCXImageFILE(FILE *fp, DMImage *img, const DMImageConvSpec *spec); | |
122 int dmWritePCXImage(const char *filename, DMImage *img, const DMImageConvSpec *spec); | |
123 int dmReadPCXImageFILE(FILE *fp, DMImage **pimg); | |
124 int dmReadPCXImage(const char *filename, DMImage **pimg); | |
125 | |
126 | |
127 #ifdef __cplusplus | |
128 } | |
129 #endif | |
130 | |
131 #endif // LIBMGFX_H |