diff --git a/src/io/ReadImageArrayBufferOptions.ts b/src/io/ReadImageArrayBufferOptions.ts index f4e86f273..5807e3fe2 100644 --- a/src/io/ReadImageArrayBufferOptions.ts +++ b/src/io/ReadImageArrayBufferOptions.ts @@ -1,7 +1,7 @@ import CastImageOptions from '../core/CastImageOptions.js' interface ReadImageArrayBufferOptions extends CastImageOptions { - mimeType: string + mimeType?: string } export default ReadImageArrayBufferOptions diff --git a/src/io/readImageFile.ts b/src/io/readImageFile.ts index b0a60ac31..86ed74b07 100644 --- a/src/io/readImageFile.ts +++ b/src/io/readImageFile.ts @@ -2,10 +2,14 @@ import { readAsArrayBuffer } from 'promise-file-reader' import readImageArrayBuffer from './readImageArrayBuffer.js' import ReadImageResult from './ReadImageResult.js' +import CastImageOptions from '../core/CastImageOptions.js' +import ReadImageArrayBufferOptions from './ReadImageArrayBufferOptions.js' -async function readImageFile (webWorker: Worker | null, file: File): Promise { +async function readImageFile (webWorker: Worker | null, file: File, options?: CastImageOptions): Promise { const arrayBuffer = await readAsArrayBuffer(file) - return await readImageArrayBuffer(webWorker, arrayBuffer, file.name, file.type) + const optionsToPass: ReadImageArrayBufferOptions = typeof options === 'undefined' ? {} : { ...options } + optionsToPass.mimeType = file.type + return await readImageArrayBuffer(webWorker, arrayBuffer, file.name, optionsToPass) } export default readImageFile diff --git a/test/browser/io/readImageTest.js b/test/browser/io/readImageTest.js index 8a28988f3..aa607187f 100644 --- a/test/browser/io/readImageTest.js +++ b/test/browser/io/readImageTest.js @@ -93,6 +93,14 @@ export default function () { verifyImage(t, image, componentType, pixelType) }) + test('readImageFile reads a File, given componentType, pixelType', async (t) => { + const componentType = IntTypes.UInt16 + const pixelType = PixelTypes.Vector + const { image, webWorker } = await readImageFile(null, cthead1SmallFile, { componentType, pixelType }) + webWorker.terminate() + verifyImage(t, image, componentType, pixelType) + }) + test('readImageFile re-uses a WebWorker', async (t) => { const { webWorker } = await readImageFile(null, cthead1SmallFile) const { image } = await readImageFile(webWorker, cthead1SmallFile)