Add more checks for read-only Bitmaps

Fixes #7768
This commit is contained in:
Scott Shawcroft 2023-03-22 10:14:34 -07:00
parent e1f16472c1
commit 36dbaf4ccc
No known key found for this signature in database
GPG Key ID: 0DFD512649C052DA
1 changed files with 16 additions and 1 deletions

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) {
if (self->read_only) {
mp_raise_RuntimeError(translate("Read-only"));
}
// Writes the color index value into a pixel position
// 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,
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"
// If skip_value is encountered in the source bitmap, it will not be 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) {
if (self->read_only) {
mp_raise_RuntimeError(translate("Read-only"));
}
// update the dirty region
displayio_area_t a = {x, y, x + 1, y + 1, NULL};
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) {
if (self->dirty_area.x1 == self->dirty_area.x2) {
if (self->dirty_area.x1 == self->dirty_area.x2 || self->read_only) {
return 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) {
if (self->read_only) {
return;
}
self->dirty_area.x1 = 0;
self->dirty_area.x2 = 0;
}
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_bitmap_set_dirty_area(self, &a);