-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathface_test.go
132 lines (104 loc) · 2.42 KB
/
face_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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
package skin_test
import (
"fmt"
"image/png"
"os"
"strconv"
"testing"
"github.com/mineatar-io/skin-render"
)
var (
writeRenders = os.Getenv("WRITE_RENDERS") == "true"
defaultBenchmarkRenderScale = 4
)
func init() {
if v := os.Getenv("RENDER_SCALE"); len(v) > 0 {
value, err := strconv.ParseUint(v, 10, 32)
if err != nil {
panic(err)
}
defaultBenchmarkRenderScale = int(value)
}
}
func TestFaceSteve(t *testing.T) {
rawSkin := skin.GetDefaultSkin(false)
for i := 0; i <= 8; i++ {
scale := 1 << i
output := skin.RenderFace(rawSkin, skin.Options{
Scale: scale,
Overlay: true,
Slim: false,
Square: false,
})
if output.Bounds().Dx() < 1 {
t.Fatalf("result image width is %d pixels\n", output.Bounds().Dx())
}
if output.Bounds().Dy() < 1 {
t.Fatalf("result image height is %d pixels\n", output.Bounds().Dy())
}
if writeRenders {
f, err := os.OpenFile(fmt.Sprintf("face_steve_test_%d.png", scale), os.O_CREATE|os.O_RDWR, 0777)
if err != nil {
t.Fatal(err)
}
if err = png.Encode(f, output); err != nil {
t.Fatal(err)
}
if err = f.Close(); err != nil {
t.Fatal(err)
}
}
}
}
func BenchmarkFaceSteve(b *testing.B) {
rawSkin := skin.GetDefaultSkin(false)
for n := 0; n <= b.N; n++ {
skin.RenderFace(rawSkin, skin.Options{
Scale: defaultBenchmarkRenderScale,
Overlay: true,
Slim: false,
Square: false,
})
}
}
func TestFaceAlex(t *testing.T) {
rawSkin := skin.GetDefaultSkin(true)
for i := 0; i <= 8; i++ {
scale := 1 << i
output := skin.RenderFace(rawSkin, skin.Options{
Scale: scale,
Overlay: true,
Slim: true,
Square: false,
})
if output.Bounds().Dx() < 1 {
t.Fatalf("result image width is %d pixels\n", output.Bounds().Dx())
}
if output.Bounds().Dy() < 1 {
t.Fatalf("result image height is %d pixels\n", output.Bounds().Dy())
}
if writeRenders {
f, err := os.OpenFile(fmt.Sprintf("face_alex_test_%d.png", scale), os.O_CREATE|os.O_RDWR, 0777)
if err != nil {
t.Fatal(err)
}
if err = png.Encode(f, output); err != nil {
t.Fatal(err)
}
if err = f.Close(); err != nil {
t.Fatal(err)
}
}
}
}
func BenchmarkFaceAlex(b *testing.B) {
rawSkin := skin.GetDefaultSkin(true)
for n := 0; n <= b.N; n++ {
skin.RenderFace(rawSkin, skin.Options{
Scale: defaultBenchmarkRenderScale,
Overlay: true,
Slim: true,
Square: false,
})
}
}