mirror of
https://github.com/rkd77/elinks.git
synced 2025-06-30 22:19:29 -04:00
Merge branch 'elsix'
This commit is contained in:
commit
32ab019299
@ -29,6 +29,7 @@
|
||||
#include "config/options.h"
|
||||
#include "config/kbdbind.h"
|
||||
#include "document/html/frames.h"
|
||||
#include "document/html/parser/general.h"
|
||||
#include "document/html/parser/link.h"
|
||||
#include "document/html/parser/parse.h"
|
||||
#include "document/html/parser/stack.h"
|
||||
@ -37,6 +38,10 @@
|
||||
#include "globhist/globhist.h"
|
||||
#include "mime/mime.h"
|
||||
#include "protocol/uri.h"
|
||||
#ifdef CONFIG_LIBSIXEL
|
||||
#include "terminal/sixel.h"
|
||||
#endif
|
||||
#include "util/base64.h"
|
||||
#include "util/conv.h"
|
||||
#include "util/error.h"
|
||||
#include "util/memdebug.h"
|
||||
@ -222,6 +227,46 @@ put_image_label(char *a, char *label,
|
||||
elformat.style.attr = saved_attr;
|
||||
}
|
||||
|
||||
static void
|
||||
html_img_sixel(struct html_context *html_context, char *a,
|
||||
char *html, char *eof, char **end)
|
||||
{
|
||||
#ifdef CONFIG_LIBSIXEL
|
||||
if (!html_context->options->sixel || !html_context->part->document || html_context->table_level) {
|
||||
return;
|
||||
}
|
||||
char *elsix = get_attr_val(a, "elsix", html_context->doc_cp);
|
||||
|
||||
if (!elsix) {
|
||||
return;
|
||||
}
|
||||
struct string pixels;
|
||||
|
||||
if (!init_string(&pixels)) {
|
||||
mem_free(elsix);
|
||||
return;
|
||||
}
|
||||
int datalen;
|
||||
unsigned char *data = base64_decode_bin((const unsigned char *)elsix, strlen(elsix), &datalen);
|
||||
|
||||
mem_free(elsix);
|
||||
|
||||
if (!data) {
|
||||
done_string(&pixels);
|
||||
return;
|
||||
}
|
||||
add_bytes_to_string(&pixels, (const char *)data, datalen);
|
||||
mem_free(data);
|
||||
struct document *document = html_context->document;
|
||||
html_linebrk(html_context, a, html, eof, end);
|
||||
|
||||
int lineno = html_context->part->cy + html_context->part->box.y;
|
||||
int how_many = add_image_to_document(document, &pixels, lineno) + 1;
|
||||
done_string(&pixels);
|
||||
ln_break(html_context, how_many);
|
||||
#endif
|
||||
}
|
||||
|
||||
static void
|
||||
html_img_do(char *a, char *object_src,
|
||||
struct html_context *html_context)
|
||||
@ -258,7 +303,7 @@ html_img_do(char *a, char *object_src,
|
||||
elformat.form = NULL;
|
||||
elformat.style.attr |= AT_BOLD;
|
||||
usemap = 1;
|
||||
}
|
||||
}
|
||||
|
||||
ismap = elformat.link
|
||||
&& has_attr(a, "ismap", html_context->doc_cp)
|
||||
@ -365,8 +410,11 @@ html_img_do(char *a, char *object_src,
|
||||
|
||||
void
|
||||
html_img(struct html_context *html_context, char *a,
|
||||
char *xxx3, char *xxx4, char **xxx5)
|
||||
char *html, char *eof, char **end)
|
||||
{
|
||||
#ifdef CONFIG_LIBSIXEL
|
||||
html_img_sixel(html_context, a, html, eof, end);
|
||||
#endif
|
||||
html_img_do(a, NULL, html_context);
|
||||
}
|
||||
|
||||
|
@ -903,9 +903,8 @@ end:
|
||||
return ile;
|
||||
}
|
||||
|
||||
|
||||
struct image *
|
||||
copy_frame(struct image *src, int box_width, int box_height, int cell_width, int cell_height, int dx, int dy)
|
||||
copy_frame(struct image *src, struct el_box *box, int cell_width, int cell_height, int dx, int dy)
|
||||
{
|
||||
sixel_decoder_t *decoder = NULL;
|
||||
sixel_encoder_t *encoder = NULL;
|
||||
@ -977,12 +976,27 @@ copy_frame(struct image *src, int box_width, int box_height, int cell_width, int
|
||||
if (SIXEL_FAILED(status)) {
|
||||
goto end;
|
||||
}
|
||||
x = src->x - dx;
|
||||
y = src->y - dy;
|
||||
x = src->x - box->x - dx;
|
||||
y = src->y - box->y - dy;
|
||||
|
||||
encoder->clipx = x >= 0 ? 0 : (-x * cell_width);
|
||||
encoder->clipy = y >= 0 ? 0 : (-y * cell_height);
|
||||
encoder->clipwidth = box_width * cell_width;
|
||||
encoder->clipheight = box_height * cell_height;
|
||||
encoder->clipwidth = box->width * cell_width;
|
||||
encoder->clipheight = box->height * cell_height;
|
||||
|
||||
if (src->width < encoder->clipwidth) {
|
||||
encoder->clipwidth = src->width;
|
||||
}
|
||||
if (src->height < encoder->clipheight) {
|
||||
encoder->clipheight = src->height;
|
||||
}
|
||||
|
||||
if (x * cell_width + encoder->clipwidth >= box->width * cell_width) {
|
||||
encoder->clipwidth = (box->width * cell_width - x * cell_width);
|
||||
}
|
||||
if (y * cell_height + encoder->clipheight >= box->height * cell_height) {
|
||||
encoder->clipheight = (box->height * cell_height - y * cell_height);
|
||||
}
|
||||
status = sixel_output_new(&output, sixel_write_callback, &dest->pixels, NULL);
|
||||
|
||||
if (SIXEL_FAILED(status)) {
|
||||
@ -993,15 +1007,21 @@ copy_frame(struct image *src, int box_width, int box_height, int cell_width, int
|
||||
if (SIXEL_FAILED(status)) {
|
||||
goto end;
|
||||
}
|
||||
dest->x = x < 0 ? 0 : x;
|
||||
dest->y = y < 0 ? 1 : y;
|
||||
dest->width = src->width;
|
||||
dest->height = src->height;
|
||||
dest->x = x < box->x ? box->x : x;
|
||||
dest->y = y < box->y ? box->y : y;
|
||||
dest->width = encoder->clipx >= src->width ? 0 : sixel_frame_get_width(frame);
|
||||
dest->height = encoder->clipy >= src->height ? 0 : sixel_frame_get_height(frame);
|
||||
end:
|
||||
sixel_frame_unref(frame);
|
||||
sixel_output_unref(output);
|
||||
sixel_decoder_unref(decoder);
|
||||
sixel_encoder_unref(encoder);
|
||||
|
||||
if (!dest->width || !dest->height) {
|
||||
done_string(&dest->pixels);
|
||||
mem_free(dest);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return dest;
|
||||
}
|
||||
|
@ -11,6 +11,7 @@ extern "C" {
|
||||
|
||||
#ifdef CONFIG_LIBSIXEL
|
||||
struct document;
|
||||
struct el_box;
|
||||
struct terminal;
|
||||
|
||||
|
||||
@ -30,7 +31,7 @@ void try_to_draw_images(struct terminal *term);
|
||||
/* return height of image in terminal rows */
|
||||
int add_image_to_document(struct document *doc, struct string *pixels, int lineno);
|
||||
|
||||
struct image *copy_frame(struct image *src, int box_width, int box_height, int cell_width, int cell_height, int dx, int dy);
|
||||
struct image *copy_frame(struct image *src, struct el_box *box, int cell_width, int cell_height, int dx, int dy);
|
||||
|
||||
|
||||
#endif
|
||||
|
@ -504,7 +504,7 @@ draw_doc(struct session *ses, struct document_view *doc_view, int active)
|
||||
continue;
|
||||
}
|
||||
|
||||
struct image *im_copy = copy_frame(&im, box->width, box->height, term->cell_width, term->cell_height, vs->x, vs->y);
|
||||
struct image *im_copy = copy_frame(&im, box, term->cell_width, term->cell_height, vs->x, vs->y);
|
||||
|
||||
if (im_copy) {
|
||||
add_to_list(term->images, im_copy);
|
||||
|
Loading…
x
Reference in New Issue
Block a user