@cleerlycode/cornerstone-wado-image-loader
Version:
Cornerstone ImageLoader for DICOM WADO-URI
171 lines (131 loc) • 5.91 kB
HTML
<html lang="en">
<head>
<meta charset="utf-8">
<title>webWorker/decodeTask/decodeTask.js - Documentation</title>
<script src="scripts/prettify/prettify.js"></script>
<script src="scripts/prettify/lang-css.js"></script>
<!--[if lt IE 9]>
<script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<link type="text/css" rel="stylesheet" href="styles/prettify.css">
<link type="text/css" rel="stylesheet" href="styles/jsdoc.css">
</head>
<body>
<input type="checkbox" id="nav-trigger" class="nav-trigger" />
<label for="nav-trigger" class="navicon-button x">
<div class="navicon"></div>
</label>
<label for="nav-trigger" class="overlay"></label>
<nav>
<h2><a href="index.html">Home</a></h2><h3>Global</h3><ul><li><a href="global.html#addTask">addTask</a></li><li><a href="global.html#arrayBufferToString">arrayBufferToString</a></li><li><a href="global.html#cacheSizeInBytes">cacheSizeInBytes</a></li><li><a href="global.html#cancelTask">cancelTask</a></li><li><a href="global.html#framesAreFragmented">framesAreFragmented</a></li><li><a href="global.html#getNumberString">getNumberString</a></li><li><a href="global.html#getNumberValues">getNumberValues</a></li><li><a href="global.html#getStatistics">getStatistics</a></li><li><a href="global.html#getTransferSyntaxForContentType">getTransferSyntaxForContentType</a></li><li><a href="global.html#getUncompressedImageFrame">getUncompressedImageFrame</a></li><li><a href="global.html#getValue">getValue</a></li><li><a href="global.html#handleMessageFromWorker">handleMessageFromWorker</a></li><li><a href="global.html#handler">handler</a></li><li><a href="global.html#initialize">initialize</a></li><li><a href="global.html#loadCodecs">loadCodecs</a></li><li><a href="global.html#loadWebWorkerTask">loadWebWorkerTask</a></li><li><a href="global.html#registerLoaders">registerLoaders</a></li><li><a href="global.html#registerTaskHandler">registerTaskHandler</a></li><li><a href="global.html#setPixelDataType">setPixelDataType</a></li><li><a href="global.html#setTaskPriority">setTaskPriority</a></li><li><a href="global.html#spawnWebWorker">spawnWebWorker</a></li><li><a href="global.html#startTaskOnWebWorker">startTaskOnWebWorker</a></li><li><a href="global.html#unpackBinaryFrame">unpackBinaryFrame</a></li></ul>
</nav>
<div id="main">
<h1 class="page-title">webWorker/decodeTask/decodeTask.js</h1>
<section>
<article>
<pre class="prettyprint source linenums"><code>import { initializeJPEG2000 } from './decoders/decodeJPEG2000.js';
import { initializeJPEGLS } from './decoders/decodeJPEGLS.js';
import getMinMax from '../../shared/getMinMax.js';
import decodeImageFrame from './decodeImageFrame.js';
const kTaskType = 'decodeTask';
// flag to ensure codecs are loaded only once
let codecsLoaded = false;
// the configuration object for the decodeTask
let decodeConfig;
/**
* Function to control loading and initializing the codecs
*/
function loadCodecs() {
// prevent loading codecs more than once
if (codecsLoaded) {
return;
}
// Load the codecs
// console.time('loadCodecs');
self.importScripts(decodeConfig.codecsPath);
codecsLoaded = true;
// console.timeEnd('loadCodecs');
// Initialize the codecs
if (decodeConfig.initializeCodecsOnStartup) {
// console.time('initializeCodecs');
initializeJPEG2000(decodeConfig);
initializeJPEGLS(decodeConfig);
// console.timeEnd('initializeCodecs');
}
}
/**
* Task initialization function
* @param {Object} config The web worker manager `taskConfiguration` field.
*/
function initialize(config) {
decodeConfig = config[kTaskType] || {};
if (decodeConfig.loadCodecsOnStartup) {
loadCodecs();
}
}
function calculateMinMax(imageFrame) {
const minMax = getMinMax(imageFrame.pixelData);
if (decodeConfig.strict === true) {
if (imageFrame.smallestPixelValue !== minMax.min) {
console.warn(
'Image smallestPixelValue tag is incorrect. Rendering performance will suffer considerably.'
);
}
if (imageFrame.largestPixelValue !== minMax.max) {
console.warn(
'Image largestPixelValue tag is incorrect. Rendering performance will suffer considerably.'
);
}
} else {
imageFrame.smallestPixelValue = minMax.min;
imageFrame.largestPixelValue = minMax.max;
}
}
/**
* Task handler function
*/
function handler({ data }, doneCallback) {
// Load the codecs if they aren't already loaded
loadCodecs();
const imageFrame = data.imageFrame;
// convert pixel data from ArrayBuffer to Uint8Array since web workers support passing ArrayBuffers but
// not typed arrays
const pixelData = new Uint8Array(data.pixelData);
decodeImageFrame(
imageFrame,
data.transferSyntax,
pixelData,
decodeConfig,
data.options
);
if (!imageFrame.pixelData) {
throw new Error(
'decodeTask: imageFrame.pixelData is undefined after decoding'
);
}
calculateMinMax(imageFrame);
// convert from TypedArray to ArrayBuffer since web workers support passing ArrayBuffers but not
// typed arrays
imageFrame.pixelData = imageFrame.pixelData.buffer;
// invoke the callback with our result and pass the pixelData in the transferList to move it to
// UI thread without making a copy
doneCallback(imageFrame, [imageFrame.pixelData]);
}
export default {
taskType: kTaskType,
handler,
initialize
};
</code></pre>
</article>
</section>
</div>
<br class="clear">
<footer>
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.5.5</a> using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
</footer>
<script>prettyPrint();</script>
<script src="scripts/linenumber.js"></script>
</body>
</html>