Skip to content

Commit 28bd29e

Browse files
committed
displayio: ColorConverter: fix logic errors about transparent pixels
The transparent_color field was never initialized. I _think_ this means its value was always set to 0, or the blackest of blacks. Instead, initialize it to the sentinel value, newly given the name NO_TRANSPARENT_COLOR. This exposed a second problem: The test for whether there was an existing transparent color was wrong (backwards). I am guessing that this was not found due to the first bug; since the converter had a transparent color, the correct test would have led to always getting the error "Only one color can be transparent at a time". Closes #3723
1 parent f2204d7 commit 28bd29e

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

shared-module/displayio/ColorConverter.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@
2929
#include "py/misc.h"
3030
#include "py/runtime.h"
3131

32+
#define NO_TRANSPARENT_COLOR (0x1000000)
33+
3234
uint32_t displayio_colorconverter_dither_noise_1 (uint32_t n)
3335
{
3436
n = (n >> 13) ^ n;
@@ -42,6 +44,7 @@ uint32_t displayio_colorconverter_dither_noise_2(uint32_t x, uint32_t y) {
4244

4345
void common_hal_displayio_colorconverter_construct(displayio_colorconverter_t* self, bool dither) {
4446
self->dither = dither;
47+
self->transparent_color = NO_TRANSPARENT_COLOR;
4548
}
4649

4750
uint16_t displayio_colorconverter_compute_rgb565(uint32_t color_rgb888) {
@@ -130,16 +133,16 @@ bool common_hal_displayio_colorconverter_get_dither(displayio_colorconverter_t*
130133
}
131134

132135
void common_hal_displayio_colorconverter_make_transparent(displayio_colorconverter_t* self, uint32_t transparent_color) {
133-
if (self->transparent_color >= 0x1000000) {
136+
if (self->transparent_color != NO_TRANSPARENT_COLOR) {
134137
mp_raise_RuntimeError(translate("Only one color can be transparent at a time"));
135138
}
136139
self->transparent_color = transparent_color;
137140
}
138141

139142
void common_hal_displayio_colorconverter_make_opaque(displayio_colorconverter_t* self, uint32_t transparent_color) {
140143
(void) transparent_color;
141-
// 0x1000000 will never equal a valid color
142-
self->transparent_color = 0x1000000;
144+
// NO_TRANSPARENT_COLOR will never equal a valid color
145+
self->transparent_color = NO_TRANSPARENT_COLOR;
143146
}
144147

145148
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) {

0 commit comments

Comments
 (0)