Skip to content

Commit c27b3a0

Browse files
authored
Merge pull request #5490 from jepler/gifio
Implement gifio.GifWriter
2 parents 102af55 + 334a9c8 commit c27b3a0

File tree

27 files changed

+812
-66
lines changed

27 files changed

+812
-66
lines changed

locale/circuitpython.pot

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,11 +104,11 @@ msgid "%q length must be >= 1"
104104
msgstr ""
105105

106106
#: py/argcheck.c
107-
msgid "%q must <= %d"
107+
msgid "%q must be %d-%d"
108108
msgstr ""
109109

110-
#: py/argcheck.c
111-
msgid "%q must be %d-%d"
110+
#: py/argcheck.c shared-bindings/gifio/GifWriter.c
111+
msgid "%q must be <= %d"
112112
msgstr ""
113113

114114
#: py/argcheck.c
@@ -3087,6 +3087,7 @@ msgstr ""
30873087

30883088
#: shared-bindings/audiocore/WaveFile.c shared-bindings/audiomp3/MP3Decoder.c
30893089
#: shared-bindings/displayio/OnDiskBitmap.c shared-bindings/synthio/__init__.c
3090+
#: shared-module/gifio/GifWriter.c
30903091
msgid "file must be a file opened in byte mode"
30913092
msgstr ""
30923093

@@ -4345,6 +4346,10 @@ msgstr ""
43454346
msgid "unsupported Xtensa instruction '%s' with %d arguments"
43464347
msgstr ""
43474348

4349+
#: shared-module/gifio/GifWriter.c
4350+
msgid "unsupported colorspace for GifWriter"
4351+
msgstr ""
4352+
43484353
#: py/objstr.c
43494354
#, c-format
43504355
msgid "unsupported format character '%c' (0x%x) at index %d"

ports/atmel-samd/boards/pybadge/mpconfigboard.mk

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ LONGINT_IMPL = MPZ
1212

1313
CIRCUITPY_AESIO = 0
1414
CIRCUITPY_GAMEPADSHIFT = 1
15+
CIRCUITPY_GIFIO = 0
1516
CIRCUITPY_STAGE = 1
1617

1718
FROZEN_MPY_DIRS += $(TOP)/frozen/circuitpython-stage/pybadge

ports/atmel-samd/boards/pygamer/mpconfigboard.mk

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ LONGINT_IMPL = MPZ
1212

1313
CIRCUITPY_AESIO = 0
1414
CIRCUITPY_GAMEPADSHIFT = 1
15+
CIRCUITPY_GIFIO = 0
1516
CIRCUITPY_STAGE = 1
1617

1718
FROZEN_MPY_DIRS += $(TOP)/frozen/circuitpython-stage/pygamer

ports/atmel-samd/mpconfigport.mk

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ CIRCUITPY_COUNTIO ?= 0
4949
# Not enough RAM for framebuffers
5050
CIRCUITPY_FRAMEBUFFERIO ?= 0
5151
CIRCUITPY_FREQUENCYIO ?= 0
52+
CIRCUITPY_GIFIO ?= 0
5253
CIRCUITPY_I2CPERIPHERAL ?= 0
5354
CIRCUITPY_JSON ?= 0
5455
CIRCUITPY_KEYPAD ?= 0

ports/stm/boards/espruino_pico/mpconfigboard.mk

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ CIRCUITPY_AUDIOPWMIO = 0
2323
CIRCUITPY_BUSDEVICE = 0
2424
CIRCUITPY_BITMAPTOOLS = 0
2525
CIRCUITPY_FRAMEBUFFERIO = 0
26+
CIRCUITPY_GIFIO = 0
2627
CIRCUITPY_KEYPAD = 0
2728
CIRCUITPY_MIDI = 0
2829
CIRCUITPY_MSGPACK = 0

ports/stm/boards/meowbit_v121/mpconfigboard.mk

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ LD_FILE = boards/STM32F401xe_boot.ld
2222

2323
CIRCUITPY_AESIO = 0
2424
CIRCUITPY_BLEIO_HCI = 0
25+
CIRCUITPY_GIFIO = 0
2526
CIRCUITPY_ULAB = 0
2627
CIRCUITPY_STAGE = 1
2728

ports/stm/boards/pyb_nano_v2/mpconfigboard.mk

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ LD_FILE = boards/STM32F411_fs.ld
1717
CIRCUITPY_AUDIOCORE = 0
1818
CIRCUITPY_AUDIOPWMIO = 0
1919
CIRCUITPY_KEYPAD = 0
20+
CIRCUITPY_GIFIO = 0
2021
CIRCUITPY_MIDI = 0
2122
CIRCUITPY_MSGPACK = 0
2223
CIRCUITPY_BITMAPTOOLS = 0
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
/*
2+
* This file is part of the MicroPython project, http://micropython.org/
3+
*
4+
* The MIT License (MIT)
5+
*
6+
* Copyright (c) 2021 Jeff Epler for Adafruit Industries
7+
*
8+
* Permission is hereby granted, free of charge, to any person obtaining a copy
9+
* of this software and associated documentation files (the "Software"), to deal
10+
* in the Software without restriction, including without limitation the rights
11+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12+
* copies of the Software, and to permit persons to whom the Software is
13+
* furnished to do so, subject to the following conditions:
14+
*
15+
* The above copyright notice and this permission notice shall be included in
16+
* all copies or substantial portions of the Software.
17+
*
18+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24+
* THE SOFTWARE.
25+
*/
26+
27+
#include "py/enum.h"
28+
#include "py/obj.h"
29+
#include "py/runtime.h"
30+
31+
#include "shared-bindings/displayio/__init__.h"
32+
33+
MAKE_ENUM_VALUE(displayio_colorspace_type, displayio_colorspace, RGB888, DISPLAYIO_COLORSPACE_RGB888);
34+
MAKE_ENUM_VALUE(displayio_colorspace_type, displayio_colorspace, RGB565, DISPLAYIO_COLORSPACE_RGB565);
35+
MAKE_ENUM_VALUE(displayio_colorspace_type, displayio_colorspace, RGB565_SWAPPED, DISPLAYIO_COLORSPACE_RGB565_SWAPPED);
36+
MAKE_ENUM_VALUE(displayio_colorspace_type, displayio_colorspace, RGB555, DISPLAYIO_COLORSPACE_RGB555);
37+
MAKE_ENUM_VALUE(displayio_colorspace_type, displayio_colorspace, RGB555_SWAPPED, DISPLAYIO_COLORSPACE_RGB555_SWAPPED);
38+
MAKE_ENUM_VALUE(displayio_colorspace_type, displayio_colorspace, BGR565, DISPLAYIO_COLORSPACE_BGR565);
39+
MAKE_ENUM_VALUE(displayio_colorspace_type, displayio_colorspace, BGR565_SWAPPED, DISPLAYIO_COLORSPACE_BGR565_SWAPPED);
40+
MAKE_ENUM_VALUE(displayio_colorspace_type, displayio_colorspace, BGR555, DISPLAYIO_COLORSPACE_BGR555);
41+
MAKE_ENUM_VALUE(displayio_colorspace_type, displayio_colorspace, BGR555_SWAPPED, DISPLAYIO_COLORSPACE_BGR555_SWAPPED);
42+
MAKE_ENUM_VALUE(displayio_colorspace_type, displayio_colorspace, L8, DISPLAYIO_COLORSPACE_L8);
43+
44+
//| class Colorspace:
45+
//| """The colorspace for a `ColorConverter` to operate in"""
46+
//|
47+
//| RGB888: Colorspace
48+
//| """The standard 24-bit colorspace. Bits 0-7 are blue, 8-15 are green, and 16-24 are red. (0xRRGGBB)"""
49+
//|
50+
//| RGB565: Colorspace
51+
//| """The standard 16-bit colorspace. Bits 0-4 are blue, bits 5-10 are green, and 11-15 are red (0bRRRRRGGGGGGBBBBB)"""
52+
//|
53+
//| RGB565_SWAPPED: Colorspace
54+
//| """The swapped 16-bit colorspace. First, the high and low 8 bits of the number are swapped, then they are interpreted as for RGB565"""
55+
//|
56+
//| RGB555: Colorspace
57+
//| """The standard 15-bit colorspace. Bits 0-4 are blue, bits 5-9 are green, and 11-14 are red. The top bit is ignored. (0bxRRRRRGGGGGBBBBB)"""
58+
//|
59+
//| RGB555_SWAPPED: Colorspace
60+
//| """The swapped 15-bit colorspace. First, the high and low 8 bits of the number are swapped, then they are interpreted as for RGB555"""
61+
//|
62+
MAKE_ENUM_MAP(displayio_colorspace) {
63+
MAKE_ENUM_MAP_ENTRY(displayio_colorspace, RGB888),
64+
MAKE_ENUM_MAP_ENTRY(displayio_colorspace, RGB565),
65+
MAKE_ENUM_MAP_ENTRY(displayio_colorspace, RGB565_SWAPPED),
66+
MAKE_ENUM_MAP_ENTRY(displayio_colorspace, RGB555),
67+
MAKE_ENUM_MAP_ENTRY(displayio_colorspace, RGB555_SWAPPED),
68+
MAKE_ENUM_MAP_ENTRY(displayio_colorspace, BGR565),
69+
MAKE_ENUM_MAP_ENTRY(displayio_colorspace, BGR565_SWAPPED),
70+
MAKE_ENUM_MAP_ENTRY(displayio_colorspace, BGR555),
71+
MAKE_ENUM_MAP_ENTRY(displayio_colorspace, BGR555_SWAPPED),
72+
MAKE_ENUM_MAP_ENTRY(displayio_colorspace, L8),
73+
};
74+
STATIC MP_DEFINE_CONST_DICT(displayio_colorspace_locals_dict, displayio_colorspace_locals_table);
75+
76+
MAKE_PRINTER(displayio, displayio_colorspace);
77+
MAKE_ENUM_TYPE(displayio, ColorSpace, displayio_colorspace);
78+
79+
STATIC const mp_rom_map_elem_t displayio_module_globals_table[] = {
80+
{ MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_displayio) },
81+
{ MP_ROM_QSTR(MP_QSTR_Colorspace), MP_ROM_PTR(&displayio_colorspace_type) },
82+
};
83+
STATIC MP_DEFINE_CONST_DICT(displayio_module_globals, displayio_module_globals_table);
84+
85+
const mp_obj_module_t displayio_module = {
86+
.base = { &mp_type_module },
87+
.globals = (mp_obj_dict_t *)&displayio_module_globals,
88+
};
89+
90+
MP_REGISTER_MODULE(MP_QSTR_displayio, displayio_module, CIRCUITPY_DISPLAYIO_COLORSPACE_ONLY);

ports/unix/variants/coverage/mpconfigvariant.mk

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,5 +27,10 @@ SRC_C += $(SRC_QRIO)
2727
CFLAGS += -DCIRCUITPY_QRIO=1
2828
$(BUILD)/lib/quirc/lib/%.o: CFLAGS += -Wno-shadow -Wno-sign-compare -include shared-module/qrio/quirc_alloc.h
2929

30+
SRC_GIFIO := $(patsubst ../../%,%,$(wildcard ../../shared-bindings/gifio/*.c ../../shared-module/gifio/*.c)) shared/runtime/context_manager_helpers.c displayio_colorspace_only.c shared-module/displayio/ColorConverter.c shared-bindings/util.c
31+
SRC_C += $(SRC_GIFIO)
32+
33+
CFLAGS += -DCIRCUITPY_GIFIO=1 -DCIRCUITPY_DISPLAYIO_COLORSPACE_ONLY=1
34+
3035
SRC_C += coverage.c
3136
SRC_CXX += coveragecpp.cpp

py/argcheck.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ mp_int_t mp_arg_validate_int_min(mp_int_t i, mp_int_t min, qstr arg_name) {
165165

166166
mp_int_t mp_arg_validate_int_max(mp_int_t i, mp_int_t max, qstr arg_name) {
167167
if (i > max) {
168-
mp_raise_ValueError_varg(translate("%q must <= %d"), arg_name, max);
168+
mp_raise_ValueError_varg(translate("%q must be <= %d"), arg_name, max);
169169
}
170170
return i;
171171
}

0 commit comments

Comments
 (0)