Skip to main content
gamedev.net
🔒 Locked

help. bmp loading tramma

Started by Mardigin Jan 12, 2002 at 12:33 AM 0 replies 500+ views
Original Post
Mardigin
Mardigin
I am loading an 8bit 256 color bmp. Now it works most of the time, but it crashes with some bmp. specifically bmp''s that I make in photoshop. The following are some snippets of code that may have something to do with my problem. NOte I actually crash on the memcpy bytes_per_line = bitmap->bitmapinfoheader.biWidth*(bitmap->bitmapinfoheader.biBitCount/8) if (!(buffer = (UCHAR *)malloc(bytes_per_line*height))) return(0); memcpy(buffer,image,bytes_per_line*height);
Countach
Countach
Your problem is that you don''t check for padding bytes that may occur when the width of the bitmap is odd.

Use this:
  
if(width % 2 == 0) {
// Width is even, the texture can be loaded directly and then flipped

uint bufferLength = width * height;
uchar *buffer = new uchar[bufferLength];

// Read all data into the texture

stream.readBuffer(buffer, bufferLength);

} else {
// Width is odd so there will be padding (extra bytes for proper memory alignment)

// in the bitmap.

// Bitmaps put the padding bytes at the end of each line


uint bufferLength = (width + 1) * height;
uchar *buffer = new uchar[bufferLength];

// Read all data into the texture

stream.readBuffer(buffer, bufferLength);

}





-------homepage - email

Topic Locked

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

Sign in to reply to this topic.