@loaders.gl/geotiff 4.0.0-alpha.5 → 4.0.0-alpha.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/bundle.js +28 -2
- package/dist/es5/bundle.js +9 -0
- package/dist/es5/bundle.js.map +1 -0
- package/dist/es5/index.js +21 -0
- package/dist/es5/index.js.map +1 -0
- package/dist/es5/lib/load-geotiff.js +76 -0
- package/dist/es5/lib/load-geotiff.js.map +1 -0
- package/dist/es5/lib/ome/load-ome-tiff.js +66 -0
- package/dist/es5/lib/ome/load-ome-tiff.js.map +1 -0
- package/dist/es5/lib/ome/ome-indexers.js +140 -0
- package/dist/es5/lib/ome/ome-indexers.js.map +1 -0
- package/dist/es5/lib/ome/ome-utils.js +74 -0
- package/dist/es5/lib/ome/ome-utils.js.map +1 -0
- package/dist/es5/lib/ome/omexml.js +68 -0
- package/dist/es5/lib/ome/omexml.js.map +1 -0
- package/dist/es5/lib/ome/utils.js +26 -0
- package/dist/es5/lib/ome/utils.js.map +1 -0
- package/dist/es5/lib/tiff-pixel-source.js +163 -0
- package/dist/es5/lib/tiff-pixel-source.js.map +1 -0
- package/dist/es5/lib/utils/Pool.js +136 -0
- package/dist/es5/lib/utils/Pool.js.map +1 -0
- package/dist/es5/lib/utils/proxies.js +65 -0
- package/dist/es5/lib/utils/proxies.js.map +1 -0
- package/dist/es5/lib/utils/tiff-utils.js +43 -0
- package/dist/es5/lib/utils/tiff-utils.js.map +1 -0
- package/dist/es5/types.js +2 -0
- package/dist/es5/types.js.map +1 -0
- package/dist/es5/typings/geotiff.js +2 -0
- package/dist/es5/typings/geotiff.js.map +1 -0
- package/dist/esm/bundle.js +4 -0
- package/dist/esm/bundle.js.map +1 -0
- package/dist/esm/index.js +3 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/lib/load-geotiff.js +28 -0
- package/dist/esm/lib/load-geotiff.js.map +1 -0
- package/dist/esm/lib/ome/load-ome-tiff.js +47 -0
- package/dist/esm/lib/ome/load-ome-tiff.js.map +1 -0
- package/dist/esm/lib/ome/ome-indexers.js +120 -0
- package/dist/esm/lib/ome/ome-indexers.js.map +1 -0
- package/dist/esm/lib/ome/ome-utils.js +66 -0
- package/dist/esm/lib/ome/ome-utils.js.map +1 -0
- package/dist/esm/lib/ome/omexml.js +64 -0
- package/dist/esm/lib/ome/omexml.js.map +1 -0
- package/dist/esm/lib/ome/utils.js +17 -0
- package/dist/esm/lib/ome/utils.js.map +1 -0
- package/dist/esm/lib/tiff-pixel-source.js +92 -0
- package/dist/esm/lib/tiff-pixel-source.js.map +1 -0
- package/dist/esm/lib/utils/Pool.js +61 -0
- package/dist/esm/lib/utils/Pool.js.map +1 -0
- package/dist/esm/lib/utils/decoder.worker.ts.disabled +21 -0
- package/dist/esm/lib/utils/proxies.js +54 -0
- package/dist/esm/lib/utils/proxies.js.map +1 -0
- package/dist/esm/lib/utils/tiff-utils.js +27 -0
- package/dist/esm/lib/utils/tiff-utils.js.map +1 -0
- package/dist/esm/types.js +2 -0
- package/dist/esm/types.js.map +1 -0
- package/dist/esm/typings/geotiff.js +2 -0
- package/dist/esm/typings/geotiff.js.map +1 -0
- package/dist/index.js +10 -3
- package/dist/lib/load-geotiff.js +56 -31
- package/dist/lib/ome/load-ome-tiff.js +45 -50
- package/dist/lib/ome/ome-indexers.d.ts +2 -2
- package/dist/lib/ome/ome-indexers.d.ts.map +1 -1
- package/dist/lib/ome/ome-indexers.js +104 -112
- package/dist/lib/ome/ome-utils.js +59 -69
- package/dist/lib/ome/omexml.d.ts +4 -4
- package/dist/lib/ome/omexml.d.ts.map +1 -1
- package/dist/lib/ome/omexml.js +60 -60
- package/dist/lib/ome/utils.js +27 -18
- package/dist/lib/tiff-pixel-source.js +59 -106
- package/dist/lib/utils/Pool.js +78 -72
- package/dist/lib/utils/proxies.js +79 -56
- package/dist/lib/utils/tiff-utils.js +40 -24
- package/dist/types.d.ts +4 -4
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +2 -2
- package/dist/typings/geotiff.js +1 -2
- package/package.json +4 -4
- package/dist/bundle.js.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/lib/load-geotiff.js.map +0 -1
- package/dist/lib/ome/load-ome-tiff.js.map +0 -1
- package/dist/lib/ome/ome-indexers.js.map +0 -1
- package/dist/lib/ome/ome-utils.js.map +0 -1
- package/dist/lib/ome/omexml.js.map +0 -1
- package/dist/lib/ome/utils.js.map +0 -1
- package/dist/lib/tiff-pixel-source.js.map +0 -1
- package/dist/lib/utils/Pool.js.map +0 -1
- package/dist/lib/utils/proxies.js.map +0 -1
- package/dist/lib/utils/tiff-utils.js.map +0 -1
- package/dist/types.js.map +0 -1
- package/dist/typings/geotiff.js.map +0 -1
- /package/dist/{lib → es5/lib}/utils/decoder.worker.ts.disabled +0 -0
|
@@ -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":""}
|
package/dist/index.js
CHANGED
|
@@ -1,3 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
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; } });
|
package/dist/lib/load-geotiff.js
CHANGED
|
@@ -1,32 +1,57 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
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.js';
|
|
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
|
-
|
|
57
|
+
exports.loadGeoTiff = loadGeoTiff;
|
|
@@ -1,51 +1,46 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
return
|
|
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
|
-
|
|
46
|
+
exports.loadOmeTiff = loadOmeTiff;
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import type { GeoTIFFImage, GeoTIFF } from 'geotiff';
|
|
2
2
|
import type { OMEXML } from '../ome/omexml';
|
|
3
|
-
export
|
|
3
|
+
export type OmeTiffSelection = {
|
|
4
4
|
t: number;
|
|
5
5
|
c: number;
|
|
6
6
|
z: number;
|
|
7
7
|
};
|
|
8
|
-
export
|
|
8
|
+
export type OmeTiffIndexer = (sel: OmeTiffSelection, z: number) => Promise<GeoTIFFImage>;
|
|
9
9
|
export declare function getOmeLegacyIndexer(tiff: GeoTIFF, rootMeta: OMEXML): OmeTiffIndexer;
|
|
10
10
|
export declare function getOmeSubIFDIndexer(tiff: GeoTIFF, rootMeta: OMEXML): OmeTiffIndexer;
|
|
11
11
|
//# sourceMappingURL=ome-indexers.d.ts.map
|
|
@@ -1 +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,
|
|
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
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
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
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
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
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
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
|
|
@@ -1,73 +1,63 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getOmePixelSourceMeta = exports.DTYPE_LOOKUP = void 0;
|
|
4
|
+
const utils_1 = require("./utils");
|
|
5
|
+
exports.DTYPE_LOOKUP = {
|
|
6
|
+
uint8: 'Uint8',
|
|
7
|
+
uint16: 'Uint16',
|
|
8
|
+
uint32: 'Uint32',
|
|
9
|
+
float: 'Float32',
|
|
10
|
+
double: 'Float64',
|
|
11
|
+
int8: 'Int8',
|
|
12
|
+
int16: 'Int16',
|
|
13
|
+
int32: 'Int32'
|
|
11
14
|
};
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
const getShape = level => {
|
|
28
|
-
const s = [...shape];
|
|
29
|
-
s[dims('x')] = Pixels.SizeX >> level;
|
|
30
|
-
s[dims('y')] = Pixels.SizeY >> level;
|
|
31
|
-
return s;
|
|
32
|
-
};
|
|
33
|
-
|
|
34
|
-
if (!(Pixels.Type in DTYPE_LOOKUP)) {
|
|
35
|
-
throw Error("Pixel type ".concat(Pixels.Type, " not supported."));
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
const dtype = DTYPE_LOOKUP[Pixels.Type];
|
|
39
|
-
|
|
40
|
-
if (Pixels.PhysicalSizeX && Pixels.PhysicalSizeY) {
|
|
41
|
-
const physicalSizes = {
|
|
42
|
-
x: {
|
|
43
|
-
size: Pixels.PhysicalSizeX,
|
|
44
|
-
unit: Pixels.PhysicalSizeXUnit
|
|
45
|
-
},
|
|
46
|
-
y: {
|
|
47
|
-
size: Pixels.PhysicalSizeY,
|
|
48
|
-
unit: Pixels.PhysicalSizeYUnit
|
|
49
|
-
}
|
|
50
|
-
};
|
|
51
|
-
|
|
52
|
-
if (Pixels.PhysicalSizeZ) {
|
|
53
|
-
physicalSizes.z = {
|
|
54
|
-
size: Pixels.PhysicalSizeZ,
|
|
55
|
-
unit: Pixels.PhysicalSizeZUnit
|
|
56
|
-
};
|
|
15
|
+
function getOmePixelSourceMeta({ Pixels }) {
|
|
16
|
+
// e.g. 'XYZCT' -> ['t', 'c', 'z', 'y', 'x']
|
|
17
|
+
const labels = (0, utils_1.getLabels)(Pixels.DimensionOrder);
|
|
18
|
+
// Compute "shape" of image
|
|
19
|
+
const dims = (0, utils_1.getDims)(labels);
|
|
20
|
+
const shape = Array(labels.length).fill(0);
|
|
21
|
+
shape[dims('t')] = Pixels.SizeT;
|
|
22
|
+
shape[dims('c')] = Pixels.SizeC;
|
|
23
|
+
shape[dims('z')] = Pixels.SizeZ;
|
|
24
|
+
// Push extra dimension if data are interleaved.
|
|
25
|
+
if (Pixels.Interleaved) {
|
|
26
|
+
// @ts-ignore
|
|
27
|
+
labels.push('_c');
|
|
28
|
+
shape.push(3);
|
|
57
29
|
}
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
30
|
+
// Creates a new shape for different level of pyramid.
|
|
31
|
+
// Assumes factor-of-two downsampling.
|
|
32
|
+
const getShape = (level) => {
|
|
33
|
+
const s = [...shape];
|
|
34
|
+
s[dims('x')] = Pixels.SizeX >> level;
|
|
35
|
+
s[dims('y')] = Pixels.SizeY >> level;
|
|
36
|
+
return s;
|
|
64
37
|
};
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
38
|
+
if (!(Pixels.Type in exports.DTYPE_LOOKUP)) {
|
|
39
|
+
throw Error(`Pixel type ${Pixels.Type} not supported.`);
|
|
40
|
+
}
|
|
41
|
+
const dtype = exports.DTYPE_LOOKUP[Pixels.Type];
|
|
42
|
+
if (Pixels.PhysicalSizeX && Pixels.PhysicalSizeY) {
|
|
43
|
+
const physicalSizes = {
|
|
44
|
+
x: {
|
|
45
|
+
size: Pixels.PhysicalSizeX,
|
|
46
|
+
unit: Pixels.PhysicalSizeXUnit
|
|
47
|
+
},
|
|
48
|
+
y: {
|
|
49
|
+
size: Pixels.PhysicalSizeY,
|
|
50
|
+
unit: Pixels.PhysicalSizeYUnit
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
if (Pixels.PhysicalSizeZ) {
|
|
54
|
+
physicalSizes.z = {
|
|
55
|
+
size: Pixels.PhysicalSizeZ,
|
|
56
|
+
unit: Pixels.PhysicalSizeZUnit
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
return { labels, getShape, physicalSizes, dtype };
|
|
60
|
+
}
|
|
61
|
+
return { labels, getShape, dtype };
|
|
72
62
|
}
|
|
73
|
-
|
|
63
|
+
exports.getOmePixelSourceMeta = getOmePixelSourceMeta;
|
package/dist/lib/ome/omexml.d.ts
CHANGED
|
@@ -41,9 +41,9 @@ export declare function fromString(str: string): {
|
|
|
41
41
|
ID: string;
|
|
42
42
|
Name: string;
|
|
43
43
|
}[];
|
|
44
|
-
export
|
|
45
|
-
export
|
|
46
|
-
|
|
47
|
-
export
|
|
44
|
+
export type OMEXML = ReturnType<typeof fromString>;
|
|
45
|
+
export type DimensionOrder = 'XYZCT' | 'XYZTC' | 'XYCTZ' | 'XYCZT' | 'XYTCZ' | 'XYTZC';
|
|
46
|
+
type PixelType = 'int8' | 'int16' | 'int32' | 'uint8' | 'uint16' | 'uint32' | 'float' | 'bit' | 'double' | 'complex' | 'double-complex';
|
|
47
|
+
export type UnitsLength = 'Ym' | 'Zm' | 'Em' | 'Pm' | 'Tm' | 'Gm' | 'Mm' | 'km' | 'hm' | 'dam' | 'm' | 'dm' | 'cm' | 'mm' | 'µm' | 'nm' | 'pm' | 'fm' | 'am' | 'zm' | 'ym' | 'Å' | 'thou' | 'li' | 'in' | 'ft' | 'yd' | 'mi' | 'ua' | 'ly' | 'pc' | 'pt' | 'pixel' | 'reference frame';
|
|
48
48
|
export {};
|
|
49
49
|
//# sourceMappingURL=omexml.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"omexml.d.ts","sourceRoot":"","sources":["../../../src/lib/ome/omexml.ts"],"names":[],"mappings":"AAmBA,wBAAgB,UAAU,CAAC,GAAG,EAAE,MAAM;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IA8CrC;AAED,
|
|
1
|
+
{"version":3,"file":"omexml.d.ts","sourceRoot":"","sources":["../../../src/lib/ome/omexml.ts"],"names":[],"mappings":"AAmBA,wBAAgB,UAAU,CAAC,GAAG,EAAE,MAAM;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IA8CrC;AAED,MAAM,MAAM,MAAM,GAAG,UAAU,CAAC,OAAO,UAAU,CAAC,CAAC;AACnD,MAAM,MAAM,cAAc,GAAG,OAAO,GAAG,OAAO,GAAG,OAAO,GAAG,OAAO,GAAG,OAAO,GAAG,OAAO,CAAC;AAuBvF,KAAK,SAAS,GACV,MAAM,GACN,OAAO,GACP,OAAO,GACP,OAAO,GACP,QAAQ,GACR,QAAQ,GACR,OAAO,GACP,KAAK,GACL,QAAQ,GACR,SAAS,GACT,gBAAgB,CAAC;AAErB,MAAM,MAAM,WAAW,GACnB,IAAI,GACJ,IAAI,GACJ,IAAI,GACJ,IAAI,GACJ,IAAI,GACJ,IAAI,GACJ,IAAI,GACJ,IAAI,GACJ,IAAI,GACJ,KAAK,GACL,GAAG,GACH,IAAI,GACJ,IAAI,GACJ,IAAI,GACJ,IAAI,GACJ,IAAI,GACJ,IAAI,GACJ,IAAI,GACJ,IAAI,GACJ,IAAI,GACJ,IAAI,GACJ,GAAG,GACH,MAAM,GACN,IAAI,GACJ,IAAI,GACJ,IAAI,GACJ,IAAI,GACJ,IAAI,GACJ,IAAI,GACJ,IAAI,GACJ,IAAI,GACJ,IAAI,GACJ,OAAO,GACP,iBAAiB,CAAC"}
|