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

Cannot assign values to 32-bit Bitmap #3227

Merged
merged 1 commit into from
Jul 30, 2020
Merged

Conversation

cwalther
Copy link

Actual result:

>>> import displayio
>>> b = displayio.Bitmap(8, 8, 2**28)
>>> b[0, 0] = 1
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ValueError: pixel value requires too many bits
>>> b.fill(1)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ValueError: pixel value requires too many bits

(2**28 is used because the PewPew M4 I am testing on doesn’t have long ints enabled – the bit depth is rounded up to multiples of 8 so this results in a 32-bit bitmap.)

Expected result: no error in either case, b[0, 0] == 1.

This happens because the left-shift by 32 in the check in bitmap_subscr() and displayio_bitmap_obj_fill() overflows a 32-bit integer, ending up in zero, which is always matched by the comparison. The attached commit fixes it by right-shifting on the other side of the equation instead (using an unsigned type to avoid sign extension).

@jepler jepler merged commit 510985f into adafruit:main Jul 30, 2020
@cwalther
Copy link
Author

Thanks, that was quick!

@cwalther cwalther deleted the 32bitmap branch July 30, 2020 12:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants