Puregrain.Palette
- Package
- purescript-puregrain
- Repository
- roman-mkh/puregrain
Dithering to a palette: each pixel becomes the nearest palette color,
with all three channels chosen together. nearestColor is the ready
quantizer; ready-made palettes (black and white, web-safe, CGA, ANSI,
Commodore 64, ZX Spectrum) are in Puregrain.Palette.Presets.
Distances are plain RGB distances, which aren't perceptual: pure green is nearer to black than to white.
#CompiledPalette Source
newtype CompiledPaletteA palette ready to search: its colors, never empty, and the distance
to search them by. Build it once per image with compilePalette or
compilePaletteFromArray; read its colors with paletteColors.
Opaque, so its representation may change, to make the search faster,
say.
#compilePalette Source
compilePalette :: (RGB -> RGB -> Number) -> NonEmptyArray RGB -> CompiledPaletteMakes a palette ready to search.
RGB -> RGB -> Number: the distance between a pixel and a color, usuallydistance2.NonEmptyArray RGB: the colors.
palette = compilePalette distance2 websafe216
#compilePaletteFromArray Source
compilePaletteFromArray :: (RGB -> RGB -> Number) -> Array RGB -> Maybe CompiledPaletteAs compilePalette, for colors in a plain Array, as they come from
JSON or JavaScript, say.
RGB -> RGB -> Number: the distance, usuallydistance2.Array RGB: the colors.
Nothing for an empty array.
#paletteColors Source
paletteColors :: CompiledPalette -> NonEmptyArray RGBThe palette's colors, in the order they were given.
#nearestColorFast Source
nearestColorFast :: CompiledPalette -> RGB -> RGBThe palette's color nearest to a pixel, by the palette's distance; on
a tie, the earlier color. For many pixels, compile the palette once;
nearestColor does that for you.
CompiledPalette: the palette.RGB: the pixel.
#nearestColor Source
nearestColor :: NonEmptyArray RGB -> Quantize RGBA quantizer that turns each pixel into the nearest palette color, all
three channels together, by distance2; on a tie, the earlier color.
NonEmptyArray RGB: the palette, e.g. fromPuregrain.Palette.Presets.
ditherImage floydSteinberg (nearestColor websafe216) image
With a gamma (Puregrain.Dither.ditherImageWith), the nearest color is
still chosen on stored values, as the eye sees them: each corrected
pixel is brought back from light for the comparison, and the chosen
color taken to light, while the error stays in light. A pixel that's
exactly a byte's light comes back as that byte, so without diffusion
the result is the one ditherImage gives.
Its tone, for the methods whose weights depend on it
(Puregrain.Dither.ostromoukhov), is the mean of the pixel's three
channels, the same in every channel: one set of weights for the whole
pixel, as the palette decides on the whole pixel.
- 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