...

Package colorful

import "github.com/lucasb-eyer/go-colorful"
Overview
Index
Subdirectories

Overview ▾

The colorful package provides all kinds of functions for working with colors.

Index ▾

Constants
Variables
func HPLuvToLuvLCh(h, s, l float64) (float64, float64, float64)
func HSLuvToLuvLCh(h, s, l float64) (float64, float64, float64)
func HclToLab(h, c, l float64) (L, a, b float64)
func LabToHcl(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 FastHappyColor() Color
    func FastHappyPalette(colorsCount int) (colors []Color)
    func FastLinearRgb(r, g, b float64) Color
    func FastWarmColor() Color
    func FastWarmPalette(colorsCount int) (colors []Color)
    func HPLuv(h, s, l float64) Color
    func HSLuv(h, s, l float64) Color
    func HappyColor() (c Color)
    func HappyPalette(colorsCount int) ([]Color, error)
    func Hcl(h, c, l float64) Color
    func HclWhiteRef(h, c, l float64, wref [3]float64) Color
    func Hex(scol string) (Color, error)
    func Hsl(h, s, l float64) Color
    func Hsv(H, S, V float64) Color
    func Lab(l, a, b 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 MakeColor(col color.Color) (Color, bool)
    func SoftPalette(colorsCount int) ([]Color, error)
    func SoftPaletteEx(colorsCount int, settings SoftPaletteSettings) ([]Color, error)
    func WarmColor() (c Color)
    func WarmPalette(colorsCount int) ([]Color, error)
    func Xyy(x, y, Y float64) Color
    func Xyz(x, y, z float64) Color
    func (c1 Color) AlmostEqualRgb(c2 Color) bool
    func (col1 Color) BlendHcl(col2 Color, t float64) Color
    func (c1 Color) BlendHsv(c2 Color, t float64) Color
    func (c1 Color) BlendLab(c2 Color, t float64) Color
    func (c1 Color) BlendLuv(c2 Color, t float64) Color
    func (col1 Color) BlendLuvLCh(col2 Color, t float64) Color
    func (c1 Color) BlendRgb(c2 Color, t float64) Color
    func (c Color) Clamped() Color
    func (c1 Color) DistanceCIE76(c2 Color) float64
    func (cl Color) DistanceCIE94(cr Color) float64
    func (cl Color) DistanceCIEDE2000(cr Color) float64
    func (cl Color) DistanceCIEDE2000klch(cr Color, kl, kc, kh float64) float64
    func (c1 Color) DistanceHPLuv(c2 Color) float64
    func (c1 Color) DistanceHSLuv(c2 Color) float64
    func (c1 Color) DistanceLab(c2 Color) float64
    func (c1 Color) DistanceLinearRGB(c2 Color) float64
    func (c1 Color) DistanceLuv(c2 Color) float64
    func (c1 Color) DistanceRgb(c2 Color) float64
    func (col Color) FastLinearRgb() (r, g, b float64)
    func (col Color) HPLuv() (h, s, l float64)
    func (col Color) HSLuv() (h, s, l float64)
    func (col Color) Hcl() (h, c, l float64)
    func (col Color) HclWhiteRef(wref [3]float64) (h, c, l float64)
    func (col Color) Hex() string
    func (col Color) Hsl() (h, s, l float64)
    func (col Color) Hsv() (h, s, v float64)
    func (c Color) IsValid() bool
    func (col Color) Lab() (l, a, b 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) 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
    func (hc *HexColor) Decode(hexCode string) error
    func (hc HexColor) MarshalJSON() ([]byte, error)
    func (hc *HexColor) Scan(value interface{}) error
    func (hc *HexColor) UnmarshalJSON(data []byte) error
    func (hc *HexColor) Value() (driver.Value, error)
type SoftPaletteSettings

Package files

colorgens.go colors.go happy_palettegen.go hexcolor.go hsluv.go soft_palettegen.go warm_palettegen.go

Constants

This is the tolerance used when comparing colors using AlmostEqualRgb.

const Delta = 1.0 / 255.0
const LAB_DELTA = 1e-6

Variables

And another one.

var D50 = [3]float64{0.96422, 1.00000, 0.82521}

This is the default reference white point.

var D65 = [3]float64{0.95047, 1.00000, 1.08883}

func HPLuvToLuvLCh

func HPLuvToLuvLCh(h, s, l float64) (float64, float64, float64)

func HSLuvToLuvLCh

func HSLuvToLuvLCh(h, s, l float64) (float64, float64, float64)

func HclToLab

func HclToLab(h, c, l float64) (L, a, b float64)

func LabToHcl

func LabToHcl(L, a, b float64) (h, c, l float64)

func LabToXyz

func LabToXyz(l, a, b float64) (x, y, z float64)

func LabToXyzWhiteRef

func LabToXyzWhiteRef(l, a, b float64, wref [3]float64) (x, y, z float64)

func LinearRgbToXyz

func LinearRgbToXyz(r, g, b float64) (x, y, z float64)

func LuvLChToHPLuv

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

func LuvLChToHSLuv

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

func LuvLChToLuv

func LuvLChToLuv(l, c, h float64) (L, u, v float64)

func LuvToLuvLCh

func LuvToLuvLCh(L, u, v float64) (l, c, h float64)

func LuvToXyz

func LuvToXyz(l, u, v float64) (x, y, z float64)

func LuvToXyzWhiteRef

func LuvToXyzWhiteRef(l, u, v float64, wref [3]float64) (x, y, z float64)

func XyyToXyz

func XyyToXyz(x, y, Y float64) (X, Yout, Z float64)

func XyzToLab

func XyzToLab(x, y, z float64) (l, a, b float64)

func XyzToLabWhiteRef

func XyzToLabWhiteRef(x, y, z float64, wref [3]float64) (l, a, b float64)

func XyzToLinearRgb

func XyzToLinearRgb(x, y, z float64) (r, g, b float64)

XyzToLinearRgb converts from CIE XYZ-space to Linear RGB space.

func XyzToLuv

func XyzToLuv(x, y, z float64) (l, a, b float64)

func XyzToLuvWhiteRef

func XyzToLuvWhiteRef(x, y, z float64, wref [3]float64) (l, u, v float64)

func XyzToXyy

func XyzToXyy(X, Y, Z float64) (x, y, Yout float64)

Well, the name is bad, since it's xyY but Golang needs me to start with a capital letter to make the method public.

func XyzToXyyWhiteRef

func XyzToXyyWhiteRef(X, Y, Z float64, wref [3]float64) (x, y, Yout float64)

type Color

A color is stored internally using sRGB (standard RGB) values in the range 0-1

type Color struct {
    R, G, B float64
}

func FastHappyColor

func FastHappyColor() Color

Creates a random bright, "pimpy" color through a restricted HSV space.

func FastHappyPalette

func FastHappyPalette(colorsCount int) (colors []Color)

Uses the HSV color space to generate colors with similar S,V but distributed evenly along their Hue. This is fast but not always pretty. If you've got time to spare, use Lab (the non-fast below).

func FastLinearRgb

func FastLinearRgb(r, g, b float64) Color

FastLinearRgb is much faster than and almost as accurate as LinearRgb. BUT it is important to NOTE that they only produce good results for valid inputs r,g,b in [0,1].

func FastWarmColor

func FastWarmColor() Color

Creates a random dark, "warm" color through a restricted HSV space.

func FastWarmPalette

func FastWarmPalette(colorsCount int) (colors []Color)

Uses the HSV color space to generate colors with similar S,V but distributed evenly along their Hue. This is fast but not always pretty. If you've got time to spare, use Lab (the non-fast below).

func HPLuv

func HPLuv(h, s, l float64) Color

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

func HSLuv(h, s, l float64) Color

HSLuv creates a new Color from values in the HSLuv 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 HappyColor

func HappyColor() (c Color)

Creates a random bright, "pimpy" color through restricted HCL space. This is slower than FastHappyColor but will likely give you colors which have the same "brightness" if you run it many times.

func HappyPalette

func HappyPalette(colorsCount int) ([]Color, error)

func Hcl

func Hcl(h, c, l float64) Color

Generates a color by using data given in HCL space using D65 as reference white. H values are in [0..360], C and L values are in [0..1] WARNING: many combinations of `h`, `c`, and `l` values do not have corresponding valid RGB values, check the FAQ in the README if you're unsure.

func HclWhiteRef

func HclWhiteRef(h, c, l float64, wref [3]float64) Color

Generates a color by using data given in HCL 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 Hex

func Hex(scol string) (Color, error)

Hex parses a "html" hex color-string, either in the 3 "#f0c" or 6 "#ff1034" digits form.

func Hsl

func Hsl(h, s, l float64) Color

Hsl creates a new Color given a Hue in [0..360], a Saturation [0..1], and a Luminance (lightness) in [0..1]

func Hsv

func Hsv(H, S, V float64) Color

Hsv creates a new Color given a Hue in [0..360], a Saturation and a Value in [0..1]

func Lab

func Lab(l, a, b float64) Color

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 LabWhiteRef

func LabWhiteRef(l, a, b float64, wref [3]float64) Color

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 LinearRgb

func LinearRgb(r, g, b float64) Color

LinearRgb creates an sRGB color out of the given linear RGB color (see http://www.sjbrown.co.uk/2004/05/14/gamma-correct-rendering/).

func Luv

func Luv(l, u, v float64) Color

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

func LuvLCh(l, c, h float64) Color

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

func LuvLChWhiteRef(l, c, h float64, wref [3]float64) Color

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

func LuvWhiteRef(l, u, v float64, wref [3]float64) Color

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 MakeColor

func MakeColor(col color.Color) (Color, bool)

Constructs a colorful.Color from something implementing color.Color

func SoftPalette

func SoftPalette(colorsCount int) ([]Color, error)

A wrapper which uses common parameters.

func SoftPaletteEx

func SoftPaletteEx(colorsCount int, settings SoftPaletteSettings) ([]Color, error)

Yeah, windows-stype Foo, FooEx, screw you golang... Uses K-means to cluster the color-space and return the means of the clusters as a new palette of distinctive colors. Falls back to K-medoid if the mean happens to fall outside of the color-space, which can only happen if you specify a CheckColor function.

func WarmColor

func WarmColor() (c Color)

Creates a random dark, "warm" color through restricted HCL space. This is slower than FastWarmColor but will likely give you colors which have the same "warmness" if you run it many times.

func WarmPalette

func WarmPalette(colorsCount int) ([]Color, error)

func Xyy

func Xyy(x, y, Y float64) Color

Generates a color by using data given in CIE xyY space. x, y and Y are in [0..1]

func Xyz

func Xyz(x, y, z float64) Color

func (Color) AlmostEqualRgb

func (c1 Color) AlmostEqualRgb(c2 Color) bool

Check for equality between colors within the tolerance Delta (1/255).

func (Color) BlendHcl

func (col1 Color) BlendHcl(col2 Color, t float64) Color

BlendHcl blends two colors in the CIE-L*C*h° color-space, which should result in a smoother blend. t == 0 results in c1, t == 1 results in c2

func (Color) BlendHsv

func (c1 Color) BlendHsv(c2 Color, t float64) Color

You don't really want to use this, do you? Go for BlendLab, BlendLuv or BlendHcl.

func (Color) BlendLab

func (c1 Color) BlendLab(c2 Color, t float64) Color

BlendLab blends two colors in the L*a*b* color-space, which should result in a smoother blend. t == 0 results in c1, t == 1 results in c2

func (Color) BlendLuv

func (c1 Color) BlendLuv(c2 Color, t float64) Color

BlendLuv blends two colors in the CIE-L*u*v* color-space, which should result in a smoother blend. t == 0 results in c1, t == 1 results in c2

func (Color) BlendLuvLCh

func (col1 Color) BlendLuvLCh(col2 Color, t float64) Color

BlendLuvLCh blends two colors in the cylindrical CIELUV color space. t == 0 results in c1, t == 1 results in c2

func (Color) BlendRgb

func (c1 Color) BlendRgb(c2 Color, t float64) Color

You don't really want to use this, do you? Go for BlendLab, BlendLuv or BlendHcl.

func (Color) Clamped

func (c Color) Clamped() Color

Returns Clamps the color into valid range, clamping each value to [0..1] If the color is valid already, this is a no-op.

func (Color) DistanceCIE76

func (c1 Color) DistanceCIE76(c2 Color) float64

DistanceCIE76 is the same as DistanceLab.

func (Color) DistanceCIE94

func (cl Color) DistanceCIE94(cr Color) float64

Uses the CIE94 formula to calculate color distance. More accurate than DistanceLab, but also more work.

func (Color) DistanceCIEDE2000

func (cl Color) DistanceCIEDE2000(cr Color) float64

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

func (cl Color) DistanceCIEDE2000klch(cr Color, kl, kc, kh float64) float64

DistanceCIEDE2000klch uses the Delta E 2000 formula with custom values for the weighting factors kL, kC, and kH.

func (Color) DistanceHPLuv

func (c1 Color) DistanceHPLuv(c2 Color) float64

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

func (c1 Color) DistanceHSLuv(c2 Color) float64

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

func (c1 Color) DistanceLab(c2 Color) float64

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

func (c1 Color) DistanceLinearRGB(c2 Color) float64

DistanceLinearRGB computes the distance between two colors in linear RGB space. This is not useful for measuring how humans perceive color, but might be useful for other things, like dithering.

func (Color) DistanceLuv

func (c1 Color) DistanceLuv(c2 Color) float64

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

func (c1 Color) DistanceRgb(c2 Color) float64

DistanceRgb computes the distance between two colors in RGB space. This is not a good measure! Rather do it in Lab space.

func (Color) FastLinearRgb

func (col Color) FastLinearRgb() (r, g, b float64)

FastLinearRgb is much faster than and almost as accurate as LinearRgb. BUT it is important to NOTE that they only produce good results for valid colors r,g,b in [0,1].

func (Color) HPLuv

func (col Color) HPLuv() (h, s, l float64)

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) HSLuv

func (col Color) HSLuv() (h, s, l float64)

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) Hcl

func (col Color) Hcl() (h, c, l float64)

Converts the given color to HCL 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) HclWhiteRef

func (col Color) HclWhiteRef(wref [3]float64) (h, c, l float64)

Converts the given color to HCL 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) Hex

func (col Color) Hex() string

Hex returns the hex "html" representation of the color, as in #ff0080.

func (Color) Hsl

func (col Color) Hsl() (h, s, l float64)

Hsl returns the Hue [0..360], Saturation [0..1], and Luminance (lightness) [0..1] of the color.

func (Color) Hsv

func (col Color) Hsv() (h, s, v float64)

Hsv returns the Hue [0..360], Saturation and Value [0..1] of the color.

func (Color) IsValid

func (c Color) IsValid() bool

Checks whether the color exists in RGB space, i.e. all values are in [0..1]

func (Color) Lab

func (col Color) Lab() (l, a, b float64)

Converts the given color to CIE L*a*b* space using D65 as reference white.

func (Color) LabWhiteRef

func (col Color) LabWhiteRef(wref [3]float64) (l, a, b float64)

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

func (col Color) LinearRgb() (r, g, b float64)

LinearRgb converts the color into the linear RGB space (see http://www.sjbrown.co.uk/2004/05/14/gamma-correct-rendering/).

func (Color) Luv

func (col Color) Luv() (l, u, v float64)

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

func (col Color) LuvLCh() (l, c, h float64)

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

func (col Color) LuvLChWhiteRef(wref [3]float64) (l, c, h float64)

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

func (col Color) LuvWhiteRef(wref [3]float64) (l, u, v float64)

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) RGB255

func (col Color) RGB255() (r, g, b uint8)

Might come in handy sometimes to reduce boilerplate code.

func (Color) RGBA

func (col Color) RGBA() (r, g, b, a uint32)

Implement the Go color.Color interface.

func (Color) Xyy

func (col Color) Xyy() (x, y, Y float64)

Converts the given color to CIE xyY space using D65 as reference white. (Note that the reference white is only used for black input.) x, y and Y are in [0..1]

func (Color) XyyWhiteRef

func (col Color) XyyWhiteRef(wref [3]float64) (x, y, Y float64)

Converts the given color to CIE xyY space, taking into account a given reference white. (i.e. the monitor's white) (Note that the reference white is only used for black input.) x, y and Y are in [0..1]

func (Color) Xyz

func (col Color) Xyz() (x, y, z float64)

type HexColor

A HexColor is a Color stored as a hex string "#rrggbb". It implements the database/sql.Scanner, database/sql/driver.Value, encoding/json.Unmarshaler and encoding/json.Marshaler interfaces.

type HexColor Color

func (*HexColor) Decode

func (hc *HexColor) Decode(hexCode string) error

Decode - deserialize function for https://github.com/kelseyhightower/envconfig

func (HexColor) MarshalJSON

func (hc HexColor) MarshalJSON() ([]byte, error)

func (*HexColor) Scan

func (hc *HexColor) Scan(value interface{}) error

func (*HexColor) UnmarshalJSON

func (hc *HexColor) UnmarshalJSON(data []byte) error

func (*HexColor) Value

func (hc *HexColor) Value() (driver.Value, error)

type SoftPaletteSettings

type SoftPaletteSettings struct {
    // A function which can be used to restrict the allowed color-space.
    CheckColor func(l, a, b float64) bool

    // The higher, the better quality but the slower. Usually two figures.
    Iterations int

    // Use up to 160000 or 8000 samples of the L*a*b* space (and thus calls to CheckColor).
    // Set this to true only if your CheckColor shapes the Lab space weirdly.
    ManySamples bool
}

Subdirectories