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