Skip to content

@mbtech-nl/bitmap / floydSteinberg

Function: floydSteinberg()

ts
function floydSteinberg(
   luminance: Float32Array, 
   width: number, 
   height: number, 
   invert: boolean, 
   mask?: Uint8Array): LabelBitmap;

Defined in: dither.ts:145

Floyd–Steinberg error-diffusion dither.

Quantises a normalised luminance buffer (values in [0, 1]) to packed 1bpp output. Kept as a public export for v1.0 compatibility; new code should pass dither: 'floyd-steinberg' to renderImage instead, which handles luminance conversion, gamma, and rotation around it.

Parameters

ParameterTypeDescription
luminanceFloat32ArrayNormalised luminance, length width * height.
widthnumberImage width in pixels.
heightnumberImage height in pixels.
invertbooleanIf true, swap black and white in the output.
mask?Uint8ArrayOptional Uint8Array (length width * height); pixels with mask[i] === 0 neither emit ink nor receive diffused error. Used internally by renderMultiPlaneImage to keep error confined to a plane's classified region. Omit for ordinary single-plane dithering.

Returns

LabelBitmap

A 1bpp LabelBitmap of dimensions width × height.

Example

ts
const bmp = floydSteinberg(luminance, 384, 64, false);

Released under the MIT License.