sixel: refactor the sixel display mode (#142)

This does not change the current behavior of SDM.
This commit is contained in:
veltza 2024-07-05 12:30:55 +03:00 committed by GitHub
parent 546dd288c0
commit 48c85cdcf5
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

62
st.c
View File

@ -220,6 +220,9 @@ static void tsetattr(const int *, int);
static void tsetchar(Rune, const Glyph *, int, int);
static void tsetdirt(int, int);
static void tsetscroll(int, int);
#if SIXEL_PATCH
static inline void tsetsixelattr(Line line, int x1, int x2);
#endif // SIXEL_PATCH
static void tswapscreen(void);
static void tsetmode(int, int, const int *, int);
static int twrite(const char *, int, int);
@ -1149,6 +1152,15 @@ tsetdirtattr(int attr)
}
}
#if SIXEL_PATCH
void
tsetsixelattr(Line line, int x1, int x2)
{
for (; x1 <= x2; x1++)
line[x1].mode |= ATTR_SIXEL;
}
#endif // SIXEL_PATCH
void
tfulldirt(void)
{
@ -2592,7 +2604,7 @@ strhandle(void)
};
#if SIXEL_PATCH
ImageList *im, *newimages, *next, *tail;
int i, x, y, x1, y1, x2, y2, numimages;
int i, x1, y1, x2, y2, numimages;
int cx, cy;
Line line;
#if SCROLLBACK_PATCH || REFLOW_PATCH
@ -2736,36 +2748,40 @@ strhandle(void)
} else {
term.images = newimages;
}
x2 = MIN(x2, term.col);
for (i = 0, im = newimages; im; im = next, i++) {
next = im->next;
#if SCROLLBACK_PATCH || REFLOW_PATCH
scr = IS_SET(MODE_ALTSCREEN) ? 0 : term.scr;
#endif // SCROLLBACK_PATCH
if (IS_SET(MODE_SIXEL_SDM)) {
x2 = MIN(x2, term.col) - 1;
if (IS_SET(MODE_SIXEL_SDM)) {
/* Sixel display mode: put the sixel in the upper left corner of
* the screen, disable scrolling (the sixel will be truncated if
* it is too long) and do not change the cursor position. */
for (i = 0, im = newimages; im; im = next, i++) {
next = im->next;
if (i >= term.row) {
delete_image(im);
continue;
}
im->y = i + scr;
line = term.line[i];
} else {
tsetsixelattr(term.line[i], x1, x2);
term.dirty[MIN(im->y, term.row-1)] = 1;
}
} else {
for (i = 0, im = newimages; im; im = next, i++) {
next = im->next;
#if SCROLLBACK_PATCH || REFLOW_PATCH
scr = IS_SET(MODE_ALTSCREEN) ? 0 : term.scr;
#endif // SCROLLBACK_PATCH
im->y = term.c.y + scr;
line = term.line[term.c.y];
}
for (x = im->x; x < x2; x++) {
line[x].mode |= ATTR_SIXEL;
}
term.dirty[MIN(im->y, term.row-1)] = 1;
if (!IS_SET(MODE_SIXEL_SDM) && i < numimages-1) {
im->next = NULL;
tnewline(0);
im->next = next;
tsetsixelattr(term.line[term.c.y], x1, x2);
term.dirty[MIN(im->y, term.row-1)] = 1;
if (i < numimages-1) {
im->next = NULL;
tnewline(0);
im->next = next;
}
}
/* if mode 8452 is set, sixel scrolling leaves cursor to right of graphic */
if (IS_SET(MODE_SIXEL_CUR_RT))
term.c.x = MIN(term.c.x + newimages->cols, term.col-1);
}
/* if mode 8452 is set, sixel scrolling leaves cursor to right of graphic */
if (!IS_SET(MODE_SIXEL_SDM) && IS_SET(MODE_SIXEL_CUR_RT))
term.c.x = MIN(term.c.x + newimages->cols, term.col-1);
}
#endif // SIXEL_PATCH
#if SYNC_PATCH