-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathpng_test.go
55 lines (49 loc) · 1.02 KB
/
png_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
package imagecoding
import (
"bytes"
"image/png"
"os"
"testing"
"github.com/Nr90/imgsim"
"github.com/stretchr/testify/assert"
)
func TestEncodePng(t *testing.T) {
var buf bytes.Buffer
imgbytes, err := EncodePng(&buf, img)
assert.NoError(t, err)
output, err := png.Decode(bytes.NewReader(imgbytes))
assert.NoError(t, err)
outputHash := imgsim.AverageHash(output)
assert.Equal(t, ref, outputHash)
}
func BenchmarkPNG(b *testing.B) {
var err error
var buf bytes.Buffer
buf.Grow(10 << 20)
for n := 0; n < b.N; n++ {
_, err = EncodePng(&buf, img)
if err != nil {
b.Log(err)
b.FailNow()
}
}
}
func BenchmarkPNGComplex(b *testing.B) {
sample, err := os.ReadFile("testdata/world-political.jpg")
if !assert.NoError(b, err) {
b.FailNow()
}
img, _, _, _, err := TransformJpeg(sample, true, DefaultScale)
if !assert.NoError(b, err) {
b.FailNow()
}
var buf bytes.Buffer
buf.Grow(10 << 20)
for n := 0; n < b.N; n++ {
_, err = EncodePng(&buf, img)
if err != nil {
b.Log(err)
b.FailNow()
}
}
}