ssa
1package goroi
2
3import "math"
4
5// RGB2HSV converts RGB color to HSV (HSB)
6func RGB2HSV(R, G, B float64) (H, S, V float64) {
7max := math.Max(math.Max(R, G), B)
8min := math.Min(math.Min(R, G), B)
9h, s, v := 0.0, 0.0, max
10if max != min {
11d := max - min
12s = d / max
13h = calcHUE(max, R, G, B, d)
14}
15return h, s, v
16}
17func calcHUE(max, r, g, b, d float64) float64 {
18var h float64
19switch max {
20case r:
21if g < b {
22h = (g-b)/d + 6.0
23} else {
24h = (g - b) / d
25}
26case g:
27h = (b-r)/d + 2.0
28case b:
29h = (r-g)/d + 4.0
30}
31return h / 6
32}
33