All files / dicomImageLoader/src/shared/scaling replicate.ts

0% Statements 0/18
0% Branches 0/1
0% Functions 0/1
0% Lines 0/14

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                                                                   
/** Handle replicate scaling.  Use this function for samplesPerPixel>1 */
 
export default function replicate(src, dest) {
  const {
    rows: srcRows,
    columns: srcColumns,
    pixelData: srcData,
    samplesPerPixel = 1,
  } = src;
  const { rows, columns, pixelData } = dest;
 
  const xSrc1Off = [];
 
  // Precompute offsets
  for (let x = 0; x < columns; x++) {
    const xSrc = (x * (srcColumns - 1)) / (columns - 1);
    xSrc1Off[x] = Math.floor(xSrc) * samplesPerPixel;
    // console.log("x src info", x, xSrc, xFrac[x]);
  }
 
  for (let y = 0; y < rows; y++) {
    const ySrc = (y * (srcRows - 1)) / (rows - 1);
    const ySrc1Off = Math.floor(ySrc) * srcColumns * samplesPerPixel;
    const yOff = y * columns;
 
    for (let x = 0; x < columns; x++) {
      for (let sample = 0; sample < samplesPerPixel; sample++) {
        pixelData[yOff + x + sample] = srcData[ySrc1Off + xSrc1Off[x] + sample];
      }
    }
  }
  return pixelData;
}