UNPKG

dcmjs-codecs

Version:

DICOM file and dataset transcoding for Node.js and browser using dcmjs

2 lines 42.9 kB
/*! dcmjs-codecs - 0.0.6 - 2025-05-23 | (c) 2025 Pantelis Georgiadis | https://github.com/PantelisGeorgiadis/dcmjs-codecs */ !function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t(require("dcmjs")):"function"==typeof define&&define.amd?define("dcmjs-codecs",["dcmjs"],t):"object"==typeof exports?exports["dcmjs-codecs"]=t(require("dcmjs")):e.dcmjsCodecs=t(e.dcmjs)}(this,(__WEBPACK_EXTERNAL_MODULE__111__=>(()=>{var __webpack_modules__={25:(module,__unused_webpack_exports,__webpack_require__)=>{const{ErrNo,Jpeg2000ProgressionOrder,JpegSampleFactor,PhotometricInterpretation}=__webpack_require__(492),Context=__webpack_require__(234),log=__webpack_require__(547),wasmFilename="dcmjs-native-codecs.wasm";Object.freeze(wasmFilename);class NativeCodecs{static async initializeAsync(e={}){this.logCodecsInfo=e.logCodecsInfo||!1,this.logCodecsTrace=e.logCodecsTrace||!1,this.webAssemblyModulePathOrUrl=e.webAssemblyModulePathOrUrl;const{instance:t,module:r}=await this._createWebAssemblyInstance(),s=WebAssembly.Module.exports(r).filter((e=>"function"===e.kind)),o={wasmInstance:t,wasmModule:r,wasmMemory:t.exports.memory,wasmEnv:{}};s.forEach((e=>{const r=`wasm${e.name}`;o[r]=t.exports[e.name]})),this.wasmApi=o}static isInitialized(){return void 0!==this.wasmApi}static release(){this.wasmApi=void 0}static decodeRle(e,t){this._throwIfCodecsModuleIsNotInitialized();const r=this._createDecoderContext(e),s=this._createDecoderParameters(t);return this.wasmApi.wasmDecodeRle(r,s),this._releaseDecoderParameters(s),this._releaseDecoderContext(r)}static encodeRle(e,t){this._throwIfCodecsModuleIsNotInitialized();const r=this._createEncoderContext(e),s=this._createEncoderParameters(t);return this.wasmApi.wasmEncodeRle(r,s),this._releaseEncoderParameters(s),this._releaseEncoderContext(r)}static decodeJpeg(e,t){this._throwIfCodecsModuleIsNotInitialized();const r=this._createDecoderContext(e),s=this._createDecoderParameters(t);return this.wasmApi.wasmDecodeJpeg(r,s),this._releaseDecoderParameters(s),this._releaseDecoderContext(r)}static encodeJpeg(e,t){this._throwIfCodecsModuleIsNotInitialized();const r=this._createEncoderContext(e),s=this._createEncoderParameters(t);return this.wasmApi.wasmEncodeJpeg(r,s),this._releaseEncoderParameters(s),this._releaseEncoderContext(r)}static decodeJpegLs(e,t){this._throwIfCodecsModuleIsNotInitialized();const r=this._createDecoderContext(e),s=this._createDecoderParameters(t);return this.wasmApi.wasmDecodeJpegLs(r,s),this._releaseDecoderParameters(s),this._releaseDecoderContext(r)}static encodeJpegLs(e,t){this._throwIfCodecsModuleIsNotInitialized();const r=this._createEncoderContext(e),s=this._createEncoderParameters(t);return this.wasmApi.wasmEncodeJpegLs(r,s),this._releaseEncoderParameters(s),this._releaseEncoderContext(r)}static decodeJpeg2000(e,t){this._throwIfCodecsModuleIsNotInitialized();const r=this._createDecoderContext(e),s=this._createDecoderParameters(t);return this.wasmApi.wasmDecodeJpeg2000(r,s),this._releaseDecoderParameters(s),this._releaseDecoderContext(r)}static encodeJpeg2000(e,t){this._throwIfCodecsModuleIsNotInitialized();const r=this._createEncoderContext(e),s=this._createEncoderParameters(t);return this.wasmApi.wasmEncodeJpeg2000(r,s),this._releaseEncoderParameters(s),this._releaseEncoderContext(r)}static decodeHtJpeg2000(e,t){this._throwIfCodecsModuleIsNotInitialized();const r=this._createDecoderContext(e),s=this._createDecoderParameters(t);return this.wasmApi.wasmDecodeHtJpeg2000(r,s),this._releaseDecoderParameters(s),this._releaseDecoderContext(r)}static encodeHtJpeg2000(e,t){this._throwIfCodecsModuleIsNotInitialized();const r=this._createEncoderContext(e),s=this._createEncoderParameters(t);return this.wasmApi.wasmEncodeHtJpeg2000(r,s),this._releaseEncoderParameters(s),this._releaseEncoderContext(r)}static _createDecoderContext(e){this._throwIfCodecsModuleIsNotInitialized(),e.validate();const t=this.wasmApi.wasmCreateCodecsContext();this.wasmApi.wasmSetColumns(t,e.getWidth()),this.wasmApi.wasmSetRows(t,e.getHeight()),this.wasmApi.wasmSetBitsAllocated(t,e.getBitsAllocated()),this.wasmApi.wasmSetBitsStored(t,e.getBitsStored()),this.wasmApi.wasmSetSamplesPerPixel(t,e.getSamplesPerPixel()),this.wasmApi.wasmSetPixelRepresentation(t,e.getPixelRepresentation()),this.wasmApi.wasmSetPlanarConfiguration(t,e.getPlanarConfiguration()),this.wasmApi.wasmSetPhotometricInterpretation(t,Object.values(PhotometricInterpretation).indexOf(e.getPhotometricInterpretation()));const r=e.getEncodedBuffer();this.wasmApi.wasmSetEncodedBufferSize(t,r.length);const s=this.wasmApi.wasmGetEncodedBuffer(t);return new Uint8Array(this.wasmApi.wasmMemory.buffer).set(r,s),t}static _createEncoderContext(e){this._throwIfCodecsModuleIsNotInitialized(),e.validate();const t=this.wasmApi.wasmCreateCodecsContext();this.wasmApi.wasmSetColumns(t,e.getWidth()),this.wasmApi.wasmSetRows(t,e.getHeight()),this.wasmApi.wasmSetBitsAllocated(t,e.getBitsAllocated()),this.wasmApi.wasmSetBitsStored(t,e.getBitsStored()),this.wasmApi.wasmSetSamplesPerPixel(t,e.getSamplesPerPixel()),this.wasmApi.wasmSetPixelRepresentation(t,e.getPixelRepresentation()),this.wasmApi.wasmSetPlanarConfiguration(t,e.getPlanarConfiguration()),this.wasmApi.wasmSetPhotometricInterpretation(t,Object.values(PhotometricInterpretation).indexOf(e.getPhotometricInterpretation()));const r=e.getDecodedBuffer();this.wasmApi.wasmSetDecodedBufferSize(t,r.length);const s=this.wasmApi.wasmGetDecodedBuffer(t);return new Uint8Array(this.wasmApi.wasmMemory.buffer).set(r,s),t}static _releaseDecoderContext(e){this._throwIfCodecsModuleIsNotInitialized();const t=this.wasmApi.wasmGetDecodedBuffer(e),r=this.wasmApi.wasmGetDecodedBufferSize(e),s=new Uint8Array(this.wasmApi.wasmMemory.buffer),o=new Uint8Array(s.buffer,t,r).slice(0),i=new Context({width:this.wasmApi.wasmGetColumns(e),height:this.wasmApi.wasmGetRows(e),bitsAllocated:this.wasmApi.wasmGetBitsAllocated(e),bitsStored:this.wasmApi.wasmGetBitsStored(e),samplesPerPixel:this.wasmApi.wasmGetSamplesPerPixel(e),pixelRepresentation:this.wasmApi.wasmGetPixelRepresentation(e),planarConfiguration:this.wasmApi.wasmGetPlanarConfiguration(e),photometricInterpretation:Object.values(PhotometricInterpretation)[this.wasmApi.wasmGetPhotometricInterpretation(e)],decodedBuffer:o});return this.wasmApi.wasmReleaseCodecsContext(e),i}static _releaseEncoderContext(e){this._throwIfCodecsModuleIsNotInitialized();const t=this.wasmApi.wasmGetEncodedBuffer(e),r=this.wasmApi.wasmGetEncodedBufferSize(e),s=new Uint8Array(this.wasmApi.wasmMemory.buffer),o=new Uint8Array(s.buffer,t,r).slice(0),i=new Context({width:this.wasmApi.wasmGetColumns(e),height:this.wasmApi.wasmGetRows(e),bitsAllocated:this.wasmApi.wasmGetBitsAllocated(e),bitsStored:this.wasmApi.wasmGetBitsStored(e),samplesPerPixel:this.wasmApi.wasmGetSamplesPerPixel(e),pixelRepresentation:this.wasmApi.wasmGetPixelRepresentation(e),planarConfiguration:this.wasmApi.wasmGetPlanarConfiguration(e),photometricInterpretation:Object.values(PhotometricInterpretation)[this.wasmApi.wasmGetPhotometricInterpretation(e)],encodedBuffer:o});return this.wasmApi.wasmReleaseCodecsContext(e),i}static _createDecoderParameters(e={}){this._throwIfCodecsModuleIsNotInitialized();const t=this.wasmApi.wasmCreateDecoderParameters();return this.wasmApi.wasmSetConvertColorspaceToRgb(t,e.convertColorspaceToRgb||!1),t}static _createEncoderParameters(e={}){this._throwIfCodecsModuleIsNotInitialized();const t=this.wasmApi.wasmCreateEncoderParameters();return this.wasmApi.wasmSetLossy(t,e.lossy||!1),this.wasmApi.wasmSetQuality(t,e.quality??90),this.wasmApi.wasmSetSmoothingFactor(t,e.smoothingFactor??0),this.wasmApi.wasmSetSampleFactor(t,Object.values(JpegSampleFactor).indexOf(e.sampleFactor??JpegSampleFactor.Sf444)),this.wasmApi.wasmSetPredictor(t,e.predictor??1),this.wasmApi.wasmSetPointTransform(t,e.pointTransform??0),this.wasmApi.wasmSetAllowedLossyError(t,e.allowedLossyError??10),this.wasmApi.wasmSetProgressionOrder(t,Object.values(Jpeg2000ProgressionOrder).indexOf(e.progressionOrder??Jpeg2000ProgressionOrder.Lrcp)),this.wasmApi.wasmSetRate(t,e.rate??20),this.wasmApi.wasmSetAllowMct(t,e.allowMct??1),t}static _releaseDecoderParameters(e){this._throwIfCodecsModuleIsNotInitialized(),this.wasmApi.wasmReleaseDecoderParameters(e)}static _releaseEncoderParameters(e){this._throwIfCodecsModuleIsNotInitialized(),this.wasmApi.wasmReleaseEncoderParameters(e)}static async _createWebAssemblyInstance(){const e={wasi_snapshot_preview1:{environ_get:(e,t)=>{this._throwIfCodecsModuleIsNotInitialized();const r=new Uint8Array(this.wasmApi.wasmMemory.buffer),s=new DataView(this.wasmApi.wasmMemory.buffer),o=this.wasmApi.wasmEnv;return Object.keys(o).forEach((i=>{s.setUint32(e,t,!0),e+=4;const n=this._stringToBytes(`${i}=${o[i]}\0`);r.set(n,t),t+=n.length})),ErrNo.Success},environ_sizes_get:(e,t)=>{this._throwIfCodecsModuleIsNotInitialized();const r=new DataView(this.wasmApi.wasmMemory.buffer),s=this.wasmApi.wasmEnv;return r.setUint32(e,Object.keys(s).length,!0),r.setUint32(t,Object.keys(s).reduce(((e,t)=>e+this._stringToBytes(`${t}=${s[t]}\0`).length),0),!0),ErrNo.Success},proc_exit:e=>{throw new Error(`WebAssembly module exited with return value ${e}`)},fd_write:(e,t,r,s)=>{if(this._throwIfCodecsModuleIsNotInitialized(),1!==e&&2!==e)return ErrNo.BadFileDescriptor;const o=new DataView(this.wasmApi.wasmMemory.buffer);let i=0;for(let e=0;e<r;e++){const e=o.getUint32(t,!0);t+=4;const r=o.getUint32(t,!0);t+=4;const s=this._wasmToJsString(e,r);log.error(`NativeCodecs::fd_write::${s}`),i+=r}return o.setUint32(s,i,!0),ErrNo.Success},fd_seek:(e,t,r,s)=>ErrNo.Success,fd_close:e=>ErrNo.Success},env:{emscripten_notify_memory_growth:e=>{},onCodecsInfo:(e,t)=>{if(!this.logCodecsInfo)return;const r=this._wasmToJsString(e,t);log.info(`NativeCodecs::onCodecsInfo::${r}`)},onCodecsTrace:(e,t)=>{if(!this.logCodecsTrace)return;const r=this._wasmToJsString(e,t);log.info(`NativeCodecs::onCodecsTrace::${r}`)},onCodecsException:(e,t)=>{const r=this._wasmToJsString(e,t);throw new Error(r)}}},t=await this._getWebAssemblyBytes(),{instance:r,module:s}=await WebAssembly.instantiate(t,e);return{instance:r,module:s}}static async _getWebAssemblyBytes(){const isNodeJs=!("undefined"==typeof process||!process.versions||!process.versions.node);if(!isNodeJs){const response=await eval("fetch(this.webAssemblyModulePathOrUrl || wasmFilename)"),responseArrayBuffer=await response.arrayBuffer();return responseArrayBuffer}const fs=eval("require('fs')"),path=eval("require('path')"),buffer=await fs.promises.readFile(this.webAssemblyModulePathOrUrl||path.resolve(__dirname,wasmFilename));return buffer.buffer.slice(buffer.byteOffset,buffer.byteOffset+buffer.byteLength)}static _wasmToJsString(e,t){this._throwIfCodecsModuleIsNotInitialized();const r=new Uint8Array(this.wasmApi.wasmMemory.buffer),s=new Uint8Array(r.buffer,e,t);let o="";for(let e=0;e<t;e++)o+=String.fromCharCode(s[e]);return o}static _stringToBytes(e){return e.split("").map((e=>e.charCodeAt(0)))}static _throwIfCodecsModuleIsNotInitialized(){if(!this.wasmApi)throw new Error("Native codecs module is not initialized")}}module.exports=NativeCodecs},111:e=>{"use strict";e.exports=__WEBPACK_EXTERNAL_MODULE__111__},190:(e,t,r)=>{const{Implementation:s,StorageClass:o,TranscodeMap:i,TransferSyntax:n}=r(492),{Codec:a}=r(258),l=r(111),{DicomDict:c,DicomMessage:d,DicomMetaDictionary:p,ReadBufferStream:h,WriteBufferStream:m}=l.data,u=l.log;e.exports=class{constructor(e,t,r={}){r={ignoreErrors:!0,...r},u.level="error",this.transferSyntaxUid=t||n.ImplicitVRLittleEndian,e instanceof ArrayBuffer?t?this._fromElementsBuffer(e,t,r):this._fromP10Buffer(e):this.elements=e||{}}transcode(e,t={}){if(!e)throw new Error("New transfer syntax UID is required");let r=this.getTransferSyntaxUid();if(r===e)return;const s=i.find((e=>e.syntax===r)),o=i.find((t=>t.syntax===e));if(!s||!o)throw new Error(`A transfer syntax transcoding from ${r} to ${e} is currently not supported`);if(s.encapsulated&&o.encapsulated&&(this.transcode(n.ExplicitVRLittleEndian,t),r=n.ExplicitVRLittleEndian),this._getElement("PixelData")){const i=this._getElement("BitsAllocated");if(8!==i&&16!==i)throw new Error(`Transcoding is supported for 8 and 16 bits allocated [bits: ${i}]`);let n=this.getElements();if(s.encapsulated||s.bigEndian){n=a.getCodec(r).decode(n,r,t)}if(o.encapsulated||o.bigEndian){n=a.getCodec(e).encode(n,r,t)}this.elements=n}this.transferSyntaxUid=e}getTransferSyntaxUid(){return this.transferSyntaxUid}getElements(){return this.elements}getDicomDataset(e,t){e={fragmentMultiframe:!1,...e};const r=t?p.denaturalizeDataset(this.getElements(),{...p.nameMap,...t}):p.denaturalizeDataset(this.getElements()),s=new m;return d.write(r,s,this.transferSyntaxUid,e),s.getBuffer()}getDicomPart10(e,t){e={fragmentMultiframe:!1,...e};const r={_meta:{FileMetaInformationVersion:new Uint8Array([0,1]).buffer,MediaStorageSOPClassUID:this._getElement("SOPClassUID")||o.SecondaryCaptureImageStorage,MediaStorageSOPInstanceUID:this._getElement("SOPInstanceUID")||p.uid(),TransferSyntaxUID:this.getTransferSyntaxUid(),ImplementationClassUID:s.ImplementationClassUid,ImplementationVersionName:s.ImplementationVersion},...this.getElements()},i=p.denaturalizeDataset(r._meta),n=new c(i);return n.dict=t?p.denaturalizeDataset(r,{...p.nameMap,...t}):p.denaturalizeDataset(r),n.write(e)}_getElement(e){return this.elements[e]}_fromP10Buffer(e,t){const r=d.readFile(e,t),s=p.naturalizeDataset(r.meta).TransferSyntaxUID,o=p.naturalizeDataset(r.dict);this.elements=o,this.transferSyntaxUid=s}_fromElementsBuffer(e,t,r){const s=new h(e),o=t===n.ImplicitVRLittleEndian?n.ImplicitVRLittleEndian:t===n.ExplicitVRBigEndian?n.ExplicitVRBigEndian:n.ExplicitVRLittleEndian,i=d._read(s,o,r);this.elements=p.naturalizeDataset(i),this.transferSyntaxUid=t}}},213:function(e,t,r){var s,o;!function(){"use strict";s=function(){var e=function(){},t="undefined",r=typeof window!==t&&typeof window.navigator!==t&&/Trident\/|MSIE /.test(window.navigator.userAgent),s=["trace","debug","info","warn","error"],o={},i=null;function n(e,t){var r=e[t];if("function"==typeof r.bind)return r.bind(e);try{return Function.prototype.bind.call(r,e)}catch(t){return function(){return Function.prototype.apply.apply(r,[e,arguments])}}}function a(){console.log&&(console.log.apply?console.log.apply(console,arguments):Function.prototype.apply.apply(console.log,[console,arguments])),console.trace&&console.trace()}function l(s){return"debug"===s&&(s="log"),typeof console!==t&&("trace"===s&&r?a:void 0!==console[s]?n(console,s):void 0!==console.log?n(console,"log"):e)}function c(){for(var r=this.getLevel(),o=0;o<s.length;o++){var i=s[o];this[i]=o<r?e:this.methodFactory(i,r,this.name)}if(this.log=this.debug,typeof console===t&&r<this.levels.SILENT)return"No console available for logging"}function d(e){return function(){typeof console!==t&&(c.call(this),this[e].apply(this,arguments))}}function p(e,t,r){return l(e)||d.apply(this,arguments)}function h(e,r){var n,a,l,d=this,h="loglevel";function m(e){var r=(s[e]||"silent").toUpperCase();if(typeof window!==t&&h){try{return void(window.localStorage[h]=r)}catch(e){}try{window.document.cookie=encodeURIComponent(h)+"="+r+";"}catch(e){}}}function u(){var e;if(typeof window!==t&&h){try{e=window.localStorage[h]}catch(e){}if(typeof e===t)try{var r=window.document.cookie,s=encodeURIComponent(h),o=r.indexOf(s+"=");-1!==o&&(e=/^([^;]+)/.exec(r.slice(o+s.length+1))[1])}catch(e){}return void 0===d.levels[e]&&(e=void 0),e}}function g(){if(typeof window!==t&&h){try{window.localStorage.removeItem(h)}catch(e){}try{window.document.cookie=encodeURIComponent(h)+"=; expires=Thu, 01 Jan 1970 00:00:00 UTC"}catch(e){}}}function f(e){var t=e;if("string"==typeof t&&void 0!==d.levels[t.toUpperCase()]&&(t=d.levels[t.toUpperCase()]),"number"==typeof t&&t>=0&&t<=d.levels.SILENT)return t;throw new TypeError("log.setLevel() called with invalid level: "+e)}"string"==typeof e?h+=":"+e:"symbol"==typeof e&&(h=void 0),d.name=e,d.levels={TRACE:0,DEBUG:1,INFO:2,WARN:3,ERROR:4,SILENT:5},d.methodFactory=r||p,d.getLevel=function(){return null!=l?l:null!=a?a:n},d.setLevel=function(e,t){return l=f(e),!1!==t&&m(l),c.call(d)},d.setDefaultLevel=function(e){a=f(e),u()||d.setLevel(e,!1)},d.resetLevel=function(){l=null,g(),c.call(d)},d.enableAll=function(e){d.setLevel(d.levels.TRACE,e)},d.disableAll=function(e){d.setLevel(d.levels.SILENT,e)},d.rebuild=function(){if(i!==d&&(n=f(i.getLevel())),c.call(d),i===d)for(var e in o)o[e].rebuild()},n=f(i?i.getLevel():"WARN");var w=u();null!=w&&(l=f(w)),c.call(d)}(i=new h).getLogger=function(e){if("symbol"!=typeof e&&"string"!=typeof e||""===e)throw new TypeError("You must supply a name when creating a logger.");var t=o[e];return t||(t=o[e]=new h(e,i.methodFactory)),t};var m=typeof window!==t?window.log:void 0;return i.noConflict=function(){return typeof window!==t&&window.log===i&&(window.log=m),i},i.getLoggers=function(){return o},i.default=i,i},void 0===(o="function"==typeof s?s.call(t,r,t,e):s)||(e.exports=o)}()},234:(e,t,r)=>{const{PhotometricInterpretation:s}=r(492);class o{constructor(e={}){const{width:t,height:r,bitsAllocated:s,bitsStored:o,samplesPerPixel:i,pixelRepresentation:n,planarConfiguration:a,photometricInterpretation:l,encodedBuffer:c,decodedBuffer:d}=e;this.width=t,this.height=r,this.bitsAllocated=s,this.bitsStored=o,this.samplesPerPixel=i,this.pixelRepresentation=n,this.planarConfiguration=a,this.photometricInterpretation=l,this.encodedBuffer=c,this.decodedBuffer=d}getWidth(){return this.width}setWidth(e){this.width=e}getHeight(){return this.height}setHeight(e){this.height=e}getBitsStored(){return this.bitsStored}setBitsStored(e){this.bitsStored=e}getBitsAllocated(){return this.bitsAllocated}setBitsAllocated(e){this.bitsAllocated=e}getSamplesPerPixel(){return this.samplesPerPixel}setSamplesPerPixel(e){this.samplesPerPixel=e}getPixelRepresentation(){return this.pixelRepresentation}setPixelRepresentation(e){this.pixelRepresentation=e}getPlanarConfiguration(){return this.planarConfiguration}setPlanarConfiguration(e){this.planarConfiguration=e}getPhotometricInterpretation(){return this.photometricInterpretation}setPhotometricInterpretation(e){this.photometricInterpretation=e}getEncodedBuffer(){return this.encodedBuffer}setEncodedBuffer(e){this.encodedBuffer=e}getDecodedBuffer(){return this.decodedBuffer}setDecodedBuffer(e){this.decodedBuffer=e}validate(){if(!this.getWidth())throw new Error(`Width has an invalid value [${this.getWidth()}]`);if(!this.getHeight())throw new Error(`Height has an invalid value [${this.getHeight()}]`);if(!this.getBitsStored())throw new Error(`Bits stored has an invalid value [${this.getBitsStored()}]`);if(!this.getBitsAllocated())throw new Error(`Bits allocated has an invalid value [${this.getBitsAllocated()}]`);if(!this.getSamplesPerPixel())throw new Error(`Sample per pixel has an invalid value [${this.getSamplesPerPixel()}]`);if(void 0===this.getPixelRepresentation())throw new Error(`Pixel representation has an invalid value [${this.getSamplesPerPixel()}]`);if(!Object.values(s).includes(this.getPhotometricInterpretation()))throw new Error(`Photometric interpretation has an invalid value [${this.getPhotometricInterpretation()}]`)}static fromDicomElements(e){const t=new o({width:e.Columns,height:e.Rows,bitsAllocated:e.BitsAllocated,bitsStored:e.BitsStored,samplesPerPixel:e.SamplesPerPixel,pixelRepresentation:e.PixelRepresentation,planarConfiguration:e.PlanarConfiguration,photometricInterpretation:e.PhotometricInterpretation});return void 0!==e.PlanarConfiguration&&t.setPlanarConfiguration(e.PlanarConfiguration),t}toDicomElements(){const e={Columns:this.getWidth(),Rows:this.getHeight(),BitsAllocated:this.getBitsAllocated(),BitsStored:this.getBitsStored(),SamplesPerPixel:this.getSamplesPerPixel(),PixelRepresentation:this.getPixelRepresentation(),PhotometricInterpretation:this.getPhotometricInterpretation()};return void 0!==this.getPlanarConfiguration()&&(e.PlanarConfiguration=this.getPlanarConfiguration()),e}toString(){return`Width: ${this.getWidth()}, Height: ${this.getHeight()}, Bits Stored: ${this.getBitsStored()}, Bits Allocated: ${this.getBitsAllocated()}, Samples per Pixel: ${this.getSamplesPerPixel()}, Pixel Representation: ${this.getPixelRepresentation()}, Planar Configuration: ${this.getPlanarConfiguration()}, Photometric Interpretation: ${this.getPhotometricInterpretation()}`}}e.exports=o},237:(e,t,r)=>{const{Codec:s,ExplicitVRBigEndianCodec:o,ExplicitVRLittleEndianCodec:i,HtJpeg2000LosslessCodec:n,HtJpeg2000LosslessRpclCodec:a,HtJpeg2000LossyCodec:l,ImplicitVRLittleEndianCodec:c,Jpeg2000LosslessCodec:d,Jpeg2000LossyCodec:p,JpegBaselineProcess1Codec:h,JpegLosslessProcess14V1Codec:m,JpegLsLosslessCodec:u,JpegLsLossyCodec:g,RleLosslessCodec:f}=r(258),{Jpeg2000ProgressionOrder:w,JpegSampleFactor:P,PhotometricInterpretation:y,PixelRepresentation:x,PlanarConfiguration:C,TransferSyntax:b}=r(492),_=r(234),I=r(25),A=r(190),S={codecs:{Codec:s,ExplicitVRBigEndianCodec:o,ExplicitVRLittleEndianCodec:i,HtJpeg2000LosslessCodec:n,HtJpeg2000LosslessRpclCodec:a,HtJpeg2000LossyCodec:l,ImplicitVRLittleEndianCodec:c,Jpeg2000LosslessCodec:d,Jpeg2000LossyCodec:p,JpegBaselineProcess1Codec:h,JpegLosslessProcess14V1Codec:m,JpegLsLosslessCodec:u,JpegLsLossyCodec:g,RleLosslessCodec:f},constants:{Jpeg2000ProgressionOrder:w,JpegSampleFactor:P,PhotometricInterpretation:y,PixelRepresentation:x,PlanarConfiguration:C,TransferSyntax:b},Context:_,log:r(547),NativeCodecs:I,Transcoder:A,version:r(837)};e.exports=S},258:(e,t,r)=>{const{Jpeg2000ProgressionOrder:s,JpegSampleFactor:o,PhotometricInterpretation:i,PlanarConfiguration:n,TransferSyntax:a}=r(492),{FrameConverter:l,Frames:c}=r(859),d=r(234),p=r(25),h=r(984);class m{encode(e,t,r={}){throw new Error("encode should be implemented")}decode(e,t,r={}){throw new Error("decode should be implemented")}static getCodec(e){const t={[a.ImplicitVRLittleEndian]:u,[a.ExplicitVRLittleEndian]:g,[a.ExplicitVRBigEndian]:f,[a.RleLossless]:w,[a.JpegBaselineProcess1]:y,[a.JpegLosslessProcess14V1]:x,[a.JpegLsLossless]:b,[a.JpegLsLossy]:_,[a.Jpeg2000Lossless]:A,[a.Jpeg2000Lossy]:S,[a.HtJpeg2000Lossless]:E,[a.HtJpeg2000LosslessRpcl]:v,[a.HtJpeg2000Lossy]:B}[e];if(!t)throw new Error(`Codec for transfer syntax UID ${e} is not implemented`);return new t}_baseEncodeImpl(e,t,r,s={}){const o=new c(e,t),i=o.getNumberOfFrames(),a=[];for(let t=0;t<i;t++){let i=o.getFrameBuffer(t);s.unpackLow16&&(i=l.unpackLow16(i)),s.convertYbrFullToRgb&&(i=l.ybrFullToRgb(i)),s.convertYbrFull422ToRgb&&(i=l.ybrFull422ToRgb(i,o.getWidth())),s.updatePlanarConfiguration&&(i=l.changePlanarConfiguration(i,e.BitsAllocated,e.SamplesPerPixel,n.Planar));const c=d.fromDicomElements(e);c.setDecodedBuffer(i);const m=p[r](c,s);let u=m.getEncodedBuffer();u.length%2!=0&&(u=h.concatBuffers([u,Uint8Array.from([0])])),a.push(u.buffer.slice(u.byteOffset,u.byteOffset+u.byteLength)),Object.assign(e,m.toDicomElements())}return e._vrMap={PixelData:1===o.getBytesAllocated()?"OB":"OW"},e.PixelData=a,e}_baseDecodeImpl(e,t,r,s={}){const o=new c(e,t),i=o.getNumberOfFrames(),a=[];for(let t=0;t<i;t++){const i=o.getFrameBuffer(t),c=d.fromDicomElements(e);c.setEncodedBuffer(i);const m=p[r](c,s);let u=m.getDecodedBuffer();u.length%2!=0&&(u=h.concatBuffers([u,Uint8Array.from([0])])),s.updatePlanarConfiguration&&(u=l.changePlanarConfiguration(u,e.BitsAllocated,e.SamplesPerPixel,n.Interleaved)),a.push(u.buffer.slice(u.byteOffset,u.byteOffset+u.byteLength)),Object.assign(e,m.toDicomElements())}return e._vrMap={PixelData:1===o.getBytesAllocated()?"OB":"OW"},e.PixelData=[h.concatBuffers(a)],e}}class u extends m{encode(e,t,r={}){return e}decode(e,t,r={}){return e}}class g extends m{encode(e,t,r={}){return e}decode(e,t,r={}){return e}}class f extends m{encode(e,t,r={}){return this._swapPixelData(e,t)}decode(e,t,r={}){return this._swapPixelData(e,t)}_swapPixelData(e,t){const r=new c(e,t),s=r.getNumberOfFrames(),o=[];for(let e=0;e<s;e++){const t=r.getFrameBuffer(e);if(r.getBitsAllocated()>8&&r.getBitsAllocated()<=16)for(let e=0;e<t.length;e+=2){const r=t[e];t[e]=t[e+1],t[e+1]=r}o.push(t.buffer.slice(t.byteOffset,t.byteOffset+t.byteLength))}return e._vrMap={PixelData:1===r.getBytesAllocated()?"OB":"OW"},e.PixelData=[h.concatBuffers(o)],e}}class w extends m{encode(e,t,r={}){return this._baseEncodeImpl(e,t,"encodeRle",r)}decode(e,t,r={}){return this._baseDecodeImpl(e,t,"decodeRle",r)}}class P extends m{encode(e,t,r={}){const s={...r};if(e.PhotometricInterpretation===i.YbrIct||e.PhotometricInterpretation===i.YbrRct)throw new Error(`Photometric Interpretation ${e.PhotometricInterpretation} not supported by JPEG encoder`);const a=(Array.isArray(e.PixelData)?e.PixelData:[e.PixelData]).reduce(((e,t)=>e+t.byteLength),0);if(16===e.BitsAllocated&&e.BitsStored<=8&&(s.unpackLow16=!0),e.PhotometricInterpretation===i.YbrFull422&&(s.convertYbrFull422ToRgb=!0),e.PlanarConfiguration===n.Planar&&e.SamplesPerPixel>1){if(3!==e.SamplesPerPixel||e.BitsStored>8)throw new Error("Planar reconfiguration only implemented for SamplesPerPixel = 3 and BitsStored <= 8");s.updatePlanarConfiguration=!0}const l=super._baseEncodeImpl(e,t,"encodeJpeg",s);void 0!==s.updatePlanarConfiguration&&s.updatePlanarConfiguration&&(l.PlanarConfiguration=n.Interleaved),e.PhotometricInterpretation===i.Rgb&&(l.PhotometricInterpretation=i.YbrFull422,void 0!==s.sampleFactor&&s.sampleFactor===o.Sf444&&(l.PhotometricInterpretation=i.YbrFull)),e.PhotometricInterpretation===i.YbrFull422&&(l.PhotometricInterpretation=i.Rgb);const c=(Array.isArray(l.PixelData)?l.PixelData:[l.PixelData]).reduce(((e,t)=>e+t.byteLength),0);return void 0!==s.lossy&&s.lossy&&(l.LossyImageCompressionMethod="ISO_10918_1",l.LossyImageCompression="01",l.LossyImageCompressionRatio=`${(a/c).toFixed(3)}`,l.SOPInstanceUID=h.generateDerivedUid()),l}decode(e,t,r={}){const s={...r};if(e.PhotometricInterpretation!==i.Rgb&&(s.convertColorspaceToRgb=!0),e.PlanarConfiguration===n.Planar&&e.SamplesPerPixel>1){if(3!==e.SamplesPerPixel||e.BitsStored>8)throw new Error("Planar reconfiguration only implemented for SamplesPerPixel = 3 and BitsStored <= 8");s.updatePlanarConfiguration=!0}return super._baseDecodeImpl(e,t,"decodeJpeg",s)}}class y extends P{encode(e,t,r={}){if(r.lossy=!0,r.predictor=0,r.pointTransform=0,8!==e.BitsStored)throw new Error(`Unable to create JpegBaselineProcess1Codec for bits stored ${e.BitsStored}`);return super.encode(e,t,r)}decode(e,t,r={}){return r.convertColorspaceToRgb=!0,super.decode(e,t,r)}}class x extends P{encode(e,t,r={}){return r.lossy=!1,r.predictor=1,r.pointTransform=0,super.encode(e,t,r)}decode(e,t,r={}){return super.decode(e,t,r)}}class C extends m{encode(e,t,r={}){const s={...r};if(e.PhotometricInterpretation===i.YbrPartial422||e.PhotometricInterpretation===i.YbrPartial420)throw new Error(`Photometric Interpretation ${e.PhotometricInterpretation} not supported by JPEG-LS encoder`);const o=(Array.isArray(e.PixelData)?e.PixelData:[e.PixelData]).reduce(((e,t)=>e+t.byteLength),0);if(e.PhotometricInterpretation===i.YbrFull&&(s.convertYbrFullToRgb=!0),e.PhotometricInterpretation===i.YbrFull422&&(s.convertYbrFull422ToRgb=!0),e.PlanarConfiguration===n.Planar&&e.SamplesPerPixel>1){if(3!==e.SamplesPerPixel||e.BitsStored>8)throw new Error("Planar reconfiguration only implemented for SamplesPerPixel = 3 and BitsStored <= 8");s.updatePlanarConfiguration=!0}const a=super._baseEncodeImpl(e,t,"encodeJpegLs",s);void 0!==s.updatePlanarConfiguration&&s.updatePlanarConfiguration&&(a.PlanarConfiguration=n.Interleaved);const l=(Array.isArray(a.PixelData)?a.PixelData:[a.PixelData]).reduce(((e,t)=>e+t.byteLength),0);return void 0!==s.lossy&&s.lossy&&(a.LossyImageCompressionMethod="ISO_14495_1",a.LossyImageCompression="01",a.LossyImageCompressionRatio=`${(o/l).toFixed(3)}`,a.SOPInstanceUID=h.generateDerivedUid()),a}decode(e,t,r={}){const s={...r};if(e.PlanarConfiguration===n.Planar&&e.SamplesPerPixel>1){if(3!==e.SamplesPerPixel||e.BitsStored>8)throw new Error("Planar reconfiguration only implemented for SamplesPerPixel = 3 and BitsStored <= 8");s.updatePlanarConfiguration=!0}return super._baseDecodeImpl(e,t,"decodeJpegLs",s)}}class b extends C{encode(e,t,r={}){return r.lossy=!1,super.encode(e,t,r)}decode(e,t,r={}){return super.decode(e,t,r)}}class _ extends C{encode(e,t,r={}){return r.lossy=!0,super.encode(e,t,r)}decode(e,t,r={}){return super.decode(e,t,r)}}class I extends m{encode(e,t,r,s={}){const o={...s};if(e.PhotometricInterpretation===i.YbrPartial422||e.PhotometricInterpretation===i.YbrPartial420)throw new Error(`Photometric Interpretation ${e.PhotometricInterpretation} not supported by JPEG 2000 encoder`);const a=(Array.isArray(e.PixelData)?e.PixelData:[e.PixelData]).reduce(((e,t)=>e+t.byteLength),0);if(e.PhotometricInterpretation===i.YbrFull&&(o.convertYbrFullToRgb=!0),e.PhotometricInterpretation===i.YbrFull422&&(o.convertYbrFull422ToRgb=!0),e.PlanarConfiguration===n.Planar&&e.SamplesPerPixel>1){if(3!==e.SamplesPerPixel||e.BitsStored>8)throw new Error("Planar reconfiguration only implemented for SamplesPerPixel = 3 and BitsStored <= 8");o.updatePlanarConfiguration=!0}const l=super._baseEncodeImpl(e,t,r,o);void 0!==o.updatePlanarConfiguration&&o.updatePlanarConfiguration&&(l.PlanarConfiguration=n.Interleaved),e.PhotometricInterpretation!==i.Rgb&&e.PhotometricInterpretation!=i.YbrFull&&e.PhotometricInterpretation!=i.YbrFull422||void 0!==o.allowMct&&o.allowMct&&(void 0!==o.lossy&&o.lossy?l.PhotometricInterpretation=i.YbrIct:l.PhotometricInterpretation=i.YbrRct);const c=(Array.isArray(l.PixelData)?l.PixelData:[l.PixelData]).reduce(((e,t)=>e+t.byteLength),0);return void 0!==o.lossy&&o.lossy&&(l.LossyImageCompressionMethod="ISO_15444_1",l.LossyImageCompression="01",l.LossyImageCompressionRatio=`${(a/c).toFixed(3)}`,l.SOPInstanceUID=h.generateDerivedUid()),l}decode(e,t,r,s={}){const o={...s};if(e.PlanarConfiguration===n.Planar&&e.SamplesPerPixel>1){if(3!==e.SamplesPerPixel||e.BitsStored>8)throw new Error("Planar reconfiguration only implemented for SamplesPerPixel = 3 and BitsStored <= 8");o.updatePlanarConfiguration=!0}const a=super._baseDecodeImpl(e,t,r,o);return a.PhotometricInterpretation!=i.YbrIct&&a.PhotometricInterpretation!=i.YbrRct||(a.PhotometricInterpretation=i.Rgb),a.PhotometricInterpretation!=i.YbrFull422&&a.PhotometricInterpretation!=i.YbrPartial422&&a.PhotometricInterpretation!=i.YbrFull||(a.PhotometricInterpretation=i.Rgb),a}}class A extends I{encode(e,t,r={}){return r.lossy=!1,super.encode(e,t,"encodeJpeg2000",r)}decode(e,t,r={}){return super.decode(e,t,"decodeJpeg2000",r)}}class S extends I{encode(e,t,r={}){return r.lossy=!0,super.encode(e,t,"encodeJpeg2000",r)}decode(e,t,r={}){return super.decode(e,t,"decodeJpeg2000",r)}}class E extends I{encode(e,t,r={}){return r.lossy=!1,super.encode(e,t,"encodeHtJpeg2000",r)}decode(e,t,r={}){return super.decode(e,t,"decodeHtJpeg2000",r)}}class v extends I{encode(e,t,r={}){return r.lossy=!1,r.progressionOrder=s.Rpcl,super.encode(e,t,"encodeHtJpeg2000",r)}decode(e,t,r={}){return super.decode(e,t,"decodeHtJpeg2000",r)}}class B extends I{encode(e,t,r={}){return r.lossy=!0,super.encode(e,t,"encodeHtJpeg2000",r)}decode(e,t,r={}){return super.decode(e,t,"decodeHtJpeg2000",r)}}e.exports={Codec:m,ExplicitVRBigEndianCodec:f,ExplicitVRLittleEndianCodec:g,HtJpeg2000LosslessCodec:E,HtJpeg2000LosslessRpclCodec:v,HtJpeg2000LossyCodec:B,ImplicitVRLittleEndianCodec:u,Jpeg2000LosslessCodec:A,Jpeg2000LossyCodec:S,JpegBaselineProcess1Codec:y,JpegLosslessProcess14V1Codec:x,JpegLsLosslessCodec:b,JpegLsLossyCodec:_,RleLosslessCodec:w}},492:e=>{const t={ImplicitVRLittleEndian:"1.2.840.10008.1.2",ExplicitVRLittleEndian:"1.2.840.10008.1.2.1",ExplicitVRBigEndian:"1.2.840.10008.1.2.2",RleLossless:"1.2.840.10008.1.2.5",JpegBaselineProcess1:"1.2.840.10008.1.2.4.50",JpegLosslessProcess14V1:"1.2.840.10008.1.2.4.70",JpegLsLossless:"1.2.840.10008.1.2.4.80",JpegLsLossy:"1.2.840.10008.1.2.4.81",Jpeg2000Lossless:"1.2.840.10008.1.2.4.90",Jpeg2000Lossy:"1.2.840.10008.1.2.4.91",JpegXlLossless:"1.2.840.10008.1.2.4.110",JpegXlRecompression:"1.2.840.10008.1.2.4.111",JpegXl:"1.2.840.10008.1.2.4.112",HtJpeg2000Lossless:"1.2.840.10008.1.2.4.201",HtJpeg2000LosslessRpcl:"1.2.840.10008.1.2.4.202",HtJpeg2000Lossy:"1.2.840.10008.1.2.4.203"};Object.freeze(t);const r=[{syntax:t.ImplicitVRLittleEndian,lossy:!1,encapsulated:!1,bigEndian:!1},{syntax:t.ExplicitVRLittleEndian,lossy:!1,encapsulated:!1,bigEndian:!1},{syntax:t.ExplicitVRBigEndian,lossy:!1,encapsulated:!1,bigEndian:!0},{syntax:t.RleLossless,lossy:!1,encapsulated:!0,bigEndian:!1},{syntax:t.JpegBaselineProcess1,lossy:!0,encapsulated:!0,bigEndian:!1},{syntax:t.JpegLosslessProcess14V1,lossy:!1,encapsulated:!0,bigEndian:!1},{syntax:t.JpegLsLossless,lossy:!1,encapsulated:!0,bigEndian:!1},{syntax:t.JpegLsLossy,lossy:!0,encapsulated:!0,bigEndian:!1},{syntax:t.Jpeg2000Lossless,lossy:!1,encapsulated:!0,bigEndian:!1},{syntax:t.Jpeg2000Lossy,lossy:!0,encapsulated:!0,bigEndian:!1},{syntax:t.HtJpeg2000Lossless,lossy:!1,encapsulated:!0,bigEndian:!1},{syntax:t.HtJpeg2000LosslessRpcl,lossy:!1,encapsulated:!0,bigEndian:!1},{syntax:t.HtJpeg2000Lossy,lossy:!0,encapsulated:!0,bigEndian:!1}];Object.freeze(r);const s={Monochrome1:"MONOCHROME1",Monochrome2:"MONOCHROME2",PaletteColor:"PALETTE COLOR",Rgb:"RGB",YbrFull:"YBR_FULL",YbrFull422:"YBR_FULL_422",YbrPartial422:"YBR_PARTIAL_422",YbrPartial420:"YBR_PARTIAL_420",YbrIct:"YBR_ICT",YbrRct:"YBR_RCT",Cmyk:"CMYK",Argb:"ARGB",Hsv:"HSV"};Object.freeze(s);const o={Interleaved:0,Planar:1};Object.freeze(o);const i={Unsigned:0,Signed:1};Object.freeze(i);const n={ImplementationClassUid:"1.2.826.0.1.3680043.10.854",ImplementationVersion:"DCMJS-CODECS-V1"};Object.freeze(n);const a={SecondaryCaptureImageStorage:"1.2.840.10008.5.1.4.1.1.7"};Object.freeze(a);const l={Success:0,BadFileDescriptor:8};Object.freeze(l);const c={Sf444:0,Sf422:1,Unknown:2};Object.freeze(c);const d={Lrcp:0,Rlcp:1,Rpcl:2,Pcrl:3,Cprl:4};Object.freeze(d),e.exports={ErrNo:l,Implementation:n,Jpeg2000ProgressionOrder:d,JpegSampleFactor:c,PhotometricInterpretation:s,PixelRepresentation:i,PlanarConfiguration:o,StorageClass:a,TranscodeMap:r,TransferSyntax:t}},547:(e,t,r)=>{const s=r(213),o=r(935);o.reg(s),s.enableAll(!1),o.apply(s,{format:(e,t,r)=>`${r} -- ${e.toUpperCase()} --`,timestampFormatter:e=>e.toISOString()}),e.exports=s},837:e=>{e.exports="0.0.6"},859:(e,t,r)=>{const{PhotometricInterpretation:s,PixelRepresentation:o,PlanarConfiguration:i,TranscodeMap:n,TransferSyntax:a}=r(492),l=r(984);e.exports={FrameConverter:class{static changePlanarConfiguration(e,t,r,s){if(1!==t/8)throw new Error(`Unsupported bits allocated for changing planar configuration: ${t}`);const o=e.length/r,n=new Uint8Array(e.length);if(s===i.Planar)for(let t=0;t<o;++t)for(let s=0;s<r;++s)n[t*r+s]=e[t+o*s];else for(let t=0;t<o;++t)for(let s=0;s<r;++s)n[t+o*s]=e[t*r+s];return n}static ybrFullToRgb(e){const t=new Uint8Array(e.length);for(let r=0;r<e.length;r+=3){const s=e[r],o=e[r+1],i=e[r+2];t[r]=this._truncAndClamp(s+1.402*(i-128)+.5,0,255),t[r+1]=this._truncAndClamp(s-.3441*(o-128)-.7141*(i-128)+.5,0,255),t[r+2]=this._truncAndClamp(s+1.772*(o-128)+.5,0,255)}return t}static ybrFull422ToRgb(e,t){const r=new Uint8Array(Math.trunc(e.length/4*2*3));for(let s=0,o=0,i=0;s<e.length;){const n=e[s++],a=e[s++],l=e[s++],c=e[s++];r[o++]=this._truncAndClamp(n+1.402*(c-128)+.5,0,255),r[o++]=this._truncAndClamp(n-.3441*(l-128)-.7141*(c-128)+.5,0,255),r[o++]=this._truncAndClamp(n+1.772*(l-128)+.5,0,255),++i!==t?(r[o++]=this._truncAndClamp(a+1.402*(c-128)+.5,0,255),r[o++]=this._truncAndClamp(a-.3441*(l-128)-.7141*(c-128)+.5,0,255),r[o++]=this._truncAndClamp(a+1.772*(l-128)+.5,0,255),++i===t&&(i=0)):i=0}return r}static ybrPartial422ToRgb(e,t){const r=new Uint8Array(Math.trunc(e.length/4*2*3));for(let s=0,o=0,i=0;s<e.length;){const n=e[s++],a=e[s++],l=e[s++],c=e[s++];r[o++]=this._truncAndClamp(1.1644*(n-16)+1.596*(c-128)+.5,0,255),r[o++]=this._truncAndClamp(1.1644*(n-16)-.3917*(l-128)-.813*(c-128)+.5,0,255),r[o++]=this._truncAndClamp(1.1644*(n-16)+2.0173*(l-128)+.5,0,255),++i!==t?(r[o++]=this._truncAndClamp(1.1644*(a-16)+1.596*(c-128)+.5,0,255),r[o++]=this._truncAndClamp(1.1644*(a-16)-.3917*(l-128)-.813*(c-128)+.5,0,255),r[o++]=this._truncAndClamp(1.1644*(a-16)+2.0173*(l-128)+.5,0,255),++i===t&&(i=0)):i=0}return r}static unpackLow16(e){const t=new Uint8Array(e.length/2);for(let r=0;r<t.length&&2*r<e.length;r++)t[r]=e[2*r];return t}static unpackHigh16(e){const t=new Uint8Array(e.length/2);for(let r=0;r<t.length&&2*r+1<e.length;r++)t[r]=e[2*r+1];return t}static _truncAndClamp(e,t,r){return Math.min(Math.max(Math.trunc(e),t),r)}},Frames:class{constructor(e,t){this.transferSyntaxUid=t,this.frames=e.NumberOfFrames||1,this.width=e.Columns,this.height=e.Rows,this.bitsAllocated=e.BitsAllocated||0,this.bitsStored=e.BitsStored||this.bitsAllocated,this.highBit=e.HighBit||this.bitsStored-1,this.samplesPerPixel=e.SamplesPerPixel||1,this.pixelRepresentation=e.PixelRepresentation||o.Unsigned,this.planarConfiguration=e.PlanarConfiguration||i.Interleaved;const r=e.PhotometricInterpretation;this.photometricInterpretation=r?r.replace(/[^ -~]+/g,"").trim():"",this.pixelData=e.PixelData}getTransferSyntaxUid(){return this.transferSyntaxUid}getNumberOfFrames(){return this.frames}getWidth(){return this.width}getHeight(){return this.height}getBitsStored(){return this.bitsStored}getBitsAllocated(){return this.bitsAllocated}getBytesAllocated(){let e=this.getBitsAllocated()/8;return this.getBitsAllocated()%8>0&&e++,e}getHighBit(){return this.highBit}getSamplesPerPixel(){return this.samplesPerPixel}getPixelRepresentation(){return this.pixelRepresentation}isSigned(){return this.getPixelRepresentation()!==o.Unsigned}getPlanarConfiguration(){return this.planarConfiguration}isPlanar(){return this.getPlanarConfiguration()!==i.Interleaved}getPhotometricInterpretation(){return this.photometricInterpretation}getPixelData(){return this.pixelData}getUncompressedFrameSize(){if(1===this.getBitsAllocated())return Math.trunc((this.getWidth()*this.getHeight()-1)/8+1);if(this.getPhotometricInterpretation()===s.YbrFull422){const e=this.getTransferSyntaxUid();if(e===a.ImplicitVRLittleEndian||e===a.ExplicitVRLittleEndian||e===a.ExplicitVRBigEndian)return 2*this.getBytesAllocated()*this.getWidth()*this.getHeight()}return this.getWidth()*this.getHeight()*this.getBytesAllocated()*this.getSamplesPerPixel()}getFrameBuffer(e){if(e<0||e>=this.getNumberOfFrames())throw new Error(`Requested frame is out of range [${e}]`);if(!this.getPixelData())throw new Error("Could not extract pixel data");if(!this.getWidth()||!this.getHeight())throw new Error(`Width/height has an invalid value [w: ${this.getWidth()}, h: ${this.getHeight()}]`);if(!this.getBitsAllocated()||!this.getBitsStored())throw new Error(`Bits allocated/stored has an invalid value [allocated: ${this.getBitsAllocated()}, stored: ${this.getBitsStored()}]`);if(!this.getPhotometricInterpretation())throw new Error(`Photometric interpretation has an invalid value [${this.getPhotometricInterpretation()}]`);const t=this.getPixelData();if(!t)throw new Error("Pixel data could not be extracted");const r=n.find((e=>e.syntax===this.getTransferSyntaxUid()));if(!r)throw new Error(`Transfer syntax is not currently supported [syntax: ${this.getTransferSyntaxUid()}]`);if(r.encapsulated)return this._getFrameFragments(t,e);{const r=this.getUncompressedFrameSize(),s=r*e;return new Uint8Array(Array.isArray(t)?t.find((e=>e)):t).slice(s,s+r)}}toString(){const e=[];return e.push(`Pixel Data: ${this.getTransferSyntaxUid()}`),e.push(` Photometric Interpretation: ${this.getPhotometricInterpretation()}`),e.push(` Bits Allocated: ${this.getBitsAllocated()}; Stored: ${this.getBitsStored()}; High: ${this.getHighBit()}; Signed: ${this.isSigned()?"True":"False"}`),e.push(` Width: ${this.getWidth()}; Height: ${this.getHeight()}; Frames: ${this.getNumberOfFrames()}`),e.join("\n")}_getFrameFragments(e,t){if(0===e.length)throw new Error("No fragmented pixel data");if(t>=e.length)throw new Error(`Requested frame is larger or equal to the pixel fragments number [frame: (${t}), fragments: ${e.length}]`);if(1===this.getNumberOfFrames())return new Uint8Array(l.concatBuffers(e));if(e.length===this.getNumberOfFrames())return new Uint8Array(e[t]);throw new Error("Multiple fragments per frame is not yet implemented")}}}},935:function(e,t,r){var s,o;s=function(e){"use strict";var t,r,s=function(e){for(var t,r=1,s=arguments.length;r<s;r++)for(t in arguments[r])Object.prototype.hasOwnProperty.call(arguments[r],t)&&(e[t]=arguments[r][t]);return e},o={template:"[%t] %l:",levelFormatter:function(e){return e.toUpperCase()},nameFormatter:function(e){return e||"root"},timestampFormatter:function(e){return e.toTimeString().replace(/.*(\d{2}:\d{2}:\d{2}).*/,"$1")},format:void 0},i={},n=function(e,r){if(!e||!e.setLevel)throw new TypeError("Argument is not a logger");var n=e.methodFactory,a=e.name||"",l=i[a]||i[""]||o;function c(e,t,r){var s=n(e,t,r),o=i[r]||i[""],l=-1!==o.template.indexOf("%t"),c=-1!==o.template.indexOf("%l"),d=-1!==o.template.indexOf("%n");return function(){for(var t="",n=arguments.length,p=Array(n),h=0;h<n;h++)p[h]=arguments[h];if(a||!i[r]){var m=o.timestampFormatter(new Date),u=o.levelFormatter(e),g=o.nameFormatter(r);o.format?t+=o.format(u,g,m):(t+=o.template,l&&(t=t.replace(/%t/,m)),c&&(t=t.replace(/%l/,u)),d&&(t=t.replace(/%n/,g))),p.length&&"string"==typeof p[0]?p[0]=t+" "+p[0]:p.unshift(t)}s.apply(void 0,p)}}return i[a]||(e.methodFactory=c),(r=r||{}).template&&(r.format=void 0),i[a]=s({},l,r),e.setLevel(e.getLevel()),t||e.warn("It is necessary to call the function reg() of loglevel-plugin-prefix before calling apply. From the next release, it will throw an error. See more: https://github.com/kutuluk/loglevel-plugin-prefix/blob/master/README.md"),e},a={reg:function(e){if(!e||!e.getLogger)throw new TypeError("Argument is not a root logger");t=e},apply:n};return e&&(r=e.prefix,a.noConflict=function(){return e.prefix===a&&(e.prefix=r),a}),a},void 0===(o="function"==typeof s?s.call(t,r,t,e):s)||(e.exports=o)},984:(e,t,r)=>{const s=r(111),{DicomMetaDictionary:o}=s.data;e.exports=class{static concatBuffers(e){const t=(e=Array.isArray(e)?e:[e]).every((e=>e instanceof ArrayBuffer));let r=0;for(let s=0;s<e.length;s++){const o=e[s];r+=t?o.byteLength:o.length}let s=0;const o=new Uint8Array(r);for(let r=0;r<e.length;r++){const i=e[r];o.set(t?new Uint8Array(i):i,s),s+=t?i.byteLength:i.length}return t?o.buffer:o}static generateDerivedUid(){return o.uid()}}}},__webpack_module_cache__={};function __webpack_require__(e){var t=__webpack_module_cache__[e];if(void 0!==t)return t.exports;var r=__webpack_module_cache__[e]={exports:{}};return __webpack_modules__[e].call(r.exports,r,r.exports,__webpack_require__),r.exports}var __webpack_exports__=__webpack_require__(237);return __webpack_exports__})()));