adafruit / adafruit/Adafruit_CircuitPython_framebuf

Misallocated Pixels when GS2HMSBFormat has a width that's not a multiple of 4

Open
#60 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
Python
Stars
42
Forks
36
PR merge metrics
No merged PRs in 30d

Description

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))
```

Using the above, setup:
```
fb.pixel(4,0, RED)
print_arr(fb.buf)
print_buffer(fb)
```
gives
```
11 11 11 11 11 11 11
10 11 11 11 11 11 11
11 11

+++++++++
+____*__+
+*______+
+++++++++
```
The same result occurs with `fb.pixel(0,1, RED)` as well.

Contributor guide

No contributing guide indexed for this repository

Research direction

Reproduce the issue with adafruit_framebuf.FrameBuffer using GS2_HMSB, WIDTH=7, HEIGHT=2, and the provided pixel calls. Start by tracing pixel() and the framebuffer packing represented by fb.buf. Done means edge pixels remain in their intended positions for widths that are not multiples of four, including the supplied examples.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
embedded-iot
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.