|
12 | 12 | #include "shared-bindings/util.h" |
13 | 13 | #include "shared-bindings/displayio/Palette.h" |
14 | 14 | #include "shared-bindings/displayio/ColorConverter.h" |
| 15 | +#include "shared-bindings/displayio/TileGrid.h" |
15 | 16 | #include "shared-bindings/tilepalettemapper/TilePaletteMapper.h" |
16 | 17 |
|
17 | 18 | //| class TilePaletteMapper: |
|
21 | 22 | //| bitmap with a wider array of colors.""" |
22 | 23 | //| |
23 | 24 | //| def __init__( |
24 | | -//| self, palette: displayio.Palette, input_color_count: int, width: int, height: int |
| 25 | +//| self, palette: displayio.Palette, input_color_count: int |
25 | 26 | //| ) -> None: |
26 | 27 | //| """Create a TilePaletteMApper object to store a set of color mappings for tiles. |
27 | 28 | //| |
28 | 29 | //| :param Union[displayio.Palette, displayio.ColorConverter] pixel_shader: |
29 | 30 | //| The palette or ColorConverter to get mapped colors from. |
30 | | -//| :param int input_color_count: The number of colors in in the input bitmap. |
31 | | -//| :param int width: The width of the grid in tiles. |
32 | | -//| :param int height: The height of the grid in tiles.""" |
| 31 | +//| :param int input_color_count: The number of colors in in the input bitmap.""" |
33 | 32 | //| |
34 | 33 |
|
35 | 34 | static mp_obj_t tilepalettemapper_tilepalettemapper_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) { |
36 | | - enum { ARG_pixel_shader, ARG_input_color_count, ARG_width, ARG_height }; |
| 35 | + enum { ARG_pixel_shader, ARG_input_color_count }; |
37 | 36 | static const mp_arg_t allowed_args[] = { |
38 | 37 | { MP_QSTR_pixel_shader, MP_ARG_OBJ | MP_ARG_REQUIRED }, |
39 | 38 | { MP_QSTR_input_color_count, MP_ARG_INT | MP_ARG_REQUIRED }, |
40 | | - { MP_QSTR_width, MP_ARG_INT | MP_ARG_REQUIRED }, |
41 | | - { MP_QSTR_height, MP_ARG_INT | MP_ARG_REQUIRED }, |
| 39 | + |
42 | 40 | }; |
43 | 41 | mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; |
44 | 42 | mp_arg_parse_all_kw_array(n_args, n_kw, all_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); |
45 | 43 | mp_obj_t pixel_shader = args[ARG_pixel_shader].u_obj; |
46 | 44 | if (!mp_obj_is_type(pixel_shader, &displayio_palette_type) && !mp_obj_is_type(pixel_shader, &displayio_colorconverter_type)) { |
47 | 45 | mp_raise_TypeError_varg(MP_ERROR_TEXT("unsupported %q type"), MP_QSTR_pixel_shader); |
48 | 46 | } |
| 47 | + |
| 48 | + |
49 | 49 | tilepalettemapper_tilepalettemapper_t *self = mp_obj_malloc(tilepalettemapper_tilepalettemapper_t, &tilepalettemapper_tilepalettemapper_type); |
50 | | - common_hal_tilepalettemapper_tilepalettemapper_construct(self, pixel_shader, args[ARG_input_color_count].u_int, args[ARG_width].u_int, args[ARG_height].u_int); |
| 50 | + common_hal_tilepalettemapper_tilepalettemapper_construct(self, pixel_shader, args[ARG_input_color_count].u_int); |
51 | 51 |
|
52 | 52 | return MP_OBJ_FROM_PTR(self); |
53 | 53 | } |
@@ -84,9 +84,20 @@ static mp_obj_t tilepalettemapper_tilepalettemapper_obj_get_pixel_shader(mp_obj_ |
84 | 84 | } |
85 | 85 | MP_DEFINE_CONST_FUN_OBJ_1(tilepalettemapper_tilepalettemapper_get_pixel_shader_obj, tilepalettemapper_tilepalettemapper_obj_get_pixel_shader); |
86 | 86 |
|
87 | | -MP_PROPERTY_GETTER(tilepalettemapper_tilepalettemapper_palette_obj, |
| 87 | +MP_PROPERTY_GETTER(tilepalettemapper_tilepalettemapper_pixel_shader_obj, |
88 | 88 | (mp_obj_t)&tilepalettemapper_tilepalettemapper_get_pixel_shader_obj); |
89 | 89 |
|
| 90 | +//| tilegrid: displayio.TileGrid |
| 91 | +//| """The TileGrid that the TilePaletteMapper is used with.""" |
| 92 | +//| |
| 93 | +static mp_obj_t tilepalettemapper_tilepalettemapper_obj_get_tilegrid(mp_obj_t self_in) { |
| 94 | + tilepalettemapper_tilepalettemapper_t *self = MP_OBJ_TO_PTR(self_in); |
| 95 | + return common_hal_tilepalettemapper_tilepalettemapper_get_tilegrid(self); |
| 96 | +} |
| 97 | +MP_DEFINE_CONST_FUN_OBJ_1(tilepalettemapper_tilepalettemapper_get_tilegrid_obj, tilepalettemapper_tilepalettemapper_obj_get_tilegrid); |
| 98 | + |
| 99 | +MP_PROPERTY_GETTER(tilepalettemapper_tilepalettemapper_tilegrid_obj, |
| 100 | + (mp_obj_t)&tilepalettemapper_tilepalettemapper_get_tilegrid_obj); |
90 | 101 |
|
91 | 102 | //| def __getitem__(self, index: Union[Tuple[int, int], int]) -> Tuple[int]: |
92 | 103 | //| """Returns the mapping for the given index. The index can either be an x,y tuple or an int equal |
@@ -154,7 +165,8 @@ static mp_obj_t tilepalettemapper_subscr(mp_obj_t self_in, mp_obj_t index_obj, m |
154 | 165 | static const mp_rom_map_elem_t tilepalettemapper_tilepalettemapper_locals_dict_table[] = { |
155 | 166 | { MP_ROM_QSTR(MP_QSTR_width), MP_ROM_PTR(&tilepalettemapper_tilepalettemapper_width_obj) }, |
156 | 167 | { MP_ROM_QSTR(MP_QSTR_height), MP_ROM_PTR(&tilepalettemapper_tilepalettemapper_height_obj) }, |
157 | | - { MP_ROM_QSTR(MP_QSTR_palette), MP_ROM_PTR(&tilepalettemapper_tilepalettemapper_palette_obj) }, |
| 168 | + { MP_ROM_QSTR(MP_QSTR_pixel_shader), MP_ROM_PTR(&tilepalettemapper_tilepalettemapper_pixel_shader_obj) }, |
| 169 | + { MP_ROM_QSTR(MP_QSTR_tilegrid), MP_ROM_PTR(&tilepalettemapper_tilepalettemapper_tilegrid_obj) }, |
158 | 170 | }; |
159 | 171 | static MP_DEFINE_CONST_DICT(tilepalettemapper_tilepalettemapper_locals_dict, tilepalettemapper_tilepalettemapper_locals_dict_table); |
160 | 172 |
|
|
0 commit comments