omezarr-tilesource 0.6.0 → 0.7.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/README.md +22 -5
- package/dist/omezarr-tilesource.d.ts +35 -20
- package/dist/omezarr-tilesource.js +51 -35
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -63,8 +63,13 @@ const tileSource2 = {
|
|
|
63
63
|
// direct instantiation with URL (works with any OME-Zarr storage backend)
|
|
64
64
|
const tileSource3 = new OMEZarrTileSource(url);
|
|
65
65
|
|
|
66
|
+
// direct instantiation with a File (or any Blob) holding a zipped OME-Zarr file,
|
|
67
|
+
// e.g. from an <input type="file"> or a drop event; also accepted as `url` in
|
|
68
|
+
// inline configurations and options objects (but not directly as a tile source)
|
|
69
|
+
const tileSource4 = new OMEZarrTileSource(file);
|
|
70
|
+
|
|
66
71
|
// direct instantiation with options object
|
|
67
|
-
const
|
|
72
|
+
const tileSource5 = new OMEZarrTileSource({
|
|
68
73
|
url: url,
|
|
69
74
|
// zip: undefined, // undefined = OME-Zarr ZIP auto-detection based on .ozx path suffix
|
|
70
75
|
// t: undefined, // undefined = omero rdefs default (middle timepoint if missing)
|
|
@@ -83,7 +88,8 @@ const viewer = OpenSeadragon({
|
|
|
83
88
|
tileSource1,
|
|
84
89
|
tileSource2,
|
|
85
90
|
tileSource3,
|
|
86
|
-
tileSource4
|
|
91
|
+
tileSource4,
|
|
92
|
+
tileSource5
|
|
87
93
|
]
|
|
88
94
|
});
|
|
89
95
|
```
|
|
@@ -92,8 +98,8 @@ const viewer = OpenSeadragon({
|
|
|
92
98
|
|
|
93
99
|
| Option | Type | Default | Description |
|
|
94
100
|
| --------------- | ------------------------------------------------------- | ------------------------------------------------------------------------------ | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
95
|
-
| `url` | `string \| URL`
|
|
96
|
-
| `zip` | `boolean` | `true` if the `url` path ends with `.ozx`
|
|
101
|
+
| `url` | `string \| URL \| Blob` | (required) | URL of the OME-Zarr image (group) or of a zipped OME-Zarr file, relative to the document base URL, or a `Blob` (e.g. a `File`) holding a zipped OME-Zarr file |
|
|
102
|
+
| `zip` | `boolean` | `true` if the `url` path ends with `.ozx` or `url` is a `Blob` | Whether `url` points to a zipped OME-Zarr file; must not be `false` for a `Blob` |
|
|
97
103
|
| `t` | `number` | omero `rdefs.defaultT`, else middle plane | Timepoint index (0-based) |
|
|
98
104
|
| `z` | `number` | omero `rdefs.defaultZ`, else middle plane | Z-slice index (0-based) |
|
|
99
105
|
| `c` | `number \| number[]` | all channels marked active in omero | Channel index or indices (0-based) to render, composited in the given order. Arrays must be non-empty |
|
|
@@ -121,6 +127,16 @@ created; the resolved absolute URL is available as `tileSource.url` (always a
|
|
|
121
127
|
string) and is used for loading, for the tile cache keys and for comparing tile
|
|
122
128
|
sources.
|
|
123
129
|
|
|
130
|
+
A `Blob` (e.g. a `File` picked by the user) is read with the zarrita
|
|
131
|
+
`ZipFileStore.fromBlob` store, so it must hold a zipped OME-Zarr file
|
|
132
|
+
(`zip: false` is rejected by the constructor). The `Blob` is available as
|
|
133
|
+
`tileSource.blob`, and `tileSource.url` is an object URL created once per
|
|
134
|
+
`Blob` instance (never revoked), so tile sources for the same `Blob` share
|
|
135
|
+
cached tiles. OpenSeadragon only passes strings and plain objects to
|
|
136
|
+
`supports`, so a `File` must be wrapped in an inline configuration
|
|
137
|
+
(`{ type: "ome-zarr", url: file }`) or passed to the constructor rather than
|
|
138
|
+
given to the viewer directly.
|
|
139
|
+
|
|
124
140
|
### Accessing OME-Zarr metadata
|
|
125
141
|
|
|
126
142
|
Directly instantiated tile sources start loading the OME-Zarr metadata
|
|
@@ -190,7 +206,8 @@ const tileSource2 = new OMEZarrTileSource(
|
|
|
190
206
|
```
|
|
191
207
|
|
|
192
208
|
`loadOMEZarr(url, zip?, { signal })` loads the metadata with ome-zarr.js and
|
|
193
|
-
opens the arrays of all resolution levels
|
|
209
|
+
opens the arrays of all resolution levels; `url` may also be a `Blob` holding a
|
|
210
|
+
zipped OME-Zarr file. An `OMEZarr` can also be assembled
|
|
194
211
|
from an `NgffImage` loaded by the app, as long as `arrays` lists the
|
|
195
212
|
opened arrays of `image.paths` in order. It is not checked against the URL of
|
|
196
213
|
the tile source it is passed to.
|
|
@@ -123,6 +123,7 @@ export declare interface OMEZarrTileData {
|
|
|
123
123
|
*/
|
|
124
124
|
export declare class OMEZarrTileSource extends default_2.TileSource {
|
|
125
125
|
readonly url: string;
|
|
126
|
+
readonly blob?: Blob;
|
|
126
127
|
readonly zip: boolean;
|
|
127
128
|
private readonly _t?;
|
|
128
129
|
private readonly _z?;
|
|
@@ -151,14 +152,16 @@ export declare class OMEZarrTileSource extends default_2.TileSource {
|
|
|
151
152
|
* metadata load across several tile sources for the same URL.
|
|
152
153
|
*
|
|
153
154
|
* @param url - URL of the OME-Zarr image or zipped OME-Zarr file, as a string
|
|
154
|
-
* or a `URL
|
|
155
|
+
* or a `URL` (relative URLs are resolved against the document base URL),
|
|
156
|
+
* or a `Blob` (e.g. a `File`) holding a zipped OME-Zarr file
|
|
155
157
|
* @param zip - Whether the URL points to a zipped OME-Zarr file; defaults to
|
|
156
|
-
* `true` for URLs whose path ends in `.ozx`
|
|
158
|
+
* `true` for URLs whose path ends in `.ozx` and for `Blob`s
|
|
157
159
|
* @param options - `signal` aborts the load
|
|
158
160
|
* @returns The loaded image and its arrays, highest resolution first
|
|
159
|
-
* @throws If the URL is relative and there is no document base URL
|
|
161
|
+
* @throws If the URL is relative and there is no document base URL, or if
|
|
162
|
+
* `zip` is `false` for a `Blob`
|
|
160
163
|
*/
|
|
161
|
-
static loadOMEZarr(url: string | URL, zip?: boolean, options?: {
|
|
164
|
+
static loadOMEZarr(url: string | URL | Blob, zip?: boolean, options?: {
|
|
162
165
|
signal?: AbortSignal;
|
|
163
166
|
}): Promise<OMEZarr>;
|
|
164
167
|
/**
|
|
@@ -167,13 +170,13 @@ export declare class OMEZarrTileSource extends default_2.TileSource {
|
|
|
167
170
|
* Equivalent to `new OMEZarrTileSource(config, loaded).whenReady()`, except
|
|
168
171
|
* that loading the metadata can be aborted with `signal`.
|
|
169
172
|
*
|
|
170
|
-
* @param config - URL or {@link OMEZarrTileSourceOptions}
|
|
173
|
+
* @param config - URL, `Blob` or {@link OMEZarrTileSourceOptions}
|
|
171
174
|
* @param loaded - Previously loaded image of the same URL to reuse instead of
|
|
172
175
|
* loading it
|
|
173
176
|
* @param options - `signal` aborts the load
|
|
174
177
|
* @returns The ready tile source; rejects if loading or validation fails
|
|
175
178
|
*/
|
|
176
|
-
static open(config: string | URL | OMEZarrTileSourceOptions, loaded?: OMEZarr, options?: {
|
|
179
|
+
static open(config: string | URL | Blob | OMEZarrTileSourceOptions, loaded?: OMEZarr, options?: {
|
|
177
180
|
signal?: AbortSignal;
|
|
178
181
|
}): Promise<OMEZarrTileSource>;
|
|
179
182
|
/**
|
|
@@ -200,13 +203,13 @@ export declare class OMEZarrTileSource extends default_2.TileSource {
|
|
|
200
203
|
* `loaded` is given), raising `ready` or `open-failed` asynchronously.
|
|
201
204
|
*
|
|
202
205
|
* @param url - URL of the OME-Zarr image, as a string or a `URL`, resolved
|
|
203
|
-
* against the document base URL
|
|
204
|
-
* path suffix
|
|
206
|
+
* against the document base URL (zipped files are detected by the `.ozx`
|
|
207
|
+
* path suffix), or a `Blob` (e.g. a `File`) holding a zipped OME-Zarr file
|
|
205
208
|
* @param loaded - Previously loaded image of the same URL to reuse instead of
|
|
206
209
|
* loading it
|
|
207
210
|
* @throws If the URL cannot be resolved
|
|
208
211
|
*/
|
|
209
|
-
constructor(url: string | URL, loaded?: OMEZarr);
|
|
212
|
+
constructor(url: string | URL | Blob, loaded?: OMEZarr);
|
|
210
213
|
/**
|
|
211
214
|
* Creates a tile source and starts loading the OME-Zarr metadata (unless
|
|
212
215
|
* `loaded` is given), raising `ready` or `open-failed` asynchronously.
|
|
@@ -214,7 +217,8 @@ export declare class OMEZarrTileSource extends default_2.TileSource {
|
|
|
214
217
|
* @param options - Tile source configuration
|
|
215
218
|
* @param loaded - Previously loaded image of the same URL to reuse instead of
|
|
216
219
|
* loading it
|
|
217
|
-
* @throws If the configuration is invalid
|
|
220
|
+
* @throws If the configuration is invalid (e.g. `zip: false` with a `Blob`)
|
|
221
|
+
* or the URL cannot be resolved */
|
|
218
222
|
constructor(options: OMEZarrTileSourceOptions, loaded?: OMEZarr);
|
|
219
223
|
/**
|
|
220
224
|
* The loaded OME-Zarr image and arrays.
|
|
@@ -261,8 +265,9 @@ export declare class OMEZarrTileSource extends default_2.TileSource {
|
|
|
261
265
|
/**
|
|
262
266
|
* The RGB colors of the rendered channels ({@link cs}): the configured
|
|
263
267
|
* `colors` (as an array, even if a single color was configured), otherwise
|
|
264
|
-
* the colors of the corresponding omero {@link channels}
|
|
265
|
-
* wherever those
|
|
268
|
+
* the colors of the corresponding omero {@link channels} (six-digit hex
|
|
269
|
+
* strings, with or without a leading `#`), and `undefined` wherever those
|
|
270
|
+
* are missing or malformed.
|
|
266
271
|
*
|
|
267
272
|
* Channels without a color (`undefined` entries, or `undefined` instead of
|
|
268
273
|
* the whole array) are rendered in white.
|
|
@@ -358,7 +363,8 @@ export declare class OMEZarrTileSource extends default_2.TileSource {
|
|
|
358
363
|
* Loads (or reuses) the OME-Zarr metadata, validates it against the
|
|
359
364
|
* configuration and raises `ready`, or raises `open-failed` on error.
|
|
360
365
|
*
|
|
361
|
-
* Called asynchronously by the OpenSeadragon `TileSource` constructor.
|
|
366
|
+
* Called asynchronously by the OpenSeadragon `TileSource` constructor. Loads
|
|
367
|
+
* from {@link blob} if configured, otherwise from the URL.
|
|
362
368
|
*/
|
|
363
369
|
getImageInfo(url: string): void;
|
|
364
370
|
/** Chunk width of a resolution level in pixels. */
|
|
@@ -375,7 +381,8 @@ export declare class OMEZarrTileSource extends default_2.TileSource {
|
|
|
375
381
|
*/
|
|
376
382
|
getTileUrl(level: number, x: number, y: number): string;
|
|
377
383
|
/**
|
|
378
|
-
* Cache key of a tile: the image URL
|
|
384
|
+
* Cache key of a tile: the image URL (the object URL of a configured
|
|
385
|
+
* {@link blob}) plus the resolved data parameters
|
|
379
386
|
* (`zip`, {@link t}, {@link z}, {@link cs}) and tile coordinates, and an
|
|
380
387
|
* FNV-1a hash of the rendering settings (the configured `ranges`, `colors`,
|
|
381
388
|
* `lutsOrColorMaps` and `inverteds`, and `autoBoost`), so that tile sources
|
|
@@ -438,16 +445,20 @@ export declare interface OMEZarrTileSourceOptions {
|
|
|
438
445
|
type?: "ome-zarr";
|
|
439
446
|
/**
|
|
440
447
|
* URL of the OME-Zarr image (group) or of a zipped OME-Zarr file, as a
|
|
441
|
-
* string or a `URL
|
|
448
|
+
* string or a `URL`, or a `Blob` (e.g. a `File`) holding a zipped OME-Zarr
|
|
449
|
+
* file.
|
|
442
450
|
*
|
|
443
|
-
* Relative URLs are resolved against the document base URL.
|
|
451
|
+
* Relative URLs are resolved against the document base URL. A `Blob` is read
|
|
452
|
+
* with `ZipFileStore.fromBlob` and must be zipped ({@link zip} must not be
|
|
453
|
+
* `false`).
|
|
444
454
|
*/
|
|
445
|
-
url: string | URL;
|
|
455
|
+
url: string | URL | Blob;
|
|
446
456
|
/**
|
|
447
457
|
* Whether the URL points to a zipped OME-Zarr file.
|
|
448
458
|
*
|
|
449
459
|
* Defaults to `true` for URLs whose path ends in `.ozx` (ignoring any query
|
|
450
|
-
* and fragment) and `false` otherwise.
|
|
460
|
+
* and fragment) and for `Blob`s, and `false` otherwise. Must not be `false`
|
|
461
|
+
* for a `Blob`.
|
|
451
462
|
*/
|
|
452
463
|
zip?: boolean;
|
|
453
464
|
/**
|
|
@@ -533,10 +544,14 @@ export declare interface OMEZarrTileSourceOptions {
|
|
|
533
544
|
/**
|
|
534
545
|
* Resolves a URL against the document base URL.
|
|
535
546
|
*
|
|
536
|
-
*
|
|
547
|
+
* A `Blob` (e.g. a `File`) resolves to an object URL (`blob:`), created once
|
|
548
|
+
* per `Blob` instance (and never revoked) so that tile sources for the same
|
|
549
|
+
* `Blob` share a URL.
|
|
550
|
+
*
|
|
551
|
+
* @param url - URL of the OME-Zarr image, as a string or a `URL`, or a `Blob`
|
|
537
552
|
* @returns The absolute URL
|
|
538
553
|
* @throws If the URL is relative and there is no document base URL
|
|
539
554
|
*/
|
|
540
|
-
export declare function resolveUrl(url: string | URL): URL;
|
|
555
|
+
export declare function resolveUrl(url: string | URL | Blob): URL;
|
|
541
556
|
|
|
542
557
|
export { }
|
|
@@ -3,12 +3,12 @@ import { NgffImage as t, getSlices as n, renderChunks as r } from "ome-zarr.js";
|
|
|
3
3
|
import i from "openseadragon";
|
|
4
4
|
import * as a from "zarrita";
|
|
5
5
|
//#region src/utils.ts
|
|
6
|
-
|
|
7
|
-
let t = 2166136261;
|
|
8
|
-
for (let n = 0; n < e.length; n++) t = Math.imul(t ^ e.charCodeAt(n), 16777619);
|
|
9
|
-
return t >>> 0;
|
|
10
|
-
}
|
|
6
|
+
var o = /* @__PURE__ */ new WeakMap();
|
|
11
7
|
function s(e) {
|
|
8
|
+
if (e instanceof Blob) {
|
|
9
|
+
let t = o.get(e);
|
|
10
|
+
return t === void 0 && (t = URL.createObjectURL(e), o.set(e, t)), new URL(t);
|
|
11
|
+
}
|
|
12
12
|
return new URL(e, globalThis.document?.baseURI);
|
|
13
13
|
}
|
|
14
14
|
function c(e) {
|
|
@@ -22,9 +22,15 @@ function l(e) {
|
|
|
22
22
|
let { data: t } = e;
|
|
23
23
|
return t instanceof Int8Array ? [-128, 127] : t instanceof Uint8Array ? [0, 255] : t instanceof Int16Array ? [-32768, 32767] : t instanceof Uint16Array ? [0, 65535] : t instanceof Int32Array ? [-2147483648, 2147483647] : t instanceof Uint32Array ? [0, 4294967295] : t instanceof BigInt64Array ? [-(2 ** 63), 2 ** 63 - 1] : t instanceof BigUint64Array ? [0, 2 ** 64 - 1] : [0, 1];
|
|
24
24
|
}
|
|
25
|
+
function u(e) {
|
|
26
|
+
let t = 2166136261;
|
|
27
|
+
for (let n = 0; n < e.length; n++) t = Math.imul(t ^ e.charCodeAt(n), 16777619);
|
|
28
|
+
return t >>> 0;
|
|
29
|
+
}
|
|
25
30
|
//#endregion
|
|
26
31
|
//#region src/OMEZarrTileSource.ts
|
|
27
|
-
var
|
|
32
|
+
var d = class o extends i.TileSource {
|
|
33
|
+
blob;
|
|
28
34
|
zip = !1;
|
|
29
35
|
_t;
|
|
30
36
|
_z;
|
|
@@ -38,23 +44,31 @@ var u = class u extends i.TileSource {
|
|
|
38
44
|
this.addOnceHandler("ready", () => e(this)), this.addOnceHandler("open-failed", (e) => t(Error(e.message)));
|
|
39
45
|
});
|
|
40
46
|
static {
|
|
41
|
-
|
|
47
|
+
o._learnConverters(i);
|
|
42
48
|
}
|
|
43
49
|
static enable(e = i) {
|
|
44
|
-
Object.assign(e, { OMEZarrTileSource:
|
|
50
|
+
Object.assign(e, { OMEZarrTileSource: o }), o._learnConverters(e);
|
|
45
51
|
}
|
|
46
52
|
static async loadOMEZarr(n, r, i) {
|
|
47
53
|
let { signal: a } = i ?? {};
|
|
48
|
-
a?.throwIfAborted()
|
|
49
|
-
let o
|
|
54
|
+
a?.throwIfAborted();
|
|
55
|
+
let o;
|
|
56
|
+
if (n instanceof Blob) {
|
|
57
|
+
if (r === !1) throw Error("only zipped OME-Zarr files can be loaded from a Blob");
|
|
58
|
+
o = e.fromBlob(n);
|
|
59
|
+
} else {
|
|
60
|
+
let t = s(n);
|
|
61
|
+
o = r ?? c(t) ? e.fromUrl(t) : n.toString();
|
|
62
|
+
}
|
|
63
|
+
let l = await t.load(o, { signal: a });
|
|
50
64
|
return {
|
|
51
|
-
image:
|
|
52
|
-
arrays: await Promise.all(
|
|
65
|
+
image: l,
|
|
66
|
+
arrays: await Promise.all(l.paths.map((e) => l.openArray(e, { signal: a })))
|
|
53
67
|
};
|
|
54
68
|
}
|
|
55
69
|
static async open(e, t, n) {
|
|
56
70
|
let { signal: r } = n ?? {};
|
|
57
|
-
return r?.throwIfAborted(), t ??= typeof e == "string" || e instanceof URL ? await
|
|
71
|
+
return r?.throwIfAborted(), t ??= typeof e == "string" || e instanceof URL || e instanceof Blob ? await o.loadOMEZarr(e, void 0, { signal: r }) : await o.loadOMEZarr(e.url, e.zip, { signal: r }), new o(e, t).whenReady();
|
|
58
72
|
}
|
|
59
73
|
static render(e) {
|
|
60
74
|
let { chunks: t, ranges: n, colors: i, lutsOrColorMaps: a, inverteds: o, autoBoost: s } = e, c = t[0].shape[1], l = t[0].shape[0], u = document.createElement("canvas");
|
|
@@ -65,19 +79,21 @@ var u = class u extends i.TileSource {
|
|
|
65
79
|
return d.putImageData(p, 0, 0), d;
|
|
66
80
|
}
|
|
67
81
|
constructor(e, t) {
|
|
68
|
-
let n = typeof e == "string" || e instanceof URL ? { url: e } : e, r = s(n.url)
|
|
82
|
+
let n = typeof e == "string" || e instanceof URL || e instanceof Blob ? { url: e } : e, r = s(n.url);
|
|
83
|
+
if (n.url instanceof Blob && n.zip === !1) throw Error("zip must not be false for a Blob (only zipped OME-Zarr files can be loaded from a Blob)");
|
|
84
|
+
let i;
|
|
69
85
|
if (n.c !== void 0) if (Array.isArray(n.c)) {
|
|
70
86
|
if (n.c.length === 0) throw Error("c array must be non-empty");
|
|
71
87
|
i = n.c;
|
|
72
88
|
} else i = [n.c];
|
|
73
|
-
let a =
|
|
74
|
-
super(r.toString()), this.url = r.toString(), this.zip = n.zip ?? c(r), this._t = n.t, this._z = n.z, this._c = i, this._renderSettings = {
|
|
89
|
+
let a = o._normalize(n, "range", (e) => Array.isArray(e) && e.length === 2 && e.every((e) => typeof e == "number"), i), l = o._normalize(n, "color", (e) => Array.isArray(e) && e.length === 3 && e.every((e) => typeof e == "number"), i), d = o._normalize(n, "lutOrColorMap", (e) => e instanceof Map || Array.isArray(e) && e.length > 0 && e.every((e) => Array.isArray(e) && (e.length === 3 || e.length === 4) && e.every((e) => typeof e == "number")), i), f = o._normalize(n, "inverted", (e) => typeof e == "boolean", i);
|
|
90
|
+
super(r.toString()), this.url = r.toString(), this.blob = n.url instanceof Blob ? n.url : void 0, this.zip = n.zip ?? (this.blob !== void 0 || c(r)), this._t = n.t, this._z = n.z, this._c = i, this._renderSettings = {
|
|
75
91
|
ranges: a,
|
|
76
92
|
colors: l,
|
|
77
93
|
lutsOrColorMaps: d,
|
|
78
94
|
inverteds: f,
|
|
79
95
|
autoBoost: n.autoBoost ?? !1
|
|
80
|
-
}, this._renderSettingsHash =
|
|
96
|
+
}, this._renderSettingsHash = u(JSON.stringify({
|
|
81
97
|
...this._renderSettings,
|
|
82
98
|
lutsOrColorMaps: d?.map((e) => e instanceof Map ? [...e].sort(([e], [t]) => e - t) : e)
|
|
83
99
|
})), this._loaded = t, this._readyPromise.catch(() => {});
|
|
@@ -102,27 +118,27 @@ var u = class u extends i.TileSource {
|
|
|
102
118
|
let e = this.channels, t = (e) => {
|
|
103
119
|
if (e?.window.start !== void 0 && e.window.end !== void 0) return [e.window.start, e.window.end];
|
|
104
120
|
};
|
|
105
|
-
return
|
|
121
|
+
return o._repeat(this._renderSettings.ranges, e)?.map((n, r) => n ?? t(e?.[r]));
|
|
106
122
|
}
|
|
107
123
|
get colors() {
|
|
108
124
|
let e = this.channels, t = (e) => {
|
|
109
125
|
if (e === void 0) return;
|
|
110
|
-
let t = e.color
|
|
111
|
-
return [
|
|
126
|
+
let t = /^#?([0-9A-Fa-f]{6})$/.exec(e.color)?.[1];
|
|
127
|
+
if (t !== void 0) return [
|
|
112
128
|
parseInt(t.slice(0, 2), 16),
|
|
113
129
|
parseInt(t.slice(2, 4), 16),
|
|
114
130
|
parseInt(t.slice(4, 6), 16)
|
|
115
131
|
];
|
|
116
132
|
};
|
|
117
|
-
return
|
|
133
|
+
return o._repeat(this._renderSettings.colors, e)?.map((n, r) => n ?? t(e?.[r]));
|
|
118
134
|
}
|
|
119
135
|
get lutsOrColorMaps() {
|
|
120
136
|
let e = this.channels, t = (e) => e?.lut ?? e?.colorMap;
|
|
121
|
-
return
|
|
137
|
+
return o._repeat(this._renderSettings.lutsOrColorMaps, e)?.map((n, r) => n ?? t(e?.[r]));
|
|
122
138
|
}
|
|
123
139
|
get inverteds() {
|
|
124
140
|
let e = this.channels;
|
|
125
|
-
return
|
|
141
|
+
return o._repeat(this._renderSettings.inverteds, e)?.map((t, n) => t ?? e?.[n]?.inverted);
|
|
126
142
|
}
|
|
127
143
|
get autoBoost() {
|
|
128
144
|
return this._renderSettings.autoBoost;
|
|
@@ -132,11 +148,11 @@ var u = class u extends i.TileSource {
|
|
|
132
148
|
}
|
|
133
149
|
getWidth(e = this.maxLevel) {
|
|
134
150
|
if (e < 0 || e > this.maxLevel) throw Error("level out of bounds");
|
|
135
|
-
return
|
|
151
|
+
return o._getAxisSize(this.loaded, "x", this.maxLevel - e);
|
|
136
152
|
}
|
|
137
153
|
getHeight(e = this.maxLevel) {
|
|
138
154
|
if (e < 0 || e > this.maxLevel) throw Error("level out of bounds");
|
|
139
|
-
return
|
|
155
|
+
return o._getAxisSize(this.loaded, "y", this.maxLevel - e);
|
|
140
156
|
}
|
|
141
157
|
loadChunks(e, t, r) {
|
|
142
158
|
let i = {
|
|
@@ -149,8 +165,8 @@ var u = class u extends i.TileSource {
|
|
|
149
165
|
let a = this.getTileWidth(e), o = this.getTileHeight(e);
|
|
150
166
|
i.x = [t.x * a, (t.x + 1) * a], i.y = [t.y * o, (t.y + 1) * o];
|
|
151
167
|
}
|
|
152
|
-
let
|
|
153
|
-
return Promise.all(
|
|
168
|
+
let s = o._getAxisSize(this.loaded, "c"), c = n(this.cs ?? Array.from({ length: s }, (e, t) => t), this.loaded.arrays[this.maxLevel - e].shape, this.loaded.image.getAxesNames(), i);
|
|
169
|
+
return Promise.all(c.map((t) => a.get(this.loaded.arrays[this.maxLevel - e], t, r)));
|
|
154
170
|
}
|
|
155
171
|
supports(e) {
|
|
156
172
|
return Array.isArray(e) || e instanceof Document ? !1 : typeof e == "string" ? c(e) : "type" in e && e.type === "ome-zarr";
|
|
@@ -168,10 +184,10 @@ var u = class u extends i.TileSource {
|
|
|
168
184
|
};
|
|
169
185
|
}
|
|
170
186
|
equals(e) {
|
|
171
|
-
return e instanceof
|
|
187
|
+
return e instanceof o && this.url === e.url && this.zip === e.zip && this.t === e.t && this.z === e.z && this.cs?.join(",") === e.cs?.join(",") && this._renderSettingsHash === e._renderSettingsHash;
|
|
172
188
|
}
|
|
173
189
|
getImageInfo(e) {
|
|
174
|
-
Promise.resolve(this._loaded ??
|
|
190
|
+
Promise.resolve(this._loaded ?? o.loadOMEZarr(this.blob ?? e, this.zip)).then((e) => {
|
|
175
191
|
let t = e.image.getAxesNames();
|
|
176
192
|
for (let e of t) if (![
|
|
177
193
|
"t",
|
|
@@ -182,11 +198,11 @@ var u = class u extends i.TileSource {
|
|
|
182
198
|
].includes(e)) throw Error(`unsupported axis: ${e}`);
|
|
183
199
|
if (!t.includes("x") || !t.includes("y")) throw Error("missing X or Y axis");
|
|
184
200
|
if (t.indexOf("y") > t.indexOf("x")) throw Error("X axis must come after Y axis");
|
|
185
|
-
let n =
|
|
201
|
+
let n = o._getAxisSize(e, "t");
|
|
186
202
|
if (this._t !== void 0 && (this._t < 0 || this._t >= n)) throw Error(`Invalid t index ${this._t} for image with ${n} timepoints`);
|
|
187
|
-
let r =
|
|
203
|
+
let r = o._getAxisSize(e, "z");
|
|
188
204
|
if (this._z !== void 0 && (this._z < 0 || this._z >= r)) throw Error(`Invalid z index ${this._z} for image with ${r} z-slices`);
|
|
189
|
-
let i =
|
|
205
|
+
let i = o._getAxisSize(e, "c");
|
|
190
206
|
if (this._c !== void 0 && this._c.some((e) => e < 0 || e >= i)) throw Error(`Invalid c indices [${this._c?.join(", ")}] for image with ${i} channels`);
|
|
191
207
|
if (e.image.omero !== void 0 && e.image.omero.channels !== void 0 && e.image.omero.channels.length !== i) throw Error(`OME-Zarr metadata lists ${e.image.omero.channels.length} channels, but the image has ${i}`);
|
|
192
208
|
if (this._c === void 0 && e.image.omero !== void 0 && e.image.omero.channels !== void 0 && !e.image.omero.channels.some((e) => e.active !== !1)) throw Error("No active channels; specify c or activate channels in the OME-Zarr metadata");
|
|
@@ -278,7 +294,7 @@ var u = class u extends i.TileSource {
|
|
|
278
294
|
return e === void 0 ? t?.map(() => void 0) : e.length === 1 && t !== void 0 ? t.map(() => e[0]) : e;
|
|
279
295
|
}
|
|
280
296
|
static _learnConverters(e) {
|
|
281
|
-
e.converter.existsType("ome-zarr") || (e.converter.learn("ome-zarr", "context2d", (e, t) =>
|
|
297
|
+
e.converter.existsType("ome-zarr") || (e.converter.learn("ome-zarr", "context2d", (e, t) => o.render(t), 1, 1), e.converter.learn("ome-zarr", "ome-zarr", (e, t) => ({
|
|
282
298
|
...t,
|
|
283
299
|
chunks: t.chunks.map((e) => ({
|
|
284
300
|
...e,
|
|
@@ -293,6 +309,6 @@ var u = class u extends i.TileSource {
|
|
|
293
309
|
};
|
|
294
310
|
//#endregion
|
|
295
311
|
//#region src/main.ts
|
|
296
|
-
globalThis.OpenSeadragon &&
|
|
312
|
+
globalThis.OpenSeadragon && d.enable(globalThis.OpenSeadragon);
|
|
297
313
|
//#endregion
|
|
298
|
-
export {
|
|
314
|
+
export { d as OMEZarrTileSource, u as fnv1a, l as getDataTypeRange, c as isOZX, s as resolveUrl };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "omezarr-tilesource",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.0",
|
|
4
4
|
"description": "An OpenSeadragon tile source for the OME-Zarr bioimage file format",
|
|
5
5
|
"homepage": "https://github.com/TissUUmaps/OMEZarrTileSource#readme",
|
|
6
6
|
"bugs": "https://github.com/TissUUmaps/OMEZarrTileSource/issues",
|