help. bmp loading tramma
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);
Your problem is that you don''t check for padding bytes that may occur when the width of the bitmap is odd.
Use this:
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);}
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement