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

help with .bmp

Started by Theses Nov 27, 1999 at 4:11 PM 1 replies 700+ views
Original Post
Theses
Theses
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;
}
}

acw83
acw83
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.
logistix
logistix
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.

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

Topic Locked

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

Sign in to reply to this topic.