-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgray.go
70 lines (55 loc) · 1.18 KB
/
gray.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
67
68
69
70
package coco
import (
"math"
"strconv"
"strings"
)
func Gray2Rgb(gray float64) [3]float64 {
var result [3]float64
result[0] = math.Round(gray / 100 * 255)
result[1] = math.Round(gray / 100 * 255)
result[2] = math.Round(gray / 100 * 255)
return result
}
func Gray2Hsl(gray float64) [3]float64 {
var result [3]float64
result[0] = 0
result[1] = 0
result[2] = math.Round(gray)
return result
}
func Gray2Hsv(gray float64) [3]float64 {
var result [3]float64
result[0] = 0
result[1] = 0
result[2] = math.Round(gray)
return result
}
func Gray2Hwb(gray float64) [3]float64 {
var result [3]float64
result[0] = 0
result[1] = 100
result[2] = math.Round(gray)
return result
}
func Gray2Cmyk(gray float64) [4]float64 {
var result [4]float64
result[0] = 0
result[1] = 0
result[2] = 0
result[3] = math.Round(gray)
return result
}
func Gray2Lab(gray float64) [3]float64 {
var result [3]float64
result[0] = math.Round(gray)
result[1] = 0
result[2] = 0
return result
}
func Gray2Hex(gray float64) string {
val := int64(math.Round(gray/100*255)) & 0xFF
integer := (val << 16) + (val << 8) + val
myString := strings.ToUpper(strconv.FormatInt(integer, 16))
return myString
}