Documentation
¶
Overview ¶
Package hct is a Go port of Google's HCT Material color utility.
https://github.com/material-foundation/material-color-utilities/tree/main/java/hct
Copyright 2021 Google LLC ¶
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Index ¶
- Variables
- func AreInCyclicOrder(a, b, c float64) bool
- func ArgbFromLinrgb(linrgb []float64) int
- func ArgbFromLstar(lstar float64) int
- func ArgbFromRgb(red, green, blue int) int
- func ArgbFromXyz(x, y, z float64) int
- func BisectToLimit(y float64, targetHue float64) []float64
- func BisectToSegment(y float64, targetHue float64) [][]float64
- func BlueFromArgb(argb int) int
- func ChromaticAdaptation(component float64) float64
- func ClampDouble(min, max, input float64) float64
- func ClampInt(min, max, input int) int
- func CriticalPlaneAbove(x float64) int
- func CriticalPlaneBelow(x float64) int
- func Delinearized(rgbComponent float64) int
- func FindResultByJ(hueRadians float64, chroma float64, y float64) int
- func GreenFromArgb(argb int) int
- func HueOf(linrgb []float64) float64
- func Intercept(source, mid, target float64) float64
- func InverseChromaticAdaptation(adapted float64) float64
- func IsBounded(x float64) bool
- func LabF(t float64) float64
- func LabInvf(ft float64) float64
- func Lerp(start, stop, amount float64) float64
- func LerpPoint(source []float64, t float64, target []float64) []float64
- func Linearized(rgbComponent int) float64
- func LstarFromArgb(argb int) float64
- func LstarFromY(y float64) float64
- func MatrixMultiply(row []float64, matrix [][]float64) []float64
- func Midpoint(a []float64, b []float64) []float64
- func NthVertex(y float64, n int) []float64
- func RedFromArgb(argb int) int
- func SanitizeDegreesDouble(degrees float64) float64
- func SanitizeRadians(angle float64) float64
- func SetCoordinate(source []float64, coordinate float64, target []float64, axis int) []float64
- func Signum(num float64) float64
- func SolveToInt(hueDegrees float64, chroma float64, lstar float64) int
- func ToDegrees(radians float64) float64
- func ToRadians(degrees float64) float64
- func TrueDelinearized(rgbComponent float64) float64
- func XyzFromArgb(argb int) []float64
- func YFromLstar(lstar float64) float64
- type Cam16
- func FromInt(argb int) *Cam16
- func FromIntInViewingConditions(argb int, viewingConditions *ViewingConditions) *Cam16
- func FromJch(j, c, h float64) *Cam16
- func FromJchInViewingConditions(j, c, h float64, viewingConditions *ViewingConditions) *Cam16
- func FromUcs(jstar, astar, bstar float64) *Cam16
- func FromUcsInViewingConditions(jstar, astar, bstar float64, viewingConditions *ViewingConditions) *Cam16
- func FromXyzInViewingConditions(x, y, z float64, viewingConditions *ViewingConditions) *Cam16
- func SolveToCam(hueDegrees, chroma, lstar float64) *Cam16
- func (c *Cam16) Astar() float64
- func (c *Cam16) Bstar() float64
- func (c *Cam16) Chroma() float64
- func (c *Cam16) Distance(other *Cam16) float64
- func (c *Cam16) Hue() float64
- func (c *Cam16) J() float64
- func (c *Cam16) Jstar() float64
- func (c *Cam16) M() float64
- func (c *Cam16) Q() float64
- func (c *Cam16) S() float64
- func (c *Cam16) ToInt() int
- func (c *Cam16) Viewed(viewingConditions *ViewingConditions) int
- func (c *Cam16) XyzInViewingConditions(viewingConditions *ViewingConditions) []float64
- type Hct
- func (hct *Hct) Chroma() float64
- func (hct *Hct) Hue() float64
- func (hct *Hct) InViewingConditions(vc *ViewingConditions) *Hct
- func (hct *Hct) SetChroma(newChroma float64)
- func (hct *Hct) SetHue(newHue float64)
- func (hct *Hct) SetTone(newTone float64)
- func (hct *Hct) ToInt() int
- func (hct *Hct) Tone() float64
- type ViewingConditions
- func (vc *ViewingConditions) Aw() float64
- func (vc *ViewingConditions) C() float64
- func (vc *ViewingConditions) Fl() float64
- func (vc *ViewingConditions) FlRoot() float64
- func (vc *ViewingConditions) N() float64
- func (vc *ViewingConditions) Nbb() float64
- func (vc *ViewingConditions) Nc() float64
- func (vc *ViewingConditions) Ncb() float64
- func (vc *ViewingConditions) RgbD() []float64
- func (vc *ViewingConditions) Z() float64
Constants ¶
This section is empty.
Variables ¶
var CAM16RGB_TO_XYZ = [][]float64{
{1.8620678, -1.0112547, 0.14918678},
{0.38752654, 0.62144744, -0.00897398},
{-0.01584150, -0.03412294, 1.0499644},
}
CAM16RGB_TO_XYZ transforms 'cone'/'RGB' responses in CAM16 to XYZ color space coordinates.
var CRITICAL_PLANES = []float64{}/* 255 elements not displayed */
var DEFAULT_VIEWING_CONDITIONS = DefaultWithBackgroundLstar(50.0)
sRGB-like viewing conditions.
var LINRGB_FROM_SCALED_DISCOUNT = [][]float64{
{1373.2198709594231, -1100.4251190754821, -7.278681089101213},
{-271.815969077903, 559.6580465940733, -32.46047482791194},
{1.9622899599665666, -57.173814538844006, 308.7233197812385},
}
var SCALED_DISCOUNT_FROM_LINRGB = [][]float64{
{0.001200833568784504, 0.002389694492170889, 0.0002795742885861124},
{0.0005891086651375999, 0.0029785502573438758, 0.0003270666104008398},
{0.00010146692491640572, 0.0005364214359186694, 0.0032979401770712076},
}
var SRGB_TO_XYZ = [][]float64{
{0.41233895, 0.35762064, 0.18051042},
{0.2126, 0.7152, 0.0722},
{0.01932141, 0.11916382, 0.95034478},
}
var WHITE_POINT_D65 = []float64{95.047, 100.0, 108.883}
var XYZ_TO_CAM16RGB = [][]float64{
{0.401288, 0.650173, -0.051461},
{-0.250268, 1.204414, 0.045854},
{-0.002079, 0.048952, 0.953127},
}
XYZ_TO_CAM16RGB transforms XYZ color space coordinates to 'cone'/'RGB' responses in CAM16.
var XYZ_TO_SRGB = [][]float64{
{3.2413774792388685, -1.5376652402851851, -0.49885366846268053},
{-0.9691452513005321, 1.8758853451067872, 0.04156585616912061},
{0.05562093689691305, -0.20395524564742123, 1.0571799111220335},
}
var Y_FROM_LINRGB = []float64{0.2126, 0.7152, 0.0722}
Functions ¶
func AreInCyclicOrder ¶
func ArgbFromLinrgb ¶
ArgbFromLinrgb converts a color from linear RGB components to ARGB format.
func ArgbFromLstar ¶
ArgbFromLstar converts an L* value to an ARGB representation.
func ArgbFromRgb ¶
ArgbFromRgb Converts a color from RGB components to ARGB format.
func ArgbFromXyz ¶
ArgbFromXyz converts a color from ARGB to XYZ.
func BisectToLimit ¶
func BisectToSegment ¶
BisectToSegment finds the segment containing the desired color.
func BlueFromArgb ¶
BlueFromArgb returns the blue component of a color in ARGB format. */
func ChromaticAdaptation ¶
func ClampDouble ¶
ClampDouble clamps an floating point number between two floating-point numbers.
func CriticalPlaneAbove ¶
func CriticalPlaneBelow ¶
func Delinearized ¶
Delinearized delinearizes an RGB component.
func FindResultByJ ¶
FindResultByJ finds a color with the given hue, chroma, and Y.
func GreenFromArgb ¶
GreenFromArgb returns the green component of a color in ARGB format. */
func Lerp ¶
Lerp is the linear interpolation function. It returns start if amount = 0 and stop if amount = 1.
func LstarFromArgb ¶
LstarFromArgb computes the L* value of a color in ARGB representation.
func LstarFromY ¶
LstarFromY converts a Y value to an L* value. L* in L*a*b* and Y in XYZ measure the same quantity, luminance. L* measures perceptual luminance, a linear scale. Y in XYZ measures relative luminance, a logarithmic scale.
func MatrixMultiply ¶
MatrixMultiply multiplies a 1x3 row vector with a 3x3 matrix.
func RedFromArgb ¶
RedFromArgb returns the red component of a color in ARGB format.
func SanitizeDegreesDouble ¶
SanitizeDegreesDouble sanitizes a degree measure as a floating-point number.
func SanitizeRadians ¶
SanitizeRadians sanitizes a small enough angle in radians.
func SetCoordinate ¶
SetCoordinate intersects a segment with a plane.
func SolveToInt ¶
SolveToInt finds an sRGB color with the given hue, chroma, and L*, if possible.
func ToDegrees ¶
ToDegrees converts an angle measured in radians to an approximately equivalent angle measured in degrees.
func ToRadians ¶
ToRadians converts an angle measured in degrees to an approximately equivalent angle measured in radians.
func TrueDelinearized ¶
TrueDelinearized delinearizes an RGB component, returning a floating-point number.
func XyzFromArgb ¶
XyzFromArgb converts a color from XYZ to ARGB
func YFromLstar ¶
Converts an L* value to a Y value. L* in L*a*b* and Y in XYZ measure the same quantity, luminance. L* measures perceptual luminance, a linear scale. Y in XYZ measures relative luminance, a logarithmic scale.
Types ¶
type Cam16 ¶
type Cam16 struct {
// contains filtered or unexported fields
}
*
- Cam16, a color appearance model. Colors are not just defined by their hex code, but rather, a hex
- code and viewing conditions. *
- <p>CAM16 instances also have coordinates in the CAM16-UCS space, called J*, a*, b*, or jstar,
- astar, bstar in code. CAM16-UCS is included in the CAM16 specification, and should be used when
- measuring distances between colors. *
- <p>In traditional color spaces, a color can be identified solely by the observer's measurement of
- the color. Color appearance models such as CAM16 also use information about the environment where
- the color was observed, known as the viewing conditions. *
- <p>For example, white under the traditional assumption of a midday sun white point is accurately
- measured as a slightly chromatic blue by CAM16. (roughly, hue 203, chroma 3, lightness 100)
func FromInt ¶
FromInt creates a CAM16 color from an ARGB representation of a color, assuming the color was viewed in default viewing conditions.
func FromIntInViewingConditions ¶
func FromIntInViewingConditions(argb int, viewingConditions *ViewingConditions) *Cam16
FromIntInViewingConditions creates a CAM16 color from an ARGB representation of a color, defined viewing conditions.
func FromJch ¶
FromJch creates a CAM16 color from CAM16 lighness, chroma and hue, assuming the color was viewed in default viewing conditions.
func FromJchInViewingConditions ¶
func FromJchInViewingConditions(j, c, h float64, viewingConditions *ViewingConditions) *Cam16
FromJchInViewingConditions creates a CAM16 color from CAM16 lighness, chroma and hue, defined viewing conditions.
func FromUcsInViewingConditions ¶
func FromUcsInViewingConditions(jstar, astar, bstar float64, viewingConditions *ViewingConditions) *Cam16
FromUcsInViewingConditions creates a CAM16 color from CAM16-UCS coordinates in defined viewing conditions.
func FromXyzInViewingConditions ¶
func FromXyzInViewingConditions(x, y, z float64, viewingConditions *ViewingConditions) *Cam16
func SolveToCam ¶
SolveToCam finds an sRGB color with the given hue, chroma, and L*, if possible.
func (*Cam16) Distance ¶
Distance measures the distance between colors. CAM16 instances also have coordinates in the CAM16-UCS space, called J*, a*, b*, or jstar, astar, bstar in code. CAM16-UCS is included in the CAM16 specification, and is used to measure distances between colors.
func (*Cam16) M ¶
M is colorfulness in CAM16. Prefer chroma, colorfulness is an absolute quantity. For example, a yellow toy car is much more colorful outside than inside, but it has the same chroma in both environments.
func (*Cam16) Q ¶
Q is brightness in CAM16. Prefer lightness, brightness is an absolute quantity. For example, a sheet of white paper is much brighter viewed in sunlight than in indoor light, but it is the lightest object under any lighting.
func (*Cam16) S ¶
S is saturation in CAM16. Colorfulness in proportion to brightness. Prefer chroma, saturation measures colorfulness relative to the color's own brightness, where chroma is colorfulness relative to white.
func (*Cam16) ToInt ¶
ToInt returns the ARGB representation of the color. Assumes the color was viewed in default viewing conditions, which are near-identical to the default viewing conditions for sRGB.
func (*Cam16) Viewed ¶
func (c *Cam16) Viewed(viewingConditions *ViewingConditions) int
func (*Cam16) XyzInViewingConditions ¶
func (c *Cam16) XyzInViewingConditions(viewingConditions *ViewingConditions) []float64
type Hct ¶
type Hct struct {
// contains filtered or unexported fields
}
Hct is hue, chroma, and tone. A color system that provides a perceptually accurate color measurement system that can also accurately render what colors will appear as in different lighting environments.
func (*Hct) InViewingConditions ¶
func (hct *Hct) InViewingConditions(vc *ViewingConditions) *Hct
Translate a color into different ViewingConditions.
Colors change appearance. They look different with lights on versus off, the same color, as in hex code, on white looks different when on black. This is called color relativity, most famously explicated by Josef Albers in Interaction of Color.
In color science, color appearance models can account for this and calculate the appearance of a color in different settings. HCT is based on CAM16, a color appearance model, and uses it to make these calculations.
See ViewingConditions.make for parameters affecting color appearance.
func (*Hct) SetChroma ¶
SetChroma sets the chroma of this color. Chroma may decrease because chroma has a different maximum for any given hue and tone. 0 <= newChroma < ?
func (*Hct) SetHue ¶
SetHue sets the hue of this color. Chroma may decrease because chroma has a different maximum for any given hue and tone. 0 <= newHue < 360
type ViewingConditions ¶
type ViewingConditions struct {
// contains filtered or unexported fields
}
In traditional color spaces, a color can be identified solely by the observer's measurement of the color. Color appearance models such as CAM16 also use information about the environment where the color was observed, known as the viewing conditions.
For example, white under the traditional assumption of a midday sun white point is accurately measured as a slightly chromatic blue by CAM16. (roughly, hue 203, chroma 3, lightness 100)
This class caches intermediate values of the CAM16 conversion process that depend only on viewing conditions, enabling speed ups.
func DefaultWithBackgroundLstar ¶
func DefaultWithBackgroundLstar(lstar float64) *ViewingConditions
Create sRGB-like viewing conditions with a custom background lstar. Default viewing conditions have a lstar of 50, midgray.
func Make ¶
func Make(whitePoint []float64, adaptingLuminance, backgroundLstar, surround float64, discountingIlluminant bool) *ViewingConditions
Create ViewingConditions from a simple, physically relevant, set of parameters.
White point, measured in the XYZ color space. default = D65, or sunny day afternoon.
The luminance of the adapting field. Informally, how bright it is in the room where the color is viewed. Can be calculated from lux by multiplying lux by 0.0586. default = 11.72, or 200 lux.
The lightness of the area surrounding the color. measured by L* in L*a*b*. default = 50.0
A general description of the lighting surrounding the color. 0 is pitch dark, like watching a movie in a theater. 1.0 is a dimly light room, like watching TV at home at night. 2.0 means there is no difference between the lighting on the color and around it. default = 2.0
Whether the eye accounts for the tint of the ambient lighting, such as knowing an apple is still red in green light. default = false, the eye does not perform this process on self-luminous objects like displays.
func (*ViewingConditions) Aw ¶
func (vc *ViewingConditions) Aw() float64
func (*ViewingConditions) C ¶
func (vc *ViewingConditions) C() float64
func (*ViewingConditions) Fl ¶
func (vc *ViewingConditions) Fl() float64
func (*ViewingConditions) FlRoot ¶
func (vc *ViewingConditions) FlRoot() float64
func (*ViewingConditions) N ¶
func (vc *ViewingConditions) N() float64
func (*ViewingConditions) Nbb ¶
func (vc *ViewingConditions) Nbb() float64
func (*ViewingConditions) Nc ¶
func (vc *ViewingConditions) Nc() float64
func (*ViewingConditions) Ncb ¶
func (vc *ViewingConditions) Ncb() float64
func (*ViewingConditions) RgbD ¶
func (vc *ViewingConditions) RgbD() []float64
func (*ViewingConditions) Z ¶
func (vc *ViewingConditions) Z() float64