make packed word and copy it in

This commit is contained in:
caternuson 2020-04-13 16:48:27 -07:00
parent dc75746842
commit a9fb34eb93

View File

@ -173,29 +173,13 @@ void common_hal_displayio_bitmap_fill(displayio_bitmap_t *self, uint32_t value)
self->dirty_area.y1 = 0; self->dirty_area.y1 = 0;
self->dirty_area.y2 = self->height; self->dirty_area.y2 = self->height;
// Update our data // build the packed word
int32_t row_start; uint32_t word = 0;
uint32_t bytes_per_value = self->bits_per_value / 8; for (uint8_t i=0; i<32 / self->bits_per_value; i++) {
for (uint32_t x=0; x<self->width; x++) { word |= (value & self->bitmask) << (32 - ((i+1)*self->bits_per_value));
for (uint32_t y=0; y<self->height; y++) {
row_start = y * self->stride;
if (bytes_per_value < 1) {
uint32_t bit_position = (sizeof(size_t) * 8 - ((x & self->x_mask) + 1) * self->bits_per_value);
uint32_t index = row_start + (x >> self->x_shift);
uint32_t word = self->data[index];
word &= ~(self->bitmask << bit_position);
word |= (value & self->bitmask) << bit_position;
self->data[index] = word;
} else {
size_t* row = self->data + row_start;
if (bytes_per_value == 1) {
((uint8_t*) row)[x] = value;
} else if (bytes_per_value == 2) {
((uint16_t*) row)[x] = value;
} else if (bytes_per_value == 4) {
((uint32_t*) row)[x] = value;
}
}
} }
// copy it in
for (uint32_t i=0; i<self->stride * self->height; i++) {
self->data[i] = word;
} }
} }