mirror of
https://github.com/rkd77/elinks.git
synced 2025-06-30 22:19:29 -04:00
[sixel] sixel_allocator also in image.c
el_sixel_allocator is NULL when not initialised by init_sixel_allocator.
This commit is contained in:
parent
bf6ebe2687
commit
71a99b4436
@ -25,6 +25,7 @@
|
||||
#include "terminal/kitty.h"
|
||||
#endif
|
||||
#include "util/base64.h"
|
||||
#include "util/memcount.h"
|
||||
#include "util/memory.h"
|
||||
#include "util/string.h"
|
||||
|
||||
@ -99,6 +100,21 @@ el_kitty_get_image(char *data, int length, int *width, int *height, int *compres
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_LIBSIXEL
|
||||
sixel_allocator_t *el_sixel_allocator;
|
||||
|
||||
#ifdef CONFIG_MEMCOUNT
|
||||
void
|
||||
init_sixel_allocator(void)
|
||||
{
|
||||
ELOG
|
||||
static int initialized = 0;
|
||||
if (!initialized) {
|
||||
sixel_allocator_new(&el_sixel_allocator, el_sixel_malloc, el_sixel_calloc, el_sixel_realloc, el_sixel_free);
|
||||
initialized = 1;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
static int
|
||||
sixel_write_callback(char *data, int size, void *priv)
|
||||
{
|
||||
@ -128,7 +144,10 @@ el_sixel_get_image(char *data, int length, int *outlen)
|
||||
if (!init_string(&ret)) {
|
||||
goto end;
|
||||
}
|
||||
SIXELSTATUS status = sixel_output_new(&output, sixel_write_callback, &ret, NULL);
|
||||
#ifdef CONFIG_MEMCOUNT
|
||||
init_sixel_allocator();
|
||||
#endif
|
||||
SIXELSTATUS status = sixel_output_new(&output, sixel_write_callback, &ret, el_sixel_allocator);
|
||||
|
||||
if (SIXEL_FAILED(status)) {
|
||||
goto end;
|
||||
|
@ -1,6 +1,10 @@
|
||||
#ifndef EL__TERMINAL_IMAGE_H
|
||||
#define EL__TERMINAL_IMAGE_H
|
||||
|
||||
#ifdef CONFIG_LIBSIXEL
|
||||
#include <sixel.h>
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
@ -12,7 +16,13 @@ struct el_string *el_kitty_get_image(char *data, int len, int *width, int *heigh
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_LIBSIXEL
|
||||
extern sixel_allocator_t *el_sixel_allocator;
|
||||
char *el_sixel_get_image(char *data, int len, int *outlen);
|
||||
|
||||
#ifdef CONFIG_MEMCOUNT
|
||||
void init_sixel_allocator(void);
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
@ -39,6 +39,7 @@
|
||||
#include "document/document.h"
|
||||
#include "osdep/osdep.h"
|
||||
#include "terminal/hardio.h"
|
||||
#include "terminal/image.h"
|
||||
#include "terminal/screen.h"
|
||||
#include "terminal/sixel.h"
|
||||
#include "terminal/terminal.h"
|
||||
@ -96,21 +97,6 @@ struct sixel_encoder {
|
||||
void *dither_cache;
|
||||
};
|
||||
|
||||
#ifdef CONFIG_MEMCOUNT
|
||||
static sixel_allocator_t *el_sixel_allocator;
|
||||
|
||||
static void
|
||||
init_allocator(void)
|
||||
{
|
||||
ELOG
|
||||
static int initialized = 0;
|
||||
if (!initialized) {
|
||||
sixel_allocator_new(&el_sixel_allocator, el_sixel_malloc, el_sixel_calloc, el_sixel_realloc, el_sixel_free);
|
||||
initialized = 1;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
/* palette type */
|
||||
#define SIXEL_COLOR_OPTION_DEFAULT 0 /* use default settings */
|
||||
#define SIXEL_COLOR_OPTION_MONOCHROME 1 /* use monochrome palette */
|
||||
@ -857,11 +843,10 @@ add_image_to_document(struct document *doc, char *data, int datalen, int lineno,
|
||||
return 0;
|
||||
}
|
||||
#ifdef CONFIG_MEMCOUNT
|
||||
init_allocator();
|
||||
status = sixel_decoder_new(&decoder, el_sixel_allocator);
|
||||
#else
|
||||
status = sixel_decoder_new(&decoder, NULL);
|
||||
init_sixel_allocator();
|
||||
#endif
|
||||
status = sixel_decoder_new(&decoder, el_sixel_allocator);
|
||||
|
||||
if (SIXEL_FAILED(status)) {
|
||||
goto end;
|
||||
}
|
||||
@ -943,11 +928,9 @@ copy_frame(struct image *src, struct el_box *box, int cell_width, int cell_heigh
|
||||
return NULL;
|
||||
}
|
||||
#ifdef CONFIG_MEMCOUNT
|
||||
init_allocator();
|
||||
status = sixel_decoder_new(&decoder, el_sixel_allocator);
|
||||
#else
|
||||
status = sixel_decoder_new(&decoder, NULL);
|
||||
init_sixel_allocator();
|
||||
#endif
|
||||
status = sixel_decoder_new(&decoder, el_sixel_allocator);
|
||||
|
||||
if (SIXEL_FAILED(status)) {
|
||||
goto end;
|
||||
|
Loading…
x
Reference in New Issue
Block a user