Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update for clean blitting into itself #4268

Merged
merged 1 commit into from
Feb 25, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 24 additions & 5 deletions shared-module/displayio/Bitmap.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
Expand Down