Documentation
¶
Index ¶
- Constants
- Variables
- func Contrast(c1, c2 Color) float64
- func DeltaE76(c1, c2 Color) float64
- func DeltaE76LabD65(c1, c2 Color) float64
- func DeltaE94(c1, c2 Color) float64
- func DeltaE94LabD65(c1, c2 Color) float64
- func DeltaE2000(c1, c2 Color) float64
- func DeltaE2000LabD65(c1, c2 Color) float64
- func DeltaEOK(c1, c2 Color) float64
- func DeltaEOK2(c1, c2 Color) float64
- func InGamut(c Color) bool
- func InGamutSpace(c Color, dst space.Space) bool
- func Luminance(c Color) float64
- type Adjuster
- func (a *Adjuster) AdjustHue(amount float64) *Adjuster
- func (a *Adjuster) Chroma() float64
- func (a *Adjuster) Color() Color
- func (a *Adjuster) Darken(amount float64) *Adjuster
- func (a *Adjuster) Desaturate(amount float64) *Adjuster
- func (a *Adjuster) Grayscale() *Adjuster
- func (a *Adjuster) Hue() float64
- func (a *Adjuster) Lighten(amount float64) *Adjuster
- func (a *Adjuster) Lightness() float64
- func (a *Adjuster) Result() Color
- func (a *Adjuster) Saturate(amount float64) *Adjuster
- func (a *Adjuster) SetChroma(v float64) *Adjuster
- func (a *Adjuster) SetHue(v float64) *Adjuster
- func (a *Adjuster) SetLightness(v float64) *Adjuster
- type Color
- func A98(r, g, b float64) Color
- func A98Alpha(r, g, b, alpha float64) Color
- func Clamp(c Color) Color
- func DisplayP3(r, g, b float64) Color
- func DisplayP3Alpha(r, g, b, alpha float64) Color
- func FromStd[T color.Color](c T) Color
- func FromStdToLinear[T color.Color](c T) Color
- func Hex(s string) Color
- func Hsl(h, s, l float64) Color
- func HslAlpha(h, s, l, alpha float64) Color
- func Hsv(h, s, v float64) Color
- func HsvAlpha(h, s, v, alpha float64) Color
- func Hwb(h, w, b float64) Color
- func HwbAlpha(h, w, b, alpha float64) Color
- func LabD50(l, a, b float64) Color
- func LabD50Alpha(l, a, b, alpha float64) Color
- func LabD65(l, a, b float64) Color
- func LabD65Alpha(l, a, b, alpha float64) Color
- func LchD50(l, c, h float64) Color
- func LchD50Alpha(l, c, h, alpha float64) Color
- func LchD65(l, c, h float64) Color
- func LchD65Alpha(l, c, h, alpha float64) Color
- func LchuvD50(l, c, h float64) Color
- func LchuvD50Alpha(l, c, h, alpha float64) Color
- func LchuvD65(l, c, h float64) Color
- func LchuvD65Alpha(l, c, h, alpha float64) Color
- func LinearA98(r, g, b float64) Color
- func LinearA98Alpha(r, g, b, alpha float64) Color
- func LinearDisplayP3(r, g, b float64) Color
- func LinearDisplayP3Alpha(r, g, b, alpha float64) Color
- func LinearProPhoto(r, g, b float64) Color
- func LinearProPhotoAlpha(r, g, b, alpha float64) Color
- func LinearRec2020(r, g, b float64) Color
- func LinearRec2020Alpha(r, g, b, alpha float64) Color
- func LinearRec2100(r, g, b float64) Color
- func LinearRec2100Alpha(r, g, b, alpha float64) Color
- func LinearSrgb(r, g, b float64) Color
- func LinearSrgbAlpha(r, g, b, alpha float64) Color
- func LuvD50(l, u, v float64) Color
- func LuvD50Alpha(l, u, v, alpha float64) Color
- func LuvD65(l, u, v float64) Color
- func LuvD65Alpha(l, u, v, alpha float64) Color
- func MapToGamut(c Color, dst space.Space) Color
- func Mix(c1, c2 Color, t float64) Color
- func MixWith(c1, c2 Color, t float64, opts InterpOptions) Color
- func New(space space.Space, channels ...float64) Color
- func Oklab(l, a, b float64) Color
- func OklabAlpha(l, a, b, alpha float64) Color
- func Oklch(l, c, h float64) Color
- func OklchAlpha(l, c, h, alpha float64) Color
- func Parse(s string) (Color, error)
- func ParseBytes(b []byte) (Color, error)
- func ProPhoto(r, g, b float64) Color
- func ProPhotoAlpha(r, g, b, alpha float64) Color
- func Rec2020(r, g, b float64) Color
- func Rec2020Alpha(r, g, b, alpha float64) Color
- func Rec2020OETF(r, g, b float64) Color
- func Rec2020OETFAlpha(r, g, b, alpha float64) Color
- func Rec2100HLG(r, g, b float64) Color
- func Rec2100HLGAlpha(r, g, b, alpha float64) Color
- func Rec2100PQ(r, g, b float64) Color
- func Rec2100PQAlpha(r, g, b, alpha float64) Color
- func Rgb(r, g, b float64) Color
- func Rgba(r, g, b, a float64) Color
- func Srgb(r, g, b float64) Color
- func Srgb8(r, g, b uint8) Color
- func Srgb8ToLinear(r, g, b uint8) Color
- func Srgb16(r, g, b uint16) Color
- func Srgb16ToLinear(r, g, b uint16) Color
- func SrgbAlpha(r, g, b, alpha float64) Color
- func Srgba8(r, g, b, a uint8) Color
- func Srgba8ToLinear(r, g, b, a uint8) Color
- func Srgba16(r, g, b, a uint16) Color
- func Srgba16ToLinear(r, g, b, a uint16) Color
- func StdAlpha(c color.Alpha) Color
- func StdAlpha16(c color.Alpha16) Color
- func StdAlpha16ToLinear(c color.Alpha16) Color
- func StdAlphaToLinear(c color.Alpha) Color
- func StdCMYK(c color.CMYK) Color
- func StdCMYKToLinear(c color.CMYK) Color
- func StdGray(c color.Gray) Color
- func StdGray16(c color.Gray16) Color
- func StdGray16ToLinear(c color.Gray16) Color
- func StdGrayToLinear(c color.Gray) Color
- func StdNRGBA(c color.NRGBA) Color
- func StdNRGBA64(c color.NRGBA64) Color
- func StdNRGBA64ToLinear(c color.NRGBA64) Color
- func StdNRGBAToLinear(c color.NRGBA) Color
- func StdNYCbCrA(c color.NYCbCrA) Color
- func StdNYCbCrAToLinear(c color.NYCbCrA) Color
- func StdRGBA(c color.RGBA) Color
- func StdRGBA64(c color.RGBA64) Color
- func StdRGBA64ToLinear(c color.RGBA64) Color
- func StdRGBAToLinear(c color.RGBA) Color
- func StdYCbCr(c color.YCbCr) Color
- func StdYCbCrToLinear(c color.YCbCr) Color
- func TryHex(s string) (Color, bool)
- func TryMapToGamut(c Color, dst space.Space) (Color, bool)
- func TryNew(space space.Space, channels ...float64) (Color, bool)
- func XyYD50(x, y, luminance float64) Color
- func XyYD50Alpha(x, y, luminance, alpha float64) Color
- func XyYD65(x, y, luminance float64) Color
- func XyYD65Alpha(x, y, luminance, alpha float64) Color
- func XyzAbsD65(x, y, z float64) Color
- func XyzAbsD65Alpha(x, y, z, alpha float64) Color
- func XyzD50(x, y, z float64) Color
- func XyzD50Alpha(x, y, z, alpha float64) Color
- func XyzD65(x, y, z float64) Color
- func XyzD65Alpha(x, y, z, alpha float64) Color
- func (c Color) A98() (r, g, b float64)
- func (c Color) AdjustHue(amount float64) Color
- func (c Color) Adjuster() *Adjuster
- func (c Color) Alpha() float64
- func (c Color) Alpha8() uint8
- func (c Color) AppendChannels(dst []float64) []float64
- func (c Color) Channel(index int) (float64, bool)
- func (c Color) Channel3() (c1, c2, c3 float64)
- func (c Color) Channel4() (c1, c2, c3, c4 float64)
- func (c Color) ChannelCount() int
- func (c Color) Channels() []float64
- func (c Color) Clamp() Color
- func (c Color) Contrast(other Color) float64
- func (c Color) CoordinateSystem() space.CoordinateSystem
- func (c Color) Darken(amount float64) Color
- func (c Color) DeltaE76(other Color) float64
- func (c Color) DeltaE76LabD65(other Color) float64
- func (c Color) DeltaE94(other Color) float64
- func (c Color) DeltaE94LabD65(other Color) float64
- func (c Color) DeltaE2000(other Color) float64
- func (c Color) DeltaE2000LabD65(other Color) float64
- func (c Color) DeltaEOK(other Color) float64
- func (c Color) DeltaEOK2(other Color) float64
- func (c Color) Desaturate(amount float64) Color
- func (c Color) DisplayP3() (r, g, b float64)
- func (c Color) Dither(x, y int) Color
- func (c Color) Grayscale() Color
- func (c Color) Hex() string
- func (c Color) Hsl() (h, s, l float64)
- func (c Color) Hsv() (h, s, v float64)
- func (c Color) Hwb() (h, w, b float64)
- func (c Color) InGamut() bool
- func (c Color) InGamutSpace(dst space.Space) bool
- func (c Color) IsOpaque() bool
- func (c Color) IsValid() bool
- func (c Color) Lab() (l, a, b float64)
- func (c Color) LabD50() (l, a, b float64)
- func (c Color) LabD65() (l, a, b float64)
- func (c Color) Lch() (float64, float64, float64)
- func (c Color) LchD50() (float64, float64, float64)
- func (c Color) LchD65() (float64, float64, float64)
- func (c Color) Lchuv() (float64, float64, float64)
- func (c Color) LchuvD50() (float64, float64, float64)
- func (c Color) LchuvD65() (float64, float64, float64)
- func (c Color) Lighten(amount float64) Color
- func (c Color) LinearA98() (r, g, b float64)
- func (c Color) LinearDisplayP3() (r, g, b float64)
- func (c Color) LinearProPhoto() (r, g, b float64)
- func (c Color) LinearRec2020() (r, g, b float64)
- func (c Color) LinearRec2100() (r, g, b float64)
- func (c Color) LinearSrgb() (r, g, b float64)
- func (c Color) Luminance() float64
- func (c Color) Luv() (l, u, v float64)
- func (c Color) LuvD50() (l, u, v float64)
- func (c Color) LuvD65() (l, u, v float64)
- func (c Color) MapToGamut(dst space.Space) Color
- func (c Color) MarshalText() ([]byte, error)
- func (c Color) Mix(other Color, t float64) Color
- func (c Color) MixWith(other Color, t float64, opts InterpOptions) Color
- func (c *Color) MutTo(dst space.Space) *Color
- func (c Color) Oklab() (l, a, b float64)
- func (c Color) Oklch() (float64, float64, float64)
- func (c Color) Opaque() Color
- func (c Color) ProPhoto() (r, g, b float64)
- func (c Color) RGBA() (r, g, b, a uint32)
- func (c Color) Rec2020() (r, g, b float64)
- func (c Color) Rec2020OETF() (r, g, b float64)
- func (c Color) Rec2100HLG() (r, g, b float64)
- func (c Color) Rec2100PQ() (r, g, b float64)
- func (c Color) Rgb() (r, g, b float64)
- func (c Color) Rgba() (r, g, b, a float64)
- func (c Color) Saturate(amount float64) Color
- func (c Color) Space() space.Space
- func (c Color) Srgb() (r, g, b float64)
- func (c Color) Srgb8() (r, g, b uint8)
- func (c Color) Srgb16() (r, g, b uint16)
- func (c Color) Srgba8() (r, g, b, a uint8)
- func (c Color) Srgba16() (r, g, b, a uint16)
- func (c Color) String() string
- func (c Color) To(dst space.Space) Color
- func (c Color) ToNRGBA() color.NRGBA
- func (c Color) ToNRGBA64() color.NRGBA64
- func (c Color) ToRGBA() color.RGBA
- func (c Color) ToRGBA64() color.RGBA64
- func (c Color) TryMapToGamut(dst space.Space) (Color, bool)
- func (c *Color) TryMutTo(dst space.Space) bool
- func (c Color) TryTo(dst space.Space) (Color, bool)
- func (c *Color) UnmarshalText(text []byte) error
- func (c Color) WithAlpha(alpha float64) Color
- func (c Color) WithAlpha8(alpha uint8) Color
- func (c Color) XyY() (x, y, luminance float64)
- func (c Color) XyYD50() (x, y, luminance float64)
- func (c Color) XyYD65() (x, y, luminance float64)
- func (c Color) Xyz() (x, y, z float64)
- func (c Color) XyzAbsD65() (x, y, z float64)
- func (c Color) XyzD50() (x, y, z float64)
- func (c Color) XyzD65() (x, y, z float64)
- type Gradient
- type GradientBuilder
- func (b *GradientBuilder) AddHint(offset float64) *GradientBuilder
- func (b *GradientBuilder) AddStop(color Color, offsets ...float64) *GradientBuilder
- func (b *GradientBuilder) Build() Gradient
- func (b *GradientBuilder) BuildWithOptions(opts InterpOptions) Gradient
- func (b *GradientBuilder) Reset() *GradientBuilder
- func (b *GradientBuilder) Stops() []GradientStop
- type GradientStop
- type HueInterpolation
- type InterpOptions
- type Mixer
- type Spread
Examples ¶
Constants ¶
const ( HueShorter = interp.HueShorter HueLonger = interp.HueLonger HueIncreasing = interp.HueIncreasing HueDecreasing = interp.HueDecreasing )
Variables ¶
Functions ¶
func DeltaE76 ¶
DeltaE76 returns the CIE76 color difference between two [Color]s in space.LabD50.
func DeltaE76LabD65 ¶
DeltaE76LabD65 returns the CIE76 color difference between two [Color]s in space.LabD65.
func DeltaE94 ¶
DeltaE94 returns the CIE94 color difference between two [Color]s in space.LabD50.
func DeltaE94LabD65 ¶
DeltaE94LabD65 returns the CIE94 color difference between two [Color]s in space.LabD65.
func DeltaE2000 ¶
DeltaE2000 returns the CIEDE2000 color difference between two [Color]s in space.LabD50.
func DeltaE2000LabD65 ¶
DeltaE2000LabD65 returns the CIEDE2000 color difference between two [Color]s in space.LabD65.
func DeltaEOK ¶
DeltaEOK returns the Euclidean distance between two [Color]s in the space.Oklab color space.
func DeltaEOK2 ¶
DeltaEOK2 returns the Euclidean distance between two [Color]s in the space.Oklab color space, with the a and b components scaled by 2.
func InGamutSpace ¶
InGamutSpace reports whether c is within the gamut of the specified color space.
Types ¶
type Adjuster ¶
type Adjuster struct {
// contains filtered or unexported fields
}
Adjuster provides chained adjustments for a color in space.Oklch.
func NewAdjuster ¶
NewAdjuster returns an Adjuster initialized with the specified color. The color is converted to space.Oklch for adjustment.
func (*Adjuster) AdjustHue ¶
AdjustHue adjusts the hue in space.Oklch by amount.
func (*Adjuster) Chroma ¶
Chroma returns the current chroma in space.Oklch.
func (*Adjuster) Color ¶
Color returns the current color in space.Oklch.
func (*Adjuster) Darken ¶
Darken decreases the lightness in space.Oklch by amount.
func (*Adjuster) Desaturate ¶
Desaturate decreases the chroma in space.Oklch by amount.
func (*Adjuster) Grayscale ¶
Grayscale sets the chroma in space.Oklch to 0.
func (*Adjuster) Hue ¶
Hue returns the current hue in space.Oklch in degrees.
func (*Adjuster) Lighten ¶
Lighten increases the lightness in space.Oklch by amount.
func (*Adjuster) Lightness ¶
Lightness returns the current lightness in space.Oklch.
func (*Adjuster) Saturate ¶
Saturate increases the chroma in space.Oklch by amount.
func (*Adjuster) SetChroma ¶
SetChroma sets the chroma in space.Oklch to v. Negative values are clamped to 0.
func (*Adjuster) SetHue ¶
SetHue sets the hue in space.Oklch to v degrees. The value is normalized to [0, 360).
func (*Adjuster) SetLightness ¶
SetLightness sets the lightness in space.Oklch to v. The value is clamped to [0, 1].
type Color ¶
type Color struct {
// contains filtered or unexported fields
}
Color represents a color in a space.Space.
func A98Alpha ¶
A98Alpha returns a Color from Adobe RGB (1998) components with alpha.
r: [0, 1] g: [0, 1] b: [0, 1] alpha: [0, 1]
func DisplayP3 ¶
DisplayP3 returns a Color from Display P3 components.
r: [0, 1] g: [0, 1] b: [0, 1]
func DisplayP3Alpha ¶
DisplayP3Alpha returns a Color from Display P3 components with alpha.
r: [0, 1] g: [0, 1] b: [0, 1] alpha: [0, 1]
func FromStd ¶
FromStd converts a color.Color to a Color in space.Srgb. A nil input returns an invalid Color.
func FromStdToLinear ¶
FromStdToLinear converts a color.Color to a Color in space.LinearSrgb. A nil input returns an invalid Color.
func HslAlpha ¶
HslAlpha returns a Color from HSL components with alpha.
h: [0, 360) s: [0, 1] l: [0, 1] alpha: [0, 1]
func HsvAlpha ¶
HsvAlpha returns a Color from HSV components with alpha.
h: [0, 360) s: [0, 1] v: [0, 1] alpha: [0, 1]
func HwbAlpha ¶
HwbAlpha returns a Color from HWB components with alpha.
h: [0, 360) w: [0, 1] b: [0, 1] alpha: [0, 1]
func LabD50 ¶
LabD50 returns a Color from CIE Lab D50 components.
l: [0, 100] a: [-125, 125] (typical) b: [-125, 125] (typical)
func LabD50Alpha ¶
LabD50Alpha returns a Color from CIE Lab D50 components with alpha.
l: [0, 100] a: [-125, 125] (typical) b: [-125, 125] (typical) alpha: [0, 1]
func LabD65 ¶
LabD65 returns a Color from CIE Lab D65 components.
l: [0, 100] a: [-125, 125] (typical) b: [-125, 125] (typical)
func LabD65Alpha ¶
LabD65Alpha returns a Color from CIE Lab D65 components with alpha.
l: [0, 100] a: [-125, 125] (typical) b: [-125, 125] (typical) alpha: [0, 1]
func LchD50 ¶
LchD50 returns a Color from CIE LCh D50 components.
l: [0, 100] c: [0, 150] (typical) h: [0, 360)
func LchD50Alpha ¶
LchD50Alpha returns a Color from CIE LCh D50 components with alpha.
l: [0, 100] c: [0, 150] (typical) h: [0, 360) alpha: [0, 1]
func LchD65 ¶
LchD65 returns a Color from CIE LCh D65 components.
l: [0, 100] c: [0, 150] (typical) h: [0, 360)
func LchD65Alpha ¶
LchD65Alpha returns a Color from CIE LCh D65 components with alpha.
l: [0, 100] c: [0, 150] (typical) h: [0, 360) alpha: [0, 1]
func LchuvD50 ¶
LchuvD50 returns a Color from CIE LChuv D50 components.
l: [0, 100] c: [0, 180] (typical) h: [0, 360)
func LchuvD50Alpha ¶
LchuvD50Alpha returns a Color from CIE LChuv D50 components with alpha.
l: [0, 100] c: [0, 180] (typical) h: [0, 360) alpha: [0, 1]
func LchuvD65 ¶
LchuvD65 returns a Color from CIE LChuv D65 components.
l: [0, 100] c: [0, 180] (typical) h: [0, 360)
func LchuvD65Alpha ¶
LchuvD65Alpha returns a Color from CIE LChuv D65 components with alpha.
l: [0, 100] c: [0, 180] (typical) h: [0, 360) alpha: [0, 1]
func LinearA98 ¶
LinearA98 returns a Color from Linear Adobe RGB (1998) components.
r: [0, 1] g: [0, 1] b: [0, 1]
func LinearA98Alpha ¶
LinearA98Alpha returns a Color from Linear Adobe RGB (1998) components with alpha.
r: [0, 1] g: [0, 1] b: [0, 1] alpha: [0, 1]
func LinearDisplayP3 ¶
LinearDisplayP3 returns a Color from Linear Display P3 components.
r: [0, 1] g: [0, 1] b: [0, 1]
func LinearDisplayP3Alpha ¶
LinearDisplayP3Alpha returns a Color from Linear Display P3 components with alpha.
r: [0, 1] g: [0, 1] b: [0, 1] alpha: [0, 1]
func LinearProPhoto ¶
LinearProPhoto returns a Color from Linear ProPhoto components.
r: [0, 1] g: [0, 1] b: [0, 1]
func LinearProPhotoAlpha ¶
LinearProPhotoAlpha returns a Color from Linear ProPhoto components with alpha.
r: [0, 1] g: [0, 1] b: [0, 1] alpha: [0, 1]
func LinearRec2020 ¶
LinearRec2020 returns a Color from Linear Rec. 2020 components.
r: [0, 1] g: [0, 1] b: [0, 1]
func LinearRec2020Alpha ¶
LinearRec2020Alpha returns a Color from Linear Rec. 2020 components with alpha.
r: [0, 1] g: [0, 1] b: [0, 1] alpha: [0, 1]
func LinearRec2100 ¶
LinearRec2100 returns a Color from Linear Rec. 2100 components.
r: [0, 1] g: [0, 1] b: [0, 1]
func LinearRec2100Alpha ¶
LinearRec2100Alpha returns a Color from Linear Rec. 2100 components with alpha.
r: [0, 1] g: [0, 1] b: [0, 1] alpha: [0, 1]
func LinearSrgb ¶
LinearSrgb returns a Color from Linear sRGB components.
r: [0, 1] g: [0, 1] b: [0, 1]
func LinearSrgbAlpha ¶
LinearSrgbAlpha returns a Color from Linear sRGB components with alpha.
r: [0, 1] g: [0, 1] b: [0, 1] alpha: [0, 1]
func LuvD50 ¶
LuvD50 returns a Color from CIE Luv D50 components.
l: [0, 100] u: [-134, 220] (typical) v: [-140, 122] (typical)
func LuvD50Alpha ¶
LuvD50Alpha returns a Color from CIE Luv D50 components with alpha.
l: [0, 100] u: [-134, 220] (typical) v: [-140, 122] (typical) alpha: [0, 1]
func LuvD65 ¶
LuvD65 returns a Color from CIE Luv D65 components.
l: [0, 100] u: [-134, 220] (typical) v: [-140, 122] (typical)
func LuvD65Alpha ¶
LuvD65Alpha returns a Color from CIE Luv D65 components with alpha.
l: [0, 100] u: [-134, 220] (typical) v: [-140, 122] (typical) alpha: [0, 1]
func MapToGamut ¶
MapToGamut maps the color to the gamut of the specified color space. It returns the original color if mapping fails.
func Mix ¶
Mix interpolates between two colors using the default mix options. See NewMixer for the default mix options.
func MixWith ¶
func MixWith(c1, c2 Color, t float64, opts InterpOptions) Color
MixWith interpolates between two colors using the specified interpolation options. The interpolation is performed in opts.Space. An invalid space defaults to space.Oklab.
func New ¶
New creates a Color from a color space and its channel values. The number of values must match the color space's channel count, optionally followed by an alpha value. Alpha defaults to 1.
It returns an invalid Color if the color space or number of values is invalid.
func Oklab ¶
Oklab returns a Color from Oklab components.
l: [0, 1] a: [-0.4, 0.4] (typical) b: [-0.4, 0.4] (typical)
func OklabAlpha ¶
OklabAlpha returns a Color from Oklab components with alpha.
l: [0, 1] a: [-0.4, 0.4] (typical) b: [-0.4, 0.4] (typical) alpha: [0, 1]
func Oklch ¶
Oklch returns a Color from Oklch components.
l: [0, 1] c: [0, 0.4] (typical) h: [0, 360)
func OklchAlpha ¶
OklchAlpha returns a Color from Oklch components with alpha.
l: [0, 1] c: [0, 0.4] (typical) h: [0, 360) alpha: [0, 1]
func ParseBytes ¶
ParseBytes parses a CSS color value from b.
func ProPhotoAlpha ¶
ProPhotoAlpha returns a Color from ProPhoto components with alpha.
r: [0, 1] g: [0, 1] b: [0, 1] alpha: [0, 1]
func Rec2020Alpha ¶
Rec2020Alpha returns a Color from Rec. 2020 components with alpha.
r: [0, 1] g: [0, 1] b: [0, 1] alpha: [0, 1]
func Rec2020OETF ¶
Rec2020OETF returns a Color from Rec. 2020 Scene Referred components.
r: [0, 1] g: [0, 1] b: [0, 1]
func Rec2020OETFAlpha ¶
Rec2020OETFAlpha returns a Color from Rec. 2020 Scene Referred components with alpha.
r: [0, 1] g: [0, 1] b: [0, 1] alpha: [0, 1]
func Rec2100HLG ¶
Rec2100HLG returns a Color from Rec. 2100 HLG components.
r: [0, 1] g: [0, 1] b: [0, 1]
func Rec2100HLGAlpha ¶
Rec2100HLGAlpha returns a Color from Rec. 2100 HLG components with alpha.
r: [0, 1] g: [0, 1] b: [0, 1] alpha: [0, 1]
func Rec2100PQ ¶
Rec2100PQ returns a Color from Rec. 2100 PQ components.
r: [0, 1] g: [0, 1] b: [0, 1]
func Rec2100PQAlpha ¶
Rec2100PQAlpha returns a Color from Rec. 2100 PQ components with alpha.
r: [0, 1] g: [0, 1] b: [0, 1] alpha: [0, 1]
func Srgb8ToLinear ¶
Srgb8ToLinear returns a Color in linear sRGB from 8-bit sRGB components.
It provides fast sRGB-to-linear conversion.
func Srgb16ToLinear ¶
Srgb16ToLinear returns a Color in linear sRGB from 16-bit sRGB components.
It provides fast sRGB-to-linear conversion.
func SrgbAlpha ¶
SrgbAlpha returns a Color from sRGB components with alpha.
r: [0, 1] g: [0, 1] b: [0, 1] alpha: [0, 1]
func Srgba8ToLinear ¶
Srgba8ToLinear returns a Color in linear sRGB from 8-bit sRGB components and alpha.
It provides fast sRGB-to-linear conversion.
func Srgba16ToLinear ¶
Srgba16ToLinear returns a Color in linear sRGB from 16-bit sRGB components and alpha.
It provides fast sRGB-to-linear conversion.
func StdAlpha ¶
StdAlpha returns a sRGB Color from a color.Alpha.
func StdAlpha16 ¶
StdAlpha16 returns a sRGB Color from a color.Alpha16.
func StdAlpha16ToLinear ¶
StdAlpha16ToLinear returns a linear sRGB Color from a color.Alpha16.
func StdAlphaToLinear ¶
StdAlphaToLinear returns a linear sRGB Color from a color.Alpha.
func StdCMYKToLinear ¶
StdCMYKToLinear returns a linear sRGB Color from a color.CMYK.
func StdGray16 ¶
StdGray16 returns a sRGB Color from a color.Gray16.
func StdGray16ToLinear ¶
StdGray16ToLinear returns a linear sRGB Color from a color.Gray16.
func StdGrayToLinear ¶
StdGrayToLinear returns a linear sRGB Color from a color.Gray.
func StdNRGBA ¶
StdNRGBA returns a sRGB Color from a color.NRGBA.
func StdNRGBA64 ¶
StdNRGBA64 returns a sRGB Color from a color.NRGBA64.
func StdNRGBA64ToLinear ¶
StdNRGBA64ToLinear returns a linear sRGB Color from a color.NRGBA64.
func StdNRGBAToLinear ¶
StdNRGBAToLinear returns a linear sRGB Color from a color.NRGBA.
func StdNYCbCrA ¶
StdNYCbCrA returns a sRGB Color from a color.NYCbCrA.
func StdNYCbCrAToLinear ¶
StdNYCbCrAToLinear returns a linear sRGB Color from a color.NYCbCrA.
func StdRGBA64 ¶
StdRGBA64 returns a sRGB Color from a color.RGBA64.
func StdRGBA64ToLinear ¶
StdRGBA64ToLinear returns a linear sRGB Color from a color.RGBA64.
func StdRGBAToLinear ¶
StdRGBAToLinear returns a linear sRGB Color from a color.RGBA.
func StdYCbCr ¶
StdYCbCr returns a sRGB Color from a color.YCbCr.
func StdYCbCrToLinear ¶
StdYCbCrToLinear returns a linear sRGB Color from a color.YCbCr.
func TryHex ¶
TryHex returns an sRGB color from a hexadecimal color string and reports whether the string was successfully parsed.
func TryMapToGamut ¶
TryMapToGamut maps the color to the gamut of the specified color space and reports whether the mapping succeeded.
func TryNew ¶
TryNew creates a Color from a color space and its channel values. The number of values must match the color space's channel count, optionally followed by an alpha value. Alpha defaults to 1.
It returns an invalid Color and [false] if the color space or number of values is invalid.
func XyYD50 ¶
XyYD50 returns a Color from CIE xyY components.
x: [0, 1] y: [0, 1] luminance: [0, 1] (typical)
func XyYD50Alpha ¶
XyYD50Alpha returns a Color from CIE xyY components with alpha.
x: [0, 1] y: [0, 1] luminance: [0, 1] (typical) alpha: [0, 1]
func XyYD65 ¶
XyYD65 returns a Color from CIE xyY components.
x: [0, 1] y: [0, 1] luminance: [0, 1] (typical)
func XyYD65Alpha ¶
XyYD65Alpha returns a Color from CIE xyY components with alpha.
x: [0, 1] y: [0, 1] luminance: [0, 1] (typical) alpha: [0, 1]
func XyzAbsD65 ¶
XyzAbsD65 returns a Color from Absolute XYZ D65 components.
x: [0, 193] (typical) y: [0, 203] (typical) z: [0, 221] (typical)
func XyzAbsD65Alpha ¶
XyzAbsD65Alpha returns a Color from Absolute XYZ D65 components with alpha.
x: [0, 193] (typical) y: [0, 203] (typical) z: [0, 221] (typical) alpha: [0, 1]
func XyzD50 ¶
XyzD50 returns a Color from CIE XYZ D50 components.
x: [0, 0.9642956764295677] (typical) y: [0, 1] (typical) z: [0, 0.8251046025104602] (typical)
func XyzD50Alpha ¶
XyzD50Alpha returns a Color from CIE XYZ D50 components with alpha.
x: [0, 0.9642956764295677] (typical) y: [0, 1] (typical) z: [0, 0.8251046025104602] (typical) alpha: [0, 1]
func XyzD65 ¶
XyzD65 returns a Color from CIE XYZ D65 components.
x: [0, 0.9504559270516716] (typical) y: [0, 1] (typical) z: [0, 1.0890577507598784] (typical)
func XyzD65Alpha ¶
XyzD65Alpha returns a Color from CIE XYZ D65 components with alpha.
x: [0, 0.9504559270516716] (typical) y: [0, 1] (typical) z: [0, 1.0890577507598784] (typical) alpha: [0, 1]
func (Color) AdjustHue ¶
AdjustHue returns a copy of the color with its hue in space.Oklch adjusted by amount.
The resulting hue is normalized to [0, 360).
func (Color) AppendChannels ¶
AppendChannels appends the color channels to dst and returns the resulting slice.
func (Color) Channel ¶
Channel returns the channel value at index in the order defined by the color's space.Space. The returned boolean reports whether index is valid.
func (Color) ChannelCount ¶
ChannelCount returns the number of color channels.
func (Color) Channels ¶
Channels returns the channel values of c in the order defined by its space.Space.
func (Color) Contrast ¶
Contrast returns the WCAG 2 contrast ratio between the color and another color.
func (Color) CoordinateSystem ¶
func (c Color) CoordinateSystem() space.CoordinateSystem
CoordinateSystem returns the coordinate system of the color space.
func (Color) Darken ¶
Darken returns a copy of the color with its lightness in space.Oklch decreased by amount.
The resulting lightness is clamped to [0, 1].
func (Color) DeltaE76 ¶
DeltaE76 returns the CIE76 color difference between two [Color]s in space.LabD50.
func (Color) DeltaE76LabD65 ¶
DeltaE76LabD65 returns the CIE76 color difference between two [Color]s in space.LabD65.
func (Color) DeltaE94 ¶
DeltaE94 returns the CIE94 color difference between two [Color]s in space.LabD50.
func (Color) DeltaE94LabD65 ¶
DeltaE94LabD65 returns the CIE94 color difference between two [Color]s in space.LabD65.
func (Color) DeltaE2000 ¶
DeltaE2000 returns the CIEDE2000 color difference between two [Color]s in space.LabD50.
func (Color) DeltaE2000LabD65 ¶
DeltaE2000LabD65 returns the CIEDE2000 color difference between two [Color]s in space.LabD65.
func (Color) DeltaEOK ¶
DeltaEOK returns the Euclidean distance between two [Color]s in the space.Oklab color space.
func (Color) DeltaEOK2 ¶
DeltaEOK2 returns the Euclidean distance between two [Color]s in the space.Oklab color space, with the a and b components scaled by 2.
func (Color) Desaturate ¶
Desaturate returns a copy of the color with its chroma in space.Oklch decreased by amount.
The resulting chroma is clamped to [0, +Inf).
func (Color) DisplayP3 ¶
DisplayP3 returns the color components in the space.DisplayP3 color space.
func (Color) Dither ¶
Dither applies ordered dithering to the sRGB color channels at pixel position (x, y). The dithering offset is scaled to the normalized sRGB [0, 1] range; the alpha channel is left unchanged. The returned color is always in space.Srgb.
func (Color) Grayscale ¶
Grayscale returns a copy of the color with its chroma in space.Oklch set to 0.
func (Color) InGamutSpace ¶
InGamutSpace reports whether the color is within the gamut of the specified color space.
func (Color) LabD50 ¶
LabD50 returns the color components in the space.LabD50 color space.
func (Color) LabD65 ¶
LabD65 returns the color components in the space.LabD65 color space.
func (Color) Lch ¶
Lch is an alias for Color.LchD50.
func (Color) LchD50 ¶
LchD50 returns the color components in the space.LchD50 color space.
func (Color) LchD65 ¶
LchD65 returns the color components in the space.LchD65 color space.
func (Color) Lchuv ¶
Lchuv is an alias for Color.LchuvD50.
func (Color) LchuvD50 ¶
LchuvD50 returns the color components in the space.LchuvD50 color space.
func (Color) LchuvD65 ¶
LchuvD65 returns the color components in the space.LchuvD65 color space.
func (Color) Lighten ¶
Lighten returns a copy of the color with its lightness in space.Oklch increased by amount.
The resulting lightness is clamped to [0, 1].
func (Color) LinearA98 ¶
LinearA98 returns the color components in the space.LinearA98 color space.
func (Color) LinearDisplayP3 ¶
LinearDisplayP3 returns the color components in the space.LinearDisplayP3 color space.
func (Color) LinearProPhoto ¶
LinearProPhoto returns the color components in the space.LinearProPhoto color space.
func (Color) LinearRec2020 ¶
LinearRec2020 returns the color components in the space.LinearRec2020 color space.
func (Color) LinearRec2100 ¶
LinearRec2100 returns the color components in the space.LinearRec2100 color space.
func (Color) LinearSrgb ¶
LinearSrgb returns the color components in the space.LinearSrgb color space.
func (Color) LuvD50 ¶
LuvD50 returns the color components in the space.LuvD50 color space.
func (Color) LuvD65 ¶
LuvD65 returns the color components in the space.LuvD65 color space.
func (Color) MapToGamut ¶
MapToGamut maps the color to the gamut of the specified color space. It returns the original color if mapping fails.
func (Color) MarshalText ¶
MarshalText encodes the color as a hexadecimal text representation.
func (Color) MixWith ¶
func (c Color) MixWith(other Color, t float64, opts InterpOptions) Color
MixWith is shorthand for MixWith(c, other, t, opts).
func (*Color) MutTo ¶
MutTo converts the color to the specified color space in place and returns the receiver.
func (Color) Oklab ¶
Oklab returns the color components in the space.Oklab color space.
func (Color) Oklch ¶
Oklch returns the color components in the space.Oklch color space.
func (Color) ProPhoto ¶
ProPhoto returns the color components in the space.ProPhoto color space.
func (Color) RGBA ¶
RGBA implements the color.Color interface
func (Color) Rec2020 ¶
Rec2020 returns the color components in the space.Rec2020 color space.
func (Color) Rec2020OETF ¶
Rec2020OETF returns the color components in the space.Rec2020OETF color space.
func (Color) Rec2100HLG ¶
Rec2100HLG returns the color components in the space.Rec2100HLG color space.
func (Color) Rec2100PQ ¶
Rec2100PQ returns the color components in the space.Rec2100PQ color space.
func (Color) Saturate ¶
Saturate returns a copy of the color with its chroma in space.Oklch increased by amount.
The resulting chroma is clamped to [0, +Inf).
func (Color) Space ¶
Space returns the color space of the color.
Example ¶
package main
import (
"fmt"
"github.com/thmalt/colors"
)
func main() {
c := colors.Rgba(50, 60, 70, 0.995)
// color space info
inf := c.Space().Info()
if inf == nil {
fmt.Println("invalid color space: ", c.Space())
return
}
fmt.Println("Space display name:", inf.DisplayName())
}
Output: Space display name: sRGB
func (Color) Srgb ¶
Srgb returns the color components in the space.Srgb color space.
func (Color) Srgb8 ¶
Srgb8 returns the sRGB components of the Color as 8-bit values in the range [0, 255].
func (Color) Srgb16 ¶
Srgb16 returns the sRGB components of the Color as 16-bit values in the range [0, 65535].
func (Color) Srgba8 ¶
Srgba8 returns the sRGB components and alpha of the Color as 8-bit values in the range [0, 255].
func (Color) Srgba16 ¶
Srgba16 returns the sRGB components and alpha of the Color as 16-bit values in the range [0, 65535].
func (Color) To ¶
To converts the color to the destination color space.
Example ¶
package main
import (
"fmt"
"github.com/thmalt/colors"
"github.com/thmalt/colors/space"
)
func main() {
c := colors.Rgba(50, 60, 70, 0.995)
c1 := c.To(space.XyzD65)
if !c1.IsValid() {
return
}
fmt.Println(c1.Space())
c2 := c.To(space.Oklab)
if !c2.IsValid() {
return
}
fmt.Println(c2.Space())
}
Output: XyzD65 Oklab
func (Color) ToNRGBA ¶
ToNRGBA converts the color to an sRGB color.NRGBA.
func (Color) ToNRGBA64 ¶
ToNRGBA64 converts the color to an sRGB color.NRGBA64.
func (Color) ToRGBA ¶
ToRGBA converts the color to an sRGB color.RGBA.
func (Color) ToRGBA64 ¶
ToRGBA64 converts the color to an sRGB color.RGBA64.
func (Color) TryMapToGamut ¶
TryMapToGamut maps the color to the gamut of the specified color space and reports whether the mapping succeeded.
func (*Color) TryMutTo ¶
TryMutTo converts the color to the specified color space in place and reports whether the conversion succeeded.
func (Color) TryTo ¶
TryTo converts the color to destination color space and reports whether the conversion succeeded.
func (*Color) UnmarshalText ¶
UnmarshalText decodes a color from its CSS text representation.
func (Color) WithAlpha ¶
WithAlpha returns a copy of Color with the specified alpha value. Alpha values in the range [0, 1] are typical.
func (Color) WithAlpha8 ¶
WithAlpha8 returns a copy of Color with the specified 8-bit alpha value in the range [0, 255].
func (Color) XyYD50 ¶
XyYD50 returns the color components in the space.XyYD50 color space.
func (Color) XyYD65 ¶
XyYD65 returns the color components in the space.XyYD65 color space.
func (Color) XyzAbsD65 ¶
XyzAbsD65 returns the color components in the space.XyzAbsD65 color space.
func (Color) XyzD50 ¶
XyzD50 returns the color components in the space.XyzD50 color space.
func (Color) XyzD65 ¶
XyzD65 returns the color components in the space.XyzD65 color space.
type Gradient ¶
type Gradient struct {
// contains filtered or unexported fields
}
Gradient stores a mixer and color stops for color interpolation. An empty gradient, including the zero value, returns an invalid zero Color when sampled. A single color stop produces a constant gradient in the interpolation space.
func NewGradient ¶
func NewGradient(stops ...GradientStop) Gradient
NewGradient returns a new Gradient using DefaultInterpOptions.
func NewGradientWithOptions ¶
func NewGradientWithOptions(opts InterpOptions, stops ...GradientStop) Gradient
NewGradientWithOptions creates a gradient with the specified interpolation options and color stops.
func (Gradient) AtReflect ¶
AtReflect returns the interpolated color at position t using reflect spreading.
func (Gradient) AtRepeat ¶
AtRepeat returns the interpolated color at position t using repeat spreading.
func (Gradient) AtSpread ¶
AtSpread returns the interpolated color at position t using the specified spread method.
func (Gradient) Stops ¶
func (g Gradient) Stops() []GradientStop
Stops returns a copy of the gradient's color stops.
type GradientBuilder ¶
type GradientBuilder struct {
// contains filtered or unexported fields
}
GradientBuilder builds a gradient from a sequence of color stops and hints.
func NewGradientBuilder ¶
func NewGradientBuilder() *GradientBuilder
NewGradientBuilder returns a new GradientBuilder.
func (*GradientBuilder) AddHint ¶
func (b *GradientBuilder) AddHint(offset float64) *GradientBuilder
AddHint adds a color interpolation hint at the given offset.
func (*GradientBuilder) AddStop ¶
func (b *GradientBuilder) AddStop(color Color, offsets ...float64) *GradientBuilder
AddStop adds a color stop to the builder.
If no offsets are provided, the stop has no explicit position. If multiple offsets are provided, a stop is added at each offset.
func (*GradientBuilder) Build ¶
func (b *GradientBuilder) Build() Gradient
Build builds a Gradient using the builder's stops and default interpolation options.
func (*GradientBuilder) BuildWithOptions ¶
func (b *GradientBuilder) BuildWithOptions(opts InterpOptions) Gradient
BuildWithOptions builds a Gradient using the builder's stops and the given interpolation options.
func (*GradientBuilder) Reset ¶
func (b *GradientBuilder) Reset() *GradientBuilder
Reset removes all gradient stops and retains the allocated storage for reuse.
func (*GradientBuilder) Stops ¶
func (b *GradientBuilder) Stops() []GradientStop
Stops returns the gradient stops currently added to the builder
type GradientStop ¶
GradientStop represents a color and its position within a gradient.
func NewHint ¶
func NewHint(offset float64) GradientStop
func NewStop ¶
func NewStop(color Color) GradientStop
func NewStopAt ¶
func NewStopAt(color Color, offset float64) GradientStop
func NewStopsAt ¶
func NewStopsAt(color Color, offsets ...float64) []GradientStop
func (GradientStop) HasOffset ¶
func (s GradientStop) HasOffset() bool
HasOffset reports whether the stop has an explicit offset.
func (GradientStop) IsHint ¶
func (s GradientStop) IsHint() bool
IsHint reports whether the stop is an interpolation hint.
type HueInterpolation ¶
type HueInterpolation = interp.HueInterpolation
type InterpOptions ¶
type InterpOptions struct {
// Space specifies the color space used for interpolation.
Space space.Space
// Premultiplied specifies whether alpha-premultiplied interpolation is used.
Premultiplied bool
Hue HueInterpolation
}
func DefaultInterpOptions ¶
func DefaultInterpOptions() InterpOptions
DefaultInterpOptions returns a Mixer configured with the default options. The defaults are:
- Space: space.Oklab
- Premultiplied: [true]
- Hue: interp.HueShorter
type Mixer ¶
type Mixer struct {
// contains filtered or unexported fields
}
func NewMixerWithOptions ¶
func NewMixerWithOptions(opts InterpOptions) Mixer
NewMixerWithOptions creates a Mixer that interpolates colors in opts.Space. An invalid space defaults to space.Oklab.
Source Files
¶
- color.go
- color_adjust.go
- color_constructors_gen.go
- color_contrast.go
- color_convert_gen.go
- color_encoding.go
- color_gen.go
- color_hex.go
- color_methods.go
- color_mutable.go
- color_mutable_gen.go
- color_srgb.go
- color_std.go
- color_std_linear.go
- color_string_gen.go
- constants.go
- difference.go
- errors.go
- float.go
- gamut.go
- gamut_gen.go
- gradient.go
- gradient_builder.go
- gradient_resolve.go
- gradient_stop.go
- interp.go
- mixer.go
- mixer_gen.go
- named_gen.go
- parser.go
- parser_gen.go
- parser_math.go
- parser_types.go
Directories
¶
| Path | Synopsis |
|---|---|
|
examples
|
|
|
conversion
command
|
|
|
gradient
command
|
|
|
codegen/internal/convert
primitives functions
|
primitives functions |
|
internal
|
|