starting bitmaptools.paint_fill

This commit is contained in:
foamyguy 2021-08-08 09:31:09 -05:00
parent 06325c44d8
commit bcfec10552
3 changed files with 69 additions and 0 deletions

View File

@ -296,6 +296,63 @@ STATIC mp_obj_t bitmaptools_obj_fill_region(size_t n_args, const mp_obj_t *pos_a
}
MP_DEFINE_CONST_FUN_OBJ_KW(bitmaptools_fill_region_obj, 0, bitmaptools_obj_fill_region);
//|
//| def paint_fill(
//| dest_bitmap: displayio.Bitmap,
//| x: int, y: int
//| value: int, background_value: int) -> None:
//| """Draws the color value into the destination bitmap enclosed
//| area of pixels of the background_value color. Like "Paint Bucket"
//| fill tool.
//|
//| :param bitmap dest_bitmap: Destination bitmap that will be written into
//| :param int x: x-pixel position of the first pixel to check and fill if needed
//| :param int y: y-pixel position of the first pixel to check and fill if needed
//| :param int value: Bitmap palette index that will be written into the rectangular
//| fill region in the destination bitmap"""
//| :param int background_value: Bitmap palette index that will filled with the
//| value color in the enclosed area in the destination bitmap"""
//| ...
//|
STATIC mp_obj_t bitmaptools_obj_paint_fill(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
enum {ARG_dest_bitmap, ARG_x, ARG_y, ARG_value, ARG_background_value};
static const mp_arg_t allowed_args[] = {
{MP_QSTR_dest_bitmap, MP_ARG_REQUIRED | MP_ARG_OBJ},
{MP_QSTR_x, MP_ARG_REQUIRED | MP_ARG_INT},
{MP_QSTR_y, MP_ARG_REQUIRED | MP_ARG_INT},
{MP_QSTR_value, MP_ARG_REQUIRED | MP_ARG_INT},
{MP_QSTR_background_value, MP_ARG_REQUIRED | MP_ARG_INT},
};
mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)];
mp_arg_parse_all(n_args, pos_args, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args);
displayio_bitmap_t *destination = MP_OBJ_TO_PTR(args[ARG_dest_bitmap].u_obj); // the destination bitmap
uint32_t value, color_depth;
value = args[ARG_value].u_int;
color_depth = (1 << destination->bits_per_value);
if (color_depth <= value) {
mp_raise_ValueError(translate("value out of range of target"));
}
uint32_t background_value, color_depth;
background_value = args[ARG_background_value].u_int;
color_depth = (1 << destination->bits_per_value);
if (color_depth <= background_value) {
mp_raise_ValueError(translate("background value out of range of target"));
}
int16_t x = args[ARG_x].u_int;
int16_t y = args[ARG_y].u_int;
common_hal_bitmaptools_paint_fill(destination, x, y, value, background_value);
return mp_const_none;
}
MP_DEFINE_CONST_FUN_OBJ_KW(bitmaptools_paint_fill_obj, 0, bitmaptools_obj_paint_fill);
// requires all 6 arguments
//|
@ -520,6 +577,7 @@ STATIC const mp_rom_map_elem_t bitmaptools_module_globals_table[] = {
{ MP_ROM_QSTR(MP_QSTR_rotozoom), MP_ROM_PTR(&bitmaptools_rotozoom_obj) },
{ MP_ROM_QSTR(MP_QSTR_arrayblit), MP_ROM_PTR(&bitmaptools_arrayblit_obj) },
{ MP_ROM_QSTR(MP_QSTR_fill_region), MP_ROM_PTR(&bitmaptools_fill_region_obj) },
{ MP_ROM_QSTR(MP_QSTR_paint_fill), MP_ROM_PTR(&bitmaptools_paint_fill_obj) },
{ MP_ROM_QSTR(MP_QSTR_draw_line), MP_ROM_PTR(&bitmaptools_draw_line_obj) },
};
STATIC MP_DEFINE_CONST_DICT(bitmaptools_module_globals, bitmaptools_module_globals_table);

View File

@ -46,6 +46,10 @@ void common_hal_bitmaptools_fill_region(displayio_bitmap_t *destination,
int16_t x2, int16_t y2,
uint32_t value);
void common_hal_bitmaptools_paint_fill(displayio_bitmap_t *destination,
int16_t x, int16_t y,
uint32_t value, uint32_t background_value);
void common_hal_bitmaptools_draw_line(displayio_bitmap_t *destination,
int16_t x0, int16_t y0,
int16_t x1, int16_t y1,

View File

@ -252,6 +252,13 @@ void common_hal_bitmaptools_fill_region(displayio_bitmap_t *destination,
}
}
void common_hal_bitmaptools_paint_fill(displayio_bitmap_t *destination,
int16_t x, int16_t y,
uint32_t value, uint32_t background_value) {
}
void common_hal_bitmaptools_draw_line(displayio_bitmap_t *destination,
int16_t x0, int16_t y0,
int16_t x1, int16_t y1,