1 #include <allegro.h>
2 #include <stdio.h>
3 
4 /*
5  * Compile with the line g++ -o Export export.cpp `allegro-config --libs`
6  *
7  * This program extracts all bitmaps from an Allegro datafile.
8 */
9 
main(int argc,char * argv[])10 int main(int argc, char *argv[])
11 {
12    int counter = 0;
13    char filename[256];
14    BITMAP *new_bitmap;
15    DATAFILE *my_datafile;
16 
17    if (argc < 2)
18    {
19       printf("usage: export datafile\n");
20       return 0;
21    }
22 
23    allegro_init();
24    set_color_depth(24);
25 
26    // load a datafile
27    my_datafile = load_datafile(argv[1]);
28    if (! my_datafile)
29    {
30         printf("Unable to open datafile.\n");
31         return 1;
32    }
33 
34    // for each bitmap, save to a new file
35    while (counter < 256)
36    {
37       new_bitmap = (BITMAP *) my_datafile[counter].dat;
38       if (new_bitmap)
39       {
40         sprintf(filename, "%d.bmp", counter);
41         save_bmp(filename, new_bitmap, NULL);
42       }
43       counter++;
44    }
45 
46    unload_datafile(my_datafile);
47    return 0;
48 }
49 
50