File tree Expand file tree Collapse file tree 1 file changed +28
-8
lines changed Expand file tree Collapse file tree 1 file changed +28
-8
lines changed Original file line number Diff line number Diff line change @@ -88,14 +88,34 @@ def load(
88
88
if compression == 0 :
89
89
90
90
if _bitmap_readinto :
91
- _bitmap_readinto (
92
- bitmap ,
93
- file ,
94
- bits_per_pixel = color_depth ,
95
- element_size = 4 ,
96
- reverse_pixels_in_element = False ,
97
- reverse_rows = True ,
98
- )
91
+ try :
92
+ _bitmap_readinto (
93
+ bitmap ,
94
+ file ,
95
+ bits_per_pixel = color_depth ,
96
+ element_size = 4 ,
97
+ reverse_pixels_in_element = False ,
98
+ reverse_rows = True ,
99
+ )
100
+ except TypeError :
101
+ # catch unexpected argument, try python read code.
102
+ # this can be removed after a release is made that
103
+ # includes bitmapttools.readinto() with all arguments
104
+ # used above.
105
+ chunk = bytearray (line_size )
106
+ for y in range (range1 , range2 , range3 ):
107
+ file .readinto (chunk )
108
+ pixels_per_byte = 8 // color_depth
109
+ offset = y * width
110
+
111
+ for x in range (width ):
112
+ i = x // pixels_per_byte
113
+ pixel = (
114
+ chunk [i ]
115
+ >> (8 - color_depth * (x % pixels_per_byte + 1 ))
116
+ ) & mask
117
+ bitmap [offset + x ] = pixel
118
+
99
119
else : # use the standard file.readinto
100
120
chunk = bytearray (line_size )
101
121
for y in range (range1 , range2 , range3 ):
You can’t perform that action at this time.
0 commit comments