initial working fill

crypto-aes
caternuson 3 years ago
parent b3b8b5ca71
commit 49fff2d9b4
  1. 19
      shared-bindings/displayio/Bitmap.c
  2. 1
      shared-bindings/displayio/Bitmap.h
  3. 32
      shared-module/displayio/Bitmap.c

@ -178,9 +178,28 @@ STATIC mp_obj_t bitmap_subscr(mp_obj_t self_in, mp_obj_t index_obj, mp_obj_t val
return mp_const_none;
}
//| .. method:: fill()
//|
//| Fills the bitmap.
//|
STATIC mp_obj_t displayio_bitmap_obj_fill(mp_obj_t self_in, mp_obj_t value_obj) {
displayio_bitmap_t *self = MP_OBJ_TO_PTR(self_in);
mp_int_t value = mp_obj_get_int(value_obj);
if (value >= 1 << common_hal_displayio_bitmap_get_bits_per_value(self)) {
mp_raise_ValueError(translate("pixel value requires too many bits"));
}
common_hal_displayio_bitmap_fill(self, value);
return mp_const_none;
}
MP_DEFINE_CONST_FUN_OBJ_2(displayio_bitmap_fill_obj, displayio_bitmap_obj_fill);
STATIC const mp_rom_map_elem_t displayio_bitmap_locals_dict_table[] = {
{ MP_ROM_QSTR(MP_QSTR_height), MP_ROM_PTR(&displayio_bitmap_height_obj) },
{ MP_ROM_QSTR(MP_QSTR_width), MP_ROM_PTR(&displayio_bitmap_width_obj) },
{ MP_ROM_QSTR(MP_QSTR_fill), MP_ROM_PTR(&displayio_bitmap_fill_obj) },
};
STATIC MP_DEFINE_CONST_DICT(displayio_bitmap_locals_dict, displayio_bitmap_locals_dict_table);

@ -41,5 +41,6 @@ uint16_t common_hal_displayio_bitmap_get_width(displayio_bitmap_t *self);
uint32_t common_hal_displayio_bitmap_get_bits_per_value(displayio_bitmap_t *self);
void common_hal_displayio_bitmap_set_pixel(displayio_bitmap_t *bitmap, int16_t x, int16_t y, uint32_t value);
uint32_t common_hal_displayio_bitmap_get_pixel(displayio_bitmap_t *bitmap, int16_t x, int16_t y);
void common_hal_displayio_bitmap_fill(displayio_bitmap_t *bitmap, uint32_t value);
#endif // MICROPY_INCLUDED_SHARED_BINDINGS_DISPLAYIO_BITMAP_H

@ -162,3 +162,35 @@ void displayio_bitmap_finish_refresh(displayio_bitmap_t *self) {
self->dirty_area.x1 = 0;
self->dirty_area.x2 = 0;
}
void common_hal_displayio_bitmap_fill(displayio_bitmap_t *self, uint32_t value) {
for (uint32_t x=0; x<self->width; x++) {
for (uint32_t y=0; y<self->height; y++) {
int32_t row_start = y * self->stride;
uint32_t bytes_per_value = self->bits_per_value / 8;
if (bytes_per_value < 1) {
uint32_t bit_position = (sizeof(size_t) * 8 - ((x & self->x_mask) + 1) * self->bits_per_value);
uint32_t index = row_start + (x >> self->x_shift);
uint32_t word = self->data[index];
word &= ~(self->bitmask << bit_position);
word |= (value & self->bitmask) << bit_position;
self->data[index] = word;
} else {
size_t* row = self->data + row_start;
if (bytes_per_value == 1) {
((uint8_t*) row)[x] = value;
} else if (bytes_per_value == 2) {
((uint16_t*) row)[x] = value;
} else if (bytes_per_value == 4) {
((uint32_t*) row)[x] = value;
}
}
}
}
self->dirty_area.x1 = 0;
self->dirty_area.x2 = self->width;
self->dirty_area.y1 = 0;
self->dirty_area.y2 = self->height;
}

Loading…
Cancel
Save