-
Notifications
You must be signed in to change notification settings - Fork 1
/
lab.go
66 lines (50 loc) · 944 Bytes
/
lab.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
61
62
63
64
65
66
package coco
import "math"
func Lab2Xyz(l float64, a float64, b float64) [3]float64 {
var x float64
var y float64
var z float64
y = (l + 16) / 116
x = a/500 + y
z = y - b/200
x2 := math.Pow(x, 3)
y2 := math.Pow(y, 3)
z2 := math.Pow(z, 3)
if x2 > 0.008856 {
x = x2
} else {
x = (x - 16.0/116.0) / 7.787
}
if y2 > 0.008856 {
y = y2
} else {
y = (y - 16.0/116.0) / 7.787
}
if z2 > 0.008856 {
z = z2
} else {
z = (z - 16.0/116.0) / 7.787
}
x *= 95.047
y *= 100
z *= 108.883
var result [3]float64
result[0] = math.Round(x)
result[1] = math.Round(y)
result[2] = math.Round(z)
return result
}
func Lab2Lch(l float64, a float64, b float64) [3]float64 {
var h float64
hr := math.Atan2(b, a)
h = hr * 360.0 / 2.0 / math.Pi
if h < 0 {
h += 360
}
c := math.Sqrt(a*a + b*b)
var result [3]float64
result[0] = math.Round(l)
result[1] = math.Round(c)
result[2] = math.Round(h)
return result
}