@@ -84,11 +84,19 @@ STATIC mp_obj_t displayio_bitmap_make_new(const mp_obj_type_t *type, size_t n_ar
8484
8585 return MP_OBJ_FROM_PTR (self );
8686}
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+
8794//| width: int
8895//| """Width of the bitmap. (read only)"""
8996STATIC mp_obj_t displayio_bitmap_obj_get_width (mp_obj_t self_in ) {
9097 displayio_bitmap_t * self = MP_OBJ_TO_PTR (self_in );
9198
99+ check_for_deinit (self );
92100 return MP_OBJ_NEW_SMALL_INT (common_hal_displayio_bitmap_get_width (self ));
93101}
94102
@@ -102,6 +110,7 @@ MP_PROPERTY_GETTER(displayio_bitmap_width_obj,
102110STATIC mp_obj_t displayio_bitmap_obj_get_height (mp_obj_t self_in ) {
103111 displayio_bitmap_t * self = MP_OBJ_TO_PTR (self_in );
104112
113+ check_for_deinit (self );
105114 return MP_OBJ_NEW_SMALL_INT (common_hal_displayio_bitmap_get_height (self ));
106115}
107116
@@ -134,6 +143,7 @@ STATIC mp_obj_t bitmap_subscr(mp_obj_t self_in, mp_obj_t index_obj, mp_obj_t val
134143 }
135144
136145 displayio_bitmap_t * self = MP_OBJ_TO_PTR (self_in );
146+ check_for_deinit (self );
137147
138148 if (mp_obj_is_type (index_obj , & mp_type_slice )) {
139149 // 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
214224 mp_arg_parse_all (n_args - 1 , pos_args + 1 , kw_args , MP_ARRAY_SIZE (allowed_args ), allowed_args , args );
215225
216226 displayio_bitmap_t * self = MP_OBJ_TO_PTR (pos_args [0 ]);
227+ check_for_deinit (self );
217228
218229 int16_t x = args [ARG_x ].u_int ;
219230 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
288299//| ...
289300STATIC mp_obj_t displayio_bitmap_obj_fill (mp_obj_t self_in , mp_obj_t value_obj ) {
290301 displayio_bitmap_t * self = MP_OBJ_TO_PTR (self_in );
302+ check_for_deinit (self );
291303
292304 mp_uint_t value = (mp_uint_t )mp_obj_get_int (value_obj );
293305 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);
318330//| notified of the "dirty rectangle" that encloses all modified
319331//| pixels."""
320332//| ...
321- //|
322333STATIC mp_obj_t displayio_bitmap_obj_dirty (size_t n_args , const mp_obj_t * pos_args , mp_map_t * kw_args ) {
323334 displayio_bitmap_t * self = MP_OBJ_TO_PTR (pos_args [0 ]);
335+ check_for_deinit (self );
336+
324337 enum { ARG_x1 , ARG_y1 , ARG_x2 , ARG_y2 };
325338 static const mp_arg_t allowed_args [] = {
326339 { 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
344357}
345358MP_DEFINE_CONST_FUN_OBJ_KW (displayio_bitmap_dirty_obj , 0 , displayio_bitmap_obj_dirty );
346359
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+
347371STATIC const mp_rom_map_elem_t displayio_bitmap_locals_dict_table [] = {
348372 { MP_ROM_QSTR (MP_QSTR_height ), MP_ROM_PTR (& displayio_bitmap_height_obj ) },
349373 { MP_ROM_QSTR (MP_QSTR_width ), MP_ROM_PTR (& displayio_bitmap_width_obj ) },
350374 { MP_ROM_QSTR (MP_QSTR_blit ), MP_ROM_PTR (& displayio_bitmap_blit_obj ) },
351375 { MP_ROM_QSTR (MP_QSTR_fill ), MP_ROM_PTR (& displayio_bitmap_fill_obj ) },
352376 { 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 ) },
354378};
355379STATIC MP_DEFINE_CONST_DICT (displayio_bitmap_locals_dict , displayio_bitmap_locals_dict_table );
356380
0 commit comments