GMLscripts.com

Discuss and collaborate on GML scripts
Invert

You are not logged in.

#1 2008-02-23 19:31:26

$pecter
Member
From: Australia
Registered: 2008-01-18
Posts: 9

BMP Format

I'm trying to develop a script for loading the contents of a .BMP file into an array, and a script to save them back into a .bmp.
I can load alright, but the file always becomes unusable when I save.
A .zip of the source file and an image is located here.
Does anyone know what I'm doing wrong? Or does anybody have a working script?

NOTE: I know I'm not utilizing a lot of the header data, but I'm just trying to get the basic working before I go further.

Last edited by $pecter (2008-02-25 01:10:33)

Offline

#2 2008-02-23 22:33:07

Yourself
Member
Registered: 2007-10-09
Posts: 48

Re: BMP Format

repeat(4)
    width+=file_bin_read_byte(file);

For one, that's not how little-endian 32-bit integers work.  You can't just add the byte values together.  Just like how 1111 doesn't have the value "4".  You're completely ignoring place value.

Offline

#3 2008-02-24 02:53:53

$pecter
Member
From: Australia
Registered: 2008-01-18
Posts: 9

Re: BMP Format

For one, that's not how little-endian 32-bit integers work.  You can't just add the byte values together.  Just like how 1111 doesn't have the value "4".  You're completely ignoring place value.

Wow, it was some extreme co-incidence that it worked on that image.
Now I'm confused...
So I would do it like this?

repeat(4)
    width+=string(file_bin_read_byte(file));
width=bin_to_dec(bytes_to_bin(width));

Offline

#4 2008-02-24 12:15:49

xot
Administrator
Registered: 2007-08-18
Posts: 1,240

Re: BMP Format

More like this for reading a four-byte little-endian word:

Expand// Coded for clarity, not brevity.
b1 = file_bin_read_byte(file);
b2 = file_bin_read_byte(file);
b3 = file_bin_read_byte(file);
b4 = file_bin_read_byte(file);
value = (b4 << 24) | (b3 << 16) | (b2 << 8) | (b1)

You might have better luck using these scripts from Leif902:

http://www.gmlscripts.com/script/file_bin_read_word
http://www.gmlscripts.com/script/file_bin_write_word


Abusing forum power since 1986.

Offline

#5 2008-02-25 01:15:42

$pecter
Member
From: Australia
Registered: 2008-01-18
Posts: 9

Re: BMP Format

Thanks xot, that works. I think I better read up on bitwise operations now.

PS. Sorry for the inconvenience of uploading the .gm6 and making you supply your own .bmp. I meant to upload a .zip. whistle

NEW QUESTION
Now, with my previous code, I'm trying to encode some text into the 'unused' alpha 'channel' of the bmp.
I can't get it to save/load (I can't tell)!
This is what I've got so far.

Last edited by $pecter (2008-02-25 05:36:49)

Offline

Board footer

Powered by FluxBB