Skip to content

Commit 36dbaf4

Browse files
committed
Add more checks for read-only Bitmaps
Fixes #7768
1 parent e1f1647 commit 36dbaf4

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

shared-module/displayio/Bitmap.c

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,9 @@ void displayio_bitmap_set_dirty_area(displayio_bitmap_t *self, const displayio_a
128128
}
129129

130130
void displayio_bitmap_write_pixel(displayio_bitmap_t *self, int16_t x, int16_t y, uint32_t value) {
131+
if (self->read_only) {
132+
mp_raise_RuntimeError(translate("Read-only"));
133+
}
131134
// Writes the color index value into a pixel position
132135
// Must update the dirty area separately
133136

@@ -160,6 +163,9 @@ void displayio_bitmap_write_pixel(displayio_bitmap_t *self, int16_t x, int16_t y
160163

161164
void common_hal_displayio_bitmap_blit(displayio_bitmap_t *self, int16_t x, int16_t y, displayio_bitmap_t *source,
162165
int16_t x1, int16_t y1, int16_t x2, int16_t y2, uint32_t skip_index, bool skip_index_none) {
166+
if (self->read_only) {
167+
mp_raise_RuntimeError(translate("Read-only"));
168+
}
163169
// Copy region of "source" bitmap into "self" bitmap at location x,y in the "self"
164170
// If skip_value is encountered in the source bitmap, it will not be copied.
165171
// 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
213219
}
214220

215221
void common_hal_displayio_bitmap_set_pixel(displayio_bitmap_t *self, int16_t x, int16_t y, uint32_t value) {
222+
if (self->read_only) {
223+
mp_raise_RuntimeError(translate("Read-only"));
224+
}
216225
// update the dirty region
217226
displayio_area_t a = {x, y, x + 1, y + 1, NULL};
218227
displayio_bitmap_set_dirty_area(self, &a);
@@ -223,19 +232,25 @@ void common_hal_displayio_bitmap_set_pixel(displayio_bitmap_t *self, int16_t x,
223232
}
224233

225234
displayio_area_t *displayio_bitmap_get_refresh_areas(displayio_bitmap_t *self, displayio_area_t *tail) {
226-
if (self->dirty_area.x1 == self->dirty_area.x2) {
235+
if (self->dirty_area.x1 == self->dirty_area.x2 || self->read_only) {
227236
return tail;
228237
}
229238
self->dirty_area.next = tail;
230239
return &self->dirty_area;
231240
}
232241

233242
void displayio_bitmap_finish_refresh(displayio_bitmap_t *self) {
243+
if (self->read_only) {
244+
return;
245+
}
234246
self->dirty_area.x1 = 0;
235247
self->dirty_area.x2 = 0;
236248
}
237249

238250
void common_hal_displayio_bitmap_fill(displayio_bitmap_t *self, uint32_t value) {
251+
if (self->read_only) {
252+
mp_raise_RuntimeError(translate("Read-only"));
253+
}
239254
displayio_area_t a = {0, 0, self->width, self->height, NULL};
240255
displayio_bitmap_set_dirty_area(self, &a);
241256

0 commit comments

Comments
 (0)