All files / packages/core/src/RenderingEngine/helpers/cpuFallback/rendering storedPixelDataToCanvasImageDataPseudocolorLUTPET.ts

0% Statements 0/27
0% Branches 0/4
0% Functions 0/1
0% Lines 0/27

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69                                                                                                                                         
import * as colors from '../colors/index';
import now from './now';
import type { IImage, CPUFallbackLookupTable } from '../../../../types';
 
/**
 *
 * @param {Image} image A Cornerstone Image Object
 * @param {Array} grayscaleLut Lookup table array
 * @param {LookupTable|Array} colorLUT Lookup table array
 * @param {Uint8ClampedArray} canvasImageDataData canvasImageData.data buffer filled with white pixels
 *
 * @returns {void}
 * @memberof Internal
 */
function storedPixelDataToCanvasImageDataPseudocolorLUTPET(
  image: IImage,
  lutFunction: (value: number) => number,
  colorLUT: CPUFallbackLookupTable,
  canvasImageDataData: Uint8ClampedArray
): void {
  let start = now();
  const pixelData = image.getPixelData();
 
  image.stats.lastGetPixelDataTime = now() - start;
 
  const numPixels = pixelData.length;
  const minPixelValue = image.minPixelValue;
  let canvasImageDataIndex = 0;
  let storedPixelDataIndex = 0;
  let grayscale;
  let rgba;
  let clut;
 
  start = now();
 
  if (colorLUT instanceof colors.LookupTable) {
    clut = colorLUT.Table;
  } else {
    clut = colorLUT;
  }
 
  if (minPixelValue < 0) {
    while (storedPixelDataIndex < numPixels) {
      grayscale = lutFunction(
        pixelData[storedPixelDataIndex++] + -minPixelValue
      );
 
      rgba = clut[grayscale];
      canvasImageDataData[canvasImageDataIndex++] = rgba[0];
      canvasImageDataData[canvasImageDataIndex++] = rgba[1];
      canvasImageDataData[canvasImageDataIndex++] = rgba[2];
      canvasImageDataData[canvasImageDataIndex++] = rgba[3];
    }
  } else {
    while (storedPixelDataIndex < numPixels) {
      grayscale = lutFunction(pixelData[storedPixelDataIndex++]);
      rgba = clut[grayscale];
      canvasImageDataData[canvasImageDataIndex++] = rgba[0];
      canvasImageDataData[canvasImageDataIndex++] = rgba[1];
      canvasImageDataData[canvasImageDataIndex++] = rgba[2];
      canvasImageDataData[canvasImageDataIndex++] = rgba[3];
    }
  }
 
  image.stats.lastStoredPixelDataToCanvasImageDataTime = now() - start;
}
 
export default storedPixelDataToCanvasImageDataPseudocolorLUTPET;