- Adjust the image size to the terminal cell size. - If the image size is specified in html source, skip to load the image.

This commit is contained in:
Araki Ken
2013-02-02 16:32:37 +09:00
committed by Tatsuya Kinoshita
parent f4268d8d18
commit 147ef0048b
3 changed files with 55 additions and 33 deletions

2
fm.h
View File

@@ -1177,9 +1177,11 @@ global char *ssl_forbid_method init("2, 3");
global int is_redisplay init(FALSE); global int is_redisplay init(FALSE);
global int clear_buffer init(TRUE); global int clear_buffer init(TRUE);
global double pixel_per_char init(DEFAULT_PIXEL_PER_CHAR); global double pixel_per_char init(DEFAULT_PIXEL_PER_CHAR);
global int pixel_per_char_i init(DEFAULT_PIXEL_PER_CHAR);
global int set_pixel_per_char init(FALSE); global int set_pixel_per_char init(FALSE);
#ifdef USE_IMAGE #ifdef USE_IMAGE
global double pixel_per_line init(DEFAULT_PIXEL_PER_LINE); global double pixel_per_line init(DEFAULT_PIXEL_PER_LINE);
global int pixel_per_line_i init(DEFAULT_PIXEL_PER_LINE);
global int set_pixel_per_line init(FALSE); global int set_pixel_per_line init(FALSE);
global double image_scale init(100); global double image_scale init(100);
#endif #endif

41
image.c
View File

@@ -57,6 +57,8 @@ getCharSize()
int ppc, ppl; int ppc, ppl;
if (get_pixel_per_cell(&ppc,&ppl)) { if (get_pixel_per_cell(&ppc,&ppl)) {
pixel_per_char_i = ppc ;
pixel_per_line_i = ppl ;
pixel_per_char = (double)ppc; pixel_per_char = (double)ppc;
pixel_per_line = (double)ppl; pixel_per_line = (double)ppl;
} }
@@ -210,7 +212,7 @@ drawImage()
i->cache->width > 0 ? i->cache->width : 0, i->cache->width > 0 ? i->cache->width : 0,
i->cache->height > 0 ? i->cache->height : 0, i->cache->height > 0 ? i->cache->height : 0,
i->sx, i->sy, i->width, i->height, i->sx, i->sy, i->width, i->height,
(int)pixel_per_char, (int)pixel_per_line); pixel_per_char_i, pixel_per_line_i);
#endif #endif
put_image( put_image(
#if 1 #if 1
@@ -220,27 +222,25 @@ drawImage()
#else #else
i->cache->url, i->cache->url,
#endif #endif
(int)(i->x / pixel_per_char), i->x / pixel_per_char_i,
(int)(i->y / pixel_per_line), i->y / pixel_per_line_i,
#if 1 #if 1
i->cache->a_width > 0 ? i->cache->a_width > 0 ?
(int)((i->cache->width + i->x % (int)pixel_per_char + (i->cache->width + i->x % pixel_per_char_i + pixel_per_char_i - 1) /
pixel_per_char - 1) / pixel_per_char) : pixel_per_char_i :
#endif #endif
0, 0,
#if 1 #if 1
i->cache->a_height > 0 ? i->cache->a_height > 0 ?
(int)((i->cache->height + i->y % (int)pixel_per_line + (i->cache->height + i->y % pixel_per_line_i + pixel_per_line_i - 1) /
pixel_per_line - 1) / pixel_per_line) : pixel_per_line_i :
#endif #endif
0, 0,
(int)(i->sx / pixel_per_char), i->sx / pixel_per_char_i,
(int)(i->sy / pixel_per_line), i->sy / pixel_per_line_i,
(int)((i->width + i->sx % (int)pixel_per_char + (i->width + i->sx % pixel_per_char_i + pixel_per_char_i - 1) / pixel_per_char_i,
pixel_per_char - 1) / pixel_per_char), (i->height + i->sy % pixel_per_line_i + pixel_per_line_i - 1) / pixel_per_line_i);
(int)((i->height + i->sy % (int)pixel_per_line +
pixel_per_line - 1) / pixel_per_line));
continue ; continue ;
} }
@@ -593,8 +593,19 @@ getImage(Image * image, ParsedURL *current, int flag)
cache->pid = 0; cache->pid = 0;
cache->index = 0; cache->index = 0;
cache->loaded = IMG_FLAG_UNLOADED; cache->loaded = IMG_FLAG_UNLOADED;
cache->width = image->width; if (support_remote_image) {
cache->height = image->height; if (image->width > 0 && image->width % pixel_per_char_i > 0)
image->width += (pixel_per_char_i - image->width % pixel_per_char_i);
if (image->height > 0 && image->height % pixel_per_line_i > 0)
image->height += (pixel_per_line_i - image->height % pixel_per_line_i);
if (image->height > 0 && image->width > 0)
cache->loaded = IMG_FLAG_LOADED;
}
cache->width = image->width ;
cache->height = image->height ;
cache->a_width = image->width; cache->a_width = image->width;
cache->a_height = image->height; cache->a_height = image->height;
putHash_sv(image_hash, key->ptr, (void *)cache); putHash_sv(image_hash, key->ptr, (void *)cache);

45
terms.c
View File

@@ -489,31 +489,40 @@ get_pixel_per_cell(int *ppc, int *ppl)
fd_set rfd; fd_set rfd;
struct timeval tval; struct timeval tval;
char buf[100]; char buf[100];
char *p;
ssize_t len; ssize_t len;
ssize_t left;
int wp,hp,wc,hc; int wp,hp,wc,hc;
int i;
fputs("\x1b[14t\x1b[18t",ttyf); flush_tty(); fputs("\x1b[14t\x1b[18t",ttyf); flush_tty();
tval.tv_usec = 10000; /* 0.1 sec */ p = buf;
tval.tv_sec = 0; left = sizeof(buf) - 1;
FD_SET(tty,&rfd); for (i = 0; i < 5; i++) {
if (select(tty+1,&rfd,NULL,NULL,&tval) < 0 || ! FD_ISSET(tty,&rfd)) { tval.tv_usec = 100000; /* 0.1 sec */
return 0; tval.tv_sec = 0;
FD_SET(tty,&rfd);
if (select(tty+1,&rfd,NULL,NULL,&tval) <= 0 || ! FD_ISSET(tty,&rfd)) {
continue;
}
if ((len = read(tty,p,left)) <= 0) {
return 0;
}
p[len] = '\0';
if (sscanf(buf,"\x1b[4;%d;%dt\x1b[8;%d;%dt",&hp,&wp,&hc,&wc) == 4) {
*ppc = wp / wc;
*ppl = hp / hc;
return 1;
}
p = buf + len;
left -= len;
} }
if ((len = read(tty,buf,sizeof(buf)-1)) <= 0) { return 0;
return 0;
}
buf[len] = '\0';
if (sscanf(buf,"\x1b[4;%d;%dt\x1b[8;%d;%dt",&hp,&wp,&hc,&wc) != 4) {
return 0;
}
*ppc = wp / wc;
*ppl = hp / hc;
return 1;
} }
#ifdef USE_MOUSE #ifdef USE_MOUSE