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

57.14% Statements 8/14
54.55% Branches 6/11
100% Functions 1/1
57.14% Lines 8/14
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                                                         
 
 
function decodeJPEGLossless (imageFrame, pixelData) {
  // check to make sure codec is loaded
  Iif (typeof jpeg === 'undefined' ||
    typeof jpeg.lossless === 'undefined' ||
    typeof jpeg.lossless.Decoder === 'undefined') {
    throw new Error('No JPEG Lossless decoder loaded');
  }
 
  const byteOutput = imageFrame.bitsAllocated <= 8 ? 1 : 2;
  // console.time('jpeglossless');
  const buffer = pixelData.buffer;
  const decoder = new jpeg.lossless.Decoder();
  const decompressedData = decoder.decode(buffer, pixelData.byteOffset, pixelData.length, byteOutput);
  // console.timeEnd('jpeglossless');
 
  Iif (imageFrame.pixelRepresentation === 0) {
    if (imageFrame.bitsAllocated === 16) {
      imageFrame.pixelData = new Uint16Array(decompressedData.buffer);
 
      return imageFrame;
    }
    // untested!
    imageFrame.pixelData = new Uint8Array(decompressedData.buffer);
 
    return imageFrame;
 
  }
  imageFrame.pixelData = new Int16Array(decompressedData.buffer);
 
  return imageFrame;
 
}
 
export default decodeJPEGLossless;