diff options
Diffstat (limited to 'src/others/mimesh/libg3d-0.0.8/include/g3d/iff.h')
-rw-r--r-- | src/others/mimesh/libg3d-0.0.8/include/g3d/iff.h | 325 |
1 files changed, 325 insertions, 0 deletions
diff --git a/src/others/mimesh/libg3d-0.0.8/include/g3d/iff.h b/src/others/mimesh/libg3d-0.0.8/include/g3d/iff.h new file mode 100644 index 0000000..a8df77e --- /dev/null +++ b/src/others/mimesh/libg3d-0.0.8/include/g3d/iff.h | |||
@@ -0,0 +1,325 @@ | |||
1 | /* $Id$ */ | ||
2 | |||
3 | /* | ||
4 | libg3d - 3D object loading library | ||
5 | |||
6 | Copyright (C) 2005-2009 Markus Dahms <mad@automagically.de> | ||
7 | |||
8 | This library is free software; you can redistribute it and/or | ||
9 | modify it under the terms of the GNU Lesser General Public | ||
10 | License as published by the Free Software Foundation; either | ||
11 | version 2.1 of the License, or (at your option) any later version. | ||
12 | |||
13 | This library is distributed in the hope that it will be useful, | ||
14 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
16 | Lesser General Public License for more details. | ||
17 | |||
18 | You should have received a copy of the GNU Lesser General Public | ||
19 | License along with this library; if not, write to the Free Software | ||
20 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | ||
21 | */ | ||
22 | |||
23 | #ifndef __G3D_IFF_H__ | ||
24 | #define __G3D_IFF_H__ | ||
25 | |||
26 | /* FIXME: still needed for FILE until all plugins are converted | ||
27 | * #ifndef G3D_DISABLE_DEPRECATED */ | ||
28 | #include <stdio.h> | ||
29 | /* #endif */ | ||
30 | #include <glib.h> | ||
31 | |||
32 | #include <g3d/types.h> | ||
33 | |||
34 | /** | ||
35 | * SECTION:iff | ||
36 | * @short_description: IFF file helper functions | ||
37 | * @include: g3d/iff.h | ||
38 | * | ||
39 | * These are helper functions to read data from the Interchange File Format | ||
40 | * (IFF). | ||
41 | */ | ||
42 | |||
43 | |||
44 | /** | ||
45 | * G3D_IFF_PAD1: | ||
46 | * | ||
47 | * No padding is done after chunks. | ||
48 | */ | ||
49 | #define G3D_IFF_PAD1 0x01 | ||
50 | /** | ||
51 | * G3D_IFF_PAD2: | ||
52 | * | ||
53 | * Chunks are 2-byte aligned | ||
54 | */ | ||
55 | #define G3D_IFF_PAD2 0x02 | ||
56 | /** | ||
57 | * G3D_IFF_PAD4: | ||
58 | * | ||
59 | * Chunks are 4-byte aligned | ||
60 | */ | ||
61 | #define G3D_IFF_PAD4 0x04 | ||
62 | /** | ||
63 | * G3D_IFF_PAD8: | ||
64 | * | ||
65 | * Chunks are 8-byte aligned | ||
66 | */ | ||
67 | #define G3D_IFF_PAD8 0x08 | ||
68 | |||
69 | /** | ||
70 | * G3D_IFF_SUBCHUNK_LEN16: | ||
71 | * | ||
72 | * All chunks except the toplevel ones have 16-bit sizes. | ||
73 | */ | ||
74 | #define G3D_IFF_SUBCHUNK_LEN16 0x10 | ||
75 | /** | ||
76 | * G3D_IFF_LEN16: | ||
77 | * | ||
78 | * All chunks have 16-bit sizes. | ||
79 | */ | ||
80 | #define G3D_IFF_LEN16 0x20 | ||
81 | /** | ||
82 | * G3D_IFF_LE: | ||
83 | * | ||
84 | * The file has little-endian data. | ||
85 | */ | ||
86 | #define G3D_IFF_LE 0x40 /* little endian */ | ||
87 | |||
88 | /** | ||
89 | * G3D_IFF_MKID: | ||
90 | * @a: first byte | ||
91 | * @b: second byte | ||
92 | * @c: third byte | ||
93 | * @d: fourth byte | ||
94 | * | ||
95 | * Generate an IFF chunk identifier from character representation, e.g. | ||
96 | * G3D_IFF_MKID('F','O','R','M'). | ||
97 | * | ||
98 | * Returns: unsigned integer identifier. | ||
99 | */ | ||
100 | #define G3D_IFF_MKID(a,b,c,d) ( \ | ||
101 | (((guint32)(a))<<24) | \ | ||
102 | (((guint32)(b))<<16) | \ | ||
103 | (((guint32)(c))<< 8) | \ | ||
104 | (((guint32)(d)) ) ) | ||
105 | |||
106 | #ifdef __cplusplus | ||
107 | extern "C" { | ||
108 | #endif /* ifdef __cplusplus */ | ||
109 | |||
110 | #ifndef G3D_DISABLE_DEPRECATED | ||
111 | /** | ||
112 | * g3d_iff_gdata: | ||
113 | * | ||
114 | * IFF global data (deprecated). | ||
115 | */ | ||
116 | #define g3d_iff_gdata G3DIffGlobal | ||
117 | /** | ||
118 | * g3d_iff_ldata: | ||
119 | * | ||
120 | * IFF local data (deprecated). | ||
121 | */ | ||
122 | #define g3d_iff_ldata G3DIffLocal | ||
123 | /** | ||
124 | * g3d_iff_chunk_callback: | ||
125 | * | ||
126 | * IFF chunk callback (deprecated). | ||
127 | */ | ||
128 | #define g3d_iff_chunk_callback G3DIffChunkCallback | ||
129 | /** | ||
130 | * g3d_iff_chunk_info: | ||
131 | * | ||
132 | * IFF chunk description (deprecated). | ||
133 | */ | ||
134 | #define g3d_iff_chunk_info G3DIffChunkInfo | ||
135 | #endif | ||
136 | |||
137 | /** | ||
138 | * G3DIffGlobal: | ||
139 | * @context: a valid context | ||
140 | * @model: a model | ||
141 | * @stream: the stream to read model from | ||
142 | * @flags: IFF flags | ||
143 | * @user_data: to be used by plugin | ||
144 | * @f: file to read model from (DEPRECATED) | ||
145 | * @max_fpos: maximum file position (DEPRECATED) | ||
146 | * | ||
147 | * The plugin-global data to be given to IFF callback functions. | ||
148 | */ | ||
149 | typedef struct { | ||
150 | G3DContext *context; | ||
151 | G3DModel *model; | ||
152 | G3DStream *stream; | ||
153 | guint32 flags; | ||
154 | gpointer user_data; | ||
155 | FILE *f; | ||
156 | long int max_fpos; | ||
157 | } G3DIffGlobal; | ||
158 | |||
159 | /** | ||
160 | * G3DIffLocal: | ||
161 | * @id: chunk identifier | ||
162 | * @parent_id: parent chunk identifier | ||
163 | * @object: an object set by parent callbacks, may be NULL | ||
164 | * @level: level of chunk | ||
165 | * @level_object: object shared by callbacks on the same level, may be NULL | ||
166 | * @nb: number of bytes remaining in chunk, has to be decremented after | ||
167 | * correctly after reading from stream | ||
168 | * @finalize: for container chunks the callback function is called before | ||
169 | * and after processing possible sub-chunks, the second time @finalize is set | ||
170 | * to TRUE | ||
171 | * | ||
172 | * The function-local data for IFF callback functions. | ||
173 | */ | ||
174 | typedef struct { | ||
175 | guint32 id; | ||
176 | guint32 parent_id; | ||
177 | gpointer object; | ||
178 | gint32 level; | ||
179 | gpointer level_object; | ||
180 | gint32 nb; | ||
181 | gboolean finalize; | ||
182 | } G3DIffLocal; | ||
183 | |||
184 | /** | ||
185 | * G3DIffChunkCallback: | ||
186 | * @global: the global data | ||
187 | * @local: the local data | ||
188 | * | ||
189 | * IFF callback function prototype. | ||
190 | * | ||
191 | * Returns: TRUE on success, FALSE else. | ||
192 | */ | ||
193 | typedef gboolean (* G3DIffChunkCallback)( | ||
194 | G3DIffGlobal *global, G3DIffLocal *local); | ||
195 | |||
196 | /** | ||
197 | * G3DIffChunkInfo: | ||
198 | * @id: identifier of chunk | ||
199 | * @description: human-readable description of chunk type | ||
200 | * @container: TRUE if this chunk contains sub-chunks | ||
201 | * @callback: function to be called if such a chunk is found | ||
202 | * | ||
203 | * A chunk type description. | ||
204 | */ | ||
205 | typedef struct { | ||
206 | gchar *id; | ||
207 | gchar *description; | ||
208 | gboolean container; | ||
209 | G3DIffChunkCallback callback; | ||
210 | } G3DIffChunkInfo; | ||
211 | |||
212 | /** | ||
213 | * g3d_iff_check: | ||
214 | * @stream: stream containing IFF file to check | ||
215 | * @id: top level ID (out) | ||
216 | * @len: length of top level container (out) | ||
217 | * | ||
218 | * Checks a stream for a valid IFF signature and reads the top level container. | ||
219 | * | ||
220 | * Returns: TRUE on success (valid IFF), FALSE else | ||
221 | */ | ||
222 | EAPI | ||
223 | gboolean g3d_iff_check(G3DStream *stream, guint32 *id, gsize *len); | ||
224 | |||
225 | /** | ||
226 | * g3d_iff_read_chunk: | ||
227 | * @stream: stream to read from | ||
228 | * @id: ID of chunk (out) | ||
229 | * @len: length of chunk (excluding header) (out) | ||
230 | * @flags: flags | ||
231 | * | ||
232 | * Reads one chunk header from an IFF file. | ||
233 | * | ||
234 | * Returns: real length of chunk including header and possible padding byte | ||
235 | */ | ||
236 | EAPI | ||
237 | gsize g3d_iff_read_chunk(G3DStream *stream, guint32 *id, gsize *len, | ||
238 | guint32 flags); | ||
239 | |||
240 | #ifndef G3D_DISABLE_DEPRECATED | ||
241 | /** | ||
242 | * g3d_iff_open: | ||
243 | * @filename: file name of IFF file | ||
244 | * @id: top level ID (out) | ||
245 | * @len: length of top level container (out) | ||
246 | * | ||
247 | * Opens an IFF file, checks it and reads its top level container. | ||
248 | * | ||
249 | * Returns: the file pointer of open file or NULL in case of an error | ||
250 | */ | ||
251 | FILE *g3d_iff_open(const gchar *filename, guint32 *id, guint32 *len); | ||
252 | |||
253 | /** | ||
254 | * g3d_iff_readchunk: | ||
255 | * @f: the open IFF file pointer | ||
256 | * @id: ID of chunk (out) | ||
257 | * @len: length of chunk (excluding header) (out) | ||
258 | * @flags: flags | ||
259 | * | ||
260 | * Reads one chunk header from an IFF file. | ||
261 | * | ||
262 | * Returns: real length of chunk including header and possible padding byte | ||
263 | */ | ||
264 | int g3d_iff_readchunk(FILE *f, guint32 *id, guint32 *len, guint32 flags); | ||
265 | #endif /* G3D_DISABLE_DEPRECATED */ | ||
266 | |||
267 | /** | ||
268 | * g3d_iff_id_to_text: | ||
269 | * @id: an IFF identifier | ||
270 | * | ||
271 | * Get the text representation of an IFF chunk identifier. | ||
272 | * | ||
273 | * Returns: a newly allocated string containing the text identifier. | ||
274 | */ | ||
275 | EAPI | ||
276 | gchar *g3d_iff_id_to_text(guint32 id); | ||
277 | |||
278 | /** | ||
279 | * g3d_iff_chunk_matches: | ||
280 | * @id: IFF identifier | ||
281 | * @tid: textual representation of identifier | ||
282 | * | ||
283 | * Check whether @id and @tid match. | ||
284 | * | ||
285 | * Returns: TRUE on match, FALSE else. | ||
286 | */ | ||
287 | EAPI | ||
288 | gboolean g3d_iff_chunk_matches(guint32 id, gchar *tid); | ||
289 | |||
290 | /** | ||
291 | * g3d_iff_handle_chunk: | ||
292 | * @global: global data | ||
293 | * @plocal: local data of parent chunk, must not be NULL | ||
294 | * @chunks: chunk description list | ||
295 | * @flags: IFF flags | ||
296 | * | ||
297 | * Handle an IFF chunk based on chunk description. | ||
298 | * | ||
299 | * Returns: level object for siblings, may be NULL. | ||
300 | */ | ||
301 | EAPI | ||
302 | gpointer g3d_iff_handle_chunk(G3DIffGlobal *global, G3DIffLocal *plocal, | ||
303 | G3DIffChunkInfo *chunks, guint32 flags); | ||
304 | |||
305 | /** | ||
306 | * g3d_iff_read_ctnr: | ||
307 | * @global: global data | ||
308 | * @local: local data of current chunk, must not be NULL | ||
309 | * @chunks: chunk description list | ||
310 | * @flags: IFF flags | ||
311 | * | ||
312 | * Read subchunks in current chunk and handle them appropriately. | ||
313 | * | ||
314 | * Returns: TRUE on success, FALSE else. | ||
315 | */ | ||
316 | EAPI | ||
317 | gboolean g3d_iff_read_ctnr(G3DIffGlobal *global, G3DIffLocal *local, | ||
318 | G3DIffChunkInfo *chunks, guint32 flags); | ||
319 | |||
320 | #ifdef __cplusplus | ||
321 | } | ||
322 | #endif /* ifdef __cplusplus */ | ||
323 | |||
324 | #endif | ||
325 | |||