Skip to content

Commit 3b75081

Browse files
MichaelBellGadgetoid
authored andcommitted
ST7701: Fix palette update with layers.
1 parent b6fd333 commit 3b75081

File tree

1 file changed

+27
-2
lines changed

1 file changed

+27
-2
lines changed

drivers/st7701/st7701.cpp

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -619,7 +619,26 @@ void ST7701::start_frame_xfer()
619619
for (int i = 0; i < 256; ++i) {
620620
set_palette_colour(i, palette[i]);
621621
}
622-
memcpy(framebuffer, graphics->frame_buffer, width * height);
622+
if (graphics->layers == 1) {
623+
memcpy(framebuffer, graphics->frame_buffer, width * height);
624+
}
625+
else {
626+
uint8_t* dst = (uint8_t*)framebuffer;
627+
const uint8_t* end = dst + width * height;
628+
uint8_t* src = (uint8_t*)graphics->frame_buffer;
629+
const size_t layer_offset = width * height;
630+
const int top_layer_idx = graphics->layers - 1;
631+
632+
while (dst != end) {
633+
uint8_t colour = 0;
634+
for (int layer = top_layer_idx; layer >= 0; --layer) {
635+
colour = *(src + layer * layer_offset);
636+
if (colour) break;
637+
}
638+
*dst++ = colour;
639+
++src;
640+
}
641+
}
623642
} else {
624643
uint8_t* frame_ptr = (uint8_t*)framebuffer;
625644
graphics->frame_convert(PicoGraphics::PEN_RGB565, [this, &frame_ptr](void *data, size_t length) {
@@ -632,11 +651,17 @@ void ST7701::start_frame_xfer()
632651
}
633652

634653
void ST7701::partial_update(PicoGraphics *graphics, Rect region) {
635-
if(graphics->pen_type == PicoGraphics::PEN_RGB565 && graphics->layers == 1) { // Display buffer is screen native
654+
if (graphics->pen_type == PicoGraphics::PEN_RGB565 && !palette && graphics->layers == 1) { // Display buffer is screen native
636655
for (int y = region.y; y < region.y + region.h; ++y) {
637656
memcpy(&framebuffer[y * width + region.x], (uint16_t*)graphics->frame_buffer + y * width + region.x, region.w * sizeof(uint16_t));
638657
}
639658
}
659+
else if (graphics->pen_type == PicoGraphics::PEN_P8 && palette && graphics->layers == 1) {
660+
uint8_t* fb8 = (uint8_t*)framebuffer;
661+
for (int y = region.y; y < region.y + region.h; ++y) {
662+
memcpy(&fb8[y * width + region.x], (uint8_t*)graphics->frame_buffer + y * width + region.x, region.w * sizeof(uint8_t));
663+
}
664+
}
640665
}
641666

642667
void ST7701::set_backlight(uint8_t brightness) {

0 commit comments

Comments
 (0)