@loaders.gl/geotiff 4.0.4 → 4.1.0-alpha.10

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 (69) hide show
  1. package/dist/dist.dev.js +1257 -1073
  2. package/dist/geotiff-loader.d.ts +21 -0
  3. package/dist/geotiff-loader.d.ts.map +1 -0
  4. package/dist/geotiff-loader.js +59 -0
  5. package/dist/geotiff-loader.js.map +1 -0
  6. package/dist/index.cjs +46 -40
  7. package/dist/index.d.ts +2 -1
  8. package/dist/index.d.ts.map +1 -1
  9. package/dist/index.js +2 -1
  10. package/dist/index.js.map +1 -1
  11. package/dist/lib/load-geotiff.d.ts +1 -1
  12. package/dist/lib/load-geotiff.d.ts.map +1 -1
  13. package/dist/lib/load-geotiff.js +1 -5
  14. package/dist/lib/load-geotiff.js.map +1 -1
  15. package/dist/lib/ome/load-ome-tiff.d.ts +4 -4
  16. package/dist/lib/ome/load-ome-tiff.d.ts.map +1 -1
  17. package/dist/lib/ome/load-ome-tiff.js +1 -1
  18. package/dist/lib/ome/load-ome-tiff.js.map +1 -1
  19. package/dist/lib/ome/ome-indexers.d.ts +1 -0
  20. package/dist/lib/ome/ome-indexers.d.ts.map +1 -1
  21. package/dist/lib/ome/ome-indexers.js.map +1 -1
  22. package/dist/lib/ome/ome-utils.d.ts.map +1 -1
  23. package/dist/lib/ome/ome-utils.js.map +1 -1
  24. package/dist/lib/ome/omexml.d.ts.map +1 -1
  25. package/dist/lib/ome/omexml.js.map +1 -1
  26. package/dist/lib/ome/utils.d.ts.map +1 -1
  27. package/dist/lib/ome/utils.js.map +1 -1
  28. package/dist/lib/tiff-pixel-source.d.ts +1 -2
  29. package/dist/lib/tiff-pixel-source.d.ts.map +1 -1
  30. package/dist/lib/tiff-pixel-source.js +1 -2
  31. package/dist/lib/tiff-pixel-source.js.map +1 -1
  32. package/{src/lib/utils/Pool.ts → dist/lib/utils/Pool.ts.disabled} +5 -1
  33. package/{src/lib/utils/proxies.ts → dist/lib/utils/proxies.ts.disabled} +4 -0
  34. package/dist/lib/utils/tiff-utils.d.ts.map +1 -1
  35. package/dist/lib/utils/tiff-utils.js.map +1 -1
  36. package/dist/loaders.d.ts +13 -0
  37. package/dist/loaders.d.ts.map +1 -0
  38. package/dist/loaders.js +32 -0
  39. package/dist/loaders.js.map +1 -0
  40. package/dist/types.d.ts.map +1 -1
  41. package/dist/types.js.map +1 -1
  42. package/package.json +6 -5
  43. package/src/geotiff-loader.ts +115 -0
  44. package/src/index.ts +7 -1
  45. package/src/lib/load-geotiff.ts +12 -8
  46. package/src/lib/ome/load-ome-tiff.ts +5 -1
  47. package/src/lib/ome/ome-indexers.ts +9 -2
  48. package/src/lib/ome/ome-utils.ts +4 -0
  49. package/src/lib/ome/omexml.ts +4 -0
  50. package/src/lib/ome/utils.ts +4 -0
  51. package/src/lib/tiff-pixel-source.ts +9 -5
  52. package/src/lib/utils/Pool.ts.disabled +99 -0
  53. package/src/lib/utils/proxies.ts.disabled +96 -0
  54. package/src/lib/utils/tiff-utils.ts +4 -0
  55. package/src/loaders.ts +68 -0
  56. package/src/types.ts +4 -0
  57. package/dist/lib/utils/Pool.d.ts +0 -29
  58. package/dist/lib/utils/Pool.d.ts.map +0 -1
  59. package/dist/lib/utils/Pool.js +0 -60
  60. package/dist/lib/utils/Pool.js.map +0 -1
  61. package/dist/lib/utils/proxies.d.ts +0 -6
  62. package/dist/lib/utils/proxies.d.ts.map +0 -1
  63. package/dist/lib/utils/proxies.js +0 -54
  64. package/dist/lib/utils/proxies.js.map +0 -1
  65. package/dist/typings/geotiff.d.ts +0 -60
  66. package/dist/typings/geotiff.d.ts.map +0 -1
  67. package/dist/typings/geotiff.js +0 -2
  68. package/dist/typings/geotiff.js.map +0 -1
  69. package/src/typings/geotiff.ts +0 -71
@@ -0,0 +1,96 @@
1
+ // loaders.gl
2
+ // SPDX-License-Identifier: MIT
3
+ // Copyright (c) vis.gl contributors
4
+
5
+ import type {GeoTIFF} from 'geotiff';
6
+ import type Pool from './Pool';
7
+
8
+ const VIV_PROXY_KEY = '__viv';
9
+ const OFFSETS_PROXY_KEY = `${VIV_PROXY_KEY}-offsets` as const;
10
+ const POOL_PROXY_KEY = `${VIV_PROXY_KEY}-decoder-pool` as const;
11
+
12
+ /*
13
+ * Inspect if the GeoTIFF source is wrapped in our proxies,
14
+ * and warn if missing.
15
+ */
16
+ export function checkProxies(tiff: GeoTIFF) {
17
+ if (!isProxy(tiff, OFFSETS_PROXY_KEY)) {
18
+ console.warn('GeoTIFF source is missing offsets proxy.'); // eslint-disable-line no-console
19
+ }
20
+
21
+ if (!isProxy(tiff, POOL_PROXY_KEY)) {
22
+ console.warn('GeoTIFF source is missing decoder-pool proxy.'); // eslint-disable-line no-console
23
+ }
24
+ }
25
+
26
+ /*
27
+ * > isProxy(tiff, POOL_PROXY_KEY) === true; // false
28
+ * > tiff = createPoolProxy(tiff, new Pool());
29
+ * > isProxy(tiff, POOL_PROXY_KEY) === true; // true
30
+ */
31
+ function isProxy(tiff: GeoTIFF, proxyFlag: string) {
32
+ return (tiff as any)[proxyFlag] as boolean;
33
+ }
34
+
35
+ /*
36
+ * Creates an ES6 Proxy that wraps a GeoTIFF object. The proxy
37
+ * handler intercepts calls to `tiff.getImage` and uses our custom
38
+ * pre-computed offsets to pre-fetch the correct file directory.
39
+ *
40
+ * This is a bit of a hack. Internally GeoTIFF inspects `this.ifdRequests`
41
+ * to see which fileDirectories need to be traversed. By adding the
42
+ * ifdRequest for an 'index' manually, GeoTIFF will await that request
43
+ * rather than traversing the file system remotely.
44
+ */
45
+ export function createOffsetsProxy(tiff: GeoTIFF, offsets: number[]) {
46
+ const get = (target: GeoTIFF, key: any) => {
47
+ // Intercept `tiff.getImage`
48
+ if (key === 'getImage') {
49
+ return (index: number) => {
50
+ // Manually add ifdRequest to tiff if missing and we have an offset.
51
+ if (!(index in target.ifdRequests) && index in offsets) {
52
+ const offset = offsets[index];
53
+ target.ifdRequests[index] = target.parseFileDirectoryAt(offset);
54
+ }
55
+ return target.getImage(index);
56
+ };
57
+ }
58
+
59
+ // tiff['__viv-offsets'] === true
60
+ if (key === OFFSETS_PROXY_KEY) {
61
+ return true;
62
+ }
63
+
64
+ return Reflect.get(target, key);
65
+ };
66
+ return new Proxy(tiff, {get});
67
+ }
68
+
69
+ /*
70
+ * Creates an ES6 Proxy that wraps a GeoTIFF object. The proxy
71
+ * handler intercepts calls to `tiff.readRasters` and injects
72
+ * a pool argument to every call. This means our TiffPixelSource
73
+ * doesn't need to be aware of whether a decoder pool is in use.
74
+ *
75
+ * > tiff.readRasters({ window }) -> tiff.readRasters({ window, pool });
76
+ */
77
+ export function createPoolProxy(tiff: GeoTIFF, pool: Pool) {
78
+ const get = (target: GeoTIFF, key: any) => {
79
+ // Intercept calls to `image.readRasters`
80
+ if (key === 'readRasters') {
81
+ return (options: Parameters<typeof target.readRasters>) => {
82
+ // Inject `pool` argument with other raster options.
83
+ // @ts-ignore
84
+ return target.readRasters({...options, pool});
85
+ };
86
+ }
87
+
88
+ // tiff['__viv-decoder-pool'] === true
89
+ if (key === POOL_PROXY_KEY) {
90
+ return true;
91
+ }
92
+
93
+ return Reflect.get(target, key);
94
+ };
95
+ return new Proxy(tiff, {get});
96
+ }
@@ -1,3 +1,7 @@
1
+ // loaders.gl
2
+ // SPDX-License-Identifier: MIT
3
+ // Copyright (c) vis.gl contributors
4
+
1
5
  import type {PixelSource} from '../../types';
2
6
 
3
7
  export function ensureArray<T>(x: T | T[]) {
package/src/loaders.ts ADDED
@@ -0,0 +1,68 @@
1
+ import {fromArrayBuffer} from 'geotiff';
2
+ import type {LoaderWithParser, LoaderOptions} from '@loaders.gl/loader-utils';
3
+
4
+ // __VERSION__ is injected by babel-plugin-version-inline
5
+ // @ts-ignore TS2304: Cannot find name '__VERSION__'.
6
+ const VERSION = typeof __VERSION__ !== 'undefined' ? __VERSION__ : 'latest';
7
+
8
+ // Type definitions
9
+ type GeoTiffData = {
10
+ bounds: number[];
11
+ width: number;
12
+ height: number;
13
+ imageData: ImageData;
14
+ };
15
+
16
+ interface GeoTiffLoaderOptions extends LoaderOptions {
17
+ enableAlpha: boolean;
18
+ }
19
+
20
+ /**
21
+ * Loads a GeoTIFF file containing a RGB image.
22
+ */
23
+ const loadGeoTiff = async (
24
+ data: ArrayBuffer,
25
+ options?: GeoTiffLoaderOptions
26
+ ): Promise<GeoTiffData> => {
27
+ // Load using Geotiff.js
28
+ const tiff = await fromArrayBuffer(data);
29
+
30
+ // Assumes we only have one image inside TIFF
31
+ const image = await tiff.getImage();
32
+
33
+ // Read image and size
34
+ // TODO: Add support for worker pools here.
35
+ // TODO: Add support for more image formats.
36
+ const rgbData = await image.readRGB({
37
+ enableAlpha: options?.enableAlpha
38
+ });
39
+ const width = image.getWidth();
40
+ const height = image.getHeight();
41
+
42
+ // Create a new ImageData object
43
+ const imageData = new ImageData(width, height);
44
+ imageData.data.set(new Uint8ClampedArray(rgbData as unknown as Uint8Array));
45
+
46
+ // Return GeoJSON data
47
+ return {
48
+ // TODO: Add bounds here
49
+ bounds: [],
50
+ imageData,
51
+ width,
52
+ height
53
+ };
54
+ };
55
+
56
+ // Export loader
57
+ export const GeoTiffLoader: LoaderWithParser<GeoTiffData, never, GeoTiffLoaderOptions> = {
58
+ id: 'geotiff',
59
+ name: 'GeoTIFF',
60
+ module: 'geotiff',
61
+ version: VERSION,
62
+ options: {
63
+ enableAlpha: true
64
+ },
65
+ mimeTypes: ['image/tiff', 'image/geotiff'],
66
+ extensions: ['geotiff', 'tiff', 'geotif', 'tif'],
67
+ parse: loadGeoTiff
68
+ };
package/src/types.ts CHANGED
@@ -1,3 +1,7 @@
1
+ // loaders.gl
2
+ // SPDX-License-Identifier: MIT
3
+ // Copyright (c) vis.gl contributors
4
+
1
5
  import {DTYPE_LOOKUP} from './lib/ome/ome-utils';
2
6
 
3
7
  export type Dtype = (typeof DTYPE_LOOKUP)[keyof typeof DTYPE_LOOKUP];
@@ -1,29 +0,0 @@
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.8/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
@@ -1 +0,0 @@
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"}
@@ -1,60 +0,0 @@
1
- var _globalThis$navigator, _globalThis$navigator2;
2
- 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;
3
- export default class Pool {
4
- constructor() {
5
- let size = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : defaultPoolSize;
6
- this.workers = void 0;
7
- this.idleWorkers = void 0;
8
- this.waitQueue = void 0;
9
- this.decoder = void 0;
10
- this.workers = [];
11
- this.idleWorkers = [];
12
- this.waitQueue = [];
13
- this.decoder = null;
14
- for (let i = 0; i < size; ++i) {
15
- const w = new Worker('./decoder.worker');
16
- this.workers.push(w);
17
- this.idleWorkers.push(w);
18
- }
19
- }
20
- async decode(fileDirectory, buffer) {
21
- const currentWorker = await this.waitForWorker();
22
- return new Promise((resolve, reject) => {
23
- currentWorker.onmessage = event => {
24
- this.finishTask(currentWorker);
25
- resolve(event.data[0]);
26
- };
27
- currentWorker.onerror = error => {
28
- this.finishTask(currentWorker);
29
- reject(error);
30
- };
31
- currentWorker.postMessage(['decode', fileDirectory, buffer], [buffer]);
32
- });
33
- }
34
- async waitForWorker() {
35
- const idleWorker = this.idleWorkers.pop();
36
- if (idleWorker) {
37
- return idleWorker;
38
- }
39
- const waiter = {};
40
- const promise = new Promise(resolve => {
41
- waiter.resolve = resolve;
42
- });
43
- this.waitQueue.push(waiter);
44
- return promise;
45
- }
46
- async finishTask(currentWorker) {
47
- const waiter = this.waitQueue.pop();
48
- if (waiter) {
49
- waiter.resolve(currentWorker);
50
- } else {
51
- this.idleWorkers.push(currentWorker);
52
- }
53
- }
54
- destroy() {
55
- for (let i = 0; i < this.workers.length; ++i) {
56
- this.workers[i].terminate();
57
- }
58
- }
59
- }
60
- //# sourceMappingURL=Pool.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"Pool.js","names":["defaultPoolSize","_globalThis$navigator","globalThis","_globalThis$navigator2","navigator","hardwareConcurrency","Pool","constructor","size","arguments","length","undefined","workers","idleWorkers","waitQueue","decoder","i","w","Worker","push","decode","fileDirectory","buffer","currentWorker","waitForWorker","Promise","resolve","reject","onmessage","event","finishTask","data","onerror","error","postMessage","idleWorker","pop","waiter","promise","destroy","terminate"],"sources":["../../../src/lib/utils/Pool.ts"],"sourcesContent":["/** eslint-disable */\nimport type {FileDirectory} from 'geotiff';\n\n// import Worker from 'web-worker:./decoder.worker.ts';\n\n// https://developer.mozilla.org/en-US/docs/Web/API/NavigatorConcurrentHardware/hardwareConcurrency\n// We need to give a different way of getting this for safari, so 4 is probably a safe bet\n// for parallel processing in the meantime. More can't really hurt since they'll just block\n// each other and not the UI thread, which is the real benefit.\nconst defaultPoolSize = globalThis?.navigator?.hardwareConcurrency ?? 4;\n\n/**\n * Pool for workers to decode chunks of the images.\n * This is a line-for-line copy of GeoTIFFs old implementation: https://github.com/geotiffjs/geotiff.js/blob/v1.0.0-beta.8/src/pool.js\n */\nexport default class Pool {\n workers: Worker[];\n idleWorkers: Worker[];\n waitQueue: any[];\n decoder: null;\n\n /**\n * @constructor\n * @param {Number} size The size of the pool. Defaults to the number of CPUs\n * available. When this parameter is `null` or 0, then the\n * decoding will be done in the main thread.\n */\n constructor(size = defaultPoolSize) {\n this.workers = [];\n this.idleWorkers = [];\n this.waitQueue = [];\n this.decoder = null;\n\n // eslint-disable-next-line no-plusplus\n for (let i = 0; i < size; ++i) {\n const w = new Worker('./decoder.worker');\n this.workers.push(w);\n this.idleWorkers.push(w);\n }\n }\n\n /**\n * Decode the given block of bytes with the set compression method.\n * @param {ArrayBuffer} buffer the array buffer of bytes to decode.\n * @returns {Promise.<ArrayBuffer>} the decoded result as a `Promise`\n */\n async decode(fileDirectory: FileDirectory, buffer: ArrayBuffer) {\n const currentWorker = await this.waitForWorker();\n return new Promise((resolve, reject) => {\n currentWorker.onmessage = (event) => {\n // this.workers.push(currentWorker);\n // eslint-disable-next-line\n this.finishTask(currentWorker);\n resolve(event.data[0]);\n };\n currentWorker.onerror = (error) => {\n // this.workers.push(currentWorker);\n // eslint-disable-next-line\n this.finishTask(currentWorker);\n reject(error);\n };\n currentWorker.postMessage(['decode', fileDirectory, buffer], [buffer]);\n });\n }\n\n async waitForWorker() {\n const idleWorker = this.idleWorkers.pop();\n if (idleWorker) {\n return idleWorker;\n }\n const waiter: any = {};\n const promise = new Promise((resolve) => {\n waiter.resolve = resolve;\n });\n\n this.waitQueue.push(waiter);\n return promise as Promise<Worker>;\n }\n\n async finishTask(currentWorker: Worker) {\n const waiter = this.waitQueue.pop();\n if (waiter) {\n waiter.resolve(currentWorker);\n } else {\n this.idleWorkers.push(currentWorker);\n }\n }\n\n destroy() {\n // eslint-disable-next-line no-plusplus\n for (let i = 0; i < this.workers.length; ++i) {\n this.workers[i].terminate();\n }\n }\n}\n"],"mappings":";AASA,MAAMA,eAAe,IAAAC,qBAAA,GAAGC,UAAU,aAAVA,UAAU,wBAAAC,sBAAA,GAAVD,UAAU,CAAEE,SAAS,cAAAD,sBAAA,uBAArBA,sBAAA,CAAuBE,mBAAmB,cAAAJ,qBAAA,cAAAA,qBAAA,GAAI,CAAC;AAMvE,eAAe,MAAMK,IAAI,CAAC;EAYxBC,WAAWA,CAAA,EAAyB;IAAA,IAAxBC,IAAI,GAAAC,SAAA,CAAAC,MAAA,QAAAD,SAAA,QAAAE,SAAA,GAAAF,SAAA,MAAGT,eAAe;IAAA,KAXlCY,OAAO;IAAA,KACPC,WAAW;IAAA,KACXC,SAAS;IAAA,KACTC,OAAO;IASL,IAAI,CAACH,OAAO,GAAG,EAAE;IACjB,IAAI,CAACC,WAAW,GAAG,EAAE;IACrB,IAAI,CAACC,SAAS,GAAG,EAAE;IACnB,IAAI,CAACC,OAAO,GAAG,IAAI;IAGnB,KAAK,IAAIC,CAAC,GAAG,CAAC,EAAEA,CAAC,GAAGR,IAAI,EAAE,EAAEQ,CAAC,EAAE;MAC7B,MAAMC,CAAC,GAAG,IAAIC,MAAM,CAAC,kBAAkB,C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C,MAAM,EAAE;MACVA,MAAM,CAACX,OAAO,CAACH,aAAa,CAAC;IAC/B,CAAC,MAAM;MACL,IAAI,CAACV,WAAW,CAACM,IAAI,CAACI,aAAa,CAAC;IACtC;EACF;EAEAgB,OAAOA,CAAA,EAAG;IAER,KAAK,IAAIvB,CAAC,GAAG,CAAC,EAAEA,CAAC,GAAG,IAAI,CAACJ,OAAO,CAACF,MAAM,EAAE,EAAEM,CAAC,EAAE;MAC5C,IAAI,CAACJ,OAAO,CAACI,CAAC,CAAC,CAACwB,SAAS,CAAC,CAAC;IAC7B;EACF;AACF"}
@@ -1,6 +0,0 @@
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
@@ -1 +0,0 @@
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,54 +0,0 @@
1
- const VIV_PROXY_KEY = '__viv';
2
- const OFFSETS_PROXY_KEY = `${VIV_PROXY_KEY}-offsets`;
3
- const POOL_PROXY_KEY = `${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
- if (!isProxy(tiff, POOL_PROXY_KEY)) {
9
- console.warn('GeoTIFF source is missing decoder-pool proxy.');
10
- }
11
- }
12
- function isProxy(tiff, proxyFlag) {
13
- return tiff[proxyFlag];
14
- }
15
- export function createOffsetsProxy(tiff, offsets) {
16
- const get = (target, key) => {
17
- if (key === 'getImage') {
18
- return index => {
19
- if (!(index in target.ifdRequests) && index in offsets) {
20
- const offset = offsets[index];
21
- target.ifdRequests[index] = target.parseFileDirectoryAt(offset);
22
- }
23
- return target.getImage(index);
24
- };
25
- }
26
- if (key === OFFSETS_PROXY_KEY) {
27
- return true;
28
- }
29
- return Reflect.get(target, key);
30
- };
31
- return new Proxy(tiff, {
32
- get
33
- });
34
- }
35
- export function createPoolProxy(tiff, pool) {
36
- const get = (target, key) => {
37
- if (key === 'readRasters') {
38
- return options => {
39
- return target.readRasters({
40
- ...options,
41
- pool
42
- });
43
- };
44
- }
45
- if (key === POOL_PROXY_KEY) {
46
- return true;
47
- }
48
- return Reflect.get(target, key);
49
- };
50
- return new Proxy(tiff, {
51
- get
52
- });
53
- }
54
- //# sourceMappingURL=proxies.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"proxies.js","names":["VIV_PROXY_KEY","OFFSETS_PROXY_KEY","POOL_PROXY_KEY","checkProxies","tiff","isProxy","console","warn","proxyFlag","createOffsetsProxy","offsets","get","target","key","index","ifdRequests","offset","parseFileDirectoryAt","getImage","Reflect","Proxy","createPoolProxy","pool","options","readRasters"],"sources":["../../../src/lib/utils/proxies.ts"],"sourcesContent":["import type {GeoTIFF} from 'geotiff';\nimport type Pool from './Pool';\n\nconst VIV_PROXY_KEY = '__viv';\nconst OFFSETS_PROXY_KEY = `${VIV_PROXY_KEY}-offsets` as const;\nconst POOL_PROXY_KEY = `${VIV_PROXY_KEY}-decoder-pool` as const;\n\n/*\n * Inspect if the GeoTIFF source is wrapped in our proxies,\n * and warn if missing.\n */\nexport function checkProxies(tiff: GeoTIFF) {\n if (!isProxy(tiff, OFFSETS_PROXY_KEY)) {\n console.warn('GeoTIFF source is missing offsets proxy.'); // eslint-disable-line no-console\n }\n\n if (!isProxy(tiff, POOL_PROXY_KEY)) {\n console.warn('GeoTIFF source is missing decoder-pool proxy.'); // eslint-disable-line no-console\n }\n}\n\n/*\n * > isProxy(tiff, POOL_PROXY_KEY) === true; // false\n * > tiff = createPoolProxy(tiff, new Pool());\n * > isProxy(tiff, POOL_PROXY_KEY) === true; // true\n */\nfunction isProxy(tiff: GeoTIFF, proxyFlag: string) {\n return (tiff as any)[proxyFlag] as boolean;\n}\n\n/*\n * Creates an ES6 Proxy that wraps a GeoTIFF object. The proxy\n * handler intercepts calls to `tiff.getImage` and uses our custom\n * pre-computed offsets to pre-fetch the correct file directory.\n *\n * This is a bit of a hack. Internally GeoTIFF inspects `this.ifdRequests`\n * to see which fileDirectories need to be traversed. By adding the\n * ifdRequest for an 'index' manually, GeoTIFF will await that request\n * rather than traversing the file system remotely.\n */\nexport function createOffsetsProxy(tiff: GeoTIFF, offsets: number[]) {\n const get = (target: GeoTIFF, key: any) => {\n // Intercept `tiff.getImage`\n if (key === 'getImage') {\n return (index: number) => {\n // Manually add ifdRequest to tiff if missing and we have an offset.\n if (!(index in target.ifdRequests) && index in offsets) {\n const offset = offsets[index];\n target.ifdRequests[index] = target.parseFileDirectoryAt(offset);\n }\n return target.getImage(index);\n };\n }\n\n // tiff['__viv-offsets'] === true\n if (key === OFFSETS_PROXY_KEY) {\n return true;\n }\n\n return Reflect.get(target, key);\n };\n return new Proxy(tiff, {get});\n}\n\n/*\n * Creates an ES6 Proxy that wraps a GeoTIFF object. The proxy\n * handler intercepts calls to `tiff.readRasters` and injects\n * a pool argument to every call. This means our TiffPixelSource\n * doesn't need to be aware of whether a decoder pool is in use.\n *\n * > tiff.readRasters({ window }) -> tiff.readRasters({ window, pool });\n */\nexport function createPoolProxy(tiff: GeoTIFF, pool: Pool) {\n const get = (target: GeoTIFF, key: any) => {\n // Intercept calls to `image.readRasters`\n if (key === 'readRasters') {\n return (options: Parameters<typeof target.readRasters>) => {\n // Inject `pool` argument with other raster options.\n // @ts-ignore\n return target.readRasters({...options, pool});\n };\n }\n\n // tiff['__viv-decoder-pool'] === true\n if (key === POOL_PROXY_KEY) {\n return true;\n }\n\n return Reflect.get(target, key);\n };\n return new Proxy(tiff, {get});\n}\n"],"mappings":"AAGA,MAAMA,aAAa,GAAG,OAAO;AAC7B,MAAMC,iBAAiB,GAAI,GAAED,aAAc,UAAkB;AAC7D,MAAME,cAAc,GAAI,GAAEF,aAAc,eAAuB;AAM/D,OAAO,SAASG,YAAYA,CAACC,IAAa,EAAE;EAC1C,IAAI,CAACC,OAAO,CAACD,IAAI,EAAEH,iBAAiB,CAAC,EAAE;IACrCK,OAAO,CAACC,IAAI,CAAC,0CAA0C,CAAC;EAC1D;EAEA,IAAI,CAACF,OAAO,CAACD,IAAI,EAAEF,cAAc,CAAC,EAAE;IAClCI,OAAO,CAACC,IAAI,CAAC,+CAA+C,CAAC;EAC/D;AACF;AAOA,SAASF,OAAOA,CAACD,IAAa,EAAEI,SAAiB,EAAE;EACjD,OAAQJ,IAAI,CAASI,SAAS,CAAC;AACjC;AAYA,OAAO,SAASC,kBAAkBA,CAACL,IAAa,EAAEM,OAAiB,EAAE;EACnE,MAAMC,GAAG,GAAGA,CAACC,MAAe,EAAEC,GAAQ,KAAK;IAEzC,IAAIA,GAAG,KAAK,UAAU,EAAE;MACtB,OAAQC,KAAa,IAAK;QAExB,IAAI,EAAEA,KAAK,IAAIF,MAAM,CAACG,WAAW,CAAC,IAAID,KAAK,IAAIJ,OAAO,EAAE;UACtD,MAAMM,MAAM,GAAGN,OAAO,CAACI,KAAK,CAAC;UAC7BF,MAAM,CAACG,WAAW,CAACD,KAAK,CAAC,GAAGF,MAAM,CAACK,oBAAoB,CAACD,MAAM,CAAC;QACjE;QACA,OAAOJ,MAAM,CAACM,QAAQ,CAACJ,KAAK,CAAC;MAC/B,CAAC;IACH;IAGA,IAAID,GAAG,KAAKZ,iBAAiB,EAAE;MAC7B,OAAO,IAAI;IACb;IAEA,OAAOkB,OAAO,CAACR,GAAG,CAACC,MAAM,EAAEC,GAAG,CAAC;EACjC,CAAC;EACD,OAAO,IAAIO,KAAK,CAAChB,IAAI,EAAE;IAACO;EAAG,CAAC,CAAC;AAC/B;AAUA,OAAO,SAASU,eAAeA,CAACjB,IAAa,EAAEkB,IAAU,EAAE;EACzD,MAAMX,GAAG,GAAGA,CAACC,MAAe,EAAEC,GAAQ,KAAK;IAEzC,IAAIA,GAAG,KAAK,aAAa,EAAE;MACzB,OAAQU,OAA8C,IAAK;QAGzD,OAAOX,MAAM,CAACY,WAAW,CAAC;UAAC,GAAGD,OAAO;UAAED;QAAI,CAAC,CAAC;MAC/C,CAAC;IACH;IAGA,IAAIT,GAAG,KAAKX,cAAc,EAAE;MAC1B,OAAO,IAAI;IACb;IAEA,OAAOiB,OAAO,CAACR,GAAG,CAACC,MAAM,EAAEC,GAAG,CAAC;EACjC,CAAC;EACD,OAAO,IAAIO,KAAK,CAAChB,IAAI,EAAE;IAACO;EAAG,CAAC,CAAC;AAC/B"}
@@ -1,60 +0,0 @@
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
@@ -1 +0,0 @@
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,aA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,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 +0,0 @@
1
-
2
- //# sourceMappingURL=geotiff.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"geotiff.js","names":[],"sources":["../../src/typings/geotiff.ts"],"sourcesContent":["declare type TypedArray = import('../types').TypedArray;\n\ndeclare module 'geotiff' {\n function fromUrl(url: string, headers?: Record<string, unknown>): Promise<GeoTIFF>;\n function fromBlob(blob: Blob): Promise<GeoTIFF>;\n function fromFile(path: string): Promise<GeoTIFF>;\n\n class GeoTIFF {\n readRasters(options?: RasterOptions): Promise<TypedArray>;\n getImage(index: number): Promise<GeoTIFFImage>;\n parseFileDirectoryAt(offset: number): Promise<ImageFileDirectory>;\n ifdRequests: {[key: number]: Promise<ImageFileDirectory>};\n dataView: DataView;\n littleEndian: boolean;\n cache: any;\n source: any;\n }\n\n interface Pool {\n decode(fileDirectory: FileDirectory, buffer: ArrayBuffer): Promise<ArrayBuffer>;\n }\n\n interface RasterOptions {\n window?: number[];\n bbox?: number[];\n samples?: number[];\n interleave?: boolean;\n pool?: Pool;\n width?: number;\n height?: number;\n resampleMethod?: string;\n enableAlpha?: boolean;\n signal?: AbortSignal;\n }\n\n type RasterData = (TypedArray | TypedArray[]) & {\n width: number;\n height: number;\n };\n class GeoTIFFImage {\n constructor(\n fileDirectory: FileDirectory,\n geoKeyDirectory: any,\n dataView: DataView,\n littleEndian: boolean,\n cache: any,\n source: any\n );\n fileDirectory: FileDirectory;\n getBoundingBox(): number[];\n getFileDirectory(): FileDirectory;\n getBytesPerPixel(): number;\n getHeight(): number;\n getSamplesPerPixel(): number;\n getTileHeight(): number;\n getTileWidth(): number;\n getWidth(): number;\n readRasters(options?: RasterOptions): Promise<RasterData>;\n }\n\n interface FileDirectory {\n ImageDescription: string;\n SubIFDs?: number[];\n PhotometricInterpretation?: number;\n }\n\n interface ImageFileDirectory {\n fileDirectory: FileDirectory;\n geoKeyDirectory: any;\n }\n}\n"],"mappings":""}
@@ -1,71 +0,0 @@
1
- declare type TypedArray = import('../types').TypedArray;
2
-
3
- declare module 'geotiff' {
4
- function fromUrl(url: string, headers?: Record<string, unknown>): Promise<GeoTIFF>;
5
- function fromBlob(blob: Blob): Promise<GeoTIFF>;
6
- function fromFile(path: string): Promise<GeoTIFF>;
7
-
8
- class GeoTIFF {
9
- readRasters(options?: RasterOptions): Promise<TypedArray>;
10
- getImage(index: number): Promise<GeoTIFFImage>;
11
- parseFileDirectoryAt(offset: number): Promise<ImageFileDirectory>;
12
- ifdRequests: {[key: number]: Promise<ImageFileDirectory>};
13
- dataView: DataView;
14
- littleEndian: boolean;
15
- cache: any;
16
- source: any;
17
- }
18
-
19
- interface Pool {
20
- decode(fileDirectory: FileDirectory, buffer: ArrayBuffer): Promise<ArrayBuffer>;
21
- }
22
-
23
- interface RasterOptions {
24
- window?: number[];
25
- bbox?: number[];
26
- samples?: number[];
27
- interleave?: boolean;
28
- pool?: Pool;
29
- width?: number;
30
- height?: number;
31
- resampleMethod?: string;
32
- enableAlpha?: boolean;
33
- signal?: AbortSignal;
34
- }
35
-
36
- type RasterData = (TypedArray | TypedArray[]) & {
37
- width: number;
38
- height: number;
39
- };
40
- class GeoTIFFImage {
41
- constructor(
42
- fileDirectory: FileDirectory,
43
- geoKeyDirectory: any,
44
- dataView: DataView,
45
- littleEndian: boolean,
46
- cache: any,
47
- source: any
48
- );
49
- fileDirectory: FileDirectory;
50
- getBoundingBox(): number[];
51
- getFileDirectory(): FileDirectory;
52
- getBytesPerPixel(): number;
53
- getHeight(): number;
54
- getSamplesPerPixel(): number;
55
- getTileHeight(): number;
56
- getTileWidth(): number;
57
- getWidth(): number;
58
- readRasters(options?: RasterOptions): Promise<RasterData>;
59
- }
60
-
61
- interface FileDirectory {
62
- ImageDescription: string;
63
- SubIFDs?: number[];
64
- PhotometricInterpretation?: number;
65
- }
66
-
67
- interface ImageFileDirectory {
68
- fileDirectory: FileDirectory;
69
- geoKeyDirectory: any;
70
- }
71
- }