|
11 | 11 | #include "shared-bindings/displayio/TileGrid.h"
|
12 | 12 |
|
13 | 13 | void common_hal_tilepalettemapper_tilepalettemapper_construct(tilepalettemapper_tilepalettemapper_t *self,
|
14 |
| - mp_obj_t pixel_shader, uint16_t input_color_count, mp_obj_t tilegrid) { |
15 |
| - self->tilegrid = tilegrid; |
| 14 | + mp_obj_t pixel_shader, uint16_t input_color_count) { |
16 | 15 | self->pixel_shader = pixel_shader;
|
17 |
| - self->width_in_tiles = common_hal_displayio_tilegrid_get_width(tilegrid); |
18 |
| - self->height_in_tiles = common_hal_displayio_tilegrid_get_height(tilegrid); |
19 | 16 | self->input_color_count = input_color_count;
|
20 |
| - int mappings_len = self->width_in_tiles * self->height_in_tiles; |
21 |
| - self->tile_mappings = (uint32_t **)m_malloc(mappings_len * sizeof(uint32_t *)); |
22 |
| - for (int i = 0; i < mappings_len; i++) { |
23 |
| - self->tile_mappings[i] = (uint32_t *)m_malloc_without_collect(input_color_count * sizeof(uint32_t)); |
24 |
| - if (mp_obj_is_type(self->pixel_shader, &displayio_palette_type)) { |
25 |
| - for (uint16_t j = 0; j < input_color_count; j++) { |
26 |
| - self->tile_mappings[i][j] = j; |
27 |
| - } |
28 |
| - } else if (mp_obj_is_type(self->pixel_shader, &displayio_colorconverter_type)) { |
29 |
| - for (uint16_t j = 0; j < input_color_count; j++) { |
30 |
| - self->tile_mappings[i][j] = 0; |
31 |
| - } |
32 |
| - } |
33 |
| - } |
34 |
| - common_hal_displayio_tilegrid_set_pixel_shader(self->tilegrid, self); |
35 | 17 | }
|
36 | 18 |
|
37 | 19 | uint16_t common_hal_tilepalettemapper_tilepalettemapper_get_width(tilepalettemapper_tilepalettemapper_t *self) {
|
@@ -95,3 +77,24 @@ void tilepalettemapper_tilepalettemapper_get_color(tilepalettemapper_tilepalette
|
95 | 77 | }
|
96 | 78 |
|
97 | 79 | }
|
| 80 | + |
| 81 | +void tilepalettemapper_tilepalettemapper_bind(tilepalettemapper_tilepalettemapper_t *self, displayio_tilegrid_t *tilegrid) { |
| 82 | + self->tilegrid = tilegrid; |
| 83 | + self->width_in_tiles = common_hal_displayio_tilegrid_get_width(tilegrid); |
| 84 | + self->height_in_tiles = common_hal_displayio_tilegrid_get_height(tilegrid); |
| 85 | + |
| 86 | + int mappings_len = self->width_in_tiles * self->height_in_tiles; |
| 87 | + self->tile_mappings = (uint32_t **)m_malloc(mappings_len * sizeof(uint32_t *)); |
| 88 | + for (int i = 0; i < mappings_len; i++) { |
| 89 | + self->tile_mappings[i] = (uint32_t *)m_malloc_without_collect(self->input_color_count * sizeof(uint32_t)); |
| 90 | + if (mp_obj_is_type(self->pixel_shader, &displayio_palette_type)) { |
| 91 | + for (uint16_t j = 0; j < self->input_color_count; j++) { |
| 92 | + self->tile_mappings[i][j] = j; |
| 93 | + } |
| 94 | + } else if (mp_obj_is_type(self->pixel_shader, &displayio_colorconverter_type)) { |
| 95 | + for (uint16_t j = 0; j < self->input_color_count; j++) { |
| 96 | + self->tile_mappings[i][j] = 0; |
| 97 | + } |
| 98 | + } |
| 99 | + } |
| 100 | +} |
0 commit comments