File Formats
  • Audio
  • Video
  • Images
  • 3D & CAD
  • Documents
  • Data
  • Code
  • System
Images
  • Raster
  • Vector
  • Camera raw
  • Layered projects
  • HDR & scientific
  • Icons
  • Retro
  1. Home
  2. Images
  3. Raster
  4. BMP
  5. BM
  6. Pixel data
  7. Compression
.BMP
  • Overview
  • Windows bitmap (BM)
    • File header
    • DIB header
    • Colour spaces
    • Colour table
    • Bit masks
    • Pixel data
    • Compression
  • OS/2 bitmap array (BA)
  • OS/2 icon (IC)
  • OS/2 colour icon (CI)
  • OS/2 pointer (PT)
  • OS/2 colour pointer (CP)

Compression

The biCompression field of the DIB header says how the pixel data is stored. Most BMP files are uncompressed; the others use a simple run-length encoding for palette images, or hold a whole JPEG or PNG.

03 04 05 06 00 03 45 56 67 00 02 78 00 02 05 01
02 78 00 00 09 1E 00 01
RLE8 data: runs, a literal run, a move, an end of line and an end of bitmap

Values

ValueNameBit countMeaning
0x00 (0)BI_RGBanyUncompressed.
0x01 (1)BI_RLE88Run-length encoded 8-bit indexes.
0x02 (2)BI_RLE44Run-length encoded 4-bit indexes.
0x03 (3)BI_BITFIELDS16, 32Uncompressed, with bit masks. In OS/2 2.x files, 3 means Huffman 1D for 1-bit images.
0x04 (4)BI_JPEG0The pixels are a JPEG image. In OS/2 2.x files, 4 means RLE24 for 24-bit images.
0x05 (5)BI_PNG0The pixels are a PNG image.
0x06 (6)BI_ALPHABITFIELDS16, 32Uncompressed, with bit masks including alpha. From Windows CE.
0x0B (11)BI_CMYKCMYK, used only in Windows metafiles.
0x0C (12)BI_CMYKRLE8CMYK with RLE8, used only in Windows metafiles.
0x0D (13)BI_CMYKRLE4CMYK with RLE4, used only in Windows metafiles.

A compressed bitmap is always bottom-up: its height must be positive. Its biSizeImage must give the size of the compressed data.

RLE8

RLE8 data is read two bytes at a time. In encoded mode the first byte is a count from 1 to 255 and the second is a palette index to repeat that many times. A first byte of zero is an escape, and the second byte says what it means:

Second byteMeaning
0x00 (0)End of line: go to the start of the next row.
0x01 (1)End of bitmap: the image is complete.
0x02 (2)Delta: the next two bytes move the position right and on by that many pixels and rows. Skipped pixels are left undefined.
0x03 (3) to 0xFF (255)Absolute mode: that many literal palette indexes follow, padded with a zero byte to an even length.

Decoding the example at the top of the page:

BytesResult
03 0404 04 04
05 0606 06 06 06 06
00 03 45 56 67 0045 56 67, then one pad byte
02 7878 78
00 02 05 01Move 5 pixels right and 1 row on
02 7878 78
00 00End of line
09 1E1E nine times
00 01End of bitmap

RLE4

RLE4 works the same way with 4-bit indexes. In encoded mode the count is a number of pixels and the second byte holds two indexes, which are used in turn: high nibble, low nibble, high nibble and so on. In absolute mode the count is a number of pixels, packed two to a byte, and the bytes are padded to an even length. The escapes are the same as RLE8.

BytesResult
03 040 4 0
05 060 6 0 6 0
00 06 45 56 67 004 5 5 6 6 7, then one pad byte
04 787 8 7 8
00 02 05 01Move 5 pixels right and 1 row on
00 00End of line
09 1E1 E 1 E 1 E 1 E 1
00 01End of bitmap

Embedded JPEG and PNG

With BI_JPEG or BI_PNG the bit count is 0 and the pixel data is a complete JPEG or PNG file, whose length is given by biSizeImage. These values were added so that Windows could pass compressed images straight to printers. Few programs write them in BMP files, and many readers do not support them.

© 2026 fileformats.org About Contact Made by Lewpen