5#ifndef __LIBDRAGON_ASSET_INTERNAL_H
6#define __LIBDRAGON_ASSET_INTERNAL_H
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
25static inline int asset_winsize_from_flags(uint16_t flags) {
28 return (2*1024) << flags;
30 return (16*1024) >> flags;
34static int asset_winsize_to_flags(
int winsize) {
57_Static_assert(
sizeof(
asset_header_t) == 20,
"invalid sizeof(asset_header_t)");
64 void (*decompress_init)(
void *state,
int fd,
int winsize);
67 ssize_t (*decompress_read)(
void *state,
void *buf,
size_t len);
70 void (*decompress_reset)(
void *state);
73 void* (*decompress_full)(
const char *fn,
int fd,
size_t cmp_size,
size_t len);
76 int (*decompress_full_inplace)(
const uint8_t *in,
size_t cmp_size, uint8_t *out,
size_t len);
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
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