mirror of
https://codeberg.org/dnkl/foot.git
synced 2026-03-29 07:58:01 -04:00
sixel: calculate image height in (cell) rows
This commit is contained in:
parent
564e8909f4
commit
63140a68f5
4 changed files with 25 additions and 23 deletions
43
render.c
43
render.c
|
|
@ -520,30 +520,23 @@ grid_render_scroll_reverse(struct terminal *term, struct buffer *buf,
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
render_sixel(struct terminal *term, pixman_image_t *pix, const struct sixel *sixel)
|
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 view_end = (term->grid->view + term->rows - 1) & (term->grid->num_rows - 1);
|
||||||
int first_visible_row = -1;
|
int first_visible_row = -1;
|
||||||
|
|
||||||
if (view_end >= term->grid->view) {
|
for (size_t i = sixel->pos.row; i < sixel->pos.row + sixel->rows; i++) {
|
||||||
/* Not wrapped */
|
int row = i & (term->grid->num_rows - 1);
|
||||||
for (size_t i = sixel->pos.row;
|
|
||||||
i < sixel->pos.row + (sixel->height + term->cell_height - 1) / term->cell_height;
|
if (view_end >= term->grid->view) {
|
||||||
i++)
|
/* Not wrapped */
|
||||||
{
|
|
||||||
int row = i & (term->grid->num_rows - 1);
|
|
||||||
if (row >= term->grid->view && row <= view_end) {
|
if (row >= term->grid->view && row <= view_end) {
|
||||||
first_visible_row = i;
|
first_visible_row = i;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
} else {
|
/* Wrapped */
|
||||||
/* Wrapped */
|
|
||||||
for (size_t i = sixel->pos.row;
|
|
||||||
i < sixel->pos.row + (sixel->height + term->cell_height - 1) / term->cell_height;
|
|
||||||
i++)
|
|
||||||
{
|
|
||||||
int row = i & (term->grid->num_rows - 1);
|
|
||||||
if (row >= term->grid->view || row <= view_end) {
|
if (row >= term->grid->view || row <= view_end) {
|
||||||
first_visible_row = i;
|
first_visible_row = i;
|
||||||
break;
|
break;
|
||||||
|
|
@ -554,20 +547,30 @@ render_sixel(struct terminal *term, pixman_image_t *pix, const struct sixel *six
|
||||||
if (first_visible_row < 0)
|
if (first_visible_row < 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
/* First visible (0 based) row of the image */
|
||||||
const int first_img_row = first_visible_row - sixel->pos.row;
|
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 row = first_visible_row & (term->grid->num_rows - 1);
|
||||||
const int view_aligned =
|
const int view_aligned =
|
||||||
(row - term->grid->view + term->grid->num_rows) & (term->grid->num_rows - 1);
|
(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 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);
|
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 width = min(sixel->width, term->width - x - term->x_margin);
|
||||||
const int height = min(
|
const int height = min(
|
||||||
sixel->height - first_img_row * term->cell_height,
|
sixel->height - first_img_row * term->cell_height,
|
||||||
term->height - y - term->y_margin);
|
term->height - y - term->y_margin);
|
||||||
|
|
||||||
//LOG_INFO("x=%d, y=%d, width=%d, height=%d", x, y, width, height);
|
/* 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_image_composite(
|
||||||
PIXMAN_OP_SRC,
|
PIXMAN_OP_SRC,
|
||||||
|
|
@ -579,9 +582,7 @@ render_sixel(struct terminal *term, pixman_image_t *pix, const struct sixel *six
|
||||||
x, y,
|
x, y,
|
||||||
width, height);
|
width, height);
|
||||||
|
|
||||||
wl_surface_damage_buffer(
|
wl_surface_damage_buffer(term->window->surface, x, y, width, height);
|
||||||
term->window->surface,
|
|
||||||
x, y, width, height);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
|
|
||||||
1
sixel.c
1
sixel.c
|
|
@ -56,6 +56,7 @@ sixel_unhook(struct terminal *term)
|
||||||
.data = term->sixel.image,
|
.data = term->sixel.image,
|
||||||
.width = term->sixel.max_col,
|
.width = term->sixel.max_col,
|
||||||
.height = term->sixel.row * 6,
|
.height = term->sixel.row * 6,
|
||||||
|
.rows = (term->sixel.row * 6 + term->cell_height - 1) / term->cell_height,
|
||||||
.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},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1601,8 +1601,7 @@ term_scroll_reverse_partial(struct terminal *term,
|
||||||
|
|
||||||
/* TODO: untested */
|
/* TODO: untested */
|
||||||
|
|
||||||
int img_rows = (it->item.height + term->cell_height - 1) / term->cell_height;
|
int img_bottom_row = (it->item.pos.row + it->item.rows) & (term->grid->num_rows - 1);
|
||||||
int img_bottom_row = (it->item.pos.row + img_rows) & (term->grid->num_rows - 1);
|
|
||||||
int new_row = (term->grid->offset + r) & (term->grid->num_rows - 1);
|
int new_row = (term->grid->offset + r) & (term->grid->num_rows - 1);
|
||||||
|
|
||||||
if (img_bottom_row == new_row) {
|
if (img_bottom_row == new_row) {
|
||||||
|
|
|
||||||
|
|
@ -180,6 +180,7 @@ struct sixel {
|
||||||
pixman_image_t *pix;
|
pixman_image_t *pix;
|
||||||
int width;
|
int width;
|
||||||
int height;
|
int height;
|
||||||
|
int rows;
|
||||||
struct coord pos;
|
struct coord pos;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue