@@ -104,38 +104,22 @@ def load( # noqa: PLR0912, PLR0915, Too many branches, Too many statements
104
104
data_bytes = zlib .decompress (data )
105
105
unit = (1 , 0 , 3 , 1 , 2 , 0 , 4 )[mode ]
106
106
scanline = (width * depth * unit + 7 ) // 8
107
- colors = 1 << (depth * unit )
108
107
if mode == 3 : # indexed
109
- bmp = bitmap (width , height , colors )
110
- mem = memoryview (bmp )
108
+ bmp = bitmap (width , height , 1 << depth )
111
109
pixels_per_byte = 8 // depth
112
110
# Adjust for Displayio.Bitmap filler to scanline at 4-byte boundry
113
111
filladj = (4 - (scanline % 4 )) % 4
114
112
src = 1
115
- if (
116
- (implementation [1 ][0 ] == 9 and implementation [1 ][1 ] < 2 ) or implementation [1 ][0 ] < 9
117
- ) and (depth < 8 or width % 4 != 0 ):
118
- # Work around the bug in displayio.Bitmap
119
- # remove once CircuitPython 9.1 is no longer supported
120
- # https://github.com/adafruit/circuitpython/issues/6675
121
- # https://github.com/adafruit/circuitpython/issues/9707
122
- src_b = 1
123
- for y in range (height ):
124
- for x in range (0 , width , pixels_per_byte ):
125
- byte = data_bytes [src_b ]
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_b += 1
131
- src += scanline + 1
132
- src_b = src
133
- else :
134
- dst = 0
135
- for y in range (height ):
136
- mem [dst : dst + scanline ] = data_bytes [src : src + scanline ]
137
- dst += scanline + filladj
138
- src += scanline + 1
113
+ src_b = 1
114
+ pixmask = (1 << depth ) - 1
115
+ for y in range (height ):
116
+ for x in range (0 , width , pixels_per_byte ):
117
+ byte = data_bytes [src_b ]
118
+ for pixel in range (pixels_per_byte ):
119
+ bmp [x + pixel , y ] = (byte >> ((pixels_per_byte - pixel - 1 ) * depth )) & pixmask
120
+ src_b += 1
121
+ src += scanline + 1
122
+ src_b = src
139
123
return bmp , pal
140
124
# RGB, RGBA or Grayscale
141
125
import displayio
0 commit comments