-
Notifications
You must be signed in to change notification settings - Fork 0
/
decoder_test.go
50 lines (45 loc) · 987 Bytes
/
decoder_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
package pcx
import (
"fmt"
"image/png"
"os"
"path/filepath"
"testing"
)
func TestDecoder(t *testing.T) {
savePNG := os.Getenv("PCX_TEST_SAVE") != ""
testImages, err := filepath.Glob("testfiles/*.pcx")
if err != nil {
t.Fatal(err)
}
for _, filename := range testImages {
file, err := os.Open(filename)
if err != nil {
t.Fatal(err)
}
d, err := newDecoder(file)
if err != nil {
t.Errorf("Failed to read header for %s: %s", filename, err.Error())
file.Close()
continue
}
t.Logf("%s : %dx%d version:%d pb4:%+v nplanes:%d bpp:%d", filename, d.bounds.Dx(), d.bounds.Dy(), d.version, d.pb4, d.nplanes, d.bpp)
img, err := d.decode()
file.Close()
if err != nil {
t.Errorf("Failed to decode %s: %s", filename, err.Error())
continue
}
if savePNG {
w, err := os.Create(fmt.Sprintf("out-%s.png", filename))
if err != nil {
t.Fatal(err)
}
err = png.Encode(w, img)
w.Close()
if err != nil {
t.Fatal(err)
}
}
}
}