Puregrain.Internal.Kernel
- Package
- purescript-puregrain
- Repository
- roman-mkh/puregrain
The compiled form of a kernel, built once per image so the per-pixel step doesn't filter the kernel again for every pixel (PureScript shares nothing automatically). Internal: may change without notice.
#CompiledOffset Source
type CompiledOffset a = { dx :: Int, dy :: Int, weightFor :: a -> a }One neighbour of a compiled kernel: where its share of the error goes
(dx, dy, as in Offset), and the weights it gets, one per channel,
as a function of the pixel's tone. A kernel's weights don't depend on
the tone (fixed); a method by tone's do. The positions stay plain
data, so a tone can change how much error a neighbour gets, never
where it goes.
#CompiledKernel Source
type CompiledKernel a = { currentOffsets :: Array (CompiledOffset a), futureLayers :: Array (Array (CompiledOffset a)), maxDepth :: Int, needsTone :: Boolean, thresholdRaise :: Maybe ({ x :: Int, y :: Int } -> a -> a) }Precomputed per kernel: the offsets in the current row, the offsets
of each later row grouped by dy (layer i holds those with
dy == i + 1), the deepest dy, and whether the weights depend on
the tone (needsTone: only then does the step ask the quantizer for
it), and the threshold's raise, from the pixel's position and tone, for
a method that modulates its threshold (Zhou–Fang's; Nothing for the
others, which then cost nothing for it). Built once by compileKernel
or compileOffsets, then passed on as plain data through the row and
step code.
#compileKernel Source
compileKernel :: forall a. Semiring a => Scalable a => Kernel -> CompiledKernel a#compileOffsets Source
compileOffsets :: forall a. Boolean -> Array (CompiledOffset a) -> CompiledKernel aCompiled offsets sorted by row, as compileKernel sorts a kernel's.
Boolean: whether their weights depend on the tone.Array (CompiledOffset a): the offsets.
#fixed Source
fixed :: forall a. Semiring a => Scalable a => Offset -> CompiledOffset aAn offset whose weight is the same for every tone and channel: the
weight's pixel, (w, w, w), is built once. The step multiplies it by the
error, channel by channel, which gives the same numbers as
scale w error: w × 1 is w, and the products are the same.
#byTone Source
byTone :: forall a. MapChannels a => Int -> Int -> Array Number -> CompiledOffset aAn offset whose weights depend on the tone: its column holds one
weight per tone, 0 to 255, and each channel looks its own up by its
own tone, rounded to the nearest row and kept within 0..255 (a tone
that isn't a finite number counts as 0, as Data.Int.round makes it).
Int,Int: the offset'sdxanddy.Array Number: the column, 256 weights.
#paddingFor Source
paddingFor :: forall r. { dx :: Int | r } -> IntThe zeros a queue starts with: one per column its error skips to the
right. For any offset with a dx, compiled or not.
- Modules
- Puregrain
- Puregrain.
Cells - Puregrain.
Dither - Puregrain.
Gamma - Puregrain.
Internal. Cells - Puregrain.
Internal. Exact - Puregrain.
Internal. Fifo - Puregrain.
Internal. Gamma - Puregrain.
Internal. Image - Puregrain.
Internal. Kernel - Puregrain.
Internal. Noise - Puregrain.
Internal. Ostromoukhov - Puregrain.
Internal. Params - Puregrain.
Internal. Quantize - Puregrain.
Internal. Row - Puregrain.
Internal. SelfCheck - Puregrain.
Internal. State - Puregrain.
Internal. Step - Puregrain.
Internal. Util - Puregrain.
Internal. WeightsByTone - Puregrain.
Internal. ZhouFang - Puregrain.
Kernel - Puregrain.
Machine. C64 - Puregrain.
Machine. ZxSpectrum - Puregrain.
Ordered - Puregrain.
Palette - Puregrain.
Palette. Presets - Puregrain.
Pixel - Puregrain.
Quantize - Puregrain.
SelfCheck