Module

Puregrain.Internal.WeightsByTone

Package
purescript-puregrain
Repository
roman-mkh/puregrain

Weights by tone: a fixed set of neighbours whose weights depend on the pixel's tone, one table of 256 weights per neighbour. The general form of Ostromoukhov's method (Puregrain.Internal.Ostromoukhov), so that nothing in the diffusion core knows a method's name, and its engine can be checked on random tables. Internal: may change without notice.

#WeightsByTone Source

newtype WeightsByTone

The neighbours, each with its column: the weight it gets for each tone, 0 to 255. One column per neighbour, not a row of weights per tone, so that the shape is fixed by construction: a tone changes how much error a neighbour gets, never which neighbours get it.

And the threshold's modulation strength by tone, 0 to 1, for a method that modulates its threshold (Zhou–Fang's): 0 everywhere for the others.

#fromRows Source

fromRows :: Array { dx :: Int, dy :: Int } -> Array (Array Number) -> Either String WeightsByTone

A table by tone from its rows, as tables are printed: row i holds the weights for tone i, one per neighbour, in the neighbours' order.

  • Array { dx :: Int, dy :: Int }: the neighbours, under the rules of Puregrain.Kernel.fromOffsets: each points forward, none twice.
  • Array (Array Number): exactly 256 rows, each with one finite weight per neighbour.

Left names the first rule broken.

#withStrength Source

withStrength :: Array Number -> WeightsByTone -> Either String WeightsByTone

The table with a threshold's modulation strength by tone: Zhou and Fang's m(i), which raises the threshold by noise × m(tone) / 255 of the interval between the two levels around the value (the noise from 0 to 127), so below one half.

  • Array Number: exactly 256 strengths, one per tone, each from 0 to 1.
  • WeightsByTone: the table.

Left names the first rule broken.

#columns Source

columns :: WeightsByTone -> Array { column :: Array Number, dx :: Int, dy :: Int }

The neighbours and their columns, as built.

#strength Source

strength :: WeightsByTone -> Array Number

The threshold's modulation strength by tone, as built.

#compileWeightsByTone Source

compileWeightsByTone :: forall a. MapChannels a => WeightsByTone -> CompiledKernel a

The table compiled for a pixel type: each neighbour looks its weight up in its column by the tone, channel by channel; and, where the strength isn't 0 everywhere, the threshold's raise for each pixel: the position's noise times each channel's strength, by its own tone, / 255.