forked from jdeng/goheif
-
Notifications
You must be signed in to change notification settings - Fork 14
/
goheif_test.go
60 lines (49 loc) · 1.09 KB
/
goheif_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
package goheif
import (
"bytes"
"image"
"io"
"io/ioutil"
"testing"
)
func TestFormatRegistered(t *testing.T) {
b, err := ioutil.ReadFile("testdata/camel.heic")
if err != nil {
t.Fatal(err)
}
img, dec, err := image.Decode(bytes.NewReader(b))
if err != nil {
t.Fatalf("unable to decode heic image: %s", err)
}
if got, want := dec, "heic"; got != want {
t.Errorf("unexpected decoder: got %s, want %s", got, want)
}
if w, h := img.Bounds().Dx(), img.Bounds().Dy(); w != 1596 || h != 1064 {
t.Errorf("unexpected decoded image size: got %dx%d, want 1596x1064", w, h)
}
}
func BenchmarkSafeEncoding(b *testing.B) {
benchEncoding(b, true)
}
func BenchmarkRegularEncoding(b *testing.B) {
benchEncoding(b, false)
}
func benchEncoding(b *testing.B, safe bool) {
b.Helper()
currentSetting := SafeEncoding
defer func() {
SafeEncoding = currentSetting
}()
SafeEncoding = safe
f, err := ioutil.ReadFile("testdata/camel.heic")
if err != nil {
b.Fatal(err)
}
r := bytes.NewReader(f)
b.ResetTimer()
b.ReportAllocs()
for i := 0; i < b.N; i++ {
Decode(r)
r.Seek(0, io.SeekStart)
}
}