Skip to content

Commit c23d736

Browse files
committed
Use workaround for older versions of CircuitPython
1 parent 82c0841 commit c23d736

File tree

1 file changed

+16
-14
lines changed

1 file changed

+16
-14
lines changed

adafruit_imageload/png.py

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
except ImportError:
2626
pass
2727

28+
from sys import implementation
2829
import struct
2930
import zlib
3031

@@ -112,22 +113,23 @@ def load( # noqa: PLR0912, PLR0915, Too many branches, Too many statements
112113
filladj = y * ((4 - (scanline % 4)) % 4)
113114
dst = y * scanline + filladj
114115
src = y * (scanline + 1) + 1
115-
# Work around the bug in displayio.Bitmap - removed afer resolution
116-
# however left here as comments because it's helpful in
117-
# understanding the memoryview scanline and adjustment calculations
116+
# Work around the bug in displayio.Bitmap
117+
# remove once CircuitPython 9.1 is no longer supported
118118
# https://github.com/adafruit/circuitpython/issues/6675
119119
# https://github.com/adafruit/circuitpython/issues/9707
120-
#
121-
# pixels_per_byte = 8 // depth
122-
# for x in range(0, width, pixels_per_byte):
123-
# byte = data_bytes[src]
124-
# for pixel in range(pixels_per_byte):
125-
# bmp[x + pixel, y] = (byte >> ((pixels_per_byte - pixel - 1) * depth)) & (
126-
# (1 << depth) - 1
127-
# )
128-
# src += 1
129-
#
130-
mem[dst : dst + scanline] = data_bytes[src : src + scanline]
120+
if ((implementation[1][0] == 9 and implementation[1][1] < 2) or
121+
implementation[1][0] < 9) and (depth < 8 or width % 4 != 0):
122+
123+
pixels_per_byte = 8 // depth
124+
for x in range(0, width, pixels_per_byte):
125+
byte = data_bytes[src]
126+
for pixel in range(pixels_per_byte):
127+
bmp[x + pixel, y] = (byte >> ((pixels_per_byte - pixel - 1) * depth)) & (
128+
(1 << depth) - 1
129+
)
130+
src += 1
131+
else:
132+
mem[dst : dst + scanline] = data_bytes[src : src + scanline]
131133
return bmp, pal
132134
# RGB, RGBA or Grayscale
133135
import displayio

0 commit comments

Comments
 (0)