Skip to main content
GameDev.net gamedev.net
🔒 Locked

BMP Loader Problems

Started by Monder May 5, 2003 at 7:49 AM 2 replies 650+ views
Original Post
Monder
Monder
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]
Monder
Monder
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.
Zimans
Zimans
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
BlueMonk
BlueMonk
What''s that extra "(BmpInfoHead.biWidth*3)" after the "&bmpimage[f]"?

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

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.