package hugin

  1. Overview
  2. Docs

Module Hugin.ColorSource

Perceptually uniform OKLCH colors.

Perceptually uniform colors.

Colors are represented internally in the OKLCH color space. All operations (lighten, darken, mix) produce perceptually uniform results: equal numerical steps yield equal perceived differences.

Constructors accept common input formats (sRGB, hex) and convert to OKLCH on creation. The reverse conversion to_rgba is called only at render time.

Types

Sourcetype t

The type for colors in OKLCH space. Components are lightness [0, 1], chroma [0, ~0.4], hue [0, 360), and alpha [0, 1].

Constructors

Sourceval oklch : l:float -> c:float -> h:float -> unit -> t

oklch ~l ~c ~h () is the fully opaque OKLCH color with lightness l, chroma c, and hue h (in degrees).

Sourceval oklcha : l:float -> c:float -> h:float -> a:float -> unit -> t

oklcha ~l ~c ~h ~a () is like oklch with alpha a.

Sourceval rgb : r:float -> g:float -> b:float -> unit -> t

rgb ~r ~g ~b () is the fully opaque color with sRGB components r, g, b in [0, 1], converted to OKLCH.

Sourceval rgba : r:float -> g:float -> b:float -> a:float -> unit -> t

rgba ~r ~g ~b ~a () is like rgb with alpha a.

Sourceval hex : string -> t

hex s is the color parsed from the hex string s. Accepts "#RRGGBB" and "#RRGGBBAA" formats.

Raises Invalid_argument if s is not a valid hex color.

Accessors

Sourceval lightness : t -> float

lightness c is the OKLCH lightness of c in [0, 1].

Sourceval chroma : t -> float

chroma c is the OKLCH chroma of c in [0, ~0.4].

Sourceval hue : t -> float

hue c is the OKLCH hue of c in degrees [0, 360).

Sourceval alpha : t -> float

alpha c is the alpha of c in [0, 1].

Converting

Sourceval to_rgba : t -> float * float * float * float

to_rgba c is (r, g, b, a) with sRGB components in [0, 1]. Values are clamped to the sRGB gamut.

Operations

Sourceval with_alpha : float -> t -> t

with_alpha a c is c with alpha set to a.

Sourceval lighten : float -> t -> t

lighten amount c is c with lightness increased by amount, clamped to [0, 1].

Sourceval darken : float -> t -> t

darken amount c is c with lightness decreased by amount, clamped to [0, 1].

Sourceval mix : float -> t -> t -> t

mix ratio a b is the perceptual blend of a and b. ratio is the interpolation factor: 0.0 gives a, 1.0 gives b. Hue is interpolated along the shortest arc.

Named colors

The default named colors follow the Okabe-Ito palette, designed to be distinguishable under all forms of color-vision deficiency.

Sourceval orange : t
Sourceval sky_blue : t
Sourceval green : t
Sourceval yellow : t
Sourceval blue : t
Sourceval vermillion : t
Sourceval purple : t
Sourceval black : t
Sourceval white : t
Sourceval gray : t

Formatting

Sourceval pp : Format.formatter -> t -> unit

pp formats the color as oklch(L C H / A).