sixel: re-scale images when the cell dimensions change

Before this patch, when the cell dimensions changed (i.e. when the
font size changes), sixel images were either removed (the new cell
dimensions are smaller than the old), or simply kept at their original
size (new cell dimensions are larger).

With this patch, sixels are instead resized. This means a
sixel *always* occupies the same number of rows and columns,
regardless of how much the font size is changed.

This is done by maintaining two sets of image data and pixman images,
as well as their dimensions. These two sets are the new ‘original’ and
‘scaled’ members of the sixel struct.

The "top-level" pixman image pointer, and the ‘width’ and ‘height’
members either point to the "original", or the "scaled" version.

They are invalidated as soon as the cell dimensions change. They, and
the ‘scaled’ image is updated on-demand (when we need to render a
sixel).

Note that the ‘scaled’ image is always NULL when the current cell
dimensions matches the ones used when emitting the sixel (to save
run-time memory).

Closes #1383
This commit is contained in:
Daniel Eklöf 2023-06-29 14:49:54 +02:00
parent 7a37e6891f
commit 49fb0cf359
No known key found for this signature in database
GPG key ID: 5BBD4992C116573F
7 changed files with 295 additions and 112 deletions

View file

@ -1160,6 +1160,10 @@ static void
render_sixel(struct terminal *term, pixman_image_t *pix,
const struct coord *cursor, const struct sixel *sixel)
{
xassert(sixel->pix != NULL);
xassert(sixel->width >= 0);
xassert(sixel->height >= 0);
const int view_end = (term->grid->view + term->rows - 1) & (term->grid->num_rows - 1);
const bool last_row_needs_erase = sixel->height % term->cell_height != 0;
const bool last_col_needs_erase = sixel->width % term->cell_width != 0;
@ -1324,6 +1328,7 @@ render_sixel_images(struct terminal *term, pixman_image_t *pix,
break;
}
sixel_sync_cache(term, &it->item);
render_sixel(term, pix, cursor, &it->item);
}
}