-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutil.go
49 lines (33 loc) · 958 Bytes
/
util.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
package hue
import (
"image/color"
"github.com/lucasb-eyer/go-colorful"
)
func Bool(v bool) *bool { return &v }
func Int(v int) *int { return &v }
func UInt8(v uint8) *uint8 { return &v }
func Int64(v int64) *int64 { return &v }
func String(v string) *string { return &v }
func Slice(v []string) *[]string { return &v }
func colorToHSV(clr color.Color) (uint16, uint8, uint8, bool) {
hueclr, ok := colorful.MakeColor(clr)
if !ok {
return 0, 0, 0, false
}
hue, sat, val := hueclr.Hsv()
hueVal := uint16((hue * 65535) / 360)
satVal := uint8(sat * 255)
briVal := uint8(val * 255)
return hueVal, satVal, briVal, true
}
func hexColorToHSV(hexColor string) (uint16, uint8, uint8, bool) {
hueclr, err := colorful.Hex(hexColor)
if err != nil {
return 0, 0, 0, false
}
hue, sat, val := hueclr.Hsv()
hueVal := uint16((hue * 65535) / 360)
satVal := uint8(sat * 255)
briVal := uint8(val * 255)
return hueVal, satVal, briVal, true
}