Add README.sixel. W3M_IMG2SIXEL environmental variable enables to specify options of img2sixel.

This commit is contained in:
Araki Ken
2014-11-16 04:07:05 +09:00
committed by Tatsuya Kinoshita
parent 982a8feab0
commit 2e8def7ab6
2 changed files with 62 additions and 20 deletions

27
doc/README.sixel Normal file
View File

@@ -0,0 +1,27 @@
Sixel support of w3m
2014/11/05
K. Araki
Introduction
This is the extension for w3m to show inline images by sixel graphics.
Requirements
Install 'img2sixel' command provided by libsixel project.
(https://github.com/saitoha/libsixel)
Build
$ ./configure --enable-image ...
$ make
$ make install
Usage
$ w3m -sixel http://...
You can specify options of 'img2sixel' command by "W3M_IMG2SIXEL"
environmental variable.
$ W3M_IMG2SIXEL="img2sixel -d atkinson" w3m -sixel http://...

55
terms.c
View File

@@ -596,7 +596,9 @@ put_image_sixel(char *url, int x, int y, int w, int h, int sx, int sy, int sw, i
prevstop = mySignal(SIGTSTP, SIG_IGN); prevstop = mySignal(SIGTSTP, SIG_IGN);
if ((pid = fork()) == 0) { if ((pid = fork()) == 0) {
char *argv[12]; char *env;
int n = 0;
char *argv[20];
char digit[2][11+1]; char digit[2][11+1];
char clip[44+3+1]; char clip[44+3+1];
Str str_url; Str str_url;
@@ -611,28 +613,41 @@ put_image_sixel(char *url, int x, int y, int w, int h, int sx, int sy, int sw, i
} }
ttymode_set(ISIG, 0); ttymode_set(ISIG, 0);
argv[0] = "img2sixel"; if ((env = getenv("W3M_IMG2SIXEL"))) {
argv[1] = "-l"; char *p;
argv[2] = do_anim ? "auto" : "disable"; env = Strnew_charp(env)->ptr;
argv[3] = "-w"; while (n < 8 && (p = strchr(env, ' '))) {
sprintf(digit[0], "%d", w*pixel_per_char_i); *p = '\0';
argv[4] = digit[0]; if (*env != '\0') {
argv[5] = "-h"; argv[n++] = env;
sprintf(digit[1], "%d", h*pixel_per_line_i); }
argv[6] = digit[1]; env = p+1;
argv[7] = "-c"; }
sprintf(clip, "%dx%d+%d+%d", sw*pixel_per_char_i, sh*pixel_per_line_i, if (*env != '\0') {
sx*pixel_per_char_i, sy*pixel_per_line_i); argv[n++] = env;
argv[8] = clip; }
argv[9] = url;
if (getenv("TERM") && strcmp(getenv("TERM"), "screen") == 0 &&
(!getenv("SCREEN_VARIANT") || strcmp(getenv("SCREEN_VARIANT"), "sixel") != 0)) {
argv[10] = "-P";
argv[11] = NULL;
} }
else { else {
argv[10] = NULL; argv[n++] = "img2sixel";
} }
argv[n++] = "-l";
argv[n++] = do_anim ? "auto" : "disable";
argv[n++] = "-w";
sprintf(digit[0], "%d", w*pixel_per_char_i);
argv[n++] = digit[0];
argv[n++] = "-h";
sprintf(digit[1], "%d", h*pixel_per_line_i);
argv[n++] = digit[1];
argv[n++] = "-c";
sprintf(clip, "%dx%d+%d+%d", sw*pixel_per_char_i, sh*pixel_per_line_i,
sx*pixel_per_char_i, sy*pixel_per_line_i);
argv[n++] = clip;
argv[n++] = url;
if (getenv("TERM") && strcmp(getenv("TERM"), "screen") == 0 &&
(!getenv("SCREEN_VARIANT") || strcmp(getenv("SCREEN_VARIANT"), "sixel") != 0)) {
argv[n++] = "-P";
}
argv[n++] = NULL;
execvp(argv[0],argv); execvp(argv[0],argv);
exit(0); exit(0);
} }