Skip to content
Merged
Changes from 1 commit
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
29 changes: 29 additions & 0 deletions Marlin/src/lcd/tft/canvas.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,17 @@ uint16_t Canvas::startLine, Canvas::endLine;
uint16_t Canvas::background_color;
uint16_t *Canvas::buffer = TFT::buffer;

struct rle_state_struct {
bool has_rle_state = false;
uint16_t dstx; // store dstx
uint16_t dsty; // store dsty
uint16_t srcx; // store srcx
uint16_t srcy; // store srcy
uint32_t rle_offset;
};

struct rle_state_struct rle_state;

void Canvas::instantiate(uint16_t x, uint16_t y, uint16_t width, uint16_t height) {
Canvas::width = width;
Canvas::height = height;
Expand Down Expand Up @@ -139,8 +150,25 @@ void Canvas::addImage(int16_t x, int16_t y, MarlinImage image, uint16_t *colors)
dsty = y, dstx = x; // Destination line / column index

uint16_t color = 0; // Persist the last fetched color value
if (rle_state.has_rle_state) { // do we have rle position data
dstx = rle_state.dstx; // restore dstx
dsty = rle_state.dsty; // restore dstx
srcx = rle_state.srcx; // restore dstx
srcy = rle_state.srcy; // restore dstx
bytedata = (uint8_t *)images[image].data + rle_state.rle_offset; // restart decode from here instead of teh start of data
rle_state.has_rle_state = false; // invalidate stored rle state // Invalidate date
}

bool done = false;
while (!done) {
if (dsty >= endLine -1 || srcy >= image_height -1) { // Store state?
rle_state.dstx = dstx; // save required states
rle_state.dsty = dsty;
rle_state.srcx = srcx;
rle_state.srcy = srcy;
rle_state.rle_offset = bytedata - (uint8_t *)images[image].data;; // Keep these for skipping full rle decode on future iteratons
}

uint8_t count = *bytedata++; // Get the count byte
const bool uniq = bool(count & 0x80); // >= 128 is a distinct run; < 128 is a repeat run
count = (count & 0x7F) + 1; // Actual count is 7-bit plus 1
Expand Down Expand Up @@ -169,6 +197,7 @@ void Canvas::addImage(int16_t x, int16_t y, MarlinImage image, uint16_t *colors)
srcx = 0; dstx = x; // May be shifted within the canvas, but usually not
if (dsty >= endLine || srcy >= image_height) { // Done with the segment or the image?
done = true; // Set a flag to end the loop...
rle_state.has_rle_state = true; // rle state is stored
break; // ...and break out of while(count--)
}
}
Expand Down