aboutsummaryrefslogtreecommitdiff
path: root/sixel.c
diff options
context:
space:
mode:
authorDaniel Eklöf <daniel@ekloef.se>2020-06-28 08:45:05 +0000
committerDaniel Eklöf <daniel@ekloef.se>2020-06-28 08:45:05 +0000
commit0483466f68467694e960497e5f33cf0bf2f2cb90 (patch)
treeab2ee24adab12db534bfe75a331a80b7aa7283e7 /sixel.c
parentsixel: insert: sort sixels such that those furthest up in the scrollback is at the back (diff)
sixel: insert: calculate end rows in a single statement
Diffstat (limited to 'sixel.c')
-rw-r--r--sixel.c29
1 files changed, 21 insertions, 8 deletions
diff --git a/sixel.c b/sixel.c
index ddb0091c..beab0896 100644
--- a/sixel.c
+++ b/sixel.c
@@ -93,23 +93,36 @@ sixel_insert(struct terminal *term, struct sixel sixel)
const int scrollback_end
= (term->grid->offset + term->rows) & (term->grid->num_rows - 1);
- int end_row = sixel.pos.row + sixel.rows - scrollback_end;
- while (end_row < 0)
- end_row += term->grid->num_rows;
+ const int end_row
+ = (sixel.pos.row + sixel.rows
+ - scrollback_end
+ + term->grid->num_rows) & (term->grid->num_rows - 1);
+ assert(end_row >= 0 && end_row < term->grid->num_rows);
tll_foreach(term->grid->sixel_images, it) {
- int e = it->item.pos.row + it->item.rows - scrollback_end;
- e -= scrollback_end;
- while (e < 0)
- e += term->grid->num_rows;
+ const int e
+ = (it->item.pos.row + it->item.rows
+ - scrollback_end
+ + term->grid->num_rows) & (term->grid->num_rows - 1);
+ assert(e >= 0 && e < term->grid->num_rows);
if (e < end_row) {
tll_insert_before(term->grid->sixel_images, it, sixel);
- return;
+ goto out;
}
}
tll_push_back(term->grid->sixel_images, sixel);
+
+out:
+#if defined(LOG_ENABLE_DBG) && LOG_ENABLE_DBG
+ LOG_DBG("sixel list after insertion:");
+ tll_foreach(term->grid->sixel_images, it) {
+ LOG_DBG(" rows=%d+%d", it->item.pos.row, it->item.rows);
+ }
+#else
+ ;
+#endif
}
/* Row numbers are absolute */