@loaders.gl/geotiff 4.0.0-alpha.1 → 4.0.0-alpha.11

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 (117) hide show
  1. package/dist/bundle.d.ts +2 -0
  2. package/dist/bundle.d.ts.map +1 -0
  3. package/dist/bundle.js +28 -2
  4. package/dist/es5/bundle.js +9 -0
  5. package/dist/es5/bundle.js.map +1 -0
  6. package/dist/es5/index.js +21 -0
  7. package/dist/es5/index.js.map +1 -0
  8. package/dist/es5/lib/load-geotiff.js +76 -0
  9. package/dist/es5/lib/load-geotiff.js.map +1 -0
  10. package/dist/es5/lib/ome/load-ome-tiff.js +66 -0
  11. package/dist/es5/lib/ome/load-ome-tiff.js.map +1 -0
  12. package/dist/es5/lib/ome/ome-indexers.js +140 -0
  13. package/dist/es5/lib/ome/ome-indexers.js.map +1 -0
  14. package/dist/es5/lib/ome/ome-utils.js +74 -0
  15. package/dist/es5/lib/ome/ome-utils.js.map +1 -0
  16. package/dist/es5/lib/ome/omexml.js +68 -0
  17. package/dist/es5/lib/ome/omexml.js.map +1 -0
  18. package/dist/es5/lib/ome/utils.js +26 -0
  19. package/dist/es5/lib/ome/utils.js.map +1 -0
  20. package/dist/es5/lib/tiff-pixel-source.js +163 -0
  21. package/dist/es5/lib/tiff-pixel-source.js.map +1 -0
  22. package/dist/es5/lib/utils/Pool.js +136 -0
  23. package/dist/es5/lib/utils/Pool.js.map +1 -0
  24. package/dist/es5/lib/utils/proxies.js +65 -0
  25. package/dist/es5/lib/utils/proxies.js.map +1 -0
  26. package/dist/es5/lib/utils/tiff-utils.js +43 -0
  27. package/dist/es5/lib/utils/tiff-utils.js.map +1 -0
  28. package/dist/es5/types.js +2 -0
  29. package/dist/es5/types.js.map +1 -0
  30. package/dist/es5/typings/geotiff.js +2 -0
  31. package/dist/es5/typings/geotiff.js.map +1 -0
  32. package/dist/esm/bundle.js +4 -0
  33. package/dist/esm/bundle.js.map +1 -0
  34. package/dist/esm/index.js +3 -0
  35. package/dist/esm/index.js.map +1 -0
  36. package/dist/esm/lib/load-geotiff.js +28 -0
  37. package/dist/esm/lib/load-geotiff.js.map +1 -0
  38. package/dist/esm/lib/ome/load-ome-tiff.js +47 -0
  39. package/dist/esm/lib/ome/load-ome-tiff.js.map +1 -0
  40. package/dist/esm/lib/ome/ome-indexers.js +120 -0
  41. package/dist/esm/lib/ome/ome-indexers.js.map +1 -0
  42. package/dist/esm/lib/ome/ome-utils.js +66 -0
  43. package/dist/esm/lib/ome/ome-utils.js.map +1 -0
  44. package/dist/esm/lib/ome/omexml.js +64 -0
  45. package/dist/esm/lib/ome/omexml.js.map +1 -0
  46. package/dist/esm/lib/ome/utils.js +17 -0
  47. package/dist/esm/lib/ome/utils.js.map +1 -0
  48. package/dist/esm/lib/tiff-pixel-source.js +92 -0
  49. package/dist/esm/lib/tiff-pixel-source.js.map +1 -0
  50. package/dist/esm/lib/utils/Pool.js +61 -0
  51. package/dist/esm/lib/utils/Pool.js.map +1 -0
  52. package/dist/esm/lib/utils/decoder.worker.ts.disabled +21 -0
  53. package/dist/esm/lib/utils/proxies.js +54 -0
  54. package/dist/esm/lib/utils/proxies.js.map +1 -0
  55. package/dist/esm/lib/utils/tiff-utils.js +27 -0
  56. package/dist/esm/lib/utils/tiff-utils.js.map +1 -0
  57. package/dist/esm/types.js +2 -0
  58. package/dist/esm/types.js.map +1 -0
  59. package/dist/esm/typings/geotiff.js +2 -0
  60. package/dist/esm/typings/geotiff.js.map +1 -0
  61. package/dist/index.d.ts +3 -0
  62. package/dist/index.d.ts.map +1 -0
  63. package/dist/index.js +10 -3
  64. package/dist/lib/load-geotiff.d.ts +28 -0
  65. package/dist/lib/load-geotiff.d.ts.map +1 -0
  66. package/dist/lib/load-geotiff.js +56 -31
  67. package/dist/lib/ome/load-ome-tiff.d.ts +50 -0
  68. package/dist/lib/ome/load-ome-tiff.d.ts.map +1 -0
  69. package/dist/lib/ome/load-ome-tiff.js +45 -50
  70. package/dist/lib/ome/ome-indexers.d.ts +11 -0
  71. package/dist/lib/ome/ome-indexers.d.ts.map +1 -0
  72. package/dist/lib/ome/ome-indexers.js +104 -112
  73. package/dist/lib/ome/ome-utils.d.ts +28 -0
  74. package/dist/lib/ome/ome-utils.d.ts.map +1 -0
  75. package/dist/lib/ome/ome-utils.js +59 -69
  76. package/dist/lib/ome/omexml.d.ts +49 -0
  77. package/dist/lib/ome/omexml.d.ts.map +1 -0
  78. package/dist/lib/ome/omexml.js +60 -60
  79. package/dist/lib/ome/utils.d.ts +5 -0
  80. package/dist/lib/ome/utils.d.ts.map +1 -0
  81. package/dist/lib/ome/utils.js +27 -18
  82. package/dist/lib/tiff-pixel-source.d.ts +18 -0
  83. package/dist/lib/tiff-pixel-source.d.ts.map +1 -0
  84. package/dist/lib/tiff-pixel-source.js +59 -106
  85. package/dist/lib/utils/Pool.d.ts +29 -0
  86. package/dist/lib/utils/Pool.d.ts.map +1 -0
  87. package/dist/lib/utils/Pool.js +78 -72
  88. package/dist/lib/utils/proxies.d.ts +6 -0
  89. package/dist/lib/utils/proxies.d.ts.map +1 -0
  90. package/dist/lib/utils/proxies.js +79 -56
  91. package/dist/lib/utils/tiff-utils.d.ts +10 -0
  92. package/dist/lib/utils/tiff-utils.d.ts.map +1 -0
  93. package/dist/lib/utils/tiff-utils.js +40 -24
  94. package/dist/types.d.ts +47 -0
  95. package/dist/types.d.ts.map +1 -0
  96. package/dist/types.js +2 -2
  97. package/dist/typings/geotiff.d.ts +60 -0
  98. package/dist/typings/geotiff.d.ts.map +1 -0
  99. package/dist/typings/geotiff.js +1 -2
  100. package/package.json +7 -7
  101. package/dist/bundle.js.map +0 -1
  102. package/dist/dist.min.js +0 -13
  103. package/dist/dist.min.js.map +0 -1
  104. package/dist/index.js.map +0 -1
  105. package/dist/lib/load-geotiff.js.map +0 -1
  106. package/dist/lib/ome/load-ome-tiff.js.map +0 -1
  107. package/dist/lib/ome/ome-indexers.js.map +0 -1
  108. package/dist/lib/ome/ome-utils.js.map +0 -1
  109. package/dist/lib/ome/omexml.js.map +0 -1
  110. package/dist/lib/ome/utils.js.map +0 -1
  111. package/dist/lib/tiff-pixel-source.js.map +0 -1
  112. package/dist/lib/utils/Pool.js.map +0 -1
  113. package/dist/lib/utils/proxies.js.map +0 -1
  114. package/dist/lib/utils/tiff-utils.js.map +0 -1
  115. package/dist/types.js.map +0 -1
  116. package/dist/typings/geotiff.js.map +0 -1
  117. /package/dist/{lib → es5/lib}/utils/decoder.worker.ts.disabled +0 -0
@@ -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;
@@ -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 = "".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;
@@ -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
- export function ensureArray(x) {
2
- return Array.isArray(x) ? x : [x];
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
- export function intToRgba(int) {
5
- if (!Number.isInteger(int)) {
6
- throw Error('Not an integer.');
7
- }
8
-
9
- const buffer = new ArrayBuffer(4);
10
- const view = new DataView(buffer);
11
- view.setInt32(0, int, false);
12
- const bytes = new Uint8Array(buffer);
13
- return Array.from(bytes);
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
- export function isInterleaved(shape) {
16
- const lastDimSize = shape[shape.length - 1];
17
- return lastDimSize === 3 || lastDimSize === 4;
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
- export function getImageSize(source) {
20
- const interleaved = isInterleaved(source.shape);
21
- const [height, width] = source.shape.slice(interleaved ? -3 : -2);
22
- return {
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
- export const SIGNAL_ABORTED = '__vivSignalAborted';
28
- //# sourceMappingURL=tiff-utils.js.map
43
+ exports.getImageSize = getImageSize;
44
+ exports.SIGNAL_ABORTED = '__vivSignalAborted';
@@ -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
- export {};
2
- //# sourceMappingURL=types.js.map
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"}
@@ -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.1",
3
+ "version": "4.0.0-alpha.11",
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": "src/index.ts",
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": "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": "e48f5534fe7188c810f23f965a440c144b3cf6d0"
42
+ "gitHead": "bc680098cfea790c67b7fb95bab96e8d9288d34f"
43
43
  }
@@ -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"}