Skip to content

Commit 2bcf81f

Browse files
authored
Merge pull request #1479 from siddacious/master
adding height and width to OnDiskBitmap for #1460
2 parents b369fa9 + ab2ad7b commit 2bcf81f

File tree

3 files changed

+55
-0
lines changed

3 files changed

+55
-0
lines changed

shared-bindings/displayio/OnDiskBitmap.c

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,9 @@
2929
#include <stdint.h>
3030

3131
#include "py/runtime.h"
32+
#include "py/objproperty.h"
3233
#include "supervisor/shared/translate.h"
34+
#include "shared-bindings/displayio/OnDiskBitmap.h"
3335

3436
//| .. currentmodule:: displayio
3537
//|
@@ -92,7 +94,49 @@ STATIC mp_obj_t displayio_ondiskbitmap_make_new(const mp_obj_type_t *type, size_
9294
return MP_OBJ_FROM_PTR(self);
9395
}
9496

97+
//| .. attribute:: width
98+
//|
99+
//| Width of the bitmap. (read only)
100+
//|
101+
STATIC mp_obj_t displayio_ondiskbitmap_obj_get_width(mp_obj_t self_in) {
102+
displayio_ondiskbitmap_t *self = MP_OBJ_TO_PTR(self_in);
103+
104+
return MP_OBJ_NEW_SMALL_INT(common_hal_displayio_ondiskbitmap_get_width(self));
105+
}
106+
107+
MP_DEFINE_CONST_FUN_OBJ_1(displayio_ondiskbitmap_get_width_obj, displayio_ondiskbitmap_obj_get_width);
108+
109+
const mp_obj_property_t displayio_ondiskbitmap_width_obj = {
110+
.base.type = &mp_type_property,
111+
.proxy = {(mp_obj_t)&displayio_ondiskbitmap_get_width_obj,
112+
(mp_obj_t)&mp_const_none_obj,
113+
(mp_obj_t)&mp_const_none_obj},
114+
115+
};
116+
117+
//| .. attribute:: height
118+
//|
119+
//| Height of the bitmap. (read only)
120+
//|
121+
STATIC mp_obj_t displayio_ondiskbitmap_obj_get_height(mp_obj_t self_in) {
122+
displayio_ondiskbitmap_t *self = MP_OBJ_TO_PTR(self_in);
123+
124+
return MP_OBJ_NEW_SMALL_INT(common_hal_displayio_ondiskbitmap_get_height(self));
125+
}
126+
127+
MP_DEFINE_CONST_FUN_OBJ_1(displayio_ondiskbitmap_get_height_obj, displayio_ondiskbitmap_obj_get_height);
128+
129+
const mp_obj_property_t displayio_ondiskbitmap_height_obj = {
130+
.base.type = &mp_type_property,
131+
.proxy = {(mp_obj_t)&displayio_ondiskbitmap_get_height_obj,
132+
(mp_obj_t)&mp_const_none_obj,
133+
(mp_obj_t)&mp_const_none_obj},
134+
135+
};
136+
95137
STATIC const mp_rom_map_elem_t displayio_ondiskbitmap_locals_dict_table[] = {
138+
{ MP_ROM_QSTR(MP_QSTR_height), MP_ROM_PTR(&displayio_ondiskbitmap_height_obj) },
139+
{ MP_ROM_QSTR(MP_QSTR_width), MP_ROM_PTR(&displayio_ondiskbitmap_width_obj) },
96140
};
97141
STATIC MP_DEFINE_CONST_DICT(displayio_ondiskbitmap_locals_dict, displayio_ondiskbitmap_locals_dict_table);
98142

shared-bindings/displayio/OnDiskBitmap.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,7 @@ void common_hal_displayio_ondiskbitmap_construct(displayio_ondiskbitmap_t *self,
3737
uint32_t common_hal_displayio_ondiskbitmap_get_pixel(displayio_ondiskbitmap_t *bitmap,
3838
int16_t x, int16_t y);
3939

40+
uint16_t common_hal_displayio_ondiskbitmap_get_height(displayio_ondiskbitmap_t *self);
41+
42+
uint16_t common_hal_displayio_ondiskbitmap_get_width(displayio_ondiskbitmap_t *self);
4043
#endif // MICROPY_INCLUDED_SHARED_BINDINGS_DISPLAYIO_ONDISKBITMAP_H

shared-module/displayio/OnDiskBitmap.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,3 +91,11 @@ uint32_t common_hal_displayio_ondiskbitmap_get_pixel(displayio_ondiskbitmap_t *s
9191
}
9292
return 0;
9393
}
94+
95+
uint16_t common_hal_displayio_ondiskbitmap_get_height(displayio_ondiskbitmap_t *self) {
96+
return self->height;
97+
}
98+
99+
uint16_t common_hal_displayio_ondiskbitmap_get_width(displayio_ondiskbitmap_t *self) {
100+
return self->width;
101+
}

0 commit comments

Comments
 (0)