@fideus-labs/ngff-zarr 0.0.1 → 0.2.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.
Files changed (176) hide show
  1. package/README.md +10 -2
  2. package/esm/io/from_ngff_zarr.d.ts +4 -1
  3. package/esm/io/from_ngff_zarr.d.ts.map +1 -1
  4. package/esm/io/from_ngff_zarr.js +94 -27
  5. package/esm/io/hcs.d.ts +18 -0
  6. package/esm/io/hcs.d.ts.map +1 -0
  7. package/esm/io/hcs.js +51 -0
  8. package/esm/io/itk_image_to_ngff_image.d.ts +30 -0
  9. package/esm/io/itk_image_to_ngff_image.d.ts.map +1 -0
  10. package/esm/io/itk_image_to_ngff_image.js +127 -0
  11. package/esm/io/ngff_image_to_itk_image.d.ts +30 -0
  12. package/esm/io/ngff_image_to_itk_image.d.ts.map +1 -0
  13. package/esm/io/ngff_image_to_itk_image.js +218 -0
  14. package/esm/io/to_multiscales.d.ts +18 -0
  15. package/esm/io/to_multiscales.d.ts.map +1 -0
  16. package/esm/io/to_multiscales.js +62 -0
  17. package/esm/io/to_ngff_image.d.ts +17 -0
  18. package/esm/io/to_ngff_image.d.ts.map +1 -0
  19. package/esm/io/to_ngff_image.js +136 -0
  20. package/esm/io/to_ngff_zarr.d.ts +3 -2
  21. package/esm/io/to_ngff_zarr.d.ts.map +1 -1
  22. package/esm/io/to_ngff_zarr.js +289 -26
  23. package/esm/methods/itkwasm.d.ts +6 -0
  24. package/esm/methods/itkwasm.d.ts.map +1 -0
  25. package/esm/methods/itkwasm.js +958 -0
  26. package/esm/mod.d.ts +9 -2
  27. package/esm/mod.d.ts.map +1 -1
  28. package/esm/mod.js +10 -2
  29. package/esm/schemas/coordinate_systems.d.ts +251 -0
  30. package/esm/schemas/coordinate_systems.d.ts.map +1 -0
  31. package/esm/schemas/coordinate_systems.js +139 -0
  32. package/esm/schemas/index.d.ts +9 -0
  33. package/esm/schemas/index.d.ts.map +1 -0
  34. package/esm/schemas/index.js +38 -0
  35. package/esm/schemas/methods.d.ts.map +1 -1
  36. package/esm/schemas/methods.js +2 -0
  37. package/esm/schemas/multiscales.d.ts.map +1 -1
  38. package/esm/schemas/multiscales.js +2 -0
  39. package/esm/schemas/ngff_image.d.ts +9 -2
  40. package/esm/schemas/ngff_image.d.ts.map +1 -1
  41. package/esm/schemas/ngff_image.js +11 -2
  42. package/esm/schemas/ome_zarr.d.ts +617 -0
  43. package/esm/schemas/ome_zarr.d.ts.map +1 -0
  44. package/esm/schemas/ome_zarr.js +208 -0
  45. package/esm/schemas/rfc4.d.ts +334 -0
  46. package/esm/schemas/rfc4.d.ts.map +1 -0
  47. package/esm/schemas/rfc4.js +129 -0
  48. package/esm/schemas/units.d.ts +70 -5
  49. package/esm/schemas/units.d.ts.map +1 -1
  50. package/esm/schemas/units.js +4 -12
  51. package/esm/schemas/zarr_metadata.d.ts +10 -4
  52. package/esm/schemas/zarr_metadata.d.ts.map +1 -1
  53. package/esm/schemas/zarr_metadata.js +22 -1
  54. package/esm/types/array_interface.d.ts +7 -0
  55. package/esm/types/array_interface.d.ts.map +1 -0
  56. package/esm/types/array_interface.js +1 -0
  57. package/esm/types/hcs.d.ts +70 -0
  58. package/esm/types/hcs.d.ts.map +1 -0
  59. package/esm/types/hcs.js +204 -0
  60. package/esm/types/methods.d.ts.map +1 -1
  61. package/esm/types/methods.js +2 -0
  62. package/esm/types/multiscales.d.ts.map +1 -1
  63. package/esm/types/ngff_image.d.ts +6 -3
  64. package/esm/types/ngff_image.d.ts.map +1 -1
  65. package/esm/types/ngff_image.js +13 -1
  66. package/esm/types/rfc4.d.ts +94 -0
  67. package/esm/types/rfc4.d.ts.map +1 -0
  68. package/esm/types/rfc4.js +135 -0
  69. package/esm/types/units.d.ts +1 -1
  70. package/esm/types/units.d.ts.map +1 -1
  71. package/esm/types/zarr_metadata.d.ts +14 -5
  72. package/esm/types/zarr_metadata.d.ts.map +1 -1
  73. package/esm/utils/create_queue.d.ts +6 -0
  74. package/esm/utils/create_queue.d.ts.map +1 -0
  75. package/esm/utils/create_queue.js +11 -0
  76. package/esm/utils/factory.d.ts +1 -1
  77. package/esm/utils/factory.d.ts.map +1 -1
  78. package/esm/utils/factory.js +16 -7
  79. package/esm/utils/method_metadata.d.ts +10 -0
  80. package/esm/utils/method_metadata.d.ts.map +1 -0
  81. package/esm/utils/method_metadata.js +37 -0
  82. package/esm/utils/validation.d.ts.map +1 -1
  83. package/package.json +7 -1
  84. package/script/io/from_ngff_zarr.d.ts +4 -1
  85. package/script/io/from_ngff_zarr.d.ts.map +1 -1
  86. package/script/io/from_ngff_zarr.js +94 -27
  87. package/script/io/hcs.d.ts +18 -0
  88. package/script/io/hcs.d.ts.map +1 -0
  89. package/script/io/hcs.js +55 -0
  90. package/script/io/itk_image_to_ngff_image.d.ts +30 -0
  91. package/script/io/itk_image_to_ngff_image.d.ts.map +1 -0
  92. package/script/io/itk_image_to_ngff_image.js +153 -0
  93. package/script/io/ngff_image_to_itk_image.d.ts +30 -0
  94. package/script/io/ngff_image_to_itk_image.d.ts.map +1 -0
  95. package/script/io/ngff_image_to_itk_image.js +244 -0
  96. package/script/io/to_multiscales.d.ts +18 -0
  97. package/script/io/to_multiscales.d.ts.map +1 -0
  98. package/script/io/to_multiscales.js +67 -0
  99. package/script/io/to_ngff_image.d.ts +17 -0
  100. package/script/io/to_ngff_image.d.ts.map +1 -0
  101. package/script/io/to_ngff_image.js +162 -0
  102. package/script/io/to_ngff_zarr.d.ts +3 -2
  103. package/script/io/to_ngff_zarr.d.ts.map +1 -1
  104. package/script/io/to_ngff_zarr.js +289 -26
  105. package/script/methods/itkwasm.d.ts +6 -0
  106. package/script/methods/itkwasm.d.ts.map +1 -0
  107. package/script/methods/itkwasm.js +984 -0
  108. package/script/mod.d.ts +9 -2
  109. package/script/mod.d.ts.map +1 -1
  110. package/script/mod.js +12 -3
  111. package/script/schemas/coordinate_systems.d.ts +251 -0
  112. package/script/schemas/coordinate_systems.d.ts.map +1 -0
  113. package/script/schemas/coordinate_systems.js +142 -0
  114. package/script/schemas/index.d.ts +9 -0
  115. package/script/schemas/index.d.ts.map +1 -0
  116. package/script/schemas/index.js +101 -0
  117. package/script/schemas/methods.d.ts.map +1 -1
  118. package/script/schemas/methods.js +2 -0
  119. package/script/schemas/multiscales.d.ts.map +1 -1
  120. package/script/schemas/multiscales.js +2 -0
  121. package/script/schemas/ngff_image.d.ts +9 -2
  122. package/script/schemas/ngff_image.d.ts.map +1 -1
  123. package/script/schemas/ngff_image.js +11 -2
  124. package/script/schemas/ome_zarr.d.ts +617 -0
  125. package/script/schemas/ome_zarr.d.ts.map +1 -0
  126. package/script/schemas/ome_zarr.js +211 -0
  127. package/script/schemas/rfc4.d.ts +334 -0
  128. package/script/schemas/rfc4.d.ts.map +1 -0
  129. package/script/schemas/rfc4.js +132 -0
  130. package/script/schemas/units.d.ts +70 -5
  131. package/script/schemas/units.d.ts.map +1 -1
  132. package/script/schemas/units.js +4 -12
  133. package/script/schemas/zarr_metadata.d.ts +10 -4
  134. package/script/schemas/zarr_metadata.d.ts.map +1 -1
  135. package/script/schemas/zarr_metadata.js +23 -2
  136. package/script/types/array_interface.d.ts +7 -0
  137. package/script/types/array_interface.d.ts.map +1 -0
  138. package/script/types/array_interface.js +2 -0
  139. package/script/types/hcs.d.ts +70 -0
  140. package/script/types/hcs.d.ts.map +1 -0
  141. package/script/types/hcs.js +233 -0
  142. package/script/types/methods.d.ts.map +1 -1
  143. package/script/types/methods.js +2 -0
  144. package/script/types/multiscales.d.ts.map +1 -1
  145. package/script/types/ngff_image.d.ts +6 -3
  146. package/script/types/ngff_image.d.ts.map +1 -1
  147. package/script/types/ngff_image.js +13 -1
  148. package/script/types/rfc4.d.ts +94 -0
  149. package/script/types/rfc4.d.ts.map +1 -0
  150. package/script/types/rfc4.js +143 -0
  151. package/script/types/units.d.ts +1 -1
  152. package/script/types/units.d.ts.map +1 -1
  153. package/script/types/zarr_metadata.d.ts +14 -5
  154. package/script/types/zarr_metadata.d.ts.map +1 -1
  155. package/script/utils/create_queue.d.ts +6 -0
  156. package/script/utils/create_queue.d.ts.map +1 -0
  157. package/script/utils/create_queue.js +17 -0
  158. package/script/utils/factory.d.ts +1 -1
  159. package/script/utils/factory.d.ts.map +1 -1
  160. package/script/utils/factory.js +39 -7
  161. package/script/utils/method_metadata.d.ts +10 -0
  162. package/script/utils/method_metadata.d.ts.map +1 -0
  163. package/script/utils/method_metadata.js +40 -0
  164. package/script/utils/validation.d.ts.map +1 -1
  165. package/esm/schemas/lazy_array.d.ts +0 -8
  166. package/esm/schemas/lazy_array.d.ts.map +0 -1
  167. package/esm/schemas/lazy_array.js +0 -7
  168. package/esm/types/lazy_array.d.ts +0 -18
  169. package/esm/types/lazy_array.d.ts.map +0 -1
  170. package/esm/types/lazy_array.js +0 -27
  171. package/script/schemas/lazy_array.d.ts +0 -8
  172. package/script/schemas/lazy_array.d.ts.map +0 -1
  173. package/script/schemas/lazy_array.js +0 -10
  174. package/script/types/lazy_array.d.ts +0 -18
  175. package/script/types/lazy_array.d.ts.map +0 -1
  176. package/script/types/lazy_array.js +0 -31
@@ -1,57 +1,320 @@
1
+ // SPDX-FileCopyrightText: Copyright (c) Fideus Labs LLC
2
+ // SPDX-License-Identifier: MIT
3
+ import * as dntShim from "../_dnt.shims.js";
1
4
  import * as zarr from "zarrita";
2
- export function toNgffZarr(_storePath, _multiscales, options = {}) {
5
+ import { createQueue } from "../utils/create_queue.js";
6
+ export async function toNgffZarr(store, multiscales, options = {}) {
3
7
  const _overwrite = options.overwrite ?? true;
4
8
  const _version = options.version ?? "0.4";
5
9
  try {
6
- // TODO: Implement using zarrita v0.5.2 API
7
- // Example implementation would be:
8
- // 1. Create a writable store (e.g., FileSystemStore for local files)
9
- // 2. Use zarr.root(store) to create a Location
10
- // 3. Use zarr.create(root, { attributes: { multiscales: [...] } }) to create group
11
- // 4. For each image, use zarr.create(root.resolve(path), { shape, data_type, chunk_shape })
12
- // 5. Use zarr.set() to write actual data
13
- throw new Error("Writing OME-Zarr files is not yet fully implemented with zarrita v0.5.2");
10
+ // Determine the appropriate store type based on the path
11
+ let _resolvedStore; // Use unknown for FileSystemStore since we import it dynamically
12
+ if (store instanceof Map) {
13
+ _resolvedStore = store;
14
+ }
15
+ else if (store instanceof zarr.FetchStore) {
16
+ throw new Error("FetchStore is read-only and cannot be used for writing. Use a local file path or MemoryStore instead.");
17
+ }
18
+ else if (store.startsWith("http://") || store.startsWith("https://")) {
19
+ throw new Error("HTTP/HTTPS URLs are read-only and cannot be used for writing. Use a local file path instead.");
20
+ }
21
+ else {
22
+ // For local paths, check if we're in a browser environment
23
+ if (typeof dntShim.dntGlobalThis !== "undefined") {
24
+ throw new Error("Local file paths are not supported in browser environments. Use a MemoryStore instead.");
25
+ }
26
+ // Use dynamic import for FileSystemStore in Node.js/Deno environments
27
+ try {
28
+ const { FileSystemStore } = await import("@zarrita/storage");
29
+ // Normalize the path for cross-platform compatibility
30
+ const normalizedPath = store.replace(/^\/([A-Za-z]:)/, "$1");
31
+ _resolvedStore = new FileSystemStore(normalizedPath);
32
+ }
33
+ catch (error) {
34
+ throw new Error(`Failed to load FileSystemStore: ${error}. Use MemoryStore for browser compatibility.`);
35
+ }
36
+ }
37
+ // Create root location and group with zarrita v0.5.2 API
38
+ const root = zarr.root(_resolvedStore);
39
+ // Create the root group with OME-Zarr metadata
40
+ const rootGroup = await zarr.create(root, {
41
+ attributes: {
42
+ multiscales: [
43
+ {
44
+ version: _version,
45
+ name: multiscales.metadata.name,
46
+ axes: multiscales.metadata.axes,
47
+ datasets: multiscales.metadata.datasets,
48
+ ...(multiscales.metadata.coordinateTransformations && {
49
+ coordinateTransformations: multiscales.metadata.coordinateTransformations,
50
+ }),
51
+ ...(multiscales.metadata.type && {
52
+ type: multiscales.metadata.type,
53
+ }),
54
+ ...(multiscales.metadata.metadata && {
55
+ metadata: multiscales.metadata.metadata,
56
+ }),
57
+ },
58
+ ],
59
+ ...(multiscales.metadata.omero && {
60
+ omero: multiscales.metadata.omero,
61
+ }),
62
+ },
63
+ });
64
+ // Write each image in the multiscales
65
+ for (let i = 0; i < multiscales.images.length; i++) {
66
+ const image = multiscales.images[i];
67
+ const dataset = multiscales.metadata.datasets[i];
68
+ if (!dataset) {
69
+ throw new Error(`No dataset configuration found for image ${i}`);
70
+ }
71
+ await _writeImage(rootGroup, image, dataset.path);
72
+ }
14
73
  }
15
74
  catch (error) {
16
75
  throw new Error(`Failed to write OME-Zarr: ${error instanceof Error ? error.message : String(error)}`);
17
76
  }
18
77
  }
78
+ function _convertDtypeToZarrType(dtype) {
79
+ // Map common numpy/LazyArray dtypes to zarrita data types
80
+ const dtypeMap = {
81
+ int8: "int8",
82
+ int16: "int16",
83
+ int32: "int32",
84
+ int64: "int64",
85
+ uint8: "uint8",
86
+ uint16: "uint16",
87
+ uint32: "uint32",
88
+ uint64: "uint64",
89
+ float32: "float32",
90
+ float64: "float64",
91
+ bool: "bool",
92
+ // Handle some alternative formats
93
+ i1: "int8",
94
+ i2: "int16",
95
+ i4: "int32",
96
+ i8: "int64",
97
+ u1: "uint8",
98
+ u2: "uint16",
99
+ u4: "uint32",
100
+ u8: "uint64",
101
+ f4: "float32",
102
+ f8: "float64",
103
+ };
104
+ if (dtype in dtypeMap) {
105
+ return dtypeMap[dtype];
106
+ }
107
+ else {
108
+ throw new Error(`Unsupported data type: ${dtype}`);
109
+ }
110
+ }
111
+ function getTypedArrayConstructor(dtype) {
112
+ // Map zarrita data types to TypedArray constructors
113
+ const constructorMap = {
114
+ int8: Int8Array,
115
+ int16: Int16Array,
116
+ int32: Int32Array,
117
+ int64: BigInt64Array,
118
+ uint8: Uint8Array,
119
+ uint16: Uint16Array,
120
+ uint32: Uint32Array,
121
+ uint64: BigUint64Array,
122
+ float32: Float32Array,
123
+ float64: Float64Array,
124
+ bool: Uint8Array, // Use Uint8Array for boolean, where 0 represents false and 1 represents true
125
+ // Note: float16 and "v2:object" not supported by standard TypedArrays
126
+ };
127
+ const constructor = constructorMap[dtype];
128
+ if (constructor) {
129
+ return constructor;
130
+ }
131
+ else {
132
+ throw new Error(`Unsupported data type for typed array: ${dtype}`);
133
+ }
134
+ }
19
135
  async function _writeImage(group, image, arrayPath) {
20
136
  try {
21
137
  const chunks = getChunksFromImage(image);
22
- // TODO: Update to use zarrita v0.5.2 API properly
23
- // The new API would use:
24
- // const location = (group as { resolve: (path: string) => Location }).resolve(arrayPath);
25
- // const zarrArray = await zarr.create(location, { ... });
26
- // Then use zarr.set(zarrArray, data, selection) to write data
27
- const resolvedPath = group.resolve(arrayPath);
28
- // @ts-ignore - zarrita API types are complex, this is a temporary workaround
29
- const _zarrArray = await zarr.create(resolvedPath, {
138
+ // Convert LazyArray dtype to zarrita DataType
139
+ const zarrDataType = _convertDtypeToZarrType(image.data.dtype);
140
+ // Create array location
141
+ const arrayLocation = group.resolve(arrayPath);
142
+ // Create the zarr array with proper configuration
143
+ const zarrArray = await zarr.create(arrayLocation, {
30
144
  shape: image.data.shape,
31
- data_type: image.data.dtype,
145
+ data_type: zarrDataType,
32
146
  chunk_shape: chunks,
33
147
  fill_value: 0,
34
148
  });
35
- // Note: With zarrita v0.5.2, attributes can be set during creation
36
- // or updated using the store's set method for metadata files
149
+ await _writeArrayData(zarrArray, image);
37
150
  }
38
151
  catch (error) {
39
152
  throw new Error(`Failed to write image array: ${error instanceof Error ? error.message : String(error)}`);
40
153
  }
41
154
  }
42
155
  function getChunksFromImage(image) {
43
- if (image.data.chunks.length > 0 && image.data.chunks[0].length > 0) {
44
- return image.data.chunks[0];
156
+ // zarr.Array.chunks is a number[] representing chunk shape
157
+ if (image.data.chunks && image.data.chunks.length > 0) {
158
+ return image.data.chunks;
45
159
  }
46
160
  return image.data.shape.map((dim) => Math.min(dim, 1024));
47
161
  }
48
- function _writeArrayData(_storePath, _arrayPath, _data, _selection) {
162
+ async function _writeArrayData(zarrArray, image) {
49
163
  try {
50
- // Note: zarrita doesn't have a direct set method for arrays
51
- // This would need to be implemented differently
52
- throw new Error("Writing array data not yet implemented with zarrita");
164
+ // Get array shape for chunk calculation - we don't need the full data here
165
+ const shape = image.data.shape;
166
+ // Calculate chunk indices for parallel writing
167
+ const chunkIndices = calculateChunkIndices(shape, zarrArray.chunks);
168
+ // Create a queue for parallel chunk writing
169
+ const writeQueue = createQueue();
170
+ // Queue all chunks for writing
171
+ for (const chunkIndex of chunkIndices) {
172
+ writeQueue.add(async () => {
173
+ await writeChunkWithGet(zarrArray, image, chunkIndex);
174
+ });
175
+ }
176
+ // Wait for all chunks to be written
177
+ await writeQueue.onIdle();
53
178
  }
54
179
  catch (error) {
55
180
  throw new Error(`Failed to write array data: ${error instanceof Error ? error.message : String(error)}`);
56
181
  }
57
182
  }
183
+ async function writeChunkWithGet(zarrArray, image, chunkIndex) {
184
+ // Calculate the chunk bounds
185
+ const shape = image.data.shape;
186
+ const chunkStart = chunkIndex.map((idx, dim) => idx * zarrArray.chunks[dim]);
187
+ const chunkEnd = chunkStart.map((start, dim) => Math.min(start + zarrArray.chunks[dim], shape[dim]));
188
+ // Calculate chunk shape
189
+ const chunkShape = chunkEnd.map((end, dim) => end - chunkStart[dim]);
190
+ // Create selection for this chunk from the source data
191
+ const sourceSelection = chunkStart.map((start, dim) => zarr.slice(start, chunkEnd[dim]));
192
+ // Get only the chunk data we need from the source
193
+ const { data: chunkSourceData } = await zarr.get(image.data, sourceSelection);
194
+ // Convert chunk data to target type
195
+ const targetTypedArrayConstructor = getTypedArrayConstructor(zarrArray.dtype);
196
+ const chunkTargetData = convertChunkToTargetType(chunkSourceData, zarrArray.dtype, targetTypedArrayConstructor);
197
+ // Validate chunk data size
198
+ const expectedSize = chunkShape.reduce((a, b) => a * b, 1);
199
+ const actualSize = chunkTargetData.byteLength /
200
+ (chunkTargetData
201
+ .BYTES_PER_ELEMENT || 1);
202
+ if (actualSize !== expectedSize) {
203
+ console.error(`[writeChunkWithGet] Chunk data size mismatch!`);
204
+ console.error(` Image shape:`, shape);
205
+ console.error(` Chunk index:`, chunkIndex);
206
+ console.error(` Chunk start:`, chunkStart);
207
+ console.error(` Chunk end:`, chunkEnd);
208
+ console.error(` Chunk shape:`, chunkShape);
209
+ console.error(` Expected size:`, expectedSize);
210
+ console.error(` Actual size:`, actualSize);
211
+ throw new Error(`Chunk data size mismatch: expected ${expectedSize} elements, got ${actualSize}`);
212
+ }
213
+ // Create the selection for writing to the target zarr array
214
+ const targetSelection = chunkStart.map((start, dim) => zarr.slice(start, chunkEnd[dim]));
215
+ // Write the chunk using zarrita's set function
216
+ await zarr.set(zarrArray, targetSelection, {
217
+ data: chunkTargetData,
218
+ shape: chunkShape,
219
+ stride: calculateChunkStride(chunkShape),
220
+ });
221
+ }
222
+ function convertChunkToTargetType(chunkData, targetDtype, targetTypedArrayConstructor) {
223
+ // Handle different source data types
224
+ if (chunkData instanceof BigInt64Array ||
225
+ chunkData instanceof BigUint64Array) {
226
+ // Handle BigInt arrays separately
227
+ if (chunkData.constructor === targetTypedArrayConstructor) {
228
+ return chunkData;
229
+ }
230
+ else if (targetDtype === "int64" || targetDtype === "uint64") {
231
+ // BigInt to BigInt conversion
232
+ const bigIntArray = new targetTypedArrayConstructor(chunkData.length);
233
+ for (let i = 0; i < chunkData.length; i++) {
234
+ bigIntArray[i] = chunkData[i];
235
+ }
236
+ return bigIntArray;
237
+ }
238
+ else {
239
+ // BigInt to regular number conversion
240
+ const numberArray = new targetTypedArrayConstructor(chunkData.length);
241
+ for (let i = 0; i < chunkData.length; i++) {
242
+ numberArray[i] = Number(chunkData[i]);
243
+ }
244
+ return numberArray;
245
+ }
246
+ }
247
+ else if (chunkData instanceof Uint8Array ||
248
+ chunkData instanceof Int8Array ||
249
+ chunkData instanceof Uint16Array ||
250
+ chunkData instanceof Int16Array ||
251
+ chunkData instanceof Uint32Array ||
252
+ chunkData instanceof Int32Array ||
253
+ chunkData instanceof Float32Array ||
254
+ chunkData instanceof Float64Array) {
255
+ // Handle regular typed arrays
256
+ if (chunkData.constructor === targetTypedArrayConstructor) {
257
+ return chunkData;
258
+ }
259
+ else {
260
+ // Convert between typed arrays
261
+ if (targetDtype === "int64" || targetDtype === "uint64") {
262
+ // Regular number to BigInt conversion
263
+ const bigIntArray = new targetTypedArrayConstructor(chunkData.length);
264
+ for (let i = 0; i < chunkData.length; i++) {
265
+ bigIntArray[i] = BigInt(chunkData[i]);
266
+ }
267
+ return bigIntArray;
268
+ }
269
+ else {
270
+ // Standard numeric conversion - use typed conversion
271
+ const typedArrayMap = new Map([
272
+ [Uint8Array, (data) => new Uint8Array(Array.from(data))],
273
+ [Int8Array, (data) => new Int8Array(Array.from(data))],
274
+ [Uint16Array, (data) => new Uint16Array(Array.from(data))],
275
+ [Int16Array, (data) => new Int16Array(Array.from(data))],
276
+ [Uint32Array, (data) => new Uint32Array(Array.from(data))],
277
+ [Int32Array, (data) => new Int32Array(Array.from(data))],
278
+ [Float32Array, (data) => new Float32Array(Array.from(data))],
279
+ [Float64Array, (data) => new Float64Array(Array.from(data))],
280
+ ]);
281
+ const createTypedArray = typedArrayMap.get(targetTypedArrayConstructor);
282
+ if (createTypedArray) {
283
+ return createTypedArray(chunkData);
284
+ }
285
+ else {
286
+ throw new Error(`Unsupported target constructor: ${targetTypedArrayConstructor.name}`);
287
+ }
288
+ }
289
+ }
290
+ }
291
+ else {
292
+ // Handle other types (fallback)
293
+ throw new Error(`Unsupported source data type: ${chunkData.constructor.name}`);
294
+ }
295
+ }
296
+ function calculateChunkIndices(shape, chunks) {
297
+ const indices = [];
298
+ function generateIndices(dimIndex, currentIndex) {
299
+ if (dimIndex === shape.length) {
300
+ indices.push([...currentIndex]);
301
+ return;
302
+ }
303
+ const chunkSize = chunks[dimIndex];
304
+ const dimSize = shape[dimIndex];
305
+ for (let i = 0; i < Math.ceil(dimSize / chunkSize); i++) {
306
+ currentIndex[dimIndex] = i;
307
+ generateIndices(dimIndex + 1, currentIndex);
308
+ }
309
+ }
310
+ generateIndices(0, new Array(shape.length));
311
+ return indices;
312
+ }
313
+ function calculateChunkStride(chunkShape) {
314
+ const stride = new Array(chunkShape.length);
315
+ stride[chunkShape.length - 1] = 1;
316
+ for (let i = chunkShape.length - 2; i >= 0; i--) {
317
+ stride[i] = stride[i + 1] * chunkShape[i + 1];
318
+ }
319
+ return stride;
320
+ }
@@ -0,0 +1,6 @@
1
+ import { NgffImage } from "../types/ngff_image.js";
2
+ /**
3
+ * Main downsampling function for ITK-Wasm
4
+ */
5
+ export declare function downsampleItkWasm(ngffImage: NgffImage, scaleFactors: (Record<string, number> | number)[], smoothing: "gaussian" | "bin_shrink" | "label_image"): Promise<NgffImage[]>;
6
+ //# sourceMappingURL=itkwasm.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"itkwasm.d.ts","sourceRoot":"","sources":["../../src/methods/itkwasm.ts"],"names":[],"mappings":"AAcA,OAAO,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;AAknCnD;;GAEG;AACH,wBAAsB,iBAAiB,CACrC,SAAS,EAAE,SAAS,EACpB,YAAY,EAAE,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,MAAM,CAAC,EAAE,EACjD,SAAS,EAAE,UAAU,GAAG,YAAY,GAAG,aAAa,GACnD,OAAO,CAAC,SAAS,EAAE,CAAC,CA8HtB"}