diff --git a/shared-bindings/bitmaptools/__init__.c b/shared-bindings/bitmaptools/__init__.c index a7e0103a96..32822fc0a3 100644 --- a/shared-bindings/bitmaptools/__init__.c +++ b/shared-bindings/bitmaptools/__init__.c @@ -297,7 +297,7 @@ 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( +//| def boundary_fill( //| dest_bitmap: displayio.Bitmap, //| x: int, y: int //| value: int, background_value: int) -> None: @@ -308,13 +308,13 @@ MP_DEFINE_CONST_FUN_OBJ_KW(bitmaptools_fill_region_obj, 0, bitmaptools_obj_fill_ //| :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 value: Bitmap palette index that will be written into the +//| enclosed area 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) { +STATIC mp_obj_t bitmaptools_obj_boundary_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[] = { @@ -346,12 +346,12 @@ STATIC mp_obj_t bitmaptools_obj_paint_fill(size_t n_args, const mp_obj_t *pos_ar int16_t y = args[ARG_y].u_int; - common_hal_bitmaptools_paint_fill(destination, x, y, value, background_value); + common_hal_bitmaptools_boundary_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); +MP_DEFINE_CONST_FUN_OBJ_KW(bitmaptools_boundary_fill_obj, 0, bitmaptools_obj_boundary_fill); // requires all 6 arguments //| @@ -576,7 +576,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_boundary_fill), MP_ROM_PTR(&bitmaptools_boundary_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); diff --git a/shared-bindings/bitmaptools/__init__.h b/shared-bindings/bitmaptools/__init__.h index 94cf7e60c4..8e22235e77 100644 --- a/shared-bindings/bitmaptools/__init__.h +++ b/shared-bindings/bitmaptools/__init__.h @@ -46,7 +46,7 @@ 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, +void common_hal_bitmaptools_boundary_fill(displayio_bitmap_t *destination, int16_t x, int16_t y, uint32_t value, uint32_t background_value); diff --git a/shared-module/bitmaptools/__init__.c b/shared-module/bitmaptools/__init__.c index bd3a4b4d8f..ae00c68b46 100644 --- a/shared-module/bitmaptools/__init__.c +++ b/shared-module/bitmaptools/__init__.c @@ -253,90 +253,57 @@ void common_hal_bitmaptools_fill_region(displayio_bitmap_t *destination, } } -void common_hal_bitmaptools_paint_fill(displayio_bitmap_t *destination, +void common_hal_bitmaptools_boundary_fill(displayio_bitmap_t *destination, int16_t x, int16_t y, uint32_t value, uint32_t background_value) { - /*def _boundaryFill4(self, px, py, fc, bc): # px & py = x, y coord to start fill, fc = fill color, bc = background color - fillArea = [[px, py]] - - while len(fillArea) > 0: - x, y = fillArea.pop() - - if self._bitmap[x, y] != bc: - continue - self._bitmap[x, y] = fc - fillArea.append((x + 1, y)) - fillArea.append((x - 1, y)) - fillArea.append((x, y + 1)) - fillArea.append((x, y - 1))*/ - + // the list of points that we'll check mp_obj_t fill_area = mp_obj_new_list(0, NULL); + + // first point is the one user passed in mp_obj_t point[] = { mp_obj_new_int(x), mp_obj_new_int(y) }; mp_obj_list_append( fill_area, mp_obj_new_tuple(2, point) ); - //mp_obj_list_t *point; - //mp_obj_list_append(point, x); - //mp_obj_list_append(point, y); - mp_obj_t *fill_points; size_t list_length = 0; mp_obj_list_get(fill_area, &list_length, &fill_points); - //mp_printf(&mp_plat_print, "\nLen bfore loop: %d", list_length); + mp_obj_t current_point; uint32_t current_point_color_value; size_t tuple_len = 0; mp_obj_t *tuple_items; - + // while there are still points to check while (list_length > 0){ mp_obj_list_get(fill_area, &list_length, &fill_points); - //mp_printf(&mp_plat_print, "\nLen begin loop: %d\n", list_length); current_point = mp_obj_list_pop(fill_area, 0); - - - //mp_obj_print(current_point, PRINT_STR); mp_obj_tuple_get(current_point, &tuple_len, &tuple_items); current_point_color_value = common_hal_displayio_bitmap_get_pixel( destination, mp_obj_get_int(tuple_items[0]), mp_obj_get_int(tuple_items[1])); - //mp_printf(&mp_plat_print, "%d\n", current_point_color_value); - + // if the current point is not background color ignore it if(current_point_color_value != background_value){ mp_obj_list_get(fill_area, &list_length, &fill_points); continue; } - - + // fill the current point with fill color displayio_bitmap_write_pixel( destination, mp_obj_get_int(tuple_items[0]), mp_obj_get_int(tuple_items[1]), value); - - //mp_obj_t above_point[] = { mp_obj_new_int(tuple_items[0]), mp_obj_new_int(tuple_items[1])-1 }; - //mp_printf(&mp_plat_print,"math:\n"); - //mp_printf(&mp_plat_print, "%d\n", mp_obj_get_int(tuple_items[0])); - //mp_printf(&mp_plat_print, "%d\n", mp_obj_get_int(tuple_items[0])+1); - //int16_t above_int = mp_obj_get_int(tuple_items[0])+1; - //mp_printf(&mp_plat_print, "%d\n", above_int); - //int16_t *above = &above_int; - //mp_printf(&mp_plat_print, "%d\n", above); - + // add all 4 surrounding points to the list to check mp_obj_t above_point[] = { tuple_items[0], MP_OBJ_NEW_SMALL_INT(mp_obj_int_get_checked(tuple_items[1])-1)}; - - //mp_printf(&mp_plat_print,"above_point:\n"); - //mp_obj_print(above_point, PRINT_STR); mp_obj_list_append( fill_area, mp_obj_new_tuple(2, above_point)); @@ -363,26 +330,12 @@ void common_hal_bitmaptools_paint_fill(displayio_bitmap_t *destination, mp_obj_new_tuple(2, below_point)); mp_obj_list_get(fill_area, &list_length, &fill_points); - //mp_printf(&mp_plat_print, "\nLen end loop: %d\n", list_length); } + // set dirty the area so displayio will draw displayio_area_t area = { 0, 0, destination->width, destination->height }; displayio_bitmap_set_dirty_area(destination, &area); - //mp_obj_print(fill_area, PRINT_STR); - //mp_obj_print(current_point[0], PRINT_STR); - - /* - mp_printf(&mp_plat_print, "\nLen: %d", list_length); - size_t tuple_len = 0; - mp_obj_t *tuple_items; - mp_obj_tuple_get(current_point[0], &tuple_len, &tuple_items); - - //mp_obj_print(mp_obj_get_int(tuple_items[0])+1, PRINT_STR); - - mp_printf(&mp_plat_print, "\n%d", mp_obj_get_int(tuple_items[0])+1); - */ - } void common_hal_bitmaptools_draw_line(displayio_bitmap_t *destination,