@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,159 @@
|
|
|
1
|
+
import { inflate_ } from "../codec/_deflate.js";
|
|
2
|
+
import { decodeLzw_ } from "../codec/_lzw.js";
|
|
3
|
+
import { decodePackBits_ } from "../codec/_packbits.js";
|
|
4
|
+
import { undoFloatingPointPredictor_, undoHorizontalDifferencing_, } from "../codec/_predictor.js";
|
|
5
|
+
import { TiffFormatError, TiffLimitError, TiffUnsupportedError, } from "../errors.js";
|
|
6
|
+
import { fieldNumberAt_, fieldValueCount_ } from "../field/_field-values.js";
|
|
7
|
+
import { TiffCompression, TiffPredictor, TiffTag } from "../field/tiff-tag.js";
|
|
8
|
+
const REVERSED_ = new Uint8Array(256);
|
|
9
|
+
for (let byte = 0; byte < 256; byte++) {
|
|
10
|
+
let reversed = 0;
|
|
11
|
+
for (let bit = 0; bit < 8; bit++) {
|
|
12
|
+
reversed |= ((byte >>> bit) & 1) << (7 - bit);
|
|
13
|
+
}
|
|
14
|
+
REVERSED_[byte] = reversed;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Checks that the image's codec, predictor and colour layout can be decoded,
|
|
18
|
+
* before any read.
|
|
19
|
+
*
|
|
20
|
+
* @throws {TiffUnsupportedError} For a compression with no decoder, a predictor
|
|
21
|
+
* other than 1–3 or one the samples' widths rule out, or subsampled YCbCr
|
|
22
|
+
* outside JPEG.
|
|
23
|
+
*/
|
|
24
|
+
export function checkDecodable_(image, decoders) {
|
|
25
|
+
const { compression } = image;
|
|
26
|
+
// A number, not the enum: a file may hold any predictor value.
|
|
27
|
+
const predictor = image.predictor;
|
|
28
|
+
if (decoders?.[compression] === undefined &&
|
|
29
|
+
compression !== TiffCompression.NONE &&
|
|
30
|
+
compression !== TiffCompression.PACK_BITS &&
|
|
31
|
+
compression !== TiffCompression.LZW &&
|
|
32
|
+
compression !== TiffCompression.DEFLATE &&
|
|
33
|
+
compression !== TiffCompression.DEFLATE_OBSOLETE) {
|
|
34
|
+
throw new TiffUnsupportedError(`Compression ${compression} without a decoder`, compression);
|
|
35
|
+
}
|
|
36
|
+
if (image.photometric === 6 &&
|
|
37
|
+
compression !== TiffCompression.JPEG &&
|
|
38
|
+
compression !== TiffCompression.OJPEG) {
|
|
39
|
+
const field = image.fields.get(TiffTag.Y_CB_CR_SUBSAMPLING);
|
|
40
|
+
const horizontal = field === undefined || fieldValueCount_(field) < 2
|
|
41
|
+
? 2
|
|
42
|
+
: fieldNumberAt_(field, 0);
|
|
43
|
+
const vertical = field === undefined || fieldValueCount_(field) < 2
|
|
44
|
+
? 2
|
|
45
|
+
: fieldNumberAt_(field, 1);
|
|
46
|
+
if (horizontal !== 1 || vertical !== 1) {
|
|
47
|
+
throw new TiffUnsupportedError(`YCbCr subsampled ${horizontal}×${vertical} outside JPEG`);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
if (predictor === TiffPredictor.NONE) {
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
const bits = image.bitsPerSample[0];
|
|
54
|
+
const uniform = image.bitsPerSample.every((value) => value === bits);
|
|
55
|
+
if (predictor === TiffPredictor.HORIZONTAL) {
|
|
56
|
+
if (!uniform || (bits !== 8 && bits !== 16 && bits !== 32 && bits !== 64)) {
|
|
57
|
+
throw new TiffUnsupportedError(`Predictor 2 over ${image.bitsPerSample.join("/")}-bit samples`, predictor);
|
|
58
|
+
}
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
if (predictor === TiffPredictor.FLOATING_POINT) {
|
|
62
|
+
if (!uniform || bits % 8 !== 0) {
|
|
63
|
+
throw new TiffUnsupportedError(`Predictor 3 over ${image.bitsPerSample.join("/")}-bit samples`, predictor);
|
|
64
|
+
}
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
throw new TiffUnsupportedError(`Predictor ${predictor}`, predictor);
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Decodes one stored chunk to its rows, predictor undone, in an array the
|
|
71
|
+
* caller may change. `stored` holds exactly the chunk's bytes.
|
|
72
|
+
*/
|
|
73
|
+
export async function decodeChunk_(image, context, chunk, stored, decoders, signal) {
|
|
74
|
+
const needed = chunk.rows * chunk.rowBytes;
|
|
75
|
+
let input = stored;
|
|
76
|
+
if (image.fillOrder === 2) {
|
|
77
|
+
input = new Uint8Array(stored.length);
|
|
78
|
+
for (let index = 0; index < stored.length; index++) {
|
|
79
|
+
input[index] = REVERSED_[stored[index]];
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
const { compression } = image;
|
|
83
|
+
const decoder = decoders?.[compression];
|
|
84
|
+
let decoded;
|
|
85
|
+
let written;
|
|
86
|
+
if (decoder !== undefined) {
|
|
87
|
+
const planar = image.planar;
|
|
88
|
+
const result = await decoder({
|
|
89
|
+
bytes: input,
|
|
90
|
+
compression,
|
|
91
|
+
width: image.chunkWidth,
|
|
92
|
+
height: chunk.rows,
|
|
93
|
+
samplesPerPixel: planar ? 1 : image.samplesPerPixel,
|
|
94
|
+
bitsPerSample: planar
|
|
95
|
+
? [image.bitsPerSample[chunk.plane]]
|
|
96
|
+
: image.bitsPerSample,
|
|
97
|
+
sampleFormat: planar
|
|
98
|
+
? [image.sampleFormat[chunk.plane]]
|
|
99
|
+
: image.sampleFormat,
|
|
100
|
+
littleEndian: context.littleEndian,
|
|
101
|
+
byteLength: needed,
|
|
102
|
+
image,
|
|
103
|
+
signal,
|
|
104
|
+
});
|
|
105
|
+
signal?.throwIfAborted();
|
|
106
|
+
if (result.length > context.limits.maxDecodedBytes) {
|
|
107
|
+
throw new TiffLimitError(`A decoder gave ${result.length} bytes, past maxDecodedBytes (${context.limits.maxDecodedBytes})`);
|
|
108
|
+
}
|
|
109
|
+
decoded = new Uint8Array(needed);
|
|
110
|
+
written = Math.min(needed, result.length);
|
|
111
|
+
decoded.set(result.subarray(0, written));
|
|
112
|
+
}
|
|
113
|
+
else if (compression === TiffCompression.NONE) {
|
|
114
|
+
written = Math.min(needed, input.length);
|
|
115
|
+
// Only undoing a predictor writes to the bytes, which may be the source's.
|
|
116
|
+
decoded =
|
|
117
|
+
image.predictor === TiffPredictor.NONE || input !== stored
|
|
118
|
+
? input.subarray(0, written)
|
|
119
|
+
: input.slice(0, written);
|
|
120
|
+
}
|
|
121
|
+
else {
|
|
122
|
+
decoded = new Uint8Array(needed);
|
|
123
|
+
try {
|
|
124
|
+
switch (compression) {
|
|
125
|
+
case TiffCompression.PACK_BITS:
|
|
126
|
+
written = decodePackBits_(input, decoded);
|
|
127
|
+
break;
|
|
128
|
+
case TiffCompression.LZW:
|
|
129
|
+
written = decodeLzw_(input, decoded);
|
|
130
|
+
break;
|
|
131
|
+
default:
|
|
132
|
+
written = await inflate_(input, decoded, signal);
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
catch (error) {
|
|
136
|
+
signal?.throwIfAborted();
|
|
137
|
+
if (error instanceof RangeError || error instanceof TypeError) {
|
|
138
|
+
throw new TiffFormatError(`Corrupt data in chunk ${chunk.index} (${error.message})`, chunk.offset);
|
|
139
|
+
}
|
|
140
|
+
throw error;
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
if (written < needed) {
|
|
144
|
+
throw new TiffFormatError(`Chunk ${chunk.index} decodes to ${written} of its ${needed} bytes`, chunk.offset);
|
|
145
|
+
}
|
|
146
|
+
undoPredictor_(image, context, chunk, decoded);
|
|
147
|
+
return decoded;
|
|
148
|
+
}
|
|
149
|
+
function undoPredictor_(image, context, chunk, decoded) {
|
|
150
|
+
const stride = image.planar ? 1 : image.samplesPerPixel;
|
|
151
|
+
const bits = image.bitsPerSample[0];
|
|
152
|
+
if (image.predictor === TiffPredictor.HORIZONTAL) {
|
|
153
|
+
undoHorizontalDifferencing_(decoded, chunk.rows, chunk.rowBytes, image.chunkWidth, stride, bits, context.littleEndian);
|
|
154
|
+
}
|
|
155
|
+
else if (image.predictor === TiffPredictor.FLOATING_POINT) {
|
|
156
|
+
undoFloatingPointPredictor_(decoded, chunk.rows, chunk.rowBytes, image.chunkWidth, stride, bits / 8, context.littleEndian, new Uint8Array(chunk.rowBytes));
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
//# sourceMappingURL=_decode-chunk.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"_decode-chunk.js","sourceRoot":"","sources":["../../src/raster/_decode-chunk.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAChD,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC9C,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AACxD,OAAO,EACN,2BAA2B,EAC3B,2BAA2B,GAC3B,MAAM,wBAAwB,CAAC;AAIhC,OAAO,EACN,eAAe,EACf,cAAc,EACd,oBAAoB,GACpB,MAAM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AAO,OAAO,CAAC;AAChB,CAAC;AAED,SAAS,cAAc,CACtB,KAAgB,EAChB,OAAsB,EACtB,KAAa,EACb,OAAgC;IAEhC,MAAM,MAAM,GAAG,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,eAAe,CAAC;IACxD,MAAM,IAAI,GAAG,KAAK,CAAC,aAAa,CAAC,CAAC,CAAE,CAAC;IACrC,IAAI,KAAK,CAAC,SAAS,KAAK,aAAa,CAAC,UAAU,EAAE,CAAC;QAClD,2BAA2B,CAC1B,OAAO,EACP,KAAK,CAAC,IAAI,EACV,KAAK,CAAC,QAAQ,EACd,KAAK,CAAC,UAAU,EAChB,MAAM,EACN,IAAI,EACJ,OAAO,CAAC,YAAY,CACpB,CAAC;IACH,CAAC;SAAM,IAAI,KAAK,CAAC,SAAS,KAAK,aAAa,CAAC,cAAc,EAAE,CAAC;QAC7D,2BAA2B,CAC1B,OAAO,EACP,KAAK,CAAC,IAAI,EACV,KAAK,CAAC,QAAQ,EACd,KAAK,CAAC,UAAU,EAChB,MAAM,EACN,IAAI,GAAG,CAAC,EACR,OAAO,CAAC,YAAY,EACpB,IAAI,UAAU,CAAC,KAAK,CAAC,QAAQ,CAAC,CAC9B,CAAC;IACH,CAAC;AACF,CAAC"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { TiffImage } from "../container/tiff.js";
|
|
2
|
+
/** Where an image's chunks are, validated once and cached. */
|
|
3
|
+
export type Layout_ = {
|
|
4
|
+
readonly offsets: Float64Array;
|
|
5
|
+
readonly byteCounts: Float64Array;
|
|
6
|
+
/** Planes: the samples per pixel of a planar image, 1 otherwise. */
|
|
7
|
+
readonly planes: number;
|
|
8
|
+
readonly chunksPerPlane: number;
|
|
9
|
+
/** Bits of one pixel of each plane's chunks. */
|
|
10
|
+
readonly pixelBits: readonly number[];
|
|
11
|
+
/** Bit offset of each sample in its plane's pixel. */
|
|
12
|
+
readonly sampleBitOffsets: readonly number[];
|
|
13
|
+
/** The plane each sample is in. */
|
|
14
|
+
readonly samplePlanes: readonly number[];
|
|
15
|
+
};
|
|
16
|
+
/**
|
|
17
|
+
* The image's chunk tables and bit layout.
|
|
18
|
+
*
|
|
19
|
+
* @throws {TiffFormatError} When its offsets or byte counts are missing or list
|
|
20
|
+
* fewer chunks than its size and chunking need.
|
|
21
|
+
*/
|
|
22
|
+
export declare function layout_(image: TiffImage): Layout_;
|
|
23
|
+
/** Bytes of one row of a chunk of `plane`, padded to a whole byte. */
|
|
24
|
+
export declare function rowBytes_(image: TiffImage, layout: Layout_, plane: number): number;
|
|
25
|
+
/** Rows a chunk in row `chunkRow` holds: a tile's all, a last strip's rest. */
|
|
26
|
+
export declare function chunkRows_(image: TiffImage, chunkRow: number): number;
|
|
27
|
+
//# sourceMappingURL=_layout.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"_layout.d.ts","sourceRoot":"","sources":["../../src/raster/_layout.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AAKtD,8DAA8D;AAC9D,MAAM,MAAM,OAAO,GAAG;IACrB,QAAQ,CAAC,OAAO,EAAE,YAAY,CAAC;IAC/B,QAAQ,CAAC,UAAU,EAAE,YAAY,CAAC;IAClC,oEAAoE;IACpE,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,cAAc,EAAE,MAAM,CAAC;IAChC,gDAAgD;IAChD,QAAQ,CAAC,SAAS,EAAE,SAAS,MAAM,EAAE,CAAC;IACtC,sDAAsD;IACtD,QAAQ,CAAC,gBAAgB,EAAE,SAAS,MAAM,EAAE,CAAC;IAC7C,mCAAmC;IACnC,QAAQ,CAAC,YAAY,EAAE,SAAS,MAAM,EAAE,CAAC;CACzC,CAAC;AA8BF;;;;;GAKG;AACH,wBAAgB,OAAO,CAAC,KAAK,EAAE,SAAS,GAAG,OAAO,CAiDjD;AAED,sEAAsE;AACtE,wBAAgB,SAAS,CACxB,KAAK,EAAE,SAAS,EAChB,MAAM,EAAE,OAAO,EACf,KAAK,EAAE,MAAM,GACX,MAAM,CAER;AAED,+EAA+E;AAC/E,wBAAgB,UAAU,CAAC,KAAK,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,GAAG,MAAM,CAIrE"}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { TiffFormatError } from "../errors.js";
|
|
2
|
+
import { fieldNumberAt_, fieldValueCount_ } from "../field/_field-values.js";
|
|
3
|
+
import { TiffTag } from "../field/tiff-tag.js";
|
|
4
|
+
const LAYOUTS_ = new WeakMap();
|
|
5
|
+
function table_(image, tag, name, count) {
|
|
6
|
+
const field = image.fields.get(tag);
|
|
7
|
+
if (field === undefined || fieldValueCount_(field) < count) {
|
|
8
|
+
throw new TiffFormatError(field === undefined
|
|
9
|
+
? `An image without ${name}`
|
|
10
|
+
: `${name} lists ${fieldValueCount_(field)} chunks of ${count}`, image.offset);
|
|
11
|
+
}
|
|
12
|
+
const values = new Float64Array(count);
|
|
13
|
+
for (let index = 0; index < count; index++) {
|
|
14
|
+
const value = fieldNumberAt_(field, index);
|
|
15
|
+
if (!Number.isSafeInteger(value) || value < 0) {
|
|
16
|
+
throw new TiffFormatError(`${name} holds ${value}`, image.offset);
|
|
17
|
+
}
|
|
18
|
+
values[index] = value;
|
|
19
|
+
}
|
|
20
|
+
return values;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* The image's chunk tables and bit layout.
|
|
24
|
+
*
|
|
25
|
+
* @throws {TiffFormatError} When its offsets or byte counts are missing or list
|
|
26
|
+
* fewer chunks than its size and chunking need.
|
|
27
|
+
*/
|
|
28
|
+
export function layout_(image) {
|
|
29
|
+
const cached = LAYOUTS_.get(image);
|
|
30
|
+
if (cached !== undefined) {
|
|
31
|
+
return cached;
|
|
32
|
+
}
|
|
33
|
+
const planes = image.planar ? image.samplesPerPixel : 1;
|
|
34
|
+
const chunksPerPlane = image.chunksAcross * image.chunksDown;
|
|
35
|
+
const count = chunksPerPlane * planes;
|
|
36
|
+
const offsets = table_(image, image.tiled ? TiffTag.TILE_OFFSETS : TiffTag.STRIP_OFFSETS, image.tiled ? "TileOffsets" : "StripOffsets", count);
|
|
37
|
+
const byteCounts = table_(image, image.tiled ? TiffTag.TILE_BYTE_COUNTS : TiffTag.STRIP_BYTE_COUNTS, image.tiled ? "TileByteCounts" : "StripByteCounts", count);
|
|
38
|
+
const pixelBits = [];
|
|
39
|
+
const sampleBitOffsets = [];
|
|
40
|
+
const samplePlanes = [];
|
|
41
|
+
if (image.planar) {
|
|
42
|
+
for (let sample = 0; sample < image.samplesPerPixel; sample++) {
|
|
43
|
+
pixelBits.push(image.bitsPerSample[sample]);
|
|
44
|
+
sampleBitOffsets.push(0);
|
|
45
|
+
samplePlanes.push(sample);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
else {
|
|
49
|
+
let bits = 0;
|
|
50
|
+
for (let sample = 0; sample < image.samplesPerPixel; sample++) {
|
|
51
|
+
sampleBitOffsets.push(bits);
|
|
52
|
+
samplePlanes.push(0);
|
|
53
|
+
bits += image.bitsPerSample[sample];
|
|
54
|
+
}
|
|
55
|
+
pixelBits.push(bits);
|
|
56
|
+
}
|
|
57
|
+
const layout = {
|
|
58
|
+
offsets,
|
|
59
|
+
byteCounts,
|
|
60
|
+
planes,
|
|
61
|
+
chunksPerPlane,
|
|
62
|
+
pixelBits,
|
|
63
|
+
sampleBitOffsets,
|
|
64
|
+
samplePlanes,
|
|
65
|
+
};
|
|
66
|
+
LAYOUTS_.set(image, layout);
|
|
67
|
+
return layout;
|
|
68
|
+
}
|
|
69
|
+
/** Bytes of one row of a chunk of `plane`, padded to a whole byte. */
|
|
70
|
+
export function rowBytes_(image, layout, plane) {
|
|
71
|
+
return Math.ceil((image.chunkWidth * layout.pixelBits[plane]) / 8);
|
|
72
|
+
}
|
|
73
|
+
/** Rows a chunk in row `chunkRow` holds: a tile's all, a last strip's rest. */
|
|
74
|
+
export function chunkRows_(image, chunkRow) {
|
|
75
|
+
return image.tiled
|
|
76
|
+
? image.chunkHeight
|
|
77
|
+
: Math.min(image.chunkHeight, image.height - chunkRow * image.chunkHeight);
|
|
78
|
+
}
|
|
79
|
+
//# sourceMappingURL=_layout.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"_layout.js","sourceRoot":"","sources":["../../src/raster/_layout.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAC/C,OAAO,EAAE,cAAc,EAAE,gBAAgB,EAAE,MAAM,2BAA2B,CAAC;AAC7E,OAAO,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC;AAiB/C,MAAM,QAAQ,GAAG,IAAI,OAAO,EAAsB,CAAC;AAEnD,SAAS,MAAM,CACd,KAAgB,EAChB,GAAW,EACX,IAAY,EACZ,KAAa;IAEb,MAAM,KAAK,GAAG,KAAK,CAAC,MAAM,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;IACpC,IAAI,KAAK,KAAK,SAAS,IAAI,gBAAgB,CAAC,KAAK,CAAC,GAAG,KAAK,EAAE,CAAC;QAC5D,MAAM,IAAI,eAAe,CACxB,KAAK,KAAK,SAAS;YAClB,CAAC,CAAC,oBAAoB,IAAI,EAAE;YAC5B,CAAC,CAAC,GAAG,IAAI,UAAU,gBAAgB,CAAC,KAAK,CAAC,cAAc,KAAK,EAAE,EAChE,KAAK,CAAC,MAAM,CACZ,CAAC;IACH,CAAC;IACD,MAAM,MAAM,GAAG,IAAI,YAAY,CAAC,KAAK,CAAC,CAAC;IACvC,KAAK,IAAI,KAAK,GAAG,CAAC,EAAE,KAAK,GAAG,KAAK,EAAE,KAAK,EAAE,EAAE,CAAC;QAC5C,MAAM,KAAK,GAAG,cAAc,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC;QAC3C,IAAI,CAAC,MAAM,CAAC,aAAa,CAA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C,KAAgB,EAAE,QAAgB;IAC5D,OAAO,KAAK,CAAC,KAAK;QACjB,CAAC,CAAC,KAAK,CAAC,WAAW;QACnB,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,WAAW,EAAE,KAAK,CAAC,MAAM,GAAG,QAAQ,GAAG,KAAK,CAAC,WAAW,CAAC,CAAC;AAC7E,CAAC"}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { type TypedArrayName } from "@ac-kit/core";
|
|
2
|
+
import type { TiffSampleArray } from "./tiff-sample-array.js";
|
|
3
|
+
export type { TiffSampleArray };
|
|
4
|
+
/** How one stored value (a sample, or a part of a complex one) is read. */
|
|
5
|
+
export declare enum ValueKind_ {
|
|
6
|
+
UINT8 = 0,
|
|
7
|
+
INT8 = 1,
|
|
8
|
+
UINT16 = 2,
|
|
9
|
+
INT16 = 3,
|
|
10
|
+
UINT32 = 4,
|
|
11
|
+
INT32 = 5,
|
|
12
|
+
UINT64 = 6,
|
|
13
|
+
INT64 = 7,
|
|
14
|
+
FLOAT16 = 8,
|
|
15
|
+
FLOAT24 = 9,
|
|
16
|
+
FLOAT32 = 10,
|
|
17
|
+
FLOAT64 = 11,
|
|
18
|
+
/** An unsigned integer of 1 to 31 bits not on a byte boundary. */
|
|
19
|
+
BITS_UNSIGNED = 12,
|
|
20
|
+
/** A two's complement integer of 1 to 31 bits not on a byte boundary. */
|
|
21
|
+
BITS_SIGNED = 13
|
|
22
|
+
}
|
|
23
|
+
/** A sample as the readers decode it. */
|
|
24
|
+
export type SampleKind_ = {
|
|
25
|
+
readonly value: ValueKind_;
|
|
26
|
+
/** Bits of one value: the sample's, or half a complex sample's. */
|
|
27
|
+
readonly valueBits: number;
|
|
28
|
+
/** 2 for a complex sample, 1 otherwise. */
|
|
29
|
+
readonly components: number;
|
|
30
|
+
readonly natural: TypedArrayName;
|
|
31
|
+
readonly bigInt: boolean;
|
|
32
|
+
};
|
|
33
|
+
/**
|
|
34
|
+
* How a sample of `format` and `bits` is read.
|
|
35
|
+
*
|
|
36
|
+
* @throws {TiffUnsupportedError} For a format or a width TIFF does not define
|
|
37
|
+
* or this reader does not decode.
|
|
38
|
+
*/
|
|
39
|
+
export declare function sampleKind_(format: number, bits: number): SampleKind_;
|
|
40
|
+
/**
|
|
41
|
+
* Checks that `out` may receive samples of `kind`: their natural array, or
|
|
42
|
+
* `Float64Array` for any but 64-bit integers.
|
|
43
|
+
*
|
|
44
|
+
* @throws {TypeError} For any other array.
|
|
45
|
+
*/
|
|
46
|
+
export declare function checkOutArray_(out: TiffSampleArray, kind: SampleKind_): void;
|
|
47
|
+
export declare function createArray_(natural: TypedArrayName, length: number): TiffSampleArray;
|
|
48
|
+
/** Reads `bits` (1–32) of a most-significant-bit-first stream at `position`. */
|
|
49
|
+
export declare function readBits_(data: Uint8Array, position: number, bits: number): number;
|
|
50
|
+
/** An IEEE-style 24-bit float: sign, 7 exponent bits (bias 63), 16 mantissa. */
|
|
51
|
+
export declare function float24_(bits: number): number;
|
|
52
|
+
//# sourceMappingURL=_samples.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"_samples.d.ts","sourceRoot":"","sources":["../../src/raster/_samples.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,cAAc,EAAkB,MAAM,cAAc,CAAC;AAInE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAE9D,YAAY,EAAE,eAAe,EAAE,CAAC;AAEhC,2EAA2E;AAC3E,oBAAY,UAAU;IACrB,KAAK,IAAA;IACL,IAAI,IAAA;IACJ,MAAM,IAAA;IACN,KAAK,IAAA;IACL,MAAM,IAAA;IACN,KAAK,IAAA;IACL,MAAM,IAAA;IACN,KAAK,IAAA;IACL,OAAO,IAAA;IACP,OAAO,IAAA;IACP,OAAO,KAAA;IACP,OAAO,KAAA;IACP,kEAAkE;IAClE,aAAa,KAAA;IACb,yEAAyE;IACzE,WAAW,KAAA;CACX;AAED,yCAAyC;AACzC,MAAM,MAAM,WAAW,GAAG;IACzB,QAAQ,CAAC,KAAK,EAAE,UAAU,CAAC;IAC3B,mEAAmE;IACnE,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,2CAA2C;IAC3C,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,OAAO,EAAE,cAAc,CAAC;IACjC,QAAQ,CAAC,MAAM,EAAE,OAAO,CAAC;CACzB,CAAC;AA4DF;;;;;GAKG;AACH,wBAAgB,WAAW,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,WAAW,CA6CrE;AAED;;;;;GAKG;AACH,wBAAgB,cAAc,CAAC,GAAG,EAAE,eAAe,EAAE,IAAI,EAAE,WAAW,GAAG,IAAI,CAQ5E;AAED,wBAAgB,YAAY,CAC3B,OAAO,EAAE,cAAc,EACvB,MAAM,EAAE,MAAM,GACZ,eAAe,CAuBjB;AAED,gFAAgF;AAChF,wBAAgB,SAAS,CACxB,IAAI,EAAE,UAAU,EAChB,QAAQ,EAAE,MAAM,EAChB,IAAI,EAAE,MAAM,GACV,MAAM,CAeR;AAED,gFAAgF;AAChF,wBAAgB,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAW7C"}
|
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
import { typedArrayName } from "@ac-kit/core";
|
|
2
|
+
import { TiffUnsupportedError } from "../errors.js";
|
|
3
|
+
import { TiffSampleFormat } from "../field/tiff-tag.js";
|
|
4
|
+
/** How one stored value (a sample, or a part of a complex one) is read. */
|
|
5
|
+
export var ValueKind_;
|
|
6
|
+
(function (ValueKind_) {
|
|
7
|
+
ValueKind_[ValueKind_["UINT8"] = 0] = "UINT8";
|
|
8
|
+
ValueKind_[ValueKind_["INT8"] = 1] = "INT8";
|
|
9
|
+
ValueKind_[ValueKind_["UINT16"] = 2] = "UINT16";
|
|
10
|
+
ValueKind_[ValueKind_["INT16"] = 3] = "INT16";
|
|
11
|
+
ValueKind_[ValueKind_["UINT32"] = 4] = "UINT32";
|
|
12
|
+
ValueKind_[ValueKind_["INT32"] = 5] = "INT32";
|
|
13
|
+
ValueKind_[ValueKind_["UINT64"] = 6] = "UINT64";
|
|
14
|
+
ValueKind_[ValueKind_["INT64"] = 7] = "INT64";
|
|
15
|
+
ValueKind_[ValueKind_["FLOAT16"] = 8] = "FLOAT16";
|
|
16
|
+
ValueKind_[ValueKind_["FLOAT24"] = 9] = "FLOAT24";
|
|
17
|
+
ValueKind_[ValueKind_["FLOAT32"] = 10] = "FLOAT32";
|
|
18
|
+
ValueKind_[ValueKind_["FLOAT64"] = 11] = "FLOAT64";
|
|
19
|
+
/** An unsigned integer of 1 to 31 bits not on a byte boundary. */
|
|
20
|
+
ValueKind_[ValueKind_["BITS_UNSIGNED"] = 12] = "BITS_UNSIGNED";
|
|
21
|
+
/** A two's complement integer of 1 to 31 bits not on a byte boundary. */
|
|
22
|
+
ValueKind_[ValueKind_["BITS_SIGNED"] = 13] = "BITS_SIGNED";
|
|
23
|
+
})(ValueKind_ || (ValueKind_ = {}));
|
|
24
|
+
function integerKind_(bits, signed) {
|
|
25
|
+
switch (bits) {
|
|
26
|
+
case 8:
|
|
27
|
+
return signed
|
|
28
|
+
? { value: ValueKind_.INT8, natural: "Int8Array" }
|
|
29
|
+
: { value: ValueKind_.UINT8, natural: "Uint8Array" };
|
|
30
|
+
case 16:
|
|
31
|
+
return signed
|
|
32
|
+
? { value: ValueKind_.INT16, natural: "Int16Array" }
|
|
33
|
+
: { value: ValueKind_.UINT16, natural: "Uint16Array" };
|
|
34
|
+
case 32:
|
|
35
|
+
return signed
|
|
36
|
+
? { value: ValueKind_.INT32, natural: "Int32Array" }
|
|
37
|
+
: { value: ValueKind_.UINT32, natural: "Uint32Array" };
|
|
38
|
+
case 64:
|
|
39
|
+
return signed
|
|
40
|
+
? { value: ValueKind_.INT64, natural: "BigInt64Array" }
|
|
41
|
+
: { value: ValueKind_.UINT64, natural: "BigUint64Array" };
|
|
42
|
+
default: {
|
|
43
|
+
if (!Number.isInteger(bits) || bits < 1 || bits > 31) {
|
|
44
|
+
return undefined;
|
|
45
|
+
}
|
|
46
|
+
let natural;
|
|
47
|
+
if (bits <= 8) {
|
|
48
|
+
natural = signed ? "Int8Array" : "Uint8Array";
|
|
49
|
+
}
|
|
50
|
+
else if (bits <= 16) {
|
|
51
|
+
natural = signed ? "Int16Array" : "Uint16Array";
|
|
52
|
+
}
|
|
53
|
+
else {
|
|
54
|
+
natural = signed ? "Int32Array" : "Uint32Array";
|
|
55
|
+
}
|
|
56
|
+
return {
|
|
57
|
+
value: signed ? ValueKind_.BITS_SIGNED : ValueKind_.BITS_UNSIGNED,
|
|
58
|
+
natural,
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
function floatKind_(bits) {
|
|
64
|
+
switch (bits) {
|
|
65
|
+
case 16:
|
|
66
|
+
return { value: ValueKind_.FLOAT16, natural: "Float32Array" };
|
|
67
|
+
case 24:
|
|
68
|
+
return { value: ValueKind_.FLOAT24, natural: "Float32Array" };
|
|
69
|
+
case 32:
|
|
70
|
+
return { value: ValueKind_.FLOAT32, natural: "Float32Array" };
|
|
71
|
+
case 64:
|
|
72
|
+
return { value: ValueKind_.FLOAT64, natural: "Float64Array" };
|
|
73
|
+
default:
|
|
74
|
+
return undefined;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* How a sample of `format` and `bits` is read.
|
|
79
|
+
*
|
|
80
|
+
* @throws {TiffUnsupportedError} For a format or a width TIFF does not define
|
|
81
|
+
* or this reader does not decode.
|
|
82
|
+
*/
|
|
83
|
+
export function sampleKind_(format, bits) {
|
|
84
|
+
let kind;
|
|
85
|
+
let components = 1;
|
|
86
|
+
switch (format) {
|
|
87
|
+
case TiffSampleFormat.UNSIGNED_INTEGER:
|
|
88
|
+
case TiffSampleFormat.UNDEFINED:
|
|
89
|
+
kind = integerKind_(bits, false);
|
|
90
|
+
break;
|
|
91
|
+
case TiffSampleFormat.SIGNED_INTEGER:
|
|
92
|
+
kind = integerKind_(bits, true);
|
|
93
|
+
break;
|
|
94
|
+
case TiffSampleFormat.FLOATING_POINT:
|
|
95
|
+
kind = floatKind_(bits);
|
|
96
|
+
break;
|
|
97
|
+
case TiffSampleFormat.COMPLEX_SIGNED_INTEGER:
|
|
98
|
+
components = 2;
|
|
99
|
+
kind =
|
|
100
|
+
bits === 16 || bits === 32 || bits === 64
|
|
101
|
+
? integerKind_(bits / 2, true)
|
|
102
|
+
: undefined;
|
|
103
|
+
break;
|
|
104
|
+
case TiffSampleFormat.COMPLEX_FLOATING_POINT:
|
|
105
|
+
components = 2;
|
|
106
|
+
kind =
|
|
107
|
+
bits === 32 || bits === 64 || bits === 128
|
|
108
|
+
? floatKind_(bits / 2)
|
|
109
|
+
: undefined;
|
|
110
|
+
break;
|
|
111
|
+
default:
|
|
112
|
+
throw new TiffUnsupportedError(`SampleFormat ${format}`, format);
|
|
113
|
+
}
|
|
114
|
+
if (kind === undefined) {
|
|
115
|
+
throw new TiffUnsupportedError(`A sample of ${bits} bits in SampleFormat ${format}`, bits);
|
|
116
|
+
}
|
|
117
|
+
return {
|
|
118
|
+
value: kind.value,
|
|
119
|
+
valueBits: bits / components,
|
|
120
|
+
components,
|
|
121
|
+
natural: kind.natural,
|
|
122
|
+
bigInt: kind.natural === "BigInt64Array" || kind.natural === "BigUint64Array",
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Checks that `out` may receive samples of `kind`: their natural array, or
|
|
127
|
+
* `Float64Array` for any but 64-bit integers.
|
|
128
|
+
*
|
|
129
|
+
* @throws {TypeError} For any other array.
|
|
130
|
+
*/
|
|
131
|
+
export function checkOutArray_(out, kind) {
|
|
132
|
+
const name = typedArrayName(out);
|
|
133
|
+
if (name === kind.natural || (name === "Float64Array" && !kind.bigInt)) {
|
|
134
|
+
return;
|
|
135
|
+
}
|
|
136
|
+
throw new TypeError(`A ${name ?? typeof out} for samples read into a ${kind.natural}${kind.bigInt ? "" : " or a Float64Array"}`);
|
|
137
|
+
}
|
|
138
|
+
export function createArray_(natural, length) {
|
|
139
|
+
switch (natural) {
|
|
140
|
+
case "Int8Array":
|
|
141
|
+
return new Int8Array(length);
|
|
142
|
+
case "Uint16Array":
|
|
143
|
+
return new Uint16Array(length);
|
|
144
|
+
case "Int16Array":
|
|
145
|
+
return new Int16Array(length);
|
|
146
|
+
case "Uint32Array":
|
|
147
|
+
return new Uint32Array(length);
|
|
148
|
+
case "Int32Array":
|
|
149
|
+
return new Int32Array(length);
|
|
150
|
+
case "Float32Array":
|
|
151
|
+
return new Float32Array(length);
|
|
152
|
+
case "Float64Array":
|
|
153
|
+
return new Float64Array(length);
|
|
154
|
+
case "BigUint64Array":
|
|
155
|
+
return new BigUint64Array(length);
|
|
156
|
+
case "BigInt64Array":
|
|
157
|
+
return new BigInt64Array(length);
|
|
158
|
+
default:
|
|
159
|
+
return new Uint8Array(length);
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
/** Reads `bits` (1–32) of a most-significant-bit-first stream at `position`. */
|
|
163
|
+
export function readBits_(data, position, bits) {
|
|
164
|
+
let value = 0;
|
|
165
|
+
let at = position;
|
|
166
|
+
let remaining = bits;
|
|
167
|
+
while (remaining > 0) {
|
|
168
|
+
const offset = at & 7;
|
|
169
|
+
const take = Math.min(8 - offset, remaining);
|
|
170
|
+
const byte = data[at >>> 3];
|
|
171
|
+
value =
|
|
172
|
+
value * (1 << take) +
|
|
173
|
+
((byte >>> (8 - offset - take)) & ((1 << take) - 1));
|
|
174
|
+
at += take;
|
|
175
|
+
remaining -= take;
|
|
176
|
+
}
|
|
177
|
+
return value;
|
|
178
|
+
}
|
|
179
|
+
/** An IEEE-style 24-bit float: sign, 7 exponent bits (bias 63), 16 mantissa. */
|
|
180
|
+
export function float24_(bits) {
|
|
181
|
+
const sign = bits >>> 23 === 1 ? -1 : 1;
|
|
182
|
+
const exponent = (bits >>> 16) & 0x7f;
|
|
183
|
+
const mantissa = bits & 0xffff;
|
|
184
|
+
if (exponent === 0) {
|
|
185
|
+
return sign * mantissa * 2 ** (1 - 63 - 16);
|
|
186
|
+
}
|
|
187
|
+
if (exponent === 0x7f) {
|
|
188
|
+
return mantissa === 0 ? sign * Number.POSITIVE_INFINITY : Number.NaN;
|
|
189
|
+
}
|
|
190
|
+
return sign * (1 + mantissa / 0x10000) * 2 ** (exponent - 63);
|
|
191
|
+
}
|
|
192
|
+
//# sourceMappingURL=_samples.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"_samples.js","sourceRoot":"","sources":["../../src/raster/_samples.ts"],"names":[],"mappings":"AAAA,OAAO,EAAuB,cAAc,EAAE,MAAM,cAAc,CAAC;AAEnE,OAAO,EAAE,oBAAoB,EAAE,MAAM,cAAc,CAAC;AACpD,OAAO,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AAKxD,2EAA2E;AAC3E,MAAM,CAAN,IAAY,UAiBX;AAjBD,WAAY,UAAU;IACrB,6CAAK,CAAA;IACL,2CAAI,CAAA;IACJ,+CAAM,CAAA;IACN,6CAAK,CAAA;IACL,+CAAM,CAAA;IACN,6CAAK,CAAA;IACL,+CAAM,CAAA;IACN,6CAAK,CAAA;IACL,iDAAO,CAAA;IACP,iDAAO,CAAA;IACP,kDAAO,CAAA;IACP,kDAAO,CAAA;IACP,kEAAkE;IAClE,8DAAa,CAAA;IACb,yEAAyE;IACzE,0DAAW,CAAA;AACZ,CAAC,EAjBW,UAAU,KAAV,UAAU,QAiBrB;AAaD,SAAS,YAAY,CACpB,IAAY,EACZ,MAAe;IAEf,QAAQ,IAAI,EAAE,CAAC;QACd,KAAK,CAAC;YACL,OAAO,MAAM;gBACZ,CAAC,CAAC,EAAE,KAAK,EAAE,UAAU,CAAC,IAAI,EAAE,OAAO,EAAE,WAAW,EAAE;gBAClD,CAAC,CA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
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import type { TiffDecoders } from "../codec/tiff-decoder.js";
|
|
2
|
+
import type { TiffImage } from "../container/tiff.js";
|
|
3
|
+
import { type TiffSampleArray } from "./_samples.js";
|
|
4
|
+
/** A rectangle of pixels: `x`, `y` of its top-left pixel, then its size. */
|
|
5
|
+
export type TiffWindow = {
|
|
6
|
+
readonly x: number;
|
|
7
|
+
readonly y: number;
|
|
8
|
+
readonly width: number;
|
|
9
|
+
readonly height: number;
|
|
10
|
+
};
|
|
11
|
+
/** Options of {@link readTiffWindow} and {@link readTiffTile}. */
|
|
12
|
+
export type TiffReadOptions = {
|
|
13
|
+
/**
|
|
14
|
+
* The one sample (band) to read, from 0. Without it every sample is read,
|
|
15
|
+
* pixel-interleaved, which needs them all of one natural array type.
|
|
16
|
+
*/
|
|
17
|
+
readonly band?: number | undefined;
|
|
18
|
+
readonly signal?: AbortSignal | undefined;
|
|
19
|
+
/** Decoders by `Compression` value, for codecs not built in. */
|
|
20
|
+
readonly decoders?: TiffDecoders | undefined;
|
|
21
|
+
/**
|
|
22
|
+
* Largest gap, in bytes, between two chunks read in one request: 4096 by
|
|
23
|
+
* default, past a COG's 4-byte block leaders and trailers.
|
|
24
|
+
*/
|
|
25
|
+
readonly maxGapBytes?: number | undefined;
|
|
26
|
+
/** Largest request when chunks are read together: 16 MiB by default. */
|
|
27
|
+
readonly maxReadBytes?: number | undefined;
|
|
28
|
+
};
|
|
29
|
+
/**
|
|
30
|
+
* Reads a window of an image into `out`, row by row from its top-left pixel:
|
|
31
|
+
* `window.width × window.height` pixels, each one value of `band`, or every
|
|
32
|
+
* sample in order without it, and two values (real, imaginary) per complex
|
|
33
|
+
* sample. Samples are as stored, with no photometric conversion; a sparse chunk
|
|
34
|
+
* (offset and byte count 0, as GDAL writes it) reads as `noDataValue`, or 0
|
|
35
|
+
* without one.
|
|
36
|
+
*
|
|
37
|
+
* Only the strips or tiles the window touches are read, sorted by offset and
|
|
38
|
+
* read together where the gap between them is at most `maxGapBytes`, up to
|
|
39
|
+
* `maxReadBytes` per request: a COG window is one read per run of adjacent
|
|
40
|
+
* tiles. Chunks decode with the built-in codecs (none, PackBits, LZW, Deflate
|
|
41
|
+
* through `DecompressionStream`) and predictors (2, 3), or with
|
|
42
|
+
* `options.decoders`.
|
|
43
|
+
*
|
|
44
|
+
* `out` is the samples' natural array ({@link createTiffSampleArray} makes
|
|
45
|
+
* one): `Uint8Array` to `Uint32Array` and `Int8Array` to `Int32Array` for
|
|
46
|
+
* integers up to 8, 16 and 32 bits, `BigUint64Array`/`BigInt64Array` for 64,
|
|
47
|
+
* `Float32Array` for 16-, 24- and 32-bit floats, `Float64Array` for 64-bit
|
|
48
|
+
* ones; a `Float64Array` also takes any but 64-bit integers.
|
|
49
|
+
*
|
|
50
|
+
* Time linear in the chunks touched; memory one run of stored chunks and one
|
|
51
|
+
* decoded chunk at a time.
|
|
52
|
+
*
|
|
53
|
+
* @example
|
|
54
|
+
* const window = { x: 570, y: 70, width: 750, height: 930 };
|
|
55
|
+
* const heights = await readTiffWindow(
|
|
56
|
+
* image,
|
|
57
|
+
* window,
|
|
58
|
+
* new Float32Array(window.width * window.height),
|
|
59
|
+
* { band: 0 },
|
|
60
|
+
* );
|
|
61
|
+
*
|
|
62
|
+
* @returns `out`.
|
|
63
|
+
* @throws {RangeError} When the window is not inside the image, `band` is not
|
|
64
|
+
* one of its samples, or `out` is too short.
|
|
65
|
+
* @throws {TypeError} When `out` is not an array the samples may be read into,
|
|
66
|
+
* the image did not come from {@link openTiff}, an option is not a safe
|
|
67
|
+
* non-negative integer, or without `band` the samples differ in type.
|
|
68
|
+
* @throws {TiffFormatError} When the offsets or byte counts are missing or
|
|
69
|
+
* short, a chunk lies past the end of the file, or its data is corrupt or
|
|
70
|
+
* decodes to fewer bytes than its rows hold.
|
|
71
|
+
* @throws {TiffLimitError} When a chunk is larger than `maxTileBytes` stored or
|
|
72
|
+
* `maxDecodedBytes` decoded.
|
|
73
|
+
* @throws {TiffUnsupportedError} When the compression has no decoder, or the
|
|
74
|
+
* predictor, sample format or YCbCr subsampling is not one this reads.
|
|
75
|
+
* @throws When `signal` aborts, its reason; the source's or a decoder's error.
|
|
76
|
+
*/
|
|
77
|
+
export declare function readTiffWindow<T extends TiffSampleArray>(image: TiffImage, window: TiffWindow, out: T, options?: TiffReadOptions): Promise<T>;
|
|
78
|
+
/**
|
|
79
|
+
* Reads one tile, or one strip, into `out` as {@link readTiffWindow} reads a
|
|
80
|
+
* window: `chunkWidth × chunkHeight` pixels for a tile, its padding past the
|
|
81
|
+
* image's edge included, or `width ×` the strip's rows (fewer for the last
|
|
82
|
+
* one). `column` and `row` count tiles from the top left; a strip is `(0,
|
|
83
|
+
* strip)`.
|
|
84
|
+
*
|
|
85
|
+
* @returns `out`.
|
|
86
|
+
* @throws {RangeError} When there is no such tile or strip; what
|
|
87
|
+
* {@link readTiffWindow} throws otherwise.
|
|
88
|
+
*/
|
|
89
|
+
export declare function readTiffTile<T extends TiffSampleArray>(image: TiffImage, column: number, row: number, out: T, options?: TiffReadOptions): Promise<T>;
|
|
90
|
+
/**
|
|
91
|
+
* Makes the natural array for `pixels` pixels of `band` of `image`, or of every
|
|
92
|
+
* sample interleaved without it: `pixels × samples × 2` values for complex
|
|
93
|
+
* samples, `pixels × samples` otherwise. See {@link readTiffWindow} for which
|
|
94
|
+
* array each sample format takes.
|
|
95
|
+
*
|
|
96
|
+
* @example
|
|
97
|
+
* const out = createTiffSampleArray(
|
|
98
|
+
* image,
|
|
99
|
+
* image.chunkWidth * image.chunkHeight,
|
|
100
|
+
* );
|
|
101
|
+
* await readTiffTile(image, 0, 0, out);
|
|
102
|
+
*
|
|
103
|
+
* @throws {RangeError} When `pixels` is not a safe non-negative integer or
|
|
104
|
+
* `band` not one of the samples.
|
|
105
|
+
* @throws {TypeError} Without `band`, when the samples differ in type.
|
|
106
|
+
* @throws {TiffUnsupportedError} When the sample format is not one this reads.
|
|
107
|
+
*/
|
|
108
|
+
export declare function createTiffSampleArray(image: TiffImage, pixels: number, band?: number): TiffSampleArray;
|
|
109
|
+
//# sourceMappingURL=read-tiff-window.d.ts.map
|