diff options
| author | Mark <56205165+gamblor21@users.noreply.github.com> | 2021-03-02 19:47:53 -0600 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-03-02 19:47:53 -0600 |
| commit | 37ee18349f99ffafd7b60db8a107cd6f1e9e3f92 (patch) | |
| tree | 5db36911199729499d91d0c317957cfff0b71013 /shared-module/displayio/Bitmap.c | |
| parent | 4246cc3f6d718e2f28fbeb73fc8c3c39dfb9d7f0 (diff) | |
| parent | efc2667b5f087480b1b3233ae00ab1529a442f9f (diff) | |
Merge branch 'main' into rp2040_countio
Diffstat (limited to 'shared-module/displayio/Bitmap.c')
| -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..c9ea83428 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) - i - 1) : x1+i; // x-index into the source bitmap + const int xd_index = x_reverse ? ((x + (x2-x1)) - i - 1) : 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 ) - j - 1) : y1+j ; // y-index into the source bitmap + const int yd_index = y_reverse ? ((y + (y2-y1)) - j - 1) : 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); } } } |
