@@ -172,42 +172,82 @@ STATIC mp_obj_t bitmap_subscr(mp_obj_t self_in, mp_obj_t index_obj, mp_obj_t val
172
172
return mp_const_none ;
173
173
}
174
174
175
- //| def blit(self, x: int, y: int, source_bitmap: bitmap, x1: int, y1: int, x2: int, y2:int) -> Any:
175
+ //| def blit(self, x: int, y: int, source_bitmap: bitmap, x1: int, y1: int, x2: int, y2: int, skip_index: int) -> Any:
176
176
//| """Inserts the source_bitmap region defined by rectangular boundaries
177
177
//| (x1,y1) and (x2,y2) into the bitmap at the specified (x,y) location.
178
178
//| :param int x: Horizontal pixel location in bitmap where source_bitmap upper-left
179
179
//| corner will be placed
180
180
//| :param int y: Vertical pixel location in bitmap where source_bitmap upper-left
181
181
//| corner will be placed
182
182
//| :param bitmap source_bitmap: Source bitmap that contains the graphical region to be copied
183
- //| : param x1: Minimum x-value for rectangular bounding box to be copied from the source bitmap
184
- //| : param y1: Minimum y-value for rectangular bounding box to be copied from the source bitmap
185
- //| : param x2: Maximum x-value for rectangular bounding box to be copied from the source bitmap
186
- //| : param y2: Maximum y-value for rectangular bounding box to be copied from the source bitmap
187
- //|
183
+ //| : param int x1: Minimum x-value for rectangular bounding box to be copied from the source bitmap
184
+ //| : param int y1: Minimum y-value for rectangular bounding box to be copied from the source bitmap
185
+ //| : param int x2: Maximum x-value for rectangular bounding box to be copied from the source bitmap
186
+ //| : param int y2: Maximum y-value for rectangular bounding box to be copied from the source bitmap
187
+ //| : param int skip_index: bitmap palette index in the source that will not be copied, set `None` to copy all pixels
188
188
//| ...
189
189
//|
190
190
191
191
STATIC mp_obj_t displayio_bitmap_obj_blit (size_t n_args , const mp_obj_t * pos_args , mp_map_t * kw_args ){
192
+ enum {ARG_x , ARG_y , ARG_source , ARG_x1 , ARG_y1 , ARG_x2 , ARG_y2 , ARG_skip_index };
193
+ static const mp_arg_t allowed_args [] = {
194
+ {MP_QSTR_x , MP_ARG_REQUIRED | MP_ARG_INT },
195
+ {MP_QSTR_y , MP_ARG_REQUIRED | MP_ARG_INT },
196
+ {MP_QSTR_source , MP_ARG_REQUIRED | MP_ARG_OBJ },
197
+ {MP_QSTR_x1 , MP_ARG_KW_ONLY | MP_ARG_OBJ , {.u_obj = mp_const_none } },
198
+ {MP_QSTR_y1 , MP_ARG_KW_ONLY | MP_ARG_OBJ , {.u_obj = mp_const_none } },
199
+ {MP_QSTR_x2 , MP_ARG_KW_ONLY | MP_ARG_OBJ , {.u_obj = mp_const_none } }, // None convert to source->width
200
+ {MP_QSTR_y2 , MP_ARG_KW_ONLY | MP_ARG_OBJ , {.u_obj = mp_const_none } }, // None convert to source->height
201
+ {MP_QSTR_skip_index , MP_ARG_OBJ | MP_ARG_KW_ONLY , {.u_obj = mp_const_none } },
202
+ };
203
+ mp_arg_val_t args [MP_ARRAY_SIZE (allowed_args )];
204
+ mp_arg_parse_all (n_args - 1 , pos_args + 1 , kw_args , MP_ARRAY_SIZE (allowed_args ), allowed_args , args );
205
+
206
+ displayio_bitmap_t * self = MP_OBJ_TO_PTR (pos_args [0 ]); //*******
207
+
208
+ int16_t x = args [ARG_x ].u_int ;
209
+ int16_t y = args [ARG_y ].u_int ;
210
+
211
+ displayio_bitmap_t * source = MP_OBJ_TO_PTR (args [ARG_source ].u_obj );
212
+
213
+ int16_t x1 , y1 ;
214
+ // if x1 or y1 is None, then set as the zero-point of the bitmap
215
+ if ( args [ARG_x1 ].u_obj == mp_const_none ) {
216
+ x1 = 0 ;
217
+ } else {
218
+ x1 = mp_obj_get_int (args [ARG_x1 ].u_obj );
219
+ }
220
+ //int16_t y1;
221
+ if ( args [ARG_y1 ].u_obj == mp_const_none ) {
222
+ y1 = 0 ;
223
+ } else {
224
+ y1 = mp_obj_get_int (args [ARG_y1 ].u_obj );
225
+ }
226
+
227
+ int16_t x2 , y2 ;
228
+ // if x2 or y2 is None, then set as the maximum size of the source bitmap
229
+ if ( args [ARG_x2 ].u_obj == mp_const_none ) {
230
+ x2 = source -> width - 1 ;
231
+ } else {
232
+ x2 = mp_obj_get_int (args [ARG_x2 ].u_obj );
233
+ }
234
+ //int16_t y2;
235
+ if ( args [ARG_y2 ].u_obj == mp_const_none ) {
236
+ y2 = source -> height - 1 ;
237
+ } else {
238
+ y2 = mp_obj_get_int (args [ARG_y2 ].u_obj );
239
+ }
192
240
193
- // Consider improving the input checking.
194
-
195
- displayio_bitmap_t * self = MP_OBJ_TO_PTR (pos_args [0 ]);
196
- int16_t x = mp_obj_get_int (pos_args [1 ]);
197
- int16_t y = mp_obj_get_int (pos_args [2 ]);
198
- displayio_bitmap_t * source = MP_OBJ_TO_PTR (pos_args [3 ]);
199
- int16_t x1 = mp_obj_get_int (pos_args [4 ]);
200
- int16_t y1 = mp_obj_get_int (pos_args [5 ]);
201
- int16_t x2 = mp_obj_get_int (pos_args [6 ]);
202
- int16_t y2 = mp_obj_get_int (pos_args [7 ]);
203
241
204
- if ( (x < 0 ) || (y < 0 ) || (x > self -> width ) || (y > self -> height ) ) {
242
+ // Check x,y are within self (target) bitmap boundary
243
+ if ( (x < 0 ) || (y < 0 ) || (x >= self -> width ) || (y >= self -> height ) ) {
205
244
mp_raise_ValueError (translate ("(x,y): out of range of target bitmap" ));
206
245
}
207
- if ( (x1 < 0 ) || (x1 > source -> width ) ||
208
- (y1 < 0 ) || (y1 > source -> height ) ||
209
- (x2 < 0 ) || (x2 > source -> width ) ||
210
- (y2 < 0 ) || (y2 > source -> height ) ) {
246
+ // Check x1,y1,x2,y2 are within source bitmap boundary
247
+ if ( (x1 < 0 ) || (x1 >= source -> width ) ||
248
+ (y1 < 0 ) || (y1 >= source -> height ) ||
249
+ (x2 < 0 ) || (x2 >= source -> width ) ||
250
+ (y2 < 0 ) || (y2 >= source -> height ) ) {
211
251
mp_raise_ValueError (translate ("(x1,y1) or (x2,y2): out of range of source bitmap" ));
212
252
}
213
253
@@ -223,13 +263,23 @@ STATIC mp_obj_t displayio_bitmap_obj_blit(size_t n_args, const mp_obj_t *pos_arg
223
263
y1 = temp ;
224
264
}
225
265
226
- common_hal_displayio_bitmap_blit (self , x , y , source , x1 , y1 , x2 , y2 );
266
+ uint32_t skip_index ;
267
+ bool skip_index_none ; // flag whether skip_value was None
268
+
269
+ if (args [ARG_skip_index ].u_obj == mp_const_none ) {
270
+ skip_index = 0 ;
271
+ skip_index_none = true;
272
+ } else {
273
+ skip_index = mp_obj_get_int (args [ARG_skip_index ].u_obj );
274
+ skip_index_none = false;
275
+ }
276
+
277
+ common_hal_displayio_bitmap_blit (self , x , y , source , x1 , y1 , x2 , y2 , skip_index , skip_index_none );
227
278
228
279
return mp_const_none ;
229
280
}
230
-
231
- MP_DEFINE_CONST_FUN_OBJ_KW (displayio_bitmap_blit_obj , 8 , displayio_bitmap_obj_blit );
232
- // requires 8 parameters
281
+ MP_DEFINE_CONST_FUN_OBJ_KW (displayio_bitmap_blit_obj , 4 , displayio_bitmap_obj_blit );
282
+ // `displayio_bitmap_obj_blit` requires at least 4 arguments
233
283
234
284
//| def fill(self, value: Any) -> Any:
235
285
//| """Fills the bitmap with the supplied palette index value."""
0 commit comments