diff --git a/src/io/readWriteImage.ts b/src/io/readWriteImage.ts index 1ac2fafd..41132c70 100644 --- a/src/io/readWriteImage.ts +++ b/src/io/readWriteImage.ts @@ -6,13 +6,13 @@ import { writeImage as writeImageItk, } from '@itk-wasm/image-io'; import { vtiReader, vtiWriter } from '@/src/io/vtk/async'; +import { getWorker } from '@/src/io/itk/worker'; export const readImage = async (file: File) => { if (file.name.endsWith('.vti')) return (await vtiReader(file)) as vtkImageData; - const { image, webWorker } = await readImageItk(file); - webWorker.terminate(); + const { image } = await readImageItk(file, { webWorker: getWorker() }); return vtkITKHelper.convertItkToVtkImage(image); }; @@ -34,7 +34,8 @@ export const writeImage = async (format: string, image: vtkImageData) => { } } - const result = await writeImageItk(itkImage, `image.${format}`); - result.webWorker?.terminate(); + const result = await writeImageItk(itkImage, `image.${format}`, { + webWorker: getWorker(), + }); return result.serializedImage.data; }; diff --git a/src/io/readers.ts b/src/io/readers.ts index 7cccf9c7..fb2ae955 100644 --- a/src/io/readers.ts +++ b/src/io/readers.ts @@ -1,5 +1,6 @@ import { convertItkToVtkImage } from '@kitware/vtk.js/Common/DataModel/ITKHelper'; import { readImage, extensionToImageIo } from '@itk-wasm/image-io'; +import { getWorker } from '@/src/io/itk/worker'; import { FileReaderMap } from '.'; import { stlReader, vtiReader, vtpReader } from './vtk/async'; @@ -14,8 +15,9 @@ export const ITK_IMAGE_MIME_TYPES = Array.from( ); async function itkReader(file: File) { - const { image, webWorker } = await readImage(file); - webWorker.terminate(); + const { image } = await readImage(file, { + webWorker: getWorker(), + }); return convertItkToVtkImage(image); }