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

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
User avatar
Agola
Member
Member
Posts: 155
Joined: Sun Nov 20, 2016 7:26 am
Location: Somewhere

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

Post 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:
Last edited by Agola on Fri Jan 20, 2017 2:22 pm, edited 1 time in total.
Keyboard not found!

Press F1 to run setup.
Press F2 to continue.
Techel
Member
Member
Posts: 215
Joined: Fri Jan 30, 2015 4:57 pm
Location: Germany
Contact:

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

Post 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.
User avatar
Agola
Member
Member
Posts: 155
Joined: Sun Nov 20, 2016 7:26 am
Location: Somewhere

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

Post 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
Keyboard not found!

Press F1 to run setup.
Press F2 to continue.
User avatar
dozniak
Member
Member
Posts: 723
Joined: Thu Jul 12, 2012 7:29 am
Location: Tallinn, Estonia

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

Post 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
Learn to read.
User avatar
Agola
Member
Member
Posts: 155
Joined: Sun Nov 20, 2016 7:26 am
Location: Somewhere

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

Post 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 :|
Keyboard not found!

Press F1 to run setup.
Press F2 to continue.
Techel
Member
Member
Posts: 215
Joined: Fri Jan 30, 2015 4:57 pm
Location: Germany
Contact:

Techel

Post by Techel »

That's basically what I said :P
Post Reply