Puregrain.Gamma
- Package
- purescript-puregrain
- Repository
- roman-mkh/puregrain
How a picture's stored numbers turn into light, for dithering that keeps the amount of light rather than the average of the numbers.
A gamma here doesn't adjust the picture, as an image editor's gamma
slider does: it says how the screen turns the numbers into light, and
the dithering then keeps that light. gammaOff, the default, converts
nothing, as dithering always has; gammaSrgb is linear light, the sRGB
standard's own curve; gamma1p2, gamma1p5 and gamma1p8 lie between.
Which value for which view, measured:
docs/gamma.md.
The curves are computed from exact arithmetic only, so they give the same results on every JavaScript engine; why and how: docs/exact-arithmetic.md.
#toLight Source
toLight :: forall a. ColorChannels a => Gamma -> a -> aConverts a pixel's color channels from stored values to light, on the same 0–255 scale, leaving alpha as it is.
Gamma: the curve.a: the pixel, as stored.
Returns the pixel in light. A whole number from 0 to 255 gets its light from a table built once per curve, the first time it's needed; other values from the curve's formula, with the same results. A negative value gets the negative of its magnitude's light.
toLight gammaSrgb 128.0 -- 55.04…, 21.6% of white's light
toLight gammaOff 128.0 -- 128.0
#fromLight Source
fromLight :: forall a. ColorChannels a => Gamma -> a -> aConverts a pixel's color channels from light back to stored values, leaving alpha as it is.
Gamma: the curve.a: the pixel, in light.
Returns the pixel as stored. The light of a whole number from 0 to 255 gives that number back exactly, so a palette's colors and a ramp's levels come back as they were; other values go through the curve's formula.
fromLight gammaSrgb (toLight gammaSrgb 85.0) -- 85.0, exactly
#toGray Source
toGray :: Gamma -> RGB -> NumberA color's gray, for dithering a color picture in gray.
Gamma: the curve, which decides the formula; give the dithering the same one.RGB: the color, as stored.
Returns the gray as a stored value, 0 to 255. A neutral color, with
red, green and blue equal, gives exactly that value. With gammaOff,
the gray is luma, 0.299 R + 0.587 G + 0.114 B on the stored values, the
classic conversion. With a curve, it's the gray that gives off as much
light as the color: 0.2126 R + 0.7152 G + 0.0722 B on the channels'
light (luminance, with gammaSrgb), brought back to a stored value.
Saturated colors then come out lighter than with luma, pure blue 76
instead of 29 with gammaSrgb; natural colors such as skin barely
change.
toGray gammaOff (RGB { r: 0.0, g: 0.0, b: 255.0 }) -- 29.07
toGray gammaSrgb (RGB { r: 0.0, g: 0.0, b: 255.0 }) -- 75.96…
ditherImageWith gammaSrgb floydSteinberg (threshold 128.0)
(map (map (toGray gammaSrgb)) image)
Re-exports from Puregrain.Internal.Gamma
- 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