aboutsummaryrefslogtreecommitdiff
path: root/render.c
diff options
context:
space:
mode:
authorDaniel Eklöf <daniel@ekloef.se>2020-02-22 21:06:14 +0000
committerDaniel Eklöf <daniel@ekloef.se>2020-02-22 21:06:14 +0000
commit3a24777e45238a896743707cad65f2b5bef0a708 (patch)
tree0f524d0e80fb81e1b1086e00b771e21b768d6139 /render.c
parentkeymap: tab: handle all modifiers (diff)
parentREADME: add screenshot of sixel graphics (diff)
Merge branch 'sixel-graphics'
Diffstat (limited to 'render.c')
-rw-r--r--render.c75
1 files changed, 75 insertions, 0 deletions
diff --git a/render.c b/render.c
index bb229288..a4741b90 100644
--- a/render.c
+++ b/render.c
@@ -520,6 +520,79 @@ grid_render_scroll_reverse(struct terminal *term, struct buffer *buf,
}
static void
+render_sixel(struct terminal *term, pixman_image_t *pix,
+ const struct sixel *sixel)
+{
+ int view_end = (term->grid->view + term->rows - 1) & (term->grid->num_rows - 1);
+ int first_visible_row = -1;
+
+ for (size_t i = sixel->pos.row; i < sixel->pos.row + sixel->rows; i++) {
+ int row = i & (term->grid->num_rows - 1);
+
+ if (view_end >= term->grid->view) {
+ /* Not wrapped */
+ if (row >= term->grid->view && row <= view_end) {
+ first_visible_row = i;
+ break;
+ }
+ } else {
+ /* Wrapped */
+ if (row >= term->grid->view || row <= view_end) {
+ first_visible_row = i;
+ break;
+ }
+ }
+ }
+
+ if (first_visible_row < 0)
+ return;
+
+ /* First visible (0 based) row of the image */
+ const int first_img_row = first_visible_row - sixel->pos.row;
+
+ /* Map first visible line to current grid view */
+ const int row = first_visible_row & (term->grid->num_rows - 1);
+ const int view_aligned =
+ (row - term->grid->view + term->grid->num_rows) & (term->grid->num_rows - 1);
+
+ /* Translate row/column to x/y pixel values */
+ const int x = term->x_margin + sixel->pos.col * term->cell_width;
+ const int y = max(
+ term->y_margin, term->y_margin + view_aligned * term->cell_height);
+
+ /* Width/height, in pixels - and don't touch the window margins */
+ const int width = min(sixel->width, term->width - x - term->x_margin);
+ const int height = min(
+ sixel->height - first_img_row * term->cell_height,
+ term->height - y - term->y_margin);
+
+ /* Verify we're not stepping outside the grid */
+ assert(x >= term->x_margin);
+ assert(y >= term->y_margin);
+ assert(x + width <= term->width - term->x_margin);
+ assert(y + height <= term->height - term->y_margin);
+
+ pixman_image_composite(
+ PIXMAN_OP_SRC,
+ sixel->pix,
+ NULL,
+ pix,
+ 0, first_img_row * term->cell_height,
+ 0, 0,
+ x, y,
+ width, height);
+
+ wl_surface_damage_buffer(term->window->surface, x, y, width, height);
+}
+
+static void
+render_sixel_images(struct terminal *term, pixman_image_t *pix)
+{
+ tll_foreach(term->sixel_images, it)
+ render_sixel(term, pix, &it->item);
+}
+
+static void
render_row(struct terminal *term, pixman_image_t *pix, struct row *row, int row_no)
{
for (int col = term->cols - 1; col >= 0; col--)
@@ -816,6 +889,8 @@ grid_render(struct terminal *term)
cols_updated * term->cell_width, term->cell_height);
}
+ render_sixel_images(term, pix);
+
if (term->flash.active) {
/* Note: alpha is pre-computed in each color component */
/* TODO: dim while searching */