function pixelDataSize
pixelDataSize(
width: number,
height: number,
bpp: number
): number

Computes the total pixel-data size for a BITMAPINFOHEADER, in bytes.

The result is rowStride(width, bpp) * |height| — the absolute value of height is used so top-down (height < 0) and bottom-up images yield the same buffer size.

Examples

Pixel-data size for 2×2 24bpp and a top-down 2×2 32bpp image

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

assertEquals(pixelDataSize(2, 2, 24), 16);   // stride 8 × 2 rows
assertEquals(pixelDataSize(2, -2, 32), 16);  // top-down, sign ignored

Parameters

width: number

Image width in pixels.

height: number

Image height in pixels (sign ignored).

bpp: number

Bits per pixel.

Return Type

number

Total bytes of pixel data including row padding.