Sign in to follow this  
noNchaoTic

BMP loader help

Recommended Posts

Hey everyone, Just wondering if I could get a diagnosis for a problem... Wrote my own BMP loader, and its working, but with one small problem, it kinda got half of the bmp folded in half, it has a black line from the bottom left to the top right (presumably where its loading no data as I am memsetting the area to 0), and then its sort of flipped on half of the bmp so it looks like its been folded... any idea of whats going wrong here? Cheers, Ste

Share this post


Link to post
Share on other sites
NoNchaoTic,

Its a bit difficult to help diagnose the problem without anything to go off of. Can you paste some code here using the source tags so we might get a better look.

Cheers!

Share this post


Link to post
Share on other sites
code is on my other machine that's not hooked up right now, so i'll give you a run down...


using an rgb triple

freading a chunk of it, into that this is inside a for loop (running width*height), then assigning the various components of the rgb triple into the locations of the array. this is done by a second variable...

bmpdata[j++] = rgbtriple.red;
bmpdata[j++] = rgbtriple.greed;
bmpdata[j++] = rgbtriple.blue;
bmpdata[j++] = 255;

the memory is allocated using malloc the size of width*height*4... erm, thats bout all i can think of right now :-)

hope this helps

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Remember also that .bmp files are stored with bottom-to-top, with the bottom row of pixels stored first in the file. The 4-byte aligning of rows mentioned before sounds like your the cause of your diagonal line problem.

Share this post


Link to post
Share on other sites
BMPs image data is saved in lines. Lines need to be padded to 32bit.

Therefore if your image is 24bit and the width is for example 13 you get 39 bytes per line. Now this needs to be padded to be divisible by 4. In this case there's one more byte to read, the value of it is not important.

Share this post


Link to post
Share on other sites
i'm still get a few problems... i've tried switching to an RGBQUAD and freading a block with that, that gives even worse results that what i have currently... also tried freading a byte seperately and then discarding it... still same bad results, any ideas why its screwing up :-S

Share this post


Link to post
Share on other sites
It really depends on the bmp image format and the width of the stored image, if and how many bytes you need to read and discard.
If bytes per pixel multiplied by image width is not even divisible by four you need to read as many bytes as you need to make the value divisible by four.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this