diff options
| author | Scott Shawcroft <scott@adafruit.com> | 2021-02-25 14:15:25 -0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-02-25 14:15:25 -0800 |
| commit | b69cb0144ca0d54011be540213d1e25e673a63de (patch) | |
| tree | 39dfb8fec410ad987c9558e47e9e62cd67ea3897 /shared-module/displayio | |
| parent | 94d7bfb1c93503fc11b4b29ea08ded07c1e4795e (diff) | |
| parent | 4097c949a33e53e378cecb1b50fb455f6f209bfb (diff) | |
Merge pull request #4268 from kmatch98/blit_self
Update for clean blitting into itself
Diffstat (limited to 'shared-module/displayio')
| -rw-r--r-- | shared-module/displayio/Bitmap.c | 29 |
1 files changed, 24 insertions, 5 deletions
diff --git a/shared-module/displayio/Bitmap.c b/shared-module/displayio/Bitmap.c index d1942efc7..cf34f2d35 100644 --- a/shared-module/displayio/Bitmap.c +++ b/shared-module/displayio/Bitmap.c @@ -116,14 +116,33 @@ void common_hal_displayio_bitmap_blit(displayio_bitmap_t *self, int16_t x, int16 mp_raise_RuntimeError(translate("Read-only object")); } + bool x_reverse = false; + bool y_reverse = false; + + // Add reverse direction option to protect blitting of self bitmap back into self bitmap + if (x > x1) { + x_reverse = true; + } + if (y > y1) { + y_reverse = true; + } + // 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 i=0; i < (x2-x1); i++) { + + const int xs_index = x_reverse ? ( (x2 - 1) - i ) : x1+i; // x-index into the source bitmap + const int xd_index = x_reverse ? ((x + (x2-x1)) - i ) : x+i; // x-index into the destination bitmap + + if ( (xd_index >= 0) && (xd_index < 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); + + const int ys_index = y_reverse ? ( (y2 - 1) - j ) : y1+j ; // y-index into the source bitmap + const int yd_index = y_reverse ? ((y + (y2-y1)) - j ) : y+j ; // y-index into the destination bitmap + + if ((yd_index >= 0) && (yd_index < self->height) ) { + uint32_t value = common_hal_displayio_bitmap_get_pixel(source, xs_index, ys_index); 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); + common_hal_displayio_bitmap_set_pixel(self, xd_index, yd_index, value); } } } |
