UNPKG

@cornerstonejs/dicom-image-loader

Version:

Cornerstone Image Loader for DICOM WADO-URI and WADO-RS and Local file

38 lines (37 loc) 1.33 kB
const local = { DecoderClass: undefined, decodeConfig: {}, }; export function initialize(decodeConfig) { local.decodeConfig = decodeConfig; if (local.DecoderClass) { return Promise.resolve(); } return new Promise((resolve, reject) => { import('jpeg-lossless-decoder-js').then(({ Decoder }) => { local.DecoderClass = Decoder; resolve(); }, reject); }); } async function decodeJPEGLossless(imageFrame, pixelData) { await initialize(); if (typeof local.DecoderClass === 'undefined') { throw new Error('No JPEG Lossless decoder loaded'); } const decoder = new local.DecoderClass(); const byteOutput = imageFrame.bitsAllocated <= 8 ? 1 : 2; const buffer = pixelData.buffer; const decompressedData = decoder.decode(buffer, pixelData.byteOffset, pixelData.length, byteOutput); if (imageFrame.pixelRepresentation === 0) { if (imageFrame.bitsAllocated === 16) { imageFrame.pixelData = new Uint16Array(decompressedData.buffer); return imageFrame; } imageFrame.pixelData = new Uint8Array(decompressedData.buffer); return imageFrame; } imageFrame.pixelData = new Int16Array(decompressedData.buffer); return imageFrame; } export default decodeJPEGLossless;