quantise

Reduces each grid cell of the layer inside to 0 or 1 using a dither pattern.

quantise(slots: {grid: PixelGrid; pattern: PropRef; threshold: PropRef; spread: PropRef}): GatherStage

Import patterns from shaders/std and use patterns.quantise.

Returns a per-pixel level for ditherInks. pattern is a compileTime: true select prop with one of bayer2, bayer4, bayer8, clusteredDot, blueNoise, whiteNoise or floydSteinberg. threshold 0–1 shifts the cut point; 0.5 is neutral. spread 0–1 is how much of the brightness range dithers; lower leaves more solid areas.

Parameters

NameTypeNotes
slots{grid: PixelGrid; pattern: PropRef; threshold: PropRef; spread: PropRef}

Example

const levels = quantise({grid, pattern: p('pattern'), threshold: p('threshold'), spread: p('spread')})

Tip. Floyd–Steinberg is the costliest pattern: it re-reads 64 cells per pixel. Bayer 4 is the cheap default.

See also

  • pixelGrid — The pixel grid of a dither: the layer inside it chopped into square cells of a given size.
  • ditherInks — A dither filter: colors the 0/1 levels from quantise, either with two colors of your own or with darkened and brightened versions of the layer's own pixels.

Used by

Dither