sixel and osc5379 image display protocols can be chosen in options

This commit is contained in:
bptato
2021-02-02 15:06:53 +01:00
parent 64b0d8cafe
commit c5cd2b5716
4 changed files with 47 additions and 28 deletions
+4
View File
@@ -312,6 +312,10 @@ extern int REV_LB[];
#define EOL(l) (&(l)->ptr[(l)->length])
#define IS_EOL(p,l) ((p)==&(l)->ptr[(l)->length])
#define INLINE_IMG_NONE 0
#define INLINE_IMG_OSC5379 1
#define INLINE_IMG_SIXEL 2
/*
* Types.
*/
+26 -23
View File
@@ -224,31 +224,34 @@ drawImage()
i->sx, i->sy, i->width, i->height,
pixel_per_char_i, pixel_per_line_i);
#endif
(enable_inline_image == 2 ? put_image_sixel : put_image_osc5379)(
((enable_inline_image == 2 /* sixel */ || getenv("WINDOWID")) &&
char *url = ((enable_inline_image == INLINE_IMG_SIXEL || getenv("WINDOWID")) &&
/* XXX I don't know why but sometimes i->cache->file doesn't exist. */
i->cache->touch && stat(i->cache->file,&st) == 0) ?
/* local */ i->cache->file : /* remote */ i->cache->url,
i->x / pixel_per_char_i,
i->y / pixel_per_line_i,
#if 1
i->cache->a_width > 0 ?
(i->cache->width + i->x % pixel_per_char_i + pixel_per_char_i - 1) /
pixel_per_char_i :
#endif
0,
/* local */ i->cache->file : /* remote */ i->cache->url;
#if 1
i->cache->a_height > 0 ?
(i->cache->height + i->y % pixel_per_line_i + pixel_per_line_i - 1) /
pixel_per_line_i :
#endif
0,
i->sx / pixel_per_char_i,
i->sy / pixel_per_line_i,
(i->width + i->sx % pixel_per_char_i + pixel_per_char_i - 1) / pixel_per_char_i,
(i->height + i->sy % pixel_per_line_i + pixel_per_line_i - 1) / pixel_per_line_i,
n_terminal_image);
int x = i->x / pixel_per_char_i;
int y = i->y / pixel_per_line_i;
int w = i->cache->a_width > 0 ? (
(i->cache->width + i->x % pixel_per_char_i + pixel_per_char_i - 1) /
pixel_per_char_i) : 0;
int h = i->cache->a_height > 0 ? (
(i->cache->height + i->y % pixel_per_line_i + pixel_per_line_i - 1) /
pixel_per_line_i) : 0;
int sx = i->sx / pixel_per_char_i;
int sy = i->sy / pixel_per_line_i;
int sw = (i->width + i->sx % pixel_per_char_i + pixel_per_char_i - 1) /
pixel_per_char_i;
int sh = (i->height + i->sy % pixel_per_line_i + pixel_per_line_i - 1) /
pixel_per_line_i;
if (enable_inline_image == INLINE_IMG_SIXEL) {
put_image_sixel(url, x, y, w, h, sx, sy, sw, sh, n_terminal_image);
} else {
put_image_osc5379(url, x, y, w, h, sx, sy, sw, sh, n_terminal_image);
}
continue ;
}
@@ -599,7 +602,7 @@ getImage(Image * image, ParsedURL *current, int flag)
cache->pid = 0;
cache->index = 0;
cache->loaded = IMG_FLAG_UNLOADED;
if (enable_inline_image == 1) {
if (enable_inline_image == INLINE_IMG_OSC5379) {
if (image->width > 0 && image->width % pixel_per_char_i > 0)
image->width += (pixel_per_char_i - image->width % pixel_per_char_i);
+4 -4
View File
@@ -123,7 +123,7 @@ static int searchKeyNum(void);
#define help() fusage(stdout, 0)
#define usage() fusage(stderr, 1)
int enable_inline_image; /* 1 == mlterm OSC 5379, 2 == sixel */
int enable_inline_image;
static void
fversion(FILE * f)
@@ -692,10 +692,10 @@ main(int argc, char **argv, char **envp)
}
#endif
else if (!strcmp("-ri", argv[i])) {
enable_inline_image = 1;
enable_inline_image = INLINE_IMG_OSC5379;
}
else if (!strcmp("-sixel", argv[i])) {
enable_inline_image = 2;
enable_inline_image = INLINE_IMG_SIXEL;
}
else if (!strcmp("-num", argv[i]))
showLineNum = TRUE;
@@ -5961,7 +5961,7 @@ deleteFiles()
}
while ((f = popText(fileToDelete)) != NULL) {
unlink(f);
if (enable_inline_image == 2 && strcmp(f+strlen(f)-4, ".gif") == 0) {
if (enable_inline_image == INLINE_IMG_SIXEL && strcmp(f+strlen(f)-4, ".gif") == 0) {
Str firstframe = Strnew_charp(f);
Strcat_charp(firstframe, "-1");
unlink(firstframe->ptr);
+13 -1
View File
@@ -86,6 +86,7 @@ static int OptionEncode = FALSE;
#define CMT_IMAGE_SCALE N_("Scale of image (%)")
#define CMT_IMGDISPLAY N_("External command to display image")
#define CMT_IMAGE_MAP_LIST N_("Use link list of image map")
#define CMT_INLINE_IMG_PROTOCOL N_("Inline image protocol")
#endif
#define CMT_MULTICOL N_("Display file names in multi-column format")
#define CMT_ALT_ENTITY N_("Use ASCII equivalents to display entities")
@@ -363,6 +364,15 @@ static struct sel_c graphic_char_str[] = {
{0, NULL, NULL}
};
#ifdef USE_IMAGE
static struct sel_c inlineimgstr[] = {
{N_S(INLINE_IMG_NONE), N_("none")},
{N_S(INLINE_IMG_OSC5379), N_("mlterm osc 5379")},
{N_S(INLINE_IMG_SIXEL), N_("sixel")},
{0, NULL, NULL}
};
#endif /* USE_IMAGE */
struct param_ptr params1[] = {
{"tabstop", P_NZINT, PI_TEXT, (void *)&Tabstop, CMT_TABSTOP, NULL},
{"indent_incr", P_NZINT, PI_TEXT, (void *)&IndentIncr, CMT_INDENT_INCR,
@@ -428,6 +438,8 @@ struct param_ptr params1[] = {
NULL},
{"image_map_list", P_INT, PI_ONOFF, (void *)&image_map_list,
CMT_IMAGE_MAP_LIST, NULL},
{"inline_img_protocol", P_INT, PI_SEL_C, (void *)&enable_inline_image,
CMT_INLINE_IMG_PROTOCOL, (void *)inlineimgstr},
#endif
{"fold_line", P_INT, PI_ONOFF, (void *)&FoldLine, CMT_FOLD_LINE, NULL},
{"show_lnum", P_INT, PI_ONOFF, (void *)&showLineNum, CMT_SHOW_NUM, NULL},
@@ -1223,7 +1235,7 @@ sync_with_option(void)
init_migemo();
#endif
#ifdef USE_IMAGE
if (fmInitialized && displayImage)
if (fmInitialized && (displayImage || enable_inline_image))
initImage();
#else
displayImage = FALSE; /* XXX */