From 2e7afc615c4b3a32a383da2efad8e30dc3fd9eac Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Sun, 4 Oct 2020 13:12:44 +0200 Subject: sixel: implement reflow Move sixel reflow from grid_reflow() to sixel_reflow(). This lets us use internal sixel functions to update the sixels. Note that grid_reflow() still needs to remap the sixelss coordinates. --- sixel.c | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) (limited to 'sixel.c') diff --git a/sixel.c b/sixel.c index 84b889fd..52eaa406 100644 --- a/sixel.c +++ b/sixel.c @@ -508,6 +508,54 @@ sixel_cell_size_changed(struct terminal *term) term->grid = g; } +void +sixel_reflow(struct terminal *term) +{ + struct grid *g = term->grid; + + for (size_t i = 0; i < 2; i++) { + struct grid *grid = i == 0 ? &term->normal : &term->alt; + + term->grid = grid; + + /* Need the “real” list to be empty from the beginning */ + tll(struct sixel) copy = tll_init(); + tll_foreach(grid->sixel_images, it) + tll_push_back(copy, it->item); + tll_free(grid->sixel_images); + + tll_rforeach(copy, it) { + struct sixel *six = &it->item; + int start = six->pos.row; + int end = (start + six->rows - 1) & (grid->num_rows - 1); + + if (end < start) { + /* Crosses scrollback wrap-around */ + /* TOOD: split image */ + sixel_destroy(six); + continue; + } + + if (six->rows > grid->num_rows) { + /* Image too large */ + /* TODO: keep bottom part? */ + sixel_destroy(six); + continue; + } + + /* Sixels that didn’t overlap may now do so, which isn’t + * allowed of course */ + _sixel_overwrite_by_rectangle( + term, six->pos.row, six->pos.col, six->rows, six->cols); + sixel_insert(term, it->item); + } + + tll_free(copy); + } + + term->grid = g; +} + void sixel_unhook(struct terminal *term) { -- cgit v1.3