2018-09-11 01:00:21 -04:00
|
|
|
/*
|
|
|
|
* This file is part of the Micro Python project, http://micropython.org/
|
|
|
|
*
|
|
|
|
* The MIT License (MIT)
|
|
|
|
*
|
|
|
|
* Copyright (c) 2018 Scott Shawcroft for Adafruit Industries
|
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
* of this software and associated documentation files (the "Software"), to deal
|
|
|
|
* in the Software without restriction, including without limitation the rights
|
|
|
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
* copies of the Software, and to permit persons to whom the Software is
|
|
|
|
* furnished to do so, subject to the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice shall be included in
|
|
|
|
* all copies or substantial portions of the Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
* THE SOFTWARE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "shared-bindings/displayio/OnDiskBitmap.h"
|
|
|
|
|
|
|
|
#include <stdint.h>
|
|
|
|
|
|
|
|
#include "py/runtime.h"
|
2019-01-21 01:33:22 -05:00
|
|
|
#include "py/objproperty.h"
|
2018-09-11 01:00:21 -04:00
|
|
|
#include "supervisor/shared/translate.h"
|
2019-01-21 01:33:22 -05:00
|
|
|
#include "shared-bindings/displayio/OnDiskBitmap.h"
|
2018-09-11 01:00:21 -04:00
|
|
|
|
2020-05-07 10:54:09 -04:00
|
|
|
//| class OnDiskBitmap:
|
2020-05-12 20:15:28 -04:00
|
|
|
//| """Loads values straight from disk. This minimizes memory use but can lead to
|
2020-05-07 10:54:09 -04:00
|
|
|
//| much slower pixel load times. These load times may result in frame tearing where only part of
|
|
|
|
//| the image is visible.
|
2018-09-11 01:00:21 -04:00
|
|
|
//|
|
2020-05-07 10:54:09 -04:00
|
|
|
//| 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>`_.
|
2018-09-11 01:00:21 -04:00
|
|
|
//|
|
2020-05-07 10:54:09 -04:00
|
|
|
//| .. code-block:: Python
|
2018-09-11 01:00:21 -04:00
|
|
|
//|
|
2020-05-07 10:54:09 -04:00
|
|
|
//| import board
|
|
|
|
//| import displayio
|
|
|
|
//| import time
|
|
|
|
//| import pulseio
|
2018-09-11 01:00:21 -04:00
|
|
|
//|
|
2020-05-07 10:54:09 -04:00
|
|
|
//| board.DISPLAY.auto_brightness = False
|
|
|
|
//| board.DISPLAY.brightness = 0
|
|
|
|
//| splash = displayio.Group()
|
|
|
|
//| board.DISPLAY.show(splash)
|
2018-09-11 01:00:21 -04:00
|
|
|
//|
|
2020-05-07 10:54:09 -04:00
|
|
|
//| 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)
|
2018-09-11 01:00:21 -04:00
|
|
|
//|
|
2020-05-07 10:54:09 -04:00
|
|
|
//| # Fade up the backlight
|
|
|
|
//| for i in range(100):
|
|
|
|
//| board.DISPLAY.brightness = 0.01 * i
|
|
|
|
//| time.sleep(0.05)
|
2018-09-11 01:00:21 -04:00
|
|
|
//|
|
2020-05-07 10:54:09 -04:00
|
|
|
//| # Wait forever
|
|
|
|
//| while True:
|
|
|
|
//| pass"""
|
2018-09-11 01:00:21 -04:00
|
|
|
//|
|
2020-07-23 14:22:41 -04:00
|
|
|
//| def __init__(self, file: typing.BinaryIO) -> None:
|
2020-05-07 10:54:09 -04:00
|
|
|
//| """Create an OnDiskBitmap object with the given file.
|
2018-09-11 01:00:21 -04:00
|
|
|
//|
|
2020-05-07 10:54:09 -04:00
|
|
|
//| :param file file: The open bitmap file"""
|
|
|
|
//| ...
|
2018-09-11 01:00:21 -04:00
|
|
|
//|
|
2019-01-14 20:26:36 -05:00
|
|
|
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);
|
2018-09-11 01:00:21 -04:00
|
|
|
|
2021-04-22 20:55:39 -04:00
|
|
|
if (!mp_obj_is_type(pos_args[0], &mp_type_fileio)) {
|
2018-09-11 01:00:21 -04:00
|
|
|
mp_raise_TypeError(translate("file must be a file opened in byte mode"));
|
|
|
|
}
|
|
|
|
|
|
|
|
displayio_ondiskbitmap_t *self = m_new_obj(displayio_ondiskbitmap_t);
|
|
|
|
self->base.type = &displayio_ondiskbitmap_type;
|
|
|
|
common_hal_displayio_ondiskbitmap_construct(self, MP_OBJ_TO_PTR(pos_args[0]));
|
|
|
|
|
|
|
|
return MP_OBJ_FROM_PTR(self);
|
|
|
|
}
|
|
|
|
|
2020-07-25 04:58:37 -04:00
|
|
|
//| width: int
|
2020-05-07 10:54:09 -04:00
|
|
|
//| """Width of the bitmap. (read only)"""
|
2019-01-21 01:33:22 -05:00
|
|
|
//|
|
|
|
|
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},
|
|
|
|
|
|
|
|
};
|
|
|
|
|
2020-07-25 04:58:37 -04:00
|
|
|
//| height: int
|
2020-05-07 10:54:09 -04:00
|
|
|
//| """Height of the bitmap. (read only)"""
|
2019-01-21 01:33:22 -05:00
|
|
|
//|
|
|
|
|
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},
|
|
|
|
|
|
|
|
};
|
|
|
|
|
2018-09-11 01:00:21 -04:00
|
|
|
STATIC const mp_rom_map_elem_t displayio_ondiskbitmap_locals_dict_table[] = {
|
2019-01-21 01:33:22 -05:00
|
|
|
{ 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) },
|
2018-09-11 01:00:21 -04:00
|
|
|
};
|
|
|
|
STATIC MP_DEFINE_CONST_DICT(displayio_ondiskbitmap_locals_dict, displayio_ondiskbitmap_locals_dict_table);
|
|
|
|
|
|
|
|
const mp_obj_type_t displayio_ondiskbitmap_type = {
|
|
|
|
{ &mp_type_type },
|
|
|
|
.name = MP_QSTR_OnDiskBitmap,
|
|
|
|
.make_new = displayio_ondiskbitmap_make_new,
|
2021-03-15 09:57:36 -04:00
|
|
|
.locals_dict = (mp_obj_dict_t *)&displayio_ondiskbitmap_locals_dict,
|
2018-09-11 01:00:21 -04:00
|
|
|
};
|