Documentation
¶
Index ¶
- func LerpCIEXYZ(c1, c2 color.Color, v float32) color.Color
- func LerpLSRGB(c1, c2 color.Color, v float32) color.Color
- func LerpOKLAB(c1, c2 color.Color, v float32) color.Color
- func LerpOKLCH(c1, c2 color.Color, v float32) color.Color
- func LerpSRGB(c1, c2 color.Color, v float32) color.Color
- type CIELAB
- type CIELCH
- type CIEXYZ
- type HSL
- type HSV
- type LSRGB
- type OKLAB
- type OKLCH
- type SRGB
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func LerpCIEXYZ ¶
LerpCIEXYZ interpolates in device-independent CIE XYZ space. Useful for cross-device workflows and conversions, not perceptually uniform.
func LerpLSRGB ¶
LerpLSRGB interpolates in linear-light sRGB (after removing gamma). More physically accurate than plain sRGB (like mixing light). Best for image compositing and blending intensities.
func LerpOKLAB ¶
LerpOKLAB interpolates in OKLab, a perceptually uniform space. Produces smooth, visually even blends. Best for perceptual color mixing and gradients.
Types ¶
type CIELAB ¶
type CIELAB struct {
// L* (L-star) Perceptual Lightness calcuilated using the cube root of relative luminance with an offset near black.
// Defines black at 0 and white at 1.
L float32
// a* axis (unbounded) Varies greenish appearance.
A float32
// b* axis (unbounded) varies red/green/yellow to blue.
B float32
}
CIELAB or also known as LAB, is a color model defined by the international commission on illumination (CIE) in 1976. It is designed so that a given numerical change always corresponds to a similar preceived change in color. Since a* and b* axes are unbounded a correct CIELAB color may not be representable in sRGB gamut.
type CIELCH ¶
type CIELCH struct {
L float32 // Perceptual luminosity. Same as for [CIELAB].
C float32 // chroma.
H float32 // hue.
}
CIELCH is the cylindiracl hue color space representation of CIELAB.
type CIEXYZ ¶
type CIEXYZ struct {
X, Y, Z float32
}
CIEXYZ refers to the 1931 CIE color space defined such that a mixture between two colors in some proportion lies on the line between those two colors in this space. One disadvantage of this model is that it is not perceptually uniform. The disadvantage is remedied in subsequent color models such as CIELUV and CIELAB. The XYZ values are also called tristiumulants.
func Illuminant ¶
Illuminant returns a standard illuminant given the CIE chromaticity coordinates of a perfectly reflecting (or transmitting) diffuser.
func IlluminantD50 ¶
IlluminantD50 returns the standard illuminant representing horizon light (D50). Values are normalized to the y value provided.
func IlluminantD65 ¶
IlluminantD65 returns the standard illuminant which represents noon daylight (D65). Values are normalized to the y value provided.
type HSL ¶
type HSL struct {
H float32 // Hue. Is the radial component.
S float32 // Saturation. Also known as chroma. Corresponds to intensity of color.
L float32 // Lightness.
}
HSL is the Hue–Saturation–Lightness cylindrical-coordinate color space. It is similar to HSV but defines the third axis as lightness rather than value. HSL is widely used in digital art and CSS because its parameters allow for intuitive control over tints, shades, and tones.
type HSV ¶
HSV is the Hue–Saturation–Value cylindrical-coordinate color space. It is often used in user interfaces and color pickers because it aligns more closely with human perception of color attributes than RGB.
Components:
- H (Hue): The angle of the color on the color wheel, measured in degrees. Range is [0, 360). Red = 0°, Green = 120°, Blue = 240°. Undefined for achromatic colors (S = 0).
- S (Saturation): The intensity or purity of the hue, in [0, 1]. 0 means grayscale (no color), 1 means fully saturated.
- V (Value): The brightness of the color, in [0, 1]. 0 corresponds to black, 1 corresponds to the brightest form of the color given its hue and saturation.
Example usage:
HSV{H: 0, S: 1, V: 1} // pure red
HSV{H: 120, S: 1, V: 1} // pure green
HSV{H: 240, S: 1, V: 1} // pure blue
type LSRGB ¶
LSRGB is linear-light (un-companded) color space.
func (LSRGB) ClipToGamut ¶
ClipToGamut clamps each channel of the linear-light RGB color to [0,1]. Useful after computations that may push values slightly outside the gamut.
type OKLAB ¶
type OKLAB struct {
// Preceptual lightness. See [LAB]
L float32
// A and B for opposite channels of the four unique hues. unbounded but in practice ranging from -0.5 to 0.5.
// CSS assigns ±100% to ±0.4 for both.
A float32
B float32
}
OKLAB is a uniform color space for device independent coloring designed to improve preceptual uniformity, hue and lightness prediction, color blending and usability regarding numerical stability.
type OKLCH ¶
type OKLCH struct {
L float32 // Perceptual luminosity. Same as for [OKLAB].
C float32 // Chroma. Defines intensity of hue.
H float32 // Hue in degrees.
}
OKLCH is cylindrical representation of OKLAB color space.
func (OKLCH) GamutMappedLSRGB ¶
GamutMappedLSRGB maps the OKLCH color into the sRGB gamut.
If the color is already representable in sRGB, it is returned unchanged. Otherwise, chroma is reduced until the color can be expressed in linear sRGB without clipping, while keeping lightness and hue as stable as possible.
Best used after interpolation in OKLab/OKLCH to ensure the result is displayable.
type SRGB ¶
SRGB usually denoted as sRGB (standard Red-Green-Blue) is a color space for use on printers, monitors and the world wide web. This is to say most monitors/printers receive color data as a triplets for each pixel representing redness, greeness and blueness.
func ColorToSRGB ¶
ColorToSRGB converts the color to SRGB discarding the opacity/alpha (A) field.
func (SRGB) ClipToGamut ¶
ClipToGamut clamps each channel of the gamma-encoded sRGB color to [0,1]. Useful to avoid invalid values when converting or interpolating.
