libacfutils
A general purpose library of utility functions designed to make it easier to develop addons for the X-Plane flight simulator.
Loading...
Searching...
No Matches
dsf.h
Go to the documentation of this file.
1/*
2 * CDDL HEADER START
3 *
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License, Version 1.0 only
6 * (the "License"). You may not use this file except in compliance
7 * with the License.
8 *
9 * You can obtain a copy of the license in the file COPYING
10 * or http://www.opensource.org/licenses/CDDL-1.0.
11 * See the License for the specific language governing permissions
12 * and limitations under the License.
13 *
14 * When distributing Covered Code, include this CDDL HEADER in each
15 * file and include the License file COPYING.
16 * If applicable, add the following below this CDDL HEADER, with the
17 * fields enclosed by brackets "[]" replaced with your own identifying
18 * information: Portions Copyright [yyyy] [name of copyright owner]
19 *
20 * CDDL HEADER END
21 */
22/*
23 * Copyright 2023 Saso Kiselkov. All rights reserved.
24 */
32#ifndef _ACFUTILS_DSF_H_
33#define _ACFUTILS_DSF_H_
34
35#include <stdlib.h>
36#include <stdint.h>
37
38#include "avl.h"
39#include "list.h"
40
41#ifdef __cplusplus
42extern "C" {
43#endif
44
45#define DSF_ATOM(a, b, c, d) (((a) << 24) | ((b) << 16) | ((c) << 8) | (d))
46
47#define DSF_ATOM_HEAD DSF_ATOM('H', 'E', 'A', 'D')
48#define DSF_ATOM_PROP DSF_ATOM('P', 'R', 'O', 'P')
49
50#define DSF_ATOM_DEFN DSF_ATOM('D', 'E', 'F', 'N')
51#define DSF_ATOM_TERT DSF_ATOM('T', 'E', 'R', 'T')
52#define DSF_ATOM_OBJT DSF_ATOM('O', 'B', 'J', 'T')
53#define DSF_ATOM_POLY DSF_ATOM('P', 'O', 'L', 'Y')
54#define DSF_ATOM_NEWT DSF_ATOM('N', 'E', 'T', 'W')
55
56#define DSF_ATOM_DEMN DSF_ATOM('D', 'E', 'M', 'N')
57#define DSF_ATOM_GEOD DSF_ATOM('G', 'E', 'O', 'D')
58#define DSF_ATOM_POOL DSF_ATOM('P', 'O', 'O', 'L')
59#define DSF_ATOM_SCAL DSF_ATOM('S', 'C', 'A', 'L')
60#define DSF_ATOM_PO32 DSF_ATOM('P', 'O', '3', '2')
61#define DSF_ATOM_SC32 DSF_ATOM('S', 'C', '3', '2')
62
63#define DSF_ATOM_DEMS DSF_ATOM('D', 'E', 'M', 'S')
64#define DSF_ATOM_DEMI DSF_ATOM('D', 'E', 'M', 'I')
65#define DSF_ATOM_DEMD DSF_ATOM('D', 'E', 'M', 'D')
66
67#define DSF_ATOM_CMDS DSF_ATOM('C', 'M', 'D', 'S')
68
69enum { DSF_REASON_SZ = 256 };
70
71#define DSF_ATOM_ID_PRINTF(atom) \
72 ((atom)->id & 0xff000000) >> 24, \
73 ((atom)->id & 0xff0000) >> 16, \
74 ((atom)->id & 0xff00) >> 8, \
75 ((atom)->id & 0xff)
76
77typedef enum {
78 DSF_DATA_SINT16,
79 DSF_DATA_UINT16,
80 DSF_DATA_SINT32,
81 DSF_DATA_UINT32,
82 DSF_DATA_SINT64,
83 DSF_DATA_UINT64,
84 DSF_DATA_FP32,
85 DSF_DATA_FP64
86} dsf_data_type_t;
87
88typedef enum {
89 DSF_ENC_RAW = 0,
90 DSF_ENC_DIFF = 1 << 0,
91 DSF_ENC_RLE = 1 << 1
92} dsf_data_plane_enc_t;
93
94typedef struct {
95 const char *name;
96 const char *value;
97 list_node_t prop_node;
99
100typedef struct {
101 list_t props;
103
104enum {
105 DEMI_DATA_FP32 = 0,
106 DEMI_DATA_SINT = 1,
107 DEMI_DATA_UINT = 2,
108 DEMI_DATA_MASK = 3,
109 DEMI_POST_CTR = 1 << 2
110};
111
112typedef struct {
113 unsigned version;
114 unsigned bpp;
115 uint16_t flags;
116 uint32_t width;
117 uint32_t height;
118 float scale;
119 float offset;
121
122typedef struct {
123 dsf_data_type_t data_type;
124 uint32_t data_count;
125 unsigned plane_count;
126 union {
127 void **data;
128 int16_t **data_sint16;
129 uint16_t **data_uint16;
130 int32_t **data_sint32;
131 uint32_t **data_uint32;
132 int64_t **data_sint64;
133 uint64_t **data_uint64;
134 float **data_fp32;
135 double **data_fp64;
136 };
138
139typedef struct {
140 uint32_t id;
141 uint32_t payload_sz;
142 const uint8_t *payload;
143 list_t subatoms;
144 unsigned long long file_off;
145
146 bool_t subtype_inited;
147 union {
148 dsf_prop_atom_t prop_atom;
149 dsf_planar_atom_t planar_atom;
150 dsf_demi_atom_t demi_atom;
151 };
152
153 list_node_t atom_list;
154} dsf_atom_t;
155
156typedef struct {
157 int version;
158 list_t atoms;
159 uint8_t *data;
160 uint64_t size;
161 uint8_t md5sum[16];
162} dsf_t;
163
164typedef struct {
165 uint32_t atom_id;
166 unsigned idx;
168
169typedef enum {
170 DSF_POOL_SEL,
171 DSF_JUNCT_OFFSET_SEL,
172 DSF_SET_DEFN8,
173 DSF_SET_DEFN16,
174 DSF_SET_DEFN32,
175 DSF_ROAD_SUBTYPE,
176 DSF_OBJ,
177 DSF_OBJ_RNG,
178 DSF_NET_CHAIN,
179 DSF_NET_CHAIN_RNG,
180 DSF_NET_CHAIN32,
181 DSF_POLY,
182 DSF_POLY_RNG,
183 DSF_NEST_POLY,
184 DSF_NEST_POLY_RNG,
185 DSF_TERR_PATCH,
186 DSF_TERR_PATCH_FLAGS,
187 DSF_TERR_PATCH_FLAGS_N_LOD,
188 DSF_PATCH_TRIA,
189 DSF_PATCH_TRIA_XPOOL,
190 DSF_PATCH_TRIA_RNG,
191 DSF_PATCH_TRIA_STRIP,
192 DSF_PATCH_TRIA_STRIP_XPOOL,
193 DSF_PATCH_TRIA_STRIP_RNG,
194 DSF_PATCH_TRIA_FAN,
195 DSF_PATCH_TRIA_FAN_XPOOL,
196 DSF_PATCH_TRIA_FAN_RNG,
197 DSF_COMMENT8,
198 DSF_COMMENT16,
199 DSF_COMMENT32,
200 NUM_DSF_CMDS
201} dsf_cmd_t;
202
203typedef struct {
204 const dsf_t *dsf;
205
206 size_t cmd_file_off;
207
208 uint64_t junct_off;
209 uint64_t defn_idx;
210 uint64_t road_subt;
211
212 const dsf_atom_t *pool;
213 const dsf_atom_t *scal;
214
215 void *userinfo;
216
217 char *reason;
219
220typedef struct {
221 unsigned first;
222 unsigned last_plus_one;
224
225typedef struct {
226 int num_coords;
227 unsigned indices[255];
229
230typedef struct {
231 int num_coords;
232 struct {
233 const dsf_atom_t *pool;
234 const dsf_atom_t *scal;
235 unsigned idx;
236 } indices[255];
238
239typedef struct {
240 unsigned param;
241 int num_coords;
242 unsigned indices[255];
244
245typedef struct {
246 unsigned param;
247 unsigned first;
248 unsigned last_plus_one;
250
251typedef struct {
252 uint8_t flags;
253 float near_lod;
254 float far_lod;
256
257typedef struct {
258 size_t len;
259 const uint8_t *data;
261
262typedef void (*dsf_cmd_cb_t)(dsf_cmd_t cmd, const void *cmd_args,
263 const dsf_cmd_parser_t *parser);
264
265API_EXPORT dsf_t *dsf_init(const char *filename);
266API_EXPORT dsf_t *dsf_parse(uint8_t *buf, size_t bufsz,
267 char reason[DSF_REASON_SZ]);
268API_EXPORT void dsf_fini(dsf_t *dsf);
269API_EXPORT char *dsf_dump(const dsf_t *dsf);
270
271API_EXPORT const dsf_atom_t *dsf_lookup(const dsf_t *dsf, ...);
272API_EXPORT const dsf_atom_t *dsf_lookup_v(const dsf_t *dsf,
273 const dsf_lookup_t *lookup);
274API_EXPORT const dsf_atom_t *dsf_iter(const dsf_atom_t *parent,
275 uint32_t atom_id, const dsf_atom_t *prev);
276API_EXPORT bool_t dsf_parse_cmds(const dsf_t *dsf,
277 dsf_cmd_cb_t user_cbs[NUM_DSF_CMDS],
278 void *userinfo, char reason[DSF_REASON_SZ]);
279
280API_EXPORT const char *dsf_cmd2str(dsf_cmd_t cmd);
281
282#ifdef __cplusplus
283}
284#endif
285
286#endif /* _ACFUTILS_DSF_H_ */
const dsf_atom_t * dsf_iter(const dsf_atom_t *parent, uint32_t atom_id, const dsf_atom_t *prev)
Definition dsf.c:1052
const dsf_atom_t * dsf_lookup_v(const dsf_t *dsf, const dsf_lookup_t *lookup)
Definition dsf.c:1006
bool_t dsf_parse_cmds(const dsf_t *dsf, dsf_cmd_cb_t user_cbs[NUM_DSF_CMDS], void *userinfo, char reason[DSF_REASON_SZ])
Definition dsf.c:1081
dsf_t * dsf_parse(uint8_t *buf, size_t bufsz, char reason[DSF_REASON_SZ])
Definition dsf.c:707
const dsf_atom_t * dsf_lookup(const dsf_t *dsf,...)
Definition dsf.c:963
const char * dsf_cmd2str(dsf_cmd_t cmd)
Definition dsf.c:1152
dsf_t * dsf_init(const char *filename)
Definition dsf.c:173
void dsf_fini(dsf_t *dsf)
Definition dsf.c:786
char * dsf_dump(const dsf_t *dsf)
Definition dsf.c:922
Definition dsf.h:156