@fideus-labs/fiff 0.1.2 → 0.3.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 CHANGED
@@ -11,11 +11,13 @@
11
11
  </p>
12
12
 
13
13
  <p align="center">
14
- Present <a href="https://docs.openmicroscopy.org/ome-model/latest/ome-tiff/">TIFF</a> and <a href="https://docs.openmicroscopy.org/ome-model/latest/ome-tiff/">OME-TIFF</a> files as a <a href="https://github.com/manzt/zarrita.js">zarrita.js</a> Zarr store following the <a href="https://ngff.openmicroscopy.org/0.5/">OME-Zarr v0.5</a> data model.
14
+ Read and write <a href="https://docs.openmicroscopy.org/ome-model/latest/ome-tiff/">OME-TIFF</a> files through a <a href="https://github.com/manzt/zarrita.js">zarrita.js</a> Zarr store following the <a href="https://ngff.openmicroscopy.org/0.5/">OME-Zarr v0.5</a> data model.
15
15
  </p>
16
16
 
17
17
  ## ✨ Features
18
18
 
19
+ ### Reading
20
+
19
21
  - 🚀 **Lazy HTTP range requests** -- Chunk data is fetched on demand via
20
22
  geotiff.js `readRasters()`, no full file download needed
21
23
  - 📐 **OME-XML support** -- Parses OME-XML metadata for dimensions, channels,
@@ -29,51 +31,201 @@
29
31
  - 📋 **OME-Zarr v0.5 output** -- Generates Zarr v3 metadata with
30
32
  `ome.multiscales` and `ome.omero` attributes
31
33
 
34
+ ### Writing
35
+
36
+ - 📝 **OME-TIFF generation** -- Convert ngff-zarr `Multiscales` objects to
37
+ valid OME-TIFF files with embedded OME-XML metadata
38
+ - 🔻 **Full pyramid support** -- Multi-resolution levels are written as SubIFDs,
39
+ matching the modern OME-TIFF pyramid convention
40
+ - 🗜️ **Deflate compression** -- Async zlib/deflate via native `CompressionStream`
41
+ (non-blocking) with synchronous pako fallback
42
+ - 🧱 **Tiled output** -- Large images are automatically written as 256x256 tiles
43
+ (configurable), the OME-TIFF recommended format for efficient random access
44
+ - ⚡ **Parallel plane reading** -- Planes are read with bounded concurrency
45
+ (configurable) for faster writes from async data sources
46
+ - 💾 **BigTIFF support** -- Automatic 64-bit offset format when files exceed
47
+ 4 GB, with manual override via `format` option
48
+ - 📐 **5D support** -- Handles all dimension orders (XYZCT, XYZTC, etc.) and
49
+ arbitrary combinations of T, C, Z, Y, X axes
50
+
32
51
  ## 📦 Installation
33
52
 
34
53
  ```bash
35
54
  npm install @fideus-labs/fiff
36
55
  ```
37
56
 
38
- ## Quick Start
57
+ For write support, also install the optional peer dependency:
58
+
59
+ ```bash
60
+ npm install @fideus-labs/ngff-zarr
61
+ ```
62
+
63
+ ## ⚡ Usage
64
+
65
+ ### Reading: Open an OME-TIFF as a Zarr store
39
66
 
40
- ### From a remote URL
67
+ #### From a remote URL
41
68
 
42
69
  ```typescript
43
- import { TiffStore } from "@fideus-labs/fiff"
44
- import * as zarr from "zarrita"
70
+ import { TiffStore } from "@fideus-labs/fiff";
71
+ import * as zarr from "zarrita";
72
+
73
+ const store = await TiffStore.fromUrl("https://example.com/image.ome.tif");
74
+ const group = await zarr.open(store as unknown as zarr.Readable, { kind: "group" });
75
+
76
+ // Open the full-resolution array (level 0)
77
+ const arr = await zarr.open(group.resolve("0"), { kind: "array" });
78
+ const chunk = await zarr.get(arr);
79
+
80
+ console.log(chunk.shape); // e.g. [1, 3, 1, 512, 512]
81
+ console.log(chunk.data); // Float32Array, Uint16Array, etc.
82
+ ```
83
+
84
+ #### From an ArrayBuffer
45
85
 
46
- const store = await TiffStore.fromUrl("https://example.com/image.ome.tif")
47
- const group = await zarr.open(store as unknown as zarr.Readable, { kind: "group" })
48
- const arr = await zarr.open(group.resolve("0"), { kind: "array" })
49
- const chunk = await zarr.get(arr)
86
+ ```typescript
87
+ const response = await fetch("https://example.com/image.tif");
88
+ const buffer = await response.arrayBuffer();
89
+ const store = await TiffStore.fromArrayBuffer(buffer);
50
90
  ```
51
91
 
52
- ### From an ArrayBuffer
92
+ #### From a File / Blob
53
93
 
54
94
  ```typescript
55
- const response = await fetch("https://example.com/image.tif")
56
- const buffer = await response.arrayBuffer()
57
- const store = await TiffStore.fromArrayBuffer(buffer)
95
+ const file = document.querySelector("input[type=file]").files[0];
96
+ const store = await TiffStore.fromBlob(file);
58
97
  ```
59
98
 
60
- ### From a File / Blob
99
+ #### From an existing GeoTIFF instance
61
100
 
62
101
  ```typescript
63
- const file = document.querySelector("input[type=file]").files[0]
64
- const store = await TiffStore.fromBlob(file)
102
+ import { fromUrl } from "geotiff";
103
+
104
+ const tiff = await fromUrl("https://example.com/image.tif");
105
+ const store = await TiffStore.fromGeoTIFF(tiff);
65
106
  ```
66
107
 
67
- ### From an existing GeoTIFF instance
108
+ #### Accessing store metadata
68
109
 
69
110
  ```typescript
70
- import { fromUrl } from "geotiff"
111
+ const store = await TiffStore.fromUrl("https://example.com/image.ome.tif");
112
+
113
+ store.levels; // number of resolution levels
114
+ store.dataType; // "uint16", "float32", etc.
115
+ store.dimensionNames; // ["t", "c", "z", "y", "x"]
116
+ store.getShape(0); // full-res shape, e.g. [1, 3, 1, 2048, 2048]
117
+ store.getShape(1); // level 1 shape, e.g. [1, 3, 1, 1024, 1024]
118
+ store.ome; // parsed OME-XML image metadata (if present)
119
+ store.pyramidInfo; // pyramid structure details
120
+ ```
71
121
 
72
- const tiff = await fromUrl("https://example.com/image.tif")
73
- const store = await TiffStore.fromGeoTIFF(tiff)
122
+ ### Writing: Convert ngff-zarr Multiscales to OME-TIFF
123
+
124
+ `toOmeTiff()` takes an ngff-zarr `Multiscales` object and returns a complete
125
+ OME-TIFF file as an `ArrayBuffer`.
126
+
127
+ #### Basic write
128
+
129
+ ```typescript
130
+ import { toOmeTiff } from "@fideus-labs/fiff";
131
+ import {
132
+ createNgffImage,
133
+ createAxis,
134
+ createDataset,
135
+ createMetadata,
136
+ createMultiscales,
137
+ } from "@fideus-labs/ngff-zarr";
138
+ import * as zarr from "zarrita";
139
+
140
+ // 1. Create an ngff-zarr image
141
+ const image = await createNgffImage(
142
+ [], // no parent images
143
+ [512, 512], // shape: [y, x]
144
+ "uint16", // data type
145
+ ["y", "x"], // dimension names
146
+ { y: 0.5, x: 0.5 }, // pixel spacing (micrometers)
147
+ { y: 0.0, x: 0.0 }, // origin offsets
148
+ "my-image",
149
+ );
150
+
151
+ // 2. Populate pixel data
152
+ const data = new Uint16Array(512 * 512);
153
+ for (let i = 0; i < data.length; i++) data[i] = i % 65536;
154
+ await zarr.set(image.data, null, {
155
+ data,
156
+ shape: [512, 512],
157
+ stride: [512, 1],
158
+ });
159
+
160
+ // 3. Build the Multiscales object
161
+ const axes = [
162
+ createAxis("y", "space", "micrometer"),
163
+ createAxis("x", "space", "micrometer"),
164
+ ];
165
+ const datasets = [createDataset("0", [0.5, 0.5], [0.0, 0.0])];
166
+ const metadata = createMetadata(axes, datasets, "my-image");
167
+ const multiscales = createMultiscales([image], metadata);
168
+
169
+ // 4. Write to OME-TIFF
170
+ const buffer = await toOmeTiff(multiscales);
171
+
172
+ // Save to disk (Node.js / Bun)
173
+ await Bun.write("output.ome.tif", buffer);
74
174
  ```
75
175
 
76
- ## 🏭 Factory Methods
176
+ #### Write options
177
+
178
+ ```typescript
179
+ const buffer = await toOmeTiff(multiscales, {
180
+ compression: "deflate", // "deflate" (default) or "none"
181
+ compressionLevel: 6, // 1-9, default 6 (only for deflate)
182
+ dimensionOrder: "XYZCT", // IFD layout order, default "XYZCT"
183
+ imageName: "my-image", // name in OME-XML metadata
184
+ creator: "my-app", // creator string in OME-XML
185
+ tileSize: 256, // tile size in px (0 = strip-based), default 256
186
+ concurrency: 4, // parallel plane reads, default 4
187
+ format: "auto", // "auto" | "classic" | "bigtiff", default "auto"
188
+ });
189
+ ```
190
+
191
+ #### Multi-resolution pyramids
192
+
193
+ When the `Multiscales` object contains multiple images (resolution levels),
194
+ all sub-resolution levels are written as SubIFDs:
195
+
196
+ ```typescript
197
+ const fullRes = await createNgffImage([], [1024, 1024], "uint16", ["y", "x"], ...);
198
+ const halfRes = await createNgffImage([], [512, 512], "uint16", ["y", "x"], ...);
199
+ // ... populate both images with zarr.set() ...
200
+
201
+ const datasets = [
202
+ createDataset("0", [0.5, 0.5], [0.0, 0.0]),
203
+ createDataset("1", [1.0, 1.0], [0.0, 0.0]),
204
+ ];
205
+ const metadata = createMetadata(axes, datasets, "pyramid");
206
+ const multiscales = createMultiscales([fullRes, halfRes], metadata);
207
+
208
+ const buffer = await toOmeTiff(multiscales);
209
+ // Result: OME-TIFF with full-res IFDs + half-res SubIFDs
210
+ ```
211
+
212
+ #### Round-trip: write then read back
213
+
214
+ ```typescript
215
+ import { toOmeTiff, TiffStore } from "@fideus-labs/fiff";
216
+ import * as zarr from "zarrita";
217
+
218
+ const buffer = await toOmeTiff(multiscales);
219
+ const store = await TiffStore.fromArrayBuffer(buffer);
220
+ const group = await zarr.open(store as unknown as zarr.Readable, { kind: "group" });
221
+ const arr = await zarr.open(group.resolve("0"), { kind: "array" });
222
+ const result = await zarr.get(arr);
223
+ // result.data contains the original pixel values
224
+ ```
225
+
226
+ ## 🏭 Read API
227
+
228
+ ### Factory Methods
77
229
 
78
230
  | Method | Description |
79
231
  | --------------------------------- | ---------------------------------------------- |
@@ -82,7 +234,7 @@ const store = await TiffStore.fromGeoTIFF(tiff)
82
234
  | `TiffStore.fromBlob(blob)` | Open from a Blob or File |
83
235
  | `TiffStore.fromGeoTIFF(tiff)` | Open from an already-opened GeoTIFF instance |
84
236
 
85
- ## ⚙️ Options
237
+ ### Options
86
238
 
87
239
  All factory methods accept an optional `TiffStoreOptions` object:
88
240
 
@@ -91,7 +243,7 @@ All factory methods accept an optional `TiffStoreOptions` object:
91
243
  | `offsets` | `number[]` | `undefined` | Pre-computed IFD byte offsets for O(1) access |
92
244
  | `headers` | `Record<string, string>` | `undefined` | Additional HTTP headers for remote TIFF requests |
93
245
 
94
- ## 📖 Public Accessors
246
+ ### Public Accessors
95
247
 
96
248
  | Accessor | Type | Description |
97
249
  | --------------------- | -------------- | ---------------------------------- |
@@ -103,6 +255,30 @@ All factory methods accept an optional `TiffStoreOptions` object:
103
255
  | `store.getShape(l)` | `number[]` | Shape for resolution level `l` |
104
256
  | `store.getChunkShape(l)` | `number[]` | Chunk shape for resolution level `l` |
105
257
 
258
+ ## 📝 Write API
259
+
260
+ ### `toOmeTiff(multiscales, options?)`
261
+
262
+ | Parameter | Type | Description |
263
+ | ------------- | ------------- | ------------------------------------------------------ |
264
+ | `multiscales` | `Multiscales` | ngff-zarr Multiscales object with populated pixel data |
265
+ | `options` | `WriteOptions`| Optional writer configuration |
266
+
267
+ **Returns:** `Promise<ArrayBuffer>` -- a complete OME-TIFF file.
268
+
269
+ ### WriteOptions
270
+
271
+ | Option | Type | Default | Description |
272
+ | ------------------ | -------------------------------------- | ----------- | ----------------------------------------- |
273
+ | `compression` | `"none" \| "deflate"` | `"deflate"` | Pixel data compression |
274
+ | `compressionLevel` | `number` | `6` | Deflate level 1-9 (higher = smaller) |
275
+ | `dimensionOrder` | `string` | `"XYZCT"` | IFD plane layout order |
276
+ | `imageName` | `string` | `"image"` | Image name in OME-XML |
277
+ | `creator` | `string` | `"fiff"` | Creator string in OME-XML |
278
+ | `tileSize` | `number` | `256` | Tile size (0 = strip-based, must be x16) |
279
+ | `concurrency` | `number` | `4` | Max parallel plane reads |
280
+ | `format` | `"auto" \| "classic" \| "bigtiff"` | `"auto"` | TIFF format (auto-detects BigTIFF > 4 GB) |
281
+
106
282
  ## 🛠️ Development
107
283
 
108
284
  ### 📋 Prerequisites
@@ -127,11 +303,14 @@ src/
127
303
  ome-xml.ts # OME-XML parser (dimensions, channels, DimensionOrder)
128
304
  ifd-indexer.ts # IFD-to-pyramid-level mapping (SubIFD/legacy/COG)
129
305
  chunk-reader.ts # Pixel data reading via geotiff.js readRasters
130
- dtypes.ts # TIFF SampleFormat -> Zarr data_type mapping
306
+ dtypes.ts # TIFF Zarr data_type mapping
131
307
  utils.ts # Key parsing, pixel window computation, encoding
308
+ write.ts # High-level toOmeTiff() writer
309
+ tiff-writer.ts # Low-level TIFF binary builder (IFDs, SubIFDs, deflate)
310
+ ome-xml-writer.ts # OME-XML generation from Multiscales metadata
132
311
  test/
133
312
  fixtures.ts # Test TIFF generation helpers
134
- *.test.ts # 120 tests across 8 files
313
+ *.test.ts # 201 tests across 11 files
135
314
  ```
136
315
 
137
316
  ### 📝 Commands
package/dist/dtypes.d.ts CHANGED
@@ -33,6 +33,21 @@ export declare function tiffDtypeToZarr(sampleFormat: number, bitsPerSample: num
33
33
  export declare function omePixelTypeToZarr(omeType: string): ZarrDataType;
34
34
  /** Number of bytes per element for a given Zarr data_type. */
35
35
  export declare function bytesPerElement(dtype: ZarrDataType): number;
36
+ /**
37
+ * Map a Zarr v3 data_type string to an OME-XML pixel Type string.
38
+ * Reverse of omePixelTypeToZarr.
39
+ */
40
+ export declare function zarrToOmePixelType(dtype: ZarrDataType): string;
41
+ /** TIFF tag values for a given Zarr data_type. */
42
+ export interface TiffDtypeInfo {
43
+ sampleFormat: number;
44
+ bitsPerSample: number;
45
+ }
46
+ /**
47
+ * Map a Zarr v3 data_type string to TIFF SampleFormat + BitsPerSample.
48
+ * Reverse of tiffDtypeToZarr.
49
+ */
50
+ export declare function zarrToTiffDtype(dtype: ZarrDataType): TiffDtypeInfo;
36
51
  /**
37
52
  * Get the appropriate TypedArray constructor for a Zarr data_type.
38
53
  */
@@ -1 +1 @@
1
- {"version":3,"file":"dtypes.d.ts","sourceRoot":"","sources":["../src/dtypes.ts"],"names":[],"mappings":"AAGA;;;;;;;;;;GAUG;AAEH,yCAAyC;AACzC,MAAM,MAAM,YAAY,GACpB,MAAM,GACN,OAAO,GACP,OAAO,GACP,OAAO,GACP,QAAQ,GACR,QAAQ,GACR,SAAS,GACT,SAAS,CAAC;AAEd,oCAAoC;AACpC,eAAO,MAAM,kBAAkB,IAAI,CAAC;AACpC,eAAO,MAAM,iBAAiB,IAAI,CAAC;AACnC,eAAO,MAAM,mBAAmB,IAAI,CAAC;AAErC;;;;;;;;GAQG;AACH,wBAAgB,eAAe,CAC7B,YAAY,EAAE,MAAM,EACpB,a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;IACrB,aAAa,EAAE,MAAM,CAAC;CACvB;AAED;;;GAGG;AACH,wBAAgB,eAAe,CAAC,KAAK,EAAE,YAAY,GAAG,aAAa,CAYlE;AAED;;GAEG;AACH,wBAAgB,wBAAwB,CACtC,KAAK,EAAE,YAAY,GAClB;IACD,KAAK,MAAM,EAAE,WAAW,EAAE,UAAU,CAAC,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,GAC1D,UAAU,GACV,SAAS,GACT,WAAW,GACX,UAAU,GACV,WAAW,GACX,UAAU,GACV,YAAY,GACZ,YAAY,CAAC;CAClB,CAmBA"}
package/dist/dtypes.js CHANGED
@@ -87,6 +87,40 @@ export function bytesPerElement(dtype) {
87
87
  };
88
88
  return map[dtype];
89
89
  }
90
+ /**
91
+ * Map a Zarr v3 data_type string to an OME-XML pixel Type string.
92
+ * Reverse of omePixelTypeToZarr.
93
+ */
94
+ export function zarrToOmePixelType(dtype) {
95
+ const map = {
96
+ int8: "int8",
97
+ int16: "int16",
98
+ int32: "int32",
99
+ uint8: "uint8",
100
+ uint16: "uint16",
101
+ uint32: "uint32",
102
+ float32: "float",
103
+ float64: "double",
104
+ };
105
+ return map[dtype];
106
+ }
107
+ /**
108
+ * Map a Zarr v3 data_type string to TIFF SampleFormat + BitsPerSample.
109
+ * Reverse of tiffDtypeToZarr.
110
+ */
111
+ export function zarrToTiffDtype(dtype) {
112
+ const map = {
113
+ uint8: { sampleFormat: SAMPLE_FORMAT_UINT, bitsPerSample: 8 },
114
+ uint16: { sampleFormat: SAMPLE_FORMAT_UINT, bitsPerSample: 16 },
115
+ uint32: { sampleFormat: SAMPLE_FORMAT_UINT, bitsPerSample: 32 },
116
+ int8: { sampleFormat: SAMPLE_FORMAT_INT, bitsPerSample: 8 },
117
+ int16: { sampleFormat: SAMPLE_FORMAT_INT, bitsPerSample: 16 },
118
+ int32: { sampleFormat: SAMPLE_FORMAT_INT, bitsPerSample: 32 },
119
+ float32: { sampleFormat: SAMPLE_FORMAT_FLOAT, bitsPerSample: 32 },
120
+ float64: { sampleFormat: SAMPLE_FORMAT_FLOAT, bitsPerSample: 64 },
121
+ };
122
+ return map[dtype];
123
+ }
90
124
  /**
91
125
  * Get the appropriate TypedArray constructor for a Zarr data_type.
92
126
  */
@@ -1 +1 @@
1
- {"version":3,"file":"dtypes.js","sourceRoot":"","sources":["../src/dtypes.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,+BAA+B;AAyB/B,oCAAoC;AACpC,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAAC,CAAC;AACpC,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAAC,CAAC;AACnC,MAAM,CAAC,MAAM,mBAAmB,GAAG,CAAC,CAAC;AAErC;;;;;;;;GAQG;AACH,MAAM,UAAU,eAAe,CAC7B,YAAoB,EACpB,aAAqB;IAErB,IAAI,YAAY,KAAK,kBAAkB,EAAE,CAAC;QACxC,QAAQ,aAAa,EAAE,CAAC;YACtB,KAAK,CAAC;gBACJ,OAAO,OAAO,CAAC;YACjB,KAAK,EAAE;gBACL,OAAO,QAAQ,CAAC;YAClB,KAAK,EAAE;gBACL,OAAO,QAAQ,CAAC;YAClB;gBACE,MAAM,IAAI,KAAK,CACb,2CAA2C,aAAa,EAAE,CAC3D,CAAC;QACN,CAAC;IACH,CAAC;SAAM,IAAI,YAAY,KAAK,iBAAiB,EAAE,CAAC;QAC9C,QAAQ,aAAa,EAAE,CAAC;YACtB,KAAK,CAAC;gBACJ,OAAO,MAAM,CAAC;YAChB,KAAK,EAAE;gBACL,OAAO,OAAO,CAAC;YACjB,KAAK,EAAE;gBACL,OAAO,OAAO,CAAC;YACjB;gBACE,MAAM,IAAI,KAAK,CACb,yCAAyC,aAAa,EAAE,CACzD,CAAC;QACN,CAAC;IACH,CAAC;SAAM,IAAI,YAAY,KAAK,mBAAmB,EAAE,CAAC;QAChD,QAAQ,aAAa,EAAE,CAAC;YACtB,KAAK,EAAE;gBACL,OAAO,SAAS,CAAC;YACnB,KAAK,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QACpB,KAAK,QAAQ;YACX,OAAO,WAAW,CAAC;QACrB,KAAK,OAAO;YACV,OAAO,UAAU,CAAC;QACpB,KAAK,SAAS;YACZ,OAAO,YAAY,CAAC;QACtB,KAAK,SAAS;YACZ,OAAO,YAAY,CAAC;IACxB,CAAC;AACH,CAAC"}
package/dist/index.d.ts CHANGED
@@ -20,7 +20,10 @@ export type { ZarrDataType } from "./dtypes.js";
20
20
  export type { OmeImage, OmePixels, OmeChannel, DimensionOrder } from "./ome-xml.js";
21
21
  export type { PyramidInfo, PlaneSelection } from "./ifd-indexer.js";
22
22
  export type { OmeAxis, OmeMultiscale, OmeDataset, OmeCoordinateTransformation, OmeroMetadata, OmeroChannel, ZarrGroupMetadata, ZarrArrayMetadata, } from "./metadata.js";
23
+ export { toOmeTiff, type WriteOptions } from "./write.js";
24
+ export { buildOmeXml, type OmeXmlWriterOptions, type DimensionInfo } from "./ome-xml-writer.js";
25
+ export { buildTiff, makeImageTags, sliceTiles, compressDeflate, compressDeflateAsync, DEFAULT_TILE_SIZE, type WritableIfd, type TiffTag, type BuildTiffOptions, } from "./tiff-writer.js";
23
26
  export { parseOmeXml, isOmeXml, getIfdIndex } from "./ome-xml.js";
24
- export { tiffDtypeToZarr, omePixelTypeToZarr, bytesPerElement } from "./dtypes.js";
27
+ export { tiffDtypeToZarr, omePixelTypeToZarr, zarrToOmePixelType, zarrToTiffDtype, bytesPerElement, type TiffDtypeInfo, } from "./dtypes.js";
25
28
  export { parseStoreKey, computePixelWindow } from "./utils.js";
26
29
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAGA;;;;;;;;;;;;;;;;GAgBG;AAEH,OAAO,EAAE,SAAS,EAAE,KAAK,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AAGnE,YAAY,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAChD,YAAY,EAAE,QAAQ,EAAE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AAK,OAAO,EACZ,KAAK,gBAAgB,GACtB,MAAM,kBAAkB,CAAC;AAG1B,OAAO,EAAE,WAAW,EAAE,QAAQ,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAClE,OAAO,EACL,eAAe,EACf,kBAAkB,EAClB,kBAAkB,EAClB,eAAe,EACf,eAAe,EACf,KAAK,aAAa,GACnB,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,aAAa,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAC"}
package/dist/index.js CHANGED
@@ -18,8 +18,12 @@
18
18
  * ```
19
19
  */
20
20
  export { TiffStore } from "./tiff-store.js";
21
+ // Writer
22
+ export { toOmeTiff } from "./write.js";
23
+ export { buildOmeXml } from "./ome-xml-writer.js";
24
+ export { buildTiff, makeImageTags, sliceTiles, compressDeflate, compressDeflateAsync, DEFAULT_TILE_SIZE, } from "./tiff-writer.js";
21
25
  // Export utilities that may be useful
22
26
  export { parseOmeXml, isOmeXml, getIfdIndex } from "./ome-xml.js";
23
- export { tiffDtypeToZarr, omePixelTypeToZarr, bytesPerElement } from "./dtypes.js";
27
+ export { tiffDtypeToZarr, omePixelTypeToZarr, zarrToOmePixelType, zarrToTiffDtype, bytesPerElement, } from "./dtypes.js";
24
28
  export { parseStoreKey, computePixelWindow } from "./utils.js";
25
29
  //# sourceMappingURL=index.js.map
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;AAE/B;;;;;;;;;;;;;;;;GAgBG;AAEH,OAAO,EAAE,SAAS,EAAyB,MAAM,iBAAiB,CAAC;AAiBnE,sCAAsC;AACtC,OAAO,EAAE,WAAW,EAAE,QAAQ,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAClE,OAAO,EAAE,eAAe,EAAE,kBAAkB,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AACnF,OAAO,EAAE,aAAa,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,+BAA+B;AAE/B;;;;;;;;;;;;;;;;GAgBG;AAEH,OAAO,EAAE,SAAS,EAAyB,MAAM,iBAAiB,CAAC;AAiBnE,SAAS;AACT,OAAO,EAAE,SAAS,EAAqB,MAAM,YAAY,CAAC;AAC1D,OAAO,EAAE,WAAW,EAAgD,MAAM,qBAAqB,CAAC;AAChG,OAAO,EACL,SAAS,EACT,aAAa,EACb,UAAU,EACV,eAAe,EACf,oBAAoB,EACpB,iBAAiB,GAIlB,MAAM,kBAAkB,CAAC;AAE1B,sCAAsC;AACtC,OAAO,EAAE,WAAW,EAAE,QAAQ,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAClE,OAAO,EACL,eAAe,EACf,kBAAkB,EAClB,kBAAkB,EAClB,eAAe,EACf,eAAe,GAEhB,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,aAAa,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAC"}
@@ -0,0 +1,57 @@
1
+ /**
2
+ * OME-XML writer: generates an OME-XML metadata string from an
3
+ * ngff-zarr Multiscales object.
4
+ *
5
+ * The generated XML follows the 2016-06 OME schema and embeds
6
+ * dimension sizes, pixel type, channel metadata, and physical
7
+ * sizes extracted from the Multiscales metadata.
8
+ */
9
+ import type { Multiscales } from "@fideus-labs/ngff-zarr";
10
+ import type { ZarrDataType } from "./dtypes.js";
11
+ /** Options for OME-XML generation. */
12
+ export interface OmeXmlWriterOptions {
13
+ /** DimensionOrder for the TIFF. Default: "XYZCT". */
14
+ dimensionOrder?: string;
15
+ /** Creator string embedded in the OME element. Default: "fiff". */
16
+ creator?: string;
17
+ /** Image name. Falls back to multiscales.metadata.name or "image". */
18
+ imageName?: string;
19
+ }
20
+ /** Extracted dimension info from a Multiscales object. */
21
+ export interface DimensionInfo {
22
+ sizeX: number;
23
+ sizeY: number;
24
+ sizeZ: number;
25
+ sizeC: number;
26
+ sizeT: number;
27
+ physicalSizeX?: number;
28
+ physicalSizeY?: number;
29
+ physicalSizeZ?: number;
30
+ physicalSizeXUnit?: string;
31
+ physicalSizeYUnit?: string;
32
+ physicalSizeZUnit?: string;
33
+ }
34
+ /**
35
+ * Generate an OME-XML metadata string from a Multiscales object.
36
+ *
37
+ * @param multiscales - The ngff-zarr Multiscales to generate XML for.
38
+ * @param dtype - The Zarr data type of the pixel data.
39
+ * @param options - Writer options.
40
+ * @returns A complete OME-XML string suitable for a TIFF ImageDescription tag.
41
+ */
42
+ export declare function buildOmeXml(multiscales: Multiscales, dtype: ZarrDataType, options?: OmeXmlWriterOptions): string;
43
+ /**
44
+ * Extract dimension sizes and physical sizes from a Multiscales object.
45
+ * Uses the highest-resolution image (images[0]).
46
+ */
47
+ export declare function extractDimensions(multiscales: Multiscales): DimensionInfo;
48
+ /**
49
+ * Convert a 6-digit hex color string (e.g. "FF0000") to a signed 32-bit RGBA int.
50
+ * Alpha defaults to 0xFF.
51
+ */
52
+ export declare function hexColorToOmeInt(hex: string): number;
53
+ /**
54
+ * Convert an OME signed 32-bit RGBA int to a 6-digit hex color string.
55
+ */
56
+ export declare function omeIntToHexColor(value: number): string;
57
+ //# sourceMappingURL=ome-xml-writer.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ome-xml-writer.d.ts","sourceRoot":"","sources":["../src/ome-xml-writer.ts"],"names":[],"mappings":"AAGA;;;;;;;GAOG;AAEH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AAC1D,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAGhD,sCAAsC;AACtC,MAAM,WAAW,mBAAmB;IAClC,qDAAqD;IACrD,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,mEAAmE;IACnE,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,sEAAsE;IACtE,SAAS,CA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