From 46de70ba31590f2e1db9d88ec2fa9ebb8473f1c5 Mon Sep 17 00:00:00 2001 From: Petr Baudis Date: Tue, 4 Oct 2011 00:52:21 +0200 Subject: [PATCH] [wip] show_image(): Introduce crop_box to specify visible part of the image --- src/osdep/image.c | 2 +- src/osdep/image.h | 2 +- src/osdep/unix/image.c | 15 ++++++++++++--- src/terminal/image.c | 8 +++++--- src/terminal/image.h | 2 +- src/terminal/kbd.c | 9 ++++++--- src/viewer/text/draw.c | 22 ++++++++-------------- 7 files changed, 34 insertions(+), 26 deletions(-) diff --git a/src/osdep/image.c b/src/osdep/image.c index 82df1ec0..4fc38545 100644 --- a/src/osdep/image.c +++ b/src/osdep/image.c @@ -30,7 +30,7 @@ slave_images_getres(struct image_ctx *img, int *xres, int *yres) } void -slave_render_image(struct image_ctx *img, int imgid, int x, int y, unsigned char *file, int w, int h) +slave_render_image(struct image_ctx *img, int imgid, struct box *img_box, struct box *crop_box, unsigned char *file); { } diff --git a/src/osdep/image.h b/src/osdep/image.h index a0135d1b..fd969e88 100644 --- a/src/osdep/image.h +++ b/src/osdep/image.h @@ -30,7 +30,7 @@ extern struct image_ctx *init_images(); // NULL if N/A extern void done_images(struct image_ctx *img); extern void slave_images_getres(struct image_ctx *img, int *xres, int *yres); -extern void slave_render_image(struct image_ctx *img, int imgid, struct box *box, unsigned char *file); +extern void slave_render_image(struct image_ctx *img, int imgid, struct box *img_box, struct box *crop_box, unsigned char *file); extern void slave_hide_image_region(struct image_ctx *img, struct box *region); extern void slave_sync_images(struct image_ctx *img); diff --git a/src/osdep/unix/image.c b/src/osdep/unix/image.c index c143643e..b4912184 100644 --- a/src/osdep/unix/image.c +++ b/src/osdep/unix/image.c @@ -67,17 +67,26 @@ slave_images_getres(struct image_ctx *img, int *xres, int *yres) } void -slave_render_image(struct image_ctx *img, int imgid, struct box *box, unsigned char *file) +slave_render_image(struct image_ctx *img, int imgid, struct box *img_box, struct box *crop_box, unsigned char *file) { unsigned char buf[4096]; + int sx, sy; if (img->images[imgid].file) free(img->images[imgid].file); img->images[imgid].file = strdup(file); - copy_box(&img->images[imgid].box, box); + copy_box(&img->images[imgid].box, img_box); img->images[imgid].visible = 1; - snprintf(buf, sizeof(buf), "0;%d;%d;%d;%d;%d;%d;%d;%d;%d;%s\n", imgid, img->images[imgid].box.x, img->images[imgid].box.y, img->images[imgid].box.width, img->images[imgid].box.height, 0, 0, 0, 0, img->images[imgid].file); + sx = crop_box->x - img_box->x; + sy = crop_box->y - img_box->y; + + snprintf(buf, sizeof(buf), "0;%d;%d;%d;%d;%d;%d;%d;%d;%d;%s\n", imgid, + crop_box->x, crop_box->y, + img_box->width, img_box->height, + sx, sy, + crop_box->width, crop_box->height, + img->images[imgid].file); safe_write(img->pipe_to[1], buf, strlen(buf)); } diff --git a/src/terminal/image.c b/src/terminal/image.c index 4b4b66f6..7aa01cdd 100644 --- a/src/terminal/image.c +++ b/src/terminal/image.c @@ -26,7 +26,7 @@ void -show_image(struct terminal *term, int imgid, struct box *box, struct cache_entry *ce) +show_image(struct terminal *term, int imgid, struct box *img_box, struct box *crop_box, struct cache_entry *ce) { struct string s; int fd; @@ -56,8 +56,10 @@ show_image(struct terminal *term, int imgid, struct box *box, struct cache_entry if (!init_string(&s)) return; - add_format_to_string(&s, "%d %d %d %s %d %d", imgid, box->x, box->y, - term->imgfiles[imgid], box->width, box->height); + add_format_to_string(&s, "%d %d %d %d %d %d %d %d %d %s", imgid, + img_box->x, img_box->y, img_box->width, img_box->height, + crop_box->x, crop_box->y, crop_box->width, crop_box->height, + term->imgfiles[imgid]); do_terminal_function(term, TERM_FN_IMG_DRAW, s.source); done_string(&s); } diff --git a/src/terminal/image.h b/src/terminal/image.h index 402f3257..41156b32 100644 --- a/src/terminal/image.h +++ b/src/terminal/image.h @@ -5,7 +5,7 @@ struct box; struct cache_entry; struct terminal; -extern void show_image(struct terminal *term, int imgid, struct box *box, struct cache_entry *ce); +extern void show_image(struct terminal *term, int imgid, struct box *img_box, struct box *crop_box, struct cache_entry *ce); extern void sync_images(struct terminal *term); extern void get_image_size(struct cache_entry *ce, int *w, int *h); diff --git a/src/terminal/kbd.c b/src/terminal/kbd.c index 91d049a1..dd5120fd 100644 --- a/src/terminal/kbd.c +++ b/src/terminal/kbd.c @@ -561,11 +561,14 @@ dispatch_special(unsigned char *text) case TERM_FN_IMG_DRAW: if (ditrm && ditrm->image_h) { int imgid; - struct box b; + struct box img_box, crop_box; unsigned char file[4096]; - sscanf(text + 1, "%d %d %d %s %d %d", &imgid, &b.x, &b.y, file, &b.width, &b.height); - slave_render_image(ditrm->image_h, imgid, &b, file); + sscanf(text + 1, "%d %d %d %d %d %d %d %d %d %s", &imgid, + &img_box.x, &img_box.y, &img_box.width, &img_box.height, + &crop_box.x, &crop_box.y, &crop_box.width, &crop_box.height, + file); + slave_render_image(ditrm->image_h, imgid, &img_box, &crop_box, file); } break; case TERM_FN_IMG_HIDE_REG: diff --git a/src/viewer/text/draw.c b/src/viewer/text/draw.c index f0b566af..1a02dc8d 100644 --- a/src/viewer/text/draw.c +++ b/src/viewer/text/draw.c @@ -186,21 +186,18 @@ draw_images(struct session *ses, struct document_view *doc_view, struct view_sta /* Character width, height in pixels. */ chw = term->xres / term->width; chh = term->yres / term->height; - //printf("RES %d/%d->%d %d/%d->%d\n", term->xres, term->width, chw, term->yres, term->height, chh); set_box(&win_pixbox, win_box->x * chw, win_box->y * chh, win_box->width * chw, win_box->height * chh); set_box(&vs_pixbox, vs->x * chw, vs->y * chh, win_pixbox.width, win_pixbox.height); - //printf("ni %d\n", document->nimages); - for (i = 0; i < document->nimages; i++) { struct image *img = &document->images[i]; struct cache_entry *cached; struct box img_pixbox; + struct box winimg_pixbox; /* Fetch cache entry. */ cached = get_redirected_cache_entry(img->uri); - //printf("ce %p %d\n", cached, cached ? cached->incomplete : -1); if (!cached || cached->incomplete) continue; @@ -213,17 +210,14 @@ draw_images(struct session *ses, struct document_view *doc_view, struct view_sta if (img->h < 0) img->h = h; } - set_box(&img_pixbox, img->pos.x * chw, img->pos.y * chh, img->w, img->h); - - if (is_in_box(&vs_pixbox, img_pixbox.x, img_pixbox.y)) { - /* Arrange the image in the tab window bounding box. */ - img_pixbox.x = win_pixbox.x + img_pixbox.x - vs_pixbox.x; - img_pixbox.y = win_pixbox.y + img_pixbox.y - vs_pixbox.y; - img_pixbox.width = int_min(img_pixbox.width, win_pixbox.width - img_pixbox.x); - img_pixbox.height = int_min(img_pixbox.height, win_pixbox.height - img_pixbox.y); + img_pixbox.x = win_pixbox.x + img->pos.x * chw - vs_pixbox.x, + img_pixbox.y = win_pixbox.y + img->pos.y * chh - vs_pixbox.y, + img_pixbox.width = img->w; + img_pixbox.height = img->h; - show_image(term, cnt++, &img_pixbox, cached); - } + box_intersect(&winimg_pixbox, &img_pixbox, &win_pixbox); + if (winimg_pixbox.width > 0 && winimg_pixbox.height > 0) + show_image(term, cnt++, &img_pixbox, &winimg_pixbox, cached); } sync_images(term); -- 2.11.4.GIT