@loaders.gl/geotiff 4.0.0-alpha.4 → 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.
- package/dist/bundle.d.ts +2 -0
- package/dist/bundle.d.ts.map +1 -0
- 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.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +10 -3
- package/dist/lib/load-geotiff.d.ts +28 -0
- package/dist/lib/load-geotiff.d.ts.map +1 -0
- package/dist/lib/load-geotiff.js +56 -31
- package/dist/lib/ome/load-ome-tiff.d.ts +50 -0
- package/dist/lib/ome/load-ome-tiff.d.ts.map +1 -0
- package/dist/lib/ome/load-ome-tiff.js +45 -50
- package/dist/lib/ome/ome-indexers.d.ts +11 -0
- package/dist/lib/ome/ome-indexers.d.ts.map +1 -0
- package/dist/lib/ome/ome-indexers.js +104 -112
- package/dist/lib/ome/ome-utils.d.ts +28 -0
- package/dist/lib/ome/ome-utils.d.ts.map +1 -0
- package/dist/lib/ome/ome-utils.js +59 -69
- package/dist/lib/ome/omexml.d.ts +49 -0
- package/dist/lib/ome/omexml.d.ts.map +1 -0
- package/dist/lib/ome/omexml.js +60 -60
- package/dist/lib/ome/utils.d.ts +5 -0
- package/dist/lib/ome/utils.d.ts.map +1 -0
- package/dist/lib/ome/utils.js +27 -18
- package/dist/lib/tiff-pixel-source.d.ts +18 -0
- package/dist/lib/tiff-pixel-source.d.ts.map +1 -0
- package/dist/lib/tiff-pixel-source.js +59 -106
- package/dist/lib/utils/Pool.d.ts +29 -0
- package/dist/lib/utils/Pool.d.ts.map +1 -0
- package/dist/lib/utils/Pool.js +78 -72
- package/dist/lib/utils/proxies.d.ts +6 -0
- package/dist/lib/utils/proxies.d.ts.map +1 -0
- package/dist/lib/utils/proxies.js +79 -56
- package/dist/lib/utils/tiff-utils.d.ts +10 -0
- package/dist/lib/utils/tiff-utils.d.ts.map +1 -0
- package/dist/lib/utils/tiff-utils.js +40 -24
- package/dist/types.d.ts +47 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +2 -2
- package/dist/typings/geotiff.d.ts +60 -0
- package/dist/typings/geotiff.d.ts.map +1 -0
- package/dist/typings/geotiff.js +1 -2
- package/package.json +7 -7
- package/dist/bundle.js.map +0 -1
- package/dist/dist.min.js +0 -13
- package/dist/dist.min.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/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;
|
|
@@ -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"}
|
|
@@ -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;
|
|
@@ -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"}
|
|
@@ -1,28 +1,44 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
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];
|
|
3
6
|
}
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
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);
|
|
14
26
|
}
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
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;
|
|
18
36
|
}
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
height,
|
|
24
|
-
width
|
|
25
|
-
};
|
|
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 };
|
|
26
42
|
}
|
|
27
|
-
|
|
28
|
-
|
|
43
|
+
exports.getImageSize = getImageSize;
|
|
44
|
+
exports.SIGNAL_ABORTED = '__vivSignalAborted';
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { DTYPE_LOOKUP } from './lib/ome/ome-utils';
|
|
2
|
+
export type Dtype = typeof DTYPE_LOOKUP[keyof typeof DTYPE_LOOKUP];
|
|
3
|
+
export type TypedArray = InstanceType<typeof globalThis[`${Dtype}Array`]>;
|
|
4
|
+
export interface PixelData {
|
|
5
|
+
data: TypedArray;
|
|
6
|
+
width: number;
|
|
7
|
+
height: number;
|
|
8
|
+
}
|
|
9
|
+
export 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 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,MAAM,MAAM,KAAK,GAAG,OAAO,YAAY,CAAC,MAAM,OAAO,YAAY,CAAC,CAAC;AACnE,MAAM,MAAM,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,MAAM,MAAM,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,MAAM,MAAM,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
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
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"}
|
package/dist/typings/geotiff.js
CHANGED
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
//# sourceMappingURL=geotiff.js.map
|
|
1
|
+
"use strict";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@loaders.gl/geotiff",
|
|
3
|
-
"version": "4.0.0-alpha.
|
|
3
|
+
"version": "4.0.0-alpha.6",
|
|
4
4
|
"description": "Framework-independent loaders for tiff and geotiff",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"publishConfig": {
|
|
@@ -18,9 +18,9 @@
|
|
|
18
18
|
"tiff",
|
|
19
19
|
"geotiff"
|
|
20
20
|
],
|
|
21
|
-
"types": "
|
|
22
|
-
"main": "dist/index.js",
|
|
23
|
-
"module": "dist/index.js",
|
|
21
|
+
"types": "dist/index.d.ts",
|
|
22
|
+
"main": "dist/es5/index.js",
|
|
23
|
+
"module": "dist/esm/index.js",
|
|
24
24
|
"sideEffects": false,
|
|
25
25
|
"files": [
|
|
26
26
|
"src",
|
|
@@ -29,8 +29,8 @@
|
|
|
29
29
|
"README.md"
|
|
30
30
|
],
|
|
31
31
|
"scripts": {
|
|
32
|
-
"pre-build": "npm run build-bundle",
|
|
33
|
-
"build-bundle": "
|
|
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": "
|
|
42
|
+
"gitHead": "acc1985050dfaa0f1f0c066f8da5bce7454a046c"
|
|
43
43
|
}
|
package/dist/bundle.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/bundle.ts"],"names":["moduleExports","globalThis","loaders","module","exports","Object","assign"],"mappings":"AAAA,OAAO,KAAKA,aAAZ,MAA+B,SAA/B;AAEAC,UAAU,CAACC,OAAX,GAAqBD,UAAU,CAACC,OAAX,IAAsB,EAA3C;AAEAC,MAAM,CAACC,OAAP,GAAiBC,MAAM,CAACC,MAAP,CAAcL,UAAU,CAACC,OAAzB,EAAkCF,aAAlC,CAAjB","sourcesContent":["import * as moduleExports from './index';\n// @ts-ignore\nglobalThis.loaders = globalThis.loaders || {};\n// @ts-ignore\nmodule.exports = Object.assign(globalThis.loaders, moduleExports);\n"],"file":"bundle.js"}
|