Mercurial > hg > dmlib
annotate tools/libgfx.h @ 1759:027fb7313d85
Add a format flag for marking formats that have broken/incomplete support and use it.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Mon, 11 Jun 2018 18:09:00 +0300 |
parents | 59c2b08a80a6 |
children | 0562dd55a1f6 |
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 }; |
29 | |
30 | |
31 enum | |
32 { | |
33 DM_IFMT_PALETTE, | |
34 DM_IFMT_RGB, | |
35 DM_IFMT_RGBA, | |
36 }; | |
37 | |
38 | |
1544 | 39 // 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
|
40 enum |
e4bda4909d72
Make libgfx error mode a global variable, at least for now.
Matti Hamalainen <ccr@tnsp.org>
parents:
971
diff
changeset
|
41 { |
1544 | 42 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
|
43 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
|
44 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
|
45 }; |
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 |
1544 | 48 // Probe scores |
49 enum | |
50 { | |
51 DM_PROBE_SCORE_FALSE = 0, | |
52 DM_PROBE_SCORE_MAYBE = 250, | |
53 DM_PROBE_SCORE_AVG = 500, | |
54 DM_PROBE_SCORE_GOOD = 750, | |
55 DM_PROBE_SCORE_MAX = 1000, | |
56 }; | |
57 | |
58 | |
1545
3b613fcbf3ff
Improve how format read/write capabilities are marked and shown.
Matti Hamalainen <ccr@tnsp.org>
parents:
1544
diff
changeset
|
59 // 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
|
60 enum |
3b613fcbf3ff
Improve how format read/write capabilities are marked and shown.
Matti Hamalainen <ccr@tnsp.org>
parents:
1544
diff
changeset
|
61 { |
1759
027fb7313d85
Add a format flag for marking formats that have broken/incomplete support and use it.
Matti Hamalainen <ccr@tnsp.org>
parents:
1733
diff
changeset
|
62 DM_FMT_WR = 0x0001, // Format can be written |
027fb7313d85
Add a format flag for marking formats that have broken/incomplete support and use it.
Matti Hamalainen <ccr@tnsp.org>
parents:
1733
diff
changeset
|
63 DM_FMT_RD = 0x0002, // Format can be read |
027fb7313d85
Add a format flag for marking formats that have broken/incomplete support and use it.
Matti Hamalainen <ccr@tnsp.org>
parents:
1733
diff
changeset
|
64 DM_FMT_RDWR = (DM_FMT_RD | DM_FMT_WR), // Read and write support |
027fb7313d85
Add a format flag for marking formats that have broken/incomplete support and use it.
Matti Hamalainen <ccr@tnsp.org>
parents:
1733
diff
changeset
|
65 DM_FMT_BROKEN = 0x1000, // Support is broken/incomplete |
1545
3b613fcbf3ff
Improve how format read/write capabilities are marked and shown.
Matti Hamalainen <ccr@tnsp.org>
parents:
1544
diff
changeset
|
66 }; |
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 |
1609
c29adf5ce240
Convert libgfx file format routines to use DMResource instead of stdio FILE.
Matti Hamalainen <ccr@tnsp.org>
parents:
1545
diff
changeset
|
69 // Bitmapped image struct |
435 | 70 typedef struct |
71 { | |
1286 | 72 int format; // one of types specified by DM_IFMT_* |
73 int width, height; | |
74 int pitch; // bytes per scanline | |
75 int bpp; // bits per pixel | |
76 | |
1628
a549d33d543a
Add image aspect ratio information.
Matti Hamalainen <ccr@tnsp.org>
parents:
1616
diff
changeset
|
77 float aspect; // aspect ratio (vert / horiz), <= 0 if not set |
a549d33d543a
Add image aspect ratio information.
Matti Hamalainen <ccr@tnsp.org>
parents:
1616
diff
changeset
|
78 |
1286 | 79 int ncolors; // number of colors in palette, if any |
80 int ctransp; // transparency color index | |
81 BOOL constpal; // is the palette a const? | |
82 DMColor *pal; // pointer to palette struct, NULL if no palette | |
83 | |
929
e1378398be0f
Add size field for allocated data size in DMImage.
Matti Hamalainen <ccr@tnsp.org>
parents:
902
diff
changeset
|
84 size_t size; |
435 | 85 Uint8 *data; |
86 } DMImage; | |
87 | |
88 | |
89 typedef struct | |
90 { | |
1288 | 91 int format; |
92 int scaleX, scaleY; | |
93 int nplanes, bpp; | |
1291 | 94 BOOL planar, paletted; |
1290
e7dc9bb9777e
Rename struct DMImageSpec to DMImageConvSpec.
Matti Hamalainen <ccr@tnsp.org>
parents:
1288
diff
changeset
|
95 } DMImageConvSpec; |
435 | 96 |
97 | |
98 typedef struct | |
99 { | |
100 char *fext; | |
1616
36d073c45327
Refactor the format handling a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
1609
diff
changeset
|
101 char *name; |
36d073c45327
Refactor the format handling a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
1609
diff
changeset
|
102 int fmtid; // DM_IMGFMT_* |
36d073c45327
Refactor the format handling a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
1609
diff
changeset
|
103 int flags; // DM_FMT_* flags |
435 | 104 int (*probe)(const Uint8 *buf, const size_t len); |
105 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
|
106 int (*readFILE)(DMResource *fp, DMImage **pimg); |
1341 | 107 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
|
108 int (*writeFILE)(DMResource *fp, const DMImage *pimg, const DMImageConvSpec *spec); |
435 | 109 } DMImageFormat; |
110 | |
111 | |
1616
36d073c45327
Refactor the format handling a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
1609
diff
changeset
|
112 extern const DMImageFormat dmImageFormatList[]; |
36d073c45327
Refactor the format handling a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
1609
diff
changeset
|
113 extern const int ndmImageFormatList; |
1285
e4bda4909d72
Make libgfx error mode a global variable, at least for now.
Matti Hamalainen <ccr@tnsp.org>
parents:
971
diff
changeset
|
114 extern int dmGFXErrorMode; |
435 | 115 |
116 | |
1286 | 117 DMImage * dmImageAlloc(const int width, const int height, const int format, const int bpp); |
435 | 118 void dmImageFree(DMImage *img); |
1286 | 119 int dmImageGetBytesPerPixel(const int format); |
1616
36d073c45327
Refactor the format handling a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
1609
diff
changeset
|
120 int dmImageProbeGeneric(const Uint8 *buf, const size_t len, const DMImageFormat **fmt, int *index); |
435 | 121 |
487
b89598501cec
Move dmCompareColor() to libgfx.
Matti Hamalainen <ccr@tnsp.org>
parents:
462
diff
changeset
|
122 BOOL dmCompareColor(const DMColor *c1, const DMColor *c2, BOOL alpha); |
1733
59c2b08a80a6
Make some palette allocation functions public.
Matti Hamalainen <ccr@tnsp.org>
parents:
1628
diff
changeset
|
123 BOOL dmPaletteAlloc(DMColor **ppal, int ncolors, int ctransp); |
59c2b08a80a6
Make some palette allocation functions public.
Matti Hamalainen <ccr@tnsp.org>
parents:
1628
diff
changeset
|
124 BOOL dmImagePaletteAlloc(DMImage *img, int ncolors, int ctransp); |
487
b89598501cec
Move dmCompareColor() to libgfx.
Matti Hamalainen <ccr@tnsp.org>
parents:
462
diff
changeset
|
125 |
435 | 126 |
1341 | 127 int dmWriteImageData(const DMImage *img, void *cbdata, int (*writeRowCB)(void *, const Uint8 *, const size_t), const DMImageConvSpec *spec); |
435 | 128 |
1609
c29adf5ce240
Convert libgfx file format routines to use DMResource instead of stdio FILE.
Matti Hamalainen <ccr@tnsp.org>
parents:
1545
diff
changeset
|
129 int dmWriteRAWImageFILE(DMResource *fp, const DMImage *img, const DMImageConvSpec *spec); |
1341 | 130 int dmWriteRAWImage(const char *filename, const DMImage *img, const DMImageConvSpec *spec); |
435 | 131 |
1609
c29adf5ce240
Convert libgfx file format routines to use DMResource instead of stdio FILE.
Matti Hamalainen <ccr@tnsp.org>
parents:
1545
diff
changeset
|
132 int dmWritePPMImageFILE(DMResource *fp, const DMImage *img, const DMImageConvSpec *spec); |
1341 | 133 int dmWritePPMImage(const char *filename, const DMImage *img, const DMImageConvSpec *spec); |
435 | 134 |
135 #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
|
136 int dmWritePNGImageFILE(DMResource *fp, const DMImage *img, const DMImageConvSpec *spec); |
1341 | 137 int dmWritePNGImage(const char *filename, const DMImage *img, const DMImageConvSpec *spec); |
435 | 138 #endif |
139 | |
1609
c29adf5ce240
Convert libgfx file format routines to use DMResource instead of stdio FILE.
Matti Hamalainen <ccr@tnsp.org>
parents:
1545
diff
changeset
|
140 int dmReadILBMImageFILE(DMResource *fp, DMImage **pimg); |
1341 | 141 int dmReadILBMImage(const char *filename, DMImage **pimg); |
142 | |
1609
c29adf5ce240
Convert libgfx file format routines to use DMResource instead of stdio FILE.
Matti Hamalainen <ccr@tnsp.org>
parents:
1545
diff
changeset
|
143 int dmWritePCXImageFILE(DMResource *fp, const DMImage *img, const DMImageConvSpec *spec); |
1341 | 144 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
|
145 int dmReadPCXImageFILE(DMResource *fp, DMImage **pimg); |
435 | 146 int dmReadPCXImage(const char *filename, DMImage **pimg); |
147 | |
148 | |
1309
5ad7d780a09b
Move bitstream reading functions to libgfx, as they were only used there.
Matti Hamalainen <ccr@tnsp.org>
parents:
1307
diff
changeset
|
149 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
|
150 { |
5ad7d780a09b
Move bitstream reading functions to libgfx, as they were only used there.
Matti Hamalainen <ccr@tnsp.org>
parents:
1307
diff
changeset
|
151 void *handle; |
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 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
|
154 |
5ad7d780a09b
Move bitstream reading functions to libgfx, as they were only used there.
Matti Hamalainen <ccr@tnsp.org>
parents:
1307
diff
changeset
|
155 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
|
156 } DMBitStreamContext; |
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 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
|
160 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
|
161 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
|
162 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
|
163 |
5ad7d780a09b
Move bitstream reading functions to libgfx, as they were only used there.
Matti Hamalainen <ccr@tnsp.org>
parents:
1307
diff
changeset
|
164 |
5ad7d780a09b
Move bitstream reading functions to libgfx, as they were only used there.
Matti Hamalainen <ccr@tnsp.org>
parents:
1307
diff
changeset
|
165 |
435 | 166 #ifdef __cplusplus |
167 } | |
168 #endif | |
169 | |
170 #endif // LIBMGFX_H |