Module

Puregrain.Internal.State

Package
purescript-puregrain
Repository
roman-mkh/puregrain

The state the diffusion carries along: the queues of error fractions waiting for later pixels. Internal: may change without notice.

#RowLayer Source

type RowLayer :: (Type -> Type) -> Type -> Typetype RowLayer (f :: Type -> Type) a = Array (f a)

One queue per kernel offset of one row: the error fractions on their way to the pixels of a later row (or, for the current row's offsets, to pixels further right).

#DelayLine Source

type DelayLine :: (Type -> Type) -> Type -> Typetype DelayLine (f :: Type -> Type) a = Array (RowLayer f a)

The maturing RowLayers for one dy. It starts padded with dy copies of the empty RowLayer ([]): a placeholder that contributes zero error for free (sumErrors [] = zero), with no special case in the step. An Array rather than a queue: it's always short, at most the kernel's maxDepth.

#DitherState Source

type DitherState :: (Type -> Type) -> Type -> Typetype DitherState (f :: Type -> Type) a = { delayLines :: Array (DelayLine f a), nextRow :: Int, width :: Maybe Int }

What crosses from one row to the next: the delay lines; the index of the next row (nextRow, the y the quantizer will see), kept here rather than passed in, so a caller stepping row by row can't pass a wrong one; and the image's width, taken from the first row (Nothing before it), which every later row must match.

A plain immutable value: stepping from an old state again (an undo, say) redoes that row's work, the queues' list reversals included, and no more (see the CatQueue instance in Puregrain.Internal.Fifo).

#RowState Source

type RowState :: (Type -> Type) -> Type -> Typetype RowState (f :: Type -> Type) a = { building :: Array (RowLayer f a), current :: RowLayer f a, matured :: Array (RowLayer f a), x :: Int, y :: Int }

Row-local state, rebuilt for every pixel. x is the column of the next pixel and y this row's index — carried here rather than computed by an indexed traversal, because step rebuilds this record per pixel anyway (no extra allocation), whereas mapAccumLWithIndex on Array is a generic default with an extra pass per row.

#freshLayer Source

freshLayer :: forall f a. Fifo f => Ring a => Array Offset -> RowLayer f a

#initState Source

initState :: forall f a. CompiledKernel -> DitherState f a