@ac-kit/format-tiff 0.0.0-stage → 0.1.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/CHANGELOG.md +40 -0
- package/LICENSE +28 -0
- package/README.md +114 -2
- package/dist/codec/_deflate.d.ts +12 -0
- package/dist/codec/_deflate.d.ts.map +1 -0
- package/dist/codec/_deflate.js +33 -0
- package/dist/codec/_deflate.js.map +1 -0
- package/dist/codec/_lzw.d.ts +18 -0
- package/dist/codec/_lzw.d.ts.map +1 -0
- package/dist/codec/_lzw.js +134 -0
- package/dist/codec/_lzw.js.map +1 -0
- package/dist/codec/_packbits.d.ts +10 -0
- package/dist/codec/_packbits.d.ts.map +1 -0
- package/dist/codec/_packbits.js +34 -0
- package/dist/codec/_packbits.js.map +1 -0
- package/dist/codec/_predictor.d.ts +15 -0
- package/dist/codec/_predictor.d.ts.map +1 -0
- package/dist/codec/_predictor.js +68 -0
- package/dist/codec/_predictor.js.map +1 -0
- package/dist/codec/tiff-decoder.d.ts +54 -0
- package/dist/codec/tiff-decoder.d.ts.map +1 -0
- package/dist/codec/tiff-decoder.js +2 -0
- package/dist/codec/tiff-decoder.js.map +1 -0
- package/dist/container/_ifd.d.ts +45 -0
- package/dist/container/_ifd.d.ts.map +1 -0
- package/dist/container/_ifd.js +160 -0
- package/dist/container/_ifd.js.map +1 -0
- package/dist/container/_image.d.ts +37 -0
- package/dist/container/_image.d.ts.map +1 -0
- package/dist/container/_image.js +201 -0
- package/dist/container/_image.js.map +1 -0
- package/dist/container/_reader.d.ts +18 -0
- package/dist/container/_reader.d.ts.map +1 -0
- package/dist/container/_reader.js +53 -0
- package/dist/container/_reader.js.map +1 -0
- package/dist/container/open-tiff.d.ts +40 -0
- package/dist/container/open-tiff.d.ts.map +1 -0
- package/dist/container/open-tiff.js +209 -0
- package/dist/container/open-tiff.js.map +1 -0
- package/dist/container/read-tiff-gdal-metadata.d.ts +33 -0
- package/dist/container/read-tiff-gdal-metadata.d.ts.map +1 -0
- package/dist/container/read-tiff-gdal-metadata.js +82 -0
- package/dist/container/read-tiff-gdal-metadata.js.map +1 -0
- package/dist/container/tiff.d.ts +119 -0
- package/dist/container/tiff.d.ts.map +1 -0
- package/dist/container/tiff.js +2 -0
- package/dist/container/tiff.js.map +1 -0
- package/dist/errors.d.ts +34 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +43 -0
- package/dist/errors.js.map +1 -0
- package/dist/field/_field-values.d.ts +10 -0
- package/dist/field/_field-values.d.ts.map +1 -0
- package/dist/field/_field-values.js +51 -0
- package/dist/field/_field-values.js.map +1 -0
- package/dist/field/tiff-field-type.d.ts +42 -0
- package/dist/field/tiff-field-type.d.ts.map +1 -0
- package/dist/field/tiff-field-type.js +68 -0
- package/dist/field/tiff-field-type.js.map +1 -0
- package/dist/field/tiff-field.d.ts +62 -0
- package/dist/field/tiff-field.d.ts.map +1 -0
- package/dist/field/tiff-field.js +125 -0
- package/dist/field/tiff-field.js.map +1 -0
- package/dist/field/tiff-tag.d.ts +120 -0
- package/dist/field/tiff-tag.d.ts.map +1 -0
- package/dist/field/tiff-tag.js +124 -0
- package/dist/field/tiff-tag.js.map +1 -0
- package/dist/geotiff/geo-key.d.ts +67 -0
- package/dist/geotiff/geo-key.d.ts.map +1 -0
- package/dist/geotiff/geo-key.js +69 -0
- package/dist/geotiff/geo-key.js.map +1 -0
- package/dist/geotiff/geotiff-raster-to-model.d.ts +36 -0
- package/dist/geotiff/geotiff-raster-to-model.d.ts.map +1 -0
- package/dist/geotiff/geotiff-raster-to-model.js +70 -0
- package/dist/geotiff/geotiff-raster-to-model.js.map +1 -0
- package/dist/geotiff/index.d.ts +4 -0
- package/dist/geotiff/index.d.ts.map +1 -0
- package/dist/geotiff/index.js +4 -0
- package/dist/geotiff/index.js.map +1 -0
- package/dist/geotiff/read-geotiff.d.ts +63 -0
- package/dist/geotiff/read-geotiff.d.ts.map +1 -0
- package/dist/geotiff/read-geotiff.js +150 -0
- package/dist/geotiff/read-geotiff.js.map +1 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +11 -0
- package/dist/index.js.map +1 -0
- package/dist/raster/_decode-chunk.d.ts +29 -0
- package/dist/raster/_decode-chunk.d.ts.map +1 -0
- package/dist/raster/_decode-chunk.js +159 -0
- package/dist/raster/_decode-chunk.js.map +1 -0
- package/dist/raster/_layout.d.ts +27 -0
- package/dist/raster/_layout.d.ts.map +1 -0
- package/dist/raster/_layout.js +79 -0
- package/dist/raster/_layout.js.map +1 -0
- package/dist/raster/_samples.d.ts +52 -0
- package/dist/raster/_samples.d.ts.map +1 -0
- package/dist/raster/_samples.js +192 -0
- package/dist/raster/_samples.js.map +1 -0
- package/dist/raster/read-tiff-window.d.ts +109 -0
- package/dist/raster/read-tiff-window.d.ts.map +1 -0
- package/dist/raster/read-tiff-window.js +396 -0
- package/dist/raster/read-tiff-window.js.map +1 -0
- package/dist/raster/tiff-sample-array.d.ts +7 -0
- package/dist/raster/tiff-sample-array.d.ts.map +1 -0
- package/dist/raster/tiff-sample-array.js +2 -0
- package/dist/raster/tiff-sample-array.js.map +1 -0
- package/package.json +68 -3
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import type { TiffField } from "../field/tiff-field.js";
|
|
2
|
+
export type Header_ = {
|
|
3
|
+
readonly littleEndian: boolean;
|
|
4
|
+
readonly bigTiff: boolean;
|
|
5
|
+
readonly firstIfd: number;
|
|
6
|
+
readonly structuralMetadata: ReadonlyMap<string, string> | undefined;
|
|
7
|
+
};
|
|
8
|
+
/**
|
|
9
|
+
* Reads the 8- or 16-byte header, then GDAL's ghost area when it follows.
|
|
10
|
+
* `prefix` is the start of the file, at least as long as the header.
|
|
11
|
+
*/
|
|
12
|
+
export declare function parseHeader_(prefix: Uint8Array<ArrayBuffer>): Header_;
|
|
13
|
+
/** An entry whose value lies outside the entry, to be read in a batch. */
|
|
14
|
+
export type PendingValue_ = {
|
|
15
|
+
readonly fields: Map<number, TiffField>;
|
|
16
|
+
readonly tag: number;
|
|
17
|
+
readonly type: number;
|
|
18
|
+
readonly count: number;
|
|
19
|
+
readonly offset: number;
|
|
20
|
+
readonly length: number;
|
|
21
|
+
};
|
|
22
|
+
export type ParsedIfd_ = {
|
|
23
|
+
readonly offset: number;
|
|
24
|
+
readonly fields: Map<number, TiffField>;
|
|
25
|
+
readonly next: number;
|
|
26
|
+
readonly pending: PendingValue_[];
|
|
27
|
+
};
|
|
28
|
+
/** Bytes before the entries, per entry and after them, classic or BigTIFF. */
|
|
29
|
+
export declare function ifdSizes_(bigTiff: boolean): {
|
|
30
|
+
readonly count: number;
|
|
31
|
+
readonly entry: number;
|
|
32
|
+
readonly next: number;
|
|
33
|
+
};
|
|
34
|
+
/** Running total of tag bytes against `maxTagBytes`. */
|
|
35
|
+
export type TagBudget_ = {
|
|
36
|
+
spent: number;
|
|
37
|
+
readonly max: number;
|
|
38
|
+
};
|
|
39
|
+
export declare function spendTagBytes_(budget: TagBudget_, bytes: number): void;
|
|
40
|
+
/**
|
|
41
|
+
* Parses the IFD at `offset` from `bytes`, which hold the whole IFD (count,
|
|
42
|
+
* entries, next offset). Inline values are copied; others become pending.
|
|
43
|
+
*/
|
|
44
|
+
export declare function parseIfd_(bytes: Uint8Array<ArrayBuffer>, offset: number, header: Header_, size: number, budget: TagBudget_): ParsedIfd_;
|
|
45
|
+
//# sourceMappingURL=_ifd.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"_ifd.d.ts","sourceRoot":"","sources":["../../src/container/_ifd.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;AAExD,MAAM,MAAM,OAAO,GAAG;IACrB,QAAQ,CAAC,YAAY,EAAE,OAAO,CAAC;IAC/B,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;IAC1B,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,QAAQ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wBAAgB,SAAS,CACxB,KAAK,EAAE,UAAU,CAAC,WAAW,CAAC,EAC9B,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,OAAO,EACf,IAAI,EAAE,MAAM,EACZ,MAAM,EAAE,UAAU,GAChB,UAAU,CA8DZ"}
|
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
import { TiffFormatError, TiffLimitError } from "../errors.js";
|
|
2
|
+
import { tiffFieldTypeSize } from "../field/tiff-field-type.js";
|
|
3
|
+
const GHOST_PREFIX_ = "GDAL_STRUCTURAL_METADATA_SIZE=";
|
|
4
|
+
const LATIN1_ = new TextDecoder("latin1");
|
|
5
|
+
function readUint64_(data, offset, little) {
|
|
6
|
+
const value = data.getBigUint64(offset, little);
|
|
7
|
+
if (value > BigInt(Number.MAX_SAFE_INTEGER)) {
|
|
8
|
+
throw new TiffFormatError(`A 64-bit offset or count of ${value}`, offset);
|
|
9
|
+
}
|
|
10
|
+
return Number(value);
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Reads the 8- or 16-byte header, then GDAL's ghost area when it follows.
|
|
14
|
+
* `prefix` is the start of the file, at least as long as the header.
|
|
15
|
+
*/
|
|
16
|
+
export function parseHeader_(prefix) {
|
|
17
|
+
if (prefix.length < 8) {
|
|
18
|
+
throw new TiffFormatError("Too short for a TIFF header", 0);
|
|
19
|
+
}
|
|
20
|
+
const data = new DataView(prefix.buffer, prefix.byteOffset, prefix.length);
|
|
21
|
+
const order = data.getUint16(0, false);
|
|
22
|
+
let littleEndian;
|
|
23
|
+
if (order === 0x4949) {
|
|
24
|
+
littleEndian = true;
|
|
25
|
+
}
|
|
26
|
+
else if (order === 0x4d4d) {
|
|
27
|
+
littleEndian = false;
|
|
28
|
+
}
|
|
29
|
+
else {
|
|
30
|
+
throw new TiffFormatError("Not a TIFF byte order mark", 0);
|
|
31
|
+
}
|
|
32
|
+
const version = data.getUint16(2, littleEndian);
|
|
33
|
+
let firstIfd;
|
|
34
|
+
let headerLength;
|
|
35
|
+
if (version === 42) {
|
|
36
|
+
firstIfd = data.getUint32(4, littleEndian);
|
|
37
|
+
headerLength = 8;
|
|
38
|
+
}
|
|
39
|
+
else if (version === 43) {
|
|
40
|
+
if (prefix.length < 16) {
|
|
41
|
+
throw new TiffFormatError("Too short for a BigTIFF header", 0);
|
|
42
|
+
}
|
|
43
|
+
if (data.getUint16(4, littleEndian) !== 8 ||
|
|
44
|
+
data.getUint16(6, littleEndian) !== 0) {
|
|
45
|
+
throw new TiffFormatError("A BigTIFF offset size other than 8", 4);
|
|
46
|
+
}
|
|
47
|
+
firstIfd = readUint64_(data, 8, littleEndian);
|
|
48
|
+
headerLength = 16;
|
|
49
|
+
}
|
|
50
|
+
else {
|
|
51
|
+
throw new TiffFormatError(`TIFF version ${version}`, 2);
|
|
52
|
+
}
|
|
53
|
+
return {
|
|
54
|
+
littleEndian,
|
|
55
|
+
bigTiff: version === 43,
|
|
56
|
+
firstIfd,
|
|
57
|
+
structuralMetadata: parseGhost_(prefix, headerLength),
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
function parseGhost_(prefix, start) {
|
|
61
|
+
const sizeEnd = start + GHOST_PREFIX_.length + 6;
|
|
62
|
+
if (prefix.length < sizeEnd + 7) {
|
|
63
|
+
return undefined;
|
|
64
|
+
}
|
|
65
|
+
if (LATIN1_.decode(prefix.subarray(start, start + GHOST_PREFIX_.length)) !==
|
|
66
|
+
GHOST_PREFIX_) {
|
|
67
|
+
return undefined;
|
|
68
|
+
}
|
|
69
|
+
const digits = LATIN1_.decode(prefix.subarray(start + GHOST_PREFIX_.length, sizeEnd));
|
|
70
|
+
if (!/^\d{6}$/u.test(digits)) {
|
|
71
|
+
return undefined;
|
|
72
|
+
}
|
|
73
|
+
const bodyStart = sizeEnd + " bytes\n".length;
|
|
74
|
+
const bodyEnd = Math.min(prefix.length, bodyStart + Number(digits));
|
|
75
|
+
const entries = new Map();
|
|
76
|
+
for (const line of LATIN1_.decode(prefix.subarray(bodyStart, bodyEnd)).split("\n")) {
|
|
77
|
+
const equals = line.indexOf("=");
|
|
78
|
+
if (equals > 0) {
|
|
79
|
+
entries.set(line.slice(0, equals), line.slice(equals + 1));
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
return entries;
|
|
83
|
+
}
|
|
84
|
+
/** Bytes before the entries, per entry and after them, classic or BigTIFF. */
|
|
85
|
+
export function ifdSizes_(bigTiff) {
|
|
86
|
+
return bigTiff
|
|
87
|
+
? { count: 8, entry: 20, next: 8 }
|
|
88
|
+
: { count: 2, entry: 12, next: 4 };
|
|
89
|
+
}
|
|
90
|
+
export function spendTagBytes_(budget, bytes) {
|
|
91
|
+
budget.spent += bytes;
|
|
92
|
+
if (budget.spent > budget.max) {
|
|
93
|
+
throw new TiffLimitError(`The file's IFDs and tag values pass maxTagBytes (${budget.max})`);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Parses the IFD at `offset` from `bytes`, which hold the whole IFD (count,
|
|
98
|
+
* entries, next offset). Inline values are copied; others become pending.
|
|
99
|
+
*/
|
|
100
|
+
export function parseIfd_(bytes, offset, header, size, budget) {
|
|
101
|
+
const { littleEndian: little, bigTiff } = header;
|
|
102
|
+
const sizes = ifdSizes_(bigTiff);
|
|
103
|
+
const data = new DataView(bytes.buffer, bytes.byteOffset, bytes.length);
|
|
104
|
+
const entryCount = bigTiff
|
|
105
|
+
? readUint64_(data, 0, little)
|
|
106
|
+
: data.getUint16(0, little);
|
|
107
|
+
const fields = new Map();
|
|
108
|
+
const pending = [];
|
|
109
|
+
const seen = new Set();
|
|
110
|
+
const slotSize = bigTiff ? 8 : 4;
|
|
111
|
+
for (let index = 0; index < entryCount; index++) {
|
|
112
|
+
const at = sizes.count + index * sizes.entry;
|
|
113
|
+
const tag = data.getUint16(at, little);
|
|
114
|
+
const type = data.getUint16(at + 2, little);
|
|
115
|
+
const count = bigTiff
|
|
116
|
+
? readUint64_(data, at + 4, little)
|
|
117
|
+
: data.getUint32(at + 4, little);
|
|
118
|
+
const slot = at + (bigTiff ? 12 : 8);
|
|
119
|
+
if (seen.has(tag)) {
|
|
120
|
+
continue;
|
|
121
|
+
}
|
|
122
|
+
seen.add(tag);
|
|
123
|
+
const typeSize = tiffFieldTypeSize(type);
|
|
124
|
+
if (typeSize === 0) {
|
|
125
|
+
fields.set(tag, {
|
|
126
|
+
tag,
|
|
127
|
+
type,
|
|
128
|
+
count,
|
|
129
|
+
bytes: bytes.slice(slot, slot + slotSize),
|
|
130
|
+
littleEndian: little,
|
|
131
|
+
});
|
|
132
|
+
continue;
|
|
133
|
+
}
|
|
134
|
+
const length = count * typeSize;
|
|
135
|
+
if (length <= slotSize) {
|
|
136
|
+
fields.set(tag, {
|
|
137
|
+
tag,
|
|
138
|
+
type,
|
|
139
|
+
count,
|
|
140
|
+
bytes: bytes.slice(slot, slot + length),
|
|
141
|
+
littleEndian: little,
|
|
142
|
+
});
|
|
143
|
+
continue;
|
|
144
|
+
}
|
|
145
|
+
const valueOffset = bigTiff
|
|
146
|
+
? readUint64_(data, slot, little)
|
|
147
|
+
: data.getUint32(slot, little);
|
|
148
|
+
if (!Number.isSafeInteger(length) || valueOffset + length > size) {
|
|
149
|
+
throw new TiffFormatError(`Tag ${tag} declares ${count} values past the end of the file`, offset + slot);
|
|
150
|
+
}
|
|
151
|
+
spendTagBytes_(budget, length);
|
|
152
|
+
pending.push({ fields, tag, type, count, offset: valueOffset, length });
|
|
153
|
+
}
|
|
154
|
+
const nextAt = sizes.count + entryCount * sizes.entry;
|
|
155
|
+
const next = bigTiff
|
|
156
|
+
? readUint64_(data, nextAt, little)
|
|
157
|
+
: data.getUint32(nextAt, little);
|
|
158
|
+
return { offset, fields, next, pending };
|
|
159
|
+
}
|
|
160
|
+
//# sourceMappingURL=_ifd.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"_ifd.js","sourceRoot":"","sources":["../../src/container/_ifd.ts"],"names":[],"mappings":"AAAA,OAAO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AK,CAAC,IAAI,EAAE,IAAI,GAAG,MAAM,CAAC;gBACvC,YAAY,EAAE,MAAM;aACpB,CAAC,CAAC;YACH,SAAS;QACV,CAAC;QACD,MAAM,WAAW,GAAG,OAAO;YAC1B,CAAC,CAAC,WAAW,CAAC,IAAI,EAAE,IAAI,EAAE,MAAM,CAAC;YACjC,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;QAChC,IAAI,CAAC,MAAM,CAAC,aAAa,CAAC,MAAM,CAAC,IAAI,WAAW,GAAG,MAAM,GAAG,IAAI,EAAE,CAAC;YAClE,MAAM,IAAI,eAAe,CACxB,OAAO,GAAG,aAAa,KAAK,kCAAkC,EAC9D,MAAM,GAAG,IAAI,CACb,CAAC;QACH,CAAC;QACD,cAAc,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;QAC/B,OAAO,CAAC,IAAI,CAAC,EAAE,MAAM,EAAE,GAAG,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,EAAE,CAAC,CAAC;IACzE,CAAC;IACD,MAAM,MAAM,GAAG,KAAK,CAAC,KAAK,GAAG,UAAU,GAAG,KAAK,CAAC,KAAK,CAAC;IACtD,MAAM,IAAI,GAAG,OAAO;QACnB,CAAC,CAAC,WAAW,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,CAAC;QACnC,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAClC,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC;AAC1C,CAAC"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { type TiffField } from "../field/tiff-field.js";
|
|
2
|
+
import type { TiffReader_ } from "./_reader.js";
|
|
3
|
+
import type { TiffImage, TiffLimits } from "./tiff.js";
|
|
4
|
+
type Mutable_<T> = {
|
|
5
|
+
-readonly [K in keyof T]: T[K];
|
|
6
|
+
};
|
|
7
|
+
export type MutableImage_ = Omit<Mutable_<TiffImage>, "overviews" | "subImages" | "mask" | "parent"> & {
|
|
8
|
+
overviews: MutableImage_[];
|
|
9
|
+
subImages: MutableImage_[];
|
|
10
|
+
mask: MutableImage_ | undefined;
|
|
11
|
+
parent: MutableImage_ | undefined;
|
|
12
|
+
};
|
|
13
|
+
/** What the readers need of the file an image came from. */
|
|
14
|
+
export type ImageContext_ = {
|
|
15
|
+
readonly reader: TiffReader_;
|
|
16
|
+
readonly limits: TiffLimits;
|
|
17
|
+
readonly littleEndian: boolean;
|
|
18
|
+
};
|
|
19
|
+
export declare function setImageContext_(image: TiffImage, context: ImageContext_): void;
|
|
20
|
+
/** @throws {TypeError} When `image` did not come from {@link openTiff}. */
|
|
21
|
+
export declare function imageContext_(image: TiffImage): ImageContext_;
|
|
22
|
+
/** `GDAL_NODATA` text as a number, as GDAL reads it. */
|
|
23
|
+
export declare function parseNoData_(text: string): number | undefined;
|
|
24
|
+
/** Builds an image from its IFD's fields, its links left empty. */
|
|
25
|
+
export declare function createImage_(offset: number, fields: ReadonlyMap<number, TiffField>): MutableImage_;
|
|
26
|
+
/**
|
|
27
|
+
* Groups the chain's images as GDAL does: an image neither reduced nor a mask
|
|
28
|
+
* starts a group, which the reduced images and masks after it join.
|
|
29
|
+
*/
|
|
30
|
+
export declare function groupImages_(chain: readonly MutableImage_[]): void;
|
|
31
|
+
/**
|
|
32
|
+
* Links an image's SubIFDs: the reduced ones and masks join its group, the
|
|
33
|
+
* others are its sub-images only.
|
|
34
|
+
*/
|
|
35
|
+
export declare function linkSubImages_(image: MutableImage_, subImages: readonly MutableImage_[]): void;
|
|
36
|
+
export {};
|
|
37
|
+
//# sourceMappingURL=_image.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"_image.d.ts","sourceRoot":"","sources":["../../src/container/_image.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,KAAK,SAAS,EAAiB,MAAM,wB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lE;AAED;;;GAGG;AACH,wBAAgB,cAAc,CAC7B,KAAK,EAAE,aAAa,EACpB,SAAS,EAAE,SAAS,aAAa,EAAE,GACjC,IAAI,CAWN"}
|
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
import { TiffFormatError } from "../errors.js";
|
|
2
|
+
import { fieldNumberAt_, fieldValueCount_ } from "../field/_field-values.js";
|
|
3
|
+
import { TiffFieldType } from "../field/tiff-field-type.js";
|
|
4
|
+
import { tiffFieldText } from "../field/tiff-field.js";
|
|
5
|
+
import { TiffTag } from "../field/tiff-tag.js";
|
|
6
|
+
const CONTEXTS_ = new WeakMap();
|
|
7
|
+
export function setImageContext_(image, context) {
|
|
8
|
+
CONTEXTS_.set(image, context);
|
|
9
|
+
}
|
|
10
|
+
/** @throws {TypeError} When `image` did not come from {@link openTiff}. */
|
|
11
|
+
export function imageContext_(image) {
|
|
12
|
+
const context = CONTEXTS_.get(image);
|
|
13
|
+
if (context === undefined) {
|
|
14
|
+
throw new TypeError("An image that openTiff did not return");
|
|
15
|
+
}
|
|
16
|
+
return context;
|
|
17
|
+
}
|
|
18
|
+
function isNumeric_(field) {
|
|
19
|
+
return field.type !== TiffFieldType.ASCII && fieldValueCount_(field) > 0;
|
|
20
|
+
}
|
|
21
|
+
function first_(fields, tag) {
|
|
22
|
+
const field = fields.get(tag);
|
|
23
|
+
if (field === undefined || !isNumeric_(field)) {
|
|
24
|
+
return undefined;
|
|
25
|
+
}
|
|
26
|
+
return fieldNumberAt_(field, 0);
|
|
27
|
+
}
|
|
28
|
+
/** One value per sample: the field's, the first repeated where it has fewer. */
|
|
29
|
+
function perSample_(fields, tag, samples, fallback) {
|
|
30
|
+
const field = fields.get(tag);
|
|
31
|
+
const count = field === undefined || !isNumeric_(field) ? 0 : fieldValueCount_(field);
|
|
32
|
+
const values = Array.from({ length: samples });
|
|
33
|
+
for (let index = 0; index < samples; index++) {
|
|
34
|
+
values[index] =
|
|
35
|
+
count === 0
|
|
36
|
+
? fallback
|
|
37
|
+
: fieldNumberAt_(field, index < count ? index : 0);
|
|
38
|
+
}
|
|
39
|
+
return values;
|
|
40
|
+
}
|
|
41
|
+
function positiveInteger_(value, name, offset) {
|
|
42
|
+
if (value === undefined || !Number.isSafeInteger(value) || value < 1) {
|
|
43
|
+
throw new TiffFormatError(value === undefined ? `An IFD without ${name}` : `${name} ${value}`, offset);
|
|
44
|
+
}
|
|
45
|
+
return value;
|
|
46
|
+
}
|
|
47
|
+
const NUMBER_TEXT_ = /^[+-]?(?:\d+\.?\d*|\.\d+)(?:[eE][+-]?\d+)?$/u;
|
|
48
|
+
/** `GDAL_NODATA` text as a number, as GDAL reads it. */
|
|
49
|
+
export function parseNoData_(text) {
|
|
50
|
+
const trimmed = text.trim();
|
|
51
|
+
switch (trimmed.toLowerCase()) {
|
|
52
|
+
case "nan":
|
|
53
|
+
case "-nan":
|
|
54
|
+
case "+nan":
|
|
55
|
+
return Number.NaN;
|
|
56
|
+
case "inf":
|
|
57
|
+
case "+inf":
|
|
58
|
+
case "infinity":
|
|
59
|
+
case "+infinity":
|
|
60
|
+
return Number.POSITIVE_INFINITY;
|
|
61
|
+
case "-inf":
|
|
62
|
+
case "-infinity":
|
|
63
|
+
return Number.NEGATIVE_INFINITY;
|
|
64
|
+
default:
|
|
65
|
+
return NUMBER_TEXT_.test(trimmed) ? Number(trimmed) : undefined;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
/** Builds an image from its IFD's fields, its links left empty. */
|
|
69
|
+
export function createImage_(offset, fields) {
|
|
70
|
+
const width = positiveInteger_(first_(fields, TiffTag.IMAGE_WIDTH), "ImageWidth", offset);
|
|
71
|
+
const height = positiveInteger_(first_(fields, TiffTag.IMAGE_LENGTH), "ImageLength", offset);
|
|
72
|
+
const samplesPerPixel = positiveInteger_(first_(fields, TiffTag.SAMPLES_PER_PIXEL) ?? 1, "SamplesPerPixel", offset);
|
|
73
|
+
let newSubfileType = first_(fields, TiffTag.NEW_SUBFILE_TYPE) ?? 0;
|
|
74
|
+
if (!fields.has(TiffTag.NEW_SUBFILE_TYPE)) {
|
|
75
|
+
// SubfileType (TIFF 6.0 §8): 2 a reduced-resolution image, 3 a page.
|
|
76
|
+
const subfileType = first_(fields, TiffTag.SUBFILE_TYPE);
|
|
77
|
+
newSubfileType = subfileType === 2 ? 1 : subfileType === 3 ? 2 : 0;
|
|
78
|
+
}
|
|
79
|
+
const tileWidth = first_(fields, TiffTag.TILE_WIDTH);
|
|
80
|
+
const tileHeight = first_(fields, TiffTag.TILE_LENGTH);
|
|
81
|
+
const tiled = tileWidth !== undefined || tileHeight !== undefined;
|
|
82
|
+
let chunkWidth;
|
|
83
|
+
let chunkHeight;
|
|
84
|
+
if (tiled) {
|
|
85
|
+
chunkWidth = positiveInteger_(tileWidth, "TileWidth", offset);
|
|
86
|
+
chunkHeight = positiveInteger_(tileHeight, "TileLength", offset);
|
|
87
|
+
}
|
|
88
|
+
else {
|
|
89
|
+
chunkWidth = width;
|
|
90
|
+
const rowsPerStrip = first_(fields, TiffTag.ROWS_PER_STRIP) ?? 2 ** 32 - 1;
|
|
91
|
+
chunkHeight = positiveInteger_(rowsPerStrip === 0 ? undefined : Math.min(rowsPerStrip, height), "RowsPerStrip", offset);
|
|
92
|
+
}
|
|
93
|
+
const noDataField = fields.get(TiffTag.GDAL_NODATA);
|
|
94
|
+
let noData;
|
|
95
|
+
if (noDataField !== undefined) {
|
|
96
|
+
try {
|
|
97
|
+
noData = tiffFieldText(noDataField)[0];
|
|
98
|
+
}
|
|
99
|
+
catch {
|
|
100
|
+
noData = undefined;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
const extraSamplesField = fields.get(TiffTag.EXTRA_SAMPLES);
|
|
104
|
+
return {
|
|
105
|
+
offset,
|
|
106
|
+
fields,
|
|
107
|
+
width,
|
|
108
|
+
height,
|
|
109
|
+
samplesPerPixel,
|
|
110
|
+
bitsPerSample: perSample_(fields, TiffTag.BITS_PER_SAMPLE, samplesPerPixel, 1),
|
|
111
|
+
sampleFormat: perSample_(fields, TiffTag.SAMPLE_FORMAT, samplesPerPixel, 1),
|
|
112
|
+
compression: first_(fields, TiffTag.COMPRESSION) ?? 1,
|
|
113
|
+
predictor: first_(fields, TiffTag.PREDICTOR) ?? 1,
|
|
114
|
+
photometric: first_(fields, TiffTag.PHOTOMETRIC_INTERPRETATION),
|
|
115
|
+
planar: samplesPerPixel > 1 && first_(fields, TiffTag.PLANAR_CONFIGURATION) === 2,
|
|
116
|
+
fillOrder: first_(fields, TiffTag.FILL_ORDER) ?? 1,
|
|
117
|
+
extraSamples: extraSamplesField === undefined || !isNumeric_(extraSamplesField)
|
|
118
|
+
? []
|
|
119
|
+
: perSample_(fields, TiffTag.EXTRA_SAMPLES, fieldValueCount_(extraSamplesField), 0),
|
|
120
|
+
newSubfileType,
|
|
121
|
+
isReducedResolution: (newSubfileType & 1) !== 0,
|
|
122
|
+
isPage: (newSubfileType & 2) !== 0,
|
|
123
|
+
isMask: (newSubfileType & 4) !== 0,
|
|
124
|
+
tiled,
|
|
125
|
+
chunkWidth,
|
|
126
|
+
chunkHeight,
|
|
127
|
+
chunksAcross: Math.ceil(width / chunkWidth),
|
|
128
|
+
chunksDown: Math.ceil(height / chunkHeight),
|
|
129
|
+
noData,
|
|
130
|
+
noDataValue: noData === undefined ? undefined : parseNoData_(noData),
|
|
131
|
+
overviews: [],
|
|
132
|
+
mask: undefined,
|
|
133
|
+
subImages: [],
|
|
134
|
+
parent: undefined,
|
|
135
|
+
};
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* Joins `members` to `parent`: reduced-resolution images become its overviews,
|
|
139
|
+
* then each mask becomes the mask of the group's image of its size (the
|
|
140
|
+
* parent's when none matches), whatever their order in the file.
|
|
141
|
+
*/
|
|
142
|
+
function joinGroup_(parent, members) {
|
|
143
|
+
const masks = [];
|
|
144
|
+
for (const member of members) {
|
|
145
|
+
if (member.isMask) {
|
|
146
|
+
masks.push(member);
|
|
147
|
+
}
|
|
148
|
+
else {
|
|
149
|
+
parent.overviews.push(member);
|
|
150
|
+
member.parent = parent;
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
parent.overviews.sort((left, right) => right.width - left.width);
|
|
154
|
+
const candidates = [parent, ...parent.overviews];
|
|
155
|
+
for (const mask of masks) {
|
|
156
|
+
const owner = candidates.find((image) => image.mask === undefined &&
|
|
157
|
+
image.width === mask.width &&
|
|
158
|
+
image.height === mask.height) ?? parent;
|
|
159
|
+
owner.mask ??= mask;
|
|
160
|
+
mask.parent = owner;
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
/**
|
|
164
|
+
* Groups the chain's images as GDAL does: an image neither reduced nor a mask
|
|
165
|
+
* starts a group, which the reduced images and masks after it join.
|
|
166
|
+
*/
|
|
167
|
+
export function groupImages_(chain) {
|
|
168
|
+
let index = 0;
|
|
169
|
+
while (index < chain.length) {
|
|
170
|
+
const parent = chain[index];
|
|
171
|
+
const members = [];
|
|
172
|
+
index++;
|
|
173
|
+
while (index < chain.length) {
|
|
174
|
+
const image = chain[index];
|
|
175
|
+
if (!image.isReducedResolution && !image.isMask) {
|
|
176
|
+
break;
|
|
177
|
+
}
|
|
178
|
+
members.push(image);
|
|
179
|
+
index++;
|
|
180
|
+
}
|
|
181
|
+
joinGroup_(parent, members);
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
/**
|
|
185
|
+
* Links an image's SubIFDs: the reduced ones and masks join its group, the
|
|
186
|
+
* others are its sub-images only.
|
|
187
|
+
*/
|
|
188
|
+
export function linkSubImages_(image, subImages) {
|
|
189
|
+
const members = [];
|
|
190
|
+
for (const subImage of subImages) {
|
|
191
|
+
image.subImages.push(subImage);
|
|
192
|
+
if (subImage.isReducedResolution || subImage.isMask) {
|
|
193
|
+
members.push(subImage);
|
|
194
|
+
}
|
|
195
|
+
else {
|
|
196
|
+
subImage.parent = image;
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
joinGroup_(image, members);
|
|
200
|
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,OAAO,CAAC,CAAC;AAC5B,CAAC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { type ByteRangeSource } from "@ac-kit/core";
|
|
2
|
+
/**
|
|
3
|
+
* The file as the reader sees it: its size, and reads that give exactly the
|
|
4
|
+
* bytes asked, in an `ArrayBuffer` of their own when the source's are not.
|
|
5
|
+
*/
|
|
6
|
+
export type TiffReader_ = {
|
|
7
|
+
readonly size: number;
|
|
8
|
+
read(offset: number, length: number, signal: AbortSignal | undefined): Promise<Uint8Array<ArrayBuffer>>;
|
|
9
|
+
};
|
|
10
|
+
export declare function createReader_(source: ByteRangeSource | Blob | Uint8Array<ArrayBuffer>): TiffReader_;
|
|
11
|
+
/** Byte spans already read, looked up by the range a parser needs. */
|
|
12
|
+
export declare class SpanCache_ {
|
|
13
|
+
private readonly spans_;
|
|
14
|
+
add(offset: number, bytes: Uint8Array<ArrayBuffer>): void;
|
|
15
|
+
/** The bytes of `[offset, offset + length)` when one span holds them all. */
|
|
16
|
+
get(offset: number, length: number): Uint8Array<ArrayBuffer> | undefined;
|
|
17
|
+
}
|
|
18
|
+
//# sourceMappingURL=_reader.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"_reader.d.ts","sourceRoot":"","sources":["../../src/container/_reader.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,KAAK,eAAe,EAGpB,MAAM,cAAc,CAAC;AAItB;;;GAGG;AACH,MAAM,MAAM,WAAW,GAAG;IACzB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,IAAI,CACH,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,WAAW,GAAG,SAAS,GAC7B,OAAO,CAAC,UAAU,CAAC,WAAW,CAAC,CAAC,CAAC;CACpC,CAAC;AAEF,wBAAgB,aAAa,CAC5B,MAAM,EAAE,eAAe,GAAG,IAAI,GAAG,UAAU,CAAC,WAAW,CAAC,GACtD,WAAW,CAoCb;AAED,sEAAsE;AACtE,qBAAa,UAAU;IACtB,OAAO,CAAC,QAAQ,CAAC,MAAM,CAGd;IAET,GAAG,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,UAAU,CAAC,WAAW,CAAC,GAAG,IAAI,CAExD;IAED,6EAA6E;IAC7E,GAAG,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,UAAU,CAAC,WAAW,CAAC,GAAG,SAAS,CAQvE;CACD"}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { byteRangeSourceFromBlob, byteRangeSourceFromBytes, } from "@ac-kit/core";
|
|
2
|
+
import { TiffFormatError } from "../errors.js";
|
|
3
|
+
export function createReader_(source) {
|
|
4
|
+
let ranged;
|
|
5
|
+
if (source instanceof Uint8Array) {
|
|
6
|
+
ranged = byteRangeSourceFromBytes(source);
|
|
7
|
+
}
|
|
8
|
+
else if (source instanceof Blob) {
|
|
9
|
+
ranged = byteRangeSourceFromBlob(source);
|
|
10
|
+
}
|
|
11
|
+
else {
|
|
12
|
+
ranged = source;
|
|
13
|
+
}
|
|
14
|
+
const { size } = ranged;
|
|
15
|
+
if (!Number.isSafeInteger(size) || size < 0) {
|
|
16
|
+
throw new TypeError(`A TIFF source of size ${size}`);
|
|
17
|
+
}
|
|
18
|
+
return {
|
|
19
|
+
size,
|
|
20
|
+
read: async (offset, length, signal) => {
|
|
21
|
+
if (offset + length > size) {
|
|
22
|
+
throw new TiffFormatError(`A read of ${length} bytes past the end of the ${size}-byte file`, offset);
|
|
23
|
+
}
|
|
24
|
+
const bytes = await ranged.read(offset, length, signal);
|
|
25
|
+
// A source may resolve despite an abort: checked after every read.
|
|
26
|
+
signal?.throwIfAborted();
|
|
27
|
+
if (bytes.length !== length) {
|
|
28
|
+
throw new TiffFormatError(`The source gave ${bytes.length} bytes instead of ${length}`, offset);
|
|
29
|
+
}
|
|
30
|
+
return bytes.buffer instanceof ArrayBuffer
|
|
31
|
+
? bytes
|
|
32
|
+
: new Uint8Array(bytes);
|
|
33
|
+
},
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
/** Byte spans already read, looked up by the range a parser needs. */
|
|
37
|
+
export class SpanCache_ {
|
|
38
|
+
spans_ = [];
|
|
39
|
+
add(offset, bytes) {
|
|
40
|
+
this.spans_.push({ offset, bytes });
|
|
41
|
+
}
|
|
42
|
+
/** The bytes of `[offset, offset + length)` when one span holds them all. */
|
|
43
|
+
get(offset, length) {
|
|
44
|
+
for (const span of this.spans_) {
|
|
45
|
+
const start = offset - span.offset;
|
|
46
|
+
if (start >= 0 && start + length <= span.bytes.length) {
|
|
47
|
+
return span.bytes.subarray(start, start + length);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
return undefined;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
//# sourceMappingURL=_reader.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"_reader.js","sourceRoot":"","sources":["../../src/container/_reader.ts"],"names":[],"mappings":"AAAA,OAAO,EAEN,uBAAuB,EACvB,wBAAwB,GACxB,MAAM,cAAc,CAAC;AAEtB,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAe/C,MAAM,UAAU,aAAa,CAC5B,MAAwD;IAExD,IAAI,MAAuB,CAAC;IAC5B,IAAI,MAAM,YAAY,UAAU,EAAE,CAAC;QAClC,MAAM,GAAG,wBAAwB,CAAC,MAAM,CAAC,CAAC;IAC3C,CAAC;SAAM,IAAI,MAAM,YAAY,IAAI,EAAE,CAAC;QACnC,MAAM,GAAG,uBAAuB,CAAC,MAAM,CAAC,CAAC;IAC1C,CAAC;SAAM,CAAC;QACP,MAAM,GAAG,MAAM,CAAC;IACjB,CAAC;IACD,MAAM,EAAE,IAAI,EAAE,GAAG,MAAM,CAAC;IACxB,IAAI,CAAC,MAAM,CAAC,aAAa,CAAC,IAAI,CAAC,IAAI,IAAI,GAAG,CAAC,EAAE,CAAC;QAC7C,MAAM,I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C,MAAM,EAAE,CAAC;gBACvD,OAAO,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,KAAK,EAAE,KAAK,GAAG,MAAM,CAAC,CAAC;YACnD,CAAC;QACF,CAAC;QACD,OAAO,SAAS,CAAC;IAClB,CAAC;CACD"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import type { ByteRangeSource } from "@ac-kit/core";
|
|
2
|
+
import type { Tiff, TiffLimits } from "./tiff.js";
|
|
3
|
+
/**
|
|
4
|
+
* Opens a TIFF 6.0, BigTIFF or Cloud Optimized GeoTIFF file by ranges, without
|
|
5
|
+
* reading its image data: the header and GDAL's ghost area, every IFD of the
|
|
6
|
+
* chain and every SubIFD, and every tag value, so each {@link TiffImage} is
|
|
7
|
+
* complete when this resolves.
|
|
8
|
+
*
|
|
9
|
+
* The first read takes the first 16 KiB, which in a COG holds every IFD
|
|
10
|
+
* (`LAYOUT=IFDS_BEFORE_DATA`); the values those IFDs point to outside it are
|
|
11
|
+
* then read together, in one read when they are close together, as a COG's are.
|
|
12
|
+
* An IFD outside what was read costs one more read. Images are then read with
|
|
13
|
+
* {@link readTiffWindow} and {@link readTiffTile}.
|
|
14
|
+
*
|
|
15
|
+
* A `Blob` (a `File`, Node's `fs.openAsBlob`) is read with `slice`, bytes in
|
|
16
|
+
* memory as views; any other {@link ByteRangeSource} (HTTP `Range`, object
|
|
17
|
+
* storage) through `read`.
|
|
18
|
+
*
|
|
19
|
+
* Memory is linear in the tag bytes, bounded by `maxTagBytes`.
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* const tiff = await openTiff(await fs.openAsBlob(path), {
|
|
23
|
+
* maxImages: 64,
|
|
24
|
+
* maxTagBytes: 16 * 1024 * 1024,
|
|
25
|
+
* maxTileBytes: 64 * 1024 * 1024,
|
|
26
|
+
* maxDecodedBytes: 256 * 1024 * 1024,
|
|
27
|
+
* });
|
|
28
|
+
* const [image] = tiff.images;
|
|
29
|
+
*
|
|
30
|
+
* @throws {TiffFormatError} When the header is not TIFF's, an IFD or a value
|
|
31
|
+
* lies past the end, the chain loops, an image lacks its size, or the source
|
|
32
|
+
* gives fewer bytes than asked.
|
|
33
|
+
* @throws {TiffLimitError} When the file has more than `maxImages` IFDs or more
|
|
34
|
+
* than `maxTagBytes` of IFDs and values.
|
|
35
|
+
* @throws {TypeError} When a limit or the source's size is not a safe
|
|
36
|
+
* non-negative integer.
|
|
37
|
+
* @throws When `signal` aborts, its reason; the source's own read error.
|
|
38
|
+
*/
|
|
39
|
+
export declare function openTiff(source: ByteRangeSource | Blob | Uint8Array<ArrayBuffer>, limits: TiffLimits, signal?: AbortSignal): Promise<Tiff>;
|
|
40
|
+
//# sourceMappingURL=open-tiff.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"open-tiff.d.ts","sourceRoot":"","sources":["../../src/container/open-tiff.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAuBpD,OAAO,KAAK,EAAE,IAAI,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AAwIlD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmCG;AACH,wBAAsB,QAAQ,CAC7B,MAAM,EAAE,eAAe,GAAG,IAAI,GAAG,UAAU,CAAC,WAAW,CAAC,EACxD,MAAM,EAAE,UAAU,EAClB,MAAM,CAAC,EAAE,WAAW,GAClB,OAAO,CAAC,IAAI,CAAC,CA8Ef"}
|