BMP loader help
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
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!
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!
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
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
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?
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.
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.
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
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.
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.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement