@itk-wasm/image-io
Version:
Input and output for scientific and medical image file formats.
57 lines • 2.25 kB
JavaScript
// Generated file. To retain edits, remove this comment.
import { InterfaceTypes, runPipeline } from 'itk-wasm';
import { getPipelinesBaseUrl } from './pipelines-base-url.js';
import { getPipelineWorkerUrl } from './pipeline-worker-url.js';
import { getDefaultWebWorker } from './default-web-worker.js';
/**
* Write an itk-wasm file format converted to an image file format
*
* @param {Image} image - Input image
* @param {string} serializedImage - Output image serialized in the file format.
* @param {MetaWriteImageOptions} options - options object
*
* @returns {Promise<MetaWriteImageResult>} - result object
*/
async function metaWriteImage(image, serializedImage, options = {}) {
const desiredOutputs = [
{ type: InterfaceTypes.JsonCompatible },
{ type: InterfaceTypes.BinaryFile, data: { path: serializedImage, data: new Uint8Array() } },
];
const inputs = [
{ type: InterfaceTypes.Image, data: image },
];
const args = [];
// Inputs
const imageName = '0';
args.push(imageName);
// Outputs
const couldWriteName = '0';
args.push(couldWriteName);
const serializedImageName = serializedImage;
args.push(serializedImageName);
// Options
args.push('--memory-io');
if (options.informationOnly) {
options.informationOnly && args.push('--information-only');
}
if (options.useCompression) {
options.useCompression && args.push('--use-compression');
}
const pipelinePath = 'meta-write-image';
let workerToUse = options?.webWorker;
if (workerToUse === undefined) {
workerToUse = await getDefaultWebWorker();
}
const { webWorker: usedWebWorker, returnValue, stderr, outputs } = await runPipeline(pipelinePath, args, desiredOutputs, inputs, { pipelineBaseUrl: getPipelinesBaseUrl(), pipelineWorkerUrl: getPipelineWorkerUrl(), webWorker: workerToUse, noCopy: options?.noCopy });
if (returnValue !== 0 && stderr !== "") {
throw new Error(stderr);
}
const result = {
webWorker: usedWebWorker,
couldWrite: outputs[0]?.data,
serializedImage: outputs[1]?.data,
};
return result;
}
export default metaWriteImage;
//# sourceMappingURL=meta-write-image.js.map