diff options
Diffstat (limited to 'shared-bindings/displayio/OnDiskBitmap.c')
| -rw-r--r-- | shared-bindings/displayio/OnDiskBitmap.c | 115 |
1 files changed, 76 insertions, 39 deletions
diff --git a/shared-bindings/displayio/OnDiskBitmap.c b/shared-bindings/displayio/OnDiskBitmap.c index d3d413da1..170873653 100644 --- a/shared-bindings/displayio/OnDiskBitmap.c +++ b/shared-bindings/displayio/OnDiskBitmap.c @@ -29,57 +29,54 @@ #include <stdint.h> #include "py/runtime.h" +#include "py/objproperty.h" #include "supervisor/shared/translate.h" +#include "shared-bindings/displayio/OnDiskBitmap.h" -//| .. currentmodule:: displayio -//| -//| :class:`OnDiskBitmap` -- Loads pixels straight from disk -//| ========================================================================== -//| -//| Loads values straight from disk. This minimizes memory use but can lead to -//| much slower pixel load times. These load times may result in frame tearing where only part of -//| the image is visible. +//| class OnDiskBitmap: +//| """Loads values straight from disk. This minimizes memory use but can lead to +//| much slower pixel load times. These load times may result in frame tearing where only part of +//| the image is visible. //| -//| .. warning:: This will likely be changed before 4.0.0. Consider it very experimental. +//| It's easiest to use on a board with a built in display such as the `Hallowing M0 Express +//| <https://www.adafruit.com/product/3900>`_. //| -//| It's easiest to use on a board with a built in display such as the `Hallowing M0 Express -//| <https://www.adafruit.com/product/3900>`_. +//| .. code-block:: Python //| -//| .. code-block:: Python +//| import board +//| import displayio +//| import time +//| import pulseio //| -//| import board -//| import displayio -//| import time -//| import pulseio +//| board.DISPLAY.auto_brightness = False +//| board.DISPLAY.brightness = 0 +//| splash = displayio.Group() +//| board.DISPLAY.show(splash) //| -//| backlight = pulseio.PWMOut(board.TFT_BACKLIGHT) -//| splash = displayio.Group() -//| board.DISPLAY.show(splash) +//| with open("/sample.bmp", "rb") as f: +//| odb = displayio.OnDiskBitmap(f) +//| face = displayio.TileGrid(odb, pixel_shader=displayio.ColorConverter()) +//| splash.append(face) +//| # Wait for the image to load. +//| board.DISPLAY.refresh(target_frames_per_second=60) //| -//| with open("/sample.bmp", "rb") as f: -//| odb = displayio.OnDiskBitmap(f) -//| face = displayio.Sprite(odb, pixel_shader=displayio.ColorConverter(), position=(0,0)) -//| splash.append(face) -//| # Wait for the image to load. -//| board.DISPLAY.wait_for_frame() +//| # Fade up the backlight +//| for i in range(100): +//| board.DISPLAY.brightness = 0.01 * i +//| time.sleep(0.05) //| -//| # Fade up the backlight -//| for i in range(100): -//| backlight.duty_cycle = i * (2 ** 15) // 100 -//| time.sleep(0.01) +//| # Wait forever +//| while True: +//| pass""" //| -//| # Wait forever -//| while True: -//| pass +//| def __init__(self, file: file): +//| """Create an OnDiskBitmap object with the given file. //| -//| .. class:: OnDiskBitmap(file) +//| :param file file: The open bitmap file""" +//| ... //| -//| Create an OnDiskBitmap object with the given file. -//| -//| :param file file: The open bitmap file -//| -STATIC mp_obj_t displayio_ondiskbitmap_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *pos_args) { - mp_arg_check_num(n_args, n_kw, 1, 1, false); +STATIC mp_obj_t displayio_ondiskbitmap_make_new(const mp_obj_type_t *type, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { + mp_arg_check_num(n_args, kw_args, 1, 1, false); if (!MP_OBJ_IS_TYPE(pos_args[0], &mp_type_fileio)) { mp_raise_TypeError(translate("file must be a file opened in byte mode")); @@ -92,7 +89,47 @@ STATIC mp_obj_t displayio_ondiskbitmap_make_new(const mp_obj_type_t *type, size_ return MP_OBJ_FROM_PTR(self); } +//| width: Any = ... +//| """Width of the bitmap. (read only)""" +//| +STATIC mp_obj_t displayio_ondiskbitmap_obj_get_width(mp_obj_t self_in) { + displayio_ondiskbitmap_t *self = MP_OBJ_TO_PTR(self_in); + + return MP_OBJ_NEW_SMALL_INT(common_hal_displayio_ondiskbitmap_get_width(self)); +} + +MP_DEFINE_CONST_FUN_OBJ_1(displayio_ondiskbitmap_get_width_obj, displayio_ondiskbitmap_obj_get_width); + +const mp_obj_property_t displayio_ondiskbitmap_width_obj = { + .base.type = &mp_type_property, + .proxy = {(mp_obj_t)&displayio_ondiskbitmap_get_width_obj, + (mp_obj_t)&mp_const_none_obj, + (mp_obj_t)&mp_const_none_obj}, + +}; + +//| height: Any = ... +//| """Height of the bitmap. (read only)""" +//| +STATIC mp_obj_t displayio_ondiskbitmap_obj_get_height(mp_obj_t self_in) { + displayio_ondiskbitmap_t *self = MP_OBJ_TO_PTR(self_in); + + return MP_OBJ_NEW_SMALL_INT(common_hal_displayio_ondiskbitmap_get_height(self)); +} + +MP_DEFINE_CONST_FUN_OBJ_1(displayio_ondiskbitmap_get_height_obj, displayio_ondiskbitmap_obj_get_height); + +const mp_obj_property_t displayio_ondiskbitmap_height_obj = { + .base.type = &mp_type_property, + .proxy = {(mp_obj_t)&displayio_ondiskbitmap_get_height_obj, + (mp_obj_t)&mp_const_none_obj, + (mp_obj_t)&mp_const_none_obj}, + +}; + STATIC const mp_rom_map_elem_t displayio_ondiskbitmap_locals_dict_table[] = { + { MP_ROM_QSTR(MP_QSTR_height), MP_ROM_PTR(&displayio_ondiskbitmap_height_obj) }, + { MP_ROM_QSTR(MP_QSTR_width), MP_ROM_PTR(&displayio_ondiskbitmap_width_obj) }, }; STATIC MP_DEFINE_CONST_DICT(displayio_ondiskbitmap_locals_dict, displayio_ondiskbitmap_locals_dict_table); |
