-
Notifications
You must be signed in to change notification settings - Fork 0
/
integration_test.go
98 lines (86 loc) · 2.07 KB
/
integration_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
package got6
import (
"bytes"
"image"
"image/gif"
"image/png"
"io/ioutil"
"os"
"testing"
)
var testImageNames = []string{"red"}
var benchmarkImageNames = []string{"red"}
func sample(name string) []byte {
data, err := ioutil.ReadFile("testdata/" + name + ".tiff")
if err != nil {
panic(err)
}
return data[8:] // strip TIFF header
}
func prototype(name string) (result image.Image) {
file, err := os.Open("testdata/" + name + ".gif")
if err != nil {
panic(err)
}
defer file.Close()
result, err = gif.Decode(file)
if err != nil {
panic(err)
}
return result
}
func TestFullDecode(t *testing.T) {
for _, name := range testImageNames {
failFile := name + "-fail.png"
os.Remove(failFile)
expected := prototype(name)
bounds := expected.Bounds()
reader := bytes.NewBuffer(sample(name))
result, err := DecodeG4(reader, bounds.Dx(), bounds.Dy())
if err != nil {
t.Fatalf("decode %s gave %s", name, err)
}
if !bounds.Eq(result.Bounds()) {
t.Fatalf("%s bound to %#v", name, result.Bounds())
}
for x := bounds.Min.X; x < bounds.Max.X; x++ {
for y := bounds.Min.Y; y < bounds.Max.Y; y++ {
ra, ga, ba, aa := result.At(x, y).RGBA()
rb, gb, bb, ab := expected.At(x, y).RGBA()
if ra != rb || ga != gb || ba != bb || aa != ab {
file, err := os.Create(failFile)
if err != nil {
t.Fatalf("create %s gave %s", failFile, err)
}
defer file.Close()
err = png.Encode(file, result)
if err != nil {
t.Fatalf("encode %s gave %s", failFile, err)
}
t.Error("recorded mismatch:", failFile)
}
}
}
}
}
func BenchmarkFullDecode(b *testing.B) {
b.StopTimer()
var pixelCount int64
for _, name := range benchmarkImageNames {
data := sample(name)
bounds := prototype(name).Bounds()
width := bounds.Dx()
height := bounds.Dy()
pixelCount += int64(width * height)
for remaining := b.N; remaining > 0; remaining-- {
reader := bytes.NewBuffer(data)
b.StartTimer()
_, err := DecodeG4(reader, width, height)
b.StopTimer()
if err != nil {
b.Fatal(err)
}
}
}
b.SetBytes(pixelCount)
}