gamut

package
v0.1.17 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 9, 2026 License: MIT Imports: 1 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package gamut converts between sRGB, Display P3, Oklab and Oklch, and maps colors into a display's gamut as CSS Color 4 does.

Colors travel as extended sRGB: gamma encoded with the sRGB curve, mirrored around zero, so that a color outside the sRGB gamut (but inside Display P3's) has components below 0 or above 1.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Decode

func Decode(v float64) float64

Decode returns the linear light of an sRGB-encoded component, which may be outside 0 to 1.

func Encode

func Encode(v float64) float64

Encode is the inverse of Decode.

func FromOklch

func FromOklch(l, c, h float64) (float64, float64, float64)

FromOklch converts Oklch, with the hue in degrees, to Oklab.

func LinearP3ToSRGB

func LinearP3ToSRGB(r, g, b float64) (float64, float64, float64)

LinearP3ToSRGB converts linear Display P3 to linear sRGB.

func LinearSRGB

func LinearSRGB(l, a, b float64) (r, g, bb float64)

LinearSRGB converts Oklab to linear sRGB, unclamped.

func LinearSRGBToP3

func LinearSRGBToP3(r, g, b float64) (float64, float64, float64)

LinearSRGBToP3 converts linear sRGB to linear Display P3.

func Map

func Map(sp Space, l, c, h float64) (r, g, b float64)

Map returns the Oklch color as linear RGB inside the gamut of sp. It reduces the chroma, keeping lightness and hue, until clipping what is left out changes the color imperceptibly (the algorithm of CSS Color 4, "gamut mapping to a destination color space"). A negative or NaN chroma is 0, as CSS clamps it, a NaN lightness 0 and a hue that is not finite 0.

func Oklab

func Oklab(r, g, b float64) (l, a, bb float64)

Oklab converts linear sRGB to Oklab.

func Oklch

func Oklch(l, a, b float64) (float64, float64, float64)

Oklch converts Oklab to Oklch, with the hue in degrees.

Types

type Space

type Space int

Space is an RGB gamut colors are mapped into.

const (
	SRGB Space = iota
	DisplayP3
)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL