From 9c1f1d0b75de0d2ed299842d3025941f3e681c16 Mon Sep 17 00:00:00 2001 From: yzrh Date: Thu, 22 Dec 2022 19:47:40 +0000 Subject: Fix HN conversion and add JBIG2 support. Signed-off-by: yzrh --- src/jbig2.c | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 src/jbig2.c (limited to 'src/jbig2.c') diff --git a/src/jbig2.c b/src/jbig2.c new file mode 100644 index 0000000..9b3a9be --- /dev/null +++ b/src/jbig2.c @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2022, yzrh + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include +#include +#include + +#include + +int +strdec_jbig2(char **bitmap, + const char * restrict jbig2, int jbig2_size) +{ + Jbig2Ctx *ctx = jbig2_ctx_new(NULL, JBIG2_OPTIONS_EMBEDDED, NULL, NULL, NULL); + + jbig2_data_in(ctx, (unsigned char *) jbig2, jbig2_size); + + jbig2_complete_page(ctx); + + Jbig2Image *image = jbig2_page_out(ctx); + + int width_padded = (image->width + 7) / 8; + unsigned char *data = image->data; + + for (unsigned int i = 0; i < image->height; i++) { + memcpy(*bitmap + i * width_padded, data, width_padded); + data += image->stride; + } + + jbig2_release_page(ctx, image); + return 0; +} -- cgit v1.2.3