@loaders.gl/geotiff 4.0.0-alpha.5 → 4.0.0-alpha.7
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/bundle.js +28 -2
- package/dist/es5/bundle.js +9 -0
- package/dist/es5/bundle.js.map +1 -0
- package/dist/es5/index.js +21 -0
- package/dist/es5/index.js.map +1 -0
- package/dist/es5/lib/load-geotiff.js +76 -0
- package/dist/es5/lib/load-geotiff.js.map +1 -0
- package/dist/es5/lib/ome/load-ome-tiff.js +66 -0
- package/dist/es5/lib/ome/load-ome-tiff.js.map +1 -0
- package/dist/es5/lib/ome/ome-indexers.js +140 -0
- package/dist/es5/lib/ome/ome-indexers.js.map +1 -0
- package/dist/es5/lib/ome/ome-utils.js +74 -0
- package/dist/es5/lib/ome/ome-utils.js.map +1 -0
- package/dist/es5/lib/ome/omexml.js +68 -0
- package/dist/es5/lib/ome/omexml.js.map +1 -0
- package/dist/es5/lib/ome/utils.js +26 -0
- package/dist/es5/lib/ome/utils.js.map +1 -0
- package/dist/es5/lib/tiff-pixel-source.js +163 -0
- package/dist/es5/lib/tiff-pixel-source.js.map +1 -0
- package/dist/es5/lib/utils/Pool.js +136 -0
- package/dist/es5/lib/utils/Pool.js.map +1 -0
- package/dist/es5/lib/utils/proxies.js +65 -0
- package/dist/es5/lib/utils/proxies.js.map +1 -0
- package/dist/es5/lib/utils/tiff-utils.js +43 -0
- package/dist/es5/lib/utils/tiff-utils.js.map +1 -0
- package/dist/es5/types.js +2 -0
- package/dist/es5/types.js.map +1 -0
- package/dist/es5/typings/geotiff.js +2 -0
- package/dist/es5/typings/geotiff.js.map +1 -0
- package/dist/esm/bundle.js +4 -0
- package/dist/esm/bundle.js.map +1 -0
- package/dist/esm/index.js +3 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/lib/load-geotiff.js +28 -0
- package/dist/esm/lib/load-geotiff.js.map +1 -0
- package/dist/esm/lib/ome/load-ome-tiff.js +47 -0
- package/dist/esm/lib/ome/load-ome-tiff.js.map +1 -0
- package/dist/esm/lib/ome/ome-indexers.js +120 -0
- package/dist/esm/lib/ome/ome-indexers.js.map +1 -0
- package/dist/esm/lib/ome/ome-utils.js +66 -0
- package/dist/esm/lib/ome/ome-utils.js.map +1 -0
- package/dist/esm/lib/ome/omexml.js +64 -0
- package/dist/esm/lib/ome/omexml.js.map +1 -0
- package/dist/esm/lib/ome/utils.js +17 -0
- package/dist/esm/lib/ome/utils.js.map +1 -0
- package/dist/esm/lib/tiff-pixel-source.js +92 -0
- package/dist/esm/lib/tiff-pixel-source.js.map +1 -0
- package/dist/esm/lib/utils/Pool.js +61 -0
- package/dist/esm/lib/utils/Pool.js.map +1 -0
- package/dist/esm/lib/utils/decoder.worker.ts.disabled +21 -0
- package/dist/esm/lib/utils/proxies.js +54 -0
- package/dist/esm/lib/utils/proxies.js.map +1 -0
- package/dist/esm/lib/utils/tiff-utils.js +27 -0
- package/dist/esm/lib/utils/tiff-utils.js.map +1 -0
- package/dist/esm/types.js +2 -0
- package/dist/esm/types.js.map +1 -0
- package/dist/esm/typings/geotiff.js +2 -0
- package/dist/esm/typings/geotiff.js.map +1 -0
- package/dist/index.js +10 -3
- package/dist/lib/load-geotiff.js +56 -31
- package/dist/lib/ome/load-ome-tiff.js +45 -50
- package/dist/lib/ome/ome-indexers.d.ts +2 -2
- package/dist/lib/ome/ome-indexers.d.ts.map +1 -1
- package/dist/lib/ome/ome-indexers.js +104 -112
- package/dist/lib/ome/ome-utils.js +59 -69
- package/dist/lib/ome/omexml.d.ts +4 -4
- package/dist/lib/ome/omexml.d.ts.map +1 -1
- package/dist/lib/ome/omexml.js +60 -60
- package/dist/lib/ome/utils.js +27 -18
- package/dist/lib/tiff-pixel-source.js +59 -106
- package/dist/lib/utils/Pool.js +78 -72
- package/dist/lib/utils/proxies.js +79 -56
- package/dist/lib/utils/tiff-utils.js +40 -24
- package/dist/types.d.ts +4 -4
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +2 -2
- package/dist/typings/geotiff.js +1 -2
- package/package.json +4 -4
- package/dist/bundle.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.js.map +0 -1
- package/dist/lib/utils/proxies.js.map +0 -1
- package/dist/lib/utils/tiff-utils.js.map +0 -1
- package/dist/types.js.map +0 -1
- package/dist/typings/geotiff.js.map +0 -1
- /package/dist/{lib → es5/lib}/utils/decoder.worker.ts.disabled +0 -0
package/dist/lib/ome/omexml.js
CHANGED
|
@@ -1,66 +1,66 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.fromString = void 0;
|
|
7
|
+
const fast_xml_parser_1 = __importDefault(require("fast-xml-parser"));
|
|
8
|
+
const tiff_utils_1 = require("../utils/tiff-utils");
|
|
9
|
+
// WARNING: Changes to the parser options _will_ effect the types in types/omexml.d.ts.
|
|
3
10
|
const PARSER_OPTIONS = {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
11
|
+
// Nests attributes withtout prefix under 'attr' key for each node
|
|
12
|
+
attributeNamePrefix: '',
|
|
13
|
+
attrNodeName: 'attr',
|
|
14
|
+
// Parses numbers for both attributes and nodes
|
|
15
|
+
parseNodeValue: true,
|
|
16
|
+
parseAttributeValue: true,
|
|
17
|
+
// Forces attributes to be parsed
|
|
18
|
+
ignoreAttributes: false
|
|
9
19
|
};
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
20
|
+
const parse = (str) => fast_xml_parser_1.default.parse(str, PARSER_OPTIONS);
|
|
21
|
+
function fromString(str) {
|
|
22
|
+
const res = parse(str);
|
|
23
|
+
if (!res.OME) {
|
|
24
|
+
throw Error('Failed to parse OME-XML metadata.');
|
|
25
|
+
}
|
|
26
|
+
return (0, tiff_utils_1.ensureArray)(res.OME.Image).map((img) => {
|
|
27
|
+
const Channels = (0, tiff_utils_1.ensureArray)(img.Pixels.Channel).map((c) => {
|
|
28
|
+
if ('Color' in c.attr) {
|
|
29
|
+
return { ...c.attr, Color: (0, tiff_utils_1.intToRgba)(c.attr.Color) };
|
|
30
|
+
}
|
|
31
|
+
return { ...c.attr };
|
|
32
|
+
});
|
|
33
|
+
const { AquisitionDate = '', Description = '' } = img;
|
|
34
|
+
const image = {
|
|
35
|
+
...img.attr,
|
|
36
|
+
AquisitionDate,
|
|
37
|
+
Description,
|
|
38
|
+
Pixels: {
|
|
39
|
+
...img.Pixels.attr,
|
|
40
|
+
Channels
|
|
41
|
+
}
|
|
25
42
|
};
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
return { ...c.attr
|
|
29
|
-
};
|
|
30
|
-
});
|
|
31
|
-
const {
|
|
32
|
-
AquisitionDate = '',
|
|
33
|
-
Description = ''
|
|
34
|
-
} = img;
|
|
35
|
-
const image = { ...img.attr,
|
|
36
|
-
AquisitionDate,
|
|
37
|
-
Description,
|
|
38
|
-
Pixels: { ...img.Pixels.attr,
|
|
39
|
-
Channels
|
|
40
|
-
}
|
|
41
|
-
};
|
|
42
|
-
return { ...image,
|
|
43
|
-
|
|
44
|
-
format() {
|
|
45
|
-
const {
|
|
46
|
-
Pixels
|
|
47
|
-
} = image;
|
|
48
|
-
const sizes = ['X', 'Y', 'Z'].map(name => {
|
|
49
|
-
const size = Pixels["PhysicalSize".concat(name)];
|
|
50
|
-
const unit = Pixels["PhysicalSize".concat(name, "Unit")];
|
|
51
|
-
return size && unit ? "".concat(size, " ").concat(unit) : '-';
|
|
52
|
-
}).join(' x ');
|
|
53
43
|
return {
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
44
|
+
...image,
|
|
45
|
+
format() {
|
|
46
|
+
const { Pixels } = image;
|
|
47
|
+
const sizes = ['X', 'Y', 'Z']
|
|
48
|
+
.map((name) => {
|
|
49
|
+
const size = Pixels[`PhysicalSize${name}`];
|
|
50
|
+
const unit = Pixels[`PhysicalSize${name}Unit`];
|
|
51
|
+
return size && unit ? `${size} ${unit}` : '-';
|
|
52
|
+
})
|
|
53
|
+
.join(' x ');
|
|
54
|
+
return {
|
|
55
|
+
'Acquisition Date': image.AquisitionDate,
|
|
56
|
+
'Dimensions (XY)': `${Pixels.SizeX} x ${Pixels.SizeY}`,
|
|
57
|
+
'Pixels Type': Pixels.Type,
|
|
58
|
+
'Pixels Size (XYZ)': sizes,
|
|
59
|
+
'Z-sections/Timepoints': `${Pixels.SizeZ} x ${Pixels.SizeT}`,
|
|
60
|
+
Channels: Pixels.SizeC
|
|
61
|
+
};
|
|
62
|
+
}
|
|
60
63
|
};
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
};
|
|
64
|
-
});
|
|
64
|
+
});
|
|
65
65
|
}
|
|
66
|
-
|
|
66
|
+
exports.fromString = fromString;
|
package/dist/lib/ome/utils.js
CHANGED
|
@@ -1,21 +1,30 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getDims = exports.getLabels = void 0;
|
|
4
|
+
function getLabels(dimOrder) {
|
|
5
|
+
return dimOrder.toLowerCase().split('').reverse();
|
|
3
6
|
}
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
7
|
+
exports.getLabels = getLabels;
|
|
8
|
+
/*
|
|
9
|
+
* Creates an ES6 map of 'label' -> index
|
|
10
|
+
* > const labels = ['a', 'b', 'c', 'd'];
|
|
11
|
+
* > const dims = getDims(labels);
|
|
12
|
+
* > dims('a') === 0;
|
|
13
|
+
* > dims('b') === 1;
|
|
14
|
+
* > dims('c') === 2;
|
|
15
|
+
* > dims('hi!'); // throws
|
|
16
|
+
*/
|
|
17
|
+
function getDims(labels) {
|
|
18
|
+
const lookup = new Map(labels.map((name, i) => [name, i]));
|
|
19
|
+
if (lookup.size !== labels.length) {
|
|
20
|
+
throw Error('Labels must be unique, found duplicated label.');
|
|
16
21
|
}
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
22
|
+
return (name) => {
|
|
23
|
+
const index = lookup.get(name);
|
|
24
|
+
if (index === undefined) {
|
|
25
|
+
throw Error('Invalid dimension.');
|
|
26
|
+
}
|
|
27
|
+
return index;
|
|
28
|
+
};
|
|
20
29
|
}
|
|
21
|
-
|
|
30
|
+
exports.getDims = getDims;
|
|
@@ -1,111 +1,64 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const tiff_utils_1 = require("./utils/tiff-utils");
|
|
4
4
|
class TiffPixelSource {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
_defineProperty(this, "meta", void 0);
|
|
15
|
-
|
|
16
|
-
_defineProperty(this, "_indexer", void 0);
|
|
17
|
-
|
|
18
|
-
this._indexer = indexer;
|
|
19
|
-
this.dtype = dtype;
|
|
20
|
-
this.tileSize = tileSize;
|
|
21
|
-
this.shape = shape;
|
|
22
|
-
this.labels = labels;
|
|
23
|
-
this.meta = meta;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
async getRaster({
|
|
27
|
-
selection,
|
|
28
|
-
signal
|
|
29
|
-
}) {
|
|
30
|
-
const image = await this._indexer(selection);
|
|
31
|
-
return this._readRasters(image, {
|
|
32
|
-
signal
|
|
33
|
-
});
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
async getTile({
|
|
37
|
-
x,
|
|
38
|
-
y,
|
|
39
|
-
selection,
|
|
40
|
-
signal
|
|
41
|
-
}) {
|
|
42
|
-
const {
|
|
43
|
-
height,
|
|
44
|
-
width
|
|
45
|
-
} = this._getTileExtent(x, y);
|
|
46
|
-
|
|
47
|
-
const x0 = x * this.tileSize;
|
|
48
|
-
const y0 = y * this.tileSize;
|
|
49
|
-
const window = [x0, y0, x0 + width, y0 + height];
|
|
50
|
-
const image = await this._indexer(selection);
|
|
51
|
-
return this._readRasters(image, {
|
|
52
|
-
window,
|
|
53
|
-
width,
|
|
54
|
-
height,
|
|
55
|
-
signal
|
|
56
|
-
});
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
async _readRasters(image, props) {
|
|
60
|
-
var _props$signal;
|
|
61
|
-
|
|
62
|
-
const interleave = isInterleaved(this.shape);
|
|
63
|
-
const raster = await image.readRasters({
|
|
64
|
-
interleave,
|
|
65
|
-
...props
|
|
66
|
-
});
|
|
67
|
-
|
|
68
|
-
if (props !== null && props !== void 0 && (_props$signal = props.signal) !== null && _props$signal !== void 0 && _props$signal.aborted) {
|
|
69
|
-
throw SIGNAL_ABORTED;
|
|
5
|
+
// eslint-disable-next-line max-params
|
|
6
|
+
constructor(indexer, dtype, tileSize, shape, labels, meta) {
|
|
7
|
+
this._indexer = indexer;
|
|
8
|
+
this.dtype = dtype;
|
|
9
|
+
this.tileSize = tileSize;
|
|
10
|
+
this.shape = shape;
|
|
11
|
+
this.labels = labels;
|
|
12
|
+
this.meta = meta;
|
|
70
13
|
}
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
data,
|
|
75
|
-
width: raster.width,
|
|
76
|
-
height: raster.height
|
|
77
|
-
};
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
_getTileExtent(x, y) {
|
|
81
|
-
const {
|
|
82
|
-
height: zoomLevelHeight,
|
|
83
|
-
width: zoomLevelWidth
|
|
84
|
-
} = getImageSize(this);
|
|
85
|
-
let height = this.tileSize;
|
|
86
|
-
let width = this.tileSize;
|
|
87
|
-
const maxXTileCoord = Math.floor(zoomLevelWidth / this.tileSize);
|
|
88
|
-
const maxYTileCoord = Math.floor(zoomLevelHeight / this.tileSize);
|
|
89
|
-
|
|
90
|
-
if (x === maxXTileCoord) {
|
|
91
|
-
width = zoomLevelWidth % this.tileSize;
|
|
14
|
+
async getRaster({ selection, signal }) {
|
|
15
|
+
const image = await this._indexer(selection);
|
|
16
|
+
return this._readRasters(image, { signal });
|
|
92
17
|
}
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
18
|
+
async getTile({ x, y, selection, signal }) {
|
|
19
|
+
const { height, width } = this._getTileExtent(x, y);
|
|
20
|
+
const x0 = x * this.tileSize;
|
|
21
|
+
const y0 = y * this.tileSize;
|
|
22
|
+
const window = [x0, y0, x0 + width, y0 + height];
|
|
23
|
+
const image = await this._indexer(selection);
|
|
24
|
+
return this._readRasters(image, { window, width, height, signal });
|
|
25
|
+
}
|
|
26
|
+
async _readRasters(image, props) {
|
|
27
|
+
const interleave = (0, tiff_utils_1.isInterleaved)(this.shape);
|
|
28
|
+
const raster = await image.readRasters({ interleave, ...props });
|
|
29
|
+
if (props?.signal?.aborted) {
|
|
30
|
+
throw tiff_utils_1.SIGNAL_ABORTED;
|
|
31
|
+
}
|
|
32
|
+
/*
|
|
33
|
+
* geotiff.js returns objects with different structure
|
|
34
|
+
* depending on `interleave`. It's weird, but this seems to work.
|
|
35
|
+
*/
|
|
36
|
+
const data = (interleave ? raster : raster[0]);
|
|
37
|
+
return {
|
|
38
|
+
data,
|
|
39
|
+
width: raster.width,
|
|
40
|
+
height: raster.height
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
/*
|
|
44
|
+
* Computes tile size given x, y coord.
|
|
45
|
+
*/
|
|
46
|
+
_getTileExtent(x, y) {
|
|
47
|
+
const { height: zoomLevelHeight, width: zoomLevelWidth } = (0, tiff_utils_1.getImageSize)(this);
|
|
48
|
+
let height = this.tileSize;
|
|
49
|
+
let width = this.tileSize;
|
|
50
|
+
const maxXTileCoord = Math.floor(zoomLevelWidth / this.tileSize);
|
|
51
|
+
const maxYTileCoord = Math.floor(zoomLevelHeight / this.tileSize);
|
|
52
|
+
if (x === maxXTileCoord) {
|
|
53
|
+
width = zoomLevelWidth % this.tileSize;
|
|
54
|
+
}
|
|
55
|
+
if (y === maxYTileCoord) {
|
|
56
|
+
height = zoomLevelHeight % this.tileSize;
|
|
57
|
+
}
|
|
58
|
+
return { height, width };
|
|
59
|
+
}
|
|
60
|
+
onTileError(err) {
|
|
61
|
+
console.error(err); // eslint-disable-line no-console
|
|
96
62
|
}
|
|
97
|
-
|
|
98
|
-
return {
|
|
99
|
-
height,
|
|
100
|
-
width
|
|
101
|
-
};
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
onTileError(err) {
|
|
105
|
-
console.error(err);
|
|
106
|
-
}
|
|
107
|
-
|
|
108
63
|
}
|
|
109
|
-
|
|
110
|
-
export default TiffPixelSource;
|
|
111
|
-
//# sourceMappingURL=tiff-pixel-source.js.map
|
|
64
|
+
exports.default = TiffPixelSource;
|
package/dist/lib/utils/Pool.js
CHANGED
|
@@ -1,77 +1,83 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
// import Worker from 'web-worker:./decoder.worker.ts';
|
|
4
|
+
// https://developer.mozilla.org/en-US/docs/Web/API/NavigatorConcurrentHardware/hardwareConcurrency
|
|
5
|
+
// We need to give a different way of getting this for safari, so 4 is probably a safe bet
|
|
6
|
+
// for parallel processing in the meantime. More can't really hurt since they'll just block
|
|
7
|
+
// each other and not the UI thread, which is the real benefit.
|
|
8
|
+
const defaultPoolSize = globalThis?.navigator?.hardwareConcurrency ?? 4;
|
|
9
|
+
/**
|
|
10
|
+
* Pool for workers to decode chunks of the images.
|
|
11
|
+
* This is a line-for-line copy of GeoTIFFs old implementation: https://github.com/geotiffjs/geotiff.js/blob/v1.0.0-beta.6/src/pool.js
|
|
12
|
+
*/
|
|
13
|
+
class Pool {
|
|
14
|
+
/**
|
|
15
|
+
* @constructor
|
|
16
|
+
* @param {Number} size The size of the pool. Defaults to the number of CPUs
|
|
17
|
+
* available. When this parameter is `null` or 0, then the
|
|
18
|
+
* decoding will be done in the main thread.
|
|
19
|
+
*/
|
|
20
|
+
constructor(size = defaultPoolSize) {
|
|
21
|
+
this.workers = [];
|
|
22
|
+
this.idleWorkers = [];
|
|
23
|
+
this.waitQueue = [];
|
|
24
|
+
this.decoder = null;
|
|
25
|
+
// eslint-disable-next-line no-plusplus
|
|
26
|
+
for (let i = 0; i < size; ++i) {
|
|
27
|
+
const w = new Worker('./decoder.worker');
|
|
28
|
+
this.workers.push(w);
|
|
29
|
+
this.idleWorkers.push(w);
|
|
30
|
+
}
|
|
25
31
|
}
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
this.
|
|
33
|
-
resolve
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
if (idleWorker) {
|
|
49
|
-
return idleWorker;
|
|
32
|
+
/**
|
|
33
|
+
* Decode the given block of bytes with the set compression method.
|
|
34
|
+
* @param {ArrayBuffer} buffer the array buffer of bytes to decode.
|
|
35
|
+
* @returns {Promise.<ArrayBuffer>} the decoded result as a `Promise`
|
|
36
|
+
*/
|
|
37
|
+
async decode(fileDirectory, buffer) {
|
|
38
|
+
const currentWorker = await this.waitForWorker();
|
|
39
|
+
return new Promise((resolve, reject) => {
|
|
40
|
+
currentWorker.onmessage = (event) => {
|
|
41
|
+
// this.workers.push(currentWorker);
|
|
42
|
+
// eslint-disable-next-line
|
|
43
|
+
this.finishTask(currentWorker);
|
|
44
|
+
resolve(event.data[0]);
|
|
45
|
+
};
|
|
46
|
+
currentWorker.onerror = (error) => {
|
|
47
|
+
// this.workers.push(currentWorker);
|
|
48
|
+
// eslint-disable-next-line
|
|
49
|
+
this.finishTask(currentWorker);
|
|
50
|
+
reject(error);
|
|
51
|
+
};
|
|
52
|
+
currentWorker.postMessage(['decode', fileDirectory, buffer], [buffer]);
|
|
53
|
+
});
|
|
50
54
|
}
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
if (waiter) {
|
|
64
|
-
waiter.resolve(currentWorker);
|
|
65
|
-
} else {
|
|
66
|
-
this.idleWorkers.push(currentWorker);
|
|
55
|
+
async waitForWorker() {
|
|
56
|
+
const idleWorker = this.idleWorkers.pop();
|
|
57
|
+
if (idleWorker) {
|
|
58
|
+
return idleWorker;
|
|
59
|
+
}
|
|
60
|
+
const waiter = {};
|
|
61
|
+
const promise = new Promise((resolve) => {
|
|
62
|
+
waiter.resolve = resolve;
|
|
63
|
+
});
|
|
64
|
+
this.waitQueue.push(waiter);
|
|
65
|
+
return promise;
|
|
67
66
|
}
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
67
|
+
async finishTask(currentWorker) {
|
|
68
|
+
const waiter = this.waitQueue.pop();
|
|
69
|
+
if (waiter) {
|
|
70
|
+
waiter.resolve(currentWorker);
|
|
71
|
+
}
|
|
72
|
+
else {
|
|
73
|
+
this.idleWorkers.push(currentWorker);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
destroy() {
|
|
77
|
+
// eslint-disable-next-line no-plusplus
|
|
78
|
+
for (let i = 0; i < this.workers.length; ++i) {
|
|
79
|
+
this.workers[i].terminate();
|
|
80
|
+
}
|
|
73
81
|
}
|
|
74
|
-
}
|
|
75
|
-
|
|
76
82
|
}
|
|
77
|
-
|
|
83
|
+
exports.default = Pool;
|
|
@@ -1,63 +1,86 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createPoolProxy = exports.createOffsetsProxy = exports.checkProxies = void 0;
|
|
1
4
|
const VIV_PROXY_KEY = '__viv';
|
|
2
|
-
const OFFSETS_PROXY_KEY =
|
|
3
|
-
const POOL_PROXY_KEY =
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
5
|
+
const OFFSETS_PROXY_KEY = `${VIV_PROXY_KEY}-offsets`;
|
|
6
|
+
const POOL_PROXY_KEY = `${VIV_PROXY_KEY}-decoder-pool`;
|
|
7
|
+
/*
|
|
8
|
+
* Inspect if the GeoTIFF source is wrapped in our proxies,
|
|
9
|
+
* and warn if missing.
|
|
10
|
+
*/
|
|
11
|
+
function checkProxies(tiff) {
|
|
12
|
+
if (!isProxy(tiff, OFFSETS_PROXY_KEY)) {
|
|
13
|
+
console.warn('GeoTIFF source is missing offsets proxy.'); // eslint-disable-line no-console
|
|
14
|
+
}
|
|
15
|
+
if (!isProxy(tiff, POOL_PROXY_KEY)) {
|
|
16
|
+
console.warn('GeoTIFF source is missing decoder-pool proxy.'); // eslint-disable-line no-console
|
|
17
|
+
}
|
|
12
18
|
}
|
|
13
|
-
|
|
19
|
+
exports.checkProxies = checkProxies;
|
|
20
|
+
/*
|
|
21
|
+
* > isProxy(tiff, POOL_PROXY_KEY) === true; // false
|
|
22
|
+
* > tiff = createPoolProxy(tiff, new Pool());
|
|
23
|
+
* > isProxy(tiff, POOL_PROXY_KEY) === true; // true
|
|
24
|
+
*/
|
|
14
25
|
function isProxy(tiff, proxyFlag) {
|
|
15
|
-
|
|
26
|
+
return tiff[proxyFlag];
|
|
16
27
|
}
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
28
|
+
/*
|
|
29
|
+
* Creates an ES6 Proxy that wraps a GeoTIFF object. The proxy
|
|
30
|
+
* handler intercepts calls to `tiff.getImage` and uses our custom
|
|
31
|
+
* pre-computed offsets to pre-fetch the correct file directory.
|
|
32
|
+
*
|
|
33
|
+
* This is a bit of a hack. Internally GeoTIFF inspects `this.ifdRequests`
|
|
34
|
+
* to see which fileDirectories need to be traversed. By adding the
|
|
35
|
+
* ifdRequest for an 'index' manually, GeoTIFF will await that request
|
|
36
|
+
* rather than traversing the file system remotely.
|
|
37
|
+
*/
|
|
38
|
+
function createOffsetsProxy(tiff, offsets) {
|
|
39
|
+
const get = (target, key) => {
|
|
40
|
+
// Intercept `tiff.getImage`
|
|
41
|
+
if (key === 'getImage') {
|
|
42
|
+
return (index) => {
|
|
43
|
+
// Manually add ifdRequest to tiff if missing and we have an offset.
|
|
44
|
+
if (!(index in target.ifdRequests) && index in offsets) {
|
|
45
|
+
const offset = offsets[index];
|
|
46
|
+
target.ifdRequests[index] = target.parseFileDirectoryAt(offset);
|
|
47
|
+
}
|
|
48
|
+
return target.getImage(index);
|
|
49
|
+
};
|
|
25
50
|
}
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
return Reflect.get(target, key);
|
|
36
|
-
};
|
|
37
|
-
|
|
38
|
-
return new Proxy(tiff, {
|
|
39
|
-
get
|
|
40
|
-
});
|
|
51
|
+
// tiff['__viv-offsets'] === true
|
|
52
|
+
if (key === OFFSETS_PROXY_KEY) {
|
|
53
|
+
return true;
|
|
54
|
+
}
|
|
55
|
+
return Reflect.get(target, key);
|
|
56
|
+
};
|
|
57
|
+
return new Proxy(tiff, { get });
|
|
41
58
|
}
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
59
|
+
exports.createOffsetsProxy = createOffsetsProxy;
|
|
60
|
+
/*
|
|
61
|
+
* Creates an ES6 Proxy that wraps a GeoTIFF object. The proxy
|
|
62
|
+
* handler intercepts calls to `tiff.readRasters` and injects
|
|
63
|
+
* a pool argument to every call. This means our TiffPixelSource
|
|
64
|
+
* doesn't need to be aware of whether a decoder pool is in use.
|
|
65
|
+
*
|
|
66
|
+
* > tiff.readRasters({ window }) -> tiff.readRasters({ window, pool });
|
|
67
|
+
*/
|
|
68
|
+
function createPoolProxy(tiff, pool) {
|
|
69
|
+
const get = (target, key) => {
|
|
70
|
+
// Intercept calls to `image.readRasters`
|
|
71
|
+
if (key === 'readRasters') {
|
|
72
|
+
return (options) => {
|
|
73
|
+
// Inject `pool` argument with other raster options.
|
|
74
|
+
// @ts-ignore
|
|
75
|
+
return target.readRasters({ ...options, pool });
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
// tiff['__viv-decoder-pool'] === true
|
|
79
|
+
if (key === POOL_PROXY_KEY) {
|
|
80
|
+
return true;
|
|
81
|
+
}
|
|
82
|
+
return Reflect.get(target, key);
|
|
83
|
+
};
|
|
84
|
+
return new Proxy(tiff, { get });
|
|
62
85
|
}
|
|
63
|
-
|
|
86
|
+
exports.createPoolProxy = createPoolProxy;
|