diff options
| author | Margaret Matocha <ksmatocha@gmail.com> | 2020-08-07 15:59:42 -0500 |
|---|---|---|
| committer | Margaret Matocha <ksmatocha@gmail.com> | 2020-08-07 15:59:42 -0500 |
| commit | b6008d0032a49e6b5c332576fa2f141d353b9fd3 (patch) | |
| tree | f6f15b4fe8893d43d82606c02b9ae25ee9adb741 | |
| parent | 64c9baa6aa6203e21ff0420ce5a9889f44422334 (diff) | |
Adding bitmap.insert to copy a slice of a source bitmap into another bitmap
| -rw-r--r-- | shared-module/displayio/Bitmap.c | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/shared-module/displayio/Bitmap.c b/shared-module/displayio/Bitmap.c index ab6e4f5dd..75f352b30 100644 --- a/shared-module/displayio/Bitmap.c +++ b/shared-module/displayio/Bitmap.c @@ -115,6 +115,10 @@ void common_hal_displayio_bitmap_insert(displayio_bitmap_t *self, int16_t x, int mp_raise_RuntimeError(translate("Read-only object")); } + // If this value is encountered in the source bitmap, it will not be copied (for text glyphs) + // This should be added as an optional parameter, and if it is `None`, then all pixels are copied + uint32_t skip_value=0; + //// check for zero width, this would be a single pixel // if (x1_source == x2_source) || (y1_source == y2_source) { // return 0 @@ -140,9 +144,11 @@ void common_hal_displayio_bitmap_insert(displayio_bitmap_t *self, int16_t x, int // simplest version - use internal functions for get/set pixels for (uint16_t i=0; i<= (x2-x1) ; i++) { for (uint16_t j=0; j<= (y2-y1) ; j++){ - uint16_t value = common_hal_displayio_bitmap_get_pixel(source, x1+i, y1+j); - if ( (x+i >= 0) && (y+j >= 0) && (x+i <= self->width-1) && (y+j <= self->height-1) ){ - common_hal_displayio_bitmap_set_pixel(self, x+i, y+j, value); + uint32_t value = common_hal_displayio_bitmap_get_pixel(source, x1+i, y1+j); + if (value != skip_value) { + if ( (x+i >= 0) && (y+j >= 0) && (x+i <= self->width-1) && (y+j <= self->height-1) ){ + common_hal_displayio_bitmap_set_pixel(self, x+i, y+j, value); + } } } } |
