|
25 | 25 | except ImportError:
|
26 | 26 | pass
|
27 | 27 |
|
| 28 | +from sys import implementation |
28 | 29 | import struct
|
29 | 30 | import zlib
|
30 | 31 |
|
@@ -112,22 +113,23 @@ def load( # noqa: PLR0912, PLR0915, Too many branches, Too many statements
|
112 | 113 | filladj = y * ((4 - (scanline % 4)) % 4)
|
113 | 114 | dst = y * scanline + filladj
|
114 | 115 | 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 |
118 | 118 | # https://github.com/adafruit/circuitpython/issues/6675
|
119 | 119 | # 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] |
131 | 133 | return bmp, pal
|
132 | 134 | # RGB, RGBA or Grayscale
|
133 | 135 | import displayio
|
|
0 commit comments