Skip to content

Allow setting RGBW pixels with RGB tuples #3142

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 1 commit into from
Jul 11, 2020
Merged
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
18 changes: 10 additions & 8 deletions shared-module/_pixelbuf/PixelBuf.c
Original file line number Diff line number Diff line change
Expand Up @@ -147,18 +147,11 @@ void _pixelbuf_parse_color(pixelbuf_pixelbuf_obj_t* self, mp_obj_t color, uint8_
*r = value >> 16 & 0xff;
*g = (value >> 8) & 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 {
mp_obj_t *items;
size_t len;
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);
}

Expand All @@ -171,8 +164,17 @@ void _pixelbuf_parse_color(pixelbuf_pixelbuf_obj_t* self, mp_obj_t color, uint8_
} else {
*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) {
Expand Down