You are not logged in.
Pages: 1
This is a small example I wrote for someone on the GMC recently, it does not support compression and should probably be expanded to convert from any bit depth to any other bit depth, but if you would like it here it is.
- Leif
//////////////////////////////////////////////////
// bmp_32_to_24
// Converts uncompressed 32 bit bitmaps to 24
// bit bitmaps.
//
// Arguments:
// argument0 - The file to convert as a
// relative or absolute path.
// argument1 - The file to output as a
// relative or absolute path.
//
// Returns:
// Nothing
//
//
//////////////////////////////////////////////////
var in, out, comp, in_size, image_size, out_image_size, i;
in = file_bin_open(argument0,0);
out = file_bin_open(argument1,1);
in_size = file_bin_size(in);
image_size = in_size - 54;
out_image_size = ( image_size / 4 ) * 3;
file_bin_write_word(out, 2, 0, 19778);
file_bin_write_word(out, 4, 0, out_image_size + 54 );
file_bin_seek(in, 6);
repeat ( 5 ) {
file_bin_write_word(out, 4, 0, file_bin_read_word(in, 4, 0) );
}
file_bin_write_word(out, 2, 0, file_bin_read_word(in, 2, 0) );
file_bin_write_word(out, 2, 0, 24);
file_bin_seek(in, 30);
comp = file_bin_read_word(in, 4, 0);
if ( comp != 0) {
// TODO: Add a switch statement here that deals
// with different modes of compression.
show_error("Bitmap File is Compressed.", 0);
}
file_bin_write_word(out, 4, 0, 0);
file_bin_write_word(out, 4, 0, out_image_size);
file_bin_write_word(out, 16, 0, 0);
file_bin_seek(in, 54);
file_bin_seek(out, 54);
for(i = 0; i < image_size / 4; i += 1) {
repeat ( 3 ) {
file_bin_write_byte(out, file_bin_read_byte(in) );
}
file_bin_seek(in, file_bin_position(in) + 1);
}
file_bin_close(in);
file_bin_close(out);
Leif902
Offline
Great.
Offline
Nice. I wonder if it would be faster if you replaced the seek with a dummy byte read. I probably would have done the main loop like this:
repeat (image_size div 4) {
file_bin_write_byte(out, file_bin_read_byte(in));
file_bin_write_byte(out, file_bin_read_byte(in));
file_bin_write_byte(out, file_bin_read_byte(in));
file_bin_read_byte(in);
}
Here are the dependent file_bin_read_word and file_bin_write_word functions for Leif's script.
Abusing forum power since 1986.
Offline
Good point Xot, I like that, a single repeat loop like that should improve the speed a bit as well, I didn't even think about it.
- Leif
EDIT: I'm going to assume the seek performs a dummy byte read from the beginning of the file, in which case it (the dummy byte read) may be faster, but who knows? If I have time later I'll time it and check it out.
EDIT: Just re-read this and it sounded confusing... by "in which case it may be faster" I was not refering to the file_bin_seek function, but a dummy byte read... inserted it for clarity.
Last edited by leif902 (2008-01-01 20:32:00)
Leif902
Offline
Pages: 1