Tuesday, 15 January 2013

Terminology of BMP file format

Here we discuss some of terminology which are used in BMP file format.It is very important to having knowledge about them during study of BMP file format.They are following:-

Padding :-In Bmp file format each row in the pixel array must be in multiple of 4.If the image data row size is not in the multiple of 4 then it will make in multiple of 4 by adding to the each row. If each row in pixel array is in multiple of 4,then there is no need of padding.Row size is calculated with the help of Bits per pixel & image width in pixels which is following:-
                   
                 \mbox{RowSize} = \left\lfloor\frac { \mbox{BitsPerPixel} \cdot \mbox{ImageWidth}+31
 }{32}\right\rfloor \cdot 4,

Bits Per Pixel/Bit depth:- Bits per pixel or Bit depth are the same thing.It used to describe how many bits are stored in each pixel.With the help of bit depth we can know two things which are very important.First ,If image is of n bit per pixel it means it support 2^n distinct colors.For Example,If image is 8-bit per pixel then it supports 2^8=256 distinct colors.Second most important which we come to know is ,if image having n-bit per pixels it means n/8 byte occupies by 1 pixel because 8 bit=1 byte. Normally 1,2,4,8,12,16,24,30,32,36,48 bit depth images are possible.1 bpp is also called monochrome.Images of 15/16 bit color depth are called high color image.Image of 24-bit color depth is called true color image.There are 2^24 colors in the true color. 30,36 & 48 bit color depth image called deep color image .It used xvYCC,sRGB & YCbCr color spaces.Information of Bit depth stores on 28th byte of header & 14th byte of DIB header.Its information occupy 2 bytes.

Extra bit Masks:-It is found after DIB header.It is an optional structure in BMP image.Its main purpose is to define pixel formats.It has size of 3 or 4 DWORDs (12 or 16 bytes). This is only present when DIB header is BITMAPINFOHEADER.

BitMask:-In order to resolove the ambiguity of which bits define which samples,the dib header provide
certain defaults as well as specific BITFIELDS which are called bitmask that defines the particular group of bits in a pixel to a particular channel.

Alpha & Gamma :-There is many type of bitmasks available in DIB header.There is bitmask for all three channels R,G & B.There is an another bitmask which is called alpha channel bitmask.Alpha channel  is basically used as opacity channel.Alpha bitmask is avaliable after  66 bytes in header & occupy 4 bytes in DIB header.The alpha bitmask is valid whenever it is present in the DIB heder or when the compression member of DIB header is set to BI_ALPHABITFIELDS.
                                                                         Gamma is applicable for the all three channels RED,GREEN & BLUE.It is available in DIB header of a BMP image.It occupies 4-byte for each channel.If it is available in DIB header then It comes after 74 byte .

Some of more important details about BMP image are given below pointwise:-

1)Information of compression method used in image is available  after 30 byte of header .It is available in DIB header after 16 byte .Its occupies 4 bytes in header.

ValueIdentified byCompression methodComments
0BI_RGBnoneMost common
1BI_RLE8RLE 8-bit/pixelCan be used only with 8-bit/pixel bitmaps
2BI_RLE4RLE 4-bit/pixelCan be used only with 4-bit/pixel bitmaps
3BI_BITFIELDSBit field or Huffman 1D compression for BITMAPCOREHEADER2Pixel format defined by bit masks or Huffman 1D compressed bitmap for BITMAPCOREHEADER2
4BI_JPEGJPEG or RLE-24 compression for BITMAPCOREHEADER2The bitmap contains a JPEG image or RLE-24 compressed bitmap for BITMAPCOREHEADER2
5BI_PNGPNGThe bitmap contains a PNG image
6BI_ALPHABITFIELDSBit fieldThis value is valid in Windows CE .NET 4.0 and later.


2)BITMAPFILEHEADER is the first part of BMP image header.It has the information about Header field,file size,two reserved fields & an offset which is the starting address of image data.Its total size is 14 bytes .Header field is identification of BMP image .It has values like BM,BA,CM,CI etc. BITMAPFILEHEADER   also gives file size in bytes.It also have the reserved field each of size 2 bytes whose actual value depends on the  application   that creates the image.It also has information which stores information of starting address of  image data in bytes.this information occupy 4 bytes.

3)BITMAPCOREHEADER is the second part of BMP image header.It has the information about size of this structure,Width & height of image in pixels,no of color planes being used,no of bits per pixel in image.
It occupy  4 bytes for first 3 & occupy 2 bytes for last two.It means this structure total occupy 16 bytes.

4)BITMAPV5HEADER is an extended version of BITMAPINFOHEADER Structure.It has large information about image.It has extended information ARGB channel bitmask,Gamma for RGB channels
& Color space type,color space end points etc.

5)Size of color table entries is 3 bytes in BITMAPCOREHEADER & 4 bytes in BITMAPV5HEADER.

6)No of entries present in the Color table is found by 2^n where n is the bit depth or bits per pixel. Thus it is totally depend upon bit depth.Color table is mandatory for images which have bit depth of less than or equal to 8.  

7)The field colors in color table shows th no of colors in palette whose possible values 0 to default to 2^n where n is the bit depth.its information is stores on 46 th byte of header & its information size is 4 byte.

8)Number of important color count is availbale on 50th byte of header.Its information stores 4 byte of memory.It explain that how many important colors are used .0 means all colors are important.

9)The size of color space endpoints is 36 bytes .It comes after color space type in header. 74th byte is the offset for the color space points.

10)The 26th byte of header contains the information for how much color planes are used which must be set to 1.It occupy 2 bytes in header.

Color Space:-When the color model is associated with precise description of how the components are to be interpreted (viewing conditions etc.) the resulting set of colors is called Color Spaces.Possible values for color spaces are RGB,CMY/CMYK, YIQ,YPbPr,xvYCC,HSB,HSL,Munsell Color System,Natural Color System,RG chromaticity,TSL Color Space.70 byte is the offset for the color space type in header.Its inforamation size is 4 byte.
                                     RGB & CMYK color space are respectively additive & substractive color spaces they are descibed in previous blogs .Munsell & natural color systems are commercial color system.The RG chromaticity & TSL color Spaces are special purpose color spaces.The first one is used in computer vision application & the later is used for face detection.

*The two color Schemes widely used in bitmap compression are ARGB & AYCoCg.These schemes have the following color planes:-

Color scheme
Color planes
ARGB
Alpha, Red, Green, Blue
AYCoCg
Alpha, Luma, Orange Chroma, Green Chroma

Color Space Conversion:-Color channel based compression does not operate on the ARGB color space but rather a color space based on Luminosity (Y) & differential of two color components :Orange(Co)& Green(Cg).Conversion between ARGB & AYCoCg color spaces can be performed by using forward & inverse transformation.The Alpha channel is never converted in either direction.
The forward transformation to convert from ARGB to AYCoCg is as follows:-
A=A
|Y|=|1/4  1/2  1/4|       |R|
|Co|=|1    0     -1|   *  |G|
|Cg|=|-1/2  1  -1/2|     |B|
The inverse transformation to convert from AYCoCg to ARGB is as follows:-
A=A
|R|=|1 1/2 -1/2|     |Y|
|G|=|1 0 1/2 |     * |Co|
|B|=|1 -1/2 -1/2|   |Cg |
The allowed ranges of the individual color planes & their lengths in bits are as follows:-

Color plane
Range
Type
Alpha (A)
0 (transparent) – 255 (opaque)
8 bits
Red (R)
0 – 255
8 bits
Green (G)
0 – 255
8 bits
Blue (B)
0 – 255
8 bits
Luma (Y)
0 – 255
8 bits
Orange Chroma (Co)
-255 – 255
9 bits (two's complement)
Green Chroma (Cg)
-255 – 255
9 bits (two's complement)



No comments:

Post a Comment