libdragon
Macros | Functions
asset.h File Reference

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...
 

Detailed Description

Asset Subsystem.

Macro Definition Documentation

◆ asset_init_compression

#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.

// Load an asset that might use level 2 compression
sprite_t *hero = sprite_load("rom:/hero.sprite");
#define asset_init_compression(level)
Enable a non-default compression level.
Definition: asset.h:103
sprite_t * sprite_load(const char *fn)
Load a sprite from a filesystem (eg: ROM)
Definition: sprite.c:62
Sprite structure.
Definition: sprite.h:40
Parameters
levelCompression level to initialize
See also
asset_load

Function Documentation

◆ asset_load()

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.

Parameters
fnFilename to load (including filesystem prefix, eg: "rom:/foo.dat")
szIf not NULL, this will be filed with the uncompressed size of the loaded file
Returns
void* Pointer to the loaded file (must be freed with free() when done)

◆ asset_fopen()

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.

Parameters
fnFilename to load (including filesystem prefix, eg: "rom:/foo.dat")
szIf not NULL, this will be filed with the uncompressed size of the loaded file
Returns
FILE* FILE pointer to use with standard C functions (fread, fclose)