displayio: Pass transparent_color to ColorConverter
Signed-off-by: Jensen <jensechu@gmail.com>
This commit is contained in:
parent
b578afa02f
commit
57b44928a3
|
@ -43,6 +43,7 @@
|
|||
//| """Create a ColorConverter object to convert color formats. Only supports RGB888 to RGB565
|
||||
//| currently.
|
||||
//| :param bool dither: Adds random noise to dither the output image"""
|
||||
//| :param bool transparent_color: Sets one color in the colorset to transparent"""
|
||||
//| ...
|
||||
//|
|
||||
|
||||
|
@ -50,9 +51,11 @@
|
|||
//|
|
||||
STATIC mp_obj_t displayio_colorconverter_make_new(const mp_obj_type_t *type, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
||||
enum { ARG_dither};
|
||||
enum { ARG_transparent_color };
|
||||
|
||||
static const mp_arg_t allowed_args[] = {
|
||||
{ MP_QSTR_dither, MP_ARG_KW_ONLY | MP_ARG_BOOL, {.u_bool = false} },
|
||||
{ MP_QSTR_transparent_color, MP_ARG_KW_ONLY | MP_ARG_INT, {.uint32_t = 0} },
|
||||
};
|
||||
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);
|
||||
|
@ -60,7 +63,7 @@ STATIC mp_obj_t displayio_colorconverter_make_new(const mp_obj_type_t *type, siz
|
|||
displayio_colorconverter_t *self = m_new_obj(displayio_colorconverter_t);
|
||||
self->base.type = &displayio_colorconverter_type;
|
||||
|
||||
common_hal_displayio_colorconverter_construct(self, args[ARG_dither].u_bool);
|
||||
common_hal_displayio_colorconverter_construct(self, args[ARG_dither].u_bool, args[ARG_transparent_color].uint32_t);
|
||||
|
||||
return MP_OBJ_FROM_PTR(self);
|
||||
}
|
||||
|
|
|
@ -33,7 +33,7 @@
|
|||
|
||||
extern const mp_obj_type_t displayio_colorconverter_type;
|
||||
|
||||
void common_hal_displayio_colorconverter_construct(displayio_colorconverter_t* self, bool dither);
|
||||
void common_hal_displayio_colorconverter_construct(displayio_colorconverter_t* self, bool dither, uint32_t transparent_color);
|
||||
void common_hal_displayio_colorconverter_convert(displayio_colorconverter_t *colorconverter, const _displayio_colorspace_t* colorspace, uint32_t input_color, uint32_t* output_color);
|
||||
|
||||
void common_hal_displayio_colorconverter_set_dither(displayio_colorconverter_t* self, bool dither);
|
||||
|
|
|
@ -39,8 +39,9 @@ uint32_t displayio_colorconverter_dither_noise_2(uint32_t x, uint32_t y) {
|
|||
return displayio_colorconverter_dither_noise_1(x + y * 0xFFFF);
|
||||
}
|
||||
|
||||
void common_hal_displayio_colorconverter_construct(displayio_colorconverter_t* self, bool dither) {
|
||||
void common_hal_displayio_colorconverter_construct(displayio_colorconverter_t* self, bool dither, uint32_t transparent_color) {
|
||||
self->dither = dither;
|
||||
self->transparent_color = transparent_color;
|
||||
}
|
||||
|
||||
uint16_t displayio_colorconverter_compute_rgb565(uint32_t color_rgb888) {
|
||||
|
@ -161,6 +162,9 @@ void displayio_colorconverter_convert(displayio_colorconverter_t *self, const _d
|
|||
}
|
||||
output_color->pixel = packed;
|
||||
output_color->opaque = true;
|
||||
if (self->transparent_color == pixel) {
|
||||
output_color->opaque = false;
|
||||
}
|
||||
return;
|
||||
} else if (colorspace->tricolor) {
|
||||
uint8_t luma = displayio_colorconverter_compute_luma(pixel);
|
||||
|
@ -170,6 +174,9 @@ void displayio_colorconverter_convert(displayio_colorconverter_t *self, const _d
|
|||
output_color->pixel = 0;
|
||||
}
|
||||
output_color->opaque = true;
|
||||
if (self->transparent_color == pixel) {
|
||||
output_color->opaque = false;
|
||||
}
|
||||
return;
|
||||
}
|
||||
uint8_t pixel_hue = displayio_colorconverter_compute_hue(pixel);
|
||||
|
@ -179,6 +186,9 @@ void displayio_colorconverter_convert(displayio_colorconverter_t *self, const _d
|
|||
uint8_t luma = displayio_colorconverter_compute_luma(pixel);
|
||||
output_color->pixel = luma >> (8 - colorspace->depth);
|
||||
output_color->opaque = true;
|
||||
if (self->transparent_color == pixel) {
|
||||
output_color->opaque = false;
|
||||
}
|
||||
return;
|
||||
}
|
||||
output_color->opaque = false;
|
||||
|
|
|
@ -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