Page 1 of 1

[Solved] 24-bit BMP hasn't got padding!?

Posted: Sun Jan 15, 2017 1:54 pm
by Agola
Hi.

I was testing to load bmp files. I have 4 bmp files, Agola.bmp, Test1.bmp, Test2.bmp, Test3.bmp in root directory. All bmp files are 24-bit bmp except Test3.bmp, Test3.bmp is a 32-bit bmp.
Now, the interesting part. I read all 24-bit bmp files have padding bits to make it 32-bits, but my files haven't!? :shock: :shock: :shock: .

This is the code to load my bmps:

Code: Select all

uint16_t mode = VBE_FindMode(1920, 1080, 24);
VBE_SetMode(mode);

uint8_t* fb = (uint8_t*) ModeInfo->PhysBase;
ext2_read_file("/Agola.bmp", 1920 * 1080 * 3, 54, fb);
Yes, the output is upside down but this is not a problem now. Still I can't understand, if 24-bit bmp files have padding, that should fail.
But it doesn't fail, surprisingly if I make the read size 1920 * 1080 * 4 and VBE_FindMode(1920, 1080, 32); it fails, draws broken image. But if I use the same 1920 * 1080 * 4 and VBE_FindMode(1920, 1080, 32); with Test3.bmp (32-bit bmp) it works.

If they have padding, how draw doesn't fail?

What's happening? help pls :shock: :shock: :shock:

Re: 24-bit BMP hasn't got padding!?

Posted: Sun Jan 15, 2017 2:04 pm
by Techel
24-Bit Bitmaps only have padding Bytes at the end of each scanline to make it 4-Byte aligned, but not after every Pixel.

Re: 24-bit BMP hasn't got padding!?

Posted: Sun Jan 15, 2017 2:15 pm
by Agola
Techel wrote:24-Bit Bitmaps only have padding Bytes at the end of each scanline to make it 4-Byte aligned, but not after every Pixel.
But shouldn't be still some corruptions in image?

Here is an screenshot from both vm and bmp viewer:

Image

Re: 24-bit BMP hasn't got padding!?

Posted: Sun Jan 15, 2017 3:05 pm
by dozniak
Agola wrote:But shouldn't be still some corruptions in image?
What do you mean? Padding is not displayed.

http://stackoverflow.com/questions/2601 ... ap#2601392

Re: 24-bit BMP hasn't got padding!?

Posted: Sun Jan 15, 2017 3:06 pm
by Agola
After playing with values, I found the problem.

My bad, I feel like a dumb now.

(Image width * bpp) is divisible by 4, so it doesn't need to be padded. Resolutions like 831x622 or 1915x1000 needs to be padded, not 800x600 or 1920x1080.

So sorry :|

Techel

Posted: Mon Jan 16, 2017 1:47 am
by Techel
That's basically what I said :P