-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
draw_test.go
53 lines (48 loc) · 1.12 KB
/
draw_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
package ilda
import (
"image"
"image/color"
"image/gif"
"os"
"path/filepath"
"strings"
"testing"
)
func TestDraw(t *testing.T) {
files, err := filepath.Glob("testdata/*.ild")
if err != nil {
t.Fatal(err)
}
for _, file := range files {
t.Run(filepath.Base(file), func(t *testing.T) {
ild, err := os.Open(file)
if err != nil {
t.Fatal(err)
}
defer ild.Close()
frames, err := NewDecoder(ild).AllFrames()
if err != nil {
t.Fatal(err)
}
if testing.Short() && len(frames) > 1 {
t.Skip("skip animation")
}
bg := image.NewUniform(color.Black)
pal := append(DefaultPalette, color.Black, color.Transparent)
r := image.Rect(0, 0, 640, 640)
images := make([]*image.Paletted, len(frames))
delays := make([]int, len(frames))
for i, frame := range frames {
images[i] = image.NewPaletted(r, pal)
delays[i] = 4 // 25Hz
frame.Draw(images[i], r, bg, image.ZP)
}
out, err := os.Create(strings.TrimSuffix(file, filepath.Ext(file)) + ".gif")
if err != nil {
t.Fatal(err)
}
defer out.Close()
gif.EncodeAll(out, &gif.GIF{Image: images, Delay: delays})
})
}
}