Improve antiburn speed on large displays

This commit is contained in:
fvanroie 2023-02-02 04:16:43 +01:00
parent 7934c47509
commit 16c900d5e4

View File

@ -213,31 +213,50 @@ void hasp_antiburn_cb(lv_task_t* task)
{
lv_obj_t* layer = lv_disp_get_layer_sys(NULL);
if(layer) {
// lv_color_t color[5] = {LV_COLOR_BLACK, LV_COLOR_WHITE, LV_COLOR_RED, LV_COLOR_LIME, LV_COLOR_BLUE};
// lv_obj_set_style_local_bg_color(layer, LV_OBJ_PART_MAIN, LV_STATE_DEFAULT, color[task->repeat_count % 5]);
lv_disp_t* disp = lv_disp_get_default();
lv_disp_drv_t* disp_drv = &disp->driver;
lv_area_t area;
area.x1 = 0;
// area.x2 = disp_drv->hor_res - 1;
// lv_color_t color[disp_drv->hor_res];
area.x2 = lv_obj_get_width(layer) - 1;
lv_color_t color[area.x2];
for(lv_coord_t y = 0; y < lv_obj_get_height(layer); y++) {
for(lv_coord_t x = 0; x < area.x2; x++) {
color[x].full = HASP_RANDOM(UINT16_MAX);
}
area.y1 = y;
area.y2 = y;
haspTft.flush_pixels(disp_drv, &area, color);
// Fill a buffer with random colors
lv_color_t color[1223];
size_t len = sizeof(color) / sizeof(color[0]);
for(size_t x = 0; x < len; x++) {
color[x].full = HASP_RANDOM(UINT16_MAX);
}
if(task->repeat_count != 1) return; // don't stop yet
// list of possible draw widths; prime numbers combat recurring patterns on the screen
uint8_t prime[] = {61, 67, 73, 79, 83, 89, 97, 103, 109, 113, 127, 131, 137, 139, 149,
157, 163, 167, 173, 179, 181, 191, 197, 211, 223, 227, 229, 233, 251};
lv_disp_t* disp = lv_disp_get_default();
lv_disp_drv_t* disp_drv = &disp->driver;
lv_coord_t scr_h = lv_obj_get_height(layer) - 1;
lv_coord_t scr_w = lv_obj_get_width(layer) - 1;
lv_coord_t w = 487; // first prime larger than 480
lv_area_t area;
area.y1 = 0;
while(area.y1 <= scr_h) {
if(w > scr_w) w = scr_w; // limit to the actual screenwidth
if(w > len) w = len; // don't overrun the buffer
lv_coord_t h = len / w;
size_t headroom = len % w; // additional bytes in the buffer that can be used for a random offset
area.y2 = area.y1 + h - 1;
if(area.y2 > scr_h) area.y2 = scr_h;
area.x1 = 0;
while(area.x1 <= scr_w) {
area.x2 = area.x1 + w - 1;
if(area.x2 > scr_w) area.x2 = scr_w;
size_t offset = headroom ? HASP_RANDOM(headroom) : 0;
haspTft.flush_pixels(disp_drv, &area, color + offset);
area.x1 += w;
}
w = prime[HASP_RANDOM(sizeof(prime))]; // new random width
area.y1 += h;
}
}
// lv_obj_invalidate(lv_scr_act());
if(task->repeat_count != 1) return; // don't stop yet
// task is about to get deleted