-
-
Notifications
You must be signed in to change notification settings - Fork 11
/
gimp_test.go
77 lines (68 loc) · 2.45 KB
/
gimp_test.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
71
72
73
74
75
76
77
package colorgrad
import (
"math"
"strings"
"testing"
)
func Test_GIMPGradient(t *testing.T) {
black := Rgb(0, 0, 0, 1)
red := Rgb(1, 0, 0, 1)
blue := Rgb(0, 0, 1, 1)
// Black to white
ggr := "GIMP Gradient\nName: My Gradient\n1\n0 0.5 1 0 0 0 1 1 1 1 1 0 0 0 0"
grad, name, err := ParseGgr(strings.NewReader(ggr), black, black)
test(t, err, nil)
test(t, name, "My Gradient")
test(t, grad.At(0).HexString(), "#000000")
test(t, grad.At(1).HexString(), "#ffffff")
test(t, grad.At(-0.5).HexString(), "#000000")
test(t, grad.At(1.5).HexString(), "#ffffff")
test(t, grad.At(math.NaN()).HexString(), "#000000")
// Foreground to background
ggr = "GIMP Gradient\nName: My Gradient\n1\n0 0.5 1 0 0 0 1 1 1 1 1 0 0 1 3"
grad, name, err = ParseGgr(strings.NewReader(ggr), red, blue)
test(t, err, nil)
test(t, name, "My Gradient")
test(t, grad.At(0).HexString(), "#ff0000")
test(t, grad.At(1).HexString(), "#0000ff")
// Blending function: step
ggr = "GIMP Gradient\nName: My Gradient\n1\n0 0.5 1 1 0 0 1 0 0 1 1 5 0 0 0"
grad, name, err = ParseGgr(strings.NewReader(ggr), black, black)
test(t, err, nil)
test(t, name, "My Gradient")
test(t, grad.At(0.00).HexString(), "#ff0000")
test(t, grad.At(0.25).HexString(), "#ff0000")
test(t, grad.At(0.49).HexString(), "#ff0000")
test(t, grad.At(0.51).HexString(), "#0000ff")
test(t, grad.At(0.75).HexString(), "#0000ff")
test(t, grad.At(1.00).HexString(), "#0000ff")
// Coloring type: HSV CCW (white to blue)
ggr = "GIMP Gradient\nName: My Gradient\n1\n0 0.5 1 1 1 1 1 0 0 1 1 0 1 0 0"
grad, name, err = ParseGgr(strings.NewReader(ggr), black, black)
test(t, err, nil)
test(t, name, "My Gradient")
test(t, grad.At(0.0).HexString(), "#ffffff")
test(t, grad.At(0.5).HexString(), "#80ff80")
test(t, grad.At(1.0).HexString(), "#0000ff")
// Coloring type: HSV CW (white to blue)
ggr = "GIMP Gradient\nName: My Gradient\n1\n0 0.5 1 1 1 1 1 0 0 1 1 0 2 0 0"
grad, name, err = ParseGgr(strings.NewReader(ggr), black, black)
test(t, err, nil)
test(t, name, "My Gradient")
test(t, grad.At(0.0).HexString(), "#ffffff")
test(t, grad.At(0.5).HexString(), "#ff80ff")
test(t, grad.At(1.0).HexString(), "#0000ff")
// Invalid formats
data := []string{
"",
" ",
"GIMP Palette\nName: Gold\n#\n252 252 128",
"GIMP Gradient\nxx",
"GIMP Gradient\nName: Gradient\nx",
"GIMP Gradient\nName: Gradient\n1\n0 0 0",
}
for _, s := range data {
_, _, err := ParseGgr(strings.NewReader(s), black, black)
testTrue(t, err != nil)
}
}