Skip to content

vectorio: palettes don't color dirty rectangles #5087

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 2 commits into from
Aug 9, 2021
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion shared-bindings/vectorio/VectorShape.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

//| class VectorShape:
//| def __init__(self, shape: Union[Polygon, Rectangle, Circle], pixel_shader: Union[displayio.ColorConverter, displayio.Palette], x: int=0, y: int=0) -> None:
//| """Binds a vector shape to a location and pixel color
//| """Binds a vector shape to a location and pixel shader. The shader can be a displayio.Palette(1); it will be asked to color pixel value 0.
//|
//| :param shape: The shape to draw.
//| :param pixel_shader: The pixel shader that produces colors from values
Expand Down
30 changes: 21 additions & 9 deletions shared-module/vectorio/VectorShape.c
Original file line number Diff line number Diff line change
Expand Up @@ -214,18 +214,30 @@ bool vectorio_vector_shape_fill_area(vectorio_vector_shape_t *self, const _displ
#endif
VECTORIO_SHAPE_PIXEL_DEBUG(" -> %d", input_pixel.pixel);

output_pixel.opaque = true;
if (self->pixel_shader == mp_const_none) {
output_pixel.pixel = input_pixel.pixel;
} else if (mp_obj_is_type(self->pixel_shader, &displayio_palette_type)) {
output_pixel.opaque = displayio_palette_get_color(self->pixel_shader, colorspace, input_pixel.pixel, &output_pixel.pixel);
} else if (mp_obj_is_type(self->pixel_shader, &displayio_colorconverter_type)) {
displayio_colorconverter_convert(self->pixel_shader, colorspace, &input_pixel, &output_pixel);
}
if (!output_pixel.opaque) {
// vectorio shapes use 0 to mean "area is not covered."
// We can skip all the rest of the work for this pixel if it's not currently covered by the shape.
if (input_pixel.pixel == 0) {
VECTORIO_SHAPE_PIXEL_DEBUG(" (encountered transparent pixel; input area is not fully covered)\n");
full_coverage = false;
} else {
// Pixel is not transparent. Let's pull the pixel value index down to 0-base for more error-resistant palettes.
input_pixel.pixel -= 1;
output_pixel.opaque = true;

if (self->pixel_shader == mp_const_none) {
output_pixel.pixel = input_pixel.pixel;
} else if (mp_obj_is_type(self->pixel_shader, &displayio_palette_type)) {
output_pixel.opaque = displayio_palette_get_color(self->pixel_shader, colorspace, input_pixel.pixel, &output_pixel.pixel);
} else if (mp_obj_is_type(self->pixel_shader, &displayio_colorconverter_type)) {
displayio_colorconverter_convert(self->pixel_shader, colorspace, &input_pixel, &output_pixel);
}

// We double-check this to fast-path the case when a pixel is not covered by the shape & not call the color converter unnecessarily.
if (!output_pixel.opaque) {
VECTORIO_SHAPE_PIXEL_DEBUG(" (encountered transparent pixel from colorconverter; input area is not fully covered)\n");
full_coverage = false;
}

*mask_doubleword |= 1u << mask_bit;
if (colorspace->depth == 16) {
VECTORIO_SHAPE_PIXEL_DEBUG(" buffer = %04x 16\n", output_pixel.pixel);
Expand Down