-
Notifications
You must be signed in to change notification settings - Fork 13
/
image_test.go
78 lines (74 loc) · 1.65 KB
/
image_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
70
71
72
73
74
75
76
77
78
// Copyright 2021 Frederik Zipp. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package canvas
import (
"image"
"image/color"
"testing"
"github.com/google/go-cmp/cmp"
)
func TestEnsureRGBA(t *testing.T) {
tests := []struct {
name string
img image.Image
want *image.RGBA
}{
{
"Gray",
&image.Gray{
Pix: []uint8{
0x00, 0x4a,
0xb0, 0x12,
0xff, 0xa0,
},
Stride: 2,
Rect: image.Rect(0, 0, 2, 3),
},
&image.RGBA{
Pix: []uint8{
0x00, 0x00, 0x00, 0xff, 0x4a, 0x4a, 0x4a, 0xff,
0xb0, 0xb0, 0xb0, 0xff, 0x12, 0x12, 0x12, 0xff,
0xff, 0xff, 0xff, 0xff, 0xa0, 0xa0, 0xa0, 0xff,
},
Stride: 8,
Rect: image.Rect(0, 0, 2, 3),
},
},
{
"Paletted",
&image.Paletted{
Pix: []uint8{
0x01, 0x02,
0x03, 0x01,
0x00, 0x02,
},
Stride: 2,
Rect: image.Rect(0, 0, 2, 3),
Palette: color.Palette{
color.RGBA{R: 0xa1, G: 0xa2, B: 0xa3, A: 0xa4},
color.RGBA{R: 0xb1, G: 0xb2, B: 0xb3, A: 0xb4},
color.RGBA{R: 0xc1, G: 0xc2, B: 0xc3, A: 0xc4},
color.RGBA{R: 0xd1, G: 0xd2, B: 0xd3, A: 0xd4},
},
},
&image.RGBA{
Pix: []uint8{
0xb1, 0xb2, 0xb3, 0xb4, 0xc1, 0xc2, 0xc3, 0xc4,
0xd1, 0xd2, 0xd3, 0xd4, 0xb1, 0xb2, 0xb3, 0xb4,
0xa1, 0xa2, 0xa3, 0xa4, 0xc1, 0xc2, 0xc3, 0xc4,
},
Stride: 8,
Rect: image.Rect(0, 0, 2, 3),
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got := ensureRGBA(tt.img)
if diff := cmp.Diff(tt.want, got); diff != "" {
t.Errorf("mismatch (-want +got):\n%s", diff)
}
})
}
}