summaryrefslogtreecommitdiff
path: root/shared-module
diff options
context:
space:
mode:
authorScott Shawcroft <scott@adafruit.com>2020-04-14 12:54:44 -0700
committerGitHub <noreply@github.com>2020-04-14 12:54:44 -0700
commite063b066f0e1bc1dfbdbb354ec2cb01a548bea8b (patch)
tree3acf97c6818713badb0dabdf8129120d354f4f5d /shared-module
parent1f17bdb4ff6e6f5a1f1ff59245edbaa64c0d8c7c (diff)
parenta9fb34eb93ff19df1bcf6498d492a31fd00c2c96 (diff)
Merge pull request #2756 from caternuson/bitmap_fill
Add fill method to displayio.Bitmap
Diffstat (limited to 'shared-module')
-rw-r--r--shared-module/displayio/Bitmap.c21
1 files changed, 21 insertions, 0 deletions
diff --git a/shared-module/displayio/Bitmap.c b/shared-module/displayio/Bitmap.c
index 59971d25c..8bcda6086 100644
--- a/shared-module/displayio/Bitmap.c
+++ b/shared-module/displayio/Bitmap.c
@@ -162,3 +162,24 @@ void displayio_bitmap_finish_refresh(displayio_bitmap_t *self) {
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 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;
+
+ // build the packed word
+ uint32_t word = 0;
+ for (uint8_t i=0; i<32 / self->bits_per_value; i++) {
+ word |= (value & self->bitmask) << (32 - ((i+1)*self->bits_per_value));
+ }
+ // copy it in
+ for (uint32_t i=0; i<self->stride * self->height; i++) {
+ self->data[i] = word;
+ }
+}