/***************************************************************
                           datafile.h
 ***************************************************************/

module allegro.datafile;

import allegro.base;
import allegro.file;
import allegro.gfx;
import allegro.palette;
import allegro.internal.dversion;


alias allegro.base.AL_ID DAT_ID;
alias allegro.base._AL_ID _DAT_ID;


const int DAT_MAGIC        = _DAT_ID!('A','L','L','.');
const int DAT_FILE         = _DAT_ID!('F','I','L','E');
const int DAT_DATA         = _DAT_ID!('D','A','T','A');
const int DAT_FONT         = _DAT_ID!('F','O','N','T');
const int DAT_SAMPLE       = _DAT_ID!('S','A','M','P');
const int DAT_MIDI         = _DAT_ID!('M','I','D','I');
const int DAT_PATCH        = _DAT_ID!('P','A','T',' ');
const int DAT_FLI          = _DAT_ID!('F','L','I','C');
const int DAT_BITMAP       = _DAT_ID!('B','M','P',' ');
const int DAT_RLE_SPRITE   = _DAT_ID!('R','L','E',' ');
const int DAT_C_SPRITE     = _DAT_ID!('C','M','P',' ');
const int DAT_XC_SPRITE    = _DAT_ID!('X','C','M','P');
const int DAT_PALETTE      = _DAT_ID!('P','A','L',' ');
const int DAT_PROPERTY     = _DAT_ID!('p','r','o','p');
const int DAT_NAME         = _DAT_ID!('N','A','M','E');
const int DAT_END          = -1;


struct DATAFILE_PROPERTY
{
   char *dat;                          /* pointer to the data */
   int type;                           /* property type */
}


struct DATAFILE
{
   void *dat;                          /* pointer to the data */
   int type;                           /* object type */
   int size;                           /* size of the object */
   DATAFILE_PROPERTY *prop;            /* object properties */
}


struct DATAFILE_INDEX
{
   char *filename;                     /* datafile name (path) */
   int *offset;                        /* list of offsets */
}

extern (C) {

DATAFILE * load_datafile (in char *filename);
DATAFILE * load_datafile_callback (in char *filename, void (*callback) (DATAFILE *));
DATAFILE_INDEX * create_datafile_index (in char *filename);
void unload_datafile (DATAFILE *dat);
void destroy_datafile_index (DATAFILE_INDEX *index);

DATAFILE * load_datafile_object (in char *filename, in char *objectname);
DATAFILE * load_datafile_object_indexed (in DATAFILE_INDEX *index, int item);
void unload_datafile_object (DATAFILE *dat);

DATAFILE * find_datafile_object (in DATAFILE *dat, in char *objectname);
stringz get_datafile_property (in DATAFILE *dat, int type);
void register_datafile_object (int id_, void * (*load) (PACKFILE *f, int size), void (*destroy) (void *data));

void fixup_datafile (DATAFILE *data);

BITMAP * load_bitmap (in char *filename, RGB *pal);
BITMAP * load_bmp (in char *filename, RGB *pal);
BITMAP * load_bmp_pf (PACKFILE *f, RGB *pal);
BITMAP * load_lbm (in char *filename, RGB *pal);
BITMAP * load_pcx (in char *filename, RGB *pal);
BITMAP * load_pcx_pf (PACKFILE *f, RGB *pal);
BITMAP * load_tga (in char *filename, RGB *pal);
BITMAP * load_tga_pf (PACKFILE *f, RGB *pal);

int save_bitmap (in char *filename, BITMAP *bmp, in RGB *pal);
int save_bmp (in char *filename, BITMAP *bmp, in RGB *pal);
int save_bmp_pf (PACKFILE *f, BITMAP *bmp, in RGB *pal);
int save_pcx (in char *filename, BITMAP *bmp, in RGB *pal);
int save_pcx_pf (PACKFILE *f, BITMAP *bmp, in RGB *pal);
int save_tga (in char *filename, BITMAP *bmp, in RGB *pal);
int save_tga_pf (PACKFILE *f, BITMAP *bmp, in RGB *pal);

void register_bitmap_file_type (in char*ext, BITMAP * (*load) (in char *filename, RGB *pal), int (*save) (in char *filename, BITMAP *bmp, in RGB *pal));

} // extern (C)
