pdf-codec 1.6.0 → 1.8.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 +75 -12
- 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-content-write.cjs +37 -1
- package/dist/math-content-write.d.cts +1 -1
- package/dist/math-content-write.d.ts +1 -1
- package/dist/math-content-write.js +38 -2
- package/dist/math-font-write.cjs +6 -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 +6 -1
- package/dist/math-font.cjs +91 -18
- package/dist/math-font.d.cts +8 -1
- package/dist/math-font.d.ts +8 -1
- package/dist/math-font.js +91 -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.ts → math-types-BZkWO5Ow.d.cts} +30 -2
- package/dist/{math-types-Ba8qAf1p.d.cts → math-types-Bq7tyV4g.d.ts} +30 -2
- package/dist/math-types.d.cts +3 -2
- package/dist/math-types.d.ts +3 -2
- package/package.json +1 -1
|
@@ -0,0 +1,316 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_image_jpeg2000_errors = require("./jpeg2000-errors.cjs");
|
|
3
|
+
const require_image_jpeg2000_tagtree = require("./jpeg2000-tagtree.cjs");
|
|
4
|
+
//#region src/image/jpeg2000-t2.ts
|
|
5
|
+
const HIGHER_RESOLUTION_BANDS = [
|
|
6
|
+
"HL",
|
|
7
|
+
"LH",
|
|
8
|
+
"HH"
|
|
9
|
+
];
|
|
10
|
+
const SUBBAND_GAIN_LOG2 = {
|
|
11
|
+
LL: 0,
|
|
12
|
+
HL: 1,
|
|
13
|
+
LH: 1,
|
|
14
|
+
HH: 2
|
|
15
|
+
};
|
|
16
|
+
const INITIAL_LBLOCK = 3;
|
|
17
|
+
function ceilDiv(value, divisor) {
|
|
18
|
+
return Math.ceil(value / divisor);
|
|
19
|
+
}
|
|
20
|
+
function tileBounds(siz, tileX, tileY) {
|
|
21
|
+
return {
|
|
22
|
+
x0: Math.max(siz.xtosiz + tileX * siz.xtsiz, siz.xosiz),
|
|
23
|
+
y0: Math.max(siz.ytosiz + tileY * siz.ytsiz, siz.yosiz),
|
|
24
|
+
x1: Math.min(siz.xtosiz + (tileX + 1) * siz.xtsiz, siz.xsiz),
|
|
25
|
+
y1: Math.min(siz.ytosiz + (tileY + 1) * siz.ytsiz, siz.ysiz)
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
function componentBounds(tile, dx, dy) {
|
|
29
|
+
return {
|
|
30
|
+
x0: ceilDiv(tile.x0, dx),
|
|
31
|
+
y0: ceilDiv(tile.y0, dy),
|
|
32
|
+
x1: ceilDiv(tile.x1, dx),
|
|
33
|
+
y1: ceilDiv(tile.y1, dy)
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
function resolutionBounds(component, levels, resolution) {
|
|
37
|
+
const scale = 2 ** (levels - resolution);
|
|
38
|
+
return {
|
|
39
|
+
x0: ceilDiv(component.x0, scale),
|
|
40
|
+
y0: ceilDiv(component.y0, scale),
|
|
41
|
+
x1: ceilDiv(component.x1, scale),
|
|
42
|
+
y1: ceilDiv(component.y1, scale)
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
function precinctGrid(bounds, ppx, ppy) {
|
|
46
|
+
return {
|
|
47
|
+
wide: bounds.x1 > bounds.x0 ? Math.ceil(bounds.x1 / 2 ** ppx) - Math.floor(bounds.x0 / 2 ** ppx) : 0,
|
|
48
|
+
high: bounds.y1 > bounds.y0 ? Math.ceil(bounds.y1 / 2 ** ppy) - Math.floor(bounds.y0 / 2 ** ppy) : 0
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
function tileHasSubdividedPrecincts(siz, tileX, tileY, codingPerComponent) {
|
|
52
|
+
const tile = tileBounds(siz, tileX, tileY);
|
|
53
|
+
for (let c = 0; c < siz.components.length; c++) {
|
|
54
|
+
const size = siz.components[c];
|
|
55
|
+
const coding = codingPerComponent[c];
|
|
56
|
+
if (size === void 0 || coding === void 0) continue;
|
|
57
|
+
const component = componentBounds(tile, size.dx, size.dy);
|
|
58
|
+
for (let r = 0; r <= coding.decompositionLevels; r++) {
|
|
59
|
+
const precinctSize = coding.precinctSizes[r];
|
|
60
|
+
if (precinctSize === void 0) continue;
|
|
61
|
+
const grid = precinctGrid(resolutionBounds(component, coding.decompositionLevels, r), precinctSize.ppx, precinctSize.ppy);
|
|
62
|
+
if (grid.wide * grid.high > 1) return true;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
return false;
|
|
66
|
+
}
|
|
67
|
+
function bandCoordinate(componentCoordinate, levels, orientation) {
|
|
68
|
+
if (levels === 0) return componentCoordinate;
|
|
69
|
+
const half = 2 ** (levels - 1);
|
|
70
|
+
return Math.ceil((componentCoordinate - half * orientation) / (2 * half));
|
|
71
|
+
}
|
|
72
|
+
function quantizationIndex(resolution, bandIndex) {
|
|
73
|
+
return resolution === 0 ? 0 : 3 * (resolution - 1) + bandIndex + 1;
|
|
74
|
+
}
|
|
75
|
+
function stepSizeFor(quantization, resolution, bandIndex) {
|
|
76
|
+
if (quantization.style === "derived") {
|
|
77
|
+
const base = quantization.stepSizes[0];
|
|
78
|
+
if (base === void 0) throw new require_image_jpeg2000_errors.Jpeg2000ParseError("a QCD/QCC marker declares derived quantization but carries no step size");
|
|
79
|
+
return {
|
|
80
|
+
exponent: Math.max(base.exponent - Math.max(resolution - 1, 0), 0),
|
|
81
|
+
mantissa: base.mantissa
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
const index = quantizationIndex(resolution, bandIndex);
|
|
85
|
+
const step = quantization.stepSizes[index];
|
|
86
|
+
if (step === void 0) throw new require_image_jpeg2000_errors.Jpeg2000ParseError(`a QCD/QCC marker carries no step size for subband ${String(index)}, which its own decomposition level count requires`);
|
|
87
|
+
return step;
|
|
88
|
+
}
|
|
89
|
+
function buildPrecinct(band, precinctX, precinctY, bandPpx, bandPpy, codeBlockWidthExp, codeBlockHeightExp) {
|
|
90
|
+
const precinctWidth = 2 ** bandPpx;
|
|
91
|
+
const precinctHeight = 2 ** bandPpy;
|
|
92
|
+
const originX = (Math.floor(band.x0 / precinctWidth) + precinctX) * precinctWidth;
|
|
93
|
+
const originY = (Math.floor(band.y0 / precinctHeight) + precinctY) * precinctHeight;
|
|
94
|
+
const px0 = Math.max(originX, band.x0);
|
|
95
|
+
const py0 = Math.max(originY, band.y0);
|
|
96
|
+
const px1 = Math.min(originX + precinctWidth, band.x1);
|
|
97
|
+
const py1 = Math.min(originY + precinctHeight, band.y1);
|
|
98
|
+
const cbWidth = 2 ** Math.min(codeBlockWidthExp, bandPpx);
|
|
99
|
+
const cbHeight = 2 ** Math.min(codeBlockHeightExp, bandPpy);
|
|
100
|
+
const gridX0 = Math.floor(px0 / cbWidth);
|
|
101
|
+
const gridY0 = Math.floor(py0 / cbHeight);
|
|
102
|
+
const gridX1 = px1 > px0 ? Math.ceil(px1 / cbWidth) : gridX0;
|
|
103
|
+
const gridY1 = py1 > py0 ? Math.ceil(py1 / cbHeight) : gridY0;
|
|
104
|
+
const gridWidth = gridX1 - gridX0;
|
|
105
|
+
const gridHeight = gridY1 - gridY0;
|
|
106
|
+
const codeBlocks = [];
|
|
107
|
+
for (let gy = 0; gy < gridHeight; gy++) for (let gx = 0; gx < gridWidth; gx++) {
|
|
108
|
+
const cellX = (gridX0 + gx) * cbWidth;
|
|
109
|
+
const cellY = (gridY0 + gy) * cbHeight;
|
|
110
|
+
codeBlocks.push({
|
|
111
|
+
x0: Math.max(cellX, px0),
|
|
112
|
+
y0: Math.max(cellY, py0),
|
|
113
|
+
x1: Math.min(cellX + cbWidth, px1),
|
|
114
|
+
y1: Math.min(cellY + cbHeight, py1),
|
|
115
|
+
gridX: gx,
|
|
116
|
+
gridY: gy,
|
|
117
|
+
included: false,
|
|
118
|
+
lblock: INITIAL_LBLOCK,
|
|
119
|
+
zeroBitPlanes: 0,
|
|
120
|
+
passes: 0,
|
|
121
|
+
chunks: []
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
return {
|
|
125
|
+
inclusion: new require_image_jpeg2000_tagtree.TagTree(gridWidth, gridHeight),
|
|
126
|
+
zeroBitPlaneTree: new require_image_jpeg2000_tagtree.TagTree(gridWidth, gridHeight),
|
|
127
|
+
codeBlocks
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
function buildTileGeometry(siz, tileX, tileY, codingPerComponent, quantizationPerComponent) {
|
|
131
|
+
const tile = tileBounds(siz, tileX, tileY);
|
|
132
|
+
const components = [];
|
|
133
|
+
for (let c = 0; c < siz.components.length; c++) {
|
|
134
|
+
const componentSize = siz.components[c];
|
|
135
|
+
const coding = codingPerComponent[c];
|
|
136
|
+
const quantization = quantizationPerComponent[c];
|
|
137
|
+
if (componentSize === void 0 || coding === void 0 || quantization === void 0) throw new require_image_jpeg2000_errors.Jpeg2000ParseError(`no coding style or quantization is defined for component ${String(c)}`);
|
|
138
|
+
const bounds = componentBounds(tile, componentSize.dx, componentSize.dy);
|
|
139
|
+
const levels = coding.decompositionLevels;
|
|
140
|
+
const resolutions = [];
|
|
141
|
+
for (let r = 0; r <= levels; r++) {
|
|
142
|
+
const level = resolutionBounds(bounds, levels, r);
|
|
143
|
+
const { x0: rx0, y0: ry0, x1: rx1, y1: ry1 } = level;
|
|
144
|
+
const precinctSize = coding.precinctSizes[r];
|
|
145
|
+
if (precinctSize === void 0) throw new require_image_jpeg2000_errors.Jpeg2000ParseError(`the coding style declares ${String(levels)} decomposition levels but no precinct size for resolution ${String(r)}`);
|
|
146
|
+
const { ppx, ppy } = precinctSize;
|
|
147
|
+
if (r > 0 && (ppx === 0 || ppy === 0)) throw new require_image_jpeg2000_errors.Jpeg2000ParseError(`resolution level ${String(r)} declares a precinct exponent of zero, which ISO/IEC 15444-1 B.6 permits only at resolution level 0`);
|
|
148
|
+
const { wide: precinctsWide, high: precinctsHigh } = precinctGrid(level, ppx, ppy);
|
|
149
|
+
const bandPpx = r === 0 ? ppx : ppx - 1;
|
|
150
|
+
const bandPpy = r === 0 ? ppy : ppy - 1;
|
|
151
|
+
const bandTypes = r === 0 ? ["LL"] : HIGHER_RESOLUTION_BANDS;
|
|
152
|
+
const subbands = [];
|
|
153
|
+
for (let b = 0; b < bandTypes.length; b++) {
|
|
154
|
+
const type = bandTypes[b] ?? "LL";
|
|
155
|
+
const bandLevels = r === 0 ? levels : levels - r + 1;
|
|
156
|
+
const xob = type === "HL" || type === "HH" ? 1 : 0;
|
|
157
|
+
const yob = type === "LH" || type === "HH" ? 1 : 0;
|
|
158
|
+
const bx0 = bandCoordinate(bounds.x0, bandLevels, xob);
|
|
159
|
+
const by0 = bandCoordinate(bounds.y0, bandLevels, yob);
|
|
160
|
+
const bx1 = bandCoordinate(bounds.x1, bandLevels, xob);
|
|
161
|
+
const by1 = bandCoordinate(bounds.y1, bandLevels, yob);
|
|
162
|
+
const stepSize = stepSizeFor(quantization, r, b);
|
|
163
|
+
const precincts = [];
|
|
164
|
+
for (let py = 0; py < precinctsHigh; py++) for (let px = 0; px < precinctsWide; px++) precincts.push(buildPrecinct({
|
|
165
|
+
x0: bx0,
|
|
166
|
+
y0: by0,
|
|
167
|
+
x1: bx1,
|
|
168
|
+
y1: by1
|
|
169
|
+
}, px, py, bandPpx, bandPpy, coding.codeBlockWidthExp, coding.codeBlockHeightExp));
|
|
170
|
+
subbands.push({
|
|
171
|
+
type,
|
|
172
|
+
x0: bx0,
|
|
173
|
+
y0: by0,
|
|
174
|
+
x1: bx1,
|
|
175
|
+
y1: by1,
|
|
176
|
+
stepSize,
|
|
177
|
+
maxBitPlanes: stepSize.exponent + quantization.guardBits - 1,
|
|
178
|
+
precincts
|
|
179
|
+
});
|
|
180
|
+
}
|
|
181
|
+
resolutions.push({
|
|
182
|
+
index: r,
|
|
183
|
+
x0: rx0,
|
|
184
|
+
y0: ry0,
|
|
185
|
+
x1: rx1,
|
|
186
|
+
y1: ry1,
|
|
187
|
+
precinctsWide,
|
|
188
|
+
precinctsHigh,
|
|
189
|
+
subbands
|
|
190
|
+
});
|
|
191
|
+
}
|
|
192
|
+
components.push({
|
|
193
|
+
...bounds,
|
|
194
|
+
coding,
|
|
195
|
+
quantization,
|
|
196
|
+
resolutions
|
|
197
|
+
});
|
|
198
|
+
}
|
|
199
|
+
return {
|
|
200
|
+
...tile,
|
|
201
|
+
components
|
|
202
|
+
};
|
|
203
|
+
}
|
|
204
|
+
function subbandGainLog2(type) {
|
|
205
|
+
return SUBBAND_GAIN_LOG2[type];
|
|
206
|
+
}
|
|
207
|
+
function readCodingPasses(reader) {
|
|
208
|
+
if (reader.readBit() === 0) return 1;
|
|
209
|
+
if (reader.readBit() === 0) return 2;
|
|
210
|
+
const twoBit = reader.readBits(2);
|
|
211
|
+
if (twoBit < 3) return 3 + twoBit;
|
|
212
|
+
const fiveBit = reader.readBits(5);
|
|
213
|
+
if (fiveBit < 31) return 6 + fiveBit;
|
|
214
|
+
return 37 + reader.readBits(7);
|
|
215
|
+
}
|
|
216
|
+
function buildPacketSequence(tile, order, layers) {
|
|
217
|
+
const maxResolutions = Math.max(...tile.components.map((component) => component.resolutions.length));
|
|
218
|
+
const precinctCount = (component, resolution) => {
|
|
219
|
+
const level = (tile.components[component]?.resolutions)?.[resolution];
|
|
220
|
+
return level === void 0 ? 0 : level.precinctsWide * level.precinctsHigh;
|
|
221
|
+
};
|
|
222
|
+
const packets = [];
|
|
223
|
+
const push = (layer, resolution, component, precinct) => {
|
|
224
|
+
packets.push({
|
|
225
|
+
layer,
|
|
226
|
+
resolution,
|
|
227
|
+
component,
|
|
228
|
+
precinct
|
|
229
|
+
});
|
|
230
|
+
};
|
|
231
|
+
if (order === "LRCP") {
|
|
232
|
+
for (let l = 0; l < layers; l++) for (let r = 0; r < maxResolutions; r++) for (let c = 0; c < tile.components.length; c++) for (let p = 0; p < precinctCount(c, r); p++) push(l, r, c, p);
|
|
233
|
+
return packets;
|
|
234
|
+
}
|
|
235
|
+
if (order === "RLCP") {
|
|
236
|
+
for (let r = 0; r < maxResolutions; r++) for (let l = 0; l < layers; l++) for (let c = 0; c < tile.components.length; c++) for (let p = 0; p < precinctCount(c, r); p++) push(l, r, c, p);
|
|
237
|
+
return packets;
|
|
238
|
+
}
|
|
239
|
+
for (let c = 0; c < tile.components.length; c++) for (let r = 0; r < maxResolutions; r++) if (precinctCount(c, r) > 1) throw new require_image_jpeg2000_errors.Jpeg2000UnsupportedError(`progression order ${order} is only decoded here when every resolution level holds a single precinct, and this codestream subdivides at least one of them`);
|
|
240
|
+
if (order === "RPCL") {
|
|
241
|
+
for (let r = 0; r < maxResolutions; r++) for (let c = 0; c < tile.components.length; c++) for (let l = 0; l < layers; l++) if (precinctCount(c, r) > 0) push(l, r, c, 0);
|
|
242
|
+
return packets;
|
|
243
|
+
}
|
|
244
|
+
if (order === "PCRL") {
|
|
245
|
+
for (let c = 0; c < tile.components.length; c++) for (let r = 0; r < maxResolutions; r++) for (let l = 0; l < layers; l++) if (precinctCount(c, r) > 0) push(l, r, c, 0);
|
|
246
|
+
return packets;
|
|
247
|
+
}
|
|
248
|
+
for (let c = 0; c < tile.components.length; c++) for (let r = 0; r < maxResolutions; r++) for (let l = 0; l < layers; l++) if (precinctCount(c, r) > 0) push(l, r, c, 0);
|
|
249
|
+
return packets;
|
|
250
|
+
}
|
|
251
|
+
const MARKER_SOP_HIGH = 255;
|
|
252
|
+
const MARKER_SOP_LOW = 145;
|
|
253
|
+
const MARKER_EPH_LOW = 146;
|
|
254
|
+
const SOP_SEGMENT_BYTES = 6;
|
|
255
|
+
const EPH_MARKER_BYTES = 2;
|
|
256
|
+
function readTilePackets(data, start, end, tile, sequence, options) {
|
|
257
|
+
let position = start;
|
|
258
|
+
for (let packetIndex = 0; packetIndex < sequence.length; packetIndex++) {
|
|
259
|
+
const packet = sequence[packetIndex];
|
|
260
|
+
if (packet === void 0) break;
|
|
261
|
+
if (position >= end) {
|
|
262
|
+
options.onWarning(`the tile's coded data ended after ${String(packetIndex)} of ${String(sequence.length)} packets; the rest of the image is reconstructed from what did arrive`);
|
|
263
|
+
return position;
|
|
264
|
+
}
|
|
265
|
+
if (options.useSop && position + SOP_SEGMENT_BYTES <= end && data[position] === MARKER_SOP_HIGH && data[position + 1] === MARKER_SOP_LOW) position += SOP_SEGMENT_BYTES;
|
|
266
|
+
const component = tile.components[packet.component];
|
|
267
|
+
const resolution = component?.resolutions[packet.resolution];
|
|
268
|
+
if (component === void 0 || resolution === void 0) throw new require_image_jpeg2000_errors.Jpeg2000ParseError("the progression sequence names a resolution level the tile does not have");
|
|
269
|
+
const reader = new require_image_jpeg2000_tagtree.PacketBitReader(data, position, end);
|
|
270
|
+
const included = [];
|
|
271
|
+
const lengths = [];
|
|
272
|
+
if (reader.readBit() === 1) for (const band of resolution.subbands) {
|
|
273
|
+
const precinct = band.precincts[packet.precinct];
|
|
274
|
+
if (precinct === void 0) continue;
|
|
275
|
+
for (const block of precinct.codeBlocks) {
|
|
276
|
+
if (!(block.included ? reader.readBit() === 1 : precinct.inclusion.decode(reader, block.gridX, block.gridY, packet.layer + 1))) continue;
|
|
277
|
+
if (!block.included) {
|
|
278
|
+
block.included = true;
|
|
279
|
+
let threshold = 1;
|
|
280
|
+
while (!precinct.zeroBitPlaneTree.decode(reader, block.gridX, block.gridY, threshold)) threshold++;
|
|
281
|
+
block.zeroBitPlanes = threshold - 1;
|
|
282
|
+
}
|
|
283
|
+
const passes = readCodingPasses(reader);
|
|
284
|
+
while (reader.readBit() === 1) block.lblock++;
|
|
285
|
+
const lengthBits = block.lblock + Math.floor(Math.log2(passes));
|
|
286
|
+
const length = reader.readBits(lengthBits);
|
|
287
|
+
block.passes += passes;
|
|
288
|
+
included.push(block);
|
|
289
|
+
lengths.push(length);
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
reader.alignToByte();
|
|
293
|
+
position = reader.offset;
|
|
294
|
+
if (options.useEph && position + EPH_MARKER_BYTES <= end && data[position] === MARKER_SOP_HIGH && data[position + 1] === MARKER_EPH_LOW) position += EPH_MARKER_BYTES;
|
|
295
|
+
for (let i = 0; i < included.length; i++) {
|
|
296
|
+
const block = included[i];
|
|
297
|
+
const length = lengths[i] ?? 0;
|
|
298
|
+
if (block === void 0) continue;
|
|
299
|
+
const chunkEnd = Math.min(position + length, end);
|
|
300
|
+
if (chunkEnd < position + length) options.onWarning("a code-block declares more coded bytes than the tile carries; decoding it from the bytes that did arrive");
|
|
301
|
+
block.chunks.push({
|
|
302
|
+
start: position,
|
|
303
|
+
end: chunkEnd
|
|
304
|
+
});
|
|
305
|
+
position += length;
|
|
306
|
+
if (position > end) return end;
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
return position;
|
|
310
|
+
}
|
|
311
|
+
//#endregion
|
|
312
|
+
exports.buildPacketSequence = buildPacketSequence;
|
|
313
|
+
exports.buildTileGeometry = buildTileGeometry;
|
|
314
|
+
exports.readTilePackets = readTilePackets;
|
|
315
|
+
exports.subbandGainLog2 = subbandGainLog2;
|
|
316
|
+
exports.tileHasSubdividedPrecincts = tileHasSubdividedPrecincts;
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { Jpeg2000CodingStyle, Jpeg2000ImageSize, Jpeg2000ProgressionOrder, Jpeg2000Quantization, Jpeg2000StepSize } from "./jpeg2000-codestream.cjs";
|
|
2
|
+
import { Jpeg2000SubbandType } from "./jpeg2000-t1.cjs";
|
|
3
|
+
import { TagTree } from "./jpeg2000-tagtree.cjs";
|
|
4
|
+
//#region src/image/jpeg2000-t2.d.ts
|
|
5
|
+
interface Jpeg2000CodeBlock {
|
|
6
|
+
readonly x0: number;
|
|
7
|
+
readonly y0: number;
|
|
8
|
+
readonly x1: number;
|
|
9
|
+
readonly y1: number;
|
|
10
|
+
readonly gridX: number;
|
|
11
|
+
readonly gridY: number;
|
|
12
|
+
included: boolean;
|
|
13
|
+
lblock: number;
|
|
14
|
+
zeroBitPlanes: number;
|
|
15
|
+
passes: number;
|
|
16
|
+
readonly chunks: {
|
|
17
|
+
start: number;
|
|
18
|
+
end: number;
|
|
19
|
+
}[];
|
|
20
|
+
}
|
|
21
|
+
interface Jpeg2000Precinct {
|
|
22
|
+
readonly inclusion: TagTree;
|
|
23
|
+
readonly zeroBitPlaneTree: TagTree;
|
|
24
|
+
readonly codeBlocks: Jpeg2000CodeBlock[];
|
|
25
|
+
}
|
|
26
|
+
interface Jpeg2000Subband {
|
|
27
|
+
readonly type: Jpeg2000SubbandType;
|
|
28
|
+
readonly x0: number;
|
|
29
|
+
readonly y0: number;
|
|
30
|
+
readonly x1: number;
|
|
31
|
+
readonly y1: number;
|
|
32
|
+
readonly stepSize: Jpeg2000StepSize;
|
|
33
|
+
readonly maxBitPlanes: number;
|
|
34
|
+
readonly precincts: readonly Jpeg2000Precinct[];
|
|
35
|
+
}
|
|
36
|
+
interface Jpeg2000Resolution {
|
|
37
|
+
readonly index: number;
|
|
38
|
+
readonly x0: number;
|
|
39
|
+
readonly y0: number;
|
|
40
|
+
readonly x1: number;
|
|
41
|
+
readonly y1: number;
|
|
42
|
+
readonly precinctsWide: number;
|
|
43
|
+
readonly precinctsHigh: number;
|
|
44
|
+
readonly subbands: readonly Jpeg2000Subband[];
|
|
45
|
+
}
|
|
46
|
+
interface Jpeg2000TileComponent {
|
|
47
|
+
readonly x0: number;
|
|
48
|
+
readonly y0: number;
|
|
49
|
+
readonly x1: number;
|
|
50
|
+
readonly y1: number;
|
|
51
|
+
readonly coding: Jpeg2000CodingStyle;
|
|
52
|
+
readonly quantization: Jpeg2000Quantization;
|
|
53
|
+
readonly resolutions: readonly Jpeg2000Resolution[];
|
|
54
|
+
}
|
|
55
|
+
interface Jpeg2000TileGeometry {
|
|
56
|
+
readonly x0: number;
|
|
57
|
+
readonly y0: number;
|
|
58
|
+
readonly x1: number;
|
|
59
|
+
readonly y1: number;
|
|
60
|
+
readonly components: readonly Jpeg2000TileComponent[];
|
|
61
|
+
}
|
|
62
|
+
declare function tileHasSubdividedPrecincts(siz: Jpeg2000ImageSize, tileX: number, tileY: number, codingPerComponent: readonly Jpeg2000CodingStyle[]): boolean;
|
|
63
|
+
declare function buildTileGeometry(siz: Jpeg2000ImageSize, tileX: number, tileY: number, codingPerComponent: readonly Jpeg2000CodingStyle[], quantizationPerComponent: readonly Jpeg2000Quantization[]): Jpeg2000TileGeometry;
|
|
64
|
+
declare function subbandGainLog2(type: Jpeg2000SubbandType): number;
|
|
65
|
+
interface PacketPosition {
|
|
66
|
+
readonly layer: number;
|
|
67
|
+
readonly resolution: number;
|
|
68
|
+
readonly component: number;
|
|
69
|
+
readonly precinct: number;
|
|
70
|
+
}
|
|
71
|
+
declare function buildPacketSequence(tile: Jpeg2000TileGeometry, order: Jpeg2000ProgressionOrder, layers: number): PacketPosition[];
|
|
72
|
+
interface PacketReadOptions {
|
|
73
|
+
readonly useSop: boolean;
|
|
74
|
+
readonly useEph: boolean;
|
|
75
|
+
readonly onWarning: (message: string) => void;
|
|
76
|
+
}
|
|
77
|
+
declare function readTilePackets(data: Uint8Array<ArrayBuffer>, start: number, end: number, tile: Jpeg2000TileGeometry, sequence: readonly PacketPosition[], options: PacketReadOptions): number;
|
|
78
|
+
//#endregion
|
|
79
|
+
export { Jpeg2000CodeBlock, Jpeg2000Precinct, Jpeg2000Resolution, Jpeg2000Subband, Jpeg2000TileComponent, Jpeg2000TileGeometry, PacketReadOptions, buildPacketSequence, buildTileGeometry, readTilePackets, subbandGainLog2, tileHasSubdividedPrecincts };
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { Jpeg2000CodingStyle, Jpeg2000ImageSize, Jpeg2000ProgressionOrder, Jpeg2000Quantization, Jpeg2000StepSize } from "./jpeg2000-codestream.js";
|
|
2
|
+
import { Jpeg2000SubbandType } from "./jpeg2000-t1.js";
|
|
3
|
+
import { TagTree } from "./jpeg2000-tagtree.js";
|
|
4
|
+
//#region src/image/jpeg2000-t2.d.ts
|
|
5
|
+
interface Jpeg2000CodeBlock {
|
|
6
|
+
readonly x0: number;
|
|
7
|
+
readonly y0: number;
|
|
8
|
+
readonly x1: number;
|
|
9
|
+
readonly y1: number;
|
|
10
|
+
readonly gridX: number;
|
|
11
|
+
readonly gridY: number;
|
|
12
|
+
included: boolean;
|
|
13
|
+
lblock: number;
|
|
14
|
+
zeroBitPlanes: number;
|
|
15
|
+
passes: number;
|
|
16
|
+
readonly chunks: {
|
|
17
|
+
start: number;
|
|
18
|
+
end: number;
|
|
19
|
+
}[];
|
|
20
|
+
}
|
|
21
|
+
interface Jpeg2000Precinct {
|
|
22
|
+
readonly inclusion: TagTree;
|
|
23
|
+
readonly zeroBitPlaneTree: TagTree;
|
|
24
|
+
readonly codeBlocks: Jpeg2000CodeBlock[];
|
|
25
|
+
}
|
|
26
|
+
interface Jpeg2000Subband {
|
|
27
|
+
readonly type: Jpeg2000SubbandType;
|
|
28
|
+
readonly x0: number;
|
|
29
|
+
readonly y0: number;
|
|
30
|
+
readonly x1: number;
|
|
31
|
+
readonly y1: number;
|
|
32
|
+
readonly stepSize: Jpeg2000StepSize;
|
|
33
|
+
readonly maxBitPlanes: number;
|
|
34
|
+
readonly precincts: readonly Jpeg2000Precinct[];
|
|
35
|
+
}
|
|
36
|
+
interface Jpeg2000Resolution {
|
|
37
|
+
readonly index: number;
|
|
38
|
+
readonly x0: number;
|
|
39
|
+
readonly y0: number;
|
|
40
|
+
readonly x1: number;
|
|
41
|
+
readonly y1: number;
|
|
42
|
+
readonly precinctsWide: number;
|
|
43
|
+
readonly precinctsHigh: number;
|
|
44
|
+
readonly subbands: readonly Jpeg2000Subband[];
|
|
45
|
+
}
|
|
46
|
+
interface Jpeg2000TileComponent {
|
|
47
|
+
readonly x0: number;
|
|
48
|
+
readonly y0: number;
|
|
49
|
+
readonly x1: number;
|
|
50
|
+
readonly y1: number;
|
|
51
|
+
readonly coding: Jpeg2000CodingStyle;
|
|
52
|
+
readonly quantization: Jpeg2000Quantization;
|
|
53
|
+
readonly resolutions: readonly Jpeg2000Resolution[];
|
|
54
|
+
}
|
|
55
|
+
interface Jpeg2000TileGeometry {
|
|
56
|
+
readonly x0: number;
|
|
57
|
+
readonly y0: number;
|
|
58
|
+
readonly x1: number;
|
|
59
|
+
readonly y1: number;
|
|
60
|
+
readonly components: readonly Jpeg2000TileComponent[];
|
|
61
|
+
}
|
|
62
|
+
declare function tileHasSubdividedPrecincts(siz: Jpeg2000ImageSize, tileX: number, tileY: number, codingPerComponent: readonly Jpeg2000CodingStyle[]): boolean;
|
|
63
|
+
declare function buildTileGeometry(siz: Jpeg2000ImageSize, tileX: number, tileY: number, codingPerComponent: readonly Jpeg2000CodingStyle[], quantizationPerComponent: readonly Jpeg2000Quantization[]): Jpeg2000TileGeometry;
|
|
64
|
+
declare function subbandGainLog2(type: Jpeg2000SubbandType): number;
|
|
65
|
+
interface PacketPosition {
|
|
66
|
+
readonly layer: number;
|
|
67
|
+
readonly resolution: number;
|
|
68
|
+
readonly component: number;
|
|
69
|
+
readonly precinct: number;
|
|
70
|
+
}
|
|
71
|
+
declare function buildPacketSequence(tile: Jpeg2000TileGeometry, order: Jpeg2000ProgressionOrder, layers: number): PacketPosition[];
|
|
72
|
+
interface PacketReadOptions {
|
|
73
|
+
readonly useSop: boolean;
|
|
74
|
+
readonly useEph: boolean;
|
|
75
|
+
readonly onWarning: (message: string) => void;
|
|
76
|
+
}
|
|
77
|
+
declare function readTilePackets(data: Uint8Array<ArrayBuffer>, start: number, end: number, tile: Jpeg2000TileGeometry, sequence: readonly PacketPosition[], options: PacketReadOptions): number;
|
|
78
|
+
//#endregion
|
|
79
|
+
export { Jpeg2000CodeBlock, Jpeg2000Precinct, Jpeg2000Resolution, Jpeg2000Subband, Jpeg2000TileComponent, Jpeg2000TileGeometry, PacketReadOptions, buildPacketSequence, buildTileGeometry, readTilePackets, subbandGainLog2, tileHasSubdividedPrecincts };
|