@@ -415,14 +415,30 @@ STATIC mp_obj_t framebuf_line(size_t n_args, const mp_obj_t *args) {
415
415
}
416
416
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN (framebuf_line_obj , 6 , 6 , framebuf_line );
417
417
418
- STATIC mp_obj_t framebuf_blit (size_t n_args , const mp_obj_t * args ) {
419
- mp_obj_framebuf_t * self = MP_OBJ_TO_PTR (args [0 ]);
420
- mp_obj_framebuf_t * source = MP_OBJ_TO_PTR (args [1 ]);
421
- mp_int_t x = mp_obj_get_int (args [2 ]);
422
- mp_int_t y = mp_obj_get_int (args [3 ]);
423
- mp_int_t key = -1 ;
424
- if (n_args > 4 ) {
425
- key = mp_obj_get_int (args [4 ]);
418
+ STATIC mp_obj_t framebuf_blit (size_t n_args , const mp_obj_t * pos_args , mp_map_t * kw_args ) {
419
+ enum { ARG_self , ARG_source , ARG_x , ARG_y , ARG_key , ARG_remap };
420
+ static const mp_arg_t allowed_args [] = {
421
+ { MP_QSTR_self , MP_ARG_REQUIRED | MP_ARG_OBJ },
422
+ { MP_QSTR_source , MP_ARG_REQUIRED | MP_ARG_OBJ },
423
+ { MP_QSTR_x , MP_ARG_INT | MP_ARG_REQUIRED },
424
+ { MP_QSTR_y , MP_ARG_INT | MP_ARG_REQUIRED },
425
+ { MP_QSTR_key , MP_ARG_INT , {.u_int = -1 } },
426
+ { MP_QSTR_remap , MP_ARG_OBJ , {.u_obj = MP_OBJ_NULL } },
427
+ };
428
+ mp_arg_val_t args [MP_ARRAY_SIZE (allowed_args )];
429
+ mp_arg_parse_all (n_args , pos_args , kw_args ,
430
+ MP_ARRAY_SIZE (allowed_args ), allowed_args , args );
431
+
432
+ mp_obj_framebuf_t * self = args [ARG_self ].u_obj ;
433
+ mp_obj_framebuf_t * source = args [ARG_source ].u_obj ;
434
+ mp_int_t x = args [ARG_x ].u_int ;
435
+ mp_int_t y = args [ARG_y ].u_int ;
436
+ mp_int_t key = args [ARG_key ].u_int ;
437
+
438
+ size_t remap_size = 0 ;
439
+ mp_obj_t * remap ;
440
+ if (args [ARG_remap ].u_obj != MP_OBJ_NULL ) {
441
+ mp_obj_get_array (args [ARG_remap ].u_obj , & remap_size , & remap );
426
442
}
427
443
428
444
if (
@@ -449,6 +465,9 @@ STATIC mp_obj_t framebuf_blit(size_t n_args, const mp_obj_t *args) {
449
465
for (int cx0 = x0 ; cx0 < x0end ; ++ cx0 ) {
450
466
color = getpixel (source , cx1 , y1 );
451
467
if (color != (uint32_t )key ) {
468
+ if (color < remap_size ) {
469
+ color = mp_obj_get_int (remap [color ]);
470
+ }
452
471
setpixel (self , cx0 , y0 , color );
453
472
}
454
473
++ cx1 ;
@@ -457,7 +476,7 @@ STATIC mp_obj_t framebuf_blit(size_t n_args, const mp_obj_t *args) {
457
476
}
458
477
return mp_const_none ;
459
478
}
460
- STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN (framebuf_blit_obj , 4 , 5 , framebuf_blit );
479
+ STATIC MP_DEFINE_CONST_FUN_OBJ_KW (framebuf_blit_obj , 4 , framebuf_blit );
461
480
462
481
STATIC mp_obj_t framebuf_scroll (mp_obj_t self_in , mp_obj_t xstep_in , mp_obj_t ystep_in ) {
463
482
mp_obj_framebuf_t * self = MP_OBJ_TO_PTR (self_in );
0 commit comments