Mercurial > hg > dmlib
annotate tools/libgfx.h @ 1544:48823642c4fb
Cleanups.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Sat, 12 May 2018 21:00:22 +0300 |
parents | 416d7b3ba3b2 |
children | 3b613fcbf3ff |
rev | line source |
---|---|
435 | 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" | |
947
5ac8f5513978
Delete useless include line.
Matti Hamalainen <ccr@tnsp.org>
parents:
929
diff
changeset
|
12 |
435 | 13 |
14 #ifdef __cplusplus | |
15 extern "C" { | |
16 #endif | |
17 | |
18 | |
19 enum | |
20 { | |
1543
416d7b3ba3b2
Rename libgfx IMGFMT_* constants to DM_IMGFMT_*.
Matti Hamalainen <ccr@tnsp.org>
parents:
1341
diff
changeset
|
21 DM_IMGFMT_PNG, |
416d7b3ba3b2
Rename libgfx IMGFMT_* constants to DM_IMGFMT_*.
Matti Hamalainen <ccr@tnsp.org>
parents:
1341
diff
changeset
|
22 DM_IMGFMT_PPM, |
416d7b3ba3b2
Rename libgfx IMGFMT_* constants to DM_IMGFMT_*.
Matti Hamalainen <ccr@tnsp.org>
parents:
1341
diff
changeset
|
23 DM_IMGFMT_PCX, |
416d7b3ba3b2
Rename libgfx IMGFMT_* constants to DM_IMGFMT_*.
Matti Hamalainen <ccr@tnsp.org>
parents:
1341
diff
changeset
|
24 DM_IMGFMT_ILBM, |
416d7b3ba3b2
Rename libgfx IMGFMT_* constants to DM_IMGFMT_*.
Matti Hamalainen <ccr@tnsp.org>
parents:
1341
diff
changeset
|
25 DM_IMGFMT_RAW, |
416d7b3ba3b2
Rename libgfx IMGFMT_* constants to DM_IMGFMT_*.
Matti Hamalainen <ccr@tnsp.org>
parents:
1341
diff
changeset
|
26 DM_IMGFMT_ARAW, |
435 | 27 |
1543
416d7b3ba3b2
Rename libgfx IMGFMT_* constants to DM_IMGFMT_*.
Matti Hamalainen <ccr@tnsp.org>
parents:
1341
diff
changeset
|
28 DM_IMGFMT_LAST |
435 | 29 }; |
30 | |
31 | |
32 enum | |
33 { | |
34 DM_IFMT_PALETTE, | |
35 DM_IFMT_RGB, | |
36 DM_IFMT_RGBA, | |
37 }; | |
38 | |
39 | |
1544 | 40 // Error handling modes |
1285
e4bda4909d72
Make libgfx error mode a global variable, at least for now.
Matti Hamalainen <ccr@tnsp.org>
parents:
971
diff
changeset
|
41 enum |
e4bda4909d72
Make libgfx error mode a global variable, at least for now.
Matti Hamalainen <ccr@tnsp.org>
parents:
971
diff
changeset
|
42 { |
1544 | 43 DM_ERRMODE_FAIL = 0, |
1285
e4bda4909d72
Make libgfx error mode a global variable, at least for now.
Matti Hamalainen <ccr@tnsp.org>
parents:
971
diff
changeset
|
44 DM_ERRMODE_RECOV_1, |
e4bda4909d72
Make libgfx error mode a global variable, at least for now.
Matti Hamalainen <ccr@tnsp.org>
parents:
971
diff
changeset
|
45 DM_ERRMODE_RECOV_2, |
e4bda4909d72
Make libgfx error mode a global variable, at least for now.
Matti Hamalainen <ccr@tnsp.org>
parents:
971
diff
changeset
|
46 }; |
e4bda4909d72
Make libgfx error mode a global variable, at least for now.
Matti Hamalainen <ccr@tnsp.org>
parents:
971
diff
changeset
|
47 |
e4bda4909d72
Make libgfx error mode a global variable, at least for now.
Matti Hamalainen <ccr@tnsp.org>
parents:
971
diff
changeset
|
48 |
1544 | 49 // Probe scores |
50 enum | |
51 { | |
52 DM_PROBE_SCORE_FALSE = 0, | |
53 DM_PROBE_SCORE_MAYBE = 250, | |
54 DM_PROBE_SCORE_AVG = 500, | |
55 DM_PROBE_SCORE_GOOD = 750, | |
56 DM_PROBE_SCORE_MAX = 1000, | |
57 }; | |
58 | |
59 | |
1286 | 60 // Bitmapped image struct |
435 | 61 typedef struct |
62 { | |
1286 | 63 int format; // one of types specified by DM_IFMT_* |
64 int width, height; | |
65 int pitch; // bytes per scanline | |
66 int bpp; // bits per pixel | |
67 | |
68 int ncolors; // number of colors in palette, if any | |
69 int ctransp; // transparency color index | |
70 BOOL constpal; // is the palette a const? | |
71 DMColor *pal; // pointer to palette struct, NULL if no palette | |
72 | |
929
e1378398be0f
Add size field for allocated data size in DMImage.
Matti Hamalainen <ccr@tnsp.org>
parents:
902
diff
changeset
|
73 size_t size; |
435 | 74 Uint8 *data; |
75 } DMImage; | |
76 | |
77 | |
78 typedef struct | |
79 { | |
1288 | 80 int format; |
81 int scaleX, scaleY; | |
82 int nplanes, bpp; | |
1291 | 83 BOOL planar, paletted; |
1290
e7dc9bb9777e
Rename struct DMImageSpec to DMImageConvSpec.
Matti Hamalainen <ccr@tnsp.org>
parents:
1288
diff
changeset
|
84 } DMImageConvSpec; |
435 | 85 |
86 | |
87 typedef struct | |
88 { | |
89 char *fext; | |
90 char *desc; | |
91 int (*probe)(const Uint8 *buf, const size_t len); | |
92 int (*read)(const char *filename, DMImage **pimg); | |
93 int (*readFILE)(FILE *fp, DMImage **pimg); | |
1341 | 94 int (*write)(const char *filename, const DMImage *pimg, const DMImageConvSpec *spec); |
95 int (*writeFILE)(FILE *fp, const DMImage *pimg, const DMImageConvSpec *spec); | |
435 | 96 } DMImageFormat; |
97 | |
98 | |
1543
416d7b3ba3b2
Rename libgfx IMGFMT_* constants to DM_IMGFMT_*.
Matti Hamalainen <ccr@tnsp.org>
parents:
1341
diff
changeset
|
99 extern DMImageFormat dmImageFormatList[DM_IMGFMT_LAST]; |
1285
e4bda4909d72
Make libgfx error mode a global variable, at least for now.
Matti Hamalainen <ccr@tnsp.org>
parents:
971
diff
changeset
|
100 extern int dmGFXErrorMode; |
435 | 101 |
102 | |
1286 | 103 DMImage * dmImageAlloc(const int width, const int height, const int format, const int bpp); |
435 | 104 void dmImageFree(DMImage *img); |
1286 | 105 int dmImageGetBytesPerPixel(const int format); |
435 | 106 int dmImageProbeGeneric(const Uint8 *buf, const size_t len, DMImageFormat **fmt, int *index); |
107 | |
487
b89598501cec
Move dmCompareColor() to libgfx.
Matti Hamalainen <ccr@tnsp.org>
parents:
462
diff
changeset
|
108 BOOL dmCompareColor(const DMColor *c1, const DMColor *c2, BOOL alpha); |
b89598501cec
Move dmCompareColor() to libgfx.
Matti Hamalainen <ccr@tnsp.org>
parents:
462
diff
changeset
|
109 |
435 | 110 |
1341 | 111 int dmWriteImageData(const DMImage *img, void *cbdata, int (*writeRowCB)(void *, const Uint8 *, const size_t), const DMImageConvSpec *spec); |
435 | 112 |
1341 | 113 int dmWriteIFFMasterRAWPalette(FILE *fp, const DMImage *img, int ncolors, const char *indent, const char *type); |
114 int dmWriteRAWImageFILE(FILE *fp, const DMImage *img, const DMImageConvSpec *spec); | |
115 int dmWriteRAWImage(const char *filename, const DMImage *img, const DMImageConvSpec *spec); | |
435 | 116 |
1341 | 117 int dmWritePPMImageFILE(FILE *fp, const DMImage *img, const DMImageConvSpec *spec); |
118 int dmWritePPMImage(const char *filename, const DMImage *img, const DMImageConvSpec *spec); | |
435 | 119 |
120 #ifdef DM_USE_LIBPNG | |
1341 | 121 int dmWritePNGImageFILE(FILE *fp, const DMImage *img, const DMImageConvSpec *spec); |
122 int dmWritePNGImage(const char *filename, const DMImage *img, const DMImageConvSpec *spec); | |
435 | 123 #endif |
124 | |
1341 | 125 int dmReadILBMImageFILE(FILE *fp, DMImage **pimg); |
126 int dmReadILBMImage(const char *filename, DMImage **pimg); | |
127 | |
128 int dmWritePCXImageFILE(FILE *fp, const DMImage *img, const DMImageConvSpec *spec); | |
129 int dmWritePCXImage(const char *filename, const DMImage *img, const DMImageConvSpec *spec); | |
435 | 130 int dmReadPCXImageFILE(FILE *fp, DMImage **pimg); |
131 int dmReadPCXImage(const char *filename, DMImage **pimg); | |
132 | |
133 | |
1309
5ad7d780a09b
Move bitstream reading functions to libgfx, as they were only used there.
Matti Hamalainen <ccr@tnsp.org>
parents:
1307
diff
changeset
|
134 typedef struct _DMBitStreamContext |
5ad7d780a09b
Move bitstream reading functions to libgfx, as they were only used there.
Matti Hamalainen <ccr@tnsp.org>
parents:
1307
diff
changeset
|
135 { |
5ad7d780a09b
Move bitstream reading functions to libgfx, as they were only used there.
Matti Hamalainen <ccr@tnsp.org>
parents:
1307
diff
changeset
|
136 void *handle; |
5ad7d780a09b
Move bitstream reading functions to libgfx, as they were only used there.
Matti Hamalainen <ccr@tnsp.org>
parents:
1307
diff
changeset
|
137 |
5ad7d780a09b
Move bitstream reading functions to libgfx, as they were only used there.
Matti Hamalainen <ccr@tnsp.org>
parents:
1307
diff
changeset
|
138 BOOL (*putByte)(struct _DMBitStreamContext *ctx, Uint8 val); |
5ad7d780a09b
Move bitstream reading functions to libgfx, as they were only used there.
Matti Hamalainen <ccr@tnsp.org>
parents:
1307
diff
changeset
|
139 |
5ad7d780a09b
Move bitstream reading functions to libgfx, as they were only used there.
Matti Hamalainen <ccr@tnsp.org>
parents:
1307
diff
changeset
|
140 int outBuf, outBitCount, outByteCount; |
5ad7d780a09b
Move bitstream reading functions to libgfx, as they were only used there.
Matti Hamalainen <ccr@tnsp.org>
parents:
1307
diff
changeset
|
141 } DMBitStreamContext; |
5ad7d780a09b
Move bitstream reading functions to libgfx, as they were only used there.
Matti Hamalainen <ccr@tnsp.org>
parents:
1307
diff
changeset
|
142 |
5ad7d780a09b
Move bitstream reading functions to libgfx, as they were only used there.
Matti Hamalainen <ccr@tnsp.org>
parents:
1307
diff
changeset
|
143 |
5ad7d780a09b
Move bitstream reading functions to libgfx, as they were only used there.
Matti Hamalainen <ccr@tnsp.org>
parents:
1307
diff
changeset
|
144 void dmInitBitStreamContext(DMBitStreamContext *ctx); |
5ad7d780a09b
Move bitstream reading functions to libgfx, as they were only used there.
Matti Hamalainen <ccr@tnsp.org>
parents:
1307
diff
changeset
|
145 int dmFlushBitStream(DMBitStreamContext *ctx); |
5ad7d780a09b
Move bitstream reading functions to libgfx, as they were only used there.
Matti Hamalainen <ccr@tnsp.org>
parents:
1307
diff
changeset
|
146 BOOL dmPutBits(DMBitStreamContext *ctx, const int val, const int n); |
5ad7d780a09b
Move bitstream reading functions to libgfx, as they were only used there.
Matti Hamalainen <ccr@tnsp.org>
parents:
1307
diff
changeset
|
147 int dmInitBitStreamFILE(DMBitStreamContext *ctx, FILE *fp); |
5ad7d780a09b
Move bitstream reading functions to libgfx, as they were only used there.
Matti Hamalainen <ccr@tnsp.org>
parents:
1307
diff
changeset
|
148 |
5ad7d780a09b
Move bitstream reading functions to libgfx, as they were only used there.
Matti Hamalainen <ccr@tnsp.org>
parents:
1307
diff
changeset
|
149 |
5ad7d780a09b
Move bitstream reading functions to libgfx, as they were only used there.
Matti Hamalainen <ccr@tnsp.org>
parents:
1307
diff
changeset
|
150 |
435 | 151 #ifdef __cplusplus |
152 } | |
153 #endif | |
154 | |
155 #endif // LIBMGFX_H |