Puregrain.Internal.Params
- Package
- purescript-puregrain
- Repository
- roman-mkh/puregrain
The settings every driver shares, behind Puregrain.Dither's opaque
DitherParams, and their compiled form. Internal: may change without
notice.
(The doc comments below the module's are what Pursuit shows, through
Puregrain.Dither's re-export.)
#DitherParams Source
newtype DitherParamsHow an image is dithered, apart from the quantizer: the diffusion,
where each pixel's error goes (a kernel, or a method by tone); the
gamma, in which light; and the scan, the order the pixels are visited
in. Opaque: start from defaults and
change one setting at a time with the with… functions, chained with
#:
params = defaults # withKernel floydSteinberg # withGamma gammaSrgb # withScan serpentine
dithered = ditherImageBy params (threshold 128.0) image
The order of the with… calls doesn't matter; a later call of the
same one replaces the earlier setting. The quantizer is an argument of
its own, since its type depends on the driver: a Quantize a for
ditherImageBy, a cell rule for Puregrain.Cells.ditherCellsBy.
Constructors
DitherParams { diffusion :: Diffusion, gamma :: Gamma, scan :: Scan }
#Scan Source
data ScanThe order the pixels are visited in, for withScan: raster or
serpentine. Opaque.
Constructors
#Diffusion Source
data DiffusionHow each pixel's error is spread, for withDiffusion: a kernel's
fixed weights (fixedKernel), or weights that depend on the pixel's
tone (ostromoukhov). Opaque.
Constructors
#defaults Source
defaults :: DitherParamsThe settings to start from, each one neutral: no diffusion
(noDiffusion), so each pixel is only quantized; gammaOff; and
raster, every row left to right. Dithering with them alone is plain
quantizing, or pure ordered dithering with a quantizer from
Puregrain.Ordered; add a kernel with withKernel for error
diffusion.
#withKernel Source
withKernel :: Kernel -> DitherParams -> DitherParamsSets the kernel: the same as withDiffusion (fixedKernel kernel).
Kernel: where each pixel's error goes, fromPuregrain.Kernel;noDiffusionfor nowhere.DitherParams: the settings to change.
Returns the settings with that kernel, the others unchanged.
#withDiffusion Source
withDiffusion :: Diffusion -> DitherParams -> DitherParamsSets the diffusion. It and withKernel set the same setting, so the
later of the two counts.
Diffusion:fixedKernelwith a kernel, orostromoukhov.DitherParams: the settings to change.
Returns the settings with that diffusion, the others unchanged.
params = defaults # withDiffusion ostromoukhov
#fixedKernel Source
fixedKernel :: Kernel -> DiffusionA kernel's diffusion: the same weights for every pixel, from
Puregrain.Kernel.
#ostromoukhov Source
ostromoukhov :: DiffusionOstromoukhov's variable-coefficient error diffusion (SIGGRAPH 2001): three neighbours, right, down-left and down, whose weights depend on the pixel's tone, from a table tuned so that flat areas of every gray come out as even patterns, without the lines and lattices of Floyd–Steinberg in its worst grays.
Each channel looks its weights up by its own tone. The tone is where the pixel's original value lies between the two levels around it, so that a mix of two levels gets the row tuned for that mix: with black and white, the value itself; with a palette, the mean of the pixel's channels, the same in each, as palette colors have no order to lie between and the palette decides on the whole pixel; in a machine's cells, the share along the cell's two colors.
It always scans serpentine, as the method is defined, whatever
withScan says. Its table, its sources and what it looks like:
docs/weights-by-tone/ostromoukhov.md.
#zhouFang Source
zhouFang :: DiffusionZhou and Fang's error diffusion with threshold modulation (SIGGRAPH
2003): Ostromoukhov's three neighbours with weights of its own by
tone, and a threshold raised at random, 128 + (noise mod 128) ×
m(tone), with a strength m by tone. The noise breaks up the regular
patterns Ostromoukhov's method still shows in the mid-tones, for a
little more grain.
The threshold is raised by a fraction of the interval between the two levels around a value, so with more levels each interval gets the black-and-white patterns, scaled; per channel by each channel's tone; in a machine's cells along the cell's two colors. Palettes, ordered dithering and quantizers of one's own have no threshold to raise: with them, it diffuses with its weights alone. The noise comes from a hash of the pixel's position, with a fixed seed: the same picture dithers alike everywhere, every time. It always scans serpentine. Its tables, its sources and what it looks like: docs/weights-by-tone/zhou-fang.md.
#withGamma Source
withGamma :: Gamma -> DitherParams -> DitherParamsSets the gamma.
Gamma: how the stored numbers turn into light, fromPuregrain.Gamma:gammaOff,gamma1p2,gamma1p5,gamma1p8orgammaSrgb. Which for which view: docs/gamma.md.DitherParams: the settings to change.
Returns the settings with that gamma, the others unchanged.
#withScan Source
withScan :: Scan -> DitherParams -> DitherParamsSets the scan, the order the pixels are visited in.
Scan:raster, every row left to right (the default), orserpentine, the rows alternating.DitherParams: the settings to change.
Returns the settings with that scan, the others unchanged.
#serpentine Source
serpentine :: ScanSerpentine scanning: the rows alternate, the first (row 0) left to
right, the second right to left, and so on, top to bottom. On a row
scanned right to left the kernel is mirrored, so each pixel's error
still goes to pixels not yet processed: an offset's dx then counts
to the left. It's the usual remedy for the patterns error diffusion
draws when every row is scanned the same way.
Each pixel's quantizer still gets its own position, counted from the
image's left and top edges, so ordered dithering and machine cells
work as with raster. With noDiffusion it changes nothing. What it
changes, and what it doesn't:
docs/error-diffusion.md.
#gammaOf Source
gammaOf :: DitherParams -> GammaThe gamma of the settings, for the drivers' conversion to light.
#CompiledParams Source
type CompiledParams a = { kernel :: CompiledKernel a, scan :: Scan }What the row code needs of the settings, compiled once per image: the
kernel's offsets sorted by row (CompiledKernel), and the scan. The
kernel's compiled form stays apart from the scan, since the scan isn't
a property of the kernel: the per-pixel step needs only the kernel.
Typed by the pixel, since the compiled kernel's weights are pixels
(one weight per channel).
#compileParams Source
compileParams :: forall a. Semiring a => Scalable a => MapChannels a => DitherParams -> CompiledParams aThe settings compiled for a pixel type. The rule between settings lives here: a diffusion by tone always scans serpentine, as the methods by tone are defined (Ostromoukhov's table was tuned for it), whatever the scan set.
#compileKernelParams Source
compileKernelParams :: forall a. Semiring a => Scalable a => Kernel -> CompiledParams aA kernel alone compiled, with every row left to right: the settings
of the drivers that take a kernel and nothing else (ditherImage,
initDithering, and their twins with a gamma). Needs no
MapChannels, since a kernel's weights don't depend on the tone.
- 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