limage - xcf/encoder_test.go
1 package xcf
2
3 import (
4 "image"
5 "image/color"
6 "testing"
7
8 "vimagination.zapto.org/limage"
9 "vimagination.zapto.org/memio"
10 )
11
12 /*
13 type colourSquare struct {
14 image.Rectangle
15 color.Color
16 }
17
18 func (c colourSquare) ColorModel() color.Model {
19 return color.ModelFunc(func(color.Color) color.Color {
20 return c.Color
21 })
22 }
23
24 func (c colourSquare) Bounds() image.Rectangle {
25 return c.Rectangle
26 }
27
28 func (c colourSquare) At(int, int) color.Color {
29 return c.Color
30 }
31 */
32
33 func TestEncode(t *testing.T) {
34 tests := []limage.Image{
35 {
36 limage.Layer{
37 Name: "Layer Group",
38 Image: limage.Image{
39 limage.Layer{
40 Name: "Blue",
41 Image: singleColourImage{
42 Colour: color.NRGBA{B: 255, A: 255},
43 Width: 30,
44 Height: 30,
45 },
46 LayerBounds: image.Rect(0, 0, 30, 30),
47 },
48 limage.Layer{
49 Name: "Red",
50 Image: singleColourImage{Colour: color.NRGBA{R: 255, A: 255},
51 Width: 30,
52 Height: 30,
53 },
54 LayerBounds: image.Rect(20, 20, 50, 50),
55 },
56 },
57 LayerBounds: image.Rect(0, 0, 50, 50),
58 },
59 limage.Layer{
60 Name: "Background",
61 Image: singleColourImage{
62 Colour: color.NRGBA{A: 255},
63 Width: 50,
64 Height: 50,
65 },
66 LayerBounds: image.Rect(0, 0, 50, 50),
67 },
68 },
69 {
70 limage.Layer{
71 Name: "Layer",
72 Image: singleColourImage{
73 Colour: color.NRGBA{R: 255, A: 255},
74 Width: 30,
75 Height: 30,
76 },
77 LayerBounds: image.Rect(10, 10, 40, 40),
78 },
79 limage.Layer{
80 Name: "Background",
81 Image: singleColourImage{
82 Colour: color.NRGBA{A: 255},
83 Width: 50,
84 Height: 50,
85 },
86 LayerBounds: image.Rect(0, 0, 50, 50),
87 },
88 },
89 {
90 limage.Layer{
91 Name: "Background",
92 Image: singleColourImage{
93 Colour: color.NRGBA{A: 255},
94 Width: 50,
95 Height: 50,
96 },
97 LayerBounds: image.Rect(0, 0, 50, 50),
98 },
99 },
100 {
101 limage.Layer{
102 Name: "Background",
103 Image: singleColourImage{
104 Colour: color.NRGBA{R: 255, A: 255},
105 Width: 50,
106 Height: 50,
107 },
108 LayerBounds: image.Rect(0, 0, 50, 50),
109 },
110 },
111 {
112 limage.Layer{
113 Name: "Background",
114 Image: singleColourImage{
115 Colour: color.NRGBA{R: 255, G: 255, B: 255, A: 255},
116 Width: 50,
117 Height: 50,
118 },
119 LayerBounds: image.Rect(0, 0, 50, 50),
120 },
121 },
122 }
123
124 buf := make([]byte, 683)
125
126 for n, test := range tests {
127 buf = buf[:0]
128 if err := Encode(memio.Create(&buf), test); err != nil {
129 t.Errorf("test %d: unexpected error: %s", n+1, err)
130 continue
131 }
132 l, err := Decode(memio.Open(buf))
133 if err != nil {
134 t.Errorf("test %d: unexpected error: %s", n+1, err)
135 continue
136 }
137 if err := compareLayers(l, test); err != nil {
138 t.Errorf("test %d: %s", n+1, err)
139 }
140 }
141 }
142