Jump to content

  • Log In with Google      Sign In   
  • Create Account


help with .bmp


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
2 replies to this topic

#1 Theses   Members   -  Reputation: 122

Like
Likes
Like

Posted 27 November 1999 - 10:11 AM

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;
}
}


Sponsor:

#2 acw83   Members   -  Reputation: 174

Like
Likes
Like

Posted 27 November 1999 - 09:38 AM

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.

#3 logistix   Members   -  Reputation: 122

Like
Likes
Like

Posted 27 November 1999 - 10:11 AM

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.





Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS