Dark Bit Factory & Gravity
PROGRAMMING => General coding questions => Topic started by: Shockwave on October 15, 2007
-
In a lot of recent intros, there have been some really great logos that were downgraded to 256 colour indexed palettes, I have been exploring 24 bit bitmaps a little and here is what I understand about them.
They are stored upside down.
Each pixel has three bytes hence 24 bit colour
The bytes are specified in Blue , Green , Red order.
The bitmap contains a header with information such as file size etc.
What I would like to be able to do is to use 24 bit bitmaps and I thought to convert the 24 bit bitmap straight into a .bas file using bin2bas.
I did this and wasn't too horrified to see a 1.7mb file! Meh :) anyway it will crunch down small..
The header as far as I can tell contains a lot of information that I do not need.
All I want are those rgb values so if somebody could tell me how to calculate where the header stops I would be really grateful.
If anything, it should be easier to use 24 bit bitmap images than 8 bit ones.
Thanks.
-
I think that the colours start 55 bytes into the file... I am not sure...
-
The description of the Windows BMP file format can be found here: http://www.fortunecity.com/skyscraper/windows/364/bmpffrmt.html
Although it's a simple format, it's too Windows-dependent for my taste. A lot of information contained in the header is really useless for your purpose.
I strongly suggest that you use the Targa file format, which is much simpler and also stable (no new variations with every new Windows release).
I have attached the Targa file format specs. All the image manipulation software can handle it. It supports 24bits as well as 32bit (24bit RGB and 8bit alpha) in a format that is proper for display.
A few lines of code in any language will give you results, quickly
-
I specifically want to understand where the pixel data starts in a 24 bit bitmap Stormbringer so please let my question stand, thanks :) Any help on finding where the pixel data starts in 24 bit windows bitmap pictures would be gratefully accepted!
-
It's ok now I worked it out :)
I will tidy up the source and post it later for others.
-
Look up BITMAPFILEHEADER on MSDN, then, 10 bytes in, there's a 32bit offset to the actual bits counting from the beginning of the file.
http://msdn2.microsoft.com/en-us/library/ms532321.aspx (http://msdn2.microsoft.com/en-us/library/ms532321.aspx)
If you use MS Paint to save .bmp, then the files are often not compressed and there will be width*height worth of pixels, but that's not always the case - there are various methods of compression.
Jim
-
Yep, I've assumed no compression. The solution I have is a little bit messy at the moment bit it will soon work well enough for others to use :)
Cheers Jim :)
-
ok.. ok... hehe.. watch out as rows in a BMP file are stored as 4-byte boundaries. So if your image width*bytes per pixel is not a multiple of 4 bytes, then you have extra padding bytes at the end of each row..
-
Yep, I worked that out mate :)
-
@Shockwave: Take a look on this thread (http://dbfinteractive.com/index.php?topic=73.0), there's a fine example for loading 32 bits image by Jim and I have showed a way to load them from resource exe file.
-
Hehe, if only I had seen that Rbraz :) I made my own solution and posted it though. Anyway, than you for the help!
-
More code here for http://dbfinteractive.com/index.php?topic=2334.0 (http://dbfinteractive.com/index.php?topic=2334.0) loading other formats.
Jim