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