diff options
author | yzrh <yzrh@noema.org> | 2022-12-22 19:47:40 +0000 |
---|---|---|
committer | yzrh <yzrh@noema.org> | 2022-12-24 23:29:56 +0000 |
commit | 9c1f1d0b75de0d2ed299842d3025941f3e681c16 (patch) | |
tree | 302f6d4a2235acfe8872a3c0c1c216fecc323b95 /src/cnki_jbig.c | |
parent | ac3b1dda63944f2cc8caaa52344774255e1956c8 (diff) | |
download | melon-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_jbig.c')
-rw-r--r-- | src/cnki_jbig.c | 62 |
1 files changed, 8 insertions, 54 deletions
diff --git a/src/cnki_jbig.c b/src/cnki_jbig.c index 02040be..f35d1d5 100644 --- a/src/cnki_jbig.c +++ b/src/cnki_jbig.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020-2021, yzrh <yzrh@noema.org> + * Copyright (c) 2020-2022, yzrh <yzrh@noema.org> * * SPDX-License-Identifier: Apache-2.0 */ @@ -22,68 +22,22 @@ cnki_jbig(char **bitmap, int *bitmap_size, memcpy(dib, jbig, 40); - bih_t *bih = malloc(sizeof(bih_t)); + int width_padded = (dib->width * dib->depth + 7) / 8; - if (bih == NULL) { - free(dib); - return 1; - } - - memset(bih, 0, sizeof(bih_t)); - - bih->d_l = 0; - bih->d = 0; - - bih->p = 1; - - bih->fill = 0; - - bih->x_d = dib->width; - bih->y_d = dib->height; - bih->l_0 = bih->y_d / 35; - - while (bih->l_0 > 128) - bih->l_0--; - if (bih->l_0 < 2) - bih->l_0 = 2; + *bitmap_size = dib->height * width_padded; + *bitmap = malloc(*bitmap_size); - bih->m_x = 8; - bih->m_y = 0; - - bih->order |= 1 << 1; - bih->order |= 1 << 0; - - bih->options |= 1 << 4; - bih->options |= 1 << 3; - bih->options |= 1 << 2; - - bih->dptable = NULL; - - int bie_size = jbig_size - 28; /* - 40 - 8 + 20 */ - char *bie = malloc(bie_size); - - if (bie == NULL) { + if (*bitmap == NULL) { free(dib); - free(bih); return 1; } - memcpy(bie, bih, 20); - memcpy(bie + 20, jbig + 48, jbig_size - 48); + strdec_jbig(bitmap, dib->width, dib->height, jbig + 48, jbig_size - 48); - int ret = strdec_jbig(bitmap, bitmap_size, bie, bie_size); - - if (ret == 0) { - *bitmap_width = bih->x_d; - *bitmap_height = bih->y_d; - } + *bitmap_width = dib->width; + *bitmap_height = dib->height; free(dib); - free(bih); - free(bie); - - if (ret != 0) - return 1; return 0; } |