3333#include "supervisor/shared/translate/translate.h"
3434#include "shared-bindings/displayio/OnDiskGif.h"
3535
36- //| class OnDiskBitmap :
36+ //| class OnDiskGif :
3737//| """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
4339//|
4440//| .. code-block:: Python
4541//|
4844//| import time
4945//| import pulseio
5046//|
51- //| board.DISPLAY.brightness = 0
5247//| splash = displayio.Group()
5348//| board.DISPLAY.show(splash)
5449//|
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))
5753//| 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()
6555//|
6656//| # Wait forever
6757//| while True:
68- //| pass"""
58+ //| gif.play_frame()
59+ //| time.sleep(0.1)"""
6960//|
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.
7263//|
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.
7465//|
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.
7966//| """
8067//| ...
8168STATIC 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
9885}
9986
10087//| width: int
101- //| """Width of the bitmap . (read only)"""
88+ //| """Width of the gif . (read only)"""
10289STATIC mp_obj_t displayio_ondiskgif_obj_get_width (mp_obj_t self_in ) {
10390 displayio_ondiskgif_t * self = MP_OBJ_TO_PTR (self_in );
10491
@@ -111,7 +98,7 @@ MP_PROPERTY_GETTER(displayio_ondiskgif_width_obj,
11198 (mp_obj_t )& displayio_ondiskgif_get_width_obj );
11299
113100//| height: int
114- //| """Height of the bitmap . (read only)"""
101+ //| """Height of the gif . (read only)"""
115102STATIC mp_obj_t displayio_ondiskgif_obj_get_height (mp_obj_t self_in ) {
116103 displayio_ondiskgif_t * self = MP_OBJ_TO_PTR (self_in );
117104
@@ -124,10 +111,7 @@ MP_PROPERTY_GETTER(displayio_ondiskgif_height_obj,
124111 (mp_obj_t )& displayio_ondiskgif_get_height_obj );
125112
126113//| 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."""
131115STATIC mp_obj_t displayio_ondiskgif_obj_get_bitmap (mp_obj_t self_in ) {
132116 displayio_ondiskgif_t * self = MP_OBJ_TO_PTR (self_in );
133117 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
138122MP_PROPERTY_GETTER (displayio_ondiskgif_bitmap_obj ,
139123 (mp_obj_t )& displayio_ondiskgif_get_bitmap_obj );
140124
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 ;
149130
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+ }
155134
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 ));
157136}
158137
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 );
160139
161140//| duration: int
162- //| """Height of the bitmap . (read only)"""
141+ //| """Returns the total duration of the GIF in milliseconds . (read only)"""
163142STATIC mp_obj_t displayio_ondiskgif_obj_get_duration (mp_obj_t self_in ) {
164143 displayio_ondiskgif_t * self = MP_OBJ_TO_PTR (self_in );
165144
@@ -172,7 +151,7 @@ MP_PROPERTY_GETTER(displayio_ondiskgif_duration_obj,
172151 (mp_obj_t )& displayio_ondiskgif_get_duration_obj );
173152
174153//| frame_count: int
175- //| """Height of the bitmap . (read only)"""
154+ //| """Returns the number of frames in the GIF . (read only)"""
176155STATIC mp_obj_t displayio_ondiskgif_obj_get_frame_count (mp_obj_t self_in ) {
177156 displayio_ondiskgif_t * self = MP_OBJ_TO_PTR (self_in );
178157
@@ -185,7 +164,7 @@ MP_PROPERTY_GETTER(displayio_ondiskgif_frame_count_obj,
185164 (mp_obj_t )& displayio_ondiskgif_get_frame_count_obj );
186165
187166//| min_delay: int
188- //| """Height of the bitmap . (read only)"""
167+ //| """The minimum delay found between frames . (read only)"""
189168STATIC mp_obj_t displayio_ondiskgif_obj_get_min_delay (mp_obj_t self_in ) {
190169 displayio_ondiskgif_t * self = MP_OBJ_TO_PTR (self_in );
191170
@@ -198,7 +177,7 @@ MP_PROPERTY_GETTER(displayio_ondiskgif_min_delay_obj,
198177 (mp_obj_t )& displayio_ondiskgif_get_min_delay_obj );
199178
200179//| max_delay: int
201- //| """Height of the bitmap . (read only)"""
180+ //| """The maximum delay found between frames . (read only)"""
202181//|
203182STATIC mp_obj_t displayio_ondiskgif_obj_get_max_delay (mp_obj_t self_in ) {
204183 displayio_ondiskgif_t * self = MP_OBJ_TO_PTR (self_in );
0 commit comments