diff options
| author | Scott Shawcroft <scott@tannewt.org> | 2019-04-16 10:32:38 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2019-04-16 10:32:38 -0700 |
| commit | f58446e937ede4735a7ecb0852f2d2739f147cdd (patch) | |
| tree | 72185232547d424dfe0b61fb7f98ce11378d1e6d /shared-bindings/displayio/Bitmap.c | |
| parent | 2d303213ed4ee058c0fc4c541dd7a7181f59d50f (diff) | |
| parent | 7822d013cd6d379c777f95c73a803b749d1bebe4 (diff) | |
Merge branch 'master' into master
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); } |
