Bitmap format

This page illustrates the bitmap file format used in the SampleGrabber sample.

Bitmap file format overview

The Bitmap format used in SampleGrabber sample is very simple. The Bitmap file consists of BITMAPFILEHEADER, BITMAPINFOHEADER, and RGB data.

BITMAPFILEHEADER
BITMAPINFOHEADER
RGB data

BITMAPFILEHEADER

The BITMAPFILEHEADER structure is defined as the following.


typedef struct tagBITMAPFILEHEADER { 
  WORD    bfType; 
  DWORD   bfSize; 
  WORD    bfReserved1; 
  WORD    bfReserved2; 
  DWORD   bfOffBits; 
} BITMAPFILEHEADER;

bfType
Identifier information comes first in the Bitmap file. The first two bytes of a bitmap file will be 'B' + 'M'.
bfSize
File size. The file size of the output bitmap file of the SampleGrabber sample is, sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER) + (width x height x 3).
bfReserved1, bfReserved2
unused.
bfOffBits
The offset from the head of the file to the first RGB data. The value will show the number of bytes to the first RGB data. In the SampleGrabber sample, this value will be, sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER).

BITMAPINFOHEADER

The BITMAPINFOHEADER structure is defined as the following.


typedef struct tagBITMAPINFOHEADER{
  DWORD  biSize; 
  LONG   biWidth; 
  LONG   biHeight; 
  WORD   biPlanes; 
  WORD   biBitCount; 
  DWORD  biCompression; 
  DWORD  biSizeImage; 
  LONG   biXPelsPerMeter; 
  LONG   biYPelsPerMeter; 
  DWORD  biClrUsed; 
  DWORD  biClrImportant; 
} BITMAPINFOHEADER;

biSize
size of the structure.
biWidth
width of image (in pixels)
biHeight
height of image (in pixels)
biPlanes
number of planes. must be 1.
biBitCount
bits-per-pixel
biCompression
the used compression technology. BI_RGB(no compression), BI_RLE8, BI_RLE4(run length encoded, 8bpp, 4bpp), BI_JPEG, BI_PNG.
biSizeImage
image size. can be 0 when BI_RGB.
biXPelsPerMeter
width by pixel-per-meter.
biYPelsPerMeter
height by pixel-per-meter.
biClrUsed
number of color index used.
biClrImportant
number of color to show the color index.

RGB data

The RGB data structure is defined as the following. The directshow sample shown in this site uses MEDIASUBTYPE_RGB24 (24 bit RGB). However, please note there are other formats that can be used too.


BYTE red;
BYTE green;
BYTE blue;

The RGB data will contine for the number of pixels. For example, if the image size is 720x480, the RGB data will contine 720x480 times. The whole RGB data will be 720x480x3 = 1036800 bytes.

  

Copyright (C) GeekPage.JP. All rights reserved.