help with .bmp

Started by
1 comment, last by Theses 24 years, 4 months ago
I'm not sure, but the remaining 4 units(BYTES, WORDS, whatever) are stuffed in as padding. Thus, if you have a bitmap with a width of 33 at 8bpp then the file sticks in 3 BYTES of padding before starting the next line. As for coding around this, don't ask me as I am still learning myself.
Advertisement
right now this works for bitmaps that have width of multiples of 4
could someone show me what i need to do to get this to take bmps with nonmultiple of 4 widths


for (int index_y = 0; index_y < bitmap.bitmapinfoheader.biHeight; index_y++)
{
for (int index_x = 0; index_x < bitmap.bitmapinfoheader.biWidth; index_x++)
{
UCHAR blue = (bitmap.buffer[index_y * bitmap.bitmapinfoheader.biWidth * 3 + index_x * 3 + 0]),
green = (bitmap.buffer[index_y * bitmap.bitmapinfoheader.biWidth * 3 + index_x * 3 + 1]),
red = (bitmap.buffer[index_y * bitmap.bitmapinfoheader.biWidth * 3 + index_x * 3 + 2]);

UINT pixel = _RGB32BIT(0, red, green, blue);
back_buffer[(index_y * ddsd.lPitch >> 2) + index_x] = pixel;
}
}

Yeah, you need multiples of four. This was driving me crazy(and then I found out my Algo was right and OpenGL just wasn't loading some textures)

You need to skip ahead
sizof(DWORD) - (sizeof(whatever color format) * width % 4)

for 24 bit color sizeof(whatever color format) would be sizeof(UCHAR) * 3

Instead of trying to implement that logic into your assignments, you might want to use a dummy variable for the bitmat.buffer[] index.

int i=0;for(height){  for(width)  {    UCHAR blue = bitmap.buffer;<BR>    green = bitmap.buffer[i+1];<BR>    red = bitmat.buffer [i+2];<BR>    <BR>    i += 3;<BR>  }<BR>  i += sizeof(DWORD) - (sizeof(UCHAR) * 3 * width %4)<BR>}<P></pre><P>Or, alternately, since youre using 32 bit color you can just save 32 bit .BMP's which should have properly aligned scan lines.  <IMG SRC="http://www.gamedev.net/community/forums/ubb/wink.gif"><BR>

-the logistical one-http://members.bellatlantic.net/~olsongt

This topic is closed to new replies.

Advertisement