05-13-2004, 02:33 AM
I've been trying to load PUT files and BSV files using Allegro and C++. I got the BSV loading function to work, but the put function I can't figure out. Any help is appreciated.
BSV loading:
PUT loading function:
BSV loading:
Code:
BITMAP *load_bsv(char *filename, RGB *palette) {
PACKFILE *f;
BITMAP *bmp = NULL;
char temp[6];
int w, h, i;
if (!(f = pack_fopen(filename, F_READ))) return NULL;
// check if it's a bsaved file
if (pack_getc(f) != 0xfd) goto error;
// skip source seg:off and length
pack_fread(temp, 6, f);
if (pack_feof(f)) goto error;
// get sprite dimensions
w = pack_igetw(f) / 8;
h = pack_igetw(f);
bmp = create_bitmap_ex(8, w, h);
if (!bmp) goto error;
clear_to_color(bmp, makecol16(255, 0, 255));
// load the sprite data
for (i = 0; i < h; i++) pack_fread(bmp->line[i], w, f);
// check if there's an appended palette
if ((!pack_feof(f)) && (palette)) {
load appended data as palette data
for (i = 0; i < 256; i++) {
pack_fread(palette[i], 3, f);
if (pack_feof(f)) break;
}
}
error:
pack_fclose(f);
return bmp;
}
PUT loading function:
Code:
BITMAP *load_put(char *filename, RGB *palette) {
clear(screen);
FILE *put_file = fopen(filename, "r");
if (!put_file) {
textprintf(screen, font, 0, 0, gfx.WHITE, "Error opening PP256 file '%s' for input.\n", filename);
return NULL;
}
// read the first pp256 image to find dimensions of each image
short w, h;
fseek(put_file, 7, SEEK_SET);
fread(&w, 2, 1, put_file);
w >>= 3;
fread(&h, 2, 1, put_file);
fseek(put_file, 0, SEEK_END);
int numimgs = (ftell(put_file) - 7) / (w * h);
textprintf(screen, font, 0, 0, gfx.WHITE, "width: %d height: %d images: %d", w, h, numimgs);
BITMAP *bmp = create_bitmap(w, h * numimgs);
fseek(put_file, 7, SEEK_SET);
int imgsize = w * h;
//char data[imgsize];
for (int i = 0; i < numimgs; i++) {
fseek(put_file, 4, SEEK_CUR);
fread(bmp->, 1, imgsize, put_file);
//fwrite(data, 1, imgsize, bmp_file);
}
fclose(put_file);
return bmp;
}