From 9e3bfb1eab2c7b1c7a1ec6021331fddc57e8a266 Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Fri, 21 Feb 2020 21:53:23 +0100 Subject: sixel: initial support This implements basic parsing of sixel data. Lots of limitations and temporary solutions as this is still work-in-progress: * Maximum image size hardcoded to 800x800 * No HLS color format support * Image is always rendered at 0x0 in the terminal --- dcs.c | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) (limited to 'dcs.c') diff --git a/dcs.c b/dcs.c index 048cd62e..f9e3c10c 100644 --- a/dcs.c +++ b/dcs.c @@ -3,6 +3,7 @@ #define LOG_MODULE "dcs" #define LOG_ENABLE_DBG 0 #include "log.h" +#include "sixel.h" #include "vt.h" static void @@ -35,9 +36,20 @@ dcs_hook(struct terminal *term, uint8_t final) assert(term->vt.dcs.data == NULL); assert(term->vt.dcs.size == 0); + assert(term->vt.dcs.put_handler == NULL); assert(term->vt.dcs.unhook_handler == NULL); switch (term->vt.private[0]) { + case 0: + switch (final) { + case 'q': + sixel_init(term); + term->vt.dcs.put_handler = &sixel_put; + term->vt.dcs.unhook_handler = &sixel_unhook; + break; + } + break; + case '=': switch (final) { case 's': @@ -75,9 +87,13 @@ void dcs_put(struct terminal *term, uint8_t c) { LOG_DBG("PUT: %c", c); - if (!ensure_size(term, term->vt.dcs.idx + 1)) - return; - term->vt.dcs.data[term->vt.dcs.idx++] = c; + if (term->vt.dcs.put_handler != NULL) + term->vt.dcs.put_handler(term, c); + else { + if (!ensure_size(term, term->vt.dcs.idx + 1)) + return; + term->vt.dcs.data[term->vt.dcs.idx++] = c; + } } void @@ -87,6 +103,7 @@ dcs_unhook(struct terminal *term) term->vt.dcs.unhook_handler(term); term->vt.dcs.unhook_handler = NULL; + term->vt.dcs.put_handler = NULL; free(term->vt.dcs.data); term->vt.dcs.data = NULL; -- cgit v1.3