loading 24 bits -rebirth

Started by
4 comments, last by darookie 17 years, 10 months ago
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
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'.
It only takes one mistake to wake up dead the next morning.
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
thanks anyway
I will have a look at this, but I'm still waiting for other suggestions
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?
The scanlines are stored left to right as usual.

This topic is closed to new replies.

Advertisement