diff options
Diffstat (limited to 'shared-bindings')
| -rw-r--r-- | shared-bindings/displayio/Bitmap.h | 2 | ||||
| -rw-r--r-- | shared-bindings/displayio/Palette.c | 32 | ||||
| -rw-r--r-- | shared-bindings/displayio/Palette.h | 6 | ||||
| -rw-r--r-- | shared-bindings/displayio/Sprite.c | 7 |
4 files changed, 24 insertions, 23 deletions
diff --git a/shared-bindings/displayio/Bitmap.h b/shared-bindings/displayio/Bitmap.h index 2ae468481..b736f9459 100644 --- a/shared-bindings/displayio/Bitmap.h +++ b/shared-bindings/displayio/Bitmap.h @@ -32,7 +32,7 @@ extern const mp_obj_type_t displayio_bitmap_type; void common_hal_displayio_bitmap_construct(displayio_bitmap_t *self, uint32_t width, - uint32_t height, uint32_t value_size); + uint32_t height, uint32_t bits_per_value); void common_hal_displayio_bitmap_load_row(displayio_bitmap_t *self, uint16_t y, uint8_t* data, uint16_t len); diff --git a/shared-bindings/displayio/Palette.c b/shared-bindings/displayio/Palette.c index 99963f131..21744f947 100644 --- a/shared-bindings/displayio/Palette.c +++ b/shared-bindings/displayio/Palette.c @@ -38,10 +38,10 @@ //| .. currentmodule:: displayio //| -//| :class:`Palette` -- Stores a mapping from bitmap pixel values to display colors +//| :class:`Palette` -- Stores a mapping from bitmap pixel palette_indexes to display colors //| =============================================================================== //| -//| Map a pixel value to a full color. Colors are transformed to the display's format internally to +//| Map a pixel palette_index to a full color. Colors are transformed to the display's format internally to //| save memory. //| //| .. warning:: This will be changed before 4.0.0. Consider it very experimental. @@ -86,7 +86,7 @@ STATIC mp_obj_t palette_subscr(mp_obj_t self_in, mp_obj_t index_in, mp_obj_t val return MP_OBJ_NULL; } displayio_palette_t *self = MP_OBJ_TO_PTR(self_in); - size_t index = mp_get_index(&displayio_palette_type, self->max_value, index_in, false); + size_t index = mp_get_index(&displayio_palette_type, self->color_count, index_in, false); uint32_t color; mp_int_t int_value; @@ -99,7 +99,7 @@ STATIC mp_obj_t palette_subscr(mp_obj_t self_in, mp_obj_t index_in, mp_obj_t val if (bufinfo.len == 3 || bufinfo.len == 4) { color = buf[0] << 16 | buf[1] << 8 | buf[2]; } else { - mp_raise_ValueError(translate("color buffer must be 3 bytes (RGB) or 4 bytes (RGBA)")); + mp_raise_ValueError(translate("color buffer must be 3 bytes (RGB) or 4 bytes (RGB + pad byte)")); } } else if (mp_obj_get_int_maybe(value, &int_value)) { if (int_value < 0 || int_value > 0xffffff) { @@ -113,30 +113,30 @@ STATIC mp_obj_t palette_subscr(mp_obj_t self_in, mp_obj_t index_in, mp_obj_t val return mp_const_none; } -//| .. method:: make_transparent(value) +//| .. method:: make_transparent(palette_index) //| -STATIC mp_obj_t displayio_palette_obj_make_transparent(mp_obj_t self_in, mp_obj_t value_obj) { +STATIC mp_obj_t displayio_palette_obj_make_transparent(mp_obj_t self_in, mp_obj_t palette_index_obj) { displayio_palette_t *self = MP_OBJ_TO_PTR(self_in); - mp_int_t value; - if (!mp_obj_get_int_maybe(value_obj, &value)) { - mp_raise_ValueError(translate("value should be an int")); + mp_int_t palette_index; + if (!mp_obj_get_int_maybe(palette_index_obj, &palette_index)) { + mp_raise_ValueError(translate("palette_index should be an int")); } - common_hal_displayio_palette_make_transparent(self, value); + common_hal_displayio_palette_make_transparent(self, palette_index); return mp_const_none; } MP_DEFINE_CONST_FUN_OBJ_2(displayio_palette_make_transparent_obj, displayio_palette_obj_make_transparent); -//| .. method:: make_opaque(value) +//| .. method:: make_opaque(palette_index) //| -STATIC mp_obj_t displayio_palette_obj_make_opaque(mp_obj_t self_in, mp_obj_t value_obj) { +STATIC mp_obj_t displayio_palette_obj_make_opaque(mp_obj_t self_in, mp_obj_t palette_index_obj) { displayio_palette_t *self = MP_OBJ_TO_PTR(self_in); - mp_int_t value; - if (!mp_obj_get_int_maybe(value_obj, &value)) { - mp_raise_ValueError(translate("value should be an int")); + mp_int_t palette_index; + if (!mp_obj_get_int_maybe(palette_index_obj, &palette_index)) { + mp_raise_ValueError(translate("palette_index should be an int")); } - common_hal_displayio_palette_make_opaque(self, value); + common_hal_displayio_palette_make_opaque(self, palette_index); return mp_const_none; } MP_DEFINE_CONST_FUN_OBJ_2(displayio_palette_make_opaque_obj, displayio_palette_obj_make_opaque); diff --git a/shared-bindings/displayio/Palette.h b/shared-bindings/displayio/Palette.h index fde6ab7d3..767fc7b63 100644 --- a/shared-bindings/displayio/Palette.h +++ b/shared-bindings/displayio/Palette.h @@ -32,9 +32,9 @@ extern const mp_obj_type_t displayio_palette_type; void common_hal_displayio_palette_construct(displayio_palette_t* self, uint16_t color_count); -void common_hal_displayio_palette_set_color(displayio_palette_t* self, uint32_t value, uint32_t color); +void common_hal_displayio_palette_set_color(displayio_palette_t* self, uint32_t palette_index, uint32_t color); -void common_hal_displayio_palette_make_opaque(displayio_palette_t* self, uint32_t value); -void common_hal_displayio_palette_make_transparent(displayio_palette_t* self, uint32_t value); +void common_hal_displayio_palette_make_opaque(displayio_palette_t* self, uint32_t palette_index); +void common_hal_displayio_palette_make_transparent(displayio_palette_t* self, uint32_t palette_index); #endif // MICROPY_INCLUDED_SHARED_BINDINGS_DISPLAYIO_PALETTE_H diff --git a/shared-bindings/displayio/Sprite.c b/shared-bindings/displayio/Sprite.c index 25ea79f5c..223a8a394 100644 --- a/shared-bindings/displayio/Sprite.c +++ b/shared-bindings/displayio/Sprite.c @@ -35,7 +35,8 @@ #include "shared-bindings/displayio/Bitmap.h" #include "supervisor/shared/translate.h" -void parse_position(mp_obj_t position_obj, int16_t* x, int16_t* y) { +void unpack_position(mp_obj_t position_obj, int16_t* x, int16_t* y) { + // TODO(tannewt): Support any value sequence such as bytearray or bytes. mp_obj_tuple_t *position = MP_OBJ_TO_PTR(position_obj); if (MP_OBJ_IS_TYPE(position_obj, &mp_type_tuple) && position->len == 2) { *x = mp_obj_get_int(position->items[0]); @@ -88,7 +89,7 @@ STATIC mp_obj_t displayio_sprite_make_new(const mp_obj_type_t *type, size_t n_ar int16_t x = 0; int16_t y = 0; mp_obj_t position_obj = args[ARG_position].u_obj; - parse_position(position_obj, &x, &y); + unpack_position(position_obj, &x, &y); displayio_sprite_t *self = m_new_obj(displayio_sprite_t); self->base.type = &displayio_sprite_type; @@ -120,7 +121,7 @@ STATIC mp_obj_t displayio_sprite_obj_set_position(mp_obj_t self_in, mp_obj_t val int16_t x = 0; int16_t y = 0; - parse_position(value, &x, &y); + unpack_position(value, &x, &y); common_hal_displayio_sprite_set_position(self, x, y); |
