13 #include "osdep/image.h"
14 #include "osdep/osdep.h"
15 #include "util/error.h"
20 image_helper(struct image_ctx
*img
, int xfd
)
23 dup2(img
->pipe_to
[0], 0); dup2(img
->pipe_from
[1], 1);
24 close(img
->pipe_to
[0]); close(img
->pipe_to
[1]);
25 close(img
->pipe_from
[0]); close(img
->pipe_from
[1]);
26 execl(DEFAULT_IMGHELPER_CMD
, DEFAULT_IMGHELPER_CMD
, NULL
);
32 struct image_ctx
*img
= calloc(1, sizeof(*img
));
34 setenv("W3M_TTY", ttyname(0), 0);
37 c_pipe(img
->pipe_from
);
38 close(start_thread((void (*)(void *, int)) image_helper
, img
, 0));
39 close(img
->pipe_to
[0]);
40 close(img
->pipe_from
[1]);
46 done_images(struct image_ctx
*img
)
48 safe_write(img
->pipe_to
[1], "2;\n", 3);
49 close(img
->pipe_to
[1]);
50 close(img
->pipe_from
[0]);
56 slave_images_getres(struct image_ctx
*img
, int *xres
, int *yres
)
60 p
= popen(DEFAULT_IMGHELPER_CMD
" -test", "r");
61 if (!p
) return; // XXX
62 fscanf(p
, "%d %d", &img
->xres
, &img
->yres
);
65 if (xres
) *xres
= img
->xres
;
66 if (yres
) *yres
= img
->yres
;
70 slave_render_image(struct image_ctx
*img
, int imgid
, struct box
*box
, unsigned char *file
)
72 unsigned char buf
[4096];
74 if (img
->images
[imgid
].file
)
75 free(img
->images
[imgid
].file
);
76 img
->images
[imgid
].file
= strdup(file
);
77 copy_box(&img
->images
[imgid
].box
, box
);
78 img
->images
[imgid
].visible
= 1;
80 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
);
81 safe_write(img
->pipe_to
[1], buf
, strlen(buf
));
85 slave_hide_image_region(struct image_ctx
*img
, struct box
*region
)
87 unsigned char buf
[4096];
89 snprintf(buf
, sizeof(buf
), "6;%d;%d;%d;%d\n", region
->x
, region
->y
, region
->width
, region
->height
);
90 safe_write(img
->pipe_to
[1], buf
, strlen(buf
));
94 slave_sync_images(struct image_ctx
*img
)
97 safe_write(img
->pipe_to
[1], "3;\n", 3);
98 /* Return '\n' for synchronization */
99 safe_write(img
->pipe_to
[1], "4;\n", 3);
101 if (safe_read(img
->pipe_from
[0], &nl
, 1) < 0) {
102 INTERNAL("Communication with w3mimgdisplay failed.");
108 image_size(unsigned char *file
, int *w
, int *h
)
110 unsigned char pcmd
[4096];
113 snprintf(pcmd
, sizeof(pcmd
), "%s -size %s", DEFAULT_IMGHELPER_CMD
, file
);
114 p
= popen(pcmd
, "r");
115 if (!p
) return; // XXX
116 fscanf(p
, "%d %d", w
, h
);