diff --git a/go.mod b/go.mod index b32355faf..ea5578be6 100644 --- a/go.mod +++ b/go.mod @@ -22,7 +22,7 @@ require ( github.com/kardianos/osext v0.0.0-20190222173326-2bc1f35cddc0 github.com/karimkhaleel/jsonschema v0.0.0-20231001195015-d933f0d94ea3 github.com/kyokomi/emoji/v2 v2.2.8 - github.com/lucasb-eyer/go-colorful v1.3.0 + github.com/lucasb-eyer/go-colorful v1.4.0 github.com/mgutz/str v1.2.0 github.com/mitchellh/go-ps v1.0.0 github.com/rivo/uniseg v0.4.7 diff --git a/go.sum b/go.sum index ba7fb757e..543050e29 100644 --- a/go.sum +++ b/go.sum @@ -186,8 +186,8 @@ github.com/kylelemons/godebug v1.1.0 h1:RPNrshWIDI6G2gRW9EHilWtl7Z6Sb1BR0xunSBf0 github.com/kylelemons/godebug v1.1.0/go.mod h1:9/0rRGxNHcop5bhtWyNeEfOS8JIWk580+fNqagV/RAw= github.com/kyokomi/emoji/v2 v2.2.8 h1:jcofPxjHWEkJtkIbcLHvZhxKgCPl6C7MyjTrD4KDqUE= github.com/kyokomi/emoji/v2 v2.2.8/go.mod h1:JUcn42DTdsXJo1SWanHh4HKDEyPaR5CqkmoirZZP9qE= -github.com/lucasb-eyer/go-colorful v1.3.0 h1:2/yBRLdWBZKrf7gB40FoiKfAWYQ0lqNcbuQwVHXptag= -github.com/lucasb-eyer/go-colorful v1.3.0/go.mod h1:R4dSotOR9KMtayYi1e77YzuveK+i7ruzyGqttikkLy0= +github.com/lucasb-eyer/go-colorful v1.4.0 h1:UtrWVfLdarDgc44HcS7pYloGHJUjHV/4FwW4TvVgFr4= +github.com/lucasb-eyer/go-colorful v1.4.0/go.mod h1:R4dSotOR9KMtayYi1e77YzuveK+i7ruzyGqttikkLy0= github.com/mailru/easyjson v0.7.7 h1:UGYAvKxe3sBsEDzO8ZeWOSlIQfWFlxbzLZe7hwFURr0= github.com/mailru/easyjson v0.7.7/go.mod h1:xzfreul335JAWq5oZzymOObrkdz5UnU4kGfJJLY9Nlc= github.com/mattn/go-colorable v0.1.0/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaOChaDxuIBZU= diff --git a/vendor/github.com/lucasb-eyer/go-colorful/CHANGELOG.md b/vendor/github.com/lucasb-eyer/go-colorful/CHANGELOG.md index a10d3fc8d..3879f14aa 100644 --- a/vendor/github.com/lucasb-eyer/go-colorful/CHANGELOG.md +++ b/vendor/github.com/lucasb-eyer/go-colorful/CHANGELOG.md @@ -8,6 +8,12 @@ but only releases after v1.0.3 properly adhere to it. ## [Unreleased] +## [1.4.0] - 2026-03-28 +### Added +- Constructors, decomposers, and blend functions for the CSS Color Level 4 wide-gamut RGB color spaces `DisplayP3`, `A98Rgb`, `ProPhotoRgb`, and `Rec2020` (#81) +- `XyzD50`, `Color.XyzD50`, `D50ToD65`, and `D65ToD50` for working with D50-based color spaces (#81) +- `HexColor` now implements `fmt.Stringer` + ## [1.3.0] - 2025-09-08 ### Added - `BlendLinearRgb` (#50) @@ -19,7 +25,7 @@ but only releases after v1.0.3 properly adhere to it. - Functions BlendOkLab and BlendOkLch (#70) ## Changed -- `Hex()` parsing is much faster (#78) +- `Hex()` parsing is much faster (#78). However, it doesn't tolerate hex codes with alpha anymore (previously ignoring the alpha was unintentional). ### Fixed - Fix bug when doing HSV/HCL blending between a gray color and non-gray color (#60) diff --git a/vendor/github.com/lucasb-eyer/go-colorful/README.md b/vendor/github.com/lucasb-eyer/go-colorful/README.md index b3bb545cf..1da19f703 100644 --- a/vendor/github.com/lucasb-eyer/go-colorful/README.md +++ b/vendor/github.com/lucasb-eyer/go-colorful/README.md @@ -34,6 +34,8 @@ Go-Colorful stores colors in RGB and provides methods from converting these to v - **CIE LCh(uv):** Called `LuvLCh` in code, this is a cylindrical transformation of the CIE-L\*u\*v\* color space. Like HCL above: H° is in [0..360], C\* almost in [0..1] and L\* as in CIE-L\*u\*v\*. - **HSLuv:** The better alternative to HSL, see [here](https://www.hsluv.org/) and [here](https://www.kuon.ch/post/2020-03-08-hsluv/). Hue in [0..360], Saturation and Luminance in [0..1]. - **HPLuv:** A variant of HSLuv. The color space is smoother, but only pastel colors can be included. Because the valid colors are limited, it's easy to get invalid Saturation values way above 1.0, indicating the color can't be represented in HPLuv because it's not pastel. +- **Oklab:** A perceptual color space by Björn Ottosson that improves on CIE-L\*a\*b\* with better perceptual uniformity, especially for blue hues. L in [0..1], a and b roughly in [-0.5..0.5]. See [Oklab](https://bottosson.github.io/posts/oklab/). +- **Oklch:** The cylindrical (polar) representation of Oklab, similar to HCL. L in [0..1], C roughly in [0..0.5], h° in [0..360]. For the colorspaces where it makes sense (XYZ, Lab, Luv, HCl), the [D65](http://en.wikipedia.org/wiki/Illuminant_D65) is used as reference white @@ -96,6 +98,8 @@ c = colorful.Xyy(0.219895, 0.221839, 0.190837) c = colorful.Lab(0.507850, 0.040585,-0.370945) c = colorful.Luv(0.507849,-0.194172,-0.567924) c = colorful.Hcl(276.2440, 0.373160, 0.507849) +c = colorful.OkLab(0.577227, -0.021391, -0.104541) +c = colorful.OkLch(0.577227, 0.106707, 258.435657) fmt.Printf("RGB values: %v, %v, %v", c.R, c.G, c.B) ``` @@ -109,6 +113,8 @@ x, y, Y := c.Xyy() l, a, b := c.Lab() l, u, v := c.Luv() h, c, l := c.Hcl() +l, a, b = c.OkLab() +l, c, h = c.OkLch() ``` Note that, because of Go's unfortunate choice of requiring an initial uppercase, @@ -190,7 +196,7 @@ it only if you really know what you're doing. It will eat your cat. Blending is highly connected to distance, since it basically "walks through" the colorspace thus, if the colorspace maps distances well, the walk is "smooth". -Colorful comes with blending functions in RGB, HSV and any of the LAB spaces. +Colorful comes with blending functions in RGB, HSV, Oklab, Oklch, and any of the CIE-LAB spaces. Of course, you'd rather want to use the blending functions of the LAB spaces since these spaces map distances well but, just in case, here is an example showing you how the blendings (`#fdffcc` to `#242a42`) are done in the various spaces: @@ -472,11 +478,12 @@ section above. Who? ==== -This library was developed by Lucas Beyer with contributions from -Bastien Dejean (@baskerville), Phil Kulak (@pkulak), Christian Muehlhaeuser (@muesli), and Scott Pakin (@spakin). - -It is now maintained by makeworld (@makew0rld). +This library was originally developed by Lucas Beyer, with notable +contributions from Bastien Dejean (@baskerville), Phil Kulak (@pkulak), +Christian Muehlhaeuser (@muesli), Scott Pakin (@spakin), and many others. +See the [contributors list](https://github.com/lucasb-eyer/go-colorful/graphs/contributors) for the full roster. +It is currently maintained by makeworld (@makew0rld). ## License diff --git a/vendor/github.com/lucasb-eyer/go-colorful/hexcolor.go b/vendor/github.com/lucasb-eyer/go-colorful/hexcolor.go index ad8b06cc9..26f357304 100644 --- a/vendor/github.com/lucasb-eyer/go-colorful/hexcolor.go +++ b/vendor/github.com/lucasb-eyer/go-colorful/hexcolor.go @@ -34,6 +34,10 @@ func (hc *HexColor) Value() (driver.Value, error) { return Color(*hc).Hex(), nil } +func (hc HexColor) String() string { + return Color(hc).Hex() +} + func (e errUnsupportedType) Error() string { return fmt.Sprintf("unsupported type: got %v, want a %s", e.got, e.want) } diff --git a/vendor/github.com/lucasb-eyer/go-colorful/widegamut.go b/vendor/github.com/lucasb-eyer/go-colorful/widegamut.go new file mode 100644 index 000000000..6805a2b96 --- /dev/null +++ b/vendor/github.com/lucasb-eyer/go-colorful/widegamut.go @@ -0,0 +1,290 @@ +package colorful + +import "math" + +// Wide-gamut RGB color spaces from CSS Color Level 4. +// https://www.w3.org/TR/css-color-4/#color-conversion-code + +/// Bradford /// +//////////////// +// Bradford chromatic adaptation between D50 and D65 illuminants. + +func D50ToD65(x, y, z float64) (xo, yo, zo float64) { + xo = 0.9555766*x - 0.0230393*y + 0.0631636*z + yo = -0.0282895*x + 1.0099416*y + 0.0210077*z + zo = 0.0122982*x - 0.0204830*y + 1.3299098*z + return +} + +func D65ToD50(x, y, z float64) (xo, yo, zo float64) { + xo = 1.0479298208405488*x + 0.022946793341019088*y - 0.05019222954313557*z + yo = 0.029627815688159344*x + 0.990434484573249*y - 0.01707382502938514*z + zo = -0.009243058152591178*x + 0.015055144896577895*y + 0.7518742899580008*z + return +} + +/// XYZ D50 /// +/////////////// + +func XyzD50(x, y, z float64) Color { + return Xyz(D50ToD65(x, y, z)) +} + +func (col Color) XyzD50() (x, y, z float64) { + return D65ToD50(col.Xyz()) +} + +/// Display P3 /// +////////////////// +// Uses the sRGB transfer function with DCI-P3 primaries. + +func DisplayP3ToLinearRgb(r, g, b float64) (rl, gl, bl float64) { + rl = linearize(r) + gl = linearize(g) + bl = linearize(b) + return +} + +func LinearDisplayP3ToXyz(r, g, b float64) (x, y, z float64) { + x = 0.4865709486482162*r + 0.26566769316909306*g + 0.1982172852343625*b + y = 0.2289745640697488*r + 0.6917385218365064*g + 0.079286914093745*b + z = 0.04511338185890264*g + 1.043944368900976*b + return +} + +func XyzToLinearDisplayP3(x, y, z float64) (r, g, b float64) { + r = 2.493496911941425*x - 0.9313836179191239*y - 0.40271078445071684*z + g = -0.8294889695615747*x + 1.7626640603183463*y + 0.023624685841943577*z + b = 0.035845830243784335*x - 0.07617238926804182*y + 0.9568845240076872*z + return +} + +func DisplayP3(r, g, b float64) Color { + rl, gl, bl := DisplayP3ToLinearRgb(r, g, b) + x, y, z := LinearDisplayP3ToXyz(rl, gl, bl) + return Xyz(x, y, z) +} + +func (col Color) DisplayP3() (r, g, b float64) { + x, y, z := col.Xyz() + rl, gl, bl := XyzToLinearDisplayP3(x, y, z) + r = delinearize(rl) + g = delinearize(gl) + b = delinearize(bl) + return +} + +// BlendDisplayP3 blends two colors in the Display P3 color-space. +// t == 0 results in c1, t == 1 results in c2 +func (c1 Color) BlendDisplayP3(c2 Color, t float64) Color { + r1, g1, b1 := c1.DisplayP3() + r2, g2, b2 := c2.DisplayP3() + return DisplayP3( + r1+t*(r2-r1), + g1+t*(g2-g1), + b1+t*(b2-b1)) +} + +/// A98 RGB /// +/////////////// +// Adobe RGB (1998) color space. + +func linearizeA98(v float64) float64 { + sign := 1.0 + if v < 0 { + sign = -1.0 + v = -v + } + return sign * math.Pow(v, 563.0/256.0) +} + +func delinearizeA98(v float64) float64 { + sign := 1.0 + if v < 0 { + sign = -1.0 + v = -v + } + return sign * math.Pow(v, 256.0/563.0) +} + +func A98RgbToLinearRgb(r, g, b float64) (rl, gl, bl float64) { + rl = linearizeA98(r) + gl = linearizeA98(g) + bl = linearizeA98(b) + return +} + +func LinearA98RgbToXyz(r, g, b float64) (x, y, z float64) { + x = 0.5766690429101305*r + 0.1855582379065463*g + 0.1882286462349947*b + y = 0.29734497525053605*r + 0.6273635662554661*g + 0.07529145849399788*b + z = 0.02703136138641234*r + 0.07068885253582723*g + 0.9913375368376388*b + return +} + +func XyzToLinearA98Rgb(x, y, z float64) (r, g, b float64) { + r = 2.0415879038107327*x - 0.5650069742788597*y - 0.34473135077832956*z + g = -0.9692436362808795*x + 1.8759675015077202*y + 0.04155505740717559*z + b = 0.013444280632031142*x - 0.11836239223101838*y + 1.0151749943912054*z + return +} + +func A98Rgb(r, g, b float64) Color { + rl, gl, bl := A98RgbToLinearRgb(r, g, b) + x, y, z := LinearA98RgbToXyz(rl, gl, bl) + return Xyz(x, y, z) +} + +func (col Color) A98Rgb() (r, g, b float64) { + x, y, z := col.Xyz() + rl, gl, bl := XyzToLinearA98Rgb(x, y, z) + r = delinearizeA98(rl) + g = delinearizeA98(gl) + b = delinearizeA98(bl) + return +} + +// BlendA98Rgb blends two colors in the A98 RGB color-space. +// t == 0 results in c1, t == 1 results in c2 +func (c1 Color) BlendA98Rgb(c2 Color, t float64) Color { + r1, g1, b1 := c1.A98Rgb() + r2, g2, b2 := c2.A98Rgb() + return A98Rgb( + r1+t*(r2-r1), + g1+t*(g2-g1), + b1+t*(b2-b1)) +} + +/// ProPhoto RGB /// +//////////////////// +// ProPhoto RGB (ROMM RGB) uses D50 illuminant. + +func linearizeProPhoto(v float64) float64 { + if v <= 16.0/512.0 { + return v / 16.0 + } + return math.Pow(v, 1.8) +} + +func delinearizeProPhoto(v float64) float64 { + if v < 1.0/512.0 { + return 16.0 * v + } + return math.Pow(v, 1.0/1.8) +} + +func ProPhotoRgbToLinearRgb(r, g, b float64) (rl, gl, bl float64) { + rl = linearizeProPhoto(r) + gl = linearizeProPhoto(g) + bl = linearizeProPhoto(b) + return +} + +func LinearProPhotoRgbToXyzD50(r, g, b float64) (x, y, z float64) { + x = 0.7977604896723027*r + 0.13518583717574031*g + 0.0313493495815248*b + y = 0.2880711282292934*r + 0.7118432178101014*g + 0.00008565396060525902*b + z = 0.8251046025104602 * b + return +} + +func XyzD50ToLinearProPhotoRgb(x, y, z float64) (r, g, b float64) { + r = 1.3457989731028281*x - 0.25558010007997534*y - 0.05110628506753401*z + g = -0.5446224939028347*x + 1.5082327413132781*y + 0.02053603239147973*z + b = 1.2119675456389454 * z + return +} + +func ProPhotoRgb(r, g, b float64) Color { + rl, gl, bl := ProPhotoRgbToLinearRgb(r, g, b) + x, y, z := LinearProPhotoRgbToXyzD50(rl, gl, bl) + return XyzD50(x, y, z) +} + +func (col Color) ProPhotoRgb() (r, g, b float64) { + x, y, z := col.XyzD50() + rl, gl, bl := XyzD50ToLinearProPhotoRgb(x, y, z) + r = delinearizeProPhoto(rl) + g = delinearizeProPhoto(gl) + b = delinearizeProPhoto(bl) + return +} + +// BlendProPhotoRgb blends two colors in the ProPhoto RGB color-space. +// t == 0 results in c1, t == 1 results in c2 +func (c1 Color) BlendProPhotoRgb(c2 Color, t float64) Color { + r1, g1, b1 := c1.ProPhotoRgb() + r2, g2, b2 := c2.ProPhotoRgb() + return ProPhotoRgb( + r1+t*(r2-r1), + g1+t*(g2-g1), + b1+t*(b2-b1)) +} + +/// Rec. 2020 /// +///////////////// +// ITU-R BT.2020 color space. + +const ( + rec2020Alpha = 1.09929682680944 + rec2020Beta = 0.018053968510807 +) + +func linearizeRec2020(v float64) float64 { + if v < rec2020Beta*4.5 { + return v / 4.5 + } + return math.Pow((v+rec2020Alpha-1)/rec2020Alpha, 1.0/0.45) +} + +func delinearizeRec2020(v float64) float64 { + if v < rec2020Beta { + return 4.5 * v + } + return rec2020Alpha*math.Pow(v, 0.45) - (rec2020Alpha - 1) +} + +func Rec2020ToLinearRgb(r, g, b float64) (rl, gl, bl float64) { + rl = linearizeRec2020(r) + gl = linearizeRec2020(g) + bl = linearizeRec2020(b) + return +} + +func LinearRec2020ToXyz(r, g, b float64) (x, y, z float64) { + x = 0.6369580483012914*r + 0.14461690358620832*g + 0.1688809751641721*b + y = 0.2627002120112671*r + 0.6779980715188708*g + 0.05930171646986196*b + z = 0.028072693049087428*g + 1.0609850577107909*b + return +} + +func XyzToLinearRec2020(x, y, z float64) (r, g, b float64) { + r = 1.7166511879712674*x - 0.35567078377639233*y - 0.25336628137365974*z + g = -0.666684351832489*x + 1.616481236634939*y + 0.0157685458139402*z + b = 0.017639857445310783*x - 0.042770613257808524*y + 0.9421031212354738*z + return +} + +func Rec2020(r, g, b float64) Color { + rl, gl, bl := Rec2020ToLinearRgb(r, g, b) + x, y, z := LinearRec2020ToXyz(rl, gl, bl) + return Xyz(x, y, z) +} + +func (col Color) Rec2020() (r, g, b float64) { + x, y, z := col.Xyz() + rl, gl, bl := XyzToLinearRec2020(x, y, z) + r = delinearizeRec2020(rl) + g = delinearizeRec2020(gl) + b = delinearizeRec2020(bl) + return +} + +// BlendRec2020 blends two colors in the Rec. 2020 color-space. +// t == 0 results in c1, t == 1 results in c2 +func (c1 Color) BlendRec2020(c2 Color, t float64) Color { + r1, g1, b1 := c1.Rec2020() + r2, g2, b2 := c2.Rec2020() + return Rec2020( + r1+t*(r2-r1), + g1+t*(g2-g1), + b1+t*(b2-b1)) +} diff --git a/vendor/modules.txt b/vendor/modules.txt index ebfe30b6a..2f63e9234 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -112,7 +112,7 @@ github.com/kr/logfmt # github.com/kyokomi/emoji/v2 v2.2.8 ## explicit; go 1.14 github.com/kyokomi/emoji/v2 -# github.com/lucasb-eyer/go-colorful v1.3.0 +# github.com/lucasb-eyer/go-colorful v1.4.0 ## explicit; go 1.12 github.com/lucasb-eyer/go-colorful # github.com/mailru/easyjson v0.7.7