|
Datafile routines
Datafiles are created by the grabber utility, and have a .dat extension. They can contain bitmaps, palettes, fonts, samples, MIDI music, FLI/FLC animations, and any other binary data that you import. Warning: when using truecolor images, you should always set the graphics mode before loading any bitmap data! Otherwise the pixel format (RGB or BGR) will not be known, so the file may be converted wrongly. See the documentation for pack_fopen() for information about how to read directly from a specific datafile object.
DATAFILE *load_datafile(const char *filename);
DATAFILE *load_datafile_callback(const char *filename,
void (*callback)(DATAFILE *d));
void unload_datafile(DATAFILE *dat);
DATAFILE *load_datafile_object(const char *filename,
const char *objectname);
void unload_datafile_object(DATAFILE *dat);
DATAFILE *find_datafile_object(const DATAFILE *dat, const char *objectname);
const char *get_datafile_property(const DATAFILE *dat, int type);
void register_datafile_object(int id, void *(*load)(PACKFILE *f, long size),
void (*destroy)(void *data));
void fixup_datafile(DATAFILE *data);
When you load a datafile, you will obtain a pointer to an array of DATAFILE structures: typedef struct DATAFILE { void *dat; - pointer to the actual data int type; - type of the data long size; - size of the data in bytes void *prop; - list of object properties } DATAFILE;The type field will be one of the values: DAT_FILE - dat points to a nested datafile DAT_DATA - dat points to a block of binary data DAT_FONT - dat points to a font object DAT_SAMPLE - dat points to a sample structure DAT_MIDI - dat points to a MIDI file DAT_PATCH - dat points to a GUS patch file DAT_FLI - dat points to an FLI/FLC animation DAT_BITMAP - dat points to a BITMAP structure DAT_RLE_SPRITE - dat points to a RLE_SPRITE structure DAT_C_SPRITE - dat points to a linear compiled sprite DAT_XC_SPRITE - dat points to a mode-X compiled sprite DAT_PALETTE - dat points to an array of 256 RGB structures DAT_END - special flag to mark the end of the data listThe grabber program can also produce a header file defining the index of each object within the file as a series of #defined constants, using the names you gave the objects in the grabber. So, for example, if you have made a datafile called foo.dat which contains a bitmap called THE_IMAGE, you could display it with the code fragment: #include "foo.h"If you are programming in C++ you will get an error because the dat field is a void pointer and draw_sprite() expects a BITMAP pointer. You can get around this with a cast, eg: draw_sprite(screen, (BITMAP *)data[THE_IMAGE].dat, x, y);When you load a single datafile object, you will obtain a pointer to a single DATAFILE structure. This means that you don't access it any more like an array, and it doesn't have any DAT_END object. Example: music_object = load_datafile_object("datafile.dat", "MUSIC"); play_midi(music_object->dat); |