diff options
| author | Scott Shawcroft <scott@adafruit.com> | 2020-10-20 10:41:57 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-10-20 10:41:57 -0700 |
| commit | 1a677406bf116aaba85656c64d0632fbb60189c2 (patch) | |
| tree | 988cad3808aff8bddd2bac63f520baaaa45e662f | |
| parent | 098fd3efd2d24ede727d4f82cd6497f6dd360370 (diff) | |
| parent | 8beb36c240d162bfb3f12dceb46d409eee26722d (diff) | |
Merge pull request #3529 from jensechu/color-converter-transparency
displayio: Pass transparent_color to ColorConverter
| -rw-r--r-- | locale/circuitpython.pot | 6 | ||||
| -rw-r--r-- | locale/zh_Latn_pinyin.po | 2 | ||||
| -rw-r--r-- | ports/atmel-samd/Makefile | 4 | ||||
| -rw-r--r-- | shared-bindings/displayio/ColorConverter.c | 28 | ||||
| -rw-r--r-- | shared-bindings/displayio/ColorConverter.h | 3 | ||||
| -rw-r--r-- | shared-module/displayio/ColorConverter.c | 19 | ||||
| -rw-r--r-- | shared-module/displayio/ColorConverter.h | 1 |
7 files changed, 58 insertions, 5 deletions
diff --git a/locale/circuitpython.pot b/locale/circuitpython.pot index 71ef9adca..7ed2d1ba1 100644 --- a/locale/circuitpython.pot +++ b/locale/circuitpython.pot @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2020-10-16 13:56-0500\n" +"POT-Creation-Date: 2020-10-16 19:50-0500\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n" "Language-Team: LANGUAGE <LL@li.org>\n" @@ -1404,6 +1404,10 @@ msgid "" "%d bpp given" msgstr "" +#: shared-module/displayio/ColorConverter.c +msgid "Only one color can be transparent at a time" +msgstr "" + #: shared-bindings/ipaddress/__init__.c msgid "Only raw int supported for ip" msgstr "" diff --git a/locale/zh_Latn_pinyin.po b/locale/zh_Latn_pinyin.po index 365b1e498..892b9ac58 100644 --- a/locale/zh_Latn_pinyin.po +++ b/locale/zh_Latn_pinyin.po @@ -3277,7 +3277,7 @@ msgstr "yòubiān bìxū shì ndarray huò biāoliàng" #: py/objstr.c msgid "rsplit(None,n)" -msgstr "Rchāifēn(wú ,N)" +msgstr "Rchāifēn(wú,N)" #: shared-bindings/audiocore/RawSample.c msgid "" diff --git a/ports/atmel-samd/Makefile b/ports/atmel-samd/Makefile index 111f12b4e..dc7b4e4c8 100644 --- a/ports/atmel-samd/Makefile +++ b/ports/atmel-samd/Makefile @@ -121,7 +121,7 @@ $(echo PERIPHERALS_CHIP_FAMILY=$(PERIPHERALS_CHIP_FAMILY)) ifeq ($(DEBUG), 1) CFLAGS += -ggdb3 -Og # You may want to disable -flto if it interferes with debugging. - CFLAGS += -flto + CFLAGS += -flto -flto-partition=none # You may want to enable these flags to make setting breakpoints easier. # CFLAGS += -fno-inline -fno-ipa-sra ifeq ($(CHIP_FAMILY), samd21) @@ -144,7 +144,7 @@ else CFLAGS += -finline-limit=$(CFLAGS_INLINE_LIMIT) endif - CFLAGS += -flto + CFLAGS += -flto -flto-partition=none ifeq ($(CIRCUITPY_FULL_BUILD),0) CFLAGS += --param inline-unit-growth=15 --param max-inline-insns-auto=20 diff --git a/shared-bindings/displayio/ColorConverter.c b/shared-bindings/displayio/ColorConverter.c index a2b6699ef..0e6e9bfd9 100644 --- a/shared-bindings/displayio/ColorConverter.c +++ b/shared-bindings/displayio/ColorConverter.c @@ -52,7 +52,7 @@ STATIC mp_obj_t displayio_colorconverter_make_new(const mp_obj_type_t *type, siz enum { ARG_dither}; static const mp_arg_t allowed_args[] = { - { MP_QSTR_dither, MP_ARG_KW_ONLY | MP_ARG_BOOL, {.u_bool = false} }, + { MP_QSTR_dither, MP_ARG_KW_ONLY | MP_ARG_BOOL, {.u_bool = false} } }; mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; mp_arg_parse_all(n_args, pos_args, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); @@ -110,9 +110,35 @@ const mp_obj_property_t displayio_colorconverter_dither_obj = { (mp_obj_t)&mp_const_none_obj}, }; +//| def make_transparent(self, pixel: int) -> None: +//| """Sets a pixel to not opaque.""" +//| +STATIC mp_obj_t displayio_colorconverter_make_transparent(mp_obj_t self_in, mp_obj_t transparent_color_obj) { + displayio_colorconverter_t *self = MP_OBJ_TO_PTR(self_in); + + mp_int_t transparent_color = mp_obj_get_int(&transparent_color); + common_hal_displayio_colorconverter_make_transparent(self, transparent_color); + return mp_const_none; +} +MP_DEFINE_CONST_FUN_OBJ_2(displayio_colorconverter_make_transparent_obj, displayio_colorconverter_make_transparent); + +//| def make_opaque(self, pixel: int) -> None: +//| """Sets a pixel to opaque.""" +//| +STATIC mp_obj_t displayio_colorconverter_make_opaque(mp_obj_t self_in, mp_obj_t transparent_color_obj) { + displayio_colorconverter_t *self = MP_OBJ_TO_PTR(self_in); + + mp_int_t transparent_color = mp_obj_get_int(&transparent_color); + common_hal_displayio_colorconverter_make_opaque(self, transparent_color); + return mp_const_none; +} +MP_DEFINE_CONST_FUN_OBJ_2(displayio_colorconverter_make_opaque_obj, displayio_colorconverter_make_opaque); + STATIC const mp_rom_map_elem_t displayio_colorconverter_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_convert), MP_ROM_PTR(&displayio_colorconverter_convert_obj) }, { MP_ROM_QSTR(MP_QSTR_dither), MP_ROM_PTR(&displayio_colorconverter_dither_obj) }, + { MP_ROM_QSTR(MP_QSTR_make_transparent), MP_ROM_PTR(&displayio_colorconverter_make_transparent_obj) }, + { MP_ROM_QSTR(MP_QSTR_make_opaque), MP_ROM_PTR(&displayio_colorconverter_make_opaque_obj) }, }; STATIC MP_DEFINE_CONST_DICT(displayio_colorconverter_locals_dict, displayio_colorconverter_locals_dict_table); diff --git a/shared-bindings/displayio/ColorConverter.h b/shared-bindings/displayio/ColorConverter.h index d550d81be..441f7c7ae 100644 --- a/shared-bindings/displayio/ColorConverter.h +++ b/shared-bindings/displayio/ColorConverter.h @@ -39,4 +39,7 @@ void common_hal_displayio_colorconverter_convert(displayio_colorconverter_t *col void common_hal_displayio_colorconverter_set_dither(displayio_colorconverter_t* self, bool dither); bool common_hal_displayio_colorconverter_get_dither(displayio_colorconverter_t* self); +void common_hal_displayio_colorconverter_make_transparent(displayio_colorconverter_t* self, uint32_t transparent_color); +void common_hal_displayio_colorconverter_make_opaque(displayio_colorconverter_t* self, uint32_t transparent_color); + #endif // MICROPY_INCLUDED_SHARED_BINDINGS_DISPLAYIO_COLORCONVERTER_H diff --git a/shared-module/displayio/ColorConverter.c b/shared-module/displayio/ColorConverter.c index c2c3214aa..dc64da03d 100644 --- a/shared-module/displayio/ColorConverter.c +++ b/shared-module/displayio/ColorConverter.c @@ -27,6 +27,7 @@ #include "shared-bindings/displayio/ColorConverter.h" #include "py/misc.h" +#include "py/runtime.h" uint32_t displayio_colorconverter_dither_noise_1 (uint32_t n) { @@ -128,9 +129,27 @@ bool common_hal_displayio_colorconverter_get_dither(displayio_colorconverter_t* return self->dither; } +void common_hal_displayio_colorconverter_make_transparent(displayio_colorconverter_t* self, uint32_t transparent_color) { + if (self->transparent_color >= 0x1000000) { + mp_raise_RuntimeError(translate("Only one color can be transparent at a time")); + } + self->transparent_color = transparent_color; +} + +void common_hal_displayio_colorconverter_make_opaque(displayio_colorconverter_t* self, uint32_t transparent_color) { + (void) transparent_color; + // 0x1000000 will never equal a valid color + self->transparent_color = 0x1000000; +} + void displayio_colorconverter_convert(displayio_colorconverter_t *self, const _displayio_colorspace_t* colorspace, const displayio_input_pixel_t *input_pixel, displayio_output_pixel_t *output_color) { uint32_t pixel = input_pixel->pixel; + if (self->transparent_color == pixel) { + output_color->opaque = false; + return; + } + if (self->dither){ uint8_t randr = (displayio_colorconverter_dither_noise_2(input_pixel->tile_x,input_pixel->tile_y)); uint8_t randg = (displayio_colorconverter_dither_noise_2(input_pixel->tile_x+33,input_pixel->tile_y)); diff --git a/shared-module/displayio/ColorConverter.h b/shared-module/displayio/ColorConverter.h index 10b1604a4..b402625ef 100644 --- a/shared-module/displayio/ColorConverter.h +++ b/shared-module/displayio/ColorConverter.h @@ -36,6 +36,7 @@ typedef struct { mp_obj_base_t base; bool dither; + uint32_t transparent_color; } displayio_colorconverter_t; bool displayio_colorconverter_needs_refresh(displayio_colorconverter_t *self); |
