pdf-codec 1.6.0 → 1.7.0
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/README.md +67 -9
- package/dist/cff-bounds.cjs +432 -0
- package/dist/cff-bounds.d.cts +9 -0
- package/dist/cff-bounds.d.ts +9 -0
- package/dist/cff-bounds.js +431 -0
- package/dist/cff-probe.cjs +8 -106
- package/dist/cff-probe.js +9 -107
- package/dist/cff.cjs +158 -0
- package/dist/cff.d.cts +17 -0
- package/dist/cff.d.ts +17 -0
- package/dist/cff.js +150 -0
- package/dist/filters.cjs +45 -2
- package/dist/filters.d.cts +4 -3
- package/dist/filters.d.ts +4 -3
- package/dist/filters.js +45 -2
- package/dist/formula.d.cts +1 -1
- package/dist/formula.d.ts +1 -1
- package/dist/glyf.cjs +62 -6
- package/dist/glyf.d.cts +2 -0
- package/dist/glyf.d.ts +2 -0
- package/dist/glyf.js +62 -6
- package/dist/glyph-bounds-BV_Z40KS.d.cts +10 -0
- package/dist/glyph-bounds-BV_Z40KS.d.ts +10 -0
- package/dist/glyph-bounds.cjs +12 -0
- package/dist/glyph-bounds.d.cts +2 -0
- package/dist/glyph-bounds.d.ts +2 -0
- package/dist/glyph-bounds.js +11 -0
- package/dist/image/jbig2-arith.cjs +432 -0
- package/dist/image/jbig2-arith.d.cts +23 -0
- package/dist/image/jbig2-arith.d.ts +23 -0
- package/dist/image/jbig2-arith.js +426 -0
- package/dist/image/jbig2-bitmap.cjs +80 -0
- package/dist/image/jbig2-bitmap.d.cts +20 -0
- package/dist/image/jbig2-bitmap.d.ts +20 -0
- package/dist/image/jbig2-bitmap.js +72 -0
- package/dist/image/jbig2-errors.cjs +17 -0
- package/dist/image/jbig2-errors.d.cts +2 -0
- package/dist/image/jbig2-errors.d.ts +2 -0
- package/dist/image/jbig2-errors.js +15 -0
- package/dist/image/jbig2-generic.cjs +242 -0
- package/dist/image/jbig2-generic.d.cts +27 -0
- package/dist/image/jbig2-generic.d.ts +27 -0
- package/dist/image/jbig2-generic.js +237 -0
- package/dist/image/jbig2-text.cjs +175 -0
- package/dist/image/jbig2-text.d.cts +58 -0
- package/dist/image/jbig2-text.d.ts +58 -0
- package/dist/image/jbig2-text.js +170 -0
- package/dist/image/jbig2.cjs +333 -0
- package/dist/image/jbig2.d.cts +15 -0
- package/dist/image/jbig2.d.ts +15 -0
- package/dist/image/jbig2.js +332 -0
- package/dist/image/jp2-boxes.cjs +148 -0
- package/dist/image/jp2-boxes.d.cts +26 -0
- package/dist/image/jp2-boxes.d.ts +26 -0
- package/dist/image/jp2-boxes.js +146 -0
- package/dist/image/jpeg2000-codestream.cjs +309 -0
- package/dist/image/jpeg2000-codestream.d.cts +78 -0
- package/dist/image/jpeg2000-codestream.d.ts +78 -0
- package/dist/image/jpeg2000-codestream.js +308 -0
- package/dist/image/jpeg2000-dwt.cjs +148 -0
- package/dist/image/jpeg2000-dwt.d.cts +34 -0
- package/dist/image/jpeg2000-dwt.d.ts +34 -0
- package/dist/image/jpeg2000-dwt.js +145 -0
- package/dist/image/jpeg2000-errors.cjs +17 -0
- package/dist/image/jpeg2000-errors.d.cts +9 -0
- package/dist/image/jpeg2000-errors.d.ts +9 -0
- package/dist/image/jpeg2000-errors.js +15 -0
- package/dist/image/jpeg2000-t1.cjs +254 -0
- package/dist/image/jpeg2000-t1.d.cts +18 -0
- package/dist/image/jpeg2000-t1.d.ts +18 -0
- package/dist/image/jpeg2000-t1.js +253 -0
- package/dist/image/jpeg2000-t2.cjs +316 -0
- package/dist/image/jpeg2000-t2.d.cts +79 -0
- package/dist/image/jpeg2000-t2.d.ts +79 -0
- package/dist/image/jpeg2000-t2.js +311 -0
- package/dist/image/jpeg2000-tagtree.cjs +105 -0
- package/dist/image/jpeg2000-tagtree.d.cts +29 -0
- package/dist/image/jpeg2000-tagtree.d.ts +29 -0
- package/dist/image/jpeg2000-tagtree.js +103 -0
- package/dist/image/jpeg2000.cjs +322 -0
- package/dist/image/jpeg2000.d.cts +54 -0
- package/dist/image/jpeg2000.d.ts +54 -0
- package/dist/image/jpeg2000.js +320 -0
- package/dist/images-read.cjs +78 -1
- package/dist/images-read.js +78 -1
- package/dist/index.cjs +17 -0
- package/dist/index.d.cts +11 -2
- package/dist/index.d.ts +11 -2
- package/dist/index.js +7 -1
- package/dist/jbig2-errors-Bj6MPxrx.d.cts +9 -0
- package/dist/jbig2-errors-Bj6MPxrx.d.ts +9 -0
- package/dist/math-font.cjs +43 -18
- package/dist/math-font.d.cts +8 -1
- package/dist/math-font.d.ts +8 -1
- package/dist/math-font.js +43 -18
- package/dist/math-stretch-Bwk_bxh1.d.ts +24 -0
- package/dist/math-stretch-DXWjs8gL.d.cts +24 -0
- package/dist/math-stretch.cjs +96 -0
- package/dist/math-stretch.d.cts +2 -0
- package/dist/math-stretch.d.ts +2 -0
- package/dist/math-stretch.js +94 -0
- package/dist/math-table-DhPrNoPa.d.ts +70 -0
- package/dist/math-table-gFNB8DmQ.d.cts +70 -0
- package/dist/math-table.cjs +69 -1
- package/dist/math-table.d.cts +2 -45
- package/dist/math-table.d.ts +2 -45
- package/dist/math-table.js +69 -1
- package/dist/{math-types-Ba8qAf1p.d.cts → math-types-YSQUTviw.d.cts} +2 -0
- package/dist/{math-types-Ba8qAf1p.d.ts → math-types-YSQUTviw.d.ts} +2 -0
- package/dist/math-types.d.cts +1 -1
- package/dist/math-types.d.ts +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,426 @@
|
|
|
1
|
+
//#region src/image/jbig2-arith.ts
|
|
2
|
+
const QE_STATES = [
|
|
3
|
+
[
|
|
4
|
+
22017,
|
|
5
|
+
1,
|
|
6
|
+
1,
|
|
7
|
+
1
|
|
8
|
+
],
|
|
9
|
+
[
|
|
10
|
+
13313,
|
|
11
|
+
2,
|
|
12
|
+
6,
|
|
13
|
+
0
|
|
14
|
+
],
|
|
15
|
+
[
|
|
16
|
+
6145,
|
|
17
|
+
3,
|
|
18
|
+
9,
|
|
19
|
+
0
|
|
20
|
+
],
|
|
21
|
+
[
|
|
22
|
+
2753,
|
|
23
|
+
4,
|
|
24
|
+
12,
|
|
25
|
+
0
|
|
26
|
+
],
|
|
27
|
+
[
|
|
28
|
+
1313,
|
|
29
|
+
5,
|
|
30
|
+
29,
|
|
31
|
+
0
|
|
32
|
+
],
|
|
33
|
+
[
|
|
34
|
+
545,
|
|
35
|
+
38,
|
|
36
|
+
33,
|
|
37
|
+
0
|
|
38
|
+
],
|
|
39
|
+
[
|
|
40
|
+
22017,
|
|
41
|
+
7,
|
|
42
|
+
6,
|
|
43
|
+
1
|
|
44
|
+
],
|
|
45
|
+
[
|
|
46
|
+
21505,
|
|
47
|
+
8,
|
|
48
|
+
14,
|
|
49
|
+
0
|
|
50
|
+
],
|
|
51
|
+
[
|
|
52
|
+
18433,
|
|
53
|
+
9,
|
|
54
|
+
14,
|
|
55
|
+
0
|
|
56
|
+
],
|
|
57
|
+
[
|
|
58
|
+
14337,
|
|
59
|
+
10,
|
|
60
|
+
14,
|
|
61
|
+
0
|
|
62
|
+
],
|
|
63
|
+
[
|
|
64
|
+
12289,
|
|
65
|
+
11,
|
|
66
|
+
17,
|
|
67
|
+
0
|
|
68
|
+
],
|
|
69
|
+
[
|
|
70
|
+
9217,
|
|
71
|
+
12,
|
|
72
|
+
18,
|
|
73
|
+
0
|
|
74
|
+
],
|
|
75
|
+
[
|
|
76
|
+
7169,
|
|
77
|
+
13,
|
|
78
|
+
20,
|
|
79
|
+
0
|
|
80
|
+
],
|
|
81
|
+
[
|
|
82
|
+
5633,
|
|
83
|
+
29,
|
|
84
|
+
21,
|
|
85
|
+
0
|
|
86
|
+
],
|
|
87
|
+
[
|
|
88
|
+
22017,
|
|
89
|
+
15,
|
|
90
|
+
14,
|
|
91
|
+
1
|
|
92
|
+
],
|
|
93
|
+
[
|
|
94
|
+
21505,
|
|
95
|
+
16,
|
|
96
|
+
14,
|
|
97
|
+
0
|
|
98
|
+
],
|
|
99
|
+
[
|
|
100
|
+
20737,
|
|
101
|
+
17,
|
|
102
|
+
15,
|
|
103
|
+
0
|
|
104
|
+
],
|
|
105
|
+
[
|
|
106
|
+
18433,
|
|
107
|
+
18,
|
|
108
|
+
16,
|
|
109
|
+
0
|
|
110
|
+
],
|
|
111
|
+
[
|
|
112
|
+
14337,
|
|
113
|
+
19,
|
|
114
|
+
17,
|
|
115
|
+
0
|
|
116
|
+
],
|
|
117
|
+
[
|
|
118
|
+
13313,
|
|
119
|
+
20,
|
|
120
|
+
18,
|
|
121
|
+
0
|
|
122
|
+
],
|
|
123
|
+
[
|
|
124
|
+
12289,
|
|
125
|
+
21,
|
|
126
|
+
19,
|
|
127
|
+
0
|
|
128
|
+
],
|
|
129
|
+
[
|
|
130
|
+
10241,
|
|
131
|
+
22,
|
|
132
|
+
19,
|
|
133
|
+
0
|
|
134
|
+
],
|
|
135
|
+
[
|
|
136
|
+
9217,
|
|
137
|
+
23,
|
|
138
|
+
20,
|
|
139
|
+
0
|
|
140
|
+
],
|
|
141
|
+
[
|
|
142
|
+
8705,
|
|
143
|
+
24,
|
|
144
|
+
21,
|
|
145
|
+
0
|
|
146
|
+
],
|
|
147
|
+
[
|
|
148
|
+
7169,
|
|
149
|
+
25,
|
|
150
|
+
22,
|
|
151
|
+
0
|
|
152
|
+
],
|
|
153
|
+
[
|
|
154
|
+
6145,
|
|
155
|
+
26,
|
|
156
|
+
23,
|
|
157
|
+
0
|
|
158
|
+
],
|
|
159
|
+
[
|
|
160
|
+
5633,
|
|
161
|
+
27,
|
|
162
|
+
24,
|
|
163
|
+
0
|
|
164
|
+
],
|
|
165
|
+
[
|
|
166
|
+
5121,
|
|
167
|
+
28,
|
|
168
|
+
25,
|
|
169
|
+
0
|
|
170
|
+
],
|
|
171
|
+
[
|
|
172
|
+
4609,
|
|
173
|
+
29,
|
|
174
|
+
26,
|
|
175
|
+
0
|
|
176
|
+
],
|
|
177
|
+
[
|
|
178
|
+
4353,
|
|
179
|
+
30,
|
|
180
|
+
27,
|
|
181
|
+
0
|
|
182
|
+
],
|
|
183
|
+
[
|
|
184
|
+
2753,
|
|
185
|
+
31,
|
|
186
|
+
28,
|
|
187
|
+
0
|
|
188
|
+
],
|
|
189
|
+
[
|
|
190
|
+
2497,
|
|
191
|
+
32,
|
|
192
|
+
29,
|
|
193
|
+
0
|
|
194
|
+
],
|
|
195
|
+
[
|
|
196
|
+
2209,
|
|
197
|
+
33,
|
|
198
|
+
30,
|
|
199
|
+
0
|
|
200
|
+
],
|
|
201
|
+
[
|
|
202
|
+
1313,
|
|
203
|
+
34,
|
|
204
|
+
31,
|
|
205
|
+
0
|
|
206
|
+
],
|
|
207
|
+
[
|
|
208
|
+
1089,
|
|
209
|
+
35,
|
|
210
|
+
32,
|
|
211
|
+
0
|
|
212
|
+
],
|
|
213
|
+
[
|
|
214
|
+
673,
|
|
215
|
+
36,
|
|
216
|
+
33,
|
|
217
|
+
0
|
|
218
|
+
],
|
|
219
|
+
[
|
|
220
|
+
545,
|
|
221
|
+
37,
|
|
222
|
+
34,
|
|
223
|
+
0
|
|
224
|
+
],
|
|
225
|
+
[
|
|
226
|
+
321,
|
|
227
|
+
38,
|
|
228
|
+
35,
|
|
229
|
+
0
|
|
230
|
+
],
|
|
231
|
+
[
|
|
232
|
+
273,
|
|
233
|
+
39,
|
|
234
|
+
36,
|
|
235
|
+
0
|
|
236
|
+
],
|
|
237
|
+
[
|
|
238
|
+
133,
|
|
239
|
+
40,
|
|
240
|
+
37,
|
|
241
|
+
0
|
|
242
|
+
],
|
|
243
|
+
[
|
|
244
|
+
73,
|
|
245
|
+
41,
|
|
246
|
+
38,
|
|
247
|
+
0
|
|
248
|
+
],
|
|
249
|
+
[
|
|
250
|
+
37,
|
|
251
|
+
42,
|
|
252
|
+
39,
|
|
253
|
+
0
|
|
254
|
+
],
|
|
255
|
+
[
|
|
256
|
+
21,
|
|
257
|
+
43,
|
|
258
|
+
40,
|
|
259
|
+
0
|
|
260
|
+
],
|
|
261
|
+
[
|
|
262
|
+
9,
|
|
263
|
+
44,
|
|
264
|
+
41,
|
|
265
|
+
0
|
|
266
|
+
],
|
|
267
|
+
[
|
|
268
|
+
5,
|
|
269
|
+
45,
|
|
270
|
+
42,
|
|
271
|
+
0
|
|
272
|
+
],
|
|
273
|
+
[
|
|
274
|
+
1,
|
|
275
|
+
45,
|
|
276
|
+
43,
|
|
277
|
+
0
|
|
278
|
+
],
|
|
279
|
+
[
|
|
280
|
+
22017,
|
|
281
|
+
46,
|
|
282
|
+
46,
|
|
283
|
+
0
|
|
284
|
+
]
|
|
285
|
+
];
|
|
286
|
+
const QE_VALUE = Uint16Array.from(QE_STATES, (row) => row[0]);
|
|
287
|
+
const QE_NMPS = Uint8Array.from(QE_STATES, (row) => row[1]);
|
|
288
|
+
const QE_NLPS = Uint8Array.from(QE_STATES, (row) => row[2]);
|
|
289
|
+
const QE_SWITCH = Uint8Array.from(QE_STATES, (row) => row[3]);
|
|
290
|
+
function createArithContexts(contextBits) {
|
|
291
|
+
return new Uint8Array(1 << contextBits);
|
|
292
|
+
}
|
|
293
|
+
const A_INITIAL = 32768;
|
|
294
|
+
const C_INITIAL_SHIFT = 16;
|
|
295
|
+
const INITDEC_C_SHIFT = 7;
|
|
296
|
+
const PAST_END_BYTE = 255;
|
|
297
|
+
var MqDecoder = class {
|
|
298
|
+
data;
|
|
299
|
+
start;
|
|
300
|
+
end;
|
|
301
|
+
bp;
|
|
302
|
+
c = 0;
|
|
303
|
+
a = 0;
|
|
304
|
+
ct = 0;
|
|
305
|
+
constructor(data, start = 0, end = data.length) {
|
|
306
|
+
this.data = data;
|
|
307
|
+
this.start = start;
|
|
308
|
+
this.end = end;
|
|
309
|
+
this.bp = start;
|
|
310
|
+
this.c = this.byteAt(this.bp) << C_INITIAL_SHIFT >>> 0;
|
|
311
|
+
this.byteIn();
|
|
312
|
+
this.c = this.c << INITDEC_C_SHIFT >>> 0;
|
|
313
|
+
this.ct -= INITDEC_C_SHIFT;
|
|
314
|
+
this.a = A_INITIAL;
|
|
315
|
+
}
|
|
316
|
+
byteAt(index) {
|
|
317
|
+
return index >= this.start && index < this.end ? this.data[index] ?? PAST_END_BYTE : PAST_END_BYTE;
|
|
318
|
+
}
|
|
319
|
+
byteIn() {
|
|
320
|
+
if (this.byteAt(this.bp) === 255) {
|
|
321
|
+
if (this.byteAt(this.bp + 1) > 143) {
|
|
322
|
+
this.c = this.c + 65280 >>> 0;
|
|
323
|
+
this.ct = 8;
|
|
324
|
+
return;
|
|
325
|
+
}
|
|
326
|
+
this.bp++;
|
|
327
|
+
this.c = this.c + (this.byteAt(this.bp) << 9) >>> 0;
|
|
328
|
+
this.ct = 7;
|
|
329
|
+
return;
|
|
330
|
+
}
|
|
331
|
+
this.bp++;
|
|
332
|
+
this.c = this.c + (this.byteAt(this.bp) << 8) >>> 0;
|
|
333
|
+
this.ct = 8;
|
|
334
|
+
}
|
|
335
|
+
renormalise() {
|
|
336
|
+
do {
|
|
337
|
+
if (this.ct === 0) this.byteIn();
|
|
338
|
+
this.a = this.a << 1 & 65535;
|
|
339
|
+
this.c = this.c << 1 >>> 0;
|
|
340
|
+
this.ct--;
|
|
341
|
+
} while ((this.a & A_INITIAL) === 0);
|
|
342
|
+
}
|
|
343
|
+
decode(contexts, contextIndex) {
|
|
344
|
+
const state = contexts[contextIndex] ?? 0;
|
|
345
|
+
let index = state >> 1;
|
|
346
|
+
let mps = state & 1;
|
|
347
|
+
const qe = QE_VALUE[index] ?? 0;
|
|
348
|
+
this.a -= qe;
|
|
349
|
+
let decision;
|
|
350
|
+
if (this.c >>> 16 < qe) {
|
|
351
|
+
if (this.a < qe) {
|
|
352
|
+
decision = mps;
|
|
353
|
+
index = QE_NMPS[index] ?? 0;
|
|
354
|
+
} else {
|
|
355
|
+
decision = 1 - mps;
|
|
356
|
+
if (QE_SWITCH[index] === 1) mps = 1 - mps;
|
|
357
|
+
index = QE_NLPS[index] ?? 0;
|
|
358
|
+
}
|
|
359
|
+
this.a = qe;
|
|
360
|
+
} else {
|
|
361
|
+
this.c = this.c - (qe << 16) >>> 0;
|
|
362
|
+
if ((this.a & A_INITIAL) !== 0) return mps;
|
|
363
|
+
if (this.a < qe) {
|
|
364
|
+
decision = 1 - mps;
|
|
365
|
+
if (QE_SWITCH[index] === 1) mps = 1 - mps;
|
|
366
|
+
index = QE_NLPS[index] ?? 0;
|
|
367
|
+
} else {
|
|
368
|
+
decision = mps;
|
|
369
|
+
index = QE_NMPS[index] ?? 0;
|
|
370
|
+
}
|
|
371
|
+
}
|
|
372
|
+
this.renormalise();
|
|
373
|
+
contexts[contextIndex] = index << 1 | mps;
|
|
374
|
+
return decision;
|
|
375
|
+
}
|
|
376
|
+
};
|
|
377
|
+
const INTEGER_CONTEXT_BITS = 9;
|
|
378
|
+
function createIntegerContexts() {
|
|
379
|
+
return createArithContexts(INTEGER_CONTEXT_BITS);
|
|
380
|
+
}
|
|
381
|
+
const INTEGER_RANGES = [
|
|
382
|
+
[2, 0],
|
|
383
|
+
[4, 4],
|
|
384
|
+
[6, 20],
|
|
385
|
+
[8, 84],
|
|
386
|
+
[12, 340],
|
|
387
|
+
[32, 4436]
|
|
388
|
+
];
|
|
389
|
+
function decodeInteger(mq, contexts) {
|
|
390
|
+
let prev = 1;
|
|
391
|
+
const nextBit = () => {
|
|
392
|
+
const bit = mq.decode(contexts, prev);
|
|
393
|
+
prev = prev < 256 ? prev << 1 | bit : (prev << 1 | bit) & 511 | 256;
|
|
394
|
+
return bit;
|
|
395
|
+
};
|
|
396
|
+
const readBits = (count) => {
|
|
397
|
+
let value = 0;
|
|
398
|
+
for (let i = 0; i < count; i++) value = value * 2 + nextBit();
|
|
399
|
+
return value;
|
|
400
|
+
};
|
|
401
|
+
const sign = nextBit();
|
|
402
|
+
let magnitude = 0;
|
|
403
|
+
let matched = false;
|
|
404
|
+
for (let i = 0; i < INTEGER_RANGES.length - 1; i++) if (nextBit() === 0) {
|
|
405
|
+
const [bits, offset] = INTEGER_RANGES[i] ?? [0, 0];
|
|
406
|
+
magnitude = readBits(bits) + offset;
|
|
407
|
+
matched = true;
|
|
408
|
+
break;
|
|
409
|
+
}
|
|
410
|
+
if (!matched) {
|
|
411
|
+
const [bits, offset] = INTEGER_RANGES[INTEGER_RANGES.length - 1] ?? [0, 0];
|
|
412
|
+
magnitude = readBits(bits) + offset;
|
|
413
|
+
}
|
|
414
|
+
if (sign === 1) return magnitude === 0 ? void 0 : -magnitude;
|
|
415
|
+
return magnitude;
|
|
416
|
+
}
|
|
417
|
+
function createSymbolIdContexts(codeLength) {
|
|
418
|
+
return createArithContexts(codeLength + 1);
|
|
419
|
+
}
|
|
420
|
+
function decodeSymbolId(mq, contexts, codeLength) {
|
|
421
|
+
let prev = 1;
|
|
422
|
+
for (let i = 0; i < codeLength; i++) prev = prev << 1 | mq.decode(contexts, prev);
|
|
423
|
+
return prev - (1 << codeLength);
|
|
424
|
+
}
|
|
425
|
+
//#endregion
|
|
426
|
+
export { MqDecoder, createArithContexts, createIntegerContexts, createSymbolIdContexts, decodeInteger, decodeSymbolId };
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_image_jbig2_errors = require("./jbig2-errors.cjs");
|
|
3
|
+
//#region src/image/jbig2-bitmap.ts
|
|
4
|
+
const MAX_JBIG2_BITMAP_PIXELS = 1 << 26;
|
|
5
|
+
var Jbig2BitmapTooLargeError = class extends require_image_jbig2_errors.Jbig2ParseError {
|
|
6
|
+
constructor(width, height) {
|
|
7
|
+
super(`JBIG2 bitmap of ${String(width)}x${String(height)} exceeds the ${String(MAX_JBIG2_BITMAP_PIXELS)}-pixel limit this decoder allocates`);
|
|
8
|
+
this.name = "Jbig2BitmapTooLargeError";
|
|
9
|
+
}
|
|
10
|
+
};
|
|
11
|
+
function createBitmap(width, height, fill = 0) {
|
|
12
|
+
if (width < 0 || height < 0 || !Number.isFinite(width) || !Number.isFinite(height) || width * height > 67108864) throw new Jbig2BitmapTooLargeError(width, height);
|
|
13
|
+
const data = new Uint8Array(width * height);
|
|
14
|
+
if (fill !== 0) data.fill(1);
|
|
15
|
+
return {
|
|
16
|
+
width,
|
|
17
|
+
height,
|
|
18
|
+
data
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
function getPixel(bitmap, x, y) {
|
|
22
|
+
if (x < 0 || x >= bitmap.width || y < 0 || y >= bitmap.height) return 0;
|
|
23
|
+
return bitmap.data[y * bitmap.width + x] ?? 0;
|
|
24
|
+
}
|
|
25
|
+
const COMBINATION_OPERATORS = [
|
|
26
|
+
"or",
|
|
27
|
+
"and",
|
|
28
|
+
"xor",
|
|
29
|
+
"xnor",
|
|
30
|
+
"replace"
|
|
31
|
+
];
|
|
32
|
+
function combinationOperatorFromCode(code) {
|
|
33
|
+
return COMBINATION_OPERATORS[code];
|
|
34
|
+
}
|
|
35
|
+
function combineValue(destination, source, operator) {
|
|
36
|
+
if (operator === "or") return destination | source;
|
|
37
|
+
if (operator === "and") return destination & source;
|
|
38
|
+
if (operator === "xor") return destination ^ source;
|
|
39
|
+
if (operator === "xnor") return destination === source ? 1 : 0;
|
|
40
|
+
return source;
|
|
41
|
+
}
|
|
42
|
+
function combineBitmap(destination, source, x, y, operator) {
|
|
43
|
+
for (let sy = 0; sy < source.height; sy++) {
|
|
44
|
+
const dy = y + sy;
|
|
45
|
+
if (dy < 0 || dy >= destination.height) continue;
|
|
46
|
+
for (let sx = 0; sx < source.width; sx++) {
|
|
47
|
+
const dx = x + sx;
|
|
48
|
+
if (dx < 0 || dx >= destination.width) continue;
|
|
49
|
+
const destinationIndex = dy * destination.width + dx;
|
|
50
|
+
destination.data[destinationIndex] = combineValue(destination.data[destinationIndex] ?? 0, source.data[sy * source.width + sx] ?? 0, operator);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
function packBitmapRows(bitmap, width, height) {
|
|
55
|
+
const bytesPerRow = Math.ceil(width / 8);
|
|
56
|
+
const out = new Uint8Array(bytesPerRow * height);
|
|
57
|
+
for (let y = 0; y < height; y++) {
|
|
58
|
+
const rowStart = y * bytesPerRow;
|
|
59
|
+
for (let x = 0; x < width; x++) if (getPixel(bitmap, x, y) === 1) out[rowStart + (x >> 3)] = (out[rowStart + (x >> 3)] ?? 0) | 128 >> (x & 7);
|
|
60
|
+
}
|
|
61
|
+
return out;
|
|
62
|
+
}
|
|
63
|
+
function unpackBitmapRows(packed, width, height) {
|
|
64
|
+
const bitmap = createBitmap(width, height);
|
|
65
|
+
const bytesPerRow = Math.ceil(width / 8);
|
|
66
|
+
for (let y = 0; y < height; y++) {
|
|
67
|
+
const rowStart = y * bytesPerRow;
|
|
68
|
+
for (let x = 0; x < width; x++) bitmap.data[y * width + x] = (packed[rowStart + (x >> 3)] ?? 0) >> 7 - (x & 7) & 1;
|
|
69
|
+
}
|
|
70
|
+
return bitmap;
|
|
71
|
+
}
|
|
72
|
+
//#endregion
|
|
73
|
+
exports.Jbig2BitmapTooLargeError = Jbig2BitmapTooLargeError;
|
|
74
|
+
exports.MAX_JBIG2_BITMAP_PIXELS = MAX_JBIG2_BITMAP_PIXELS;
|
|
75
|
+
exports.combinationOperatorFromCode = combinationOperatorFromCode;
|
|
76
|
+
exports.combineBitmap = combineBitmap;
|
|
77
|
+
exports.createBitmap = createBitmap;
|
|
78
|
+
exports.getPixel = getPixel;
|
|
79
|
+
exports.packBitmapRows = packBitmapRows;
|
|
80
|
+
exports.unpackBitmapRows = unpackBitmapRows;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { t as Jbig2ParseError } from "../jbig2-errors-Bj6MPxrx.cjs";
|
|
2
|
+
//#region src/image/jbig2-bitmap.d.ts
|
|
3
|
+
interface Jbig2Bitmap {
|
|
4
|
+
readonly width: number;
|
|
5
|
+
readonly height: number;
|
|
6
|
+
readonly data: Uint8Array<ArrayBuffer>;
|
|
7
|
+
}
|
|
8
|
+
declare const MAX_JBIG2_BITMAP_PIXELS: number;
|
|
9
|
+
declare class Jbig2BitmapTooLargeError extends Jbig2ParseError {
|
|
10
|
+
constructor(width: number, height: number);
|
|
11
|
+
}
|
|
12
|
+
declare function createBitmap(width: number, height: number, fill?: number): Jbig2Bitmap;
|
|
13
|
+
declare function getPixel(bitmap: Jbig2Bitmap, x: number, y: number): number;
|
|
14
|
+
type Jbig2CombinationOperator = 'or' | 'and' | 'xor' | 'xnor' | 'replace';
|
|
15
|
+
declare function combinationOperatorFromCode(code: number): Jbig2CombinationOperator | undefined;
|
|
16
|
+
declare function combineBitmap(destination: Jbig2Bitmap, source: Jbig2Bitmap, x: number, y: number, operator: Jbig2CombinationOperator): void;
|
|
17
|
+
declare function packBitmapRows(bitmap: Jbig2Bitmap, width: number, height: number): Uint8Array<ArrayBuffer>;
|
|
18
|
+
declare function unpackBitmapRows(packed: Uint8Array<ArrayBuffer>, width: number, height: number): Jbig2Bitmap;
|
|
19
|
+
//#endregion
|
|
20
|
+
export { Jbig2Bitmap, Jbig2BitmapTooLargeError, Jbig2CombinationOperator, MAX_JBIG2_BITMAP_PIXELS, combinationOperatorFromCode, combineBitmap, createBitmap, getPixel, packBitmapRows, unpackBitmapRows };
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { t as Jbig2ParseError } from "../jbig2-errors-Bj6MPxrx.js";
|
|
2
|
+
//#region src/image/jbig2-bitmap.d.ts
|
|
3
|
+
interface Jbig2Bitmap {
|
|
4
|
+
readonly width: number;
|
|
5
|
+
readonly height: number;
|
|
6
|
+
readonly data: Uint8Array<ArrayBuffer>;
|
|
7
|
+
}
|
|
8
|
+
declare const MAX_JBIG2_BITMAP_PIXELS: number;
|
|
9
|
+
declare class Jbig2BitmapTooLargeError extends Jbig2ParseError {
|
|
10
|
+
constructor(width: number, height: number);
|
|
11
|
+
}
|
|
12
|
+
declare function createBitmap(width: number, height: number, fill?: number): Jbig2Bitmap;
|
|
13
|
+
declare function getPixel(bitmap: Jbig2Bitmap, x: number, y: number): number;
|
|
14
|
+
type Jbig2CombinationOperator = 'or' | 'and' | 'xor' | 'xnor' | 'replace';
|
|
15
|
+
declare function combinationOperatorFromCode(code: number): Jbig2CombinationOperator | undefined;
|
|
16
|
+
declare function combineBitmap(destination: Jbig2Bitmap, source: Jbig2Bitmap, x: number, y: number, operator: Jbig2CombinationOperator): void;
|
|
17
|
+
declare function packBitmapRows(bitmap: Jbig2Bitmap, width: number, height: number): Uint8Array<ArrayBuffer>;
|
|
18
|
+
declare function unpackBitmapRows(packed: Uint8Array<ArrayBuffer>, width: number, height: number): Jbig2Bitmap;
|
|
19
|
+
//#endregion
|
|
20
|
+
export { Jbig2Bitmap, Jbig2BitmapTooLargeError, Jbig2CombinationOperator, MAX_JBIG2_BITMAP_PIXELS, combinationOperatorFromCode, combineBitmap, createBitmap, getPixel, packBitmapRows, unpackBitmapRows };
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { Jbig2ParseError } from "./jbig2-errors.js";
|
|
2
|
+
//#region src/image/jbig2-bitmap.ts
|
|
3
|
+
const MAX_JBIG2_BITMAP_PIXELS = 1 << 26;
|
|
4
|
+
var Jbig2BitmapTooLargeError = class extends Jbig2ParseError {
|
|
5
|
+
constructor(width, height) {
|
|
6
|
+
super(`JBIG2 bitmap of ${String(width)}x${String(height)} exceeds the ${String(MAX_JBIG2_BITMAP_PIXELS)}-pixel limit this decoder allocates`);
|
|
7
|
+
this.name = "Jbig2BitmapTooLargeError";
|
|
8
|
+
}
|
|
9
|
+
};
|
|
10
|
+
function createBitmap(width, height, fill = 0) {
|
|
11
|
+
if (width < 0 || height < 0 || !Number.isFinite(width) || !Number.isFinite(height) || width * height > 67108864) throw new Jbig2BitmapTooLargeError(width, height);
|
|
12
|
+
const data = new Uint8Array(width * height);
|
|
13
|
+
if (fill !== 0) data.fill(1);
|
|
14
|
+
return {
|
|
15
|
+
width,
|
|
16
|
+
height,
|
|
17
|
+
data
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
function getPixel(bitmap, x, y) {
|
|
21
|
+
if (x < 0 || x >= bitmap.width || y < 0 || y >= bitmap.height) return 0;
|
|
22
|
+
return bitmap.data[y * bitmap.width + x] ?? 0;
|
|
23
|
+
}
|
|
24
|
+
const COMBINATION_OPERATORS = [
|
|
25
|
+
"or",
|
|
26
|
+
"and",
|
|
27
|
+
"xor",
|
|
28
|
+
"xnor",
|
|
29
|
+
"replace"
|
|
30
|
+
];
|
|
31
|
+
function combinationOperatorFromCode(code) {
|
|
32
|
+
return COMBINATION_OPERATORS[code];
|
|
33
|
+
}
|
|
34
|
+
function combineValue(destination, source, operator) {
|
|
35
|
+
if (operator === "or") return destination | source;
|
|
36
|
+
if (operator === "and") return destination & source;
|
|
37
|
+
if (operator === "xor") return destination ^ source;
|
|
38
|
+
if (operator === "xnor") return destination === source ? 1 : 0;
|
|
39
|
+
return source;
|
|
40
|
+
}
|
|
41
|
+
function combineBitmap(destination, source, x, y, operator) {
|
|
42
|
+
for (let sy = 0; sy < source.height; sy++) {
|
|
43
|
+
const dy = y + sy;
|
|
44
|
+
if (dy < 0 || dy >= destination.height) continue;
|
|
45
|
+
for (let sx = 0; sx < source.width; sx++) {
|
|
46
|
+
const dx = x + sx;
|
|
47
|
+
if (dx < 0 || dx >= destination.width) continue;
|
|
48
|
+
const destinationIndex = dy * destination.width + dx;
|
|
49
|
+
destination.data[destinationIndex] = combineValue(destination.data[destinationIndex] ?? 0, source.data[sy * source.width + sx] ?? 0, operator);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
function packBitmapRows(bitmap, width, height) {
|
|
54
|
+
const bytesPerRow = Math.ceil(width / 8);
|
|
55
|
+
const out = new Uint8Array(bytesPerRow * height);
|
|
56
|
+
for (let y = 0; y < height; y++) {
|
|
57
|
+
const rowStart = y * bytesPerRow;
|
|
58
|
+
for (let x = 0; x < width; x++) if (getPixel(bitmap, x, y) === 1) out[rowStart + (x >> 3)] = (out[rowStart + (x >> 3)] ?? 0) | 128 >> (x & 7);
|
|
59
|
+
}
|
|
60
|
+
return out;
|
|
61
|
+
}
|
|
62
|
+
function unpackBitmapRows(packed, width, height) {
|
|
63
|
+
const bitmap = createBitmap(width, height);
|
|
64
|
+
const bytesPerRow = Math.ceil(width / 8);
|
|
65
|
+
for (let y = 0; y < height; y++) {
|
|
66
|
+
const rowStart = y * bytesPerRow;
|
|
67
|
+
for (let x = 0; x < width; x++) bitmap.data[y * width + x] = (packed[rowStart + (x >> 3)] ?? 0) >> 7 - (x & 7) & 1;
|
|
68
|
+
}
|
|
69
|
+
return bitmap;
|
|
70
|
+
}
|
|
71
|
+
//#endregion
|
|
72
|
+
export { Jbig2BitmapTooLargeError, MAX_JBIG2_BITMAP_PIXELS, combinationOperatorFromCode, combineBitmap, createBitmap, getPixel, packBitmapRows, unpackBitmapRows };
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
//#region src/image/jbig2-errors.ts
|
|
3
|
+
var Jbig2ParseError = class extends Error {
|
|
4
|
+
constructor(message) {
|
|
5
|
+
super(message);
|
|
6
|
+
this.name = "Jbig2ParseError";
|
|
7
|
+
}
|
|
8
|
+
};
|
|
9
|
+
var Jbig2UnsupportedError = class extends Error {
|
|
10
|
+
constructor(message) {
|
|
11
|
+
super(message);
|
|
12
|
+
this.name = "Jbig2UnsupportedError";
|
|
13
|
+
}
|
|
14
|
+
};
|
|
15
|
+
//#endregion
|
|
16
|
+
exports.Jbig2ParseError = Jbig2ParseError;
|
|
17
|
+
exports.Jbig2UnsupportedError = Jbig2UnsupportedError;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
//#region src/image/jbig2-errors.ts
|
|
2
|
+
var Jbig2ParseError = class extends Error {
|
|
3
|
+
constructor(message) {
|
|
4
|
+
super(message);
|
|
5
|
+
this.name = "Jbig2ParseError";
|
|
6
|
+
}
|
|
7
|
+
};
|
|
8
|
+
var Jbig2UnsupportedError = class extends Error {
|
|
9
|
+
constructor(message) {
|
|
10
|
+
super(message);
|
|
11
|
+
this.name = "Jbig2UnsupportedError";
|
|
12
|
+
}
|
|
13
|
+
};
|
|
14
|
+
//#endregion
|
|
15
|
+
export { Jbig2ParseError, Jbig2UnsupportedError };
|