Skip to content

Commit 5847506

Browse files
sago35deadprogram
authored andcommitted
Add TestImageRGB888 and TestImageRGB555
1 parent e35e6b8 commit 5847506

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

pixel/image_test.go

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,27 @@ import (
99
"tinygo.org/x/drivers/pixel"
1010
)
1111

12+
func TestImageRGB888(t *testing.T) {
13+
image := pixel.NewImage[pixel.RGB888](5, 3)
14+
if width, height := image.Size(); width != 5 || height != 3 {
15+
t.Errorf("image.Size(): expected 5, 3 but got %d, %d", width, height)
16+
}
17+
for _, c := range []color.RGBA{
18+
{R: 0xff, A: 0xff},
19+
{G: 0xff, A: 0xff},
20+
{B: 0xff, A: 0xff},
21+
{R: 0x10, A: 0xff},
22+
{G: 0x10, A: 0xff},
23+
{B: 0x10, A: 0xff},
24+
} {
25+
image.Set(4, 2, pixel.NewColor[pixel.RGB888](c.R, c.G, c.B))
26+
c2 := image.Get(4, 2).RGBA()
27+
if c2 != c {
28+
t.Errorf("failed to roundtrip color: expected %v but got %v", c, c2)
29+
}
30+
}
31+
}
32+
1233
func TestImageRGB565BE(t *testing.T) {
1334
image := pixel.NewImage[pixel.RGB565BE](5, 3)
1435
if width, height := image.Size(); width != 5 || height != 3 {
@@ -30,6 +51,27 @@ func TestImageRGB565BE(t *testing.T) {
3051
}
3152
}
3253

54+
func TestImageRGB555(t *testing.T) {
55+
image := pixel.NewImage[pixel.RGB555](5, 3)
56+
if width, height := image.Size(); width != 5 || height != 3 {
57+
t.Errorf("image.Size(): expected 5, 3 but got %d, %d", width, height)
58+
}
59+
for _, c := range []color.RGBA{
60+
{R: 0xff, A: 0xff},
61+
{G: 0xff, A: 0xff},
62+
{B: 0xff, A: 0xff},
63+
{R: 0x10, A: 0xff},
64+
{G: 0x10, A: 0xff},
65+
{B: 0x10, A: 0xff},
66+
} {
67+
image.Set(4, 2, pixel.NewColor[pixel.RGB555](c.R, c.G, c.B))
68+
c2 := image.Get(4, 2).RGBA()
69+
if c2 != c {
70+
t.Errorf("failed to roundtrip color: expected %v but got %v", c, c2)
71+
}
72+
}
73+
}
74+
3375
func TestImageRGB444BE(t *testing.T) {
3476
image := pixel.NewImage[pixel.RGB444BE](5, 3)
3577
if width, height := image.Size(); width != 5 || height != 3 {

0 commit comments

Comments
 (0)