all files / src/webWorker/decodeTask/decoders/ decodeBigEndian.js

68.75% Statements 11/16
37.5% Branches 3/8
100% Functions 2/2
68.75% Lines 11/16
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    262144×                                 262144×                    
/* eslint no-bitwise: 0 */
function swap16 (val) {
  return ((val & 0xFF) << 8) |
    ((val >> 8) & 0xFF);
}
 
 
function decodeBigEndian (imageFrame, pixelData) {
  Eif (imageFrame.bitsAllocated === 16) {
    let arrayBuffer = pixelData.buffer;
    let offset = pixelData.byteOffset;
    const length = pixelData.length;
    // if pixel data is not aligned on even boundary, shift it so we can create the 16 bit array
    // buffers on it
 
    Iif (offset % 2) {
      arrayBuffer = arrayBuffer.slice(offset);
      offset = 0;
    }
 
    Iif (imageFrame.pixelRepresentation === 0) {
      imageFrame.pixelData = new Uint16Array(arrayBuffer, offset, length / 2);
    } else {
      imageFrame.pixelData = new Int16Array(arrayBuffer, offset, length / 2);
    }
    // Do the byte swap
    for (let i = 0; i < imageFrame.pixelData.length; i++) {
      imageFrame.pixelData[i] = swap16(imageFrame.pixelData[i]);
    }
 
  } else if (imageFrame.bitsAllocated === 8) {
    imageFrame.pixelData = pixelData;
  }
 
  return imageFrame;
}
 
export default decodeBigEndian;