st/sixel.h

62 lines
1.7 KiB
C
Raw Normal View History

2021-03-10 17:09:47 +00:00
#ifndef SIXEL_H
#define SIXEL_H
#define DECSIXEL_PARAMS_MAX 16
#define DECSIXEL_PALETTE_MAX 1024
#define DECSIXEL_PARAMVALUE_MAX 65535
#define DECSIXEL_WIDTH_MAX 4096
#define DECSIXEL_HEIGHT_MAX 4096
typedef unsigned short sixel_color_no_t;
typedef unsigned int sixel_color_t;
typedef struct sixel_image_buffer {
sixel_color_no_t *data;
int width;
int height;
sixel_color_t palette[DECSIXEL_PALETTE_MAX];
sixel_color_no_t ncolors;
int palette_modified;
int use_private_register;
} sixel_image_t;
typedef enum parse_state {
PS_ESC = 1, /* ESC */
PS_DECSIXEL = 2, /* DECSIXEL body part ", $, -, ? ... ~ */
PS_DECGRA = 3, /* DECGRA Set Raster Attributes " Pan; Pad; Ph; Pv */
PS_DECGRI = 4, /* DECGRI Graphics Repeat Introducer ! Pn Ch */
PS_DECGCI = 5, /* DECGCI Graphics Color Introducer # Pc; Pu; Px; Py; Pz */
Reworking sixel implementation based on veltza's implementation (#117) * sixel: remove black bars from sixel images When the images don't fully cover the text cells, black bars are added to them. This fix removes those bars, but if you need the old behavior, you can restore it by setting 'sixelremovebars' to zero in config.h * sixel: fix a potential memory leak * sixel: improve behavior with text reflow * sixel: prevent animated gifs from choking the terminal Animated gifs constantly spawn new images that eventually choke the terminal because the old animation frames are kept in the image buffer. This fix removes overlapping images from the image buffer and prevents them from piling up. * sixel: add zooming and clipping * sixel: copying bulk of changes * sixel: move sixel_parser_parse() and add missing sequences and blocks (#113) - Move sixel_parser_parse() from tputc() to twrite() - Add missing 8452, DECSDM, XTSMGRAPHICS and XTWINOPS sequences - Add more conditional blocks for the scrollback and sync patches - Remove unused reflow_y from ImageList. It is only used for the scrollback-reflow patch in st-sx. * sixel: update vtiden to VT200 family * sixel: fix scrolling issues inside tmux (#114) tmux is using the scrolling region and sequence to clear the screen below the shell prompt. This peculiar behavior caused the tscrollup() function to be called, which always scrolled the images regardless of whether they were inside the region or not. So the images moved out of place whenever the bottom of the screen was cleared. This fix checks that the images are inside the region before scrolling them. * sixel: prevent images from being deleted when resizing (#115) This fixes resizing issues outside of tmux not inside. * Rewriting tresize logic based on veltza's proposed implementation in PR #115 * tresize: correction for tscrollup call when scrollback patch is used --------- Co-authored-by: veltza <106755522+veltza@users.noreply.github.com>
2024-03-07 08:22:44 +00:00
PS_ERROR = 6,
2021-03-10 17:09:47 +00:00
} parse_state_t;
typedef struct parser_context {
parse_state_t state;
int pos_x;
int pos_y;
int max_x;
int max_y;
int attributed_pan;
int attributed_pad;
int attributed_ph;
int attributed_pv;
int repeat_count;
int color_index;
int bgindex;
int grid_width;
int grid_height;
int param;
int nparams;
int params[DECSIXEL_PARAMS_MAX];
sixel_image_t image;
} sixel_state_t;
Reworking sixel implementation based on veltza's implementation (#117) * sixel: remove black bars from sixel images When the images don't fully cover the text cells, black bars are added to them. This fix removes those bars, but if you need the old behavior, you can restore it by setting 'sixelremovebars' to zero in config.h * sixel: fix a potential memory leak * sixel: improve behavior with text reflow * sixel: prevent animated gifs from choking the terminal Animated gifs constantly spawn new images that eventually choke the terminal because the old animation frames are kept in the image buffer. This fix removes overlapping images from the image buffer and prevents them from piling up. * sixel: add zooming and clipping * sixel: copying bulk of changes * sixel: move sixel_parser_parse() and add missing sequences and blocks (#113) - Move sixel_parser_parse() from tputc() to twrite() - Add missing 8452, DECSDM, XTSMGRAPHICS and XTWINOPS sequences - Add more conditional blocks for the scrollback and sync patches - Remove unused reflow_y from ImageList. It is only used for the scrollback-reflow patch in st-sx. * sixel: update vtiden to VT200 family * sixel: fix scrolling issues inside tmux (#114) tmux is using the scrolling region and sequence to clear the screen below the shell prompt. This peculiar behavior caused the tscrollup() function to be called, which always scrolled the images regardless of whether they were inside the region or not. So the images moved out of place whenever the bottom of the screen was cleared. This fix checks that the images are inside the region before scrolling them. * sixel: prevent images from being deleted when resizing (#115) This fixes resizing issues outside of tmux not inside. * Rewriting tresize logic based on veltza's proposed implementation in PR #115 * tresize: correction for tscrollup call when scrollback patch is used --------- Co-authored-by: veltza <106755522+veltza@users.noreply.github.com>
2024-03-07 08:22:44 +00:00
void scroll_images(int n);
void delete_image(ImageList *im);
2021-03-10 17:09:47 +00:00
int sixel_parser_init(sixel_state_t *st, sixel_color_t fgcolor, sixel_color_t bgcolor, unsigned char use_private_register, int cell_width, int cell_height);
Reworking sixel implementation based on veltza's implementation (#117) * sixel: remove black bars from sixel images When the images don't fully cover the text cells, black bars are added to them. This fix removes those bars, but if you need the old behavior, you can restore it by setting 'sixelremovebars' to zero in config.h * sixel: fix a potential memory leak * sixel: improve behavior with text reflow * sixel: prevent animated gifs from choking the terminal Animated gifs constantly spawn new images that eventually choke the terminal because the old animation frames are kept in the image buffer. This fix removes overlapping images from the image buffer and prevents them from piling up. * sixel: add zooming and clipping * sixel: copying bulk of changes * sixel: move sixel_parser_parse() and add missing sequences and blocks (#113) - Move sixel_parser_parse() from tputc() to twrite() - Add missing 8452, DECSDM, XTSMGRAPHICS and XTWINOPS sequences - Add more conditional blocks for the scrollback and sync patches - Remove unused reflow_y from ImageList. It is only used for the scrollback-reflow patch in st-sx. * sixel: update vtiden to VT200 family * sixel: fix scrolling issues inside tmux (#114) tmux is using the scrolling region and sequence to clear the screen below the shell prompt. This peculiar behavior caused the tscrollup() function to be called, which always scrolled the images regardless of whether they were inside the region or not. So the images moved out of place whenever the bottom of the screen was cleared. This fix checks that the images are inside the region before scrolling them. * sixel: prevent images from being deleted when resizing (#115) This fixes resizing issues outside of tmux not inside. * Rewriting tresize logic based on veltza's proposed implementation in PR #115 * tresize: correction for tscrollup call when scrollback patch is used --------- Co-authored-by: veltza <106755522+veltza@users.noreply.github.com>
2024-03-07 08:22:44 +00:00
int sixel_parser_parse(sixel_state_t *st, const unsigned char *p, size_t len);
2021-03-10 17:09:47 +00:00
int sixel_parser_set_default_color(sixel_state_t *st);
Reworking sixel implementation based on veltza's implementation (#117) * sixel: remove black bars from sixel images When the images don't fully cover the text cells, black bars are added to them. This fix removes those bars, but if you need the old behavior, you can restore it by setting 'sixelremovebars' to zero in config.h * sixel: fix a potential memory leak * sixel: improve behavior with text reflow * sixel: prevent animated gifs from choking the terminal Animated gifs constantly spawn new images that eventually choke the terminal because the old animation frames are kept in the image buffer. This fix removes overlapping images from the image buffer and prevents them from piling up. * sixel: add zooming and clipping * sixel: copying bulk of changes * sixel: move sixel_parser_parse() and add missing sequences and blocks (#113) - Move sixel_parser_parse() from tputc() to twrite() - Add missing 8452, DECSDM, XTSMGRAPHICS and XTWINOPS sequences - Add more conditional blocks for the scrollback and sync patches - Remove unused reflow_y from ImageList. It is only used for the scrollback-reflow patch in st-sx. * sixel: update vtiden to VT200 family * sixel: fix scrolling issues inside tmux (#114) tmux is using the scrolling region and sequence to clear the screen below the shell prompt. This peculiar behavior caused the tscrollup() function to be called, which always scrolled the images regardless of whether they were inside the region or not. So the images moved out of place whenever the bottom of the screen was cleared. This fix checks that the images are inside the region before scrolling them. * sixel: prevent images from being deleted when resizing (#115) This fixes resizing issues outside of tmux not inside. * Rewriting tresize logic based on veltza's proposed implementation in PR #115 * tresize: correction for tscrollup call when scrollback patch is used --------- Co-authored-by: veltza <106755522+veltza@users.noreply.github.com>
2024-03-07 08:22:44 +00:00
int sixel_parser_finalize(sixel_state_t *st, ImageList **newimages, int cx, int cy, int cw, int ch);
2021-03-10 17:09:47 +00:00
void sixel_parser_deinit(sixel_state_t *st);
#endif