Skip to content

Commit a9624ff

Browse files
committed
add show
1 parent 56720ea commit a9624ff

1 file changed

Lines changed: 24 additions & 4 deletions

File tree

shared-bindings/_pixelbuf/PixelBuf.c

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ STATIC mp_obj_t pixelbuf_pixelbuf_obj_set_brightness(mp_obj_t self_in, mp_obj_t
230230
if (self->two_buffers)
231231
pixelbuf_recalculate_brightness(self);
232232
if (self->auto_write)
233-
call_show(self_in, 'b');
233+
call_show(self_in);
234234
return mp_const_none;
235235
}
236236
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) {
253253
}
254254
}
255255

256-
mp_obj_t call_show(mp_obj_t self_in, char origin) {
256+
mp_obj_t call_show(mp_obj_t self_in) {
257257
mp_obj_t dest[2];
258258
mp_load_method(self_in, MP_QSTR_show, dest);
259259
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) {
340340
}
341341
STATIC MP_DEFINE_CONST_FUN_OBJ_1(pixelbuf_pixelbuf_show_obj, pixelbuf_pixelbuf_show);
342342

343+
344+
//| .. method:: fill(color)
345+
//|
346+
//| Fills the entire buffer with the given color.
347+
//|
348+
349+
STATIC mp_obj_t pixelbuf_pixelbuf_fill(mp_obj_t self_in, mp_obj_t value) {
350+
pixelbuf_pixelbuf_obj_t *self = native_pixelbuf(self_in);
351+
352+
for (size_t offset = 0; offset < self->pixels; offset++) {
353+
pixelbuf_set_pixel(self->buf + offset, self->two_buffers ? self->rawbuf + offset : NULL,
354+
self->brightness, value, &self->byteorder, self->byteorder.is_dotstar);
355+
if (self->auto_write)
356+
call_show(self_in);
357+
}
358+
}
359+
STATIC MP_DEFINE_CONST_FUN_OBJ_1(pixelbuf_pixelbuf_show_obj, pixelbuf_pixelbuf_fill);
360+
361+
343362
//| .. method:: __getitem__(index)
344363
//|
345364
//| 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
410429
}
411430
}
412431
if (self->auto_write)
413-
call_show(instance, 's');
432+
call_show(instance);
414433
return mp_const_none;
415434
#else
416435
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
430449
pixelbuf_set_pixel(self->buf + offset, self->two_buffers ? self->rawbuf + offset : NULL,
431450
self->brightness, value, &self->byteorder, self->byteorder.is_dotstar);
432451
if (self->auto_write)
433-
call_show(instance, 'i');
452+
call_show(instance);
434453
return mp_const_none;
435454
}
436455
}
@@ -443,6 +462,7 @@ STATIC const mp_rom_map_elem_t pixelbuf_pixelbuf_locals_dict_table[] = {
443462
{ MP_ROM_QSTR(MP_QSTR_buf), MP_ROM_PTR(&pixelbuf_pixelbuf_buf_obj)},
444463
{ MP_ROM_QSTR(MP_QSTR_byteorder), MP_ROM_PTR(&pixelbuf_pixelbuf_byteorder_str)},
445464
{ MP_ROM_QSTR(MP_QSTR_show), MP_ROM_PTR(&pixelbuf_pixelbuf_show_obj)},
465+
{ MP_ROM_QSTR(MP_QSTR_fill), MP_ROM_PTR(&pixelbuf_pixelbuf_fill_obj)},
446466
};
447467

448468
STATIC MP_DEFINE_CONST_DICT(pixelbuf_pixelbuf_locals_dict, pixelbuf_pixelbuf_locals_dict_table);

0 commit comments

Comments
 (0)