@@ -172,7 +172,78 @@ 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 insert(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_insert(mp_obj_t self_in, mp_obj_t x_obj, mp_obj_t y_obj, mp_obj_t source_in, mp_obj_t x1_obj, mp_obj_t y1_obj, mp_obj_t x2_obj, mp_obj_t y2_obj){
192
+ STATIC mp_obj_t displayio_bitmap_obj_insert (size_t n_args , const mp_obj_t * pos_args , mp_map_t * kw_args ){
193
+
194
+ // // convert the inputs into the correct type
195
+ // displayio_bitmap_t *self = MP_OBJ_TO_PTR(self_in);
196
+ // int16_t x = mp_obj_get_int(x_obj);
197
+ // int16_t y = mp_obj_get_int(y_obj);
198
+ // displayio_bitmap_t *source = MP_OBJ_TO_PTR(source_in);
199
+ // int16_t x1 = mp_obj_get_int(x1_obj);
200
+ // int16_t y1 = mp_obj_get_int(y1_obj);
201
+ // int16_t x2 = mp_obj_get_int(x2_obj);
202
+ // int16_t y2 = mp_obj_get_int(y2_obj);
203
+ displayio_bitmap_t * self = MP_OBJ_TO_PTR (pos_args [0 ]);
204
+ int16_t x = mp_obj_get_int (pos_args [1 ]);
205
+ int16_t y = mp_obj_get_int (pos_args [2 ]);
206
+ displayio_bitmap_t * source = MP_OBJ_TO_PTR (pos_args [3 ]);
207
+ int16_t x1 = mp_obj_get_int (pos_args [4 ]);
208
+ int16_t y1 = mp_obj_get_int (pos_args [5 ]);
209
+ int16_t x2 = mp_obj_get_int (pos_args [6 ]);
210
+ int16_t y2 = mp_obj_get_int (pos_args [7 ]);
211
+
212
+
213
+
214
+
215
+ if ( (x < 0 ) || (y < 0 ) || (x > self -> width ) || (y > self -> height ) ) {
216
+ mp_raise_ValueError (translate ("(x,y): out of range of target bitmap" ));
217
+ }
218
+ if ( (x1 < 0 ) || (x1 > source -> width ) ||
219
+ (y1 < 0 ) || (y1 > source -> height ) ||
220
+ (x2 < 0 ) || (x2 > source -> width ) ||
221
+ (y2 < 0 ) || (y2 > source -> height ) ) {
222
+ mp_raise_ValueError (translate ("(x1,y1) or (x2,y2): out of range of source bitmap" ));
223
+ }
224
+
225
+ // Ensure x1 < x2 and y1 < y2
226
+ if (x1 > x2 ) {
227
+ int16_t temp = x2 ;
228
+ x2 = x1 ;
229
+ x1 = temp ;
230
+ }
231
+ if (y1 > y2 ) {
232
+ int16_t temp = y2 ;
233
+ y2 = y1 ;
234
+ y1 = temp ;
235
+ }
236
+
237
+ common_hal_displayio_bitmap_insert (self , x , y , source , x1 , y1 , x2 , y2 );
238
+
239
+ return mp_const_none ;
240
+ }
241
+
242
+ MP_DEFINE_CONST_FUN_OBJ_KW (displayio_bitmap_insert_obj , 8 , displayio_bitmap_obj_insert );
243
+ /// What should this number value be? ****
244
+
245
+
246
+ //| def fill(self, value: Any) -> Any:
176
247
//| """Fills the bitmap with the supplied palette index value."""
177
248
//| ...
178
249
//|
@@ -192,6 +263,7 @@ MP_DEFINE_CONST_FUN_OBJ_2(displayio_bitmap_fill_obj, displayio_bitmap_obj_fill);
192
263
STATIC const mp_rom_map_elem_t displayio_bitmap_locals_dict_table [] = {
193
264
{ MP_ROM_QSTR (MP_QSTR_height ), MP_ROM_PTR (& displayio_bitmap_height_obj ) },
194
265
{ MP_ROM_QSTR (MP_QSTR_width ), MP_ROM_PTR (& displayio_bitmap_width_obj ) },
266
+ { MP_ROM_QSTR (MP_QSTR_insert ), MP_ROM_PTR (& displayio_bitmap_insert_obj ) }, // Added insert function 8/7/2020
195
267
{ MP_ROM_QSTR (MP_QSTR_fill ), MP_ROM_PTR (& displayio_bitmap_fill_obj ) },
196
268
197
269
};
0 commit comments