annotate tools/libgfx.h @ 2209:7a0af15fbe97

Add support for 'raw' 768 byte palette files.
author Matti Hamalainen <ccr@tnsp.org>
date Fri, 14 Jun 2019 05:32:58 +0300
parents 1ea48084055e
children b858ade0fb0b
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,
2209
7a0af15fbe97 Add support for 'raw' 768 byte palette files.
Matti Hamalainen <ccr@tnsp.org>
parents: 2207
diff changeset
39 DM_PALFMT_RAW,
2207
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
1ea48084055e Add functionality for separate palette file handling, reading, writing and
Matti Hamalainen <ccr@tnsp.org>
parents: 2202
diff changeset
42
2095
80786a28caf0 Mark image format flags with the color formats they support.
Matti Hamalainen <ccr@tnsp.org>
parents: 2094
diff changeset
43 // Color formats (these can be used along with DM_FMT_*)
435
e4a3f183e463 Modularize some more.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
44 enum
e4a3f183e463 Modularize some more.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
45 {
2157
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_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
47 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
48 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
49 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
50
2157
9a9493809b3a Rename DM_COLFMT_* constants to DM_PIXFMT_* and the 'format' field of DMImage
Matti Hamalainen <ccr@tnsp.org>
parents: 2156
diff changeset
51 DM_PIXFMT_ANY = 0x00f0,
435
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
e4a3f183e463 Modularize some more.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
54
1544
48823642c4fb Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 1543
diff changeset
55 // 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
56 enum
e4bda4909d72 Make libgfx error mode a global variable, at least for now.
Matti Hamalainen <ccr@tnsp.org>
parents: 971
diff changeset
57 {
1544
48823642c4fb Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 1543
diff changeset
58 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
59 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
60 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
61 };
e4bda4909d72 Make libgfx error mode a global variable, at least for now.
Matti Hamalainen <ccr@tnsp.org>
parents: 971
diff changeset
62
e4bda4909d72 Make libgfx error mode a global variable, at least for now.
Matti Hamalainen <ccr@tnsp.org>
parents: 971
diff changeset
63
1544
48823642c4fb Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 1543
diff changeset
64 // Probe scores
48823642c4fb Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 1543
diff changeset
65 enum
48823642c4fb Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 1543
diff changeset
66 {
48823642c4fb Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 1543
diff changeset
67 DM_PROBE_SCORE_FALSE = 0,
48823642c4fb Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 1543
diff changeset
68 DM_PROBE_SCORE_MAYBE = 250,
48823642c4fb Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 1543
diff changeset
69 DM_PROBE_SCORE_AVG = 500,
48823642c4fb Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 1543
diff changeset
70 DM_PROBE_SCORE_GOOD = 750,
48823642c4fb Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 1543
diff changeset
71 DM_PROBE_SCORE_MAX = 1000,
48823642c4fb Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 1543
diff changeset
72 };
48823642c4fb Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 1543
diff changeset
73
48823642c4fb Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 1543
diff changeset
74
1545
3b613fcbf3ff Improve how format read/write capabilities are marked and shown.
Matti Hamalainen <ccr@tnsp.org>
parents: 1544
diff changeset
75 // 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
76 enum
3b613fcbf3ff Improve how format read/write capabilities are marked and shown.
Matti Hamalainen <ccr@tnsp.org>
parents: 1544
diff changeset
77 {
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
78 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
79 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
80 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
81 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
82 };
3b613fcbf3ff Improve how format read/write capabilities are marked and shown.
Matti Hamalainen <ccr@tnsp.org>
parents: 1544
diff changeset
83
3b613fcbf3ff Improve how format read/write capabilities are marked and shown.
Matti Hamalainen <ccr@tnsp.org>
parents: 1544
diff changeset
84
2094
4276b8c0fef0 Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents: 2093
diff changeset
85 typedef struct
4276b8c0fef0 Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents: 2093
diff changeset
86 {
4276b8c0fef0 Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents: 2093
diff changeset
87 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
88 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
89 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
90 } DMPalette;
4276b8c0fef0 Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents: 2093
diff changeset
91
4276b8c0fef0 Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents: 2093
diff changeset
92
1609
c29adf5ce240 Convert libgfx file format routines to use DMResource instead of stdio FILE.
Matti Hamalainen <ccr@tnsp.org>
parents: 1545
diff changeset
93 // Bitmapped image struct
435
e4a3f183e463 Modularize some more.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
94 typedef struct
e4a3f183e463 Modularize some more.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
95 {
2157
9a9493809b3a Rename DM_COLFMT_* constants to DM_PIXFMT_* and the 'format' field of DMImage
Matti Hamalainen <ccr@tnsp.org>
parents: 2156
diff changeset
96 int pixfmt; // one of types specified by DM_PIXFMT_*
1286
b812fad6f33e Work on libgfx.
Matti Hamalainen <ccr@tnsp.org>
parents: 1285
diff changeset
97 int width, height;
b812fad6f33e Work on libgfx.
Matti Hamalainen <ccr@tnsp.org>
parents: 1285
diff changeset
98 int pitch; // bytes per scanline
b812fad6f33e Work on libgfx.
Matti Hamalainen <ccr@tnsp.org>
parents: 1285
diff changeset
99 int bpp; // bits per pixel
b812fad6f33e Work on libgfx.
Matti Hamalainen <ccr@tnsp.org>
parents: 1285
diff changeset
100
1628
a549d33d543a Add image aspect ratio information.
Matti Hamalainen <ccr@tnsp.org>
parents: 1616
diff changeset
101 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
102
1286
b812fad6f33e Work on libgfx.
Matti Hamalainen <ccr@tnsp.org>
parents: 1285
diff changeset
103 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
104 DMPalette *pal; // pointer to palette struct, NULL if no palette
1286
b812fad6f33e Work on libgfx.
Matti Hamalainen <ccr@tnsp.org>
parents: 1285
diff changeset
105
929
e1378398be0f Add size field for allocated data size in DMImage.
Matti Hamalainen <ccr@tnsp.org>
parents: 902
diff changeset
106 size_t size;
435
e4a3f183e463 Modularize some more.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
107 Uint8 *data;
e4a3f183e463 Modularize some more.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
108 } DMImage;
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
e4a3f183e463 Modularize some more.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
111 typedef struct
e4a3f183e463 Modularize some more.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
112 {
2065
451980580189 Refactor how paletted/indexed formats are handled in libgfx.
Matti Hamalainen <ccr@tnsp.org>
parents: 2064
diff changeset
113 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
114 int pixfmt; // Target color format DM_PIXFMT_*
2148
487157934904 Clarifications in comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 2146
diff changeset
115 int scaleX, scaleY; // Integer scale factors (1..)
487157934904 Clarifications in comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 2146
diff changeset
116
2146
26f21e487fe2 Add some comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 2100
diff changeset
117 int nplanes, bpp, mask; // number of planes, bits per PLANE, masking
26f21e487fe2 Add some comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 2100
diff changeset
118 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
119 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
120 } DMImageWriteSpec;
435
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
e4a3f183e463 Modularize some more.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
123 typedef struct
e4a3f183e463 Modularize some more.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
124 {
2202
455a3849b8ac Comments and cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 2157
diff changeset
125 char *fext; // Typical filename extension
455a3849b8ac Comments and cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 2157
diff changeset
126 char *name; // Format name / description
1616
36d073c45327 Refactor the format handling a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 1609
diff changeset
127 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
128 int flags; // DM_FMT_* and DM_PIXFMT_* flags
2202
455a3849b8ac Comments and cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 2157
diff changeset
129
435
e4a3f183e463 Modularize some more.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
130 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
131 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
132 int (*write)(DMResource *fp, const DMImage *pimg, const DMImageWriteSpec *spec);
435
e4a3f183e463 Modularize some more.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
133 } DMImageFormat;
e4a3f183e463 Modularize some more.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
134
e4a3f183e463 Modularize some more.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
135
2207
1ea48084055e Add functionality for separate palette file handling, reading, writing and
Matti Hamalainen <ccr@tnsp.org>
parents: 2202
diff changeset
136 typedef struct
1ea48084055e Add functionality for separate palette file handling, reading, writing and
Matti Hamalainen <ccr@tnsp.org>
parents: 2202
diff changeset
137 {
1ea48084055e Add functionality for separate palette file handling, reading, writing and
Matti Hamalainen <ccr@tnsp.org>
parents: 2202
diff changeset
138 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
139 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
140 int fmtid; // DM_PALFMT_*
1ea48084055e Add functionality for separate palette file handling, reading, writing and
Matti Hamalainen <ccr@tnsp.org>
parents: 2202
diff changeset
141 int flags; // DM_FMT_*
1ea48084055e Add functionality for separate palette file handling, reading, writing and
Matti Hamalainen <ccr@tnsp.org>
parents: 2202
diff changeset
142
1ea48084055e Add functionality for separate palette file handling, reading, writing and
Matti Hamalainen <ccr@tnsp.org>
parents: 2202
diff changeset
143 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
144 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
145 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
146 } DMPaletteFormat;
1ea48084055e Add functionality for separate palette file handling, reading, writing and
Matti Hamalainen <ccr@tnsp.org>
parents: 2202
diff changeset
147
1ea48084055e Add functionality for separate palette file handling, reading, writing and
Matti Hamalainen <ccr@tnsp.org>
parents: 2202
diff changeset
148
1616
36d073c45327 Refactor the format handling a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 1609
diff changeset
149 extern const DMImageFormat dmImageFormatList[];
36d073c45327 Refactor the format handling a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 1609
diff changeset
150 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
151 extern const DMPaletteFormat dmPaletteFormatList[];
1ea48084055e Add functionality for separate palette file handling, reading, writing and
Matti Hamalainen <ccr@tnsp.org>
parents: 2202
diff changeset
152 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
153 extern int dmGFXErrorMode;
435
e4a3f183e463 Modularize some more.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
154
e4a3f183e463 Modularize some more.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
155
1286
b812fad6f33e Work on libgfx.
Matti Hamalainen <ccr@tnsp.org>
parents: 1285
diff changeset
156 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
157 void dmImageFree(DMImage *img);
1286
b812fad6f33e Work on libgfx.
Matti Hamalainen <ccr@tnsp.org>
parents: 1285
diff changeset
158 int dmImageGetBytesPerPixel(const int format);
2093
d17512dbb4ef Some work on reading >8bpp images.
Matti Hamalainen <ccr@tnsp.org>
parents: 2092
diff changeset
159 int dmImageGetBitsPerPixel(const int format);
1616
36d073c45327 Refactor the format handling a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 1609
diff changeset
160 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
161 int dmGetNPlanesFromNColors(const int ncolors);
435
e4a3f183e463 Modularize some more.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
162
2207
1ea48084055e Add functionality for separate palette file handling, reading, writing and
Matti Hamalainen <ccr@tnsp.org>
parents: 2202
diff changeset
163 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
164 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
165 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
166 void dmPaletteFree(DMPalette *pal);
1ea48084055e Add functionality for separate palette file handling, reading, writing and
Matti Hamalainen <ccr@tnsp.org>
parents: 2202
diff changeset
167 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
168 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
169
1ea48084055e Add functionality for separate palette file handling, reading, writing and
Matti Hamalainen <ccr@tnsp.org>
parents: 2202
diff changeset
170
1ea48084055e Add functionality for separate palette file handling, reading, writing and
Matti Hamalainen <ccr@tnsp.org>
parents: 2202
diff changeset
171 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
172 int dmWriteACTPalette(DMResource *fp, const DMPalette *pdst);
487
b89598501cec Move dmCompareColor() to libgfx.
Matti Hamalainen <ccr@tnsp.org>
parents: 462
diff changeset
173
435
e4a3f183e463 Modularize some more.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
174
1886
1af79412f249 Remove the stdio FILE support from libgfx API, now only DMResource is supported.
Matti Hamalainen <ccr@tnsp.org>
parents: 1809
diff changeset
175 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
176 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
177
435
e4a3f183e463 Modularize some more.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
178
2156
e6ec7fad9ce2 Rename DMImageConvSpec to DMImageWriteSpec to better reflec the struct's purpose.
Matti Hamalainen <ccr@tnsp.org>
parents: 2148
diff changeset
179 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
180 int dmWriteRAWImage(DMResource *fp, const DMImage *img, const DMImageWriteSpec *spec);
435
e4a3f183e463 Modularize some more.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
181
2156
e6ec7fad9ce2 Rename DMImageConvSpec to DMImageWriteSpec to better reflec the struct's purpose.
Matti Hamalainen <ccr@tnsp.org>
parents: 2148
diff changeset
182 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
183 int dmReadPPMImage(DMResource *fp, DMImage **pimg);
435
e4a3f183e463 Modularize some more.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
184
e4a3f183e463 Modularize some more.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
185 #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
186 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
187 int dmReadPNGImage(DMResource *fp, DMImage **pimg);
435
e4a3f183e463 Modularize some more.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
188 #endif
e4a3f183e463 Modularize some more.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
189
2156
e6ec7fad9ce2 Rename DMImageConvSpec to DMImageWriteSpec to better reflec the struct's purpose.
Matti Hamalainen <ccr@tnsp.org>
parents: 2148
diff changeset
190 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
191 int dmReadPCXImage(DMResource *fp, DMImage **pimg);
435
e4a3f183e463 Modularize some more.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
192
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
193 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
194 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
195
435
e4a3f183e463 Modularize some more.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
196
2202
455a3849b8ac Comments and cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 2157
diff changeset
197 //
455a3849b8ac Comments and cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 2157
diff changeset
198 // Simplistic bitstream reading and writing
455a3849b8ac Comments and cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 2157
diff changeset
199 //
1309
5ad7d780a09b Move bitstream reading functions to libgfx, as they were only used there.
Matti Hamalainen <ccr@tnsp.org>
parents: 1307
diff changeset
200 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
201 {
5ad7d780a09b Move bitstream reading functions to libgfx, as they were only used there.
Matti Hamalainen <ccr@tnsp.org>
parents: 1307
diff changeset
202 void *handle;
5ad7d780a09b Move bitstream reading functions to libgfx, as they were only used there.
Matti Hamalainen <ccr@tnsp.org>
parents: 1307
diff changeset
203
2086
aedadff9e116 Implement dmGetBits() to the DMBitStreamContext API. Also improve error handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 2070
diff changeset
204 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
205 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
206
2086
aedadff9e116 Implement dmGetBits() to the DMBitStreamContext API. Also improve error handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 2070
diff changeset
207 unsigned int
aedadff9e116 Implement dmGetBits() to the DMBitStreamContext API. Also improve error handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 2070
diff changeset
208 outBuf, outBitCount, outByteCount,
aedadff9e116 Implement dmGetBits() to the DMBitStreamContext API. Also improve error handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 2070
diff changeset
209 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
210 } DMBitStreamContext;
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
5ad7d780a09b Move bitstream reading functions to libgfx, as they were only used there.
Matti Hamalainen <ccr@tnsp.org>
parents: 1307
diff changeset
213 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
214 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
215 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
216
aedadff9e116 Implement dmGetBits() to the DMBitStreamContext API. Also improve error handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 2070
diff changeset
217 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
218 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
219
5ad7d780a09b Move bitstream reading functions to libgfx, as they were only used there.
Matti Hamalainen <ccr@tnsp.org>
parents: 1307
diff changeset
220
435
e4a3f183e463 Modularize some more.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
221 #ifdef __cplusplus
e4a3f183e463 Modularize some more.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
222 }
e4a3f183e463 Modularize some more.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
223 #endif
e4a3f183e463 Modularize some more.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
224
e4a3f183e463 Modularize some more.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
225 #endif // LIBMGFX_H