UNPKG

cornerstone-wado-image-loader

Version:
153 lines (110 loc) 5.53 kB
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>webWorker/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"> <script src="scripts/nav.js" defer></script> <meta name="viewport" content="width=device-width, initial-scale=1.0"> </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#decodeAsync">decodeAsync</a></li><li><a href="global.html#framesAreFragmented">framesAreFragmented</a></li><li><a href="global.html#getMinMax">getMinMax</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#terminate">terminate</a></li><li><a href="global.html#unpackBinaryFrame">unpackBinaryFrame</a></li></ul> </nav> <div id="main"> <h1 class="page-title">webWorker/decodeTask.js</h1> <section> <article> <pre class="prettyprint source linenums"><code>import { initialize as initializeJPEG2000 } from '../shared/decoders/decodeJPEG2000.js'; import { initialize as initializeJPEGLS } from '../shared/decoders/decodeJPEGLS.js'; import calculateMinMax from '../shared/calculateMinMax.js'; import decodeImageFrame from '../shared/decodeImageFrame.js'; // the configuration object for the decodeTask let decodeConfig; /** * Function to control loading and initializing the codecs * @param config */ function loadCodecs(config) { // Initialize the codecs if (config.decodeTask.initializeCodecsOnStartup) { console.time('initializeCodecs'); initializeJPEG2000(config.decodeTask); initializeJPEGLS(config.decodeTask); console.timeEnd('initializeCodecs'); } } /** * Task initialization function */ function initialize(config) { decodeConfig = config; loadCodecs(config); } /** * Task handler function */ function handler(data, doneCallback) { // Load the codecs if they aren't already loaded loadCodecs(decodeConfig); const strict = decodeConfig &amp;&amp; decodeConfig.decodeTask &amp;&amp; decodeConfig.decodeTask.strict; // convert pixel data from ArrayBuffer to Uint8Array since web workers support passing ArrayBuffers but // not typed arrays const pixelData = new Uint8Array(data.data.pixelData); // TODO switch to promise function finishedCallback(imageFrame) { if (!imageFrame.pixelData) { throw new Error( 'decodeTask: imageFrame.pixelData is undefined after decoding' ); } calculateMinMax(imageFrame, strict); // 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 // ONLY USING setTIMEOUT for TESTING>.. REMOVE THIS // setTimeout(() => { doneCallback(imageFrame, [imageFrame.pixelData]); // }, 100); } decodeImageFrame( data.data.imageFrame, data.data.transferSyntax, pixelData, decodeConfig.decodeTask, data.data.options, finishedCallback ); } export default { taskType: 'decodeTask', handler, initialize, }; </code></pre> </article> </section> </div> <br class="clear"> <footer> Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.6.7</a> using the <a href="https://github.com/clenemt/docdash">docdash</a> theme. </footer> <script>prettyPrint();</script> <script src="scripts/polyfill.js"></script> <script src="scripts/linenumber.js"></script> </body> </html>