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.
#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.
#initState Source
initState :: forall f a. CompiledKernel -> DitherState f a- Modules
- Puregrain
- Puregrain.
Cells - Puregrain.
Dither - Puregrain.
Gamma - Puregrain.
Internal. Exact - Puregrain.
Internal. Fifo - Puregrain.
Internal. Gamma - Puregrain.
Internal. Image - Puregrain.
Internal. Kernel - Puregrain.
Internal. Quantize - Puregrain.
Internal. Row - Puregrain.
Internal. SelfCheck - Puregrain.
Internal. State - Puregrain.
Internal. Step - Puregrain.
Internal. Util - Puregrain.
Kernel - Puregrain.
Machine. C64 - Puregrain.
Machine. ZxSpectrum - Puregrain.
Ordered - Puregrain.
Palette - Puregrain.
Palette. Presets - Puregrain.
Pixel - Puregrain.
Quantize - Puregrain.
SelfCheck