Module

Puregrain.Internal.Noise

Package
purescript-puregrain
Repository
roman-mkh/puregrain

White noise for threshold modulation (Zhou–Fang's method): a number from 0 to 127 for each pixel position, from a hash of the position, so that it doesn't depend on the order the pixels are visited in (rows streamed, the stepper, cells, serpentine scanning) and is the same on every engine. Internal: may change without notice.

#noise Source

noise :: Int -> Int -> Int

The noise at a position: 0 to 127, like C's rand() % 128 in Zhou and Fang's formula, whose generator they leave to "the program library supplied with any programming languages" (their footnote 3). A fixed seed, so the same picture dithers alike every time.

  • Int, Int: the column and the row, from the image's top-left.

#imul Source

imul :: Int -> Int -> Int

32-bit multiplication, as JavaScript's Math.imul, exactly: from 16-bit halves, so that no product exceeds 2^53. PureScript's own * on Int compiles to a * b | 0, whose product loses its low bits once it passes 2^53 (the same on every engine, but not the 32-bit product a hash needs).