function rowStride
rowStride(
width: number,
bpp: number
): number

Computes the BMP row stride in bytes for a given pixel width and bit depth.

BMP rows are padded so each row's byte length is a multiple of 4. The formula is the canonical floor((bpp * width + 31) / 32) * 4.

Examples

Row stride matches the spec for common bit depths

import { assertEquals } from "@std/assert";
import { rowStride } from "@binstruct/bmp";

assertEquals(rowStride(2, 24), 8);   // 6 bytes of pixels + 2 bytes pad
assertEquals(rowStride(2, 32), 8);   // 8 bytes, already aligned
assertEquals(rowStride(3, 24), 12);  // 9 bytes of pixels + 3 bytes pad
assertEquals(rowStride(7, 1), 4);    // 1 byte of pixels + 3 bytes pad

Parameters

width: number

Image width in pixels (must be non-negative).

bpp: number

Bits per pixel.

Return Type

number

Bytes per row including padding.