Merge pull request #7775 from tannewt/fix_pyportal

Add more checks for read-only Bitmaps
This commit is contained in:
Dan Halbert 2023-03-22 20:16:43 -04:00 committed by GitHub
commit 05e783cbbd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -128,6 +128,9 @@ void displayio_bitmap_set_dirty_area(displayio_bitmap_t *self, const displayio_a
} }
void displayio_bitmap_write_pixel(displayio_bitmap_t *self, int16_t x, int16_t y, uint32_t value) { void displayio_bitmap_write_pixel(displayio_bitmap_t *self, int16_t x, int16_t y, uint32_t value) {
if (self->read_only) {
mp_raise_RuntimeError(translate("Read-only"));
}
// Writes the color index value into a pixel position // Writes the color index value into a pixel position
// Must update the dirty area separately // Must update the dirty area separately
@ -160,6 +163,9 @@ void displayio_bitmap_write_pixel(displayio_bitmap_t *self, int16_t x, int16_t y
void common_hal_displayio_bitmap_blit(displayio_bitmap_t *self, int16_t x, int16_t y, displayio_bitmap_t *source, 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) { int16_t x1, int16_t y1, int16_t x2, int16_t y2, uint32_t skip_index, bool skip_index_none) {
if (self->read_only) {
mp_raise_RuntimeError(translate("Read-only"));
}
// Copy region of "source" bitmap into "self" bitmap at location x,y in the "self" // Copy region of "source" bitmap into "self" bitmap at location x,y in the "self"
// If skip_value is encountered in the source bitmap, it will not be copied. // 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 skip_value is `None`, then all pixels are copied.
@ -213,6 +219,9 @@ void common_hal_displayio_bitmap_blit(displayio_bitmap_t *self, int16_t x, int16
} }
void common_hal_displayio_bitmap_set_pixel(displayio_bitmap_t *self, int16_t x, int16_t y, uint32_t 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"));
}
// update the dirty region // update the dirty region
displayio_area_t a = {x, y, x + 1, y + 1, NULL}; displayio_area_t a = {x, y, x + 1, y + 1, NULL};
displayio_bitmap_set_dirty_area(self, &a); displayio_bitmap_set_dirty_area(self, &a);
@ -223,7 +232,7 @@ void common_hal_displayio_bitmap_set_pixel(displayio_bitmap_t *self, int16_t x,
} }
displayio_area_t *displayio_bitmap_get_refresh_areas(displayio_bitmap_t *self, displayio_area_t *tail) { displayio_area_t *displayio_bitmap_get_refresh_areas(displayio_bitmap_t *self, displayio_area_t *tail) {
if (self->dirty_area.x1 == self->dirty_area.x2) { if (self->dirty_area.x1 == self->dirty_area.x2 || self->read_only) {
return tail; return tail;
} }
self->dirty_area.next = tail; self->dirty_area.next = tail;
@ -231,11 +240,17 @@ displayio_area_t *displayio_bitmap_get_refresh_areas(displayio_bitmap_t *self, d
} }
void displayio_bitmap_finish_refresh(displayio_bitmap_t *self) { void displayio_bitmap_finish_refresh(displayio_bitmap_t *self) {
if (self->read_only) {
return;
}
self->dirty_area.x1 = 0; self->dirty_area.x1 = 0;
self->dirty_area.x2 = 0; self->dirty_area.x2 = 0;
} }
void common_hal_displayio_bitmap_fill(displayio_bitmap_t *self, uint32_t value) { void common_hal_displayio_bitmap_fill(displayio_bitmap_t *self, uint32_t value) {
if (self->read_only) {
mp_raise_RuntimeError(translate("Read-only"));
}
displayio_area_t a = {0, 0, self->width, self->height, NULL}; displayio_area_t a = {0, 0, self->width, self->height, NULL};
displayio_bitmap_set_dirty_area(self, &a); displayio_bitmap_set_dirty_area(self, &a);