From 5847506ba6123ada1140f83d8f5cdd8414567ac5 Mon Sep 17 00:00:00 2001 From: sago35 Date: Mon, 10 Nov 2025 19:33:18 +0900 Subject: [PATCH] Add TestImageRGB888 and TestImageRGB555 --- pixel/image_test.go | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/pixel/image_test.go b/pixel/image_test.go index 1feef75..b0963b1 100644 --- a/pixel/image_test.go +++ b/pixel/image_test.go @@ -9,6 +9,27 @@ import ( "tinygo.org/x/drivers/pixel" ) +func TestImageRGB888(t *testing.T) { + image := pixel.NewImage[pixel.RGB888](5, 3) + if width, height := image.Size(); width != 5 || height != 3 { + t.Errorf("image.Size(): expected 5, 3 but got %d, %d", width, height) + } + for _, c := range []color.RGBA{ + {R: 0xff, A: 0xff}, + {G: 0xff, A: 0xff}, + {B: 0xff, A: 0xff}, + {R: 0x10, A: 0xff}, + {G: 0x10, A: 0xff}, + {B: 0x10, A: 0xff}, + } { + image.Set(4, 2, pixel.NewColor[pixel.RGB888](c.R, c.G, c.B)) + c2 := image.Get(4, 2).RGBA() + if c2 != c { + t.Errorf("failed to roundtrip color: expected %v but got %v", c, c2) + } + } +} + func TestImageRGB565BE(t *testing.T) { image := pixel.NewImage[pixel.RGB565BE](5, 3) if width, height := image.Size(); width != 5 || height != 3 { @@ -30,6 +51,27 @@ func TestImageRGB565BE(t *testing.T) { } } +func TestImageRGB555(t *testing.T) { + image := pixel.NewImage[pixel.RGB555](5, 3) + if width, height := image.Size(); width != 5 || height != 3 { + t.Errorf("image.Size(): expected 5, 3 but got %d, %d", width, height) + } + for _, c := range []color.RGBA{ + {R: 0xff, A: 0xff}, + {G: 0xff, A: 0xff}, + {B: 0xff, A: 0xff}, + {R: 0x10, A: 0xff}, + {G: 0x10, A: 0xff}, + {B: 0x10, A: 0xff}, + } { + image.Set(4, 2, pixel.NewColor[pixel.RGB555](c.R, c.G, c.B)) + c2 := image.Get(4, 2).RGBA() + if c2 != c { + t.Errorf("failed to roundtrip color: expected %v but got %v", c, c2) + } + } +} + func TestImageRGB444BE(t *testing.T) { image := pixel.NewImage[pixel.RGB444BE](5, 3) if width, height := image.Size(); width != 5 || height != 3 {