@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
@@ -0,0 +1,2 @@
1
+
2
+ //# sourceMappingURL=geotiff.js.map
@@ -0,0 +1 @@
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":""}
@@ -0,0 +1,3 @@
1
+ export { loadGeoTiff } from './lib/load-geotiff';
2
+ export { default as TiffPixelSource } from './lib/tiff-pixel-source';
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,WAAW,EAAC,MAAM,oBAAoB,CAAC;AAC/C,OAAO,EAAC,OAAO,IAAI,eAAe,EAAC,MAAM,yBAAyB,CAAC"}
package/dist/index.js CHANGED
@@ -1,3 +1,10 @@
1
- export { loadGeoTiff } from './lib/load-geotiff';
2
- export { default as TiffPixelSource } from './lib/tiff-pixel-source';
3
- //# sourceMappingURL=index.js.map
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.TiffPixelSource = exports.loadGeoTiff = void 0;
7
+ var load_geotiff_1 = require("./lib/load-geotiff");
8
+ Object.defineProperty(exports, "loadGeoTiff", { enumerable: true, get: function () { return load_geotiff_1.loadGeoTiff; } });
9
+ var tiff_pixel_source_1 = require("./lib/tiff-pixel-source");
10
+ Object.defineProperty(exports, "TiffPixelSource", { enumerable: true, get: function () { return __importDefault(tiff_pixel_source_1).default; } });
@@ -0,0 +1,28 @@
1
+ import { GeoTIFF } from 'geotiff';
2
+ import type TiffPixelSource from './tiff-pixel-source';
3
+ /** Options for initializing a tiff pixel source. */
4
+ interface GeoTIFFOptions {
5
+ /** Headers passed to each underlying request. */
6
+ headers?: Record<string, unknown>;
7
+ /** Performance enhancment to index the remote tiff source using pre-computed byte-offsets. Generated via https://github.com/ilan-gold/generate-tiff-offsets */
8
+ offsets?: number[];
9
+ /** Indicates whether a multi-threaded pool of image decoders should be used to decode tiles. */
10
+ pool?: boolean;
11
+ }
12
+ interface GeoTIFFData {
13
+ data: TiffPixelSource<string[]>[];
14
+ metadata: Record<string, unknown>;
15
+ }
16
+ /**
17
+ * Opens an OME-TIFF via URL and returns data source and associated metadata for first image.
18
+ *
19
+ * @param source url string, File/Blob object, or GeoTIFF object
20
+ * @param opts options for initializing a tiff pixel source.
21
+ * - `opts.headers` are passed to each underlying fetch request.
22
+ * - `opts.offsets` are a performance enhancment to index the remote tiff source using pre-computed byte-offsets.
23
+ * - `opts.pool` indicates whether a multi-threaded pool of image decoders should be used to decode tiles (default = true).
24
+ * @return data source and associated OME-Zarr metadata.
25
+ */
26
+ export declare function loadGeoTiff(source: string | Blob | GeoTIFF, opts?: GeoTIFFOptions): Promise<GeoTIFFData>;
27
+ export {};
28
+ //# sourceMappingURL=load-geotiff.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"load-geotiff.d.ts","sourceRoot":"","sources":["../../src/lib/load-geotiff.ts"],"names":[],"mappings":"AAAA,OAAO,EAAoB,OAAO,EAAC,MAAM,SAAS,CAAC;AAUnD,OAAO,KAAK,eAAe,MAAM,qBAAqB,CAAC;AAEvD,oDAAoD;AACpD,UAAU,cAAc;IACtB,iDAAiD;IACjD,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAClC,+JAA+J;IAC/J,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;IACnB,gGAAgG;IAChG,IAAI,CAAC,EAAE,OAAO,CAAC;CAChB;AAED,UAAU,WAAW;IACnB,IAAI,EAAE,eAAe,CAAC,MAAM,EAAE,CAAC,EAAE,CAAC;IAClC,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACnC;AAED;;;;;;;;;GASG;AACH,wBAAsB,WAAW,CAC/B,MAAM,EAAE,MAAM,GAAG,IAAI,GAAG,OAAO,EAC/B,IAAI,GAAE,cAAmB,GACxB,OAAO,CAAC,WAAW,CAAC,CA2CtB"}
@@ -1,32 +1,57 @@
1
- import { fromUrl, fromBlob, GeoTIFF } from 'geotiff';
2
- import { createOffsetsProxy, checkProxies } from './utils/proxies';
3
- import { loadOmeTiff, isOmeTiff } from './ome/load-ome-tiff';
4
- export async function loadGeoTiff(source, opts = {}) {
5
- const {
6
- headers,
7
- offsets
8
- } = opts;
9
- let tiff;
10
-
11
- if (source instanceof GeoTIFF) {
12
- tiff = source;
13
- } else if (typeof source === 'string') {
14
- tiff = await fromUrl(source, headers);
15
- } else {
16
- tiff = await fromBlob(source);
17
- }
18
-
19
- if (offsets) {
20
- tiff = createOffsetsProxy(tiff, offsets);
21
- }
22
-
23
- checkProxies(tiff);
24
- const firstImage = await tiff.getImage(0);
25
-
26
- if (isOmeTiff(firstImage)) {
27
- return loadOmeTiff(tiff, firstImage);
28
- }
29
-
30
- throw new Error('GeoTIFF not recognized.');
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.loadGeoTiff = void 0;
4
+ const geotiff_1 = require("geotiff");
5
+ const proxies_1 = require("./utils/proxies");
6
+ // import Pool from './lib/Pool';
7
+ const load_ome_tiff_1 = require("./ome/load-ome-tiff");
8
+ /**
9
+ * Opens an OME-TIFF via URL and returns data source and associated metadata for first image.
10
+ *
11
+ * @param source url string, File/Blob object, or GeoTIFF object
12
+ * @param opts options for initializing a tiff pixel source.
13
+ * - `opts.headers` are passed to each underlying fetch request.
14
+ * - `opts.offsets` are a performance enhancment to index the remote tiff source using pre-computed byte-offsets.
15
+ * - `opts.pool` indicates whether a multi-threaded pool of image decoders should be used to decode tiles (default = true).
16
+ * @return data source and associated OME-Zarr metadata.
17
+ */
18
+ async function loadGeoTiff(source, opts = {}) {
19
+ const { headers, offsets } = opts;
20
+ // Create tiff source
21
+ let tiff;
22
+ if (source instanceof geotiff_1.GeoTIFF) {
23
+ tiff = source;
24
+ }
25
+ else if (typeof source === 'string') {
26
+ tiff = await (0, geotiff_1.fromUrl)(source, headers);
27
+ }
28
+ else {
29
+ tiff = await (0, geotiff_1.fromBlob)(source);
30
+ }
31
+ // if (pool) {
32
+ /*
33
+ * Creates a worker pool to decode tiff tiles. Wraps tiff
34
+ * in a Proxy that injects 'pool' into `tiff.readRasters`.
35
+ */
36
+ // tiff = createPoolProxy(tiff, new Pool());
37
+ // }
38
+ if (offsets) {
39
+ /*
40
+ * Performance enhancement. If offsets are provided, we
41
+ * create a proxy that intercepts calls to `tiff.getImage`
42
+ * and injects the pre-computed offsets.
43
+ */
44
+ tiff = (0, proxies_1.createOffsetsProxy)(tiff, offsets);
45
+ }
46
+ /*
47
+ * Inspect tiff source for our performance enhancing proxies.
48
+ * Prints warnings to console if `offsets` or `pool` are missing.
49
+ */
50
+ (0, proxies_1.checkProxies)(tiff);
51
+ const firstImage = await tiff.getImage(0);
52
+ if ((0, load_ome_tiff_1.isOmeTiff)(firstImage)) {
53
+ return (0, load_ome_tiff_1.loadOmeTiff)(tiff, firstImage);
54
+ }
55
+ throw new Error('GeoTIFF not recognized.');
31
56
  }
32
- //# sourceMappingURL=load-geotiff.js.map
57
+ exports.loadGeoTiff = loadGeoTiff;
@@ -0,0 +1,50 @@
1
+ import type { GeoTIFF, GeoTIFFImage } from 'geotiff';
2
+ import TiffPixelSource from '../tiff-pixel-source';
3
+ export declare const isOmeTiff: (img: GeoTIFFImage) => boolean;
4
+ export declare function loadOmeTiff(tiff: GeoTIFF, firstImage: GeoTIFFImage): Promise<{
5
+ data: TiffPixelSource<["t", "c", "z"] | ["c", "t", "z"] | ["z", "t", "c"] | ["t", "z", "c"] | ["z", "c", "t"] | ["c", "z", "t"]>[];
6
+ metadata: {
7
+ format(): {
8
+ 'Acquisition Date': string;
9
+ 'Dimensions (XY)': string;
10
+ 'Pixels Type': "uint8" | "uint16" | "uint32" | "float" | "double" | "int8" | "int16" | "int32" | "bit" | "complex" | "double-complex";
11
+ 'Pixels Size (XYZ)': string;
12
+ 'Z-sections/Timepoints': string;
13
+ Channels: number;
14
+ };
15
+ AquisitionDate: string;
16
+ Description: string;
17
+ Pixels: {
18
+ Channels: ({
19
+ Color: [number, number, number, number];
20
+ ID: string;
21
+ SamplesPerPixel: number;
22
+ Name?: string | undefined;
23
+ } | {
24
+ ID: string;
25
+ SamplesPerPixel: number;
26
+ Name?: string | undefined;
27
+ })[];
28
+ PhysicalSizeX: number;
29
+ PhysicalSizeY: number;
30
+ PhysicalSizeZ: number;
31
+ SignificantBits: number;
32
+ SizeX: number;
33
+ SizeY: number;
34
+ SizeZ: number;
35
+ SizeT: number;
36
+ SizeC: number;
37
+ PhysicalSizeXUnit: import("./omexml").UnitsLength;
38
+ PhysicalSizeYUnit: import("./omexml").UnitsLength;
39
+ PhysicalSizeZUnit: import("./omexml").UnitsLength;
40
+ BigEndian: boolean;
41
+ Interleaved: boolean;
42
+ ID: string;
43
+ DimensionOrder: import("./omexml").DimensionOrder;
44
+ Type: "uint8" | "uint16" | "uint32" | "float" | "double" | "int8" | "int16" | "int32" | "bit" | "complex" | "double-complex";
45
+ };
46
+ ID: string;
47
+ Name: string;
48
+ };
49
+ }>;
50
+ //# sourceMappingURL=load-ome-tiff.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"load-ome-tiff.d.ts","sourceRoot":"","sources":["../../../src/lib/ome/load-ome-tiff.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,OAAO,EAAE,YAAY,EAAC,MAAM,SAAS,CAAC;AAEnD,OAAO,eAAe,MAAM,sBAAsB,CAAC;AAMnD,eAAO,MAAM,SAAS,QAAS,YAAY,YAAwD,CAAC;AAEpG,wBAAsB,WAAW,CAAC,IAAI,EAAE,OAAO,EAAE,UAAU,EAAE,YAAY;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAwCxE"}
@@ -1,51 +1,46 @@
1
- import TiffPixelSource from '../tiff-pixel-source';
2
- import { getOmeLegacyIndexer, getOmeSubIFDIndexer } from './ome-indexers';
3
- import { getOmePixelSourceMeta } from './ome-utils';
4
- import { fromString } from './omexml';
5
- export const isOmeTiff = img => img.fileDirectory.ImageDescription.includes('<OME');
6
- export async function loadOmeTiff(tiff, firstImage) {
7
- const {
8
- ImageDescription,
9
- SubIFDs,
10
- PhotometricInterpretation: photometricInterpretation
11
- } = firstImage.fileDirectory;
12
- const omexml = fromString(ImageDescription);
13
- let levels;
14
- let pyramidIndexer;
15
-
16
- if (SubIFDs) {
17
- levels = SubIFDs.length + 1;
18
- pyramidIndexer = getOmeSubIFDIndexer(tiff, omexml);
19
- } else {
20
- levels = omexml.length;
21
- pyramidIndexer = getOmeLegacyIndexer(tiff, omexml);
22
- }
23
-
24
- const imgMeta = omexml[0];
25
- const {
26
- labels,
27
- getShape,
28
- physicalSizes,
29
- dtype
30
- } = getOmePixelSourceMeta(imgMeta);
31
- const tileSize = firstImage.getTileWidth();
32
- const meta = {
33
- photometricInterpretation,
34
- physicalSizes
35
- };
36
- const data = Array.from({
37
- length: levels
38
- }).map((_, resolution) => {
39
- const shape = getShape(resolution);
40
-
41
- const indexer = sel => pyramidIndexer(sel, resolution);
42
-
43
- const source = new TiffPixelSource(indexer, dtype, tileSize, shape, labels, meta);
44
- return source;
45
- });
46
- return {
47
- data,
48
- metadata: imgMeta
49
- };
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.loadOmeTiff = exports.isOmeTiff = void 0;
7
+ const tiff_pixel_source_1 = __importDefault(require("../tiff-pixel-source"));
8
+ const ome_indexers_1 = require("./ome-indexers");
9
+ const ome_utils_1 = require("./ome-utils");
10
+ const omexml_1 = require("./omexml");
11
+ const isOmeTiff = (img) => img.fileDirectory.ImageDescription.includes('<OME');
12
+ exports.isOmeTiff = isOmeTiff;
13
+ async function loadOmeTiff(tiff, firstImage) {
14
+ // Get first image from tiff and inspect OME-XML metadata
15
+ const { ImageDescription, SubIFDs, PhotometricInterpretation: photometricInterpretation } = firstImage.fileDirectory;
16
+ const omexml = (0, omexml_1.fromString)(ImageDescription);
17
+ /*
18
+ * Image pyramids are stored differently between versions of Bioformats.
19
+ * Thus we need a different indexer depending on which format we have.
20
+ */
21
+ let levels;
22
+ let pyramidIndexer;
23
+ if (SubIFDs) {
24
+ // Image is >= Bioformats 6.0 and resolutions are stored using SubIFDs.
25
+ levels = SubIFDs.length + 1;
26
+ pyramidIndexer = (0, ome_indexers_1.getOmeSubIFDIndexer)(tiff, omexml);
27
+ }
28
+ else {
29
+ // Image is legacy format; resolutions are stored as separate images.
30
+ levels = omexml.length;
31
+ pyramidIndexer = (0, ome_indexers_1.getOmeLegacyIndexer)(tiff, omexml);
32
+ }
33
+ // TODO: The OmeTIFF loader only works for the _first_ image in the metadata.
34
+ const imgMeta = omexml[0];
35
+ const { labels, getShape, physicalSizes, dtype } = (0, ome_utils_1.getOmePixelSourceMeta)(imgMeta);
36
+ const tileSize = firstImage.getTileWidth();
37
+ const meta = { photometricInterpretation, physicalSizes };
38
+ const data = Array.from({ length: levels }).map((_, resolution) => {
39
+ const shape = getShape(resolution);
40
+ const indexer = (sel) => pyramidIndexer(sel, resolution);
41
+ const source = new tiff_pixel_source_1.default(indexer, dtype, tileSize, shape, labels, meta);
42
+ return source;
43
+ });
44
+ return { data, metadata: imgMeta };
50
45
  }
51
- //# sourceMappingURL=load-ome-tiff.js.map
46
+ exports.loadOmeTiff = loadOmeTiff;
@@ -0,0 +1,11 @@
1
+ import type { GeoTIFFImage, GeoTIFF } from 'geotiff';
2
+ import type { OMEXML } from '../ome/omexml';
3
+ export type OmeTiffSelection = {
4
+ t: number;
5
+ c: number;
6
+ z: number;
7
+ };
8
+ export type OmeTiffIndexer = (sel: OmeTiffSelection, z: number) => Promise<GeoTIFFImage>;
9
+ export declare function getOmeLegacyIndexer(tiff: GeoTIFF, rootMeta: OMEXML): OmeTiffIndexer;
10
+ export declare function getOmeSubIFDIndexer(tiff: GeoTIFF, rootMeta: OMEXML): OmeTiffIndexer;
11
+ //# sourceMappingURL=ome-indexers.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ome-indexers.d.ts","sourceRoot":"","sources":["../../../src/lib/ome/ome-indexers.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,YAAY,EAAE,OAAO,EAAqB,MAAM,SAAS,CAAC;AACvE,OAAO,KAAK,EAAC,MAAM,EAAC,MAAM,eAAe,CAAC;AAE1C,MAAM,MAAM,gBAAgB,GAAG;IAAC,CAAC,EAAE,MAAM,CAAC;IAAC,CAAC,EAAE,MAAM,CAAC;IAAC,CAAC,EAAE,MAAM,CAAA;CAAC,CAAC;AACjE,MAAM,MAAM,cAAc,GAAG,CAAC,GAAG,EAAE,gBAAgB,EAAE,CAAC,EAAE,MAAM,KAAK,OAAO,CAAC,YAAY,CAAC,CAAC;AAqBzF,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,GAAG,cAAc,CAanF;AAgBD,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,GAAG,cAAc,CAuCnF"}
@@ -1,116 +1,108 @@
1
- export function getOmeLegacyIndexer(tiff, rootMeta) {
2
- const imgMeta = rootMeta[0];
3
- const {
4
- SizeT,
5
- SizeC,
6
- SizeZ
7
- } = imgMeta.Pixels;
8
- const ifdIndexer = getOmeIFDIndexer(imgMeta);
9
- return (sel, pyramidLevel) => {
10
- const index = ifdIndexer(sel);
11
- const pyramidIndex = pyramidLevel * SizeZ * SizeT * SizeC;
12
- return tiff.getImage(index + pyramidIndex);
13
- };
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getOmeSubIFDIndexer = exports.getOmeLegacyIndexer = void 0;
4
+ /*
5
+ * An "indexer" for a GeoTIFF-based source is a function that takes a
6
+ * "selection" (e.g. { z, t, c }) and returns a Promise for the GeoTIFFImage
7
+ * object corresponding to that selection.
8
+ *
9
+ * For OME-TIFF images, the "selection" object is the same regardless of
10
+ * the format version. However, modern version of Bioformats have a different
11
+ * memory layout for pyramidal resolutions. Thus, we have two different "indexers"
12
+ * depending on which format version is detected.
13
+ *
14
+ * TODO: We currently only support indexing the first image in the OME-TIFF with
15
+ * our indexers. There can be multiple images in an OME-TIFF, so supporting these
16
+ * images will require extending these indexers or creating new methods.
17
+ */
18
+ /*
19
+ * Returns an indexer for legacy Bioformats images. This assumes that
20
+ * downsampled resolutions are stored sequentially in the OME-TIFF.
21
+ */
22
+ function getOmeLegacyIndexer(tiff, rootMeta) {
23
+ const imgMeta = rootMeta[0];
24
+ const { SizeT, SizeC, SizeZ } = imgMeta.Pixels;
25
+ const ifdIndexer = getOmeIFDIndexer(imgMeta);
26
+ return (sel, pyramidLevel) => {
27
+ // Get IFD index at base pyramid level
28
+ const index = ifdIndexer(sel);
29
+ // Get index of first image at pyramidal level
30
+ const pyramidIndex = pyramidLevel * SizeZ * SizeT * SizeC;
31
+ // Return image at IFD index for pyramidal level
32
+ return tiff.getImage(index + pyramidIndex);
33
+ };
14
34
  }
15
- export function getOmeSubIFDIndexer(tiff, rootMeta) {
16
- const imgMeta = rootMeta[0];
17
- const ifdIndexer = getOmeIFDIndexer(imgMeta);
18
- const ifdCache = new Map();
19
- return async (sel, pyramidLevel) => {
20
- const index = ifdIndexer(sel);
21
- const baseImage = await tiff.getImage(index);
22
-
23
- if (pyramidLevel === 0) {
24
- return baseImage;
25
- }
26
-
27
- const {
28
- SubIFDs
29
- } = baseImage.fileDirectory;
30
-
31
- if (!SubIFDs) {
32
- throw Error('Indexing Error: OME-TIFF is missing SubIFDs.');
33
- }
34
-
35
- const key = "".concat(sel.t, "-").concat(sel.c, "-").concat(sel.z, "-").concat(pyramidLevel);
36
-
37
- if (!ifdCache.has(key)) {
38
- const subIfdOffset = SubIFDs[pyramidLevel - 1];
39
- ifdCache.set(key, tiff.parseFileDirectoryAt(subIfdOffset));
40
- }
41
-
42
- const ifd = await ifdCache.get(key);
43
- return new baseImage.constructor(ifd.fileDirectory, ifd.geoKeyDirectory, tiff.dataView, tiff.littleEndian, tiff.cache, tiff.source);
44
- };
35
+ exports.getOmeLegacyIndexer = getOmeLegacyIndexer;
36
+ /*
37
+ * Returns an indexer for modern Bioforamts images that store multiscale
38
+ * resolutions using SubIFDs.
39
+ *
40
+ * The ifdIndexer returns the 'index' to the base resolution for a
41
+ * particular 'selection'. The SubIFDs to the downsampled resolutions
42
+ * of the 'selection' are stored within the `baseImage.fileDirectory`.
43
+ * We use the SubIFDs to get the IFD for the corresponding sub-resolution.
44
+ *
45
+ * NOTE: This function create a custom IFD cache rather than mutating
46
+ * `GeoTIFF.ifdRequests` with a random offset. The IFDs are cached in
47
+ * an ES6 Map that maps a string key that identifies the selection uniquely
48
+ * to the corresponding IFD.
49
+ */
50
+ function getOmeSubIFDIndexer(tiff, rootMeta) {
51
+ const imgMeta = rootMeta[0];
52
+ const ifdIndexer = getOmeIFDIndexer(imgMeta);
53
+ const ifdCache = new Map();
54
+ return async (sel, pyramidLevel) => {
55
+ const index = ifdIndexer(sel);
56
+ const baseImage = await tiff.getImage(index);
57
+ // It's the highest resolution, no need to look up SubIFDs.
58
+ if (pyramidLevel === 0) {
59
+ return baseImage;
60
+ }
61
+ const { SubIFDs } = baseImage.fileDirectory;
62
+ if (!SubIFDs) {
63
+ throw Error('Indexing Error: OME-TIFF is missing SubIFDs.');
64
+ }
65
+ // Get IFD for the selection at the pyramidal level
66
+ const key = `${sel.t}-${sel.c}-${sel.z}-${pyramidLevel}`;
67
+ if (!ifdCache.has(key)) {
68
+ // Only create a new request if we don't have the key.
69
+ const subIfdOffset = SubIFDs[pyramidLevel - 1];
70
+ ifdCache.set(key, tiff.parseFileDirectoryAt(subIfdOffset));
71
+ }
72
+ const ifd = (await ifdCache.get(key));
73
+ // Create a new image object manually from IFD
74
+ // https://github.com/geotiffjs/geotiff.js/blob/8ef472f41b51d18074aece2300b6a8ad91a21ae1/src/geotiff.js#L447-L453
75
+ return new baseImage.constructor(ifd.fileDirectory, ifd.geoKeyDirectory, tiff.dataView, tiff.littleEndian, tiff.cache, tiff.source);
76
+ };
45
77
  }
46
-
78
+ exports.getOmeSubIFDIndexer = getOmeSubIFDIndexer;
79
+ /*
80
+ * Returns a function that computes the image index based on the dimension
81
+ * order and dimension sizes.
82
+ */
47
83
  function getOmeIFDIndexer(imgMeta) {
48
- const {
49
- SizeC,
50
- SizeZ,
51
- SizeT,
52
- DimensionOrder
53
- } = imgMeta.Pixels;
54
-
55
- switch (DimensionOrder) {
56
- case 'XYZCT':
57
- {
58
- return ({
59
- t,
60
- c,
61
- z
62
- }) => t * SizeZ * SizeC + c * SizeZ + z;
63
- }
64
-
65
- case 'XYZTC':
66
- {
67
- return ({
68
- t,
69
- c,
70
- z
71
- }) => c * SizeZ * SizeT + t * SizeZ + z;
72
- }
73
-
74
- case 'XYCTZ':
75
- {
76
- return ({
77
- t,
78
- c,
79
- z
80
- }) => z * SizeC * SizeT + t * SizeC + c;
81
- }
82
-
83
- case 'XYCZT':
84
- {
85
- return ({
86
- t,
87
- c,
88
- z
89
- }) => t * SizeC * SizeZ + z * SizeC + c;
90
- }
91
-
92
- case 'XYTCZ':
93
- {
94
- return ({
95
- t,
96
- c,
97
- z
98
- }) => z * SizeT * SizeC + c * SizeT + t;
99
- }
100
-
101
- case 'XYTZC':
102
- {
103
- return ({
104
- t,
105
- c,
106
- z
107
- }) => c * SizeT * SizeZ + z * SizeT + t;
108
- }
109
-
110
- default:
111
- {
112
- throw new Error("Invalid OME-XML DimensionOrder, got ".concat(DimensionOrder, "."));
113
- }
114
- }
84
+ const { SizeC, SizeZ, SizeT, DimensionOrder } = imgMeta.Pixels;
85
+ switch (DimensionOrder) {
86
+ case 'XYZCT': {
87
+ return ({ t, c, z }) => t * SizeZ * SizeC + c * SizeZ + z;
88
+ }
89
+ case 'XYZTC': {
90
+ return ({ t, c, z }) => c * SizeZ * SizeT + t * SizeZ + z;
91
+ }
92
+ case 'XYCTZ': {
93
+ return ({ t, c, z }) => z * SizeC * SizeT + t * SizeC + c;
94
+ }
95
+ case 'XYCZT': {
96
+ return ({ t, c, z }) => t * SizeC * SizeZ + z * SizeC + c;
97
+ }
98
+ case 'XYTCZ': {
99
+ return ({ t, c, z }) => z * SizeT * SizeC + c * SizeT + t;
100
+ }
101
+ case 'XYTZC': {
102
+ return ({ t, c, z }) => c * SizeT * SizeZ + z * SizeT + t;
103
+ }
104
+ default: {
105
+ throw new Error(`Invalid OME-XML DimensionOrder, got ${DimensionOrder}.`);
106
+ }
107
+ }
115
108
  }
116
- //# sourceMappingURL=ome-indexers.js.map
@@ -0,0 +1,28 @@
1
+ import type { OMEXML, UnitsLength } from './omexml';
2
+ export declare const DTYPE_LOOKUP: {
3
+ readonly uint8: "Uint8";
4
+ readonly uint16: "Uint16";
5
+ readonly uint32: "Uint32";
6
+ readonly float: "Float32";
7
+ readonly double: "Float64";
8
+ readonly int8: "Int8";
9
+ readonly int16: "Int16";
10
+ readonly int32: "Int32";
11
+ };
12
+ export declare function getOmePixelSourceMeta({ Pixels }: OMEXML[0]): {
13
+ labels: import("../../types").Labels<["t", "c", "z"] | ["c", "t", "z"] | ["z", "t", "c"] | ["t", "z", "c"] | ["z", "c", "t"] | ["c", "z", "t"]>;
14
+ getShape: (level: number) => number[];
15
+ physicalSizes: {
16
+ [k: string]: {
17
+ size: number;
18
+ unit: UnitsLength;
19
+ };
20
+ };
21
+ dtype: "Uint8" | "Uint16" | "Uint32" | "Float32" | "Float64" | "Int8" | "Int16" | "Int32";
22
+ } | {
23
+ labels: import("../../types").Labels<["t", "c", "z"] | ["c", "t", "z"] | ["z", "t", "c"] | ["t", "z", "c"] | ["z", "c", "t"] | ["c", "z", "t"]>;
24
+ getShape: (level: number) => number[];
25
+ dtype: "Uint8" | "Uint16" | "Uint32" | "Float32" | "Float64" | "Int8" | "Int16" | "Int32";
26
+ physicalSizes?: undefined;
27
+ };
28
+ //# sourceMappingURL=ome-utils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ome-utils.d.ts","sourceRoot":"","sources":["../../../src/lib/ome/ome-utils.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAC,MAAM,EAAE,WAAW,EAAC,MAAM,UAAU,CAAC;AAElD,eAAO,MAAM,YAAY;;;;;;;;;CASf,CAAC;AAEX,wBAAgB,qBAAqB,CAAC,EAAC,MAAM,EAAC,EAAE,MAAM,CAAC,CAAC,CAAC;;sBAoB9B,MAAM;;;kBAcP,MAAM;kBAAQ,WAAW;;;;;;sBAdxB,MAAM;;;EAmChC"}