Skip to content

Commit 9ac40b9

Browse files
committed
feat(readImageFile): Support componentType, pixelType
1 parent 5e5d142 commit 9ac40b9

File tree

3 files changed

+15
-3
lines changed

3 files changed

+15
-3
lines changed
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import CastImageOptions from '../core/CastImageOptions.js'
22

33
interface ReadImageArrayBufferOptions extends CastImageOptions {
4-
mimeType: string
4+
mimeType?: string
55
}
66

77
export default ReadImageArrayBufferOptions

src/io/readImageFile.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,14 @@ import { readAsArrayBuffer } from 'promise-file-reader'
22

33
import readImageArrayBuffer from './readImageArrayBuffer.js'
44
import ReadImageResult from './ReadImageResult.js'
5+
import CastImageOptions from '../core/CastImageOptions.js'
6+
import ReadImageArrayBufferOptions from './ReadImageArrayBufferOptions.js'
57

6-
async function readImageFile (webWorker: Worker | null, file: File): Promise<ReadImageResult> {
8+
async function readImageFile (webWorker: Worker | null, file: File, options?: CastImageOptions): Promise<ReadImageResult> {
79
const arrayBuffer = await readAsArrayBuffer(file)
8-
return await readImageArrayBuffer(webWorker, arrayBuffer, file.name, file.type)
10+
const optionsToPass: ReadImageArrayBufferOptions = typeof options === 'undefined' ? {} : { ...options }
11+
optionsToPass.mimeType = file.type
12+
return await readImageArrayBuffer(webWorker, arrayBuffer, file.name, optionsToPass)
913
}
1014

1115
export default readImageFile

test/browser/io/readImageTest.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,14 @@ export default function () {
9393
verifyImage(t, image, componentType, pixelType)
9494
})
9595

96+
test('readImageFile reads a File, given componentType, pixelType', async (t) => {
97+
const componentType = IntTypes.UInt16
98+
const pixelType = PixelTypes.Vector
99+
const { image, webWorker } = await readImageFile(null, cthead1SmallFile, { componentType, pixelType })
100+
webWorker.terminate()
101+
verifyImage(t, image, componentType, pixelType)
102+
})
103+
96104
test('readImageFile re-uses a WebWorker', async (t) => {
97105
const { webWorker } = await readImageFile(null, cthead1SmallFile)
98106
const { image } = await readImageFile(webWorker, cthead1SmallFile)

0 commit comments

Comments
 (0)