Skip to content

Commit

Permalink
feat(readImageBlob): Add pixelType, componentType options
Browse files Browse the repository at this point in the history
  • Loading branch information
thewtex committed Nov 4, 2022
1 parent 6d1c20a commit 9b8c32a
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
5 changes: 3 additions & 2 deletions src/io/readImageBlob.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ import { readAsArrayBuffer } from 'promise-file-reader'

import readImageArrayBuffer from './readImageArrayBuffer.js'
import ReadImageResult from './ReadImageResult.js'
import ReadImageArrayBufferOptions from './ReadImageArrayBufferOptions.js'

async function readImageBlob (webWorker: Worker | null, blob: Blob, fileName: string, mimeType: string): Promise<ReadImageResult> {
async function readImageBlob (webWorker: Worker | null, blob: Blob, fileName: string, options?: ReadImageArrayBufferOptions | string): Promise<ReadImageResult> {
const arrayBuffer = await readAsArrayBuffer(blob)
return await readImageArrayBuffer(webWorker, arrayBuffer, fileName, mimeType)
return readImageArrayBuffer(webWorker, arrayBuffer, fileName, options)
}

export default readImageBlob
18 changes: 17 additions & 1 deletion test/browser/io/readImageTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export default function () {
test('readImageArrayBuffer casts to the specified pixelType', async (t) => {
const arrayBuffer = await PromiseFileReader.readAsArrayBuffer(cthead1SmallFile)
const componentType = IntTypes.UInt16
const pixelType = PixelTypes.Scalar
const pixelType = PixelTypes.Vector
const { image, webWorker } = await readImageArrayBuffer(null, arrayBuffer, 'cthead1Small.png', { componentType, pixelType })
webWorker.terminate()
verifyImage(t, image, componentType, pixelType)
Expand All @@ -69,6 +69,22 @@ export default function () {
verifyImage(t, image, componentType, pixelType)
})

test('readImageBlob casts to the specified componentType', async (t) => {
const componentType = IntTypes.UInt16
const { image, webWorker } = await readImageBlob(null, cthead1SmallBlob, 'cthead1Small.png', { componentType })
webWorker.terminate()
const pixelType = PixelTypes.Scalar
verifyImage(t, image, componentType, pixelType)
})

test('readImageBlob casts to the specified pixelType', async (t) => {
const componentType = IntTypes.UInt16
const pixelType = PixelTypes.Vector
const { image, webWorker } = await readImageBlob(null, cthead1SmallBlob, 'cthead1Small.png', { componentType, pixelType })
webWorker.terminate()
verifyImage(t, image, componentType, pixelType)
})

test('readImageFile reads a File', async (t) => {
const { image, webWorker } = await readImageFile(null, cthead1SmallFile)
webWorker.terminate()
Expand Down

0 comments on commit 9b8c32a

Please sign in to comment.