33
33
#include "supervisor/shared/translate/translate.h"
34
34
#include "shared-bindings/displayio/OnDiskGif.h"
35
35
36
- //| class OnDiskBitmap :
36
+ //| class OnDiskGif :
37
37
//| """Loads values straight from disk. This minimizes memory use but can lead to
38
- //| much slower pixel load times. These load times may result in frame tearing where only part of
39
- //| the image is visible.
40
- //|
41
- //| It's easiest to use on a board with a built in display such as the `Hallowing M0 Express
42
- //| <https://www.adafruit.com/product/3900>`_.
38
+ //| much slower pixel load times
43
39
//|
44
40
//| .. code-block:: Python
45
41
//|
48
44
//| import time
49
45
//| import pulseio
50
46
//|
51
- //| board.DISPLAY.brightness = 0
52
47
//| splash = displayio.Group()
53
48
//| board.DISPLAY.show(splash)
54
49
//|
55
- //| odb = displayio.OnDiskBitmap('/sample.bmp')
56
- //| face = displayio.TileGrid(odb, pixel_shader=odb.pixel_shader)
50
+ //| odg = displayio.OnDiskBitmap('/sample.gif')
51
+ //| odg.play_frame() # Load the first frame
52
+ //| face = displayio.TileGrid(odg, pixel_shader=displayio.ColorConverter(input_colorspace=displayio.Colorspace.RGB565))
57
53
//| splash.append(face)
58
- //| # Wait for the image to load.
59
- //| board.DISPLAY.refresh(target_frames_per_second=60)
60
- //|
61
- //| # Fade up the backlight
62
- //| for i in range(100):
63
- //| board.DISPLAY.brightness = 0.01 * i
64
- //| time.sleep(0.05)
54
+ //| board.DISPLAY.refresh()
65
55
//|
66
56
//| # Wait forever
67
57
//| while True:
68
- //| pass"""
58
+ //| gif.play_frame()
59
+ //| time.sleep(0.1)"""
69
60
//|
70
- //| def __init__(self, file: Union[ str, typing.BinaryIO] ) -> None:
71
- //| """Create an OnDiskBitmap object with the given file.
61
+ //| def __init__(self, file: str) -> None:
62
+ //| """Create an OnDiskGif object with the given file.
72
63
//|
73
- //| :param file file: The name of the bitmap file. For backwards compatibility, a file opened in binary mode may also be passed .
64
+ //| :param file file: The name of the GIF file.
74
65
//|
75
- //| Older versions of CircuitPython required a file opened in binary
76
- //| mode. CircuitPython 7.0 modified OnDiskBitmap so that it takes a
77
- //| filename instead, and opens the file internally. A future version
78
- //| of CircuitPython will remove the ability to pass in an opened file.
79
66
//| """
80
67
//| ...
81
68
STATIC mp_obj_t displayio_ondiskgif_make_new (const mp_obj_type_t * type , size_t n_args , size_t n_kw , const mp_obj_t * all_args ) {
@@ -98,7 +85,7 @@ STATIC mp_obj_t displayio_ondiskgif_make_new(const mp_obj_type_t *type, size_t n
98
85
}
99
86
100
87
//| width: int
101
- //| """Width of the bitmap . (read only)"""
88
+ //| """Width of the gif . (read only)"""
102
89
STATIC mp_obj_t displayio_ondiskgif_obj_get_width (mp_obj_t self_in ) {
103
90
displayio_ondiskgif_t * self = MP_OBJ_TO_PTR (self_in );
104
91
@@ -111,7 +98,7 @@ MP_PROPERTY_GETTER(displayio_ondiskgif_width_obj,
111
98
(mp_obj_t )& displayio_ondiskgif_get_width_obj );
112
99
113
100
//| height: int
114
- //| """Height of the bitmap . (read only)"""
101
+ //| """Height of the gif . (read only)"""
115
102
STATIC mp_obj_t displayio_ondiskgif_obj_get_height (mp_obj_t self_in ) {
116
103
displayio_ondiskgif_t * self = MP_OBJ_TO_PTR (self_in );
117
104
@@ -124,10 +111,7 @@ MP_PROPERTY_GETTER(displayio_ondiskgif_height_obj,
124
111
(mp_obj_t )& displayio_ondiskgif_get_height_obj );
125
112
126
113
//| bitmap: Bitmap
127
- //| """The image's bitmap. The type depends on the underlying
128
- //| bitmap's structure. The pixel shader can be modified (e.g., to set the
129
- //| transparent pixel or, for palette shaded images, to update the palette.)"""
130
- //|
114
+ //| """The bitmap used to hold the current frame."""
131
115
STATIC mp_obj_t displayio_ondiskgif_obj_get_bitmap (mp_obj_t self_in ) {
132
116
displayio_ondiskgif_t * self = MP_OBJ_TO_PTR (self_in );
133
117
return common_hal_displayio_ondiskgif_get_bitmap (self );
@@ -138,28 +122,23 @@ MP_DEFINE_CONST_FUN_OBJ_1(displayio_ondiskgif_get_bitmap_obj, displayio_ondiskgi
138
122
MP_PROPERTY_GETTER (displayio_ondiskgif_bitmap_obj ,
139
123
(mp_obj_t )& displayio_ondiskgif_get_bitmap_obj );
140
124
141
- /*
142
- const mp_obj_property_t displayio_ondiskgif_bitmap_obj = {
143
- .base.type = &mp_type_property,
144
- .proxy = {(mp_obj_t)&displayio_ondiskgif_get_bitmap_obj,
145
- (mp_obj_t)MP_ROM_NONE,
146
- (mp_obj_t)MP_ROM_NONE},
147
- };*/
148
-
125
+ //| play_frame: int
126
+ //| """Play next frame. Returns expected delay until the next frame."""
127
+ STATIC mp_obj_t displayio_ondiskgif_obj_play_frame (size_t n_args , const mp_obj_t * args ) {
128
+ displayio_ondiskgif_t * self = MP_OBJ_TO_PTR (args [0 ]);
129
+ bool setDirty = mp_const_true ;
149
130
150
- //| play_frame: None
151
- //| """Play next frame. (read only)"""
152
- //|
153
- STATIC mp_obj_t displayio_ondiskgif_obj_play_frame (mp_obj_t self_in ) {
154
- displayio_ondiskgif_t * self = MP_OBJ_TO_PTR (self_in );
131
+ if (n_args == 1 ) {
132
+ setDirty = mp_obj_is_true (args [1 ]);
133
+ }
155
134
156
- return MP_OBJ_NEW_SMALL_INT (common_hal_displayio_ondiskgif_play_frame (self ));
135
+ return MP_OBJ_NEW_SMALL_INT (common_hal_displayio_ondiskgif_play_frame (self , setDirty ));
157
136
}
158
137
159
- MP_DEFINE_CONST_FUN_OBJ_1 (displayio_ondiskgif_play_frame_obj , displayio_ondiskgif_obj_play_frame );
138
+ STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN (displayio_ondiskgif_play_frame_obj , 1 , 2 , displayio_ondiskgif_obj_play_frame );
160
139
161
140
//| duration: int
162
- //| """Height of the bitmap . (read only)"""
141
+ //| """Returns the total duration of the GIF in milliseconds . (read only)"""
163
142
STATIC mp_obj_t displayio_ondiskgif_obj_get_duration (mp_obj_t self_in ) {
164
143
displayio_ondiskgif_t * self = MP_OBJ_TO_PTR (self_in );
165
144
@@ -172,7 +151,7 @@ MP_PROPERTY_GETTER(displayio_ondiskgif_duration_obj,
172
151
(mp_obj_t )& displayio_ondiskgif_get_duration_obj );
173
152
174
153
//| frame_count: int
175
- //| """Height of the bitmap . (read only)"""
154
+ //| """Returns the number of frames in the GIF . (read only)"""
176
155
STATIC mp_obj_t displayio_ondiskgif_obj_get_frame_count (mp_obj_t self_in ) {
177
156
displayio_ondiskgif_t * self = MP_OBJ_TO_PTR (self_in );
178
157
@@ -185,7 +164,7 @@ MP_PROPERTY_GETTER(displayio_ondiskgif_frame_count_obj,
185
164
(mp_obj_t )& displayio_ondiskgif_get_frame_count_obj );
186
165
187
166
//| min_delay: int
188
- //| """Height of the bitmap . (read only)"""
167
+ //| """The minimum delay found between frames . (read only)"""
189
168
STATIC mp_obj_t displayio_ondiskgif_obj_get_min_delay (mp_obj_t self_in ) {
190
169
displayio_ondiskgif_t * self = MP_OBJ_TO_PTR (self_in );
191
170
@@ -198,7 +177,7 @@ MP_PROPERTY_GETTER(displayio_ondiskgif_min_delay_obj,
198
177
(mp_obj_t )& displayio_ondiskgif_get_min_delay_obj );
199
178
200
179
//| max_delay: int
201
- //| """Height of the bitmap . (read only)"""
180
+ //| """The maximum delay found between frames . (read only)"""
202
181
//|
203
182
STATIC mp_obj_t displayio_ondiskgif_obj_get_max_delay (mp_obj_t self_in ) {
204
183
displayio_ondiskgif_t * self = MP_OBJ_TO_PTR (self_in );
0 commit comments