@fideus-labs/fidnii 0.3.0 → 0.4.0
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/fromTiff.d.ts +51 -0
- package/dist/fromTiff.d.ts.map +1 -0
- package/dist/fromTiff.js +64 -0
- package/dist/fromTiff.js.map +1 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -32
- package/dist/index.js.map +1 -1
- package/package.json +3 -2
- package/src/fromTiff.ts +88 -0
- package/src/index.ts +5 -0
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Load TIFF files (OME-TIFF, pyramidal, plain) and produce a
|
|
3
|
+
* {@link Multiscales} object ready for {@link OMEZarrNVImage.create}.
|
|
4
|
+
*
|
|
5
|
+
* Uses {@link https://github.com/fideus-labs/fiff | @fideus-labs/fiff}
|
|
6
|
+
* to present TIFFs as zarrita-compatible stores, then delegates to
|
|
7
|
+
* {@link fromNgffZarr} for OME-Zarr metadata parsing.
|
|
8
|
+
*/
|
|
9
|
+
import type { TiffStoreOptions } from "@fideus-labs/fiff";
|
|
10
|
+
import { TiffStore } from "@fideus-labs/fiff";
|
|
11
|
+
import type { Multiscales } from "@fideus-labs/ngff-zarr";
|
|
12
|
+
import type { FromNgffZarrOptions } from "@fideus-labs/ngff-zarr/browser";
|
|
13
|
+
/** Options for {@link fromTiff}. */
|
|
14
|
+
export interface FromTiffOptions {
|
|
15
|
+
/** Options forwarded to {@link TiffStore} (e.g. IFD offsets, HTTP headers). */
|
|
16
|
+
tiff?: TiffStoreOptions;
|
|
17
|
+
/** Options forwarded to {@link fromNgffZarr} (e.g. validate, cache). */
|
|
18
|
+
ngffZarr?: Omit<FromNgffZarrOptions, "version">;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Load a TIFF file and return a {@link Multiscales} object ready for
|
|
22
|
+
* {@link OMEZarrNVImage.create}.
|
|
23
|
+
*
|
|
24
|
+
* Supports OME-TIFF, pyramidal TIFF (SubIFDs / legacy / COG), and
|
|
25
|
+
* plain single-image TIFFs. Both local (Blob/ArrayBuffer) and
|
|
26
|
+
* remote (URL with HTTP range requests) sources are supported.
|
|
27
|
+
*
|
|
28
|
+
* @param source - A URL string, Blob/File, ArrayBuffer, or
|
|
29
|
+
* pre-built {@link TiffStore}.
|
|
30
|
+
* @param options - Optional {@link FromTiffOptions}.
|
|
31
|
+
* @returns A {@link Multiscales} object for use with
|
|
32
|
+
* {@link OMEZarrNVImage.create}.
|
|
33
|
+
* @throws If the source cannot be opened as a TIFF or if the
|
|
34
|
+
* synthesized OME-Zarr metadata is invalid.
|
|
35
|
+
*
|
|
36
|
+
* @example
|
|
37
|
+
* ```typescript
|
|
38
|
+
* // From a remote URL
|
|
39
|
+
* const ms = await fromTiff("https://example.com/image.ome.tif")
|
|
40
|
+
* const image = await OMEZarrNVImage.create({
|
|
41
|
+
* multiscales: ms,
|
|
42
|
+
* niivue: nv,
|
|
43
|
+
* })
|
|
44
|
+
*
|
|
45
|
+
* // From a File input
|
|
46
|
+
* const file = inputElement.files[0]
|
|
47
|
+
* const ms = await fromTiff(file)
|
|
48
|
+
* ```
|
|
49
|
+
*/
|
|
50
|
+
export declare function fromTiff(source: string | Blob | ArrayBuffer | TiffStore, options?: FromTiffOptions): Promise<Multiscales>;
|
|
51
|
+
//# sourceMappingURL=fromTiff.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fromTiff.d.ts","sourceRoot":"","sources":["../src/fromTiff.ts"],"names":[],"mappings":"AAGA;;;;;;;GAOG;AAEH,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAA;AACzD,OAAO,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAA;AAC7C,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAA;AACzD,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,gCAAgC,CAAA;AAIzE,oCAAoC;AACpC,MAAM,WAAW,eAAe;IAC9B,+EAA+E;IAC/E,IAAI,CAAC,EAAE,gBAAgB,CAAA;IACvB,wEAAwE;IACxE,QAAQ,CAAC,EAAE,IAAI,CAAC,mBAAmB,EAAE,SAAS,CAAC,CAAA;CAChD;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACH,wBAAsB,QAAQ,CAC5B,MAAM,EAAE,MAAM,GAAG,IAAI,GAAG,WAAW,GAAG,SAAS,EAC/C,OAAO,GAAE,eAAoB,GAC5B,OAAO,CAAC,WAAW,CAAC,CA2BtB"}
|
package/dist/fromTiff.js
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
// SPDX-FileCopyrightText: Copyright (c) Fideus Labs LLC
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
import { TiffStore } from "@fideus-labs/fiff";
|
|
4
|
+
import { fromNgffZarr } from "@fideus-labs/ngff-zarr/browser";
|
|
5
|
+
/**
|
|
6
|
+
* Load a TIFF file and return a {@link Multiscales} object ready for
|
|
7
|
+
* {@link OMEZarrNVImage.create}.
|
|
8
|
+
*
|
|
9
|
+
* Supports OME-TIFF, pyramidal TIFF (SubIFDs / legacy / COG), and
|
|
10
|
+
* plain single-image TIFFs. Both local (Blob/ArrayBuffer) and
|
|
11
|
+
* remote (URL with HTTP range requests) sources are supported.
|
|
12
|
+
*
|
|
13
|
+
* @param source - A URL string, Blob/File, ArrayBuffer, or
|
|
14
|
+
* pre-built {@link TiffStore}.
|
|
15
|
+
* @param options - Optional {@link FromTiffOptions}.
|
|
16
|
+
* @returns A {@link Multiscales} object for use with
|
|
17
|
+
* {@link OMEZarrNVImage.create}.
|
|
18
|
+
* @throws If the source cannot be opened as a TIFF or if the
|
|
19
|
+
* synthesized OME-Zarr metadata is invalid.
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* ```typescript
|
|
23
|
+
* // From a remote URL
|
|
24
|
+
* const ms = await fromTiff("https://example.com/image.ome.tif")
|
|
25
|
+
* const image = await OMEZarrNVImage.create({
|
|
26
|
+
* multiscales: ms,
|
|
27
|
+
* niivue: nv,
|
|
28
|
+
* })
|
|
29
|
+
*
|
|
30
|
+
* // From a File input
|
|
31
|
+
* const file = inputElement.files[0]
|
|
32
|
+
* const ms = await fromTiff(file)
|
|
33
|
+
* ```
|
|
34
|
+
*/
|
|
35
|
+
export async function fromTiff(source, options = {}) {
|
|
36
|
+
let store;
|
|
37
|
+
if (source instanceof TiffStore) {
|
|
38
|
+
store = source;
|
|
39
|
+
}
|
|
40
|
+
else if (typeof source === "string") {
|
|
41
|
+
store = await TiffStore.fromUrl(source, options.tiff);
|
|
42
|
+
}
|
|
43
|
+
else if (source instanceof Blob) {
|
|
44
|
+
store = await TiffStore.fromBlob(source, options.tiff);
|
|
45
|
+
}
|
|
46
|
+
else if (source instanceof ArrayBuffer) {
|
|
47
|
+
store = await TiffStore.fromArrayBuffer(source, options.tiff);
|
|
48
|
+
}
|
|
49
|
+
else {
|
|
50
|
+
throw new Error("[fidnii] fromTiff: source must be a URL string, Blob, " +
|
|
51
|
+
"ArrayBuffer, or TiffStore");
|
|
52
|
+
}
|
|
53
|
+
// TiffStore implements zarrita's Readable interface structurally
|
|
54
|
+
// (its get() method accepts string keys including the leading "/"
|
|
55
|
+
// that zarrita uses for AbsolutePath). Since fromNgffZarr (v0.10+)
|
|
56
|
+
// accepts zarr.Readable directly, we only need a type assertion.
|
|
57
|
+
//
|
|
58
|
+
// TiffStore always produces OME-Zarr v0.5 metadata.
|
|
59
|
+
return fromNgffZarr(store, {
|
|
60
|
+
version: "0.5",
|
|
61
|
+
...options.ngffZarr,
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
//# sourceMappingURL=fromTiff.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fromTiff.js","sourceRoot":"","sources":["../src/fromTiff.ts"],"names":[],"mappings":"AAAA,wDAAwD;A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";
|
|
34
|
+
export { TiffStore } from "@fideus-labs/fiff";
|
|
33
35
|
export { Methods } from "@fideus-labs/ngff-zarr";
|
|
34
36
|
export { terminateOmeroWorkerPool, terminateWorkerPool, } from "@fideus-labs/ngff-zarr/browser";
|
|
35
37
|
export { BufferManager } from "./BufferManager.js";
|
|
36
38
|
export { alignToChunks, azimuthElevationToNormal, calculateNiivueDepth, clipPlanesToBoundingBox, clipPlanesToNiivue, clipPlanesToPixelRegion, clipPlaneToNiivue, createAxisAlignedClipPlane, createClipPlane, createDefaultClipPlanes, getVolumeBoundsFromMultiscales, isInsideClipPlanes, MAX_CLIP_PLANES, normalizeVector, normalToAzimuthElevation, pointToPlaneDistance, validateClipPlanes, } from "./ClipPlanes.js";
|
|
37
39
|
export type { OMEZarrNVImageEventListener, OMEZarrNVImageEventListenerOptions, OMEZarrNVImageEventMap, PopulateTrigger, } from "./events.js";
|
|
38
40
|
export { OMEZarrNVImageEvent } from "./events.js";
|
|
41
|
+
export type { FromTiffOptions } from "./fromTiff.js";
|
|
42
|
+
export { fromTiff } from "./fromTiff.js";
|
|
39
43
|
export type { ChannelWindow } from "./normalize.js";
|
|
40
44
|
export { computeChannelMinMax, normalizeToUint8 } from "./normalize.js";
|
|
41
45
|
export { OMEZarrNVImage } from "./OMEZarrNVImage.js";
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAGA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAGA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AAEH,YAAY,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAA;AACzD,OAAO,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAA;AAE7C,OAAO,EAAE,OAAO,EAA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Ae,EACf,aAAa,EACb,UAAU,EACV,YAAY,EACZ,SAAS,GACV,MAAM,YAAY,CAAA;AAGnB,OAAO,EACL,gBAAgB,EAChB,cAAc,EACd,gBAAgB,EAChB,mBAAmB,EACnB,wBAAwB,EACxB,UAAU,EACV,aAAa,EACb,qBAAqB,EACrB,iBAAiB,EACjB,UAAU,GACX,MAAM,YAAY,CAAA;AAEnB,OAAO,EACL,kBAAkB,EAClB,oBAAoB,EACpB,yBAAyB,EACzB,uBAAuB,EACvB,kBAAkB,EAClB,qBAAqB,GACtB,MAAM,mBAAmB,CAAA;AAE1B,OAAO,EACL,cAAc,EACd,eAAe,EACf,eAAe,EACf,iBAAiB,EACjB,YAAY,EACZ,kBAAkB,EAClB,eAAe,EACf,iBAAiB,EACjB,YAAY,EACZ,kBAAkB,GACnB,MAAM,wBAAwB,CAAA;AAE/B,OAAO,EACL,iBAAiB,EACjB,uBAAuB,EACvB,uBAAuB,EACvB,eAAe,GAChB,MAAM,qBAAqB,CAAA"}
|
package/dist/index.js
CHANGED
|
@@ -1,37 +1,6 @@
|
|
|
1
1
|
// SPDX-FileCopyrightText: Copyright (c) Fideus Labs LLC
|
|
2
2
|
// SPDX-License-Identifier: MIT
|
|
3
|
-
|
|
4
|
-
* @fideus-labs/fidnii
|
|
5
|
-
*
|
|
6
|
-
* Render OME-Zarr images in NiiVue with progressive multi-resolution loading.
|
|
7
|
-
*
|
|
8
|
-
* @example
|
|
9
|
-
* ```typescript
|
|
10
|
-
* import { Niivue } from '@niivue/niivue';
|
|
11
|
-
* import { fromNgffZarr } from '@fideus-labs/ngff-zarr';
|
|
12
|
-
* import { OMEZarrNVImage } from '@fideus-labs/fidnii';
|
|
13
|
-
*
|
|
14
|
-
* const nv = new Niivue();
|
|
15
|
-
* await nv.attachToCanvas(document.getElementById('canvas'));
|
|
16
|
-
*
|
|
17
|
-
* const multiscales = await fromNgffZarr('/path/to/data.ome.zarr');
|
|
18
|
-
*
|
|
19
|
-
* // Image is automatically added to NiiVue and loads progressively
|
|
20
|
-
* const image = await OMEZarrNVImage.create({ multiscales, niivue: nv });
|
|
21
|
-
*
|
|
22
|
-
* // Listen for loading complete if needed
|
|
23
|
-
* image.addEventListener('populateComplete', () => console.log('Loaded!'));
|
|
24
|
-
*
|
|
25
|
-
* // For manual control, use autoLoad: false
|
|
26
|
-
* // const image = await OMEZarrNVImage.create({
|
|
27
|
-
* // multiscales,
|
|
28
|
-
* // niivue: nv,
|
|
29
|
-
* // autoLoad: false,
|
|
30
|
-
* // });
|
|
31
|
-
* // nv.addVolume(image);
|
|
32
|
-
* // await image.populateVolume();
|
|
33
|
-
* ```
|
|
34
|
-
*/
|
|
3
|
+
export { TiffStore } from "@fideus-labs/fiff";
|
|
35
4
|
// Re-export Methods enum so consumers can check isLabelImage or compare method values
|
|
36
5
|
export { Methods } from "@fideus-labs/ngff-zarr";
|
|
37
6
|
// Worker pool lifecycle (re-exported from ngff-zarr)
|
|
@@ -42,6 +11,8 @@ export { BufferManager } from "./BufferManager.js";
|
|
|
42
11
|
export { alignToChunks, azimuthElevationToNormal, calculateNiivueDepth, clipPlanesToBoundingBox, clipPlanesToNiivue, clipPlanesToPixelRegion, clipPlaneToNiivue, createAxisAlignedClipPlane, createClipPlane, createDefaultClipPlanes, getVolumeBoundsFromMultiscales, isInsideClipPlanes, MAX_CLIP_PLANES, normalizeVector, normalToAzimuthElevation, pointToPlaneDistance, validateClipPlanes, } from "./ClipPlanes.js";
|
|
43
12
|
// Event system (browser-native EventTarget API)
|
|
44
13
|
export { OMEZarrNVImageEvent } from "./events.js";
|
|
14
|
+
// TIFF support (via @fideus-labs/fiff)
|
|
15
|
+
export { fromTiff } from "./fromTiff.js";
|
|
45
16
|
export { computeChannelMinMax, normalizeToUint8 } from "./normalize.js";
|
|
46
17
|
// Main class
|
|
47
18
|
export { OMEZarrNVImage } from "./OMEZarrNVImage.js";
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,+BAA+B;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,+BAA+B;AAoC/B,OAAO,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAA;AAC7C,sFAAsF;AACtF,OAAO,EAAE,OAAO,EAAE,MAAM,wBAAwB,CAAA;AAChD,qDAAqD;AACrD,OAAO,EACL,wBAAwB,EACxB,mBAAmB,GACpB,MAAM,gCAAgC,CAAA;AAEvC,iBAAiB;AACjB,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAA;AAClD,wBAAwB;AACxB,OAAO,EACL,aAAa,EACb,wBAAwB,EACxB,oBAAoB,EACpB,uBAAuB,EACvB,kBAAkB,EAClB,uBAAuB,EACvB,iBAAiB,EACjB,0BAA0B,EAC1B,eAAe,EACf,uBAAuB,EACvB,8BAA8B,EAC9B,kBAAkB,EAClB,eAAe,EACf,eAAe,EACf,wBAAwB,EACxB,oBAAoB,EACpB,kBAAkB,GACnB,MAAM,iBAAiB,CAAA;AAOxB,gDAAgD;AAChD,OAAO,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAA;AAEjD,uCAAuC;AACvC,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAA;AAGxC,OAAO,EAAE,oBAAoB,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAA;AACvE,aAAa;AACb,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAA;AACpD,mBAAmB;AACnB,OAAO,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAA;AAEtE,gCAAgC;AAChC,OAAO,EACL,mBAAmB,EACnB,uBAAuB,EACvB,aAAa,EACb,uBAAuB,EACvB,wBAAwB,EACxB,cAAc,EACd,kBAAkB,EAClB,gBAAgB,GACjB,MAAM,yBAAyB,CAAA;AAmBhC,iEAAiE;AACjE,iBAAiB;AACjB,OAAO,EACL,gBAAgB,EAChB,cAAc,EACd,gBAAgB,EAChB,mBAAmB,EACnB,wBAAwB,EACxB,UAAU,EACV,aAAa,EACb,qBAAqB,EACrB,iBAAiB,EACjB,UAAU,GACX,MAAM,YAAY,CAAA;AACnB,mBAAmB;AACnB,OAAO,EACL,kBAAkB,EAClB,oBAAoB,EACpB,yBAAyB,EACzB,uBAAuB,EACvB,kBAAkB,EAClB,qBAAqB,GACtB,MAAM,mBAAmB,CAAA;AAC1B,uBAAuB;AACvB,OAAO,EACL,cAAc,EACd,eAAe,EACf,eAAe,EACf,iBAAiB,EACjB,YAAY,EACZ,kBAAkB,EAClB,eAAe,EACf,iBAAiB,EACjB,YAAY,EACZ,kBAAkB,GACnB,MAAM,wBAAwB,CAAA;AAC/B,4BAA4B;AAC5B,OAAO,EACL,iBAAiB,EACjB,uBAAuB,EACvB,uBAAuB,EACvB,eAAe,GAChB,MAAM,qBAAqB,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fideus-labs/fidnii",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0",
|
|
4
4
|
"description": "Render OME-Zarr images in NiiVue with progressive multi-resolution loading",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -16,7 +16,8 @@
|
|
|
16
16
|
"src"
|
|
17
17
|
],
|
|
18
18
|
"dependencies": {
|
|
19
|
-
"@fideus-labs/
|
|
19
|
+
"@fideus-labs/fiff": "^0.3.2",
|
|
20
|
+
"@fideus-labs/ngff-zarr": "^0.11.0",
|
|
20
21
|
"@itk-wasm/downsample": "^1.8.1",
|
|
21
22
|
"lru-cache": "^11.1.0",
|
|
22
23
|
"@niivue/niivue": "^0.67.0",
|
package/src/fromTiff.ts
ADDED
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
// SPDX-FileCopyrightText: Copyright (c) Fideus Labs LLC
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Load TIFF files (OME-TIFF, pyramidal, plain) and produce a
|
|
6
|
+
* {@link Multiscales} object ready for {@link OMEZarrNVImage.create}.
|
|
7
|
+
*
|
|
8
|
+
* Uses {@link https://github.com/fideus-labs/fiff | @fideus-labs/fiff}
|
|
9
|
+
* to present TIFFs as zarrita-compatible stores, then delegates to
|
|
10
|
+
* {@link fromNgffZarr} for OME-Zarr metadata parsing.
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
import type { TiffStoreOptions } from "@fideus-labs/fiff"
|
|
14
|
+
import { TiffStore } from "@fideus-labs/fiff"
|
|
15
|
+
import type { Multiscales } from "@fideus-labs/ngff-zarr"
|
|
16
|
+
import type { FromNgffZarrOptions } from "@fideus-labs/ngff-zarr/browser"
|
|
17
|
+
import { fromNgffZarr } from "@fideus-labs/ngff-zarr/browser"
|
|
18
|
+
import type { Readable } from "zarrita"
|
|
19
|
+
|
|
20
|
+
/** Options for {@link fromTiff}. */
|
|
21
|
+
export interface FromTiffOptions {
|
|
22
|
+
/** Options forwarded to {@link TiffStore} (e.g. IFD offsets, HTTP headers). */
|
|
23
|
+
tiff?: TiffStoreOptions
|
|
24
|
+
/** Options forwarded to {@link fromNgffZarr} (e.g. validate, cache). */
|
|
25
|
+
ngffZarr?: Omit<FromNgffZarrOptions, "version">
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Load a TIFF file and return a {@link Multiscales} object ready for
|
|
30
|
+
* {@link OMEZarrNVImage.create}.
|
|
31
|
+
*
|
|
32
|
+
* Supports OME-TIFF, pyramidal TIFF (SubIFDs / legacy / COG), and
|
|
33
|
+
* plain single-image TIFFs. Both local (Blob/ArrayBuffer) and
|
|
34
|
+
* remote (URL with HTTP range requests) sources are supported.
|
|
35
|
+
*
|
|
36
|
+
* @param source - A URL string, Blob/File, ArrayBuffer, or
|
|
37
|
+
* pre-built {@link TiffStore}.
|
|
38
|
+
* @param options - Optional {@link FromTiffOptions}.
|
|
39
|
+
* @returns A {@link Multiscales} object for use with
|
|
40
|
+
* {@link OMEZarrNVImage.create}.
|
|
41
|
+
* @throws If the source cannot be opened as a TIFF or if the
|
|
42
|
+
* synthesized OME-Zarr metadata is invalid.
|
|
43
|
+
*
|
|
44
|
+
* @example
|
|
45
|
+
* ```typescript
|
|
46
|
+
* // From a remote URL
|
|
47
|
+
* const ms = await fromTiff("https://example.com/image.ome.tif")
|
|
48
|
+
* const image = await OMEZarrNVImage.create({
|
|
49
|
+
* multiscales: ms,
|
|
50
|
+
* niivue: nv,
|
|
51
|
+
* })
|
|
52
|
+
*
|
|
53
|
+
* // From a File input
|
|
54
|
+
* const file = inputElement.files[0]
|
|
55
|
+
* const ms = await fromTiff(file)
|
|
56
|
+
* ```
|
|
57
|
+
*/
|
|
58
|
+
export async function fromTiff(
|
|
59
|
+
source: string | Blob | ArrayBuffer | TiffStore,
|
|
60
|
+
options: FromTiffOptions = {},
|
|
61
|
+
): Promise<Multiscales> {
|
|
62
|
+
let store: TiffStore
|
|
63
|
+
if (source instanceof TiffStore) {
|
|
64
|
+
store = source
|
|
65
|
+
} else if (typeof source === "string") {
|
|
66
|
+
store = await TiffStore.fromUrl(source, options.tiff)
|
|
67
|
+
} else if (source instanceof Blob) {
|
|
68
|
+
store = await TiffStore.fromBlob(source, options.tiff)
|
|
69
|
+
} else if (source instanceof ArrayBuffer) {
|
|
70
|
+
store = await TiffStore.fromArrayBuffer(source, options.tiff)
|
|
71
|
+
} else {
|
|
72
|
+
throw new Error(
|
|
73
|
+
"[fidnii] fromTiff: source must be a URL string, Blob, " +
|
|
74
|
+
"ArrayBuffer, or TiffStore",
|
|
75
|
+
)
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
// TiffStore implements zarrita's Readable interface structurally
|
|
79
|
+
// (its get() method accepts string keys including the leading "/"
|
|
80
|
+
// that zarrita uses for AbsolutePath). Since fromNgffZarr (v0.10+)
|
|
81
|
+
// accepts zarr.Readable directly, we only need a type assertion.
|
|
82
|
+
//
|
|
83
|
+
// TiffStore always produces OME-Zarr v0.5 metadata.
|
|
84
|
+
return fromNgffZarr(store as unknown as Readable, {
|
|
85
|
+
version: "0.5",
|
|
86
|
+
...options.ngffZarr,
|
|
87
|
+
})
|
|
88
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -34,6 +34,8 @@
|
|
|
34
34
|
* ```
|
|
35
35
|
*/
|
|
36
36
|
|
|
37
|
+
export type { TiffStoreOptions } from "@fideus-labs/fiff"
|
|
38
|
+
export { TiffStore } from "@fideus-labs/fiff"
|
|
37
39
|
// Re-export Methods enum so consumers can check isLabelImage or compare method values
|
|
38
40
|
export { Methods } from "@fideus-labs/ngff-zarr"
|
|
39
41
|
// Worker pool lifecycle (re-exported from ngff-zarr)
|
|
@@ -72,6 +74,9 @@ export type {
|
|
|
72
74
|
} from "./events.js"
|
|
73
75
|
// Event system (browser-native EventTarget API)
|
|
74
76
|
export { OMEZarrNVImageEvent } from "./events.js"
|
|
77
|
+
export type { FromTiffOptions } from "./fromTiff.js"
|
|
78
|
+
// TIFF support (via @fideus-labs/fiff)
|
|
79
|
+
export { fromTiff } from "./fromTiff.js"
|
|
75
80
|
// RGB normalization utilities
|
|
76
81
|
export type { ChannelWindow } from "./normalize.js"
|
|
77
82
|
export { computeChannelMinMax, normalizeToUint8 } from "./normalize.js"
|