pdf-parser.js 5.2.26 → 5.2.28
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{afm-widths-BYiX2L9D.cjs → afm-widths-BHD2HZIL.cjs} +553 -642
- package/dist/{afm-widths-blUDDjlI.js → afm-widths-B_IGbGky.js} +553 -642
- package/dist/afm-widths.cjs +1 -1
- package/dist/afm-widths.js +1 -1
- package/dist/annotations.cjs +5 -3
- package/dist/annotations.d.cts +2 -2
- package/dist/annotations.d.ts +2 -2
- package/dist/annotations.js +5 -3
- package/dist/attachments.d.cts +2 -2
- package/dist/attachments.d.ts +2 -2
- package/dist/builtin-encoding.cjs +17 -6
- package/dist/builtin-encoding.js +17 -6
- package/dist/bytes/crc32.cjs +5 -3
- package/dist/bytes/crc32.js +5 -3
- package/dist/bytes/flate.cjs +0 -1
- package/dist/bytes/flate.js +0 -1
- package/dist/cff-bounds.cjs +73 -45
- package/dist/cff-bounds.js +73 -45
- package/dist/cff.cjs +13 -6
- package/dist/cff.js +13 -6
- package/dist/cmap-table.cjs +54 -26
- package/dist/cmap-table.js +54 -26
- package/dist/cmap.cjs +5 -3
- package/dist/cmap.js +5 -3
- package/dist/content-read.d.cts +1 -1
- package/dist/content-read.d.ts +1 -1
- package/dist/content-write.cjs +21 -14
- package/dist/content-write.d.cts +2 -2
- package/dist/content-write.d.ts +2 -2
- package/dist/content-write.js +21 -14
- package/dist/crypto/aes.cjs +76 -55
- package/dist/crypto/aes.js +76 -55
- package/dist/crypto/md5.cjs +345 -149
- package/dist/crypto/md5.js +345 -149
- package/dist/crypto/rc4.cjs +5 -4
- package/dist/crypto/rc4.js +5 -4
- package/dist/crypto/sha2.cjs +92 -43
- package/dist/crypto/sha2.js +92 -43
- package/dist/document.cjs +17 -11
- package/dist/document.d.cts +1 -1
- package/dist/document.d.ts +1 -1
- package/dist/document.js +17 -11
- package/dist/{embedded-font-Bnhh4juV.d.ts → embedded-font-ByD7ZiQS.d.ts} +1 -1
- package/dist/{embedded-font-CEf-zBCA.d.cts → embedded-font-DgVBedw6.d.cts} +1 -1
- package/dist/embedded-font-write.d.cts +2 -2
- package/dist/embedded-font-write.d.ts +2 -2
- package/dist/embedded-font.cjs +4 -2
- package/dist/embedded-font.d.cts +1 -1
- package/dist/embedded-font.d.ts +1 -1
- package/dist/embedded-font.js +4 -2
- package/dist/encoding.cjs +1 -1
- package/dist/encoding.js +1 -1
- package/dist/encrypt-write.cjs +25 -21
- package/dist/encrypt-write.d.cts +1 -1
- package/dist/encrypt-write.d.ts +1 -1
- package/dist/encrypt-write.js +25 -21
- package/dist/encrypt.cjs +43 -64
- package/dist/encrypt.d.cts +1 -1
- package/dist/encrypt.d.ts +1 -1
- package/dist/encrypt.js +43 -64
- package/dist/filters.cjs +46 -26
- package/dist/filters.d.cts +1 -1
- package/dist/filters.d.ts +1 -1
- package/dist/filters.js +46 -26
- package/dist/font-face.cjs +2 -1
- package/dist/font-face.js +2 -1
- package/dist/font-read.cjs +12 -6
- package/dist/font-read.d.cts +1 -1
- package/dist/font-read.d.ts +1 -1
- package/dist/font-read.js +12 -6
- package/dist/font-registry.d.cts +3 -3
- package/dist/font-registry.d.ts +3 -3
- package/dist/font-tables.cjs +55 -28
- package/dist/font-tables.js +55 -28
- package/dist/form.cjs +13 -8
- package/dist/form.d.cts +2 -2
- package/dist/form.d.ts +2 -2
- package/dist/form.js +13 -8
- package/dist/gdef-table.cjs +6 -3
- package/dist/gdef-table.js +6 -3
- package/dist/{glyf-contours-C0epBNqP.d.ts → glyf-contours-B1PsI9oA.d.ts} +1 -1
- package/dist/{glyf-contours-BRpvd0rt.d.cts → glyf-contours-NHBpgks-.d.cts} +1 -1
- package/dist/glyf-contours.cjs +3 -1
- package/dist/glyf-contours.d.cts +1 -1
- package/dist/glyf-contours.d.ts +1 -1
- package/dist/glyf-contours.js +3 -1
- package/dist/glyf.cjs +22 -11
- package/dist/glyf.js +22 -11
- package/dist/gpos-table.cjs +37 -19
- package/dist/gpos-table.js +37 -19
- package/dist/gsub-table.cjs +40 -25
- package/dist/gsub-table.js +40 -25
- package/dist/hmtx-table.cjs +5 -3
- package/dist/hmtx-table.js +5 -3
- package/dist/image/ccitt-encode.cjs +8 -5
- package/dist/image/ccitt-encode.js +8 -5
- package/dist/image/ccitt.cjs +801 -209
- package/dist/image/ccitt.js +801 -209
- package/dist/image/jbig2-arith.cjs +340 -306
- package/dist/image/jbig2-arith.js +340 -306
- package/dist/image/jbig2-bitmap.cjs +8 -5
- package/dist/image/jbig2-bitmap.js +8 -5
- package/dist/image/jbig2-generic.cjs +240 -69
- package/dist/image/jbig2-generic.js +240 -69
- package/dist/image/jbig2-text.cjs +4 -2
- package/dist/image/jbig2-text.js +4 -2
- package/dist/image/jbig2.cjs +69 -31
- package/dist/image/jbig2.js +69 -31
- package/dist/image/jp2-boxes.cjs +52 -27
- package/dist/image/jp2-boxes.js +52 -27
- package/dist/image/jpeg-info.cjs +29 -24
- package/dist/image/jpeg-info.js +29 -24
- package/dist/image/jpeg2000-codestream.cjs +61 -32
- package/dist/image/jpeg2000-codestream.js +61 -32
- package/dist/image/jpeg2000-dwt.cjs +2 -1
- package/dist/image/jpeg2000-dwt.js +2 -1
- package/dist/image/jpeg2000-t1.cjs +21 -11
- package/dist/image/jpeg2000-t1.js +21 -11
- package/dist/image/jpeg2000-t2.cjs +12 -5
- package/dist/image/jpeg2000-t2.js +12 -5
- package/dist/image/jpeg2000-tagtree.cjs +8 -4
- package/dist/image/jpeg2000-tagtree.js +8 -4
- package/dist/image/jpeg2000.cjs +11 -6
- package/dist/image/jpeg2000.js +11 -6
- package/dist/image/png-decode.cjs +62 -39
- package/dist/image/png-decode.d.cts +3 -2
- package/dist/image/png-decode.d.ts +3 -2
- package/dist/image/png-decode.js +62 -39
- package/dist/image/png-filter.cjs +23 -15
- package/dist/image/png-filter.js +23 -15
- package/dist/images-read.cjs +41 -36
- package/dist/images-read.d.cts +2 -2
- package/dist/images-read.d.ts +2 -2
- package/dist/images-read.js +41 -36
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/interpret.cjs +68 -40
- package/dist/interpret.d.cts +1 -1
- package/dist/interpret.d.ts +1 -1
- package/dist/interpret.js +68 -40
- package/dist/lexer.cjs +86 -51
- package/dist/lexer.js +86 -51
- package/dist/math-content-write.cjs +9 -5
- package/dist/math-content-write.js +9 -5
- package/dist/math-font-write.cjs +2 -1
- package/dist/math-font-write.d.cts +1 -1
- package/dist/math-font-write.d.ts +1 -1
- package/dist/math-font-write.js +2 -1
- package/dist/math-font.cjs +16 -7
- package/dist/math-font.js +16 -7
- package/dist/math-table.cjs +25 -13
- package/dist/math-table.js +25 -13
- package/dist/matrix.cjs +3 -2
- package/dist/matrix.js +3 -2
- package/dist/measure.cjs +1 -1
- package/dist/measure.js +1 -1
- package/dist/names.cjs +7 -7
- package/dist/names.d.cts +2 -2
- package/dist/names.d.ts +2 -2
- package/dist/names.js +7 -7
- package/dist/navigation.cjs +16 -12
- package/dist/navigation.d.cts +4 -4
- package/dist/navigation.d.ts +4 -4
- package/dist/navigation.js +16 -12
- package/dist/{objects-B7HdMeWS.d.cts → objects-e2RS3-yT.d.cts} +3 -3
- package/dist/{objects-B7HdMeWS.d.ts → objects-e2RS3-yT.d.ts} +3 -3
- package/dist/objects.d.cts +1 -1
- package/dist/objects.d.ts +1 -1
- package/dist/optional-content.d.cts +2 -2
- package/dist/optional-content.d.ts +2 -2
- package/dist/ot-layout-common.cjs +22 -15
- package/dist/ot-layout-common.js +22 -15
- package/dist/parse.cjs +7 -5
- package/dist/parse.d.cts +1 -1
- package/dist/parse.d.ts +1 -1
- package/dist/parse.js +7 -5
- package/dist/pdf-text.cjs +5 -2
- package/dist/pdf-text.js +5 -2
- package/dist/predictors.cjs +14 -9
- package/dist/predictors.d.cts +1 -1
- package/dist/predictors.d.ts +1 -1
- package/dist/predictors.js +14 -9
- package/dist/raster.cjs +30 -19
- package/dist/raster.d.cts +8 -8
- package/dist/raster.d.ts +8 -8
- package/dist/raster.js +30 -19
- package/dist/read.cjs +29 -16
- package/dist/read.js +29 -16
- package/dist/serialize.cjs +6 -2
- package/dist/serialize.d.cts +1 -1
- package/dist/serialize.d.ts +1 -1
- package/dist/serialize.js +6 -2
- package/dist/sfnt-subset.cjs +25 -13
- package/dist/sfnt-subset.d.cts +1 -1
- package/dist/sfnt-subset.d.ts +1 -1
- package/dist/sfnt-subset.js +25 -13
- package/dist/sfnt.cjs +20 -10
- package/dist/sfnt.js +20 -10
- package/dist/structure.d.cts +2 -2
- package/dist/structure.d.ts +2 -2
- package/dist/text-group.cjs +0 -1
- package/dist/text-group.js +0 -1
- package/dist/text-layout.d.cts +1 -1
- package/dist/text-layout.d.ts +1 -1
- package/dist/tounicode.cjs +4 -2
- package/dist/tounicode.d.cts +1 -1
- package/dist/tounicode.d.ts +1 -1
- package/dist/tounicode.js +4 -2
- package/dist/winansi.cjs +1 -1
- package/dist/winansi.js +1 -1
- package/dist/write.cjs +20 -12
- package/dist/write.d.cts +1 -1
- package/dist/write.d.ts +1 -1
- package/dist/write.js +20 -12
- package/dist/xref.cjs +5 -2
- package/dist/xref.d.cts +1 -1
- package/dist/xref.d.ts +1 -1
- package/dist/xref.js +5 -2
- package/package.json +1 -1
|
@@ -1,76 +1,252 @@
|
|
|
1
1
|
import { Jbig2UnsupportedError } from "./jbig2-errors.js";
|
|
2
2
|
import { createBitmap, getPixel } from "./jbig2-bitmap.js";
|
|
3
3
|
//#region src/image/jbig2-generic.ts
|
|
4
|
-
function fixed(dx, dy) {
|
|
5
|
-
return {
|
|
6
|
-
kind: "fixed",
|
|
7
|
-
dx,
|
|
8
|
-
dy
|
|
9
|
-
};
|
|
10
|
-
}
|
|
11
|
-
function at(index) {
|
|
12
|
-
return {
|
|
13
|
-
kind: "at",
|
|
14
|
-
index
|
|
15
|
-
};
|
|
16
|
-
}
|
|
17
4
|
const GENERIC_TEMPLATES = [
|
|
18
5
|
[
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
6
|
+
{
|
|
7
|
+
kind: "at",
|
|
8
|
+
index: 3
|
|
9
|
+
},
|
|
10
|
+
{
|
|
11
|
+
kind: "fixed",
|
|
12
|
+
dx: -1,
|
|
13
|
+
dy: -2
|
|
14
|
+
},
|
|
15
|
+
{
|
|
16
|
+
kind: "fixed",
|
|
17
|
+
dx: 0,
|
|
18
|
+
dy: -2
|
|
19
|
+
},
|
|
20
|
+
{
|
|
21
|
+
kind: "fixed",
|
|
22
|
+
dx: 1,
|
|
23
|
+
dy: -2
|
|
24
|
+
},
|
|
25
|
+
{
|
|
26
|
+
kind: "at",
|
|
27
|
+
index: 2
|
|
28
|
+
},
|
|
29
|
+
{
|
|
30
|
+
kind: "at",
|
|
31
|
+
index: 1
|
|
32
|
+
},
|
|
33
|
+
{
|
|
34
|
+
kind: "fixed",
|
|
35
|
+
dx: -2,
|
|
36
|
+
dy: -1
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
kind: "fixed",
|
|
40
|
+
dx: -1,
|
|
41
|
+
dy: -1
|
|
42
|
+
},
|
|
43
|
+
{
|
|
44
|
+
kind: "fixed",
|
|
45
|
+
dx: 0,
|
|
46
|
+
dy: -1
|
|
47
|
+
},
|
|
48
|
+
{
|
|
49
|
+
kind: "fixed",
|
|
50
|
+
dx: 1,
|
|
51
|
+
dy: -1
|
|
52
|
+
},
|
|
53
|
+
{
|
|
54
|
+
kind: "fixed",
|
|
55
|
+
dx: 2,
|
|
56
|
+
dy: -1
|
|
57
|
+
},
|
|
58
|
+
{
|
|
59
|
+
kind: "at",
|
|
60
|
+
index: 0
|
|
61
|
+
},
|
|
62
|
+
{
|
|
63
|
+
kind: "fixed",
|
|
64
|
+
dx: -4,
|
|
65
|
+
dy: 0
|
|
66
|
+
},
|
|
67
|
+
{
|
|
68
|
+
kind: "fixed",
|
|
69
|
+
dx: -3,
|
|
70
|
+
dy: 0
|
|
71
|
+
},
|
|
72
|
+
{
|
|
73
|
+
kind: "fixed",
|
|
74
|
+
dx: -2,
|
|
75
|
+
dy: 0
|
|
76
|
+
},
|
|
77
|
+
{
|
|
78
|
+
kind: "fixed",
|
|
79
|
+
dx: -1,
|
|
80
|
+
dy: 0
|
|
81
|
+
}
|
|
35
82
|
],
|
|
36
83
|
[
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
84
|
+
{
|
|
85
|
+
kind: "fixed",
|
|
86
|
+
dx: -1,
|
|
87
|
+
dy: -2
|
|
88
|
+
},
|
|
89
|
+
{
|
|
90
|
+
kind: "fixed",
|
|
91
|
+
dx: 0,
|
|
92
|
+
dy: -2
|
|
93
|
+
},
|
|
94
|
+
{
|
|
95
|
+
kind: "fixed",
|
|
96
|
+
dx: 1,
|
|
97
|
+
dy: -2
|
|
98
|
+
},
|
|
99
|
+
{
|
|
100
|
+
kind: "fixed",
|
|
101
|
+
dx: 2,
|
|
102
|
+
dy: -2
|
|
103
|
+
},
|
|
104
|
+
{
|
|
105
|
+
kind: "fixed",
|
|
106
|
+
dx: -2,
|
|
107
|
+
dy: -1
|
|
108
|
+
},
|
|
109
|
+
{
|
|
110
|
+
kind: "fixed",
|
|
111
|
+
dx: -1,
|
|
112
|
+
dy: -1
|
|
113
|
+
},
|
|
114
|
+
{
|
|
115
|
+
kind: "fixed",
|
|
116
|
+
dx: 0,
|
|
117
|
+
dy: -1
|
|
118
|
+
},
|
|
119
|
+
{
|
|
120
|
+
kind: "fixed",
|
|
121
|
+
dx: 1,
|
|
122
|
+
dy: -1
|
|
123
|
+
},
|
|
124
|
+
{
|
|
125
|
+
kind: "fixed",
|
|
126
|
+
dx: 2,
|
|
127
|
+
dy: -1
|
|
128
|
+
},
|
|
129
|
+
{
|
|
130
|
+
kind: "at",
|
|
131
|
+
index: 0
|
|
132
|
+
},
|
|
133
|
+
{
|
|
134
|
+
kind: "fixed",
|
|
135
|
+
dx: -3,
|
|
136
|
+
dy: 0
|
|
137
|
+
},
|
|
138
|
+
{
|
|
139
|
+
kind: "fixed",
|
|
140
|
+
dx: -2,
|
|
141
|
+
dy: 0
|
|
142
|
+
},
|
|
143
|
+
{
|
|
144
|
+
kind: "fixed",
|
|
145
|
+
dx: -1,
|
|
146
|
+
dy: 0
|
|
147
|
+
}
|
|
50
148
|
],
|
|
51
149
|
[
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
150
|
+
{
|
|
151
|
+
kind: "fixed",
|
|
152
|
+
dx: -1,
|
|
153
|
+
dy: -2
|
|
154
|
+
},
|
|
155
|
+
{
|
|
156
|
+
kind: "fixed",
|
|
157
|
+
dx: 0,
|
|
158
|
+
dy: -2
|
|
159
|
+
},
|
|
160
|
+
{
|
|
161
|
+
kind: "fixed",
|
|
162
|
+
dx: 1,
|
|
163
|
+
dy: -2
|
|
164
|
+
},
|
|
165
|
+
{
|
|
166
|
+
kind: "fixed",
|
|
167
|
+
dx: -2,
|
|
168
|
+
dy: -1
|
|
169
|
+
},
|
|
170
|
+
{
|
|
171
|
+
kind: "fixed",
|
|
172
|
+
dx: -1,
|
|
173
|
+
dy: -1
|
|
174
|
+
},
|
|
175
|
+
{
|
|
176
|
+
kind: "fixed",
|
|
177
|
+
dx: 0,
|
|
178
|
+
dy: -1
|
|
179
|
+
},
|
|
180
|
+
{
|
|
181
|
+
kind: "fixed",
|
|
182
|
+
dx: 1,
|
|
183
|
+
dy: -1
|
|
184
|
+
},
|
|
185
|
+
{
|
|
186
|
+
kind: "at",
|
|
187
|
+
index: 0
|
|
188
|
+
},
|
|
189
|
+
{
|
|
190
|
+
kind: "fixed",
|
|
191
|
+
dx: -2,
|
|
192
|
+
dy: 0
|
|
193
|
+
},
|
|
194
|
+
{
|
|
195
|
+
kind: "fixed",
|
|
196
|
+
dx: -1,
|
|
197
|
+
dy: 0
|
|
198
|
+
}
|
|
62
199
|
],
|
|
63
200
|
[
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
201
|
+
{
|
|
202
|
+
kind: "fixed",
|
|
203
|
+
dx: -3,
|
|
204
|
+
dy: -1
|
|
205
|
+
},
|
|
206
|
+
{
|
|
207
|
+
kind: "fixed",
|
|
208
|
+
dx: -2,
|
|
209
|
+
dy: -1
|
|
210
|
+
},
|
|
211
|
+
{
|
|
212
|
+
kind: "fixed",
|
|
213
|
+
dx: -1,
|
|
214
|
+
dy: -1
|
|
215
|
+
},
|
|
216
|
+
{
|
|
217
|
+
kind: "fixed",
|
|
218
|
+
dx: 0,
|
|
219
|
+
dy: -1
|
|
220
|
+
},
|
|
221
|
+
{
|
|
222
|
+
kind: "fixed",
|
|
223
|
+
dx: 1,
|
|
224
|
+
dy: -1
|
|
225
|
+
},
|
|
226
|
+
{
|
|
227
|
+
kind: "at",
|
|
228
|
+
index: 0
|
|
229
|
+
},
|
|
230
|
+
{
|
|
231
|
+
kind: "fixed",
|
|
232
|
+
dx: -4,
|
|
233
|
+
dy: 0
|
|
234
|
+
},
|
|
235
|
+
{
|
|
236
|
+
kind: "fixed",
|
|
237
|
+
dx: -3,
|
|
238
|
+
dy: 0
|
|
239
|
+
},
|
|
240
|
+
{
|
|
241
|
+
kind: "fixed",
|
|
242
|
+
dx: -2,
|
|
243
|
+
dy: 0
|
|
244
|
+
},
|
|
245
|
+
{
|
|
246
|
+
kind: "fixed",
|
|
247
|
+
dx: -1,
|
|
248
|
+
dy: 0
|
|
249
|
+
}
|
|
74
250
|
]
|
|
75
251
|
];
|
|
76
252
|
const GENERIC_SLTP_CONTEXT = [
|
|
@@ -79,12 +255,7 @@ const GENERIC_SLTP_CONTEXT = [
|
|
|
79
255
|
229,
|
|
80
256
|
405
|
|
81
257
|
];
|
|
82
|
-
const GENERIC_CONTEXT_BITS =
|
|
83
|
-
16,
|
|
84
|
-
13,
|
|
85
|
-
10,
|
|
86
|
-
10
|
|
87
|
-
];
|
|
258
|
+
const GENERIC_CONTEXT_BITS = GENERIC_TEMPLATES.map((positions) => positions.length);
|
|
88
259
|
function resolveTemplate(template) {
|
|
89
260
|
const positions = GENERIC_TEMPLATES[template];
|
|
90
261
|
if (positions === void 0) throw new Jbig2UnsupportedError(`generic region declares GBTEMPLATE ${String(template)}, which is outside the 0-3 range T.88 6.2.5.3 defines`);
|
|
@@ -199,7 +370,7 @@ const REFINEMENT_TEMPLATES = [[
|
|
|
199
370
|
reference(1, 1)
|
|
200
371
|
]];
|
|
201
372
|
const TPGRON_UNSUPPORTED = "JBIG2 refinement region sets TPGRON (typical prediction, T.88 6.3.5.6), whose per-template pseudo-context constants this decoder has no way to verify against a real encoder; refusing rather than risking a silently wrong bitmap";
|
|
202
|
-
const REFINEMENT_CONTEXT_BITS =
|
|
373
|
+
const REFINEMENT_CONTEXT_BITS = REFINEMENT_TEMPLATES.map((positions) => positions.length);
|
|
203
374
|
const NOMINAL_REFINEMENT_AT = [{
|
|
204
375
|
x: -1,
|
|
205
376
|
y: -1
|
|
@@ -4,6 +4,8 @@ const require_image_jbig2_errors = require("./jbig2-errors.cjs");
|
|
|
4
4
|
const require_image_jbig2_bitmap = require("./jbig2-bitmap.cjs");
|
|
5
5
|
const require_image_jbig2_generic = require("./jbig2-generic.cjs");
|
|
6
6
|
//#region src/image/jbig2-text.ts
|
|
7
|
+
const GENERIC_TEMPLATE_0_CONTEXT_BITS = 16;
|
|
8
|
+
const REFINEMENT_TEMPLATE_0_CONTEXT_BITS = 13;
|
|
7
9
|
const REFERENCE_CORNERS = [
|
|
8
10
|
{
|
|
9
11
|
right: false,
|
|
@@ -46,8 +48,8 @@ function createTextArithContexts(genericTemplate, refinementTemplate, symbolIdBi
|
|
|
46
48
|
iardx: require_image_jbig2_arith.createIntegerContexts(),
|
|
47
49
|
iardy: require_image_jbig2_arith.createIntegerContexts(),
|
|
48
50
|
iaid: require_image_jbig2_arith.createSymbolIdContexts(symbolIdBits),
|
|
49
|
-
generic: require_image_jbig2_arith.createArithContexts(require_image_jbig2_generic.GENERIC_CONTEXT_BITS[genericTemplate] ??
|
|
50
|
-
refinement: require_image_jbig2_arith.createArithContexts(require_image_jbig2_generic.REFINEMENT_CONTEXT_BITS[refinementTemplate] ??
|
|
51
|
+
generic: require_image_jbig2_arith.createArithContexts(require_image_jbig2_generic.GENERIC_CONTEXT_BITS[genericTemplate] ?? GENERIC_TEMPLATE_0_CONTEXT_BITS),
|
|
52
|
+
refinement: require_image_jbig2_arith.createArithContexts(require_image_jbig2_generic.REFINEMENT_CONTEXT_BITS[refinementTemplate] ?? REFINEMENT_TEMPLATE_0_CONTEXT_BITS)
|
|
51
53
|
};
|
|
52
54
|
}
|
|
53
55
|
function instanceTopLeft(s, t, width, height, corner, transposed) {
|
package/dist/image/jbig2-text.js
CHANGED
|
@@ -3,6 +3,8 @@ import { Jbig2ParseError, Jbig2UnsupportedError } from "./jbig2-errors.js";
|
|
|
3
3
|
import { combineBitmap, createBitmap } from "./jbig2-bitmap.js";
|
|
4
4
|
import { GENERIC_CONTEXT_BITS, REFINEMENT_CONTEXT_BITS, decodeGenericRegion, decodeRefinementRegion } from "./jbig2-generic.js";
|
|
5
5
|
//#region src/image/jbig2-text.ts
|
|
6
|
+
const GENERIC_TEMPLATE_0_CONTEXT_BITS = 16;
|
|
7
|
+
const REFINEMENT_TEMPLATE_0_CONTEXT_BITS = 13;
|
|
6
8
|
const REFERENCE_CORNERS = [
|
|
7
9
|
{
|
|
8
10
|
right: false,
|
|
@@ -45,8 +47,8 @@ function createTextArithContexts(genericTemplate, refinementTemplate, symbolIdBi
|
|
|
45
47
|
iardx: createIntegerContexts(),
|
|
46
48
|
iardy: createIntegerContexts(),
|
|
47
49
|
iaid: createSymbolIdContexts(symbolIdBits),
|
|
48
|
-
generic: createArithContexts(GENERIC_CONTEXT_BITS[genericTemplate] ??
|
|
49
|
-
refinement: createArithContexts(REFINEMENT_CONTEXT_BITS[refinementTemplate] ??
|
|
50
|
+
generic: createArithContexts(GENERIC_CONTEXT_BITS[genericTemplate] ?? GENERIC_TEMPLATE_0_CONTEXT_BITS),
|
|
51
|
+
refinement: createArithContexts(REFINEMENT_CONTEXT_BITS[refinementTemplate] ?? REFINEMENT_TEMPLATE_0_CONTEXT_BITS)
|
|
50
52
|
};
|
|
51
53
|
}
|
|
52
54
|
function instanceTopLeft(s, t, width, height, corner, transposed) {
|
package/dist/image/jbig2.cjs
CHANGED
|
@@ -29,6 +29,44 @@ const SEGMENT_TABLES = 53;
|
|
|
29
29
|
const SEGMENT_EXTENSION = 62;
|
|
30
30
|
const UNKNOWN_DATA_LENGTH = 4294967295;
|
|
31
31
|
const UNKNOWN_PAGE_HEIGHT = 4294967295;
|
|
32
|
+
const BITS_PER_BYTE = 8;
|
|
33
|
+
const UINT8_MODULUS = 256;
|
|
34
|
+
const INT8_MAX = UINT8_MODULUS / 2 - 1;
|
|
35
|
+
const UINT32_BYTE_2_SHIFT = 16;
|
|
36
|
+
const UINT32_BYTE_3_SHIFT = 24;
|
|
37
|
+
const SEGMENT_TYPE_MASK = 63;
|
|
38
|
+
const PAGE_ASSOCIATION_SIZE_FLAG = 64;
|
|
39
|
+
const REFERRED_COUNT_SHORT_SHIFT = 5;
|
|
40
|
+
const REFERRED_COUNT_LONG_FORM_SENTINEL = 7;
|
|
41
|
+
const REFERRED_COUNT_LONG_MASK = 536870911;
|
|
42
|
+
const SEGMENT_NUMBER_1BYTE_LIMIT = 256;
|
|
43
|
+
const SEGMENT_NUMBER_2BYTE_LIMIT = 65536;
|
|
44
|
+
const REFERRED_NUMBER_SIZE_4_BYTES = 4;
|
|
45
|
+
const REGION_COMBOP_MASK = 7;
|
|
46
|
+
const PAGE_DEFAULT_COMBOP_SHIFT = 3;
|
|
47
|
+
const PAGE_DEFAULT_COMBOP_MASK = 3;
|
|
48
|
+
const PAGE_COMBOP_OVERRIDE_FLAG = 64;
|
|
49
|
+
const GENERIC_CODING_AT_PIXEL_COUNT_TEMPLATE_0 = 4;
|
|
50
|
+
const GENERIC_TEMPLATE_0_CONTEXT_BITS = 16;
|
|
51
|
+
const REFINEMENT_TEMPLATE_0_CONTEXT_BITS = 13;
|
|
52
|
+
const GENERIC_REGION_TEMPLATE_MASK = 3;
|
|
53
|
+
const GENERIC_REGION_TPGDON_FLAG = 8;
|
|
54
|
+
const GENERIC_REGION_EXTTEMPLATE_FLAG = 16;
|
|
55
|
+
const SYMBOL_DICT_BITMAP_CODING_CONTEXT_USED = 256;
|
|
56
|
+
const SYMBOL_DICT_BITMAP_CODING_CONTEXT_RETAINED = 512;
|
|
57
|
+
const SYMBOL_DICT_TEMPLATE_SHIFT = 10;
|
|
58
|
+
const SYMBOL_DICT_TEMPLATE_MASK = 3;
|
|
59
|
+
const SYMBOL_DICT_REFINEMENT_TEMPLATE_SHIFT = 12;
|
|
60
|
+
const TEXT_REGION_STRIP_SIZE_LOG_MASK = 3;
|
|
61
|
+
const TEXT_REGION_REFCORNER_SHIFT = 4;
|
|
62
|
+
const TEXT_REGION_REFCORNER_MASK = 3;
|
|
63
|
+
const TEXT_REGION_TRANSPOSED_FLAG = 64;
|
|
64
|
+
const TEXT_REGION_SBCOMBOP_SHIFT = 7;
|
|
65
|
+
const TEXT_REGION_SBCOMBOP_MASK = 3;
|
|
66
|
+
const TEXT_REGION_DEFAULT_PIXEL_SHIFT = 9;
|
|
67
|
+
const TEXT_REGION_REFINEMENT_TEMPLATE_SHIFT = 15;
|
|
68
|
+
const SBDSOFFSET_SIGN_EXTEND_LEFT_SHIFT = 17;
|
|
69
|
+
const SBDSOFFSET_SIGN_EXTEND_RIGHT_SHIFT = 27;
|
|
32
70
|
var ByteCursor = class {
|
|
33
71
|
data;
|
|
34
72
|
position;
|
|
@@ -46,28 +84,28 @@ var ByteCursor = class {
|
|
|
46
84
|
return value;
|
|
47
85
|
}
|
|
48
86
|
uint16() {
|
|
49
|
-
return this.uint8() <<
|
|
87
|
+
return this.uint8() << BITS_PER_BYTE | this.uint8();
|
|
50
88
|
}
|
|
51
89
|
uint32() {
|
|
52
|
-
return (this.uint8() <<
|
|
90
|
+
return (this.uint8() << UINT32_BYTE_3_SHIFT | this.uint8() << UINT32_BYTE_2_SHIFT | this.uint8() << BITS_PER_BYTE | this.uint8()) >>> 0;
|
|
53
91
|
}
|
|
54
92
|
int8() {
|
|
55
93
|
const value = this.uint8();
|
|
56
|
-
return value >
|
|
94
|
+
return value > INT8_MAX ? value - UINT8_MODULUS : value;
|
|
57
95
|
}
|
|
58
96
|
};
|
|
59
97
|
function readSegmentHeader(cursor, dataLength) {
|
|
60
98
|
const number = cursor.uint32();
|
|
61
99
|
const flags = cursor.uint8();
|
|
62
|
-
const type = flags &
|
|
63
|
-
const pageAssociationIsLong = (flags &
|
|
64
|
-
let referredCount = cursor.uint8() >>
|
|
65
|
-
if (referredCount ===
|
|
100
|
+
const type = flags & SEGMENT_TYPE_MASK;
|
|
101
|
+
const pageAssociationIsLong = (flags & PAGE_ASSOCIATION_SIZE_FLAG) !== 0;
|
|
102
|
+
let referredCount = cursor.uint8() >> REFERRED_COUNT_SHORT_SHIFT;
|
|
103
|
+
if (referredCount === REFERRED_COUNT_LONG_FORM_SENTINEL) {
|
|
66
104
|
cursor.position -= 1;
|
|
67
|
-
referredCount = cursor.uint32() &
|
|
68
|
-
cursor.position += Math.ceil((referredCount + 1) /
|
|
105
|
+
referredCount = cursor.uint32() & REFERRED_COUNT_LONG_MASK;
|
|
106
|
+
cursor.position += Math.ceil((referredCount + 1) / BITS_PER_BYTE);
|
|
69
107
|
}
|
|
70
|
-
const referredSize = number <=
|
|
108
|
+
const referredSize = number <= SEGMENT_NUMBER_1BYTE_LIMIT ? 1 : number <= SEGMENT_NUMBER_2BYTE_LIMIT ? 2 : REFERRED_NUMBER_SIZE_4_BYTES;
|
|
71
109
|
const referredTo = [];
|
|
72
110
|
for (let i = 0; i < referredCount; i++) referredTo.push(referredSize === 1 ? cursor.uint8() : referredSize === 2 ? cursor.uint16() : cursor.uint32());
|
|
73
111
|
const pageAssociation = pageAssociationIsLong ? cursor.uint32() : cursor.uint8();
|
|
@@ -91,8 +129,8 @@ function readRegionInfo(cursor) {
|
|
|
91
129
|
const x = cursor.uint32();
|
|
92
130
|
const y = cursor.uint32();
|
|
93
131
|
const flags = cursor.uint8();
|
|
94
|
-
const combinationOperator = require_image_jbig2_bitmap.combinationOperatorFromCode(flags &
|
|
95
|
-
if (combinationOperator === void 0) throw new require_image_jbig2_errors.Jbig2ParseError(`JBIG2 region declares external combination operator ${String(flags &
|
|
132
|
+
const combinationOperator = require_image_jbig2_bitmap.combinationOperatorFromCode(flags & REGION_COMBOP_MASK);
|
|
133
|
+
if (combinationOperator === void 0) throw new require_image_jbig2_errors.Jbig2ParseError(`JBIG2 region declares external combination operator ${String(flags & REGION_COMBOP_MASK)}, outside the 0-4 range T.88 Table 12 defines`);
|
|
96
134
|
return {
|
|
97
135
|
width,
|
|
98
136
|
height,
|
|
@@ -175,12 +213,12 @@ var Jbig2Decoder = class {
|
|
|
175
213
|
const declaredOrHintedHeight = declaredHeight === UNKNOWN_PAGE_HEIGHT ? this.options.height : this.options.height ?? declaredHeight;
|
|
176
214
|
if (declaredOrHintedHeight === void 0) throw new require_image_jbig2_errors.Jbig2UnsupportedError("JBIG2 page information declares an unknown height and the caller supplied none; a striped page with no known height is not resolvable from the page segments alone");
|
|
177
215
|
const defaultPixel = flags >> 2 & 1;
|
|
178
|
-
const defaultCombinationOperator = require_image_jbig2_bitmap.combinationOperatorFromCode(flags >>
|
|
216
|
+
const defaultCombinationOperator = require_image_jbig2_bitmap.combinationOperatorFromCode(flags >> PAGE_DEFAULT_COMBOP_SHIFT & PAGE_DEFAULT_COMBOP_MASK);
|
|
179
217
|
if (defaultCombinationOperator === void 0) throw new require_image_jbig2_errors.Jbig2ParseError("JBIG2 page information declares an unrecognised default combination operator");
|
|
180
218
|
this.page = {
|
|
181
219
|
bitmap: require_image_jbig2_bitmap.createBitmap(width, declaredOrHintedHeight, defaultPixel),
|
|
182
220
|
defaultCombinationOperator,
|
|
183
|
-
combinationOperatorOverridden: (flags &
|
|
221
|
+
combinationOperatorOverridden: (flags & PAGE_COMBOP_OVERRIDE_FLAG) !== 0
|
|
184
222
|
};
|
|
185
223
|
}
|
|
186
224
|
requirePage() {
|
|
@@ -195,10 +233,10 @@ var Jbig2Decoder = class {
|
|
|
195
233
|
const region = readRegionInfo(cursor);
|
|
196
234
|
const flags = cursor.uint8();
|
|
197
235
|
const mmr = (flags & 1) !== 0;
|
|
198
|
-
const template = flags >> 1 &
|
|
199
|
-
const tpgdon = (flags &
|
|
200
|
-
if ((flags &
|
|
201
|
-
const at = mmr ? [] : readAtPixels(cursor, template === 0 ?
|
|
236
|
+
const template = flags >> 1 & GENERIC_REGION_TEMPLATE_MASK;
|
|
237
|
+
const tpgdon = (flags & GENERIC_REGION_TPGDON_FLAG) !== 0;
|
|
238
|
+
if ((flags & GENERIC_REGION_EXTTEMPLATE_FLAG) !== 0) throw new require_image_jbig2_errors.Jbig2UnsupportedError("JBIG2 generic region sets EXTTEMPLATE, the twelve-adaptive-pixel template of T.88 Amendment 2, which is not implemented");
|
|
239
|
+
const at = mmr ? [] : readAtPixels(cursor, template === 0 ? GENERIC_CODING_AT_PIXEL_COUNT_TEMPLATE_0 : 1);
|
|
202
240
|
const payload = cursor.position;
|
|
203
241
|
if (mmr) {
|
|
204
242
|
const fax = require_image_ccitt.decodeCcittFax(cursor.data.subarray(payload, dataEnd), {
|
|
@@ -214,7 +252,7 @@ var Jbig2Decoder = class {
|
|
|
214
252
|
return;
|
|
215
253
|
}
|
|
216
254
|
const mq = new require_image_jbig2_arith.MqDecoder(cursor.data, payload, dataEnd);
|
|
217
|
-
const contexts = require_image_jbig2_arith.createArithContexts(require_image_jbig2_generic.GENERIC_CONTEXT_BITS[template] ??
|
|
255
|
+
const contexts = require_image_jbig2_arith.createArithContexts(require_image_jbig2_generic.GENERIC_CONTEXT_BITS[template] ?? GENERIC_TEMPLATE_0_CONTEXT_BITS);
|
|
218
256
|
this.compose(region, require_image_jbig2_generic.decodeGenericRegion(region.width, region.height, {
|
|
219
257
|
template,
|
|
220
258
|
tpgdon,
|
|
@@ -231,7 +269,7 @@ var Jbig2Decoder = class {
|
|
|
231
269
|
const reference = require_image_jbig2_bitmap.createBitmap(region.width, region.height);
|
|
232
270
|
for (let y = 0; y < region.height; y++) for (let x = 0; x < region.width; x++) reference.data[y * region.width + x] = require_image_jbig2_bitmap.getPixel(page.bitmap, region.x + x, region.y + y);
|
|
233
271
|
const mq = new require_image_jbig2_arith.MqDecoder(cursor.data, cursor.position, dataEnd);
|
|
234
|
-
const contexts = require_image_jbig2_arith.createArithContexts(require_image_jbig2_generic.REFINEMENT_CONTEXT_BITS[template] ??
|
|
272
|
+
const contexts = require_image_jbig2_arith.createArithContexts(require_image_jbig2_generic.REFINEMENT_CONTEXT_BITS[template] ?? REFINEMENT_TEMPLATE_0_CONTEXT_BITS);
|
|
235
273
|
const refined = require_image_jbig2_generic.decodeRefinementRegion(region.width, region.height, {
|
|
236
274
|
template,
|
|
237
275
|
tpgron,
|
|
@@ -245,11 +283,11 @@ var Jbig2Decoder = class {
|
|
|
245
283
|
readSymbolDictionary(header, cursor) {
|
|
246
284
|
const flags = cursor.uint16();
|
|
247
285
|
if ((flags & 1) !== 0) throw new require_image_jbig2_errors.Jbig2UnsupportedError("JBIG2 symbol dictionary is Huffman-coded (SDHUFF = 1); only the arithmetic form is implemented");
|
|
248
|
-
if ((flags &
|
|
286
|
+
if ((flags & SYMBOL_DICT_BITMAP_CODING_CONTEXT_USED) !== 0 || (flags & SYMBOL_DICT_BITMAP_CODING_CONTEXT_RETAINED) !== 0) throw new require_image_jbig2_errors.Jbig2UnsupportedError("JBIG2 symbol dictionary uses or retains a shared bitmap coding context (T.88 7.4.3.1.1 bits 8-9), which is not implemented");
|
|
249
287
|
const refinementAggregate = (flags & 2) !== 0;
|
|
250
|
-
const template = flags >>
|
|
251
|
-
const refinementTemplate = flags >>
|
|
252
|
-
const at = readAtPixels(cursor, template === 0 ?
|
|
288
|
+
const template = flags >> SYMBOL_DICT_TEMPLATE_SHIFT & SYMBOL_DICT_TEMPLATE_MASK;
|
|
289
|
+
const refinementTemplate = flags >> SYMBOL_DICT_REFINEMENT_TEMPLATE_SHIFT & 1;
|
|
290
|
+
const at = readAtPixels(cursor, template === 0 ? GENERIC_CODING_AT_PIXEL_COUNT_TEMPLATE_0 : 1);
|
|
253
291
|
const refinementAt = refinementAggregate && refinementTemplate === 0 ? readAtPixels(cursor, 2) : [...require_image_jbig2_generic.NOMINAL_REFINEMENT_AT];
|
|
254
292
|
const exportedSymbolCount = cursor.uint32();
|
|
255
293
|
const newSymbolCount = cursor.uint32();
|
|
@@ -273,15 +311,15 @@ var Jbig2Decoder = class {
|
|
|
273
311
|
const flags = cursor.uint16();
|
|
274
312
|
if ((flags & 1) !== 0) throw new require_image_jbig2_errors.Jbig2UnsupportedError("JBIG2 text region is Huffman-coded (SBHUFF = 1); only the arithmetic form is implemented");
|
|
275
313
|
const refine = (flags & 2) !== 0;
|
|
276
|
-
const stripSize = 1 << (flags >> 2 &
|
|
277
|
-
const referenceCorner = require_image_jbig2_text.referenceCornerFromCode(flags >>
|
|
314
|
+
const stripSize = 1 << (flags >> 2 & TEXT_REGION_STRIP_SIZE_LOG_MASK);
|
|
315
|
+
const referenceCorner = require_image_jbig2_text.referenceCornerFromCode(flags >> TEXT_REGION_REFCORNER_SHIFT & TEXT_REGION_REFCORNER_MASK);
|
|
278
316
|
if (referenceCorner === void 0) throw new require_image_jbig2_errors.Jbig2ParseError("JBIG2 text region declares an unrecognised REFCORNER");
|
|
279
|
-
const transposed = (flags &
|
|
280
|
-
const combinationOperator = require_image_jbig2_bitmap.combinationOperatorFromCode(flags >>
|
|
317
|
+
const transposed = (flags & TEXT_REGION_TRANSPOSED_FLAG) !== 0;
|
|
318
|
+
const combinationOperator = require_image_jbig2_bitmap.combinationOperatorFromCode(flags >> TEXT_REGION_SBCOMBOP_SHIFT & TEXT_REGION_SBCOMBOP_MASK);
|
|
281
319
|
if (combinationOperator === void 0) throw new require_image_jbig2_errors.Jbig2ParseError("JBIG2 text region declares an unrecognised SBCOMBOP");
|
|
282
|
-
const defaultPixel = flags >>
|
|
283
|
-
const dsOffset = flags <<
|
|
284
|
-
const refinementTemplate = flags >>
|
|
320
|
+
const defaultPixel = flags >> TEXT_REGION_DEFAULT_PIXEL_SHIFT & 1;
|
|
321
|
+
const dsOffset = flags << SBDSOFFSET_SIGN_EXTEND_LEFT_SHIFT >> SBDSOFFSET_SIGN_EXTEND_RIGHT_SHIFT | 0;
|
|
322
|
+
const refinementTemplate = flags >> TEXT_REGION_REFINEMENT_TEMPLATE_SHIFT & 1;
|
|
285
323
|
const refinementAt = refine && refinementTemplate === 0 ? readAtPixels(cursor, 2) : [...require_image_jbig2_generic.NOMINAL_REFINEMENT_AT];
|
|
286
324
|
const instanceCount = cursor.uint32();
|
|
287
325
|
const symbols = this.gatherSymbols(header.referredTo);
|