annotate 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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
435
e4a3f183e463 Modularize some more.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1 /*
e4a3f183e463 Modularize some more.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
2 * Functions for loading and saving bitmap images
e4a3f183e463 Modularize some more.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
3 * Programmed and designed by Matti 'ccr' Hamalainen
2066
63284e9ad95e Bump copyright.
Matti Hamalainen <ccr@tnsp.org>
parents: 2065
diff changeset
4 * (C) Copyright 2012-2018 Tecnic Software productions (TNSP)
435
e4a3f183e463 Modularize some more.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
5 *
e4a3f183e463 Modularize some more.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
6 * Please read file 'COPYING' for information on license and distribution.
e4a3f183e463 Modularize some more.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
7 */
e4a3f183e463 Modularize some more.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
8 #ifndef LIBMGFX_H
e4a3f183e463 Modularize some more.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
9 #define LIBMGFX_H 1
e4a3f183e463 Modularize some more.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
10
e4a3f183e463 Modularize some more.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
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
e4a3f183e463 Modularize some more.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
14
e4a3f183e463 Modularize some more.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
15 #ifdef __cplusplus
e4a3f183e463 Modularize some more.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
16 extern "C" {
e4a3f183e463 Modularize some more.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
17 #endif
e4a3f183e463 Modularize some more.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
18
e4a3f183e463 Modularize some more.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
19
2207
1ea48084055e Add functionality for separate palette file handling, reading, writing and
Matti Hamalainen <ccr@tnsp.org>
parents: 2202
diff changeset
20 // Image formats
435
e4a3f183e463 Modularize some more.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
21 enum
e4a3f183e463 Modularize some more.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
22 {
1543
416d7b3ba3b2 Rename libgfx IMGFMT_* constants to DM_IMGFMT_*.
Matti Hamalainen <ccr@tnsp.org>
parents: 1341
diff changeset
23 DM_IMGFMT_PNG,
416d7b3ba3b2 Rename libgfx IMGFMT_* constants to DM_IMGFMT_*.
Matti Hamalainen <ccr@tnsp.org>
parents: 1341
diff changeset
24 DM_IMGFMT_PPM,
416d7b3ba3b2 Rename libgfx IMGFMT_* constants to DM_IMGFMT_*.
Matti Hamalainen <ccr@tnsp.org>
parents: 1341
diff changeset
25 DM_IMGFMT_PCX,
2064
3617ef01c1de Separate ILBM and PBM subformats of IFF images.
Matti Hamalainen <ccr@tnsp.org>
parents: 2047
diff changeset
26 DM_IMGFMT_IFF_ILBM,
3617ef01c1de Separate ILBM and PBM subformats of IFF images.
Matti Hamalainen <ccr@tnsp.org>
parents: 2047
diff changeset
27 DM_IMGFMT_IFF_PBM,
2068
e4dc8fbaa5ad Improve IFF probing.
Matti Hamalainen <ccr@tnsp.org>
parents: 2066
diff changeset
28 DM_IMGFMT_IFF_ACBM,
1543
416d7b3ba3b2 Rename libgfx IMGFMT_* constants to DM_IMGFMT_*.
Matti Hamalainen <ccr@tnsp.org>
parents: 1341
diff changeset
29 DM_IMGFMT_RAW,
416d7b3ba3b2 Rename libgfx IMGFMT_* constants to DM_IMGFMT_*.
Matti Hamalainen <ccr@tnsp.org>
parents: 1341
diff changeset
30 DM_IMGFMT_ARAW,
2047
3829c292df02 Add 'cdump' image output format, mainly for debugging purposes.
Matti Hamalainen <ccr@tnsp.org>
parents: 1921
diff changeset
31 DM_IMGFMT_CDUMP,
435
e4a3f183e463 Modularize some more.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
32 };
e4a3f183e463 Modularize some more.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
33
e4a3f183e463 Modularize some more.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
34
2207
1ea48084055e Add functionality for separate palette file handling, reading, writing and
Matti Hamalainen <ccr@tnsp.org>
parents: 2202
diff changeset
35 // Palette formats
1ea48084055e Add functionality for separate palette file handling, reading, writing and
Matti Hamalainen <ccr@tnsp.org>
parents: 2202
diff changeset
36 enum
1ea48084055e Add functionality for separate palette file handling, reading, writing and
Matti Hamalainen <ccr@tnsp.org>
parents: 2202
diff changeset
37 {
1ea48084055e Add functionality for separate palette file handling, reading, writing and
Matti Hamalainen <ccr@tnsp.org>
parents: 2202
diff changeset
38 DM_PALFMT_ACT,
1ea48084055e Add functionality for separate palette file handling, reading, writing and
Matti Hamalainen <ccr@tnsp.org>
parents: 2202
diff changeset
39 };
1ea48084055e Add functionality for separate palette file handling, reading, writing and
Matti Hamalainen <ccr@tnsp.org>
parents: 2202
diff changeset
40
1ea48084055e Add functionality for separate palette file handling, reading, writing and
Matti Hamalainen <ccr@tnsp.org>
parents: 2202
diff changeset
41
2095
80786a28caf0 Mark image format flags with the color formats they support.
Matti Hamalainen <ccr@tnsp.org>
parents: 2094
diff changeset
42 // Color formats (these can be used along with DM_FMT_*)
435
e4a3f183e463 Modularize some more.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
43 enum
e4a3f183e463 Modularize some more.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
44 {
2157
9a9493809b3a Rename DM_COLFMT_* constants to DM_PIXFMT_* and the 'format' field of DMImage
Matti Hamalainen <ccr@tnsp.org>
parents: 2156
diff changeset
45 DM_PIXFMT_PALETTE = 0x0010,
9a9493809b3a Rename DM_COLFMT_* constants to DM_PIXFMT_* and the 'format' field of DMImage
Matti Hamalainen <ccr@tnsp.org>
parents: 2156
diff changeset
46 DM_PIXFMT_GRAYSCALE = 0x0020,
9a9493809b3a Rename DM_COLFMT_* constants to DM_PIXFMT_* and the 'format' field of DMImage
Matti Hamalainen <ccr@tnsp.org>
parents: 2156
diff changeset
47 DM_PIXFMT_RGB = 0x0040,
9a9493809b3a Rename DM_COLFMT_* constants to DM_PIXFMT_* and the 'format' field of DMImage
Matti Hamalainen <ccr@tnsp.org>
parents: 2156
diff changeset
48 DM_PIXFMT_RGBA = 0x0080,
2095
80786a28caf0 Mark image format flags with the color formats they support.
Matti Hamalainen <ccr@tnsp.org>
parents: 2094
diff changeset
49
2157
9a9493809b3a Rename DM_COLFMT_* constants to DM_PIXFMT_* and the 'format' field of DMImage
Matti Hamalainen <ccr@tnsp.org>
parents: 2156
diff changeset
50 DM_PIXFMT_ANY = 0x00f0,
435
e4a3f183e463 Modularize some more.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
51 };
e4a3f183e463 Modularize some more.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
52
e4a3f183e463 Modularize some more.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
53
1544
48823642c4fb Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 1543
diff changeset
54 // 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
55 enum
e4bda4909d72 Make libgfx error mode a global variable, at least for now.
Matti Hamalainen <ccr@tnsp.org>
parents: 971
diff changeset
56 {
1544
48823642c4fb Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 1543
diff changeset
57 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
58 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
59 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
60 };
e4bda4909d72 Make libgfx error mode a global variable, at least for now.
Matti Hamalainen <ccr@tnsp.org>
parents: 971
diff changeset
61
e4bda4909d72 Make libgfx error mode a global variable, at least for now.
Matti Hamalainen <ccr@tnsp.org>
parents: 971
diff changeset
62
1544
48823642c4fb Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 1543
diff changeset
63 // Probe scores
48823642c4fb Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 1543
diff changeset
64 enum
48823642c4fb Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 1543
diff changeset
65 {
48823642c4fb Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 1543
diff changeset
66 DM_PROBE_SCORE_FALSE = 0,
48823642c4fb Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 1543
diff changeset
67 DM_PROBE_SCORE_MAYBE = 250,
48823642c4fb Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 1543
diff changeset
68 DM_PROBE_SCORE_AVG = 500,
48823642c4fb Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 1543
diff changeset
69 DM_PROBE_SCORE_GOOD = 750,
48823642c4fb Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 1543
diff changeset
70 DM_PROBE_SCORE_MAX = 1000,
48823642c4fb Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 1543
diff changeset
71 };
48823642c4fb Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 1543
diff changeset
72
48823642c4fb Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 1543
diff changeset
73
1545
3b613fcbf3ff Improve how format read/write capabilities are marked and shown.
Matti Hamalainen <ccr@tnsp.org>
parents: 1544
diff changeset
74 // 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
75 enum
3b613fcbf3ff Improve how format read/write capabilities are marked and shown.
Matti Hamalainen <ccr@tnsp.org>
parents: 1544
diff changeset
76 {
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
77 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
78 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
79 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
80 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
81 };
3b613fcbf3ff Improve how format read/write capabilities are marked and shown.
Matti Hamalainen <ccr@tnsp.org>
parents: 1544
diff changeset
82
3b613fcbf3ff Improve how format read/write capabilities are marked and shown.
Matti Hamalainen <ccr@tnsp.org>
parents: 1544
diff changeset
83
2094
4276b8c0fef0 Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents: 2093
diff changeset
84 typedef struct
4276b8c0fef0 Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents: 2093
diff changeset
85 {
4276b8c0fef0 Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents: 2093
diff changeset
86 int ncolors; // number of colors in palette, if any
4276b8c0fef0 Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents: 2093
diff changeset
87 int ctransp; // transparency color index, -1 if none
4276b8c0fef0 Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents: 2093
diff changeset
88 DMColor *colors;// colors
4276b8c0fef0 Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents: 2093
diff changeset
89 } DMPalette;
4276b8c0fef0 Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents: 2093
diff changeset
90
4276b8c0fef0 Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents: 2093
diff changeset
91
1609
c29adf5ce240 Convert libgfx file format routines to use DMResource instead of stdio FILE.
Matti Hamalainen <ccr@tnsp.org>
parents: 1545
diff changeset
92 // Bitmapped image struct
435
e4a3f183e463 Modularize some more.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
93 typedef struct
e4a3f183e463 Modularize some more.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
94 {
2157
9a9493809b3a Rename DM_COLFMT_* constants to DM_PIXFMT_* and the 'format' field of DMImage
Matti Hamalainen <ccr@tnsp.org>
parents: 2156
diff changeset
95 int pixfmt; // one of types specified by DM_PIXFMT_*
1286
b812fad6f33e Work on libgfx.
Matti Hamalainen <ccr@tnsp.org>
parents: 1285
diff changeset
96 int width, height;
b812fad6f33e Work on libgfx.
Matti Hamalainen <ccr@tnsp.org>
parents: 1285
diff changeset
97 int pitch; // bytes per scanline
b812fad6f33e Work on libgfx.
Matti Hamalainen <ccr@tnsp.org>
parents: 1285
diff changeset
98 int bpp; // bits per pixel
b812fad6f33e Work on libgfx.
Matti Hamalainen <ccr@tnsp.org>
parents: 1285
diff changeset
99
1628
a549d33d543a Add image aspect ratio information.
Matti Hamalainen <ccr@tnsp.org>
parents: 1616
diff changeset
100 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
101
1286
b812fad6f33e Work on libgfx.
Matti Hamalainen <ccr@tnsp.org>
parents: 1285
diff changeset
102 BOOL constpal; // is the palette a const?
2094
4276b8c0fef0 Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents: 2093
diff changeset
103 DMPalette *pal; // pointer to palette struct, NULL if no palette
1286
b812fad6f33e Work on libgfx.
Matti Hamalainen <ccr@tnsp.org>
parents: 1285
diff changeset
104
929
e1378398be0f Add size field for allocated data size in DMImage.
Matti Hamalainen <ccr@tnsp.org>
parents: 902
diff changeset
105 size_t size;
435
e4a3f183e463 Modularize some more.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
106 Uint8 *data;
e4a3f183e463 Modularize some more.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
107 } DMImage;
e4a3f183e463 Modularize some more.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
108
e4a3f183e463 Modularize some more.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
109
e4a3f183e463 Modularize some more.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
110 typedef struct
e4a3f183e463 Modularize some more.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
111 {
2065
451980580189 Refactor how paletted/indexed formats are handled in libgfx.
Matti Hamalainen <ccr@tnsp.org>
parents: 2064
diff changeset
112 int fmtid; // DM_IMGFMT_* of target format (a bit of a kludge here)
2157
9a9493809b3a Rename DM_COLFMT_* constants to DM_PIXFMT_* and the 'format' field of DMImage
Matti Hamalainen <ccr@tnsp.org>
parents: 2156
diff changeset
113 int pixfmt; // Target color format DM_PIXFMT_*
2148
487157934904 Clarifications in comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 2146
diff changeset
114 int scaleX, scaleY; // Integer scale factors (1..)
487157934904 Clarifications in comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 2146
diff changeset
115
2146
26f21e487fe2 Add some comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 2100
diff changeset
116 int nplanes, bpp, mask; // number of planes, bits per PLANE, masking
26f21e487fe2 Add some comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 2100
diff changeset
117 BOOL planar; // use planar format if the format supports it
2065
451980580189 Refactor how paletted/indexed formats are handled in libgfx.
Matti Hamalainen <ccr@tnsp.org>
parents: 2064
diff changeset
118 int compression; // Use compression/compression level (0 = none, 9 = max)
2156
e6ec7fad9ce2 Rename DMImageConvSpec to DMImageWriteSpec to better reflec the struct's purpose.
Matti Hamalainen <ccr@tnsp.org>
parents: 2148
diff changeset
119 } DMImageWriteSpec;
435
e4a3f183e463 Modularize some more.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
120
e4a3f183e463 Modularize some more.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
121
e4a3f183e463 Modularize some more.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
122 typedef struct
e4a3f183e463 Modularize some more.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
123 {
2202
455a3849b8ac Comments and cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 2157
diff changeset
124 char *fext; // Typical filename extension
455a3849b8ac Comments and cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 2157
diff changeset
125 char *name; // Format name / description
1616
36d073c45327 Refactor the format handling a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 1609
diff changeset
126 int fmtid; // DM_IMGFMT_*
2157
9a9493809b3a Rename DM_COLFMT_* constants to DM_PIXFMT_* and the 'format' field of DMImage
Matti Hamalainen <ccr@tnsp.org>
parents: 2156
diff changeset
127 int flags; // DM_FMT_* and DM_PIXFMT_* flags
2202
455a3849b8ac Comments and cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 2157
diff changeset
128
435
e4a3f183e463 Modularize some more.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
129 int (*probe)(const Uint8 *buf, const size_t len);
1886
1af79412f249 Remove the stdio FILE support from libgfx API, now only DMResource is supported.
Matti Hamalainen <ccr@tnsp.org>
parents: 1809
diff changeset
130 int (*read)(DMResource *fp, DMImage **pimg);
2156
e6ec7fad9ce2 Rename DMImageConvSpec to DMImageWriteSpec to better reflec the struct's purpose.
Matti Hamalainen <ccr@tnsp.org>
parents: 2148
diff changeset
131 int (*write)(DMResource *fp, const DMImage *pimg, const DMImageWriteSpec *spec);
435
e4a3f183e463 Modularize some more.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
132 } DMImageFormat;
e4a3f183e463 Modularize some more.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
133
e4a3f183e463 Modularize some more.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
134
2207
1ea48084055e Add functionality for separate palette file handling, reading, writing and
Matti Hamalainen <ccr@tnsp.org>
parents: 2202
diff changeset
135 typedef struct
1ea48084055e Add functionality for separate palette file handling, reading, writing and
Matti Hamalainen <ccr@tnsp.org>
parents: 2202
diff changeset
136 {
1ea48084055e Add functionality for separate palette file handling, reading, writing and
Matti Hamalainen <ccr@tnsp.org>
parents: 2202
diff changeset
137 char *fext; // Typical filename extension
1ea48084055e Add functionality for separate palette file handling, reading, writing and
Matti Hamalainen <ccr@tnsp.org>
parents: 2202
diff changeset
138 char *name; // Format name / description
1ea48084055e Add functionality for separate palette file handling, reading, writing and
Matti Hamalainen <ccr@tnsp.org>
parents: 2202
diff changeset
139 int fmtid; // DM_PALFMT_*
1ea48084055e Add functionality for separate palette file handling, reading, writing and
Matti Hamalainen <ccr@tnsp.org>
parents: 2202
diff changeset
140 int flags; // DM_FMT_*
1ea48084055e Add functionality for separate palette file handling, reading, writing and
Matti Hamalainen <ccr@tnsp.org>
parents: 2202
diff changeset
141
1ea48084055e Add functionality for separate palette file handling, reading, writing and
Matti Hamalainen <ccr@tnsp.org>
parents: 2202
diff changeset
142 int (*probe)(const Uint8 *buf, const size_t len);
1ea48084055e Add functionality for separate palette file handling, reading, writing and
Matti Hamalainen <ccr@tnsp.org>
parents: 2202
diff changeset
143 int (*read)(DMResource *fp, DMPalette **ppal);
1ea48084055e Add functionality for separate palette file handling, reading, writing and
Matti Hamalainen <ccr@tnsp.org>
parents: 2202
diff changeset
144 int (*write)(DMResource *fp, const DMPalette *ppal);
1ea48084055e Add functionality for separate palette file handling, reading, writing and
Matti Hamalainen <ccr@tnsp.org>
parents: 2202
diff changeset
145 } DMPaletteFormat;
1ea48084055e Add functionality for separate palette file handling, reading, writing and
Matti Hamalainen <ccr@tnsp.org>
parents: 2202
diff changeset
146
1ea48084055e Add functionality for separate palette file handling, reading, writing and
Matti Hamalainen <ccr@tnsp.org>
parents: 2202
diff changeset
147
1616
36d073c45327 Refactor the format handling a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 1609
diff changeset
148 extern const DMImageFormat dmImageFormatList[];
36d073c45327 Refactor the format handling a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 1609
diff changeset
149 extern const int ndmImageFormatList;
2207
1ea48084055e Add functionality for separate palette file handling, reading, writing and
Matti Hamalainen <ccr@tnsp.org>
parents: 2202
diff changeset
150 extern const DMPaletteFormat dmPaletteFormatList[];
1ea48084055e Add functionality for separate palette file handling, reading, writing and
Matti Hamalainen <ccr@tnsp.org>
parents: 2202
diff changeset
151 extern const int ndmPaletteFormatList;
1285
e4bda4909d72 Make libgfx error mode a global variable, at least for now.
Matti Hamalainen <ccr@tnsp.org>
parents: 971
diff changeset
152 extern int dmGFXErrorMode;
435
e4a3f183e463 Modularize some more.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
153
e4a3f183e463 Modularize some more.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
154
1286
b812fad6f33e Work on libgfx.
Matti Hamalainen <ccr@tnsp.org>
parents: 1285
diff changeset
155 DMImage * dmImageAlloc(const int width, const int height, const int format, const int bpp);
435
e4a3f183e463 Modularize some more.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
156 void dmImageFree(DMImage *img);
1286
b812fad6f33e Work on libgfx.
Matti Hamalainen <ccr@tnsp.org>
parents: 1285
diff changeset
157 int dmImageGetBytesPerPixel(const int format);
2093
d17512dbb4ef Some work on reading >8bpp images.
Matti Hamalainen <ccr@tnsp.org>
parents: 2092
diff changeset
158 int dmImageGetBitsPerPixel(const int format);
1616
36d073c45327 Refactor the format handling a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 1609
diff changeset
159 int dmImageProbeGeneric(const Uint8 *buf, const size_t len, const DMImageFormat **fmt, int *index);
2100
81fb21dd3265 Add dmGetNPlanesFromNColors() and use it.
Matti Hamalainen <ccr@tnsp.org>
parents: 2095
diff changeset
160 int dmGetNPlanesFromNColors(const int ncolors);
435
e4a3f183e463 Modularize some more.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
161
2207
1ea48084055e Add functionality for separate palette file handling, reading, writing and
Matti Hamalainen <ccr@tnsp.org>
parents: 2202
diff changeset
162 BOOL dmCompareColor(const DMColor *c1, const DMColor *c2, const BOOL alpha);
1ea48084055e Add functionality for separate palette file handling, reading, writing and
Matti Hamalainen <ccr@tnsp.org>
parents: 2202
diff changeset
163 int dmPaletteAlloc(DMPalette **ppal, const int ncolors, const int ctransp);
1ea48084055e Add functionality for separate palette file handling, reading, writing and
Matti Hamalainen <ccr@tnsp.org>
parents: 2202
diff changeset
164 int dmPaletteResize(DMPalette **ppal, const int ncolors);
1ea48084055e Add functionality for separate palette file handling, reading, writing and
Matti Hamalainen <ccr@tnsp.org>
parents: 2202
diff changeset
165 void dmPaletteFree(DMPalette *pal);
1ea48084055e Add functionality for separate palette file handling, reading, writing and
Matti Hamalainen <ccr@tnsp.org>
parents: 2202
diff changeset
166 int dmPaletteCopy(DMPalette **pdst, const DMPalette *src);
1ea48084055e Add functionality for separate palette file handling, reading, writing and
Matti Hamalainen <ccr@tnsp.org>
parents: 2202
diff changeset
167 int dmPaletteProbeGeneric(const Uint8 *buf, const size_t len, const DMPaletteFormat **fmt, int *index);
1ea48084055e Add functionality for separate palette file handling, reading, writing and
Matti Hamalainen <ccr@tnsp.org>
parents: 2202
diff changeset
168
1ea48084055e Add functionality for separate palette file handling, reading, writing and
Matti Hamalainen <ccr@tnsp.org>
parents: 2202
diff changeset
169
1ea48084055e Add functionality for separate palette file handling, reading, writing and
Matti Hamalainen <ccr@tnsp.org>
parents: 2202
diff changeset
170 int dmReadACTPalette(DMResource *fp, DMPalette **pdst);
1ea48084055e Add functionality for separate palette file handling, reading, writing and
Matti Hamalainen <ccr@tnsp.org>
parents: 2202
diff changeset
171 int dmWriteACTPalette(DMResource *fp, const DMPalette *pdst);
487
b89598501cec Move dmCompareColor() to libgfx.
Matti Hamalainen <ccr@tnsp.org>
parents: 462
diff changeset
172
435
e4a3f183e463 Modularize some more.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
173
1886
1af79412f249 Remove the stdio FILE support from libgfx API, now only DMResource is supported.
Matti Hamalainen <ccr@tnsp.org>
parents: 1809
diff changeset
174 int dmWriteImageData(const DMImage *img, void *cbdata,
2156
e6ec7fad9ce2 Rename DMImageConvSpec to DMImageWriteSpec to better reflec the struct's purpose.
Matti Hamalainen <ccr@tnsp.org>
parents: 2148
diff changeset
175 int (*writeRowCB)(void *, const Uint8 *, const size_t), const DMImageWriteSpec *spec);
1886
1af79412f249 Remove the stdio FILE support from libgfx API, now only DMResource is supported.
Matti Hamalainen <ccr@tnsp.org>
parents: 1809
diff changeset
176
435
e4a3f183e463 Modularize some more.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
177
2156
e6ec7fad9ce2 Rename DMImageConvSpec to DMImageWriteSpec to better reflec the struct's purpose.
Matti Hamalainen <ccr@tnsp.org>
parents: 2148
diff changeset
178 int dmWriteIFFMasterRAWHeader(DMResource *fp, const char *filename, const char *prefix, const DMImage *img, const DMImageWriteSpec *spec);
e6ec7fad9ce2 Rename DMImageConvSpec to DMImageWriteSpec to better reflec the struct's purpose.
Matti Hamalainen <ccr@tnsp.org>
parents: 2148
diff changeset
179 int dmWriteRAWImage(DMResource *fp, const DMImage *img, const DMImageWriteSpec *spec);
435
e4a3f183e463 Modularize some more.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
180
2156
e6ec7fad9ce2 Rename DMImageConvSpec to DMImageWriteSpec to better reflec the struct's purpose.
Matti Hamalainen <ccr@tnsp.org>
parents: 2148
diff changeset
181 int dmWritePPMImage(DMResource *fp, const DMImage *img, const DMImageWriteSpec *spec);
2092
614b161c0aa5 Initial support for reading PPM/PGM.
Matti Hamalainen <ccr@tnsp.org>
parents: 2086
diff changeset
182 int dmReadPPMImage(DMResource *fp, DMImage **pimg);
435
e4a3f183e463 Modularize some more.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
183
e4a3f183e463 Modularize some more.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
184 #ifdef DM_USE_LIBPNG
2156
e6ec7fad9ce2 Rename DMImageConvSpec to DMImageWriteSpec to better reflec the struct's purpose.
Matti Hamalainen <ccr@tnsp.org>
parents: 2148
diff changeset
185 int dmWritePNGImage(DMResource *fp, const DMImage *img, const DMImageWriteSpec *spec);
1886
1af79412f249 Remove the stdio FILE support from libgfx API, now only DMResource is supported.
Matti Hamalainen <ccr@tnsp.org>
parents: 1809
diff changeset
186 int dmReadPNGImage(DMResource *fp, DMImage **pimg);
435
e4a3f183e463 Modularize some more.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
187 #endif
e4a3f183e463 Modularize some more.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
188
2156
e6ec7fad9ce2 Rename DMImageConvSpec to DMImageWriteSpec to better reflec the struct's purpose.
Matti Hamalainen <ccr@tnsp.org>
parents: 2148
diff changeset
189 int dmWritePCXImage(DMResource *fp, const DMImage *img, const DMImageWriteSpec *spec);
1886
1af79412f249 Remove the stdio FILE support from libgfx API, now only DMResource is supported.
Matti Hamalainen <ccr@tnsp.org>
parents: 1809
diff changeset
190 int dmReadPCXImage(DMResource *fp, DMImage **pimg);
435
e4a3f183e463 Modularize some more.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
191
1892
cbc911ffd21e Rename ILBM functions to IFF, which is more approriate as we support both ILBM and PBM variants of the IFF images.
Matti Hamalainen <ccr@tnsp.org>
parents: 1886
diff changeset
192 int dmReadIFFImage(DMResource *fp, DMImage **pimg);
2156
e6ec7fad9ce2 Rename DMImageConvSpec to DMImageWriteSpec to better reflec the struct's purpose.
Matti Hamalainen <ccr@tnsp.org>
parents: 2148
diff changeset
193 int dmWriteIFFImage(DMResource *fp, const DMImage *img, const DMImageWriteSpec *spec);
1809
a20655e40e6c Move ILBM function declarations to position that better reflects their
Matti Hamalainen <ccr@tnsp.org>
parents: 1801
diff changeset
194
435
e4a3f183e463 Modularize some more.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
195
2202
455a3849b8ac Comments and cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 2157
diff changeset
196 //
455a3849b8ac Comments and cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 2157
diff changeset
197 // Simplistic bitstream reading and writing
455a3849b8ac Comments and cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 2157
diff changeset
198 //
1309
5ad7d780a09b Move bitstream reading functions to libgfx, as they were only used there.
Matti Hamalainen <ccr@tnsp.org>
parents: 1307
diff changeset
199 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
200 {
5ad7d780a09b Move bitstream reading functions to libgfx, as they were only used there.
Matti Hamalainen <ccr@tnsp.org>
parents: 1307
diff changeset
201 void *handle;
5ad7d780a09b Move bitstream reading functions to libgfx, as they were only used there.
Matti Hamalainen <ccr@tnsp.org>
parents: 1307
diff changeset
202
2086
aedadff9e116 Implement dmGetBits() to the DMBitStreamContext API. Also improve error handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 2070
diff changeset
203 int (*putByte)(struct _DMBitStreamContext *ctx);
aedadff9e116 Implement dmGetBits() to the DMBitStreamContext API. Also improve error handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 2070
diff changeset
204 int (*getByte)(struct _DMBitStreamContext *ctx);
1309
5ad7d780a09b Move bitstream reading functions to libgfx, as they were only used there.
Matti Hamalainen <ccr@tnsp.org>
parents: 1307
diff changeset
205
2086
aedadff9e116 Implement dmGetBits() to the DMBitStreamContext API. Also improve error handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 2070
diff changeset
206 unsigned int
aedadff9e116 Implement dmGetBits() to the DMBitStreamContext API. Also improve error handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 2070
diff changeset
207 outBuf, outBitCount, outByteCount,
aedadff9e116 Implement dmGetBits() to the DMBitStreamContext API. Also improve error handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 2070
diff changeset
208 inBuf, inBitCount, inByteCount;
1309
5ad7d780a09b Move bitstream reading functions to libgfx, as they were only used there.
Matti Hamalainen <ccr@tnsp.org>
parents: 1307
diff changeset
209 } DMBitStreamContext;
5ad7d780a09b Move bitstream reading functions to libgfx, as they were only used there.
Matti Hamalainen <ccr@tnsp.org>
parents: 1307
diff changeset
210
5ad7d780a09b Move bitstream reading functions to libgfx, as they were only used there.
Matti Hamalainen <ccr@tnsp.org>
parents: 1307
diff changeset
211
5ad7d780a09b Move bitstream reading functions to libgfx, as they were only used there.
Matti Hamalainen <ccr@tnsp.org>
parents: 1307
diff changeset
212 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
213 int dmFlushBitStream(DMBitStreamContext *ctx);
2086
aedadff9e116 Implement dmGetBits() to the DMBitStreamContext API. Also improve error handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 2070
diff changeset
214 int dmInitBitStreamRes(DMBitStreamContext *ctx, DMResource *fp);
aedadff9e116 Implement dmGetBits() to the DMBitStreamContext API. Also improve error handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 2070
diff changeset
215
aedadff9e116 Implement dmGetBits() to the DMBitStreamContext API. Also improve error handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 2070
diff changeset
216 int dmPutBits(DMBitStreamContext *ctx, const unsigned int val, const unsigned int n);
aedadff9e116 Implement dmGetBits() to the DMBitStreamContext API. Also improve error handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 2070
diff changeset
217 int dmGetBits(DMBitStreamContext *ctx, unsigned int *val, const unsigned int n);
1309
5ad7d780a09b Move bitstream reading functions to libgfx, as they were only used there.
Matti Hamalainen <ccr@tnsp.org>
parents: 1307
diff changeset
218
5ad7d780a09b Move bitstream reading functions to libgfx, as they were only used there.
Matti Hamalainen <ccr@tnsp.org>
parents: 1307
diff changeset
219
435
e4a3f183e463 Modularize some more.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
220 #ifdef __cplusplus
e4a3f183e463 Modularize some more.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
221 }
e4a3f183e463 Modularize some more.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
222 #endif
e4a3f183e463 Modularize some more.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
223
e4a3f183e463 Modularize some more.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
224 #endif // LIBMGFX_H