Archived

This topic is now archived and is closed to further replies.

Monder

BMP Loader Problems

Recommended Posts

I'm writing a BMP loader for a game engine I'm making. It was all working fine till I added this bit of code in to flip the scan lines so they were the right way round
    
unsigned int f = ImageSize - (BmpInfoHead.biWidth * 3);
for(unsigned int i=0; i < ImageSize; i+=(BmpInfoHead.biWidth *3))
{
	memcpy(&teximage[i], &bmpimage[f](BmpInfoHead.biWidth*3));
	f-= (BmpInfoHead.biWidth * 3);
}
    
teximage is the image (it's an array of unsigned chars) that will contain the image with the flipped scanlines. bmpimage is the image I've loaded from the bmp file (it's also an array of unsigned chars). The image I run through here is uncompressed and 24-bit. It works fine with a couple of BMP's I got from the book OpenGL Game Programming but when I make a BMP in photoshop and load it using my loader the colour channels seem to be offset from each other. If I skip out the scan line flipping code above they load fine only they're upside down. Does anybody know what's going on? [edited by - Monder on May 5, 2003 8:50:23 AM]

Share this post


Link to post
Share on other sites
I''ve worked it out now. For some reason Photoshop was putting the wrong image size in the bitmap info header. So if I get the loader to do width * height to work it out everything works fine.

Share this post


Link to post
Share on other sites
Something to watch out for if you use this bmp loader for images that aren''t pow2 widths, is the fact that bmps are padded such that each line falls on a DWORD boundary.

Just a little heads up.

-Zims

Share this post


Link to post
Share on other sites
What''s that extra "(BmpInfoHead.biWidth*3)" after the "&bmpimage[f]"?

"All you need to do to learn circular logic is learn circular logic"

Share this post


Link to post
Share on other sites