8000 Merge pull request #3142 from rhooper/pixelbuf_rgbw_fix_5.3.x · astrobokonon/circuitpython@365d69e · GitHub
[go: up one dir, main page]

Skip to content

Commit 365d69e

Browse files
authored
Merge pull request adafruit#3142 from rhooper/pixelbuf_rgbw_fix_5.3.x
Allow setting RGBW pixels with RGB tuples
2 parents 1ce682d + dd53e9a commit 365d69e

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

shared-module/_pixelbuf/PixelBuf.c

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -147,18 +147,11 @@ void _pixelbuf_parse_color(pixelbuf_pixelbuf_obj_t* self, mp_obj_t color, uint8_
147147
*r = value >> 16 & 0xff;
148148
*g = (value >> 8) & 0xff;
149149
*b = value & 0xff;
150-
// Int colors can't set white directly so convert to white when all components are equal.
151-
if (!byteorder->is_dotstar && byteorder->bpp == 4 && byteorder->has_white && *r == *g && *r == *b) {
152-
*w = *r;
153-
*r = 0;
154-
*g = 0;
155-
*b = 0;
156-
}
157150
} else {
158151
mp_obj_t *items;
159152
size_t len;
160153
mp_obj_get_array(color, &len, &items);
161-
if (len != byteorder->bpp && !byteorder->is_dotstar) {
154+
if (len < 3 || len > 4) {
162155
mp_raise_ValueError_varg(translate("Expected tuple of length %d, got %d"), byteorder->bpp, len);
163156
}
164157

@@ -171,8 +164,17 @@ void _pixelbuf_parse_color(pixelbuf_pixelbuf_obj_t* self, mp_obj_t color, uint8_
171164
} else {
172165
*w = mp_obj_get_int_truncated(items[PIXEL_W]);
173166
}
167+
return;
174168
}
175169
}
170+
// Int colors can't set white directly so convert to white when all components are equal.
171+
// Also handles RGBW values assigned an RGB tuple.
172+
if (!byteorder->is_dotstar && byteorder->bpp == 4 && byteorder->has_white && *r == *g && *r == *b) {
173+
*w = *r;
174+
*r = 0;
175+
*g = 0;
176+
*b = 0;
177+
}
176178
}
177179

178180
void _pixelbuf_set_pixel_color(pixelbuf_pixelbuf_obj_t* self, size_t index, uint8_t r, uint8_t g, uint8_t b, uint8_t w) {

0 commit comments

Comments
 (0)
0