bmp format

table of contents

introduction
bitmap file format
              general
              bmp contents
field details
             height field
             bits per pixel field
             compression field
             colors field
             important colors field

introduction

this document describes the microsoft windows and ibm os/2 picture bitmap files, called bitmaps or bmp files. most of the descriptions of the bmp file concentrate on the microsoft windows bmp structures like bmpinfoheader and bmpcoreinfo , but only a few describe the file contents on byte level. this information is therefor only intended to be used in applications where direct reading and writing of a bmp file is required.

bitmap file format

the following chapters contain the detailed information on the contents of the bmp file. first more general information will be given regarding the byte order and file alignment. the second chapter will concentrate on the byte-level contents of a bmp file. the third chapter will elaborate on this chapter and explain some of the concepts - like compression - and/or values in detail.

general

the bmp file has been created by microsoft and ibm and is therefor very strictly bound to the architecture of the main hardware platform that both companies support: the ibm compatible pc. this means that all values stored in the bmp file are in the intel format, sometimes also called the little endian format because of the byte order that an intel processor uses internally to store values.

the bmp files are the way, windows stores bit mapped images. the bmp image data is bit packed but every line must end on a dword boundary - if thatÆs not the case, it must be padded with zeroes. bmp files are stored bottom-up, that means that the first scan line is the bottom line.

the bmp format has four incarnations, two under windows (new and old) and two under os/2, all are described here.

bmp contents

the following table contains a description of the contents of the bmp file. for every field, the file offset, the length and the contents will be given. for a more detailed discussion, see the following chapters.

offset

field

size

contents

0000h

identifier

2 bytes

the characters identifying the bitmap. the following entries are possible:

æBmí¯ - windows 3.1x, 95, nt, í¡

æBaí¯ - os/2 bitmap array

æCií¯ - os/2 color icon

æCpí¯ - os/2 color pointer

æIcí¯ - os/2 icon

æPtí¯ - os/2 pointer

0002h

file size

1 dword

complete file size in bytes.

0006h

reserved

1 dword

reserved for later use.

000ah

bitmap data offset

1 dword

offset from beginning of file to the beginning of the bitmap data.

000eh

bitmap header size

1 dword

length of the bitmap info header used to describe the bitmap colors, compression, í¡ the following sizes are possible:

28h - windows 3.1x, 95, nt, í¡

0ch - os/2 1.x

f0h - os/2 2.x

0012h

width

1 dword

horizontal width of bitmap in pixels.

0016h

height

1 dword

vertical height of bitmap in pixels.

001ah

planes

1 word

number of planes in this bitmap.

001ch

bits per pixel

1 word

bits per pixel used to store palette entry information. this also identifies in an indirect way the number of possible colors. possible values are:

1 - monochrome bitmap

4 - 16 color bitmap

8 - 256 color bitmap

16 - 16bit (high color) bitmap

24 - 24bit (true color) bitmap

32 - 32bit (true color) bitmap

001eh

compression

1 dword

compression specifications. the following values are possible:

0 - none (also identified by bi_rgb)

1 - rle 8-bit / pixel (also identified by bi_rle4)

2 - rle 4-bit / pixel (also identified by bi_rle8)

3 - bitfields (also identified by bi_bitfields)

0022h

bitmap data size

1 dword

size of the bitmap data in bytes. this number must be rounded to the next 4 byte boundary.

0026h

hresolution

1 dword

horizontal resolution expressed in pixel per meter.

002ah

vresolution

1 dword

vertical resolution expressed in pixels per meter.

002eh

colors

1 dword

number of colors used by this bitmap. for a 8-bit / pixel bitmap this will be 100h or 256.

0032h

important colors

1 dword

number of important colors. this number will be equal to the number of colors when every color is important.

0036h

palette

n * 4 byte

the palette specification. for every entry in the palette four bytes are used to describe the rgb values of the color in the following way:

1 byte for blue component


Transfer interrupted!

p>

1 byte for red component

1 byte filler which is set to 0 (zero)

0436h

bitmap data

x bytes

depending on the compression specifications, this field contains all the bitmap data bytes which represent indices in the color palette.

íí

note: the following sizes were used in the specification above:

size

# bytes

sign

char

1

signed

word

2

unsigned

dword

4

unsigned

field details

some of the fields require some more information. the following chapters will try to provide this information:

height field

the height field identifies the height of the bitmap in pixels. in other words, it describes the number of scan lines of the bitmap. if this field is negative, indicating a top-down dib, the compression field must be either bi_rgb or bi_bitfields. top-down dibs cannot be compressed.

bits per pixel field

the bits per pixel (bbp) field of the bitmap file determines the number of bits that define each pixel and the maximum number of colors in the bitmap.

  • when this field is equal to 1.

the bitmap is monochrome, and the palette contains two entries. each bit in the bitmap array represents a pixel. if the bit is clear, the pixel is displayed with the color of the first entry in the palette; if the bit is set, the pixel has the color of the second entry in the table.

íí

  • when this field is equal to 4.

the bitmap has a maximum of 16 colors, and the palette contains up to 16 entries. each pixel in the bitmap is represented by a 4-bit index into the palette. for example, if the first byte in the bitmap is 1fh, the byte represents two pixels. the first pixel contains the color in the second palette entry, and the second pixel contains the color in the sixteenth palette entry.

íí

  • when this field is equal to 8.