sixel: split -> overwrite

This commit is contained in:
Daniel Eklöf 2020-06-27 15:29:47 +02:00
parent ae727e372a
commit 186a07c364
No known key found for this signature in database
GPG key ID: 5BBD4992C116573F
3 changed files with 28 additions and 24 deletions

30
sixel.c
View file

@ -186,8 +186,8 @@ sixel_delete_in_range(struct terminal *term, int _start, int _end)
}
static void
sixel_split(struct terminal *term, struct sixel *six,
int row, int col, int height, int width)
sixel_overwrite(struct terminal *term, struct sixel *six,
int row, int col, int height, int width)
{
assert(row >= 0);
assert(row + height <= term->grid->num_rows);
@ -290,7 +290,7 @@ sixel_split(struct terminal *term, struct sixel *six,
/* Row numbers are absolute */
static void
_sixel_split_by_rectangle(
_sixel_overwrite_by_rectangle(
struct terminal *term, int row, int col, int height, int width)
{
assert(row + height <= term->grid->num_rows);
@ -326,7 +326,7 @@ _sixel_split_by_rectangle(
(col <= col_end && col + width - 1 >= col_end) ||
(col >= col_start && col + width - 1 <= col_end))
{
sixel_split(term, six, start, col, height, width);
sixel_overwrite(term, six, start, col, height, width);
sixel_erase(term, six);
tll_remove(term->grid->sixel_images, it);
}
@ -335,7 +335,7 @@ _sixel_split_by_rectangle(
}
void
sixel_split_by_rectangle(
sixel_overwrite_by_rectangle(
struct terminal *term, int row, int col, int height, int width)
{
if (likely(tll_length(term->grid->sixel_images) == 0))
@ -348,15 +348,15 @@ sixel_split_by_rectangle(
if (wraps) {
int rows_to_wrap_around = term->grid->num_rows - start;
assert(height - rows_to_wrap_around > 0);
_sixel_split_by_rectangle(term, start, col, rows_to_wrap_around, width);
_sixel_split_by_rectangle(term, 0, col, height - rows_to_wrap_around, width);
_sixel_overwrite_by_rectangle(term, start, col, rows_to_wrap_around, width);
_sixel_overwrite_by_rectangle(term, 0, col, height - rows_to_wrap_around, width);
} else
_sixel_split_by_rectangle(term, start, col, height, width);
_sixel_overwrite_by_rectangle(term, start, col, height, width);
}
/* Row numbers are absolute */
static void
_sixel_split_by_row(struct terminal *term, int row, int col, int width)
_sixel_overwrite_by_row(struct terminal *term, int row, int col, int width)
{
assert(col >= 0);
@ -384,7 +384,7 @@ _sixel_split_by_row(struct terminal *term, int row, int col, int width)
(col <= col_end && col + width - 1 >= col_end) ||
(col >= col_start && col + width - 1 <= col_end))
{
sixel_split(term, six, row, col, 1, width);
sixel_overwrite(term, six, row, col, 1, width);
sixel_erase(term, six);
tll_remove(term->grid->sixel_images, it);
}
@ -393,18 +393,18 @@ _sixel_split_by_row(struct terminal *term, int row, int col, int width)
}
void
sixel_split_by_row(struct terminal *term, int row, int col, int width)
sixel_overwrite_by_row(struct terminal *term, int row, int col, int width)
{
_sixel_split_by_row(
_sixel_overwrite_by_row(
term,
(term->grid->offset + row) & (term->grid->num_rows - 1),
col, width);
}
void
sixel_split_at_cursor(struct terminal *term)
sixel_overwrite_at_cursor(struct terminal *term)
{
sixel_split_by_row(
sixel_overwrite_by_row(
term, term->grid->cursor.point.row, term->grid->cursor.point.col, 1);
}
@ -448,7 +448,7 @@ sixel_unhook(struct terminal *term)
.pos = (struct coord){cursor->col, cur_row},
};
sixel_split_by_rectangle(
sixel_overwrite_by_rectangle(
term, cursor->row, image.pos.col, image.rows, image.cols);
LOG_DBG("generating %dx%d pixman image at %d-%d", image.width, image.height, image.pos.row, image.pos.row + image.rows);

11
sixel.h
View file

@ -12,14 +12,17 @@ void sixel_unhook(struct terminal *term);
void sixel_destroy(struct sixel *sixel);
/* Row numbers are relative to current grid offset */
/* Deletes all sixels that are touched by the specified row(s). Row
* numbers are relative to the current grid aoffset */
void sixel_delete_in_range(struct terminal *term, int row_start, int row_end);
void sixel_delete_at_row(struct terminal *term, int row);
void sixel_split_by_rectangle(
/* Remove sixel data from the specified location. Row numbers are
* relative to the current grid offset */
void sixel_overwrite_by_rectangle(
struct terminal *term, int row, int col, int height, int width);
void sixel_split_by_row(struct terminal *term, int row, int col, int width);
void sixel_split_at_cursor(struct terminal *term);
void sixel_overwrite_by_row(struct terminal *term, int row, int col, int width);
void sixel_overwrite_at_cursor(struct terminal *term);
void sixel_colors_report_current(struct terminal *term);
void sixel_colors_reset(struct terminal *term);

View file

@ -1599,7 +1599,7 @@ term_erase(struct terminal *term, const struct coord *start, const struct coord
if (start->row == end->row) {
struct row *row = grid_row(term->grid, start->row);
erase_cell_range(term, row, start->col, end->col);
sixel_split_by_row(term, start->row, start->col, end->col - start->col + 1);
sixel_overwrite_by_row(term, start->row, start->col, end->col - start->col + 1);
return;
}
@ -1607,14 +1607,15 @@ term_erase(struct terminal *term, const struct coord *start, const struct coord
erase_cell_range(
term, grid_row(term->grid, start->row), start->col, term->cols - 1);
sixel_split_by_row(term, start->row, start->col, term->cols - start->col);
sixel_overwrite_by_row(term, start->row, start->col, term->cols - start->col);
for (int r = start->row + 1; r < end->row; r++)
erase_line(term, grid_row(term->grid, r));
sixel_split_by_rectangle(term, start->row + 1, 0, end->row - start->row, term->cols);
sixel_overwrite_by_rectangle(
term, start->row + 1, 0, end->row - start->row, term->cols);
erase_cell_range(term, grid_row(term->grid, end->row), 0, end->col);
sixel_split_by_row(term, end->row, 0, end->col + 1);
sixel_overwrite_by_row(term, end->row, 0, end->col + 1);
}
int
@ -2383,7 +2384,7 @@ term_print(struct terminal *term, wchar_t wc, int width)
print_linewrap(term);
print_insert(term, width);
sixel_split_at_cursor(term);
sixel_overwrite_at_cursor(term);
/* *Must* get current cell *after* linewrap+insert */
struct row *row = term->grid->cur_row;