Mercurial > hg > dmlib
comparison 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 |
comparison
equal
deleted
inserted
replaced
2206:7694b5c8edc1 | 2207:1ea48084055e |
---|---|
15 #ifdef __cplusplus | 15 #ifdef __cplusplus |
16 extern "C" { | 16 extern "C" { |
17 #endif | 17 #endif |
18 | 18 |
19 | 19 |
20 // Image formats | |
20 enum | 21 enum |
21 { | 22 { |
22 DM_IMGFMT_PNG, | 23 DM_IMGFMT_PNG, |
23 DM_IMGFMT_PPM, | 24 DM_IMGFMT_PPM, |
24 DM_IMGFMT_PCX, | 25 DM_IMGFMT_PCX, |
29 DM_IMGFMT_ARAW, | 30 DM_IMGFMT_ARAW, |
30 DM_IMGFMT_CDUMP, | 31 DM_IMGFMT_CDUMP, |
31 }; | 32 }; |
32 | 33 |
33 | 34 |
35 // Palette formats | |
36 enum | |
37 { | |
38 DM_PALFMT_ACT, | |
39 }; | |
40 | |
41 | |
34 // Color formats (these can be used along with DM_FMT_*) | 42 // Color formats (these can be used along with DM_FMT_*) |
35 enum | 43 enum |
36 { | 44 { |
37 DM_PIXFMT_PALETTE = 0x0010, | 45 DM_PIXFMT_PALETTE = 0x0010, |
38 DM_PIXFMT_GRAYSCALE = 0x0020, | 46 DM_PIXFMT_GRAYSCALE = 0x0020, |
122 int (*read)(DMResource *fp, DMImage **pimg); | 130 int (*read)(DMResource *fp, DMImage **pimg); |
123 int (*write)(DMResource *fp, const DMImage *pimg, const DMImageWriteSpec *spec); | 131 int (*write)(DMResource *fp, const DMImage *pimg, const DMImageWriteSpec *spec); |
124 } DMImageFormat; | 132 } DMImageFormat; |
125 | 133 |
126 | 134 |
135 typedef struct | |
136 { | |
137 char *fext; // Typical filename extension | |
138 char *name; // Format name / description | |
139 int fmtid; // DM_PALFMT_* | |
140 int flags; // DM_FMT_* | |
141 | |
142 int (*probe)(const Uint8 *buf, const size_t len); | |
143 int (*read)(DMResource *fp, DMPalette **ppal); | |
144 int (*write)(DMResource *fp, const DMPalette *ppal); | |
145 } DMPaletteFormat; | |
146 | |
147 | |
127 extern const DMImageFormat dmImageFormatList[]; | 148 extern const DMImageFormat dmImageFormatList[]; |
128 extern const int ndmImageFormatList; | 149 extern const int ndmImageFormatList; |
150 extern const DMPaletteFormat dmPaletteFormatList[]; | |
151 extern const int ndmPaletteFormatList; | |
129 extern int dmGFXErrorMode; | 152 extern int dmGFXErrorMode; |
130 | 153 |
131 | 154 |
132 DMImage * dmImageAlloc(const int width, const int height, const int format, const int bpp); | 155 DMImage * dmImageAlloc(const int width, const int height, const int format, const int bpp); |
133 void dmImageFree(DMImage *img); | 156 void dmImageFree(DMImage *img); |
134 int dmImageGetBytesPerPixel(const int format); | 157 int dmImageGetBytesPerPixel(const int format); |
135 int dmImageGetBitsPerPixel(const int format); | 158 int dmImageGetBitsPerPixel(const int format); |
136 int dmImageProbeGeneric(const Uint8 *buf, const size_t len, const DMImageFormat **fmt, int *index); | 159 int dmImageProbeGeneric(const Uint8 *buf, const size_t len, const DMImageFormat **fmt, int *index); |
137 int dmGetNPlanesFromNColors(const int ncolors); | 160 int dmGetNPlanesFromNColors(const int ncolors); |
138 | 161 |
139 BOOL dmCompareColor(const DMColor *c1, const DMColor *c2, const BOOL alpha); | 162 BOOL dmCompareColor(const DMColor *c1, const DMColor *c2, const BOOL alpha); |
140 int dmPaletteAlloc(DMPalette **ppal, const int ncolors, const int ctransp); | 163 int dmPaletteAlloc(DMPalette **ppal, const int ncolors, const int ctransp); |
141 int dmPaletteResize(DMPalette **ppal, const int ncolors); | 164 int dmPaletteResize(DMPalette **ppal, const int ncolors); |
142 void dmPaletteFree(DMPalette *pal); | 165 void dmPaletteFree(DMPalette *pal); |
143 int dmPaletteCopy(DMPalette **pdst, const DMPalette *src); | 166 int dmPaletteCopy(DMPalette **pdst, const DMPalette *src); |
167 int dmPaletteProbeGeneric(const Uint8 *buf, const size_t len, const DMPaletteFormat **fmt, int *index); | |
168 | |
169 | |
170 int dmReadACTPalette(DMResource *fp, DMPalette **pdst); | |
171 int dmWriteACTPalette(DMResource *fp, const DMPalette *pdst); | |
144 | 172 |
145 | 173 |
146 int dmWriteImageData(const DMImage *img, void *cbdata, | 174 int dmWriteImageData(const DMImage *img, void *cbdata, |
147 int (*writeRowCB)(void *, const Uint8 *, const size_t), const DMImageWriteSpec *spec); | 175 int (*writeRowCB)(void *, const Uint8 *, const size_t), const DMImageWriteSpec *spec); |
148 | 176 |