tags:

views:

1500

answers:

6
+2  Q: 

bmp loader library

I'm looking for a C library to load .BMP image-files.

I've found a lot of code on the net, but everything I've seen so far is useless for me.

Either the code seems to be in a good shape but it only supports just or two of the possible sub-formats, or the code supports all major sub-formats but does not error-checking and handling at all.

Does something with the quality of libPNG of libGIF exists for .BMP-files?

Another thing to add: I'm not looking for one of these "I load 80 different formats for you" wrapper-libraries like DevIL. Code-space and is important (it's for an embedded project).


EDIT:

Thanks to all those who've pointed me to wikipedia and the code that's linked from this page. Guys - I'm not an idiot. Of course I had a look at this code before I posted here, and I thought I made sure that THIS is one of these codes that I don't want.

Just to name some some of the defects that his code has:

  1. Code does not check for out of memory conditions (okay - in C++ I can roll everything into a try-except block, but even this will leak memory because I - as a lib-user - don't know shit about the allocation-order. A self-contained piece of code should clean up it's mess after itself if it runs into trouble and reports failure, not raise some generic exeption.

  2. Code assumes that fread always succeeds. Obviously the author never tried to read from a network-share or pipe.

  3. Code thinks that because height can be negative (which in .bmp-slang means that the image is stored in top-down fashion and is well documented), that the same is true for the width as well. Exploit-city - I welcome you.

    1. Code does not handle BI_RGB images with palettes (these are around in the wild). I have no problem using a lib that does not to handle these, but at lest the condition should be checked and returned as an error. Just returning garbage image-data is not an option. Palettes with less than 2^n entries are ignored either.

    2. Don't get me started on RGB565; ARGB4444 coded images, .BMP-Files that serve as a container for .PNG or JFIF images and all the other thousand sub-formats. At least a lib should check if it does support a format and not blindly ignore data that it does not understand.


Seems like I have to develop my own code.. Thanks everyone.

+1  A: 

bmp format is quite simple as you know. I honestly don't know any lib just for BMP but if code-space is important then i would sugest you to write a function to read it.

http://en.wikipedia.org/wiki/BMP_file_format

You may vote down if you want but it's really the best answer i can give :(

Small edit, wikipedia as this in the end of the file, maybe it's usefull for you. It's a small bitmap loader class. http://www.kalytta.com/bitmap.h

fmsf
A: 

It should probably not be too hard to rewrite some of this C++ code to C: http://www.kalytta.com/bitmap.h (link from the BMP article at Wikipedia). (Haven't tested it.)

Stein G. Strindhaug
A: 

It's not important if the source code is big if you're in embedded c. Use whatever you want, statically link and remove unused functions.

Loki
+2  A: 

I'd start with FreeImage.

Yes, it can load a bunch of other formats, and do a load of other stuff, but I'm sure you can strip out what you don't want ( or just rip the code you DO want).

Leak-wise, I've had no problems - but if it DOES leak, it will be easier to fix this than writing your own from scratch.

You can supply your own I/O routines, and take whatever action you like in them regarding errors.

However, from the tone of your post I get the feeling that you're partly looking for excuses to write your own from scratch. In which case, good luck to you...

Roddy
+2  A: 

http://easybmp.sourceforge.net/

HTH

plan9assembler
A: 

I think I am so late but if you like you can try http://qdbmp.sourceforge.net/

ismael