diff --git a/pixel/image.go b/pixel/image.go index 1a1d26fa6..3275d63ec 100644 --- a/pixel/image.go +++ b/pixel/image.go @@ -43,6 +43,40 @@ func NewImage[T Color](width, height int) Image[T] { } } +// NewImageFromBytes creates a new image of the given size using an existing data slice of bytes. +func NewImageFromBytes[T Color](width, height int, buf []byte) Image[T] { + if width < 0 || height < 0 || int(int16(width)) != width || int(int16(height)) != height { + // The width/height are stored as 16-bit integers and should never be + // negative. + panic("NewImageFromBytes: width/height out of bounds") + } + var zeroColor T + var data unsafe.Pointer + switch { + case zeroColor.BitsPerPixel()%8 == 0: + // Typical formats like RGB888 and RGB565. + // Each color starts at a whole byte offset from the start. + if len(buf) != width*height*int(unsafe.Sizeof(zeroColor)) { + panic("NewImageFromBytes: data slice size mismatch") + } + data = unsafe.Pointer(&buf[0]) + default: + // Formats like RGB444 that have 12 bits per pixel. + // We access these as bytes, so allocate the buffer as a byte slice. + bufBits := width * height * zeroColor.BitsPerPixel() + bufBytes := (bufBits + 7) / 8 + if len(buf) != bufBytes { + panic("NewImageFromBytes: data slice size mismatch") + } + data = unsafe.Pointer(&buf[0]) + } + return Image[T]{ + width: int16(width), + height: int16(height), + data: data, + } +} + // Rescale returns a new Image buffer based on the img buffer. // The contents is undefined after the Rescale operation, and any modification // to the returned image will overwrite the underlying image buffer in undefined @@ -105,14 +139,15 @@ func (img Image[T]) setPixel(index int, c T) { case zeroColor.BitsPerPixel() == 1: // Monochrome. x := index % int(img.width) - y := index / int(img.width) - offset := x + (y/8)*int(img.width) + offset := index / 8 + ptr := (*byte)(unsafe.Add(img.data, offset)) if c != zeroColor { - *((*byte)(ptr)) |= 1 << uint8(y%8) + *((*byte)(ptr)) |= (1 << (7 - uint8(x%8))) } else { - *((*byte)(ptr)) &^= 1 << uint8(y%8) + *((*byte)(ptr)) &^= (1 << (7 - uint8(x%8))) } + return case zeroColor.BitsPerPixel()%8 == 0: // Each color starts at a whole byte offset. @@ -166,9 +201,10 @@ func (img Image[T]) Get(x, y int) T { case zeroColor.BitsPerPixel() == 1: // Monochrome. var c Monochrome - offset := x + (y/8)*int(img.width) + offset := index / 8 + bits := index - (offset * 8) ptr := (*byte)(unsafe.Add(img.data, offset)) - c = (*ptr >> uint8(y%8) & 0x1) == 1 + c = ((*ptr >> (7 - uint8(bits))) & 0x1) > 0 return any(c).(T) case zeroColor.BitsPerPixel()%8 == 0: // Colors like RGB565, RGB888, etc. diff --git a/pixel/image_test.go b/pixel/image_test.go index bb7afc8b2..5e4804c58 100644 --- a/pixel/image_test.go +++ b/pixel/image_test.go @@ -66,9 +66,9 @@ func TestImageRGB444BE(t *testing.T) { } func TestImageMonochrome(t *testing.T) { - image := pixel.NewImage[pixel.Monochrome](5, 3) - if width, height := image.Size(); width != 5 && height != 3 { - t.Errorf("image.Size(): expected 5, 3 but got %d, %d", width, height) + image := pixel.NewImage[pixel.Monochrome](128, 64) + if width, height := image.Size(); width != 128 && height != 64 { + t.Errorf("image.Size(): expected 128, 64 but got %d, %d", width, height) } for _, expected := range []color.RGBA{ {R: 0xff, G: 0xff, B: 0xff}, @@ -80,19 +80,101 @@ func TestImageMonochrome(t *testing.T) { {B: 0x00, A: 0xff}, } { encoded := pixel.NewColor[pixel.Monochrome](expected.R, expected.G, expected.B) - image.Set(4, 2, encoded) - actual := image.Get(4, 2).RGBA() + image.Set(5, 3, encoded) + actual := image.Get(5, 3).RGBA() switch { - case expected.R == 0 && expected.G == 0 && expected.B == 0: - // should be false eg black - if actual.R != 0 || actual.G != 0 || actual.B != 0 { - t.Errorf("failed to roundtrip color: expected %v but got %v", expected, actual) - } case int(expected.R)+int(expected.G)+int(expected.B) > 128*3: // should be true eg white if actual.R == 0 || actual.G == 0 || actual.B == 0 { t.Errorf("failed to roundtrip color: expected %v but got %v", expected, actual) } + default: + // should be false eg black + if actual.R != 0 || actual.G != 0 || actual.B != 0 { + t.Errorf("failed to roundtrip color: expected %v but got %v", expected, actual) + } + } + } +} + +// 128x128 +var rprofile = []byte{ + 0x00, 0x00, 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 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0xFF, 0xFF, 0xFE, + 0x3F, 0xFF, 0xFE, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3F, 0xFF, 0xFE, 0x3F, 0xFF, 0xFC, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3F, 0xFF, 0xFC, + 0x3F, 0xFF, 0xFC, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3F, 0xFF, 0xFE, 0x3F, 0xFF, 0xFC, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3F, 0xFF, 0xFE, + 0x3F, 0xFF, 0xFC, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1F, 0xFF, 0xFE, 0x3F, 0xFF, 0xFC, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3F, 0xFF, 0xFC, + 0x3F, 0xFF, 0xFC, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1F, 0xFF, 0xFE, 0x3F, 0xFF, 0xFC, 0x00, 0x00, 0x00, 0x00, 0xBF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x3F, 0xFF, 0xFE, + 0x3F, 0xFF, 0xFC, 0x01, 0xF8, 0x00, 0x5F, 0xFF, 0xFF, 0xFC, 0x00, 0x02, 0x80, 0x1F, 0xFF, 0xFE, 0x3F, 0xFF, 0xFC, 0x03, 0xFE, 0x03, 0xFF, 0xFD, 0xBF, 0xFF, 0x80, 0x1F, 0xE0, 0x3F, 0xFF, 0xFC, + 0x3F, 0xFF, 0xFC, 0x03, 0xFE, 0x01, 0xFF, 0xF7, 0x6B, 0xFF, 0x80, 0x1F, 0xC0, 0x1F, 0xFF, 0xFE, 0x02, 0xFF, 0xFC, 0x03, 0xDF, 0x17, 0xFA, 0x00, 0x00, 0x37, 0xF0, 0x3F, 0xE0, 0x1F, 0xFF, 0xD0, + 0x00, 0x07, 0xFC, 0x07, 0x07, 0xBF, 0x00, 0x00, 0x00, 0x01, 0xFE, 0xF8, 0x78, 0x3F, 0xF8, 0x00, 0x00, 0x01, 0xFC, 0x06, 0x1B, 0xFC, 0x00, 0x00, 0x00, 0x00, 0x3F, 0xEA, 0x78, 0x1F, 0x80, 0x00, + 0x00, 0x01, 0xFC, 0x03, 0x1B, 0xFE, 0x00, 0x00, 0x00, 0x00, 0x3F, 0xE2, 0x68, 0x1F, 0xC0, 0x00, 0x00, 0x01, 0xFC, 0x07, 0x5B, 0xE8, 0x00, 0x00, 0x00, 0x00, 0x07, 0xC4, 0x38, 0x1F, 0x80, 0x00, + 0x00, 0x01, 0xF8, 0x03, 0x3F, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF7, 0x78, 0x3F, 0xC0, 0x00, 0x00, 0x01, 0xFC, 0x03, 0x1F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7C, 0x68, 0x1F, 0x80, 0x00, + 0x00, 0x01, 0xFC, 0x07, 0x9F, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFC, 0x70, 0x1F, 0x80, 0x00, 0x00, 0x01, 0xFC, 0x03, 0x9E, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x3F, 0x3E, 0xE8, 0x1F, 0xC0, 0x00, + 0x00, 0x01, 0xFC, 0x01, 0xFF, 0xFF, 0xE0, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xE0, 0x1F, 0x80, 0x00, 0x00, 0x01, 0xF8, 0x01, 0xFF, 0x55, 0xF8, 0x00, 0x00, 0x03, 0xEA, 0xFF, 0xC0, 0x1F, 0xC0, 0x00, + 0x00, 0x01, 0xFC, 0x01, 0xFE, 0xAF, 0xF0, 0x00, 0x00, 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, 0x00, 0x00, 0x03, 0x9F, 0xFE, 0x00, + 0x00, 0x5F, 0xFC, 0x38, 0x00, 0x00, 0x01, 0xC3, 0xE8, 0xE0, 0x00, 0x00, 0x03, 0x1F, 0xFB, 0x00, 0x00, 0x01, 0xFC, 0x3C, 0x00, 0x00, 0x01, 0xC7, 0xF8, 0xE0, 0x00, 0x00, 0x07, 0x1F, 0xC0, 0x00, + 0x00, 0x01, 0xFC, 0x3C, 0x00, 0x00, 0x03, 0x9F, 0xFC, 0x70, 0x00, 0x00, 0x07, 0x1F, 0x80, 0x00, 0x00, 0x01, 0xF8, 0x1E, 0x00, 0x00, 0x03, 0xBF, 0xFE, 0x78, 0x00, 0x00, 0x1E, 0x1F, 0xC0, 0x00, + 0x00, 0x01, 0xFC, 0x1E, 0x00, 0x00, 0x07, 0x9F, 0xFF, 0x78, 0x00, 0x00, 0x16, 0x1F, 0x80, 0x00, 0x00, 0x01, 0xFC, 0x1E, 0x00, 0x00, 0x07, 0x73, 0xC3, 0x3C, 0x00, 0x00, 0x1E, 0x1F, 0xC0, 0x00, + 0x00, 0x01, 0xFC, 0x1F, 0x00, 0x00, 0x1E, 0x60, 0x01, 0x9E, 0x00, 0x00, 0x3C, 0x1F, 0x80, 0x00, 0x00, 0x01, 0xF8, 0x1F, 0x80, 0x00, 0x7E, 0x40, 0x01, 0x17, 0x80, 0x00, 0x7E, 0x1F, 0xC0, 0x00, + 0x00, 0x01, 0xFC, 0x1F, 0x80, 0x00, 0x3C, 0x40, 0x01, 0x9F, 0x00, 0x00, 0x7C, 0x1F, 0x80, 0x00, 0x00, 0x01, 0xFC, 0x1F, 0xC0, 0x00, 0xFC, 0x40, 0x01, 0x07, 0xC0, 0x00, 0xFC, 0x1F, 0xC0, 0x00, + 0x00, 0x01, 0xFC, 0x1F, 0xF8, 0x0B, 0xE8, 0x7B, 0xFF, 0x81, 0xF8, 0x03, 0xFC, 0x1F, 0x80, 0x00, 0x00, 0x03, 0xF8, 0x1C, 0xFF, 0x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, 0x1F, 0xFF, 0xFE, 0x7F, 0xFF, 0xFC, 0x3C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1E, 0x1F, 0xFF, 0xFE, + 0x3F, 0xFF, 0xFC, 0x3C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1C, 0x1F, 0xFF, 0xFE, 0x7F, 0xFF, 0xF8, 0x3C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1C, 0x1F, 0xFF, 0xFE, + 0x7F, 0xFF, 0xFC, 0x3C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1E, 0x1F, 0xFF, 0xFE, 0x3F, 0xFF, 0xFC, 0x3C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1C, 0x1F, 0xFF, 0xFE, + 0x7F, 0xFF, 0xFC, 0x38, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x16, 0x1F, 0xFF, 0xFE, 0x0B, 0xFF, 0xF8, 0x3C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1C, 0x1F, 0xFF, 0xF8, + 0x00, 0x7F, 0xFC, 0x3C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1E, 0x1F, 0xFE, 0x00, 0x00, 0x01, 0xFC, 0x3C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1C, 0x1F, 0xC0, 0x00, + 0x00, 0x03, 0xFC, 0x3C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x16, 0x1F, 0x80, 0x00, 0x00, 0x01, 0xF8, 0x3C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1C, 0x1F, 0xC0, 0x00, + 0x00, 0x01, 0xFC, 0x3C, 0x00, 0x00, 0x00, 0x00, 0x00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0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +} + +func TestImageFromBytesMonochrome(t *testing.T) { + image := pixel.NewImageFromBytes[pixel.Monochrome](128, 128, rprofile) + if width, height := image.Size(); width != 128 && height != 128 { + t.Errorf("image.Size(): expected 128, 128 but got %d, %d", width, height) + } + + raw := image.RawBuffer() + for i, b := range raw { + if b != rprofile[i] { + t.Fatalf("failed to roundtrip image. expected %v but got %v", rprofile[i], b) } } }