w3m

Unnamed repository; edit this file to name it for gitweb.
git clone https://logand.com/git/w3m.git/
Log | Files | Refs | README

commit 105ff7cd26f6740c61cc265d9d03d35d38f0cba6
parent caba3d3d3f6e6b3c03f04fa20e1992bdbcb7e46d
Author: ukai <ukai>
Date:   Mon,  7 Jul 2003 15:48:16 +0000

[w3m-dev 03929] clear image
* image.c (syncImage): added
	(drawImage): rewrite using syncImage()
	(clearImage): use clear image command (6)
* w3mimgdisplay.c: change protocol
	2 => terminate drawing
	6 => clear image
	(main): '2' calls TermImage()
		'6' calls ClearImage()
		TermImage() when exit
	(TermImage): renamed from ClearImage
	(ClearImage): rewritten to call w_op->clear()
* w3mimg.h/w3mimg.h (w3mimg_op): add clear()
* w3mimg/fb/fb.c (fb_clear): added
* w3mimg/fb/fb.h (fb_clear): added
* w3mimg/fb/fb_img.c (fb_image_clear): added
* w3mimg/fb/fb_w3mimg.c (w3mfb_clear): added
	(w3mimg_fbopen): initialize wop->clear
* w3mimg/x11/x11_w3mimg.c (x11_clear): added
	(w3mimg_x11open): initialize wop->clear
From: Hironori SAKAMOTO <hsaka@mth.biglobe.ne.jp>

Diffstat:
MChangeLog | 23+++++++++++++++++++++++
Mimage.c | 74+++++++++++++++++++++++++++++++++++++++-----------------------------------
Mw3mimg/fb/fb.c | 24++++++++++++++++++++++++
Mw3mimg/fb/fb.h | 1+
Mw3mimg/fb/fb_img.c | 6++++++
Mw3mimg/fb/fb_w3mimg.c | 10++++++++++
Mw3mimg/w3mimg.h | 1+
Mw3mimg/x11/x11_w3mimg.c | 14++++++++++++++
Mw3mimgdisplay.c | 43++++++++++++++++++++++++++++++++++++++-----
9 files changed, 156 insertions(+), 40 deletions(-)

diff --git a/ChangeLog b/ChangeLog @@ -1,5 +1,28 @@ 2003-07-08 Hironori SAKAMOTO <hsaka@mth.biglobe.ne.jp> + * [w3m-dev 03929] clear image + * image.c (syncImage): added + (drawImage): rewrite using syncImage() + (clearImage): use clear image command (6) + * w3mimgdisplay.c: change protocol + 2 => terminate drawing + 6 => clear image + (main): '2' calls TermImage() + '6' calls ClearImage() + TermImage() when exit + (TermImage): renamed from ClearImage + (ClearImage): rewritten to call w_op->clear() + * w3mimg.h/w3mimg.h (w3mimg_op): add clear() + * w3mimg/fb/fb.c (fb_clear): added + * w3mimg/fb/fb.h (fb_clear): added + * w3mimg/fb/fb_img.c (fb_image_clear): added + * w3mimg/fb/fb_w3mimg.c (w3mfb_clear): added + (w3mimg_fbopen): initialize wop->clear + * w3mimg/x11/x11_w3mimg.c (x11_clear): added + (w3mimg_x11open): initialize wop->clear + +2003-07-08 Hironori SAKAMOTO <hsaka@mth.biglobe.ne.jp> + * [w3m-dev 03927] deflate * file.c (compression_decoder): .deflate for application/x-deflate's extension diff --git a/image.c b/image.c @@ -149,6 +149,24 @@ addImage(ImageCache * cache, int x, int y, int sx, int sy, int w, int h) n_terminal_image++; } +static void +syncImage(void) +{ + fputs("3;\n", Imgdisplay_wf); /* XSync() */ + fputs("4;\n", Imgdisplay_wf); /* put '\n' */ + while (fflush(Imgdisplay_wf) != 0) { + if (ferror(Imgdisplay_wf)) + goto err; + } + if (!fgetc(Imgdisplay_rf)) + goto err; + return; + err: + closeImgdisplay(); + image_index += MAX_IMAGE; + n_terminal_image = 0; +} + void drawImage() { @@ -169,10 +187,6 @@ drawImage() if (!openImgdisplay()) return; } - if (!draw) { - fputs("3;\n", Imgdisplay_wf); /* XSync() */ - draw = TRUE; - } if (i->cache->index > 0) { i->cache->index *= -1; fputs("0;", Imgdisplay_wf); /* DrawImage() */ @@ -187,49 +201,39 @@ drawImage() fputs(buf, Imgdisplay_wf); fputs(i->cache->file, Imgdisplay_wf); fputs("\n", Imgdisplay_wf); - fputs("4;\n", Imgdisplay_wf); /* put '\n' */ - while (fflush(Imgdisplay_wf) != 0) { - if (ferror(Imgdisplay_wf)) - goto err; - } - if (!fgetc(Imgdisplay_rf)) - goto err; + draw = TRUE; } if (!draw) return; - fputs("3;\n", Imgdisplay_wf); /* XSync() */ - fputs("4;\n", Imgdisplay_wf); /* put '\n' */ - while (fflush(Imgdisplay_wf) != 0) { - if (ferror(Imgdisplay_wf)) - goto err; - } - if (!fgetc(Imgdisplay_rf)) - goto err; - /* - * touch_line(); - * touch_column(CurColumn); - * #ifdef JP_CHARSET - * if (CurColumn > 0 && - * CHMODE(ScreenImage[CurLine]->lineprop[CurColumn]) == C_WCHAR2) - * touch_column(CurColumn - 1); - * else if (CurColumn < COLS - 1 && - * CHMODE(ScreenImage[CurLine]->lineprop[CurColumn]) == C_WCHAR1) - * touch_column(CurColumn + 1); - * #endif - */ + syncImage(); touch_cursor(); refresh(); - return; - err: - closeImgdisplay(); - image_index += MAX_IMAGE; } void clearImage() { + static char buf[64]; + int j; + TerminalImage *i; + if (!activeImage) return; + if (!n_terminal_image) + return; + if (!Imgdisplay_wf) { + n_terminal_image = 0; + return; + } + for (j = 0; j < n_terminal_image; j++) { + i = &terminal_image[j]; + if (!(i->cache->loaded & IMG_FLAG_LOADED && + i->width > 0 && i->height > 0)) + continue; + sprintf(buf, "6;%d;%d;%d;%d\n", i->x, i->y, i->width, i->height); + fputs(buf, Imgdisplay_wf); + } + syncImage(); n_terminal_image = 0; } diff --git a/w3mimg/fb/fb.c b/w3mimg/fb/fb.c @@ -365,6 +365,30 @@ fb_height(void) return vscinfo.yres; } +int +fb_clear(int x, int y, int w, int h, int r, int g, int b) +{ + unsigned long bg; + int i, offset_fb; + + if (is_open != TRUE || x > fb_width() || y > fb_height()) + return 1; + if (x + w > fb_width()) + w = fb_width() - x; + if (y + h > fb_height()) + h = fb_height() - y; + + offset_fb = fscinfo.line_length * y + pixel_size * x; + bg = ((r >> (CHAR_BIT - vscinfo.red.length)) << vscinfo.red.offset) + + ((g >> (CHAR_BIT - vscinfo.green.length)) << vscinfo.green.offset) + + ((b >> (CHAR_BIT - vscinfo.blue.length)) << vscinfo.blue.offset); + for (i = 0; i < h; i++) { + memcpy(buf + offset_fb, bg, pixel_size * w); + offset_fb += fscinfo.line_length; + } + return 0; +} + /********* static functions **************/ static int diff --git a/w3mimg/fb/fb.h b/w3mimg/fb/fb.h @@ -29,5 +29,6 @@ int fb_open(void); void fb_close(void); int fb_width(void); int fb_height(void); +int fb_clear(int x, int y, int w, int h, int r, int g, int b); #endif diff --git a/w3mimg/fb/fb_img.c b/w3mimg/fb/fb_img.c @@ -24,3 +24,9 @@ fb_image_set_bg(int r, int g, int b) bg_g = g; bg_b = b; } + +int +fb_image_clear(int x, int y, int w, int h) +{ + return fb_clear(x, y, w, h, bg_r, bg_g, bg_b); +} diff --git a/w3mimg/fb/fb_w3mimg.c b/w3mimg/fb/fb_w3mimg.c @@ -61,6 +61,15 @@ w3mfb_close(w3mimg_op * self) } static int +w3mfb_clear(w3mimg_op * self, int x, int y, int w, int h) +{ + if (self == NULL) + return 0; + fb_image_clear(x, y, w, h); + return 1; +} + +static int w3mfb_load_image(w3mimg_op * self, W3MImage * img, char *fname, int w, int h) { FB_IMAGE **im; @@ -179,6 +188,7 @@ w3mimg_fbopen() wop->set_background = w3mfb_set_background; wop->sync = w3mfb_sync; wop->close = w3mfb_close; + wop->clear = w3mfb_clear; wop->load_image = w3mfb_load_image; wop->show_image = w3mfb_show_image; diff --git a/w3mimg/w3mimg.h b/w3mimg/w3mimg.h @@ -32,6 +32,7 @@ typedef struct _w3mimg_op { void (*free_image) (struct _w3mimg_op * self, W3MImage * img); int (*get_image_size) (struct _w3mimg_op * self, W3MImage * img, char *fname, int *w, int *h); + int (*clear) (struct _w3mimg_op * self, int x, int y, int w, int h); } w3mimg_op; #ifdef USE_W3MIMG_X11 diff --git a/w3mimg/x11/x11_w3mimg.c b/w3mimg/x11/x11_w3mimg.c @@ -123,6 +123,19 @@ x11_finish(w3mimg_op * self) } static int +x11_clear(w3mimg_op * self, int x, int y, int w, int h) +{ + struct x11_info *xi; + if (self == NULL) + return 0; + xi = (struct x11_info *)self->priv; + if (xi == NULL) + return 0; + XClearArea(xi->display, xi->window, x, y, w, h, FALSE); + return 1; +} + +static int x11_active(w3mimg_op * self) { struct x11_info *xi; @@ -688,6 +701,7 @@ w3mimg_x11open() wop->set_background = x11_set_background; wop->sync = x11_sync; wop->close = x11_close; + wop->clear = x11_clear; wop->load_image = x11_load_image; wop->show_image = x11_show_image; diff --git a/w3mimgdisplay.c b/w3mimgdisplay.c @@ -21,7 +21,8 @@ static int maxImage = 0, maxAnim = 100; static void GetOption(int argc, char **argv); static void DrawImage(char *buf, int redraw); -static void ClearImage(void); +static void TermImage(void); +static void ClearImage(char *buf); int main(int argc, char **argv) @@ -100,15 +101,18 @@ main(int argc, char **argv) * op args * 0; params draw image * 1; params redraw image - * 2; -none- clear image + * 2; -none- terminate drawing * 3; -none- sync drawing * 4; -none- nop, sync communication * response '\n' * 5; path get size of image, * response "<width> <height>\n" + * 6; params(6) clear image * * params * <n>;<x>;<y>;<w>;<h>;<sx>;<sy>;<sw>;<sh>;<path> + * params(6) + * <x>;<y>;<w>;<h> * */ switch (buf[0]) { @@ -119,7 +123,7 @@ main(int argc, char **argv) DrawImage(&buf[2], 1); break; case '2': - ClearImage(); + TermImage(); break; case '3': w_op->sync(w_op); @@ -144,9 +148,12 @@ main(int argc, char **argv) fflush(stdout); } break; + case '6': + ClearImage(&buf[2]); + break; } } - ClearImage(); + TermImage(); w_op->close(w_op); exit(0); } @@ -278,7 +285,7 @@ DrawImage(char *buf, int redraw) } void -ClearImage(void) +TermImage(void) { w_op->finish(w_op); if (imageBuf) { @@ -291,3 +298,29 @@ ClearImage(void) } maxImage = 0; } + +void +ClearImage(char *buf) +{ + char *p = buf; + int x = 0, y = 0, w = 0, h = 0; + + if (!p) + return; + for (; isdigit(*p); p++) + x = 10 * x + (*p - '0'); + if (*(p++) != ';') + return; + for (; isdigit(*p); p++) + y = 10 * y + (*p - '0'); + if (*(p++) != ';') + return; + for (; isdigit(*p); p++) + w = 10 * w + (*p - '0'); + if (*(p++) != ';') + return; + for (; isdigit(*p); p++) + h = 10 * h + (*p - '0'); + + w_op->clear(w_op, x, y, w, h); +}