1 /** Support for image rendering
12 #include <sys/types.h>
18 #include "cache/cache.h"
19 #include "osdep/image.h"
20 #include "osdep/osdep.h"
21 #include "terminal/terminal.h"
22 #include "terminal/image.h"
23 #include "util/error.h"
24 #include "util/memory.h"
25 #include "util/string.h"
29 show_image(struct terminal
*term
, int imgid
, struct box
*box
, struct cache_entry
*ce
)
36 if (!term
->imgfiles
[imgid
]) {
37 /* FIXME: We hardcode /tmp here. */
38 term
->imgfiles
[imgid
] = stracpy("/tmp/elinksimgXXXXXX");
39 fd
= mkstemp(term
->imgfiles
[imgid
]);
41 fd
= open(term
->imgfiles
[imgid
], O_WRONLY
);
44 if (term
->imgfiles
[imgid
]) {
45 unlink(term
->imgfiles
[imgid
]);
46 mem_free(term
->imgfiles
[imgid
]);
48 /* FIXME: We hardcode /tmp here. */
49 term
->imgfiles
[imgid
] = stracpy("/tmp/elinksimgXXXXXX");
50 fd
= mkstemp(term
->imgfiles
[imgid
]);
52 f
= get_cache_fragment(ce
);
53 assert(f
->offset
== 0);
54 safe_write(fd
, f
->data
, f
->length
);
59 add_format_to_string(&s
, "%d %d %d %s %d %d", imgid
, box
->x
, box
->y
,
60 term
->imgfiles
[imgid
], box
->width
, box
->height
);
61 do_terminal_function(term
, TERM_FN_IMG_DRAW
, s
.source
);
66 move_image(struct terminal
*term
, int imgid
, int x
, int y
)
72 add_format_to_string(&s
, "%d %d %d", imgid
, x
, y
);
73 do_terminal_function(term
, TERM_FN_IMG_MOVE
, s
.source
);
78 hide_image(struct terminal
*term
, int imgid
)
84 add_format_to_string(&s
, "%d", imgid
);
85 do_terminal_function(term
, TERM_FN_IMG_HIDE
, s
.source
);
90 sync_images(struct terminal
*term
)
92 do_terminal_function(term
, TERM_FN_IMG_SYNC
, "");
98 get_image_size(struct cache_entry
*ce
, int *w
, int *h
)
102 unsigned char tmpfile
[] = "/tmp/elinksimgXXXXXX";
104 fd
= mkstemp(tmpfile
);
105 f
= get_cache_fragment(ce
);
106 assert(f
->offset
== 0);
107 safe_write(fd
, f
->data
, f
->length
);
110 image_size(tmpfile
, w
, h
);