forked from sugyan/ttygif
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mapped_test.go
69 lines (51 loc) · 993 Bytes
/
mapped_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
package xwd
import (
"bytes"
"image/png"
"testing"
_ "embed"
)
//go:embed 8colors.xwd
var xwd8colors []byte
//go:embed 8colors.png
var png8colors []byte
func TestMappedImage(t *testing.T) {
rdr := bytes.NewReader(xwd8colors)
hdr, err := ReadHeader(rdr)
if err != nil {
t.Fatal(err)
}
t.Log(hdr)
colors, err := ReadColorMap(rdr, hdr)
if err != nil {
t.Fatal(err)
}
t.Logf("Color map (%d entries):", len(colors))
for _, c := range colors {
t.Log(c.String())
}
p, err := ReadPixmap(rdr, hdr, &colors)
if err != nil {
t.Fatal(err)
}
pngImage, err := png.Decode(bytes.NewReader(png8colors))
if err != nil {
t.Fatal(err)
}
/*t.Log("\n" + imageToString(p))
t.Log("\n" + imageToString(pngImage))*/
if !ImageEqual(p, pngImage, 0) {
t.Fatal("images differ")
}
/*if !t.Failed() {
t.Log("All colors equal")
}
dump, err := os.Create("dump.png")
if err != nil {
t.Fatal(err)
}
err = png.Encode(dump, p)
if err != nil {
t.Fatal(err)
}*/
}