@@ -172,7 +172,66 @@ 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 fill(self, value: int) -> None:
175
+ //| def blit(self, x: int, y: int, source_bitmap: bitmap, x1: int, y1: int, x2: int, y2:int) -> Any:
176
+ //| """Inserts the source_bitmap region defined by rectangular boundaries
177
+ //| (x1,y1) and (x2,y2) into the bitmap at the specified (x,y) location.
178
+ //| :param int x: Horizontal pixel location in bitmap where source_bitmap upper-left
179
+ //| corner will be placed
180
+ //| :param int y: Vertical pixel location in bitmap where source_bitmap upper-left
181
+ //| corner will be placed
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
+ //|
188
+ //| ...
189
+ //|
190
+
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
+
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
+
204
+ if ( (x < 0 ) || (y < 0 ) || (x > self -> width ) || (y > self -> height ) ) {
205
+ mp_raise_ValueError (translate ("(x,y): out of range of target bitmap" ));
206
+ }
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 ) ) {
211
+ mp_raise_ValueError (translate ("(x1,y1) or (x2,y2): out of range of source bitmap" ));
212
+ }
213
+
214
+ // Ensure x1 < x2 and y1 < y2
215
+ if (x1 > x2 ) {
216
+ int16_t temp = x2 ;
217
+ x2 = x1 ;
218
+ x1 = temp ;
219
+ }
220
+ if (y1 > y2 ) {
221
+ int16_t temp = y2 ;
222
+ y2 = y1 ;
223
+ y1 = temp ;
224
+ }
225
+
226
+ common_hal_displayio_bitmap_blit (self , x , y , source , x1 , y1 , x2 , y2 );
227
+
228
+ return mp_const_none ;
229
+ }
230
+
231
+ MP_DEFINE_CONST_FUN_OBJ_KW (displayio_bitmap_blit_obj , 8 , displayio_bitmap_obj_blit );
232
+ // requires 8 parameters
233
+
234
+ //| def fill(self, value: Any) -> Any:
176
235
//| """Fills the bitmap with the supplied palette index value."""
177
236
//| ...
178
237
//|
@@ -192,6 +251,7 @@ MP_DEFINE_CONST_FUN_OBJ_2(displayio_bitmap_fill_obj, displayio_bitmap_obj_fill);
192
251
STATIC const mp_rom_map_elem_t displayio_bitmap_locals_dict_table [] = {
193
252
{ MP_ROM_QSTR (MP_QSTR_height ), MP_ROM_PTR (& displayio_bitmap_height_obj ) },
194
253
{ MP_ROM_QSTR (MP_QSTR_width ), MP_ROM_PTR (& displayio_bitmap_width_obj ) },
254
+ { MP_ROM_QSTR (MP_QSTR_blit ), MP_ROM_PTR (& displayio_bitmap_blit_obj ) },
195
255
{ MP_ROM_QSTR (MP_QSTR_fill ), MP_ROM_PTR (& displayio_bitmap_fill_obj ) },
196
256
197
257
};
0 commit comments