@loaders.gl/geotiff 4.0.0-alpha.5 → 4.0.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.
Files changed (93) hide show
  1. package/dist/bundle.js +28 -2
  2. package/dist/es5/bundle.js +9 -0
  3. package/dist/es5/bundle.js.map +1 -0
  4. package/dist/es5/index.js +21 -0
  5. package/dist/es5/index.js.map +1 -0
  6. package/dist/es5/lib/load-geotiff.js +76 -0
  7. package/dist/es5/lib/load-geotiff.js.map +1 -0
  8. package/dist/es5/lib/ome/load-ome-tiff.js +66 -0
  9. package/dist/es5/lib/ome/load-ome-tiff.js.map +1 -0
  10. package/dist/es5/lib/ome/ome-indexers.js +140 -0
  11. package/dist/es5/lib/ome/ome-indexers.js.map +1 -0
  12. package/dist/es5/lib/ome/ome-utils.js +74 -0
  13. package/dist/es5/lib/ome/ome-utils.js.map +1 -0
  14. package/dist/es5/lib/ome/omexml.js +68 -0
  15. package/dist/es5/lib/ome/omexml.js.map +1 -0
  16. package/dist/es5/lib/ome/utils.js +26 -0
  17. package/dist/es5/lib/ome/utils.js.map +1 -0
  18. package/dist/es5/lib/tiff-pixel-source.js +163 -0
  19. package/dist/es5/lib/tiff-pixel-source.js.map +1 -0
  20. package/dist/es5/lib/utils/Pool.js +136 -0
  21. package/dist/es5/lib/utils/Pool.js.map +1 -0
  22. package/dist/es5/lib/utils/proxies.js +65 -0
  23. package/dist/es5/lib/utils/proxies.js.map +1 -0
  24. package/dist/es5/lib/utils/tiff-utils.js +43 -0
  25. package/dist/es5/lib/utils/tiff-utils.js.map +1 -0
  26. package/dist/es5/types.js +2 -0
  27. package/dist/es5/types.js.map +1 -0
  28. package/dist/es5/typings/geotiff.js +2 -0
  29. package/dist/es5/typings/geotiff.js.map +1 -0
  30. package/dist/esm/bundle.js +4 -0
  31. package/dist/esm/bundle.js.map +1 -0
  32. package/dist/esm/index.js +3 -0
  33. package/dist/esm/index.js.map +1 -0
  34. package/dist/esm/lib/load-geotiff.js +28 -0
  35. package/dist/esm/lib/load-geotiff.js.map +1 -0
  36. package/dist/esm/lib/ome/load-ome-tiff.js +47 -0
  37. package/dist/esm/lib/ome/load-ome-tiff.js.map +1 -0
  38. package/dist/esm/lib/ome/ome-indexers.js +120 -0
  39. package/dist/esm/lib/ome/ome-indexers.js.map +1 -0
  40. package/dist/esm/lib/ome/ome-utils.js +66 -0
  41. package/dist/esm/lib/ome/ome-utils.js.map +1 -0
  42. package/dist/esm/lib/ome/omexml.js +64 -0
  43. package/dist/esm/lib/ome/omexml.js.map +1 -0
  44. package/dist/esm/lib/ome/utils.js +17 -0
  45. package/dist/esm/lib/ome/utils.js.map +1 -0
  46. package/dist/esm/lib/tiff-pixel-source.js +92 -0
  47. package/dist/esm/lib/tiff-pixel-source.js.map +1 -0
  48. package/dist/esm/lib/utils/Pool.js +61 -0
  49. package/dist/esm/lib/utils/Pool.js.map +1 -0
  50. package/dist/esm/lib/utils/decoder.worker.ts.disabled +21 -0
  51. package/dist/esm/lib/utils/proxies.js +54 -0
  52. package/dist/esm/lib/utils/proxies.js.map +1 -0
  53. package/dist/esm/lib/utils/tiff-utils.js +27 -0
  54. package/dist/esm/lib/utils/tiff-utils.js.map +1 -0
  55. package/dist/esm/types.js +2 -0
  56. package/dist/esm/types.js.map +1 -0
  57. package/dist/esm/typings/geotiff.js +2 -0
  58. package/dist/esm/typings/geotiff.js.map +1 -0
  59. package/dist/index.js +10 -3
  60. package/dist/lib/load-geotiff.js +56 -31
  61. package/dist/lib/ome/load-ome-tiff.js +45 -50
  62. package/dist/lib/ome/ome-indexers.d.ts +2 -2
  63. package/dist/lib/ome/ome-indexers.d.ts.map +1 -1
  64. package/dist/lib/ome/ome-indexers.js +104 -112
  65. package/dist/lib/ome/ome-utils.js +59 -69
  66. package/dist/lib/ome/omexml.d.ts +4 -4
  67. package/dist/lib/ome/omexml.d.ts.map +1 -1
  68. package/dist/lib/ome/omexml.js +60 -60
  69. package/dist/lib/ome/utils.js +27 -18
  70. package/dist/lib/tiff-pixel-source.js +59 -106
  71. package/dist/lib/utils/Pool.js +78 -72
  72. package/dist/lib/utils/proxies.js +79 -56
  73. package/dist/lib/utils/tiff-utils.js +40 -24
  74. package/dist/types.d.ts +4 -4
  75. package/dist/types.d.ts.map +1 -1
  76. package/dist/types.js +2 -2
  77. package/dist/typings/geotiff.js +1 -2
  78. package/package.json +4 -4
  79. package/dist/bundle.js.map +0 -1
  80. package/dist/index.js.map +0 -1
  81. package/dist/lib/load-geotiff.js.map +0 -1
  82. package/dist/lib/ome/load-ome-tiff.js.map +0 -1
  83. package/dist/lib/ome/ome-indexers.js.map +0 -1
  84. package/dist/lib/ome/ome-utils.js.map +0 -1
  85. package/dist/lib/ome/omexml.js.map +0 -1
  86. package/dist/lib/ome/utils.js.map +0 -1
  87. package/dist/lib/tiff-pixel-source.js.map +0 -1
  88. package/dist/lib/utils/Pool.js.map +0 -1
  89. package/dist/lib/utils/proxies.js.map +0 -1
  90. package/dist/lib/utils/tiff-utils.js.map +0 -1
  91. package/dist/types.js.map +0 -1
  92. package/dist/typings/geotiff.js.map +0 -1
  93. /package/dist/{lib → es5/lib}/utils/decoder.worker.ts.disabled +0 -0
@@ -1,66 +1,66 @@
1
- import parser from 'fast-xml-parser';
2
- import { ensureArray, intToRgba } from '../utils/tiff-utils';
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
- attributeNamePrefix: '',
5
- attrNodeName: 'attr',
6
- parseNodeValue: true,
7
- parseAttributeValue: true,
8
- ignoreAttributes: false
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
- const parse = str => parser.parse(str, PARSER_OPTIONS);
12
-
13
- export function fromString(str) {
14
- const res = parse(str);
15
-
16
- if (!res.OME) {
17
- throw Error('Failed to parse OME-XML metadata.');
18
- }
19
-
20
- return ensureArray(res.OME.Image).map(img => {
21
- const Channels = ensureArray(img.Pixels.Channel).map(c => {
22
- if ('Color' in c.attr) {
23
- return { ...c.attr,
24
- Color: intToRgba(c.attr.Color)
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
- 'Acquisition Date': image.AquisitionDate,
55
- 'Dimensions (XY)': "".concat(Pixels.SizeX, " x ").concat(Pixels.SizeY),
56
- 'Pixels Type': Pixels.Type,
57
- 'Pixels Size (XYZ)': sizes,
58
- 'Z-sections/Timepoints': "".concat(Pixels.SizeZ, " x ").concat(Pixels.SizeT),
59
- Channels: Pixels.SizeC
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
- //# sourceMappingURL=omexml.js.map
66
+ exports.fromString = fromString;
@@ -1,21 +1,30 @@
1
- export function getLabels(dimOrder) {
2
- return dimOrder.toLowerCase().split('').reverse();
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
- export function getDims(labels) {
5
- const lookup = new Map(labels.map((name, i) => [name, i]));
6
-
7
- if (lookup.size !== labels.length) {
8
- throw Error('Labels must be unique, found duplicated label.');
9
- }
10
-
11
- return name => {
12
- const index = lookup.get(name);
13
-
14
- if (index === undefined) {
15
- throw Error('Invalid dimension.');
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
- return index;
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
- //# sourceMappingURL=utils.js.map
30
+ exports.getDims = getDims;
@@ -1,111 +1,64 @@
1
- import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
2
- import { getImageSize, isInterleaved, SIGNAL_ABORTED } from './utils/tiff-utils';
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
- constructor(indexer, dtype, tileSize, shape, labels, meta) {
6
- _defineProperty(this, "dtype", void 0);
7
-
8
- _defineProperty(this, "tileSize", void 0);
9
-
10
- _defineProperty(this, "shape", void 0);
11
-
12
- _defineProperty(this, "labels", void 0);
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
- const data = interleave ? raster : raster[0];
73
- return {
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
- if (y === maxYTileCoord) {
95
- height = zoomLevelHeight % this.tileSize;
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;
@@ -1,77 +1,83 @@
1
- import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
2
-
3
- var _globalThis$navigator, _globalThis$navigator2;
4
-
5
- const defaultPoolSize = (_globalThis$navigator = globalThis === null || globalThis === void 0 ? void 0 : (_globalThis$navigator2 = globalThis.navigator) === null || _globalThis$navigator2 === void 0 ? void 0 : _globalThis$navigator2.hardwareConcurrency) !== null && _globalThis$navigator !== void 0 ? _globalThis$navigator : 4;
6
- export default class Pool {
7
- constructor(size = defaultPoolSize) {
8
- _defineProperty(this, "workers", void 0);
9
-
10
- _defineProperty(this, "idleWorkers", void 0);
11
-
12
- _defineProperty(this, "waitQueue", void 0);
13
-
14
- _defineProperty(this, "decoder", void 0);
15
-
16
- this.workers = [];
17
- this.idleWorkers = [];
18
- this.waitQueue = [];
19
- this.decoder = null;
20
-
21
- for (let i = 0; i < size; ++i) {
22
- const w = new Worker('./decoder.worker');
23
- this.workers.push(w);
24
- this.idleWorkers.push(w);
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
- async decode(fileDirectory, buffer) {
29
- const currentWorker = await this.waitForWorker();
30
- return new Promise((resolve, reject) => {
31
- currentWorker.onmessage = event => {
32
- this.finishTask(currentWorker);
33
- resolve(event.data[0]);
34
- };
35
-
36
- currentWorker.onerror = error => {
37
- this.finishTask(currentWorker);
38
- reject(error);
39
- };
40
-
41
- currentWorker.postMessage(['decode', fileDirectory, buffer], [buffer]);
42
- });
43
- }
44
-
45
- async waitForWorker() {
46
- const idleWorker = this.idleWorkers.pop();
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
- const waiter = {};
53
- const promise = new Promise(resolve => {
54
- waiter.resolve = resolve;
55
- });
56
- this.waitQueue.push(waiter);
57
- return promise;
58
- }
59
-
60
- async finishTask(currentWorker) {
61
- const waiter = this.waitQueue.pop();
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
- destroy() {
71
- for (let i = 0; i < this.workers.length; ++i) {
72
- this.workers[i].terminate();
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
- //# sourceMappingURL=Pool.js.map
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 = "".concat(VIV_PROXY_KEY, "-offsets");
3
- const POOL_PROXY_KEY = "".concat(VIV_PROXY_KEY, "-decoder-pool");
4
- export function checkProxies(tiff) {
5
- if (!isProxy(tiff, OFFSETS_PROXY_KEY)) {
6
- console.warn('GeoTIFF source is missing offsets proxy.');
7
- }
8
-
9
- if (!isProxy(tiff, POOL_PROXY_KEY)) {
10
- console.warn('GeoTIFF source is missing decoder-pool proxy.');
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
- return tiff[proxyFlag];
26
+ return tiff[proxyFlag];
16
27
  }
17
-
18
- export function createOffsetsProxy(tiff, offsets) {
19
- const get = (target, key) => {
20
- if (key === 'getImage') {
21
- return index => {
22
- if (!(index in target.ifdRequests) && index in offsets) {
23
- const offset = offsets[index];
24
- target.ifdRequests[index] = target.parseFileDirectoryAt(offset);
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
- return target.getImage(index);
28
- };
29
- }
30
-
31
- if (key === OFFSETS_PROXY_KEY) {
32
- return true;
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
- export function createPoolProxy(tiff, pool) {
43
- const get = (target, key) => {
44
- if (key === 'readRasters') {
45
- return options => {
46
- return target.readRasters({ ...options,
47
- pool
48
- });
49
- };
50
- }
51
-
52
- if (key === POOL_PROXY_KEY) {
53
- return true;
54
- }
55
-
56
- return Reflect.get(target, key);
57
- };
58
-
59
- return new Proxy(tiff, {
60
- get
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
- //# sourceMappingURL=proxies.js.map
86
+ exports.createPoolProxy = createPoolProxy;