@silurus/ooxml 0.88.0 → 0.89.1
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 +118 -23
- package/THIRD_PARTY_NOTICES.md +8 -7
- package/dist/abort-VrnK7mdP.js +10 -0
- package/dist/assets/render-worker-C5G_Nr_A.js +35 -0
- package/dist/assets/render-worker-DQfWdNsm.js +16 -0
- package/dist/assets/render-worker-Ds7LjwU-.js +15 -0
- package/dist/{hyperlink-Cxzhet30.js → bounded-raw-part-cache-CsnNptAy.js} +4937 -7458
- package/dist/bundled-asset-url-E2nXURF9.js +15 -0
- package/dist/canvas-viewer-mechanics-BZ8QCrRi.js +675 -0
- package/dist/cfb-guard-dNeUiANF.js +528 -0
- package/dist/chart-ex.mjs +667 -663
- package/dist/comment-overlay-controller-CBvQx-En.js +994 -0
- package/dist/comment-ui-runtime-B7ZvovcS.js +2 -0
- package/dist/{comment-ui-runtime-DcJOYlw-.js → comment-ui-runtime-BKidRH36.js} +5 -5
- package/dist/{comment-ui-runtime-CWGqn5Vr.js → comment-ui-runtime-C47QoDUy.js} +5 -5
- package/dist/delimited-text-worker-host-CikWU6_m.js +27 -0
- package/dist/document-model-source-MzFPrxt0.js +249 -0
- package/dist/document-pull-client-BoJeuURD.js +35941 -0
- package/dist/document-pull-worker-CaP8XESP.js +104 -0
- package/dist/docx-BN70UhvX.js +495 -0
- package/dist/docx-BRRtSvk3.js +3563 -0
- package/dist/docx-model-source-CTO9iw_W.js +98 -0
- package/dist/docx-source-worker.mjs +455 -0
- package/dist/docx.mjs +7 -7
- package/dist/docx_parser_bg.wasm +0 -0
- package/dist/drawingml-shape-CHmq8kpM.js +310 -0
- package/dist/duotone-DN8P4aXe.js +126 -0
- package/dist/emf-CGFQIz6c.js +1790 -0
- package/dist/font-preload-demand-Dmy31xt-.js +2058 -0
- package/dist/grid-geometry-C3IG20ut.js +384 -0
- package/dist/host-layout-DVMw8hDY.js +56 -0
- package/dist/host-layout-measure-DsuQ2UJs.js +7 -0
- package/dist/in-process-pull-transport-DuXcPZng.js +29 -0
- package/dist/index.mjs +4 -4
- package/dist/internal-companion.mjs +12 -0
- package/dist/line-distribute-Bu8psjGd.js +2799 -0
- package/dist/math.mjs +2 -2
- package/dist/mathjax-stix2.js +10 -10
- package/dist/model-source-kz_NkZqT.js +179 -0
- package/dist/model-source-s5hRpk4w.js +61 -0
- package/dist/model-source-session-6fuaqbGs.js +71 -0
- package/dist/model-source-session-DqrR4XHR.js +85 -0
- package/dist/model-source-session-cPJSF_Ak.js +58 -0
- package/dist/node.mjs +7 -1327
- package/dist/{pixel-budget-9P63Bsk5.js → pixel-budget-BpTYrepD.js} +13 -10
- package/dist/plot-area-frame-Bs_j4uu7.js +41811 -0
- package/dist/pptx-CaJ6ILnw.js +183 -0
- package/dist/pptx-_BOGcBym.js +2936 -0
- package/dist/pptx-model-source-B_9afw9R.js +37 -0
- package/dist/pptx-source-worker.mjs +446 -0
- package/dist/pptx.mjs +8 -7
- package/dist/pptx_parser_bg.wasm +0 -0
- package/dist/presentation-model-source-CGHLyX32.js +77 -0
- package/dist/raster-target-YQ4G6rxo.js +42 -0
- package/dist/region-map.mjs +117 -153
- package/dist/{render-D3iqVKCo.js → render-CzbDzRKa.js} +3 -3
- package/dist/{render-worker-host-B5wQfB7U.js → render-worker-host-B1u6BOUd.js} +1 -1
- package/dist/{render-worker-host-D4123J27.js → render-worker-host-C-EECo68.js} +1 -1
- package/dist/{render-worker-host-Di3LxLc0.js → render-worker-host-DDqZTCVf.js} +1 -1
- package/dist/renderer-CD2cvVAF.js +5823 -0
- package/dist/renderer-DRoeb14O.js +5170 -0
- package/dist/resource-measurement-Dhhm7P_l.js +772 -0
- package/dist/session-XPmC0CUd.js +656 -0
- package/dist/slide-pull-client-tq7U_fYg.js +6485 -0
- package/dist/three-d-BKwNPAP4.js +878 -0
- package/dist/three-d.mjs +925 -910
- package/dist/{raster-target-ojDdQizC.js → tiff-contract-C6M3QcPp.js} +1 -42
- package/dist/tiff.mjs +401 -248
- package/dist/types/chart-ex.d.ts +149 -2
- package/dist/types/docx.d.ts +333 -96
- package/dist/types/index.d.ts +566 -301
- package/dist/types/internal-companion.d.ts +11 -0
- package/dist/types/math.d.ts +1 -1
- package/dist/types/node.d.ts +422 -9
- package/dist/types/pptx.d.ts +302 -95
- package/dist/types/region-map.d.ts +149 -2
- package/dist/types/three-d.d.ts +149 -2
- package/dist/types/tiff.d.ts +1 -1
- package/dist/types/xlsx.d.ts +343 -132
- package/dist/wasm-loader-rlgHmcSv.js +35 -0
- package/dist/wasm-runtime-generation-D6TKZdNb.js +97 -0
- package/dist/workbook-model-source-BIGrfZy6.js +94 -0
- package/dist/worker-source-DrwhR9fw.js +22 -0
- package/dist/worker-source-SbudzjYL.js +22 -0
- package/dist/worker-source-UAi3GNcM.js +22 -0
- package/dist/worksheet-pull-client-ClvPO_Jf.js +579 -0
- package/dist/xlsx-CsmREBaZ.js +5819 -0
- package/dist/xlsx-DmHfeNNp.js +534 -0
- package/dist/xlsx-model-source-D1flORqy.js +309 -0
- package/dist/xlsx-source-worker.mjs +525 -0
- package/dist/xlsx.mjs +8 -7
- package/dist/xlsx_parser_bg.wasm +0 -0
- package/package.json +42 -16
- package/dist/assets/render-worker-1uPAxMZr.js +0 -31
- package/dist/assets/render-worker-BlvJybji.js +0 -10
- package/dist/assets/render-worker-CzmiJfFL.js +0 -11
- package/dist/bounded-raw-part-cache-Cg1BsSZQ.js +0 -119
- package/dist/canvas-viewer-mechanics-DbLz0rYW.js +0 -1384
- package/dist/cjk-fallback-bLI3z70h.js +0 -46
- package/dist/comment-occurrence-C8Y2uoVr.js +0 -6
- package/dist/comment-ui-runtime-BsK8pmUT.js +0 -2
- package/dist/comments-Diid5ujN.js +0 -246
- package/dist/delimited-text-worker-host-BVY-Ecni.js +0 -27
- package/dist/document-pull-client-B9PTM-pL.js +0 -27280
- package/dist/docx-BF9WXrYH.js +0 -3103
- package/dist/dom-interaction-boundary-Cnm8DSBN.js +0 -223
- package/dist/highlight-rect-C5hkRqUr.js +0 -13
- package/dist/line-distribute-D1WNHKz_.js +0 -1023
- package/dist/line-metrics-B60C86uh.js +0 -60
- package/dist/plot-area-frame-DLTYKHNP.js +0 -4354
- package/dist/pptx-DkyYBYoL.js +0 -3065
- package/dist/renderer-B4GZb5We.js +0 -6492
- package/dist/resource-measurement-SHQCbkh2.js +0 -150
- package/dist/session-BGq81gRQ.js +0 -743
- package/dist/slide-pull-client-DiPnm240.js +0 -6253
- package/dist/source-key-DIJG8BA0.js +0 -42
- package/dist/three-d-DJBl8g8M.js +0 -1162
- package/dist/transfer-p6iCC2R7.js +0 -6
- package/dist/units-BzZ0gAxs.js +0 -4
- package/dist/worksheet-pull-client-BM8ywvbu.js +0 -458
- package/dist/xlsx-C9NVjgaV.js +0 -8484
- /package/dist/{chunk-DmhlhrBa.js → chunk-Dy4uBu1J.js} +0 -0
- /package/dist/{mathjax-DoyWZbSp.js → mathjax-BhwN6ilc.js} +0 -0
- /package/dist/{read-only-comment-decoration-Dz7eTQ4d.js → read-only-comment-decoration-PidH0wnP.js} +0 -0
- /package/dist/{read-only-comment-margin-DkgzASAl.js → read-only-comment-margin-B52rDVKo.js} +0 -0
- /package/dist/{renderer-module-contract-D91rkYHH.js → renderer-module-contract-CWM7jv6d.js} +0 -0
- /package/dist/{visible-index-BgiHEc1z.js → visible-index-FeVA0mGE.js} +0 -0
package/dist/tiff.mjs
CHANGED
|
@@ -1,8 +1,35 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { i as a, o,
|
|
3
|
-
import { t as
|
|
1
|
+
import { c as e, l as t, o as n, s as r, u as i } from "./pixel-budget-BpTYrepD.js";
|
|
2
|
+
import { i as a, r as o, t as s } from "./tiff-contract-C6M3QcPp.js";
|
|
3
|
+
import { t as c } from "./raster-target-YQ4G6rxo.js";
|
|
4
|
+
import { t as l } from "./renderer-module-contract-CWM7jv6d.js";
|
|
4
5
|
//#region packages/core/src/image/tiff.ts
|
|
5
|
-
var u =
|
|
6
|
+
var u = class {
|
|
7
|
+
bytes;
|
|
8
|
+
truncatedMessage;
|
|
9
|
+
byteCursor = 0;
|
|
10
|
+
byteEnd = 0;
|
|
11
|
+
bitInByte = 0;
|
|
12
|
+
constructor(e, t, n, r) {
|
|
13
|
+
this.bytes = e, this.truncatedMessage = r, this.beginStrip(t, n);
|
|
14
|
+
}
|
|
15
|
+
beginStrip(e, t) {
|
|
16
|
+
this.byteCursor = e, this.byteEnd = e + t, this.bitInByte = 0;
|
|
17
|
+
}
|
|
18
|
+
readBits(e) {
|
|
19
|
+
if (e > (this.byteEnd - this.byteCursor) * 8 - this.bitInByte) throw new s(this.truncatedMessage);
|
|
20
|
+
let t = 0;
|
|
21
|
+
for (; e > 0;) {
|
|
22
|
+
let n = 8 - this.bitInByte, r = Math.min(e, n);
|
|
23
|
+
t = t << r | this.bytes[this.byteCursor] >> n - r & (1 << r) - 1, this.bitInByte += r, this.bitInByte === 8 && (this.byteCursor++, this.bitInByte = 0), e -= r;
|
|
24
|
+
}
|
|
25
|
+
return t;
|
|
26
|
+
}
|
|
27
|
+
readBit() {
|
|
28
|
+
if (this.byteCursor >= this.byteEnd) throw new s(this.truncatedMessage);
|
|
29
|
+
let e = this.bytes[this.byteCursor] >> 7 - this.bitInByte & 1;
|
|
30
|
+
return this.bitInByte++, this.bitInByte === 8 && (this.byteCursor++, this.bitInByte = 0), e;
|
|
31
|
+
}
|
|
32
|
+
}, d = 1, f = 3, p = 4, m = {
|
|
6
33
|
width: 256,
|
|
7
34
|
height: 257,
|
|
8
35
|
bitsPerSample: 258,
|
|
@@ -24,16 +51,18 @@ var u = 1, d = 3, f = 4, p = {
|
|
|
24
51
|
inkSet: 332,
|
|
25
52
|
extraSamples: 338,
|
|
26
53
|
sampleFormat: 339
|
|
27
|
-
},
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
54
|
+
}, h = [
|
|
55
|
+
m.tileWidth,
|
|
56
|
+
m.tileLength,
|
|
57
|
+
m.tileOffsets,
|
|
58
|
+
m.tileByteCounts
|
|
32
59
|
];
|
|
33
|
-
function
|
|
34
|
-
throw new
|
|
60
|
+
function g(e, t) {
|
|
61
|
+
throw new s(e, t === void 0 ? void 0 : { cause: t });
|
|
35
62
|
}
|
|
36
|
-
var
|
|
63
|
+
var _ = class {
|
|
64
|
+
bytes;
|
|
65
|
+
littleEndian;
|
|
37
66
|
view;
|
|
38
67
|
constructor(e, t) {
|
|
39
68
|
this.bytes = e, this.littleEndian = t, this.view = new DataView(e.buffer, e.byteOffset, e.byteLength);
|
|
@@ -42,32 +71,32 @@ var g = class {
|
|
|
42
71
|
return Number.isSafeInteger(e) && Number.isSafeInteger(t) && e >= 0 && t >= 0 && e <= this.view.byteLength - t;
|
|
43
72
|
}
|
|
44
73
|
u8(e, t) {
|
|
45
|
-
return this.contains(e, 1) ||
|
|
74
|
+
return this.contains(e, 1) || g(`Malformed TIFF ${t} range`), this.view.getUint8(e);
|
|
46
75
|
}
|
|
47
76
|
u16(e, t) {
|
|
48
|
-
return this.contains(e, 2) ||
|
|
77
|
+
return this.contains(e, 2) || g(`Malformed TIFF ${t} range`), this.view.getUint16(e, this.littleEndian);
|
|
49
78
|
}
|
|
50
79
|
u32(e, t) {
|
|
51
|
-
return this.contains(e, 4) ||
|
|
80
|
+
return this.contains(e, 4) || g(`Malformed TIFF ${t} range`), this.view.getUint32(e, this.littleEndian);
|
|
52
81
|
}
|
|
53
82
|
};
|
|
54
|
-
function
|
|
83
|
+
function v(e) {
|
|
55
84
|
return e.length >= 2 && (e[0] === 73 && e[1] === 73 || e[0] === 77 && e[1] === 77);
|
|
56
85
|
}
|
|
57
|
-
function
|
|
86
|
+
function y(e) {
|
|
58
87
|
if (!o(e)) {
|
|
59
|
-
if (!
|
|
60
|
-
e.length < 4 &&
|
|
88
|
+
if (!v(e)) return null;
|
|
89
|
+
e.length < 4 && g("Malformed TIFF header: missing version");
|
|
61
90
|
let t = e[0] === 73;
|
|
62
|
-
|
|
91
|
+
g(`Unsupported TIFF version: ${new DataView(e.buffer, e.byteOffset, e.byteLength).getUint16(2, t)}`);
|
|
63
92
|
}
|
|
64
|
-
e.length < 8 &&
|
|
65
|
-
let t = new
|
|
66
|
-
t.contains(n + 2, i) ||
|
|
93
|
+
e.length < 8 && g("Malformed TIFF header: missing first-IFD offset");
|
|
94
|
+
let t = new _(e, e[0] === 73), n = t.u32(4, "first-IFD offset"), r = t.u16(n, "first IFD"), i = r * 12 + 4;
|
|
95
|
+
t.contains(n + 2, i) || g("Malformed TIFF first-IFD entry range");
|
|
67
96
|
let a = /* @__PURE__ */ new Map();
|
|
68
97
|
for (let e = 0; e < r; e++) {
|
|
69
98
|
let r = n + 2 + e * 12, i = t.u16(r, `IFD entry ${e}`), o = t.u16(r + 2, `IFD entry ${e} type`), s = t.u32(r + 4, `IFD entry ${e} count`);
|
|
70
|
-
a.has(i) &&
|
|
99
|
+
a.has(i) && g(`Malformed TIFF: duplicate tag ${i}`), a.set(i, {
|
|
71
100
|
type: o,
|
|
72
101
|
count: s,
|
|
73
102
|
entryOffset: r
|
|
@@ -78,65 +107,66 @@ function v(e) {
|
|
|
78
107
|
fields: a
|
|
79
108
|
};
|
|
80
109
|
}
|
|
81
|
-
function
|
|
82
|
-
return e ===
|
|
110
|
+
function b(e) {
|
|
111
|
+
return e === d ? 1 : e === f ? 2 : e === p ? 4 : 0;
|
|
83
112
|
}
|
|
84
|
-
function
|
|
113
|
+
function x(e, t, n, r) {
|
|
85
114
|
let i = e.fields.get(t);
|
|
86
115
|
if (!i) return;
|
|
87
|
-
r.includes(i.type) ||
|
|
88
|
-
let a =
|
|
89
|
-
Number.isSafeInteger(o) ||
|
|
116
|
+
r.includes(i.type) || g(`Unsupported TIFF ${n} field type: ${i.type}`), i.count < 1 && g(`Malformed TIFF ${n}: empty value list`);
|
|
117
|
+
let a = b(i.type), o = i.count * a;
|
|
118
|
+
Number.isSafeInteger(o) || g(`Malformed TIFF ${n} value count`);
|
|
90
119
|
let s = o <= 4 ? i.entryOffset + 8 : e.reader.u32(i.entryOffset + 8, `${n} value offset`);
|
|
91
|
-
return e.reader.contains(s, o) ||
|
|
120
|
+
return e.reader.contains(s, o) || g(`Malformed TIFF ${n} value range`), {
|
|
92
121
|
count: i.count,
|
|
93
122
|
at(t) {
|
|
94
|
-
(!Number.isSafeInteger(t) || t < 0 || t >= i.count) &&
|
|
123
|
+
(!Number.isSafeInteger(t) || t < 0 || t >= i.count) && g(`Malformed TIFF ${n} value index`);
|
|
95
124
|
let r = s + t * a;
|
|
96
|
-
return i.type ===
|
|
125
|
+
return i.type === d ? e.reader.u8(r, n) : i.type === f ? e.reader.u16(r, n) : e.reader.u32(r, n);
|
|
97
126
|
}
|
|
98
127
|
};
|
|
99
128
|
}
|
|
100
|
-
function
|
|
101
|
-
let a =
|
|
129
|
+
function S(e, t, n, r, i) {
|
|
130
|
+
let a = x(e, t, n, r);
|
|
102
131
|
if (!a) {
|
|
103
132
|
if (i !== void 0) return i;
|
|
104
|
-
|
|
133
|
+
g(`Malformed TIFF: missing ${n}`);
|
|
105
134
|
}
|
|
106
|
-
return a.count !== 1 &&
|
|
135
|
+
return a.count !== 1 && g(`Malformed TIFF ${n}: expected one value`), a.at(0);
|
|
107
136
|
}
|
|
108
|
-
function
|
|
109
|
-
let a =
|
|
110
|
-
return a ||
|
|
137
|
+
function C(e, t, n, r, i) {
|
|
138
|
+
let a = x(e, t, n, r);
|
|
139
|
+
return a || g(`Malformed TIFF: missing ${n}`), a.count !== i && g(`Malformed TIFF ${n}: expected ${i} value${i === 1 ? "" : "s"}`), a;
|
|
111
140
|
}
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
141
|
+
var w = 1, T = 4, E = 5;
|
|
142
|
+
function ee(n, r) {
|
|
143
|
+
(n < 1 || r < 1) && g("Malformed TIFF: image dimensions must be positive");
|
|
144
|
+
let a = Math.max(n, r);
|
|
115
145
|
if (a > 134217728) throw new i("image-dimension", e, a);
|
|
116
|
-
let o =
|
|
117
|
-
if (o > 134217728) throw new i("image-pixels",
|
|
146
|
+
let o = n * r;
|
|
147
|
+
if (o > 134217728) throw new i("image-pixels", t, Number.isSafeInteger(o) ? o : 2 ** 53 - 1);
|
|
118
148
|
}
|
|
119
|
-
function
|
|
120
|
-
if (!e.fields.has(
|
|
121
|
-
let n =
|
|
149
|
+
function te(e, t) {
|
|
150
|
+
if (!e.fields.has(m.bitsPerSample)) return [1];
|
|
151
|
+
let n = C(e, m.bitsPerSample, "BitsPerSample", [f], t), r = Array(t);
|
|
122
152
|
for (let e = 0; e < t; e++) r[e] = n.at(e);
|
|
123
153
|
return r;
|
|
124
154
|
}
|
|
125
|
-
function
|
|
126
|
-
if (!e.fields.has(
|
|
127
|
-
let n =
|
|
128
|
-
for (let e = 0; e < n.count; e++) n.at(e) !== 1 &&
|
|
129
|
-
}
|
|
130
|
-
function
|
|
131
|
-
let n =
|
|
132
|
-
n !==
|
|
133
|
-
let r =
|
|
134
|
-
i !== 1 && i !== 3 && i !== 4 &&
|
|
135
|
-
let a =
|
|
136
|
-
if (
|
|
137
|
-
(i !== 1 || a.length !== 1 || a[0] !== 1 || r !== 0 && r !== 1) &&
|
|
138
|
-
let t =
|
|
139
|
-
return t !== 0 &&
|
|
155
|
+
function ne(e, t) {
|
|
156
|
+
if (!e.fields.has(m.sampleFormat)) return;
|
|
157
|
+
let n = C(e, m.sampleFormat, "SampleFormat", [f], t);
|
|
158
|
+
for (let e = 0; e < n.count; e++) n.at(e) !== 1 && g("Unsupported TIFF SampleFormat: only unsigned integers are supported");
|
|
159
|
+
}
|
|
160
|
+
function D(e, t) {
|
|
161
|
+
let n = S(e, m.compression, "Compression", [f], 1);
|
|
162
|
+
n !== w && n !== T && n !== E && g(`Unsupported TIFF compression: ${n}`);
|
|
163
|
+
let r = S(e, m.photometric, "PhotometricInterpretation", [f]), i = S(e, m.samplesPerPixel, "SamplesPerPixel", [f], 1);
|
|
164
|
+
i !== 1 && i !== 3 && i !== 4 && g(`Unsupported TIFF SamplesPerPixel: ${i}`);
|
|
165
|
+
let a = te(e, i);
|
|
166
|
+
if (ne(e, i), n === T) {
|
|
167
|
+
(i !== 1 || a.length !== 1 || a[0] !== 1 || r !== 0 && r !== 1) && g("Unsupported CCITT Group 4 TIFF sample layout"), e.fields.has(m.extraSamples) && g("Unsupported CCITT Group 4 TIFF ExtraSamples");
|
|
168
|
+
let t = S(e, m.t6Options, "T6Options", [p], 0);
|
|
169
|
+
return t !== 0 && g(`Unsupported TIFF T6Options: ${t}`), {
|
|
140
170
|
compression: n,
|
|
141
171
|
layout: {
|
|
142
172
|
kind: "group4",
|
|
@@ -145,7 +175,7 @@ function E(e, t) {
|
|
|
145
175
|
};
|
|
146
176
|
}
|
|
147
177
|
if (r === 0 || r === 1) {
|
|
148
|
-
if ((i !== 1 || e.fields.has(
|
|
178
|
+
if ((i !== 1 || e.fields.has(m.extraSamples)) && g("Unsupported TIFF grayscale sample layout"), a[0] === 1) return {
|
|
149
179
|
compression: n,
|
|
150
180
|
layout: {
|
|
151
181
|
kind: "gray-1",
|
|
@@ -161,10 +191,10 @@ function E(e, t) {
|
|
|
161
191
|
bytesPerRow: t
|
|
162
192
|
}
|
|
163
193
|
};
|
|
164
|
-
|
|
194
|
+
g(`Unsupported TIFF grayscale BitsPerSample: ${a[0]}`);
|
|
165
195
|
}
|
|
166
196
|
if (r === 2) {
|
|
167
|
-
if (a.some((e) => e !== 8) &&
|
|
197
|
+
if (a.some((e) => e !== 8) && g("Unsupported TIFF RGB BitsPerSample: only 8-bit samples are supported"), i === 3) return e.fields.has(m.extraSamples) && g("Unsupported TIFF RGB ExtraSamples"), {
|
|
168
198
|
compression: n,
|
|
169
199
|
layout: {
|
|
170
200
|
kind: "rgb",
|
|
@@ -172,7 +202,7 @@ function E(e, t) {
|
|
|
172
202
|
}
|
|
173
203
|
};
|
|
174
204
|
if (i === 4) {
|
|
175
|
-
let r =
|
|
205
|
+
let r = C(e, m.extraSamples, "ExtraSamples", [f], 1).at(0);
|
|
176
206
|
if (r === 1) return {
|
|
177
207
|
compression: n,
|
|
178
208
|
layout: {
|
|
@@ -187,14 +217,14 @@ function E(e, t) {
|
|
|
187
217
|
bytesPerRow: t * 4
|
|
188
218
|
}
|
|
189
219
|
};
|
|
190
|
-
|
|
220
|
+
g(`Unsupported TIFF ExtraSamples value: ${r}`);
|
|
191
221
|
}
|
|
192
|
-
|
|
222
|
+
g(`Unsupported TIFF RGB SamplesPerPixel: ${i}`);
|
|
193
223
|
}
|
|
194
224
|
if (r === 5) {
|
|
195
|
-
(i !== 4 || a.length !== 4 || a.some((e) => e !== 8)) &&
|
|
196
|
-
let r =
|
|
197
|
-
return r !== 1 &&
|
|
225
|
+
(i !== 4 || a.length !== 4 || a.some((e) => e !== 8)) && g("Unsupported TIFF separated sample layout: expected 8-bit process CMYK"), e.fields.has(m.extraSamples) && g("Unsupported TIFF CMYK ExtraSamples");
|
|
226
|
+
let r = S(e, m.inkSet, "InkSet", [f], 1);
|
|
227
|
+
return r !== 1 && g(`Unsupported TIFF InkSet: ${r}`), {
|
|
198
228
|
compression: n,
|
|
199
229
|
layout: {
|
|
200
230
|
kind: "cmyk",
|
|
@@ -202,164 +232,287 @@ function E(e, t) {
|
|
|
202
232
|
}
|
|
203
233
|
};
|
|
204
234
|
}
|
|
205
|
-
|
|
235
|
+
g(`Unsupported TIFF PhotometricInterpretation: ${r}`);
|
|
236
|
+
}
|
|
237
|
+
function O(e, t, n) {
|
|
238
|
+
let r = S(e, m.predictor, "Predictor", [f], 1);
|
|
239
|
+
if (r === 1) return null;
|
|
240
|
+
switch (r !== 2 && g(`Unsupported TIFF Predictor: ${r}`), t !== E && g(`Unsupported TIFF Predictor 2 with Compression ${t}`), n.kind) {
|
|
241
|
+
case "gray-8": return 1;
|
|
242
|
+
case "rgb": return 3;
|
|
243
|
+
case "rgba-associated":
|
|
244
|
+
case "rgba-unassociated":
|
|
245
|
+
case "cmyk": return 4;
|
|
246
|
+
default: return g("Unsupported TIFF Predictor 2 with 1-bit samples");
|
|
247
|
+
}
|
|
206
248
|
}
|
|
207
|
-
function
|
|
208
|
-
let t =
|
|
249
|
+
function k(e) {
|
|
250
|
+
let t = y(e);
|
|
209
251
|
if (!t) return null;
|
|
210
|
-
let n =
|
|
211
|
-
|
|
212
|
-
let i =
|
|
213
|
-
i !== 1 &&
|
|
214
|
-
let a =
|
|
215
|
-
a !== 1 &&
|
|
216
|
-
let o =
|
|
217
|
-
o !== 1 &&
|
|
218
|
-
let s =
|
|
219
|
-
s
|
|
220
|
-
let c =
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
let t = e * c, n = Math.min(c, r - t) * y.bytesPerRow;
|
|
227
|
-
i < n && h(`Malformed TIFF strip ${e}: ${i} bytes cannot hold ${n} bytes`);
|
|
252
|
+
let n = S(t, m.width, "ImageWidth", [f, p]), r = S(t, m.height, "ImageLength", [f, p]);
|
|
253
|
+
ee(n, r), h.some((e) => t.fields.has(e)) && g("Unsupported tiled TIFF: only stripped images are supported");
|
|
254
|
+
let i = S(t, m.orientation, "Orientation", [f], 1);
|
|
255
|
+
i !== 1 && g(`Unsupported TIFF orientation: ${i}`);
|
|
256
|
+
let a = S(t, m.planarConfiguration, "PlanarConfiguration", [f], 1);
|
|
257
|
+
a !== 1 && g(`Unsupported TIFF PlanarConfiguration: ${a}`);
|
|
258
|
+
let o = S(t, m.fillOrder, "FillOrder", [f], 1);
|
|
259
|
+
o !== 1 && g(`Unsupported TIFF FillOrder: ${o}`);
|
|
260
|
+
let s = S(t, m.rowsPerStrip, "RowsPerStrip", [f, p], 4294967295);
|
|
261
|
+
s < 1 && g("Malformed TIFF RowsPerStrip: expected a positive value");
|
|
262
|
+
let c = Math.ceil(r / s), l = C(t, m.stripOffsets, "StripOffsets", [f, p], c), u = C(t, m.stripByteCounts, "StripByteCounts", [f, p], c), { compression: d, layout: _ } = D(t, n), v = O(t, d, _);
|
|
263
|
+
for (let e = 0; e < c; e++) {
|
|
264
|
+
let n = l.at(e), i = u.at(e);
|
|
265
|
+
if (t.reader.contains(n, i) || g(`Malformed TIFF strip ${e} byte range`), d === w) {
|
|
266
|
+
let t = e * s, n = Math.min(s, r - t) * _.bytesPerRow;
|
|
267
|
+
i < n && g(`Malformed TIFF strip ${e}: ${i} bytes cannot hold ${n} bytes`);
|
|
228
268
|
}
|
|
229
269
|
}
|
|
230
270
|
return {
|
|
231
271
|
directory: t,
|
|
232
272
|
width: n,
|
|
233
273
|
height: r,
|
|
234
|
-
rowsPerStrip:
|
|
235
|
-
stripCount:
|
|
236
|
-
stripOffsets:
|
|
237
|
-
stripByteCounts:
|
|
238
|
-
|
|
274
|
+
rowsPerStrip: s,
|
|
275
|
+
stripCount: c,
|
|
276
|
+
stripOffsets: l,
|
|
277
|
+
stripByteCounts: u,
|
|
278
|
+
compression: d,
|
|
279
|
+
layout: _,
|
|
280
|
+
differencingStride: v
|
|
239
281
|
};
|
|
240
282
|
}
|
|
241
|
-
function
|
|
242
|
-
if (e !== void 0) return (!Number.isFinite(e) || e <= 0) &&
|
|
283
|
+
function A(e, t) {
|
|
284
|
+
if (e !== void 0) return (!Number.isFinite(e) || e <= 0) && g(`Invalid TIFF ${t}: expected a positive finite number`), e;
|
|
243
285
|
}
|
|
244
|
-
function
|
|
245
|
-
let o =
|
|
286
|
+
function j(e, t, a) {
|
|
287
|
+
let o = A(a.targetWidthPx, "targetWidthPx"), s = A(a.targetHeightPx, "targetHeightPx"), l = c({
|
|
246
288
|
width: e,
|
|
247
|
-
height:
|
|
248
|
-
}, o, s, !0), u = l?.width ?? e, d = l?.height ??
|
|
249
|
-
if (f > 32767) throw new i("image-dimension",
|
|
289
|
+
height: t
|
|
290
|
+
}, o, s, !0), u = l?.width ?? e, d = l?.height ?? t, f = Math.max(u, d);
|
|
291
|
+
if (f > 32767) throw new i("image-dimension", n, f);
|
|
250
292
|
let p = a.maxRetainedPixels ?? 33554432;
|
|
251
|
-
(!Number.isFinite(p) || p < 0) &&
|
|
252
|
-
let m = Math.min(
|
|
253
|
-
if (
|
|
293
|
+
(!Number.isFinite(p) || p < 0) && g("Invalid TIFF maxRetainedPixels: expected a non-negative finite number");
|
|
294
|
+
let m = Math.min(r, Math.floor(p)), h = u * d;
|
|
295
|
+
if (h > m) throw new i("image-pixels", m, h);
|
|
254
296
|
return {
|
|
255
297
|
width: u,
|
|
256
298
|
height: d,
|
|
257
|
-
pixels:
|
|
299
|
+
pixels: h
|
|
258
300
|
};
|
|
259
301
|
}
|
|
260
|
-
function
|
|
302
|
+
function M(e, t) {
|
|
261
303
|
return Math.round((255 - e) * (255 - t) / 255);
|
|
262
304
|
}
|
|
263
|
-
function
|
|
305
|
+
function N(e, t) {
|
|
264
306
|
return t === 0 ? 0 : Math.min(255, Math.round(e * 255 / t));
|
|
265
307
|
}
|
|
266
|
-
function
|
|
267
|
-
let n =
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
308
|
+
function re(e, t) {
|
|
309
|
+
let n = {
|
|
310
|
+
bytes: e.directory.reader.bytes,
|
|
311
|
+
rowOffset: 0,
|
|
312
|
+
firstX: 0,
|
|
313
|
+
endX: e.width
|
|
314
|
+
};
|
|
315
|
+
return (r, i) => {
|
|
316
|
+
let a = Math.floor(r / e.rowsPerStrip), o = r - a * e.rowsPerStrip;
|
|
317
|
+
n.rowOffset = e.stripOffsets.at(a) + o * t.bytesPerRow, i(n);
|
|
318
|
+
};
|
|
319
|
+
}
|
|
320
|
+
var ie = 4096;
|
|
321
|
+
function P(e, t) {
|
|
322
|
+
switch (e.kind) {
|
|
323
|
+
case "gray-1": return Math.ceil(t / 8);
|
|
324
|
+
case "gray-8": return t;
|
|
325
|
+
case "rgb": return t * 3;
|
|
326
|
+
default: return t * 4;
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
function ae(e, t) {
|
|
330
|
+
let n = 3 * t.bytesPerRow * e.height + 2 * e.stripCount, r = new ce(e.directory.reader.bytes, n), i = Math.min(e.width, ie), a = new Uint8Array(P(t, i)), o = e.differencingStride, s = new Uint8Array(4), c = {
|
|
331
|
+
bytes: a,
|
|
332
|
+
rowOffset: 0,
|
|
333
|
+
firstX: 0,
|
|
334
|
+
endX: 0
|
|
335
|
+
}, l = -1, u = 0;
|
|
336
|
+
return (n, d) => {
|
|
337
|
+
n !== u && g("Internal TIFF LZW row sequence failure"), u++;
|
|
338
|
+
let f = Math.floor(n / e.rowsPerStrip);
|
|
339
|
+
f !== l && (r.beginStrip(e.stripOffsets.at(f), e.stripByteCounts.at(f)), l = f);
|
|
340
|
+
for (let n = 0; n < e.width; n += i) {
|
|
341
|
+
let l = Math.min(e.width, n + i), u = a.subarray(0, P(t, l - n));
|
|
342
|
+
r.fill(u), o !== null && oe(u, o, s, n > 0), c.firstX = n, c.endX = l, c.rowOffset = -P(t, n), d(c);
|
|
294
343
|
}
|
|
344
|
+
(u === e.height || u % e.rowsPerStrip === 0) && r.finishStrip();
|
|
345
|
+
};
|
|
346
|
+
}
|
|
347
|
+
function oe(e, t, n, r) {
|
|
348
|
+
if (r) for (let r = 0; r < t; r++) e[r] = e[r] + n[r] & 255;
|
|
349
|
+
for (let n = t; n < e.length; n++) e[n] = e[n] + e[n - t] & 255;
|
|
350
|
+
n.set(e.subarray(e.length - t));
|
|
351
|
+
}
|
|
352
|
+
function F(e, t) {
|
|
353
|
+
return e.compression === E ? ae(e, t) : re(e, t);
|
|
354
|
+
}
|
|
355
|
+
function se(e, t) {
|
|
356
|
+
let n = e.layout, r = F(e, n), i = 0, a = (r) => I(e, n, r, i, t);
|
|
357
|
+
for (; i < e.height; i++) r(i, a);
|
|
358
|
+
}
|
|
359
|
+
function I(e, t, { bytes: n, rowOffset: r, firstX: i, endX: a }, o, s) {
|
|
360
|
+
for (let c = i; c < a; c++) {
|
|
361
|
+
let i = (o * e.width + c) * 4;
|
|
362
|
+
if (t.kind === "gray-1") {
|
|
363
|
+
let e = n[r + (c >> 3)] >> 7 - (c & 7) & 1, a = t.photometric === 0 ? e === 0 ? 255 : 0 : e === 0 ? 0 : 255;
|
|
364
|
+
s[i] = a, s[i + 1] = a, s[i + 2] = a, s[i + 3] = 255;
|
|
365
|
+
continue;
|
|
366
|
+
}
|
|
367
|
+
if (t.kind === "gray-8") {
|
|
368
|
+
let e = n[r + c], a = t.photometric === 0 ? 255 - e : e;
|
|
369
|
+
s[i] = a, s[i + 1] = a, s[i + 2] = a, s[i + 3] = 255;
|
|
370
|
+
continue;
|
|
371
|
+
}
|
|
372
|
+
if (t.kind === "rgb") {
|
|
373
|
+
let e = r + c * 3;
|
|
374
|
+
s[i] = n[e], s[i + 1] = n[e + 1], s[i + 2] = n[e + 2], s[i + 3] = 255;
|
|
375
|
+
continue;
|
|
376
|
+
}
|
|
377
|
+
if (t.kind === "rgba-associated" || t.kind === "rgba-unassociated") {
|
|
378
|
+
let e = r + c * 4, a = n[e + 3];
|
|
379
|
+
s[i] = t.kind === "rgba-associated" ? N(n[e], a) : n[e], s[i + 1] = t.kind === "rgba-associated" ? N(n[e + 1], a) : n[e + 1], s[i + 2] = t.kind === "rgba-associated" ? N(n[e + 2], a) : n[e + 2], s[i + 3] = a;
|
|
380
|
+
continue;
|
|
381
|
+
}
|
|
382
|
+
let a = r + c * 4, l = n[a + 3];
|
|
383
|
+
s[i] = M(n[a], l), s[i + 1] = M(n[a + 1], l), s[i + 2] = M(n[a + 2], l), s[i + 3] = 255;
|
|
295
384
|
}
|
|
296
385
|
}
|
|
297
|
-
function
|
|
386
|
+
function L(e) {
|
|
298
387
|
return Math.max(0, Math.min(255, Math.round(e)));
|
|
299
388
|
}
|
|
300
|
-
function
|
|
301
|
-
let
|
|
302
|
-
for (let
|
|
303
|
-
let
|
|
304
|
-
for (let e =
|
|
305
|
-
let i = e * t.width,
|
|
306
|
-
if (
|
|
307
|
-
let t =
|
|
308
|
-
d =
|
|
309
|
-
} else if (
|
|
310
|
-
let t =
|
|
311
|
-
d =
|
|
312
|
-
} else if (
|
|
313
|
-
let t =
|
|
314
|
-
d =
|
|
315
|
-
} else if (
|
|
316
|
-
let t =
|
|
317
|
-
v =
|
|
318
|
-
} else if (
|
|
319
|
-
let t =
|
|
320
|
-
v =
|
|
389
|
+
function R(e, t, { bytes: n, rowOffset: r, firstX: i, endX: a }, o, s) {
|
|
390
|
+
let c = e.layout, l = Math.floor(i * t.width / e.width), u = Math.floor((a * t.width - 1) / e.width);
|
|
391
|
+
for (let d = l; d <= u; d++) {
|
|
392
|
+
let l = d * e.width, u = (d + 1) * e.width, f = Math.max(i, Math.floor(l / t.width)), p = Math.min(a - 1, Math.floor((u - 1) / t.width)), m = 0, h = 0, g = 0, _ = 0;
|
|
393
|
+
for (let e = f; e <= p; e++) {
|
|
394
|
+
let i = e * t.width, a = (e + 1) * t.width, s = (Math.min(u, a) - Math.max(l, i)) * o, d, f, p, v = 255;
|
|
395
|
+
if (c.kind === "gray-1") {
|
|
396
|
+
let t = n[r + (e >> 3)] >> 7 - (e & 7) & 1;
|
|
397
|
+
d = c.photometric === 0 ? t === 0 ? 255 : 0 : t === 0 ? 0 : 255, f = d, p = d;
|
|
398
|
+
} else if (c.kind === "gray-8") {
|
|
399
|
+
let t = n[r + e];
|
|
400
|
+
d = c.photometric === 0 ? 255 - t : t, f = d, p = d;
|
|
401
|
+
} else if (c.kind === "rgb") {
|
|
402
|
+
let t = r + e * 3;
|
|
403
|
+
d = n[t], f = n[t + 1], p = n[t + 2];
|
|
404
|
+
} else if (c.kind === "rgba-associated") {
|
|
405
|
+
let t = r + e * 4;
|
|
406
|
+
v = n[t + 3], d = v === 0 ? 0 : n[t] * 255, f = v === 0 ? 0 : n[t + 1] * 255, p = v === 0 ? 0 : n[t + 2] * 255;
|
|
407
|
+
} else if (c.kind === "rgba-unassociated") {
|
|
408
|
+
let t = r + e * 4;
|
|
409
|
+
v = n[t + 3], d = n[t] * v, f = n[t + 1] * v, p = n[t + 2] * v;
|
|
321
410
|
} else {
|
|
322
|
-
let t =
|
|
323
|
-
d =
|
|
411
|
+
let t = r + e * 4, i = n[t + 3];
|
|
412
|
+
d = M(n[t], i), f = M(n[t + 1], i), p = M(n[t + 2], i);
|
|
324
413
|
}
|
|
325
|
-
|
|
414
|
+
c.kind !== "rgba-associated" && c.kind !== "rgba-unassociated" && (d *= 255, f *= 255, p *= 255), m += d * s, h += f * s, g += p * s, _ += v * s;
|
|
326
415
|
}
|
|
327
|
-
let
|
|
328
|
-
|
|
416
|
+
let v = d * 4;
|
|
417
|
+
s[v] += m, s[v + 1] += h, s[v + 2] += g, s[v + 3] += _;
|
|
329
418
|
}
|
|
330
419
|
}
|
|
331
|
-
function
|
|
420
|
+
function z(e, t, n, r, i) {
|
|
332
421
|
for (let a = 0; a < n; a++) {
|
|
333
422
|
let o = a * 4, s = (r * n + a) * 4, c = e[o + 3];
|
|
334
|
-
t[s] = c === 0 ? 0 :
|
|
423
|
+
t[s] = c === 0 ? 0 : L(e[o] / c), t[s + 1] = c === 0 ? 0 : L(e[o + 1] / c), t[s + 2] = c === 0 ? 0 : L(e[o + 2] / c), t[s + 3] = L(c / i);
|
|
335
424
|
}
|
|
336
425
|
}
|
|
337
|
-
function
|
|
338
|
-
let r = e.layout, i = new Float64Array(t.width * 4), a = e.width * e.height, o = -1
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
426
|
+
function B(e, t, n) {
|
|
427
|
+
let r = F(e, e.layout), i = [new Float64Array(t.width * 4), new Float64Array(t.width * 4)], a = e.width * e.height, o = -1, s = 0, c = 0, l = 0, u = 0, d = (e) => {
|
|
428
|
+
for (; o < e;) {
|
|
429
|
+
o++;
|
|
430
|
+
let e = i[o & 1];
|
|
431
|
+
z(e, n, t.width, o, a), e.fill(0);
|
|
432
|
+
}
|
|
433
|
+
}, f = (n) => {
|
|
434
|
+
for (let r = l; r <= u; r++) {
|
|
435
|
+
let a = r * e.height, o = (r + 1) * e.height;
|
|
436
|
+
R(e, t, n, Math.min(c, o) - Math.max(s, a), i[r & 1]);
|
|
437
|
+
}
|
|
438
|
+
};
|
|
439
|
+
for (let n = 0; n < e.height; n++) s = n * t.height, c = (n + 1) * t.height, l = Math.floor(s / e.height), u = Math.floor((c - 1) / e.height), (l <= o || u > l + 1) && g("Internal TIFF area-row sequence failure"), d(l - 1), r(n, f);
|
|
440
|
+
u !== t.height - 1 && g("Internal TIFF area-row coverage failure"), d(u);
|
|
441
|
+
}
|
|
442
|
+
function V(e, t, n) {
|
|
443
|
+
t.width === e.width && t.height === e.height ? se(e, n) : B(e, t, n);
|
|
444
|
+
}
|
|
445
|
+
var H = 256, U = 257, W = 258, G = 9, K = 12, q = 1 << K, ce = class {
|
|
446
|
+
workLimit;
|
|
447
|
+
prefix = new Uint16Array(q);
|
|
448
|
+
suffix = new Uint8Array(q);
|
|
449
|
+
first = new Uint8Array(q);
|
|
450
|
+
length = new Uint16Array(q);
|
|
451
|
+
pending = new Uint8Array(q);
|
|
452
|
+
pendingStart = 0;
|
|
453
|
+
pendingEnd = 0;
|
|
454
|
+
reader;
|
|
455
|
+
codeWidth = G;
|
|
456
|
+
nextCode = W;
|
|
457
|
+
previousCode = -1;
|
|
458
|
+
ended = !1;
|
|
459
|
+
work = 0;
|
|
460
|
+
constructor(e, t) {
|
|
461
|
+
this.workLimit = t, this.reader = new u(e, 0, 0, "TIFF LZW data is truncated");
|
|
462
|
+
for (let e = 0; e < 256; e++) this.suffix[e] = e, this.first[e] = e, this.length[e] = 1;
|
|
463
|
+
}
|
|
464
|
+
beginStrip(e, t) {
|
|
465
|
+
this.reader.beginStrip(e, t), this.pendingStart = 0, this.pendingEnd = 0, this.ended = !1, this.clearTable(), this.readCode() !== H && g("TIFF LZW strip must begin with ClearCode");
|
|
466
|
+
}
|
|
467
|
+
fill(e) {
|
|
468
|
+
let t = 0;
|
|
469
|
+
for (; t < e.length;) {
|
|
470
|
+
this.pendingStart === this.pendingEnd && this.decodeNextString(), this.ended && g("TIFF LZW strip ended before its declared rows");
|
|
471
|
+
let n = Math.min(e.length - t, this.pendingEnd - this.pendingStart);
|
|
472
|
+
e.set(this.pending.subarray(this.pendingStart, this.pendingStart + n), t), this.pendingStart += n, t += n;
|
|
345
473
|
}
|
|
346
474
|
}
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
function L(e, t, n) {
|
|
350
|
-
t.width === e.width && t.height === e.height ? M(e, n) : I(e, t, n);
|
|
351
|
-
}
|
|
352
|
-
var R = class {
|
|
353
|
-
bitOffset = 0;
|
|
354
|
-
constructor(e, t, n) {
|
|
355
|
-
this.bytes = e, this.byteOffset = t, this.byteLength = n;
|
|
475
|
+
finishStrip() {
|
|
476
|
+
this.pendingStart !== this.pendingEnd && g("TIFF LZW data exceeds its declared rows"), this.decodeNextString(!1);
|
|
356
477
|
}
|
|
357
|
-
|
|
358
|
-
this.
|
|
359
|
-
|
|
360
|
-
|
|
478
|
+
chargeWork(e) {
|
|
479
|
+
if (this.work += e, this.work > this.workLimit) throw new i("tiff-lzw-work", this.workLimit, this.work);
|
|
480
|
+
}
|
|
481
|
+
clearTable() {
|
|
482
|
+
this.codeWidth = G, this.nextCode = W, this.previousCode = -1;
|
|
483
|
+
}
|
|
484
|
+
readCode() {
|
|
485
|
+
let e = this.reader.readBits(this.codeWidth);
|
|
486
|
+
return this.chargeWork(1), e;
|
|
487
|
+
}
|
|
488
|
+
decodeNextString(e = !0) {
|
|
489
|
+
for (;;) {
|
|
490
|
+
this.ended && g("TIFF LZW strip ended before its declared rows");
|
|
491
|
+
let t = this.readCode();
|
|
492
|
+
if (t === H) {
|
|
493
|
+
this.clearTable();
|
|
494
|
+
continue;
|
|
495
|
+
}
|
|
496
|
+
if (t === U) {
|
|
497
|
+
this.ended = !0;
|
|
498
|
+
return;
|
|
499
|
+
}
|
|
500
|
+
this.previousCode < 0 ? t >= H && g(`Invalid TIFF LZW code: ${t}`) : this.addString(t), e || g("TIFF LZW data exceeds its declared rows"), this.expand(t), this.previousCode = t;
|
|
501
|
+
return;
|
|
502
|
+
}
|
|
503
|
+
}
|
|
504
|
+
addString(e) {
|
|
505
|
+
e > this.nextCode && g(`Invalid TIFF LZW code: ${e}`), this.nextCode >= q && g("TIFF LZW code table overflow");
|
|
506
|
+
let t = this.previousCode, n = this.nextCode;
|
|
507
|
+
this.prefix[n] = t, this.suffix[n] = e === n ? this.first[t] : this.first[e], this.first[n] = this.first[t], this.length[n] = this.length[t] + 1, this.nextCode++, this.nextCode >= (1 << this.codeWidth) - 1 && this.codeWidth < K && this.codeWidth++;
|
|
508
|
+
}
|
|
509
|
+
expand(e) {
|
|
510
|
+
let t = e, n = this.length[t];
|
|
511
|
+
this.chargeWork(n);
|
|
512
|
+
for (let e = n - 1; e >= 0; e--) this.pending[e] = this.suffix[t], t = this.prefix[t];
|
|
513
|
+
this.pendingStart = 0, this.pendingEnd = n;
|
|
361
514
|
}
|
|
362
|
-
},
|
|
515
|
+
}, J = [
|
|
363
516
|
["00000001000", 1792],
|
|
364
517
|
["00000001100", 1856],
|
|
365
518
|
["00000001101", 1920],
|
|
@@ -373,7 +526,7 @@ var R = class {
|
|
|
373
526
|
["000000011101", 2432],
|
|
374
527
|
["000000011110", 2496],
|
|
375
528
|
["000000011111", 2560]
|
|
376
|
-
],
|
|
529
|
+
], le = [
|
|
377
530
|
["00110101", 0],
|
|
378
531
|
["000111", 1],
|
|
379
532
|
["0111", 2],
|
|
@@ -465,8 +618,8 @@ var R = class {
|
|
|
465
618
|
["010011010", 1600],
|
|
466
619
|
["011000", 1664],
|
|
467
620
|
["010011011", 1728],
|
|
468
|
-
...
|
|
469
|
-
],
|
|
621
|
+
...J
|
|
622
|
+
], ue = [
|
|
470
623
|
["0000110111", 0],
|
|
471
624
|
["010", 1],
|
|
472
625
|
["11", 2],
|
|
@@ -558,14 +711,14 @@ var R = class {
|
|
|
558
711
|
["0000001011011", 1600],
|
|
559
712
|
["0000001100100", 1664],
|
|
560
713
|
["0000001100101", 1728],
|
|
561
|
-
...
|
|
714
|
+
...J
|
|
562
715
|
];
|
|
563
|
-
function
|
|
716
|
+
function Y(e) {
|
|
564
717
|
let t = /* @__PURE__ */ new Map();
|
|
565
718
|
for (let [n, r] of e) t.set(1 << n.length | Number.parseInt(n, 2), r);
|
|
566
719
|
return t;
|
|
567
720
|
}
|
|
568
|
-
var
|
|
721
|
+
var de = Y(le), fe = Y(ue), pe = new Map([
|
|
569
722
|
[3, 0],
|
|
570
723
|
[9, "horizontal"],
|
|
571
724
|
[10, -1],
|
|
@@ -576,57 +729,57 @@ var U = H(B), W = H(V), G = new Map([
|
|
|
576
729
|
[130, -3],
|
|
577
730
|
[131, 3]
|
|
578
731
|
]);
|
|
579
|
-
function
|
|
732
|
+
function me(e) {
|
|
580
733
|
let t = 0;
|
|
581
734
|
for (let n = 1; n <= 7; n++) {
|
|
582
735
|
t = t << 1 | e.readBit();
|
|
583
|
-
let r =
|
|
736
|
+
let r = pe.get(1 << n | t);
|
|
584
737
|
if (r !== void 0) return r;
|
|
585
738
|
}
|
|
586
|
-
|
|
739
|
+
g("Invalid or unsupported CCITT Group 4 two-dimensional mode");
|
|
587
740
|
}
|
|
588
|
-
function
|
|
589
|
-
let r = t ?
|
|
741
|
+
function X(e, t, n) {
|
|
742
|
+
let r = t ? fe : de, i = 0, a = Math.ceil(n / 64) + 64;
|
|
590
743
|
for (let t = 0; t < a; t++) {
|
|
591
744
|
let t = 0, a;
|
|
592
745
|
for (let n = 1; n <= 13 && (t = t << 1 | e.readBit(), a = r.get(1 << n | t), a === void 0); n++);
|
|
593
|
-
if (a === void 0 &&
|
|
746
|
+
if (a === void 0 && g("Invalid CCITT Group 4 run-length code"), i += a, i > n && g("CCITT Group 4 run exceeds the scanline width"), a < 64) return i;
|
|
594
747
|
}
|
|
595
|
-
|
|
748
|
+
g("CCITT Group 4 run-length code limit exceeded");
|
|
596
749
|
}
|
|
597
|
-
var
|
|
598
|
-
function
|
|
750
|
+
var Z = n + 1;
|
|
751
|
+
function Q(e, t) {
|
|
599
752
|
let n = e[e.length - 1];
|
|
600
|
-
n !== void 0 && n > t &&
|
|
753
|
+
n !== void 0 && n > t && g("Internal TIFF Group 4 changing-element order failure"), n === t ? e.pop() : (e.length >= Z && g("CCITT Group 4 changing-element limit exceeded"), e.push(t));
|
|
601
754
|
}
|
|
602
|
-
function
|
|
755
|
+
function he(e, t, n, r, i, a, o) {
|
|
603
756
|
let s = i ? n : n + 1;
|
|
604
757
|
for (; a.index < e.length && (o && o.referenceProbeCount++, !(e[a.index] >= s));) a.index++;
|
|
605
758
|
let c = a.index;
|
|
606
759
|
return c < e.length && (c + 1 & 1) != (r ^ 1) && c++, [e[c] ?? t, e[c + 1] ?? t];
|
|
607
760
|
}
|
|
608
|
-
function
|
|
761
|
+
function ge(e, t, n, r, i) {
|
|
609
762
|
n.length = 0;
|
|
610
763
|
let a = 0, o = 0, s = !0, c = { index: 0 }, l = r * 4 + 32;
|
|
611
764
|
for (let u = 0; a < r; u++) {
|
|
612
|
-
u >= l &&
|
|
613
|
-
let d =
|
|
765
|
+
u >= l && g("CCITT Group 4 scanline operation limit exceeded"), i && i.modeCount++;
|
|
766
|
+
let d = me(e);
|
|
614
767
|
if (d === "horizontal") {
|
|
615
|
-
let t =
|
|
616
|
-
c <= a &&
|
|
768
|
+
let t = X(e, o === 1, r - a), i = a + t, c = i + X(e, o === 0, r - i);
|
|
769
|
+
c <= a && g("Invalid CCITT Group 4 horizontal mode with no progress"), Q(n, i), Q(n, c), a = c, s = !1;
|
|
617
770
|
continue;
|
|
618
771
|
}
|
|
619
|
-
let [f, p] =
|
|
772
|
+
let [f, p] = he(t, r, a, o, s, c, i);
|
|
620
773
|
if (d === "pass") {
|
|
621
|
-
p <= a &&
|
|
774
|
+
p <= a && g("Invalid CCITT Group 4 pass mode with no progress"), a = p, s = !1;
|
|
622
775
|
continue;
|
|
623
776
|
}
|
|
624
777
|
let m = f + d;
|
|
625
|
-
(m < a || m > r) &&
|
|
778
|
+
(m < a || m > r) && g("Invalid CCITT Group 4 vertical mode position"), Q(n, m), a = m, o ^= 1, s = !1;
|
|
626
779
|
}
|
|
627
|
-
n[n.length - 1] !== r && (n.length >=
|
|
780
|
+
n[n.length - 1] !== r && (n.length >= Z && g("CCITT Group 4 changing-element limit exceeded"), n.push(r));
|
|
628
781
|
}
|
|
629
|
-
function
|
|
782
|
+
function $(e, t, n, r, i) {
|
|
630
783
|
let a = 0;
|
|
631
784
|
for (let o = 0; o < e.length; o++) {
|
|
632
785
|
let s = e[o], c = o & 1, l = i === 0 ? c === 0 ? 255 : 0 : c === 0 ? 0 : 255;
|
|
@@ -637,74 +790,74 @@ function Q(e, t, n, r, i) {
|
|
|
637
790
|
a = s;
|
|
638
791
|
}
|
|
639
792
|
}
|
|
640
|
-
function
|
|
793
|
+
function _e(e, t, n, r, i, a, o) {
|
|
641
794
|
let s = 0, c = n[0] * t.width;
|
|
642
795
|
for (let l = 0; l < t.width; l++) {
|
|
643
796
|
let u = l * e.width, d = (l + 1) * e.width, f = u;
|
|
644
797
|
for (; f < d;) {
|
|
645
798
|
for (o && o.areaSegmentCount++; c <= f && s + 1 < n.length;) s++, c = n[s] * t.width;
|
|
646
799
|
let e = Math.min(d, c);
|
|
647
|
-
e <= f &&
|
|
648
|
-
let u = s & 1, p = r === 0 ? u === 0 ? 255 : 0 : u === 0 ? 0 : 255, m = (e - f) * i,
|
|
649
|
-
a[
|
|
800
|
+
e <= f && g("Internal TIFF Group 4 area-run coverage failure");
|
|
801
|
+
let u = s & 1, p = r === 0 ? u === 0 ? 255 : 0 : u === 0 ? 0 : 255, m = (e - f) * i, h = l * 4, _ = p * 255 * m;
|
|
802
|
+
a[h] += _, a[h + 1] += _, a[h + 2] += _, a[h + 3] += 255 * m, f = e;
|
|
650
803
|
}
|
|
651
804
|
}
|
|
652
805
|
}
|
|
653
|
-
function
|
|
806
|
+
function ve(e, t, n, r) {
|
|
654
807
|
let i = e.layout, a = [e.width], o = [], s = t.width !== e.width || t.height !== e.height ? new Float64Array(t.width * 4) : null, c = e.width * e.height, l = -1;
|
|
655
|
-
for (let
|
|
808
|
+
for (let d = 0; d < e.stripCount; d++) {
|
|
656
809
|
a.length = 1, a[0] = e.width;
|
|
657
|
-
let
|
|
658
|
-
for (let u = 0; u <
|
|
659
|
-
let
|
|
660
|
-
if (
|
|
810
|
+
let f = d * e.rowsPerStrip, p = Math.min(e.rowsPerStrip, e.height - f), m = new u(e.directory.reader.bytes, e.stripOffsets.at(d), e.stripByteCounts.at(d), "CCITT Group 4 data is truncated");
|
|
811
|
+
for (let u = 0; u < p; u++) {
|
|
812
|
+
let d = f + u;
|
|
813
|
+
if (ge(m, a, o, e.width, r), !s) $(o, n, e.width, d, i.photometric);
|
|
661
814
|
else {
|
|
662
|
-
let a =
|
|
663
|
-
for (let
|
|
664
|
-
|
|
665
|
-
let
|
|
666
|
-
|
|
815
|
+
let a = d * t.height, u = (d + 1) * t.height, f = Math.floor(a / e.height), p = Math.floor((u - 1) / e.height);
|
|
816
|
+
for (let d = f; d <= p; d++) {
|
|
817
|
+
d !== l && (l >= 0 && (z(s, n, t.width, l, c), s.fill(0)), d !== l + 1 && g("Internal TIFF Group 4 area-row sequence failure"), l = d);
|
|
818
|
+
let f = d * e.height, p = (d + 1) * e.height, m = Math.min(u, p) - Math.max(a, f);
|
|
819
|
+
_e(e, t, o, i.photometric, m, s, r);
|
|
667
820
|
}
|
|
668
821
|
}
|
|
669
822
|
[a, o] = [o, a];
|
|
670
823
|
}
|
|
671
824
|
}
|
|
672
|
-
s && (l !== t.height - 1 &&
|
|
825
|
+
s && (l !== t.height - 1 && g("Internal TIFF Group 4 area-row coverage failure"), z(s, n, t.width, l, c));
|
|
673
826
|
}
|
|
674
|
-
function
|
|
675
|
-
let r =
|
|
827
|
+
function ye(e, t, n) {
|
|
828
|
+
let r = k(e);
|
|
676
829
|
if (!r) return null;
|
|
677
|
-
let i =
|
|
678
|
-
return r.layout.kind === "group4" ?
|
|
830
|
+
let i = j(r.width, r.height, t), a = new Uint8ClampedArray(i.pixels * 4);
|
|
831
|
+
return r.layout.kind === "group4" ? ve(r, i, a, n) : V(r, i, a), {
|
|
679
832
|
width: i.width,
|
|
680
833
|
height: i.height,
|
|
681
834
|
data: a
|
|
682
835
|
};
|
|
683
836
|
}
|
|
684
|
-
function
|
|
685
|
-
return
|
|
837
|
+
function be(e, t = {}) {
|
|
838
|
+
return ye(e, t);
|
|
686
839
|
}
|
|
687
|
-
async function
|
|
688
|
-
let n =
|
|
840
|
+
async function xe(e, t = {}) {
|
|
841
|
+
let n = be(e, t);
|
|
689
842
|
if (!n) return null;
|
|
690
|
-
typeof ImageData != "function" &&
|
|
843
|
+
typeof ImageData != "function" && g("TIFF ImageData construction is unavailable");
|
|
691
844
|
let r;
|
|
692
845
|
try {
|
|
693
846
|
r = new ImageData(n.data, n.width, n.height);
|
|
694
847
|
} catch (e) {
|
|
695
|
-
|
|
848
|
+
g("TIFF ImageData construction failed", e);
|
|
696
849
|
}
|
|
697
|
-
typeof createImageBitmap != "function" &&
|
|
850
|
+
typeof createImageBitmap != "function" && g("TIFF ImageBitmap creation is unavailable");
|
|
698
851
|
let i;
|
|
699
852
|
try {
|
|
700
853
|
i = await createImageBitmap(r);
|
|
701
854
|
} catch (e) {
|
|
702
|
-
|
|
855
|
+
g("TIFF ImageBitmap creation failed", e);
|
|
703
856
|
}
|
|
704
|
-
return i ||
|
|
857
|
+
return i || g("TIFF ImageBitmap creation returned no bitmap"), i;
|
|
705
858
|
}
|
|
706
859
|
//#endregion
|
|
707
860
|
//#region src/tiff.ts
|
|
708
|
-
var
|
|
861
|
+
var Se = l({ render: xe }, "tiff");
|
|
709
862
|
//#endregion
|
|
710
|
-
export {
|
|
863
|
+
export { s as TiffDecodeError, a as isTiffDecodeError, Se as tiff };
|