From 95f7c5586c7f8d647ed38645599ace39fb82c989 Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Mon, 24 Feb 2020 18:39:14 +0100 Subject: sixel: add sixel_delete_at_row and sixel_delete_in_range These are utility functions to erase sixel images that are at the specified row, or in a row range. --- sixel.c | 72 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 65 insertions(+), 7 deletions(-) (limited to 'sixel.c') diff --git a/sixel.c b/sixel.c index 6a0b2982..d8a494e1 100644 --- a/sixel.c +++ b/sixel.c @@ -52,25 +52,83 @@ sixel_destroy(struct sixel *sixel) sixel->data = NULL; } +static void +sixel_erase(struct terminal *term, struct sixel *sixel) +{ + for (int i = 0; i < sixel->rows; i++) { + int r = (sixel->pos.row + i) & (term->grid->num_rows - 1); + + struct row *row = term->grid->rows[r]; + row->dirty = true; + + for (int c = 0; c < term->grid->num_cols; c++) + row->cells[c].attrs.clean = 0; + } + + sixel_destroy(sixel); +} + void -sixel_delete_at_cursor(struct terminal *term) +sixel_delete_at_row(struct terminal *term, int _row) { - const int row = term->grid->offset + term->cursor.point.row; + if (likely(tll_length(term->sixel_images) == 0)) + return; tll_foreach(term->sixel_images, it) { - if (it->item.grid != term->grid) + struct sixel *six = &it->item; + + if (six->grid != term->grid) continue; - const int start = it->item.pos.row; - const int end = start + it->item.rows; + const int row = (term->grid->offset + _row) & (term->grid->num_rows - 1); + const int six_start = six->pos.row; + const int six_end = six_start + six->rows - 1; - if (row >= start && row < end) { - sixel_destroy(&it->item); + if (row >= six_start && row <= six_end) { + sixel_erase(term, six); tll_remove(term->sixel_images, it); } } } +void +sixel_delete_in_range(struct terminal *term, int _start, int _end) +{ + assert(_end >= _start); + + if (likely(tll_length(term->sixel_images) == 0)) + return; + + if (_start == _end) + return sixel_delete_at_row(term, _start); + + tll_foreach(term->sixel_images, it) { + struct sixel *six = &it->item; + + if (six->grid != term->grid) + continue; + + const int start = (term->grid->offset + _start) & (term->grid->num_rows - 1); + const int end = start + (_end - _start); + const int six_start = six->pos.row; + const int six_end = six_start + six->rows - 1; + + if ((start <= six_start && end >= six_start) || /* Crosses sixel start boundary */ + (start <= six_end && end >= six_end) || /* Crosses sixel end boundary */ + (start >= six_start && end <= six_end)) /* Fully within sixel range */ + { + sixel_erase(term, six); + tll_remove(term->sixel_images, it); + } + } +} + +void +sixel_delete_at_cursor(struct terminal *term) +{ + sixel_delete_at_row(term, term->cursor.point.row); +} + void sixel_unhook(struct terminal *term) { -- cgit v1.3 From afa9ac0cfc05ac58b4cb03f88cab7069fd137266 Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Mon, 24 Feb 2020 18:39:58 +0100 Subject: sixel: ensure 'start' row is not outside the grid row range --- sixel.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'sixel.c') diff --git a/sixel.c b/sixel.c index d8a494e1..caa31429 100644 --- a/sixel.c +++ b/sixel.c @@ -143,7 +143,9 @@ sixel_unhook(struct terminal *term) .height = term->sixel.image.height, .rows = (term->sixel.image.height + term->cell_height - 1) / term->cell_height, .grid = term->grid, - .pos = (struct coord){term->cursor.point.col, term->grid->offset + term->cursor.point.row}, + .pos = (struct coord){ + term->cursor.point.col, + (term->grid->offset + term->cursor.point.row) & (term->grid->num_rows - 1)}, }; LOG_DBG("generating %dx%d pixman image", image.width, image.height); -- cgit v1.3 From 4c6f2ea340d1432e50973961579ebd0eb4ca2c0f Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Mon, 24 Feb 2020 18:40:41 +0100 Subject: term: term_erase(): call sixel_delete_*() This ensures sixel images are removed, regardless of _how_ the screen was erased. --- sixel.c | 4 ++-- terminal.c | 2 ++ 2 files changed, 4 insertions(+), 2 deletions(-) (limited to 'sixel.c') diff --git a/sixel.c b/sixel.c index caa31429..68324fde 100644 --- a/sixel.c +++ b/sixel.c @@ -156,8 +156,6 @@ sixel_unhook(struct terminal *term) term->sixel.image.data, term->sixel.image.width * sizeof(uint32_t)); - tll_push_back(term->sixel_images, image); - term->sixel.image.data = NULL; term->sixel.image.width = 0; term->sixel.image.height = 0; @@ -168,6 +166,8 @@ sixel_unhook(struct terminal *term) term_linefeed(term); term_formfeed(term); render_refresh(term); + + tll_push_back(term->sixel_images, image); } static unsigned diff --git a/terminal.c b/terminal.c index 8504a45b..e73ea15a 100644 --- a/terminal.c +++ b/terminal.c @@ -1366,6 +1366,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_delete_at_row(term, start->row); return; } @@ -1378,6 +1379,7 @@ term_erase(struct terminal *term, const struct coord *start, const struct coord erase_line(term, grid_row(term->grid, r)); erase_cell_range(term, grid_row(term->grid, end->row), 0, end->col); + sixel_delete_in_range(term, start->row, end->row); } int -- cgit v1.3 From 0c247de4ae68f9d8ed757f21487861bd0716ad30 Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Mon, 24 Feb 2020 18:42:04 +0100 Subject: sixel: CSI setters also write a reply to the client --- sixel.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) (limited to 'sixel.c') diff --git a/sixel.c b/sixel.c index 68324fde..b538fddb 100644 --- a/sixel.c +++ b/sixel.c @@ -481,16 +481,19 @@ sixel_colors_report_current(struct terminal *term) void sixel_colors_reset(struct terminal *term) { - term->sixel.palette_size = SIXEL_MAX_COLORS; LOG_DBG("sixel palette size reset to %u", SIXEL_MAX_COLORS); + term->sixel.palette_size = SIXEL_MAX_COLORS; + sixel_colors_report_current(term); } void sixel_colors_set(struct terminal *term, unsigned count) { unsigned new_palette_size = min(max(2, count), SIXEL_MAX_COLORS); - term->sixel.palette_size = new_palette_size; LOG_DBG("sixel palette size set to %u", new_palette_size); + + term->sixel.palette_size = new_palette_size; + sixel_colors_report_current(term); } void @@ -517,18 +520,19 @@ sixel_geometry_report_current(struct terminal *term) void sixel_geometry_reset(struct terminal *term) { + LOG_DBG("sixel geometry reset to %ux%u", max_width(term), max_height(term)); term->sixel.max_width = 0; term->sixel.max_height = 0; - LOG_DBG("sixel geometry reset to %ux%u", max_width(term), max_height(term)); + sixel_geometry_report_current(term); } void sixel_geometry_set(struct terminal *term, unsigned width, unsigned height) { + LOG_DBG("sixel geometry set to %ux%u", width, height); term->sixel.max_width = width; term->sixel.max_height = height; - LOG_DBG("sixel geometry set to %ux%u", - term->sixel.max_width, term->sixel.max_height); + sixel_geometry_report_current(term); } void -- cgit v1.3