Documentation
¶
Overview ¶
Package colorful implements functions for working with colors.
colorful is adapted from github.com/lucasb-eyer/go-colorful. colorful has been adapted to favor brevity (e.g. certain functions panic instead of returning errors) and is probably not suited for general usage.
Index ¶
- Constants
- Variables
- func HPLuvToLuvLCh(h, s, l float64) (float64, float64, float64)
- func HSLuvToLuvLCh(h, s, l float64) (float64, float64, float64)
- func LABLCHToLAB(h, c, l float64) (L, a, b float64)
- func LABToLABLCH(L, a, b float64) (h, c, l float64)
- func LABToXYZ(l, a, b float64) (x, y, z float64)
- func LABToXYZWhiteRef(l, a, b float64, wref [3]float64) (x, y, z float64)
- func LinearRGBToXYZ(r, g, b float64) (x, y, z float64)
- func LuvLChToHPLuv(l, c, h float64) (float64, float64, float64)
- func LuvLChToHSLuv(l, c, h float64) (float64, float64, float64)
- func LuvLChToLuv(l, c, h float64) (L, u, v float64)
- func LuvToLuvLCh(L, u, v float64) (l, c, h float64)
- func LuvToXYZ(l, u, v float64) (x, y, z float64)
- func LuvToXYZWhiteRef(l, u, v float64, wref [3]float64) (x, y, z float64)
- func XYYToXYZ(x, y, Y float64) (X, Yout, Z float64)
- func XYZToLAB(x, y, z float64) (l, a, b float64)
- func XYZToLABWhiteRef(x, y, z float64, wref [3]float64) (l, a, b float64)
- func XYZToLinearRGB(x, y, z float64) (r, g, b float64)
- func XYZToLuv(x, y, z float64) (l, a, b float64)
- func XYZToLuvWhiteRef(x, y, z float64, wref [3]float64) (l, u, v float64)
- func XYZToXYY(X, Y, Z float64) (x, y, Yout float64)
- func XYZToXYYWhiteRef(X, Y, Z float64, wref [3]float64) (x, y, Yout float64)
- type Color
- func BlendHSV(c1, c2 Color, t float64) Color
- func BlendLAB(c1, c2 Color, t float64) Color
- func BlendLABLCH(col1, col2 Color, t float64) Color
- func BlendLUV(c1, c2 Color, t float64) Color
- func BlendLUVLCh(col1, col2 Color, t float64) Color
- func BlendLinearRGB(c1, c2 Color, t float64) Color
- func BlendOklab(c1, c2 Color, t float64) Color
- func BlendRGB(c1, c2 Color, t float64) Color
- func FastLinearRGB(r, g, b float64) Color
- func FromColor(col color.Color) Color
- func HPLuv(h, s, l float64) Color
- func HSL(h, s, l float64) Color
- func HSLuv(h, s, l float64) Color
- func HSV(H, S, V float64) Color
- func Hex(s string) Color
- func LAB(l, a, b float64) Color
- func LABLCH(h, c, l float64) Color
- func LABLCHWhiteRef(h, c, l float64, wref [3]float64) Color
- func LABWhiteRef(l, a, b float64, wref [3]float64) Color
- func LinearRGB(r, g, b float64) Color
- func Luv(l, u, v float64) Color
- func LuvLCh(l, c, h float64) Color
- func LuvLChWhiteRef(l, c, h float64, wref [3]float64) Color
- func LuvWhiteRef(l, u, v float64, wref [3]float64) Color
- func MustParseHex(s string) Colordeprecated
- func Oklab(L, a, b float64) Color
- func ParseHex(scol string) (Color, error)
- func XYY(x, y, Y float64) Color
- func XYZ(x, y, z float64) Color
- func (col Color) AlmostEqualRGB(c2 Color) bool
- func (col Color) BlendHSV(c2 Color, t float64) Color
- func (col Color) BlendLAB(c2 Color, t float64) Color
- func (col Color) BlendLABLCH(col2 Color, t float64) Color
- func (col Color) BlendLUV(c2 Color, t float64) Color
- func (col Color) BlendLUVLCh(col2 Color, t float64) Color
- func (col Color) BlendLinearRGB(c2 Color, t float64) Color
- func (col Color) BlendOklab(c2 Color, t float64) Color
- func (col Color) BlendOklabPlus(c2 Color, t float64) Color
- func (col Color) BlendRGB(c2 Color, t float64) Color
- func (col Color) Boost(m float64) Color
- func (col Color) Clamped() Color
- func (col Color) DistanceCIE76(c2 Color) float64
- func (col Color) DistanceCIE94(cr Color) float64
- func (col Color) DistanceCIEDE2000(cr Color) float64
- func (col Color) DistanceCIEDE2000klch(cr Color, kl, kc, kh float64) float64
- func (col Color) DistanceHPLuv(c2 Color) float64
- func (col Color) DistanceHSLuv(c2 Color) float64
- func (col Color) DistanceLAB(c2 Color) float64
- func (col Color) DistanceLinearRGB(c2 Color) float64
- func (col Color) DistanceLuv(c2 Color) float64
- func (col Color) DistanceRGB(c2 Color) float64
- func (col Color) DistanceRiemersma(c2 Color) float64
- func (col Color) FastLinearRGB() (r, g, b float64)
- func (col Color) HPLuv() (h, s, l float64)
- func (col Color) HSL() (h, s, l float64)
- func (col Color) HSLuv() (h, s, l float64)
- func (col Color) HSV() (h, s, v float64)
- func (col Color) Hex() string
- func (col Color) IsValid() bool
- func (col Color) LAB() (l, a, b float64)
- func (col Color) LABLCH() (h, c, l float64)
- func (col Color) LABLCHWhiteRef(wref [3]float64) (h, c, l float64)
- func (col Color) LABWhiteRef(wref [3]float64) (l, a, b float64)
- func (col Color) LinearRGB() (r, g, b float64)
- func (col Color) Luv() (l, u, v float64)
- func (col Color) LuvLCh() (l, c, h float64)
- func (col Color) LuvLChWhiteRef(wref [3]float64) (l, c, h float64)
- func (col Color) LuvWhiteRef(wref [3]float64) (l, u, v float64)
- func (col Color) Oklab() (l, a, b float64)
- func (col Color) RGB255() (r, g, b uint8)
- func (col Color) RGBA() (r, g, b, a uint32)
- func (col Color) XYY() (x, y, Y float64)
- func (col Color) XYYWhiteRef(wRef [3]float64) (x, y, Y float64)
- func (col Color) XYZ() (x, y, z float64)
- type HexColor
- type Set
Constants ¶
const Delta = 1.0 / 255.0
Delta is the tolerance used when comparing colors using AlmostEqualRGB.
Variables ¶
var ( D50 = [3]float64{0.96422, 1.00000, 0.82521} D65 = [3]float64{0.95047, 1.00000, 1.08883} )
D65 is the default reference white point.
Functions ¶
func LABLCHToLAB ¶ added in v0.0.8
func LABToLABLCH ¶ added in v0.0.8
func LABToXYZWhiteRef ¶ added in v0.0.8
func LinearRGBToXYZ ¶ added in v0.0.8
func LuvLChToLuv ¶
func LuvToLuvLCh ¶
func LuvToXYZWhiteRef ¶ added in v0.0.8
func XYZToLABWhiteRef ¶ added in v0.0.8
func XYZToLinearRGB ¶ added in v0.0.8
XYZToLinearRGB converts from CIE XYZ-space to Linear RGB space.
func XYZToLuvWhiteRef ¶ added in v0.0.8
func XYZToXYYWhiteRef ¶ added in v0.0.8
Types ¶
type Color ¶
type Color struct {
R, G, B, A float64
}
Color holds the RGBA values of a color.
func BlendLABLCH ¶ added in v0.0.8
BlendLABLCH blends col1 with col2 in the CIE-L*C*h° color space.
func BlendLUVLCh ¶ added in v0.0.8
BlendLUVLCh blends col1 and col2 in the cylindrical CIELUV color space.
func BlendLinearRGB ¶ added in v0.0.8
BlendLinearRGB blends c1 and c2 in the linear RGB color space.
func BlendOklab ¶ added in v0.0.8
BlendOklab blends c1 to c2 in the Oklab colorspace and returns the color at position t.
func BlendRGB ¶ added in v0.0.8
BlendRGB blends c1 with c2 in the sRGB color space. Prefer BlendLAB, BlendLUV or BlendLABLCH over this.
func FastLinearRGB ¶ added in v0.0.8
FastLinearRGB is a faster LinearRGB that is almost as accurate. FastLinearRGB is only accurate for valid RGB colors, i.e. colors with RGB values in the [0,1] range.
func HPLuv ¶
HPLuv creates a new Color from values in the HPLuv color space. Hue in [0..360], a Saturation [0..1], and a Luminance (lightness) in [0..1].
The returned color values are clamped (using .Clamped), so this will never output an invalid color.
func HSLuv ¶
HSLuv creates a new Color from the provided HSLuv color space coordinates. Hue in [0..360], a Saturation [0..1], and a Luminance (lightness) in [0..1].
The returned color values are clamped (using .Clamped), so this will never output an invalid color.
func HSV ¶ added in v0.0.8
HSV creates a new Color given a Hue in [0..360], a Saturation and a Value in [0..1]
func Hex ¶
Hex parses and returns the Color for a hex triplet or quadruplet from s. The string must begin with a leading '#'. Hex panics if s cannot be parsed.
func LAB ¶ added in v0.0.8
Generates a color by using data given in CIE L*a*b* space using D65 as reference white. WARNING: many combinations of `l`, `a`, and `b` values do not have corresponding valid RGB values, check the FAQ in the README if you're unsure.
func LABLCH ¶ added in v0.0.8
Generates a color by using data given in LABLCH space using D65 as reference white. H values are in [0..360], C and L values are in [0..1]
func LABLCHWhiteRef ¶ added in v0.0.8
Generates a color by using data given in LABLCH space, taking into account a given reference white. (i.e. the monitor's white) H values are in [0..360], C and L values are in [0..1]
func LABWhiteRef ¶ added in v0.0.8
Generates a color by using data given in CIE L*a*b* space, taking into account a given reference white. (i.e. the monitor's white)
func Luv ¶
Generates a color by using data given in CIE L*u*v* space using D65 as reference white. L* is in [0..1] and both u* and v* are in about [-1..1] WARNING: many combinations of `l`, `u`, and `v` values do not have corresponding valid RGB values, check the FAQ in the README if you're unsure.
func LuvLCh ¶
Generates a color by using data given in LuvLCh space using D65 as reference white. h values are in [0..360], C and L values are in [0..1] WARNING: many combinations of `l`, `c`, and `h` values do not have corresponding valid RGB values, check the FAQ in the README if you're unsure.
func LuvLChWhiteRef ¶
Generates a color by using data given in LuvLCh space, taking into account a given reference white. (i.e. the monitor's white) h values are in [0..360], C and L values are in [0..1]
func LuvWhiteRef ¶
Generates a color by using data given in CIE L*u*v* space, taking into account a given reference white. (i.e. the monitor's white) L* is in [0..1] and both u* and v* are in about [-1..1]
func MustParseHex
deprecated
func ParseHex ¶ added in v0.0.8
ParseHex parses and returns the Color for a hex triplet or quadruplet from s. The string must begin with a leading '#'.
func (Color) AlmostEqualRGB ¶ added in v0.0.8
AlmostEqualRGB returns true if the colors are equal within the tolerance Delta.
func (Color) BlendHSV ¶ added in v0.0.8
BlendHSV blends the color with c2 using the HSV color model.
func (Color) BlendLAB ¶ added in v0.0.8
BlendLAB blends the color with c2 in the L*a*b* color space.
func (Color) BlendLABLCH ¶ added in v0.0.8
BlendLABLCH blends the color with col2 in the CIE-L*C*h° color space.
func (Color) BlendLUV ¶ added in v0.0.8
BlendLUV blends the color with c2 in the CIE-L*u*v* color space.
func (Color) BlendLUVLCh ¶ added in v0.0.8
BlendLUVLCh blends the color with col2 in the cylindrical CIELUV color space.
func (Color) BlendLinearRGB ¶ added in v0.0.8
BlendLinearRGB blends the color with c2 in the linear RGB color space.
func (Color) BlendOklab ¶
BlendOklab blends col to c2 in the Oklab colorspace and returns the color at position t.
func (Color) BlendOklabPlus ¶
func (Color) BlendRGB ¶ added in v0.0.8
BlendRGB blends the color with c2 in the sRGB color space. Prefer BlendLAB, BlendLUV or BlendLABLCH over this.
func (Color) Boost ¶ added in v0.0.6
Boost returns a new color with col's RGB values multiplied by m.
func (Color) Clamped ¶
Clamped returns a copy of the color with its RGBA values clamped to the range [0,1].
func (Color) DistanceCIE76 ¶
DistanceCIE76 is the same as DistanceLAB.
func (Color) DistanceCIE94 ¶
Uses the CIE94 formula to calculate color distance. More accurate than DistanceLAB, but also more work.
func (Color) DistanceCIEDE2000 ¶
DistanceCIEDE2000 uses the Delta E 2000 formula to calculate color distance. It is more expensive but more accurate than both DistanceLAB and DistanceCIE94.
func (Color) DistanceCIEDE2000klch ¶
DistanceCIEDE2000klch uses the Delta E 2000 formula with custom values for the weighting factors kL, kC, and kH.
func (Color) DistanceHPLuv ¶
DistanceHPLuv calculates Euclidean distance in the HPLuv colorspace. No idea how useful this is.
The Hue value is divided by 100 before the calculation, so that H, S, and L have the same relative ranges.
func (Color) DistanceHSLuv ¶
DistanceHSLuv calculates Euclidan distance in the HSLuv colorspace. No idea how useful this is.
The Hue value is divided by 100 before the calculation, so that H, S, and L have the same relative ranges.
func (Color) DistanceLAB ¶ added in v0.0.8
DistanceLAB is a good measure of visual similarity between two colors! A result of 0 would mean identical colors, while a result of 1 or higher means the colors differ a lot.
func (Color) DistanceLinearRGB ¶
DistanceLinearRGB computes the distance between the color and c2 in the linear RGB color space. This is not useful for measuring how humans perceive color, but might be useful for other things, like dithering.
func (Color) DistanceLuv ¶
DistanceLuv is a good measure of visual similarity between two colors! A result of 0 would mean identical colors, while a result of 1 or higher means the colors differ a lot.
func (Color) DistanceRGB ¶ added in v0.0.8
DistanceRGB computes the distance between two colors in RGB space. This is not a good measure! Rather do it in LAB space.
func (Color) DistanceRiemersma ¶
DistanceRiemersma is a color distance algorithm developed by Thiadmer Riemersma. It uses RGB coordinates, but he claims it has similar results to CIELUV. This makes it both fast and accurate.
Sources:
https://www.compuphase.com/cmetric.htm https://github.com/lucasb-eyer/go-colorful/issues/52
func (Color) FastLinearRGB ¶ added in v0.0.8
FastLinearRGB is a faster LinearRGB that is almost as accurate. FastLinearRGB is only accurate for valid RGB colors, i.e. colors with RGB values in the [0,1] range.
func (Color) HPLuv ¶
HPLuv returns the Hue, Saturation and Luminance of the color in the HSLuv color space. Hue in [0..360], a Saturation [0..1], and a Luminance (lightness) in [0..1].
Note that HPLuv can only represent pastel colors, and so the Saturation value could be much larger than 1 for colors it can't represent.
func (Color) HSL ¶ added in v0.0.8
HSL returns the coordinates of the color in the HSL color model. The coordinates returned will fall in the following ranges. Hue - [0,360] Saturation - [0,1] Luminance - [0,1]
func (Color) HSLuv ¶
HSLuv returns the Hue, Saturation and Luminance of the color in the HSLuv color space. Hue in [0..360], a Saturation [0..1], and a Luminance (lightness) in [0..1].
func (Color) HSV ¶ added in v0.0.8
HSV returns the Hue [0..360], Saturation and Value [0..1] of the color.
func (Color) IsValid ¶
IsValid returns true if the color exists in RGB space, i.e. all values lie in the range [0,1].
func (Color) LAB ¶ added in v0.0.8
Converts the given color to CIE L*a*b* space using D65 as reference white.
func (Color) LABLCH ¶ added in v0.0.8
LABLCH returns the coordinates of the color in the CIE LABLCh color space using D65 as the white reference. H values are in [0..360], C and L values are in [0..1] although C can overshoot 1.0
func (Color) LABLCHWhiteRef ¶ added in v0.0.8
LABLCHWhiteRef returns the coordinates of the color in the CIE LABLCh color space using wref as the white reference. H values are in [0..360], C and L values are in [0..1]
func (Color) LABWhiteRef ¶ added in v0.0.8
Converts the given color to CIE L*a*b* space, taking into account a given reference white. (i.e. the monitor's white)
func (Color) LinearRGB ¶ added in v0.0.8
LinearRGB returns the color's RGB triplet in the linear RGB color space.
func (Color) Luv ¶
Converts the given color to CIE L*u*v* space using D65 as reference white. L* is in [0..1] and both u* and v* are in about [-1..1]
func (Color) LuvLCh ¶
Converts the given color to LuvLCh space using D65 as reference white. h values are in [0..360], C and L values are in [0..1] although C can overshoot 1.0
func (Color) LuvLChWhiteRef ¶
Converts the given color to LuvLCh space, taking into account a given reference white. (i.e. the monitor's white) h values are in [0..360], c and l values are in [0..1]
func (Color) LuvWhiteRef ¶
Converts the given color to CIE L*u*v* space, taking into account a given reference white. (i.e. the monitor's white) L* is in [0..1] and both u* and v* are in about [-1..1]
func (Color) XYY ¶ added in v0.0.8
XYY returns the coordinates of the color in the CIE xyY color space.
func (Color) XYYWhiteRef ¶ added in v0.0.8
XYYWhiteRef returns the coordinates of the color in the CIE xyY color space, calculated using the white reference wref.
type HexColor ¶
type HexColor Color
A HexColor is a Color that marshels to a hex triple of the form "#rrggbb". It implements the database/sql.Scanner, database/sql/driver.Value, encoding/json.Unmarshaler and encoding/json.Marshaler interfaces.
func (HexColor) MarshalJSON ¶
func (*HexColor) UnmarshalJSON ¶
type Set ¶
type Set struct {
// contains filtered or unexported fields
}
A Set is an ordered set of Colors. Set provides convenience methods when working with colors such returning a random color (Set.Rand()) and returning successive colors from a Set (Set.Next()).
func (Set) Index ¶ added in v0.0.8
Index returns the ith color. If i is out of range, i is "wrapped around" to bring it back in range.
Source Files
¶
Directories
¶
Path | Synopsis |
---|---|
Package gradient implements gradients that can be used with Ilysa.
|
Package gradient implements gradients that can be used with Ilysa. |