-
Notifications
You must be signed in to change notification settings - Fork 0
/
color.go
60 lines (49 loc) · 1.13 KB
/
color.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
package imeji
import (
"github.com/lucasb-eyer/go-colorful"
"image/color"
)
func darkest(colors ...color.Color) color.Color {
var darkest color.Color
darkestValue := 101.0
for i := range colors {
col, _ := colorful.MakeColor(colors[i])
_, _, l := col.Hsl()
if l < darkestValue {
darkestValue = l
darkest = colors[i]
}
}
return darkest
}
func lightest(colors ...color.Color) color.Color {
var lightest color.Color
lightestValue := -1.0
for i := range colors {
col, _ := colorful.MakeColor(colors[i])
_, _, l := col.Hsl()
if l > lightestValue {
lightestValue = l
lightest = colors[i]
}
}
return lightest
}
func sq(v uint32) uint32 {
return v * v
}
func diff(a color.Color, b color.Color) float64 {
ar, ag, ab, _ := a.RGBA()
br, bg, bb, _ := b.RGBA()
return float64(sq(ar-br) + sq(ag-bg) + sq(ab-bb))
}
func diffSlow(a color.Color, b color.Color) float64 {
ac, _ := colorful.MakeColor(a)
bc, _ := colorful.MakeColor(b)
return ac.DistanceRgb(bc)
}
func diffSlowest(a color.Color, b color.Color) float64 {
ac, _ := colorful.MakeColor(a)
bc, _ := colorful.MakeColor(b)
return ac.DistanceLab(bc)
}