UNPKG

cornerstone-web-image-loader

Version:
139 lines (105 loc) 3.2 kB
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>createImage.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> </nav> <div id="main"> <h1 class="page-title">createImage.js</h1> <section> <article> <pre class="prettyprint source linenums"><code>import { external } from './externalModules.js'; const canvas = document.createElement('canvas'); let lastImageIdDrawn; /** * creates a cornerstone Image object for the specified Image and imageId * * @param image - An Image * @param imageId - the imageId for this image * @returns Cornerstone Image Object */ export default function (image, imageId) { // extract the attributes we need const rows = image.naturalHeight; const columns = image.naturalWidth; function getPixelData () { const imageData = getImageData(); return imageData.data; } function getImageData () { let context; if (lastImageIdDrawn === imageId) { context = canvas.getContext('2d'); } else { canvas.height = image.naturalHeight; canvas.width = image.naturalWidth; context = canvas.getContext('2d'); context.drawImage(image, 0, 0); lastImageIdDrawn = imageId; } return context.getImageData(0, 0, image.naturalWidth, image.naturalHeight); } function getCanvas () { if (lastImageIdDrawn === imageId) { return canvas; } canvas.height = image.naturalHeight; canvas.width = image.naturalWidth; const context = canvas.getContext('2d'); context.drawImage(image, 0, 0); lastImageIdDrawn = imageId; return canvas; } // Extract the various attributes we need return { imageId, minPixelValue: 0, maxPixelValue: 255, slope: 1, intercept: 0, windowCenter: 128, windowWidth: 255, render: external.cornerstone.renderWebImage, getPixelData, getCanvas, getImage: () => image, rows, columns, height: rows, width: columns, color: true, rgba: false, columnPixelSpacing: undefined, rowPixelSpacing: undefined, invert: false, sizeInBytes: rows * columns * 4 }; } </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>