Skip to main content
GameDev.net gamedev.net
🔒 Locked

BMP loader

Started by impulsionaudio Feb 12, 2009 at 7:51 PM 11 replies 2.5k views
Original Post
impulsionaudio
impulsionaudio
I would like to write a BMP loader and have a few questions: 1) Where can I find accurate file specs for various versions of the BMP format? 2) If someone gives me a bitmap to load, don't I need to know the version of the BMP file format in order to know how to read the contents? 3) How do I determine the version? The last two questions may be answered by the results of the first question. But I thought I should ask. Thank you.
Guthur
Guthur
I'll not ask for the why...no actually why :s

But anyway a quick google revealled these 'truths' here.

It is wiki so the word truth is taken lightly here, but its a well documented and supported format so the information should be readly available, but again why...:s

Even DirectX does this for you and its about the most low level API I have used.
Innovation not reiterationIf at any point I look as if I know what I'm doing don't worry it was probably an accident.
Codeka
Codeka
The .bmp file format is rather archaic and compilcated for something so (seemingly) simple. You're better off, as Guthur says, to just use a library.

If you just want to learn how an image format works, you can probably try a simpler format like .tga. Heck, even the .png format is not as complicated (in that it's a well thought-out format not like the just-pile-the-new-features-on-top that is .bmp [smile])
impulsionaudio
impulsionaudio
Thanks. That's kind of what I thought. The loader is for a programming test for a job application. I thought it was kind of unusual myself but figured it would at least be a good learning experience. I have tried to write file loaders for other formats in the past and always run into this problem: what version? where are the versions well AND ACCURATELY documented? I/O is so important for applications, you would think that there would be a rock solid reliable archive of file formats. I guess some formats are in ANSI/ISO but that's not what I'm dealing with now.
Guthur
Guthur
It would take balls to come back with a single call to a Library loading function, did they specify that your weren't to do this, if not tell them wheels are there to be used :p.

Probably best to ignore that last bit :)
Innovation not reiterationIf at any point I look as if I know what I'm doing don't worry it was probably an accident.
Hazard org
Hazard org
Did you consider taking a look over some open source code like what Allegro has that does what you want? What is it that they actually want you to do?

If a library is totally out of the question I'm sure that there's some documentation out there that describes how bitmaps are created, the link Guthur gave is one of them. If you want to develop your program this way, I suppose it would be a good ideea telling us what programming language you plan on using also :)
daviangel
daviangel
Quote:
Original post by Codeka
The .bmp file format is rather archaic and compilcated for something so (seemingly) simple. You're better off, as Guthur says, to just use a library.

If you just want to learn how an image format works, you can probably try a simpler format like .tga. Heck, even the .png format is not as complicated (in that it's a well thought-out format not like the just-pile-the-new-features-on-top that is .bmp [smile])

Yeah all the Lamothe books used to show you how to write one but and it was messy,ugly, only supported like 16bits and that was only because DirectX didn't do it for you at the time.
Also the Mike Morisson Win32 game programming book has a BMP loader class in it.
And they always seem to be buggy and crash prone!

[size="2"]Don't talk about writing games, don't write design docs, don't spend your time on web boards. Sit in your house write 20 games when you complete them you will either want to do it the rest of your life or not * Andre Lamothe
Ravyne
Ravyne
I use Wotsit.org for all my file format needs. They have a rather large archive of just about every file you can imagine.

Bitmaps aren't terribly difficult to load. The one I have is only about 200 lines (with copious amounts of documentation and whitespace) and supports 32, 24, and 8 bit bitmaps. In theory there's supposed to be an run-length-encoded bitmap type, but I've never seen one in practice, so I just ignore that possibility and error if that flag is set.
throw table_exception("(? ???)? ? ???");
svnstrk
svnstrk
bmp is not that appropriate for gaming imho. its better to use available library.

im nit sure where to find the exact spec of the bmp files, but there is a code in robthebloke.org that might explain to you how it works. find it under OpenGL section titled Texture Manager. just read the code and you'll the answers, imho :)


ps: it belongs to a member of gamedev.net to, so you might want to ask him directly too

cignox1
cignox1
I quote Ravyne. Loading bmp becomes even easier if you only support 24 bit images. The full specs may be hard to work with, but a simple loader is just a matter of a couple of structs and a loop for the pixels... The only 'issue' I had was the order of the rows and of the pixel components :-)
impulsionaudio
impulsionaudio
Thanks for the info. The test asks for a command line image cropping tool, in C++, that takes an 8-bit bmp as a parameter and returns a bmp cropped to a minimum bounding rectangle around the image. They don't specifically say I can't use a loader so perhaps I can. Does Win32 offer a bmp loader or do I have to link in DirectX?
Thanks
hunpro
hunpro
Maybe you could try to google around DIBs (Device Independent Bitmaps). Very old stuff (from Win3.2, I think), so it is sure to be supported ;) (on Windows)
Or the DIY way, this looks good:
http://www.gamedev.net/reference/articles/article1966.asp
cignox1
cignox1
If you are allowed to use .Net then you can use the Bitmap class wich supports bitmaps (among other formats)...

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.