Skip to content

Commit aeeba39

Browse files
committed
changed argument names and make replaced_color_value argument optional
1 parent 6bd8a1d commit aeeba39

File tree

3 files changed

+33
-18
lines changed

3 files changed

+33
-18
lines changed

shared-bindings/bitmaptools/__init__.c

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -300,45 +300,45 @@ MP_DEFINE_CONST_FUN_OBJ_KW(bitmaptools_fill_region_obj, 0, bitmaptools_obj_fill_
300300
//| def boundary_fill(
301301
//| dest_bitmap: displayio.Bitmap,
302302
//| x: int, y: int,
303-
//| value: int, background_value: int) -> None:
303+
//| fill_color_value: int, replaced_color_value: int) -> None:
304304
//| """Draws the color value into the destination bitmap enclosed
305305
//| area of pixels of the background_value color. Like "Paint Bucket"
306306
//| fill tool.
307307
//|
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
311+
//| :param int fill_color_value: Bitmap palette index that will be written into the
312312
//| enclosed area in the destination bitmap
313-
//| :param int background_value: Bitmap palette index that will filled with the
313+
//| :param int replaced_color_value: Bitmap palette index that will filled with the
314314
//| value color in the enclosed area in the destination bitmap"""
315315
//| ...
316316
//|
317317
STATIC mp_obj_t bitmaptools_obj_boundary_fill(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
318-
enum {ARG_dest_bitmap, ARG_x, ARG_y, ARG_value, ARG_background_value};
318+
enum {ARG_dest_bitmap, ARG_x, ARG_y, ARG_fill_color_value, ARG_replaced_color_value};
319319

320320
static const mp_arg_t allowed_args[] = {
321321
{MP_QSTR_dest_bitmap, MP_ARG_REQUIRED | MP_ARG_OBJ},
322322
{MP_QSTR_x, MP_ARG_REQUIRED | MP_ARG_INT},
323323
{MP_QSTR_y, MP_ARG_REQUIRED | MP_ARG_INT},
324-
{MP_QSTR_value, MP_ARG_REQUIRED | MP_ARG_INT},
325-
{MP_QSTR_background_value, MP_ARG_REQUIRED | MP_ARG_INT},
324+
{MP_QSTR_fill_color_value, MP_ARG_REQUIRED | MP_ARG_INT},
325+
{MP_QSTR_replaced_color_value, MP_ARG_INT, {.u_int = INT_MAX} },
326326
};
327327
mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)];
328328
mp_arg_parse_all(n_args, pos_args, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args);
329329

330330
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
331331

332-
uint32_t value, color_depth;
333-
value = args[ARG_value].u_int;
332+
uint32_t fill_color_value, color_depth;
333+
fill_color_value = args[ARG_fill_color_value].u_int;
334334
color_depth = (1 << destination->bits_per_value);
335-
if (color_depth <= value) {
335+
if (color_depth <= fill_color_value) {
336336
mp_raise_ValueError(translate("value out of range of target"));
337337
}
338338

339-
uint32_t background_value;
340-
background_value = args[ARG_background_value].u_int;
341-
if (color_depth <= background_value) {
339+
uint32_t replaced_color_value;
340+
replaced_color_value = args[ARG_replaced_color_value].u_int;
341+
if (replaced_color_value != INT_MAX && color_depth <= replaced_color_value) {
342342
mp_raise_ValueError(translate("background value out of range of target"));
343343
}
344344

@@ -352,7 +352,7 @@ STATIC mp_obj_t bitmaptools_obj_boundary_fill(size_t n_args, const mp_obj_t *pos
352352
mp_raise_ValueError(translate("out of range of target"));
353353
}
354354

355-
common_hal_bitmaptools_boundary_fill(destination, x, y, value, background_value);
355+
common_hal_bitmaptools_boundary_fill(destination, x, y, fill_color_value, replaced_color_value);
356356

357357
return mp_const_none;
358358
}

shared-bindings/bitmaptools/__init__.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ void common_hal_bitmaptools_fill_region(displayio_bitmap_t *destination,
4848

4949
void common_hal_bitmaptools_boundary_fill(displayio_bitmap_t *destination,
5050
int16_t x, int16_t y,
51-
uint32_t value, uint32_t background_value);
51+
uint32_t fill_color_value, uint32_t replaced_color_value);
5252

5353
void common_hal_bitmaptools_draw_line(displayio_bitmap_t *destination,
5454
int16_t x0, int16_t y0,

shared-module/bitmaptools/__init__.c

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,14 @@ void common_hal_bitmaptools_fill_region(displayio_bitmap_t *destination,
255255

256256
void common_hal_bitmaptools_boundary_fill(displayio_bitmap_t *destination,
257257
int16_t x, int16_t y,
258-
uint32_t value, uint32_t background_value) {
258+
uint32_t fill_color_value, uint32_t replaced_color_value) {
259+
260+
if (fill_color_value == replaced_color_value) {
261+
// There is nothing to do
262+
return;
263+
}
264+
265+
uint32_t current_point_color_value;
259266

260267
// the list of points that we'll check
261268
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,
267274
mp_obj_new_tuple(2, point)
268275
);
269276

277+
if (replaced_color_value == INT_MAX) {
278+
current_point_color_value = common_hal_displayio_bitmap_get_pixel(
279+
destination,
280+
mp_obj_get_int(point[0]),
281+
mp_obj_get_int(point[1]));
282+
replaced_color_value = (uint32_t)current_point_color_value;
283+
}
284+
270285
mp_obj_t *fill_points;
271286
size_t list_length = 0;
272287
mp_obj_list_get(fill_area, &list_length, &fill_points);
273288

274289
mp_obj_t current_point;
275-
uint32_t current_point_color_value;
290+
276291

277292
size_t tuple_len = 0;
278293
mp_obj_t *tuple_items;
@@ -288,7 +303,7 @@ void common_hal_bitmaptools_boundary_fill(displayio_bitmap_t *destination,
288303
mp_obj_get_int(tuple_items[1]));
289304

290305
// if the current point is not background color ignore it
291-
if (current_point_color_value != background_value) {
306+
if (current_point_color_value != replaced_color_value) {
292307
mp_obj_list_get(fill_area, &list_length, &fill_points);
293308
continue;
294309
}
@@ -298,7 +313,7 @@ void common_hal_bitmaptools_boundary_fill(displayio_bitmap_t *destination,
298313
destination,
299314
mp_obj_get_int(tuple_items[0]),
300315
mp_obj_get_int(tuple_items[1]),
301-
value);
316+
fill_color_value);
302317

303318
// add all 4 surrounding points to the list to check
304319

0 commit comments

Comments
 (0)