.bmp file format: GraphViz block diagram (.dot) source

This page hosts a formal specification of .bmp file format using Kaitai Struct. This specification can be automatically translated into a variety of programming languages to get a parsing library.

GraphViz block diagram source

bmp.dot

digraph {
	rankdir=LR;
	node [shape=plaintext];
	subgraph cluster__bmp {
		label="Bmp";
		graph[style=dotted];

		bmp__seq [label=<<TABLE BORDER="0" CELLBORDER="1" CELLSPACING="0">
			<TR><TD BGCOLOR="#E0FFE0">pos</TD><TD BGCOLOR="#E0FFE0">size</TD><TD BGCOLOR="#E0FFE0">type</TD><TD BGCOLOR="#E0FFE0">id</TD></TR>
			<TR><TD PORT="file_hdr_pos">0</TD><TD PORT="file_hdr_size">14</TD><TD>FileHeader</TD><TD PORT="file_hdr_type">file_hdr</TD></TR>
			<TR><TD PORT="len_dib_header_pos">14</TD><TD PORT="len_dib_header_size">4</TD><TD>s4le</TD><TD PORT="len_dib_header_type">len_dib_header</TD></TR>
			<TR><TD PORT="dib_header_pos">18</TD><TD PORT="dib_header_size">...</TD><TD>switch (len_dib_header)</TD><TD PORT="dib_header_type">dib_header</TD></TR>
		</TABLE>>];
		bmp__inst__image [label=<<TABLE BORDER="0" CELLBORDER="1" CELLSPACING="0">
			<TR><TD BGCOLOR="#E0FFE0">pos</TD><TD BGCOLOR="#E0FFE0">size</TD><TD BGCOLOR="#E0FFE0">type</TD><TD BGCOLOR="#E0FFE0">id</TD></TR>
			<TR><TD PORT="image_pos">file_hdr.ofs_bitmap</TD><TD PORT="image_size">⇲</TD><TD></TD><TD PORT="image_type">image</TD></TR>
		</TABLE>>];
bmp__seq_dib_header_switch [label=<<TABLE BORDER="0" CELLBORDER="1" CELLSPACING="0">
	<TR><TD BGCOLOR="#F0F2E4">case</TD><TD BGCOLOR="#F0F2E4">type</TD></TR>
	<TR><TD>104</TD><TD PORT="case0">BitmapCoreHeader</TD></TR>
	<TR><TD>12</TD><TD PORT="case1">BitmapCoreHeader</TD></TR>
	<TR><TD>40</TD><TD PORT="case2">BitmapInfoHeader</TD></TR>
	<TR><TD>124</TD><TD PORT="case3">BitmapCoreHeader</TD></TR>
</TABLE>>];
		subgraph cluster__file_header {
			label="Bmp::FileHeader";
			graph[style=dotted];

			file_header__seq [label=<<TABLE BORDER="0" CELLBORDER="1" CELLSPACING="0">
				<TR><TD BGCOLOR="#E0FFE0">pos</TD><TD BGCOLOR="#E0FFE0">size</TD><TD BGCOLOR="#E0FFE0">type</TD><TD BGCOLOR="#E0FFE0">id</TD></TR>
				<TR><TD PORT="magic_pos">0</TD><TD PORT="magic_size">2</TD><TD>42 4D</TD><TD PORT="magic_type">magic</TD></TR>
				<TR><TD PORT="len_file_pos">2</TD><TD PORT="len_file_size">4</TD><TD>u4le</TD><TD PORT="len_file_type">len_file</TD></TR>
				<TR><TD PORT="reserved1_pos">6</TD><TD PORT="reserved1_size">2</TD><TD>u2le</TD><TD PORT="reserved1_type">reserved1</TD></TR>
				<TR><TD PORT="reserved2_pos">8</TD><TD PORT="reserved2_size">2</TD><TD>u2le</TD><TD PORT="reserved2_type">reserved2</TD></TR>
				<TR><TD PORT="ofs_bitmap_pos">10</TD><TD PORT="ofs_bitmap_size">4</TD><TD>s4le</TD><TD PORT="ofs_bitmap_type">ofs_bitmap</TD></TR>
			</TABLE>>];
		}
		subgraph cluster__bitmap_core_header {
			label="Bmp::BitmapCoreHeader";
			graph[style=dotted];

			bitmap_core_header__seq [label=<<TABLE BORDER="0" CELLBORDER="1" CELLSPACING="0">
				<TR><TD BGCOLOR="#E0FFE0">pos</TD><TD BGCOLOR="#E0FFE0">size</TD><TD BGCOLOR="#E0FFE0">type</TD><TD BGCOLOR="#E0FFE0">id</TD></TR>
				<TR><TD PORT="image_width_pos">0</TD><TD PORT="image_width_size">2</TD><TD>u2le</TD><TD PORT="image_width_type">image_width</TD></TR>
				<TR><TD PORT="image_height_pos">2</TD><TD PORT="image_height_size">2</TD><TD>u2le</TD><TD PORT="image_height_type">image_height</TD></TR>
				<TR><TD PORT="num_planes_pos">4</TD><TD PORT="num_planes_size">2</TD><TD>u2le</TD><TD PORT="num_planes_type">num_planes</TD></TR>
				<TR><TD PORT="bits_per_pixel_pos">6</TD><TD PORT="bits_per_pixel_size">2</TD><TD>u2le</TD><TD PORT="bits_per_pixel_type">bits_per_pixel</TD></TR>
			</TABLE>>];
		}
		subgraph cluster__bitmap_info_header {
			label="Bmp::BitmapInfoHeader";
			graph[style=dotted];

			bitmap_info_header__seq [label=<<TABLE BORDER="0" CELLBORDER="1" CELLSPACING="0">
				<TR><TD BGCOLOR="#E0FFE0">pos</TD><TD BGCOLOR="#E0FFE0">size</TD><TD BGCOLOR="#E0FFE0">type</TD><TD BGCOLOR="#E0FFE0">id</TD></TR>
				<TR><TD PORT="image_width_pos">0</TD><TD PORT="image_width_size">4</TD><TD>u4le</TD><TD PORT="image_width_type">image_width</TD></TR>
				<TR><TD PORT="image_height_pos">4</TD><TD PORT="image_height_size">4</TD><TD>u4le</TD><TD PORT="image_height_type">image_height</TD></TR>
				<TR><TD PORT="num_planes_pos">8</TD><TD PORT="num_planes_size">2</TD><TD>u2le</TD><TD PORT="num_planes_type">num_planes</TD></TR>
				<TR><TD PORT="bits_per_pixel_pos">10</TD><TD PORT="bits_per_pixel_size">2</TD><TD>u2le</TD><TD PORT="bits_per_pixel_type">bits_per_pixel</TD></TR>
				<TR><TD PORT="compression_pos">12</TD><TD PORT="compression_size">4</TD><TD>u4le→Compressions</TD><TD PORT="compression_type">compression</TD></TR>
				<TR><TD PORT="len_image_pos">16</TD><TD PORT="len_image_size">4</TD><TD>u4le</TD><TD PORT="len_image_type">len_image</TD></TR>
				<TR><TD PORT="x_px_per_m_pos">20</TD><TD PORT="x_px_per_m_size">4</TD><TD>u4le</TD><TD PORT="x_px_per_m_type">x_px_per_m</TD></TR>
				<TR><TD PORT="y_px_per_m_pos">24</TD><TD PORT="y_px_per_m_size">4</TD><TD>u4le</TD><TD PORT="y_px_per_m_type">y_px_per_m</TD></TR>
				<TR><TD PORT="num_colors_used_pos">28</TD><TD PORT="num_colors_used_size">4</TD><TD>u4le</TD><TD PORT="num_colors_used_type">num_colors_used</TD></TR>
				<TR><TD PORT="num_colors_important_pos">32</TD><TD PORT="num_colors_important_size">4</TD><TD>u4le</TD><TD PORT="num_colors_important_type">num_colors_important</TD></TR>
			</TABLE>>];
		}
	}
	bmp__seq:file_hdr_type -> file_header__seq [style=bold];
	bmp__seq:dib_header_type -> bmp__seq_dib_header_switch [style=bold];
	bmp__seq_dib_header_switch:case0 -> bitmap_core_header__seq [style=bold];
	bmp__seq_dib_header_switch:case1 -> bitmap_core_header__seq [style=bold];
	bmp__seq_dib_header_switch:case2 -> bitmap_info_header__seq [style=bold];
	bmp__seq_dib_header_switch:case3 -> bitmap_core_header__seq [style=bold];
	bmp__seq:len_dib_header_type -> bmp__seq:dib_header_type [color="#404040"];
	file_header__seq:ofs_bitmap_type -> bmp__inst__image:image_pos [color="#404040"];
}