5151// TODO(tannewt): Add support for other color formats.
5252//|
5353STATIC 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 ) {
54- mp_arg_check_num (n_args , kw_args , 0 , 0 , false);
54+ mp_arg_check_num (n_args , kw_args , 0 , 1 , false);
5555
5656 displayio_colorconverter_t * self = m_new_obj (displayio_colorconverter_t );
5757 self -> base .type = & displayio_colorconverter_type ;
58- common_hal_displayio_colorconverter_construct (self );
58+
59+ bool dither = false;
60+
61+ if (n_args > 0 ) {
62+ dither = mp_obj_is_true (pos_args [0 ]);
63+ }
64+
65+ common_hal_displayio_colorconverter_construct (self , dither );
5966
6067 return MP_OBJ_FROM_PTR (self );
6168}
@@ -79,8 +86,35 @@ STATIC mp_obj_t displayio_colorconverter_obj_convert(mp_obj_t self_in, mp_obj_t
7986}
8087MP_DEFINE_CONST_FUN_OBJ_2 (displayio_colorconverter_convert_obj , displayio_colorconverter_obj_convert );
8188
89+ //| .. attribute:: dither
90+ //|
91+ //| True when the display is dithered
92+ //|
93+ STATIC mp_obj_t displayio_colorconverter_obj_get_dither (mp_obj_t self_in ) {
94+ displayio_colorconverter_t * self = MP_OBJ_TO_PTR (self_in );
95+ return mp_obj_new_bool (common_hal_displayio_colorconverter_get_dither (self ));
96+ }
97+ MP_DEFINE_CONST_FUN_OBJ_1 (displayio_colorconverter_get_dither_obj , displayio_colorconverter_obj_get_dither );
98+
99+ STATIC mp_obj_t displayio_colorconverter_obj_set_dither (mp_obj_t self_in , mp_obj_t dither ) {
100+ displayio_colorconverter_t * self = MP_OBJ_TO_PTR (self_in );
101+
102+ common_hal_displayio_colorconverter_set_dither (self , mp_obj_is_true (dither ));
103+
104+ return mp_const_none ;
105+ }
106+ MP_DEFINE_CONST_FUN_OBJ_2 (displayio_colorconverter_set_dither_obj , displayio_colorconverter_obj_set_dither );
107+
108+ const mp_obj_property_t displayio_colorconverter_dither_obj = {
109+ .base .type = & mp_type_property ,
110+ .proxy = {(mp_obj_t )& displayio_colorconverter_get_dither_obj ,
111+ (mp_obj_t )& displayio_colorconverter_set_dither_obj ,
112+ (mp_obj_t )& mp_const_none_obj },
113+ };
114+
82115STATIC const mp_rom_map_elem_t displayio_colorconverter_locals_dict_table [] = {
83116 { MP_ROM_QSTR (MP_QSTR_convert ), MP_ROM_PTR (& displayio_colorconverter_convert_obj ) },
117+ { MP_ROM_QSTR (MP_QSTR_dither ), MP_ROM_PTR (& displayio_colorconverter_dither_obj ) },
84118};
85119STATIC MP_DEFINE_CONST_DICT (displayio_colorconverter_locals_dict , displayio_colorconverter_locals_dict_table );
86120
@@ -90,3 +124,4 @@ const mp_obj_type_t displayio_colorconverter_type = {
90124 .make_new = displayio_colorconverter_make_new ,
91125 .locals_dict = (mp_obj_dict_t * )& displayio_colorconverter_locals_dict ,
92126};
127+
0 commit comments