pdf-codec 1.5.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 +100 -9
- package/dist/assets/caladea-bold.cjs +5 -0
- package/dist/assets/caladea-bold.d.cts +4 -0
- package/dist/assets/caladea-bold.d.ts +4 -0
- package/dist/assets/caladea-bold.js +4 -0
- package/dist/assets/caladea-bolditalic.cjs +5 -0
- package/dist/assets/caladea-bolditalic.d.cts +4 -0
- package/dist/assets/caladea-bolditalic.d.ts +4 -0
- package/dist/assets/caladea-bolditalic.js +4 -0
- package/dist/assets/caladea-italic.cjs +5 -0
- package/dist/assets/caladea-italic.d.cts +4 -0
- package/dist/assets/caladea-italic.d.ts +4 -0
- package/dist/assets/caladea-italic.js +4 -0
- package/dist/assets/caladea-regular.cjs +5 -0
- package/dist/assets/caladea-regular.d.cts +4 -0
- package/dist/assets/caladea-regular.d.ts +4 -0
- package/dist/assets/caladea-regular.js +4 -0
- package/dist/assets/carlito-bold.cjs +5 -0
- package/dist/assets/carlito-bold.d.cts +4 -0
- package/dist/assets/carlito-bold.d.ts +4 -0
- package/dist/assets/carlito-bold.js +4 -0
- package/dist/assets/carlito-bolditalic.cjs +5 -0
- package/dist/assets/carlito-bolditalic.d.cts +4 -0
- package/dist/assets/carlito-bolditalic.d.ts +4 -0
- package/dist/assets/carlito-bolditalic.js +4 -0
- package/dist/assets/carlito-italic.cjs +5 -0
- package/dist/assets/carlito-italic.d.cts +4 -0
- package/dist/assets/carlito-italic.d.ts +4 -0
- package/dist/assets/carlito-italic.js +4 -0
- package/dist/assets/carlito-regular.cjs +5 -0
- package/dist/assets/carlito-regular.d.cts +4 -0
- package/dist/assets/carlito-regular.d.ts +4 -0
- package/dist/assets/carlito-regular.js +4 -0
- 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 +35 -0
- package/dist/cff-probe.d.cts +10 -0
- package/dist/cff-probe.d.ts +10 -0
- package/dist/cff-probe.js +34 -0
- 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/cmap-table.cjs +108 -0
- package/dist/cmap-table.d.cts +6 -0
- package/dist/cmap-table.d.ts +6 -0
- package/dist/cmap-table.js +107 -0
- package/dist/content-write.cjs +34 -14
- package/dist/content-write.d.cts +9 -2
- package/dist/content-write.d.ts +9 -2
- package/dist/content-write.js +34 -14
- package/dist/embedded-font-CLedn-mT.d.cts +42 -0
- package/dist/embedded-font-CbqkKgBl.d.ts +42 -0
- package/dist/embedded-font-write.cjs +92 -0
- package/dist/embedded-font-write.d.cts +22 -0
- package/dist/embedded-font-write.d.ts +22 -0
- package/dist/embedded-font-write.js +90 -0
- package/dist/embedded-font.cjs +142 -0
- package/dist/embedded-font.d.cts +2 -0
- package/dist/embedded-font.d.ts +2 -0
- package/dist/embedded-font.js +138 -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/font-registry-Cn7P9lAh.d.ts +38 -0
- package/dist/font-registry-yby02snZ.d.cts +38 -0
- package/dist/font-registry.cjs +152 -0
- package/dist/font-registry.d.cts +2 -0
- package/dist/font-registry.d.ts +2 -0
- package/dist/font-registry.js +150 -0
- package/dist/font-substitutes.cjs +13 -0
- package/dist/font-substitutes.d.cts +5 -0
- package/dist/font-substitutes.d.ts +5 -0
- package/dist/font-substitutes.js +12 -0
- package/dist/font-tables.cjs +127 -0
- package/dist/font-tables.d.cts +43 -0
- package/dist/font-tables.d.ts +43 -0
- package/dist/font-tables.js +122 -0
- package/dist/fonts.cjs +1 -0
- package/dist/fonts.d.cts +2 -1
- package/dist/fonts.d.ts +2 -1
- package/dist/fonts.js +1 -1
- package/dist/formula.d.cts +1 -1
- package/dist/formula.d.ts +1 -1
- package/dist/glyf.cjs +183 -0
- package/dist/glyf.d.cts +33 -0
- package/dist/glyf.d.ts +33 -0
- package/dist/glyf.js +181 -0
- 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/{math-hmtx.cjs → hmtx-table.cjs} +3 -3
- package/dist/{math-hmtx.d.ts → hmtx-table.d.cts} +2 -2
- package/dist/{math-hmtx.d.cts → hmtx-table.d.ts} +2 -2
- package/dist/{math-hmtx.js → hmtx-table.js} +3 -3
- 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 +22 -0
- package/dist/index.d.cts +14 -3
- package/dist/index.d.ts +14 -3
- package/dist/index.js +9 -2
- package/dist/jbig2-errors-Bj6MPxrx.d.cts +9 -0
- package/dist/jbig2-errors-Bj6MPxrx.d.ts +9 -0
- package/dist/math-font-write.cjs +2 -31
- package/dist/math-font-write.js +1 -30
- package/dist/math-font.cjs +50 -23
- package/dist/math-font.d.cts +8 -1
- package/dist/math-font.d.ts +8 -1
- package/dist/math-font.js +48 -21
- 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/dist/measure.cjs +65 -14
- package/dist/measure.d.cts +8 -1
- package/dist/measure.d.ts +8 -1
- package/dist/measure.js +64 -15
- package/dist/sfnt-V08bb5ut.d.cts +21 -0
- package/dist/sfnt-V08bb5ut.d.ts +21 -0
- package/dist/sfnt-subset.cjs +250 -0
- package/dist/sfnt-subset.d.cts +11 -0
- package/dist/sfnt-subset.d.ts +11 -0
- package/dist/sfnt-subset.js +249 -0
- package/dist/sfnt.cjs +50 -4
- package/dist/sfnt.d.cts +2 -17
- package/dist/sfnt.d.ts +2 -17
- package/dist/sfnt.js +47 -5
- package/dist/tounicode.cjs +34 -0
- package/dist/tounicode.d.cts +5 -0
- package/dist/tounicode.d.ts +5 -0
- package/dist/tounicode.js +33 -0
- package/dist/write.cjs +80 -10
- package/dist/write.d.cts +6 -0
- package/dist/write.d.ts +6 -0
- package/dist/write.js +81 -11
- package/package.json +1 -1
- package/dist/math-cmap.cjs +0 -81
- package/dist/math-cmap.d.cts +0 -6
- package/dist/math-cmap.d.ts +0 -6
- package/dist/math-cmap.js +0 -80
|
@@ -0,0 +1,309 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_image_jpeg2000_errors = require("./jpeg2000-errors.cjs");
|
|
3
|
+
//#region src/image/jpeg2000-codestream.ts
|
|
4
|
+
const MARKER_SOC = 65359;
|
|
5
|
+
const MARKER_SIZ = 65361;
|
|
6
|
+
const MARKER_COD = 65362;
|
|
7
|
+
const MARKER_COC = 65363;
|
|
8
|
+
const MARKER_QCD = 65372;
|
|
9
|
+
const MARKER_QCC = 65373;
|
|
10
|
+
const MARKER_RGN = 65374;
|
|
11
|
+
const MARKER_POC = 65375;
|
|
12
|
+
const MARKER_PPM = 65376;
|
|
13
|
+
const MARKER_PPT = 65377;
|
|
14
|
+
const MARKER_COM = 65380;
|
|
15
|
+
const MARKER_SOT = 65424;
|
|
16
|
+
const MARKER_SOD = 65427;
|
|
17
|
+
const MARKER_EOC = 65497;
|
|
18
|
+
const PROGRESSION_ORDERS = [
|
|
19
|
+
"LRCP",
|
|
20
|
+
"RLCP",
|
|
21
|
+
"RPCL",
|
|
22
|
+
"PCRL",
|
|
23
|
+
"CPRL"
|
|
24
|
+
];
|
|
25
|
+
var MarkerCursor = class {
|
|
26
|
+
data;
|
|
27
|
+
position;
|
|
28
|
+
constructor(data, start = 0) {
|
|
29
|
+
this.data = data;
|
|
30
|
+
this.position = start;
|
|
31
|
+
}
|
|
32
|
+
get remaining() {
|
|
33
|
+
return this.data.length - this.position;
|
|
34
|
+
}
|
|
35
|
+
uint8() {
|
|
36
|
+
const value = this.data[this.position];
|
|
37
|
+
if (value === void 0) throw new require_image_jpeg2000_errors.Jpeg2000ParseError("JPEG 2000 codestream ended in the middle of a marker segment");
|
|
38
|
+
this.position++;
|
|
39
|
+
return value;
|
|
40
|
+
}
|
|
41
|
+
uint16() {
|
|
42
|
+
return this.uint8() << 8 | this.uint8();
|
|
43
|
+
}
|
|
44
|
+
uint32() {
|
|
45
|
+
return this.uint16() * 65536 + this.uint16();
|
|
46
|
+
}
|
|
47
|
+
bytes(length) {
|
|
48
|
+
if (length < 0 || this.position + length > this.data.length) throw new require_image_jpeg2000_errors.Jpeg2000ParseError("a JPEG 2000 marker segment declares more data than the codestream carries");
|
|
49
|
+
const slice = this.data.subarray(this.position, this.position + length);
|
|
50
|
+
this.position += length;
|
|
51
|
+
return slice;
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
function readImageSize(cursor, segmentEnd) {
|
|
55
|
+
cursor.uint16();
|
|
56
|
+
const xsiz = cursor.uint32();
|
|
57
|
+
const ysiz = cursor.uint32();
|
|
58
|
+
const xosiz = cursor.uint32();
|
|
59
|
+
const yosiz = cursor.uint32();
|
|
60
|
+
const xtsiz = cursor.uint32();
|
|
61
|
+
const ytsiz = cursor.uint32();
|
|
62
|
+
const xtosiz = cursor.uint32();
|
|
63
|
+
const ytosiz = cursor.uint32();
|
|
64
|
+
const count = cursor.uint16();
|
|
65
|
+
if (count === 0) throw new require_image_jpeg2000_errors.Jpeg2000ParseError("SIZ declares zero components");
|
|
66
|
+
if (cursor.position + count * 3 > segmentEnd) throw new require_image_jpeg2000_errors.Jpeg2000ParseError(`SIZ declares ${String(count)} components but its own length leaves room for fewer`);
|
|
67
|
+
const components = [];
|
|
68
|
+
for (let i = 0; i < count; i++) {
|
|
69
|
+
const ssiz = cursor.uint8();
|
|
70
|
+
components.push({
|
|
71
|
+
signed: (ssiz & 128) !== 0,
|
|
72
|
+
bitDepth: (ssiz & 127) + 1,
|
|
73
|
+
dx: cursor.uint8(),
|
|
74
|
+
dy: cursor.uint8()
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
if (xsiz <= xosiz || ysiz <= yosiz) throw new require_image_jpeg2000_errors.Jpeg2000ParseError("SIZ declares an image with no area (Xsiz/Ysiz do not exceed XOsiz/YOsiz)");
|
|
78
|
+
if (xtsiz === 0 || ytsiz === 0) throw new require_image_jpeg2000_errors.Jpeg2000ParseError("SIZ declares a zero-sized tile");
|
|
79
|
+
return {
|
|
80
|
+
xsiz,
|
|
81
|
+
ysiz,
|
|
82
|
+
xosiz,
|
|
83
|
+
yosiz,
|
|
84
|
+
xtsiz,
|
|
85
|
+
ytsiz,
|
|
86
|
+
xtosiz,
|
|
87
|
+
ytosiz,
|
|
88
|
+
components
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
const DEFAULT_PRECINCT_EXPONENT = 15;
|
|
92
|
+
function readCodingStyleParameters(cursor, explicitPrecincts) {
|
|
93
|
+
const decompositionLevels = cursor.uint8();
|
|
94
|
+
const codeBlockWidthExp = (cursor.uint8() & 15) + 2;
|
|
95
|
+
const codeBlockHeightExp = (cursor.uint8() & 15) + 2;
|
|
96
|
+
const codeBlockStyle = cursor.uint8();
|
|
97
|
+
const transformCode = cursor.uint8();
|
|
98
|
+
if (transformCode !== 0 && transformCode !== 1) throw new require_image_jpeg2000_errors.Jpeg2000ParseError(`SPcod/SPcoc declares transformation ${String(transformCode)}, which is neither of the two ISO/IEC 15444-1 defines`);
|
|
99
|
+
if (codeBlockWidthExp > 10 || codeBlockHeightExp > 10 || codeBlockWidthExp + codeBlockHeightExp > 12) throw new require_image_jpeg2000_errors.Jpeg2000ParseError(`code-block size 2^${String(codeBlockWidthExp)} by 2^${String(codeBlockHeightExp)} is outside the range ISO/IEC 15444-1 Table A.18 permits`);
|
|
100
|
+
const precinctSizes = [];
|
|
101
|
+
if (explicitPrecincts) for (let r = 0; r <= decompositionLevels; r++) {
|
|
102
|
+
const packed = cursor.uint8();
|
|
103
|
+
precinctSizes.push({
|
|
104
|
+
ppx: packed & 15,
|
|
105
|
+
ppy: packed >> 4 & 15
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
else for (let r = 0; r <= decompositionLevels; r++) precinctSizes.push({
|
|
109
|
+
ppx: DEFAULT_PRECINCT_EXPONENT,
|
|
110
|
+
ppy: DEFAULT_PRECINCT_EXPONENT
|
|
111
|
+
});
|
|
112
|
+
return {
|
|
113
|
+
decompositionLevels,
|
|
114
|
+
codeBlockWidthExp,
|
|
115
|
+
codeBlockHeightExp,
|
|
116
|
+
codeBlockStyle,
|
|
117
|
+
transform: transformCode === 1 ? "reversible-5-3" : "irreversible-9-7",
|
|
118
|
+
precinctSizes
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
function readCodingDefaults(cursor) {
|
|
122
|
+
const scod = cursor.uint8();
|
|
123
|
+
const progressionOrder = PROGRESSION_ORDERS[cursor.uint8()];
|
|
124
|
+
if (progressionOrder === void 0) throw new require_image_jpeg2000_errors.Jpeg2000ParseError("COD declares a progression order outside the five ISO/IEC 15444-1 Table A.16 defines");
|
|
125
|
+
const layers = cursor.uint16();
|
|
126
|
+
if (layers === 0) throw new require_image_jpeg2000_errors.Jpeg2000ParseError("COD declares zero quality layers");
|
|
127
|
+
const multipleComponentTransform = cursor.uint8() !== 0;
|
|
128
|
+
return {
|
|
129
|
+
...readCodingStyleParameters(cursor, (scod & 1) !== 0),
|
|
130
|
+
progressionOrder,
|
|
131
|
+
layers,
|
|
132
|
+
multipleComponentTransform,
|
|
133
|
+
useSop: (scod & 2) !== 0,
|
|
134
|
+
useEph: (scod & 4) !== 0
|
|
135
|
+
};
|
|
136
|
+
}
|
|
137
|
+
function readQuantization(cursor, segmentEnd) {
|
|
138
|
+
const sq = cursor.uint8();
|
|
139
|
+
const guardBits = sq >> 5;
|
|
140
|
+
const styleCode = sq & 31;
|
|
141
|
+
const stepSizes = [];
|
|
142
|
+
if (styleCode === 0) {
|
|
143
|
+
while (cursor.position < segmentEnd) stepSizes.push({
|
|
144
|
+
exponent: cursor.uint8() >> 3,
|
|
145
|
+
mantissa: 0
|
|
146
|
+
});
|
|
147
|
+
return {
|
|
148
|
+
style: "none",
|
|
149
|
+
guardBits,
|
|
150
|
+
stepSizes
|
|
151
|
+
};
|
|
152
|
+
}
|
|
153
|
+
if (styleCode === 1 || styleCode === 2) {
|
|
154
|
+
while (cursor.position + 1 < segmentEnd) {
|
|
155
|
+
const packed = cursor.uint16();
|
|
156
|
+
stepSizes.push({
|
|
157
|
+
exponent: packed >> 11,
|
|
158
|
+
mantissa: packed & 2047
|
|
159
|
+
});
|
|
160
|
+
}
|
|
161
|
+
return {
|
|
162
|
+
style: styleCode === 1 ? "derived" : "expounded",
|
|
163
|
+
guardBits,
|
|
164
|
+
stepSizes
|
|
165
|
+
};
|
|
166
|
+
}
|
|
167
|
+
throw new require_image_jpeg2000_errors.Jpeg2000ParseError(`QCD/QCC declares quantization style ${String(styleCode)}, which ISO/IEC 15444-1 Table A.28 does not define`);
|
|
168
|
+
}
|
|
169
|
+
function readComponentIndex(cursor, componentCount) {
|
|
170
|
+
return componentCount < 257 ? cursor.uint8() : cursor.uint16();
|
|
171
|
+
}
|
|
172
|
+
function emptyHeader() {
|
|
173
|
+
return {
|
|
174
|
+
coc: /* @__PURE__ */ new Map(),
|
|
175
|
+
qcc: /* @__PURE__ */ new Map(),
|
|
176
|
+
hasProgressionChanges: false,
|
|
177
|
+
hasRegionOfInterest: false,
|
|
178
|
+
hasPackedPacketHeaders: false
|
|
179
|
+
};
|
|
180
|
+
}
|
|
181
|
+
function freezeHeader(header) {
|
|
182
|
+
const base = {
|
|
183
|
+
coc: header.coc,
|
|
184
|
+
qcc: header.qcc,
|
|
185
|
+
hasProgressionChanges: header.hasProgressionChanges,
|
|
186
|
+
hasRegionOfInterest: header.hasRegionOfInterest,
|
|
187
|
+
hasPackedPacketHeaders: header.hasPackedPacketHeaders
|
|
188
|
+
};
|
|
189
|
+
if (header.cod !== void 0 && header.qcd !== void 0) return {
|
|
190
|
+
...base,
|
|
191
|
+
cod: header.cod,
|
|
192
|
+
qcd: header.qcd
|
|
193
|
+
};
|
|
194
|
+
if (header.cod !== void 0) return {
|
|
195
|
+
...base,
|
|
196
|
+
cod: header.cod
|
|
197
|
+
};
|
|
198
|
+
if (header.qcd !== void 0) return {
|
|
199
|
+
...base,
|
|
200
|
+
qcd: header.qcd
|
|
201
|
+
};
|
|
202
|
+
return base;
|
|
203
|
+
}
|
|
204
|
+
function readHeaderSegment(marker, cursor, header, componentCount, comments) {
|
|
205
|
+
const length = cursor.uint16();
|
|
206
|
+
if (length < 2) throw new require_image_jpeg2000_errors.Jpeg2000ParseError(`marker segment 0x${marker.toString(16)} declares a length of ${String(length)}, which is shorter than the length field itself`);
|
|
207
|
+
const segmentEnd = cursor.position + length - 2;
|
|
208
|
+
if (segmentEnd > cursor.data.length) throw new require_image_jpeg2000_errors.Jpeg2000ParseError(`marker segment 0x${marker.toString(16)} declares more data than the codestream carries`);
|
|
209
|
+
if (marker === MARKER_COD) header.cod = readCodingDefaults(cursor);
|
|
210
|
+
else if (marker === MARKER_COC) {
|
|
211
|
+
const component = readComponentIndex(cursor, componentCount);
|
|
212
|
+
header.coc.set(component, readCodingStyleParameters(cursor, (cursor.uint8() & 1) !== 0));
|
|
213
|
+
} else if (marker === MARKER_QCD) header.qcd = readQuantization(cursor, segmentEnd);
|
|
214
|
+
else if (marker === MARKER_QCC) {
|
|
215
|
+
const component = readComponentIndex(cursor, componentCount);
|
|
216
|
+
header.qcc.set(component, readQuantization(cursor, segmentEnd));
|
|
217
|
+
} else if (marker === MARKER_POC) header.hasProgressionChanges = true;
|
|
218
|
+
else if (marker === MARKER_RGN) header.hasRegionOfInterest = true;
|
|
219
|
+
else if (marker === MARKER_PPT) header.hasPackedPacketHeaders = true;
|
|
220
|
+
else if (marker === MARKER_COM) {
|
|
221
|
+
const registration = cursor.uint16();
|
|
222
|
+
const body = cursor.bytes(segmentEnd - cursor.position);
|
|
223
|
+
if (registration === 1) comments.push(Array.from(body, (byte) => String.fromCharCode(byte)).join(""));
|
|
224
|
+
}
|
|
225
|
+
cursor.position = segmentEnd;
|
|
226
|
+
}
|
|
227
|
+
function validateMainHeader(header) {
|
|
228
|
+
if (header.cod === void 0) throw new require_image_jpeg2000_errors.Jpeg2000ParseError("the main header carries no COD marker, so no coding style is defined for any tile");
|
|
229
|
+
if (header.qcd === void 0) throw new require_image_jpeg2000_errors.Jpeg2000ParseError("the main header carries no QCD marker, so no quantization is defined for any tile");
|
|
230
|
+
}
|
|
231
|
+
function parseJpeg2000Codestream(data) {
|
|
232
|
+
const cursor = new MarkerCursor(data);
|
|
233
|
+
if (cursor.remaining < 4 || cursor.uint16() !== MARKER_SOC) throw new require_image_jpeg2000_errors.Jpeg2000ParseError("codestream does not begin with an SOC marker");
|
|
234
|
+
if (cursor.uint16() !== MARKER_SIZ) throw new require_image_jpeg2000_errors.Jpeg2000ParseError("the SOC marker is not immediately followed by SIZ, which ISO/IEC 15444-1 A.3 requires");
|
|
235
|
+
const sizLength = cursor.uint16();
|
|
236
|
+
const sizEnd = cursor.position + sizLength - 2;
|
|
237
|
+
const siz = readImageSize(cursor, sizEnd);
|
|
238
|
+
cursor.position = sizEnd;
|
|
239
|
+
const comments = [];
|
|
240
|
+
const main = emptyHeader();
|
|
241
|
+
const tileParts = [];
|
|
242
|
+
let sawEoc = false;
|
|
243
|
+
for (;;) {
|
|
244
|
+
if (cursor.remaining < 2) break;
|
|
245
|
+
const marker = cursor.uint16();
|
|
246
|
+
if (marker === MARKER_EOC) {
|
|
247
|
+
sawEoc = true;
|
|
248
|
+
break;
|
|
249
|
+
}
|
|
250
|
+
if (marker === MARKER_PPM) throw new require_image_jpeg2000_errors.Jpeg2000UnsupportedError("the codestream carries a PPM marker (packed packet headers in the main header), an organisation this decoder does not reassemble");
|
|
251
|
+
if (marker === MARKER_SOT) {
|
|
252
|
+
cursor.position -= 2;
|
|
253
|
+
readTilePart(cursor, siz.components.length, tileParts, comments);
|
|
254
|
+
continue;
|
|
255
|
+
}
|
|
256
|
+
if (marker === MARKER_SOD || marker === MARKER_SOC) throw new require_image_jpeg2000_errors.Jpeg2000ParseError(`unexpected marker 0x${marker.toString(16)} in the main header`);
|
|
257
|
+
readHeaderSegment(marker, cursor, main, siz.components.length, comments);
|
|
258
|
+
}
|
|
259
|
+
validateMainHeader(main);
|
|
260
|
+
const numTilesWide = Math.ceil((siz.xsiz - siz.xtosiz) / siz.xtsiz);
|
|
261
|
+
const numTilesHigh = Math.ceil((siz.ysiz - siz.ytosiz) / siz.ytsiz);
|
|
262
|
+
return {
|
|
263
|
+
bytes: data,
|
|
264
|
+
siz,
|
|
265
|
+
main: freezeHeader(main),
|
|
266
|
+
tileParts,
|
|
267
|
+
comments,
|
|
268
|
+
numTilesWide,
|
|
269
|
+
numTilesHigh,
|
|
270
|
+
truncated: !sawEoc
|
|
271
|
+
};
|
|
272
|
+
}
|
|
273
|
+
function readTilePart(cursor, componentCount, tileParts, comments) {
|
|
274
|
+
const sotStart = cursor.position;
|
|
275
|
+
cursor.uint16();
|
|
276
|
+
const lsot = cursor.uint16();
|
|
277
|
+
if (lsot !== 10) throw new require_image_jpeg2000_errors.Jpeg2000ParseError(`SOT declares a length of ${String(lsot)}, but ISO/IEC 15444-1 A.4.2 fixes it at 10`);
|
|
278
|
+
const tileIndex = cursor.uint16();
|
|
279
|
+
const psot = cursor.uint32();
|
|
280
|
+
const partIndex = cursor.uint8();
|
|
281
|
+
cursor.uint8();
|
|
282
|
+
const header = emptyHeader();
|
|
283
|
+
for (;;) {
|
|
284
|
+
if (cursor.remaining < 2) throw new require_image_jpeg2000_errors.Jpeg2000ParseError("a tile-part header ended without an SOD marker");
|
|
285
|
+
const marker = cursor.uint16();
|
|
286
|
+
if (marker === MARKER_SOD) break;
|
|
287
|
+
if (marker === MARKER_SOT || marker === MARKER_EOC) throw new require_image_jpeg2000_errors.Jpeg2000ParseError(`a tile-part header ended at marker 0x${marker.toString(16)} rather than at SOD`);
|
|
288
|
+
readHeaderSegment(marker, cursor, header, componentCount, comments);
|
|
289
|
+
}
|
|
290
|
+
const dataStart = cursor.position;
|
|
291
|
+
const declaredEnd = psot === 0 ? cursor.data.length : sotStart + psot;
|
|
292
|
+
const dataEnd = Math.min(declaredEnd, cursor.data.length);
|
|
293
|
+
if (dataEnd < dataStart) throw new require_image_jpeg2000_errors.Jpeg2000ParseError("a tile-part declares a Psot shorter than its own header");
|
|
294
|
+
const trimmedEnd = trimTrailingEoc(cursor.data, dataStart, dataEnd);
|
|
295
|
+
tileParts.push({
|
|
296
|
+
tileIndex,
|
|
297
|
+
partIndex,
|
|
298
|
+
header: freezeHeader(header),
|
|
299
|
+
dataStart,
|
|
300
|
+
dataEnd: trimmedEnd
|
|
301
|
+
});
|
|
302
|
+
cursor.position = dataEnd;
|
|
303
|
+
}
|
|
304
|
+
function trimTrailingEoc(data, start, end) {
|
|
305
|
+
if (end - start >= 2 && data[end - 2] === 255 && data[end - 1] === 217) return end - 2;
|
|
306
|
+
return end;
|
|
307
|
+
}
|
|
308
|
+
//#endregion
|
|
309
|
+
exports.parseJpeg2000Codestream = parseJpeg2000Codestream;
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
//#region src/image/jpeg2000-codestream.d.ts
|
|
2
|
+
type Jpeg2000ProgressionOrder = 'LRCP' | 'RLCP' | 'RPCL' | 'PCRL' | 'CPRL';
|
|
3
|
+
type Jpeg2000Transform = 'reversible-5-3' | 'irreversible-9-7';
|
|
4
|
+
type Jpeg2000QuantizationStyle = 'none' | 'derived' | 'expounded';
|
|
5
|
+
interface Jpeg2000ComponentSize {
|
|
6
|
+
readonly signed: boolean;
|
|
7
|
+
readonly bitDepth: number;
|
|
8
|
+
readonly dx: number;
|
|
9
|
+
readonly dy: number;
|
|
10
|
+
}
|
|
11
|
+
interface Jpeg2000ImageSize {
|
|
12
|
+
readonly xsiz: number;
|
|
13
|
+
readonly ysiz: number;
|
|
14
|
+
readonly xosiz: number;
|
|
15
|
+
readonly yosiz: number;
|
|
16
|
+
readonly xtsiz: number;
|
|
17
|
+
readonly ytsiz: number;
|
|
18
|
+
readonly xtosiz: number;
|
|
19
|
+
readonly ytosiz: number;
|
|
20
|
+
readonly components: readonly Jpeg2000ComponentSize[];
|
|
21
|
+
}
|
|
22
|
+
interface Jpeg2000PrecinctSize {
|
|
23
|
+
readonly ppx: number;
|
|
24
|
+
readonly ppy: number;
|
|
25
|
+
}
|
|
26
|
+
interface Jpeg2000CodingStyle {
|
|
27
|
+
readonly decompositionLevels: number;
|
|
28
|
+
readonly codeBlockWidthExp: number;
|
|
29
|
+
readonly codeBlockHeightExp: number;
|
|
30
|
+
readonly codeBlockStyle: number;
|
|
31
|
+
readonly transform: Jpeg2000Transform;
|
|
32
|
+
readonly precinctSizes: readonly Jpeg2000PrecinctSize[];
|
|
33
|
+
}
|
|
34
|
+
interface Jpeg2000CodingDefaults extends Jpeg2000CodingStyle {
|
|
35
|
+
readonly progressionOrder: Jpeg2000ProgressionOrder;
|
|
36
|
+
readonly layers: number;
|
|
37
|
+
readonly multipleComponentTransform: boolean;
|
|
38
|
+
readonly useSop: boolean;
|
|
39
|
+
readonly useEph: boolean;
|
|
40
|
+
}
|
|
41
|
+
interface Jpeg2000StepSize {
|
|
42
|
+
readonly exponent: number;
|
|
43
|
+
readonly mantissa: number;
|
|
44
|
+
}
|
|
45
|
+
interface Jpeg2000Quantization {
|
|
46
|
+
readonly style: Jpeg2000QuantizationStyle;
|
|
47
|
+
readonly guardBits: number;
|
|
48
|
+
readonly stepSizes: readonly Jpeg2000StepSize[];
|
|
49
|
+
}
|
|
50
|
+
interface Jpeg2000HeaderOverrides {
|
|
51
|
+
readonly cod?: Jpeg2000CodingDefaults;
|
|
52
|
+
readonly coc: ReadonlyMap<number, Jpeg2000CodingStyle>;
|
|
53
|
+
readonly qcd?: Jpeg2000Quantization;
|
|
54
|
+
readonly qcc: ReadonlyMap<number, Jpeg2000Quantization>;
|
|
55
|
+
readonly hasProgressionChanges: boolean;
|
|
56
|
+
readonly hasRegionOfInterest: boolean;
|
|
57
|
+
readonly hasPackedPacketHeaders: boolean;
|
|
58
|
+
}
|
|
59
|
+
interface Jpeg2000TilePart {
|
|
60
|
+
readonly tileIndex: number;
|
|
61
|
+
readonly partIndex: number;
|
|
62
|
+
readonly header: Jpeg2000HeaderOverrides;
|
|
63
|
+
readonly dataStart: number;
|
|
64
|
+
readonly dataEnd: number;
|
|
65
|
+
}
|
|
66
|
+
interface Jpeg2000Codestream {
|
|
67
|
+
readonly bytes: Uint8Array<ArrayBuffer>;
|
|
68
|
+
readonly siz: Jpeg2000ImageSize;
|
|
69
|
+
readonly main: Jpeg2000HeaderOverrides;
|
|
70
|
+
readonly tileParts: readonly Jpeg2000TilePart[];
|
|
71
|
+
readonly comments: readonly string[];
|
|
72
|
+
readonly numTilesWide: number;
|
|
73
|
+
readonly numTilesHigh: number;
|
|
74
|
+
readonly truncated: boolean;
|
|
75
|
+
}
|
|
76
|
+
declare function parseJpeg2000Codestream(data: Uint8Array<ArrayBuffer>): Jpeg2000Codestream;
|
|
77
|
+
//#endregion
|
|
78
|
+
export { Jpeg2000Codestream, Jpeg2000CodingDefaults, Jpeg2000CodingStyle, Jpeg2000ComponentSize, Jpeg2000HeaderOverrides, Jpeg2000ImageSize, Jpeg2000PrecinctSize, Jpeg2000ProgressionOrder, Jpeg2000Quantization, Jpeg2000QuantizationStyle, Jpeg2000StepSize, Jpeg2000TilePart, Jpeg2000Transform, parseJpeg2000Codestream };
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
//#region src/image/jpeg2000-codestream.d.ts
|
|
2
|
+
type Jpeg2000ProgressionOrder = 'LRCP' | 'RLCP' | 'RPCL' | 'PCRL' | 'CPRL';
|
|
3
|
+
type Jpeg2000Transform = 'reversible-5-3' | 'irreversible-9-7';
|
|
4
|
+
type Jpeg2000QuantizationStyle = 'none' | 'derived' | 'expounded';
|
|
5
|
+
interface Jpeg2000ComponentSize {
|
|
6
|
+
readonly signed: boolean;
|
|
7
|
+
readonly bitDepth: number;
|
|
8
|
+
readonly dx: number;
|
|
9
|
+
readonly dy: number;
|
|
10
|
+
}
|
|
11
|
+
interface Jpeg2000ImageSize {
|
|
12
|
+
readonly xsiz: number;
|
|
13
|
+
readonly ysiz: number;
|
|
14
|
+
readonly xosiz: number;
|
|
15
|
+
readonly yosiz: number;
|
|
16
|
+
readonly xtsiz: number;
|
|
17
|
+
readonly ytsiz: number;
|
|
18
|
+
readonly xtosiz: number;
|
|
19
|
+
readonly ytosiz: number;
|
|
20
|
+
readonly components: readonly Jpeg2000ComponentSize[];
|
|
21
|
+
}
|
|
22
|
+
interface Jpeg2000PrecinctSize {
|
|
23
|
+
readonly ppx: number;
|
|
24
|
+
readonly ppy: number;
|
|
25
|
+
}
|
|
26
|
+
interface Jpeg2000CodingStyle {
|
|
27
|
+
readonly decompositionLevels: number;
|
|
28
|
+
readonly codeBlockWidthExp: number;
|
|
29
|
+
readonly codeBlockHeightExp: number;
|
|
30
|
+
readonly codeBlockStyle: number;
|
|
31
|
+
readonly transform: Jpeg2000Transform;
|
|
32
|
+
readonly precinctSizes: readonly Jpeg2000PrecinctSize[];
|
|
33
|
+
}
|
|
34
|
+
interface Jpeg2000CodingDefaults extends Jpeg2000CodingStyle {
|
|
35
|
+
readonly progressionOrder: Jpeg2000ProgressionOrder;
|
|
36
|
+
readonly layers: number;
|
|
37
|
+
readonly multipleComponentTransform: boolean;
|
|
38
|
+
readonly useSop: boolean;
|
|
39
|
+
readonly useEph: boolean;
|
|
40
|
+
}
|
|
41
|
+
interface Jpeg2000StepSize {
|
|
42
|
+
readonly exponent: number;
|
|
43
|
+
readonly mantissa: number;
|
|
44
|
+
}
|
|
45
|
+
interface Jpeg2000Quantization {
|
|
46
|
+
readonly style: Jpeg2000QuantizationStyle;
|
|
47
|
+
readonly guardBits: number;
|
|
48
|
+
readonly stepSizes: readonly Jpeg2000StepSize[];
|
|
49
|
+
}
|
|
50
|
+
interface Jpeg2000HeaderOverrides {
|
|
51
|
+
readonly cod?: Jpeg2000CodingDefaults;
|
|
52
|
+
readonly coc: ReadonlyMap<number, Jpeg2000CodingStyle>;
|
|
53
|
+
readonly qcd?: Jpeg2000Quantization;
|
|
54
|
+
readonly qcc: ReadonlyMap<number, Jpeg2000Quantization>;
|
|
55
|
+
readonly hasProgressionChanges: boolean;
|
|
56
|
+
readonly hasRegionOfInterest: boolean;
|
|
57
|
+
readonly hasPackedPacketHeaders: boolean;
|
|
58
|
+
}
|
|
59
|
+
interface Jpeg2000TilePart {
|
|
60
|
+
readonly tileIndex: number;
|
|
61
|
+
readonly partIndex: number;
|
|
62
|
+
readonly header: Jpeg2000HeaderOverrides;
|
|
63
|
+
readonly dataStart: number;
|
|
64
|
+
readonly dataEnd: number;
|
|
65
|
+
}
|
|
66
|
+
interface Jpeg2000Codestream {
|
|
67
|
+
readonly bytes: Uint8Array<ArrayBuffer>;
|
|
68
|
+
readonly siz: Jpeg2000ImageSize;
|
|
69
|
+
readonly main: Jpeg2000HeaderOverrides;
|
|
70
|
+
readonly tileParts: readonly Jpeg2000TilePart[];
|
|
71
|
+
readonly comments: readonly string[];
|
|
72
|
+
readonly numTilesWide: number;
|
|
73
|
+
readonly numTilesHigh: number;
|
|
74
|
+
readonly truncated: boolean;
|
|
75
|
+
}
|
|
76
|
+
declare function parseJpeg2000Codestream(data: Uint8Array<ArrayBuffer>): Jpeg2000Codestream;
|
|
77
|
+
//#endregion
|
|
78
|
+
export { Jpeg2000Codestream, Jpeg2000CodingDefaults, Jpeg2000CodingStyle, Jpeg2000ComponentSize, Jpeg2000HeaderOverrides, Jpeg2000ImageSize, Jpeg2000PrecinctSize, Jpeg2000ProgressionOrder, Jpeg2000Quantization, Jpeg2000QuantizationStyle, Jpeg2000StepSize, Jpeg2000TilePart, Jpeg2000Transform, parseJpeg2000Codestream };
|