libdragon
|
Asset Subsystem. More...
Go to the source code of this file.
Macros | |
#define | asset_init_compression(level) |
Enable a non-default compression level. More... | |
Functions | |
void * | asset_load (const char *fn, int *sz) |
Load an asset file (possibly uncompressing it) More... | |
FILE * | asset_fopen (const char *fn, int *sz) |
Open an asset file for reading (with transparent decompression) More... | |
Asset Subsystem.
#define asset_init_compression | ( | level | ) |
Enable a non-default compression level.
This function must be called if any asset that will be loaded use a non-default compression level. The default compression level is 1, for which no initialization is required.
Currently, only level 2 requires initialization. If you have any assets compressed with level 2, you must call this function before loading them.
level | Compression level to initialize |
void * asset_load | ( | const char * | fn, |
int * | sz | ||
) |
Load an asset file (possibly uncompressing it)
This function loads a file from a file system (eg: from ROM or SD). If the file was compressed using the mkasset tool, it will be automatically uncompressed.
fn | Filename to load (including filesystem prefix, eg: "rom:/foo.dat") |
sz | If not NULL, this will be filed with the uncompressed size of the loaded file |
FILE * asset_fopen | ( | const char * | fn, |
int * | sz | ||
) |
Open an asset file for reading (with transparent decompression)
This function opens a file from a file system (eg: from ROM or SD). If the file was compressed using the mkasset tool, it will be automatically uncompressed as it is being read.
Note that since the file might be compressed, the returned FILE* cannot be arbitrarily seeked backward, as that would be impossible to do efficiently on a compressed file. Seeking forward is supported and is simulated by reading (decompressing) and discarding data. You can rewind the file to the start though, (by using either fseek or rewind).
This behavior of the returned file is enforced also for non compressed assets, so that the code is ready to switch to compressed assets if required. If you need random access to an uncompressed file, simply use the standard fopen() function.
fn | Filename to load (including filesystem prefix, eg: "rom:/foo.dat") |
sz | If not NULL, this will be filed with the uncompressed size of the loaded file |