Skip to content

Commit c1e164e

Browse files
committed
rename to boundary_fill and clean up comments
1 parent 0bbb0f1 commit c1e164e

File tree

3 files changed

+18
-65
lines changed

3 files changed

+18
-65
lines changed

shared-bindings/bitmaptools/__init__.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,7 @@ STATIC mp_obj_t bitmaptools_obj_fill_region(size_t n_args, const mp_obj_t *pos_a
297297

298298
MP_DEFINE_CONST_FUN_OBJ_KW(bitmaptools_fill_region_obj, 0, bitmaptools_obj_fill_region);
299299
//|
300-
//| def paint_fill(
300+
//| def boundary_fill(
301301
//| dest_bitmap: displayio.Bitmap,
302302
//| x: int, y: int
303303
//| value: int, background_value: int) -> None:
@@ -308,13 +308,13 @@ MP_DEFINE_CONST_FUN_OBJ_KW(bitmaptools_fill_region_obj, 0, bitmaptools_obj_fill_
308308
//| :param bitmap dest_bitmap: Destination bitmap that will be written into
309309
//| :param int x: x-pixel position of the first pixel to check and fill if needed
310310
//| :param int y: y-pixel position of the first pixel to check and fill if needed
311-
//| :param int value: Bitmap palette index that will be written into the rectangular
312-
//| fill region in the destination bitmap"""
311+
//| :param int value: Bitmap palette index that will be written into the
312+
//| enclosed area in the destination bitmap"""
313313
//| :param int background_value: Bitmap palette index that will filled with the
314314
//| value color in the enclosed area in the destination bitmap"""
315315
//| ...
316316
//|
317-
STATIC mp_obj_t bitmaptools_obj_paint_fill(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
317+
STATIC mp_obj_t bitmaptools_obj_boundary_fill(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
318318
enum {ARG_dest_bitmap, ARG_x, ARG_y, ARG_value, ARG_background_value};
319319

320320
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
346346
int16_t y = args[ARG_y].u_int;
347347

348348

349-
common_hal_bitmaptools_paint_fill(destination, x, y, value, background_value);
349+
common_hal_bitmaptools_boundary_fill(destination, x, y, value, background_value);
350350

351351
return mp_const_none;
352352
}
353353

354-
MP_DEFINE_CONST_FUN_OBJ_KW(bitmaptools_paint_fill_obj, 0, bitmaptools_obj_paint_fill);
354+
MP_DEFINE_CONST_FUN_OBJ_KW(bitmaptools_boundary_fill_obj, 0, bitmaptools_obj_boundary_fill);
355355
// requires all 6 arguments
356356

357357
//|
@@ -576,7 +576,7 @@ STATIC const mp_rom_map_elem_t bitmaptools_module_globals_table[] = {
576576
{ MP_ROM_QSTR(MP_QSTR_rotozoom), MP_ROM_PTR(&bitmaptools_rotozoom_obj) },
577577
{ MP_ROM_QSTR(MP_QSTR_arrayblit), MP_ROM_PTR(&bitmaptools_arrayblit_obj) },
578578
{ MP_ROM_QSTR(MP_QSTR_fill_region), MP_ROM_PTR(&bitmaptools_fill_region_obj) },
579-
{ MP_ROM_QSTR(MP_QSTR_paint_fill), MP_ROM_PTR(&bitmaptools_paint_fill_obj) },
579+
{ MP_ROM_QSTR(MP_QSTR_boundary_fill), MP_ROM_PTR(&bitmaptools_boundary_fill_obj) },
580580
{ MP_ROM_QSTR(MP_QSTR_draw_line), MP_ROM_PTR(&bitmaptools_draw_line_obj) },
581581
};
582582
STATIC MP_DEFINE_CONST_DICT(bitmaptools_module_globals, bitmaptools_module_globals_table);

shared-bindings/bitmaptools/__init__.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ void common_hal_bitmaptools_fill_region(displayio_bitmap_t *destination,
4646
int16_t x2, int16_t y2,
4747
uint32_t value);
4848

49-
void common_hal_bitmaptools_paint_fill(displayio_bitmap_t *destination,
49+
void common_hal_bitmaptools_boundary_fill(displayio_bitmap_t *destination,
5050
int16_t x, int16_t y,
5151
uint32_t value, uint32_t background_value);
5252

shared-module/bitmaptools/__init__.c

Lines changed: 10 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -253,90 +253,57 @@ void common_hal_bitmaptools_fill_region(displayio_bitmap_t *destination,
253253
}
254254
}
255255

256-
void common_hal_bitmaptools_paint_fill(displayio_bitmap_t *destination,
256+
void common_hal_bitmaptools_boundary_fill(displayio_bitmap_t *destination,
257257
int16_t x, int16_t y,
258258
uint32_t value, uint32_t background_value) {
259259

260-
/*def _boundaryFill4(self, px, py, fc, bc): # px & py = x, y coord to start fill, fc = fill color, bc = background color
261-
fillArea = [[px, py]]
262-
263-
while len(fillArea) > 0:
264-
x, y = fillArea.pop()
265-
266-
if self._bitmap[x, y] != bc:
267-
continue
268-
self._bitmap[x, y] = fc
269-
fillArea.append((x + 1, y))
270-
fillArea.append((x - 1, y))
271-
fillArea.append((x, y + 1))
272-
fillArea.append((x, y - 1))*/
273-
260+
// the list of points that we'll check
274261
mp_obj_t fill_area = mp_obj_new_list(0, NULL);
262+
263+
// first point is the one user passed in
275264
mp_obj_t point[] = { mp_obj_new_int(x), mp_obj_new_int(y) };
276265
mp_obj_list_append(
277266
fill_area,
278267
mp_obj_new_tuple(2, point)
279268
);
280-
//mp_obj_list_t *point;
281-
//mp_obj_list_append(point, x);
282-
//mp_obj_list_append(point, y);
283-
284269

285270
mp_obj_t *fill_points;
286271
size_t list_length = 0;
287272
mp_obj_list_get(fill_area, &list_length, &fill_points);
288-
//mp_printf(&mp_plat_print, "\nLen bfore loop: %d", list_length);
273+
289274
mp_obj_t current_point;
290275
uint32_t current_point_color_value;
291276

292277
size_t tuple_len = 0;
293278
mp_obj_t *tuple_items;
294279

295-
280+
// while there are still points to check
296281
while (list_length > 0){
297282
mp_obj_list_get(fill_area, &list_length, &fill_points);
298-
//mp_printf(&mp_plat_print, "\nLen begin loop: %d\n", list_length);
299283
current_point = mp_obj_list_pop(fill_area, 0);
300-
301-
302-
//mp_obj_print(current_point, PRINT_STR);
303284
mp_obj_tuple_get(current_point, &tuple_len, &tuple_items);
304285
current_point_color_value = common_hal_displayio_bitmap_get_pixel(
305286
destination,
306287
mp_obj_get_int(tuple_items[0]),
307288
mp_obj_get_int(tuple_items[1]));
308289

309-
//mp_printf(&mp_plat_print, "%d\n", current_point_color_value);
310-
290+
// if the current point is not background color ignore it
311291
if(current_point_color_value != background_value){
312292
mp_obj_list_get(fill_area, &list_length, &fill_points);
313293
continue;
314294
}
315295

316-
317-
296+
// fill the current point with fill color
318297
displayio_bitmap_write_pixel(
319298
destination,
320299
mp_obj_get_int(tuple_items[0]),
321300
mp_obj_get_int(tuple_items[1]),
322301
value);
323302

324-
325-
//mp_obj_t above_point[] = { mp_obj_new_int(tuple_items[0]), mp_obj_new_int(tuple_items[1])-1 };
326-
//mp_printf(&mp_plat_print,"math:\n");
327-
//mp_printf(&mp_plat_print, "%d\n", mp_obj_get_int(tuple_items[0]));
328-
//mp_printf(&mp_plat_print, "%d\n", mp_obj_get_int(tuple_items[0])+1);
329-
//int16_t above_int = mp_obj_get_int(tuple_items[0])+1;
330-
//mp_printf(&mp_plat_print, "%d\n", above_int);
331-
//int16_t *above = &above_int;
332-
//mp_printf(&mp_plat_print, "%d\n", above);
333-
303+
// add all 4 surrounding points to the list to check
334304
mp_obj_t above_point[] = {
335305
tuple_items[0],
336306
MP_OBJ_NEW_SMALL_INT(mp_obj_int_get_checked(tuple_items[1])-1)};
337-
338-
//mp_printf(&mp_plat_print,"above_point:\n");
339-
//mp_obj_print(above_point, PRINT_STR);
340307
mp_obj_list_append(
341308
fill_area,
342309
mp_obj_new_tuple(2, above_point));
@@ -363,26 +330,12 @@ void common_hal_bitmaptools_paint_fill(displayio_bitmap_t *destination,
363330
mp_obj_new_tuple(2, below_point));
364331

365332
mp_obj_list_get(fill_area, &list_length, &fill_points);
366-
//mp_printf(&mp_plat_print, "\nLen end loop: %d\n", list_length);
367333
}
368334

335+
// set dirty the area so displayio will draw
369336
displayio_area_t area = { 0, 0, destination->width, destination->height };
370337
displayio_bitmap_set_dirty_area(destination, &area);
371338

372-
//mp_obj_print(fill_area, PRINT_STR);
373-
//mp_obj_print(current_point[0], PRINT_STR);
374-
375-
/*
376-
mp_printf(&mp_plat_print, "\nLen: %d", list_length);
377-
size_t tuple_len = 0;
378-
mp_obj_t *tuple_items;
379-
mp_obj_tuple_get(current_point[0], &tuple_len, &tuple_items);
380-
381-
//mp_obj_print(mp_obj_get_int(tuple_items[0])+1, PRINT_STR);
382-
383-
mp_printf(&mp_plat_print, "\n%d", mp_obj_get_int(tuple_items[0])+1);
384-
*/
385-
386339
}
387340

388341
void common_hal_bitmaptools_draw_line(displayio_bitmap_t *destination,

0 commit comments

Comments
 (0)