@@ -84,11 +84,19 @@ STATIC mp_obj_t displayio_bitmap_make_new(const mp_obj_type_t *type, size_t n_ar
84
84
85
85
return MP_OBJ_FROM_PTR (self );
86
86
}
87
+
88
+ STATIC void check_for_deinit (displayio_bitmap_t * self ) {
89
+ if (common_hal_displayio_bitmap_deinited (self )) {
90
+ raise_deinited_error ();
91
+ }
92
+ }
93
+
87
94
//| width: int
88
95
//| """Width of the bitmap. (read only)"""
89
96
STATIC mp_obj_t displayio_bitmap_obj_get_width (mp_obj_t self_in ) {
90
97
displayio_bitmap_t * self = MP_OBJ_TO_PTR (self_in );
91
98
99
+ check_for_deinit (self );
92
100
return MP_OBJ_NEW_SMALL_INT (common_hal_displayio_bitmap_get_width (self ));
93
101
}
94
102
@@ -102,6 +110,7 @@ MP_PROPERTY_GETTER(displayio_bitmap_width_obj,
102
110
STATIC mp_obj_t displayio_bitmap_obj_get_height (mp_obj_t self_in ) {
103
111
displayio_bitmap_t * self = MP_OBJ_TO_PTR (self_in );
104
112
113
+ check_for_deinit (self );
105
114
return MP_OBJ_NEW_SMALL_INT (common_hal_displayio_bitmap_get_height (self ));
106
115
}
107
116
@@ -134,6 +143,7 @@ STATIC mp_obj_t bitmap_subscr(mp_obj_t self_in, mp_obj_t index_obj, mp_obj_t val
134
143
}
135
144
136
145
displayio_bitmap_t * self = MP_OBJ_TO_PTR (self_in );
146
+ check_for_deinit (self );
137
147
138
148
if (mp_obj_is_type (index_obj , & mp_type_slice )) {
139
149
// TODO(tannewt): Implement subscr after slices support start, stop and step tuples.
@@ -214,6 +224,7 @@ STATIC mp_obj_t displayio_bitmap_obj_blit(size_t n_args, const mp_obj_t *pos_arg
214
224
mp_arg_parse_all (n_args - 1 , pos_args + 1 , kw_args , MP_ARRAY_SIZE (allowed_args ), allowed_args , args );
215
225
216
226
displayio_bitmap_t * self = MP_OBJ_TO_PTR (pos_args [0 ]);
227
+ check_for_deinit (self );
217
228
218
229
int16_t x = args [ARG_x ].u_int ;
219
230
int16_t y = args [ARG_y ].u_int ;
@@ -288,6 +299,7 @@ MP_DEFINE_CONST_FUN_OBJ_KW(displayio_bitmap_blit_obj, 1, displayio_bitmap_obj_bl
288
299
//| ...
289
300
STATIC mp_obj_t displayio_bitmap_obj_fill (mp_obj_t self_in , mp_obj_t value_obj ) {
290
301
displayio_bitmap_t * self = MP_OBJ_TO_PTR (self_in );
302
+ check_for_deinit (self );
291
303
292
304
mp_uint_t value = (mp_uint_t )mp_obj_get_int (value_obj );
293
305
if ((value >> common_hal_displayio_bitmap_get_bits_per_value (self )) != 0 ) {
@@ -318,9 +330,10 @@ MP_DEFINE_CONST_FUN_OBJ_2(displayio_bitmap_fill_obj, displayio_bitmap_obj_fill);
318
330
//| notified of the "dirty rectangle" that encloses all modified
319
331
//| pixels."""
320
332
//| ...
321
- //|
322
333
STATIC mp_obj_t displayio_bitmap_obj_dirty (size_t n_args , const mp_obj_t * pos_args , mp_map_t * kw_args ) {
323
334
displayio_bitmap_t * self = MP_OBJ_TO_PTR (pos_args [0 ]);
335
+ check_for_deinit (self );
336
+
324
337
enum { ARG_x1 , ARG_y1 , ARG_x2 , ARG_y2 };
325
338
static const mp_arg_t allowed_args [] = {
326
339
{ MP_QSTR_x1 , MP_ARG_INT , {.u_int = 0 } },
@@ -344,13 +357,24 @@ STATIC mp_obj_t displayio_bitmap_obj_dirty(size_t n_args, const mp_obj_t *pos_ar
344
357
}
345
358
MP_DEFINE_CONST_FUN_OBJ_KW (displayio_bitmap_dirty_obj , 0 , displayio_bitmap_obj_dirty );
346
359
360
+ //| def deinit(self) -> None:
361
+ //| """Release resources allocated by Bitmap."""
362
+ //| ...
363
+ //|
364
+ STATIC mp_obj_t displayio_bitmap_obj_deinit (mp_obj_t self_in ) {
365
+ displayio_bitmap_t * self = MP_OBJ_TO_PTR (self_in );
366
+ common_hal_displayio_bitmap_deinit (self );
367
+ return mp_const_none ;
368
+ }
369
+ MP_DEFINE_CONST_FUN_OBJ_1 (displayio_bitmap_deinit_obj , displayio_bitmap_obj_deinit );
370
+
347
371
STATIC const mp_rom_map_elem_t displayio_bitmap_locals_dict_table [] = {
348
372
{ MP_ROM_QSTR (MP_QSTR_height ), MP_ROM_PTR (& displayio_bitmap_height_obj ) },
349
373
{ MP_ROM_QSTR (MP_QSTR_width ), MP_ROM_PTR (& displayio_bitmap_width_obj ) },
350
374
{ MP_ROM_QSTR (MP_QSTR_blit ), MP_ROM_PTR (& displayio_bitmap_blit_obj ) },
351
375
{ MP_ROM_QSTR (MP_QSTR_fill ), MP_ROM_PTR (& displayio_bitmap_fill_obj ) },
352
376
{ MP_ROM_QSTR (MP_QSTR_dirty ), MP_ROM_PTR (& displayio_bitmap_dirty_obj ) },
353
-
377
+ { MP_ROM_QSTR ( MP_QSTR_deinit ), MP_ROM_PTR ( & displayio_bitmap_deinit_obj ) },
354
378
};
355
379
STATIC MP_DEFINE_CONST_DICT (displayio_bitmap_locals_dict , displayio_bitmap_locals_dict_table );
356
380
0 commit comments