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