This commit is contained in:
Roy Hooper 2019-11-26 21:28:41 -05:00
parent 56720eae0a
commit a9624fff25

View File

@ -230,7 +230,7 @@ STATIC mp_obj_t pixelbuf_pixelbuf_obj_set_brightness(mp_obj_t self_in, mp_obj_t
if (self->two_buffers)
pixelbuf_recalculate_brightness(self);
if (self->auto_write)
call_show(self_in, 'b');
call_show(self_in);
return mp_const_none;
}
MP_DEFINE_CONST_FUN_OBJ_2(pixelbuf_pixelbuf_set_brightness_obj, pixelbuf_pixelbuf_obj_set_brightness);
@ -253,7 +253,7 @@ void pixelbuf_recalculate_brightness(pixelbuf_pixelbuf_obj_t *self) {
}
}
mp_obj_t call_show(mp_obj_t self_in, char origin) {
mp_obj_t call_show(mp_obj_t self_in) {
mp_obj_t dest[2];
mp_load_method(self_in, MP_QSTR_show, dest);
return mp_call_method_n_kw(0, 0, dest);
@ -340,6 +340,25 @@ STATIC mp_obj_t pixelbuf_pixelbuf_show(mp_obj_t self_in) {
}
STATIC MP_DEFINE_CONST_FUN_OBJ_1(pixelbuf_pixelbuf_show_obj, pixelbuf_pixelbuf_show);
//| .. method:: fill(color)
//|
//| Fills the entire buffer with the given color.
//|
STATIC mp_obj_t pixelbuf_pixelbuf_fill(mp_obj_t self_in, mp_obj_t value) {
pixelbuf_pixelbuf_obj_t *self = native_pixelbuf(self_in);
for (size_t offset = 0; offset < self->pixels; offset++) {
pixelbuf_set_pixel(self->buf + offset, self->two_buffers ? self->rawbuf + offset : NULL,
self->brightness, value, &self->byteorder, self->byteorder.is_dotstar);
if (self->auto_write)
call_show(self_in);
}
}
STATIC MP_DEFINE_CONST_FUN_OBJ_1(pixelbuf_pixelbuf_show_obj, pixelbuf_pixelbuf_fill);
//| .. method:: __getitem__(index)
//|
//| Returns the pixel value at the given index.
@ -410,7 +429,7 @@ STATIC mp_obj_t pixelbuf_pixelbuf_subscr(mp_obj_t self_in, mp_obj_t index_in, mp
}
}
if (self->auto_write)
call_show(instance, 's');
call_show(instance);
return mp_const_none;
#else
return MP_OBJ_NULL; // op not supported
@ -430,7 +449,7 @@ STATIC mp_obj_t pixelbuf_pixelbuf_subscr(mp_obj_t self_in, mp_obj_t index_in, mp
pixelbuf_set_pixel(self->buf + offset, self->two_buffers ? self->rawbuf + offset : NULL,
self->brightness, value, &self->byteorder, self->byteorder.is_dotstar);
if (self->auto_write)
call_show(instance, 'i');
call_show(instance);
return mp_const_none;
}
}
@ -443,6 +462,7 @@ STATIC const mp_rom_map_elem_t pixelbuf_pixelbuf_locals_dict_table[] = {
{ MP_ROM_QSTR(MP_QSTR_buf), MP_ROM_PTR(&pixelbuf_pixelbuf_buf_obj)},
{ MP_ROM_QSTR(MP_QSTR_byteorder), MP_ROM_PTR(&pixelbuf_pixelbuf_byteorder_str)},
{ MP_ROM_QSTR(MP_QSTR_show), MP_ROM_PTR(&pixelbuf_pixelbuf_show_obj)},
{ MP_ROM_QSTR(MP_QSTR_fill), MP_ROM_PTR(&pixelbuf_pixelbuf_fill_obj)},
};
STATIC MP_DEFINE_CONST_DICT(pixelbuf_pixelbuf_locals_dict, pixelbuf_pixelbuf_locals_dict_table);