Jump to content
  • Advertisement
Sign in to follow this  
Night_slr

loading 24 bits -rebirth

This topic is 4348 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

hi everyone, in this topic http://www.gamedev.net/community/forums/topic.asp?topic_id=392394 smit gave a piece of code and I want to know something about this part: pImageData = new BYTE[ bmFileHeader.bfSize - bmFileHeader.bfOffBits ]; fseek( m_pFile, bmFileHeader.bfOffBits, SEEK_SET ); fread( pImageData, bmFileHeader.bfSize - bmFileHeader.bfOffBits, 1, m_pFile ); when you store the image data in pImageData how is it ordered? for example where would be the values of the first pixel located on the left top of the image? in pImageData[0]? how can I recognize the values of the R , The G and the B? how are they ordered? thanks

Share this post


Link to post
Share on other sites
Advertisement
I learned how to turn a .BMP file into a texture by reading this. Try making your own test .BMPs (say, a 4x4 image that is half red and half blue) and opening them up in a hex editor to aid in understanding what data is where and how to use it. If you're using a Windows 24-bit BMP image, it's pretty simple - just chew through the header, picking up any useful information on the way, then load the raw color data. Good luck!

Sorry if this doesn't really answer your question, but the essence of your question seemed to be 'how do I load a BMP file'.

Share this post


Link to post
Share on other sites
The values in a BMP image are ordered BGR, i.e.
image[y * pitch + x + 0] == Blue
image[y * pitch + x + 1] == Green
image[y * pitch + x + 2] == Red

BMPs are stored "upside down" that is, you have to flip them horizontally in order to have the top-left pixel @ image[0]:

void flipImage( BYTE * image, DWORD lines, DWORD pitch ) {
assert( image != 0 );
std::vector<BYTE> lineBuffer( pitch );
BYTE * top = image;
BYTE * bottom = image + (lines-1) * pitch;
for ( DWORD line = 0, numLines = lines / 2; line < numLines; ++line ) {
std::copy( top, top + pitch, &*lineBuffer.begin() );
std::copy( top, top + pitch, bottom );
std::copy( bottom, bottom + pitch, &*lineBuffer.begin() );
bottom -= pitch;
top += pitch;
}
}



HTH,
Pat

Share this post


Link to post
Share on other sites
thanks darookie
ok in a BMP file the information about the pixels of the image are ordered from bottom to top but is it from left to right or right to left?

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!