Moving to gifio module

This commit is contained in:
gamblor21 2023-02-12 11:17:34 -06:00
parent 953c989177
commit 0c95e6a08e
9 changed files with 242 additions and 243 deletions

View File

@ -579,7 +579,6 @@ SRC_SHARED_MODULE_ALL = \
displayio/Group.c \
displayio/I2CDisplay.c \
displayio/OnDiskBitmap.c \
displayio/OnDiskGif.c \
displayio/Palette.c \
displayio/Shape.c \
displayio/TileGrid.c \
@ -593,6 +592,7 @@ SRC_SHARED_MODULE_ALL = \
getpass/__init__.c \
gifio/__init__.c \
gifio/GifWriter.c \
gifio/OnDiskGif.c \
imagecapture/ParallelImageCapture.c \
ipaddress/IPv4Address.c \
ipaddress/__init__.c \
@ -698,10 +698,12 @@ SRC_MOD += $(addprefix lib/protomatter/src/, \
$(BUILD)/lib/protomatter/src/core.o: CFLAGS += -include "shared-module/rgbmatrix/allocator.h" -DCIRCUITPY -Wno-missing-braces -Wno-missing-prototypes
endif
ifeq ($(CIRCUITPY_GIFIO),1)
SRC_MOD += $(addprefix lib/AnimatedGIF/, \
gif.c \
)
$(BUILD)/lib/AnimatedGIF/gif.o: CFLAGS += -DCIRCUITPY
endif
ifeq ($(CIRCUITPY_ZLIB),1)
SRC_MOD += $(addprefix lib/uzlib/, \

View File

@ -249,7 +249,8 @@ CIRCUITPY_GETPASS ?= $(CIRCUITPY_FULL_BUILD)
CFLAGS += -DCIRCUITPY_GETPASS=$(CIRCUITPY_GETPASS)
ifeq ($(CIRCUITPY_DISPLAYIO),1)
CIRCUITPY_GIFIO ?= $(CIRCUITPY_CAMERA)
#CIRCUITPY_GIFIO ?= $(CIRCUITPY_CAMERA)
CIRCUITPY_GIFIO ?= 1
else
CIRCUITPY_GIFIO ?= 0
endif

View File

@ -1,210 +0,0 @@
/*
* 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/OnDiskGif.h"
#include <stdint.h>
#include "py/runtime.h"
#include "py/objproperty.h"
#include "supervisor/shared/translate/translate.h"
#include "shared-bindings/displayio/OnDiskGif.h"
//| class OnDiskGif:
//| """Loads values straight from disk. This minimizes memory use but can lead to
//| much slower pixel load times
//|
//| .. code-block:: Python
//|
//| import board
//| import displayio
//| import time
//| import pulseio
//|
//| splash = displayio.Group()
//| board.DISPLAY.show(splash)
//|
//| odg = displayio.OnDiskBitmap('/sample.gif')
//| odg.play_frame() # Load the first frame
//| face = displayio.TileGrid(odg, pixel_shader=displayio.ColorConverter(input_colorspace=displayio.Colorspace.RGB565))
//| splash.append(face)
//| board.DISPLAY.refresh()
//|
//| # Wait forever
//| while True:
//| gif.play_frame()
//| time.sleep(0.1)"""
//|
//| def __init__(self, file: str) -> None:
//| """Create an OnDiskGif object with the given file.
//|
//| :param file file: The name of the GIF file.
//|
//| """
//| ...
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) {
mp_arg_check_num(n_args, n_kw, 1, 1, false);
mp_obj_t arg = all_args[0];
if (mp_obj_is_str(arg)) {
arg = mp_call_function_2(MP_OBJ_FROM_PTR(&mp_builtin_open_obj), arg, MP_ROM_QSTR(MP_QSTR_rb));
}
if (!mp_obj_is_type(arg, &mp_type_fileio)) {
mp_raise_TypeError(translate("file must be a file opened in byte mode"));
}
displayio_ondiskgif_t *self = m_new_obj(displayio_ondiskgif_t);
self->base.type = &displayio_ondiskgif_type;
common_hal_displayio_ondiskgif_construct(self, MP_OBJ_TO_PTR(arg));
return MP_OBJ_FROM_PTR(self);
}
//| width: int
//| """Width of the gif. (read only)"""
STATIC mp_obj_t displayio_ondiskgif_obj_get_width(mp_obj_t self_in) {
displayio_ondiskgif_t *self = MP_OBJ_TO_PTR(self_in);
return MP_OBJ_NEW_SMALL_INT(common_hal_displayio_ondiskgif_get_width(self));
}
MP_DEFINE_CONST_FUN_OBJ_1(displayio_ondiskgif_get_width_obj, displayio_ondiskgif_obj_get_width);
MP_PROPERTY_GETTER(displayio_ondiskgif_width_obj,
(mp_obj_t)&displayio_ondiskgif_get_width_obj);
//| height: int
//| """Height of the gif. (read only)"""
STATIC mp_obj_t displayio_ondiskgif_obj_get_height(mp_obj_t self_in) {
displayio_ondiskgif_t *self = MP_OBJ_TO_PTR(self_in);
return MP_OBJ_NEW_SMALL_INT(common_hal_displayio_ondiskgif_get_height(self));
}
MP_DEFINE_CONST_FUN_OBJ_1(displayio_ondiskgif_get_height_obj, displayio_ondiskgif_obj_get_height);
MP_PROPERTY_GETTER(displayio_ondiskgif_height_obj,
(mp_obj_t)&displayio_ondiskgif_get_height_obj);
//| bitmap: Bitmap
//| """The bitmap used to hold the current frame."""
STATIC mp_obj_t displayio_ondiskgif_obj_get_bitmap(mp_obj_t self_in) {
displayio_ondiskgif_t *self = MP_OBJ_TO_PTR(self_in);
return common_hal_displayio_ondiskgif_get_bitmap(self);
}
MP_DEFINE_CONST_FUN_OBJ_1(displayio_ondiskgif_get_bitmap_obj, displayio_ondiskgif_obj_get_bitmap);
MP_PROPERTY_GETTER(displayio_ondiskgif_bitmap_obj,
(mp_obj_t)&displayio_ondiskgif_get_bitmap_obj);
//| play_frame: int
//| """Play next frame. Returns expected delay until the next frame."""
STATIC mp_obj_t displayio_ondiskgif_obj_play_frame(size_t n_args, const mp_obj_t *args) {
displayio_ondiskgif_t *self = MP_OBJ_TO_PTR(args[0]);
bool setDirty = mp_const_true;
if (n_args == 1) {
setDirty = mp_obj_is_true(args[1]);
}
return MP_OBJ_NEW_SMALL_INT(common_hal_displayio_ondiskgif_play_frame(self, setDirty));
}
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(displayio_ondiskgif_play_frame_obj, 1, 2, displayio_ondiskgif_obj_play_frame);
//| duration: int
//| """Returns the total duration of the GIF in milliseconds. (read only)"""
STATIC mp_obj_t displayio_ondiskgif_obj_get_duration(mp_obj_t self_in) {
displayio_ondiskgif_t *self = MP_OBJ_TO_PTR(self_in);
return MP_OBJ_NEW_SMALL_INT(common_hal_displayio_ondiskgif_get_duration(self));
}
MP_DEFINE_CONST_FUN_OBJ_1(displayio_ondiskgif_get_duration_obj, displayio_ondiskgif_obj_get_duration);
MP_PROPERTY_GETTER(displayio_ondiskgif_duration_obj,
(mp_obj_t)&displayio_ondiskgif_get_duration_obj);
//| frame_count: int
//| """Returns the number of frames in the GIF. (read only)"""
STATIC mp_obj_t displayio_ondiskgif_obj_get_frame_count(mp_obj_t self_in) {
displayio_ondiskgif_t *self = MP_OBJ_TO_PTR(self_in);
return MP_OBJ_NEW_SMALL_INT(common_hal_displayio_ondiskgif_get_frame_count(self));
}
MP_DEFINE_CONST_FUN_OBJ_1(displayio_ondiskgif_get_frame_count_obj, displayio_ondiskgif_obj_get_frame_count);
MP_PROPERTY_GETTER(displayio_ondiskgif_frame_count_obj,
(mp_obj_t)&displayio_ondiskgif_get_frame_count_obj);
//| min_delay: int
//| """The minimum delay found between frames. (read only)"""
STATIC mp_obj_t displayio_ondiskgif_obj_get_min_delay(mp_obj_t self_in) {
displayio_ondiskgif_t *self = MP_OBJ_TO_PTR(self_in);
return MP_OBJ_NEW_SMALL_INT(common_hal_displayio_ondiskgif_get_min_delay(self));
}
MP_DEFINE_CONST_FUN_OBJ_1(displayio_ondiskgif_get_min_delay_obj, displayio_ondiskgif_obj_get_min_delay);
MP_PROPERTY_GETTER(displayio_ondiskgif_min_delay_obj,
(mp_obj_t)&displayio_ondiskgif_get_min_delay_obj);
//| max_delay: int
//| """The maximum delay found between frames. (read only)"""
//|
STATIC mp_obj_t displayio_ondiskgif_obj_get_max_delay(mp_obj_t self_in) {
displayio_ondiskgif_t *self = MP_OBJ_TO_PTR(self_in);
return MP_OBJ_NEW_SMALL_INT(common_hal_displayio_ondiskgif_get_max_delay(self));
}
MP_DEFINE_CONST_FUN_OBJ_1(displayio_ondiskgif_get_max_delay_obj, displayio_ondiskgif_obj_get_max_delay);
MP_PROPERTY_GETTER(displayio_ondiskgif_max_delay_obj,
(mp_obj_t)&displayio_ondiskgif_get_max_delay_obj);
STATIC const mp_rom_map_elem_t displayio_ondiskgif_locals_dict_table[] = {
{ MP_ROM_QSTR(MP_QSTR_height), MP_ROM_PTR(&displayio_ondiskgif_height_obj) },
{ MP_ROM_QSTR(MP_QSTR_bitmap), MP_ROM_PTR(&displayio_ondiskgif_bitmap_obj) },
{ MP_ROM_QSTR(MP_QSTR_width), MP_ROM_PTR(&displayio_ondiskgif_width_obj) },
{ MP_ROM_QSTR(MP_QSTR_play_frame), MP_ROM_PTR(&displayio_ondiskgif_play_frame_obj) },
{ MP_ROM_QSTR(MP_QSTR_duration), MP_ROM_PTR(&displayio_ondiskgif_duration_obj) },
{ MP_ROM_QSTR(MP_QSTR_frame_count), MP_ROM_PTR(&displayio_ondiskgif_frame_count_obj) },
{ MP_ROM_QSTR(MP_QSTR_min_delay), MP_ROM_PTR(&displayio_ondiskgif_min_delay_obj) },
{ MP_ROM_QSTR(MP_QSTR_max_delay), MP_ROM_PTR(&displayio_ondiskgif_max_delay_obj) },
};
STATIC MP_DEFINE_CONST_DICT(displayio_ondiskgif_locals_dict, displayio_ondiskgif_locals_dict_table);
const mp_obj_type_t displayio_ondiskgif_type = {
{ &mp_type_type },
.name = MP_QSTR_OnDiskGif,
.make_new = displayio_ondiskgif_make_new,
.locals_dict = (mp_obj_dict_t *)&displayio_ondiskgif_locals_dict,
};

View File

@ -39,7 +39,6 @@
#include "shared-bindings/displayio/Group.h"
#include "shared-bindings/displayio/I2CDisplay.h"
#include "shared-bindings/displayio/OnDiskBitmap.h"
#include "shared-bindings/displayio/OnDiskGif.h"
#include "shared-bindings/displayio/Palette.h"
#if CIRCUITPY_PARALLELDISPLAY
#include "shared-bindings/paralleldisplay/ParallelBus.h"
@ -86,7 +85,6 @@ STATIC const mp_rom_map_elem_t displayio_module_globals_table[] = {
{ MP_ROM_QSTR(MP_QSTR_EPaperDisplay), MP_ROM_PTR(&displayio_epaperdisplay_type) },
{ MP_ROM_QSTR(MP_QSTR_Group), MP_ROM_PTR(&displayio_group_type) },
{ MP_ROM_QSTR(MP_QSTR_OnDiskBitmap), MP_ROM_PTR(&displayio_ondiskbitmap_type) },
{ MP_ROM_QSTR(MP_QSTR_OnDiskGif), MP_ROM_PTR(&displayio_ondiskgif_type) },
{ MP_ROM_QSTR(MP_QSTR_Palette), MP_ROM_PTR(&displayio_palette_type) },
{ MP_ROM_QSTR(MP_QSTR_Shape), MP_ROM_PTR(&displayio_shape_type) },
{ MP_ROM_QSTR(MP_QSTR_TileGrid), MP_ROM_PTR(&displayio_tilegrid_type) },

View File

@ -0,0 +1,210 @@
/*
* 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/gifio/OnDiskGif.h"
#include <stdint.h>
#include "py/runtime.h"
#include "py/objproperty.h"
#include "supervisor/shared/translate/translate.h"
#include "shared-bindings/gifio/OnDiskGif.h"
//| class OnDiskGif:
//| """Loads values straight from disk. This minimizes memory use but can lead to
//| much slower pixel load times
//|
//| .. code-block:: Python
//|
//| import board
//| import gifio
//| import time
//| import pulseio
//|
//| splash = gifio.Group()
//| board.DISPLAY.show(splash)
//|
//| odg = gifio.OnDiskBitmap('/sample.gif')
//| odg.play_frame() # Load the first frame
//| face = gifio.TileGrid(odg, pixel_shader=gifio.ColorConverter(input_colorspace=gifio.Colorspace.RGB565))
//| splash.append(face)
//| board.DISPLAY.refresh()
//|
//| # Wait forever
//| while True:
//| gif.play_frame()
//| time.sleep(0.1)"""
//|
//| def __init__(self, file: str) -> None:
//| """Create an OnDiskGif object with the given file.
//|
//| :param file file: The name of the GIF file.
//|
//| """
//| ...
STATIC mp_obj_t gifio_ondiskgif_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) {
mp_arg_check_num(n_args, n_kw, 1, 1, false);
mp_obj_t arg = all_args[0];
if (mp_obj_is_str(arg)) {
arg = mp_call_function_2(MP_OBJ_FROM_PTR(&mp_builtin_open_obj), arg, MP_ROM_QSTR(MP_QSTR_rb));
}
if (!mp_obj_is_type(arg, &mp_type_fileio)) {
mp_raise_TypeError(translate("file must be a file opened in byte mode"));
}
gifio_ondiskgif_t *self = m_new_obj(gifio_ondiskgif_t);
self->base.type = &gifio_ondiskgif_type;
common_hal_gifio_ondiskgif_construct(self, MP_OBJ_TO_PTR(arg));
return MP_OBJ_FROM_PTR(self);
}
//| width: int
//| """Width of the gif. (read only)"""
STATIC mp_obj_t gifio_ondiskgif_obj_get_width(mp_obj_t self_in) {
gifio_ondiskgif_t *self = MP_OBJ_TO_PTR(self_in);
return MP_OBJ_NEW_SMALL_INT(common_hal_gifio_ondiskgif_get_width(self));
}
MP_DEFINE_CONST_FUN_OBJ_1(gifio_ondiskgif_get_width_obj, gifio_ondiskgif_obj_get_width);
MP_PROPERTY_GETTER(gifio_ondiskgif_width_obj,
(mp_obj_t)&gifio_ondiskgif_get_width_obj);
//| height: int
//| """Height of the gif. (read only)"""
STATIC mp_obj_t gifio_ondiskgif_obj_get_height(mp_obj_t self_in) {
gifio_ondiskgif_t *self = MP_OBJ_TO_PTR(self_in);
return MP_OBJ_NEW_SMALL_INT(common_hal_gifio_ondiskgif_get_height(self));
}
MP_DEFINE_CONST_FUN_OBJ_1(gifio_ondiskgif_get_height_obj, gifio_ondiskgif_obj_get_height);
MP_PROPERTY_GETTER(gifio_ondiskgif_height_obj,
(mp_obj_t)&gifio_ondiskgif_get_height_obj);
//| bitmap: Bitmap
//| """The bitmap used to hold the current frame."""
STATIC mp_obj_t gifio_ondiskgif_obj_get_bitmap(mp_obj_t self_in) {
gifio_ondiskgif_t *self = MP_OBJ_TO_PTR(self_in);
return common_hal_gifio_ondiskgif_get_bitmap(self);
}
MP_DEFINE_CONST_FUN_OBJ_1(gifio_ondiskgif_get_bitmap_obj, gifio_ondiskgif_obj_get_bitmap);
MP_PROPERTY_GETTER(gifio_ondiskgif_bitmap_obj,
(mp_obj_t)&gifio_ondiskgif_get_bitmap_obj);
//| play_frame: int
//| """Play next frame. Returns expected delay until the next frame."""
STATIC mp_obj_t gifio_ondiskgif_obj_play_frame(size_t n_args, const mp_obj_t *args) {
gifio_ondiskgif_t *self = MP_OBJ_TO_PTR(args[0]);
bool setDirty = mp_const_true;
if (n_args == 1) {
setDirty = mp_obj_is_true(args[1]);
}
return MP_OBJ_NEW_SMALL_INT(common_hal_gifio_ondiskgif_play_frame(self, setDirty));
}
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(gifio_ondiskgif_play_frame_obj, 1, 2, gifio_ondiskgif_obj_play_frame);
//| duration: int
//| """Returns the total duration of the GIF in milliseconds. (read only)"""
STATIC mp_obj_t gifio_ondiskgif_obj_get_duration(mp_obj_t self_in) {
gifio_ondiskgif_t *self = MP_OBJ_TO_PTR(self_in);
return MP_OBJ_NEW_SMALL_INT(common_hal_gifio_ondiskgif_get_duration(self));
}
MP_DEFINE_CONST_FUN_OBJ_1(gifio_ondiskgif_get_duration_obj, gifio_ondiskgif_obj_get_duration);
MP_PROPERTY_GETTER(gifio_ondiskgif_duration_obj,
(mp_obj_t)&gifio_ondiskgif_get_duration_obj);
//| frame_count: int
//| """Returns the number of frames in the GIF. (read only)"""
STATIC mp_obj_t gifio_ondiskgif_obj_get_frame_count(mp_obj_t self_in) {
gifio_ondiskgif_t *self = MP_OBJ_TO_PTR(self_in);
return MP_OBJ_NEW_SMALL_INT(common_hal_gifio_ondiskgif_get_frame_count(self));
}
MP_DEFINE_CONST_FUN_OBJ_1(gifio_ondiskgif_get_frame_count_obj, gifio_ondiskgif_obj_get_frame_count);
MP_PROPERTY_GETTER(gifio_ondiskgif_frame_count_obj,
(mp_obj_t)&gifio_ondiskgif_get_frame_count_obj);
//| min_delay: int
//| """The minimum delay found between frames. (read only)"""
STATIC mp_obj_t gifio_ondiskgif_obj_get_min_delay(mp_obj_t self_in) {
gifio_ondiskgif_t *self = MP_OBJ_TO_PTR(self_in);
return MP_OBJ_NEW_SMALL_INT(common_hal_gifio_ondiskgif_get_min_delay(self));
}
MP_DEFINE_CONST_FUN_OBJ_1(gifio_ondiskgif_get_min_delay_obj, gifio_ondiskgif_obj_get_min_delay);
MP_PROPERTY_GETTER(gifio_ondiskgif_min_delay_obj,
(mp_obj_t)&gifio_ondiskgif_get_min_delay_obj);
//| max_delay: int
//| """The maximum delay found between frames. (read only)"""
//|
STATIC mp_obj_t gifio_ondiskgif_obj_get_max_delay(mp_obj_t self_in) {
gifio_ondiskgif_t *self = MP_OBJ_TO_PTR(self_in);
return MP_OBJ_NEW_SMALL_INT(common_hal_gifio_ondiskgif_get_max_delay(self));
}
MP_DEFINE_CONST_FUN_OBJ_1(gifio_ondiskgif_get_max_delay_obj, gifio_ondiskgif_obj_get_max_delay);
MP_PROPERTY_GETTER(gifio_ondiskgif_max_delay_obj,
(mp_obj_t)&gifio_ondiskgif_get_max_delay_obj);
STATIC const mp_rom_map_elem_t gifio_ondiskgif_locals_dict_table[] = {
{ MP_ROM_QSTR(MP_QSTR_height), MP_ROM_PTR(&gifio_ondiskgif_height_obj) },
{ MP_ROM_QSTR(MP_QSTR_bitmap), MP_ROM_PTR(&gifio_ondiskgif_bitmap_obj) },
{ MP_ROM_QSTR(MP_QSTR_width), MP_ROM_PTR(&gifio_ondiskgif_width_obj) },
{ MP_ROM_QSTR(MP_QSTR_play_frame), MP_ROM_PTR(&gifio_ondiskgif_play_frame_obj) },
{ MP_ROM_QSTR(MP_QSTR_duration), MP_ROM_PTR(&gifio_ondiskgif_duration_obj) },
{ MP_ROM_QSTR(MP_QSTR_frame_count), MP_ROM_PTR(&gifio_ondiskgif_frame_count_obj) },
{ MP_ROM_QSTR(MP_QSTR_min_delay), MP_ROM_PTR(&gifio_ondiskgif_min_delay_obj) },
{ MP_ROM_QSTR(MP_QSTR_max_delay), MP_ROM_PTR(&gifio_ondiskgif_max_delay_obj) },
};
STATIC MP_DEFINE_CONST_DICT(gifio_ondiskgif_locals_dict, gifio_ondiskgif_locals_dict_table);
const mp_obj_type_t gifio_ondiskgif_type = {
{ &mp_type_type },
.name = MP_QSTR_OnDiskGif,
.make_new = gifio_ondiskgif_make_new,
.locals_dict = (mp_obj_dict_t *)&gifio_ondiskgif_locals_dict,
};

View File

@ -27,23 +27,23 @@
#ifndef MICROPY_INCLUDED_SHARED_BINDINGS_DISPLAYIO_ONDISKGIF_H
#define MICROPY_INCLUDED_SHARED_BINDINGS_DISPLAYIO_ONDISKGIF_H
#include "shared-module/displayio/OnDiskGif.h"
#include "shared-module/gifio/OnDiskGif.h"
#include "extmod/vfs_fat.h"
extern const mp_obj_type_t displayio_ondiskgif_type;
extern const mp_obj_type_t gifio_ondiskgif_type;
void common_hal_displayio_ondiskgif_construct(displayio_ondiskgif_t *self, pyb_file_obj_t *file);
void common_hal_gifio_ondiskgif_construct(gifio_ondiskgif_t *self, pyb_file_obj_t *file);
uint32_t common_hal_displayio_ondiskgif_get_pixel(displayio_ondiskgif_t *bitmap,
uint32_t common_hal_gifio_ondiskgif_get_pixel(gifio_ondiskgif_t *bitmap,
int16_t x, int16_t y);
uint16_t common_hal_displayio_ondiskgif_get_height(displayio_ondiskgif_t *self);
mp_obj_t common_hal_displayio_ondiskgif_get_pixel_shader(displayio_ondiskgif_t *self);
mp_obj_t common_hal_displayio_ondiskgif_get_bitmap(displayio_ondiskgif_t *self);
uint16_t common_hal_displayio_ondiskgif_get_width(displayio_ondiskgif_t *self);
uint8_t common_hal_displayio_ondiskgif_play_frame(displayio_ondiskgif_t *self, bool setDirty);
int32_t common_hal_displayio_ondiskgif_get_duration(displayio_ondiskgif_t *self);
int32_t common_hal_displayio_ondiskgif_get_frame_count(displayio_ondiskgif_t *self);
int32_t common_hal_displayio_ondiskgif_get_min_delay(displayio_ondiskgif_t *self);
int32_t common_hal_displayio_ondiskgif_get_max_delay(displayio_ondiskgif_t *self);
uint16_t common_hal_gifio_ondiskgif_get_height(gifio_ondiskgif_t *self);
mp_obj_t common_hal_gifio_ondiskgif_get_pixel_shader(gifio_ondiskgif_t *self);
mp_obj_t common_hal_gifio_ondiskgif_get_bitmap(gifio_ondiskgif_t *self);
uint16_t common_hal_gifio_ondiskgif_get_width(gifio_ondiskgif_t *self);
uint8_t common_hal_gifio_ondiskgif_play_frame(gifio_ondiskgif_t *self, bool setDirty);
int32_t common_hal_gifio_ondiskgif_get_duration(gifio_ondiskgif_t *self);
int32_t common_hal_gifio_ondiskgif_get_frame_count(gifio_ondiskgif_t *self);
int32_t common_hal_gifio_ondiskgif_get_min_delay(gifio_ondiskgif_t *self);
int32_t common_hal_gifio_ondiskgif_get_max_delay(gifio_ondiskgif_t *self);
#endif // MICROPY_INCLUDED_SHARED_BINDINGS_DISPLAYIO_ONDISKGIF_H

View File

@ -27,6 +27,7 @@
#include "py/runtime.h"
#include "py/mphal.h"
#include "shared-bindings/gifio/GifWriter.h"
#include "shared-bindings/gifio/OnDiskGif.h"
#include "shared-bindings/util.h"
//| """Access GIF-format images
@ -34,6 +35,7 @@
STATIC const mp_rom_map_elem_t gifio_module_globals_table[] = {
{ MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_gifio) },
{ MP_OBJ_NEW_QSTR(MP_QSTR_GifWriter), MP_ROM_PTR(&gifio_gifwriter_type)},
{ MP_ROM_QSTR(MP_QSTR_OnDiskGif), MP_ROM_PTR(&gifio_ondiskgif_type) },
};
STATIC MP_DEFINE_CONST_DICT(gifio_module_globals, gifio_module_globals_table);

View File

@ -24,12 +24,8 @@
* THE SOFTWARE.
*/
#include "shared-bindings/displayio/OnDiskGif.h"
#include "shared-bindings/displayio/ColorConverter.h"
#include "shared-bindings/displayio/Palette.h"
#include "shared-bindings/gifio/OnDiskGif.h"
#include "shared-bindings/displayio/Bitmap.h"
#include "shared-module/displayio/ColorConverter.h"
#include "shared-module/displayio/Palette.h"
#include <string.h>
@ -124,7 +120,7 @@ static void GIFDraw(GIFDRAW *pDraw) {
}
}
void common_hal_displayio_ondiskgif_construct(displayio_ondiskgif_t *self, pyb_file_obj_t *file) {
void common_hal_gifio_ondiskgif_construct(gifio_ondiskgif_t *self, pyb_file_obj_t *file) {
// mp_printf(&mp_plat_print, "Begin OnDiskGif\n");
self->file = file;
@ -161,35 +157,35 @@ void common_hal_displayio_ondiskgif_construct(displayio_ondiskgif_t *self, pyb_f
// mp_printf(&mp_plat_print, "GIF_init returned %d %x\n", result, bitmap->data);
}
uint16_t common_hal_displayio_ondiskgif_get_height(displayio_ondiskgif_t *self) {
uint16_t common_hal_gifio_ondiskgif_get_height(gifio_ondiskgif_t *self) {
return (uint16_t)self->gif.iCanvasHeight;
}
uint16_t common_hal_displayio_ondiskgif_get_width(displayio_ondiskgif_t *self) {
uint16_t common_hal_gifio_ondiskgif_get_width(gifio_ondiskgif_t *self) {
return (uint16_t)self->gif.iCanvasWidth;
}
mp_obj_t common_hal_displayio_ondiskgif_get_bitmap(displayio_ondiskgif_t *self) {
mp_obj_t common_hal_gifio_ondiskgif_get_bitmap(gifio_ondiskgif_t *self) {
return MP_OBJ_FROM_PTR(self->bitmap);
}
int32_t common_hal_displayio_ondiskgif_get_duration(displayio_ondiskgif_t *self) {
int32_t common_hal_gifio_ondiskgif_get_duration(gifio_ondiskgif_t *self) {
return self->duration;
}
int32_t common_hal_displayio_ondiskgif_get_frame_count(displayio_ondiskgif_t *self) {
int32_t common_hal_gifio_ondiskgif_get_frame_count(gifio_ondiskgif_t *self) {
return self->frame_count;
}
int32_t common_hal_displayio_ondiskgif_get_min_delay(displayio_ondiskgif_t *self) {
int32_t common_hal_gifio_ondiskgif_get_min_delay(gifio_ondiskgif_t *self) {
return self->min_delay;
}
int32_t common_hal_displayio_ondiskgif_get_max_delay(displayio_ondiskgif_t *self) {
int32_t common_hal_gifio_ondiskgif_get_max_delay(gifio_ondiskgif_t *self) {
return self->max_delay;
}
uint8_t common_hal_displayio_ondiskgif_play_frame(displayio_ondiskgif_t *self, bool setDirty) {
uint8_t common_hal_gifio_ondiskgif_play_frame(gifio_ondiskgif_t *self, bool setDirty) {
int nextDelay = 0;
int result = GIF_playFrame(&self->gif, &nextDelay, self->bitmap);

View File

@ -33,7 +33,7 @@
#include "py/obj.h"
#include "lib/AnimatedGIF/AnimatedGIF_circuitpy.h"
#include "Bitmap.h"
#include "shared-module/displayio/Bitmap.h"
#include "extmod/vfs_fat.h"
@ -46,6 +46,6 @@ typedef struct {
int32_t frame_count;
int32_t min_delay;
int32_t max_delay;
} displayio_ondiskgif_t;
} gifio_ondiskgif_t;
#endif // MICROPY_INCLUDED_SHARED_MODULE_DISPLAYIO_ONDISKGIF_H