Skip to content

Commit 8e55232

Browse files
Use kwargs for dither in ColorConverter constructor
1 parent b2fb5ac commit 8e55232

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

shared-bindings/displayio/ColorConverter.c

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -47,22 +47,23 @@
4747
//|
4848
//| Create a ColorConverter object to convert color formats. Only supports RGB888 to RGB565
4949
//| currently.
50-
//|
50+
//| :param bool dither: Adds random noise to dither the output image
51+
5152
// TODO(tannewt): Add support for other color formats.
5253
//|
5354
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) {
54-
mp_arg_check_num(n_args, kw_args, 0, 1, false);
55+
enum { ARG_dither};
56+
57+
static const mp_arg_t allowed_args[] = {
58+
{ MP_QSTR_dither, MP_ARG_KW_ONLY | MP_ARG_BOOL, {.u_bool = true} },
59+
};
60+
mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)];
61+
mp_arg_parse_all(n_args, pos_args, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args);
5562

5663
displayio_colorconverter_t *self = m_new_obj(displayio_colorconverter_t);
5764
self->base.type = &displayio_colorconverter_type;
58-
59-
bool dither = false;
60-
61-
if (n_args > 0) {
62-
dither = mp_obj_is_true(pos_args[0]);
63-
}
6465

65-
common_hal_displayio_colorconverter_construct(self, dither);
66+
common_hal_displayio_colorconverter_construct(self, args[ARG_dither].u_bool);
6667

6768
return MP_OBJ_FROM_PTR(self);
6869
}

0 commit comments

Comments
 (0)