@cornerstonejs/dicom-image-loader 2.0.0-beta.24 → 2.0.0-beta.25
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cornerstoneDICOMImageLoader.bundle.min.js +1 -1
- package/dist/cornerstoneDICOMImageLoader.bundle.min.js.map +1 -1
- package/dist/dynamic-import/cornerstoneDICOMImageLoader.min.js +1 -1
- package/dist/dynamic-import/cornerstoneDICOMImageLoader.min.js.map +1 -1
- package/dist/esm/src/constants/index.d.ts +2 -0
- package/dist/esm/src/constants/index.js +2 -0
- package/dist/esm/src/imageLoader/configure.js +1 -1
- package/dist/esm/src/imageLoader/createImage.js +1 -3
- package/package.json +15 -8
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t(require("dicom-parser")):"function"==typeof define&&define.amd?define("cornerstoneDICOMImageLoader",["dicom-parser"],t):"object"==typeof exports?exports.cornerstoneDICOMImageLoader=t(require("dicom-parser")):e.cornerstoneDICOMImageLoader=t(e.dicomParser)}(this,(e=>(()=>{"use strict";var t={713:t=>{t.exports=e}},n={};function r(e){var a=n[e];if(void 0!==a)return a.exports;var o=n[e]={exports:{}};return t[e](o,o.exports,r),o.exports}r.m=t,r.d=(e,t)=>{for(var n in t)r.o(t,n)&&!r.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:t[n]})},r.u=e=>e+".bundle.min.js",r.g=function(){if("object"==typeof globalThis)return globalThis;try{return this||new Function("return this")()}catch(e){if("object"==typeof window)return window}}(),r.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),r.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},(()=>{var e;r.g.importScripts&&(e=r.g.location+"");var t=r.g.document;if(!e&&t&&(t.currentScript&&(e=t.currentScript.src),!e)){var n=t.getElementsByTagName("script");if(n.length)for(var a=n.length-1;a>-1&&!e;)e=n[a--].src}if(!e)throw new Error("Automatic publicPath is not supported in this browser");e=e.replace(/#.*$/,"").replace(/\?.*$/,"").replace(/\/[^\/]+$/,"/"),r.p=e})(),r.b=document.baseURI||self.location.href;var a={};return(()=>{r.r(a),r.d(a,{configure:()=>pt,convertColorSpace:()=>Pe,convertPALETTECOLOR:()=>y,convertRGBColorByPixel:()=>n,convertRGBColorByPlane:()=>o,convertYBRFullByPixel:()=>i,convertYBRFullByPlane:()=>s,createImage:()=>ve,decodeJPEGBaseline8BitColor:()=>Se,default:()=>xt,external:()=>p,getImageFrame:()=>Te,getMinMax:()=>ye,getPixelData:()=>ot,internal:()=>V,isColorImage:()=>Le,isJPEGBaseline8BitColor:()=>ht,wadors:()=>gt,wadouri:()=>Ue});var e={};r.r(e),r.d(e,{ProgressiveIterator:()=>C});var t={};function n(e,t,n){if(void 0===e)throw new Error("decodeRGB: rgbBuffer must be defined");if(e.length%3!=0)throw new Error(`decodeRGB: rgbBuffer length ${e.length} must be divisible by 3`);const r=e.length/3;let a=0,o=0;if(n)for(let n=0;n<r;n++)t[o++]=e[a++],t[o++]=e[a++],t[o++]=e[a++],t[o++]=255;else t.set(e)}function o(e,t,n){if(void 0===e)throw new Error("decodeRGB: rgbBuffer must be defined");if(e.length%3!=0)throw new Error(`decodeRGB: rgbBuffer length ${e.length} must be divisible by 3`);const r=e.length/3;let a=0,o=0,i=r,s=2*r;if(n)for(let n=0;n<r;n++)t[a++]=e[o++],t[a++]=e[i++],t[a++]=e[s++],t[a++]=255;else for(let n=0;n<r;n++)t[a++]=e[o++],t[a++]=e[i++],t[a++]=e[s++]}function i(e,t,n){if(void 0===e)throw new Error("convertYBRFullByPixel: ybrBuffer must be defined");if(e.length%3!=0)throw new Error(`convertYBRFullByPixel: ybrBuffer length ${e.length} must be divisible by 3`);const r=e.length/3;let a=0,o=0;if(n)for(let n=0;n<r;n++){const n=e[a++],r=e[a++],i=e[a++];t[o++]=n+1.402*(i-128),t[o++]=n-.34414*(r-128)-.71414*(i-128),t[o++]=n+1.772*(r-128),t[o++]=255}else for(let n=0;n<r;n++){const n=e[a++],r=e[a++],i=e[a++];t[o++]=n+1.402*(i-128),t[o++]=n-.34414*(r-128)-.71414*(i-128),t[o++]=n+1.772*(r-128)}}function s(e,t,n){if(void 0===e)throw new Error("convertYBRFullByPlane: ybrBuffer must be defined");if(e.length%3!=0)throw new Error(`convertYBRFullByPlane: ybrBuffer length ${e.length} must be divisible by 3`);const r=e.length/3;let a=0,o=0,i=r,s=2*r;if(n)for(let n=0;n<r;n++){const n=e[o++],r=e[i++],l=e[s++];t[a++]=n+1.402*(l-128),t[a++]=n-.34414*(r-128)-.71414*(l-128),t[a++]=n+1.772*(r-128),t[a++]=255}else for(let n=0;n<r;n++){const n=e[o++],r=e[i++],l=e[s++];t[a++]=n+1.402*(l-128),t[a++]=n-.34414*(r-128)-.71414*(l-128),t[a++]=n+1.772*(r-128)}}r.r(t),r.d(t,{ImageQualityStatus:()=>A});let l,c,u={open(e,t){e.open("get",t,!0)},beforeSend(){},beforeProcessing:e=>Promise.resolve(e.response),imageCreated(){},strict:!1};function f(e){u=Object.assign(u,e)}function d(){return u}const g=()=>new Worker(new URL(r.p+r.u(920),r.b),{type:void 0}),m={set cornerstone(e){l=e;const t=d();m.cornerstone.getWebWorkerManager().registerWorker("dicomImageLoader",g,{maxWorkerInstances:t.maxWebWorkers||1})},get cornerstone(){if(!l&&(l=window&&window.cornerstone,!l))throw new Error("cornerstoneDICOMImageLoader requires a copy of Cornerstone to work properly. Please add cornerstoneDICOMImageLoader.external.cornerstone = cornerstone; to your application.");return l},set dicomParser(e){c=e},get dicomParser(){if(!c){if(!window||!window.dicomParser)throw new Error("cornerstoneDICOMImageLoader requires a copy of dicomParser to work properly. Please add cornerstoneDICOMImageLoader.external.dicomParser = dicomParser; to your application.");c=window.dicomParser}return c}},p=m;function h(e,t){const n=e.length,r=new Uint8ClampedArray(n);for(let a=0;a<n;++a)r[a]=e[a]>>t;return r}function x(e,t,n){const r=e[`${t}PaletteColorLookupTableData`];if(r)return Promise.resolve(r);const a=p.cornerstone.metaData.get("imagePixelModule",e.imageId);return a&&"function"==typeof a.then?a.then((e=>e?e[`${t}PaletteColorLookupTableData`]:n)):Promise.resolve(a?a[`${t}PaletteColorLookupTableData`]:n)}function y(e,t,n){const r=e.columns*e.rows,a=e.pixelData;Promise.all([x(e,"red",null),x(e,"green",null),x(e,"blue",null)]).then((([o,i,s])=>{if(!o||!i||!s)throw new Error("The image does not have a complete color palette. R, G, and B palette data are required.");const l=o.length;let c=0,u=0;const f=e.redPaletteColorLookupTableDescriptor[1],d=8===e.redPaletteColorLookupTableDescriptor[2]?0:8,g=h(o,d),m=h(i,d),p=h(s,d);if(n)for(let e=0;e<r;++e){let e=a[c++];e<f?e=0:e>f+l-1?e=l-1:e-=f,t[u++]=g[e],t[u++]=m[e],t[u++]=p[e],t[u++]=255}else for(let e=0;e<r;++e){let e=a[c++];e<f?e=0:e>f+l-1?e=l-1:e-=f,t[u++]=g[e],t[u++]=m[e],t[u++]=p[e]}}))}function b(e,t){if(e.elements[t]&&6===e.elements[t].length)return[e.uint16(t,0),e.uint16(t,1),e.uint16(t,2)]}function P(e,t,n){const r=[],a=e.elements[t];for(let o=0;o<n[0];o++)16===n[2]?r[o]=e.uint16(t,o):r[o]=e.byteArray[o+a.dataOffset];return r}const w=function(e){const t={samplesPerPixel:e.uint16("x00280002"),photometricInterpretation:e.string("x00280004"),rows:e.uint16("x00280010"),columns:e.uint16("x00280011"),bitsAllocated:e.uint16("x00280100"),bitsStored:e.uint16("x00280101"),highBit:e.uint16("x00280102"),pixelRepresentation:e.uint16("x00280103"),planarConfiguration:e.uint16("x00280006"),pixelAspectRatio:e.string("x00280034")};return function(e,t){0===e.uint16("x00280103")?(t.smallestPixelValue=e.uint16("x00280106"),t.largestPixelValue=e.uint16("x00280107")):(t.smallestPixelValue=e.int16("x00280106"),t.largestPixelValue=e.int16("x00280107"))}(e,t),"PALETTE COLOR"===t.photometricInterpretation&&e.elements.x00281101&&function(e,t){t.redPaletteColorLookupTableDescriptor=b(e,"x00281101"),t.greenPaletteColorLookupTableDescriptor=b(e,"x00281102"),t.bluePaletteColorLookupTableDescriptor=b(e,"x00281103"),0===t.redPaletteColorLookupTableDescriptor[0]&&(t.redPaletteColorLookupTableDescriptor[0]=65536,t.greenPaletteColorLookupTableDescriptor[0]=65536,t.bluePaletteColorLookupTableDescriptor[0]=65536);const n=t.redPaletteColorLookupTableDescriptor[0],r=e.elements.x00281201.length===n?8:16;t.redPaletteColorLookupTableDescriptor[2]!==r&&(t.redPaletteColorLookupTableDescriptor[2]=r,t.greenPaletteColorLookupTableDescriptor[2]=r,t.bluePaletteColorLookupTableDescriptor[2]=r),t.redPaletteColorLookupTableData=P(e,"x00281201",t.redPaletteColorLookupTableDescriptor),t.greenPaletteColorLookupTableData=P(e,"x00281202",t.greenPaletteColorLookupTableDescriptor),t.bluePaletteColorLookupTableData=P(e,"x00281203",t.bluePaletteColorLookupTableDescriptor)}(e,t),t};function S(e,t){let n=t.uint16("x00283002",0);0===n&&(n=65535);let r=0;r=0===e?t.uint16("x00283002",1):t.int16("x00283002",1);const a={id:"1",firstValueMapped:r,numBitsPerEntry:t.uint16("x00283002",2),lut:[]};for(let r=0;r<n;r++)a.lut[r]=0===e?t.uint16("x00283006",r):t.int16("x00283006",r);return a}const D=function(e,t){if(!t||!t.items||!t.items.length)return;const n=[];for(let r=0;r<t.items.length;r++){const a=S(e,t.items[r].dataSet);a&&n.push(a)}return n};const I=function(e){const t=e.string("x00080016");if("1.2.840.10008.5.1.4.1.1.2"===t||"1.2.840.10008.5.1.4.1.1.2.1"===t)return 1;const n=e.floatString("x00281052"),r=e.floatString("x00281053");if(void 0!==n&&void 0!==r){const t=function(e){const t=e.uint16("x00280103"),n=e.uint16("x00280101");return 0===t?0:-1<<n-1}(e);return t*r+n<0?1:0}return e.elements.x00283000&&e.elements.x00283000.length>0?0:e.uint16("x00280103")};const T=function(e,t,n){const r=[],a=e.string(t);if(!a)return;const o=a.split("\\");if(!(n&&o.length<n)){for(let e=0;e<o.length;e++)r.push(parseFloat(o[e]));return r}};const L=function(e){const t=e.indexOf(":");let n=e.substring(t+1);const r=n.indexOf("frame=");let a;if(-1!==r){const e=n.substring(r+6);a=parseInt(e,10),n=n.substring(0,r-1)}return{scheme:e.substring(0,t),url:n,frame:a,pixelDataFrame:void 0!==a?a-1:void 0}};const E=function(e,t,n={},r={}){const{cornerstone:a}=p,o=d(),i=e=>{if("function"==typeof o.errorInterceptor){const t=new Error("request failed");t.request=e,t.response=e.response,t.status=e.status,o.errorInterceptor(t)}},s=new XMLHttpRequest,l=new Promise(((l,c)=>{o.open(s,e,n,r);const u=o.beforeSend(s,t,n,r);s.responseType="arraybuffer";const f=Object.assign({},n,u);Object.keys(f).forEach((function(t){null!==f[t]&&("Accept"===t&&-1!==e.indexOf("accept=")||s.setRequestHeader(t,f[t]))})),r.deferred={resolve:l,reject:c},r.url=e,r.imageId=t,s.onloadstart=function(n){o.onloadstart&&o.onloadstart(n,r);const i={url:e,imageId:t};a.triggerEvent(a.events,"cornerstoneimageloadstart",i)},s.onloadend=function(n){o.onloadend&&o.onloadend(n,r);const i={url:e,imageId:t};a.triggerEvent(a.events,"cornerstoneimageloadend",i)},s.onreadystatechange=function(e){o.onreadystatechange?o.onreadystatechange(e,r):4===s.readyState&&(200===s.status||206===s.status?o.beforeProcessing(s).then(l).catch((()=>{i(s),c(s)})):(i(s),c(s)))},s.onprogress=function(e){const t=e.loaded;let n,a;e.lengthComputable&&(n=e.total,a=Math.round(t/n*100)),o.onprogress&&o.onprogress(e,r)},s.onerror=function(){i(s),c(s)},s.onabort=function(){i(s),c(s)},s.send()}));return l.xhr=s,l};class C{constructor(e){this.name=e||"unknown"}static as(e){if(e.iterator)return e.iterator;const t=new C("as iterator");return e.then((e=>{try{t.add(e,!0)}catch(e){t.reject(e)}}),(e=>{t.reject(e)})),t}add(e,t=!1){this.nextValue=e,this.done||=t,this.waiting&&(this.waiting.resolve(e),this.waiting=void 0)}resolve(){this.done=!0,this.waiting&&(this.waiting.resolve(this.nextValue),this.waiting=void 0)}reject(e){this.rejectReason=e,this.waiting?.reject(e)}getRecent(){if(this.rejectReason)throw this.rejectReason;return this.nextValue}async*[Symbol.asyncIterator](){for(;!this.done;){if(this.rejectReason)throw this.rejectReason;if(void 0!==this.nextValue&&(yield this.nextValue,this.done))break;this.waiting||(this.waiting={},this.waiting.promise=new Promise(((e,t)=>{this.waiting.resolve=e,this.waiting.reject=t}))),await this.waiting.promise}yield this.nextValue}async forEach(e,t){let n=0;try{for await(const r of this){const{done:a}=this;try{await e(r,a,n),n++}catch(e){if(!a){console.warn("Caught exception in intermediate value",e);continue}if(!t)throw e;t(e,a)}}}catch(e){if(!t)throw e;t(e,!0)}}generate(e,t){return e(this,this.reject.bind(this)).then((()=>{this.done||this.resolve()}),(e=>{this.reject(e),t?t(e):console.warn("Couldn't process because",e)}))}async nextPromise(){for await(const e of this)if(e)return e;return this.nextValue}async donePromise(){for await(const e of this);return this.nextValue}getNextPromise(){const e=this.nextPromise();return e.iterator=this,e}getDonePromise(){const e=this.donePromise();return e.iterator=this,e}}var v;!function(e){e[e.FAR_REPLICATE=1]="FAR_REPLICATE",e[e.ADJACENT_REPLICATE=3]="ADJACENT_REPLICATE",e[e.SUBRESOLUTION=6]="SUBRESOLUTION",e[e.LOSSY=7]="LOSSY",e[e.FULL_RESOLUTION=8]="FULL_RESOLUTION"}(v||(v={}));const A=v;function O(e,t,n){if(n+e.length>t.length)return!1;let r=n;for(let n=0;n<e.length;n++)if(e[n]!==t[r++])return!1;return!0}const M=function(e,t,n){n=n||0;const r=function(e){const t=new Uint8Array(e.length);for(let n=0,r=e.length;n<r;n++)t[n]=e.charCodeAt(n);return t}(t);for(let t=n;t<e.length;t++)if(r[0]===e[t]&&O(r,e,t))return t;return-1},{ImageQualityStatus:R}=t;function F(e,t,n){n||={};const r=new Uint8Array(t),a=!!n?.isPartial;if(-1===e.indexOf("multipart"))return{contentType:e,imageQualityStatus:a?R.SUBRESOLUTION:R.FULL_RESOLUTION,pixelData:r};let{tokenIndex:o,responseHeaders:i,boundary:s,multipartContentType:l}=n;if(o||=M(r,"\r\n\r\n"),-1===o)throw new Error("invalid response - no multipart mime header");if(!s){const e=function(e,t,n){t=t||0,n=n||e.length-t;let r="";for(let a=t;a<t+n;a++)r+=String.fromCharCode(e[a]);return r}(r,0,o);if(i=e.split("\r\n"),s=function(e){for(let t=0;t<e.length;t++)if("--"===e[t].substr(0,2))return e[t]}(i),!s)throw new Error("invalid response - no boundary marker")}const c=o+4,u=M(r,s,c);if(-1===u&&!a)throw new Error("invalid response - terminating boundary not found");return l||=function(e){for(let t=0;t<e.length;t++)if("Content-Type:"===e[t].substr(0,13))return e[t].substr(13).trim()}(i),n.tokenIndex=o,n.boundary=s,n.responseHeaders=i,n.multipartContentType=l,n.isPartial=-1===u,{contentType:l,extractDone:!a||-1!==u,tokenIndex:o,responseHeaders:i,boundary:s,multipartContentType:l,pixelData:t.slice(c,u-2)}}const{ImageQualityStatus:U}=t;function B(e,t=!0){return t?e.imageQualityStatus??U.FULL_RESOLUTION:U.SUBRESOLUTION}const{ProgressiveIterator:N}=e;function k(e,t,n={},r={}){const a=d(),{retrieveOptions:o={},streamingData:i={}}=r,s=o.chunkSize||131072,l=new N("streamRequest");return l.generate((async(r,l)=>{const c=Object.assign({},n);Object.keys(c).forEach((function(t){null===c[t]&&(c[t]=void 0),"Accept"===t&&-1!==e.indexOf("accept=")&&(c[t]=void 0)}));try{const a=await fetch(e,{headers:n,signal:void 0});if(200!==a.status)throw new Error(`Couldn't retrieve ${e} got status ${a.status}`);const l=a.body.getReader(),c=a.headers,u=c.get("content-type"),f=Number(c.get("Content-Length"));let d=!1,g=i.encodedData,m=i.lastSize||0;for(i.isPartial=!0;!d;){const{done:n,value:a}=await l.read();if(g=_(g,a),!g){if(d)throw new Error(`Done but no image frame available ${t}`);continue}if(d=n||g.byteLength===f,!d&&g.length<m+s)continue;m=g.length,i.isPartial=!n;const c=F(u,g,i),p=B(o,d),h={url:e,imageId:t,...c,percentComplete:n?100:100*c.pixelData?.length/f,imageQualityStatus:p,done:d};r.add(h,d)}}catch(e){(()=>{if("function"==typeof a.errorInterceptor){const e=new Error("request failed");a.errorInterceptor(e)}})(),console.error(e),l(e)}})),l.getNextPromise()}function _(e,t){if(!e)return t;if(!t)return e;const n=new Uint8Array(e.length+t.length);return n.set(e,0),n.set(t,e.length),n}const V={xhrRequest:E,streamRequest:k,setOptions:f,getOptions:d};function j(e){const{dicomParser:t}=p;let n,r=t.parseDicom(e,{untilTag:"x7fe00010"});r.elements.x7fe00010||console.warn("Pixel data not found!");try{n=t.parseDicom(e)}catch(e){console.error(e),console.log("pixel data dataset:",e.dataSet),n=e.dataSet}return r.elements.x7fe00010=n.elements.x7fe00010,r=function(e){const t=e.elements.x7fe00010.fragments,n=e.byteArray.length;for(const e of t){const{position:t,length:r}=e;r>n-t&&(console.log(`Truncated fragment, changing fragment length from ${e.length} to ${n-t}`),e.length=n-t)}return e}(r),r}async function $(e,t,n){const r=j(e),{uri:a,imageId:o,fileTotalLength:i}=n;return r.fetchMore=async function(s){const l=Object.assign({uri:a,imageId:o,fetchedLength:e.length,lengthToFetch:i-e.length},s),{fetchedLength:c,lengthToFetch:u}=l,{arrayBuffer:f}=await t(a,o,{byteRange:`${c}-${c+u}`}),d=new Uint8Array(f),g=new Uint8Array(r.byteArray.length+d.length);return g.set(r.byteArray),g.set(d,r.byteArray.length),$(g,t,n)},r}function G(e,t,n){const r={};(t?Object.values(t.items[0].dataSet.elements):[]).map((e=>r[e.tag]=e));const a={};return(e?Object.values(e.items[n-1].dataSet.elements):[]).map((e=>a[e.tag]=e)),{shared:r,perFrame:a}}function q(e){if(!e)return;const{elements:t,...n}=e,{x52009230:r,x52009229:a,...o}=t;return{NumberOfFrames:e.intString("x00280008"),PerFrameFunctionalGroupsSequence:r,SharedFunctionalGroupsSequence:a,otherElements:o,otherAttributtes:n}}let Y={};function W(e){if(Y[e])return Y[e]}function X(e){if(!e)return!1;const t=e.intString("x00280008");return t&&t>1}const z={_get:W,generateMultiframeWADOURIs:function(e){const t=[],n=W(e);if(X(n)){const r=n.intString("x00280008");for(let n=1;n<=r;n++)t.push(`${e}&frame=${n}`)}else t.push(e);return t},retrieveMultiframeDataset:function(e){const t=function(e){return e.indexOf("&frame=")}(e),n=-1===t?e:e.slice(0,t),r=parseInt(e.slice(t+7),10)||1;let a;return a=Y[n]?Y[n].dataSet:void 0,{dataSet:a,frame:r}},isMultiframeDataset:function(e){return X(W(e))}};let H=0,Q={};function J(){return{cacheSizeInBytes:H,numberOfDataSetsCached:Object.keys(Y).length}}const K={isLoaded:function(e){return void 0!==Y[e]},load:function(e,t=E,n){const{cornerstone:r,dicomParser:a}=p;if(Y[e])return new Promise((t=>{Y[e].cacheCount++,t(Y[e].dataSet)}));if(Q[e])return Q[e].cacheCount++,Q[e];const o=t(e,n),i=new Promise(((s,l)=>{o.then((async function(o){const c={isPartialContent:!1,fileTotalLength:null};if(!(o instanceof ArrayBuffer)){if(!o.arrayBuffer)return l(new Error("If not returning ArrayBuffer, must return object with `arrayBuffer` parameter"));c.isPartialContent=o.flags.isPartialContent,c.fileTotalLength=o.flags.fileTotalLength,o=o.arrayBuffer}const u=new Uint8Array(o);let f;try{f=c.isPartialContent?await $(u,t,{uri:e,imageId:n,fileTotalLength:c.fileTotalLength}):a.parseDicom(u)}catch(e){return l(e)}Y[e]={dataSet:f,cacheCount:i.cacheCount},H+=f.byteArray.length,s(f),r.triggerEvent(r.events,"datasetscachechanged",{uri:e,action:"loaded",cacheInfo:J()})}),l).then((()=>{delete Q[e]}),(()=>{delete Q[e]}))}));return i.cacheCount=1,Q[e]=i,i},unload:function(e){const{cornerstone:t}=p;Y[e]&&(Y[e].cacheCount--,0===Y[e].cacheCount&&(H-=Y[e].dataSet.byteArray.length,delete Y[e],t.triggerEvent(t.events,"datasetscachechanged",{uri:e,action:"unloaded",cacheInfo:J()})))},getInfo:J,purge:function(){Y={},Q={},H=0},get:function(e){let t;if(e.includes("&frame=")){const{frame:n,dataSet:r}=z.retrieveMultiframeDataset(e);t=function(e,t){if(!t)return;const{NumberOfFrames:n,PerFrameFunctionalGroupsSequence:r,SharedFunctionalGroupsSequence:a,otherElements:o}=q(t);if(r||n>1){const{shared:n,perFrame:i}=G(r,a,e),s={elements:{...o,...n,...i}},l=Object.create(t);return Object.assign(l,s)}return t}(n,r)}else Y[e]&&(t=Y[e].dataSet);return t},update:function(e,t){const n=Y[e];n?(H-=n.dataSet.byteArray.length,n.dataSet=t,H+=t.byteArray.length,p.cornerstone.triggerEvent(p.cornerstone.events,"datasetscachechanged",{uri:e,action:"updated",cacheInfo:J()})):console.error(`No loaded dataSet for uri ${e}`)}};function Z(e){return"RECON TOMO"===e||"RECON GATED TOMO"===e}function ee(e,t){const n=e.string("x00080008");if(n){const e=n.split("\\");if(e.length>t)return e[t]}}function te(e){let t=T(e,"x00200037",6);return!t&&e.elements.x00209116&&(t=T(e.elements.x00209116.items[0].dataSet,"x00200037",6)),t||(t=function(e){let t;const n=e.string("x00080060");if(n?.includes("NM")){const n=ee(e,2);n&&Z(n)&&e.elements.x00540022&&(t=T(e.elements.x00540022.items[0].dataSet,"x00200037",6))}return t}(e)),t}function ne(e){let t=T(e,"x00200032",3);return!t&&e.elements.x00209113&&(t=T(e.elements.x00209113.items[0].dataSet,"x00200032",3)),t||(t=function(e){let t;const n=e.string("x00080060");if(n?.includes("NM")){const n=ee(e,2);n&&Z(n)&&e.elements.x00540022&&(t=T(e.elements.x00540022.items[0].dataSet,"x00200032",3))}return t}(e)),t}function re(e){let t=T(e,"x00280030",2);return!t&&e.elements.x00289110&&(t=T(e.elements.x00289110.items[0].dataSet,"x00280030",2)),t}function ae(e){let t;return e.elements.x00180050?t=e.floatString("x00180050"):e.elements.x00289110&&e.elements.x00289110.items.length&&e.elements.x00289110.items[0].dataSet.elements.x00180050&&(t=e.elements.x00289110.items[0].dataSet.floatString("x00180050")),t}function oe(e,t,n){const r={};for(const a of n)try{const n=t(a,e);if(n){const e={};for(const t in n)if(t in n){e[ie(t)]=n[t]}Object.assign(r,e)}}catch(e){console.error(`Error retrieving ${a} data:`,e)}return r}const ie=e=>e.charAt(0).toUpperCase()+e.slice(1),se=["multiframeModule","generalSeriesModule","patientStudyModule","imagePlaneModule","nmMultiframeGeometryModule","imagePixelModule","modalityLutModule","voiLutModule","sopCommonModule","petIsotopeModule","overlayPlaneModule","transferSyntax","petSeriesModule","petImageModule"];function le(e){const t=e.elements.x00186011;if(!t||!t.items)return[];return t.items.map((e=>{const t=e.dataSet.double("x0018602c"),n=e.dataSet.double("x0018602e"),r=e.dataSet.uint16("x00186024"),a=e.dataSet.uint16("x00186026");return{regionLocationMinY0:e.dataSet.uint16("x0018601a"),regionLocationMaxY1:e.dataSet.uint16("x0018601e"),regionLocationMinX0:e.dataSet.uint16("x00186018"),regionLocationMaxX1:e.dataSet.uint16("x0018601c"),referencePixelX0:e.dataSet.int32("x00186020")||null,referencePixelY0:e.dataSet.int32("x00186022")||null,physicalDeltaX:t,physicalDeltaY:n,physicalUnitsXDirection:r,physicalUnitsYDirection:a,referencePhysicalPixelValueY:e.dataSet.uint16("x0018602a"),referencePhysicalPixelValueX:e.dataSet.uint16("x00186028"),regionSpatialFormat:e.dataSet.uint16("x00186012"),regionDataType:e.dataSet.uint16("x00186014"),regionFlags:e.dataSet.uint16("x00186016"),transducerFrequency:e.dataSet.uint16("x00186030")}}))}const ce=function e(t,n){const{MetadataModules:r}=p.cornerstone.Enums,{dicomParser:a}=p;if(Array.isArray(n))return;const o=L(n);if(t===r.MULTIFRAME){const e=z.retrieveMultiframeDataset(o.url);if(!e.dataSet)return;const t=function(e,t){if(!e)return;const{NumberOfFrames:n,PerFrameFunctionalGroupsSequence:r,SharedFunctionalGroupsSequence:a}=q(e);if(r||n>1){const{shared:e,perFrame:o}=G(r,a,t);return{NumberOfFrames:n,PerFrameFunctionalInformation:o,SharedFunctionalInformation:e}}return{NumberOfFrames:n}}(e.dataSet,e.frame);return t}let i=o.url;o.frame&&(i=`${i}&frame=${o.frame}`);const s=K.get(i);if(s){if(t===r.GENERAL_STUDY)return{studyDescription:s.string("x00081030"),studyDate:a.parseDA(s.string("x00080020")),studyTime:a.parseTM(s.string("x00080030")||""),accessionNumber:s.string("x00080050")};if(t===r.GENERAL_SERIES)return{modality:s.string("x00080060"),seriesInstanceUID:s.string("x0020000e"),seriesNumber:s.intString("x00200011"),studyInstanceUID:s.string("x0020000d"),seriesDate:a.parseDA(s.string("x00080021")),seriesTime:a.parseTM(s.string("x00080031")||""),acquisitionDate:a.parseDA(s.string("x00080022")),acquisitionTime:a.parseTM(s.string("x00080032")||"")};if(t===r.GENERAL_IMAGE)return{sopInstanceUID:s.string("x00080018"),instanceNumber:s.intString("x00200013"),lossyImageCompression:s.string("x00282110"),lossyImageCompressionRatio:s.floatString("x00282112"),lossyImageCompressionMethod:s.string("x00282114")};if(t===r.PATIENT)return{patientID:s.string("x00100020"),patientName:s.string("x00100010")};if(t===r.PATIENT_STUDY)return{patientAge:s.intString("x00101010"),patientSize:s.floatString("x00101020"),patientSex:s.string("x00100040"),patientWeight:s.floatString("x00101030")};if(t===r.NM_MULTIFRAME_GEOMETRY){const e=s.string("x00080060"),t=ee(s,2);return{modality:e,imageType:s.string("x00080008"),imageSubType:t,imageOrientationPatient:te(s),imagePositionPatient:ne(s),sliceThickness:ae(s),pixelSpacing:re(s),numberOfFrames:s.uint16("x00280008"),isNMReconstructable:Z(t)&&e.includes("NM")}}if(t===r.IMAGE_PLANE){const e=te(s),t=ne(s),n=re(s),r=ae(s);let a=null,o=null;n&&(o=n[0],a=n[1]);let i=null,l=null;return e&&(i=[parseFloat(e[0]),parseFloat(e[1]),parseFloat(e[2])],l=[parseFloat(e[3]),parseFloat(e[4]),parseFloat(e[5])]),{frameOfReferenceUID:s.string("x00200052"),rows:s.uint16("x00280010"),columns:s.uint16("x00280011"),imageOrientationPatient:e,rowCosines:i,columnCosines:l,imagePositionPatient:t,sliceThickness:r,sliceLocation:s.floatString("x00201041"),pixelSpacing:n,rowPixelSpacing:o,columnPixelSpacing:a}}if(t===r.CINE)return{frameTime:s.floatString("x00181063")};if(t===r.IMAGE_PIXEL)return w(s);if(t===r.VOI_LUT){const e=I(s);return{windowCenter:T(s,"x00281050",1),windowWidth:T(s,"x00281051",1),voiLUTSequence:D(e,s.elements.x00283010)}}if(t===r.MODALITY_LUT)return{rescaleIntercept:s.floatString("x00281052"),rescaleSlope:s.floatString("x00281053"),rescaleType:s.string("x00281054"),modalityLUTSequence:D(s.uint16("x00280103"),s.elements.x00283000)};if(t===r.SOP_COMMON)return{sopClassUID:s.string("x00080016"),sopInstanceUID:s.string("x00080018")};if(t===r.PET_ISOTOPE){const e=s.elements.x00540016;if(void 0===e)return;const t=e.items[0].dataSet;return{radiopharmaceuticalInfo:{radiopharmaceuticalStartTime:a.parseTM(t.string("x00181072")||""),radionuclideTotalDose:t.floatString("x00181074"),radionuclideHalfLife:t.floatString("x00181075")}}}if(t===r.OVERLAY_PLANE)return function(e){const t=[];for(let n=0;n<=30;n+=2){let r=`x60${n.toString(16)}`;4===r.length&&(r=`x600${n.toString(16)}`);const a=e.elements[`${r}3000`];if(!a)continue;const o=[];for(let t=0;t<a.length;t++)for(let n=0;n<8;n++){const r=e.byteArray[a.dataOffset+t];o[8*t+n]=r>>n&1}t.push({rows:e.uint16(`${r}0010`),columns:e.uint16(`${r}0011`),type:e.string(`${r}0040`),x:e.int16(`${r}0050`,1)-1,y:e.int16(`${r}0050`,0)-1,pixelData:o,description:e.string(`${r}0022`),label:e.string(`${r}1500`),roiArea:e.string(`${r}1301`),roiMean:e.string(`${r}1302`),roiStandardDeviation:e.string(`${r}1303`)})}return{overlays:t}}(s);if("transferSyntax"===t){let e;try{e=s.string("x00020010")}catch(e){}return{transferSyntaxUID:e}}if(t===r.PET_SERIES)return{correctedImage:s.string("x00280051"),units:s.string("x00541001"),decayCorrection:s.string("x00541102")};if(t===r.PET_IMAGE)return{frameReferenceTime:s.floatString(s.string("x00541300")||""),actualFrameDuration:s.intString(s.string("x00181242"))};if(t===r.ULTRASOUND_ENHANCED_REGION)return le(s);if(t===r.CALIBRATION){if("US"===s.string("x00080060")){return{sequenceOfUltrasoundRegions:le(s)}}}return"instance"===t?oe(n,e,se):void 0}};let ue=[];const fe={add:function(e){return"dicomfile:"+(ue.push(e)-1)},get:function(e){return ue[e]},remove:function(e){ue[e]=void 0},purge:function(){ue=[]}};var de=r(713);function ge(e,t){const{dicomParser:n}=p;if(e.elements.x7fe00010&&e.elements.x7fe00010.basicOffsetTable.length)return n.readEncapsulatedImageFrame(e,e.elements.x7fe00010,t);if(function(e){return e.intString("x00280008")!==e.elements.x7fe00010.fragments.length}(e)){const r=n.createJPEGBasicOffsetTable(e,e.elements.x7fe00010);return n.readEncapsulatedImageFrame(e,e.elements.x7fe00010,t,r)}const r=e.elements.x7fe00010.fragments,a=new de.ByteStream(e.byteArrayParser,e.byteArray,e.elements.x7fe00010.dataOffset),o=(0,de.readSequenceItem)(a);if("xfffee000"!==o.tag)throw"dicomParser.readEncapsulatedPixelData: missing basic offset table xfffee000";a.seek(o.length);const i=a.position;if(t+1>r.length)throw"dicomParser.readEncapsulatedPixelData: frame exceeds number of fragments";const s=i+r[t].offset+8,l=r[t].length;return new Uint8Array(a.byteArray.buffer.slice(a.byteArray.byteOffset+s,a.byteArray.byteOffset+s+l))}function me(e,t){return e&1<<t}const pe=function(e,t,n){const r=new Uint8Array(n);for(let a=0;a<n;a++){const n=e[Math.floor(a/8)+t],o=a%8;r[a]=me(n,o)?1:0}return r};const he=function(e,t){const n=e.elements.x7fe00010||e.elements.x7fe00008,r=e.uint16("x00280100"),a=e.uint16("x00280010"),o=e.uint16("x00280011");let i=e.uint16("x00280002");"YBR_FULL_422"===e.string("x00280004")&&(i=2,console.warn("Using SamplesPerPixel of 2 for YBR_FULL_422 photometric interpretation.\n See http://dicom.nema.org/medical/dicom/current/output/chtml/part03/sect_C.7.6.3.html for more information."));const s=n.dataOffset,l=a*o*i;let c;if(8===r){if(c=s+t*l,c>=e.byteArray.length)throw new Error("frame exceeds size of pixelData");return new Uint8Array(e.byteArray.buffer.slice(c,c+l))}if(16===r){if(c=s+t*l*2,c>=e.byteArray.length)throw new Error("frame exceeds size of pixelData");return new Uint8Array(e.byteArray.buffer.slice(c,c+2*l))}if(1===r){if(c=s+t*l*.125,c>=e.byteArray.length)throw new Error("frame exceeds size of pixelData");return pe(e.byteArray,c,l)}if(32===r){if(c=s+t*l*4,c>=e.byteArray.length)throw new Error("frame exceeds size of pixelData");return new Uint8Array(e.byteArray.buffer.slice(c,c+4*l))}throw new Error("unsupported pixel format")};const xe=function(e){const t=L(e),n=parseInt(t.url,10),r=fe.get(n);return new Promise(((e,t)=>{const n=new FileReader;n.onload=t=>{const n=t.target.result;e(n)},n.onerror=t,n.readAsArrayBuffer(r)}))};const ye=function(e){let t,n=e[0],r=e[0];const a=e.length;for(let o=1;o<a;o++)t=e[o],n=Math.min(n,t),r=Math.max(r,t);return{min:n,max:r}};function be(e,t,r){0===e.planarConfiguration?n(e.pixelData,t,r):o(e.pixelData,t,r)}function Pe(e,t,n){if("RGB"===e.photometricInterpretation)be(e,t,n);else if("YBR_RCT"===e.photometricInterpretation)be(e,t,n);else if("YBR_ICT"===e.photometricInterpretation)be(e,t,n);else if("PALETTE COLOR"===e.photometricInterpretation)y(e,t,n);else if("YBR_FULL_422"===e.photometricInterpretation)!function(e,t,n){if(void 0===e)throw new Error("convertYBRFull422ByPixel: ybrBuffer must be defined");if(e.length%2!=0)throw new Error(`convertYBRFull422ByPixel: ybrBuffer length ${e.length} must be divisible by 2`);const r=e.length/2;let a=0,o=0;if(n)for(let n=0;n<r;n+=2){const n=e[a++],r=e[a++],i=e[a++],s=e[a++];t[o++]=n+1.402*(s-128),t[o++]=n-.34414*(i-128)-.71414*(s-128),t[o++]=n+1.772*(i-128),t[o++]=255,t[o++]=r+1.402*(s-128),t[o++]=r-.34414*(i-128)-.71414*(s-128),t[o++]=r+1.772*(i-128),t[o++]=255}else for(let n=0;n<r;n+=2){const n=e[a++],r=e[a++],i=e[a++],s=e[a++];t[o++]=n+1.402*(s-128),t[o++]=n-.34414*(i-128)-.71414*(s-128),t[o++]=n+1.772*(i-128),t[o++]=r+1.402*(s-128),t[o++]=r-.34414*(i-128)-.71414*(s-128),t[o++]=r+1.772*(i-128)}}(e.pixelData,t,n);else{if("YBR_FULL"!==e.photometricInterpretation)throw new Error(`No color space conversion for photometric interpretation ${e.photometricInterpretation}`);!function(e,t,n){0===e.planarConfiguration?i(e.pixelData,t,n):s(e.pixelData,t,n)}(e,t,n)}}function we(e){return function(e){let t;try{return decodeURIComponent(escape(e))}catch(n){if(t=n,t instanceof URIError)return e;throw t}}(String.fromCharCode.apply(null,Array.prototype.slice.apply(new Uint8Array(e))))}const Se=function(e,t,n){const r=(new Date).getTime(),a=new Blob([t],{type:"image/jpeg"});return new Promise(((t,o)=>{const i=new FileReader;void 0===i.readAsBinaryString?i.readAsArrayBuffer(a):i.readAsBinaryString(a),i.onload=function(){const a=new Image;a.onload=function(){n.height=a.height,n.width=a.width,e.rows=a.height,e.columns=a.width;const o=n.getContext("2d");o.drawImage(this,0,0);const i=o.getImageData(0,0,a.width,a.height),s=(new Date).getTime();e.pixelData=new Uint8Array(i.data.buffer),e.imageData=i,e.decodeTimeInMS=s-r;const l=ye(e.pixelData);e.smallestPixelValue=l.min,e.largestPixelValue=l.max,e.pixelDataLength=e.pixelData.length,t(e)},a.onerror=function(e){o(e)},void 0===i.readAsBinaryString?a.src=`data:image/jpeg;base64,${window.btoa(we(i.result))}`:a.src=`data:image/jpeg;base64,${window.btoa(i.result)}`},i.onerror=e=>{o(e)}}))};function De(e,t,n,r,a){const o={...r};delete o.loader,delete o.streamingData;const i=p.cornerstone.getWebWorkerManager(),s=o.priority||void 0;o.transferPixelData&&n.buffer;return i.executeTask("dicomImageLoader","decodeTask",{imageFrame:e,transferSyntax:t,pixelData:n,options:o,decodeConfig:a},{priority:s,requestType:o?.requestType})}const Ie=function(e,t,n,r,a={},o){switch(t){case"1.2.840.10008.1.2":case"1.2.840.10008.1.2.1":case"1.2.840.10008.1.2.2":case"1.2.840.10008.1.2.1.99":case"1.2.840.10008.1.2.5":case"1.2.840.10008.1.2.4.51":case"1.2.840.10008.1.2.4.57":case"1.2.840.10008.1.2.4.70":case"1.2.840.10008.1.2.4.80":case"1.2.840.10008.1.2.4.81":case"1.2.840.10008.1.2.4.90":case"1.2.840.10008.1.2.4.91":case"3.2.840.10008.1.2.4.96":case"1.2.840.10008.1.2.4.201":case"1.2.840.10008.1.2.4.202":case"1.2.840.10008.1.2.4.203":return De(e,t,n,a,o);case"1.2.840.10008.1.2.4.50":return 8!==e.bitsAllocated||3!==e.samplesPerPixel&&4!==e.samplesPerPixel?De(e,t,n,a,o):Se(e,n,r)}return Promise.reject(new Error(`No decoder for transfer syntax ${t}`))};const Te=function(e){const{cornerstone:t}=p,n=t.metaData.get("imagePixelModule",e);return{samplesPerPixel:n.samplesPerPixel,photometricInterpretation:n.photometricInterpretation,planarConfiguration:n.planarConfiguration,rows:n.rows,columns:n.columns,bitsAllocated:n.bitsAllocated,bitsStored:n.bitsStored,pixelRepresentation:n.pixelRepresentation,smallestPixelValue:n.smallestPixelValue,largestPixelValue:n.largestPixelValue,redPaletteColorLookupTableDescriptor:n.redPaletteColorLookupTableDescriptor,greenPaletteColorLookupTableDescriptor:n.greenPaletteColorLookupTableDescriptor,bluePaletteColorLookupTableDescriptor:n.bluePaletteColorLookupTableDescriptor,redPaletteColorLookupTableData:n.redPaletteColorLookupTableData,greenPaletteColorLookupTableData:n.greenPaletteColorLookupTableData,bluePaletteColorLookupTableData:n.bluePaletteColorLookupTableData,pixelData:void 0,imageId:e}};function Le(e){return"RGB"===e||"PALETTE COLOR"===e||"YBR_FULL"===e||"YBR_FULL_422"===e||"YBR_PARTIAL_422"===e||"YBR_PARTIAL_420"===e||"YBR_RCT"===e||"YBR_ICT"===e}let Ee="";function Ce(e){const t=function(e,t){let n;return Number.isInteger(e)&&Number.isInteger(t)&&(e>=0?t<=255?n=Uint8Array:t<=65535&&(n=Uint16Array):e>=-128&&t<=127?n=Int8Array:e>=-32768&&t<=32767&&(n=Int16Array)),n||Float32Array}(e.smallestPixelValue,e.largestPixelValue);if(!t)throw new Error("Could not apply a typed array to the pixel data");{const n=new t(e.pixelData);e.pixelData=n}}const ve=function(e,t,n,r={}){const a=r.useRGBA;if(r.preScale={enabled:!r.preScale||void 0===r.preScale.enabled||r.preScale.enabled},!t?.length)return Promise.reject(new Error("The pixel data is missing"));const{cornerstone:o}=p,{MetadataModules:i}=o.Enums,s=document.createElement("canvas"),l=Te(e);if(l.decodeLevel=r.decodeLevel,r.allowFloatRendering=o.canRenderFloatTextures(),r.preScale.enabled){const t=function(e,t){const n=e.get("modalityLutModule",t)||{},r=e.get("generalSeriesModule",t)||{},{modality:a}=r,o={rescaleSlope:n.rescaleSlope,rescaleIntercept:n.rescaleIntercept,modality:a},i=e.get("scalingModule",t)||{};return{...o,..."PT"===a&&{suvbw:i.suvbw}}}(o.metaData,e);t&&(r.preScale={...r.preScale,scalingParameters:t})}const{decodeConfig:c}=d();Object.keys(l).forEach((e=>{("function"==typeof l[e]||l[e]instanceof Promise)&&delete l[e]}));const u=Ie(l,n,t,s,r,c),f=Le(l.photometricInterpretation);return new Promise(((t,n)=>{u.then((function(n){let l=!1;if(r.targetBuffer&&r.targetBuffer.type&&!f){const{arrayBuffer:e,type:t,offset:a=0,length:o}=r.targetBuffer,i=n.pixelDataLength,s=a,c=null!=o?o:i-s,u={Uint8Array,Uint16Array,Int16Array,Float32Array};if(c!==n.pixelDataLength)throw new Error(`target array for image does not have the same length (${c}) as the decoded image length (${n.pixelDataLength}).`);const f=u[t],d=e?new f(e,s,c):new f(n.pixelData);if(c!==n.pixelDataLength)throw new Error("target array for image does not have the same length as the decoded image length.");n.pixelData=d,l=!0}l||Ce(n);const c=o.metaData.get(i.IMAGE_PLANE,e)||{},u=o.metaData.get(i.VOI_LUT,e)||{},d=o.metaData.get(i.MODALITY_LUT,e)||{},g=o.metaData.get(i.SOP_COMMON,e)||{},m=o.metaData.get(i.CALIBRATION,e)||{},{rows:p,columns:h}=n;if(f){if(function(e){if(void 0===e)return!1;const{rows:t,columns:n,photometricInterpretation:r,pixelDataLength:a}=e;return a!==4*n*t&&(r.endsWith("420")?a===(3*Math.ceil(n/2)+Math.floor(n/2))*t:r.endsWith("422")?a===(3*Math.ceil(n/2)+Math.floor(n/2))*Math.ceil(t/2)+Math.floor(t/2)*n:"RGB"!==r)}(n)){s.height=n.rows,s.width=n.columns;let e=s.getContext("2d").createImageData(n.columns,n.rows);a||(e={...e,data:new Uint8ClampedArray(n.samplesPerPixel*n.columns*n.rows)}),Pe(n,e.data,a),n.imageData=e,n.pixelData=e.data,n.pixelDataLength=e.data.length}else if(!a&&n.pixelDataLength===4*p*h){const e=new Uint8Array(n.pixelData.length/4*3);n.pixelData=function(e,t){const n=e.length/4;let r=0,a=0;for(let o=0;o<n;o++)t[a++]=e[r++],t[a++]=e[r++],t[a++]=e[r++],r++;return t}(n.pixelData,e),n.pixelDataLength=n.pixelData.length}const e=ye(n.pixelData);n.smallestPixelValue=e.min,n.largestPixelValue=e.max}const x={imageId:e,dataType:n.pixelData.constructor.name,color:f,calibration:m,columnPixelSpacing:c.columnPixelSpacing,columns:n.columns,height:n.rows,preScale:n.preScale,intercept:d.rescaleIntercept?d.rescaleIntercept:0,slope:d.rescaleSlope?d.rescaleSlope:1,invert:"MONOCHROME1"===n.photometricInterpretation,minPixelValue:n.smallestPixelValue,maxPixelValue:n.largestPixelValue,rowPixelSpacing:c.rowPixelSpacing,rows:n.rows,sizeInBytes:n.pixelData.byteLength,width:n.columns,windowCenter:u.windowCenter?u.windowCenter[0]:void 0,windowWidth:u.windowWidth?u.windowWidth[0]:void 0,voiLUTFunction:u.voiLUTFunction?u.voiLUTFunction:void 0,decodeTimeInMS:n.decodeTimeInMS,floatPixelData:void 0,imageFrame:n,rgba:f&&a,getPixelData:()=>n.pixelData,getCanvas:void 0,numberOfComponents:n.samplesPerPixel};var y;if(x.color&&(x.getCanvas=function(){if(Ee===e)return s;const t=x.columns,r=x.rows;s.height=r,s.width=t;const a=s.getContext("2d"),o=a.createImageData(t,r),i=n.pixelData;if(i.length===t*r*4)for(let e=0;e<i.length;e++)o.data[e]=i[e];else if(i.length===t*r*3){let e=0;for(let t=0;t<i.length;t+=3)o.data[e++]=i[t],o.data[e++]=i[t+1],o.data[e++]=i[t+2],o.data[e++]=255}return n.pixelData=o.data,n.pixelDataLength=o.data.length,n.imageData=o,a.putImageData(n.imageData,0,0),Ee=e,s}),d.modalityLUTSequence&&d.modalityLUTSequence.length>0&&("1.2.840.10008.5.1.4.1.1.12.1"!==(y=g.sopClassUID)&&"1.2.840.10008.5.1.4.1.1.12.2.1"!==y)&&(x.modalityLUT=d.modalityLUTSequence[0]),u.voiLUTSequence&&u.voiLUTSequence.length>0&&(x.voiLUT=u.voiLUTSequence[0]),x.color&&(x.windowWidth=256,x.windowCenter=128),void 0===x.windowCenter||void 0===x.windowWidth){const e=x.imageFrame.smallestPixelValue,t=x.imageFrame.largestPixelValue;x.windowWidth=t-e,x.windowCenter=(t+e)/2}t(x)}),n)}))};const Ae=function(e,t=0){const n=e.elements.x7fe00010||e.elements.x7fe00008;return n?n.encapsulatedPixelData?ge(e,t):he(e,t):null};function Oe(e,t,n=0,r,a,o){const i=(new Date).getTime(),s={cancelFn:void 0,promise:void 0};return s.promise=new Promise(((l,c)=>{e.then((e=>{const u=Ae(e,n),f=e.string("x00020010"),d=(new Date).getTime(),g=ve(t,u,f,a);!function(e,t){e.decache=function(){const e=L(t);K.unload(e.url)}}(s,t),g.then((t=>{t.data=e,t.sharedCacheKey=r;const n=(new Date).getTime();t.loadTimeInMS=d-i,t.totalTimeInMS=n-i,void 0!==o&&void 0!==o.imageDoneCallback&&o.imageDoneCallback(t),l(t)}),(function(t){c({error:t,dataSet:e})}))}),(function(e){c({error:e})}))})),s}function Me(e){return"dicomweb"===e||"wadouri"===e?E:"dicomfile"===e?xe:void 0}function Re(e,t={}){const n=L(e);delete(t=Object.assign({},t)).loader;const r=Me(n.scheme);if(K.isLoaded(n.url)){return function(e,t,n=0,r,a){const o=(new Date).getTime();return{promise:new Promise(((i,s)=>{const l=(new Date).getTime();let c;try{const r=Ae(e,n),o=e.string("x00020010");c=ve(t,r,o,a)}catch(t){return void s({error:t,dataSet:e})}c.then((t=>{t.data=e,t.sharedCacheKey=r;const n=(new Date).getTime();t.loadTimeInMS=l-o,t.totalTimeInMS=n-o,i(t)}),s)})),cancelFn:void 0}}(K.get(n.url,r,e),e,n.pixelDataFrame,n.url,t)}return Oe(K.load(n.url,r,e),e,n.frame,n.url,t)}function Fe(e){e.registerImageLoader("dicomweb",Re),e.registerImageLoader("wadouri",Re),e.registerImageLoader("dicomfile",Re),e.metaData.addProvider(ce)}const Ue={metaData:{getImagePixelModule:w,getLUTs:D,getModalityLUTOutputPixelRepresentation:I,getNumberValues:T,metaDataProvider:ce},dataSetCacheManager:K,fileManager:fe,getEncapsulatedImageFrame:ge,getUncompressedImageFrame:he,loadFileRequest:xe,loadImageFromPromise:Oe,getLoaderForScheme:Me,loadImage:Re,parseImageId:L,unpackBinaryFrame:pe,register:Fe};const Be=function(e,t,n){return t=t||0,e&&e.Value?Array.isArray(e.Value)&&e.Value.length<=t?n:e.Value[t]:n};const Ne=function(e,t,n){const r=Be(e,t,n);if(void 0!==r)return parseFloat(String(r))};const ke=function(e,t){const n=Be(e,t);if(void 0!==n)return parseFloat(n)};const _e=function(e,t){if(!e)return;if(!e.Value)return;if(!Array.isArray(e.Value))return;if(t&&e.Value.length<t)return;const n=[];for(let t=0;t<e.Value.length;t++)n.push(parseFloat(e.Value[t]));return n};function Ve(e){const t=e.indexOf(":");return e.substring(t+1)}function je(e,t=!0){return e&&e.Value?e.Value[0]&&t?e.Value[0]:e.Value:e}function $e(e,t,n){return{shared:(t?Object.values(t[0]):[]).map((e=>e[0])).filter((e=>void 0!==e&&"object"==typeof e)),perFrame:(e?Object.values(e[n-1]):[]).map((e=>e.Value[0])).filter((e=>void 0!==e&&"object"==typeof e))}}function Ge(e){let{52009230:t,52009229:n,"00280008":r,...a}=e;return t=je(t,!1),n=je(n,!1),r=je(r),{PerFrameFunctionalGroupsSequence:t,SharedFunctionalGroupsSequence:n,NumberOfFrames:r,rest:a}}let qe=[],Ye={};function We(e){return function(e){const t=e.indexOf("/frames/")+8,n=e.slice(0,t),r=parseInt(e.slice(t),10);return{metadata:qe[`${n}1`],frame:r}}(Ve(e))}function Xe(e){const t=Be(e["00280008"]);return t&&t>1}const ze={add:function(e,t){const n=Ve(e);Object.defineProperty(t,"isMultiframe",{value:Xe(t),enumerable:!1}),qe[n]=t},get:function(e){const t=Ve(e),n=qe[t];if(n&&!n?.isMultiframe)return n;const r=Ye[t];if(r)return r;const a=We(t);if(!a||!a.metadata)return;const{metadata:o,frame:i}=a;if(o){const e=function(e,t){const{PerFrameFunctionalGroupsSequence:n,SharedFunctionalGroupsSequence:r,NumberOfFrames:a,rest:o}=Ge(t);if(n||a>1){const{shared:i,perFrame:s}=$e(n,r,e),l=Object.assign(t,{frameNumber:e});return[...i,...s].forEach((e=>{Object.entries(e).forEach((([e,t])=>{l[e]=t}))})),Object.assign(o,{"00280008":a},l)}return t}(i,o);return Ye[t]=e,e}},remove:function(e){const t=Ve(e);qe[t]=void 0,Ye[t]=void 0},purge:function(){qe=[],Ye={}}};function He(e){return Be(e["00080060"]).includes("NM")}function Qe(e,t){const n=je(e["00080008"],!1);if(n)return n[t]}function Je(e){let t=_e(e["00200037"],6);return!t&&He(e)&&(t=function(e){let t;const n=Qe(e,2);if(n&&Z(n)){const n=je(e["00540022"]);n&&(t=_e(n["00200037"],6))}return t}(e)),t}function Ke(e){let t=_e(e["00200032"],3);return!t&&He(e)&&(t=function(e){let t;const n=Qe(e,2);if(n&&Z(n)){const n=je(e["00540022"]);n&&(t=_e(n["00200032"],3))}return t}(e)),t}function Ze(e,t){const n=_e(e[t]);return n?n[0]:null}const et=function(e){return e?.Value?.length?Array.isArray(e.Value)?e.Value:"object"==typeof e.Value?(console.warn("Warning: Value should be an array, but an object was found. Encapsulating the object in an array."),[e.Value]):[]:[]};function tt(e){const t=et(e["00186011"]);if(!t||!t.length)return null;return t.map((e=>{const t=Ze(e,"0018602C"),n=Ze(e,"0018602E"),r=Ze(e,"00186024"),a=Ze(e,"00186026");return{regionLocationMinY0:Ze(e,"0018601A"),regionLocationMaxY1:Ze(e,"0018601E"),regionLocationMinX0:Ze(e,"00186018"),regionLocationMaxX1:Ze(e,"0018601C"),referencePixelX0:Ze(e,"00186020"),referencePixelY0:Ze(e,"00186022"),physicalDeltaX:t,physicalDeltaY:n,physicalUnitsXDirection:r,physicalUnitsYDirection:a,referencePhysicalPixelValueY:Ze(e,"0018602A"),referencePhysicalPixelValueX:Ze(e,"00186028"),regionSpatialFormat:Ze(e,"00186012"),regionDataType:Ze(e,"00186014"),regionFlags:Ze(e,"00186016"),transducerFrequency:Ze(e,"00186030")}}))}function nt(e,t){return{transferSyntaxUID:Be(t["00020010"])||Be(t["00083002"])}}const rt=function e(t,n){const{MetadataModules:r}=p.cornerstone.Enums,{dicomParser:a}=p;if(t===r.MULTIFRAME){const{metadata:e,frame:t}=We(n);if(!e)return;const{PerFrameFunctionalGroupsSequence:r,SharedFunctionalGroupsSequence:a,NumberOfFrames:o}=Ge(e);if(r||o>1){const{shared:e,perFrame:n}=$e(r,a,t);return{NumberOfFrames:o,PerFrameFunctionalInformation:n,SharedFunctionalInformation:e}}return{NumberOfFrames:o}}const o=ze.get(n);if(o){if(t===r.GENERAL_STUDY)return{studyDescription:Be(o["00081030"]),studyDate:a.parseDA(Be(o["00080020"])),studyTime:a.parseTM(Be(o["00080030"],0,"")),accessionNumber:Be(o["00080050"])};if(t===r.GENERAL_SERIES)return{modality:Be(o["00080060"]),seriesInstanceUID:Be(o["0020000E"]),seriesNumber:ke(o["00200011"]),studyInstanceUID:Be(o["0020000D"]),seriesDate:a.parseDA(Be(o["00080021"])),seriesTime:a.parseTM(Be(o["00080031"],0,"")),acquisitionDate:a.parseDA(Be(o["00080022"])),acquisitionTime:a.parseTM(Be(o["00080032"],0,""))};if(t===r.GENERAL_IMAGE)return{sopInstanceUID:Be(o["00080018"]),instanceNumber:ke(o["00200013"]),lossyImageCompression:Be(o["00282110"]),lossyImageCompressionRatio:ke(o["00282112"]),lossyImageCompressionMethod:Be(o["00282114"])};if(t===r.PATIENT)return{patientID:Be(o["00100020"]),patientName:Be(o["00100010"])};if(t===r.PATIENT_STUDY)return{patientAge:ke(o["00101010"]),patientSize:ke(o["00101020"]),patientSex:Be(o["00100040"]),patientWeight:ke(o["00101030"])};if(t===r.NM_MULTIFRAME_GEOMETRY){const e=Be(o["00080060"]),t=Qe(o,2);return{modality:e,imageType:Be(o["00080008"]),imageSubType:t,imageOrientationPatient:Je(o),imagePositionPatient:Ke(o),sliceThickness:ke(o["00180050"]),spacingBetweenSlices:ke(o["00180088"]),pixelSpacing:_e(o["00280030"],2),numberOfFrames:ke(o["00280008"]),isNMReconstructable:Z(t)&&e.includes("NM")}}if(t===r.IMAGE_PLANE){let e=Je(o),t=Ke(o);const n=_e(o["00280030"],2);let r=null,a=null,i=null,s=null,l=!1;return n?(a=n[0],r=n[1]):(l=!0,a=1,r=1),e?(i=[parseFloat(e[0]),parseFloat(e[1]),parseFloat(e[2])],s=[parseFloat(e[3]),parseFloat(e[4]),parseFloat(e[5])]):(i=[0,1,0],s=[0,0,-1],l=!0,e=[...i,...s]),t||(t=[0,0,0],l=!0),{frameOfReferenceUID:Be(o["00200052"]),rows:ke(o["00280010"]),columns:ke(o["00280011"]),imageOrientationPatient:e,rowCosines:i,columnCosines:s,imagePositionPatient:t,sliceThickness:ke(o["00180050"]),sliceLocation:ke(o["00201041"]),pixelSpacing:n,rowPixelSpacing:a,columnPixelSpacing:r,usingDefaultValues:l}}if(t===r.ULTRASOUND_ENHANCED_REGION)return tt(o);if(t===r.CALIBRATION){if("US"===Be(o["00080060"])){return{sequenceOfUltrasoundRegions:tt(o)}}}if(t===r.IMAGE_URL)return function(e,t){const{transferSyntaxUID:n}=nt(e,t),r=p.cornerstone.utilities.isVideoTransferSyntax(n),a=e.substring(7),o=a.replace("/frames/","/thumbnail/");let i=a.replace("/frames/","/rendered/");r&&(i=i.replace("/rendered/1","/rendered"));return{isVideo:r,rendered:i,thumbnail:o}}(n,o);if(t===r.CINE)return function(e,t){const n=Be(t["00180040"]);return{cineRate:n,numberOfFrames:ke(t["00280008"])}}(0,o);if(t===r.IMAGE_PIXEL)return{samplesPerPixel:ke(o["00280002"]),photometricInterpretation:Be(o["00280004"]),rows:ke(o["00280010"]),columns:ke(o["00280011"]),bitsAllocated:ke(o["00280100"]),bitsStored:ke(o["00280101"]),highBit:Be(o["00280102"]),pixelRepresentation:ke(o["00280103"]),planarConfiguration:ke(o["00280006"]),pixelAspectRatio:Be(o["00280034"]),smallestPixelValue:ke(o["00280106"]),largestPixelValue:ke(o["00280107"]),redPaletteColorLookupTableDescriptor:_e(o["00281101"]),greenPaletteColorLookupTableDescriptor:_e(o["00281102"]),bluePaletteColorLookupTableDescriptor:_e(o["00281103"]),redPaletteColorLookupTableData:_e(o["00281201"]),greenPaletteColorLookupTableData:_e(o["00281202"]),bluePaletteColorLookupTableData:_e(o["00281203"])};if(t===r.VOI_LUT)return{windowCenter:_e(o["00281050"],1),windowWidth:_e(o["00281051"],1)};if(t===r.MODALITY_LUT)return{rescaleIntercept:ke(o["00281052"]),rescaleSlope:ke(o["00281053"]),rescaleType:Be(o["00281054"])};if(t===r.SOP_COMMON)return{sopClassUID:Be(o["00080016"]),sopInstanceUID:Be(o["00080018"])};if(t===r.PET_ISOTOPE){const e=Be(o["00540016"]);if(void 0===e)return;return{radiopharmaceuticalInfo:{radiopharmaceuticalStartTime:a.parseTM(Be(e["00181072"],0,"")),radiopharmaceuticalStartDateTime:Be(e["00181078"],0,""),radionuclideTotalDose:ke(e["00181074"]),radionuclideHalfLife:ke(e["00181075"])}}}return t===r.OVERLAY_PLANE?function(e){const t=[];for(let n=0;n<=30;n+=2){let r=`x60${n.toString(16)}`;4===r.length&&(r=`x600${n.toString(16)}`);const a=Be(e[`${r}3000`]);if(!a)continue;const o=[];for(let t=0;t<a.length;t++)for(let n=0;n<8;n++){const r=e.Value[a.dataOffset+t];o[8*t+n]=r>>n&1}t.push({rows:ke(e[`${r}0010`]),columns:ke(e[`${r}0011`]),type:Be(e[`${r}0040`]),x:ke(e[`${r}0050`],1)-1,y:ke(e[`${r}0050`],0)-1,pixelData:o,description:Be(e[`${r}0022`]),label:Be(e[`${r}1500`]),roiArea:Be(e[`${r}1301`]),roiMean:Be(e[`${r}1302`]),roiStandardDeviation:Be(e[`${r}1303`])})}return{overlays:t}}(o):"transferSyntax"===t?nt(n,o):t===r.PET_SERIES?{correctedImage:Be(o["00280051"]),units:Be(o["00541001"]),decayCorrection:Be(o["00541102"])}:t===r.PET_IMAGE?{frameReferenceTime:ke(o["00541300"]),actualFrameDuration:ke(o["00181242"])}:"instance"===t?oe(n,e,se):void 0}};function at(e,t,n={},r={}){const a=d(),{retrieveOptions:o={},streamingData:i}=r,s=i.chunkSize||function(e,t,n){const r=t[n];if("function"!=typeof r)return r;const a=ze.get(e);return r(a,e)}(t,o,"chunkSize")||65536,l=new Promise((async(t,r)=>{const l=Object.assign({},n);Object.keys(l).forEach((function(e){null!==l[e]&&void 0!==l[e]||delete l[e]}));try{i.encodedData||(i.chunkSize=s,i.rangesFetched=0);const n=function(e,t){const{totalBytes:n,encodedData:r,chunkSize:a=65536}=e,{rangeIndex:o=0}=t;if(!(-1!==o||n&&r))return[0,""];if(-1===o||r?.byteLength>n-a)return[r?.byteLength||0,""];return[r?.byteLength||0,a*(o+1)-1]}(i,o),{encodedData:r,responseHeaders:a}=await async function(e,t,n,r){n&&(t=Object.assign(t,{Range:`bytes=${n[0]}-${n[1]}`}));let{encodedData:a}=r;if(n[1]&&a?.byteLength>n[1])return r;const o=await fetch(e,{headers:t,signal:void 0}),i=await o.arrayBuffer(),s=new Uint8Array(i),{status:l}=o;let c;a?(c=new Uint8Array(a.length+s.length),c.set(a,0),c.set(s,a.length),r.rangesFetched=1):(c=new Uint8Array(s.length),c.set(s,0),r.rangesFetched++);r.encodedData=a=c,r.responseHeaders=o.headers;const u=o.headers.get("Content-Range");u?r.totalBytes=Number(u.split("/")[1]):206===l&&n?""===n[1]||a?.length<n[1]?r.totalBytes=a.byteLength:r.totalBytes=Number.MAX_SAFE_INTEGER:r.totalBytes=a?.byteLength;return r}(e,l,n,i),c=a.get("content-type"),{totalBytes:u}=i,f=u===r.byteLength,d=F(c,r,{isPartial:!0}),g=B(o,f||d.extractDone);t({...d,imageQualityStatus:g,percentComplete:d.extractDone?100:100*s/u})}catch(e){(e=>{if("function"==typeof a.errorInterceptor){const e=new Error("request failed");a.errorInterceptor(e)}else console.warn("rangeRequest:Caught",e)})(e),console.error(e),r(e)}}));return l}const ot=function(e,t,n="application/octet-stream",r){const{streamingData:a,retrieveOptions:o={}}=r||{},i={Accept:n};let s=o.urlArguments?`${e}${-1===e.indexOf("?")?"?":"&"}${o.urlArguments}`:e;if(o.framesPath&&(s=s.replace("/frames/",o.framesPath)),a?.url!==s&&(r.streamingData={url:s}),void 0!==o.rangeIndex)return at(s,t,i,r);if(o.streaming)return k(s,t,i,r);const l=E(s,t,i),{xhr:c}=l;return l.then((function(e){const t=F(c.getResponseHeader("Content-Type")||"application/octet-stream",new Uint8Array(e));return t.imageQualityStatus=B(o,!0),t}))},{ProgressiveIterator:it}=e,{ImageQualityStatus:st}=t,lt=new Set(["3.2.840.10008.1.2.4.96","1.2.840.10008.1.2.4.202","1.2.840.10008.1.2.4.203"]);function ct(e){const t="1.2.840.10008.1.2";if(!e)return t;const n=e.split(";"),r={};n.forEach((e=>{const t=e.split("=");if(2!==t.length)return;const n=t[1].trim().replace(/"/g,"");r[t[0].trim()]=n}));const a={"image/jpeg":"1.2.840.10008.1.2.4.50","image/x-dicom-rle":"1.2.840.10008.1.2.5","image/x-jls":"1.2.840.10008.1.2.4.80","image/jls":"1.2.840.10008.1.2.4.80","image/jll":"1.2.840.10008.1.2.4.70","image/jp2":"1.2.840.10008.1.2.4.90","image/jpx":"1.2.840.10008.1.2.4.92","image/jphc":"3.2.840.10008.1.2.4.96","image/jxl":"1.2.840.10008.1.2.4.140"};return r["transfer-syntax"]?r["transfer-syntax"]:e&&!Object.keys(r).length&&a[e]?a[e]:r.type&&a[r.type]?a[r.type]:a[e]?a[e]:t}function ut(e,t=4){const n=e/100-.02;return n>1/4?Math.min(t,0):n>1/16?Math.min(t,1):n>1/64?Math.min(t,2):Math.min(t,3)}const ft=function(e,t={}){const n=p.cornerstone.imageRetrievalPoolManager,r=(new Date).getTime(),a=new it("decompress"),o=t.requestType||"interaction",i=t.additionalDetails||{imageId:e},s=void 0===t.priority?5:t.priority,l=t.addToBeginning||!1,c=e.substring(7);return n.addRequest(async function(e,n,o){a.generate((async a=>{const i=it.as(ot(e,n,o,t));let s=10;for await(const e of i){const{pixelData:o,imageQualityStatus:i=st.FULL_RESOLUTION,percentComplete:l,done:c=!0,extractDone:u=!0}=e,f=ct(e.contentType);if(!u&&!lt.has(f))continue;const d=e.decodeLevel??(i===st.FULL_RESOLUTION?0:ut(l,t.retrieveOptions?.decodeLevel));if(c||!(s<=d))try{const e={...t,decodeLevel:d},l=await ve(n,o,f,e),u=(new Date).getTime();l.loadTimeInMS=u-r,l.transferSyntaxUID=f,l.imageQualityStatus=i,a.add(l,c),s=d}catch(e){if(u)throw console.warn("Couldn't decode",e),e}}}))}.bind(this,c,e,"multipart/related; type=application/octet-stream; transfer-syntax=*"),o,i,s,l),{promise:a.getDonePromise(),cancelFn:void 0}};function dt(e){e.registerImageLoader("wadors",ft),e.metaData.addProvider(rt)}const gt={metaData:{getNumberString:Ne,getNumberValue:ke,getNumberValues:_e,getValue:Be,metaDataProvider:rt},findIndexOfString:M,getPixelData:ot,loadImage:ft,metaDataManager:ze,register:dt};const mt=function(e){dt(e),Fe(e)};const pt=function(e){if(!e.cornerstone||!e.dicomParser)throw new Error('cornerstoneWADOImageLoader.configure: Options object must contain the keys "cornerstone" and "dicomParser".');f(e),p.cornerstone=e.cornerstone,p.dicomParser=e.dicomParser,mt(e.cornerstone)};const ht=function(e,t){if(t=t||e.transferSyntax,8===e.bitsAllocated&&"1.2.840.10008.1.2.4.50"===t&&(3===e.samplesPerPixel||4===e.samplesPerPixel))return!0},xt={convertRGBColorByPixel:n,convertRGBColorByPlane:o,convertYBRFullByPixel:i,convertYBRFullByPlane:s,convertPALETTECOLOR:y,wadouri:Ue,wadors:gt,configure:pt,convertColorSpace:Pe,createImage:ve,decodeJPEGBaseline8BitColor:Se,getImageFrame:Te,getPixelData:ot,getMinMax:ye,isColorImage:Le,isJPEGBaseline8BitColor:ht,internal:V,external:p}})(),a})()));
|
|
1
|
+
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t(require("dicom-parser")):"function"==typeof define&&define.amd?define("cornerstoneDICOMImageLoader",["dicom-parser"],t):"object"==typeof exports?exports.cornerstoneDICOMImageLoader=t(require("dicom-parser")):e.cornerstoneDICOMImageLoader=t(e.dicomParser)}(this,(e=>(()=>{"use strict";var t={713:t=>{t.exports=e}},n={};function r(e){var a=n[e];if(void 0!==a)return a.exports;var o=n[e]={exports:{}};return t[e](o,o.exports,r),o.exports}r.m=t,r.d=(e,t)=>{for(var n in t)r.o(t,n)&&!r.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:t[n]})},r.u=e=>e+".bundle.min.js",r.g=function(){if("object"==typeof globalThis)return globalThis;try{return this||new Function("return this")()}catch(e){if("object"==typeof window)return window}}(),r.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),r.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},(()=>{var e;r.g.importScripts&&(e=r.g.location+"");var t=r.g.document;if(!e&&t&&(t.currentScript&&(e=t.currentScript.src),!e)){var n=t.getElementsByTagName("script");if(n.length)for(var a=n.length-1;a>-1&&!e;)e=n[a--].src}if(!e)throw new Error("Automatic publicPath is not supported in this browser");e=e.replace(/#.*$/,"").replace(/\?.*$/,"").replace(/\/[^\/]+$/,"/"),r.p=e})(),r.b=document.baseURI||self.location.href;var a={};return(()=>{r.r(a),r.d(a,{configure:()=>pt,convertColorSpace:()=>Pe,convertPALETTECOLOR:()=>y,convertRGBColorByPixel:()=>n,convertRGBColorByPlane:()=>o,convertYBRFullByPixel:()=>i,convertYBRFullByPlane:()=>s,createImage:()=>ve,decodeJPEGBaseline8BitColor:()=>Se,default:()=>xt,external:()=>p,getImageFrame:()=>Te,getMinMax:()=>ye,getPixelData:()=>ot,internal:()=>V,isColorImage:()=>Le,isJPEGBaseline8BitColor:()=>ht,wadors:()=>gt,wadouri:()=>Ue});var e={};r.r(e),r.d(e,{ProgressiveIterator:()=>C});var t={};function n(e,t,n){if(void 0===e)throw new Error("decodeRGB: rgbBuffer must be defined");if(e.length%3!=0)throw new Error(`decodeRGB: rgbBuffer length ${e.length} must be divisible by 3`);const r=e.length/3;let a=0,o=0;if(n)for(let n=0;n<r;n++)t[o++]=e[a++],t[o++]=e[a++],t[o++]=e[a++],t[o++]=255;else t.set(e)}function o(e,t,n){if(void 0===e)throw new Error("decodeRGB: rgbBuffer must be defined");if(e.length%3!=0)throw new Error(`decodeRGB: rgbBuffer length ${e.length} must be divisible by 3`);const r=e.length/3;let a=0,o=0,i=r,s=2*r;if(n)for(let n=0;n<r;n++)t[a++]=e[o++],t[a++]=e[i++],t[a++]=e[s++],t[a++]=255;else for(let n=0;n<r;n++)t[a++]=e[o++],t[a++]=e[i++],t[a++]=e[s++]}function i(e,t,n){if(void 0===e)throw new Error("convertYBRFullByPixel: ybrBuffer must be defined");if(e.length%3!=0)throw new Error(`convertYBRFullByPixel: ybrBuffer length ${e.length} must be divisible by 3`);const r=e.length/3;let a=0,o=0;if(n)for(let n=0;n<r;n++){const n=e[a++],r=e[a++],i=e[a++];t[o++]=n+1.402*(i-128),t[o++]=n-.34414*(r-128)-.71414*(i-128),t[o++]=n+1.772*(r-128),t[o++]=255}else for(let n=0;n<r;n++){const n=e[a++],r=e[a++],i=e[a++];t[o++]=n+1.402*(i-128),t[o++]=n-.34414*(r-128)-.71414*(i-128),t[o++]=n+1.772*(r-128)}}function s(e,t,n){if(void 0===e)throw new Error("convertYBRFullByPlane: ybrBuffer must be defined");if(e.length%3!=0)throw new Error(`convertYBRFullByPlane: ybrBuffer length ${e.length} must be divisible by 3`);const r=e.length/3;let a=0,o=0,i=r,s=2*r;if(n)for(let n=0;n<r;n++){const n=e[o++],r=e[i++],l=e[s++];t[a++]=n+1.402*(l-128),t[a++]=n-.34414*(r-128)-.71414*(l-128),t[a++]=n+1.772*(r-128),t[a++]=255}else for(let n=0;n<r;n++){const n=e[o++],r=e[i++],l=e[s++];t[a++]=n+1.402*(l-128),t[a++]=n-.34414*(r-128)-.71414*(l-128),t[a++]=n+1.772*(r-128)}}r.r(t),r.d(t,{ImageQualityStatus:()=>A});let l,c,u={open(e,t){e.open("get",t,!0)},beforeSend(){},beforeProcessing:e=>Promise.resolve(e.response),imageCreated(){},strict:!1};function f(e){u=Object.assign(u,e)}function d(){return u}const g=()=>new Worker(new URL(r.p+r.u(920),r.b),{type:void 0}),m={set cornerstone(e){l=e;const t=d();m.cornerstone.getWebWorkerManager().registerWorker("dicomImageLoader",g,{maxWorkerInstances:t.maxWebWorkers||1})},get cornerstone(){if(!l&&(l=window&&window.cornerstone,!l))throw new Error("cornerstoneDICOMImageLoader requires a copy of Cornerstone to work properly. Please add cornerstoneDICOMImageLoader.external.cornerstone = cornerstone; to your application.");return l},set dicomParser(e){c=e},get dicomParser(){if(!c){if(!window||!window.dicomParser)throw new Error("cornerstoneDICOMImageLoader requires a copy of dicomParser to work properly. Please add cornerstoneDICOMImageLoader.external.dicomParser = dicomParser; to your application.");c=window.dicomParser}return c}},p=m;function h(e,t){const n=e.length,r=new Uint8ClampedArray(n);for(let a=0;a<n;++a)r[a]=e[a]>>t;return r}function x(e,t,n){const r=e[`${t}PaletteColorLookupTableData`];if(r)return Promise.resolve(r);const a=p.cornerstone.metaData.get("imagePixelModule",e.imageId);return a&&"function"==typeof a.then?a.then((e=>e?e[`${t}PaletteColorLookupTableData`]:n)):Promise.resolve(a?a[`${t}PaletteColorLookupTableData`]:n)}function y(e,t,n){const r=e.columns*e.rows,a=e.pixelData;Promise.all([x(e,"red",null),x(e,"green",null),x(e,"blue",null)]).then((([o,i,s])=>{if(!o||!i||!s)throw new Error("The image does not have a complete color palette. R, G, and B palette data are required.");const l=o.length;let c=0,u=0;const f=e.redPaletteColorLookupTableDescriptor[1],d=8===e.redPaletteColorLookupTableDescriptor[2]?0:8,g=h(o,d),m=h(i,d),p=h(s,d);if(n)for(let e=0;e<r;++e){let e=a[c++];e<f?e=0:e>f+l-1?e=l-1:e-=f,t[u++]=g[e],t[u++]=m[e],t[u++]=p[e],t[u++]=255}else for(let e=0;e<r;++e){let e=a[c++];e<f?e=0:e>f+l-1?e=l-1:e-=f,t[u++]=g[e],t[u++]=m[e],t[u++]=p[e]}}))}function b(e,t){if(e.elements[t]&&6===e.elements[t].length)return[e.uint16(t,0),e.uint16(t,1),e.uint16(t,2)]}function P(e,t,n){const r=[],a=e.elements[t];for(let o=0;o<n[0];o++)16===n[2]?r[o]=e.uint16(t,o):r[o]=e.byteArray[o+a.dataOffset];return r}const w=function(e){const t={samplesPerPixel:e.uint16("x00280002"),photometricInterpretation:e.string("x00280004"),rows:e.uint16("x00280010"),columns:e.uint16("x00280011"),bitsAllocated:e.uint16("x00280100"),bitsStored:e.uint16("x00280101"),highBit:e.uint16("x00280102"),pixelRepresentation:e.uint16("x00280103"),planarConfiguration:e.uint16("x00280006"),pixelAspectRatio:e.string("x00280034")};return function(e,t){0===e.uint16("x00280103")?(t.smallestPixelValue=e.uint16("x00280106"),t.largestPixelValue=e.uint16("x00280107")):(t.smallestPixelValue=e.int16("x00280106"),t.largestPixelValue=e.int16("x00280107"))}(e,t),"PALETTE COLOR"===t.photometricInterpretation&&e.elements.x00281101&&function(e,t){t.redPaletteColorLookupTableDescriptor=b(e,"x00281101"),t.greenPaletteColorLookupTableDescriptor=b(e,"x00281102"),t.bluePaletteColorLookupTableDescriptor=b(e,"x00281103"),0===t.redPaletteColorLookupTableDescriptor[0]&&(t.redPaletteColorLookupTableDescriptor[0]=65536,t.greenPaletteColorLookupTableDescriptor[0]=65536,t.bluePaletteColorLookupTableDescriptor[0]=65536);const n=t.redPaletteColorLookupTableDescriptor[0],r=e.elements.x00281201.length===n?8:16;t.redPaletteColorLookupTableDescriptor[2]!==r&&(t.redPaletteColorLookupTableDescriptor[2]=r,t.greenPaletteColorLookupTableDescriptor[2]=r,t.bluePaletteColorLookupTableDescriptor[2]=r),t.redPaletteColorLookupTableData=P(e,"x00281201",t.redPaletteColorLookupTableDescriptor),t.greenPaletteColorLookupTableData=P(e,"x00281202",t.greenPaletteColorLookupTableDescriptor),t.bluePaletteColorLookupTableData=P(e,"x00281203",t.bluePaletteColorLookupTableDescriptor)}(e,t),t};function S(e,t){let n=t.uint16("x00283002",0);0===n&&(n=65535);let r=0;r=0===e?t.uint16("x00283002",1):t.int16("x00283002",1);const a={id:"1",firstValueMapped:r,numBitsPerEntry:t.uint16("x00283002",2),lut:[]};for(let r=0;r<n;r++)a.lut[r]=0===e?t.uint16("x00283006",r):t.int16("x00283006",r);return a}const D=function(e,t){if(!t||!t.items||!t.items.length)return;const n=[];for(let r=0;r<t.items.length;r++){const a=S(e,t.items[r].dataSet);a&&n.push(a)}return n};const I=function(e){const t=e.string("x00080016");if("1.2.840.10008.5.1.4.1.1.2"===t||"1.2.840.10008.5.1.4.1.1.2.1"===t)return 1;const n=e.floatString("x00281052"),r=e.floatString("x00281053");if(void 0!==n&&void 0!==r){const t=function(e){const t=e.uint16("x00280103"),n=e.uint16("x00280101");return 0===t?0:-1<<n-1}(e);return t*r+n<0?1:0}return e.elements.x00283000&&e.elements.x00283000.length>0?0:e.uint16("x00280103")};const T=function(e,t,n){const r=[],a=e.string(t);if(!a)return;const o=a.split("\\");if(!(n&&o.length<n)){for(let e=0;e<o.length;e++)r.push(parseFloat(o[e]));return r}};const L=function(e){const t=e.indexOf(":");let n=e.substring(t+1);const r=n.indexOf("frame=");let a;if(-1!==r){const e=n.substring(r+6);a=parseInt(e,10),n=n.substring(0,r-1)}return{scheme:e.substring(0,t),url:n,frame:a,pixelDataFrame:void 0!==a?a-1:void 0}};const E=function(e,t,n={},r={}){const{cornerstone:a}=p,o=d(),i=e=>{if("function"==typeof o.errorInterceptor){const t=new Error("request failed");t.request=e,t.response=e.response,t.status=e.status,o.errorInterceptor(t)}},s=new XMLHttpRequest,l=new Promise(((l,c)=>{o.open(s,e,n,r);const u=o.beforeSend(s,t,n,r);s.responseType="arraybuffer";const f=Object.assign({},n,u);Object.keys(f).forEach((function(t){null!==f[t]&&("Accept"===t&&-1!==e.indexOf("accept=")||s.setRequestHeader(t,f[t]))})),r.deferred={resolve:l,reject:c},r.url=e,r.imageId=t,s.onloadstart=function(n){o.onloadstart&&o.onloadstart(n,r);const i={url:e,imageId:t};a.triggerEvent(a.events,"cornerstoneimageloadstart",i)},s.onloadend=function(n){o.onloadend&&o.onloadend(n,r);const i={url:e,imageId:t};a.triggerEvent(a.events,"cornerstoneimageloadend",i)},s.onreadystatechange=function(e){o.onreadystatechange?o.onreadystatechange(e,r):4===s.readyState&&(200===s.status||206===s.status?o.beforeProcessing(s).then(l).catch((()=>{i(s),c(s)})):(i(s),c(s)))},s.onprogress=function(e){const t=e.loaded;let n,a;e.lengthComputable&&(n=e.total,a=Math.round(t/n*100)),o.onprogress&&o.onprogress(e,r)},s.onerror=function(){i(s),c(s)},s.onabort=function(){i(s),c(s)},s.send()}));return l.xhr=s,l};class C{constructor(e){this.name=e||"unknown"}static as(e){if(e.iterator)return e.iterator;const t=new C("as iterator");return e.then((e=>{try{t.add(e,!0)}catch(e){t.reject(e)}}),(e=>{t.reject(e)})),t}add(e,t=!1){this.nextValue=e,this.done||=t,this.waiting&&(this.waiting.resolve(e),this.waiting=void 0)}resolve(){this.done=!0,this.waiting&&(this.waiting.resolve(this.nextValue),this.waiting=void 0)}reject(e){this.rejectReason=e,this.waiting?.reject(e)}getRecent(){if(this.rejectReason)throw this.rejectReason;return this.nextValue}async*[Symbol.asyncIterator](){for(;!this.done;){if(this.rejectReason)throw this.rejectReason;if(void 0!==this.nextValue&&(yield this.nextValue,this.done))break;this.waiting||(this.waiting={},this.waiting.promise=new Promise(((e,t)=>{this.waiting.resolve=e,this.waiting.reject=t}))),await this.waiting.promise}yield this.nextValue}async forEach(e,t){let n=0;try{for await(const r of this){const{done:a}=this;try{await e(r,a,n),n++}catch(e){if(!a){console.warn("Caught exception in intermediate value",e);continue}if(!t)throw e;t(e,a)}}}catch(e){if(!t)throw e;t(e,!0)}}generate(e,t){return e(this,this.reject.bind(this)).then((()=>{this.done||this.resolve()}),(e=>{this.reject(e),t?t(e):console.warn("Couldn't process because",e)}))}async nextPromise(){for await(const e of this)if(e)return e;return this.nextValue}async donePromise(){for await(const e of this);return this.nextValue}getNextPromise(){const e=this.nextPromise();return e.iterator=this,e}getDonePromise(){const e=this.donePromise();return e.iterator=this,e}}var v;!function(e){e[e.FAR_REPLICATE=1]="FAR_REPLICATE",e[e.ADJACENT_REPLICATE=3]="ADJACENT_REPLICATE",e[e.SUBRESOLUTION=6]="SUBRESOLUTION",e[e.LOSSY=7]="LOSSY",e[e.FULL_RESOLUTION=8]="FULL_RESOLUTION"}(v||(v={}));const A=v;function O(e,t,n){if(n+e.length>t.length)return!1;let r=n;for(let n=0;n<e.length;n++)if(e[n]!==t[r++])return!1;return!0}const M=function(e,t,n){n=n||0;const r=function(e){const t=new Uint8Array(e.length);for(let n=0,r=e.length;n<r;n++)t[n]=e.charCodeAt(n);return t}(t);for(let t=n;t<e.length;t++)if(r[0]===e[t]&&O(r,e,t))return t;return-1},{ImageQualityStatus:R}=t;function F(e,t,n){n||={};const r=new Uint8Array(t),a=!!n?.isPartial;if(-1===e.indexOf("multipart"))return{contentType:e,imageQualityStatus:a?R.SUBRESOLUTION:R.FULL_RESOLUTION,pixelData:r};let{tokenIndex:o,responseHeaders:i,boundary:s,multipartContentType:l}=n;if(o||=M(r,"\r\n\r\n"),-1===o)throw new Error("invalid response - no multipart mime header");if(!s){const e=function(e,t,n){t=t||0,n=n||e.length-t;let r="";for(let a=t;a<t+n;a++)r+=String.fromCharCode(e[a]);return r}(r,0,o);if(i=e.split("\r\n"),s=function(e){for(let t=0;t<e.length;t++)if("--"===e[t].substr(0,2))return e[t]}(i),!s)throw new Error("invalid response - no boundary marker")}const c=o+4,u=M(r,s,c);if(-1===u&&!a)throw new Error("invalid response - terminating boundary not found");return l||=function(e){for(let t=0;t<e.length;t++)if("Content-Type:"===e[t].substr(0,13))return e[t].substr(13).trim()}(i),n.tokenIndex=o,n.boundary=s,n.responseHeaders=i,n.multipartContentType=l,n.isPartial=-1===u,{contentType:l,extractDone:!a||-1!==u,tokenIndex:o,responseHeaders:i,boundary:s,multipartContentType:l,pixelData:t.slice(c,u-2)}}const{ImageQualityStatus:U}=t;function B(e,t=!0){return t?e.imageQualityStatus??U.FULL_RESOLUTION:U.SUBRESOLUTION}const{ProgressiveIterator:N}=e;function k(e,t,n={},r={}){const a=d(),{retrieveOptions:o={},streamingData:i={}}=r,s=o.chunkSize||131072,l=new N("streamRequest");return l.generate((async(r,l)=>{const c=Object.assign({},n);Object.keys(c).forEach((function(t){null===c[t]&&(c[t]=void 0),"Accept"===t&&-1!==e.indexOf("accept=")&&(c[t]=void 0)}));try{const a=await fetch(e,{headers:n,signal:void 0});if(200!==a.status)throw new Error(`Couldn't retrieve ${e} got status ${a.status}`);const l=a.body.getReader(),c=a.headers,u=c.get("content-type"),f=Number(c.get("Content-Length"));let d=!1,g=i.encodedData,m=i.lastSize||0;for(i.isPartial=!0;!d;){const{done:n,value:a}=await l.read();if(g=_(g,a),!g){if(d)throw new Error(`Done but no image frame available ${t}`);continue}if(d=n||g.byteLength===f,!d&&g.length<m+s)continue;m=g.length,i.isPartial=!n;const c=F(u,g,i),p=B(o,d),h={url:e,imageId:t,...c,percentComplete:n?100:100*c.pixelData?.length/f,imageQualityStatus:p,done:d};r.add(h,d)}}catch(e){(()=>{if("function"==typeof a.errorInterceptor){const e=new Error("request failed");a.errorInterceptor(e)}})(),console.error(e),l(e)}})),l.getNextPromise()}function _(e,t){if(!e)return t;if(!t)return e;const n=new Uint8Array(e.length+t.length);return n.set(e,0),n.set(t,e.length),n}const V={xhrRequest:E,streamRequest:k,setOptions:f,getOptions:d};function j(e){const{dicomParser:t}=p;let n,r=t.parseDicom(e,{untilTag:"x7fe00010"});r.elements.x7fe00010||console.warn("Pixel data not found!");try{n=t.parseDicom(e)}catch(e){console.error(e),console.log("pixel data dataset:",e.dataSet),n=e.dataSet}return r.elements.x7fe00010=n.elements.x7fe00010,r=function(e){const t=e.elements.x7fe00010.fragments,n=e.byteArray.length;for(const e of t){const{position:t,length:r}=e;r>n-t&&(console.log(`Truncated fragment, changing fragment length from ${e.length} to ${n-t}`),e.length=n-t)}return e}(r),r}async function $(e,t,n){const r=j(e),{uri:a,imageId:o,fileTotalLength:i}=n;return r.fetchMore=async function(s){const l=Object.assign({uri:a,imageId:o,fetchedLength:e.length,lengthToFetch:i-e.length},s),{fetchedLength:c,lengthToFetch:u}=l,{arrayBuffer:f}=await t(a,o,{byteRange:`${c}-${c+u}`}),d=new Uint8Array(f),g=new Uint8Array(r.byteArray.length+d.length);return g.set(r.byteArray),g.set(d,r.byteArray.length),$(g,t,n)},r}function G(e,t,n){const r={};(t?Object.values(t.items[0].dataSet.elements):[]).map((e=>r[e.tag]=e));const a={};return(e?Object.values(e.items[n-1].dataSet.elements):[]).map((e=>a[e.tag]=e)),{shared:r,perFrame:a}}function q(e){if(!e)return;const{elements:t,...n}=e,{x52009230:r,x52009229:a,...o}=t;return{NumberOfFrames:e.intString("x00280008"),PerFrameFunctionalGroupsSequence:r,SharedFunctionalGroupsSequence:a,otherElements:o,otherAttributtes:n}}let Y={};function W(e){if(Y[e])return Y[e]}function X(e){if(!e)return!1;const t=e.intString("x00280008");return t&&t>1}const z={_get:W,generateMultiframeWADOURIs:function(e){const t=[],n=W(e);if(X(n)){const r=n.intString("x00280008");for(let n=1;n<=r;n++)t.push(`${e}&frame=${n}`)}else t.push(e);return t},retrieveMultiframeDataset:function(e){const t=function(e){return e.indexOf("&frame=")}(e),n=-1===t?e:e.slice(0,t),r=parseInt(e.slice(t+7),10)||1;let a;return a=Y[n]?Y[n].dataSet:void 0,{dataSet:a,frame:r}},isMultiframeDataset:function(e){return X(W(e))}};let H=0,Q={};function J(){return{cacheSizeInBytes:H,numberOfDataSetsCached:Object.keys(Y).length}}const K={isLoaded:function(e){return void 0!==Y[e]},load:function(e,t=E,n){const{cornerstone:r,dicomParser:a}=p;if(Y[e])return new Promise((t=>{Y[e].cacheCount++,t(Y[e].dataSet)}));if(Q[e])return Q[e].cacheCount++,Q[e];const o=t(e,n),i=new Promise(((s,l)=>{o.then((async function(o){const c={isPartialContent:!1,fileTotalLength:null};if(!(o instanceof ArrayBuffer)){if(!o.arrayBuffer)return l(new Error("If not returning ArrayBuffer, must return object with `arrayBuffer` parameter"));c.isPartialContent=o.flags.isPartialContent,c.fileTotalLength=o.flags.fileTotalLength,o=o.arrayBuffer}const u=new Uint8Array(o);let f;try{f=c.isPartialContent?await $(u,t,{uri:e,imageId:n,fileTotalLength:c.fileTotalLength}):a.parseDicom(u)}catch(e){return l(e)}Y[e]={dataSet:f,cacheCount:i.cacheCount},H+=f.byteArray.length,s(f),r.triggerEvent(r.events,"datasetscachechanged",{uri:e,action:"loaded",cacheInfo:J()})}),l).then((()=>{delete Q[e]}),(()=>{delete Q[e]}))}));return i.cacheCount=1,Q[e]=i,i},unload:function(e){const{cornerstone:t}=p;Y[e]&&(Y[e].cacheCount--,0===Y[e].cacheCount&&(H-=Y[e].dataSet.byteArray.length,delete Y[e],t.triggerEvent(t.events,"datasetscachechanged",{uri:e,action:"unloaded",cacheInfo:J()})))},getInfo:J,purge:function(){Y={},Q={},H=0},get:function(e){let t;if(e.includes("&frame=")){const{frame:n,dataSet:r}=z.retrieveMultiframeDataset(e);t=function(e,t){if(!t)return;const{NumberOfFrames:n,PerFrameFunctionalGroupsSequence:r,SharedFunctionalGroupsSequence:a,otherElements:o}=q(t);if(r||n>1){const{shared:n,perFrame:i}=G(r,a,e),s={elements:{...o,...n,...i}},l=Object.create(t);return Object.assign(l,s)}return t}(n,r)}else Y[e]&&(t=Y[e].dataSet);return t},update:function(e,t){const n=Y[e];n?(H-=n.dataSet.byteArray.length,n.dataSet=t,H+=t.byteArray.length,p.cornerstone.triggerEvent(p.cornerstone.events,"datasetscachechanged",{uri:e,action:"updated",cacheInfo:J()})):console.error(`No loaded dataSet for uri ${e}`)}};function Z(e){return"RECON TOMO"===e||"RECON GATED TOMO"===e}function ee(e,t){const n=e.string("x00080008");if(n){const e=n.split("\\");if(e.length>t)return e[t]}}function te(e){let t=T(e,"x00200037",6);return!t&&e.elements.x00209116&&(t=T(e.elements.x00209116.items[0].dataSet,"x00200037",6)),t||(t=function(e){let t;const n=e.string("x00080060");if(n?.includes("NM")){const n=ee(e,2);n&&Z(n)&&e.elements.x00540022&&(t=T(e.elements.x00540022.items[0].dataSet,"x00200037",6))}return t}(e)),t}function ne(e){let t=T(e,"x00200032",3);return!t&&e.elements.x00209113&&(t=T(e.elements.x00209113.items[0].dataSet,"x00200032",3)),t||(t=function(e){let t;const n=e.string("x00080060");if(n?.includes("NM")){const n=ee(e,2);n&&Z(n)&&e.elements.x00540022&&(t=T(e.elements.x00540022.items[0].dataSet,"x00200032",3))}return t}(e)),t}function re(e){let t=T(e,"x00280030",2);return!t&&e.elements.x00289110&&(t=T(e.elements.x00289110.items[0].dataSet,"x00280030",2)),t}function ae(e){let t;return e.elements.x00180050?t=e.floatString("x00180050"):e.elements.x00289110&&e.elements.x00289110.items.length&&e.elements.x00289110.items[0].dataSet.elements.x00180050&&(t=e.elements.x00289110.items[0].dataSet.floatString("x00180050")),t}function oe(e,t,n){const r={};for(const a of n)try{const n=t(a,e);if(n){const e={};for(const t in n)if(t in n){e[ie(t)]=n[t]}Object.assign(r,e)}}catch(e){console.error(`Error retrieving ${a} data:`,e)}return r}const ie=e=>e.charAt(0).toUpperCase()+e.slice(1),se=["multiframeModule","generalSeriesModule","patientStudyModule","imagePlaneModule","nmMultiframeGeometryModule","imagePixelModule","modalityLutModule","voiLutModule","sopCommonModule","petIsotopeModule","overlayPlaneModule","transferSyntax","petSeriesModule","petImageModule"];function le(e){const t=e.elements.x00186011;if(!t||!t.items)return[];return t.items.map((e=>{const t=e.dataSet.double("x0018602c"),n=e.dataSet.double("x0018602e"),r=e.dataSet.uint16("x00186024"),a=e.dataSet.uint16("x00186026");return{regionLocationMinY0:e.dataSet.uint16("x0018601a"),regionLocationMaxY1:e.dataSet.uint16("x0018601e"),regionLocationMinX0:e.dataSet.uint16("x00186018"),regionLocationMaxX1:e.dataSet.uint16("x0018601c"),referencePixelX0:e.dataSet.int32("x00186020")||null,referencePixelY0:e.dataSet.int32("x00186022")||null,physicalDeltaX:t,physicalDeltaY:n,physicalUnitsXDirection:r,physicalUnitsYDirection:a,referencePhysicalPixelValueY:e.dataSet.uint16("x0018602a"),referencePhysicalPixelValueX:e.dataSet.uint16("x00186028"),regionSpatialFormat:e.dataSet.uint16("x00186012"),regionDataType:e.dataSet.uint16("x00186014"),regionFlags:e.dataSet.uint16("x00186016"),transducerFrequency:e.dataSet.uint16("x00186030")}}))}const ce=function e(t,n){const{MetadataModules:r}=p.cornerstone.Enums,{dicomParser:a}=p;if(Array.isArray(n))return;const o=L(n);if(t===r.MULTIFRAME){const e=z.retrieveMultiframeDataset(o.url);if(!e.dataSet)return;const t=function(e,t){if(!e)return;const{NumberOfFrames:n,PerFrameFunctionalGroupsSequence:r,SharedFunctionalGroupsSequence:a}=q(e);if(r||n>1){const{shared:e,perFrame:o}=G(r,a,t);return{NumberOfFrames:n,PerFrameFunctionalInformation:o,SharedFunctionalInformation:e}}return{NumberOfFrames:n}}(e.dataSet,e.frame);return t}let i=o.url;o.frame&&(i=`${i}&frame=${o.frame}`);const s=K.get(i);if(s){if(t===r.GENERAL_STUDY)return{studyDescription:s.string("x00081030"),studyDate:a.parseDA(s.string("x00080020")),studyTime:a.parseTM(s.string("x00080030")||""),accessionNumber:s.string("x00080050")};if(t===r.GENERAL_SERIES)return{modality:s.string("x00080060"),seriesInstanceUID:s.string("x0020000e"),seriesNumber:s.intString("x00200011"),studyInstanceUID:s.string("x0020000d"),seriesDate:a.parseDA(s.string("x00080021")),seriesTime:a.parseTM(s.string("x00080031")||""),acquisitionDate:a.parseDA(s.string("x00080022")),acquisitionTime:a.parseTM(s.string("x00080032")||"")};if(t===r.GENERAL_IMAGE)return{sopInstanceUID:s.string("x00080018"),instanceNumber:s.intString("x00200013"),lossyImageCompression:s.string("x00282110"),lossyImageCompressionRatio:s.floatString("x00282112"),lossyImageCompressionMethod:s.string("x00282114")};if(t===r.PATIENT)return{patientID:s.string("x00100020"),patientName:s.string("x00100010")};if(t===r.PATIENT_STUDY)return{patientAge:s.intString("x00101010"),patientSize:s.floatString("x00101020"),patientSex:s.string("x00100040"),patientWeight:s.floatString("x00101030")};if(t===r.NM_MULTIFRAME_GEOMETRY){const e=s.string("x00080060"),t=ee(s,2);return{modality:e,imageType:s.string("x00080008"),imageSubType:t,imageOrientationPatient:te(s),imagePositionPatient:ne(s),sliceThickness:ae(s),pixelSpacing:re(s),numberOfFrames:s.uint16("x00280008"),isNMReconstructable:Z(t)&&e.includes("NM")}}if(t===r.IMAGE_PLANE){const e=te(s),t=ne(s),n=re(s),r=ae(s);let a=null,o=null;n&&(o=n[0],a=n[1]);let i=null,l=null;return e&&(i=[parseFloat(e[0]),parseFloat(e[1]),parseFloat(e[2])],l=[parseFloat(e[3]),parseFloat(e[4]),parseFloat(e[5])]),{frameOfReferenceUID:s.string("x00200052"),rows:s.uint16("x00280010"),columns:s.uint16("x00280011"),imageOrientationPatient:e,rowCosines:i,columnCosines:l,imagePositionPatient:t,sliceThickness:r,sliceLocation:s.floatString("x00201041"),pixelSpacing:n,rowPixelSpacing:o,columnPixelSpacing:a}}if(t===r.CINE)return{frameTime:s.floatString("x00181063")};if(t===r.IMAGE_PIXEL)return w(s);if(t===r.VOI_LUT){const e=I(s);return{windowCenter:T(s,"x00281050",1),windowWidth:T(s,"x00281051",1),voiLUTSequence:D(e,s.elements.x00283010)}}if(t===r.MODALITY_LUT)return{rescaleIntercept:s.floatString("x00281052"),rescaleSlope:s.floatString("x00281053"),rescaleType:s.string("x00281054"),modalityLUTSequence:D(s.uint16("x00280103"),s.elements.x00283000)};if(t===r.SOP_COMMON)return{sopClassUID:s.string("x00080016"),sopInstanceUID:s.string("x00080018")};if(t===r.PET_ISOTOPE){const e=s.elements.x00540016;if(void 0===e)return;const t=e.items[0].dataSet;return{radiopharmaceuticalInfo:{radiopharmaceuticalStartTime:a.parseTM(t.string("x00181072")||""),radionuclideTotalDose:t.floatString("x00181074"),radionuclideHalfLife:t.floatString("x00181075")}}}if(t===r.OVERLAY_PLANE)return function(e){const t=[];for(let n=0;n<=30;n+=2){let r=`x60${n.toString(16)}`;4===r.length&&(r=`x600${n.toString(16)}`);const a=e.elements[`${r}3000`];if(!a)continue;const o=[];for(let t=0;t<a.length;t++)for(let n=0;n<8;n++){const r=e.byteArray[a.dataOffset+t];o[8*t+n]=r>>n&1}t.push({rows:e.uint16(`${r}0010`),columns:e.uint16(`${r}0011`),type:e.string(`${r}0040`),x:e.int16(`${r}0050`,1)-1,y:e.int16(`${r}0050`,0)-1,pixelData:o,description:e.string(`${r}0022`),label:e.string(`${r}1500`),roiArea:e.string(`${r}1301`),roiMean:e.string(`${r}1302`),roiStandardDeviation:e.string(`${r}1303`)})}return{overlays:t}}(s);if("transferSyntax"===t){let e;try{e=s.string("x00020010")}catch(e){}return{transferSyntaxUID:e}}if(t===r.PET_SERIES)return{correctedImage:s.string("x00280051"),units:s.string("x00541001"),decayCorrection:s.string("x00541102")};if(t===r.PET_IMAGE)return{frameReferenceTime:s.floatString(s.string("x00541300")||""),actualFrameDuration:s.intString(s.string("x00181242"))};if(t===r.ULTRASOUND_ENHANCED_REGION)return le(s);if(t===r.CALIBRATION){if("US"===s.string("x00080060")){return{sequenceOfUltrasoundRegions:le(s)}}}return"instance"===t?oe(n,e,se):void 0}};let ue=[];const fe={add:function(e){return"dicomfile:"+(ue.push(e)-1)},get:function(e){return ue[e]},remove:function(e){ue[e]=void 0},purge:function(){ue=[]}};var de=r(713);function ge(e,t){const{dicomParser:n}=p;if(e.elements.x7fe00010&&e.elements.x7fe00010.basicOffsetTable.length)return n.readEncapsulatedImageFrame(e,e.elements.x7fe00010,t);if(function(e){return e.intString("x00280008")!==e.elements.x7fe00010.fragments.length}(e)){const r=n.createJPEGBasicOffsetTable(e,e.elements.x7fe00010);return n.readEncapsulatedImageFrame(e,e.elements.x7fe00010,t,r)}const r=e.elements.x7fe00010.fragments,a=new de.ByteStream(e.byteArrayParser,e.byteArray,e.elements.x7fe00010.dataOffset),o=(0,de.readSequenceItem)(a);if("xfffee000"!==o.tag)throw"dicomParser.readEncapsulatedPixelData: missing basic offset table xfffee000";a.seek(o.length);const i=a.position;if(t+1>r.length)throw"dicomParser.readEncapsulatedPixelData: frame exceeds number of fragments";const s=i+r[t].offset+8,l=r[t].length;return new Uint8Array(a.byteArray.buffer.slice(a.byteArray.byteOffset+s,a.byteArray.byteOffset+s+l))}function me(e,t){return e&1<<t}const pe=function(e,t,n){const r=new Uint8Array(n);for(let a=0;a<n;a++){const n=e[Math.floor(a/8)+t],o=a%8;r[a]=me(n,o)?1:0}return r};const he=function(e,t){const n=e.elements.x7fe00010||e.elements.x7fe00008,r=e.uint16("x00280100"),a=e.uint16("x00280010"),o=e.uint16("x00280011");let i=e.uint16("x00280002");"YBR_FULL_422"===e.string("x00280004")&&(i=2,console.warn("Using SamplesPerPixel of 2 for YBR_FULL_422 photometric interpretation.\n See http://dicom.nema.org/medical/dicom/current/output/chtml/part03/sect_C.7.6.3.html for more information."));const s=n.dataOffset,l=a*o*i;let c;if(8===r){if(c=s+t*l,c>=e.byteArray.length)throw new Error("frame exceeds size of pixelData");return new Uint8Array(e.byteArray.buffer.slice(c,c+l))}if(16===r){if(c=s+t*l*2,c>=e.byteArray.length)throw new Error("frame exceeds size of pixelData");return new Uint8Array(e.byteArray.buffer.slice(c,c+2*l))}if(1===r){if(c=s+t*l*.125,c>=e.byteArray.length)throw new Error("frame exceeds size of pixelData");return pe(e.byteArray,c,l)}if(32===r){if(c=s+t*l*4,c>=e.byteArray.length)throw new Error("frame exceeds size of pixelData");return new Uint8Array(e.byteArray.buffer.slice(c,c+4*l))}throw new Error("unsupported pixel format")};const xe=function(e){const t=L(e),n=parseInt(t.url,10),r=fe.get(n);return new Promise(((e,t)=>{const n=new FileReader;n.onload=t=>{const n=t.target.result;e(n)},n.onerror=t,n.readAsArrayBuffer(r)}))};const ye=function(e){let t,n=e[0],r=e[0];const a=e.length;for(let o=1;o<a;o++)t=e[o],n=Math.min(n,t),r=Math.max(r,t);return{min:n,max:r}};function be(e,t,r){0===e.planarConfiguration?n(e.pixelData,t,r):o(e.pixelData,t,r)}function Pe(e,t,n){if("RGB"===e.photometricInterpretation)be(e,t,n);else if("YBR_RCT"===e.photometricInterpretation)be(e,t,n);else if("YBR_ICT"===e.photometricInterpretation)be(e,t,n);else if("PALETTE COLOR"===e.photometricInterpretation)y(e,t,n);else if("YBR_FULL_422"===e.photometricInterpretation)!function(e,t,n){if(void 0===e)throw new Error("convertYBRFull422ByPixel: ybrBuffer must be defined");if(e.length%2!=0)throw new Error(`convertYBRFull422ByPixel: ybrBuffer length ${e.length} must be divisible by 2`);const r=e.length/2;let a=0,o=0;if(n)for(let n=0;n<r;n+=2){const n=e[a++],r=e[a++],i=e[a++],s=e[a++];t[o++]=n+1.402*(s-128),t[o++]=n-.34414*(i-128)-.71414*(s-128),t[o++]=n+1.772*(i-128),t[o++]=255,t[o++]=r+1.402*(s-128),t[o++]=r-.34414*(i-128)-.71414*(s-128),t[o++]=r+1.772*(i-128),t[o++]=255}else for(let n=0;n<r;n+=2){const n=e[a++],r=e[a++],i=e[a++],s=e[a++];t[o++]=n+1.402*(s-128),t[o++]=n-.34414*(i-128)-.71414*(s-128),t[o++]=n+1.772*(i-128),t[o++]=r+1.402*(s-128),t[o++]=r-.34414*(i-128)-.71414*(s-128),t[o++]=r+1.772*(i-128)}}(e.pixelData,t,n);else{if("YBR_FULL"!==e.photometricInterpretation)throw new Error(`No color space conversion for photometric interpretation ${e.photometricInterpretation}`);!function(e,t,n){0===e.planarConfiguration?i(e.pixelData,t,n):s(e.pixelData,t,n)}(e,t,n)}}function we(e){return function(e){let t;try{return decodeURIComponent(escape(e))}catch(n){if(t=n,t instanceof URIError)return e;throw t}}(String.fromCharCode.apply(null,Array.prototype.slice.apply(new Uint8Array(e))))}const Se=function(e,t,n){const r=(new Date).getTime(),a=new Blob([t],{type:"image/jpeg"});return new Promise(((t,o)=>{const i=new FileReader;void 0===i.readAsBinaryString?i.readAsArrayBuffer(a):i.readAsBinaryString(a),i.onload=function(){const a=new Image;a.onload=function(){n.height=a.height,n.width=a.width,e.rows=a.height,e.columns=a.width;const o=n.getContext("2d");o.drawImage(this,0,0);const i=o.getImageData(0,0,a.width,a.height),s=(new Date).getTime();e.pixelData=new Uint8Array(i.data.buffer),e.imageData=i,e.decodeTimeInMS=s-r;const l=ye(e.pixelData);e.smallestPixelValue=l.min,e.largestPixelValue=l.max,e.pixelDataLength=e.pixelData.length,t(e)},a.onerror=function(e){o(e)},void 0===i.readAsBinaryString?a.src=`data:image/jpeg;base64,${window.btoa(we(i.result))}`:a.src=`data:image/jpeg;base64,${window.btoa(i.result)}`},i.onerror=e=>{o(e)}}))};function De(e,t,n,r,a){const o={...r};delete o.loader,delete o.streamingData;const i=p.cornerstone.getWebWorkerManager(),s=o.priority||void 0;o.transferPixelData&&n.buffer;return i.executeTask("dicomImageLoader","decodeTask",{imageFrame:e,transferSyntax:t,pixelData:n,options:o,decodeConfig:a},{priority:s,requestType:o?.requestType})}const Ie=function(e,t,n,r,a={},o){switch(t){case"1.2.840.10008.1.2":case"1.2.840.10008.1.2.1":case"1.2.840.10008.1.2.2":case"1.2.840.10008.1.2.1.99":case"1.2.840.10008.1.2.5":case"1.2.840.10008.1.2.4.51":case"1.2.840.10008.1.2.4.57":case"1.2.840.10008.1.2.4.70":case"1.2.840.10008.1.2.4.80":case"1.2.840.10008.1.2.4.81":case"1.2.840.10008.1.2.4.90":case"1.2.840.10008.1.2.4.91":case"3.2.840.10008.1.2.4.96":case"1.2.840.10008.1.2.4.201":case"1.2.840.10008.1.2.4.202":case"1.2.840.10008.1.2.4.203":return De(e,t,n,a,o);case"1.2.840.10008.1.2.4.50":return 8!==e.bitsAllocated||3!==e.samplesPerPixel&&4!==e.samplesPerPixel?De(e,t,n,a,o):Se(e,n,r)}return Promise.reject(new Error(`No decoder for transfer syntax ${t}`))};const Te=function(e){const{cornerstone:t}=p,n=t.metaData.get("imagePixelModule",e);return{samplesPerPixel:n.samplesPerPixel,photometricInterpretation:n.photometricInterpretation,planarConfiguration:n.planarConfiguration,rows:n.rows,columns:n.columns,bitsAllocated:n.bitsAllocated,bitsStored:n.bitsStored,pixelRepresentation:n.pixelRepresentation,smallestPixelValue:n.smallestPixelValue,largestPixelValue:n.largestPixelValue,redPaletteColorLookupTableDescriptor:n.redPaletteColorLookupTableDescriptor,greenPaletteColorLookupTableDescriptor:n.greenPaletteColorLookupTableDescriptor,bluePaletteColorLookupTableDescriptor:n.bluePaletteColorLookupTableDescriptor,redPaletteColorLookupTableData:n.redPaletteColorLookupTableData,greenPaletteColorLookupTableData:n.greenPaletteColorLookupTableData,bluePaletteColorLookupTableData:n.bluePaletteColorLookupTableData,pixelData:void 0,imageId:e}};function Le(e){return"RGB"===e||"PALETTE COLOR"===e||"YBR_FULL"===e||"YBR_FULL_422"===e||"YBR_PARTIAL_422"===e||"YBR_PARTIAL_420"===e||"YBR_RCT"===e||"YBR_ICT"===e}let Ee="";function Ce(e){const t=function(e,t){let n;return Number.isInteger(e)&&Number.isInteger(t)&&(e>=0?t<=255?n=Uint8Array:t<=65535&&(n=Uint16Array):e>=-128&&t<=127?n=Int8Array:e>=-32768&&t<=32767&&(n=Int16Array)),n||Float32Array}(e.smallestPixelValue,e.largestPixelValue);if(!t)throw new Error("Could not apply a typed array to the pixel data");{const n=new t(e.pixelData);e.pixelData=n}}const ve=function(e,t,n,r={}){const a=r.useRGBA;if(r.preScale={enabled:!r.preScale||void 0===r.preScale.enabled||r.preScale.enabled},!t?.length)return Promise.reject(new Error("The pixel data is missing"));const{cornerstone:o}=p,{MetadataModules:i}=o.Enums,s=document.createElement("canvas"),l=Te(e);if(l.decodeLevel=r.decodeLevel,r.allowFloatRendering=o.canRenderFloatTextures(),r.preScale.enabled){const t=function(e,t){const n=e.get("modalityLutModule",t)||{},r=e.get("generalSeriesModule",t)||{},{modality:a}=r,o={rescaleSlope:n.rescaleSlope,rescaleIntercept:n.rescaleIntercept,modality:a},i=e.get("scalingModule",t)||{};return{...o,..."PT"===a&&{suvbw:i.suvbw}}}(o.metaData,e);t&&(r.preScale={...r.preScale,scalingParameters:t})}const{decodeConfig:c}=d();Object.keys(l).forEach((e=>{("function"==typeof l[e]||l[e]instanceof Promise)&&delete l[e]}));const u=Ie(l,n,t,s,r,c),f=Le(l.photometricInterpretation);return new Promise(((t,n)=>{u.then((function(n){let l=!1;if(r.targetBuffer&&r.targetBuffer.type&&!f){const{arrayBuffer:e,type:t,offset:a=0,length:o}=r.targetBuffer,i=n.pixelDataLength,s=a,c=null!=o?o:i-s,u={Uint8Array,Uint16Array,Int16Array,Float32Array};if(c!==n.pixelDataLength)throw new Error(`target array for image does not have the same length (${c}) as the decoded image length (${n.pixelDataLength}).`);const f=u[t],d=e?new f(e,s,c):new f(n.pixelData);if(c!==n.pixelDataLength)throw new Error("target array for image does not have the same length as the decoded image length.");n.pixelData=d,l=!0}l||Ce(n);const c=o.metaData.get(i.IMAGE_PLANE,e)||{},u=o.metaData.get(i.VOI_LUT,e)||{},d=o.metaData.get(i.MODALITY_LUT,e)||{},g=o.metaData.get(i.SOP_COMMON,e)||{},m=o.metaData.get(i.CALIBRATION,e)||{},{rows:p,columns:h}=n;if(f){if(function(e){if(void 0===e)return!1;const{rows:t,columns:n,photometricInterpretation:r,pixelDataLength:a}=e;return a!==4*n*t&&(r.endsWith("420")?a===(3*Math.ceil(n/2)+Math.floor(n/2))*t:r.endsWith("422")?a===(3*Math.ceil(n/2)+Math.floor(n/2))*Math.ceil(t/2)+Math.floor(t/2)*n:"RGB"!==r)}(n)){s.height=n.rows,s.width=n.columns;let e=s.getContext("2d").createImageData(n.columns,n.rows);a||(e={...e,data:new Uint8ClampedArray(3*n.columns*n.rows)}),Pe(n,e.data,a),n.imageData=e,n.pixelData=e.data,n.pixelDataLength=e.data.length}else if(!a&&n.pixelDataLength===4*p*h){const e=new Uint8Array(n.pixelData.length/4*3);n.pixelData=function(e,t){const n=e.length/4;let r=0,a=0;for(let o=0;o<n;o++)t[a++]=e[r++],t[a++]=e[r++],t[a++]=e[r++],r++;return t}(n.pixelData,e),n.pixelDataLength=n.pixelData.length}const e=ye(n.pixelData);n.smallestPixelValue=e.min,n.largestPixelValue=e.max}const x={imageId:e,dataType:n.pixelData.constructor.name,color:f,calibration:m,columnPixelSpacing:c.columnPixelSpacing,columns:n.columns,height:n.rows,preScale:n.preScale,intercept:d.rescaleIntercept?d.rescaleIntercept:0,slope:d.rescaleSlope?d.rescaleSlope:1,invert:"MONOCHROME1"===n.photometricInterpretation,minPixelValue:n.smallestPixelValue,maxPixelValue:n.largestPixelValue,rowPixelSpacing:c.rowPixelSpacing,rows:n.rows,sizeInBytes:n.pixelData.byteLength,width:n.columns,windowCenter:u.windowCenter?u.windowCenter[0]:void 0,windowWidth:u.windowWidth?u.windowWidth[0]:void 0,voiLUTFunction:u.voiLUTFunction?u.voiLUTFunction:void 0,decodeTimeInMS:n.decodeTimeInMS,floatPixelData:void 0,imageFrame:n,rgba:f&&a,getPixelData:()=>n.pixelData,getCanvas:void 0,numberOfComponents:n.samplesPerPixel};var y;if(x.color&&(x.getCanvas=function(){if(Ee===e)return s;const t=x.columns,r=x.rows;s.height=r,s.width=t;const a=s.getContext("2d"),o=a.createImageData(t,r),i=n.pixelData;if(i.length===t*r*4)for(let e=0;e<i.length;e++)o.data[e]=i[e];else if(i.length===t*r*3){let e=0;for(let t=0;t<i.length;t+=3)o.data[e++]=i[t],o.data[e++]=i[t+1],o.data[e++]=i[t+2],o.data[e++]=255}return n.pixelData=o.data,n.pixelDataLength=o.data.length,n.imageData=o,a.putImageData(n.imageData,0,0),Ee=e,s}),d.modalityLUTSequence&&d.modalityLUTSequence.length>0&&("1.2.840.10008.5.1.4.1.1.12.1"!==(y=g.sopClassUID)&&"1.2.840.10008.5.1.4.1.1.12.2.1"!==y)&&(x.modalityLUT=d.modalityLUTSequence[0]),u.voiLUTSequence&&u.voiLUTSequence.length>0&&(x.voiLUT=u.voiLUTSequence[0]),x.color&&(x.windowWidth=256,x.windowCenter=128),void 0===x.windowCenter||void 0===x.windowWidth){const e=x.imageFrame.smallestPixelValue,t=x.imageFrame.largestPixelValue;x.windowWidth=t-e,x.windowCenter=(t+e)/2}t(x)}),n)}))};const Ae=function(e,t=0){const n=e.elements.x7fe00010||e.elements.x7fe00008;return n?n.encapsulatedPixelData?ge(e,t):he(e,t):null};function Oe(e,t,n=0,r,a,o){const i=(new Date).getTime(),s={cancelFn:void 0,promise:void 0};return s.promise=new Promise(((l,c)=>{e.then((e=>{const u=Ae(e,n),f=e.string("x00020010"),d=(new Date).getTime(),g=ve(t,u,f,a);!function(e,t){e.decache=function(){const e=L(t);K.unload(e.url)}}(s,t),g.then((t=>{t.data=e,t.sharedCacheKey=r;const n=(new Date).getTime();t.loadTimeInMS=d-i,t.totalTimeInMS=n-i,void 0!==o&&void 0!==o.imageDoneCallback&&o.imageDoneCallback(t),l(t)}),(function(t){c({error:t,dataSet:e})}))}),(function(e){c({error:e})}))})),s}function Me(e){return"dicomweb"===e||"wadouri"===e?E:"dicomfile"===e?xe:void 0}function Re(e,t={}){const n=L(e);delete(t=Object.assign({},t)).loader;const r=Me(n.scheme);if(K.isLoaded(n.url)){return function(e,t,n=0,r,a){const o=(new Date).getTime();return{promise:new Promise(((i,s)=>{const l=(new Date).getTime();let c;try{const r=Ae(e,n),o=e.string("x00020010");c=ve(t,r,o,a)}catch(t){return void s({error:t,dataSet:e})}c.then((t=>{t.data=e,t.sharedCacheKey=r;const n=(new Date).getTime();t.loadTimeInMS=l-o,t.totalTimeInMS=n-o,i(t)}),s)})),cancelFn:void 0}}(K.get(n.url,r,e),e,n.pixelDataFrame,n.url,t)}return Oe(K.load(n.url,r,e),e,n.frame,n.url,t)}function Fe(e){e.registerImageLoader("dicomweb",Re),e.registerImageLoader("wadouri",Re),e.registerImageLoader("dicomfile",Re),e.metaData.addProvider(ce)}const Ue={metaData:{getImagePixelModule:w,getLUTs:D,getModalityLUTOutputPixelRepresentation:I,getNumberValues:T,metaDataProvider:ce},dataSetCacheManager:K,fileManager:fe,getEncapsulatedImageFrame:ge,getUncompressedImageFrame:he,loadFileRequest:xe,loadImageFromPromise:Oe,getLoaderForScheme:Me,loadImage:Re,parseImageId:L,unpackBinaryFrame:pe,register:Fe};const Be=function(e,t,n){return t=t||0,e&&e.Value?Array.isArray(e.Value)&&e.Value.length<=t?n:e.Value[t]:n};const Ne=function(e,t,n){const r=Be(e,t,n);if(void 0!==r)return parseFloat(String(r))};const ke=function(e,t){const n=Be(e,t);if(void 0!==n)return parseFloat(n)};const _e=function(e,t){if(!e)return;if(!e.Value)return;if(!Array.isArray(e.Value))return;if(t&&e.Value.length<t)return;const n=[];for(let t=0;t<e.Value.length;t++)n.push(parseFloat(e.Value[t]));return n};function Ve(e){const t=e.indexOf(":");return e.substring(t+1)}function je(e,t=!0){return e&&e.Value?e.Value[0]&&t?e.Value[0]:e.Value:e}function $e(e,t,n){return{shared:(t?Object.values(t[0]):[]).map((e=>e[0])).filter((e=>void 0!==e&&"object"==typeof e)),perFrame:(e?Object.values(e[n-1]):[]).map((e=>e.Value[0])).filter((e=>void 0!==e&&"object"==typeof e))}}function Ge(e){let{52009230:t,52009229:n,"00280008":r,...a}=e;return t=je(t,!1),n=je(n,!1),r=je(r),{PerFrameFunctionalGroupsSequence:t,SharedFunctionalGroupsSequence:n,NumberOfFrames:r,rest:a}}let qe=[],Ye={};function We(e){return function(e){const t=e.indexOf("/frames/")+8,n=e.slice(0,t),r=parseInt(e.slice(t),10);return{metadata:qe[`${n}1`],frame:r}}(Ve(e))}function Xe(e){const t=Be(e["00280008"]);return t&&t>1}const ze={add:function(e,t){const n=Ve(e);Object.defineProperty(t,"isMultiframe",{value:Xe(t),enumerable:!1}),qe[n]=t},get:function(e){const t=Ve(e),n=qe[t];if(n&&!n?.isMultiframe)return n;const r=Ye[t];if(r)return r;const a=We(t);if(!a||!a.metadata)return;const{metadata:o,frame:i}=a;if(o){const e=function(e,t){const{PerFrameFunctionalGroupsSequence:n,SharedFunctionalGroupsSequence:r,NumberOfFrames:a,rest:o}=Ge(t);if(n||a>1){const{shared:i,perFrame:s}=$e(n,r,e),l=Object.assign(t,{frameNumber:e});return[...i,...s].forEach((e=>{Object.entries(e).forEach((([e,t])=>{l[e]=t}))})),Object.assign(o,{"00280008":a},l)}return t}(i,o);return Ye[t]=e,e}},remove:function(e){const t=Ve(e);qe[t]=void 0,Ye[t]=void 0},purge:function(){qe=[],Ye={}}};function He(e){return Be(e["00080060"]).includes("NM")}function Qe(e,t){const n=je(e["00080008"],!1);if(n)return n[t]}function Je(e){let t=_e(e["00200037"],6);return!t&&He(e)&&(t=function(e){let t;const n=Qe(e,2);if(n&&Z(n)){const n=je(e["00540022"]);n&&(t=_e(n["00200037"],6))}return t}(e)),t}function Ke(e){let t=_e(e["00200032"],3);return!t&&He(e)&&(t=function(e){let t;const n=Qe(e,2);if(n&&Z(n)){const n=je(e["00540022"]);n&&(t=_e(n["00200032"],3))}return t}(e)),t}function Ze(e,t){const n=_e(e[t]);return n?n[0]:null}const et=function(e){return e?.Value?.length?Array.isArray(e.Value)?e.Value:"object"==typeof e.Value?(console.warn("Warning: Value should be an array, but an object was found. Encapsulating the object in an array."),[e.Value]):[]:[]};function tt(e){const t=et(e["00186011"]);if(!t||!t.length)return null;return t.map((e=>{const t=Ze(e,"0018602C"),n=Ze(e,"0018602E"),r=Ze(e,"00186024"),a=Ze(e,"00186026");return{regionLocationMinY0:Ze(e,"0018601A"),regionLocationMaxY1:Ze(e,"0018601E"),regionLocationMinX0:Ze(e,"00186018"),regionLocationMaxX1:Ze(e,"0018601C"),referencePixelX0:Ze(e,"00186020"),referencePixelY0:Ze(e,"00186022"),physicalDeltaX:t,physicalDeltaY:n,physicalUnitsXDirection:r,physicalUnitsYDirection:a,referencePhysicalPixelValueY:Ze(e,"0018602A"),referencePhysicalPixelValueX:Ze(e,"00186028"),regionSpatialFormat:Ze(e,"00186012"),regionDataType:Ze(e,"00186014"),regionFlags:Ze(e,"00186016"),transducerFrequency:Ze(e,"00186030")}}))}function nt(e,t){return{transferSyntaxUID:Be(t["00020010"])||Be(t["00083002"])}}const rt=function e(t,n){const{MetadataModules:r}=p.cornerstone.Enums,{dicomParser:a}=p;if(t===r.MULTIFRAME){const{metadata:e,frame:t}=We(n);if(!e)return;const{PerFrameFunctionalGroupsSequence:r,SharedFunctionalGroupsSequence:a,NumberOfFrames:o}=Ge(e);if(r||o>1){const{shared:e,perFrame:n}=$e(r,a,t);return{NumberOfFrames:o,PerFrameFunctionalInformation:n,SharedFunctionalInformation:e}}return{NumberOfFrames:o}}const o=ze.get(n);if(o){if(t===r.GENERAL_STUDY)return{studyDescription:Be(o["00081030"]),studyDate:a.parseDA(Be(o["00080020"])),studyTime:a.parseTM(Be(o["00080030"],0,"")),accessionNumber:Be(o["00080050"])};if(t===r.GENERAL_SERIES)return{modality:Be(o["00080060"]),seriesInstanceUID:Be(o["0020000E"]),seriesNumber:ke(o["00200011"]),studyInstanceUID:Be(o["0020000D"]),seriesDate:a.parseDA(Be(o["00080021"])),seriesTime:a.parseTM(Be(o["00080031"],0,"")),acquisitionDate:a.parseDA(Be(o["00080022"])),acquisitionTime:a.parseTM(Be(o["00080032"],0,""))};if(t===r.GENERAL_IMAGE)return{sopInstanceUID:Be(o["00080018"]),instanceNumber:ke(o["00200013"]),lossyImageCompression:Be(o["00282110"]),lossyImageCompressionRatio:ke(o["00282112"]),lossyImageCompressionMethod:Be(o["00282114"])};if(t===r.PATIENT)return{patientID:Be(o["00100020"]),patientName:Be(o["00100010"])};if(t===r.PATIENT_STUDY)return{patientAge:ke(o["00101010"]),patientSize:ke(o["00101020"]),patientSex:Be(o["00100040"]),patientWeight:ke(o["00101030"])};if(t===r.NM_MULTIFRAME_GEOMETRY){const e=Be(o["00080060"]),t=Qe(o,2);return{modality:e,imageType:Be(o["00080008"]),imageSubType:t,imageOrientationPatient:Je(o),imagePositionPatient:Ke(o),sliceThickness:ke(o["00180050"]),spacingBetweenSlices:ke(o["00180088"]),pixelSpacing:_e(o["00280030"],2),numberOfFrames:ke(o["00280008"]),isNMReconstructable:Z(t)&&e.includes("NM")}}if(t===r.IMAGE_PLANE){let e=Je(o),t=Ke(o);const n=_e(o["00280030"],2);let r=null,a=null,i=null,s=null,l=!1;return n?(a=n[0],r=n[1]):(l=!0,a=1,r=1),e?(i=[parseFloat(e[0]),parseFloat(e[1]),parseFloat(e[2])],s=[parseFloat(e[3]),parseFloat(e[4]),parseFloat(e[5])]):(i=[0,1,0],s=[0,0,-1],l=!0,e=[...i,...s]),t||(t=[0,0,0],l=!0),{frameOfReferenceUID:Be(o["00200052"]),rows:ke(o["00280010"]),columns:ke(o["00280011"]),imageOrientationPatient:e,rowCosines:i,columnCosines:s,imagePositionPatient:t,sliceThickness:ke(o["00180050"]),sliceLocation:ke(o["00201041"]),pixelSpacing:n,rowPixelSpacing:a,columnPixelSpacing:r,usingDefaultValues:l}}if(t===r.ULTRASOUND_ENHANCED_REGION)return tt(o);if(t===r.CALIBRATION){if("US"===Be(o["00080060"])){return{sequenceOfUltrasoundRegions:tt(o)}}}if(t===r.IMAGE_URL)return function(e,t){const{transferSyntaxUID:n}=nt(e,t),r=p.cornerstone.utilities.isVideoTransferSyntax(n),a=e.substring(7),o=a.replace("/frames/","/thumbnail/");let i=a.replace("/frames/","/rendered/");r&&(i=i.replace("/rendered/1","/rendered"));return{isVideo:r,rendered:i,thumbnail:o}}(n,o);if(t===r.CINE)return function(e,t){const n=Be(t["00180040"]);return{cineRate:n,numberOfFrames:ke(t["00280008"])}}(0,o);if(t===r.IMAGE_PIXEL)return{samplesPerPixel:ke(o["00280002"]),photometricInterpretation:Be(o["00280004"]),rows:ke(o["00280010"]),columns:ke(o["00280011"]),bitsAllocated:ke(o["00280100"]),bitsStored:ke(o["00280101"]),highBit:Be(o["00280102"]),pixelRepresentation:ke(o["00280103"]),planarConfiguration:ke(o["00280006"]),pixelAspectRatio:Be(o["00280034"]),smallestPixelValue:ke(o["00280106"]),largestPixelValue:ke(o["00280107"]),redPaletteColorLookupTableDescriptor:_e(o["00281101"]),greenPaletteColorLookupTableDescriptor:_e(o["00281102"]),bluePaletteColorLookupTableDescriptor:_e(o["00281103"]),redPaletteColorLookupTableData:_e(o["00281201"]),greenPaletteColorLookupTableData:_e(o["00281202"]),bluePaletteColorLookupTableData:_e(o["00281203"])};if(t===r.VOI_LUT)return{windowCenter:_e(o["00281050"],1),windowWidth:_e(o["00281051"],1)};if(t===r.MODALITY_LUT)return{rescaleIntercept:ke(o["00281052"]),rescaleSlope:ke(o["00281053"]),rescaleType:Be(o["00281054"])};if(t===r.SOP_COMMON)return{sopClassUID:Be(o["00080016"]),sopInstanceUID:Be(o["00080018"])};if(t===r.PET_ISOTOPE){const e=Be(o["00540016"]);if(void 0===e)return;return{radiopharmaceuticalInfo:{radiopharmaceuticalStartTime:a.parseTM(Be(e["00181072"],0,"")),radiopharmaceuticalStartDateTime:Be(e["00181078"],0,""),radionuclideTotalDose:ke(e["00181074"]),radionuclideHalfLife:ke(e["00181075"])}}}return t===r.OVERLAY_PLANE?function(e){const t=[];for(let n=0;n<=30;n+=2){let r=`x60${n.toString(16)}`;4===r.length&&(r=`x600${n.toString(16)}`);const a=Be(e[`${r}3000`]);if(!a)continue;const o=[];for(let t=0;t<a.length;t++)for(let n=0;n<8;n++){const r=e.Value[a.dataOffset+t];o[8*t+n]=r>>n&1}t.push({rows:ke(e[`${r}0010`]),columns:ke(e[`${r}0011`]),type:Be(e[`${r}0040`]),x:ke(e[`${r}0050`],1)-1,y:ke(e[`${r}0050`],0)-1,pixelData:o,description:Be(e[`${r}0022`]),label:Be(e[`${r}1500`]),roiArea:Be(e[`${r}1301`]),roiMean:Be(e[`${r}1302`]),roiStandardDeviation:Be(e[`${r}1303`])})}return{overlays:t}}(o):"transferSyntax"===t?nt(n,o):t===r.PET_SERIES?{correctedImage:Be(o["00280051"]),units:Be(o["00541001"]),decayCorrection:Be(o["00541102"])}:t===r.PET_IMAGE?{frameReferenceTime:ke(o["00541300"]),actualFrameDuration:ke(o["00181242"])}:"instance"===t?oe(n,e,se):void 0}};function at(e,t,n={},r={}){const a=d(),{retrieveOptions:o={},streamingData:i}=r,s=i.chunkSize||function(e,t,n){const r=t[n];if("function"!=typeof r)return r;const a=ze.get(e);return r(a,e)}(t,o,"chunkSize")||65536,l=new Promise((async(t,r)=>{const l=Object.assign({},n);Object.keys(l).forEach((function(e){null!==l[e]&&void 0!==l[e]||delete l[e]}));try{i.encodedData||(i.chunkSize=s,i.rangesFetched=0);const n=function(e,t){const{totalBytes:n,encodedData:r,chunkSize:a=65536}=e,{rangeIndex:o=0}=t;if(!(-1!==o||n&&r))return[0,""];if(-1===o||r?.byteLength>n-a)return[r?.byteLength||0,""];return[r?.byteLength||0,a*(o+1)-1]}(i,o),{encodedData:r,responseHeaders:a}=await async function(e,t,n,r){n&&(t=Object.assign(t,{Range:`bytes=${n[0]}-${n[1]}`}));let{encodedData:a}=r;if(n[1]&&a?.byteLength>n[1])return r;const o=await fetch(e,{headers:t,signal:void 0}),i=await o.arrayBuffer(),s=new Uint8Array(i),{status:l}=o;let c;a?(c=new Uint8Array(a.length+s.length),c.set(a,0),c.set(s,a.length),r.rangesFetched=1):(c=new Uint8Array(s.length),c.set(s,0),r.rangesFetched++);r.encodedData=a=c,r.responseHeaders=o.headers;const u=o.headers.get("Content-Range");u?r.totalBytes=Number(u.split("/")[1]):206===l&&n?""===n[1]||a?.length<n[1]?r.totalBytes=a.byteLength:r.totalBytes=Number.MAX_SAFE_INTEGER:r.totalBytes=a?.byteLength;return r}(e,l,n,i),c=a.get("content-type"),{totalBytes:u}=i,f=u===r.byteLength,d=F(c,r,{isPartial:!0}),g=B(o,f||d.extractDone);t({...d,imageQualityStatus:g,percentComplete:d.extractDone?100:100*s/u})}catch(e){(e=>{if("function"==typeof a.errorInterceptor){const e=new Error("request failed");a.errorInterceptor(e)}else console.warn("rangeRequest:Caught",e)})(e),console.error(e),r(e)}}));return l}const ot=function(e,t,n="application/octet-stream",r){const{streamingData:a,retrieveOptions:o={}}=r||{},i={Accept:n};let s=o.urlArguments?`${e}${-1===e.indexOf("?")?"?":"&"}${o.urlArguments}`:e;if(o.framesPath&&(s=s.replace("/frames/",o.framesPath)),a?.url!==s&&(r.streamingData={url:s}),void 0!==o.rangeIndex)return at(s,t,i,r);if(o.streaming)return k(s,t,i,r);const l=E(s,t,i),{xhr:c}=l;return l.then((function(e){const t=F(c.getResponseHeader("Content-Type")||"application/octet-stream",new Uint8Array(e));return t.imageQualityStatus=B(o,!0),t}))},{ProgressiveIterator:it}=e,{ImageQualityStatus:st}=t,lt=new Set(["3.2.840.10008.1.2.4.96","1.2.840.10008.1.2.4.202","1.2.840.10008.1.2.4.203"]);function ct(e){const t="1.2.840.10008.1.2";if(!e)return t;const n=e.split(";"),r={};n.forEach((e=>{const t=e.split("=");if(2!==t.length)return;const n=t[1].trim().replace(/"/g,"");r[t[0].trim()]=n}));const a={"image/jpeg":"1.2.840.10008.1.2.4.50","image/x-dicom-rle":"1.2.840.10008.1.2.5","image/x-jls":"1.2.840.10008.1.2.4.80","image/jls":"1.2.840.10008.1.2.4.80","image/jll":"1.2.840.10008.1.2.4.70","image/jp2":"1.2.840.10008.1.2.4.90","image/jpx":"1.2.840.10008.1.2.4.92","image/jphc":"3.2.840.10008.1.2.4.96","image/jxl":"1.2.840.10008.1.2.4.140"};return r["transfer-syntax"]?r["transfer-syntax"]:e&&!Object.keys(r).length&&a[e]?a[e]:r.type&&a[r.type]?a[r.type]:a[e]?a[e]:t}function ut(e,t=4){const n=e/100-.02;return n>1/4?Math.min(t,0):n>1/16?Math.min(t,1):n>1/64?Math.min(t,2):Math.min(t,3)}const ft=function(e,t={}){const n=p.cornerstone.imageRetrievalPoolManager,r=(new Date).getTime(),a=new it("decompress"),o=t.requestType||"interaction",i=t.additionalDetails||{imageId:e},s=void 0===t.priority?5:t.priority,l=t.addToBeginning||!1,c=e.substring(7);return n.addRequest(async function(e,n,o){a.generate((async a=>{const i=it.as(ot(e,n,o,t));let s=10;for await(const e of i){const{pixelData:o,imageQualityStatus:i=st.FULL_RESOLUTION,percentComplete:l,done:c=!0,extractDone:u=!0}=e,f=ct(e.contentType);if(!u&&!lt.has(f))continue;const d=e.decodeLevel??(i===st.FULL_RESOLUTION?0:ut(l,t.retrieveOptions?.decodeLevel));if(c||!(s<=d))try{const e={...t,decodeLevel:d},l=await ve(n,o,f,e),u=(new Date).getTime();l.loadTimeInMS=u-r,l.transferSyntaxUID=f,l.imageQualityStatus=i,a.add(l,c),s=d}catch(e){if(u)throw console.warn("Couldn't decode",e),e}}}))}.bind(this,c,e,"multipart/related; type=application/octet-stream; transfer-syntax=*"),o,i,s,l),{promise:a.getDonePromise(),cancelFn:void 0}};function dt(e){e.registerImageLoader("wadors",ft),e.metaData.addProvider(rt)}const gt={metaData:{getNumberString:Ne,getNumberValue:ke,getNumberValues:_e,getValue:Be,metaDataProvider:rt},findIndexOfString:M,getPixelData:ot,loadImage:ft,metaDataManager:ze,register:dt};const mt=function(e){dt(e),Fe(e)};const pt=function(e){if(!e.cornerstone||!e.dicomParser)throw new Error("cornerstoneWADOImageLoader.configure: Options object must contain the cornerstone and dicomParser packages.");f(e),p.cornerstone=e.cornerstone,p.dicomParser=e.dicomParser,mt(e.cornerstone)};const ht=function(e,t){if(t=t||e.transferSyntax,8===e.bitsAllocated&&"1.2.840.10008.1.2.4.50"===t&&(3===e.samplesPerPixel||4===e.samplesPerPixel))return!0},xt={convertRGBColorByPixel:n,convertRGBColorByPlane:o,convertYBRFullByPixel:i,convertYBRFullByPlane:s,convertPALETTECOLOR:y,wadouri:Ue,wadors:gt,configure:pt,convertColorSpace:Pe,createImage:ve,decodeJPEGBaseline8BitColor:Se,getImageFrame:Te,getPixelData:ot,getMinMax:ye,isColorImage:Le,isJPEGBaseline8BitColor:ht,internal:V,external:p}})(),a})()));
|
|
2
2
|
//# sourceMappingURL=cornerstoneDICOMImageLoader.bundle.min.js.map
|