Skip to content

Commit 3495299

Browse files
committed
Fix #74
Add a workaround for bug adafruit/circuitpython#6675 and use bitmap[x, y] instead of putting data into the bitmap directly through the memoryview for bit depths < 8.
1 parent 8e6af9b commit 3495299

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

adafruit_imageload/png.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,19 @@ def load(
112112
for y in range(height):
113113
dst = y * scanline
114114
src = y * (scanline + 1) + 1
115-
mem[dst : dst + scanline] = data_bytes[src : src + scanline]
115+
if depth < 8:
116+
# Work around the bug in displayio.Bitmap
117+
# https://github.com/adafruit/circuitpython/issues/6675
118+
pixels_per_byte = 8 // depth
119+
for x in range(0, width, pixels_per_byte):
120+
byte = data_bytes[src]
121+
for pixel in range(pixels_per_byte):
122+
bmp[x + pixel, y] = (
123+
byte >> ((pixels_per_byte - pixel - 1) * depth)
124+
) & ((1 << depth) - 1)
125+
src += 1
126+
else:
127+
mem[dst : dst + scanline] = data_bytes[src : src + scanline]
116128
return bmp, pal
117129
# RGB, RGBA or Grayscale
118130
import displayio

0 commit comments

Comments
 (0)