UNPKG

cornerstone-wado-image-loader

Version:
218 lines (165 loc) 7 kB
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>shared/decoders/decodeJPEGLS.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">shared/decoders/decodeJPEGLS.js</h1> <section> <article> <pre class="prettyprint source linenums"><code>import charlsFactory from '@cornerstonejs/codec-charls/dist/charlswasm_decode.js'; // import charlsFactory from '@cornerstonejs/codec-charls/dist/debug/charlswasm.js'; // Webpack asset/resource copies this to our output folder import charlsWasm from '@cornerstonejs/codec-charls/dist/charlswasm_decode.wasm'; // import charlsWasm from '@cornerstonejs/codec-charls/dist/debug/charlswasm.wasm'; const local = { codec: undefined, decoder: undefined, decodeConfig: {}, }; function getExceptionMessage(exception) { return typeof exception === 'number' ? local.codec.getExceptionMessage(exception) : exception; } export function initialize(decodeConfig) { local.decodeConfig = decodeConfig; if (local.codec) { return Promise.resolve(); } const charlsModule = charlsFactory({ locateFile: (f) => { if (f.endsWith('.wasm')) { return charlsWasm; } return f; }, }); return new Promise((resolve, reject) => { charlsModule.then((instance) => { local.codec = instance; local.decoder = new instance.JpegLSDecoder(); resolve(); }, reject); }); } /** * * @param {*} compressedImageFrame * @param {object} imageInfo * @param {boolean} imageInfo.signed - (pixelRepresentation === 1) */ async function decodeAsync(compressedImageFrame, imageInfo) { try { await initialize(); const decoder = local.decoder; // get pointer to the source/encoded bit stream buffer in WASM memory // that can hold the encoded bitstream const encodedBufferInWASM = decoder.getEncodedBuffer( compressedImageFrame.length ); // copy the encoded bitstream into WASM memory buffer encodedBufferInWASM.set(compressedImageFrame); // decode it decoder.decode(); // get information about the decoded image const frameInfo = decoder.getFrameInfo(); const interleaveMode = decoder.getInterleaveMode(); const nearLossless = decoder.getNearLossless(); // get the decoded pixels const decodedPixelsInWASM = decoder.getDecodedBuffer(); const encodedImageInfo = { columns: frameInfo.width, rows: frameInfo.height, bitsPerPixel: frameInfo.bitsPerSample, signed: imageInfo.signed, bytesPerPixel: imageInfo.bytesPerPixel, componentsPerPixel: frameInfo.componentCount, }; const pixelData = getPixelData( frameInfo, decodedPixelsInWASM, imageInfo.signed ); const encodeOptions = { nearLossless, interleaveMode, frameInfo, }; // local.codec.doLeakCheck(); return { ...imageInfo, pixelData, imageInfo: encodedImageInfo, encodeOptions, ...encodeOptions, ...encodedImageInfo, }; } catch (error) { // Handle cases where WASM throws an error internally, and it only gives JS a number // See https://emscripten.org/docs/porting/Debugging.html#handling-c-exceptions-from-javascript // TODO: Copy to other codecs as well throw getExceptionMessage(error); } } function getPixelData(frameInfo, decodedBuffer, signed) { if (frameInfo.bitsPerSample > 8) { if (signed) { return new Int16Array( decodedBuffer.buffer, decodedBuffer.byteOffset, decodedBuffer.byteLength / 2 ); } return new Uint16Array( decodedBuffer.buffer, decodedBuffer.byteOffset, decodedBuffer.byteLength / 2 ); } if (signed) { return new Int8Array( decodedBuffer.buffer, decodedBuffer.byteOffset, decodedBuffer.byteLength ); } return new Uint8Array( decodedBuffer.buffer, decodedBuffer.byteOffset, decodedBuffer.byteLength ); } export default decodeAsync; </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>