@@ -296,6 +296,63 @@ STATIC mp_obj_t bitmaptools_obj_fill_region(size_t n_args, const mp_obj_t *pos_a
296
296
}
297
297
298
298
MP_DEFINE_CONST_FUN_OBJ_KW (bitmaptools_fill_region_obj , 0 , bitmaptools_obj_fill_region );
299
+ //|
300
+ //| def paint_fill(
301
+ //| dest_bitmap: displayio.Bitmap,
302
+ //| x: int, y: int
303
+ //| value: int, background_value: int) -> None:
304
+ //| """Draws the color value into the destination bitmap enclosed
305
+ //| area of pixels of the background_value color. Like "Paint Bucket"
306
+ //| fill tool.
307
+ //|
308
+ //| :param bitmap dest_bitmap: Destination bitmap that will be written into
309
+ //| :param int x: x-pixel position of the first pixel to check and fill if needed
310
+ //| :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"""
313
+ //| :param int background_value: Bitmap palette index that will filled with the
314
+ //| value color in the enclosed area in the destination bitmap"""
315
+ //| ...
316
+ //|
317
+ STATIC mp_obj_t bitmaptools_obj_paint_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 };
319
+
320
+ static const mp_arg_t allowed_args [] = {
321
+ {MP_QSTR_dest_bitmap , MP_ARG_REQUIRED | MP_ARG_OBJ },
322
+ {MP_QSTR_x , MP_ARG_REQUIRED | MP_ARG_INT },
323
+ {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 },
326
+ };
327
+ mp_arg_val_t args [MP_ARRAY_SIZE (allowed_args )];
328
+ mp_arg_parse_all (n_args , pos_args , kw_args , MP_ARRAY_SIZE (allowed_args ), allowed_args , args );
329
+
330
+ displayio_bitmap_t * destination = MP_OBJ_TO_PTR (args [ARG_dest_bitmap ].u_obj ); // the destination bitmap
331
+
332
+ uint32_t value , color_depth ;
333
+ value = args [ARG_value ].u_int ;
334
+ color_depth = (1 << destination -> bits_per_value );
335
+ if (color_depth <= value ) {
336
+ mp_raise_ValueError (translate ("value out of range of target" ));
337
+ }
338
+
339
+ uint32_t background_value , color_depth ;
340
+ background_value = args [ARG_background_value ].u_int ;
341
+ color_depth = (1 << destination -> bits_per_value );
342
+ if (color_depth <= background_value ) {
343
+ mp_raise_ValueError (translate ("background value out of range of target" ));
344
+ }
345
+
346
+ int16_t x = args [ARG_x ].u_int ;
347
+ int16_t y = args [ARG_y ].u_int ;
348
+
349
+
350
+ common_hal_bitmaptools_paint_fill (destination , x , y , value , background_value );
351
+
352
+ return mp_const_none ;
353
+ }
354
+
355
+ MP_DEFINE_CONST_FUN_OBJ_KW (bitmaptools_paint_fill_obj , 0 , bitmaptools_obj_paint_fill );
299
356
// requires all 6 arguments
300
357
301
358
//|
@@ -520,6 +577,7 @@ STATIC const mp_rom_map_elem_t bitmaptools_module_globals_table[] = {
520
577
{ MP_ROM_QSTR (MP_QSTR_rotozoom ), MP_ROM_PTR (& bitmaptools_rotozoom_obj ) },
521
578
{ MP_ROM_QSTR (MP_QSTR_arrayblit ), MP_ROM_PTR (& bitmaptools_arrayblit_obj ) },
522
579
{ MP_ROM_QSTR (MP_QSTR_fill_region ), MP_ROM_PTR (& bitmaptools_fill_region_obj ) },
580
+ { MP_ROM_QSTR (MP_QSTR_paint_fill ), MP_ROM_PTR (& bitmaptools_paint_fill_obj ) },
523
581
{ MP_ROM_QSTR (MP_QSTR_draw_line ), MP_ROM_PTR (& bitmaptools_draw_line_obj ) },
524
582
};
525
583
STATIC MP_DEFINE_CONST_DICT (bitmaptools_module_globals , bitmaptools_module_globals_table );
0 commit comments