libdragon
Loading...
Searching...
No Matches
asset_internal.h
Go to the documentation of this file.
1
5#ifndef __LIBDRAGON_ASSET_INTERNAL_H
6#define __LIBDRAGON_ASSET_INTERNAL_H
7
8#include <stdint.h>
9#include <stdio.h>
10
11#define ASSET_MAGIC "DCA"
12#define ASSET_FLAG_WINSIZE_MASK 0x0007
13#define ASSET_FLAG_WINSIZE_16K 0x0000
14#define ASSET_FLAG_WINSIZE_8K 0x0001
15#define ASSET_FLAG_WINSIZE_4K 0x0002
16#define ASSET_FLAG_WINSIZE_2K 0x0003
17#define ASSET_FLAG_WINSIZE_32K 0x0004
18#define ASSET_FLAG_WINSIZE_64K 0x0005
19#define ASSET_FLAG_WINSIZE_128K 0x0006
20#define ASSET_FLAG_WINSIZE_256K 0x0007
21#define ASSET_FLAG_INPLACE 0x0100
22#define ASSET_ALIGNMENT 32
23
24__attribute__((used))
25static inline int asset_winsize_from_flags(uint16_t flags) {
27 if (flags & 4)
28 return (2*1024) << flags;
29 else
30 return (16*1024) >> flags;
31}
32
33__attribute__((used))
34static int asset_winsize_to_flags(int winsize) {
35 if (winsize == 16*1024) return ASSET_FLAG_WINSIZE_16K;
36 if (winsize == 8*1024) return ASSET_FLAG_WINSIZE_8K;
37 if (winsize == 4*1024) return ASSET_FLAG_WINSIZE_4K;
38 if (winsize == 2*1024) return ASSET_FLAG_WINSIZE_2K;
39 if (winsize == 32*1024) return ASSET_FLAG_WINSIZE_32K;
40 if (winsize == 64*1024) return ASSET_FLAG_WINSIZE_64K;
41 if (winsize == 128*1024) return ASSET_FLAG_WINSIZE_128K;
42 if (winsize == 256*1024) return ASSET_FLAG_WINSIZE_256K;
43 return -1;
44}
45
47typedef struct {
48 char magic[3];
49 uint8_t version;
50 uint16_t algo;
51 uint16_t flags;
52 uint32_t cmp_size;
53 uint32_t orig_size;
54 uint32_t inplace_margin;
56
57_Static_assert(sizeof(asset_header_t) == 20, "invalid sizeof(asset_header_t)");
58
60typedef struct {
62
64 void (*decompress_init)(void *state, int fd, int winsize);
65
67 ssize_t (*decompress_read)(void *state, void *buf, size_t len);
68
70 void (*decompress_reset)(void *state);
71
73 void* (*decompress_full)(const char *fn, int fd, size_t cmp_size, size_t len);
74
76 int (*decompress_full_inplace)(const uint8_t *in, size_t cmp_size, uint8_t *out, size_t len);
78
80FILE *must_fopen(const char *fn);
82int must_open(const char *fn);
83
84#endif
uint16_t flags
Flags.
Definition asset_internal.h:51
#define ASSET_FLAG_WINSIZE_32K
32 KiB window size
Definition asset_internal.h:17
uint32_t orig_size
Original size in bytes.
Definition asset_internal.h:53
uint8_t version
Version of the asset header.
Definition asset_internal.h:49
#define ASSET_FLAG_WINSIZE_16K
16 KiB window size
Definition asset_internal.h:13
#define ASSET_FLAG_WINSIZE_8K
8 KiB window size
Definition asset_internal.h:14
#define ASSET_FLAG_WINSIZE_MASK
Mask to isolate the window size in the flags.
Definition asset_internal.h:12
#define ASSET_FLAG_WINSIZE_4K
4 KiB window size
Definition asset_internal.h:15
#define ASSET_FLAG_WINSIZE_64K
64 KiB window size
Definition asset_internal.h:18
#define ASSET_FLAG_WINSIZE_2K
2 KiB window size
Definition asset_internal.h:16
#define ASSET_FLAG_WINSIZE_128K
128 KiB window size
Definition asset_internal.h:19
uint32_t inplace_margin
Margin for in-place decompression.
Definition asset_internal.h:54
#define ASSET_FLAG_WINSIZE_256K
256 KiB window size
Definition asset_internal.h:20
uint16_t algo
Compression algorithm.
Definition asset_internal.h:50
int must_open(const char *fn)
Open a file and assert on error.
Definition asset.c:83
FILE * must_fopen(const char *fn)
Open a file as FILE* and assert on error.
Definition asset.c:109
uint32_t cmp_size
Compressed size in bytes.
Definition asset_internal.h:52
Header of a compressed asset.
Definition asset_internal.h:47
A decompression algorithm used by the asset library.
Definition asset_internal.h:60
int state_size
Basic size of the decompression state (without ringbuffer)
Definition asset_internal.h:61