Skip to content

Commit

Permalink
feat(readImageFile): Support componentType, pixelType
Browse files Browse the repository at this point in the history
  • Loading branch information
thewtex committed Nov 7, 2022
1 parent 5e5d142 commit 9ac40b9
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/io/ReadImageArrayBufferOptions.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import CastImageOptions from '../core/CastImageOptions.js'

interface ReadImageArrayBufferOptions extends CastImageOptions {
mimeType: string
mimeType?: string
}

export default ReadImageArrayBufferOptions
8 changes: 6 additions & 2 deletions src/io/readImageFile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<ReadImageResult> {
async function readImageFile (webWorker: Worker | null, file: File, options?: CastImageOptions): Promise<ReadImageResult> {
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
8 changes: 8 additions & 0 deletions test/browser/io/readImageTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 9ac40b9

Please sign in to comment.