|
3 | 3 | * |
4 | 4 | * The MIT License (MIT) |
5 | 5 | * |
6 | | - * Copyright (c) 2018 Scott Shawcroft for Adafruit Industries |
| 6 | + * Copyright (c) 2023 Mark Komus |
7 | 7 | * |
8 | 8 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
9 | 9 | * of this software and associated documentation files (the "Software"), to deal |
|
34 | 34 | #include "shared-bindings/gifio/OnDiskGif.h" |
35 | 35 |
|
36 | 36 | //| class OnDiskGif: |
37 | | -//| """Loads values straight from disk. This minimizes memory use but can lead to |
38 | | -//| much slower pixel load times |
| 37 | +//| """Loads frames of the GIF straight from disk. This minimizes memory use but can |
| 38 | +//| lead to much slower pixel load times |
39 | 39 | //| |
40 | 40 | //| .. code-block:: Python |
41 | 41 | //| |
42 | 42 | //| import board |
43 | 43 | //| import gifio |
| 44 | +//| import displayio |
44 | 45 | //| import time |
45 | | -//| import pulseio |
46 | 46 | //| |
47 | | -//| splash = gifio.Group() |
| 47 | +//| splash = displayio.Group() |
48 | 48 | //| board.DISPLAY.show(splash) |
49 | 49 | //| |
50 | | -//| odg = gifio.OnDiskBitmap('/sample.gif') |
51 | | -//| odg.play_frame() # Load the first frame |
52 | | -//| face = gifio.TileGrid(odg, pixel_shader=gifio.ColorConverter(input_colorspace=gifio.Colorspace.RGB565)) |
| 50 | +//| odg = gifio.OnDiskGif('/sample.gif') |
| 51 | +//| odg.next_frame() # Load the first frame |
| 52 | +//| face = displayio.TileGrid(odg, pixel_shader=displayio.ColorConverter(input_colorspace=displayio.Colorspace.RGB565)) |
53 | 53 | //| splash.append(face) |
54 | 54 | //| board.DISPLAY.refresh() |
55 | 55 | //| |
56 | 56 | //| # Wait forever |
57 | 57 | //| while True: |
58 | | -//| gif.play_frame() |
| 58 | +//| gif.next_frame() |
59 | 59 | //| time.sleep(0.1)""" |
60 | 60 | //| |
61 | 61 | //| def __init__(self, file: str) -> None: |
@@ -122,20 +122,22 @@ MP_DEFINE_CONST_FUN_OBJ_1(gifio_ondiskgif_get_bitmap_obj, gifio_ondiskgif_obj_ge |
122 | 122 | MP_PROPERTY_GETTER(gifio_ondiskgif_bitmap_obj, |
123 | 123 | (mp_obj_t)&gifio_ondiskgif_get_bitmap_obj); |
124 | 124 |
|
125 | | -//| play_frame: int |
126 | | -//| """Play next frame. Returns expected delay until the next frame.""" |
127 | | -STATIC mp_obj_t gifio_ondiskgif_obj_play_frame(size_t n_args, const mp_obj_t *args) { |
| 125 | +//| def next_frame(self, set_dirty: bool = True) -> int: |
| 126 | +//| """Loads the next frame. Returns expected delay before the next frame in milliseconds. |
| 127 | +//| |
| 128 | +//| :param set_dirty: Mark the bitmap as dirty""" |
| 129 | +STATIC mp_obj_t gifio_ondiskgif_obj_next_frame(size_t n_args, const mp_obj_t *args) { |
128 | 130 | gifio_ondiskgif_t *self = MP_OBJ_TO_PTR(args[0]); |
129 | 131 | bool setDirty = mp_const_true; |
130 | 132 |
|
131 | 133 | if (n_args == 1) { |
132 | 134 | setDirty = mp_obj_is_true(args[1]); |
133 | 135 | } |
134 | 136 |
|
135 | | - return MP_OBJ_NEW_SMALL_INT(common_hal_gifio_ondiskgif_play_frame(self, setDirty)); |
| 137 | + return MP_OBJ_NEW_SMALL_INT(common_hal_gifio_ondiskgif_next_frame(self, setDirty)); |
136 | 138 | } |
137 | 139 |
|
138 | | -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(gifio_ondiskgif_play_frame_obj, 1, 2, gifio_ondiskgif_obj_play_frame); |
| 140 | +STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(gifio_ondiskgif_next_frame_obj, 1, 2, gifio_ondiskgif_obj_next_frame); |
139 | 141 |
|
140 | 142 | //| duration: int |
141 | 143 | //| """Returns the total duration of the GIF in milliseconds. (read only)""" |
@@ -194,7 +196,7 @@ STATIC const mp_rom_map_elem_t gifio_ondiskgif_locals_dict_table[] = { |
194 | 196 | { MP_ROM_QSTR(MP_QSTR_height), MP_ROM_PTR(&gifio_ondiskgif_height_obj) }, |
195 | 197 | { MP_ROM_QSTR(MP_QSTR_bitmap), MP_ROM_PTR(&gifio_ondiskgif_bitmap_obj) }, |
196 | 198 | { MP_ROM_QSTR(MP_QSTR_width), MP_ROM_PTR(&gifio_ondiskgif_width_obj) }, |
197 | | - { MP_ROM_QSTR(MP_QSTR_play_frame), MP_ROM_PTR(&gifio_ondiskgif_play_frame_obj) }, |
| 199 | + { MP_ROM_QSTR(MP_QSTR_next_frame), MP_ROM_PTR(&gifio_ondiskgif_next_frame_obj) }, |
198 | 200 | { MP_ROM_QSTR(MP_QSTR_duration), MP_ROM_PTR(&gifio_ondiskgif_duration_obj) }, |
199 | 201 | { MP_ROM_QSTR(MP_QSTR_frame_count), MP_ROM_PTR(&gifio_ondiskgif_frame_count_obj) }, |
200 | 202 | { MP_ROM_QSTR(MP_QSTR_min_delay), MP_ROM_PTR(&gifio_ondiskgif_min_delay_obj) }, |
|
0 commit comments