aboutsummaryrefslogtreecommitdiffstats
path: root/src/cnki_pdf.c
diff options
context:
space:
mode:
authoryzrh <yzrh@noema.org>2022-12-29 00:18:07 +0000
committeryzrh <yzrh@noema.org>2022-12-29 00:40:14 +0000
commit8083b30530a37d3529d453515465a00aac74a154 (patch)
tree0390c6550f642c96ad0f4b40aab949d1e120ffd0 /src/cnki_pdf.c
parentabce2fd2e4f8089779fb9b1dce94133716b0bb39 (diff)
downloadmelon-8083b30530a37d3529d453515465a00aac74a154.tar.gz
melon-8083b30530a37d3529d453515465a00aac74a154.tar.zst
Add JPEG 2000 support.
Signed-off-by: yzrh <yzrh@noema.org>
Diffstat (limited to 'src/cnki_pdf.c')
-rw-r--r--src/cnki_pdf.c36
1 files changed, 36 insertions, 0 deletions
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;