summaryrefslogtreecommitdiff
path: root/shared-module
diff options
context:
space:
mode:
authorJeff Epler <jepler@gmail.com>2021-03-18 09:20:21 -0500
committerJeff Epler <jepler@gmail.com>2021-03-18 09:20:56 -0500
commitf5fd42c39340483bc781746fd0acd304abd888ae (patch)
tree4eb089a3cc553a025292018fdfe3dcfa9d410ca2 /shared-module
parent36d608aa67229653c0be12fab407533d0d8b7d32 (diff)
displayio: Move bitmap read-only checking to displayio_bitmap_set_dirty_area
This is a modest code savings, but more importantly it reduces boilerplate in bitmap-modifying routines. Callers need only ensure they call displayio_bitmap_set_dirty_area in advance of the bitmap modifications they perform. (note that this assumes that no bitmap operation can enter background tasks. If an operation COULD enter background tasks, it MUST re-dirty the area it touches when it exits, simply by a fresh call to set_dirty_area with the same area as before)
Diffstat (limited to 'shared-module')
-rw-r--r--shared-module/bitmaptools/__init__.c23
-rw-r--r--shared-module/displayio/Bitmap.c22
2 files changed, 11 insertions, 34 deletions
diff --git a/shared-module/bitmaptools/__init__.c b/shared-module/bitmaptools/__init__.c
index 604c1a16a..1c7f36ca2 100644
--- a/shared-module/bitmaptools/__init__.c
+++ b/shared-module/bitmaptools/__init__.c
@@ -95,10 +95,6 @@ void common_hal_bitmaptools_rotozoom(displayio_bitmap_t *self, int16_t ox, int16
// # */
- if (self->read_only) {
- mp_raise_RuntimeError(translate("Read-only object"));
- }
-
int16_t x,y;
int16_t minx = dest_clip1_x;
@@ -199,6 +195,9 @@ void common_hal_bitmaptools_rotozoom(displayio_bitmap_t *self, int16_t ox, int16
float rowu = startu + miny * duCol;
float rowv = startv + miny * dvCol;
+ displayio_area_t dirty_area = {minx, miny, maxx, maxy};
+ displayio_bitmap_set_dirty_area(self, &dirty_area);
+
for (y = miny; y <= maxy; y++) {
float u = rowu + minx * duRow;
float v = rowv + minx * dvRow;
@@ -236,10 +235,6 @@ void common_hal_bitmaptools_fill_region(displayio_bitmap_t *destination,
//
// input checks should ensure that x1 < x2 and y1 < y2 and are within the bitmap region
- if (destination->read_only) {
- mp_raise_RuntimeError(translate("Read-only object"));
- }
-
displayio_area_t area = { x1, y1, x2, y2 };
displayio_area_canon(&area);
@@ -262,10 +257,6 @@ void common_hal_bitmaptools_draw_line(displayio_bitmap_t *destination,
int16_t x1, int16_t y1,
uint32_t value) {
- if (destination->read_only) {
- mp_raise_RuntimeError(translate("Read-only object"));
- }
-
//
// adapted from Adafruit_CircuitPython_Display_Shapes.Polygon._line
//
@@ -394,9 +385,8 @@ void common_hal_bitmaptools_arrayblit(displayio_bitmap_t *self, void *data, int
void common_hal_bitmaptools_readinto(displayio_bitmap_t *self, pyb_file_obj_t *file, int element_size, int bits_per_pixel, bool reverse_pixels_in_element, bool swap_bytes) {
uint32_t mask = (1 << common_hal_displayio_bitmap_get_bits_per_value(self)) - 1;
- if (self->read_only) {
- mp_raise_RuntimeError(translate("Read-only object"));
- }
+ displayio_area_t a = {0, 0, self->width, self->height};
+ displayio_bitmap_set_dirty_area(self, &a);
size_t elements_per_row = (self->width * bits_per_pixel + element_size * 8 - 1) / (element_size * 8);
size_t rowsize = element_size * elements_per_row;
@@ -472,7 +462,4 @@ void common_hal_bitmaptools_readinto(displayio_bitmap_t *self, pyb_file_obj_t *f
displayio_bitmap_write_pixel(self, x, y, value & mask);
}
}
-
- displayio_area_t a = {0, 0, self->width, self->height};
- displayio_bitmap_set_dirty_area(self, &a);
}
diff --git a/shared-module/displayio/Bitmap.c b/shared-module/displayio/Bitmap.c
index d93338dc4..7b916bb36 100644
--- a/shared-module/displayio/Bitmap.c
+++ b/shared-module/displayio/Bitmap.c
@@ -106,6 +106,10 @@ uint32_t common_hal_displayio_bitmap_get_pixel(displayio_bitmap_t *self, int16_t
}
void displayio_bitmap_set_dirty_area(displayio_bitmap_t *self, const displayio_area_t *dirty_area) {
+ if (self->read_only) {
+ mp_raise_RuntimeError(translate("Read-only object"));
+ }
+
displayio_area_t area = *dirty_area;
displayio_area_canon(&area);
displayio_area_union(&area, &self->dirty_area, &area);
@@ -146,10 +150,6 @@ void common_hal_displayio_bitmap_blit(displayio_bitmap_t *self, int16_t x, int16
// If skip_value is `None`, then all pixels are copied.
// This function assumes input checks were performed for pixel index entries.
- if (self->read_only) {
- mp_raise_RuntimeError(translate("Read-only object"));
- }
-
// Update the dirty area
int16_t dirty_x_max = (x + (x2 - x1));
if (dirty_x_max > self->width) {
@@ -198,10 +198,6 @@ 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 object"));
- }
-
// update the dirty region
displayio_area_t a = {x, y, x + 1, y + 1};
displayio_bitmap_set_dirty_area(self, &a);
@@ -225,14 +221,8 @@ void displayio_bitmap_finish_refresh(displayio_bitmap_t *self) {
}
void common_hal_displayio_bitmap_fill(displayio_bitmap_t *self, uint32_t value) {
- if (self->read_only) {
- mp_raise_RuntimeError(translate("Read-only object"));
- }
- // Update the dirty area.
- self->dirty_area.x1 = 0;
- self->dirty_area.x2 = self->width;
- self->dirty_area.y1 = 0;
- self->dirty_area.y2 = self->height;
+ displayio_area_t a = {0, 0, self->width, self->height};
+ displayio_bitmap_set_dirty_area(self, &a);
// build the packed word
uint32_t word = 0;