Move dither parameter to ColorConverter constructor and parameter

This commit is contained in:
Matthew Newberg 2019-09-05 21:55:45 -04:00
parent 3ab6a23434
commit 4604a69498
6 changed files with 56 additions and 38 deletions

View File

@ -51,11 +51,18 @@
// TODO(tannewt): Add support for other color formats.
//|
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) {
mp_arg_check_num(n_args, kw_args, 0, 0, false);
mp_arg_check_num(n_args, kw_args, 0, 1, false);
displayio_colorconverter_t *self = m_new_obj(displayio_colorconverter_t);
self->base.type = &displayio_colorconverter_type;
common_hal_displayio_colorconverter_construct(self);
bool dither = false;
if (n_args > 0) {
dither = mp_obj_is_true(pos_args[0]);
}
common_hal_displayio_colorconverter_construct(self, dither);
return MP_OBJ_FROM_PTR(self);
}
@ -79,8 +86,35 @@ STATIC mp_obj_t displayio_colorconverter_obj_convert(mp_obj_t self_in, mp_obj_t
}
MP_DEFINE_CONST_FUN_OBJ_2(displayio_colorconverter_convert_obj, displayio_colorconverter_obj_convert);
//| .. attribute:: dither
//|
//| True when the display is dithered
//|
STATIC mp_obj_t displayio_colorconverter_obj_get_dither(mp_obj_t self_in) {
displayio_colorconverter_t *self = MP_OBJ_TO_PTR(self_in);
return mp_obj_new_bool(common_hal_displayio_colorconverter_get_dither(self));
}
MP_DEFINE_CONST_FUN_OBJ_1(displayio_colorconverter_get_dither_obj, displayio_colorconverter_obj_get_dither);
STATIC mp_obj_t displayio_colorconverter_obj_set_dither(mp_obj_t self_in, mp_obj_t dither) {
displayio_colorconverter_t *self = MP_OBJ_TO_PTR(self_in);
common_hal_displayio_colorconverter_set_dither(self, mp_obj_is_true(dither));
return mp_const_none;
}
MP_DEFINE_CONST_FUN_OBJ_2(displayio_colorconverter_set_dither_obj, displayio_colorconverter_obj_set_dither);
const mp_obj_property_t displayio_colorconverter_dither_obj = {
.base.type = &mp_type_property,
.proxy = {(mp_obj_t)&displayio_colorconverter_get_dither_obj,
(mp_obj_t)&displayio_colorconverter_set_dither_obj,
(mp_obj_t)&mp_const_none_obj},
};
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) },
};
STATIC MP_DEFINE_CONST_DICT(displayio_colorconverter_locals_dict, displayio_colorconverter_locals_dict_table);
@ -90,3 +124,4 @@ const mp_obj_type_t displayio_colorconverter_type = {
.make_new = displayio_colorconverter_make_new,
.locals_dict = (mp_obj_dict_t*)&displayio_colorconverter_locals_dict,
};

View File

@ -33,7 +33,10 @@
extern const mp_obj_type_t displayio_colorconverter_type;
void common_hal_displayio_colorconverter_construct(displayio_colorconverter_t* self);
void common_hal_displayio_colorconverter_construct(displayio_colorconverter_t* self, bool dither);
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);
bool common_hal_displayio_colorconverter_get_dither(displayio_colorconverter_t* self);
#endif // MICROPY_INCLUDED_SHARED_BINDINGS_DISPLAYIO_COLORCONVERTER_H

View File

@ -346,31 +346,7 @@ const mp_obj_property_t displayio_display_auto_brightness_obj = {
(mp_obj_t)&mp_const_none_obj},
};
//| .. attribute:: dither
//|
//| True when the display is dithered
//|
STATIC mp_obj_t displayio_display_obj_get_dither(mp_obj_t self_in) {
displayio_display_obj_t *self = native_display(self_in);
return mp_obj_new_bool(common_hal_displayio_display_get_dither(self));
}
MP_DEFINE_CONST_FUN_OBJ_1(displayio_display_get_dither_obj, displayio_display_obj_get_dither);
STATIC mp_obj_t displayio_display_obj_set_dither(mp_obj_t self_in, mp_obj_t dither) {
displayio_display_obj_t *self = native_display(self_in);
common_hal_displayio_display_set_dither(self, mp_obj_is_true(dither));
return mp_const_none;
}
MP_DEFINE_CONST_FUN_OBJ_2(displayio_display_set_dither_obj, displayio_display_obj_set_dither);
const mp_obj_property_t displayio_display_dither_obj = {
.base.type = &mp_type_property,
.proxy = {(mp_obj_t)&displayio_display_get_dither_obj,
(mp_obj_t)&displayio_display_set_dither_obj,
(mp_obj_t)&mp_const_none_obj},
};
//| .. attribute:: width
@ -514,7 +490,6 @@ STATIC const mp_rom_map_elem_t displayio_display_locals_dict_table[] = {
{ MP_ROM_QSTR(MP_QSTR_brightness), MP_ROM_PTR(&displayio_display_brightness_obj) },
{ MP_ROM_QSTR(MP_QSTR_auto_brightness), MP_ROM_PTR(&displayio_display_auto_brightness_obj) },
{ MP_ROM_QSTR(MP_QSTR_dither), MP_ROM_PTR(&displayio_display_dither_obj) },
{ MP_ROM_QSTR(MP_QSTR_width), MP_ROM_PTR(&displayio_display_width_obj) },
{ MP_ROM_QSTR(MP_QSTR_height), MP_ROM_PTR(&displayio_display_height_obj) },

View File

@ -39,7 +39,8 @@ 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) {
void common_hal_displayio_colorconverter_construct(displayio_colorconverter_t* self, bool dither) {
self->dither = dither;
}
uint16_t displayio_colorconverter_compute_rgb565(uint32_t color_rgb888) {
@ -121,10 +122,18 @@ void common_hal_displayio_colorconverter_convert(displayio_colorconverter_t *sel
(*output_color) = output_pixel.pixel;
}
void common_hal_displayio_colorconverter_set_dither(displayio_colorconverter_t* self, bool dither) {
self->dither = dither;
}
bool common_hal_displayio_colorconverter_get_dither(displayio_colorconverter_t* self) {
return self->dither;
}
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 (colorspace->dither){
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));
uint8_t randb = (displayio_colorconverter_dither_noise_2(input_pixel->tile_x,input_pixel->tile_y+33));
@ -172,6 +181,8 @@ void displayio_colorconverter_convert(displayio_colorconverter_t *self, const _d
output_color->opaque = false;
}
// Currently no refresh logic is needed for a ColorConverter.
bool displayio_colorconverter_needs_refresh(displayio_colorconverter_t *self) {
return false;
@ -179,3 +190,4 @@ bool displayio_colorconverter_needs_refresh(displayio_colorconverter_t *self) {
void displayio_colorconverter_finish_refresh(displayio_colorconverter_t *self) {
}

View File

@ -35,6 +35,7 @@
typedef struct {
mp_obj_base_t base;
bool dither;
} displayio_colorconverter_t;
bool displayio_colorconverter_needs_refresh(displayio_colorconverter_t *self);

View File

@ -150,14 +150,6 @@ void common_hal_displayio_display_set_auto_brightness(displayio_display_obj_t* s
self->auto_brightness = auto_brightness;
}
void common_hal_displayio_display_set_dither(displayio_display_obj_t* self, bool dither) {
displayio_display_core_set_dither(&self->core, dither);
}
bool common_hal_displayio_display_get_dither(displayio_display_obj_t* self) {
return displayio_display_core_get_dither(&self->core);
}
mp_float_t common_hal_displayio_display_get_brightness(displayio_display_obj_t* self) {
return self->current_brightness;
}