go-colorful: github.com/lucasb-eyer/go-colorful Index | Files

package colorful

import "github.com/lucasb-eyer/go-colorful"

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

Index

Package Files

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

Constants

const Delta = 1.0 / 255.0

This is the tolerance used when comparing colors using AlmostEqualRgb.

const LAB_DELTA = 1e-6

Variables

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

And another one.

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

This is the default reference white point.

func HclToLab Uses

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

func LabToHcl Uses

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

func LabToXyz Uses

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

func LabToXyzWhiteRef Uses

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

func LinearRgbToXyz Uses

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

func LuvToXyz Uses

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

func LuvToXyzWhiteRef Uses

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

func XyyToXyz Uses

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

func XyzToLab Uses

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

func XyzToLabWhiteRef Uses

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

func XyzToLinearRgb Uses

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

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

func XyzToLuv Uses

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

func XyzToLuvWhiteRef Uses

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

func XyzToXyy Uses

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 Uses

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

type Color Uses

type Color struct {
    R, G, B float64
}

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

func FastHappyColor Uses

func FastHappyColor() Color

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

func FastHappyPalette Uses

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 Uses

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 Uses

func FastWarmColor() Color

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

func FastWarmPalette Uses

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 HappyColor Uses

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 Uses

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

func Hcl Uses

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 `l`, `a`, and `b` values do not have corresponding

valid RGB values, check the FAQ in the README if you're unsure.

func HclWhiteRef Uses

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 Uses

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 Uses

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 Uses

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 Uses

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 Uses

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 Uses

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 Uses

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`, `a`, and `b` values do not have corresponding

valid RGB values, check the FAQ in the README if you're unsure.

func LuvWhiteRef Uses

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 Uses

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

Constructs a colorful.Color from something implementing color.Color

func SoftPalette Uses

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

A wrapper which uses common parameters.

func SoftPaletteEx Uses

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 Uses

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 Uses

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

func Xyy Uses

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 Uses

func Xyz(x, y, z float64) Color

func (Color) AlmostEqualRgb Uses

func (c1 Color) AlmostEqualRgb(c2 Color) bool

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

func (Color) BlendHcl Uses

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 Uses

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 Uses

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 Uses

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) BlendRgb Uses

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 Uses

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 Uses

func (c1 Color) DistanceCIE76(c2 Color) float64

That's actually the same, but I don't want to break code.

func (Color) DistanceCIE94 Uses

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 Uses

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 Uses

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) DistanceLab Uses

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) DistanceLuv Uses

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 Uses

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 Uses

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

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 Uses

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 Uses

func (col Color) Hex() string

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

func (Color) Hsl Uses

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 Uses

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 Uses

func (c Color) IsValid() bool

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

func (Color) Lab Uses

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 Uses

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 Uses

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 Uses

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) LuvWhiteRef Uses

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 Uses

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

Might come in handy sometimes to reduce boilerplate code.

func (Color) RGBA Uses

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

Implement the Go color.Color interface.

func (Color) Xyy Uses

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 Uses

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 Uses

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

type HexColor Uses

type HexColor Color

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

func (*HexColor) Scan Uses

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

func (*HexColor) Value Uses

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

type SoftPaletteSettings Uses

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
}

Package colorful imports 6 packages (graph) and is imported by 187 packages. Updated 2018-10-28. Refresh now. Tools for package owners.