|
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, tilegrid: TileGrid |
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 | 31 | //| :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.""" |
| 32 | +//| :param TileGrid tilegrid: The tilegrid to use with the TilePaletteMapper |
33 | 33 | //|
|
34 | 34 |
|
35 | 35 | 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 }; |
| 36 | + enum { ARG_pixel_shader, ARG_input_color_count, ARG_tilegrid }; |
37 | 37 | static const mp_arg_t allowed_args[] = {
|
38 | 38 | { MP_QSTR_pixel_shader, MP_ARG_OBJ | MP_ARG_REQUIRED },
|
39 | 39 | { 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 }, |
| 40 | + { MP_QSTR_tilegrid, MP_ARG_OBJ | MP_ARG_REQUIRED }, |
| 41 | + |
42 | 42 | };
|
43 | 43 | mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)];
|
44 | 44 | mp_arg_parse_all_kw_array(n_args, n_kw, all_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args);
|
45 | 45 | mp_obj_t pixel_shader = args[ARG_pixel_shader].u_obj;
|
46 | 46 | if (!mp_obj_is_type(pixel_shader, &displayio_palette_type) && !mp_obj_is_type(pixel_shader, &displayio_colorconverter_type)) {
|
47 | 47 | mp_raise_TypeError_varg(MP_ERROR_TEXT("unsupported %q type"), MP_QSTR_pixel_shader);
|
48 | 48 | }
|
| 49 | + |
| 50 | + mp_obj_t tilegrid = args[ARG_tilegrid].u_obj; |
| 51 | + if (!mp_obj_is_type(tilegrid, &displayio_tilegrid_type)) { |
| 52 | + mp_raise_TypeError_varg(MP_ERROR_TEXT("unsupported %q type"), MP_QSTR_tilegrid); |
| 53 | + } |
| 54 | + |
49 | 55 | 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); |
| 56 | + common_hal_tilepalettemapper_tilepalettemapper_construct(self, pixel_shader, args[ARG_input_color_count].u_int, tilegrid); |
51 | 57 |
|
52 | 58 | return MP_OBJ_FROM_PTR(self);
|
53 | 59 | }
|
@@ -87,6 +93,17 @@ MP_DEFINE_CONST_FUN_OBJ_1(tilepalettemapper_tilepalettemapper_get_pixel_shader_o
|
87 | 93 | MP_PROPERTY_GETTER(tilepalettemapper_tilepalettemapper_palette_obj,
|
88 | 94 | (mp_obj_t)&tilepalettemapper_tilepalettemapper_get_pixel_shader_obj);
|
89 | 95 |
|
| 96 | +//| tilegrid: displayio.TileGrid |
| 97 | +//| """The tilegrid that the TilePaletteMapper is used on.""" |
| 98 | +//| |
| 99 | +static mp_obj_t tilepalettemapper_tilepalettemapper_obj_get_tilegrid(mp_obj_t self_in) { |
| 100 | + tilepalettemapper_tilepalettemapper_t *self = MP_OBJ_TO_PTR(self_in); |
| 101 | + return common_hal_tilepalettemapper_tilepalettemapper_get_tilegrid(self); |
| 102 | +} |
| 103 | +MP_DEFINE_CONST_FUN_OBJ_1(tilepalettemapper_tilepalettemapper_get_tilegrid_obj, tilepalettemapper_tilepalettemapper_obj_get_tilegrid); |
| 104 | + |
| 105 | +MP_PROPERTY_GETTER(tilepalettemapper_tilepalettemapper_tilegrid_obj, |
| 106 | + (mp_obj_t)&tilepalettemapper_tilepalettemapper_get_tilegrid_obj); |
90 | 107 |
|
91 | 108 | //| def __getitem__(self, index: Union[Tuple[int, int], int]) -> Tuple[int]:
|
92 | 109 | //| """Returns the mapping for the given index. The index can either be an x,y tuple or an int equal
|
|
0 commit comments