diff options
| author | Scott Shawcroft <scott@tannewt.org> | 2019-02-06 12:13:17 -0800 |
|---|---|---|
| committer | Scott Shawcroft <scott@tannewt.org> | 2019-02-11 20:55:05 -0800 |
| commit | c17f147be95e7490e5207c747add2da1cc8b167f (patch) | |
| tree | 90abe0fad90920415ae4f1e118854cf56e8dfe04 /shared-module/displayio/Bitmap.c | |
| parent | 1a6ad209439e0c8b0d01701b76195f9761949e31 (diff) | |
A variety of displayio improvements
This changes a number of things in displayio:
* Introduces BuiltinFont and Glyph so the built in font can be used by libraries. For boards with
a font it is available as board.TERMINAL_FONT. Fixes #1172
* Remove _load_row from Bitmap in favor of bitmap[] access. Index can be x/y tuple or overall index. Fixes #1191
* Add width and height properties to Bitmap.
* Add insert and [] access to Group. Fixes #1518
* Add index param to pop on Group.
* Terminal no longer takes unicode character info. It takes a BuiltinFont instead.
* Fix Terminal's handling of [###D vt100 commands used when up arrowing into repl history.
* Add x and y positions to Group plus scale as well.
* Add bitmap accessor for BuiltinFont
Diffstat (limited to 'shared-module/displayio/Bitmap.c')
| -rw-r--r-- | shared-module/displayio/Bitmap.c | 33 |
1 files changed, 32 insertions, 1 deletions
diff --git a/shared-module/displayio/Bitmap.c b/shared-module/displayio/Bitmap.c index addc341a7..2b2c70ab6 100644 --- a/shared-module/displayio/Bitmap.c +++ b/shared-module/displayio/Bitmap.c @@ -42,7 +42,7 @@ void common_hal_displayio_bitmap_construct(displayio_bitmap_t *self, uint32_t wi self->width = width; self->height = height; self->data = m_malloc(self->stride * height * sizeof(uint32_t), false); - + self->read_only = false; self->bits_per_value = bits_per_value; if (bits_per_value > 8) { @@ -64,6 +64,18 @@ void common_hal_displayio_bitmap_construct(displayio_bitmap_t *self, uint32_t wi self->bitmask = (1 << bits_per_value) - 1; } +uint16_t common_hal_displayio_bitmap_get_height(displayio_bitmap_t *self) { + return self->height; +} + +uint16_t common_hal_displayio_bitmap_get_width(displayio_bitmap_t *self) { + return self->width; +} + +uint32_t common_hal_displayio_bitmap_get_bits_per_value(displayio_bitmap_t *self) { + return self->bits_per_value; +} + void common_hal_displayio_bitmap_load_row(displayio_bitmap_t *self, uint16_t y, uint8_t* data, uint16_t len) { if (len != self->stride * sizeof(uint32_t)) { mp_raise_ValueError(translate("row must be packed and word aligned")); @@ -85,6 +97,7 @@ void common_hal_displayio_bitmap_load_row(displayio_bitmap_t *self, uint16_t y, row_value++; } } + uint32_t common_hal_displayio_bitmap_get_pixel(displayio_bitmap_t *self, int16_t x, int16_t y) { if (x >= self->width || x < 0 || y >= self->height || y < 0) { return 0; @@ -99,3 +112,21 @@ uint32_t common_hal_displayio_bitmap_get_pixel(displayio_bitmap_t *self, int16_t return self->data[row_start + x * bytes_per_value]; } } + +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")); + } + int32_t row_start = y * self->stride; + if (self->bits_per_value < 8) { + uint32_t bit_position = (32 - ((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 { + uint32_t bytes_per_value = self->bits_per_value / 8; + self->data[row_start + x * bytes_per_value] = value; + } +} |
