pdf-parser.js 4.8.11 → 4.8.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/annotations.cjs +16 -16
- package/dist/annotations.js +16 -16
- package/dist/font-style.cjs +9 -11
- package/dist/font-style.js +9 -11
- package/dist/image/jp2-boxes.cjs +12 -15
- package/dist/image/jp2-boxes.js +12 -15
- package/dist/image/jpeg2000-codestream.cjs +13 -12
- package/dist/image/jpeg2000-codestream.d.cts +11 -1
- package/dist/image/jpeg2000-codestream.d.ts +11 -1
- package/dist/image/jpeg2000-codestream.js +13 -13
- package/dist/image/jpeg2000-dwt.cjs +23 -17
- package/dist/image/jpeg2000-dwt.d.cts +13 -1
- package/dist/image/jpeg2000-dwt.d.ts +13 -1
- package/dist/image/jpeg2000-dwt.js +18 -18
- package/dist/math-stretch.cjs +0 -1
- package/dist/math-stretch.js +0 -1
- package/dist/write.cjs +1 -5
- package/dist/write.js +2 -6
- package/dist/xmp.cjs +3 -3
- package/dist/xmp.js +3 -3
- package/package.json +1 -1
package/dist/annotations.cjs
CHANGED
|
@@ -5,21 +5,21 @@ const require_pdf_text = require("./pdf-text.cjs");
|
|
|
5
5
|
const require_serialize = require("./serialize.cjs");
|
|
6
6
|
const require_matrix = require("./matrix.cjs");
|
|
7
7
|
//#region src/annotations.ts
|
|
8
|
-
const SEMANTIC_SUBTYPES = /* @__PURE__ */ new Set([
|
|
9
|
-
"Text",
|
|
10
|
-
"FreeText",
|
|
11
|
-
"Highlight",
|
|
12
|
-
"Underline",
|
|
13
|
-
"StrikeOut",
|
|
14
|
-
"Squiggly"
|
|
15
|
-
]);
|
|
16
|
-
const OWNED_ELSEWHERE_SUBTYPES = /* @__PURE__ */ new Set([
|
|
17
|
-
"Link",
|
|
18
|
-
"FileAttachment",
|
|
19
|
-
"Widget",
|
|
20
|
-
"Popup"
|
|
21
|
-
]);
|
|
22
8
|
function readPageAnnotations(page, pageMatrix, resolver, sink) {
|
|
9
|
+
const semanticSubtypes = /* @__PURE__ */ new Set([
|
|
10
|
+
"Text",
|
|
11
|
+
"FreeText",
|
|
12
|
+
"Highlight",
|
|
13
|
+
"Underline",
|
|
14
|
+
"StrikeOut",
|
|
15
|
+
"Squiggly"
|
|
16
|
+
]);
|
|
17
|
+
const ownedElsewhereSubtypes = /* @__PURE__ */ new Set([
|
|
18
|
+
"Link",
|
|
19
|
+
"FileAttachment",
|
|
20
|
+
"Widget",
|
|
21
|
+
"Popup"
|
|
22
|
+
]);
|
|
23
23
|
const annotsArr = require_objects.asArray(require_objects.dictGet(page, "Annots"));
|
|
24
24
|
if (annotsArr === void 0) return [];
|
|
25
25
|
const annotations = [];
|
|
@@ -27,7 +27,7 @@ function readPageAnnotations(page, pageMatrix, resolver, sink) {
|
|
|
27
27
|
const annot = resolver.resolveDict(annotRef);
|
|
28
28
|
if (annot === void 0) continue;
|
|
29
29
|
const subtype = require_objects.asName(require_objects.dictGet(annot, "Subtype"));
|
|
30
|
-
if (subtype === void 0 ||
|
|
30
|
+
if (subtype === void 0 || ownedElsewhereSubtypes.has(subtype)) continue;
|
|
31
31
|
if (subtype === "Text" && annotString(annot, "T") === "documents.js:notes") continue;
|
|
32
32
|
const rectArr = require_objects.asArray(require_objects.dictGet(annot, "Rect"));
|
|
33
33
|
if (rectArr === void 0) {
|
|
@@ -62,7 +62,7 @@ function readPageAnnotations(page, pageMatrix, resolver, sink) {
|
|
|
62
62
|
...contents !== void 0 ? { contents } : {},
|
|
63
63
|
...author !== void 0 ? { author } : {},
|
|
64
64
|
...modifiedIso !== void 0 ? { modifiedIso } : {},
|
|
65
|
-
...
|
|
65
|
+
...semanticSubtypes.has(subtype) ? markupFields(annot, pageMatrix) : { source: {
|
|
66
66
|
format: "pdf",
|
|
67
67
|
xml: require_serialize.serializeObjectToText(annot)
|
|
68
68
|
} }
|
package/dist/annotations.js
CHANGED
|
@@ -4,21 +4,21 @@ import { decodePdfString, parsePdfDate } from "./pdf-text.js";
|
|
|
4
4
|
import { serializeObjectToText } from "./serialize.js";
|
|
5
5
|
import { applyMatrix } from "./matrix.js";
|
|
6
6
|
//#region src/annotations.ts
|
|
7
|
-
const SEMANTIC_SUBTYPES = /* @__PURE__ */ new Set([
|
|
8
|
-
"Text",
|
|
9
|
-
"FreeText",
|
|
10
|
-
"Highlight",
|
|
11
|
-
"Underline",
|
|
12
|
-
"StrikeOut",
|
|
13
|
-
"Squiggly"
|
|
14
|
-
]);
|
|
15
|
-
const OWNED_ELSEWHERE_SUBTYPES = /* @__PURE__ */ new Set([
|
|
16
|
-
"Link",
|
|
17
|
-
"FileAttachment",
|
|
18
|
-
"Widget",
|
|
19
|
-
"Popup"
|
|
20
|
-
]);
|
|
21
7
|
function readPageAnnotations(page, pageMatrix, resolver, sink) {
|
|
8
|
+
const semanticSubtypes = /* @__PURE__ */ new Set([
|
|
9
|
+
"Text",
|
|
10
|
+
"FreeText",
|
|
11
|
+
"Highlight",
|
|
12
|
+
"Underline",
|
|
13
|
+
"StrikeOut",
|
|
14
|
+
"Squiggly"
|
|
15
|
+
]);
|
|
16
|
+
const ownedElsewhereSubtypes = /* @__PURE__ */ new Set([
|
|
17
|
+
"Link",
|
|
18
|
+
"FileAttachment",
|
|
19
|
+
"Widget",
|
|
20
|
+
"Popup"
|
|
21
|
+
]);
|
|
22
22
|
const annotsArr = asArray(dictGet(page, "Annots"));
|
|
23
23
|
if (annotsArr === void 0) return [];
|
|
24
24
|
const annotations = [];
|
|
@@ -26,7 +26,7 @@ function readPageAnnotations(page, pageMatrix, resolver, sink) {
|
|
|
26
26
|
const annot = resolver.resolveDict(annotRef);
|
|
27
27
|
if (annot === void 0) continue;
|
|
28
28
|
const subtype = asName(dictGet(annot, "Subtype"));
|
|
29
|
-
if (subtype === void 0 ||
|
|
29
|
+
if (subtype === void 0 || ownedElsewhereSubtypes.has(subtype)) continue;
|
|
30
30
|
if (subtype === "Text" && annotString(annot, "T") === "documents.js:notes") continue;
|
|
31
31
|
const rectArr = asArray(dictGet(annot, "Rect"));
|
|
32
32
|
if (rectArr === void 0) {
|
|
@@ -61,7 +61,7 @@ function readPageAnnotations(page, pageMatrix, resolver, sink) {
|
|
|
61
61
|
...contents !== void 0 ? { contents } : {},
|
|
62
62
|
...author !== void 0 ? { author } : {},
|
|
63
63
|
...modifiedIso !== void 0 ? { modifiedIso } : {},
|
|
64
|
-
...
|
|
64
|
+
...semanticSubtypes.has(subtype) ? markupFields(annot, pageMatrix) : { source: {
|
|
65
65
|
format: "pdf",
|
|
66
66
|
xml: serializeObjectToText(annot)
|
|
67
67
|
} }
|
package/dist/font-style.cjs
CHANGED
|
@@ -1,16 +1,14 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
2
|
//#region src/font-style.ts
|
|
3
|
-
const SUBSET_TAG_PATTERN = /^[A-Z]{6}\+/;
|
|
4
|
-
const KNOWN_STYLE_SUFFIXES = [
|
|
5
|
-
"BoldItalic",
|
|
6
|
-
"BoldOblique",
|
|
7
|
-
"Bold",
|
|
8
|
-
"Italic",
|
|
9
|
-
"Oblique",
|
|
10
|
-
"Regular"
|
|
11
|
-
];
|
|
12
3
|
function stripStyleSuffix(name) {
|
|
13
|
-
for (const suffix of
|
|
4
|
+
for (const suffix of [
|
|
5
|
+
"BoldItalic",
|
|
6
|
+
"BoldOblique",
|
|
7
|
+
"Bold",
|
|
8
|
+
"Italic",
|
|
9
|
+
"Oblique",
|
|
10
|
+
"Regular"
|
|
11
|
+
]) {
|
|
14
12
|
const commaPattern = new RegExp(`,${suffix}$`, "i");
|
|
15
13
|
const hyphenPattern = new RegExp(`-${suffix}$`, "i");
|
|
16
14
|
if (commaPattern.test(name)) return name.replace(commaPattern, "");
|
|
@@ -19,7 +17,7 @@ function stripStyleSuffix(name) {
|
|
|
19
17
|
return name;
|
|
20
18
|
}
|
|
21
19
|
function styleFromBaseFontName(baseFont, flags) {
|
|
22
|
-
const withoutSubset = baseFont.replace(
|
|
20
|
+
const withoutSubset = baseFont.replace(/^[A-Z]{6}\+/, "");
|
|
23
21
|
const lower = withoutSubset.toLowerCase();
|
|
24
22
|
const nameBold = lower.includes("bold");
|
|
25
23
|
const nameItalic = /italic|oblique/.test(lower);
|
package/dist/font-style.js
CHANGED
|
@@ -1,15 +1,13 @@
|
|
|
1
1
|
//#region src/font-style.ts
|
|
2
|
-
const SUBSET_TAG_PATTERN = /^[A-Z]{6}\+/;
|
|
3
|
-
const KNOWN_STYLE_SUFFIXES = [
|
|
4
|
-
"BoldItalic",
|
|
5
|
-
"BoldOblique",
|
|
6
|
-
"Bold",
|
|
7
|
-
"Italic",
|
|
8
|
-
"Oblique",
|
|
9
|
-
"Regular"
|
|
10
|
-
];
|
|
11
2
|
function stripStyleSuffix(name) {
|
|
12
|
-
for (const suffix of
|
|
3
|
+
for (const suffix of [
|
|
4
|
+
"BoldItalic",
|
|
5
|
+
"BoldOblique",
|
|
6
|
+
"Bold",
|
|
7
|
+
"Italic",
|
|
8
|
+
"Oblique",
|
|
9
|
+
"Regular"
|
|
10
|
+
]) {
|
|
13
11
|
const commaPattern = new RegExp(`,${suffix}$`, "i");
|
|
14
12
|
const hyphenPattern = new RegExp(`-${suffix}$`, "i");
|
|
15
13
|
if (commaPattern.test(name)) return name.replace(commaPattern, "");
|
|
@@ -18,7 +16,7 @@ function stripStyleSuffix(name) {
|
|
|
18
16
|
return name;
|
|
19
17
|
}
|
|
20
18
|
function styleFromBaseFontName(baseFont, flags) {
|
|
21
|
-
const withoutSubset = baseFont.replace(
|
|
19
|
+
const withoutSubset = baseFont.replace(/^[A-Z]{6}\+/, "");
|
|
22
20
|
const lower = withoutSubset.toLowerCase();
|
|
23
21
|
const nameBold = lower.includes("bold");
|
|
24
22
|
const nameItalic = /italic|oblique/.test(lower);
|
package/dist/image/jp2-boxes.cjs
CHANGED
|
@@ -12,17 +12,8 @@ const BOX_PALETTE = 1885564018;
|
|
|
12
12
|
const BOX_COMPONENT_MAPPING = 1668112752;
|
|
13
13
|
const BOX_CHANNEL_DEFINITION = 1667523942;
|
|
14
14
|
const BOX_CONTIGUOUS_CODESTREAM = 1785737827;
|
|
15
|
-
const ENUMERATED_COLOUR_SPACES = /* @__PURE__ */ new Map([
|
|
16
|
-
[12, "cmyk"],
|
|
17
|
-
[14, "cielab"],
|
|
18
|
-
[16, "srgb"],
|
|
19
|
-
[17, "greyscale"],
|
|
20
|
-
[18, "sycc"],
|
|
21
|
-
[20, "e-srgb"],
|
|
22
|
-
[24, "rommrgb"]
|
|
23
|
-
]);
|
|
24
15
|
function looksLikeBareCodestream(data) {
|
|
25
|
-
return data
|
|
16
|
+
return data[0] === 255 && data[1] === 79 && data[2] === 255 && data[3] === 81;
|
|
26
17
|
}
|
|
27
18
|
function readUint32(data, offset) {
|
|
28
19
|
const b0 = data[offset];
|
|
@@ -73,7 +64,6 @@ function readImageHeader(data, start, end) {
|
|
|
73
64
|
};
|
|
74
65
|
}
|
|
75
66
|
function readChannelDefinitions(data, start, end) {
|
|
76
|
-
if (end - start < 2) return [];
|
|
77
67
|
const count = (data[start] ?? 0) << 8 | (data[start + 1] ?? 0);
|
|
78
68
|
const definitions = [];
|
|
79
69
|
for (let i = 0; i < count; i++) {
|
|
@@ -91,7 +81,7 @@ function readJp2HeaderBox(data, start, end, into) {
|
|
|
91
81
|
let offset = start;
|
|
92
82
|
for (;;) {
|
|
93
83
|
const box = readBox(data, offset, end);
|
|
94
|
-
if (box === void 0
|
|
84
|
+
if (box === void 0) return;
|
|
95
85
|
if (box.type === BOX_IMAGE_HEADER) into.imageHeader = readImageHeader(data, box.payloadStart, box.payloadEnd);
|
|
96
86
|
else if (box.type === BOX_COLOUR_SPECIFICATION && into.colourSpace === void 0 && into.iccProfile === void 0) readColourSpecification(data, box.payloadStart, box.payloadEnd, into);
|
|
97
87
|
else if (box.type === BOX_PALETTE || box.type === BOX_COMPONENT_MAPPING) into.hasPalette = true;
|
|
@@ -100,10 +90,17 @@ function readJp2HeaderBox(data, start, end, into) {
|
|
|
100
90
|
}
|
|
101
91
|
}
|
|
102
92
|
function readColourSpecification(data, start, end, into) {
|
|
103
|
-
if (end - start < 3) return;
|
|
104
93
|
const method = data[start] ?? 0;
|
|
105
94
|
if (method === 1) {
|
|
106
|
-
if (end - start >= 7) into.colourSpace =
|
|
95
|
+
if (end - start >= 7) into.colourSpace = (/* @__PURE__ */ new Map([
|
|
96
|
+
[12, "cmyk"],
|
|
97
|
+
[14, "cielab"],
|
|
98
|
+
[16, "srgb"],
|
|
99
|
+
[17, "greyscale"],
|
|
100
|
+
[18, "sycc"],
|
|
101
|
+
[20, "e-srgb"],
|
|
102
|
+
[24, "rommrgb"]
|
|
103
|
+
])).get(readUint32(data, start + 3));
|
|
107
104
|
return;
|
|
108
105
|
}
|
|
109
106
|
if (method === 2 && end - start > 3) into.iccProfile = data.subarray(start + 3, end);
|
|
@@ -123,7 +120,7 @@ function parseJp2Container(data) {
|
|
|
123
120
|
let sawSignature = false;
|
|
124
121
|
for (;;) {
|
|
125
122
|
const box = readBox(data, offset, data.length);
|
|
126
|
-
if (box === void 0
|
|
123
|
+
if (box === void 0) break;
|
|
127
124
|
if (box.type === BOX_SIGNATURE) sawSignature = true;
|
|
128
125
|
else if (box.type === BOX_JP2_HEADER) readJp2HeaderBox(data, box.payloadStart, box.payloadEnd, contents);
|
|
129
126
|
else if (box.type === BOX_CONTIGUOUS_CODESTREAM && codestream === void 0) codestream = data.subarray(box.payloadStart, box.payloadEnd);
|
package/dist/image/jp2-boxes.js
CHANGED
|
@@ -11,17 +11,8 @@ const BOX_PALETTE = 1885564018;
|
|
|
11
11
|
const BOX_COMPONENT_MAPPING = 1668112752;
|
|
12
12
|
const BOX_CHANNEL_DEFINITION = 1667523942;
|
|
13
13
|
const BOX_CONTIGUOUS_CODESTREAM = 1785737827;
|
|
14
|
-
const ENUMERATED_COLOUR_SPACES = /* @__PURE__ */ new Map([
|
|
15
|
-
[12, "cmyk"],
|
|
16
|
-
[14, "cielab"],
|
|
17
|
-
[16, "srgb"],
|
|
18
|
-
[17, "greyscale"],
|
|
19
|
-
[18, "sycc"],
|
|
20
|
-
[20, "e-srgb"],
|
|
21
|
-
[24, "rommrgb"]
|
|
22
|
-
]);
|
|
23
14
|
function looksLikeBareCodestream(data) {
|
|
24
|
-
return data
|
|
15
|
+
return data[0] === 255 && data[1] === 79 && data[2] === 255 && data[3] === 81;
|
|
25
16
|
}
|
|
26
17
|
function readUint32(data, offset) {
|
|
27
18
|
const b0 = data[offset];
|
|
@@ -72,7 +63,6 @@ function readImageHeader(data, start, end) {
|
|
|
72
63
|
};
|
|
73
64
|
}
|
|
74
65
|
function readChannelDefinitions(data, start, end) {
|
|
75
|
-
if (end - start < 2) return [];
|
|
76
66
|
const count = (data[start] ?? 0) << 8 | (data[start + 1] ?? 0);
|
|
77
67
|
const definitions = [];
|
|
78
68
|
for (let i = 0; i < count; i++) {
|
|
@@ -90,7 +80,7 @@ function readJp2HeaderBox(data, start, end, into) {
|
|
|
90
80
|
let offset = start;
|
|
91
81
|
for (;;) {
|
|
92
82
|
const box = readBox(data, offset, end);
|
|
93
|
-
if (box === void 0
|
|
83
|
+
if (box === void 0) return;
|
|
94
84
|
if (box.type === BOX_IMAGE_HEADER) into.imageHeader = readImageHeader(data, box.payloadStart, box.payloadEnd);
|
|
95
85
|
else if (box.type === BOX_COLOUR_SPECIFICATION && into.colourSpace === void 0 && into.iccProfile === void 0) readColourSpecification(data, box.payloadStart, box.payloadEnd, into);
|
|
96
86
|
else if (box.type === BOX_PALETTE || box.type === BOX_COMPONENT_MAPPING) into.hasPalette = true;
|
|
@@ -99,10 +89,17 @@ function readJp2HeaderBox(data, start, end, into) {
|
|
|
99
89
|
}
|
|
100
90
|
}
|
|
101
91
|
function readColourSpecification(data, start, end, into) {
|
|
102
|
-
if (end - start < 3) return;
|
|
103
92
|
const method = data[start] ?? 0;
|
|
104
93
|
if (method === 1) {
|
|
105
|
-
if (end - start >= 7) into.colourSpace =
|
|
94
|
+
if (end - start >= 7) into.colourSpace = (/* @__PURE__ */ new Map([
|
|
95
|
+
[12, "cmyk"],
|
|
96
|
+
[14, "cielab"],
|
|
97
|
+
[16, "srgb"],
|
|
98
|
+
[17, "greyscale"],
|
|
99
|
+
[18, "sycc"],
|
|
100
|
+
[20, "e-srgb"],
|
|
101
|
+
[24, "rommrgb"]
|
|
102
|
+
])).get(readUint32(data, start + 3));
|
|
106
103
|
return;
|
|
107
104
|
}
|
|
108
105
|
if (method === 2 && end - start > 3) into.iccProfile = data.subarray(start + 3, end);
|
|
@@ -122,7 +119,7 @@ function parseJp2Container(data) {
|
|
|
122
119
|
let sawSignature = false;
|
|
123
120
|
for (;;) {
|
|
124
121
|
const box = readBox(data, offset, data.length);
|
|
125
|
-
if (box === void 0
|
|
122
|
+
if (box === void 0) break;
|
|
126
123
|
if (box.type === BOX_SIGNATURE) sawSignature = true;
|
|
127
124
|
else if (box.type === BOX_JP2_HEADER) readJp2HeaderBox(data, box.payloadStart, box.payloadEnd, contents);
|
|
128
125
|
else if (box.type === BOX_CONTIGUOUS_CODESTREAM && codestream === void 0) codestream = data.subarray(box.payloadStart, box.payloadEnd);
|
|
@@ -15,13 +15,6 @@ const MARKER_COM = 65380;
|
|
|
15
15
|
const MARKER_SOT = 65424;
|
|
16
16
|
const MARKER_SOD = 65427;
|
|
17
17
|
const MARKER_EOC = 65497;
|
|
18
|
-
const PROGRESSION_ORDERS = [
|
|
19
|
-
"LRCP",
|
|
20
|
-
"RLCP",
|
|
21
|
-
"RPCL",
|
|
22
|
-
"PCRL",
|
|
23
|
-
"CPRL"
|
|
24
|
-
];
|
|
25
18
|
var MarkerCursor = class {
|
|
26
19
|
data;
|
|
27
20
|
position;
|
|
@@ -96,7 +89,7 @@ function readCodingStyleParameters(cursor, explicitPrecincts) {
|
|
|
96
89
|
const codeBlockStyle = cursor.uint8();
|
|
97
90
|
const transformCode = cursor.uint8();
|
|
98
91
|
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
|
|
92
|
+
if (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
93
|
const precinctSizes = [];
|
|
101
94
|
if (explicitPrecincts) for (let r = 0; r <= decompositionLevels; r++) {
|
|
102
95
|
const packed = cursor.uint8();
|
|
@@ -119,8 +112,15 @@ function readCodingStyleParameters(cursor, explicitPrecincts) {
|
|
|
119
112
|
};
|
|
120
113
|
}
|
|
121
114
|
function readCodingDefaults(cursor) {
|
|
115
|
+
const progressionOrders = [
|
|
116
|
+
"LRCP",
|
|
117
|
+
"RLCP",
|
|
118
|
+
"RPCL",
|
|
119
|
+
"PCRL",
|
|
120
|
+
"CPRL"
|
|
121
|
+
];
|
|
122
122
|
const scod = cursor.uint8();
|
|
123
|
-
const progressionOrder =
|
|
123
|
+
const progressionOrder = progressionOrders[cursor.uint8()];
|
|
124
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
125
|
const layers = cursor.uint16();
|
|
126
126
|
if (layers === 0) throw new require_image_jpeg2000_errors.Jpeg2000ParseError("COD declares zero quality layers");
|
|
@@ -291,7 +291,7 @@ function readTilePart(cursor, componentCount, tileParts, comments) {
|
|
|
291
291
|
const declaredEnd = psot === 0 ? cursor.data.length : sotStart + psot;
|
|
292
292
|
const dataEnd = Math.min(declaredEnd, cursor.data.length);
|
|
293
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,
|
|
294
|
+
const trimmedEnd = trimTrailingEoc(cursor.data, dataEnd);
|
|
295
295
|
tileParts.push({
|
|
296
296
|
tileIndex,
|
|
297
297
|
partIndex,
|
|
@@ -301,9 +301,10 @@ function readTilePart(cursor, componentCount, tileParts, comments) {
|
|
|
301
301
|
});
|
|
302
302
|
cursor.position = dataEnd;
|
|
303
303
|
}
|
|
304
|
-
function trimTrailingEoc(data,
|
|
305
|
-
if (
|
|
304
|
+
function trimTrailingEoc(data, end) {
|
|
305
|
+
if (data[end - 2] === 255 && data[end - 1] === 217) return end - 2;
|
|
306
306
|
return end;
|
|
307
307
|
}
|
|
308
308
|
//#endregion
|
|
309
|
+
exports.MarkerCursor = MarkerCursor;
|
|
309
310
|
exports.parseJpeg2000Codestream = parseJpeg2000Codestream;
|
|
@@ -73,6 +73,16 @@ interface Jpeg2000Codestream {
|
|
|
73
73
|
readonly numTilesHigh: number;
|
|
74
74
|
readonly truncated: boolean;
|
|
75
75
|
}
|
|
76
|
+
declare class MarkerCursor {
|
|
77
|
+
readonly data: Uint8Array<ArrayBuffer>;
|
|
78
|
+
position: number;
|
|
79
|
+
constructor(data: Uint8Array<ArrayBuffer>, start?: number);
|
|
80
|
+
get remaining(): number;
|
|
81
|
+
uint8(): number;
|
|
82
|
+
uint16(): number;
|
|
83
|
+
uint32(): number;
|
|
84
|
+
bytes(length: number): Uint8Array<ArrayBuffer>;
|
|
85
|
+
}
|
|
76
86
|
declare function parseJpeg2000Codestream(data: Uint8Array<ArrayBuffer>): Jpeg2000Codestream;
|
|
77
87
|
//#endregion
|
|
78
|
-
export { Jpeg2000Codestream, Jpeg2000CodingDefaults, Jpeg2000CodingStyle, Jpeg2000ComponentSize, Jpeg2000HeaderOverrides, Jpeg2000ImageSize, Jpeg2000PrecinctSize, Jpeg2000ProgressionOrder, Jpeg2000Quantization, Jpeg2000QuantizationStyle, Jpeg2000StepSize, Jpeg2000TilePart, Jpeg2000Transform, parseJpeg2000Codestream };
|
|
88
|
+
export { Jpeg2000Codestream, Jpeg2000CodingDefaults, Jpeg2000CodingStyle, Jpeg2000ComponentSize, Jpeg2000HeaderOverrides, Jpeg2000ImageSize, Jpeg2000PrecinctSize, Jpeg2000ProgressionOrder, Jpeg2000Quantization, Jpeg2000QuantizationStyle, Jpeg2000StepSize, Jpeg2000TilePart, Jpeg2000Transform, MarkerCursor, parseJpeg2000Codestream };
|
|
@@ -73,6 +73,16 @@ interface Jpeg2000Codestream {
|
|
|
73
73
|
readonly numTilesHigh: number;
|
|
74
74
|
readonly truncated: boolean;
|
|
75
75
|
}
|
|
76
|
+
declare class MarkerCursor {
|
|
77
|
+
readonly data: Uint8Array<ArrayBuffer>;
|
|
78
|
+
position: number;
|
|
79
|
+
constructor(data: Uint8Array<ArrayBuffer>, start?: number);
|
|
80
|
+
get remaining(): number;
|
|
81
|
+
uint8(): number;
|
|
82
|
+
uint16(): number;
|
|
83
|
+
uint32(): number;
|
|
84
|
+
bytes(length: number): Uint8Array<ArrayBuffer>;
|
|
85
|
+
}
|
|
76
86
|
declare function parseJpeg2000Codestream(data: Uint8Array<ArrayBuffer>): Jpeg2000Codestream;
|
|
77
87
|
//#endregion
|
|
78
|
-
export { Jpeg2000Codestream, Jpeg2000CodingDefaults, Jpeg2000CodingStyle, Jpeg2000ComponentSize, Jpeg2000HeaderOverrides, Jpeg2000ImageSize, Jpeg2000PrecinctSize, Jpeg2000ProgressionOrder, Jpeg2000Quantization, Jpeg2000QuantizationStyle, Jpeg2000StepSize, Jpeg2000TilePart, Jpeg2000Transform, parseJpeg2000Codestream };
|
|
88
|
+
export { Jpeg2000Codestream, Jpeg2000CodingDefaults, Jpeg2000CodingStyle, Jpeg2000ComponentSize, Jpeg2000HeaderOverrides, Jpeg2000ImageSize, Jpeg2000PrecinctSize, Jpeg2000ProgressionOrder, Jpeg2000Quantization, Jpeg2000QuantizationStyle, Jpeg2000StepSize, Jpeg2000TilePart, Jpeg2000Transform, MarkerCursor, parseJpeg2000Codestream };
|
|
@@ -14,13 +14,6 @@ const MARKER_COM = 65380;
|
|
|
14
14
|
const MARKER_SOT = 65424;
|
|
15
15
|
const MARKER_SOD = 65427;
|
|
16
16
|
const MARKER_EOC = 65497;
|
|
17
|
-
const PROGRESSION_ORDERS = [
|
|
18
|
-
"LRCP",
|
|
19
|
-
"RLCP",
|
|
20
|
-
"RPCL",
|
|
21
|
-
"PCRL",
|
|
22
|
-
"CPRL"
|
|
23
|
-
];
|
|
24
17
|
var MarkerCursor = class {
|
|
25
18
|
data;
|
|
26
19
|
position;
|
|
@@ -95,7 +88,7 @@ function readCodingStyleParameters(cursor, explicitPrecincts) {
|
|
|
95
88
|
const codeBlockStyle = cursor.uint8();
|
|
96
89
|
const transformCode = cursor.uint8();
|
|
97
90
|
if (transformCode !== 0 && transformCode !== 1) throw new Jpeg2000ParseError(`SPcod/SPcoc declares transformation ${String(transformCode)}, which is neither of the two ISO/IEC 15444-1 defines`);
|
|
98
|
-
if (codeBlockWidthExp
|
|
91
|
+
if (codeBlockWidthExp + codeBlockHeightExp > 12) throw new Jpeg2000ParseError(`code-block size 2^${String(codeBlockWidthExp)} by 2^${String(codeBlockHeightExp)} is outside the range ISO/IEC 15444-1 Table A.18 permits`);
|
|
99
92
|
const precinctSizes = [];
|
|
100
93
|
if (explicitPrecincts) for (let r = 0; r <= decompositionLevels; r++) {
|
|
101
94
|
const packed = cursor.uint8();
|
|
@@ -118,8 +111,15 @@ function readCodingStyleParameters(cursor, explicitPrecincts) {
|
|
|
118
111
|
};
|
|
119
112
|
}
|
|
120
113
|
function readCodingDefaults(cursor) {
|
|
114
|
+
const progressionOrders = [
|
|
115
|
+
"LRCP",
|
|
116
|
+
"RLCP",
|
|
117
|
+
"RPCL",
|
|
118
|
+
"PCRL",
|
|
119
|
+
"CPRL"
|
|
120
|
+
];
|
|
121
121
|
const scod = cursor.uint8();
|
|
122
|
-
const progressionOrder =
|
|
122
|
+
const progressionOrder = progressionOrders[cursor.uint8()];
|
|
123
123
|
if (progressionOrder === void 0) throw new Jpeg2000ParseError("COD declares a progression order outside the five ISO/IEC 15444-1 Table A.16 defines");
|
|
124
124
|
const layers = cursor.uint16();
|
|
125
125
|
if (layers === 0) throw new Jpeg2000ParseError("COD declares zero quality layers");
|
|
@@ -290,7 +290,7 @@ function readTilePart(cursor, componentCount, tileParts, comments) {
|
|
|
290
290
|
const declaredEnd = psot === 0 ? cursor.data.length : sotStart + psot;
|
|
291
291
|
const dataEnd = Math.min(declaredEnd, cursor.data.length);
|
|
292
292
|
if (dataEnd < dataStart) throw new Jpeg2000ParseError("a tile-part declares a Psot shorter than its own header");
|
|
293
|
-
const trimmedEnd = trimTrailingEoc(cursor.data,
|
|
293
|
+
const trimmedEnd = trimTrailingEoc(cursor.data, dataEnd);
|
|
294
294
|
tileParts.push({
|
|
295
295
|
tileIndex,
|
|
296
296
|
partIndex,
|
|
@@ -300,9 +300,9 @@ function readTilePart(cursor, componentCount, tileParts, comments) {
|
|
|
300
300
|
});
|
|
301
301
|
cursor.position = dataEnd;
|
|
302
302
|
}
|
|
303
|
-
function trimTrailingEoc(data,
|
|
304
|
-
if (
|
|
303
|
+
function trimTrailingEoc(data, end) {
|
|
304
|
+
if (data[end - 2] === 255 && data[end - 1] === 217) return end - 2;
|
|
305
305
|
return end;
|
|
306
306
|
}
|
|
307
307
|
//#endregion
|
|
308
|
-
export { parseJpeg2000Codestream };
|
|
308
|
+
export { MarkerCursor, parseJpeg2000Codestream };
|
|
@@ -1,11 +1,9 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
2
|
//#region src/image/jpeg2000-dwt.ts
|
|
3
3
|
const EXTENSION_MARGIN = 6;
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
const LIFT_DELTA = .443506852043971;
|
|
8
|
-
const LIFT_K = 1.230174104914001;
|
|
4
|
+
function times(count, fn) {
|
|
5
|
+
for (let index = 0; index < count; index++) fn(index);
|
|
6
|
+
}
|
|
9
7
|
function subbandBounds(bounds) {
|
|
10
8
|
return {
|
|
11
9
|
llU0: Math.ceil(bounds.u0 / 2),
|
|
@@ -18,12 +16,11 @@ function subbandBounds(bounds) {
|
|
|
18
16
|
hV1: Math.floor(bounds.v1 / 2)
|
|
19
17
|
};
|
|
20
18
|
}
|
|
21
|
-
function mirrorIndex(
|
|
19
|
+
function mirrorIndex(offsetFromI0, i0, i1) {
|
|
22
20
|
const length = i1 - i0;
|
|
23
21
|
if (length <= 1) return i0;
|
|
24
22
|
const period = 2 * (length - 1);
|
|
25
|
-
|
|
26
|
-
if (offset < 0) offset += period;
|
|
23
|
+
const offset = (offsetFromI0 % period + period) % period;
|
|
27
24
|
return i0 + (offset >= length ? period - offset : offset);
|
|
28
25
|
}
|
|
29
26
|
function interleave(source, bounds, write) {
|
|
@@ -47,6 +44,11 @@ function inverse53Filter(buffer, i0, i1) {
|
|
|
47
44
|
}
|
|
48
45
|
}
|
|
49
46
|
function inverse97Filter(buffer, i0, i1) {
|
|
47
|
+
const LIFT_ALPHA = -1.586134342059924;
|
|
48
|
+
const LIFT_BETA = -.052980118572961;
|
|
49
|
+
const LIFT_GAMMA = .882911075530934;
|
|
50
|
+
const LIFT_DELTA = .443506852043971;
|
|
51
|
+
const LIFT_K = 1.230174104914001;
|
|
50
52
|
const base = EXTENSION_MARGIN - i0;
|
|
51
53
|
const first = Math.floor(i0 / 2);
|
|
52
54
|
const last = Math.floor(i1 / 2);
|
|
@@ -69,7 +71,7 @@ function synthesiseLine(read, write, i0, i1, fillScratch, readScratch, runFilter
|
|
|
69
71
|
write(i0, i0 % 2 === 0 ? value : singleSampleHighPassGain(value));
|
|
70
72
|
return;
|
|
71
73
|
}
|
|
72
|
-
for (let k = -6; k < length + EXTENSION_MARGIN; k++) fillScratch(EXTENSION_MARGIN + k, read(mirrorIndex(
|
|
74
|
+
for (let k = -6; k < length + EXTENSION_MARGIN; k++) fillScratch(EXTENSION_MARGIN + k, read(mirrorIndex(k, i0, i1)));
|
|
73
75
|
runFilter();
|
|
74
76
|
for (let k = 0; k < length; k++) write(i0 + k, readScratch(EXTENSION_MARGIN + k));
|
|
75
77
|
}
|
|
@@ -89,12 +91,11 @@ function inverseDwt53Level(bands, bounds) {
|
|
|
89
91
|
const width = u1 - u0;
|
|
90
92
|
const height = v1 - v0;
|
|
91
93
|
const output = new Int32Array(Math.max(width * height, 0));
|
|
92
|
-
|
|
94
|
+
const scratch = new Int32Array(Math.max(Math.max(width, height) + 12, 0));
|
|
93
95
|
interleave(interleaveSource(bands, bounds), bounds, (u, v, value) => {
|
|
94
96
|
output[(v - v0) * width + (u - u0)] = value;
|
|
95
97
|
});
|
|
96
|
-
|
|
97
|
-
for (let v = 0; v < height; v++) {
|
|
98
|
+
times(height, (v) => {
|
|
98
99
|
const rowStart = v * width;
|
|
99
100
|
synthesiseLine((index) => output[rowStart + index - u0] ?? 0, (index, value) => {
|
|
100
101
|
output[rowStart + index - u0] = value;
|
|
@@ -103,7 +104,7 @@ function inverseDwt53Level(bands, bounds) {
|
|
|
103
104
|
}, (offset) => scratch[offset] ?? 0, () => {
|
|
104
105
|
inverse53Filter(scratch, u0, u1);
|
|
105
106
|
}, (value) => value >> 1);
|
|
106
|
-
}
|
|
107
|
+
});
|
|
107
108
|
for (let u = 0; u < width; u++) synthesiseLine((index) => output[(index - v0) * width + u] ?? 0, (index, value) => {
|
|
108
109
|
output[(index - v0) * width + u] = value;
|
|
109
110
|
}, v0, v1, (offset, value) => {
|
|
@@ -118,12 +119,11 @@ function inverseDwt97Level(bands, bounds) {
|
|
|
118
119
|
const width = u1 - u0;
|
|
119
120
|
const height = v1 - v0;
|
|
120
121
|
const output = new Float32Array(Math.max(width * height, 0));
|
|
121
|
-
|
|
122
|
+
const scratch = new Float32Array(Math.max(Math.max(width, height) + 12, 0));
|
|
122
123
|
interleave(interleaveSource(bands, bounds), bounds, (u, v, value) => {
|
|
123
124
|
output[(v - v0) * width + (u - u0)] = value;
|
|
124
125
|
});
|
|
125
|
-
|
|
126
|
-
for (let v = 0; v < height; v++) {
|
|
126
|
+
times(height, (v) => {
|
|
127
127
|
const rowStart = v * width;
|
|
128
128
|
synthesiseLine((index) => output[rowStart + index - u0] ?? 0, (index, value) => {
|
|
129
129
|
output[rowStart + index - u0] = value;
|
|
@@ -132,7 +132,7 @@ function inverseDwt97Level(bands, bounds) {
|
|
|
132
132
|
}, (offset) => scratch[offset] ?? 0, () => {
|
|
133
133
|
inverse97Filter(scratch, u0, u1);
|
|
134
134
|
}, (value) => value / 2);
|
|
135
|
-
}
|
|
135
|
+
});
|
|
136
136
|
for (let u = 0; u < width; u++) synthesiseLine((index) => output[(index - v0) * width + u] ?? 0, (index, value) => {
|
|
137
137
|
output[(index - v0) * width + u] = value;
|
|
138
138
|
}, v0, v1, (offset, value) => {
|
|
@@ -143,6 +143,12 @@ function inverseDwt97Level(bands, bounds) {
|
|
|
143
143
|
return output;
|
|
144
144
|
}
|
|
145
145
|
//#endregion
|
|
146
|
+
exports.interleave = interleave;
|
|
147
|
+
exports.inverse53Filter = inverse53Filter;
|
|
148
|
+
exports.inverse97Filter = inverse97Filter;
|
|
146
149
|
exports.inverseDwt53Level = inverseDwt53Level;
|
|
147
150
|
exports.inverseDwt97Level = inverseDwt97Level;
|
|
151
|
+
exports.mirrorIndex = mirrorIndex;
|
|
148
152
|
exports.subbandBounds = subbandBounds;
|
|
153
|
+
exports.synthesiseLine = synthesiseLine;
|
|
154
|
+
exports.times = times;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
//#region src/image/jpeg2000-dwt.d.ts
|
|
2
|
+
declare function times(count: number, fn: (index: number) => void): void;
|
|
2
3
|
interface Jpeg2000ResolutionBounds {
|
|
3
4
|
readonly u0: number;
|
|
4
5
|
readonly u1: number;
|
|
@@ -16,6 +17,17 @@ interface Jpeg2000SubbandBounds {
|
|
|
16
17
|
readonly hV1: number;
|
|
17
18
|
}
|
|
18
19
|
declare function subbandBounds(bounds: Jpeg2000ResolutionBounds): Jpeg2000SubbandBounds;
|
|
20
|
+
declare function mirrorIndex(offsetFromI0: number, i0: number, i1: number): number;
|
|
21
|
+
interface InterleaveSource {
|
|
22
|
+
readonly ll: (u: number, v: number) => number;
|
|
23
|
+
readonly hl: (u: number, v: number) => number;
|
|
24
|
+
readonly lh: (u: number, v: number) => number;
|
|
25
|
+
readonly hh: (u: number, v: number) => number;
|
|
26
|
+
}
|
|
27
|
+
declare function interleave(source: InterleaveSource, bounds: Jpeg2000ResolutionBounds, write: (u: number, v: number, value: number) => void): void;
|
|
28
|
+
declare function inverse53Filter(buffer: Int32Array, i0: number, i1: number): void;
|
|
29
|
+
declare function inverse97Filter(buffer: Float32Array, i0: number, i1: number): void;
|
|
30
|
+
declare function synthesiseLine(read: (index: number) => number, write: (index: number, value: number) => void, i0: number, i1: number, fillScratch: (offset: number, value: number) => void, readScratch: (offset: number) => number, runFilter: () => void, singleSampleHighPassGain: (value: number) => number): void;
|
|
19
31
|
interface Jpeg2000ReversibleSubbands {
|
|
20
32
|
readonly ll: Int32Array;
|
|
21
33
|
readonly hl: Int32Array;
|
|
@@ -31,4 +43,4 @@ interface Jpeg2000IrreversibleSubbands {
|
|
|
31
43
|
declare function inverseDwt53Level(bands: Jpeg2000ReversibleSubbands, bounds: Jpeg2000ResolutionBounds): Int32Array;
|
|
32
44
|
declare function inverseDwt97Level(bands: Jpeg2000IrreversibleSubbands, bounds: Jpeg2000ResolutionBounds): Float32Array;
|
|
33
45
|
//#endregion
|
|
34
|
-
export { Jpeg2000IrreversibleSubbands, Jpeg2000ResolutionBounds, Jpeg2000ReversibleSubbands, Jpeg2000SubbandBounds, inverseDwt53Level, inverseDwt97Level, subbandBounds };
|
|
46
|
+
export { InterleaveSource, Jpeg2000IrreversibleSubbands, Jpeg2000ResolutionBounds, Jpeg2000ReversibleSubbands, Jpeg2000SubbandBounds, interleave, inverse53Filter, inverse97Filter, inverseDwt53Level, inverseDwt97Level, mirrorIndex, subbandBounds, synthesiseLine, times };
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
//#region src/image/jpeg2000-dwt.d.ts
|
|
2
|
+
declare function times(count: number, fn: (index: number) => void): void;
|
|
2
3
|
interface Jpeg2000ResolutionBounds {
|
|
3
4
|
readonly u0: number;
|
|
4
5
|
readonly u1: number;
|
|
@@ -16,6 +17,17 @@ interface Jpeg2000SubbandBounds {
|
|
|
16
17
|
readonly hV1: number;
|
|
17
18
|
}
|
|
18
19
|
declare function subbandBounds(bounds: Jpeg2000ResolutionBounds): Jpeg2000SubbandBounds;
|
|
20
|
+
declare function mirrorIndex(offsetFromI0: number, i0: number, i1: number): number;
|
|
21
|
+
interface InterleaveSource {
|
|
22
|
+
readonly ll: (u: number, v: number) => number;
|
|
23
|
+
readonly hl: (u: number, v: number) => number;
|
|
24
|
+
readonly lh: (u: number, v: number) => number;
|
|
25
|
+
readonly hh: (u: number, v: number) => number;
|
|
26
|
+
}
|
|
27
|
+
declare function interleave(source: InterleaveSource, bounds: Jpeg2000ResolutionBounds, write: (u: number, v: number, value: number) => void): void;
|
|
28
|
+
declare function inverse53Filter(buffer: Int32Array, i0: number, i1: number): void;
|
|
29
|
+
declare function inverse97Filter(buffer: Float32Array, i0: number, i1: number): void;
|
|
30
|
+
declare function synthesiseLine(read: (index: number) => number, write: (index: number, value: number) => void, i0: number, i1: number, fillScratch: (offset: number, value: number) => void, readScratch: (offset: number) => number, runFilter: () => void, singleSampleHighPassGain: (value: number) => number): void;
|
|
19
31
|
interface Jpeg2000ReversibleSubbands {
|
|
20
32
|
readonly ll: Int32Array;
|
|
21
33
|
readonly hl: Int32Array;
|
|
@@ -31,4 +43,4 @@ interface Jpeg2000IrreversibleSubbands {
|
|
|
31
43
|
declare function inverseDwt53Level(bands: Jpeg2000ReversibleSubbands, bounds: Jpeg2000ResolutionBounds): Int32Array;
|
|
32
44
|
declare function inverseDwt97Level(bands: Jpeg2000IrreversibleSubbands, bounds: Jpeg2000ResolutionBounds): Float32Array;
|
|
33
45
|
//#endregion
|
|
34
|
-
export { Jpeg2000IrreversibleSubbands, Jpeg2000ResolutionBounds, Jpeg2000ReversibleSubbands, Jpeg2000SubbandBounds, inverseDwt53Level, inverseDwt97Level, subbandBounds };
|
|
46
|
+
export { InterleaveSource, Jpeg2000IrreversibleSubbands, Jpeg2000ResolutionBounds, Jpeg2000ReversibleSubbands, Jpeg2000SubbandBounds, interleave, inverse53Filter, inverse97Filter, inverseDwt53Level, inverseDwt97Level, mirrorIndex, subbandBounds, synthesiseLine, times };
|
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
//#region src/image/jpeg2000-dwt.ts
|
|
2
2
|
const EXTENSION_MARGIN = 6;
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
const LIFT_DELTA = .443506852043971;
|
|
7
|
-
const LIFT_K = 1.230174104914001;
|
|
3
|
+
function times(count, fn) {
|
|
4
|
+
for (let index = 0; index < count; index++) fn(index);
|
|
5
|
+
}
|
|
8
6
|
function subbandBounds(bounds) {
|
|
9
7
|
return {
|
|
10
8
|
llU0: Math.ceil(bounds.u0 / 2),
|
|
@@ -17,12 +15,11 @@ function subbandBounds(bounds) {
|
|
|
17
15
|
hV1: Math.floor(bounds.v1 / 2)
|
|
18
16
|
};
|
|
19
17
|
}
|
|
20
|
-
function mirrorIndex(
|
|
18
|
+
function mirrorIndex(offsetFromI0, i0, i1) {
|
|
21
19
|
const length = i1 - i0;
|
|
22
20
|
if (length <= 1) return i0;
|
|
23
21
|
const period = 2 * (length - 1);
|
|
24
|
-
|
|
25
|
-
if (offset < 0) offset += period;
|
|
22
|
+
const offset = (offsetFromI0 % period + period) % period;
|
|
26
23
|
return i0 + (offset >= length ? period - offset : offset);
|
|
27
24
|
}
|
|
28
25
|
function interleave(source, bounds, write) {
|
|
@@ -46,6 +43,11 @@ function inverse53Filter(buffer, i0, i1) {
|
|
|
46
43
|
}
|
|
47
44
|
}
|
|
48
45
|
function inverse97Filter(buffer, i0, i1) {
|
|
46
|
+
const LIFT_ALPHA = -1.586134342059924;
|
|
47
|
+
const LIFT_BETA = -.052980118572961;
|
|
48
|
+
const LIFT_GAMMA = .882911075530934;
|
|
49
|
+
const LIFT_DELTA = .443506852043971;
|
|
50
|
+
const LIFT_K = 1.230174104914001;
|
|
49
51
|
const base = EXTENSION_MARGIN - i0;
|
|
50
52
|
const first = Math.floor(i0 / 2);
|
|
51
53
|
const last = Math.floor(i1 / 2);
|
|
@@ -68,7 +70,7 @@ function synthesiseLine(read, write, i0, i1, fillScratch, readScratch, runFilter
|
|
|
68
70
|
write(i0, i0 % 2 === 0 ? value : singleSampleHighPassGain(value));
|
|
69
71
|
return;
|
|
70
72
|
}
|
|
71
|
-
for (let k = -6; k < length + EXTENSION_MARGIN; k++) fillScratch(EXTENSION_MARGIN + k, read(mirrorIndex(
|
|
73
|
+
for (let k = -6; k < length + EXTENSION_MARGIN; k++) fillScratch(EXTENSION_MARGIN + k, read(mirrorIndex(k, i0, i1)));
|
|
72
74
|
runFilter();
|
|
73
75
|
for (let k = 0; k < length; k++) write(i0 + k, readScratch(EXTENSION_MARGIN + k));
|
|
74
76
|
}
|
|
@@ -88,12 +90,11 @@ function inverseDwt53Level(bands, bounds) {
|
|
|
88
90
|
const width = u1 - u0;
|
|
89
91
|
const height = v1 - v0;
|
|
90
92
|
const output = new Int32Array(Math.max(width * height, 0));
|
|
91
|
-
|
|
93
|
+
const scratch = new Int32Array(Math.max(Math.max(width, height) + 12, 0));
|
|
92
94
|
interleave(interleaveSource(bands, bounds), bounds, (u, v, value) => {
|
|
93
95
|
output[(v - v0) * width + (u - u0)] = value;
|
|
94
96
|
});
|
|
95
|
-
|
|
96
|
-
for (let v = 0; v < height; v++) {
|
|
97
|
+
times(height, (v) => {
|
|
97
98
|
const rowStart = v * width;
|
|
98
99
|
synthesiseLine((index) => output[rowStart + index - u0] ?? 0, (index, value) => {
|
|
99
100
|
output[rowStart + index - u0] = value;
|
|
@@ -102,7 +103,7 @@ function inverseDwt53Level(bands, bounds) {
|
|
|
102
103
|
}, (offset) => scratch[offset] ?? 0, () => {
|
|
103
104
|
inverse53Filter(scratch, u0, u1);
|
|
104
105
|
}, (value) => value >> 1);
|
|
105
|
-
}
|
|
106
|
+
});
|
|
106
107
|
for (let u = 0; u < width; u++) synthesiseLine((index) => output[(index - v0) * width + u] ?? 0, (index, value) => {
|
|
107
108
|
output[(index - v0) * width + u] = value;
|
|
108
109
|
}, v0, v1, (offset, value) => {
|
|
@@ -117,12 +118,11 @@ function inverseDwt97Level(bands, bounds) {
|
|
|
117
118
|
const width = u1 - u0;
|
|
118
119
|
const height = v1 - v0;
|
|
119
120
|
const output = new Float32Array(Math.max(width * height, 0));
|
|
120
|
-
|
|
121
|
+
const scratch = new Float32Array(Math.max(Math.max(width, height) + 12, 0));
|
|
121
122
|
interleave(interleaveSource(bands, bounds), bounds, (u, v, value) => {
|
|
122
123
|
output[(v - v0) * width + (u - u0)] = value;
|
|
123
124
|
});
|
|
124
|
-
|
|
125
|
-
for (let v = 0; v < height; v++) {
|
|
125
|
+
times(height, (v) => {
|
|
126
126
|
const rowStart = v * width;
|
|
127
127
|
synthesiseLine((index) => output[rowStart + index - u0] ?? 0, (index, value) => {
|
|
128
128
|
output[rowStart + index - u0] = value;
|
|
@@ -131,7 +131,7 @@ function inverseDwt97Level(bands, bounds) {
|
|
|
131
131
|
}, (offset) => scratch[offset] ?? 0, () => {
|
|
132
132
|
inverse97Filter(scratch, u0, u1);
|
|
133
133
|
}, (value) => value / 2);
|
|
134
|
-
}
|
|
134
|
+
});
|
|
135
135
|
for (let u = 0; u < width; u++) synthesiseLine((index) => output[(index - v0) * width + u] ?? 0, (index, value) => {
|
|
136
136
|
output[(index - v0) * width + u] = value;
|
|
137
137
|
}, v0, v1, (offset, value) => {
|
|
@@ -142,4 +142,4 @@ function inverseDwt97Level(bands, bounds) {
|
|
|
142
142
|
return output;
|
|
143
143
|
}
|
|
144
144
|
//#endregion
|
|
145
|
-
export { inverseDwt53Level, inverseDwt97Level, subbandBounds };
|
|
145
|
+
export { interleave, inverse53Filter, inverse97Filter, inverseDwt53Level, inverseDwt97Level, mirrorIndex, subbandBounds, synthesiseLine, times };
|
package/dist/math-stretch.cjs
CHANGED
|
@@ -5,7 +5,6 @@ function sumBy(items, value) {
|
|
|
5
5
|
}
|
|
6
6
|
function requiredRepeatCount(fixed, extenders, targetSize, minConnectorOverlap) {
|
|
7
7
|
const minimumRepeat = fixed.length === 0 ? 1 : 0;
|
|
8
|
-
if (extenders.length === 0) return minimumRepeat;
|
|
9
8
|
const growthPerRepeat = sumBy(extenders, (part) => part.fullAdvance) - extenders.length * minConnectorOverlap;
|
|
10
9
|
if (growthPerRepeat <= 0) return minimumRepeat;
|
|
11
10
|
const shortfall = targetSize - sumBy(fixed, (part) => part.fullAdvance) + (fixed.length - 1) * minConnectorOverlap;
|
package/dist/math-stretch.js
CHANGED
|
@@ -4,7 +4,6 @@ function sumBy(items, value) {
|
|
|
4
4
|
}
|
|
5
5
|
function requiredRepeatCount(fixed, extenders, targetSize, minConnectorOverlap) {
|
|
6
6
|
const minimumRepeat = fixed.length === 0 ? 1 : 0;
|
|
7
|
-
if (extenders.length === 0) return minimumRepeat;
|
|
8
7
|
const growthPerRepeat = sumBy(extenders, (part) => part.fullAdvance) - extenders.length * minConnectorOverlap;
|
|
9
8
|
if (growthPerRepeat <= 0) return minimumRepeat;
|
|
10
9
|
const shortfall = targetSize - sumBy(fixed, (part) => part.fullAdvance) + (fixed.length - 1) * minConnectorOverlap;
|
package/dist/write.cjs
CHANGED
|
@@ -74,14 +74,10 @@ function computeFontFlags(standardName, metrics) {
|
|
|
74
74
|
if (standardName.includes("Bold")) flags |= FLAG_FORCE_BOLD;
|
|
75
75
|
return flags;
|
|
76
76
|
}
|
|
77
|
-
function widthForWidthsArray(standardName, code) {
|
|
78
|
-
if (require_afm_widths.STANDARD_METRICS[standardName].fixedWidth === void 0 && require_afm_widths.winAnsiGlyphName(code) === void 0) return 0;
|
|
79
|
-
return require_afm_widths.widthOfCode(standardName, code);
|
|
80
|
-
}
|
|
81
77
|
function buildFontObjects(standardName, descriptorRef) {
|
|
82
78
|
const metrics = require_afm_widths.STANDARD_METRICS[standardName];
|
|
83
79
|
const widths = [];
|
|
84
|
-
for (let code = FIRST_CHAR; code <= LAST_CHAR; code++) widths.push(require_objects.pdfNum(
|
|
80
|
+
for (let code = FIRST_CHAR; code <= LAST_CHAR; code++) widths.push(require_objects.pdfNum(require_afm_widths.widthOfCode(standardName, code)));
|
|
85
81
|
return {
|
|
86
82
|
font: require_objects.pdfDict({
|
|
87
83
|
Type: require_objects.pdfName("Font"),
|
package/dist/write.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { n as widthOfCode,
|
|
1
|
+
import { n as widthOfCode, t as STANDARD_METRICS } from "./afm-widths-De_QMWgC.js";
|
|
2
2
|
import { NOTES_ANNOTATION_AUTHOR } from "./notes-annotation-author.js";
|
|
3
3
|
import { pdfArray, pdfBool, pdfDict, pdfHexString, pdfLiteralString, pdfName, pdfNull, pdfNum, pdfRef, pdfStream } from "./objects.js";
|
|
4
4
|
import { ByteWriter, concatBytes } from "./bytes/writer.js";
|
|
@@ -73,14 +73,10 @@ function computeFontFlags(standardName, metrics) {
|
|
|
73
73
|
if (standardName.includes("Bold")) flags |= FLAG_FORCE_BOLD;
|
|
74
74
|
return flags;
|
|
75
75
|
}
|
|
76
|
-
function widthForWidthsArray(standardName, code) {
|
|
77
|
-
if (STANDARD_METRICS[standardName].fixedWidth === void 0 && winAnsiGlyphName(code) === void 0) return 0;
|
|
78
|
-
return widthOfCode(standardName, code);
|
|
79
|
-
}
|
|
80
76
|
function buildFontObjects(standardName, descriptorRef) {
|
|
81
77
|
const metrics = STANDARD_METRICS[standardName];
|
|
82
78
|
const widths = [];
|
|
83
|
-
for (let code = FIRST_CHAR; code <= LAST_CHAR; code++) widths.push(pdfNum(
|
|
79
|
+
for (let code = FIRST_CHAR; code <= LAST_CHAR; code++) widths.push(pdfNum(widthOfCode(standardName, code)));
|
|
84
80
|
return {
|
|
85
81
|
font: pdfDict({
|
|
86
82
|
Type: pdfName("Font"),
|
package/dist/xmp.cjs
CHANGED
|
@@ -15,7 +15,7 @@ function readXmpMetadata(packet) {
|
|
|
15
15
|
function xmpValue(packet, element) {
|
|
16
16
|
const match = new RegExp(`<${element}(?:\\s[^>]*)?>([\\s\\S]*?)</${element}>`).exec(packet);
|
|
17
17
|
if (match === null) return;
|
|
18
|
-
const inner = match[1]
|
|
18
|
+
const inner = match[1];
|
|
19
19
|
const items = listItems(inner);
|
|
20
20
|
if (items.length > 0) return items;
|
|
21
21
|
const text = inner.trim();
|
|
@@ -26,7 +26,7 @@ function listItems(inner) {
|
|
|
26
26
|
const pattern = /<rdf:li(?:\s[^>]*)?>([\s\S]*?)<\/rdf:li>/g;
|
|
27
27
|
let match;
|
|
28
28
|
while ((match = pattern.exec(inner)) !== null) {
|
|
29
|
-
const text =
|
|
29
|
+
const text = match[1].trim();
|
|
30
30
|
if (text.length > 0) items.push(text);
|
|
31
31
|
}
|
|
32
32
|
return items;
|
|
@@ -39,7 +39,7 @@ function field(value, key) {
|
|
|
39
39
|
function keywordsOf(packet) {
|
|
40
40
|
const match = (/* @__PURE__ */ new RegExp("<dc:subject(?:\\s[^>]*)?>([\\s\\S]*?)</dc:subject>")).exec(packet);
|
|
41
41
|
if (match === null) return {};
|
|
42
|
-
const items = listItems(match[1]
|
|
42
|
+
const items = listItems(match[1]);
|
|
43
43
|
return items.length > 0 ? { keywords: items } : {};
|
|
44
44
|
}
|
|
45
45
|
//#endregion
|
package/dist/xmp.js
CHANGED
|
@@ -14,7 +14,7 @@ function readXmpMetadata(packet) {
|
|
|
14
14
|
function xmpValue(packet, element) {
|
|
15
15
|
const match = new RegExp(`<${element}(?:\\s[^>]*)?>([\\s\\S]*?)</${element}>`).exec(packet);
|
|
16
16
|
if (match === null) return;
|
|
17
|
-
const inner = match[1]
|
|
17
|
+
const inner = match[1];
|
|
18
18
|
const items = listItems(inner);
|
|
19
19
|
if (items.length > 0) return items;
|
|
20
20
|
const text = inner.trim();
|
|
@@ -25,7 +25,7 @@ function listItems(inner) {
|
|
|
25
25
|
const pattern = /<rdf:li(?:\s[^>]*)?>([\s\S]*?)<\/rdf:li>/g;
|
|
26
26
|
let match;
|
|
27
27
|
while ((match = pattern.exec(inner)) !== null) {
|
|
28
|
-
const text =
|
|
28
|
+
const text = match[1].trim();
|
|
29
29
|
if (text.length > 0) items.push(text);
|
|
30
30
|
}
|
|
31
31
|
return items;
|
|
@@ -38,7 +38,7 @@ function field(value, key) {
|
|
|
38
38
|
function keywordsOf(packet) {
|
|
39
39
|
const match = (/* @__PURE__ */ new RegExp("<dc:subject(?:\\s[^>]*)?>([\\s\\S]*?)</dc:subject>")).exec(packet);
|
|
40
40
|
if (match === null) return {};
|
|
41
|
-
const items = listItems(match[1]
|
|
41
|
+
const items = listItems(match[1]);
|
|
42
42
|
return items.length > 0 ? { keywords: items } : {};
|
|
43
43
|
}
|
|
44
44
|
//#endregion
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pdf-parser.js",
|
|
3
|
-
"version": "4.8.
|
|
3
|
+
"version": "4.8.12",
|
|
4
4
|
"description": "Hand-written, dependency-minimal PDF codec: parses arbitrary real-world PDFs and generates new ones, built on its own codec-owned LayoutDocument item model and Zod 4 codecs.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"repository": {
|