BMP loader help

Started by
8 comments, last by Endurion 18 years, 10 months ago
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
Steven ToveySPUify | Twitter
Advertisement
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!
Jeromy Walsh
Sr. Tools & Engine Programmer | Software Engineer
Microsoft Windows Phone Team
Chronicles of Elyria (An In-development MMORPG)
GameDevelopedia.com - Blog & Tutorials
GDNet Mentoring: XNA Workshop | C# Workshop | C++ Workshop
"The question is not how far, the question is do you possess the constitution, the depth of faith, to go as far as is needed?" - Il Duche, Boondock Saints
It sounds like your line-with is wrong. Check that you're loading it correctly, and that you are accounting for BMP lines being aligned on 4-byte boundaries.
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
Steven ToveySPUify | Twitter
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.
yeah i've got it loading the correct way up, just the silly folding thing, what exactly do you mean by the line width?
Steven ToveySPUify | Twitter
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.

Fruny: Ftagn! Ia! Ia! std::time_put_byname! Mglui naflftagn std::codecvt eY'ha-nthlei!,char,mbstate_t>

ahhh reet, so just fread another byte, and then just dump it... awesome :-)
Steven ToveySPUify | Twitter
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
Steven ToveySPUify | Twitter
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.

Fruny: Ftagn! Ia! Ia! std::time_put_byname! Mglui naflftagn std::codecvt eY'ha-nthlei!,char,mbstate_t>

This topic is closed to new replies.

Advertisement