@itk-wasm/image-io
Version:
Input and output for scientific and medical image file formats.
80 lines (64 loc) • 2.06 kB
text/typescript
// Generated file. To retain edits, remove this comment.
import {
JsonCompatible,
Image,
InterfaceTypes,
PipelineOutput,
PipelineInput,
runPipelineNode
} from 'itk-wasm'
import WasmZstdReadImageNodeOptions from './wasm-zstd-read-image-node-options.js'
import WasmZstdReadImageNodeResult from './wasm-zstd-read-image-node-result.js'
import path from 'path'
import { fileURLToPath } from 'url'
/**
* Read an image file format and convert it to the itk-wasm file format
*
* @param {string} serializedImage - Input image serialized in the file format
* @param {WasmZstdReadImageNodeOptions} options - options object
*
* @returns {Promise<WasmZstdReadImageNodeResult>} - result object
*/
async function wasmZstdReadImageNode(
serializedImage: string,
options: WasmZstdReadImageNodeOptions = {}
) : Promise<WasmZstdReadImageNodeResult> {
const mountDirs: Set<string> = new Set()
const desiredOutputs: Array<PipelineOutput> = [
{ type: InterfaceTypes.JsonCompatible },
{ type: InterfaceTypes.Image },
]
mountDirs.add(path.dirname(serializedImage as string))
const inputs: Array<PipelineInput> = [
]
const args = []
// Inputs
const serializedImageName = serializedImage
args.push(serializedImageName)
mountDirs.add(path.dirname(serializedImageName))
// Outputs
const couldReadName = '0'
args.push(couldReadName)
const imageName = '1'
args.push(imageName)
// Options
args.push('--memory-io')
if (options.informationOnly) {
options.informationOnly && args.push('--information-only')
}
const pipelinePath = path.join(path.dirname(fileURLToPath(import.meta.url)), 'pipelines', 'wasm-zstd-read-image')
const {
returnValue,
stderr,
outputs
} = await runPipelineNode(pipelinePath, args, desiredOutputs, inputs, mountDirs)
if (returnValue !== 0 && stderr !== "") {
throw new Error(stderr)
}
const result = {
couldRead: outputs[0]?.data as JsonCompatible,
image: outputs[1]?.data as Image,
}
return result
}
export default wasmZstdReadImageNode