Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

what is the difference between bisizeimage , bisize and bfsize?

Tags:

bitmap

i'm new to this field ,and i get confused between some terms!

bisizeimage, bisize and bfsize!

please i need a simple definitions for each one, and if there is equations to calculate them ?

bisizeimage bisize bfsize bitmapinfoheader bitmapfileheader

edited : ("answered by friend")

biSize > The number of bytes required by the structure. (what is the structure exactly ?)

The structure is the struct BITMAPINFOHEADER. That is a fixed value.

biSizeImage > The size, in bytes, of the image. bfSize > The size, in bytes, of the bitmap file. (what is the difference between image & bitmap file ?)

biSizeImage is the whole image size, bfSize is the same, but you have to add the size of the 2 header files.

like image 538
Osama Nsr Avatar asked Sep 07 '14 17:09

Osama Nsr


3 Answers

@Roman Abashin's answer has a slight but important error. biSize is not the combined size of both headers.

biSize is the size of the BITMAPINFOHEADER only. It is 40 bytes.

biSize = 40

The combined size of both headers is actually bfOffBits (you can think of the "Off" as referring to the offset of the actual bitmap from the beginning of the headers - remember, the bitmap comes straight after the headers).

bfOffBits = 54

Therefore all the following are correct formulas for bfSize:

bfSize = biSizeImage + sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER)
bfSize = biSizeImage + sizeof(BITMAPFILEHEADER) + biSize
bfSize = biSizeImage + 14                       + 40
bfSize = biSizeImage + 54
bfSize = biSizeImage + bfOffbits

And @Roman Abashin's formula for biSizeImage, the size of the actual bitmap, is correct for a 24-bit bitmap.

Confusingly, biSize, bfOffBits, bfSize and biSizeImage are all in units of bytes, whereas biWidth and biHeight are in units of pixels. The number of bytes per pixel is defined in the biBitCount part of the header. It is 3 bytes (or 24 bits) for a 24-bit bitmap.

Note that bfOffBits's units are in bytes and biBitCount's units are in bits.

More detail can be found on Microsoft's pages:

Info on BITMAPFILEHEADER

Info on BITMAPINFOHEADER

Edit: I added some annotations to the bitmap overview below to clarify things even more![layout of bitmap and headers with size information Edit: Changed biSizeImage + 24 (etc etc) to + 14.

like image 157
MotherBrain Avatar answered Sep 22 '22 15:09

MotherBrain


bfSize = biSizeImage + sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER)
bfSize = biSizeImage + 54               

// since BITMAPFILEHEADER = 40 and BITMAPINFOHEADER = 14 

biSizeImage = (biWidth * sizeof(RGBTRIPLE) + padding) * abs(biHeight) 
like image 33
Shock451 Avatar answered Sep 25 '22 15:09

Shock451


One tiny typo, in @Shock451 answer. According to: https://en.wikipedia.org/wiki/BMP_file_format the values of BITMAPFILEHEADER and BITMAPINFOHEADER are swapped.

there Should be:

// since BITMAPFILEHEADER = 14 and BITMAPINFOHEADER = 40

not:

// since BITMAPFILEHEADER = 40 and BITMAPINFOHEADER = 14
like image 38
ToTenMilan Avatar answered Sep 22 '22 15:09

ToTenMilan