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';
|
2021-09-24 09:06:52 +02:00
|
|
|
import { errorHandler } from '@ohif/core';
|
2020-05-15 12:48:00 +02:00
|
|
|
|
2021-06-23 20:41:27 +02:00
|
|
|
let initialized = false;
|
2020-05-15 12:48:00 +02:00
|
|
|
|
2021-06-23 20:41:27 +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
|
|
|
|
2021-06-23 20:41:27 +02:00
|
|
|
if (!initialized) {
|
|
|
|
|
cornerstoneWADOImageLoader.webWorkerManager.initialize(config);
|
|
|
|
|
initialized = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-05-15 12:48:00 +02:00
|
|
|
|
2021-06-23 20:41:27 +02:00
|
|
|
export default function initWADOImageLoader(UserAuthenticationService) {
|
|
|
|
|
cornerstoneWADOImageLoader.external.cornerstone = cornerstone;
|
|
|
|
|
cornerstoneWADOImageLoader.external.dicomParser = dicomParser;
|
|
|
|
|
|
|
|
|
|
cornerstoneWADOImageLoader.configure({
|
|
|
|
|
beforeSend: function(xhr) {
|
|
|
|
|
const headers = UserAuthenticationService.getAuthorizationHeader();
|
|
|
|
|
|
2021-09-24 09:06:52 +02:00
|
|
|
// 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 = {
|
2021-12-23 23:24:44 +01:00
|
|
|
// To prevent Preflight requests:
|
|
|
|
|
accept: 'multipart/related; type=application/octet-stream',
|
|
|
|
|
//
|
2021-09-24 09:06:52 +02:00
|
|
|
//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=*',
|
|
|
|
|
};
|
|
|
|
|
|
2021-06-23 20:41:27 +02:00
|
|
|
if (headers && headers.Authorization) {
|
2021-09-24 09:06:52 +02:00
|
|
|
xhrRequestHeaders.Authorization = headers.Authorization;
|
2021-06-23 20:41:27 +02:00
|
|
|
}
|
2021-09-24 09:06:52 +02:00
|
|
|
|
|
|
|
|
return xhrRequestHeaders;
|
2021-06-23 20:41:27 +02:00
|
|
|
},
|
2021-06-24 18:30:38 +02:00
|
|
|
errorInterceptor: error => {
|
2021-09-24 09:06:52 +02:00
|
|
|
errorHandler.getHTTPErrorHandler(error);
|
2021-06-24 18:30:38 +02:00
|
|
|
},
|
2021-06-23 20:41:27 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
initWebWorkers();
|
|
|
|
|
}
|