summaryrefslogtreecommitdiff
path: root/shared-module
diff options
context:
space:
mode:
authorJeff Epler <jepler@gmail.com>2020-12-16 13:48:07 -0600
committerJeff Epler <jepler@gmail.com>2020-12-16 13:48:27 -0600
commit28bd29eb42d61d0a7116b6c4295e166fcfbe7145 (patch)
tree2928f5249f63958194f6fcaae6e35d872e1ab9b6 /shared-module
parentf2204d7d88b505155cd25b38b71ae3c35b86d438 (diff)
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
Diffstat (limited to 'shared-module')
-rw-r--r--shared-module/displayio/ColorConverter.c9
1 files changed, 6 insertions, 3 deletions
diff --git a/shared-module/displayio/ColorConverter.c b/shared-module/displayio/ColorConverter.c
index 80558d037..40dcd9d16 100644
--- a/shared-module/displayio/ColorConverter.c
+++ b/shared-module/displayio/ColorConverter.c
@@ -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;
@@ -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) {
@@ -130,7 +133,7 @@ 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;
@@ -138,8 +141,8 @@ void common_hal_displayio_colorconverter_make_transparent(displayio_colorconvert
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) {