BITMAPINFOHEADER — the 40-byte DIB header used by virtually all modern BMP files.
The size field is what tells decoders which DIB header variant follows;
for BITMAPINFOHEADER it is always 40. Larger variants (V4/V5) are not
handled by this coder — read size first and dispatch externally if you
need to support them.
width is signed but in practice non-negative. height is signed: a
negative value means the image is stored top-down (rows in natural reading
order) instead of the BMP-default bottom-up. We deliberately preserve the
sign rather than auto-flipping rows; row orientation is the caller's
concern.
Shape of a BITMAPINFOHEADER for a 2×2 24bpp top-down image
Shape of a BITMAPINFOHEADER for a 2×2 24bpp top-down image
import { assertEquals } from "@std/assert"; import type { BitmapInfoHeader } from "@binstruct/bmp"; const dib: BitmapInfoHeader = { size: 40, width: 2, height: -2, planes: 1, bpp: 24, compression: 0, imageSize: 16, xPixelsPerMeter: 2835, yPixelsPerMeter: 2835, colorsUsed: 0, importantColors: 0, }; assertEquals(dib.size, 40); assertEquals(dib.height < 0, true);
size: number
width: number
height: number
planes: number
bpp: number
compression: number
imageSize: number
xPixelsPerMeter: number
yPixelsPerMeter: number
colorsUsed: number
importantColors: number