Module

Puregrain.Internal.Gamma

Package
purescript-puregrain
Repository
roman-mkh/puregrain

The light curves behind Puregrain.Gamma, on single values on the 0–255 scale. Internal: may change without notice. Why the curves are built from exact operations only, and how: docs/exact-arithmetic.md.

#Gamma Source

data Gamma

A curve between a picture's stored values and light: one of Puregrain.Gamma's presets, gammaOff, gamma1p2, gamma1p5, gamma1p8 and gammaSrgb.

Constructors

#CurveParts Source

type CurveParts = { fromLight :: Number -> Number, table :: Lazy (Array Number), toLight :: Number -> Number }

#Conversion Source

type Conversion a = { fromLight :: a -> a, gamma :: Gamma, toLight :: a -> a }

What a driver hands a quantizer: a pixel type's two conversions, and the curve itself, for quantizers of single channels (perChannel).

#noConversion Source

noConversion :: forall a. Conversion a

No conversion, for gammaOff: the drivers and the quantizers check isOff once per run and then skip converting altogether, so the identities here are never called per pixel.

#conversionFor Source

conversionFor :: forall a. ColorChannels a => Gamma -> Conversion a

The conversion of a pixel type's color channels by a curve.

#isOff Source

isOff :: Gamma -> Boolean

Whether the curve is Off, the identity.

#curve Source

curve :: (Number -> Number) -> (Number -> Number) -> Gamma

A curve from its two formulas on the 0–1 scale, defined for 0 and up: scaled to 0–255 and mirrored for negative values, f(-v) = -f(v), as the W3C's sample code (CSS Color 4) extends sRGB's.

#power1p2 Source

power1p2 :: Gamma

x^1.2 = x · ⁵√x; back, L^(5/6) = √L · ∛L.

#power1p5 Source

power1p5 :: Gamma

x^1.5 = x · √x; back, L^(2/3) = (∛L)².

#power1p8 Source

power1p8 :: Gamma

x^1.8 = x · (⁵√x)⁴; back, L^(5/9) = (∛(∛L))⁵.

#srgb Source

srgb :: Gamma

sRGB's curve (IEC 61966-2-1): a straight piece near black, then a power of 2.4 with an offset. x^2.4 = x² · (⁵√x)²; back, L^(5/12) = √√L · √∛L.

#toLightValue Source

toLightValue :: Gamma -> Number -> Number

A value's light: a byte's from the table, any other value's from the formula (the table holds the formula's results, so both agree).

#fromLightValue Source

fromLightValue :: Gamma -> Number -> Number

A light value back to a stored one, for what's written: the light of a byte gives that byte exactly, found in the table; any other value goes through the formula.

#toLightFormula Source

toLightFormula :: Gamma -> Number -> Number

The formula to light, without the table.

#fromLightFormula Source

fromLightFormula :: Gamma -> Number -> Number

The formula back, without the table: for the self-check and the tests. The dithering's comparisons use fromLightValue, table first, so that a byte's light comes back as exactly that byte.

#lightTable Source

lightTable :: Gamma -> Array Number

The light of the 256 bytes; for Off, the bytes themselves.