diff options
| author | Scott Shawcroft <scott@tannewt.org> | 2020-08-24 18:25:18 -0700 |
|---|---|---|
| committer | Scott Shawcroft <scott@tannewt.org> | 2020-08-24 18:25:18 -0700 |
| commit | 1527a3ce921874c78def10d0d400bc58f5324d43 (patch) | |
| tree | 118e246cd9530506be655e33f82e97cd67f5351a /shared-module | |
| parent | 9a8b4e98bf0880a5ca703077faa0028c28f17ebb (diff) | |
| parent | 5b1a1c773f612be5f27e933f7bf520bc654f7613 (diff) | |
Merge remote-tracking branch 'adafruit/main' into add_pwmio
Diffstat (limited to 'shared-module')
| -rw-r--r-- | shared-module/displayio/Bitmap.c | 26 | ||||
| -rw-r--r-- | shared-module/displayio/__init__.c | 4 |
2 files changed, 28 insertions, 2 deletions
diff --git a/shared-module/displayio/Bitmap.c b/shared-module/displayio/Bitmap.c index 8bcda6086..d1942efc7 100644 --- a/shared-module/displayio/Bitmap.c +++ b/shared-module/displayio/Bitmap.c @@ -105,6 +105,32 @@ uint32_t common_hal_displayio_bitmap_get_pixel(displayio_bitmap_t *self, int16_t return 0; } +void common_hal_displayio_bitmap_blit(displayio_bitmap_t *self, int16_t x, int16_t y, displayio_bitmap_t *source, + int16_t x1, int16_t y1, int16_t x2, int16_t y2, uint32_t skip_index, bool skip_index_none) { + // Copy complete "source" bitmap into "self" bitmap at location x,y in the "self" + // Add a boolean to determine if all values are copied, or only if non-zero + // If skip_value is encountered in the source bitmap, it will not be copied. + // If skip_value is `None`, then all pixels are copied. + + if (self->read_only) { + mp_raise_RuntimeError(translate("Read-only object")); + } + + // simplest version - use internal functions for get/set pixels + for (int16_t i=0; i < (x2-x1) ; i++) { + if ( (x+i >= 0) && (x+i < self->width) ) { + for (int16_t j=0; j < (y2-y1) ; j++){ + if ((y+j >= 0) && (y+j < self->height) ) { + uint32_t value = common_hal_displayio_bitmap_get_pixel(source, x1+i, y1+j); + if ( (skip_index_none) || (value != skip_index) ) { // write if skip_value_none is True + common_hal_displayio_bitmap_set_pixel(self, x+i, y+j, value); + } + } + } + } + } +} + void common_hal_displayio_bitmap_set_pixel(displayio_bitmap_t *self, int16_t x, int16_t y, uint32_t value) { if (self->read_only) { mp_raise_RuntimeError(translate("Read-only object")); diff --git a/shared-module/displayio/__init__.c b/shared-module/displayio/__init__.c index 4a6428ea0..101dac4b3 100644 --- a/shared-module/displayio/__init__.c +++ b/shared-module/displayio/__init__.c @@ -394,8 +394,8 @@ primary_display_t *allocate_display_or_raise(void) { } primary_display_t *allocate_display_bus(void) { for (uint8_t i = 0; i < CIRCUITPY_DISPLAY_LIMIT; i++) { - mp_const_obj_t display_type = displays[i].display.base.type; - if (display_type == NULL || display_type == &mp_type_NoneType) { + mp_const_obj_t display_bus_type = displays[i].bus_base.type; + if (display_bus_type == NULL || display_bus_type == &mp_type_NoneType) { return &displays[i]; } } |
