From bcfec105525501cec0a51cb71a1c55dfae61ca0d Mon Sep 17 00:00:00 2001 From: foamyguy Date: Sun, 8 Aug 2021 09:31:09 -0500 Subject: [PATCH 01/16] starting bitmaptools.paint_fill --- shared-bindings/bitmaptools/__init__.c | 58 ++++++++++++++++++++++++++ shared-bindings/bitmaptools/__init__.h | 4 ++ shared-module/bitmaptools/__init__.c | 7 ++++ 3 files changed, 69 insertions(+) diff --git a/shared-bindings/bitmaptools/__init__.c b/shared-bindings/bitmaptools/__init__.c index 2a5195d1a4..f06e4e0108 100644 --- a/shared-bindings/bitmaptools/__init__.c +++ b/shared-bindings/bitmaptools/__init__.c @@ -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); diff --git a/shared-bindings/bitmaptools/__init__.h b/shared-bindings/bitmaptools/__init__.h index fc1eb59068..94cf7e60c4 100644 --- a/shared-bindings/bitmaptools/__init__.h +++ b/shared-bindings/bitmaptools/__init__.h @@ -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, diff --git a/shared-module/bitmaptools/__init__.c b/shared-module/bitmaptools/__init__.c index 4c8b887200..4da6c251a6 100644 --- a/shared-module/bitmaptools/__init__.c +++ b/shared-module/bitmaptools/__init__.c @@ -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, From 6d57f43eb355026d8d89a3dd648fed7ec6fcf7b4 Mon Sep 17 00:00:00 2001 From: foamyguy Date: Sun, 8 Aug 2021 09:34:52 -0500 Subject: [PATCH 02/16] try adding print --- shared-module/bitmaptools/__init__.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/shared-module/bitmaptools/__init__.c b/shared-module/bitmaptools/__init__.c index 4da6c251a6..bf091177f8 100644 --- a/shared-module/bitmaptools/__init__.c +++ b/shared-module/bitmaptools/__init__.c @@ -256,7 +256,7 @@ void common_hal_bitmaptools_paint_fill(displayio_bitmap_t *destination, int16_t x, int16_t y, uint32_t value, uint32_t background_value) { - + mp_printf(&mp_plat_print, "paint_fill"); } void common_hal_bitmaptools_draw_line(displayio_bitmap_t *destination, From 158048e56bd88bb409bbf7121d274963b4dd77c6 Mon Sep 17 00:00:00 2001 From: foamyguy Date: Sun, 8 Aug 2021 14:33:07 -0500 Subject: [PATCH 03/16] trying to make lists --- shared-bindings/bitmaptools/__init__.c | 3 +-- shared-module/bitmaptools/__init__.c | 24 +++++++++++++++++++++++- 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/shared-bindings/bitmaptools/__init__.c b/shared-bindings/bitmaptools/__init__.c index f06e4e0108..a7e0103a96 100644 --- a/shared-bindings/bitmaptools/__init__.c +++ b/shared-bindings/bitmaptools/__init__.c @@ -336,9 +336,8 @@ STATIC mp_obj_t bitmaptools_obj_paint_fill(size_t n_args, const mp_obj_t *pos_ar mp_raise_ValueError(translate("value out of range of target")); } - uint32_t background_value, color_depth; + uint32_t background_value; 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")); } diff --git a/shared-module/bitmaptools/__init__.c b/shared-module/bitmaptools/__init__.c index bf091177f8..3aeece186f 100644 --- a/shared-module/bitmaptools/__init__.c +++ b/shared-module/bitmaptools/__init__.c @@ -256,7 +256,29 @@ void common_hal_bitmaptools_paint_fill(displayio_bitmap_t *destination, int16_t x, int16_t y, uint32_t value, uint32_t background_value) { - mp_printf(&mp_plat_print, "paint_fill"); + /*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))*/ + mp_obj_list_t *fill_area; + + //mp_obj_list_t *point; + //mp_obj_list_append(point, x); + //mp_obj_list_append(point, y); + + mp_obj_list_append(MP_OBJ_FROM_PTR(*fill_area), MP_OBJ_NEW_QSTR(qstr_from_str("hello"))); + + //mp_printf(&mp_plat_print, fill_area[0]); + //mp_obj_print(mp_obj_list_pop(fill_area, 0), PRINT_STR); } void common_hal_bitmaptools_draw_line(displayio_bitmap_t *destination, From 87358f81b258b0950e76be7cdd530e579905998f Mon Sep 17 00:00:00 2001 From: foamyguy Date: Mon, 9 Aug 2021 08:30:12 -0500 Subject: [PATCH 04/16] trying to check next pixel --- shared-module/bitmaptools/__init__.c | 85 ++++++++++++++++++++++++++-- 1 file changed, 81 insertions(+), 4 deletions(-) diff --git a/shared-module/bitmaptools/__init__.c b/shared-module/bitmaptools/__init__.c index 3aeece186f..3b421f2ccc 100644 --- a/shared-module/bitmaptools/__init__.c +++ b/shared-module/bitmaptools/__init__.c @@ -24,6 +24,7 @@ * THE SOFTWARE. */ +#include #include "shared-bindings/bitmaptools/__init__.h" #include "shared-bindings/displayio/Bitmap.h" @@ -269,16 +270,92 @@ void common_hal_bitmaptools_paint_fill(displayio_bitmap_t *destination, fillArea.append((x - 1, y)) fillArea.append((x, y + 1)) fillArea.append((x, y - 1))*/ - mp_obj_list_t *fill_area; + mp_obj_t fill_area = mp_obj_new_list(0, NULL); + 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_list_append(MP_OBJ_FROM_PTR(*fill_area), MP_OBJ_NEW_QSTR(qstr_from_str("hello"))); - //mp_printf(&mp_plat_print, fill_area[0]); - //mp_obj_print(mp_obj_list_pop(fill_area, 0), PRINT_STR); + 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 (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(current_point_color_value != background_value){ + mp_obj_list_get(fill_area, &list_length, &fill_points); + continue; + } + 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); + + mp_obj_t above_point[] = { + tuple_items[0], + above}; + + 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)); + + mp_obj_list_get(fill_area, &list_length, &fill_points); + mp_printf(&mp_plat_print, "\nLen end loop: %d\n", list_length); + } + + //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, From fd372cf06c363d60a215c55e46ac78f3175d95c3 Mon Sep 17 00:00:00 2001 From: foamyguy Date: Mon, 9 Aug 2021 13:15:58 -0500 Subject: [PATCH 05/16] it works! --- shared-module/bitmaptools/__init__.c | 53 +++++++++++++++++++++------- 1 file changed, 40 insertions(+), 13 deletions(-) diff --git a/shared-module/bitmaptools/__init__.c b/shared-module/bitmaptools/__init__.c index 3b421f2ccc..bd3a4b4d8f 100644 --- a/shared-module/bitmaptools/__init__.c +++ b/shared-module/bitmaptools/__init__.c @@ -285,7 +285,7 @@ void common_hal_bitmaptools_paint_fill(displayio_bitmap_t *destination, 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_printf(&mp_plat_print, "\nLen bfore loop: %d", list_length); mp_obj_t current_point; uint32_t current_point_color_value; @@ -295,7 +295,7 @@ void common_hal_bitmaptools_paint_fill(displayio_bitmap_t *destination, 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); + //mp_printf(&mp_plat_print, "\nLen begin loop: %d\n", list_length); current_point = mp_obj_list_pop(fill_area, 0); @@ -306,12 +306,15 @@ void common_hal_bitmaptools_paint_fill(displayio_bitmap_t *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); + //mp_printf(&mp_plat_print, "%d\n", current_point_color_value); if(current_point_color_value != background_value){ mp_obj_list_get(fill_area, &list_length, &fill_points); continue; } + + + displayio_bitmap_write_pixel( destination, mp_obj_get_int(tuple_items[0]), @@ -320,28 +323,52 @@ void common_hal_bitmaptools_paint_fill(displayio_bitmap_t *destination, //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); + //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); mp_obj_t above_point[] = { tuple_items[0], - above}; + MP_OBJ_NEW_SMALL_INT(mp_obj_int_get_checked(tuple_items[1])-1)}; - mp_printf(&mp_plat_print,"above_point:\n"); + //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)); + mp_obj_t left_point[] = { + MP_OBJ_NEW_SMALL_INT(mp_obj_int_get_checked(tuple_items[0])-1), + tuple_items[1]}; + mp_obj_list_append( + fill_area, + mp_obj_new_tuple(2, left_point)); + + mp_obj_t right_point[] = { + MP_OBJ_NEW_SMALL_INT(mp_obj_int_get_checked(tuple_items[0])+1), + tuple_items[1]}; + mp_obj_list_append( + fill_area, + mp_obj_new_tuple(2, right_point)); + + mp_obj_t below_point[] = { + tuple_items[0], + MP_OBJ_NEW_SMALL_INT(mp_obj_int_get_checked(tuple_items[1])+1)}; + mp_obj_list_append( + fill_area, + 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); + //mp_printf(&mp_plat_print, "\nLen end loop: %d\n", list_length); } + 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); From c1e164e1ffc40c521f6c7464c5f10f10e737fa03 Mon Sep 17 00:00:00 2001 From: foamyguy Date: Fri, 13 Aug 2021 09:52:51 -0500 Subject: [PATCH 06/16] rename to boundary_fill and clean up comments --- shared-bindings/bitmaptools/__init__.c | 14 +++--- shared-bindings/bitmaptools/__init__.h | 2 +- shared-module/bitmaptools/__init__.c | 67 ++++---------------------- 3 files changed, 18 insertions(+), 65 deletions(-) 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, From ec8b31e7b4988a68b83f64a22bcb59801a71e841 Mon Sep 17 00:00:00 2001 From: foamyguy Date: Fri, 13 Aug 2021 10:13:38 -0500 Subject: [PATCH 07/16] code format and translations --- locale/circuitpython.pot | 9 +++++++++ shared-module/bitmaptools/__init__.c | 26 +++++++++++++++----------- 2 files changed, 24 insertions(+), 11 deletions(-) diff --git a/locale/circuitpython.pot b/locale/circuitpython.pot index 03e15c6db2..96d1a210f4 100644 --- a/locale/circuitpython.pot +++ b/locale/circuitpython.pot @@ -2566,6 +2566,10 @@ msgstr "" msgid "axis too long" msgstr "" +#: shared-bindings/bitmaptools/__init__.c +msgid "background value out of range of target" +msgstr "" + #: py/builtinevex.c msgid "bad compile mode" msgstr "" @@ -3917,6 +3921,7 @@ msgstr "" #: ports/esp32s2/boards/gravitech_cucumber_rs/mpconfigboard.h #: ports/esp32s2/boards/lilygo_ttgo_t8_s2_st7789/mpconfigboard.h #: ports/esp32s2/boards/microdev_micro_s2/mpconfigboard.h +#: ports/esp32s2/boards/morpheans_morphesp-240/mpconfigboard.h #: ports/esp32s2/boards/muselab_nanoesp32_s2_wroom/mpconfigboard.h #: ports/esp32s2/boards/muselab_nanoesp32_s2_wrover/mpconfigboard.h #: ports/esp32s2/boards/targett_module_clip_wroom/mpconfigboard.h @@ -4358,6 +4363,10 @@ msgstr "" msgid "value must fit in %d byte(s)" msgstr "" +#: shared-bindings/bitmaptools/__init__.c +msgid "value out of range of target" +msgstr "" + #: shared-bindings/displayio/Bitmap.c msgid "value_count must be > 0" msgstr "" diff --git a/shared-module/bitmaptools/__init__.c b/shared-module/bitmaptools/__init__.c index ae00c68b46..43bb53a500 100644 --- a/shared-module/bitmaptools/__init__.c +++ b/shared-module/bitmaptools/__init__.c @@ -263,9 +263,9 @@ void common_hal_bitmaptools_boundary_fill(displayio_bitmap_t *destination, // 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) - ); + fill_area, + mp_obj_new_tuple(2, point) + ); mp_obj_t *fill_points; size_t list_length = 0; @@ -278,7 +278,7 @@ void common_hal_bitmaptools_boundary_fill(displayio_bitmap_t *destination, mp_obj_t *tuple_items; // while there are still points to check - while (list_length > 0){ + while (list_length > 0) { mp_obj_list_get(fill_area, &list_length, &fill_points); current_point = mp_obj_list_pop(fill_area, 0); mp_obj_tuple_get(current_point, &tuple_len, &tuple_items); @@ -288,7 +288,7 @@ void common_hal_bitmaptools_boundary_fill(displayio_bitmap_t *destination, mp_obj_get_int(tuple_items[1])); // if the current point is not background color ignore it - if(current_point_color_value != background_value){ + if (current_point_color_value != background_value) { mp_obj_list_get(fill_area, &list_length, &fill_points); continue; } @@ -303,28 +303,32 @@ void common_hal_bitmaptools_boundary_fill(displayio_bitmap_t *destination, // 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_OBJ_NEW_SMALL_INT(mp_obj_int_get_checked(tuple_items[1]) - 1) + }; mp_obj_list_append( fill_area, mp_obj_new_tuple(2, above_point)); mp_obj_t left_point[] = { - MP_OBJ_NEW_SMALL_INT(mp_obj_int_get_checked(tuple_items[0])-1), - tuple_items[1]}; + MP_OBJ_NEW_SMALL_INT(mp_obj_int_get_checked(tuple_items[0]) - 1), + tuple_items[1] + }; mp_obj_list_append( fill_area, mp_obj_new_tuple(2, left_point)); mp_obj_t right_point[] = { - MP_OBJ_NEW_SMALL_INT(mp_obj_int_get_checked(tuple_items[0])+1), - tuple_items[1]}; + MP_OBJ_NEW_SMALL_INT(mp_obj_int_get_checked(tuple_items[0]) + 1), + tuple_items[1] + }; mp_obj_list_append( fill_area, mp_obj_new_tuple(2, right_point)); mp_obj_t below_point[] = { tuple_items[0], - MP_OBJ_NEW_SMALL_INT(mp_obj_int_get_checked(tuple_items[1])+1)}; + MP_OBJ_NEW_SMALL_INT(mp_obj_int_get_checked(tuple_items[1]) + 1) + }; mp_obj_list_append( fill_area, mp_obj_new_tuple(2, below_point)); From 4d8494f1cd05c18774544296cb78f2fd0944c750 Mon Sep 17 00:00:00 2001 From: foamyguy Date: Fri, 13 Aug 2021 10:42:21 -0500 Subject: [PATCH 08/16] fix stubs --- shared-bindings/bitmaptools/__init__.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/shared-bindings/bitmaptools/__init__.c b/shared-bindings/bitmaptools/__init__.c index 32822fc0a3..e566168879 100644 --- a/shared-bindings/bitmaptools/__init__.c +++ b/shared-bindings/bitmaptools/__init__.c @@ -299,7 +299,7 @@ MP_DEFINE_CONST_FUN_OBJ_KW(bitmaptools_fill_region_obj, 0, bitmaptools_obj_fill_ //| //| def boundary_fill( //| dest_bitmap: displayio.Bitmap, -//| x: int, y: int +//| 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" @@ -309,7 +309,7 @@ MP_DEFINE_CONST_FUN_OBJ_KW(bitmaptools_fill_region_obj, 0, bitmaptools_obj_fill_ //| :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 -//| enclosed area in the destination bitmap""" +//| 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""" //| ... From 6f783060c296ad9787d4295d0d03c8c4c7771d44 Mon Sep 17 00:00:00 2001 From: foamyguy Date: Sun, 15 Aug 2021 19:11:15 -0500 Subject: [PATCH 09/16] ignore points outside of bitmap --- shared-module/bitmaptools/__init__.c | 69 +++++++++++++++++----------- 1 file changed, 41 insertions(+), 28 deletions(-) diff --git a/shared-module/bitmaptools/__init__.c b/shared-module/bitmaptools/__init__.c index 43bb53a500..54489357ef 100644 --- a/shared-module/bitmaptools/__init__.c +++ b/shared-module/bitmaptools/__init__.c @@ -301,37 +301,50 @@ void common_hal_bitmaptools_boundary_fill(displayio_bitmap_t *destination, value); // 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_obj_list_append( - fill_area, - mp_obj_new_tuple(2, above_point)); - mp_obj_t left_point[] = { - MP_OBJ_NEW_SMALL_INT(mp_obj_int_get_checked(tuple_items[0]) - 1), - tuple_items[1] - }; - mp_obj_list_append( - fill_area, - mp_obj_new_tuple(2, left_point)); + // ignore points outside of the bitmap + if (mp_obj_int_get_checked(tuple_items[1]) - 1 >= 0) { + mp_obj_t above_point[] = { + tuple_items[0], + MP_OBJ_NEW_SMALL_INT(mp_obj_int_get_checked(tuple_items[1]) - 1) + }; + mp_obj_list_append( + fill_area, + mp_obj_new_tuple(2, above_point)); + } - mp_obj_t right_point[] = { - MP_OBJ_NEW_SMALL_INT(mp_obj_int_get_checked(tuple_items[0]) + 1), - tuple_items[1] - }; - mp_obj_list_append( - fill_area, - mp_obj_new_tuple(2, right_point)); + // ignore points outside of the bitmap + if (mp_obj_int_get_checked(tuple_items[0]) - 1 >= 0) { + mp_obj_t left_point[] = { + MP_OBJ_NEW_SMALL_INT(mp_obj_int_get_checked(tuple_items[0]) - 1), + tuple_items[1] + }; + mp_obj_list_append( + fill_area, + mp_obj_new_tuple(2, left_point)); + } - mp_obj_t below_point[] = { - tuple_items[0], - MP_OBJ_NEW_SMALL_INT(mp_obj_int_get_checked(tuple_items[1]) + 1) - }; - mp_obj_list_append( - fill_area, - mp_obj_new_tuple(2, below_point)); + // ignore points outside of the bitmap + if (mp_obj_int_get_checked(tuple_items[0]) + 1 < destination->width) { + mp_obj_t right_point[] = { + MP_OBJ_NEW_SMALL_INT(mp_obj_int_get_checked(tuple_items[0]) + 1), + tuple_items[1] + }; + mp_obj_list_append( + fill_area, + mp_obj_new_tuple(2, right_point)); + } + + // ignore points outside of the bitmap + if (mp_obj_int_get_checked(tuple_items[1]) + 1 < destination->height) { + mp_obj_t below_point[] = { + tuple_items[0], + MP_OBJ_NEW_SMALL_INT(mp_obj_int_get_checked(tuple_items[1]) + 1) + }; + mp_obj_list_append( + fill_area, + mp_obj_new_tuple(2, below_point)); + } mp_obj_list_get(fill_area, &list_length, &fill_points); } From 029150ac3b075a8e936e6c722c6f63cf80594e2a Mon Sep 17 00:00:00 2001 From: foamyguy Date: Sun, 15 Aug 2021 19:46:20 -0500 Subject: [PATCH 10/16] validate initial point is in-bounds --- shared-bindings/bitmaptools/__init__.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/shared-bindings/bitmaptools/__init__.c b/shared-bindings/bitmaptools/__init__.c index e566168879..761a94c4c9 100644 --- a/shared-bindings/bitmaptools/__init__.c +++ b/shared-bindings/bitmaptools/__init__.c @@ -345,6 +345,12 @@ STATIC mp_obj_t bitmaptools_obj_boundary_fill(size_t n_args, const mp_obj_t *pos int16_t x = args[ARG_x].u_int; int16_t y = args[ARG_y].u_int; + if (x < 0 || x >= destination->width) { + mp_raise_ValueError(translate("out of range of target")); + } + if (y < 0 || y >= destination->height) { + mp_raise_ValueError(translate("out of range of target")); + } common_hal_bitmaptools_boundary_fill(destination, x, y, value, background_value); From 6bd8a1d6691867a59b2b798436e889379c21a137 Mon Sep 17 00:00:00 2001 From: foamyguy Date: Mon, 16 Aug 2021 09:10:29 -0500 Subject: [PATCH 11/16] ensure bitmap type in argument --- shared-bindings/bitmaptools/__init__.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/shared-bindings/bitmaptools/__init__.c b/shared-bindings/bitmaptools/__init__.c index 761a94c4c9..ccf4413453 100644 --- a/shared-bindings/bitmaptools/__init__.c +++ b/shared-bindings/bitmaptools/__init__.c @@ -327,7 +327,7 @@ STATIC mp_obj_t bitmaptools_obj_boundary_fill(size_t n_args, const mp_obj_t *pos 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 + displayio_bitmap_t *destination = MP_OBJ_TO_PTR(mp_arg_validate_type(args[ARG_dest_bitmap].u_obj, &displayio_bitmap_type, MP_QSTR_dest_bitmap)); // the destination bitmap uint32_t value, color_depth; value = args[ARG_value].u_int; From aeeba3904b45eaf8d088fc6e88584be128a339f8 Mon Sep 17 00:00:00 2001 From: foamyguy Date: Sat, 21 Aug 2021 11:08:25 -0500 Subject: [PATCH 12/16] changed argument names and make replaced_color_value argument optional --- shared-bindings/bitmaptools/__init__.c | 26 +++++++++++++------------- shared-bindings/bitmaptools/__init__.h | 2 +- shared-module/bitmaptools/__init__.c | 23 +++++++++++++++++++---- 3 files changed, 33 insertions(+), 18 deletions(-) diff --git a/shared-bindings/bitmaptools/__init__.c b/shared-bindings/bitmaptools/__init__.c index ccf4413453..4956c61a1f 100644 --- a/shared-bindings/bitmaptools/__init__.c +++ b/shared-bindings/bitmaptools/__init__.c @@ -300,7 +300,7 @@ MP_DEFINE_CONST_FUN_OBJ_KW(bitmaptools_fill_region_obj, 0, bitmaptools_obj_fill_ //| def boundary_fill( //| dest_bitmap: displayio.Bitmap, //| x: int, y: int, -//| value: int, background_value: int) -> None: +//| fill_color_value: int, replaced_color_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. @@ -308,37 +308,37 @@ 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 +//| :param int fill_color_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 +//| :param int replaced_color_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_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}; + enum {ARG_dest_bitmap, ARG_x, ARG_y, ARG_fill_color_value, ARG_replaced_color_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_QSTR_fill_color_value, MP_ARG_REQUIRED | MP_ARG_INT}, + {MP_QSTR_replaced_color_value, MP_ARG_INT, {.u_int = INT_MAX} }, }; 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(mp_arg_validate_type(args[ARG_dest_bitmap].u_obj, &displayio_bitmap_type, MP_QSTR_dest_bitmap)); // the destination bitmap - uint32_t value, color_depth; - value = args[ARG_value].u_int; + uint32_t fill_color_value, color_depth; + fill_color_value = args[ARG_fill_color_value].u_int; color_depth = (1 << destination->bits_per_value); - if (color_depth <= value) { + if (color_depth <= fill_color_value) { mp_raise_ValueError(translate("value out of range of target")); } - uint32_t background_value; - background_value = args[ARG_background_value].u_int; - if (color_depth <= background_value) { + uint32_t replaced_color_value; + replaced_color_value = args[ARG_replaced_color_value].u_int; + if (replaced_color_value != INT_MAX && color_depth <= replaced_color_value) { mp_raise_ValueError(translate("background value out of range of target")); } @@ -352,7 +352,7 @@ STATIC mp_obj_t bitmaptools_obj_boundary_fill(size_t n_args, const mp_obj_t *pos mp_raise_ValueError(translate("out of range of target")); } - common_hal_bitmaptools_boundary_fill(destination, x, y, value, background_value); + common_hal_bitmaptools_boundary_fill(destination, x, y, fill_color_value, replaced_color_value); return mp_const_none; } diff --git a/shared-bindings/bitmaptools/__init__.h b/shared-bindings/bitmaptools/__init__.h index 8e22235e77..6415b20258 100644 --- a/shared-bindings/bitmaptools/__init__.h +++ b/shared-bindings/bitmaptools/__init__.h @@ -48,7 +48,7 @@ void common_hal_bitmaptools_fill_region(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); + uint32_t fill_color_value, uint32_t replaced_color_value); void common_hal_bitmaptools_draw_line(displayio_bitmap_t *destination, int16_t x0, int16_t y0, diff --git a/shared-module/bitmaptools/__init__.c b/shared-module/bitmaptools/__init__.c index 54489357ef..fb7b5242cf 100644 --- a/shared-module/bitmaptools/__init__.c +++ b/shared-module/bitmaptools/__init__.c @@ -255,7 +255,14 @@ void common_hal_bitmaptools_fill_region(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) { + uint32_t fill_color_value, uint32_t replaced_color_value) { + + if (fill_color_value == replaced_color_value) { + // There is nothing to do + return; + } + + uint32_t current_point_color_value; // the list of points that we'll check mp_obj_t fill_area = mp_obj_new_list(0, NULL); @@ -267,12 +274,20 @@ void common_hal_bitmaptools_boundary_fill(displayio_bitmap_t *destination, mp_obj_new_tuple(2, point) ); + if (replaced_color_value == INT_MAX) { + current_point_color_value = common_hal_displayio_bitmap_get_pixel( + destination, + mp_obj_get_int(point[0]), + mp_obj_get_int(point[1])); + replaced_color_value = (uint32_t)current_point_color_value; + } + mp_obj_t *fill_points; size_t list_length = 0; mp_obj_list_get(fill_area, &list_length, &fill_points); mp_obj_t current_point; - uint32_t current_point_color_value; + size_t tuple_len = 0; mp_obj_t *tuple_items; @@ -288,7 +303,7 @@ void common_hal_bitmaptools_boundary_fill(displayio_bitmap_t *destination, mp_obj_get_int(tuple_items[1])); // if the current point is not background color ignore it - if (current_point_color_value != background_value) { + if (current_point_color_value != replaced_color_value) { mp_obj_list_get(fill_area, &list_length, &fill_points); continue; } @@ -298,7 +313,7 @@ void common_hal_bitmaptools_boundary_fill(displayio_bitmap_t *destination, destination, mp_obj_get_int(tuple_items[0]), mp_obj_get_int(tuple_items[1]), - value); + fill_color_value); // add all 4 surrounding points to the list to check From 0f478d59feef6986eb8ba047ec2dd36195dad5dc Mon Sep 17 00:00:00 2001 From: foamyguy Date: Sat, 21 Aug 2021 16:15:59 -0500 Subject: [PATCH 13/16] remove string import. use minimum sized dirty area --- shared-module/bitmaptools/__init__.c | 31 ++++++++++++++++++++++++---- 1 file changed, 27 insertions(+), 4 deletions(-) diff --git a/shared-module/bitmaptools/__init__.c b/shared-module/bitmaptools/__init__.c index fb7b5242cf..38359f5285 100644 --- a/shared-module/bitmaptools/__init__.c +++ b/shared-module/bitmaptools/__init__.c @@ -24,8 +24,6 @@ * THE SOFTWARE. */ -#include - #include "shared-bindings/bitmaptools/__init__.h" #include "shared-bindings/displayio/Bitmap.h" #include "shared-module/displayio/Bitmap.h" @@ -262,6 +260,9 @@ void common_hal_bitmaptools_boundary_fill(displayio_bitmap_t *destination, return; } + + + uint32_t current_point_color_value; // the list of points that we'll check @@ -274,6 +275,11 @@ void common_hal_bitmaptools_boundary_fill(displayio_bitmap_t *destination, mp_obj_new_tuple(2, point) ); + int16_t minx = x; + int16_t miny = x; + int16_t maxx = y; + int16_t maxy = y; + if (replaced_color_value == INT_MAX) { current_point_color_value = common_hal_displayio_bitmap_get_pixel( destination, @@ -288,10 +294,11 @@ void common_hal_bitmaptools_boundary_fill(displayio_bitmap_t *destination, mp_obj_t current_point; - size_t tuple_len = 0; mp_obj_t *tuple_items; + int cur_x, cur_y; + // while there are still points to check while (list_length > 0) { mp_obj_list_get(fill_area, &list_length, &fill_points); @@ -308,6 +315,22 @@ void common_hal_bitmaptools_boundary_fill(displayio_bitmap_t *destination, continue; } + cur_x = mp_obj_int_get_checked(tuple_items[0]); + cur_y = mp_obj_int_get_checked(tuple_items[1]); + + if (cur_x < minx) { + minx = (int16_t)cur_x; + } + if (cur_x > maxx) { + maxx = (int16_t)cur_x; + } + if (cur_y < miny) { + miny = (int16_t)cur_y; + } + if (cur_y > maxy) { + maxy = (int16_t)cur_y; + } + // fill the current point with fill color displayio_bitmap_write_pixel( destination, @@ -365,7 +388,7 @@ void common_hal_bitmaptools_boundary_fill(displayio_bitmap_t *destination, } // set dirty the area so displayio will draw - displayio_area_t area = { 0, 0, destination->width, destination->height }; + displayio_area_t area = { minx, miny, maxx + 1, maxy + 1}; displayio_bitmap_set_dirty_area(destination, &area); } From 707f2e25af2beb017a8f0f5946cd339b8c5be35d Mon Sep 17 00:00:00 2001 From: foamyguy Date: Sun, 22 Aug 2021 08:52:12 -0500 Subject: [PATCH 14/16] disable bitmaptools on devices without enough room --- ports/stm/boards/pyb_nano_v2/mpconfigboard.mk | 1 + ports/stm/boards/stm32f411ve_discovery/mpconfigboard.mk | 1 + 2 files changed, 2 insertions(+) diff --git a/ports/stm/boards/pyb_nano_v2/mpconfigboard.mk b/ports/stm/boards/pyb_nano_v2/mpconfigboard.mk index d1a627569c..4ff181c7f3 100644 --- a/ports/stm/boards/pyb_nano_v2/mpconfigboard.mk +++ b/ports/stm/boards/pyb_nano_v2/mpconfigboard.mk @@ -19,3 +19,4 @@ CIRCUITPY_AUDIOPWMIO = 0 CIRCUITPY_KEYPAD = 0 CIRCUITPY_MIDI = 0 CIRCUITPY_MSGPACK = 0 +CIRCUITPY_BITMAPTOOLS = 0 diff --git a/ports/stm/boards/stm32f411ve_discovery/mpconfigboard.mk b/ports/stm/boards/stm32f411ve_discovery/mpconfigboard.mk index c8dc80a70c..d22075aea5 100644 --- a/ports/stm/boards/stm32f411ve_discovery/mpconfigboard.mk +++ b/ports/stm/boards/stm32f411ve_discovery/mpconfigboard.mk @@ -18,3 +18,4 @@ CIRCUITPY_AUDIOPWMIO = 0 CIRCUITPY_KEYPAD = 0 CIRCUITPY_MIDI = 0 CIRCUITPY_MSGPACK = 0 +CIRCUITPY_BITMAPTOOLS = 0 \ No newline at end of file From 4c95150dabeee366edcb6ec876375c5cee47bd73 Mon Sep 17 00:00:00 2001 From: foamyguy Date: Sun, 22 Aug 2021 08:53:10 -0500 Subject: [PATCH 15/16] eol file --- ports/stm/boards/stm32f411ve_discovery/mpconfigboard.mk | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ports/stm/boards/stm32f411ve_discovery/mpconfigboard.mk b/ports/stm/boards/stm32f411ve_discovery/mpconfigboard.mk index d22075aea5..d5368fa84c 100644 --- a/ports/stm/boards/stm32f411ve_discovery/mpconfigboard.mk +++ b/ports/stm/boards/stm32f411ve_discovery/mpconfigboard.mk @@ -18,4 +18,4 @@ CIRCUITPY_AUDIOPWMIO = 0 CIRCUITPY_KEYPAD = 0 CIRCUITPY_MIDI = 0 CIRCUITPY_MSGPACK = 0 -CIRCUITPY_BITMAPTOOLS = 0 \ No newline at end of file +CIRCUITPY_BITMAPTOOLS = 0 From 80c7a15df7c382b0c821f767f686ebfd497a5b1f Mon Sep 17 00:00:00 2001 From: foamyguy Date: Sun, 22 Aug 2021 10:52:28 -0500 Subject: [PATCH 16/16] fix dirty area initial points --- shared-module/bitmaptools/__init__.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/shared-module/bitmaptools/__init__.c b/shared-module/bitmaptools/__init__.c index 38359f5285..2bb062239a 100644 --- a/shared-module/bitmaptools/__init__.c +++ b/shared-module/bitmaptools/__init__.c @@ -260,9 +260,6 @@ void common_hal_bitmaptools_boundary_fill(displayio_bitmap_t *destination, return; } - - - uint32_t current_point_color_value; // the list of points that we'll check @@ -276,8 +273,8 @@ void common_hal_bitmaptools_boundary_fill(displayio_bitmap_t *destination, ); int16_t minx = x; - int16_t miny = x; - int16_t maxx = y; + int16_t miny = y; + int16_t maxx = x; int16_t maxy = y; if (replaced_color_value == INT_MAX) {