feat(dicom-image-loader): Add ability to customise path to web worker and codec wasm files
Context
Currently, the dicom-image-loader relies on a bundler like Webpack or Vite to be correctly configured and identity the web worker and wasm files created. This doesn't work well for Angular projects where customising the build tools is significantly more difficult.
This PR addresses https://github.com/cornerstonejs/cornerstone3D/issues/1972
This PR adds the ability for users to override the default webWorkerFn where the worker is loaded and customise the location of the OpenJPH, OpenJPEG, Charls and LibTurboJpeg wasm files that are used in the decoder.
These can be set when the dicomImageLoader is initialised.
for instance:
import { init } from '@cornerstonejs/dicom-image-loader';
init({
maxWebWorkers: 1,
webWorkerUrl: () => {
return new Worker(
// use the Angular build system to create a work worker where the `decodeImageFrameWorker.js` is manually included
new URL('../cornerstone-image-decoder.worker.ts', import.meta.url)
);
},
decodeConfig: {
// Use `angular.json` to copy the required wasm files to the output `assets` directory.
// Set the path to where the library should load the wasm files from.
wasmUrlCodecCharls: './assets/charlswasm_decode.wasm',
wasmUrlCodecLibjpegTurbo8bit: './assets/libjpegturbowasm_decode.wasm',
wasmUrlCodecOpenJpeg: './assets/openjpegwasm_decode.wasm',
wasmUrlCodecOpenJph: './assets/openjphjs.wasm',
},
});
If these aren't passed, the library will use the default loaders.
Changes & Results
Testing
I have created a demo angular project that uses a dev build of this library to demonstrate that it works. You can find the demo angular project here - https://github.com/jmannau/angular-c3d
Checklist
PR
- [X] My Pull Request title is descriptive, accurate and follows the semantic-release format and guidelines.
Code
- [X] My code has been well-documented (function documentation, inline comments, etc.)
Public Documentation Updates
- [] The documentation page has been updated as necessary for any public API additions or removals.
Tested Environment
- [] "OS:
- [] "Node version:
- [] "Browser: