color

package
v2.0.0 Latest Latest
Warning

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

Go to latest
Published: Dec 5, 2025 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const CieE float64 = 216.0 / 24389.0

CieE is the threshold for linear vs. nonlinear transition. Reference

View Source
const CieK float64 = 24389.0 / 27.0

CieK s the constant used for linear approximation. Reference

Variables

View Source
var CatInvMatrix = num.NewMatrix3(
	1.86206786, -1.01125463, 0.14918678,
	0.38752654, 0.62144744, -0.00897399,
	-0.0158415, -0.03412294, 1.04996444,
)

CatInvMatrix is the inverse of CatMatrix.

It converts CAM16 LMS cone responses back into linear RGB values, reversing the chromatic adaptation process. This matrix is used when converting from the CAM16/HCT perceptual space back to RGB.

View Source
var CatMatrix = num.NewMatrix3(
	0.401288, 0.650173, -0.051461,
	-0.250268, 1.204414, 0.045854,
	-0.002079, 0.048952, 0.953127,
)

CatMatrix is the forward CAT (Chromatic Adaptation Transform) matrix.

It converts linear RGB values into the CAM16 LMS (Long, Medium, Short) cone response domain. This step models how the human visual system adapts to different white points and viewing conditions.

The CAT16 matrix is part of the CAM16 color appearance model used by the HCT color system.

View Source
var CriticalPlanes = []float64{}/* 255 elements not displayed */

CriticalPlanes is used for converting Hct to ARGB

View Source
var DefaultEnvironment = NewEnvironment(adaptingLuminance, 50, 2, false)

DefaultEnvironment returns the default sRGB-like viewing conditions.

View Source
var LinrgbFromScaledDiscount = num.NewMatrix3(
	1373.2198709594231, -1100.4251190754821, -7.278681089101213,
	-271.815969077903, 559.6580465940733, -32.46047482791194,
	1.9622899599665666, -57.173814538844006, 308.7233197812385,
)

LinrgbFromScaledDiscount is the inverse of ScaledDiscountFromLinRGB.

It converts values from the scaled discount space back into linear RGB, reconstructing displayable color values from the perceptual model (used when converting HCT → RGB).

View Source
var OkLabMatrix1 = num.NewMatrix3(
	0.8189330101, 0.3618667424, -0.1288597137,
	0.0329845436, 0.9293118715, 0.0361456387,
	0.0482003018, 0.2643662691, 0.6338517070,
)

OkLabMatrix1 defines the linear transformation from CIE XYZ to LMS cone responses used in the OkLab color model.

This corresponds to the matrix M1 in Ottosson’s paper:

[L, M, S]^T = M1 * [X, Y, Z]^T
View Source
var OkLabMatrix1Inv = num.NewMatrix3(
	1.2270138511, -0.5577999807, 0.2812561490,
	-0.0405801784, 1.1122568696, -0.0716766787,
	-0.0763812845, -0.4214819784, 1.5861632204,
)

OkLabMatrix1Inv is the inverse of M1, used to convert from LMS back to XYZ.

View Source
var OkLabMatrix2 = num.NewMatrix3(
	0.2104542553, 0.7936177850, -0.0040720468,
	1.9779984951, -2.4285922050, 0.4505937099,
	0.0259040371, 0.7827717662, -0.8086757660,
)

OkLabMatrix2 defines the transformation from nonlinearly transformed LMS (after cube-root compression) to OkLab coordinates (L, a, b).

This corresponds to matrix M2 in Ottosson’s formulation:

[L, a, b]^T = M2 * [L', M', S']^T
View Source
var OkLabMatrix2Inv = num.NewMatrix3(
	0.9999999985, 0.3963377922, 0.2158037581,
	1.0000000089, -0.1055613423, -0.0638541748,
	1.0000000547, -0.0894841821, -1.2914855379,
)

OkLabMatrix2Inv is the inverse of M2, used to convert from OkLab (L,a,b) back to cube-rooted LMS values.

View Source
var RGB_TO_XYZ = num.NewMatrix3(
	0.41233895, 0.35762064, 0.18051042,
	0.2126, 0.7152, 0.0722,
	0.01932141, 0.11916382, 0.95034478,
)

RGB_TO_XYZ is the Matrix3 that is used for converting sRGB colors to XYZ

View Source
var ScaledDiscountFromLinRGB = num.NewMatrix3(
	0.001200833568784504, 0.002389694492170889, 0.0002795742885861124,
	0.0005891086651375999, 0.0029785502573438758, 0.0003270666104008398,
	0.00010146692491640572, 0.0005364214359186694, 0.0032979401770712076,
)

ScaledDiscountFromLinRGB is a 3×3 transform matrix that converts from linear RGB to the "scaled discount" space used internally by the CAM16/HCT color appearance model.

This transformation accounts for human visual response under standard viewing conditions, mapping linear RGB signals into a perceptual domain where hue, chroma, and tone can be computed.

View Source
var WhitePointD65 = num.NewVector3(95.047, 100.0, 108.883)

WhitePointD65 is the white most point of XYZ to sRGB color space

View Source
var XYZ_TO_RGB = num.NewMatrix3(
	3.2413774792388685, -1.5376652402851851, -0.49885366846268053,
	-0.9691452513005321, 1.8758853451067872, 0.04156585616912061,
	0.05562093689691305, -0.20395524564742123, 1.0571799111220335,
)

XYZ_TO_RGB is the Matrix3 that is used for converting XYZ colors to sRGB

View Source
var YFromLinRGB = num.NewVector3(0.2126, 0.7152, 0.0722)

YFromLinRGB vector is used to get Y star of CieLab from linear RGB

Functions

func Delinearized

func Delinearized(component float64) uint8

Delinearized takes component (float64) that represents linear R/G/B channel. Component should be 0.0 < component < 1.0. Returns uint8 (0 <= n <= 255) representation of color component.

func IsBlue

func IsBlue(hue float64) bool

IsBlue reports whether hue falls in the blue range [250, 270].

func IsCyan

func IsCyan(hue float64) bool

IsCyan reports whether hue falls in the cyan range [170, 207].

func IsYellow

func IsYellow(hue float64) bool

IsYellow reports whether hue falls in the yellow range [105, 125].

func Linearized

func Linearized(component uint8) float64

Linearized takes component (uint8) that represents R/G/B channel. Returns 0.0 <= output <= 1.0, color channel converted to linear RGB space

func LstarFromY

func LstarFromY(y float64) float64

LstarFromY converts Y (relative luminance) in the XYZ color space to L* (perceptual luminance) in the CIELAB color space.

Both Y and L* represent luminance, but Y is linear and L* is perceptually uniform.

y is the Y value in the XYZ color space. It returns the corresponding L* value in the CIELAB color space.

func YFromLstar

func YFromLstar(lstar float64) float64

YFromLstar converts an L* (perceptual luminance) value from the CIELAB color space to Y (relative luminance) in the XYZ color space.

Both L* and Y represent luminance, but L* is perceptually uniform and Y is linear.

lstar is the L* value in the CIELAB color space. It returns the corresponding Y value in the XYZ color space.

Types

type ARGB

type ARGB uint32

ARGB represents a 32-bit color in ARGB format (Alpha, Red, Green, Blue) packed into a uint32. It implements the color.Color interface.

func ARGBFromHex

func ARGBFromHex(hex string) (ARGB, error)

ARGBFromHex parses a hex color string and returns an ARGB color. hex is the hexadecimal color string to parse. Returns the parsed ARGB color and error if the RGB hex is invalid.

Supports formats: #RGB, #RGBA, #RRGGBB, #RRGGBBAA.

TODO: optimize me...

func ARGBFromHexMust

func ARGBFromHexMust(hex string) ARGB

ARGBFromHexMust parses a hex color string and returns an ARGB color. Panics if the string cannot be parsed. Supports formats: #RGB, #RGBA, #RRGGBB, #RRGGBBAA. hex: The hexadecimal color string to parse Returns the parsed ARGB color.

func ARGBFromInterface

func ARGBFromInterface(c color.Color) ARGB

ARGBFromInterface converts any color.Color implementation to ARGB. It handles the 16-bit to 8-bit conversion automatically.

func ARGBFromLinearRGB

func ARGBFromLinearRGB(r, g, b float64) ARGB

ARGBFromLinearRGB creates an opaque ARGB color from linear RGB components. r, g, b are linear RGB components (0-100). Returns the corresponding opaque ARGB color after delinearization.

func ARGBFromLstar

func ARGBFromLstar(lstar float64) ARGB

ARGBFromLstar converts a CIE L* (lightness) value to an ARGB grayscale color. lstar is lightness value in the L*a*b* color space (0-100) Returns an ARGB grayscale color matching the specified lightness.

func ARGBFromRGB

func ARGBFromRGB(r, g, b uint8) ARGB

ARGBFromRGB creates an opaque ARGB color (alpha=255) from 8-bit RGB components. r, g, b are the red, green, and blue components (0-255) Returns the corresponding opaque ARGB color.

func ARGBFromXYZ

func ARGBFromXYZ(x, y, z float64) ARGB

ARGBFromXYZ creates an ARGB color from XYZ color space coordinates. x, y, z are the coordinates in the CIE 1931 XYZ color space Returns the corresponding ARGB color.

func NewARGB

func NewARGB(a, r, g, b uint8) ARGB

NewARGB creates an ARGB color from individual 8-bit alpha, red, green, and blue components. The components are packed into a uint32 in ARGB order.

func (ARGB) Alpha

func (c ARGB) Alpha() uint8

Alpha returns the 8-bit alpha component of the color (0-255).

func (ARGB) AnsiBg

func (c ARGB) AnsiBg(text string) string

AnsiBg wraps the given text with ANSI escape codes for this background color. text is the string to be colored Returns the string wrapped with ANSI background color codes.

func (ARGB) AnsiFg

func (c ARGB) AnsiFg(text string) string

AnsiFg wraps the given text with ANSI escape codes for this foreground color. text is the string to be colored Returns the string wrapped with ANSI foreground color codes.

func (ARGB) Blue

func (c ARGB) Blue() uint8

Blue returns the 8-bit blue component of the color (0-255).

func (ARGB) Components

func (c ARGB) Components() (alpha uint8, red uint8, green uint8, blue uint8)

Components returns the individual 8-bit components of the ARGB color. Returns alpha, red, green, blue components in order (0-255).

func (ARGB) Green

func (c ARGB) Green() uint8

Green returns the 8-bit green component of the color (0-255).

func (ARGB) HexARGB

func (c ARGB) HexARGB() string

HexARGB returns the hexadecimal representation of the color in #AARRGGBB format.

func (ARGB) HexRGB

func (c ARGB) HexRGB() string

HexRGB returns the hexadecimal representation of the color in #RRGGBB format.

func (ARGB) HexRGBA

func (c ARGB) HexRGBA() string

HexRGBA returns the hexadecimal representation of the color in #RRGGBBAA format.

func (ARGB) LStar

func (c ARGB) LStar() float64

LStar calculates the CIE L* (lightness) value of the color. Returns the L* value (0-100) representing the perceived lightness.

func (ARGB) MarshalText

func (c ARGB) MarshalText() ([]byte, error)

MarshalText implements the encoding.TextMarshaler interface. Returns the hexadecimal representation of the color (#RRGGBBAA format).

func (ARGB) RGBA

func (c ARGB) RGBA() (red uint32, green uint32, blue uint32, alpha uint32)

RGBA implements the color.Color interface. Returns the red, green, blue, and alpha values in the 0-65535 range.

func (ARGB) Red

func (c ARGB) Red() uint8

Red returns the 8-bit red component of the color (0-255).

func (ARGB) String

func (c ARGB) String() string

String returns a string representation of the color hex code. Eg. #FF00FF

func (ARGB) ToCam16

func (c ARGB) ToCam16() Cam16

ToCam16 converts the ARGB color to CAM16 color appearance model. Returns a pointer to the Cam16 representation of the color.

func (ARGB) ToHct

func (c ARGB) ToHct() Hct

ToHct converts the ARGB color to HCT (Hue-Chroma-Tone) color space. Returns the HCT representation of the color.

func (ARGB) ToLCHab

func (c ARGB) ToLCHab() LCHab

ToLCHab convets XYZ to LCHab color model

func (ARGB) ToLCHuv

func (c ARGB) ToLCHuv() LCHuv

ToLCHuv convets XYZ to LCHuv color model

func (ARGB) ToLab

func (c ARGB) ToLab() Lab

ToLab converts the ARGB color to CIE L*a*b* color space. Returns the Lab representation of the color.

func (ARGB) ToLinearRGB

func (c ARGB) ToLinearRGB() LinearRGB

ToLinearRGB converts the ARGB color to Linear RGB color space.

func (ARGB) ToLuv

func (c ARGB) ToLuv() Luv

ToLuv convets XYZ to CIELUV color model

func (ARGB) ToOkLab

func (c ARGB) ToOkLab() OkLab

ToOkLab converts the ARGB color to CIE L*a*b* color space. Returns the OkLab representation of the color.

func (ARGB) ToXYZ

func (c ARGB) ToXYZ() XYZ

ToXYZ converts the ARGB color to CIE XYZ color space. Returns the XYZ representation of the color.

func (*ARGB) UnmarshalText

func (c *ARGB) UnmarshalText(data []byte) error

UnmarshalText implements the encoding.UnmarshalText interface. Accepts #RRGGBB, #RRGGBBAA, RRGGBB, or RRGGBBAA formats for performance reasons. Returns an error if the string cannot be parsed as a valid color.

type Cam16

type Cam16 struct {
	// Hue represents the hue of the color
	Hue float64 `json:"hue"`
	// Chroma represents the colorfulness or color intensity, similar to
	// saturation in HSL but more perceptually accurate
	Chroma float64 `json:"chroma"`
	// J represents the lightness of the color
	J float64 `json:"j"`
	// Q represents the brightness, which is the ratio of lightness to
	// the white point's lightness
	Q float64 `json:"q"`
	// M represents the colorfulness of the color
	M float64 `json:"m"`
	// S represents the saturation, which is the ratio of chroma to
	// the white point's chroma
	S float64 `json:"s"`
	// Jstar represents the CAM16-UCS J coordinate
	Jstar float64 `json:"jstar"`
	// Astar represents the CAM16-UCS a coordinate
	Astar float64 `json:"astar"`
	// Bstar represents the CAM16-UCS b coordinate
	Bstar float64 `json:"bstar"`
}

Cam16 represents the CAM16 color model, which includes various dimensions for color representation. It can be constructed using any combination of three of the following dimensions: j or q, c, m, or s, and hue. It can also be constructed using the CAM16-UCS J, a, and b coordinates.

func Cam16FromJch

func Cam16FromJch(j, c, h float64) Cam16

Cam16FromJch constructs a Cam16 color from J (lightness), C (chroma), and H (hue angle in degrees), using DefaultViewingConditions viewing conditions.

This is used when synthesizing a CAM16 color from HCT values or performing color space conversions into perceptual models.

func Cam16FromJchInEnv

func Cam16FromJchInEnv(j, c, h float64, env Environment) Cam16

Cam16FromJchInEnv constructs a Cam16 color from J (lightness), C (chroma), and H (hue angle in degrees), using the given viewing conditions.

This is used when synthesizing a CAM16 color from HCT values or performing color space conversions into perceptual models.

func Cam16FromUcs

func Cam16FromUcs(jstar, astar, bstar float64) Cam16

Cam16FromUcs creates a CAM16 color from UCS coordinates (jstar, astar, bstar). Uses the default viewing environment for conversion.

func Cam16FromUcsInEnv

func Cam16FromUcsInEnv(jstar, astar, bstar float64, env Environment) Cam16

Cam16FromUcsInEnv creates a CAM16 color from UCS coordinates (jstar, astar, bstar) using the specified viewing environment for conversion.

func Cam16FromXYZInEnv

func Cam16FromXYZInEnv(xyz XYZ, env Environment) Cam16

Cam16FromXYZInEnv create a Cam16 color In specific ViewingConditions

func NewCam16

func NewCam16(hue, chroma, j, q, m, s, jstar, astar, bstar float64) Cam16

NewCam16 create a CAM16 color model from given values

func (Cam16) Distance

func (c Cam16) Distance(other Cam16) float64

Distance returns distance between to Cam16 color

func (Cam16) ToARGB

func (c Cam16) ToARGB() ARGB

ToARGB converts the CAM16 color to ARGB format. Uses the default viewing environment for conversion.

func (Cam16) ToHct

func (c Cam16) ToHct() Hct

ToHct converts the CAM16 color to HCT (Hue, Chroma, Tone) color space.

func (Cam16) ToLab

func (c Cam16) ToLab() Lab

ToLab converts the CAM16 color to CIE L*a*b* color space. Uses the default viewing environment for conversion.

func (Cam16) ToXYZ

func (c Cam16) ToXYZ() XYZ

ToXYZ converts the CAM16 color to CIE XYZ color space. Uses the default viewing environment for conversion.

func (Cam16) Viewed

func (c Cam16) Viewed(vc Environment) XYZ

Viewed converts a CAM16 color to an ARGB integer based on the given viewing conditions.

type Environment

type Environment struct {
	// N is the relative luminance of the background relative to the reference
	// white.
	N float64
	// Aw is the achromatic response to the white point.
	Aw float64
	// Nbb is the brightness induction factor (background).
	Nbb float64
	// Ncb is the chromatic induction factor (background).
	Ncb float64
	// C is the surround exponential non-linearity factor.
	C float64
	// Nc is the chromatic induction factor (surround).
	Nc float64
	// RgbD is the degree of adaptation for each RGB channel after discounting
	// the illuminant.
	RgbD num.Vector3
	// Fl is the luminance-level adaptation factor (nonlinear response).
	Fl float64
	// FlRoot is the fourth root of Fl, used in CAM16 computations.
	FlRoot float64
	// Z is a base exponential factor used in the CAM16 J calculation.
	Z float64
}

Environment encapsulates all constants needed for CAM16 color conversions. These are intermediate values derived from the viewing environment and are used throughout the CAM16 model to compute perceptual color attributes.

func NewEnvironment

func NewEnvironment(
	adaptingLuminance float64,
	backgroundLstar float64,
	surround float64,
	discountingIlluminant bool,
) Environment

NewEnvironment creates a ViewingConditions instance with the specified parameters.

type Hct

type Hct struct {
	// Hue is the color angle in degrees [0, 360], where 0° is red, 120° is
	// green, and 240° is blue. Values outside this range are normalized.
	Hue float64 `json:"hue"`
	// Chroma is the colorfulness of the color [0, ~150]. Higher values
	// represent more saturated colors. The maximum chroma varies depending on
	// hue and tone.
	Chroma float64 `json:"chroma"`
	// Tone is the lightness or luminance of the color [0, 100], where 0 is
	// black, 50 is mid-tone, and 100 is white. Invalid values are clamped to
	// this range.
	Tone float64 `json:"tone"`
}

Hct represents a color in the HCT (Hue, Chroma, Tone) color space.

HCT is a perceptually accurate color measurement system designed to render colors consistently across different lighting environments.

func NewHct

func NewHct(hue, chroma, tone float64) Hct

NewHct creates an HCT color from hue, chroma, and tone values. Hue values outside [0, 360] are normalized. Chroma and tone values outside their valid ranges are adjusted accordingly.

func (Hct) Hash

func (h Hct) Hash() [3]int64

Hash generates a uint64 hash value for the HCT color. Returns uint64 - Efficient hash value for color comparison.

func (Hct) InViewingConditions

func (h Hct) InViewingConditions(env Environment) Hct

InViewingConditions adjusts color appearance for different environments. Uses CAM16 color appearance model to account for viewing conditions. env is environment containing viewing condition parameters. Returns Hct color adjusted for specified viewing conditions.

func (Hct) IsBlue

func (h Hct) IsBlue() bool

IsBlue reports whether the color's hue falls in the blue range [250, 270].

func (Hct) IsCyan

func (h Hct) IsCyan() bool

IsCyan reports whether the color's hue falls in the cyan range [170, 207].

func (Hct) IsYellow

func (h Hct) IsYellow() bool

IsYellow reports whether the color's hue falls in the yellow range [105, 125].

func (Hct) String

func (h Hct) String() string

String returns a formatted string representation of HCT color.

func (Hct) ToARGB

func (h Hct) ToARGB() ARGB

ToARGB converts HCT color to ARGB representation. Returns ARGB - 32-bit packed color value.

func (Hct) ToCam16

func (h Hct) ToCam16() Cam16

ToCam16 converts HCT color to CAM16 color appearance model. Returns *Cam16 - Pointer to CAM16 color representation.

func (Hct) ToHct

func (h Hct) ToHct() Hct

ToHct returns the receiver (implements digitalColor interface). Returns Hct - The color itself.

func (Hct) ToLab

func (h Hct) ToLab() Lab

ToLab converts HCT color to CIE L*a*b* color space. Returns Lab - CIE L*a*b* color representation.

func (Hct) ToXYZ

func (h Hct) ToXYZ() XYZ

ToXYZ converts HCT color to CIE XYZ color space. Returns XYZ - CIE XYZ color representation.

func (Hct) Values

func (h Hct) Values() (float64, float64, float64)

Values returns Hue, Chroma and Tone

type LCHab

type LCHab struct {
	L float64 `json:"l"`
	C float64 `json:"c"`
	H float64 `json:"h"`
}

LCHab represents a color in the CIE LCHab color space, a cylindrical transformation of the CIE 1976 (L*, a*, b*) color space (CIELAB). It defines a color using lightness (L), chroma (C), and hue (H), providing a more perceptually uniform and intuitive model for color manipulation compared to the Cartesian Lab model.

func LchFromLab

func LchFromLab(c Lab) LCHab

LchFromLab converts a color from the CIELAB color space to the cylindrical LCHab representation.

func NewLCHab

func NewLCHab(l, c, h float64) LCHab

NewLCHab creates a new LCHab color from the given lightness (L), chroma (C), and hue (H) values.

func (LCHab) String

func (c LCHab) String() string

String returns a formatted string representation of LCH(ab) color.

func (LCHab) ToARGB

func (c LCHab) ToARGB() ARGB

ToARGB converts the LCHab color to the ARGB color model.

func (LCHab) ToLab

func (c LCHab) ToLab() Lab

ToLab converts the LCHab color back to the CIELAB color space.

func (LCHab) ToXYZ

func (c LCHab) ToXYZ() XYZ

ToXYZ converts the LCHab color to the CIE 1931 XYZ color space.

func (LCHab) Values

func (c LCHab) Values() (float64, float64, float64)

Values returns the individual components (L, C, H) of the LCHab color.

type LCHuv

type LCHuv struct {
	L float64 `json:"l"`
	C float64 `json:"c"`
	H float64 `json:"h"`
}

LCHuv represents a color in the CIE LCHuv color space, a cylindrical transformation of the CIE 1976 (L*, u*, v*) color space (CIELUV). It defines a color using lightness (L), chroma (C), and hue (H), which provides a more intuitive representation for color manipulation.

func LchFromLuv

func LchFromLuv(c Luv) LCHuv

LchFromLuv converts a color from the CIELUV color space to the cylindrical LCHuv representation (LuvLch).

func NewLCHuv

func NewLCHuv(l, c, h float64) LCHuv

NewLCHuv creates a new LuvLch color from the given lightness (L), chroma (C), and hue (H) values.

func (LCHuv) ToARGB

func (c LCHuv) ToARGB() ARGB

ToARGB converts the LCHuv color to the ARGB color model.

func (LCHuv) ToLuv

func (c LCHuv) ToLuv() Luv

ToLuv converts the LCHuv color (LuvLch) back to the CIELUV color space.

func (LCHuv) ToXYZ

func (c LCHuv) ToXYZ() XYZ

ToXYZ converts the LCHuv color to the CIE 1931 XYZ color space.

func (LCHuv) Values

func (c LCHuv) Values() (float64, float64, float64)

Values returns the individual components (L, C, H) of the LCHuv color.

type Lab

type Lab struct {
	L float64 `json:"l"`
	A float64 `json:"a"`
	B float64 `json:"b"`
}

Lab is the CIELAB color space, also referred to as L*a*b*, is a color space defined by the International Commission on Illumination (abbreviated CIE) in 1976. It expresses color as three values: L* for perceptual lightness and a* and b* for the four unique colors of human vision: red, green, blue and yellow. CIELAB was intended as a perceptually uniform space, where a given numerical change corresponds to a similar perceived change in color.

func NewLab

func NewLab(l, a, b float64) Lab

NewLab creates Lab (CIELAB) color model

func (Lab) DistanceSquared

func (c Lab) DistanceSquared(b Lab) float64

DistanceSquared returns square of distance between two color

func (Lab) LStar

func (c Lab) LStar() float64

LStar returns the L* value of L*a*b* (LabColor)

func (Lab) LuminanceY

func (c Lab) LuminanceY() float64

LuminanceY returns the Y value for XYZ color model from Lab color model

func (Lab) String

func (c Lab) String() string

String returns a formatted string representation of LAB color.

func (Lab) ToARGB

func (c Lab) ToARGB() ARGB

ToARGB returns Color (ARGB) from LabColor

func (Lab) ToLCHab

func (c Lab) ToLCHab() LCHab

ToLCHab returns Color ToLCHab from LabColor

func (Lab) ToXYZ

func (c Lab) ToXYZ() XYZ

ToXYZ return XYZColor from LabColor

func (Lab) Values

func (c Lab) Values() (float64, float64, float64)

Values returns L, a, b values of LABColor color

type LinearRGB

type LinearRGB struct {
	R float64 `json:"r"`
	G float64 `json:"g"`
	B float64 `json:"b"`
}

LinearRGB represents a color in the linear RGB color space.

Each component (R, G, and B) is expressed as a float64 value in the range [0, 100], where 0 corresponds to no intensity and 100 corresponds to full intensity. Unlike gamma-corrected RGB, LinearRGB stores values in a linear light space, making it suitable for accurate color calculations and conversions.

func LinearRGBFromARGB

func LinearRGBFromARGB(c ARGB) LinearRGB

LinearRGBFromARGB to converts ARGB (sRGB) to linear RGB.

func LinearRGBFromXYZ

func LinearRGBFromXYZ(c XYZ) LinearRGB

LinearRGBFromXYZ to converts ARGB (sRGB) to linear RGB.

func NewLinearRGB

func NewLinearRGB(r, g, b float64) LinearRGB

NewLinearRGB creates a linear RGB color model

func (LinearRGB) String

func (c LinearRGB) String() string

String returns a formatted string representation of linear sRGB color.

func (LinearRGB) ToARGB

func (c LinearRGB) ToARGB() ARGB

ToARGB converts LinearRGB to ARGB.

func (LinearRGB) ToXYZ

func (c LinearRGB) ToXYZ() XYZ

ToXYZ converts LinearRGB to ARGB.

func (LinearRGB) Values

func (c LinearRGB) Values() (float64, float64, float64)

Values returns R, G, B components of LinearRGB.

type Luv

type Luv struct {
	L float64 `json:"l"`
	U float64 `json:"a"`
	V float64 `json:"b"`
}

Luv is a color space adopted by the International Commission on Illumination (CIE) in 1976, as a simple-to-compute transformation of the 1931 CIE XYZ color space, which attempted perceptual uniformity. It is extensively used for applications such as computer graphics which deal with colored lights. Although additive mixtures of different colored lights will fall on a line in CIELUV's uniform chromaticity diagram (called the CIE 1976 UCS), such additive mixtures will not, contrary to popular belief, fall along a line in the CIELUV color space unless the mixtures are constant in lightness.

func LuvFromXYZ

func LuvFromXYZ(c XYZ) Luv

LuvFromXYZ converts from CIE XYZ to CIE L*u*v* color space.

func NewLuv

func NewLuv(l, u, v float64) Luv

NewLuv creates the CIELUV color model

func (Luv) String

func (c Luv) String() string

String returns a formatted string representation of LUV color.

func (Luv) ToARGB

func (c Luv) ToARGB() ARGB

ToARGB converts CIELUV to ARGB

func (Luv) ToLCHuv

func (c Luv) ToLCHuv() LCHuv

ToLCHuv converts CIELUV to LCHuv

func (Luv) ToXYZ

func (c Luv) ToXYZ() XYZ

ToXYZ converts CIELUV to CIEXYZ

func (Luv) Values

func (c Luv) Values() (float64, float64, float64)

Values returns L, U, C values

type Model

type Model interface {
	ToARGB() ARGB
	ToXYZ() XYZ
	String() string
	Values() (float64, float64, float64)
}

Model implements common methods for all colors in this package.

type OkLab

type OkLab struct {
	// L for perceptual lightness, ranging from 0 (pure black) to 100 (reference
	// white), often denoted as a percentage.
	L float64 `json:"l"`
	// A for green (negative) to red (positive) in range [-100, 100].
	A float64 `json:"a"`
	// B for blue (negative) to yellow (positive) in range [-100, 100].
	B float64 `json:"b"`
}

OkLab color space is a uniform color space for device-independent color designed to improve perceptual uniformity, hue and lightness prediction, color blending, and usability while ensuring numerical stability and ease of implementation. Introduced by Björn Ottosson in December 2020.

func NewOkLab

func NewOkLab(l, a, b float64) OkLab

NewOkLab create a OkLab model from l,a,b values

func OkLabFromXYZ

func OkLabFromXYZ(c XYZ) OkLab

OkLabFromXYZ create a OkLab model from x,y,z value of XYZ color space

func (OkLab) String

func (ok OkLab) String() string

String returns a formatted string representation of OkLab color.

func (OkLab) ToARGB

func (ok OkLab) ToARGB() ARGB

ToARGB convert OkLab model to ARGB color model.

func (OkLab) ToOkLch

func (ok OkLab) ToOkLch() OkLch

ToOkLch convert OkLab model to ToOkLch color model.

func (OkLab) ToXYZ

func (ok OkLab) ToXYZ() XYZ

ToXYZ convert OkLab model to XYZ color model.

func (OkLab) Values

func (ok OkLab) Values() (float64, float64, float64)

Values returns L, a, b values of OkLab Model

type OkLch

type OkLch struct {
	// Lightness is the perceptual lightness component, ranging from 0 (black)
	// to 100 (reference white).
	Lightness float64 `json:"lightness"`
	// Chroma is the chroma (color intensity or saturation) component, ranging
	// from 0 (neutral gray) to 100 (maximum vividness).
	Chroma float64 `json:"chroma"`
	// Hue is the hue angle in degrees, ranging from 0 to 360, where 0° = red,
	// 120° = green, and 240° = blue.
	Hue float64 `json:"hue"`
}

OkLch represents a color in the OkLCh color space, a cylindrical transformation of OkLab designed for perceptual uniformity and intuitive manipulation of lightness, chroma, and hue.

OkLCh provides a more perceptually uniform representation than RGB and improves color blending, interpolation, and prediction of hue and lightness. The model was introduced by Björn Ottosson in 2020.

func NewOkLch

func NewOkLch(l, c, h float64) OkLch

NewOkLch create a OkLch model from l,c,h values

func OkLchFromOkLab

func OkLchFromOkLab(ok OkLab) OkLch

OkLchFromOkLab create a OkLch model from a OkLab model

func (OkLch) String

func (ok OkLch) String() string

String returns a formatted string representation of OkLch color.

func (OkLch) ToARGB

func (ok OkLch) ToARGB() ARGB

ToARGB convert OkLab model to ARGB color model.

func (OkLch) ToOkLab

func (ok OkLch) ToOkLab() OkLab

ToOkLab convert OkLch model to OkLab color model.

func (OkLch) ToXYZ

func (ok OkLch) ToXYZ() XYZ

ToXYZ convert OkLab model to XYZ color model.

func (OkLch) Values

func (ok OkLch) Values() (float64, float64, float64)

Values returns L, a, b values of OkLab Model

type XYZ

type XYZ struct {
	X float64 `json:"x"`
	Y float64 `json:"y"`
	Z float64 `json:"z"`
}

The XYZ color space, developed by the International Commission on Illumination (CIE) in 1931, is a mathematical model that represents all colors visible to the human eye based on three components: X, Y, and Z. It serves as a standard reference for color measurement and is widely used in various industries for color management and communication.

func NewXYZ

func NewXYZ(x, y, z float64) XYZ

NewXYZ creates a color in XYZ model.

func (XYZ) LStar

func (c XYZ) LStar() float64

LStar returns the L* value of L*a*b* (LabColor)

func (XYZ) Luminance

func (c XYZ) Luminance() float64

Luminance returns the Y value of XYZColor

func (XYZ) RGBA

func (c XYZ) RGBA() (r, g, b, a uint32)

RGBA implements the color.Color interface. Returns r, g, b, a values in the 0-65535 range.

func (XYZ) ToARGB

func (c XYZ) ToARGB() ARGB

ToARGB converts c in XZY to ARGB color model.

func (XYZ) ToCam16

func (c XYZ) ToCam16() Cam16

ToCam16 converts XYZ to color appearance model (Cam16)

func (XYZ) ToHct

func (c XYZ) ToHct() Hct

ToHct convets XYZ to Hct (Hue, Chroma, Tone) model

func (XYZ) ToLCHab

func (c XYZ) ToLCHab() LCHab

ToLCHab convets XYZ to LCHab color model

func (XYZ) ToLCHuv

func (c XYZ) ToLCHuv() LCHuv

ToLCHuv convets XYZ to LCHuv color model

func (XYZ) ToLab

func (c XYZ) ToLab() Lab

ToLab convets XYZ to CieLab color model

func (XYZ) ToLinearRGB

func (c XYZ) ToLinearRGB() LinearRGB

ToLinearRGB converts c in XZY to LinearRGB color model.

func (XYZ) ToLuv

func (c XYZ) ToLuv() Luv

ToLuv convets XYZ to CIELUV color model

func (XYZ) ToOkLab

func (c XYZ) ToOkLab() OkLab

ToOkLab convets XYZ to OkLan color model

func (XYZ) Values

func (c XYZ) Values() (float64, float64, float64)

Values returns x, y, z values of XYZColor

Jump to

Keyboard shortcuts

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