|
37 | 37 | #include "supervisor/shared/translate.h"
|
38 | 38 |
|
39 | 39 | //| class Bitmap:
|
40 |
| -//| """Stores values of a certain size in a 2D array""" |
| 40 | +//| """Stores values of a certain size in a 2D array |
| 41 | +//| |
| 42 | +//| Bitmaps can be treated as read-only buffers. If the number of bits in a pixel is 8, 16, or 32; and the number of bytes |
| 43 | +//| per row is a multiple of 4, then the resulting memoryview will correspond directly with the bitmap's contents. Otherwise, |
| 44 | +//| the bitmap data is packed into the memoryview with unspecified padding. |
| 45 | +//| |
| 46 | +//| A read-only buffer can be used e.g., with `ulab.frombuffer` to efficiently create an array with the same content as a Bitmap; |
| 47 | +//| to move data efficiently from ulab back into a Bitmap, use `bitmaptools.arrayblit`. |
| 48 | +//| """ |
41 | 49 | //|
|
42 | 50 | //| def __init__(self, width: int, height: int, value_count: int) -> None:
|
43 | 51 | //| """Create a Bitmap object with the given fixed size. Each pixel stores a value that is used to
|
@@ -300,10 +308,17 @@ STATIC const mp_rom_map_elem_t displayio_bitmap_locals_dict_table[] = {
|
300 | 308 | };
|
301 | 309 | STATIC MP_DEFINE_CONST_DICT(displayio_bitmap_locals_dict, displayio_bitmap_locals_dict_table);
|
302 | 310 |
|
| 311 | +// (the get_buffer protocol returns 0 for success, 1 for failure) |
| 312 | +STATIC mp_int_t bitmap_get_buffer(mp_obj_t self_in, mp_buffer_info_t *bufinfo, mp_uint_t flags) { |
| 313 | + displayio_bitmap_t *self = MP_OBJ_TO_PTR(self_in); |
| 314 | + return common_hal_displayio_bitmap_get_buffer(self, bufinfo, flags); |
| 315 | +} |
| 316 | + |
303 | 317 | const mp_obj_type_t displayio_bitmap_type = {
|
304 | 318 | { &mp_type_type },
|
305 | 319 | .name = MP_QSTR_Bitmap,
|
306 | 320 | .make_new = displayio_bitmap_make_new,
|
307 | 321 | .subscr = bitmap_subscr,
|
308 | 322 | .locals_dict = (mp_obj_dict_t *)&displayio_bitmap_locals_dict,
|
| 323 | + .buffer_p = { .get_buffer = bitmap_get_buffer }, |
309 | 324 | };
|
0 commit comments