Skip to content

displayio: Fix several bugs (transparency and palettes of OnDiskBitmaps) #3834

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Dec 22, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions shared-module/displayio/ColorConverter.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
#include "py/misc.h"
#include "py/runtime.h"

#define NO_TRANSPARENT_COLOR (0x1000000)

uint32_t displayio_colorconverter_dither_noise_1 (uint32_t n)
{
n = (n >> 13) ^ n;
Expand All @@ -42,6 +44,7 @@ uint32_t displayio_colorconverter_dither_noise_2(uint32_t x, uint32_t y) {

void common_hal_displayio_colorconverter_construct(displayio_colorconverter_t* self, bool dither) {
self->dither = dither;
self->transparent_color = NO_TRANSPARENT_COLOR;
}

uint16_t displayio_colorconverter_compute_rgb565(uint32_t color_rgb888) {
Expand Down Expand Up @@ -130,16 +133,16 @@ bool common_hal_displayio_colorconverter_get_dither(displayio_colorconverter_t*
}

void common_hal_displayio_colorconverter_make_transparent(displayio_colorconverter_t* self, uint32_t transparent_color) {
if (self->transparent_color >= 0x1000000) {
if (self->transparent_color != NO_TRANSPARENT_COLOR) {
mp_raise_RuntimeError(translate("Only one color can be transparent at a time"));
}
self->transparent_color = transparent_color;
}

void common_hal_displayio_colorconverter_make_opaque(displayio_colorconverter_t* self, uint32_t transparent_color) {
(void) transparent_color;
// 0x1000000 will never equal a valid color
self->transparent_color = 0x1000000;
// NO_TRANSPARENT_COLOR will never equal a valid color
self->transparent_color = NO_TRANSPARENT_COLOR;
}

void displayio_colorconverter_convert(displayio_colorconverter_t *self, const _displayio_colorspace_t* colorspace, const displayio_input_pixel_t *input_pixel, displayio_output_pixel_t *output_color) {
Expand Down
5 changes: 4 additions & 1 deletion shared-module/displayio/OnDiskBitmap.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ void common_hal_displayio_ondiskbitmap_construct(displayio_ondiskbitmap_t *self,
uint32_t compression = read_word(bmp_header, 15);
uint32_t number_of_colors = read_word(bmp_header, 23);

bool indexed = ((bits_per_pixel <= 8) && (number_of_colors != 0));
bool indexed = bits_per_pixel <= 8;
self->bitfield_compressed = (compression == 3);
self->bits_per_pixel = bits_per_pixel;
self->width = read_word(bmp_header, 9);
Expand All @@ -75,6 +75,9 @@ void common_hal_displayio_ondiskbitmap_construct(displayio_ondiskbitmap_t *self,
self->b_bitmask = 0x1f;
}
} else if (indexed && self->bits_per_pixel != 1) {
if (number_of_colors == 0) {
number_of_colors = 1 << bits_per_pixel;
}
uint16_t palette_size = number_of_colors * sizeof(uint32_t);
uint16_t palette_offset = 0xe + header_size;

Expand Down