diff options
| author | Radomir Dopieralski <openstack@sheep.art.pl> | 2019-03-20 19:29:20 +0100 |
|---|---|---|
| committer | Radomir Dopieralski <openstack@sheep.art.pl> | 2019-03-25 19:40:40 +0100 |
| commit | 81fe8060d76d54a20701e6944dd29cdfab9fed4f (patch) | |
| tree | 36de8da8c4a3fb17b91007ead73a6e4f93b5c35f /shared-bindings/displayio/Bitmap.c | |
| parent | 7bac10ab6e441c83c509661b6bd5bdde280bf196 (diff) | |
Properly calculate BPP for displayio.Bitmap
Fix #1669
Diffstat (limited to 'shared-bindings/displayio/Bitmap.c')
| -rw-r--r-- | shared-bindings/displayio/Bitmap.c | 16 |
1 files changed, 12 insertions, 4 deletions
diff --git a/shared-bindings/displayio/Bitmap.c b/shared-bindings/displayio/Bitmap.c index 3612b8d63..91c17f2d1 100644 --- a/shared-bindings/displayio/Bitmap.c +++ b/shared-bindings/displayio/Bitmap.c @@ -58,14 +58,22 @@ STATIC mp_obj_t displayio_bitmap_make_new(const mp_obj_type_t *type, size_t n_ar uint32_t width = mp_obj_get_int(pos_args[0]); uint32_t height = mp_obj_get_int(pos_args[1]); uint32_t value_count = mp_obj_get_int(pos_args[2]); - uint32_t power_of_two = 1; - while (value_count > (1U << power_of_two)) { - power_of_two <<= 1; + uint32_t bits = 1; + + if (value_count == 0) { + mp_raise_ValueError(translate("value_count must be > 0")); + } + while ((value_count - 1) >> bits) { + if (bits < 8) { + bits <<= 1; + } else { + bits += 8; + } } displayio_bitmap_t *self = m_new_obj(displayio_bitmap_t); self->base.type = &displayio_bitmap_type; - common_hal_displayio_bitmap_construct(self, width, height, power_of_two); + common_hal_displayio_bitmap_construct(self, width, height, bits); return MP_OBJ_FROM_PTR(self); } |
