2012-03-05 01:45:47 +01:00
|
|
|
// Copyright 2012 The Go Authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
|
|
|
package tiff
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
2012-06-07 01:41:24 +02:00
|
|
|
"image"
|
|
|
|
"io/ioutil"
|
2012-03-05 01:45:47 +01:00
|
|
|
"os"
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
|
|
|
var roundtripTests = []string{
|
|
|
|
"video-001.tiff",
|
|
|
|
"bw-packbits.tiff",
|
|
|
|
}
|
|
|
|
|
2012-06-07 01:41:24 +02:00
|
|
|
func openImage(filename string) (image.Image, error) {
|
|
|
|
f, err := os.Open(testdataDir + filename)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
defer f.Close()
|
|
|
|
return Decode(f)
|
|
|
|
}
|
|
|
|
|
2012-03-05 01:45:47 +01:00
|
|
|
func TestRoundtrip(t *testing.T) {
|
|
|
|
for _, filename := range roundtripTests {
|
2012-06-07 01:41:24 +02:00
|
|
|
img, err := openImage(filename)
|
2012-03-05 01:45:47 +01:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
out := new(bytes.Buffer)
|
|
|
|
err = Encode(out, img)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
img2, err := Decode(&buffer{buf: out.Bytes()})
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
compare(t, img, img2)
|
|
|
|
}
|
|
|
|
}
|
2012-06-07 01:41:24 +02:00
|
|
|
|
|
|
|
// BenchmarkEncode benchmarks the encoding of an image.
|
|
|
|
func BenchmarkEncode(b *testing.B) {
|
|
|
|
img, err := openImage("video-001.tiff")
|
|
|
|
if err != nil {
|
|
|
|
b.Fatal(err)
|
|
|
|
}
|
|
|
|
s := img.Bounds().Size()
|
|
|
|
b.SetBytes(int64(s.X * s.Y * 4))
|
|
|
|
b.ResetTimer()
|
|
|
|
for i := 0; i < b.N; i++ {
|
|
|
|
Encode(ioutil.Discard, img)
|
|
|
|
}
|
|
|
|
}
|