Add -sixel option which supports image processing by img2sixel.

This commit is contained in:
Araki Ken
2014-09-22 20:16:39 +09:00
committed by Tatsuya Kinoshita
parent 98b4d10ce4
commit 2fe66f3a6f
6 changed files with 43 additions and 60 deletions
+2 -2
View File
@@ -523,7 +523,7 @@ drawAnchorCursor0(Buffer *buf, AnchorList *al, int hseq, int prevhseq,
if (hseq >= 0 && an->hseq == hseq) {
int start_pos = an->start.pos;
for (i = an->start.pos; i < an->end.pos; i++) {
if (support_remote_image && (l->propBuf[i] & PE_IMAGE))
if (enable_inline_image && (l->propBuf[i] & PE_IMAGE))
start_pos = i + 1; /* Lazy check */
if (l->propBuf[i] & (PE_IMAGE | PE_ANCHOR | PE_FORM)) {
if (active)
@@ -858,7 +858,7 @@ redrawLineImage(Buffer *buf, Line *l, int i)
y = (int)(i * pixel_per_line);
sx = (int)((rcol - COLPOS(l, a->start.pos)) * pixel_per_char);
sy = (int)((l->linenumber - image->y) * pixel_per_line);
if (! support_remote_image) {
if (! enable_inline_image) {
if (sx == 0 && x + image->xoffset >= 0)
x += image->xoffset;
else
+3 -3
View File
@@ -3345,7 +3345,7 @@ process_img(struct parsed_tag *tag, int width)
if (i < 0)
i = pixel_per_line;
}
if (support_remote_image) {
if (enable_inline_image) {
nw = (w > 1) ? ((w - 1) / pixel_per_char_i + 1) : 1 ;
ni = (i > 1) ? ((i - 1) / pixel_per_line_i + 1) : 1 ;
}
@@ -3384,7 +3384,7 @@ process_img(struct parsed_tag *tag, int width)
Strcat(tmp, Sprintf(" height=%d", i0));
switch (align) {
case ALIGN_MIDDLE:
if (!support_remote_image) {
if (!enable_inline_image) {
top = ni / 2;
bottom = top;
if (top * 2 == ni)
@@ -3416,7 +3416,7 @@ process_img(struct parsed_tag *tag, int width)
break;
}
if (support_remote_image)
if (enable_inline_image)
xoffset = 0;
else
xoffset = (int)((nw * pixel_per_char - w) / 2);
+1 -1
View File
@@ -921,7 +921,7 @@ global char *CurrentKeyData;
global char *CurrentCmdData;
global char *w3m_reqlog;
extern char *w3m_version;
extern int support_remote_image;
extern int enable_inline_image;
#define DUMP_BUFFER 0x01
#define DUMP_HEAD 0x02
+14 -14
View File
@@ -53,7 +53,7 @@ getCharSize()
set_environ("W3M_TTY", ttyname_tty());
if (support_remote_image) {
if (enable_inline_image) {
int ppc, ppl;
if (get_pixel_per_cell(&ppc,&ppl)) {
@@ -170,7 +170,7 @@ addImage(ImageCache * cache, int x, int y, int sx, int sy, int w, int h)
static void
syncImage(void)
{
if (support_remote_image) {
if (enable_inline_image) {
return;
}
@@ -189,6 +189,9 @@ syncImage(void)
n_terminal_image = 0;
}
void put_image_osc5379(char *url, int x, int y, int w, int h, int sx, int sy, int sw, int sh);
void put_image_sixel(char *url, int x, int y, int w, int h, int sx, int sy, int sw, int sh);
void
drawImage()
{
@@ -204,7 +207,7 @@ drawImage()
for (j = 0; j < n_terminal_image; j++) {
i = &terminal_image[j];
if (support_remote_image) {
if (enable_inline_image) {
#if 0
fprintf(stderr,"file %s x %d y %d w %d h %d sx %d sy %d sw %d sh %d (ppc %d ppl %d)\n",
(getenv("WINDOWID") && i->cache->touch) ? i->cache->file : i->cache->url,
@@ -214,14 +217,11 @@ drawImage()
i->sx, i->sy, i->width, i->height,
pixel_per_char_i, pixel_per_line_i);
#endif
put_image(
#if 1
/* XXX I don't know why but sometimes i->cache->file doesn't exist. */
(getenv("WINDOWID") && i->cache->touch && stat(i->cache->file,&st) == 0) ?
(enable_inline_image == 2 ? put_image_sixel : put_image_osc5379)(
((enable_inline_image == 2 /* 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,
#else
i->cache->url,
#endif
i->x / pixel_per_char_i,
i->y / pixel_per_line_i,
#if 1
@@ -269,7 +269,7 @@ drawImage()
draw = TRUE;
}
if (!support_remote_image) {
if (!enable_inline_image) {
if (!draw)
return;
syncImage();
@@ -388,7 +388,7 @@ showImageProgress(Buffer *buf)
}
}
if (n) {
if (support_remote_image && n == l)
if (enable_inline_image && n == l)
drawImage();
message(Sprintf("%d/%d images loaded", l, n)->ptr,
buf->cursorX + buf->rootX, buf->cursorY + buf->rootY);
@@ -476,7 +476,7 @@ loadImage(Buffer *buf, int flag)
}
if (draw && image_buffer) {
if (!support_remote_image)
if (!enable_inline_image)
drawImage();
showImageProgress(image_buffer);
}
@@ -591,7 +591,7 @@ getImage(Image * image, ParsedURL *current, int flag)
cache->pid = 0;
cache->index = 0;
cache->loaded = IMG_FLAG_UNLOADED;
if (support_remote_image) {
if (enable_inline_image) {
if (image->width > 0 && image->width % pixel_per_char_i > 0)
image->width += (pixel_per_char_i - image->width % pixel_per_char_i);
+6 -39
View File
@@ -122,41 +122,7 @@ static int searchKeyNum(void);
#define help() fusage(stdout, 0)
#define usage() fusage(stderr, 1)
int support_remote_image;
static void
check_support_remote_image(void)
{
char *env;
if ((env = getenv("MLTERM"))) {
char *p;
int major;
int minor;
int micro;
if (!(p = strchr(env,'.')))
return;
*p = '\0';
major = atoi(env);
env = p + 1;
if (!(p = strchr(env,'.')))
return;
*p = '\0';
minor = atoi(env);
env = p + 1;
micro = atoi(env) ;
if (major > 3 ||
(major == 3 && (minor > 1 || (minor == 1 && micro >= 7)))) {
support_remote_image = 1 ;
set_environ( "W3M_USE_REMOTE_IMAGE","1"); /* for w3mimgdisplay */
}
}
return;
}
int enable_inline_image; /* 1 == mlterm OSC 5379, 2 == sixel */
static void
fversion(FILE * f)
@@ -445,7 +411,6 @@ main(int argc, char **argv, char **envp)
#if defined(DONT_CALL_GC_AFTER_FORK) && defined(USE_IMAGE)
char **getimage_args = NULL;
#endif /* defined(DONT_CALL_GC_AFTER_FORK) && defined(USE_IMAGE) */
check_support_remote_image();
GC_INIT();
#if defined(ENABLE_NLS) || (defined(USE_M17N) && defined(HAVE_LANGINFO_CODESET))
setlocale(LC_ALL, "");
@@ -715,9 +680,11 @@ main(int argc, char **argv, char **envp)
}
}
#endif
else if (!strcmp("-ri" , argv[i])) {
support_remote_image = 1;
set_environ( "W3M_USE_REMOTE_IMAGE","1"); /* for w3mimgdisplay */
else if (!strcmp("-ri", argv[i])) {
enable_inline_image = 1;
}
else if (!strcmp("-sixel", argv[i])) {
enable_inline_image = 2;
}
else if (!strcmp("-num", argv[i]))
showLineNum = TRUE;
+17 -1
View File
@@ -467,7 +467,7 @@ writestr(char *s)
#define MOVE(line,column) writestr(tgoto(T_cm,column,line));
void
put_image(char *url, int x, int y, int w, int h, int sx, int sy, int sw, int sh)
put_image_osc5379(char *url, int x, int y, int w, int h, int sx, int sy, int sw, int sh)
{
Str buf;
char *size ;
@@ -483,6 +483,22 @@ put_image(char *url, int x, int y, int w, int h, int sx, int sy, int sw, int sh)
MOVE(Currentbuf->cursorY,Currentbuf->cursorX);
}
void
put_image_sixel(char *url, int x, int y, int w, int h, int sx, int sy, int sw, int sh)
{
Str buf;
MOVE(y,x);
flush_tty();
buf = Sprintf("img2sixel -l disable -c %dx%d+%d+%d -w %d -h %d %s 2>/dev/null",
sw*pixel_per_char_i, sh*pixel_per_line_i,
sx*pixel_per_char_i, sy*pixel_per_line_i,
w*pixel_per_char_i, h*pixel_per_line_i,
url);
system(buf->ptr);
MOVE(Currentbuf->cursorY,Currentbuf->cursorX);
}
int
get_pixel_per_cell(int *ppc, int *ppl)
{