From f10be555928dd8a59b7f6348ee08df66efe44cb3 Mon Sep 17 00:00:00 2001 From: Radomir Dopieralski Date: Sun, 11 Mar 2018 12:01:48 +0100 Subject: [PATCH] _stage: use 16 bit for coordinates to support larger screens --- shared-bindings/_stage/__init__.c | 8 ++++---- shared-module/_stage/Layer.c | 2 +- shared-module/_stage/Layer.h | 2 +- shared-module/_stage/Text.c | 2 +- shared-module/_stage/Text.h | 2 +- shared-module/_stage/__init__.c | 9 +++------ shared-module/_stage/__init__.h | 2 +- 7 files changed, 12 insertions(+), 15 deletions(-) diff --git a/shared-bindings/_stage/__init__.c b/shared-bindings/_stage/__init__.c index 16e0b58d94..a0c66cca56 100644 --- a/shared-bindings/_stage/__init__.c +++ b/shared-bindings/_stage/__init__.c @@ -56,10 +56,10 @@ //| This function is intended for internal use in the ``stage`` library //| and all the necessary checks are performed there. STATIC mp_obj_t stage_render(size_t n_args, const mp_obj_t *args) { - uint8_t x0 = mp_obj_get_int(args[0]); - uint8_t y0 = mp_obj_get_int(args[1]); - uint8_t x1 = mp_obj_get_int(args[2]); - uint8_t y1 = mp_obj_get_int(args[3]); + uint16_t x0 = mp_obj_get_int(args[0]); + uint16_t y0 = mp_obj_get_int(args[1]); + uint16_t x1 = mp_obj_get_int(args[2]); + uint16_t y1 = mp_obj_get_int(args[3]); size_t layers_size = 0; mp_obj_t *layers; diff --git a/shared-module/_stage/Layer.c b/shared-module/_stage/Layer.c index 4c9c46d7c6..d958f0d197 100644 --- a/shared-module/_stage/Layer.c +++ b/shared-module/_stage/Layer.c @@ -29,7 +29,7 @@ // Get the color of the pixel on the layer. -uint16_t get_layer_pixel(layer_obj_t *layer, int16_t x, uint16_t y) { +uint16_t get_layer_pixel(layer_obj_t *layer, uint16_t x, uint16_t y) { // Shift by the layer's position offset. x -= layer->x; diff --git a/shared-module/_stage/Layer.h b/shared-module/_stage/Layer.h index c46f71349f..17d101263f 100644 --- a/shared-module/_stage/Layer.h +++ b/shared-module/_stage/Layer.h @@ -43,6 +43,6 @@ typedef struct { uint8_t rotation; } layer_obj_t; -uint16_t get_layer_pixel(layer_obj_t *layer, int16_t x, uint16_t y); +uint16_t get_layer_pixel(layer_obj_t *layer, uint16_t x, uint16_t y); #endif // MICROPY_INCLUDED_SHARED_MODULE__STAGE_LAYER diff --git a/shared-module/_stage/Text.c b/shared-module/_stage/Text.c index 307f9bbfa7..df5bf80080 100644 --- a/shared-module/_stage/Text.c +++ b/shared-module/_stage/Text.c @@ -29,7 +29,7 @@ // Get the color of the pixel on the text. -uint16_t get_text_pixel(text_obj_t *text, int16_t x, uint16_t y) { +uint16_t get_text_pixel(text_obj_t *text, uint16_t x, uint16_t y) { // Shift by the text's position offset. x -= text->x; diff --git a/shared-module/_stage/Text.h b/shared-module/_stage/Text.h index bc111e49c1..b263fc7108 100644 --- a/shared-module/_stage/Text.h +++ b/shared-module/_stage/Text.h @@ -41,6 +41,6 @@ typedef struct { uint8_t width, height; } text_obj_t; -uint16_t get_text_pixel(text_obj_t *text, int16_t x, uint16_t y); +uint16_t get_text_pixel(text_obj_t *text, uint16_t x, uint16_t y); #endif // MICROPY_INCLUDED_SHARED_MODULE__STAGE_TEXT diff --git a/shared-module/_stage/__init__.c b/shared-module/_stage/__init__.c index 1931b89407..86f5ee7957 100644 --- a/shared-module/_stage/__init__.c +++ b/shared-module/_stage/__init__.c @@ -31,17 +31,14 @@ #include "shared-bindings/_stage/Text.h" -bool render_stage(uint8_t x0, uint8_t y0, uint8_t x1, uint8_t y1, +bool render_stage(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, mp_obj_t *layers, size_t layers_size, uint16_t *buffer, size_t buffer_size, busio_spi_obj_t *spi) { - // TODO(deshipu): Do a collision check of each layer with the - // rectangle, and only process the layers that overlap with it. - size_t index = 0; - for (uint8_t y = y0; y < y1; ++y) { - for (uint8_t x = x0; x < x1; ++x) { + for (uint16_t y = y0; y < y1; ++y) { + for (uint16_t x = x0; x < x1; ++x) { for (size_t layer = 0; layer < layers_size; ++layer) { uint16_t c = TRANSPARENT; layer_obj_t *obj = MP_OBJ_TO_PTR(layers[layer]); diff --git a/shared-module/_stage/__init__.h b/shared-module/_stage/__init__.h index 326c725599..d56a26940f 100644 --- a/shared-module/_stage/__init__.h +++ b/shared-module/_stage/__init__.h @@ -34,7 +34,7 @@ #define TRANSPARENT (0x1ff8) -bool render_stage(uint8_t x0, uint8_t y0, uint8_t x1, uint8_t y1, +bool render_stage(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, mp_obj_t *layers, size_t layers_size, uint16_t *buffer, size_t buffer_size, busio_spi_obj_t *spi);