Skip to content

Commit

Permalink
fix(ReadImagePipelines): Check for SharedArrayBuffer in read image pi…
Browse files Browse the repository at this point in the history
…pelines

adds getTransferables everywhere worker postmessage is used, specifically the read image pipelines,
where it was missing
  • Loading branch information
pritamrungta committed Jun 17, 2023
1 parent a6cf384 commit 2380b20
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 7 deletions.
3 changes: 2 additions & 1 deletion src/io/meshToPolyData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import PolyData from '../core/PolyData.js'
import meshTransferables from '../core/internal/meshTransferables.js'
import PipelineInput from '../pipeline/PipelineInput.js'
import config from '../itkConfig.js'
import getTransferables from '../core/getTransferables.js'

async function meshToPolyData (webWorker: Worker | null, mesh: Mesh): Promise<{ polyData: PolyData, webWorker: Worker }> {
let worker = webWorker
Expand Down Expand Up @@ -33,7 +34,7 @@ async function meshToPolyData (webWorker: Worker | null, mesh: Mesh): Promise<{
outputs,
inputs
},
transferables
getTransferables(transferables)
)
return { polyData: result.outputs[0].data as PolyData, webWorker: worker }
}
Expand Down
3 changes: 2 additions & 1 deletion src/io/polyDataToMesh.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import PolyData from '../core/PolyData.js'
import polyDataTransferables from '../core/internal/polyDataTransferables.js'
import PipelineInput from '../pipeline/PipelineInput.js'
import config from '../itkConfig.js'
import getTransferables from '../core/getTransferables.js'

async function polyDataToMesh (webWorker: Worker | null, polyData: PolyData): Promise<{ mesh: Mesh, webWorker: Worker }> {
let worker = webWorker
Expand Down Expand Up @@ -33,7 +34,7 @@ async function polyDataToMesh (webWorker: Worker | null, polyData: PolyData): Pr
outputs,
inputs
},
transferables
getTransferables(transferables)
)
return { mesh: result.outputs[0].data as Mesh, webWorker: worker }
}
Expand Down
4 changes: 3 additions & 1 deletion src/io/readDICOMTagsArrayBuffer.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import getTransferables from '../core/getTransferables.js'
import createWebWorkerPromise from '../core/createWebWorkerPromise.js'
import PipelineInput from '../pipeline/PipelineInput.js'
import TextStream from '../core/TextStream.js'
Expand Down Expand Up @@ -30,6 +31,7 @@ async function readDICOMTagsArrayBuffer (webWorker: Worker | null, arrayBuffer:
{ type: InterfaceTypes.TextStream }
]

const transferables: ArrayBuffer[] = [arrayBuffer]
interface PipelineResult {
stdout: string
stderr: string
Expand All @@ -45,7 +47,7 @@ async function readDICOMTagsArrayBuffer (webWorker: Worker | null, arrayBuffer:
outputs,
inputs
},
[arrayBuffer]
getTransferables(transferables)
)
const tagsJSON = (result.outputs[0].data as TextStream).data
const tagsResult = JSON.parse(tagsJSON)
Expand Down
3 changes: 2 additions & 1 deletion src/io/readImageArrayBuffer.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import getTransferables from '../core/getTransferables.js'
import createWebWorkerPromise from '../core/createWebWorkerPromise.js'
import Image from '../core/Image.js'
import InterfaceTypes from '../core/InterfaceTypes.js'
Expand Down Expand Up @@ -49,7 +50,7 @@ async function readImageArrayBuffer (webWorker: Worker | null, arrayBuffer: Arra
outputs,
inputs
},
transferables
getTransferables(transferables)
)
let image = result.outputs[0].data as Image
if (typeof options === 'object' && (typeof options.componentType !== 'undefined' || typeof options.pixelType !== 'undefined')) {
Expand Down
6 changes: 5 additions & 1 deletion src/io/readImageDICOMArrayBufferSeries.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import getTransferables from '../core/getTransferables.js'
import createWebWorkerPromise from '../core/createWebWorkerPromise.js'
import WorkerPool from '../core/WorkerPool.js'
import Metadata from '../core/Metadata.js'
Expand Down Expand Up @@ -57,7 +58,10 @@ const workerFunction = async (
outputs,
inputs
}
const result: PipelineResult = await webworkerPromise.postMessage(message, transferables)
const result: PipelineResult = await webworkerPromise.postMessage(
message,
getTransferables(transferables)
)
const image: Image = result.outputs[0].data
const filenames: string[] = result.outputs[1].data.data.split('\0')
// remove the last element since we expect it to be empty
Expand Down
3 changes: 2 additions & 1 deletion src/io/readMeshArrayBuffer.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import getTransferables from '../core/getTransferables.js'
import createWebWorkerPromise from '../core/createWebWorkerPromise.js'
import Mesh from '../core/Mesh.js'
import InterfaceTypes from '../core/InterfaceTypes.js'
Expand Down Expand Up @@ -39,7 +40,7 @@ async function readMeshArrayBuffer (webWorker: Worker | null, arrayBuffer: Array
outputs,
inputs
},
transferables
getTransferables(transferables)
)
return { mesh: result.outputs[0].data as Mesh, webWorker: worker }
}
Expand Down
3 changes: 2 additions & 1 deletion src/io/writeMeshArrayBuffer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import PipelineInput from '../pipeline/PipelineInput.js'
import PipelineOutput from '../pipeline/PipelineOutput.js'
import InterfaceTypes from '../core/InterfaceTypes.js'
import meshTransferables from '../core/internal/meshTransferables.js'
import getTransferables from '../core/getTransferables.js'

async function writeMeshArrayBuffer (webWorker: Worker | null, mesh: Mesh, fileName: string, mimeType: string, options: WriteMeshOptions): Promise<WriteArrayBufferResult> {
if ('useCompression' in (mesh as any) || 'binaryFileType' in (mesh as any)) {
Expand Down Expand Up @@ -52,7 +53,7 @@ async function writeMeshArrayBuffer (webWorker: Worker | null, mesh: Mesh, fileN
outputs,
inputs
},
transferables
getTransferables(transferables)
)
return { arrayBuffer: result.outputs[0].data.data.buffer as ArrayBuffer, webWorker: worker }
}
Expand Down

0 comments on commit 2380b20

Please sign in to comment.