aboutsummaryrefslogtreecommitdiffstats
path: root/src/cnki.h
blob: 7d7d15ea0799acbb6cc66c0f48b336a2dd148acf (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
/*
 * Copyright (c) 2020-2022, yzrh <yzrh@noema.org>
 *
 * SPDX-License-Identifier: Apache-2.0
 */

#include <stdint.h>
#include <stdio.h>

#define ADDRESS_HEAD		0x0000

#define ADDRESS_CAJ_PAGE	0x0010
#define ADDRESS_CAJ_OUTLINE	0x0110
#define ADDRESS_CAJ_BODY	0x0014

#define ADDRESS_HN_PAGE		0x0090
#define ADDRESS_HN_OUTLINE	0x0158

#define ADDRESS_C8_PAGE		0x0008

#define ADDRESS_KDH_BODY	0x00fe

#define KEY_KDH			"FZHMEI"
#define KEY_KDH_LENGTH		6

typedef struct _file_stat_t {
	char type[4];
	int32_t page;
	int32_t outline;
} file_stat_t;

typedef struct _object_outline_t {
	char title[256]; /* Starting at file_stat_t->outline + 4 */
	char hierarchy[24];
	char page[12];
	char text[12];
	int32_t depth;
	struct _object_outline_t *next;
} object_outline_t;

typedef struct _object_outline_tree_t {
	int id;
	struct _object_outline_t *item;
	struct _object_outline_tree_t *up;
	struct _object_outline_tree_t *left;
	struct _object_outline_tree_t *right;
} object_outline_tree_t;

typedef enum _hn_code {
	JBIG, /* Inverted */
	DCT_0,
	DCT_1, /* Inverted */
	JBIG2,
	JPX
} hn_code;

typedef struct _hn_image_t {
	int32_t format; /* hn_code */
	int32_t address;
	int32_t size;
	uint16_t x;
	uint16_t y;
	uint16_t w;
	uint16_t h;
	char *image;
} hn_image_t;

typedef struct _object_hn_t {
	int32_t address; /* Starting at end of object_outline_t */
	int32_t text_size;
	int16_t image_length;
	int16_t page;
	int32_t unknown; /* TODO: what is it? */
	int32_t address_next;
	char *text;
	struct _hn_image_t *image_data;
	struct _object_hn_t *next;
} object_hn_t;

typedef struct _cnki_t {
	int stat;
	int size_buf;
	FILE *fp_i;
	FILE *fp_o;
	file_stat_t *file_stat;
	object_outline_t *object_outline;
	object_hn_t *object_hn;
} cnki_t;

/* cnki_pdf.c */
int cnki_pdf(cnki_t **param);
int cnki_pdf_hn(cnki_t **param);

/* cnki_outline_tree.c */
int cnki_outline_tree(object_outline_tree_t **outline_tree,
	object_outline_t **outline, int *ids);

/* cnki_zlib.c */
int cnki_zlib(char **dst, int *dst_size,
	const char * restrict src, int src_size);

/* cnki_jbig.c */
int cnki_jbig(char **bitmap, int *bitmap_size,
	int *bitmap_width, int *bitmap_height,
	const char * restrict jbig, int jbig_size);

/* cnki_jbig2.c */
int cnki_jbig2(char **bitmap, int *bitmap_size,
	int *bitmap_width, int *bitmap_height,
	const char * restrict jbig, int jbig_size);