ohif-viewer/extensions/cornerstone/src/initWADOImageLoader.js

61 lines
2.0 KiB
JavaScript
Raw Normal View History

2020-05-15 12:48:00 +02:00
import cornerstone from 'cornerstone-core';
import cornerstoneWADOImageLoader from 'cornerstone-wado-image-loader';
import dicomParser from 'dicom-parser';
import { errorHandler } from '@ohif/core';
2020-05-15 12:48:00 +02:00
let initialized = false;
2020-05-15 12:48:00 +02:00
function initWebWorkers() {
const config = {
maxWebWorkers: Math.max(navigator.hardwareConcurrency - 1, 1),
startWebWorkersOnDemand: true,
taskConfiguration: {
decodeTask: {
initializeCodecsOnStartup: false,
usePDFJS: false,
strict: false,
},
},
};
2020-05-15 12:48:00 +02:00
if (!initialized) {
cornerstoneWADOImageLoader.webWorkerManager.initialize(config);
initialized = true;
}
}
2020-05-15 12:48:00 +02:00
export default function initWADOImageLoader(UserAuthenticationService) {
cornerstoneWADOImageLoader.external.cornerstone = cornerstone;
cornerstoneWADOImageLoader.external.dicomParser = dicomParser;
cornerstoneWADOImageLoader.configure({
beforeSend: function(xhr) {
const headers = UserAuthenticationService.getAuthorizationHeader();
// Request:
// JPEG-LS Lossless (1.2.840.10008.1.2.4.80) if available, otherwise accept
// whatever transfer-syntax the origin server provides.
// For now we use image/jls and image/x-jls because some servers still use the old type
// http://dicom.nema.org/medical/dicom/current/output/html/part18.html
const xhrRequestHeaders = {
// To prevent Preflight requests:
accept: 'multipart/related; type=application/octet-stream',
//
//accept: 'multipart/related; type="image/x-jls"',
// 'multipart/related; type="image/x-jls", multipart/related; type="image/jls"; transfer-syntax="1.2.840.10008.1.2.4.80", multipart/related; type="image/x-jls", multipart/related; type="application/octet-stream"; transfer-syntax=*',
};
if (headers && headers.Authorization) {
xhrRequestHeaders.Authorization = headers.Authorization;
}
return xhrRequestHeaders;
},
2021-06-24 18:30:38 +02:00
errorInterceptor: error => {
errorHandler.getHTTPErrorHandler(error);
2021-06-24 18:30:38 +02:00
},
});
initWebWorkers();
}