-
Notifications
You must be signed in to change notification settings - Fork 2
/
lgpng.h
730 lines (650 loc) · 15.6 KB
/
lgpng.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
/*
* Copyright (c) 2018,2022-2023 Tristan Le Guern <[email protected]>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#ifndef LGPNG_H__
#define LGPNG_H__
/* Global variables */
extern uint8_t png_sig[8];
struct chunk {
uint32_t length; /* Actualy from 0 to LONG_MAX */
uint8_t type[4];
uint32_t crc;
uint8_t data[];
};
/* IHDR chunk */
enum colourtype {
COLOUR_TYPE_GREYSCALE,
COLOUR_TYPE_FILLER1,
COLOUR_TYPE_TRUECOLOUR,
COLOUR_TYPE_INDEXED,
COLOUR_TYPE_GREYSCALE_ALPHA,
COLOUR_TYPE_FILLER5,
COLOUR_TYPE_TRUECOLOUR_ALPHA,
COLOUR_TYPE__MAX,
};
extern const char *colourtypemap[COLOUR_TYPE__MAX];
enum compressiontype {
COMPRESSION_TYPE_DEFLATE,
COMPRESSION_TYPE__MAX,
};
extern const char *compressiontypemap[COMPRESSION_TYPE__MAX];
enum filtermethod {
FILTER_METHOD_ADAPTIVE,
FILTER_METHOD__MAX,
};
extern const char *filtermethodmap[FILTER_METHOD__MAX];
enum interlace_method {
INTERLACE_METHOD_STANDARD,
INTERLACE_METHOD_ADAM7,
INTERLACE_METHOD__MAX,
};
extern const char *interlacemap[INTERLACE_METHOD__MAX];
struct IHDR {
uint32_t length;
uint8_t type[4];
uint32_t crc;
struct {
uint32_t width;
uint32_t height;
uint8_t bitdepth;
uint8_t colourtype;
uint8_t compression;
uint8_t filter;
uint8_t interlace;
} __attribute__((packed)) data;
};
/* PLTE chunk */
struct rgb8 {
uint8_t red;
uint8_t green;
uint8_t blue;
} __attribute__((packed));
struct PLTE {
uint32_t length;
uint8_t type[4];
uint32_t crc;
struct {
size_t entries;
struct rgb8 entry[256];
} __attribute__((packed)) data;
};
/* IDAT chunk */
struct IDAT {
uint32_t length;
uint8_t type[4];
uint32_t crc;
struct {
uint8_t *data;
} __attribute__((packed)) data;
};
/* tRNS chunk */
struct tRNS {
uint32_t length;
uint8_t type[4];
uint32_t crc;
struct {
uint16_t gray;
uint16_t red;
uint16_t green;
uint16_t blue;
size_t entries;
uint8_t palette[256];
} __attribute__((packed)) data;
};
/* cHRM chunk */
struct cHRM {
uint32_t length;
uint8_t type[4];
uint32_t crc;
struct {
uint32_t whitex;
uint32_t whitey;
uint32_t redx;
uint32_t redy;
uint32_t greenx;
uint32_t greeny;
uint32_t bluex;
uint32_t bluey;
} __attribute__((packed)) data;
};
/* gAMA chunk */
struct gAMA {
uint32_t length;
uint8_t type[4];
uint32_t crc;
struct {
uint32_t gamma;
} __attribute__((packed)) data;
};
/* iCCP chunk */
struct iCCP {
uint32_t length;
uint8_t type[4];
uint32_t crc;
struct {
size_t namez;
uint8_t name[80];
uint8_t compression;
size_t profilez;
uint8_t *profile;
} __attribute__((packed)) data;
};
/* sBIT chunk */
struct sBIT {
uint32_t length;
uint8_t type[4];
uint32_t crc;
struct {
uint8_t sgreyscale;
uint8_t sred;
uint8_t sgreen;
uint8_t sblue;
uint8_t salpha;
} __attribute__((packed)) data;
};
/* sRGB chunk */
enum rendering_intent {
RENDERING_INTENT_PERCEPTUAL,
RENDERING_INTENT_RELATIVE,
RENDERING_INTENT_SATURATION,
RENDERING_INTENT_ABSOLUTE,
RENDERING_INTENT__MAX,
};
extern const char *rendering_intentmap[RENDERING_INTENT__MAX];
struct sRGB {
uint32_t length;
uint8_t type[4];
uint32_t crc;
struct {
uint8_t intent;
} __attribute__((packed)) data;
};
/* cICP chunk */
struct cICP {
uint32_t length;
uint8_t type[4];
uint32_t crc;
struct {
uint8_t colour_primaries;
uint8_t transfer_function;
uint8_t matrix_coefficients;
uint8_t video_full_range;
} __attribute__((packed)) data;
};
/* tEXt chunk */
struct tEXt {
uint32_t length;
uint8_t type[4];
uint32_t crc;
struct {
uint8_t keyword[80];
uint8_t *text;
} __attribute__((packed)) data;
};
/* zTXt chunk */
struct zTXt {
uint32_t length;
uint8_t type[4];
uint32_t crc;
struct {
size_t keywordz;
uint8_t keyword[80];
uint8_t compression;
size_t textz;
uint8_t *text;
} __attribute__((packed)) data;
};
/* bKGD chunk */
struct rgb16 {
uint16_t red;
uint16_t green;
uint16_t blue;
};
struct bKGD {
uint32_t length;
uint8_t type[4];
uint32_t crc;
struct {
uint16_t greyscale;
uint8_t paletteindex;
struct rgb16 rgb;
} __attribute__((packed)) data;
};
/* hIST chunk */
struct hIST {
uint32_t length;
uint8_t type[4];
uint32_t crc;
struct {
uint16_t frequency[256];
} __attribute__((packed)) data;
};
/* pHYs chunk */
enum unitspecifier {
UNITSPECIFIER_UNKNOWN,
UNITSPECIFIER_METRE,
UNITSPECIFIER__MAX,
};
extern const char *unitspecifiermap[UNITSPECIFIER__MAX];
struct pHYs {
uint32_t length;
uint8_t type[4];
uint32_t crc;
struct {
uint32_t ppux;
uint32_t ppuy;
uint8_t unitspecifier;
} __attribute__((packed)) data;
};
/* sPLT chunk */
struct splt_entry {
union {
uint8_t raw[10];
struct {
uint16_t red;
uint16_t green;
uint16_t blue;
uint16_t alpha;
uint16_t frequency;
} depth16;
struct {
uint8_t red;
uint8_t green;
uint8_t blue;
uint8_t alpha;
uint16_t frequency;
} depth8;
};
};
struct sPLT {
uint32_t length;
uint8_t type[4];
uint32_t crc;
struct {
char palettename[80];
uint8_t sampledepth;
size_t entries;
struct splt_entry *entry;
} __attribute__((packed)) data;
};
/* eXIf chunk */
struct eXIf {
uint32_t length;
uint8_t type[4];
uint32_t crc;
struct {
uint8_t *profile;
} __attribute__((packed)) data;
};
/* tIME chunk */
struct tIME {
uint32_t length;
uint8_t type[4];
uint32_t crc;
struct {
uint16_t year;
uint8_t month;
uint8_t day;
uint8_t hour;
uint8_t minute;
uint8_t second;
} __attribute__((packed)) data;
};
/* acTL chunk */
struct acTL {
uint32_t length;
uint8_t type[4];
uint32_t crc;
struct {
uint32_t num_frames;
uint32_t num_plays;
} __attribute__((packed)) data;
};
/* fcTL chunk */
enum dispose_op {
DISPOSE_OP_NONE,
DISPOSE_OP_BACKGROUND,
DISPOSE_OP_PREVIOUS,
DISPOSE_OP__MAX,
};
extern const char *dispose_opmap[DISPOSE_OP__MAX];
enum blend_op {
BLEND_OP_SOURCE,
BLEND_OP_OVER,
BLEND_OP__MAX,
};
extern const char *blend_opmap[BLEND_OP__MAX];
struct fcTL {
uint32_t length;
uint8_t type[4];
uint32_t crc;
struct {
uint32_t sequence_number;
uint32_t width;
uint32_t height;
uint32_t x_offset;
uint32_t y_offset;
uint16_t delay_num;
uint16_t delay_den;
uint8_t dispose_op;
uint8_t blend_op;
} __attribute__((packed)) data;
};
/* fdAT chunk */
struct fdAT {
uint32_t length;
uint8_t type[4];
uint32_t crc;
struct {
uint32_t sequence_number;
uint8_t *frame_data;
} __attribute__((packed)) data;
};
/* oFFs chunk */
enum offs_unitspecifier {
OFFS_UNITSPECIFIER_PIXEL,
OFFS_UNITSPECIFIER_MICROMETER,
OFFS_UNITSPECIFIER__MAX,
};
extern const char *offsunitspecifiermap[OFFS_UNITSPECIFIER__MAX];
struct oFFs {
uint32_t length;
uint8_t type[4];
uint32_t crc;
struct {
int32_t x_position;
int32_t y_position;
uint8_t unitspecifier; /* enum offs_unitspecifier */
} __attribute__((packed)) data;
};
/* gIFg chunk */
/* Values found un gif89a section 23 Graphic Control Extension */
enum disposal_method {
DISPOSAL_METHOD_NONE,
DISPOSAL_METHOD_DO_NOT,
DISPOSAL_METHOD_RESTORE_BACKGROUND,
DISPOSAL_METHOD_RESTORE_PREVIOUS,
DISPOSAL_METHOD_RESERVED1,
DISPOSAL_METHOD_RESERVED2,
DISPOSAL_METHOD_RESERVED3,
DISPOSAL_METHOD_RESERVED4,
DISPOSAL_METHOD__MAX,
};
extern const char *disposal_methodmap[DISPOSAL_METHOD__MAX];
enum user_input {
USER_INPUT_NO,
USER_INPUT_YES,
USER_INPUT__MAX,
};
extern const char *user_inputmap[USER_INPUT__MAX];
struct gIFg {
uint32_t length;
uint8_t type[4];
uint32_t crc;
struct {
uint8_t disposal_method;
uint8_t user_input;
uint16_t delay_time;
} __attribute__((packed)) data;
};
/* gIFx chunk */
struct gIFx {
uint32_t length;
uint8_t type[4];
uint32_t crc;
struct {
uint8_t identifier[8];
uint8_t code[3];
uint8_t *data;
} __attribute__((packed)) data;
};
/* sTER chunk */
enum ster_mode {
STER_MODE_CROSS,
STER_MODE_DIVERGING,
STER_MODE__MAX,
};
extern const char *ster_mode_map[STER_MODE__MAX];
struct sTER {
uint32_t length;
uint8_t type[4];
uint32_t crc;
struct {
uint8_t mode;
} __attribute__((packed)) data;
};
/* vpAg chunk */
enum vpag_unitspecifier {
VPAG_UNITSPECIFIER_PIXEL,
VPAG_UNITSPECIFIER__MAX,
};
extern const char *vpagunitspecifiermap[VPAG_UNITSPECIFIER__MAX];
struct vpAg {
uint32_t length;
uint8_t type[4];
uint32_t crc;
struct {
uint32_t width;
uint32_t height;
uint8_t unitspecifier; /* enum vpag_unitspecifier */
} __attribute__((packed)) data;
};
/* caNv chunk */
struct caNv {
uint32_t length;
uint8_t type[4];
uint32_t crc;
struct {
uint32_t width;
uint32_t height;
int32_t x_position;
int32_t y_position;
} __attribute__((packed)) data;
};
/* orNt chunk */
typedef enum
{
ORIENTATION_UNDEFINED,
ORIENTATION_TOPLEFT,
ORIENTATION_TOPRIGHT,
ORIENTATION_BOTTOMRIGHT,
ORIENTATION_BOTTOMLEFT,
ORIENTATION_LEFTTOP,
ORIENTATION_RIGHTTOP,
ORIENTATION_RIGHTBOTTOM,
ORIENTATION_LEFTBOTTOM,
ORIENTATION__MAX,
} orientation;
extern const char *orientationmap[ORIENTATION__MAX];
struct orNt {
uint32_t length;
uint8_t type[4];
uint32_t crc;
struct {
uint8_t orientation;
} __attribute__((packed)) data;
};
/* skMf chunk */
struct skMf {
uint32_t length;
uint8_t type[4];
uint32_t crc;
struct {
uint8_t *json;
} __attribute__((packed)) data;
};
/* skRf chunk */
struct skRf {
uint32_t length;
uint8_t type[4];
uint32_t crc;
struct {
uint8_t header[16];
uint8_t *data;
} __attribute__((packed)) data;
};
/* waLV chunk */
typedef enum
{
WALV_SOIL_ART,
WALV_SOIL_CHEESE,
WALV_SOIL_CLASSIC_BEACH,
WALV_SOIL_CLASSIC_DESERT,
WALV_SOIL_CLASSIC_FARM,
WALV_SOIL_CLASSIC_FOREST,
WALV_SOIL_CLASSIC_HELL,
WALV_SOIL_CONSTRUCTION,
WALV_SOIL_DESERT,
WALV_SOIL_DUNGEON,
WALV_SOIL_EASTER,
WALV_SOIL_FOREST,
WALV_SOIL_FRUIT,
WALV_SOIL_GULF,
WALV_SOIL_HELL,
WALV_SOIL_HOSPITAL,
WALV_SOIL_JUNGLE,
WALV_SOIL_MANHATTAN,
WALV_SOIL_MEDIEVAL,
WALV_SOIL_MUSIC,
WALV_SOIL_PIRATE,
WALV_SOIL_SNOW,
WALV_SOIL_SPACE,
WALV_SOIL_SPORTS,
WALV_SOIL_TENTACLE,
WALV_SOIL_TIME,
WALV_SOIL_TOOLS,
WALV_SOIL_TRIBAL,
WALV_SOIL_URBAN,
WALV_SOIL__MAX,
} walv_soil_textures;
extern const char *walv_soil_textures_map[WALV_SOIL__MAX];
struct waLV {
uint32_t length;
uint8_t type[4];
uint32_t crc;
struct {
uint32_t land_seed;
uint32_t object_seed;
uint32_t cavern;
int32_t style; /* can be -1 */
uint32_t borders;
uint32_t object_percent;
uint32_t bridge_percent;
uint32_t water_level;
uint32_t soil_texture_idx;
uint32_t water_colour;
uint8_t worm_places;
} __attribute__((packed)) data;
};
/* msOG chunk */
struct msOG {
uint32_t length;
uint8_t type[4];
uint32_t crc;
struct {
uint8_t header[11];
size_t gifz;
uint8_t *ptr;
} __attribute__((packed)) data;
};
/* tpNG chunk */
struct tpNG {
uint32_t length;
uint8_t type[4];
uint32_t crc;
struct {
uint8_t version[4];
uint8_t password;
uint8_t alpha256;
uint8_t unused[2];
} __attribute__((packed)) data;
};
/* chunks */
bool lgpng_validate_keyword(uint8_t *, size_t);
bool lgpng_is_official_keyword(uint8_t *, size_t);
int lgpng_create_IHDR_from_data(struct IHDR *, uint8_t *, uint32_t);
int lgpng_create_PLTE_from_data(struct PLTE *, uint8_t *, uint32_t);
int lgpng_create_IDAT_from_data(struct IDAT *, uint8_t *, uint32_t);
int lgpng_create_tRNS_from_data(struct tRNS *, struct IHDR *, uint8_t *, uint32_t);
int lgpng_create_cHRM_from_data(struct cHRM *, uint8_t *, uint32_t);
int lgpng_create_gAMA_from_data(struct gAMA *, uint8_t *, uint32_t);
int lgpng_create_iCCP_from_data(struct iCCP *, uint8_t *, uint32_t);
int lgpng_create_sBIT_from_data(struct sBIT *, struct IHDR *, uint8_t *, uint32_t);
int lgpng_create_sRGB_from_data(struct sRGB *, uint8_t *, uint32_t);
int lgpng_create_cICP_from_data(struct cICP *, uint8_t *, uint32_t);
/*int lgpng_create_iTXt_from_data(struct iTXt *, uint8_t *, uint32_t);*/
int lgpng_create_tEXt_from_data(struct tEXt *, uint8_t *, uint32_t);
int lgpng_create_zTXt_from_data(struct zTXt *, uint8_t *, uint32_t);
int lgpng_create_bKGD_from_data(struct bKGD *, struct IHDR *, struct PLTE *, uint8_t *, uint32_t);
int lgpng_create_hIST_from_data(struct hIST *, struct PLTE *, uint8_t *, uint32_t);
int lgpng_create_pHYs_from_data(struct pHYs *, uint8_t *, uint32_t);
int lgpng_create_sPLT_from_data(struct sPLT *, uint8_t *, uint32_t);
int lgpng_create_eXIf_from_data(struct eXIf *, uint8_t *, uint32_t);
int lgpng_create_tIME_from_data(struct tIME *, uint8_t *, uint32_t);
int lgpng_create_acTL_from_data(struct acTL *, uint8_t *, uint32_t);
int lgpng_create_fcTL_from_data(struct fcTL *, uint8_t *, uint32_t);
int lgpng_create_fdAT_from_data(struct fdAT *, uint8_t *, uint32_t);
int lgpng_create_oFFs_from_data(struct oFFs *, uint8_t *, uint32_t);
int lgpng_create_gIFg_from_data(struct gIFg *, uint8_t *, uint32_t);
int lgpng_create_gIFx_from_data(struct gIFx *, uint8_t *, uint32_t);
int lgpng_create_sTER_from_data(struct sTER *, uint8_t *, uint32_t);
/* chunks_extra */
int lgpng_create_vpAg_from_data(struct vpAg *, uint8_t *, uint32_t);
int lgpng_create_caNv_from_data(struct caNv *, uint8_t *, uint32_t);
int lgpng_create_orNt_from_data(struct orNt *, uint8_t *, uint32_t);
int lgpng_create_skMf_from_data(struct skMf *, uint8_t *, uint32_t);
int lgpng_create_skRf_from_data(struct skRf *, uint8_t *, uint32_t);
int lgpng_create_waLV_from_data(struct waLV *, uint8_t *, uint32_t);
int lgpng_create_msOG_from_data(struct msOG *, uint8_t *, uint32_t);
int lgpng_create_tpNG_from_data(struct tpNG *, uint8_t *, uint32_t);
enum lgpng_err {
LGPNG_OK = 0,
LGPNG_INVALID_PARAM,
LGPNG_TOO_SHORT,
LGPNG_INVALID_CHUNK_LENGTH,
LGPNG_INVALID_CHUNK_NAME,
/* Generic error, to be refined */
LGPNG_ERROR,
};
enum lgpng_err lgpng_data_is_png(uint8_t *, size_t);
enum lgpng_err lgpng_data_get_length(uint8_t *, size_t, uint32_t *);
enum lgpng_err lgpng_data_get_type(uint8_t *, size_t, uint8_t [4]);
enum lgpng_err lgpng_data_get_data(uint8_t *, size_t, uint32_t, uint8_t **);
enum lgpng_err lgpng_data_get_crc(uint8_t *, size_t, uint32_t *);
size_t lgpng_data_write_sig(uint8_t *);
size_t lgpng_data_write_chunk(uint8_t *, uint32_t, uint8_t [4], uint8_t *, uint32_t);
/* stream */
enum lgpng_err lgpng_stream_is_png(FILE *);
enum lgpng_err lgpng_stream_get_length(FILE *, uint32_t *);
enum lgpng_err lgpng_stream_get_type(FILE *, uint8_t [4]);
enum lgpng_err lgpng_stream_get_data(FILE *, uint32_t, uint8_t **);
enum lgpng_err lgpng_stream_skip_data(FILE *, uint32_t);
enum lgpng_err lgpng_stream_get_crc(FILE *, uint32_t *);
enum lgpng_err lgpng_stream_write_sig(FILE *);
enum lgpng_err lgpng_stream_write_chunk(FILE *, uint32_t, uint8_t [4], uint8_t *, uint32_t);
/* crc */
extern uint32_t lgpng_crc_table[256];
uint32_t lgpng_crc_init(void);
uint32_t lgpng_crc_update(uint32_t, uint8_t *, size_t);
uint32_t lgpng_crc_finalize(uint32_t);
uint32_t lgpng_crc(uint8_t *, size_t);
bool lgpng_chunk_crc(uint32_t, uint8_t [4], uint8_t *, uint32_t *);
/* helper macro */
#define MSB16(i) (i & 0xFF00)
#define LSB16(i) (i & 0x00FF)
#endif