Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove readinto fallback for 6.2.0-beta4 #52

Merged
merged 1 commit into from
Jun 12, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 9 additions & 27 deletions adafruit_imageload/bmp/indexed.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,33 +88,15 @@ def load(
if compression == 0:

if _bitmap_readinto:
try:
_bitmap_readinto(
bitmap,
file,
bits_per_pixel=color_depth,
element_size=4,
reverse_pixels_in_element=True,
reverse_rows=True,
)
except TypeError:
# catch unexpected argument, try python read code.
# This issue affects only CircuitPython 6.2.0-beta.4.
# The try/except block here should be removed when
# a newer release is made.
chunk = bytearray(line_size)
for y in range(range1, range2, range3):
file.readinto(chunk)
pixels_per_byte = 8 // color_depth
offset = y * width

for x in range(width):
i = x // pixels_per_byte
pixel = (
chunk[i]
>> (8 - color_depth * (x % pixels_per_byte + 1))
) & mask
bitmap[offset + x] = pixel
_bitmap_readinto(
bitmap,
file,
bits_per_pixel=color_depth,
element_size=4,
reverse_pixels_in_element=True,
reverse_rows=True,
)

else: # use the standard file.readinto
chunk = bytearray(line_size)
for y in range(range1, range2, range3):
Expand Down