From 8083b30530a37d3529d453515465a00aac74a154 Mon Sep 17 00:00:00 2001 From: yzrh Date: Thu, 29 Dec 2022 00:18:07 +0000 Subject: Add JPEG 2000 support. Signed-off-by: yzrh --- src/cnki_pdf.c | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) (limited to 'src/cnki_pdf.c') diff --git a/src/cnki_pdf.c b/src/cnki_pdf.c index 0cb30ca..887e5f4 100644 --- a/src/cnki_pdf.c +++ b/src/cnki_pdf.c @@ -11,6 +11,7 @@ #include "iconv.h" #include "zlib.h" #include "jpeg.h" +#include "jp2.h" #include "pdf.h" #include "pdf_cnki.h" @@ -660,6 +661,41 @@ cnki_pdf_hn(cnki_t **param) dim[i * 2 + 1] = info[1]; break; case JPX: + ret = strinfo_jp2_dim(&info[0], + &info[1], + ptr->image_data[i].image, + ptr->image_data[i].size); + + if (ret != 0) { + dim[i * 2] = 0; + dim[i * 2 + 1] = 0; + break; + } + + stream_size = ptr->image_data[i].size; + stream = malloc(stream_size); + if (stream == NULL) { + free(root_kid); + free(ids); + free(dim); + free(dictionary); + return 1; + } + memcpy(stream, ptr->image_data[i].image, stream_size); + + snprintf(buf, 64, "/Width %d\n/Height %d\n", + info[0], info[1]); + strcat(dictionary, buf); + + snprintf(buf, 64, "/Length %d\n", + stream_size); + strcat(dictionary, buf); + + strcat(dictionary, "/Filter /JPXDecode\n"); + + dim[i * 2] = info[0]; + dim[i * 2 + 1] = info[1]; + break; default: ret = -1; dim[i * 2] = -1; -- cgit v1.2.3