forked from koreader/koreader-base
-
Notifications
You must be signed in to change notification settings - Fork 0
/
koptcontext_h.lua
166 lines (165 loc) · 3.14 KB
/
koptcontext_h.lua
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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
local ffi = require("ffi")
ffi.cdef[[
typedef struct {
float x0;
float y0;
float x1;
float y1;
} BBox;
typedef struct Boxa BOXA;
typedef struct Numa NUMA;
typedef struct Pix PIX;
typedef struct {
double x;
double y;
} POINT2D;
typedef struct {
int srcpageno;
int srcwidth;
int srcheight;
double srcdpiw;
double srcdpih;
int srcrot;
POINT2D coords[3];
} WRECTMAP;
typedef struct {
WRECTMAP *wrectmap;
int n;
int na;
} WRECTMAPS;
typedef struct {
int red[256];
int green[256];
int blue[256];
unsigned char *data;
int width;
int height;
int bpp;
int size_allocated;
int type;
} WILLUSBITMAP;
typedef struct {
int ch;
int c2;
int r1;
int r2;
} HYPHENINFO;
typedef struct {
int c1;
int c2;
int r1;
int r2;
int rowbase;
int gap;
int gapblank;
int rowheight;
int capheight;
int h5050;
int lcheight;
int type;
double rat;
HYPHENINFO hyphen;
} TEXTROW;
typedef struct {
TEXTROW *textrow;
int n;
int na;
} TEXTROWS;
typedef struct {
int r1;
int r2;
int c1;
int c2;
TEXTROWS textrows;
TEXTROW bbox;
WRECTMAPS *wrectmaps;
struct {
int n;
struct {
int row;
int col;
int type;
} k2pagebreakmark[32];
} *k2pagebreakmarks;
int k2pagebreakmarks_allocated;
int bgcolor;
int dpi;
int pageno;
int rotdeg;
int *colcount;
int *rowcount;
WILLUSBITMAP *bmp;
WILLUSBITMAP *bmp8;
WILLUSBITMAP *marked;
} BMPREGION;
typedef struct {
BMPREGION bmpregion;
int notes;
int fullspan;
int level;
} PAGEREGION;
typedef struct {
PAGEREGION *pageregion;
int n;
int na;
} PAGEREGIONS;
struct KOPTContext {
int trim;
int wrap;
int white;
int indent;
int rotate;
int columns;
int offset_x;
int offset_y;
int dev_dpi;
int dev_width;
int dev_height;
int page_width;
int page_height;
int straighten;
int justification;
int read_max_width;
int read_max_height;
int writing_direction;
double zoom;
double margin;
double quality;
double contrast;
double defect_size;
double line_spacing;
double word_spacing;
double shrink_factor;
int precache;
int debug;
int cjkchar;
BOXA *rboxa;
NUMA *rnai;
BOXA *nboxa;
NUMA *nnai;
WRECTMAPS rectmaps;
PAGEREGIONS pageregions;
BBox bbox;
char *language;
WILLUSBITMAP dst;
WILLUSBITMAP src;
};
typedef struct KOPTContext KOPTContext;
void bmp_init(WILLUSBITMAP *);
void bmp_free(WILLUSBITMAP *);
int bmp_alloc(WILLUSBITMAP *);
int bmp_bytewidth(WILLUSBITMAP *);
int bmp_copy(WILLUSBITMAP *, WILLUSBITMAP *);
void wrectmaps_init(WRECTMAPS *);
void wrectmaps_free(WRECTMAPS *);
int wrectmap_inside(WRECTMAP *, int, int);
void k2pdfopt_get_reflowed_word_boxes(KOPTContext *, WILLUSBITMAP *, int, int, int, int);
void k2pdfopt_get_native_word_boxes(KOPTContext *, WILLUSBITMAP *, int, int, int, int);
int k2pdfopt_tocr_single_word(WILLUSBITMAP *, int, int, int, int, int, char *, int, char *, char *, int, int, int);
void k2pdfopt_reflow_bmp(KOPTContext *);
void k2pdfopt_tocr_end();
void k2pdfopt_crop_bmp(KOPTContext *);
void k2pdfopt_optimize_bmp(KOPTContext *);
void pixmap_to_bmp(WILLUSBITMAP *, unsigned char *, int);
PIX *bitmap2pix(WILLUSBITMAP *, int, int, int, int);
]]