Skip to content

Commit 1a67740

Browse files
authored
Merge pull request #3529 from jensechu/color-converter-transparency
displayio: Pass transparent_color to ColorConverter
2 parents 098fd3e + 8beb36c commit 1a67740

File tree

7 files changed

+58
-5
lines changed

7 files changed

+58
-5
lines changed

locale/circuitpython.pot

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ msgid ""
88
msgstr ""
99
"Project-Id-Version: PACKAGE VERSION\n"
1010
"Report-Msgid-Bugs-To: \n"
11-
"POT-Creation-Date: 2020-10-16 13:56-0500\n"
11+
"POT-Creation-Date: 2020-10-16 19:50-0500\n"
1212
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
1313
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
1414
"Language-Team: LANGUAGE <[email protected]>\n"
@@ -1404,6 +1404,10 @@ msgid ""
14041404
"%d bpp given"
14051405
msgstr ""
14061406

1407+
#: shared-module/displayio/ColorConverter.c
1408+
msgid "Only one color can be transparent at a time"
1409+
msgstr ""
1410+
14071411
#: shared-bindings/ipaddress/__init__.c
14081412
msgid "Only raw int supported for ip"
14091413
msgstr ""

locale/zh_Latn_pinyin.po

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3277,7 +3277,7 @@ msgstr "yòubiān bìxū shì ndarray huò biāoliàng"
32773277

32783278
#: py/objstr.c
32793279
msgid "rsplit(None,n)"
3280-
msgstr "Rchāifēn(wú ,N)"
3280+
msgstr "Rchāifēn(wú,N)"
32813281

32823282
#: shared-bindings/audiocore/RawSample.c
32833283
msgid ""

ports/atmel-samd/Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ $(echo PERIPHERALS_CHIP_FAMILY=$(PERIPHERALS_CHIP_FAMILY))
121121
ifeq ($(DEBUG), 1)
122122
CFLAGS += -ggdb3 -Og
123123
# You may want to disable -flto if it interferes with debugging.
124-
CFLAGS += -flto
124+
CFLAGS += -flto -flto-partition=none
125125
# You may want to enable these flags to make setting breakpoints easier.
126126
# CFLAGS += -fno-inline -fno-ipa-sra
127127
ifeq ($(CHIP_FAMILY), samd21)
@@ -144,7 +144,7 @@ else
144144
CFLAGS += -finline-limit=$(CFLAGS_INLINE_LIMIT)
145145
endif
146146

147-
CFLAGS += -flto
147+
CFLAGS += -flto -flto-partition=none
148148

149149
ifeq ($(CIRCUITPY_FULL_BUILD),0)
150150
CFLAGS += --param inline-unit-growth=15 --param max-inline-insns-auto=20

shared-bindings/displayio/ColorConverter.c

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ STATIC mp_obj_t displayio_colorconverter_make_new(const mp_obj_type_t *type, siz
5252
enum { ARG_dither};
5353

5454
static const mp_arg_t allowed_args[] = {
55-
{ MP_QSTR_dither, MP_ARG_KW_ONLY | MP_ARG_BOOL, {.u_bool = false} },
55+
{ MP_QSTR_dither, MP_ARG_KW_ONLY | MP_ARG_BOOL, {.u_bool = false} }
5656
};
5757
mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)];
5858
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 = {
110110
(mp_obj_t)&mp_const_none_obj},
111111
};
112112

113+
//| def make_transparent(self, pixel: int) -> None:
114+
//| """Sets a pixel to not opaque."""
115+
//|
116+
STATIC mp_obj_t displayio_colorconverter_make_transparent(mp_obj_t self_in, mp_obj_t transparent_color_obj) {
117+
displayio_colorconverter_t *self = MP_OBJ_TO_PTR(self_in);
118+
119+
mp_int_t transparent_color = mp_obj_get_int(&transparent_color);
120+
common_hal_displayio_colorconverter_make_transparent(self, transparent_color);
121+
return mp_const_none;
122+
}
123+
MP_DEFINE_CONST_FUN_OBJ_2(displayio_colorconverter_make_transparent_obj, displayio_colorconverter_make_transparent);
124+
125+
//| def make_opaque(self, pixel: int) -> None:
126+
//| """Sets a pixel to opaque."""
127+
//|
128+
STATIC mp_obj_t displayio_colorconverter_make_opaque(mp_obj_t self_in, mp_obj_t transparent_color_obj) {
129+
displayio_colorconverter_t *self = MP_OBJ_TO_PTR(self_in);
130+
131+
mp_int_t transparent_color = mp_obj_get_int(&transparent_color);
132+
common_hal_displayio_colorconverter_make_opaque(self, transparent_color);
133+
return mp_const_none;
134+
}
135+
MP_DEFINE_CONST_FUN_OBJ_2(displayio_colorconverter_make_opaque_obj, displayio_colorconverter_make_opaque);
136+
113137
STATIC const mp_rom_map_elem_t displayio_colorconverter_locals_dict_table[] = {
114138
{ MP_ROM_QSTR(MP_QSTR_convert), MP_ROM_PTR(&displayio_colorconverter_convert_obj) },
115139
{ MP_ROM_QSTR(MP_QSTR_dither), MP_ROM_PTR(&displayio_colorconverter_dither_obj) },
140+
{ MP_ROM_QSTR(MP_QSTR_make_transparent), MP_ROM_PTR(&displayio_colorconverter_make_transparent_obj) },
141+
{ MP_ROM_QSTR(MP_QSTR_make_opaque), MP_ROM_PTR(&displayio_colorconverter_make_opaque_obj) },
116142
};
117143
STATIC MP_DEFINE_CONST_DICT(displayio_colorconverter_locals_dict, displayio_colorconverter_locals_dict_table);
118144

shared-bindings/displayio/ColorConverter.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,7 @@ void common_hal_displayio_colorconverter_convert(displayio_colorconverter_t *col
3939
void common_hal_displayio_colorconverter_set_dither(displayio_colorconverter_t* self, bool dither);
4040
bool common_hal_displayio_colorconverter_get_dither(displayio_colorconverter_t* self);
4141

42+
void common_hal_displayio_colorconverter_make_transparent(displayio_colorconverter_t* self, uint32_t transparent_color);
43+
void common_hal_displayio_colorconverter_make_opaque(displayio_colorconverter_t* self, uint32_t transparent_color);
44+
4245
#endif // MICROPY_INCLUDED_SHARED_BINDINGS_DISPLAYIO_COLORCONVERTER_H

shared-module/displayio/ColorConverter.c

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#include "shared-bindings/displayio/ColorConverter.h"
2828

2929
#include "py/misc.h"
30+
#include "py/runtime.h"
3031

3132
uint32_t displayio_colorconverter_dither_noise_1 (uint32_t n)
3233
{
@@ -128,9 +129,27 @@ bool common_hal_displayio_colorconverter_get_dither(displayio_colorconverter_t*
128129
return self->dither;
129130
}
130131

132+
void common_hal_displayio_colorconverter_make_transparent(displayio_colorconverter_t* self, uint32_t transparent_color) {
133+
if (self->transparent_color >= 0x1000000) {
134+
mp_raise_RuntimeError(translate("Only one color can be transparent at a time"));
135+
}
136+
self->transparent_color = transparent_color;
137+
}
138+
139+
void common_hal_displayio_colorconverter_make_opaque(displayio_colorconverter_t* self, uint32_t transparent_color) {
140+
(void) transparent_color;
141+
// 0x1000000 will never equal a valid color
142+
self->transparent_color = 0x1000000;
143+
}
144+
131145
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) {
132146
uint32_t pixel = input_pixel->pixel;
133147

148+
if (self->transparent_color == pixel) {
149+
output_color->opaque = false;
150+
return;
151+
}
152+
134153
if (self->dither){
135154
uint8_t randr = (displayio_colorconverter_dither_noise_2(input_pixel->tile_x,input_pixel->tile_y));
136155
uint8_t randg = (displayio_colorconverter_dither_noise_2(input_pixel->tile_x+33,input_pixel->tile_y));

shared-module/displayio/ColorConverter.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
typedef struct {
3737
mp_obj_base_t base;
3838
bool dither;
39+
uint32_t transparent_color;
3940
} displayio_colorconverter_t;
4041

4142
bool displayio_colorconverter_needs_refresh(displayio_colorconverter_t *self);

0 commit comments

Comments
 (0)