You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When the frame buffer has a width that's not a multiple of 4, pixels at the edge are misallocated.
I've put together the following as an example:
BLACK = 1
RED = 2
WHITE = 3
WIDTH = 7
HEIGHT = 2
buffer = bytearray(math.ceil((WIDTH * HEIGHT) / 4))
fb = adafruit_framebuf.FrameBuffer(
buffer, WIDTH, HEIGHT, buf_format=adafruit_framebuf.GS2_HMSB,
)
fb.fill(WHITE)
def print_arr(a):
"Print the byte array as paired bytes"
n = 2
a = ''.join([f'{v:08b}' for v in a])
a = [a[i:i + n] for i in range(0, len(a), n)]
for r in range(HEIGHT):
print(' '.join(a[r*WIDTH:(r+1)*WIDTH]))
print(' '.join(a[(r+1)*WIDTH:]))
color_map = {3:'_', 2: '*', 1: '#'}
def print_buffer(the_fb):
print("+" * (the_fb.width + 2))
for y in range(the_fb.height):
print("+", end="")
for x in range(the_fb.width):
c = fb.pixel(x, y)
print(color_map[c], end="")
print("+")
print("+" * (the_fb.width + 2))
class GS2HMSBFormat:
@staticmethod
def get_pixel(framebuf, x, y):
"""Get the color of a given pixel"""
index = (y * framebuf.stride + x) >> 2
pixel = framebuf.buf[index]
# shift = (x & 0b11) << 1
shift = ((y * framebuf.stride + x) & 0b11) << 1 # Update to use the absolute index of the pixel
return (pixel >> shift) & 0b11
When the frame buffer has a width that's not a multiple of 4, pixels at the edge are misallocated.
I've put together the following as an example:
Using the above, setup:
gives
The same result occurs with
fb.pixel(0,1, RED)
as well.The text was updated successfully, but these errors were encountered: