[w3m-dev 03930] Re: clear image
Hironori SAKAMOTO <[email protected]>
| Newsgroups | gmane.comp.web.w3m.devel |
|---|---|
| Message-ID | <[email protected]> |
> > rxvt(aterm,Eterm,etc) mlterm CVS > > frame buffer > (_ _) > # Zaurus SL-C700 embeddedkonsole > # w3mimgfb > # SL-C700 netmaj + w3mimgdisplay > # # ----------------------------------- <[email protected]> http://www2u.biglobe.ne.jp/~hsaka/ diff -u image.c.orig image.c --- image.c.orig Tue May 13 10:27:31 2003 +++ image.c Mon Jul 7 20:50:18 2003 @@ -149,6 +149,24 @@ 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 @@ 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 @@ 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 -u w3mimgdisplay.c.orig w3mimgdisplay.c --- w3mimgdisplay.c.orig Fri Mar 28 10:05:13 2003 +++ w3mimgdisplay.c Tue Jul 8 09:52:25 2003 @@ -21,7 +21,8 @@ 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 @@ * 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 @@ DrawImage(&buf[2], 1); break; case '2': - ClearImage(); + TermImage(); break; case '3': w_op->sync(w_op); @@ -144,9 +148,12 @@ fflush(stdout); } break; + case '6': + ClearImage(&buf[2]); + break; } } - ClearImage(); + TermImage(); w_op->close(w_op); exit(0); } @@ -278,7 +285,7 @@ } void -ClearImage(void) +TermImage(void) { w_op->finish(w_op); if (imageBuf) { @@ -290,4 +297,30 @@ imageBuf = NULL; } 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 + offset_x, y + offset_y, w, h); } diff -u w3mimg/w3mimg.h.orig w3mimg/w3mimg.h --- w3mimg/w3mimg.h.orig Fri Mar 28 10:06:07 2003 +++ w3mimg/w3mimg.h Mon Jul 7 15:45:20 2003 @@ -32,6 +32,7 @@ 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 -u w3mimg/fb/fb.c.orig w3mimg/fb/fb.c --- w3mimg/fb/fb.c.orig Fri Nov 1 10:30:44 2002 +++ w3mimg/fb/fb.c Tue Jul 8 09:54:57 2003 @@ -365,6 +365,31 @@ return vscinfo.yres; } +int +fb_clear(int x, int y, int w, int h, int r, int g, int b) +{ + unsigned long work; + int i, j, 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; + work = ((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++) { + for (j = 0; j < w; j++) + memcpy(buf + offset_fb + pixel_size * j, &work, pixel_size); + offset_fb += fscinfo.line_length; + } + return 0; +} + /********* static functions **************/ static int diff -u w3mimg/fb/fb.h.orig w3mimg/fb/fb.h --- w3mimg/fb/fb.h.orig Mon Oct 21 16:53:07 2002 +++ w3mimg/fb/fb.h Mon Jul 7 20:28:29 2003 @@ -29,5 +29,6 @@ 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 -u w3mimg/fb/fb_img.c.orig w3mimg/fb/fb_img.c --- w3mimg/fb/fb_img.c.orig Mon Oct 21 16:53:10 2002 +++ w3mimg/fb/fb_img.c Mon Jul 7 20:20:27 2003 @@ -24,3 +24,9 @@ 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 -u w3mimg/fb/fb_w3mimg.c.orig w3mimg/fb/fb_w3mimg.c --- w3mimg/fb/fb_w3mimg.c.orig Mon Apr 7 11:54:13 2003 +++ w3mimg/fb/fb_w3mimg.c Mon Jul 7 20:32:25 2003 @@ -61,6 +61,15 @@ } 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 @@ 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 -u w3mimg/x11/x11_w3mimg.c.orig w3mimg/x11/x11_w3mimg.c --- w3mimg/x11/x11_w3mimg.c.orig Fri Jun 20 13:52:54 2003 +++ w3mimg/x11/x11_w3mimg.c Mon Jul 7 15:46:01 2003 @@ -123,6 +123,19 @@ } 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 @@ 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;