Allow setting RGBW pixels with RGB tuples
This commit is contained in:
parent
51dbe9109f
commit
dd53e9a2bd
@ -147,18 +147,11 @@ void _pixelbuf_parse_color(pixelbuf_pixelbuf_obj_t* self, mp_obj_t color, uint8_
|
|||||||
*r = value >> 16 & 0xff;
|
*r = value >> 16 & 0xff;
|
||||||
*g = (value >> 8) & 0xff;
|
*g = (value >> 8) & 0xff;
|
||||||
*b = value & 0xff;
|
*b = value & 0xff;
|
||||||
// Int colors can't set white directly so convert to white when all components are equal.
|
|
||||||
if (!byteorder->is_dotstar && byteorder->bpp == 4 && byteorder->has_white && *r == *g && *r == *b) {
|
|
||||||
*w = *r;
|
|
||||||
*r = 0;
|
|
||||||
*g = 0;
|
|
||||||
*b = 0;
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
mp_obj_t *items;
|
mp_obj_t *items;
|
||||||
size_t len;
|
size_t len;
|
||||||
mp_obj_get_array(color, &len, &items);
|
mp_obj_get_array(color, &len, &items);
|
||||||
if (len != byteorder->bpp && !byteorder->is_dotstar) {
|
if (len < 3 || len > 4) {
|
||||||
mp_raise_ValueError_varg(translate("Expected tuple of length %d, got %d"), byteorder->bpp, len);
|
mp_raise_ValueError_varg(translate("Expected tuple of length %d, got %d"), byteorder->bpp, len);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -171,8 +164,17 @@ void _pixelbuf_parse_color(pixelbuf_pixelbuf_obj_t* self, mp_obj_t color, uint8_
|
|||||||
} else {
|
} else {
|
||||||
*w = mp_obj_get_int_truncated(items[PIXEL_W]);
|
*w = mp_obj_get_int_truncated(items[PIXEL_W]);
|
||||||
}
|
}
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// Int colors can't set white directly so convert to white when all components are equal.
|
||||||
|
// Also handles RGBW values assigned an RGB tuple.
|
||||||
|
if (!byteorder->is_dotstar && byteorder->bpp == 4 && byteorder->has_white && *r == *g && *r == *b) {
|
||||||
|
*w = *r;
|
||||||
|
*r = 0;
|
||||||
|
*g = 0;
|
||||||
|
*b = 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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) {
|
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) {
|
||||||
|
Loading…
Reference in New Issue
Block a user