aboutsummaryrefslogtreecommitdiffstats
path: root/src/cnki_jbig2.c
diff options
context:
space:
mode:
authoryzrh <yzrh@noema.org>2022-12-22 19:47:40 +0000
committeryzrh <yzrh@noema.org>2022-12-24 23:29:56 +0000
commit9c1f1d0b75de0d2ed299842d3025941f3e681c16 (patch)
tree302f6d4a2235acfe8872a3c0c1c216fecc323b95 /src/cnki_jbig2.c
parentac3b1dda63944f2cc8caaa52344774255e1956c8 (diff)
downloadmelon-9c1f1d0b75de0d2ed299842d3025941f3e681c16.tar.gz
melon-9c1f1d0b75de0d2ed299842d3025941f3e681c16.tar.zst
Fix HN conversion and add JBIG2 support.
Signed-off-by: yzrh <yzrh@noema.org>
Diffstat (limited to 'src/cnki_jbig2.c')
-rw-r--r--src/cnki_jbig2.c43
1 files changed, 43 insertions, 0 deletions
diff --git a/src/cnki_jbig2.c b/src/cnki_jbig2.c
new file mode 100644
index 0000000..69f4a5b
--- /dev/null
+++ b/src/cnki_jbig2.c
@@ -0,0 +1,43 @@
+/*
+ * Copyright (c) 2022, yzrh <yzrh@noema.org>
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ */
+
+#include <stdlib.h>
+#include <string.h>
+
+#include "cnki_jbig.h"
+#include "jbig2.h"
+
+int
+cnki_jbig2(char **bitmap, int *bitmap_size,
+ int *bitmap_width, int *bitmap_height,
+ const char * restrict jbig, int jbig_size)
+{
+ dib_t *dib = malloc(sizeof(dib_t));
+
+ if (dib == NULL)
+ return 1;
+
+ memcpy(dib, jbig, 40);
+
+ int width_padded = (dib->width * dib->depth + 7) / 8;
+
+ *bitmap_size = dib->height * width_padded;
+ *bitmap = malloc(*bitmap_size);
+
+ if (*bitmap == NULL) {
+ free(dib);
+ return 1;
+ }
+
+ strdec_jbig2(bitmap, jbig + 48, jbig_size - 48);
+
+ *bitmap_width = dib->width;
+ *bitmap_height = dib->height;
+
+ free(dib);
+
+ return 0;
+}