@@ -103,26 +103,20 @@ def load( # noqa: PLR0912, PLR0915, Too many branches, Too many statements
103103 data_bytes = zlib .decompress (data )
104104 unit = (1 , 0 , 3 , 1 , 2 , 0 , 4 )[mode ]
105105 scanline = (width * depth * unit + 7 ) // 8
106- colors = 1 << (depth * unit )
107106 if mode == 3 : # indexed
108- bmp = bitmap (width , height , colors )
109- mem = memoryview (bmp )
107+ bmp = bitmap (width , height , 1 << depth )
108+ pixels_per_byte = 8 // depth
109+ src = 1
110+ src_b = 1
111+ pixmask = (1 << depth ) - 1
110112 for y in range (height ):
111- dst = y * scanline
112- src = y * (scanline + 1 ) + 1
113- if depth < 8 :
114- # Work around the bug in displayio.Bitmap
115- # https://github.com/adafruit/circuitpython/issues/6675
116- pixels_per_byte = 8 // depth
117- for x in range (0 , width , pixels_per_byte ):
118- byte = data_bytes [src ]
119- for pixel in range (pixels_per_byte ):
120- bmp [x + pixel , y ] = (byte >> ((pixels_per_byte - pixel - 1 ) * depth )) & (
121- (1 << depth ) - 1
122- )
123- src += 1
124- else :
125- mem [dst : dst + scanline ] = data_bytes [src : src + scanline ]
113+ for x in range (0 , width , pixels_per_byte ):
114+ byte = data_bytes [src_b ]
115+ for pixel in range (pixels_per_byte ):
116+ bmp [x + pixel , y ] = (byte >> ((pixels_per_byte - pixel - 1 ) * depth )) & pixmask
117+ src_b += 1
118+ src += scanline + 1
119+ src_b = src
126120 return bmp , pal
127121 # RGB, RGBA or Grayscale
128122 import displayio
0 commit comments