@loaders.gl/geotiff 4.2.0-alpha.4 → 4.2.0-alpha.6
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/dist.dev.js +222 -284
- package/dist/dist.min.js +30 -0
- package/dist/geotiff-loader.js +71 -52
- package/dist/index.cjs +23 -20
- package/dist/index.cjs.map +7 -0
- package/dist/index.d.ts +3 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -1
- package/dist/lib/load-geotiff.d.ts +1 -1
- package/dist/lib/load-geotiff.d.ts.map +1 -1
- package/dist/lib/load-geotiff.js +57 -21
- package/dist/lib/ome/load-ome-tiff.d.ts +1 -1
- package/dist/lib/ome/load-ome-tiff.d.ts.map +1 -1
- package/dist/lib/ome/load-ome-tiff.js +35 -41
- package/dist/lib/ome/ome-indexers.d.ts +1 -1
- package/dist/lib/ome/ome-indexers.d.ts.map +1 -1
- package/dist/lib/ome/ome-indexers.js +102 -114
- package/dist/lib/ome/ome-utils.d.ts +1 -1
- package/dist/lib/ome/ome-utils.d.ts.map +1 -1
- package/dist/lib/ome/ome-utils.js +56 -60
- package/dist/lib/ome/omexml.js +53 -55
- package/dist/lib/ome/utils.d.ts +2 -2
- package/dist/lib/ome/utils.d.ts.map +1 -1
- package/dist/lib/ome/utils.js +23 -12
- package/dist/lib/tiff-pixel-source.d.ts +1 -1
- package/dist/lib/tiff-pixel-source.d.ts.map +1 -1
- package/dist/lib/tiff-pixel-source.js +64 -84
- package/dist/lib/utils/tiff-utils.d.ts +1 -1
- package/dist/lib/utils/tiff-utils.d.ts.map +1 -1
- package/dist/lib/utils/tiff-utils.js +31 -18
- package/dist/loaders.js +40 -27
- package/dist/types.d.ts +1 -1
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +3 -1
- package/package.json +9 -4
- package/dist/geotiff-loader.js.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/lib/load-geotiff.js.map +0 -1
- package/dist/lib/ome/load-ome-tiff.js.map +0 -1
- package/dist/lib/ome/ome-indexers.js.map +0 -1
- package/dist/lib/ome/ome-utils.js.map +0 -1
- package/dist/lib/ome/omexml.js.map +0 -1
- package/dist/lib/ome/utils.js.map +0 -1
- package/dist/lib/tiff-pixel-source.js.map +0 -1
- package/dist/lib/utils/Pool.ts.disabled +0 -99
- package/dist/lib/utils/decoder.worker.ts.disabled +0 -21
- package/dist/lib/utils/proxies.ts.disabled +0 -96
- package/dist/lib/utils/tiff-utils.js.map +0 -1
- package/dist/loaders.js.map +0 -1
- package/dist/types.js.map +0 -1
|
@@ -1,90 +1,70 @@
|
|
|
1
|
+
// loaders.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// Copyright (c) vis.gl contributors
|
|
1
4
|
import { getImageSize, isInterleaved, SIGNAL_ABORTED } from "./utils/tiff-utils.js";
|
|
2
5
|
export class TiffPixelSource {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
async getRaster(_ref) {
|
|
18
|
-
let {
|
|
19
|
-
selection,
|
|
20
|
-
signal
|
|
21
|
-
} = _ref;
|
|
22
|
-
const image = await this._indexer(selection);
|
|
23
|
-
return this._readRasters(image, {
|
|
24
|
-
signal
|
|
25
|
-
});
|
|
26
|
-
}
|
|
27
|
-
async getTile(_ref2) {
|
|
28
|
-
let {
|
|
29
|
-
x,
|
|
30
|
-
y,
|
|
31
|
-
selection,
|
|
32
|
-
signal
|
|
33
|
-
} = _ref2;
|
|
34
|
-
const {
|
|
35
|
-
height,
|
|
36
|
-
width
|
|
37
|
-
} = this._getTileExtent(x, y);
|
|
38
|
-
const x0 = x * this.tileSize;
|
|
39
|
-
const y0 = y * this.tileSize;
|
|
40
|
-
const window = [x0, y0, x0 + width, y0 + height];
|
|
41
|
-
const image = await this._indexer(selection);
|
|
42
|
-
return this._readRasters(image, {
|
|
43
|
-
window,
|
|
44
|
-
width,
|
|
45
|
-
height,
|
|
46
|
-
signal
|
|
47
|
-
});
|
|
48
|
-
}
|
|
49
|
-
async _readRasters(image, props) {
|
|
50
|
-
var _props$signal;
|
|
51
|
-
const interleave = isInterleaved(this.shape);
|
|
52
|
-
const raster = await image.readRasters({
|
|
53
|
-
interleave,
|
|
54
|
-
...props
|
|
55
|
-
});
|
|
56
|
-
if (props !== null && props !== void 0 && (_props$signal = props.signal) !== null && _props$signal !== void 0 && _props$signal.aborted) {
|
|
57
|
-
throw SIGNAL_ABORTED;
|
|
6
|
+
dtype;
|
|
7
|
+
tileSize;
|
|
8
|
+
shape;
|
|
9
|
+
labels;
|
|
10
|
+
meta;
|
|
11
|
+
_indexer;
|
|
12
|
+
// eslint-disable-next-line max-params
|
|
13
|
+
constructor(indexer, dtype, tileSize, shape, labels, meta) {
|
|
14
|
+
this._indexer = indexer;
|
|
15
|
+
this.dtype = dtype;
|
|
16
|
+
this.tileSize = tileSize;
|
|
17
|
+
this.shape = shape;
|
|
18
|
+
this.labels = labels;
|
|
19
|
+
this.meta = meta;
|
|
58
20
|
}
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
width: raster.width,
|
|
63
|
-
height: raster.height
|
|
64
|
-
};
|
|
65
|
-
}
|
|
66
|
-
_getTileExtent(x, y) {
|
|
67
|
-
const {
|
|
68
|
-
height: zoomLevelHeight,
|
|
69
|
-
width: zoomLevelWidth
|
|
70
|
-
} = getImageSize(this);
|
|
71
|
-
let height = this.tileSize;
|
|
72
|
-
let width = this.tileSize;
|
|
73
|
-
const maxXTileCoord = Math.floor(zoomLevelWidth / this.tileSize);
|
|
74
|
-
const maxYTileCoord = Math.floor(zoomLevelHeight / this.tileSize);
|
|
75
|
-
if (x === maxXTileCoord) {
|
|
76
|
-
width = zoomLevelWidth % this.tileSize;
|
|
21
|
+
async getRaster({ selection, signal }) {
|
|
22
|
+
const image = await this._indexer(selection);
|
|
23
|
+
return this._readRasters(image, { signal });
|
|
77
24
|
}
|
|
78
|
-
|
|
79
|
-
|
|
25
|
+
async getTile({ x, y, selection, signal }) {
|
|
26
|
+
const { height, width } = this._getTileExtent(x, y);
|
|
27
|
+
const x0 = x * this.tileSize;
|
|
28
|
+
const y0 = y * this.tileSize;
|
|
29
|
+
const window = [x0, y0, x0 + width, y0 + height];
|
|
30
|
+
const image = await this._indexer(selection);
|
|
31
|
+
return this._readRasters(image, { window, width, height, signal });
|
|
32
|
+
}
|
|
33
|
+
async _readRasters(image, props) {
|
|
34
|
+
const interleave = isInterleaved(this.shape);
|
|
35
|
+
const raster = await image.readRasters({ interleave, ...props });
|
|
36
|
+
if (props?.signal?.aborted) {
|
|
37
|
+
throw SIGNAL_ABORTED;
|
|
38
|
+
}
|
|
39
|
+
/*
|
|
40
|
+
* geotiff.js returns objects with different structure
|
|
41
|
+
* depending on `interleave`. It's weird, but this seems to work.
|
|
42
|
+
*/
|
|
43
|
+
const data = (interleave ? raster : raster[0]);
|
|
44
|
+
return {
|
|
45
|
+
data,
|
|
46
|
+
width: raster.width,
|
|
47
|
+
height: raster.height
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
/*
|
|
51
|
+
* Computes tile size given x, y coord.
|
|
52
|
+
*/
|
|
53
|
+
_getTileExtent(x, y) {
|
|
54
|
+
const { height: zoomLevelHeight, width: zoomLevelWidth } = getImageSize(this);
|
|
55
|
+
let height = this.tileSize;
|
|
56
|
+
let width = this.tileSize;
|
|
57
|
+
const maxXTileCoord = Math.floor(zoomLevelWidth / this.tileSize);
|
|
58
|
+
const maxYTileCoord = Math.floor(zoomLevelHeight / this.tileSize);
|
|
59
|
+
if (x === maxXTileCoord) {
|
|
60
|
+
width = zoomLevelWidth % this.tileSize;
|
|
61
|
+
}
|
|
62
|
+
if (y === maxYTileCoord) {
|
|
63
|
+
height = zoomLevelHeight % this.tileSize;
|
|
64
|
+
}
|
|
65
|
+
return { height, width };
|
|
66
|
+
}
|
|
67
|
+
onTileError(err) {
|
|
68
|
+
console.error(err); // eslint-disable-line no-console
|
|
80
69
|
}
|
|
81
|
-
return {
|
|
82
|
-
height,
|
|
83
|
-
width
|
|
84
|
-
};
|
|
85
|
-
}
|
|
86
|
-
onTileError(err) {
|
|
87
|
-
console.error(err);
|
|
88
|
-
}
|
|
89
70
|
}
|
|
90
|
-
//# sourceMappingURL=tiff-pixel-source.js.map
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { PixelSource } from
|
|
1
|
+
import type { PixelSource } from "../../types.js";
|
|
2
2
|
export declare function ensureArray<T>(x: T | T[]): T[];
|
|
3
3
|
export declare function intToRgba(int: number): [number, number, number, number];
|
|
4
4
|
export declare function isInterleaved(shape: number[]): boolean;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tiff-utils.d.ts","sourceRoot":"","sources":["../../../src/lib/utils/tiff-utils.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAC,WAAW,EAAC,
|
|
1
|
+
{"version":3,"file":"tiff-utils.d.ts","sourceRoot":"","sources":["../../../src/lib/utils/tiff-utils.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAC,WAAW,EAAC,uBAAoB;AAE7C,wBAAgB,WAAW,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,GAAG,CAAC,EAAE,OAExC;AASD,wBAAgB,SAAS,CAAC,GAAG,EAAE,MAAM,oCAapC;AAOD,wBAAgB,aAAa,CAAC,KAAK,EAAE,MAAM,EAAE,WAG5C;AAED,wBAAgB,YAAY,CAAC,CAAC,SAAS,MAAM,EAAE,EAAE,MAAM,EAAE,WAAW,CAAC,CAAC,CAAC;;;EAItE;AAED,eAAO,MAAM,cAAc,uBAAuB,CAAC"}
|
|
@@ -1,27 +1,40 @@
|
|
|
1
|
+
// loaders.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// Copyright (c) vis.gl contributors
|
|
1
4
|
export function ensureArray(x) {
|
|
2
|
-
|
|
5
|
+
return Array.isArray(x) ? x : [x];
|
|
3
6
|
}
|
|
7
|
+
/*
|
|
8
|
+
* Converts 32-bit integer color representation to RGBA tuple.
|
|
9
|
+
* Used to serialize colors from OME-XML metadata.
|
|
10
|
+
*
|
|
11
|
+
* > console.log(intToRgba(100100));
|
|
12
|
+
* > // [0, 1, 135, 4]
|
|
13
|
+
*/
|
|
4
14
|
export function intToRgba(int) {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
15
|
+
if (!Number.isInteger(int)) {
|
|
16
|
+
throw Error('Not an integer.');
|
|
17
|
+
}
|
|
18
|
+
// Write number to int32 representation (4 bytes).
|
|
19
|
+
const buffer = new ArrayBuffer(4);
|
|
20
|
+
const view = new DataView(buffer);
|
|
21
|
+
view.setInt32(0, int, false); // offset === 0, littleEndian === false
|
|
22
|
+
// Take u8 view and extract number for each byte (1 byte for R/G/B/A).
|
|
23
|
+
const bytes = new Uint8Array(buffer);
|
|
24
|
+
return Array.from(bytes);
|
|
13
25
|
}
|
|
26
|
+
/*
|
|
27
|
+
* Helper method to determine whether pixel data is interleaved or not.
|
|
28
|
+
* > isInterleaved([1, 24, 24]) === false;
|
|
29
|
+
* > isInterleaved([1, 24, 24, 3]) === true;
|
|
30
|
+
*/
|
|
14
31
|
export function isInterleaved(shape) {
|
|
15
|
-
|
|
16
|
-
|
|
32
|
+
const lastDimSize = shape[shape.length - 1];
|
|
33
|
+
return lastDimSize === 3 || lastDimSize === 4;
|
|
17
34
|
}
|
|
18
35
|
export function getImageSize(source) {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
height,
|
|
23
|
-
width
|
|
24
|
-
};
|
|
36
|
+
const interleaved = isInterleaved(source.shape);
|
|
37
|
+
const [height, width] = source.shape.slice(interleaved ? -3 : -2);
|
|
38
|
+
return { height, width };
|
|
25
39
|
}
|
|
26
40
|
export const SIGNAL_ABORTED = '__vivSignalAborted';
|
|
27
|
-
//# sourceMappingURL=tiff-utils.js.map
|
package/dist/loaders.js
CHANGED
|
@@ -1,32 +1,45 @@
|
|
|
1
1
|
import { fromArrayBuffer } from 'geotiff';
|
|
2
|
-
|
|
2
|
+
// __VERSION__ is injected by babel-plugin-version-inline
|
|
3
|
+
// @ts-ignore TS2304: Cannot find name '__VERSION__'.
|
|
4
|
+
const VERSION = typeof "4.2.0-alpha.5" !== 'undefined' ? "4.2.0-alpha.5" : 'latest';
|
|
5
|
+
/**
|
|
6
|
+
* Loads a GeoTIFF file containing a RGB image.
|
|
7
|
+
*/
|
|
3
8
|
const loadGeoTiff = async (data, options) => {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
height
|
|
18
|
-
|
|
9
|
+
// Load using Geotiff.js
|
|
10
|
+
const tiff = await fromArrayBuffer(data);
|
|
11
|
+
// Assumes we only have one image inside TIFF
|
|
12
|
+
const image = await tiff.getImage();
|
|
13
|
+
// Read image and size
|
|
14
|
+
// TODO: Add support for worker pools here.
|
|
15
|
+
// TODO: Add support for more image formats.
|
|
16
|
+
const rgbData = await image.readRGB({
|
|
17
|
+
enableAlpha: options?.enableAlpha
|
|
18
|
+
});
|
|
19
|
+
const width = image.getWidth();
|
|
20
|
+
const height = image.getHeight();
|
|
21
|
+
// Create a new ImageData object
|
|
22
|
+
const imageData = new ImageData(width, height);
|
|
23
|
+
imageData.data.set(new Uint8ClampedArray(rgbData));
|
|
24
|
+
// Return GeoJSON data
|
|
25
|
+
return {
|
|
26
|
+
// TODO: Add bounds here
|
|
27
|
+
bounds: [],
|
|
28
|
+
imageData,
|
|
29
|
+
width,
|
|
30
|
+
height
|
|
31
|
+
};
|
|
19
32
|
};
|
|
33
|
+
// Export loader
|
|
20
34
|
export const GeoTiffLoader = {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
35
|
+
id: 'geotiff',
|
|
36
|
+
name: 'GeoTIFF',
|
|
37
|
+
module: 'geotiff',
|
|
38
|
+
version: VERSION,
|
|
39
|
+
options: {
|
|
40
|
+
enableAlpha: true
|
|
41
|
+
},
|
|
42
|
+
mimeTypes: ['image/tiff', 'image/geotiff'],
|
|
43
|
+
extensions: ['geotiff', 'tiff', 'geotif', 'tif'],
|
|
44
|
+
parse: loadGeoTiff
|
|
31
45
|
};
|
|
32
|
-
//# sourceMappingURL=loaders.js.map
|
package/dist/types.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { DTYPE_LOOKUP } from
|
|
1
|
+
import { DTYPE_LOOKUP } from "./lib/ome/ome-utils.js";
|
|
2
2
|
export type Dtype = (typeof DTYPE_LOOKUP)[keyof typeof DTYPE_LOOKUP];
|
|
3
3
|
export type TypedArray = InstanceType<(typeof globalThis)[`${Dtype}Array`]>;
|
|
4
4
|
export interface PixelData {
|
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAIA,OAAO,EAAC,YAAY,EAAC
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAIA,OAAO,EAAC,YAAY,EAAC,+BAA4B;AAEjD,MAAM,MAAM,KAAK,GAAG,CAAC,OAAO,YAAY,CAAC,CAAC,MAAM,OAAO,YAAY,CAAC,CAAC;AACrE,MAAM,MAAM,UAAU,GAAG,YAAY,CAAC,CAAC,OAAO,UAAU,CAAC,CAAC,GAAG,KAAK,OAAO,CAAC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CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,SAAS,CAAC,CAAC;IACnD,WAAW,CAAC,GAAG,EAAE,KAAK,GAAG,IAAI,CAAC;IAC9B,KAAK,EAAE,MAAM,EAAE,CAAC;IAChB,KAAK,EAAE,KAAK,CAAC;IACb,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC,CAAC;IAClB,QAAQ,EAAE,MAAM,CAAC;IACjB,IAAI,CAAC,EAAE,eAAe,CAAC;CACxB"}
|
package/dist/types.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@loaders.gl/geotiff",
|
|
3
|
-
"version": "4.2.0-alpha.
|
|
3
|
+
"version": "4.2.0-alpha.6",
|
|
4
4
|
"description": "Framework-independent loaders for tiff and geotiff",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -38,15 +38,20 @@
|
|
|
38
38
|
"README.md"
|
|
39
39
|
],
|
|
40
40
|
"scripts": {
|
|
41
|
-
"pre-build": "npm run build-bundle && npm run build-bundle
|
|
42
|
-
"build-bundle": "ocular-bundle ./
|
|
41
|
+
"pre-build": "npm run build-bundle && npm run build-bundle-dev",
|
|
42
|
+
"build-bundle": "ocular-bundle ./bundle.ts --output=dist/dist.min.js",
|
|
43
|
+
"build-bundle-dev": "ocular-bundle ./bundle.ts --env=dev --output=dist/dist.dev.js"
|
|
43
44
|
},
|
|
44
45
|
"dependencies-disabled": {
|
|
45
46
|
"geotiff": "ilan-gold/geotiff.js#ilan-gold/viv_094"
|
|
46
47
|
},
|
|
47
48
|
"dependencies": {
|
|
49
|
+
"@loaders.gl/loader-utils": "4.2.0-alpha.6",
|
|
48
50
|
"fast-xml-parser": "^4.2.5",
|
|
49
51
|
"geotiff": "^2.1.0"
|
|
50
52
|
},
|
|
51
|
-
"
|
|
53
|
+
"peerDependencies": {
|
|
54
|
+
"@loaders.gl/core": "^4.0.0"
|
|
55
|
+
},
|
|
56
|
+
"gitHead": "37bd8ca71763529f18727ee4bf29dd176aa914ca"
|
|
52
57
|
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"geotiff-loader.js","names":["fromArrayBuffer","VERSION","GeoTIFFLoader","id","name","module","version","options","enableAlpha","mimeTypes","extensions","parse","parseGeoTIFF","isTiff","arrayBuffer","dataView","DataView","endianness","getUint16","littleEndian","data","_options$geotiff","tiff","image","getImage","rgbData","readRGB","geotiff","width","getWidth","height","getHeight","imageData","Uint8ClampedArray","bounds","getBoundingBox","metadata","getGeoKeys","crs","ProjectedCSTypeGeoKey"],"sources":["../src/geotiff-loader.ts"],"sourcesContent":["// loaders.gl\n// SPDX-License-Identifier: MIT\n// Copyright (c) vis.gl contributors\n\nimport type {TypedArray} from '@loaders.gl/loader-utils';\nimport type {LoaderWithParser, LoaderOptions} from '@loaders.gl/loader-utils';\nimport {fromArrayBuffer} from 'geotiff';\n\n// __VERSION__ is injected by babel-plugin-version-inline\n// @ts-ignore TS2304: Cannot find name '__VERSION__'.\nconst VERSION = typeof __VERSION__ !== 'undefined' ? __VERSION__ : 'latest';\n\n// Return type definition for GeoTIFF loader\ntype GeoTIFFData = {\n crs?: string;\n bounds: number[];\n metadata: Record<string, unknown>;\n\n width: number;\n height: number;\n data: TypedArray;\n};\n\n/** GeoTIFF load options */\nexport type GeoTIFFLoaderOptions = LoaderOptions & {\n geotiff?: {\n enableAlpha: boolean;\n };\n};\n\n/** GeoTIFF loader */\nexport const GeoTIFFLoader: LoaderWithParser<GeoTIFFData, never, GeoTIFFLoaderOptions> = {\n id: 'geotiff',\n name: 'GeoTIFF',\n module: 'geotiff',\n version: VERSION,\n options: {\n enableAlpha: true\n },\n mimeTypes: ['image/tiff', 'image/geotiff'],\n extensions: ['geotiff', 'tiff', 'geotif', 'tif'],\n parse: parseGeoTIFF\n};\n\nexport function isTiff(arrayBuffer: ArrayBuffer): boolean {\n const dataView = new DataView(arrayBuffer);\n // Byte offset\n const endianness = dataView.getUint16(0);\n let littleEndian: boolean;\n switch (endianness) {\n case 0x4949:\n littleEndian = true;\n break;\n case 0x4d4d:\n littleEndian = false;\n break;\n default:\n return false;\n // throw new Error(`invalid byte order: 0x${endianness.toString(16)}`);\n }\n\n // Magic number\n if (dataView.getUint16(2, littleEndian) !== 42) {\n return false;\n }\n\n return true;\n}\n\n/**\n * Loads a GeoTIFF file containing a RGB image.\n */\nasync function parseGeoTIFF(\n data: ArrayBuffer,\n options?: GeoTIFFLoaderOptions\n): Promise<GeoTIFFData> {\n // Load using Geotiff.js\n const tiff = await fromArrayBuffer(data);\n\n // Assumes we only have one image inside TIFF\n const image = await tiff.getImage();\n\n // Read image and size\n // TODO: Add support for worker pools here.\n // TODO: Add support for more image formats.\n const rgbData = await image.readRGB({\n enableAlpha: options?.geotiff?.enableAlpha\n });\n\n const width = image.getWidth();\n const height = image.getHeight();\n\n // Create a new ImageData object\n const imageData = new Uint8ClampedArray(rgbData as unknown as Uint8Array);\n\n // Get geo data\n const bounds = image.getBoundingBox();\n const metadata = image.getGeoKeys();\n\n // ProjectedCSTypeGeoKey is the only key we support for now, we assume it is an EPSG code\n let crs: string | undefined;\n if (metadata?.ProjectedCSTypeGeoKey) {\n crs = `EPSG:${metadata.ProjectedCSTypeGeoKey}`;\n }\n\n // Return GeoReferenced image data\n return {\n crs,\n bounds,\n width,\n height,\n data: imageData,\n metadata\n };\n}\n"],"mappings":"AAMA,SAAQA,eAAe,QAAO,SAAS;AAIvC,MAAMC,OAAO,GAAG,sBAAkB,KAAK,WAAW,qBAAiB,QAAQ;AAqB3E,OAAO,MAAMC,aAAyE,GAAG;EACvFC,EAAE,EAAE,SAAS;EACbC,IAAI,EAAE,SAAS;EACfC,MAAM,EAAE,SAAS;EACjBC,OAAO,EAAEL,OAAO;EAChBM,OAAO,EAAE;IACPC,WAAW,EAAE;EACf,CAAC;EACDC,SAAS,EAAE,CAAC,YAAY,EAAE,eAAe,CAAC;EAC1CC,UAAU,EAAE,CAAC,SAAS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GnC,IAAIC,GAAuB;EAC3B,IAAIF,QAAQ,aAARA,QAAQ,eAARA,QAAQ,CAAEG,qBAAqB,EAAE;IACnCD,GAAG,GAAI,QAAOF,QAAQ,CAACG,qBAAsB,EAAC;EAChD;EAGA,OAAO;IACLD,GAAG;IACHJ,MAAM;IACNN,KAAK;IACLE,MAAM;IACNV,IAAI,EAAEY,SAAS;IACfI;EACF,CAAC;AACH"}
|
package/dist/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["GeoTIFFLoader","loadGeoTiff","TiffPixelSource"],"sources":["../src/index.ts"],"sourcesContent":["// loaders.gl\n// SPDX-License-Identifier: MIT\n// Copyright (c) vis.gl contributors\n\nexport {GeoTIFFLoader} from './geotiff-loader';\n\nexport {loadGeoTiff} from './lib/load-geotiff';\nexport {TiffPixelSource} from './lib/tiff-pixel-source';\n"],"mappings":"SAIQA,aAAa;AAAA,SAEbC,WAAW;AAAA,SACXC,eAAe"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"load-geotiff.js","names":["fromUrl","fromBlob","GeoTIFF","loadOmeTiff","isOmeTiff","loadGeoTiff","source","opts","arguments","length","undefined","headers","offsets","tiff","firstImage","getImage","Error"],"sources":["../../src/lib/load-geotiff.ts"],"sourcesContent":["// loaders.gl\n// SPDX-License-Identifier: MIT\n// Copyright (c) vis.gl contributors\n\nimport {fromUrl, fromBlob, GeoTIFF} from 'geotiff';\n\n// import {\n// // createPoolProxy,\n// createOffsetsProxy,\n// checkProxies\n// } from './utils/proxies.ts.disabled';\n// import Pool from './lib/Pool';\n\nimport {loadOmeTiff, isOmeTiff} from './ome/load-ome-tiff';\nimport type {TiffPixelSource} from './tiff-pixel-source';\n\n/** Options for initializing a tiff pixel source. */\ninterface GeoTIFFOptions {\n /** Headers passed to each underlying request. */\n headers?: Record<string, unknown>;\n /** Performance enhancment to index the remote tiff source using pre-computed byte-offsets. Generated via https://github.com/ilan-gold/generate-tiff-offsets */\n offsets?: number[];\n /** Indicates whether a multi-threaded pool of image decoders should be used to decode tiles. */\n pool?: boolean;\n}\n\ninterface GeoTIFFData {\n data: TiffPixelSource<string[]>[];\n metadata: Record<string, unknown>;\n}\n\n/**\n * Opens an OME-TIFF via URL and returns data source and associated metadata for first image.\n *\n * @param source url string, File/Blob object, or GeoTIFF object\n * @param opts options for initializing a tiff pixel source.\n * - `opts.headers` are passed to each underlying fetch request.\n * - `opts.offsets` are a performance enhancment to index the remote tiff source using pre-computed byte-offsets.\n * - `opts.pool` indicates whether a multi-threaded pool of image decoders should be used to decode tiles (default = true).\n * @return data source and associated OME-Zarr metadata.\n */\nexport async function loadGeoTiff(\n source: string | Blob | GeoTIFF,\n opts: GeoTIFFOptions = {}\n): Promise<GeoTIFFData> {\n const {headers, offsets} = opts;\n\n // Create tiff source\n let tiff: GeoTIFF;\n if (source instanceof GeoTIFF) {\n tiff = source;\n } else if (typeof source === 'string') {\n tiff = await fromUrl(source, headers);\n } else {\n tiff = await fromBlob(source);\n }\n\n // if (pool) {\n /*\n * Creates a worker pool to decode tiff tiles. Wraps tiff\n * in a Proxy that injects 'pool' into `tiff.readRasters`.\n */\n // tiff = createPoolProxy(tiff, new Pool());\n // }\n\n if (offsets) {\n /*\n * Performance enhancement. If offsets are provided, we\n * create a proxy that intercepts calls to `tiff.getImage`\n * and injects the pre-computed offsets.\n */\n // tiff = createOffsetsProxy(tiff, offsets);\n }\n\n /*\n * Inspect tiff source for our performance enhancing proxies.\n * Prints warnings to console if `offsets` or `pool` are missing.\n */\n // checkProxies(tiff);\n\n const firstImage = await tiff.getImage(0);\n\n if (isOmeTiff(firstImage)) {\n return loadOmeTiff(tiff, firstImage);\n }\n\n throw new Error('GeoTIFF not recognized.');\n}\n"],"mappings":"AAIA,SAAQA,OAAO,EAAEC,QAAQ,EAAEC,OAAO,QAAO,SAAS;AAAC,SAS3CC,WAAW,EAAEC,SAAS;AA4B9B,OAAO,eAAeC,WAAWA,CAC/BC,MAA+B,EAET;EAAA,IADtBC,IAAoB,GAAAC,SAAA,CAAAC,MAAA,QAAAD,SAAA,QAAAE,SAAA,GAAAF,SAAA,MAAG,CAAC,CAAC;EAEzB,MAAM;IAACG,OAAO;IAAEC;EAAO,CAAC,GAAGL,IAAI;EAG/B,IAAIM,IAAa;EACjB,IAAIP,MAAM,YAAYJ,OAAO,EAAE;IAC7BW,IAAI,GAAGP,MAAM;EACf,CAAC,MAAM,IAAI,OAAOA,MAAM,KAAK,QAAQ,EAAE;IACrCO,IAAI,GAAG,MAAMb,OAAO,CAACM,MAAM,EAAEK,OAAO,CAAC;EACvC,CAAC,MAAM;IACLE,IAAI,GAAG,MAAMZ,QAAQ,CAACK,MAAM,CAAC;EAC/B;EAUA,IAAIM,OAAO,EAAE,CAOb;EAQA,MAAME,UAAU,GAAG,MAAMD,IAAI,CAACE,QAAQ,CAAC,CAAC,CAAC;EAEzC,IAAIX,SAAS,CAACU,UAAU,CAAC,EAAE;IACzB,OAAOX,WAAW,CAACU,IAAI,EAAEC,UAAU,CAAC;EACtC;EAEA,MAAM,IAAIE,KAAK,CAAC,yBAAyB,CAAC;AAC5C"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"load-ome-tiff.js","names":["TiffPixelSource","getOmeLegacyIndexer","getOmeSubIFDIndexer","getOmePixelSourceMeta","fromString","isOmeTiff","img","fileDirectory","ImageDescription","includes","loadOmeTiff","tiff","firstImage","SubIFDs","PhotometricInterpretation","photometricInterpretation","omexml","levels","pyramidIndexer","length","imgMeta","labels","getShape","physicalSizes","dtype","tileSize","getTileWidth","meta","data","Array","from","map","_","resolution","shape","indexer","sel","source","metadata"],"sources":["../../../src/lib/ome/load-ome-tiff.ts"],"sourcesContent":["// loaders.gl\n// SPDX-License-Identifier: MIT\n// Copyright (c) vis.gl contributors\n\nimport type {GeoTIFF, GeoTIFFImage} from 'geotiff';\n\nimport {TiffPixelSource} from '../tiff-pixel-source';\nimport {getOmeLegacyIndexer, getOmeSubIFDIndexer, OmeTiffIndexer} from './ome-indexers';\nimport {getOmePixelSourceMeta} from './ome-utils';\nimport {fromString} from './omexml';\nimport type {OmeTiffSelection} from './ome-indexers';\n\nexport const isOmeTiff = (img: GeoTIFFImage) => img.fileDirectory.ImageDescription.includes('<OME');\n\nexport async function loadOmeTiff(tiff: GeoTIFF, firstImage: GeoTIFFImage) {\n // Get first image from tiff and inspect OME-XML metadata\n const {\n ImageDescription,\n SubIFDs,\n PhotometricInterpretation: photometricInterpretation\n } = firstImage.fileDirectory;\n const omexml = fromString(ImageDescription);\n\n /*\n * Image pyramids are stored differently between versions of Bioformats.\n * Thus we need a different indexer depending on which format we have.\n */\n let levels: number;\n let pyramidIndexer: OmeTiffIndexer;\n\n if (SubIFDs) {\n // Image is >= Bioformats 6.0 and resolutions are stored using SubIFDs.\n levels = SubIFDs.length + 1;\n pyramidIndexer = getOmeSubIFDIndexer(tiff, omexml);\n } else {\n // Image is legacy format; resolutions are stored as separate images.\n levels = omexml.length;\n pyramidIndexer = getOmeLegacyIndexer(tiff, omexml);\n }\n\n // TODO: The OmeTIFF loader only works for the _first_ image in the metadata.\n const imgMeta = omexml[0];\n const {labels, getShape, physicalSizes, dtype} = getOmePixelSourceMeta(imgMeta);\n const tileSize = firstImage.getTileWidth();\n const meta = {photometricInterpretation, physicalSizes};\n\n const data = Array.from({length: levels}).map((_, resolution) => {\n const shape = getShape(resolution);\n const indexer = (sel: OmeTiffSelection) => pyramidIndexer(sel, resolution);\n const source = new TiffPixelSource(indexer, dtype, tileSize, shape, labels, meta);\n return source;\n });\n\n return {data, metadata: imgMeta};\n}\n"],"mappings":"SAMQA,eAAe;AAAA,SACfC,mBAAmB,EAAEC,mBAAmB;AAAA,SACxCC,qBAAqB;AAAA,SACrBC,UAAU;AAGlB,OAAO,MAAMC,SAAS,GAAIC,GAAiB,IAAKA,GAAG,CAACC,aAAa,CAACC,gBAAgB,CAACC,QAAQ,CAAC,MAAM,CAAC;AAEnG,OAAO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AO;IAACT,IAAI;IAAEU,QAAQ,EAAElB;EAAO,CAAC;AAClC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"ome-indexers.js","names":["getOmeLegacyIndexer","tiff","rootMeta","imgMeta","SizeT","SizeC","SizeZ","Pixels","ifdIndexer","getOmeIFDIndexer","sel","pyramidLevel","index","pyramidIndex","getImage","getOmeSubIFDIndexer","ifdCache","Map","baseImage","SubIFDs","fileDirectory","Error","key","t","c","z","has","subIfdOffset","set","parseFileDirectoryAt","ifd","get","constructor","geoKeyDirectory","dataView","littleEndian","cache","source","DimensionOrder","_ref","_ref2","_ref3","_ref4","_ref5","_ref6"],"sources":["../../../src/lib/ome/ome-indexers.ts"],"sourcesContent":["// loaders.gl\n// SPDX-License-Identifier: MIT\n// Copyright (c) vis.gl contributors\n\nimport type {GeoTIFFImage, GeoTIFF} from 'geotiff';\nimport type {OMEXML} from '../ome/omexml';\n\nexport type ImageFileDirectory = any;\n\nexport type OmeTiffSelection = {t: number; c: number; z: number};\nexport type OmeTiffIndexer = (sel: OmeTiffSelection, z: number) => Promise<GeoTIFFImage>;\n\n/*\n * An \"indexer\" for a GeoTIFF-based source is a function that takes a\n * \"selection\" (e.g. { z, t, c }) and returns a Promise for the GeoTIFFImage\n * object corresponding to that selection.\n *\n * For OME-TIFF images, the \"selection\" object is the same regardless of\n * the format version. However, modern version of Bioformats have a different\n * memory layout for pyramidal resolutions. Thus, we have two different \"indexers\"\n * depending on which format version is detected.\n *\n * TODO: We currently only support indexing the first image in the OME-TIFF with\n * our indexers. There can be multiple images in an OME-TIFF, so supporting these\n * images will require extending these indexers or creating new methods.\n */\n\n/*\n * Returns an indexer for legacy Bioformats images. This assumes that\n * downsampled resolutions are stored sequentially in the OME-TIFF.\n */\nexport function getOmeLegacyIndexer(tiff: GeoTIFF, rootMeta: OMEXML): OmeTiffIndexer {\n const imgMeta = rootMeta[0];\n const {SizeT, SizeC, SizeZ} = imgMeta.Pixels;\n const ifdIndexer = getOmeIFDIndexer(imgMeta);\n\n return (sel: OmeTiffSelection, pyramidLevel: number) => {\n // Get IFD index at base pyramid level\n const index = ifdIndexer(sel);\n // Get index of first image at pyramidal level\n const pyramidIndex = pyramidLevel * SizeZ * SizeT * SizeC;\n // Return image at IFD index for pyramidal level\n return tiff.getImage(index + pyramidIndex);\n };\n}\n\n/*\n * Returns an indexer for modern Bioforamts images that store multiscale\n * resolutions using SubIFDs.\n *\n * The ifdIndexer returns the 'index' to the base resolution for a\n * particular 'selection'. The SubIFDs to the downsampled resolutions\n * of the 'selection' are stored within the `baseImage.fileDirectory`.\n * We use the SubIFDs to get the IFD for the corresponding sub-resolution.\n *\n * NOTE: This function create a custom IFD cache rather than mutating\n * `GeoTIFF.ifdRequests` with a random offset. The IFDs are cached in\n * an ES6 Map that maps a string key that identifies the selection uniquely\n * to the corresponding IFD.\n */\nexport function getOmeSubIFDIndexer(tiff: GeoTIFF, rootMeta: OMEXML): OmeTiffIndexer {\n const imgMeta = rootMeta[0];\n const ifdIndexer = getOmeIFDIndexer(imgMeta);\n const ifdCache: Map<string, Promise<ImageFileDirectory>> = new Map();\n\n return async (sel: OmeTiffSelection, pyramidLevel: number) => {\n const index = ifdIndexer(sel);\n const baseImage = await tiff.getImage(index);\n\n // It's the highest resolution, no need to look up SubIFDs.\n if (pyramidLevel === 0) {\n return baseImage;\n }\n\n const {SubIFDs} = baseImage.fileDirectory;\n if (!SubIFDs) {\n throw Error('Indexing Error: OME-TIFF is missing SubIFDs.');\n }\n\n // Get IFD for the selection at the pyramidal level\n const key = `${sel.t}-${sel.c}-${sel.z}-${pyramidLevel}`;\n if (!ifdCache.has(key)) {\n // Only create a new request if we don't have the key.\n const subIfdOffset = SubIFDs[pyramidLevel - 1];\n ifdCache.set(key, tiff.parseFileDirectoryAt(subIfdOffset));\n }\n const ifd = await ifdCache.get(key);\n\n // Create a new image object manually from IFD\n // https://github.com/geotiffjs/geotiff.js/blob/8ef472f41b51d18074aece2300b6a8ad91a21ae1/src/geotiff.js#L447-L453\n return new (baseImage.constructor as any)(\n ifd.fileDirectory,\n ifd.geoKeyDirectory,\n // @ts-expect-error\n tiff.dataView,\n tiff.littleEndian,\n tiff.cache,\n tiff.source\n ) as GeoTIFFImage;\n };\n}\n\n/*\n * Returns a function that computes the image index based on the dimension\n * order and dimension sizes.\n */\nfunction getOmeIFDIndexer(imgMeta: OMEXML[0]): (sel: OmeTiffSelection) => number {\n const {SizeC, SizeZ, SizeT, DimensionOrder} = imgMeta.Pixels;\n switch (DimensionOrder) {\n case 'XYZCT': {\n return ({t, c, z}) => t * SizeZ * SizeC + c * SizeZ + z;\n }\n case 'XYZTC': {\n return ({t, c, z}) => c * SizeZ * SizeT + t * SizeZ + z;\n }\n case 'XYCTZ': {\n return ({t, c, z}) => z * SizeC * SizeT + t * SizeC + c;\n }\n case 'XYCZT': {\n return ({t, c, z}) => t * SizeC * SizeZ + z * SizeC + c;\n }\n case 'XYTCZ': {\n return ({t, c, z}) => z * SizeT * SizeC + c * SizeT + t;\n }\n case 'XYTZC': {\n return ({t, c, z}) => c * SizeT * SizeZ + z * SizeT + t;\n }\n default: {\n throw new Error(`Invalid OME-XML DimensionOrder, got ${DimensionOrder}.`);\n }\n }\n}\n"],"mappings":"AA+BA,OAAO,SAASA,mBAAmBA,CAACC,IAAa,EAAEC,QAAgB,EAAkB;EACnF,MAAMC,OAAO,GAAGD,QAAQ,CAAC,CAAC,CAAC;EAC3B,MAAM;IAACE,KAAK;IAAEC,KAAK;IAAEC;EAAK,CAAC,GAAGH,OAAO,CAACI,MAAM;EAC5C,MAAMC,UAAU,GAAGC,gBAAgB,CAACN,OAAO,CAAC;EAE5C,OAAO,CAACO,GAAqB,EAAEC,YAAoB,KAAK;IAEtD,MAAMC,KAAK,GAAGJ,UAAU,CAACE,GAAG,CAAC;IAE7B,MAAMG,YAAY,GAAGF,YAAY,GAAGL,KAAK,GAAGF,KAAK,GAAGC,KAAK;IAEzD,OAAOJ,IAAI,CAACa,QAAQ,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K,GAAGC,KAAK,GAAGmB,CAAC,GAAGpB,KAAK,GAAGmB,CAAC;QAAA;MACzD;IACA,KAAK,OAAO;MAAE;QACZ,OAAOqB,KAAA;UAAA,IAAC;YAACrB,CAAC;YAAEC,CAAC;YAAEC;UAAC,CAAC,GAAAmB,KAAA;UAAA,OAAKpB,CAAC,GAAGpB,KAAK,GAAGE,KAAK,GAAGmB,CAAC,GAAGrB,KAAK,GAAGmB,CAAC;QAAA;MACzD;IACA;MAAS;QACP,MAAM,IAAIF,KAAK,CAAE,uCAAsCiB,cAAe,GAAE,CAAC;MAC3E;EACF;AACF"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"ome-utils.js","names":["getDims","getLabels","DTYPE_LOOKUP","uint8","uint16","uint32","float","double","int8","int16","int32","getOmePixelSourceMeta","_ref","Pixels","labels","DimensionOrder","dims","shape","Array","length","fill","SizeT","SizeC","SizeZ","Interleaved","push","getShape","level","s","SizeX","SizeY","Type","Error","dtype","PhysicalSizeX","PhysicalSizeY","physicalSizes","x","size","unit","PhysicalSizeXUnit","y","PhysicalSizeYUnit","PhysicalSizeZ","z","PhysicalSizeZUnit"],"sources":["../../../src/lib/ome/ome-utils.ts"],"sourcesContent":["// loaders.gl\n// SPDX-License-Identifier: MIT\n// Copyright (c) vis.gl contributors\n\nimport {getDims, getLabels} from './utils';\nimport type {OMEXML, UnitsLength} from './omexml';\n\nexport const DTYPE_LOOKUP = {\n uint8: 'Uint8',\n uint16: 'Uint16',\n uint32: 'Uint32',\n float: 'Float32',\n double: 'Float64',\n int8: 'Int8',\n int16: 'Int16',\n int32: 'Int32'\n} as const;\n\nexport function getOmePixelSourceMeta({Pixels}: OMEXML[0]) {\n // e.g. 'XYZCT' -> ['t', 'c', 'z', 'y', 'x']\n const labels = getLabels(Pixels.DimensionOrder);\n\n // Compute \"shape\" of image\n const dims = getDims(labels);\n const shape: number[] = Array(labels.length).fill(0);\n shape[dims('t')] = Pixels.SizeT;\n shape[dims('c')] = Pixels.SizeC;\n shape[dims('z')] = Pixels.SizeZ;\n\n // Push extra dimension if data are interleaved.\n if (Pixels.Interleaved) {\n // @ts-ignore\n labels.push('_c');\n shape.push(3);\n }\n\n // Creates a new shape for different level of pyramid.\n // Assumes factor-of-two downsampling.\n const getShape = (level: number) => {\n const s = [...shape];\n s[dims('x')] = Pixels.SizeX >> level;\n s[dims('y')] = Pixels.SizeY >> level;\n return s;\n };\n\n if (!(Pixels.Type in DTYPE_LOOKUP)) {\n throw Error(`Pixel type ${Pixels.Type} not supported.`);\n }\n\n const dtype = DTYPE_LOOKUP[Pixels.Type as keyof typeof DTYPE_LOOKUP];\n if (Pixels.PhysicalSizeX && Pixels.PhysicalSizeY) {\n const physicalSizes: {\n [k: string]: {size: number; unit: UnitsLength};\n } = {\n x: {\n size: Pixels.PhysicalSizeX,\n unit: Pixels.PhysicalSizeXUnit\n },\n y: {\n size: Pixels.PhysicalSizeY,\n unit: Pixels.PhysicalSizeYUnit\n }\n };\n if (Pixels.PhysicalSizeZ) {\n physicalSizes.z = {\n size: Pixels.PhysicalSizeZ,\n unit: Pixels.PhysicalSizeZUnit\n };\n }\n return {labels, getShape, physicalSizes, dtype};\n }\n\n return {labels, getShape, dtype};\n}\n"],"mappings":"SAIQA,OAAO,EAAEC,SAAS;AAG1B,OAAO,MAAMC,YAAY,GAAG;EAC1BC,KAAK,EAAE,OAAO;EACdC,MAAM,EAAE,QAAQ;EAChBC,MAAM,EAAE,QAAQ;EAChBC,KAAK,EAAE,SAAS;EAChBC,MAAM,EAAE,SAAS;EACjBC,IAAI,EAAE,MAAM;EACZC,KAAK,EAAE,OAAO;EACdC,KAAK,EAAE;AACT,CAAU;AAEV,OAAO,SAASC,qBAAqBA,CAAAC,IAAA,EAAsB;EAAA,IAArB;IAACC;EAAiB,CAAC,GAAAD,IAAA;EAEvD,MAAME,MAAM,GAAGb,SAAS,CAACY,MAAM,CAACE,cAAc,CAAC;EAG/C,MAAMC,IAAI,GAAGhB,OAAO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a;QAC1BI,IAAI,EAAE1B,MAAM,CAAC6B;MACf;IACF,CAAC;IACD,IAAI7B,MAAM,CAAC8B,aAAa,EAAE;MACxBP,aAAa,CAACQ,CAAC,GAAG;QAChBN,IAAI,EAAEzB,MAAM,CAAC8B,aAAa;QAC1BJ,IAAI,EAAE1B,MAAM,CAACgC;MACf,CAAC;IACH;IACA,OAAO;MAAC/B,MAAM;MAAEY,QAAQ;MAAEU,aAAa;MAAEH;IAAK,CAAC;EACjD;EAEA,OAAO;IAACnB,MAAM;IAAEY,QAAQ;IAAEO;EAAK,CAAC;AAClC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"omexml.js","names":["XMLParser","ensureArray","intToRgba","xmlParser","attributeNamePrefix","attributesGroupName","parseTagValue","parseAttributeValue","ignoreAttributes","parse","str","fromString","res","OME","Error","Image","map","img","Channels","Pixels","Channel","c","attr","Color","AquisitionDate","Description","image","format","sizes","name","size","unit","join","SizeX","SizeY","Type","SizeZ","SizeT","SizeC"],"sources":["../../../src/lib/ome/omexml.ts"],"sourcesContent":["// loaders.gl\n// SPDX-License-Identifier: MIT\n// Copyright (c) vis.gl contributors\n\nimport {XMLParser} from 'fast-xml-parser';\nimport {ensureArray, intToRgba} from '../utils/tiff-utils';\n\n// WARNING: Changes to the parser options _will_ effect the types in types/omexml.d.ts.\nconst xmlParser = new XMLParser({\n // Nests attributes withtout prefix under 'attr' key for each node\n attributeNamePrefix: '',\n attributesGroupName: 'attr',\n\n // Parses numbers for both attributes and nodes\n parseTagValue: true,\n parseAttributeValue: true,\n\n // Forces attributes to be parsed\n ignoreAttributes: false\n});\n\nconst parse = (str: string): Root => xmlParser.parse(str);\n\nexport function fromString(str: string) {\n const res = parse(str);\n if (!res.OME) {\n throw Error('Failed to parse OME-XML metadata.');\n }\n return ensureArray(res.OME.Image).map((img) => {\n const Channels = ensureArray(img.Pixels.Channel).map((c) => {\n if ('Color' in c.attr) {\n return {...c.attr, Color: intToRgba(c.attr.Color)};\n }\n return {...c.attr};\n });\n const {AquisitionDate = '', Description = ''} = img;\n const image = {\n ...img.attr,\n AquisitionDate,\n Description,\n Pixels: {\n ...img.Pixels.attr,\n Channels\n }\n };\n return {\n ...image,\n format() {\n const {Pixels} = image;\n\n const sizes = (['X', 'Y', 'Z'] as const)\n .map((name) => {\n const size = Pixels[`PhysicalSize${name}` as const];\n const unit = Pixels[`PhysicalSize${name}Unit` as const];\n return size && unit ? `${size} ${unit}` : '-';\n })\n .join(' x ');\n\n return {\n 'Acquisition Date': image.AquisitionDate,\n 'Dimensions (XY)': `${Pixels.SizeX} x ${Pixels.SizeY}`,\n 'Pixels Type': Pixels.Type,\n 'Pixels Size (XYZ)': sizes,\n 'Z-sections/Timepoints': `${Pixels.SizeZ} x ${Pixels.SizeT}`,\n Channels: Pixels.SizeC\n };\n }\n };\n });\n}\n\nexport type OMEXML = ReturnType<typeof fromString>;\nexport type DimensionOrder = 'XYZCT' | 'XYZTC' | 'XYCTZ' | 'XYCZT' | 'XYTCZ' | 'XYTZC';\n\n// Structure of node is determined by the PARSER_OPTIONS.\ntype Node<T, A> = T & {attr: A};\ntype Attrs<Fields extends string, T = string> = {[K in Fields]: T};\n\ntype OMEAttrs = Attrs<'xmlns' | 'xmlns:xsi' | 'xsi:schemaLocation'>;\ntype OME = Node<{Insturment: Insturment; Image: Image | Image[]}, OMEAttrs>;\n\ntype Insturment = Node<\n {Objective: Node<{}, Attrs<'ID' | 'Model' | 'NominalMagnification'>>},\n Attrs<'ID'>\n>;\n\ninterface ImageNodes {\n AquisitionDate?: string;\n Description?: string;\n Pixels: Pixels;\n InstrumentRef: Node<{}, {ID: string}>;\n ObjectiveSettings: Node<{}, {ID: string}>;\n}\ntype Image = Node<ImageNodes, Attrs<'ID' | 'Name'>>;\n\ntype PixelType =\n | 'int8'\n | 'int16'\n | 'int32'\n | 'uint8'\n | 'uint16'\n | 'uint32'\n | 'float'\n | 'bit'\n | 'double'\n | 'complex'\n | 'double-complex';\n\nexport type UnitsLength =\n | 'Ym'\n | 'Zm'\n | 'Em'\n | 'Pm'\n | 'Tm'\n | 'Gm'\n | 'Mm'\n | 'km'\n | 'hm'\n | 'dam'\n | 'm'\n | 'dm'\n | 'cm'\n | 'mm'\n | 'µm'\n | 'nm'\n | 'pm'\n | 'fm'\n | 'am'\n | 'zm'\n | 'ym'\n | 'Å'\n | 'thou'\n | 'li'\n | 'in'\n | 'ft'\n | 'yd'\n | 'mi'\n | 'ua'\n | 'ly'\n | 'pc'\n | 'pt'\n | 'pixel'\n | 'reference frame';\n\ntype PhysicalSize<Name extends string> = `PhysicalSize${Name}`;\ntype PhysicalSizeUnit<Name extends string> = `PhysicalSize${Name}Unit`;\ntype Size<Names extends string> = `Size${Names}`;\n\ntype PixelAttrs = Attrs<\n PhysicalSize<'X' | 'Y' | 'Z'> | 'SignificantBits' | Size<'T' | 'C' | 'Z' | 'Y' | 'X'>,\n number\n> &\n Attrs<PhysicalSizeUnit<'X' | 'Y' | 'Z'>, UnitsLength> &\n Attrs<'BigEndian' | 'Interleaved', boolean> & {\n ID: string;\n DimensionOrder: DimensionOrder;\n Type: PixelType;\n };\n\ntype Pixels = Node<\n {\n Channel: Channel | Channel[];\n TiffData: Node<{}, Attrs<'IFD' | 'PlaneCount'>>;\n },\n PixelAttrs\n>;\n\ntype ChannelAttrs =\n | {\n ID: string;\n SamplesPerPixel: number;\n Name?: string;\n }\n | {\n ID: string;\n SamplesPerPixel: number;\n Name?: string;\n Color: number;\n };\n\ntype Channel = Node<{}, ChannelAttrs>;\n\ntype Root = {OME: OME};\n"],"mappings":"AAIA,SAAQA,SAAS,QAAO,iBAAiB;AAAC,SAClCC,WAAW,EAAEC,SAAS;AAG9B,MAAMC,SAAS,GAAG,IAAIH,SAAS,CAAC;EAE9BI,mBAAmB,EAAE,EAAE;EACvBC,mBAAmB,EAAE,MAAM;EAG3BC,aAAa,EAAE,IAAI;EACnBC,mBAAmB,EAAE,IAAI;EAGzBC,gBAAgB,EAAE;AACpB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ME,IAAI,GAAGZ,MAAM,CAAE,eAAcU,IAAK,MAAK,CAAU;UACvD,OAAOC,IAAI,IAAIC,IAAI,GAAI,GAAED,IAAK,IAAGC,IAAK,EAAC,GAAG,GAAG;QAC/C,CAAC,CAAC,CACDC,IAAI,CAAC,KAAK,CAAC;QAEd,OAAO;UACL,kBAAkB,EAAEN,KAAK,CAACF,cAAc;UACxC,iBAAiB,EAAG,GAAEL,MAAM,CAACc,KAAM,MAAKd,MAAM,CAACe,KAAM,EAAC;UACtD,aAAa,EAAEf,MAAM,CAACgB,IAAI;UAC1B,mBAAmB,EAAEP,KAAK;UAC1B,uBAAuB,EAAG,GAAET,MAAM,CAACiB,KAAM,MAAKjB,MAAM,CAACkB,KAAM,EAAC;UAC5DnB,QAAQ,EAAEC,MAAM,CAACmB;QACnB,CAAC;MACH;IACF,CAAC;EACH,CAAC,CAAC;AACJ"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","names":["getLabels","dimOrder","toLowerCase","split","reverse","getDims","labels","lookup","Map","map","name","i","size","length","Error","index","get","undefined"],"sources":["../../../src/lib/ome/utils.ts"],"sourcesContent":["// loaders.gl\n// SPDX-License-Identifier: MIT\n// Copyright (c) vis.gl contributors\n\nimport type {OMEXML} from '../ome/omexml';\nimport type {Labels} from '../../types';\n\n/*\n * Creates typed labels from DimensionOrder.\n * > imgMeta.Pixels.DimensionOrder === 'XYCZT'\n * > getLabels(imgMeta.Pixels) === ['t', 'z', 'c', 'y', 'x']\n */\n\n// eslint-disable-next-line @typescript-eslint/no-unused-vars\ntype Sel<Dim extends string> = Dim extends `${infer Z}${infer X}${infer A}${infer B}${infer C}`\n ? [C, B, A]\n : 'error';\nexport function getLabels(dimOrder: OMEXML[0]['Pixels']['DimensionOrder']) {\n return dimOrder.toLowerCase().split('').reverse() as Labels<Sel<Lowercase<typeof dimOrder>>>;\n}\n\n/*\n * Creates an ES6 map of 'label' -> index\n * > const labels = ['a', 'b', 'c', 'd'];\n * > const dims = getDims(labels);\n * > dims('a') === 0;\n * > dims('b') === 1;\n * > dims('c') === 2;\n * > dims('hi!'); // throws\n */\nexport function getDims<S extends string>(labels: S[]) {\n const lookup = new Map(labels.map((name, i) => [name, i]));\n if (lookup.size !== labels.length) {\n throw Error('Labels must be unique, found duplicated label.');\n }\n return (name: S) => {\n const index = lookup.get(name);\n if (index === undefined) {\n throw Error('Invalid dimension.');\n }\n return index;\n };\n}\n"],"mappings":"AAiBA,OAAO,SAASA,SAASA,CAACC,QAA+C,EAAE;EACzE,OAAOA,QAAQ,CAACC,WAAW,CAAC,CAAC,CAACC,KAAK,CAAC,EAAE,CAAC,CAACC,OAAO,CAAC,CAAC;AACnD;AAWA,OAAO,SAASC,OAAOA,CAAmBC,MAAW,EAAE;EACrD,MAAMC,MAAM,GAAG,IAAIC,GAAG,CAACF,MAAM,CAACG,GAAG,CAAC,CAACC,IAAI,EAAEC,CAAC,KAAK,CAACD,IAAI,EAAEC,CAAC,CAAC,CAAC,CAAC;EAC1D,IAAIJ,MAAM,CAACK,IAAI,KAAKN,MAAM,CAACO,MAAM,EAAE;IACjC,MAAMC,KAAK,CAAC,gDAAgD,CAAC;EAC/D;EACA,OAAQJ,IAAO,IAAK;IAClB,MAAMK,KAAK,GAAGR,MAAM,CAACS,GAAG,CAACN,IAAI,CAAC;IAC9B,IAAIK,KAAK,KAAKE,SAAS,EAAE;MACvB,MAAMH,KAAK,CAAC,oBAAoB,CAAC;IACnC;IACA,OAAOC,KAAK;EACd,CAAC;AACH"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"tiff-pixel-source.js","names":["getImageSize","isInterleaved","SIGNAL_ABORTED","TiffPixelSource","constructor","indexer","dtype","tileSize","shape","labels","meta","_indexer","getRaster","_ref","selection","signal","image","_readRasters","getTile","_ref2","x","y","height","width","_getTileExtent","x0","y0","window","props","_props$signal","interleave","raster","readRasters","aborted","data","zoomLevelHeight","zoomLevelWidth","maxXTileCoord","Math","floor","maxYTileCoord","onTileError","err","console","error"],"sources":["../../src/lib/tiff-pixel-source.ts"],"sourcesContent":["// loaders.gl\n// SPDX-License-Identifier: MIT\n// Copyright (c) vis.gl contributors\n\nimport type {GeoTIFFImage} from 'geotiff';\nimport {getImageSize, isInterleaved, SIGNAL_ABORTED} from './utils/tiff-utils';\n\nimport type {\n PixelSource,\n PixelSourceSelection,\n PixelSourceMeta,\n Dtype,\n Labels,\n RasterSelection,\n TileSelection,\n PixelData,\n TypedArray\n} from '../types';\n\ntype ReadRasterOptions = Record<string, any>;\n\nexport class TiffPixelSource<S extends string[]> implements PixelSource<S> {\n public dtype: Dtype;\n public tileSize: number;\n public shape: number[];\n public labels: Labels<S>;\n public meta: PixelSourceMeta | undefined;\n private _indexer: (sel: PixelSourceSelection<S>) => Promise<GeoTIFFImage>;\n\n // eslint-disable-next-line max-params\n constructor(\n indexer: (sel: PixelSourceSelection<S>) => Promise<GeoTIFFImage>,\n dtype: Dtype,\n tileSize: number,\n shape: number[],\n labels: Labels<S>,\n meta?: PixelSourceMeta\n ) {\n this._indexer = indexer;\n this.dtype = dtype;\n this.tileSize = tileSize;\n this.shape = shape;\n this.labels = labels;\n this.meta = meta;\n }\n\n async getRaster({selection, signal}: RasterSelection<S>) {\n const image = await this._indexer(selection);\n return this._readRasters(image, {signal});\n }\n\n async getTile({x, y, selection, signal}: TileSelection<S>) {\n const {height, width} = this._getTileExtent(x, y);\n const x0 = x * this.tileSize;\n const y0 = y * this.tileSize;\n const window = [x0, y0, x0 + width, y0 + height];\n\n const image = await this._indexer(selection);\n return this._readRasters(image, {window, width, height, signal});\n }\n\n private async _readRasters(image: GeoTIFFImage, props?: ReadRasterOptions) {\n const interleave = isInterleaved(this.shape);\n const raster = await image.readRasters({interleave, ...props});\n\n if (props?.signal?.aborted) {\n throw SIGNAL_ABORTED;\n }\n\n /*\n * geotiff.js returns objects with different structure\n * depending on `interleave`. It's weird, but this seems to work.\n */\n const data = (interleave ? raster : raster[0]) as TypedArray;\n return {\n data,\n width: raster.width,\n height: raster.height\n } as PixelData;\n }\n\n /*\n * Computes tile size given x, y coord.\n */\n private _getTileExtent(x: number, y: number) {\n const {height: zoomLevelHeight, width: zoomLevelWidth} = getImageSize(this);\n let height = this.tileSize;\n let width = this.tileSize;\n const maxXTileCoord = Math.floor(zoomLevelWidth / this.tileSize);\n const maxYTileCoord = Math.floor(zoomLevelHeight / this.tileSize);\n if (x === maxXTileCoord) {\n width = zoomLevelWidth % this.tileSize;\n }\n if (y === maxYTileCoord) {\n height = zoomLevelHeight % this.tileSize;\n }\n return {height, width};\n }\n\n onTileError(err: Error) {\n console.error(err); // eslint-disable-line no-console\n }\n}\n"],"mappings":"SAKQA,YAAY,EAAEC,aAAa,EAAEC,cAAc;AAgBnD,OAAO,MAAMC,eAAe,CAA+C;EASzEC,WAAWA,CACTC,OAAgE,EAChEC,KAAY,EACZC,QAAgB,EAChBC,KAAe,EACfC,MAAiB,EACjBC,IAAsB,EACtB;IAAA,KAfKJ,KAAK;IAAA,KACLC,QAAQ;IAAA,KACRC,KAAK;IAAA,KACLC,MAAM;IAAA,KACNC,IAAI;IAAA,KACHC,QAAQ;IAWd,IAAI,CAACA,QAAQ,GAAGN,OAAO;IACvB,IAAI,CAACC,KAAK,GAAGA,KAAK;IAClB,IAAI,CAACC,QAAQ,GAAGA,QAAQ;IACxB,IAAI,CAACC,KAAK,GAAGA,KAAK;IAClB,IAAI,CAACC,MAAM,GAAGA,MAAM;IACpB,IAAI,CAACC,IAAI,GAAGA,IAAI;EAClB;EAEA,MAAME,SAASA,CAAAC,IAAA,EAA0C;IAAA,IAAzC;MAACC,SAAS;MAAEC;IAA0B,CAAC,GAAAF,IAAA;IACrD,MAAMG,KAAK,GAAG,MAAM,IAAI,CAACL,QAAQ,CAACG,SAAS,CAAC;IAC5C,OAAO,IAAI,CAACG,YAAY,CAACD,KAAK,EAAE;MAACD;IAAM,CAAC,CAAC;EAC3C;EAEA,MAAMG,OAAOA,CAAAC,KAAA,EA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E;IAC3C,MAAM;MAACC,MAAM,EAAEa,eAAe;MAAEZ,KAAK,EAAEa;IAAc,CAAC,GAAGpC,YAAY,CAAC,IAAI,CAAC;IAC3E,IAAIsB,MAAM,GAAG,IAAI,CAACf,QAAQ;IAC1B,IAAIgB,KAAK,GAAG,IAAI,CAAChB,QAAQ;IACzB,MAAM8B,aAAa,GAAGC,IAAI,CAACC,KAAK,CAACH,cAAc,GAAG,IAAI,CAAC7B,QAAQ,CAAC;IAChE,MAAMiC,aAAa,GAAGF,IAAI,CAACC,KAAK,CAACJ,eAAe,GAAG,IAAI,CAAC5B,QAAQ,CAAC;IACjE,IAAIa,CAAC,KAAKiB,aAAa,EAAE;MACvBd,KAAK,GAAGa,cAAc,GAAG,IAAI,CAAC7B,QAAQ;IACxC;IACA,IAAIc,CAAC,KAAKmB,aAAa,EAAE;MACvBlB,MAAM,GAAGa,eAAe,GAAG,IAAI,CAAC5B,QAAQ;IAC1C;IACA,OAAO;MAACe,MAAM;MAAEC;IAAK,CAAC;EACxB;EAEAkB,WAAWA,CAACC,GAAU,EAAE;IACtBC,OAAO,CAACC,KAAK,CAACF,GAAG,CAAC;EACpB;AACF"}
|
|
@@ -1,99 +0,0 @@
|
|
|
1
|
-
// loaders.gl
|
|
2
|
-
// SPDX-License-Identifier: MIT
|
|
3
|
-
// Copyright (c) vis.gl contributors
|
|
4
|
-
|
|
5
|
-
/** eslint-disable */
|
|
6
|
-
import {FileDirectory} from 'geotiff';
|
|
7
|
-
|
|
8
|
-
// import Worker from 'web-worker:./decoder.worker.ts';
|
|
9
|
-
|
|
10
|
-
// https://developer.mozilla.org/en-US/docs/Web/API/NavigatorConcurrentHardware/hardwareConcurrency
|
|
11
|
-
// We need to give a different way of getting this for safari, so 4 is probably a safe bet
|
|
12
|
-
// for parallel processing in the meantime. More can't really hurt since they'll just block
|
|
13
|
-
// each other and not the UI thread, which is the real benefit.
|
|
14
|
-
const defaultPoolSize = globalThis?.navigator?.hardwareConcurrency ?? 4;
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* Pool for workers to decode chunks of the images.
|
|
18
|
-
* This is a line-for-line copy of GeoTIFFs old implementation: https://github.com/geotiffjs/geotiff.js/blob/v1.0.0-beta.8/src/pool.js
|
|
19
|
-
*/
|
|
20
|
-
export default class Pool {
|
|
21
|
-
workers: Worker[];
|
|
22
|
-
idleWorkers: Worker[];
|
|
23
|
-
waitQueue: any[];
|
|
24
|
-
decoder: null;
|
|
25
|
-
|
|
26
|
-
/**
|
|
27
|
-
* @constructor
|
|
28
|
-
* @param {Number} size The size of the pool. Defaults to the number of CPUs
|
|
29
|
-
* available. When this parameter is `null` or 0, then the
|
|
30
|
-
* decoding will be done in the main thread.
|
|
31
|
-
*/
|
|
32
|
-
constructor(size = defaultPoolSize) {
|
|
33
|
-
this.workers = [];
|
|
34
|
-
this.idleWorkers = [];
|
|
35
|
-
this.waitQueue = [];
|
|
36
|
-
this.decoder = null;
|
|
37
|
-
|
|
38
|
-
// eslint-disable-next-line no-plusplus
|
|
39
|
-
for (let i = 0; i < size; ++i) {
|
|
40
|
-
const w = new Worker('./decoder.worker');
|
|
41
|
-
this.workers.push(w);
|
|
42
|
-
this.idleWorkers.push(w);
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
/**
|
|
47
|
-
* Decode the given block of bytes with the set compression method.
|
|
48
|
-
* @param {ArrayBuffer} buffer the array buffer of bytes to decode.
|
|
49
|
-
* @returns {Promise.<ArrayBuffer>} the decoded result as a `Promise`
|
|
50
|
-
*/
|
|
51
|
-
async decode(fileDirectory: FileDirectory, buffer: ArrayBuffer) {
|
|
52
|
-
const currentWorker = await this.waitForWorker();
|
|
53
|
-
return new Promise((resolve, reject) => {
|
|
54
|
-
currentWorker.onmessage = (event) => {
|
|
55
|
-
// this.workers.push(currentWorker);
|
|
56
|
-
// eslint-disable-next-line
|
|
57
|
-
this.finishTask(currentWorker);
|
|
58
|
-
resolve(event.data[0]);
|
|
59
|
-
};
|
|
60
|
-
currentWorker.onerror = (error) => {
|
|
61
|
-
// this.workers.push(currentWorker);
|
|
62
|
-
// eslint-disable-next-line
|
|
63
|
-
this.finishTask(currentWorker);
|
|
64
|
-
reject(error);
|
|
65
|
-
};
|
|
66
|
-
currentWorker.postMessage(['decode', fileDirectory, buffer], [buffer]);
|
|
67
|
-
});
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
async waitForWorker() {
|
|
71
|
-
const idleWorker = this.idleWorkers.pop();
|
|
72
|
-
if (idleWorker) {
|
|
73
|
-
return idleWorker;
|
|
74
|
-
}
|
|
75
|
-
const waiter: any = {};
|
|
76
|
-
const promise = new Promise((resolve) => {
|
|
77
|
-
waiter.resolve = resolve;
|
|
78
|
-
});
|
|
79
|
-
|
|
80
|
-
this.waitQueue.push(waiter);
|
|
81
|
-
return promise as Promise<Worker>;
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
async finishTask(currentWorker: Worker) {
|
|
85
|
-
const waiter = this.waitQueue.pop();
|
|
86
|
-
if (waiter) {
|
|
87
|
-
waiter.resolve(currentWorker);
|
|
88
|
-
} else {
|
|
89
|
-
this.idleWorkers.push(currentWorker);
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
destroy() {
|
|
94
|
-
// eslint-disable-next-line no-plusplus
|
|
95
|
-
for (let i = 0; i < this.workers.length; ++i) {
|
|
96
|
-
this.workers[i].terminate();
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
}
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import type { FileDirectory } from 'geotiff';
|
|
2
|
-
import { getDecoder } from 'geotiff/src/compression';
|
|
3
|
-
|
|
4
|
-
async function decode(fileDirectory: FileDirectory, buffer: ArrayBuffer) {
|
|
5
|
-
const decoder = getDecoder(fileDirectory);
|
|
6
|
-
const result = await decoder.decode(fileDirectory, buffer);
|
|
7
|
-
self.postMessage(result, [result] as any);
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
if (typeof self !== 'undefined') {
|
|
11
|
-
self.addEventListener('message', event => {
|
|
12
|
-
const [name, ...args] = event.data;
|
|
13
|
-
switch (name) {
|
|
14
|
-
case 'decode':
|
|
15
|
-
decode(args[0], args[1]);
|
|
16
|
-
break;
|
|
17
|
-
default:
|
|
18
|
-
break;
|
|
19
|
-
}
|
|
20
|
-
});
|
|
21
|
-
}
|