@loaders.gl/geotiff 3.1.0-alpha.4 → 3.1.0-beta.3

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 (76) hide show
  1. package/dist/bundle.d.ts +2 -0
  2. package/dist/bundle.d.ts.map +1 -0
  3. package/dist/bundle.js +26 -0
  4. package/dist/es5/bundle.js +2 -4
  5. package/dist/es5/bundle.js.map +1 -1
  6. package/dist/es5/index.js +2 -2
  7. package/dist/es5/lib/load-geotiff.js +27 -85
  8. package/dist/es5/lib/load-geotiff.js.map +1 -1
  9. package/dist/es5/lib/ome/load-ome-tiff.js +45 -62
  10. package/dist/es5/lib/ome/load-ome-tiff.js.map +1 -1
  11. package/dist/es5/lib/ome/ome-indexers.js +75 -117
  12. package/dist/es5/lib/ome/ome-indexers.js.map +1 -1
  13. package/dist/es5/lib/ome/ome-utils.js +18 -21
  14. package/dist/es5/lib/ome/ome-utils.js.map +1 -1
  15. package/dist/es5/lib/ome/omexml.js +30 -35
  16. package/dist/es5/lib/ome/omexml.js.map +1 -1
  17. package/dist/es5/lib/ome/utils.js +3 -5
  18. package/dist/es5/lib/ome/utils.js.map +1 -1
  19. package/dist/es5/lib/tiff-pixel-source.js +83 -169
  20. package/dist/es5/lib/tiff-pixel-source.js.map +1 -1
  21. package/dist/es5/lib/utils/Pool.js +53 -141
  22. package/dist/es5/lib/utils/Pool.js.map +1 -1
  23. package/dist/es5/lib/utils/proxies.js +13 -22
  24. package/dist/es5/lib/utils/proxies.js.map +1 -1
  25. package/dist/es5/lib/utils/tiff-utils.js +9 -18
  26. package/dist/es5/lib/utils/tiff-utils.js.map +1 -1
  27. package/dist/esm/lib/ome/ome-indexers.js +2 -2
  28. package/dist/esm/lib/ome/ome-indexers.js.map +1 -1
  29. package/dist/esm/lib/ome/ome-utils.js +1 -1
  30. package/dist/esm/lib/ome/ome-utils.js.map +1 -1
  31. package/dist/esm/lib/ome/omexml.js +5 -5
  32. package/dist/esm/lib/ome/omexml.js.map +1 -1
  33. package/dist/esm/lib/utils/proxies.js +2 -2
  34. package/dist/esm/lib/utils/proxies.js.map +1 -1
  35. package/dist/index.d.ts +3 -0
  36. package/dist/index.d.ts.map +1 -0
  37. package/dist/index.js +10 -0
  38. package/dist/lib/load-geotiff.d.ts +28 -0
  39. package/dist/lib/load-geotiff.d.ts.map +1 -0
  40. package/dist/lib/load-geotiff.js +57 -0
  41. package/dist/lib/ome/load-ome-tiff.d.ts +50 -0
  42. package/dist/lib/ome/load-ome-tiff.d.ts.map +1 -0
  43. package/dist/lib/ome/load-ome-tiff.js +46 -0
  44. package/dist/lib/ome/ome-indexers.d.ts +11 -0
  45. package/dist/lib/ome/ome-indexers.d.ts.map +1 -0
  46. package/dist/lib/ome/ome-indexers.js +108 -0
  47. package/dist/lib/ome/ome-utils.d.ts +28 -0
  48. package/dist/lib/ome/ome-utils.d.ts.map +1 -0
  49. package/dist/lib/ome/ome-utils.js +63 -0
  50. package/dist/lib/ome/omexml.d.ts +49 -0
  51. package/dist/lib/ome/omexml.d.ts.map +1 -0
  52. package/dist/lib/ome/omexml.js +66 -0
  53. package/dist/lib/ome/utils.d.ts +5 -0
  54. package/dist/lib/ome/utils.d.ts.map +1 -0
  55. package/dist/lib/ome/utils.js +30 -0
  56. package/dist/lib/tiff-pixel-source.d.ts +18 -0
  57. package/dist/lib/tiff-pixel-source.d.ts.map +1 -0
  58. package/dist/lib/tiff-pixel-source.js +64 -0
  59. package/dist/lib/utils/Pool.d.ts +29 -0
  60. package/dist/lib/utils/Pool.d.ts.map +1 -0
  61. package/dist/lib/utils/Pool.js +83 -0
  62. package/dist/lib/utils/proxies.d.ts +6 -0
  63. package/dist/lib/utils/proxies.d.ts.map +1 -0
  64. package/dist/lib/utils/proxies.js +86 -0
  65. package/dist/lib/utils/tiff-utils.d.ts +10 -0
  66. package/dist/lib/utils/tiff-utils.d.ts.map +1 -0
  67. package/dist/lib/utils/tiff-utils.js +44 -0
  68. package/dist/types.d.ts +47 -0
  69. package/dist/types.d.ts.map +1 -0
  70. package/dist/types.js +2 -0
  71. package/dist/typings/geotiff.d.ts +60 -0
  72. package/dist/typings/geotiff.d.ts.map +1 -0
  73. package/dist/typings/geotiff.js +1 -0
  74. package/package.json +5 -5
  75. package/dist/dist.min.js +0 -13
  76. package/dist/dist.min.js.map +0 -1
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/lib/ome/utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,MAAM,EAAC,MAAM,eAAe,CAAC;AAC1C,OAAO,KAAK,EAAC,MAAM,EAAC,MAAM,aAAa,CAAC;AAYxC,wBAAgB,SAAS,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,gBAAgB,CAAC,qHAExE;AAWD,wBAAgB,OAAO,CAAC,CAAC,SAAS,MAAM,EAAE,MAAM,EAAE,CAAC,EAAE,UAKrC,CAAC,YAOhB"}
@@ -0,0 +1,30 @@
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();
6
+ }
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.');
21
+ }
22
+ return (name) => {
23
+ const index = lookup.get(name);
24
+ if (index === undefined) {
25
+ throw Error('Invalid dimension.');
26
+ }
27
+ return index;
28
+ };
29
+ }
30
+ exports.getDims = getDims;
@@ -0,0 +1,18 @@
1
+ import type { GeoTIFFImage } from 'geotiff';
2
+ import type { PixelSource, PixelSourceSelection, PixelSourceMeta, Dtype, Labels, RasterSelection, TileSelection, PixelData } from '../types';
3
+ declare class TiffPixelSource<S extends string[]> implements PixelSource<S> {
4
+ dtype: Dtype;
5
+ tileSize: number;
6
+ shape: number[];
7
+ labels: Labels<S>;
8
+ meta: PixelSourceMeta | undefined;
9
+ private _indexer;
10
+ constructor(indexer: (sel: PixelSourceSelection<S>) => Promise<GeoTIFFImage>, dtype: Dtype, tileSize: number, shape: number[], labels: Labels<S>, meta?: PixelSourceMeta);
11
+ getRaster({ selection, signal }: RasterSelection<S>): Promise<PixelData>;
12
+ getTile({ x, y, selection, signal }: TileSelection<S>): Promise<PixelData>;
13
+ private _readRasters;
14
+ private _getTileExtent;
15
+ onTileError(err: Error): void;
16
+ }
17
+ export default TiffPixelSource;
18
+ //# sourceMappingURL=tiff-pixel-source.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tiff-pixel-source.d.ts","sourceRoot":"","sources":["../../src/lib/tiff-pixel-source.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,YAAY,EAAgB,MAAM,SAAS,CAAC;AAGzD,OAAO,KAAK,EACV,WAAW,EACX,oBAAoB,EACpB,eAAe,EACf,KAAK,EACL,MAAM,EACN,eAAe,EACf,aAAa,EACb,SAAS,EAEV,MAAM,UAAU,CAAC;AAElB,cAAM,eAAe,CAAC,CAAC,SAAS,MAAM,EAAE,CAAE,YAAW,WAAW,CAAC,CAAC,CAAC;IAC1D,KAAK,EAAE,KAAK,CAAC;IACb,QAAQ,EAAE,MAAM,CAAC;IACjB,KAAK,EAAE,MAAM,EAAE,CAAC;IAChB,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC,CAAC;IAClB,IAAI,EAAE,eAAe,GAAG,SAAS,CAAC;IACzC,OAAO,CAAC,QAAQ,CAA0D;gBAIxE,OAAO,EAAE,CAAC,GAAG,EAAE,oBAAoB,CAAC,CAAC,CAAC,KAAK,OAAO,CAAC,YAAY,CAAC,EAChE,KAAK,EAAE,KAAK,EACZ,QAAQ,EAAE,MAAM,EAChB,KAAK,EAAE,MAAM,EAAE,EACf,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC,EACjB,IAAI,CAAC,EAAE,eAAe;IAUlB,SAAS,CAAC,EAAC,SAAS,EAAE,MAAM,EAAC,EAAE,eAAe,CAAC,CAAC,CAAC;IAKjD,OAAO,CAAC,EAAC,CAAC,EAAE,CAAC,EAAE,SAAS,EAAE,MAAM,EAAC,EAAE,aAAa,CAAC,CAAC,CAAC;YAU3C,YAAY;IAuB1B,OAAO,CAAC,cAAc;IAetB,WAAW,CAAC,GAAG,EAAE,KAAK;CAGvB;AAED,eAAe,eAAe,CAAC"}
@@ -0,0 +1,64 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tiff_utils_1 = require("./utils/tiff-utils");
4
+ class TiffPixelSource {
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;
13
+ }
14
+ async getRaster({ selection, signal }) {
15
+ const image = await this._indexer(selection);
16
+ return this._readRasters(image, { signal });
17
+ }
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
62
+ }
63
+ }
64
+ exports.default = TiffPixelSource;
@@ -0,0 +1,29 @@
1
+ /** eslint-disable */
2
+ import type { FileDirectory } from 'geotiff';
3
+ /**
4
+ * Pool for workers to decode chunks of the images.
5
+ * 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
6
+ */
7
+ export default class Pool {
8
+ workers: Worker[];
9
+ idleWorkers: Worker[];
10
+ waitQueue: any[];
11
+ decoder: null;
12
+ /**
13
+ * @constructor
14
+ * @param {Number} size The size of the pool. Defaults to the number of CPUs
15
+ * available. When this parameter is `null` or 0, then the
16
+ * decoding will be done in the main thread.
17
+ */
18
+ constructor(size?: number);
19
+ /**
20
+ * Decode the given block of bytes with the set compression method.
21
+ * @param {ArrayBuffer} buffer the array buffer of bytes to decode.
22
+ * @returns {Promise.<ArrayBuffer>} the decoded result as a `Promise`
23
+ */
24
+ decode(fileDirectory: FileDirectory, buffer: ArrayBuffer): Promise<unknown>;
25
+ waitForWorker(): Promise<Worker>;
26
+ finishTask(currentWorker: Worker): Promise<void>;
27
+ destroy(): void;
28
+ }
29
+ //# sourceMappingURL=Pool.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Pool.d.ts","sourceRoot":"","sources":["../../../src/lib/utils/Pool.ts"],"names":[],"mappings":"AAAA,qBAAqB;AACrB,OAAO,KAAK,EAAC,aAAa,EAAC,MAAM,SAAS,CAAC;AAU3C;;;GAGG;AACH,MAAM,CAAC,OAAO,OAAO,IAAI;IACvB,OAAO,EAAE,MAAM,EAAE,CAAC;IAClB,WAAW,EAAE,MAAM,EAAE,CAAC;IACtB,SAAS,EAAE,GAAG,EAAE,CAAC;IACjB,OAAO,EAAE,IAAI,CAAC;IAEd;;;;;OAKG;gBACS,IAAI,SAAkB;IAclC;;;;OAIG;IACG,MAAM,CAAC,aAAa,EAAE,aAAa,EAAE,MAAM,EAAE,WAAW;IAmBxD,aAAa;IAcb,UAAU,CAAC,aAAa,EAAE,MAAM;IAStC,OAAO;CAMR"}
@@ -0,0 +1,83 @@
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
+ }
31
+ }
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
+ });
54
+ }
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;
66
+ }
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
+ }
81
+ }
82
+ }
83
+ exports.default = Pool;
@@ -0,0 +1,6 @@
1
+ import type { GeoTIFF } from 'geotiff';
2
+ import type Pool from './Pool';
3
+ export declare function checkProxies(tiff: GeoTIFF): void;
4
+ export declare function createOffsetsProxy(tiff: GeoTIFF, offsets: number[]): GeoTIFF;
5
+ export declare function createPoolProxy(tiff: GeoTIFF, pool: Pool): GeoTIFF;
6
+ //# sourceMappingURL=proxies.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"proxies.d.ts","sourceRoot":"","sources":["../../../src/lib/utils/proxies.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,OAAO,EAAC,MAAM,SAAS,CAAC;AACrC,OAAO,KAAK,IAAI,MAAM,QAAQ,CAAC;AAU/B,wBAAgB,YAAY,CAAC,IAAI,EAAE,OAAO,QAQzC;AAqBD,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,WAsBlE;AAUD,wBAAgB,eAAe,CAAC,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,IAAI,WAmBxD"}
@@ -0,0 +1,86 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createPoolProxy = exports.createOffsetsProxy = exports.checkProxies = void 0;
4
+ const VIV_PROXY_KEY = '__viv';
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
+ }
18
+ }
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
+ */
25
+ function isProxy(tiff, proxyFlag) {
26
+ return tiff[proxyFlag];
27
+ }
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
+ };
50
+ }
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 });
58
+ }
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 });
85
+ }
86
+ exports.createPoolProxy = createPoolProxy;
@@ -0,0 +1,10 @@
1
+ import type { PixelSource } from '../../types';
2
+ export declare function ensureArray<T>(x: T | T[]): T[];
3
+ export declare function intToRgba(int: number): [number, number, number, number];
4
+ export declare function isInterleaved(shape: number[]): boolean;
5
+ export declare function getImageSize<T extends string[]>(source: PixelSource<T>): {
6
+ height: number;
7
+ width: number;
8
+ };
9
+ export declare const SIGNAL_ABORTED = "__vivSignalAborted";
10
+ //# sourceMappingURL=tiff-utils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tiff-utils.d.ts","sourceRoot":"","sources":["../../../src/lib/utils/tiff-utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,WAAW,EAAC,MAAM,aAAa,CAAC;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"}
@@ -0,0 +1,44 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SIGNAL_ABORTED = exports.getImageSize = exports.isInterleaved = exports.intToRgba = exports.ensureArray = void 0;
4
+ function ensureArray(x) {
5
+ return Array.isArray(x) ? x : [x];
6
+ }
7
+ exports.ensureArray = ensureArray;
8
+ /*
9
+ * Converts 32-bit integer color representation to RGBA tuple.
10
+ * Used to serialize colors from OME-XML metadata.
11
+ *
12
+ * > console.log(intToRgba(100100));
13
+ * > // [0, 1, 135, 4]
14
+ */
15
+ function intToRgba(int) {
16
+ if (!Number.isInteger(int)) {
17
+ throw Error('Not an integer.');
18
+ }
19
+ // Write number to int32 representation (4 bytes).
20
+ const buffer = new ArrayBuffer(4);
21
+ const view = new DataView(buffer);
22
+ view.setInt32(0, int, false); // offset === 0, littleEndian === false
23
+ // Take u8 view and extract number for each byte (1 byte for R/G/B/A).
24
+ const bytes = new Uint8Array(buffer);
25
+ return Array.from(bytes);
26
+ }
27
+ exports.intToRgba = intToRgba;
28
+ /*
29
+ * Helper method to determine whether pixel data is interleaved or not.
30
+ * > isInterleaved([1, 24, 24]) === false;
31
+ * > isInterleaved([1, 24, 24, 3]) === true;
32
+ */
33
+ function isInterleaved(shape) {
34
+ const lastDimSize = shape[shape.length - 1];
35
+ return lastDimSize === 3 || lastDimSize === 4;
36
+ }
37
+ exports.isInterleaved = isInterleaved;
38
+ function getImageSize(source) {
39
+ const interleaved = isInterleaved(source.shape);
40
+ const [height, width] = source.shape.slice(interleaved ? -3 : -2);
41
+ return { height, width };
42
+ }
43
+ exports.getImageSize = getImageSize;
44
+ exports.SIGNAL_ABORTED = '__vivSignalAborted';
@@ -0,0 +1,47 @@
1
+ import { DTYPE_LOOKUP } from './lib/ome/ome-utils';
2
+ export declare type Dtype = typeof DTYPE_LOOKUP[keyof typeof DTYPE_LOOKUP];
3
+ export declare type TypedArray = InstanceType<typeof globalThis[`${Dtype}Array`]>;
4
+ export interface PixelData {
5
+ data: TypedArray;
6
+ width: number;
7
+ height: number;
8
+ }
9
+ export declare type PixelSourceSelection<S extends string[]> = {
10
+ [K in S[number]]: number;
11
+ };
12
+ export interface RasterSelection<S extends string[]> {
13
+ selection: PixelSourceSelection<S>;
14
+ signal?: AbortSignal;
15
+ }
16
+ export interface TileSelection<S extends string[]> {
17
+ x: number;
18
+ y: number;
19
+ selection: PixelSourceSelection<S>;
20
+ signal?: AbortSignal;
21
+ }
22
+ interface PhysicalSize {
23
+ size: number;
24
+ unit: string;
25
+ }
26
+ export interface PixelSourceMeta {
27
+ physicalSizes?: Record<string, PhysicalSize>;
28
+ photometricInterpretation?: number;
29
+ }
30
+ export declare type Labels<S extends string[]> = [...S, 'y', 'x'] | [...S, 'y', 'x', '_c'];
31
+ /**
32
+ * Interface to load tiles from a data source
33
+ */
34
+ export interface PixelSource<S extends string[]> {
35
+ /** Loads a 2D plane */
36
+ getRaster(sel: RasterSelection<S>): Promise<PixelData>;
37
+ /** Loads a tile */
38
+ getTile(sel: TileSelection<S>): Promise<PixelData>;
39
+ onTileError(err: Error): void;
40
+ shape: number[];
41
+ dtype: Dtype;
42
+ labels: Labels<S>;
43
+ tileSize: number;
44
+ meta?: PixelSourceMeta;
45
+ }
46
+ export {};
47
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,YAAY,EAAC,MAAM,qBAAqB,CAAC;AAEjD,oBAAY,KAAK,GAAG,OAAO,YAAY,CAAC,MAAM,OAAO,YAAY,CAAC,CAAC;AACnE,oBAAY,UAAU,GAAG,YAAY,CAAC,OAAO,UAAU,CAAC,GAAG,KAAK,OAAO,CAAC,CAAC,CAAC;AAE1E,MAAM,WAAW,SAAS;IACxB,IAAI,EAAE,UAAU,CAAC;IACjB,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;CAChB;AAED,oBAAY,oBAAoB,CAAC,CAAC,SAAS,MAAM,EAAE,IAAI;KACpD,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC,GAAG,MAAM;CACzB,CAAC;AAEF,MAAM,WAAW,eAAe,CAAC,CAAC,SAAS,MAAM,EAAE;IACjD,SAAS,EAAE,oBAAoB,CAAC,CAAC,CAAC,CAAC;IACnC,MAAM,CAAC,EAAE,WAAW,CAAC;CACtB;AAED,MAAM,WAAW,aAAa,CAAC,CAAC,SAAS,MAAM,EAAE;IAC/C,CAAC,EAAE,MAAM,CAAC;IACV,CAAC,EAAE,MAAM,CAAC;IACV,SAAS,EAAE,oBAAoB,CAAC,CAAC,CAAC,CAAC;IACnC,MAAM,CAAC,EAAE,WAAW,CAAC;CACtB;AAED,UAAU,YAAY;IACpB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;CACd;AAED,MAAM,WAAW,eAAe;IAC9B,aAAa,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,YAAY,CAAC,CAAC;IAC7C,yBAAyB,CAAC,EAAE,MAAM,CAAC;CACpC;AAED,oBAAY,MAAM,CAAC,CAAC,SAAS,MAAM,EAAE,IAAI,CAAC,GAAG,CAAC,EAAE,GAAG,EAAE,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,GAAG,EAAE,GAAG,EAAE,IAAI,CAAC,CAAC;AAEnF;;GAEG;AACH,MAAM,WAAW,WAAW,CAAC,CAAC,SAAS,MAAM,EAAE;IAC7C,uBAAuB;IACvB,SAAS,CAAC,GAAG,EAAE,eAAe,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,SAAS,CAAC,CAAC;IACvD,mBAAmB;IACnB,OAAO,CAAC,GAAG,EAAE,aAAa,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 ADDED
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,60 @@
1
+ declare type TypedArray = import('../types').TypedArray;
2
+ declare module 'geotiff' {
3
+ function fromUrl(url: string, headers?: Record<string, unknown>): Promise<GeoTIFF>;
4
+ function fromBlob(blob: Blob): Promise<GeoTIFF>;
5
+ function fromFile(path: string): Promise<GeoTIFF>;
6
+ class GeoTIFF {
7
+ readRasters(options?: RasterOptions): Promise<TypedArray>;
8
+ getImage(index: number): Promise<GeoTIFFImage>;
9
+ parseFileDirectoryAt(offset: number): Promise<ImageFileDirectory>;
10
+ ifdRequests: {
11
+ [key: number]: Promise<ImageFileDirectory>;
12
+ };
13
+ dataView: DataView;
14
+ littleEndian: boolean;
15
+ cache: any;
16
+ source: any;
17
+ }
18
+ interface Pool {
19
+ decode(fileDirectory: FileDirectory, buffer: ArrayBuffer): Promise<ArrayBuffer>;
20
+ }
21
+ interface RasterOptions {
22
+ window?: number[];
23
+ bbox?: number[];
24
+ samples?: number[];
25
+ interleave?: boolean;
26
+ pool?: Pool;
27
+ width?: number;
28
+ height?: number;
29
+ resampleMethod?: string;
30
+ enableAlpha?: boolean;
31
+ signal?: AbortSignal;
32
+ }
33
+ type RasterData = (TypedArray | TypedArray[]) & {
34
+ width: number;
35
+ height: number;
36
+ };
37
+ class GeoTIFFImage {
38
+ constructor(fileDirectory: FileDirectory, geoKeyDirectory: any, dataView: DataView, littleEndian: boolean, cache: any, source: any);
39
+ fileDirectory: FileDirectory;
40
+ getBoundingBox(): number[];
41
+ getFileDirectory(): FileDirectory;
42
+ getBytesPerPixel(): number;
43
+ getHeight(): number;
44
+ getSamplesPerPixel(): number;
45
+ getTileHeight(): number;
46
+ getTileWidth(): number;
47
+ getWidth(): number;
48
+ readRasters(options?: RasterOptions): Promise<RasterData>;
49
+ }
50
+ interface FileDirectory {
51
+ ImageDescription: string;
52
+ SubIFDs?: number[];
53
+ PhotometricInterpretation?: number;
54
+ }
55
+ interface ImageFileDirectory {
56
+ fileDirectory: FileDirectory;
57
+ geoKeyDirectory: any;
58
+ }
59
+ }
60
+ //# sourceMappingURL=geotiff.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"geotiff.d.ts","sourceRoot":"","sources":["../../src/typings/geotiff.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,UAAU,GAAG,OAAO,UAAU,EAAE,UAAU,CAAC;AAExD,OAAO,QAAQ,SAAS,CAAC;IACvB,SAAS,OAAO,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;IACnF,SAAS,QAAQ,CAAC,IAAI,EAAE,IAAI,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;IAChD,SAAS,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;IAElD,MAAM,OAAO;QACX,WAAW,CAAC,OAAO,CAAC,EAAE,aAAa,GAAG,OAAO,CAAC,UAAU,CAAC;QACzD,QAAQ,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,YAAY,CAAC;QAC9C,oBAAoB,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,kBAAkB,CAAC;QACjE,WAAW,EAAE;YAAC,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,kBAAkB,CAAC,CAAA;SAAC,CAAC;QAC1D,QAAQ,EAAE,QAAQ,CAAC;QACnB,YAAY,EAAE,OAAO,CAAC;QACtB,KAAK,EAAE,GAAG,CAAC;QACX,MAAM,EAAE,GAAG,CAAC;KACb;IAED,UAAU,IAAI;QACZ,MAAM,CAAC,aAAa,EAAE,aAAa,EAAE,MAAM,EAAE,WAAW,GAAG,OAAO,CAAC,WAAW,CAAC,CAAC;KACjF;IAED,UAAU,aAAa;QACrB,MAAM,CAAC,EAAE,MAAM,EAAE,CAAC;QAClB,IAAI,CAAC,EAAE,MAAM,EAAE,CAAC;QAChB,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;QACnB,UAAU,CAAC,EAAE,OAAO,CAAC;QACrB,IAAI,CAAC,EAAE,IAAI,CAAC;QACZ,KAAK,CAAC,EAAE,MAAM,CAAC;QACf,MAAM,CAAC,EAAE,MAAM,CAAC;QAChB,cAAc,CAAC,EAAE,MAAM,CAAC;QACxB,WAAW,CAAC,EAAE,OAAO,CAAC;QACtB,MAAM,CAAC,EAAE,WAAW,CAAC;KACtB;IAED,KAAK,UAAU,GAAG,CAAC,UAAU,GAAG,UAAU,EAAE,CAAC,GAAG;QAC9C,KAAK,EAAE,MAAM,CAAC;QACd,MAAM,EAAE,MAAM,CAAC;KAChB,CAAC;IACF,MAAM,YAAY;oBAEd,aAAa,EAAE,aAAa,EAC5B,eAAe,EAAE,GAAG,EACpB,QAAQ,EAAE,QAAQ,EAClB,YAAY,EAAE,OAAO,EACrB,KAAK,EAAE,GAAG,EACV,MAAM,EAAE,GAAG;QAEb,aAAa,EAAE,aAAa,CAAC;QAC7B,cAAc,IAAI,MAAM,EAAE;QAC1B,gBAAgB,IAAI,aAAa;QACjC,gBAAgB,IAAI,MAAM;QAC1B,SAAS,IAAI,MAAM;QACnB,kBAAkB,IAAI,MAAM;QAC5B,aAAa,IAAI,MAAM;QACvB,YAAY,IAAI,MAAM;QACtB,QAAQ,IAAI,MAAM;QAClB,WAAW,CAAC,OAAO,CAAC,EAAE,aAAa,GAAG,OAAO,CAAC,UAAU,CAAC;KAC1D;IAED,UAAU,aAAa;QACrB,gBAAgB,EAAE,MAAM,CAAC;QACzB,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;QACnB,yBAAyB,CAAC,EAAE,MAAM,CAAC;KACpC;IAED,UAAU,kBAAkB;QAC1B,aAAa,EAAE,aAAa,CAAC;QAC7B,eAAe,EAAE,GAAG,CAAC;KACtB;CACF"}
@@ -0,0 +1 @@
1
+ "use strict";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@loaders.gl/geotiff",
3
- "version": "3.1.0-alpha.4",
3
+ "version": "3.1.0-beta.3",
4
4
  "description": "Framework-independent loaders for tiff and geotiff",
5
5
  "license": "MIT",
6
6
  "publishConfig": {
@@ -18,7 +18,7 @@
18
18
  "tiff",
19
19
  "geotiff"
20
20
  ],
21
- "types": "src/index.ts",
21
+ "types": "dist/index.d.ts",
22
22
  "main": "dist/es5/index.js",
23
23
  "module": "dist/esm/index.js",
24
24
  "sideEffects": false,
@@ -29,8 +29,8 @@
29
29
  "README.md"
30
30
  ],
31
31
  "scripts": {
32
- "pre-build": "npm run build-bundle",
33
- "build-bundle": "webpack --display=minimal --config ../../scripts/webpack/bundle.js"
32
+ "pre-build": "# npm run build-bundle",
33
+ "build-bundle": "esbuild src/bundle.ts --outfile=dist/dist.min.js --bundle --minify --sourcemap --external:{fs,http,https}"
34
34
  },
35
35
  "dependencies-disabled": {
36
36
  "geotiff": "ilan-gold/geotiff.js#ilan-gold/viv_094"
@@ -39,5 +39,5 @@
39
39
  "fast-xml-parser": "^3.16.0",
40
40
  "geotiff": "^1.0.4"
41
41
  },
42
- "gitHead": "e309784af37ef9f3640c7733c7851124c72e1fa3"
42
+ "gitHead": "3537c382b3ea4e092b24b6f94c3edee72076039c"
43
43
  }