Merge pull request #3529 from jensechu/color-converter-transparency
displayio: Pass transparent_color to ColorConverter
This commit is contained in:
commit
1a677406bf
|
@ -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 ""
|
||||
|
|
|
@ -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 ""
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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));
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in New Issue