@loaders.gl/geotiff 3.1.0-alpha.5 → 3.1.0-beta.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/bundle.d.ts +1 -0
- package/dist/bundle.d.ts.map +1 -0
- package/dist/bundle.js +26 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +10 -0
- package/dist/lib/load-geotiff.d.ts +1 -0
- package/dist/lib/load-geotiff.d.ts.map +1 -0
- package/dist/lib/load-geotiff.js +57 -0
- package/dist/lib/ome/load-ome-tiff.d.ts +1 -0
- package/dist/lib/ome/load-ome-tiff.d.ts.map +1 -0
- package/dist/lib/ome/load-ome-tiff.js +46 -0
- package/dist/lib/ome/ome-indexers.d.ts +1 -0
- package/dist/lib/ome/ome-indexers.d.ts.map +1 -0
- package/dist/lib/ome/ome-indexers.js +108 -0
- package/dist/lib/ome/ome-utils.d.ts +1 -0
- package/dist/lib/ome/ome-utils.d.ts.map +1 -0
- package/dist/lib/ome/ome-utils.js +63 -0
- package/dist/lib/ome/omexml.d.ts +1 -0
- package/dist/lib/ome/omexml.d.ts.map +1 -0
- package/dist/lib/ome/omexml.js +66 -0
- package/dist/lib/ome/utils.d.ts +1 -0
- package/dist/lib/ome/utils.d.ts.map +1 -0
- package/dist/lib/ome/utils.js +30 -0
- package/dist/lib/tiff-pixel-source.d.ts +1 -0
- package/dist/lib/tiff-pixel-source.d.ts.map +1 -0
- package/dist/lib/tiff-pixel-source.js +64 -0
- package/dist/lib/utils/Pool.d.ts +1 -0
- package/dist/lib/utils/Pool.d.ts.map +1 -0
- package/dist/lib/utils/Pool.js +83 -0
- package/dist/lib/utils/proxies.d.ts +1 -0
- package/dist/lib/utils/proxies.d.ts.map +1 -0
- package/dist/lib/utils/proxies.js +86 -0
- package/dist/lib/utils/tiff-utils.d.ts +1 -0
- package/dist/lib/utils/tiff-utils.d.ts.map +1 -0
- package/dist/lib/utils/tiff-utils.js +44 -0
- package/dist/types.d.ts +1 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +2 -0
- package/dist/typings/geotiff.d.ts +1 -0
- package/dist/typings/geotiff.d.ts.map +1 -0
- package/dist/typings/geotiff.js +1 -0
- package/package.json +4 -5
- package/dist/dist.min.js +0 -13
- package/dist/dist.min.js.map +0 -1
package/dist/bundle.d.ts
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bundle.d.ts","sourceRoot":"","sources":["../src/bundle.ts"],"names":[],"mappings":""}
|
package/dist/bundle.js
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
5
|
+
}) : (function(o, m, k, k2) {
|
|
6
|
+
if (k2 === undefined) k2 = k;
|
|
7
|
+
o[k2] = m[k];
|
|
8
|
+
}));
|
|
9
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
10
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
11
|
+
}) : function(o, v) {
|
|
12
|
+
o["default"] = v;
|
|
13
|
+
});
|
|
14
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
15
|
+
if (mod && mod.__esModule) return mod;
|
|
16
|
+
var result = {};
|
|
17
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
18
|
+
__setModuleDefault(result, mod);
|
|
19
|
+
return result;
|
|
20
|
+
};
|
|
21
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
22
|
+
const moduleExports = __importStar(require("./index"));
|
|
23
|
+
// @ts-ignore
|
|
24
|
+
globalThis.loaders = globalThis.loaders || {};
|
|
25
|
+
// @ts-ignore
|
|
26
|
+
module.exports = Object.assign(globalThis.loaders, moduleExports);
|
package/dist/index.d.ts
CHANGED
|
@@ -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
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
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 @@
|
|
|
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"}
|
|
@@ -0,0 +1,57 @@
|
|
|
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.');
|
|
56
|
+
}
|
|
57
|
+
exports.loadGeoTiff = loadGeoTiff;
|
|
@@ -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"}
|
|
@@ -0,0 +1,46 @@
|
|
|
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 };
|
|
45
|
+
}
|
|
46
|
+
exports.loadOmeTiff = loadOmeTiff;
|
|
@@ -8,3 +8,4 @@ export declare type OmeTiffSelection = {
|
|
|
8
8
|
export declare 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
|
+
//# 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,oBAAY,gBAAgB,GAAG;IAAC,CAAC,EAAE,MAAM,CAAC;IAAC,CAAC,EAAE,MAAM,CAAC;IAAC,CAAC,EAAE,MAAM,CAAA;CAAC,CAAC;AACjE,oBAAY,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"}
|
|
@@ -0,0 +1,108 @@
|
|
|
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
|
+
};
|
|
34
|
+
}
|
|
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
|
+
};
|
|
77
|
+
}
|
|
78
|
+
exports.getOmeSubIFDIndexer = getOmeSubIFDIndexer;
|
|
79
|
+
/*
|
|
80
|
+
* Returns a function that computes the image index based on the dimension
|
|
81
|
+
* order and dimension sizes.
|
|
82
|
+
*/
|
|
83
|
+
function getOmeIFDIndexer(imgMeta) {
|
|
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
|
+
}
|
|
108
|
+
}
|
|
@@ -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"}
|
|
@@ -0,0 +1,63 @@
|
|
|
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'
|
|
14
|
+
};
|
|
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);
|
|
29
|
+
}
|
|
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;
|
|
37
|
+
};
|
|
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 };
|
|
62
|
+
}
|
|
63
|
+
exports.getOmePixelSourceMeta = getOmePixelSourceMeta;
|
package/dist/lib/ome/omexml.d.ts
CHANGED
|
@@ -46,3 +46,4 @@ export declare type DimensionOrder = 'XYZCT' | 'XYZTC' | 'XYCTZ' | 'XYCZT' | 'XY
|
|
|
46
46
|
declare type PixelType = 'int8' | 'int16' | 'int32' | 'uint8' | 'uint16' | 'uint32' | 'float' | 'bit' | 'double' | 'complex' | 'double-complex';
|
|
47
47
|
export declare 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
|
+
//# sourceMappingURL=omexml.d.ts.map
|
|
@@ -0,0 +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,oBAAY,MAAM,GAAG,UAAU,CAAC,OAAO,UAAU,CAAC,CAAC;AACnD,oBAAY,cAAc,GAAG,OAAO,GAAG,OAAO,GAAG,OAAO,GAAG,OAAO,GAAG,OAAO,GAAG,OAAO,CAAC;AAuBvF,aAAK,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,oBAAY,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"}
|
|
@@ -0,0 +1,66 @@
|
|
|
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.fromString = void 0;
|
|
7
|
+
const fast_xml_parser_1 = __importDefault(require("fast-xml-parser"));
|
|
8
|
+
const tiff_utils_1 = require("../utils/tiff-utils");
|
|
9
|
+
// WARNING: Changes to the parser options _will_ effect the types in types/omexml.d.ts.
|
|
10
|
+
const PARSER_OPTIONS = {
|
|
11
|
+
// Nests attributes withtout prefix under 'attr' key for each node
|
|
12
|
+
attributeNamePrefix: '',
|
|
13
|
+
attrNodeName: 'attr',
|
|
14
|
+
// Parses numbers for both attributes and nodes
|
|
15
|
+
parseNodeValue: true,
|
|
16
|
+
parseAttributeValue: true,
|
|
17
|
+
// Forces attributes to be parsed
|
|
18
|
+
ignoreAttributes: false
|
|
19
|
+
};
|
|
20
|
+
const parse = (str) => fast_xml_parser_1.default.parse(str, PARSER_OPTIONS);
|
|
21
|
+
function fromString(str) {
|
|
22
|
+
const res = parse(str);
|
|
23
|
+
if (!res.OME) {
|
|
24
|
+
throw Error('Failed to parse OME-XML metadata.');
|
|
25
|
+
}
|
|
26
|
+
return (0, tiff_utils_1.ensureArray)(res.OME.Image).map((img) => {
|
|
27
|
+
const Channels = (0, tiff_utils_1.ensureArray)(img.Pixels.Channel).map((c) => {
|
|
28
|
+
if ('Color' in c.attr) {
|
|
29
|
+
return { ...c.attr, Color: (0, tiff_utils_1.intToRgba)(c.attr.Color) };
|
|
30
|
+
}
|
|
31
|
+
return { ...c.attr };
|
|
32
|
+
});
|
|
33
|
+
const { AquisitionDate = '', Description = '' } = img;
|
|
34
|
+
const image = {
|
|
35
|
+
...img.attr,
|
|
36
|
+
AquisitionDate,
|
|
37
|
+
Description,
|
|
38
|
+
Pixels: {
|
|
39
|
+
...img.Pixels.attr,
|
|
40
|
+
Channels
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
return {
|
|
44
|
+
...image,
|
|
45
|
+
format() {
|
|
46
|
+
const { Pixels } = image;
|
|
47
|
+
const sizes = ['X', 'Y', 'Z']
|
|
48
|
+
.map((name) => {
|
|
49
|
+
const size = Pixels[`PhysicalSize${name}`];
|
|
50
|
+
const unit = Pixels[`PhysicalSize${name}Unit`];
|
|
51
|
+
return size && unit ? `${size} ${unit}` : '-';
|
|
52
|
+
})
|
|
53
|
+
.join(' x ');
|
|
54
|
+
return {
|
|
55
|
+
'Acquisition Date': image.AquisitionDate,
|
|
56
|
+
'Dimensions (XY)': `${Pixels.SizeX} x ${Pixels.SizeY}`,
|
|
57
|
+
'Pixels Type': Pixels.Type,
|
|
58
|
+
'Pixels Size (XYZ)': sizes,
|
|
59
|
+
'Z-sections/Timepoints': `${Pixels.SizeZ} x ${Pixels.SizeT}`,
|
|
60
|
+
Channels: Pixels.SizeC
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
exports.fromString = fromString;
|
package/dist/lib/ome/utils.d.ts
CHANGED
|
@@ -2,3 +2,4 @@ import type { OMEXML } from '../ome/omexml';
|
|
|
2
2
|
import type { Labels } from '../../types';
|
|
3
3
|
export declare function getLabels(dimOrder: OMEXML[0]['Pixels']['DimensionOrder']): Labels<["t", "c", "z"] | ["c", "t", "z"] | ["z", "t", "c"] | ["t", "z", "c"] | ["z", "c", "t"] | ["c", "z", "t"]>;
|
|
4
4
|
export declare function getDims<S extends string>(labels: S[]): (name: S) => number;
|
|
5
|
+
//# sourceMappingURL=utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/lib/ome/utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,MAAM,EAAC,MAAM,eAAe,CAAC;AAC1C,OAAO,KAAK,EAAC,MAAM,EAAC,MAAM,aAAa,CAAC;AAYxC,wBAAgB,SAAS,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,gBAAgB,CAAC,qHAExE;AAWD,wBAAgB,OAAO,CAAC,CAAC,SAAS,MAAM,EAAE,MAAM,EAAE,CAAC,EAAE,UAKrC,CAAC,YAOhB"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getDims = exports.getLabels = void 0;
|
|
4
|
+
function getLabels(dimOrder) {
|
|
5
|
+
return dimOrder.toLowerCase().split('').reverse();
|
|
6
|
+
}
|
|
7
|
+
exports.getLabels = getLabels;
|
|
8
|
+
/*
|
|
9
|
+
* Creates an ES6 map of 'label' -> index
|
|
10
|
+
* > const labels = ['a', 'b', 'c', 'd'];
|
|
11
|
+
* > const dims = getDims(labels);
|
|
12
|
+
* > dims('a') === 0;
|
|
13
|
+
* > dims('b') === 1;
|
|
14
|
+
* > dims('c') === 2;
|
|
15
|
+
* > dims('hi!'); // throws
|
|
16
|
+
*/
|
|
17
|
+
function getDims(labels) {
|
|
18
|
+
const lookup = new Map(labels.map((name, i) => [name, i]));
|
|
19
|
+
if (lookup.size !== labels.length) {
|
|
20
|
+
throw Error('Labels must be unique, found duplicated label.');
|
|
21
|
+
}
|
|
22
|
+
return (name) => {
|
|
23
|
+
const index = lookup.get(name);
|
|
24
|
+
if (index === undefined) {
|
|
25
|
+
throw Error('Invalid dimension.');
|
|
26
|
+
}
|
|
27
|
+
return index;
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
exports.getDims = getDims;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tiff-pixel-source.d.ts","sourceRoot":"","sources":["../../src/lib/tiff-pixel-source.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,YAAY,EAAgB,MAAM,SAAS,CAAC;AAGzD,OAAO,KAAK,EACV,WAAW,EACX,oBAAoB,EACpB,eAAe,EACf,KAAK,EACL,MAAM,EACN,eAAe,EACf,aAAa,EACb,SAAS,EAEV,MAAM,UAAU,CAAC;AAElB,cAAM,eAAe,CAAC,CAAC,SAAS,MAAM,EAAE,CAAE,YAAW,WAAW,CAAC,CAAC,CAAC;IAC1D,KAAK,EAAE,KAAK,CAAC;IACb,QAAQ,EAAE,MAAM,CAAC;IACjB,KAAK,EAAE,MAAM,EAAE,CAAC;IAChB,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC,CAAC;IAClB,IAAI,EAAE,eAAe,GAAG,SAAS,CAAC;IACzC,OAAO,CAAC,QAAQ,CAA0D;gBAIxE,OAAO,EAAE,CAAC,GAAG,EAAE,oBAAoB,CAAC,CAAC,CAAC,KAAK,OAAO,CAAC,YAAY,CAAC,EAChE,KAAK,EAAE,KAAK,EACZ,QAAQ,EAAE,MAAM,EAChB,KAAK,EAAE,MAAM,EAAE,EACf,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC,EACjB,IAAI,CAAC,EAAE,eAAe;IAUlB,SAAS,CAAC,EAAC,SAAS,EAAE,MAAM,EAAC,EAAE,eAAe,CAAC,CAAC,CAAC;IAKjD,OAAO,CAAC,EAAC,CAAC,EAAE,CAAC,EAAE,SAAS,EAAE,MAAM,EAAC,EAAE,aAAa,CAAC,CAAC,CAAC;YAU3C,YAAY;IAuB1B,OAAO,CAAC,cAAc;IAetB,WAAW,CAAC,GAAG,EAAE,KAAK;CAGvB;AAED,eAAe,eAAe,CAAC"}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const tiff_utils_1 = require("./utils/tiff-utils");
|
|
4
|
+
class TiffPixelSource {
|
|
5
|
+
// eslint-disable-next-line max-params
|
|
6
|
+
constructor(indexer, dtype, tileSize, shape, labels, meta) {
|
|
7
|
+
this._indexer = indexer;
|
|
8
|
+
this.dtype = dtype;
|
|
9
|
+
this.tileSize = tileSize;
|
|
10
|
+
this.shape = shape;
|
|
11
|
+
this.labels = labels;
|
|
12
|
+
this.meta = meta;
|
|
13
|
+
}
|
|
14
|
+
async getRaster({ selection, signal }) {
|
|
15
|
+
const image = await this._indexer(selection);
|
|
16
|
+
return this._readRasters(image, { signal });
|
|
17
|
+
}
|
|
18
|
+
async getTile({ x, y, selection, signal }) {
|
|
19
|
+
const { height, width } = this._getTileExtent(x, y);
|
|
20
|
+
const x0 = x * this.tileSize;
|
|
21
|
+
const y0 = y * this.tileSize;
|
|
22
|
+
const window = [x0, y0, x0 + width, y0 + height];
|
|
23
|
+
const image = await this._indexer(selection);
|
|
24
|
+
return this._readRasters(image, { window, width, height, signal });
|
|
25
|
+
}
|
|
26
|
+
async _readRasters(image, props) {
|
|
27
|
+
const interleave = (0, tiff_utils_1.isInterleaved)(this.shape);
|
|
28
|
+
const raster = await image.readRasters({ interleave, ...props });
|
|
29
|
+
if (props?.signal?.aborted) {
|
|
30
|
+
throw tiff_utils_1.SIGNAL_ABORTED;
|
|
31
|
+
}
|
|
32
|
+
/*
|
|
33
|
+
* geotiff.js returns objects with different structure
|
|
34
|
+
* depending on `interleave`. It's weird, but this seems to work.
|
|
35
|
+
*/
|
|
36
|
+
const data = (interleave ? raster : raster[0]);
|
|
37
|
+
return {
|
|
38
|
+
data,
|
|
39
|
+
width: raster.width,
|
|
40
|
+
height: raster.height
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
/*
|
|
44
|
+
* Computes tile size given x, y coord.
|
|
45
|
+
*/
|
|
46
|
+
_getTileExtent(x, y) {
|
|
47
|
+
const { height: zoomLevelHeight, width: zoomLevelWidth } = (0, tiff_utils_1.getImageSize)(this);
|
|
48
|
+
let height = this.tileSize;
|
|
49
|
+
let width = this.tileSize;
|
|
50
|
+
const maxXTileCoord = Math.floor(zoomLevelWidth / this.tileSize);
|
|
51
|
+
const maxYTileCoord = Math.floor(zoomLevelHeight / this.tileSize);
|
|
52
|
+
if (x === maxXTileCoord) {
|
|
53
|
+
width = zoomLevelWidth % this.tileSize;
|
|
54
|
+
}
|
|
55
|
+
if (y === maxYTileCoord) {
|
|
56
|
+
height = zoomLevelHeight % this.tileSize;
|
|
57
|
+
}
|
|
58
|
+
return { height, width };
|
|
59
|
+
}
|
|
60
|
+
onTileError(err) {
|
|
61
|
+
console.error(err); // eslint-disable-line no-console
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
exports.default = TiffPixelSource;
|
package/dist/lib/utils/Pool.d.ts
CHANGED
|
@@ -0,0 +1 @@
|
|
|
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"}
|