Archived

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

help with .bmp

This topic is 6595 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

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.

Share this post


Link to post
Share on other sites
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;
}
}

Share this post


Link to post
Share on other sites
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[i];
green = bitmap.buffer[i+1];
red = bitmat.buffer [i+2];

i += 3;
}
i += sizeof(DWORD) - (sizeof(UCHAR) * 3 * width %4)
}

Or, alternately, since youre using 32 bit color you can just save 32 bit .BMP's which should have properly aligned scan lines.

Share this post


Link to post
Share on other sites