mirror of
https://github.com/tinygo-org/drivers.git
synced 2026-07-26 10:38:41 +00:00
pixel: fix Monochrome setPixel
Set/setPixel and Get weren't using the same indices. I've taken the ones used in Get and applied them to setPixel too. This fixes testImageNoise for the monochrome image.
This commit is contained in:
committed by
Ron Evans
parent
0186d0905d
commit
7d7efe25e7
+4
-4
@@ -138,14 +138,14 @@ func (img Image[T]) setPixel(index int, c T) {
|
||||
switch {
|
||||
case zeroColor.BitsPerPixel() == 1:
|
||||
// Monochrome.
|
||||
x := index % int(img.width)
|
||||
offset := index / 8
|
||||
bits := index % 8
|
||||
|
||||
ptr := (*byte)(unsafe.Add(img.data, offset))
|
||||
if c != zeroColor {
|
||||
*((*byte)(ptr)) |= (1 << (7 - uint8(x%8)))
|
||||
*((*byte)(ptr)) |= (1 << (7 - uint8(bits)))
|
||||
} else {
|
||||
*((*byte)(ptr)) &^= (1 << (7 - uint8(x%8)))
|
||||
*((*byte)(ptr)) &^= (1 << (7 - uint8(bits)))
|
||||
}
|
||||
|
||||
return
|
||||
@@ -202,7 +202,7 @@ func (img Image[T]) Get(x, y int) T {
|
||||
// Monochrome.
|
||||
var c Monochrome
|
||||
offset := index / 8
|
||||
bits := index - (offset * 8)
|
||||
bits := index % 8
|
||||
ptr := (*byte)(unsafe.Add(img.data, offset))
|
||||
c = ((*ptr >> (7 - uint8(bits))) & 0x1) > 0
|
||||
return any(c).(T)
|
||||
|
||||
@@ -194,6 +194,9 @@ func TestImageNoise(t *testing.T) {
|
||||
t.Run("RGB444BE", func(t *testing.T) {
|
||||
testImageNoise[pixel.RGB444BE](t)
|
||||
})
|
||||
t.Run("Monochrome", func(t *testing.T) {
|
||||
testImageNoise[pixel.Monochrome](t)
|
||||
})
|
||||
}
|
||||
|
||||
func testImageNoise[T pixel.Color](t *testing.T) {
|
||||
|
||||
Reference in New Issue
Block a user