aboutsummaryrefslogtreecommitdiffstats
path: root/src/jbig.c
diff options
context:
space:
mode:
authoryzrh <yzrh@noema.org>2020-12-31 22:36:28 +0000
committeryzrh <yzrh@noema.org>2021-01-03 03:01:28 +0000
commit1994f122cc29504862944cca1da1c5203c7e41eb (patch)
treed89e37c5f3443156116bd8476e0efc2d380acd55 /src/jbig.c
parentb20c6ad3ed930977990f3812b25b80d2ce282d79 (diff)
downloadmelon-1994f122cc29504862944cca1da1c5203c7e41eb.tar.gz
melon-1994f122cc29504862944cca1da1c5203c7e41eb.tar.zst
Decode JBIG and JPEG during HN conversion.
Diffstat (limited to 'src/jbig.c')
-rw-r--r--src/jbig.c41
1 files changed, 41 insertions, 0 deletions
diff --git a/src/jbig.c b/src/jbig.c
new file mode 100644
index 0000000..1e9afb3
--- /dev/null
+++ b/src/jbig.c
@@ -0,0 +1,41 @@
+/*
+ * Copyright (c) 2020-2021, yzrh <yzrh@noema.org>
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ */
+
+#include <stdio.h> /* FIXME: test */
+#include <stdlib.h>
+#include <string.h>
+
+#include <jbig.h>
+
+int
+strdec_jbig(char **bitmap, int *bitmap_size,
+ const char * restrict data, int data_size)
+{
+ struct jbg_dec_state sd;
+
+ jbg_dec_init(&sd);
+
+ unsigned char *data_ptr[1] = {(unsigned char *) data};
+
+ /* FIXME: test */
+ int ret;
+ if ((ret = jbg_dec_in(&sd, (unsigned char *) data_ptr,
+ data_size, NULL)) != JBG_EOK) {
+ printf("%s", jbg_strerror(ret));
+ jbg_dec_free(&sd);
+ return 1;
+ }
+
+ *bitmap_size = jbg_dec_getsize(&sd);
+ *bitmap = malloc(*bitmap_size);
+
+ if (*bitmap != NULL)
+ memcpy(*bitmap, jbg_dec_getimage(&sd, 0), *bitmap_size);
+
+ jbg_dec_free(&sd);
+
+ return 0;
+}