@cornerstonejs/dicom-image-loader 2.0.0-beta.21 → 2.0.0-beta.22

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.
@@ -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}},r={};function n(e){var a=r[e];if(void 0!==a)return a.exports;var o=r[e]={exports:{}};return t[e](o,o.exports,n),o.exports}n.m=t,n.d=(e,t)=>{for(var r in t)n.o(t,r)&&!n.o(e,r)&&Object.defineProperty(e,r,{enumerable:!0,get:t[r]})},n.u=e=>e+".bundle.min.js",n.g=function(){if("object"==typeof globalThis)return globalThis;try{return this||new Function("return this")()}catch(e){if("object"==typeof window)return window}}(),n.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),n.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},(()=>{var e;n.g.importScripts&&(e=n.g.location+"");var t=n.g.document;if(!e&&t&&(t.currentScript&&(e=t.currentScript.src),!e)){var r=t.getElementsByTagName("script");if(r.length)for(var a=r.length-1;a>-1&&!e;)e=r[a--].src}if(!e)throw new Error("Automatic publicPath is not supported in this browser");e=e.replace(/#.*$/,"").replace(/\?.*$/,"").replace(/\/[^\/]+$/,"/"),n.p=e})(),n.b=document.baseURI||self.location.href;var a={};return(()=>{n.r(a),n.d(a,{configure:()=>mt,convertColorSpace:()=>te,convertPALETTECOLOR:()=>dt,convertRGBColorByPixel:()=>r,convertRGBColorByPlane:()=>o,convertYBRFullByPixel:()=>i,convertYBRFullByPlane:()=>s,createImage:()=>ue,decodeJPEGBaseline8BitColor:()=>ne,default:()=>pt,external:()=>ct,getImageFrame:()=>ie,getMinMax:()=>Z,getPixelData:()=>K,internal:()=>I,isColorImage:()=>se,isJPEGBaseline8BitColor:()=>gt,wadors:()=>xe,wadouri:()=>nt});var e={};n.r(e),n.d(e,{ProgressiveIterator:()=>d});var t={};function r(e,t,r){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 n=e.length/3;let a=0,o=0;if(r)for(let r=0;r<n;r++)t[o++]=e[a++],t[o++]=e[a++],t[o++]=e[a++],t[o++]=255;else t.set(e)}function o(e,t,r){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 n=e.length/3;let a=0,o=0,i=n,s=2*n;if(r)for(let r=0;r<n;r++)t[a++]=e[o++],t[a++]=e[i++],t[a++]=e[s++],t[a++]=255;else for(let r=0;r<n;r++)t[a++]=e[o++],t[a++]=e[i++],t[a++]=e[s++]}function i(e,t,r){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 n=e.length/3;let a=0,o=0;if(r)for(let r=0;r<n;r++){const r=e[a++],n=e[a++],i=e[a++];t[o++]=r+1.402*(i-128),t[o++]=r-.34414*(n-128)-.71414*(i-128),t[o++]=r+1.772*(n-128),t[o++]=255}else for(let r=0;r<n;r++){const r=e[a++],n=e[a++],i=e[a++];t[o++]=r+1.402*(i-128),t[o++]=r-.34414*(n-128)-.71414*(i-128),t[o++]=r+1.772*(n-128)}}function s(e,t,r){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 n=e.length/3;let a=0,o=0,i=n,s=2*n;if(r)for(let r=0;r<n;r++){const r=e[o++],n=e[i++],l=e[s++];t[a++]=r+1.402*(l-128),t[a++]=r-.34414*(n-128)-.71414*(l-128),t[a++]=r+1.772*(n-128),t[a++]=255}else for(let r=0;r<n;r++){const r=e[o++],n=e[i++],l=e[s++];t[a++]=r+1.402*(l-128),t[a++]=r-.34414*(n-128)-.71414*(l-128),t[a++]=r+1.772*(n-128)}}n.r(t),n.d(t,{ImageQualityStatus:()=>g});let l={open(e,t){e.open("get",t,!0)},beforeSend(){},beforeProcessing:e=>Promise.resolve(e.response),imageCreated(){},strict:!1};function c(e){l=Object.assign(l,e)}function u(){return l}const f=function(e,t,r={},n={}){const{cornerstone:a}=ct,o=u(),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,r,n);const u=o.beforeSend(s,t,r,n);s.responseType="arraybuffer";const f=Object.assign({},r,u);Object.keys(f).forEach((function(t){null!==f[t]&&("Accept"===t&&-1!==e.indexOf("accept=")||s.setRequestHeader(t,f[t]))})),n.deferred={resolve:l,reject:c},n.url=e,n.imageId=t,s.onloadstart=function(r){o.onloadstart&&o.onloadstart(r,n);const i={url:e,imageId:t};a.triggerEvent(a.events,"cornerstoneimageloadstart",i)},s.onloadend=function(r){o.onloadend&&o.onloadend(r,n);const i={url:e,imageId:t};a.triggerEvent(a.events,"cornerstoneimageloadend",i)},s.onreadystatechange=function(e){o.onreadystatechange?o.onreadystatechange(e,n):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 r,a;e.lengthComputable&&(r=e.total,a=Math.round(t/r*100)),o.onprogress&&o.onprogress(e,n)},s.onerror=function(){i(s),c(s)},s.onabort=function(){i(s),c(s)},s.send()}));return l.xhr=s,l};class d{constructor(e){this.name=e||"unknown"}static as(e){if(e.iterator)return e.iterator;const t=new d("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 r=0;try{for await(const n of this){const{done:a}=this;try{await e(n,a,r),r++}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 m;!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"}(m||(m={}));const g=m;function p(e,t,r){if(r+e.length>t.length)return!1;let n=r;for(let r=0;r<e.length;r++)if(e[r]!==t[n++])return!1;return!0}const h=function(e,t,r){r=r||0;const n=function(e){const t=new Uint8Array(e.length);for(let r=0,n=e.length;r<n;r++)t[r]=e.charCodeAt(r);return t}(t);for(let t=r;t<e.length;t++)if(n[0]===e[t]&&p(n,e,t))return t;return-1},{ImageQualityStatus:x}=t;function y(e,t,r){r||={};const n=new Uint8Array(t),a=!!r?.isPartial;if(-1===e.indexOf("multipart"))return{contentType:e,imageQualityStatus:a?x.SUBRESOLUTION:x.FULL_RESOLUTION,pixelData:n};let{tokenIndex:o,responseHeaders:i,boundary:s,multipartContentType:l}=r;if(o||=h(n,"\r\n\r\n"),-1===o)throw new Error("invalid response - no multipart mime header");if(!s){const e=function(e,t,r){t=t||0,r=r||e.length-t;let n="";for(let a=t;a<t+r;a++)n+=String.fromCharCode(e[a]);return n}(n,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=h(n,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),r.tokenIndex=o,r.boundary=s,r.responseHeaders=i,r.multipartContentType=l,r.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:b}=t;function P(e,t=!0){return t?e.imageQualityStatus??b.FULL_RESOLUTION:b.SUBRESOLUTION}const{ProgressiveIterator:w}=e;function S(e,t,r={},n={}){const a=u(),{retrieveOptions:o={},streamingData:i={}}=n,s=o.chunkSize||131072,l=new w("streamRequest");return l.generate((async(n,l)=>{const c=Object.assign({},r);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:r,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,m=i.encodedData,g=i.lastSize||0;for(i.isPartial=!0;!d;){const{done:r,value:a}=await l.read();if(m=D(m,a),!m){if(d)throw new Error(`Done but no image frame available ${t}`);continue}if(d=r||m.byteLength===f,!d&&m.length<g+s)continue;g=m.length,i.isPartial=!r;const c=y(u,m,i),p=P(o,d),h={url:e,imageId:t,...c,percentComplete:r?100:100*c.pixelData?.length/f,imageQualityStatus:p,done:d};n.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 D(e,t){if(!e)return t;if(!t)return e;const r=new Uint8Array(e.length+t.length);return r.set(e,0),r.set(t,e.length),r}const I={xhrRequest:f,streamRequest:S,setOptions:c,getOptions:u};const T=function(e,t,r){return t=t||0,e&&e.Value?Array.isArray(e.Value)&&e.Value.length<=t?r:e.Value[t]:r};const L=function(e,t,r){const n=T(e,t,r);if(void 0!==n)return parseFloat(String(n))};const v=function(e,t){const r=T(e,t);if(void 0!==r)return parseFloat(r)};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 r=[];for(let t=0;t<e.Value.length;t++)r.push(parseFloat(e.Value[t]));return r};function C(e){const t=e.indexOf(":");return e.substring(t+1)}function A(e,t=!0){return e&&e.Value?e.Value[0]&&t?e.Value[0]:e.Value:e}function O(e,t,r){return{shared:(t?Object.values(t[0]):[]).map((e=>e[0])).filter((e=>void 0!==e&&"object"==typeof e)),perFrame:(e?Object.values(e[r-1]):[]).map((e=>e.Value[0])).filter((e=>void 0!==e&&"object"==typeof e))}}function M(e){let{52009230:t,52009229:r,"00280008":n,...a}=e;return t=A(t,!1),r=A(r,!1),n=A(n),{PerFrameFunctionalGroupsSequence:t,SharedFunctionalGroupsSequence:r,NumberOfFrames:n,rest:a}}function R(e){const t=e.indexOf("/frames/")+8,r=e.slice(0,t),n=parseInt(e.slice(t),10);return{metadata:U[`${r}1`],frame:n}}const F={_retrieveMultiframeMetadata:R,retrieveMultiframeMetadata:function(e){return R(C(e))},isMultiframe:function(e){const t=T(e["00280008"]);return t&&t>1}};let U=[],B={};const N={add:function(e,t){const r=C(e);Object.defineProperty(t,"isMultiframe",{value:F.isMultiframe(t),enumerable:!1}),U[r]=t},get:function(e){const t=C(e),r=U[t];if(r&&!r?.isMultiframe)return r;const n=B[t];if(n)return n;const a=F._retrieveMultiframeMetadata(t);if(!a||!a.metadata)return;const{metadata:o,frame:i}=a;if(o){const e=function(e,t){const{PerFrameFunctionalGroupsSequence:r,SharedFunctionalGroupsSequence:n,NumberOfFrames:a,rest:o}=M(t);if(r||a>1){const{shared:i,perFrame:s}=O(r,n,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 B[t]=e,e}},remove:function(e){const t=C(e);U[t]=void 0,B[t]=void 0},purge:function(){U=[],B={}}};function k(e){return"RECON TOMO"===e||"RECON GATED TOMO"===e}function _(e){return T(e["00080060"]).includes("NM")}function j(e,t){const r=A(e["00080008"],!1);if(r)return r[t]}function V(e){let t=E(e["00200037"],6);return!t&&_(e)&&(t=function(e){let t;const r=j(e,2);if(r&&k(r)){const r=A(e["00540022"]);r&&(t=E(r["00200037"],6))}return t}(e)),t}function $(e){let t=E(e["00200032"],3);return!t&&_(e)&&(t=function(e){let t;const r=j(e,2);if(r&&k(r)){const r=A(e["00540022"]);r&&(t=E(r["00200032"],3))}return t}(e)),t}function G(e,t,r){const n={};for(const a of r)try{const r=t(a,e);if(r){const e={};for(const t in r)if(t in r){e[q(t)]=r[t]}Object.assign(n,e)}}catch(e){console.error(`Error retrieving ${a} data:`,e)}return n}const q=e=>e.charAt(0).toUpperCase()+e.slice(1),Y=["multiframeModule","generalSeriesModule","patientStudyModule","imagePlaneModule","nmMultiframeGeometryModule","imagePixelModule","modalityLutModule","voiLutModule","sopCommonModule","petIsotopeModule","overlayPlaneModule","transferSyntax","petSeriesModule","petImageModule"];function W(e,t){const r=E(e[t]);return r?r[0]:null}const X=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 z(e){const t=X(e["00186011"]);if(!t||!t.length)return null;return t.map((e=>{const t=W(e,"0018602C"),r=W(e,"0018602E"),n=W(e,"00186024"),a=W(e,"00186026");return{regionLocationMinY0:W(e,"0018601A"),regionLocationMaxY1:W(e,"0018601E"),regionLocationMinX0:W(e,"00186018"),regionLocationMaxX1:W(e,"0018601C"),referencePixelX0:W(e,"00186020"),referencePixelY0:W(e,"00186022"),physicalDeltaX:t,physicalDeltaY:r,physicalUnitsXDirection:n,physicalUnitsYDirection:a,referencePhysicalPixelValueY:W(e,"0018602A"),referencePhysicalPixelValueX:W(e,"00186028"),regionSpatialFormat:W(e,"00186012"),regionDataType:W(e,"00186014"),regionFlags:W(e,"00186016"),transducerFrequency:W(e,"00186030")}}))}function H(e,t){return{transferSyntaxUID:T(t["00020010"])||T(t["00083002"])}}const Q=function e(t,r){const{MetadataModules:n}=ct.cornerstone.Enums,{dicomParser:a}=ct;if(t===n.MULTIFRAME){const{metadata:e,frame:t}=F.retrieveMultiframeMetadata(r);if(!e)return;const{PerFrameFunctionalGroupsSequence:n,SharedFunctionalGroupsSequence:a,NumberOfFrames:o}=M(e);if(n||o>1){const{shared:e,perFrame:r}=O(n,a,t);return{NumberOfFrames:o,PerFrameFunctionalInformation:r,SharedFunctionalInformation:e}}return{NumberOfFrames:o}}const o=N.get(r);if(o){if(t===n.GENERAL_STUDY)return{studyDescription:T(o["00081030"]),studyDate:a.parseDA(T(o["00080020"])),studyTime:a.parseTM(T(o["00080030"],0,"")),accessionNumber:T(o["00080050"])};if(t===n.GENERAL_SERIES)return{modality:T(o["00080060"]),seriesInstanceUID:T(o["0020000E"]),seriesNumber:v(o["00200011"]),studyInstanceUID:T(o["0020000D"]),seriesDate:a.parseDA(T(o["00080021"])),seriesTime:a.parseTM(T(o["00080031"],0,"")),acquisitionDate:a.parseDA(T(o["00080022"])),acquisitionTime:a.parseTM(T(o["00080032"],0,""))};if(t===n.GENERAL_IMAGE)return{sopInstanceUID:T(o["00080018"]),instanceNumber:v(o["00200013"]),lossyImageCompression:T(o["00282110"]),lossyImageCompressionRatio:v(o["00282112"]),lossyImageCompressionMethod:T(o["00282114"])};if(t===n.PATIENT)return{patientID:T(o["00100020"]),patientName:T(o["00100010"])};if(t===n.PATIENT_STUDY)return{patientAge:v(o["00101010"]),patientSize:v(o["00101020"]),patientSex:T(o["00100040"]),patientWeight:v(o["00101030"])};if(t===n.NM_MULTIFRAME_GEOMETRY){const e=T(o["00080060"]),t=j(o,2);return{modality:e,imageType:T(o["00080008"]),imageSubType:t,imageOrientationPatient:V(o),imagePositionPatient:$(o),sliceThickness:v(o["00180050"]),spacingBetweenSlices:v(o["00180088"]),pixelSpacing:E(o["00280030"],2),numberOfFrames:v(o["00280008"]),isNMReconstructable:k(t)&&e.includes("NM")}}if(t===n.IMAGE_PLANE){const e=V(o),t=$(o),r=E(o["00280030"],2);let n=null,a=null;r&&(a=r[0],n=r[1]);let i=null,s=null;return e&&(i=[parseFloat(e[0]),parseFloat(e[1]),parseFloat(e[2])],s=[parseFloat(e[3]),parseFloat(e[4]),parseFloat(e[5])]),{frameOfReferenceUID:T(o["00200052"]),rows:v(o["00280010"]),columns:v(o["00280011"]),imageOrientationPatient:e,rowCosines:i,columnCosines:s,imagePositionPatient:t,sliceThickness:v(o["00180050"]),sliceLocation:v(o["00201041"]),pixelSpacing:r,rowPixelSpacing:a,columnPixelSpacing:n}}if(t===n.ULTRASOUND_ENHANCED_REGION)return z(o);if(t===n.CALIBRATION){if("US"===T(o["00080060"])){return{sequenceOfUltrasoundRegions:z(o)}}}if(t===n.IMAGE_URL)return function(e,t){const{transferSyntaxUID:r}=H(e,t),n=ct.cornerstone.utilities.isVideoTransferSyntax(r),a=e.substring(7),o=a.replace("/frames/","/thumbnail/");let i=a.replace("/frames/","/rendered/");n&&(i=i.replace("/rendered/1","/rendered"));return{isVideo:n,rendered:i,thumbnail:o}}(r,o);if(t===n.CINE)return function(e,t){const r=T(t["00180040"]);return{cineRate:r,numberOfFrames:v(t["00280008"])}}(0,o);if(t===n.IMAGE_PIXEL)return{samplesPerPixel:v(o["00280002"]),photometricInterpretation:T(o["00280004"]),rows:v(o["00280010"]),columns:v(o["00280011"]),bitsAllocated:v(o["00280100"]),bitsStored:v(o["00280101"]),highBit:T(o["00280102"]),pixelRepresentation:v(o["00280103"]),planarConfiguration:v(o["00280006"]),pixelAspectRatio:T(o["00280034"]),smallestPixelValue:v(o["00280106"]),largestPixelValue:v(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===n.VOI_LUT)return{windowCenter:E(o["00281050"],1),windowWidth:E(o["00281051"],1)};if(t===n.MODALITY_LUT)return{rescaleIntercept:v(o["00281052"]),rescaleSlope:v(o["00281053"]),rescaleType:T(o["00281054"])};if(t===n.SOP_COMMON)return{sopClassUID:T(o["00080016"]),sopInstanceUID:T(o["00080018"])};if(t===n.PET_ISOTOPE){const e=T(o["00540016"]);if(void 0===e)return;return{radiopharmaceuticalInfo:{radiopharmaceuticalStartTime:a.parseTM(T(e["00181072"],0,"")),radiopharmaceuticalStartDateTime:T(e["00181078"],0,""),radionuclideTotalDose:v(e["00181074"]),radionuclideHalfLife:v(e["00181075"])}}}return t===n.OVERLAY_PLANE?function(e){const t=[];for(let r=0;r<=30;r+=2){let n=`x60${r.toString(16)}`;4===n.length&&(n=`x600${r.toString(16)}`);const a=T(e[`${n}3000`]);if(!a)continue;const o=[];for(let t=0;t<a.length;t++)for(let r=0;r<8;r++){const n=e.Value[a.dataOffset+t];o[8*t+r]=n>>r&1}t.push({rows:v(e[`${n}0010`]),columns:v(e[`${n}0011`]),type:T(e[`${n}0040`]),x:v(e[`${n}0050`],1)-1,y:v(e[`${n}0050`],0)-1,pixelData:o,description:T(e[`${n}0022`]),label:T(e[`${n}1500`]),roiArea:T(e[`${n}1301`]),roiMean:T(e[`${n}1302`]),roiStandardDeviation:T(e[`${n}1303`])})}return{overlays:t}}(o):"transferSyntax"===t?H(r,o):t===n.PET_SERIES?{correctedImage:T(o["00280051"]),units:T(o["00541001"]),decayCorrection:T(o["00541102"])}:t===n.PET_IMAGE?{frameReferenceTime:v(o["00541300"]),actualFrameDuration:v(o["00181242"])}:"instance"===t?G(r,e,Y):void 0}};function J(e,t,r={},n={}){const a=u(),{retrieveOptions:o={},streamingData:i}=n,s=i.chunkSize||function(e,t,r){const n=t[r];if("function"!=typeof n)return n;const a=N.get(e);return n(a,e)}(t,o,"chunkSize")||65536,l=new Promise((async(t,n)=>{const l=Object.assign({},r);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 r=function(e,t){const{totalBytes:r,encodedData:n,chunkSize:a=65536}=e,{rangeIndex:o=0}=t;if(!(-1!==o||r&&n))return[0,""];if(-1===o||n?.byteLength>r-a)return[n?.byteLength||0,""];return[n?.byteLength||0,a*(o+1)-1]}(i,o),{encodedData:n,responseHeaders:a}=await async function(e,t,r,n){r&&(t=Object.assign(t,{Range:`bytes=${r[0]}-${r[1]}`}));let{encodedData:a}=n;if(r[1]&&a?.byteLength>r[1])return n;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),n.rangesFetched=1):(c=new Uint8Array(s.length),c.set(s,0),n.rangesFetched++);n.encodedData=a=c,n.responseHeaders=o.headers;const u=o.headers.get("Content-Range");u?n.totalBytes=Number(u.split("/")[1]):206===l&&r?""===r[1]||a?.length<r[1]?n.totalBytes=a.byteLength:n.totalBytes=Number.MAX_SAFE_INTEGER:n.totalBytes=a?.byteLength;return n}(e,l,r,i),c=a.get("content-type"),{totalBytes:u}=i,f=u===n.byteLength,d=y(c,n,{isPartial:!0}),m=P(o,f||d.extractDone);t({...d,imageQualityStatus:m,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),n(e)}}));return l}const K=function(e,t,r="application/octet-stream",n){const{streamingData:a,retrieveOptions:o={}}=n||{},i={Accept:r};let s=o.urlArguments?`${e}${-1===e.indexOf("?")?"?":"&"}${o.urlArguments}`:e;if(o.framesPath&&(s=s.replace("/frames/",o.framesPath)),a?.url!==s&&(n.streamingData={url:s}),void 0!==o.rangeIndex)return J(s,t,i,n);if(o.streaming)return S(s,t,i,n);const l=f(s,t,i),{xhr:c}=l;return l.then((function(e){const t=y(c.getResponseHeader("Content-Type")||"application/octet-stream",new Uint8Array(e));return t.imageQualityStatus=P(o,!0),t}))};const Z=function(e){let t,r=e[0],n=e[0];const a=e.length;for(let o=1;o<a;o++)t=e[o],r=Math.min(r,t),n=Math.max(n,t);return{min:r,max:n}};function ee(e,t,n){0===e.planarConfiguration?r(e.pixelData,t,n):o(e.pixelData,t,n)}function te(e,t,r){if("RGB"===e.photometricInterpretation)ee(e,t,r);else if("YBR_RCT"===e.photometricInterpretation)ee(e,t,r);else if("YBR_ICT"===e.photometricInterpretation)ee(e,t,r);else if("PALETTE COLOR"===e.photometricInterpretation)dt(e,t,r);else if("YBR_FULL_422"===e.photometricInterpretation)!function(e,t,r){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 n=e.length/2;let a=0,o=0;if(r)for(let r=0;r<n;r+=2){const r=e[a++],n=e[a++],i=e[a++],s=e[a++];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,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}else for(let r=0;r<n;r+=2){const r=e[a++],n=e[a++],i=e[a++],s=e[a++];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++]=n+1.402*(s-128),t[o++]=n-.34414*(i-128)-.71414*(s-128),t[o++]=n+1.772*(i-128)}}(e.pixelData,t,r);else{if("YBR_FULL"!==e.photometricInterpretation)throw new Error(`No color space conversion for photometric interpretation ${e.photometricInterpretation}`);!function(e,t,r){0===e.planarConfiguration?i(e.pixelData,t,r):s(e.pixelData,t,r)}(e,t,r)}}function re(e){return function(e){let t;try{return decodeURIComponent(escape(e))}catch(r){if(t=r,t instanceof URIError)return e;throw t}}(String.fromCharCode.apply(null,Array.prototype.slice.apply(new Uint8Array(e))))}const ne=function(e,t,r){const n=(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(){r.height=a.height,r.width=a.width,e.rows=a.height,e.columns=a.width;const o=r.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-n;const l=Z(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(re(i.result))}`:a.src=`data:image/jpeg;base64,${window.btoa(i.result)}`},i.onerror=e=>{o(e)}}))};function ae(e,t,r,n,a){const o={...n};delete o.loader,delete o.streamingData;const i=ct.cornerstone.getWebWorkerManager(),s=o.priority||void 0;o.transferPixelData&&r.buffer;return i.executeTask("dicomImageLoader","decodeTask",{imageFrame:e,transferSyntax:t,pixelData:r,options:o,decodeConfig:a},{priority:s,requestType:o?.requestType})}const oe=function(e,t,r,n,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 ae(e,t,r,a,o);case"1.2.840.10008.1.2.4.50":return 8!==e.bitsAllocated||3!==e.samplesPerPixel&&4!==e.samplesPerPixel?ae(e,t,r,a,o):ne(e,r,n)}return Promise.reject(new Error(`No decoder for transfer syntax ${t}`))};const ie=function(e){const{cornerstone:t}=ct,r=t.metaData.get("imagePixelModule",e);return{samplesPerPixel:r.samplesPerPixel,photometricInterpretation:r.photometricInterpretation,planarConfiguration:r.planarConfiguration,rows:r.rows,columns:r.columns,bitsAllocated:r.bitsAllocated,bitsStored:r.bitsStored,pixelRepresentation:r.pixelRepresentation,smallestPixelValue:r.smallestPixelValue,largestPixelValue:r.largestPixelValue,redPaletteColorLookupTableDescriptor:r.redPaletteColorLookupTableDescriptor,greenPaletteColorLookupTableDescriptor:r.greenPaletteColorLookupTableDescriptor,bluePaletteColorLookupTableDescriptor:r.bluePaletteColorLookupTableDescriptor,redPaletteColorLookupTableData:r.redPaletteColorLookupTableData,greenPaletteColorLookupTableData:r.greenPaletteColorLookupTableData,bluePaletteColorLookupTableData:r.bluePaletteColorLookupTableData,pixelData:void 0,imageId:e}};function se(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 le="";function ce(e){const t=function(e,t){let r;return Number.isInteger(e)&&Number.isInteger(t)&&(e>=0?t<=255?r=Uint8Array:t<=65535&&(r=Uint16Array):e>=-128&&t<=127?r=Int8Array:e>=-32768&&t<=32767&&(r=Int16Array)),r||Float32Array}(e.smallestPixelValue,e.largestPixelValue);if(!t)throw new Error("Could not apply a typed array to the pixel data");{const r=new t(e.pixelData);e.pixelData=r}}const ue=function(e,t,r,n={}){const a=n.useRGBA;if(n.preScale={enabled:!n.preScale||void 0===n.preScale.enabled||n.preScale.enabled},!t?.length)return Promise.reject(new Error("The pixel data is missing"));const{cornerstone:o}=ct,{MetadataModules:i}=o.Enums,s=document.createElement("canvas"),l=ie(e);if(l.decodeLevel=n.decodeLevel,n.allowFloatRendering=o.canRenderFloatTextures(),n.preScale.enabled){const t=function(e,t){const r=e.get("modalityLutModule",t)||{},n=e.get("generalSeriesModule",t)||{},{modality:a}=n,o={rescaleSlope:r.rescaleSlope,rescaleIntercept:r.rescaleIntercept,modality:a},i=e.get("scalingModule",t)||{};return{...o,..."PT"===a&&{suvbw:i.suvbw}}}(o.metaData,e);t&&(n.preScale={...n.preScale,scalingParameters:t})}const{decodeConfig:c}=u();Object.keys(l).forEach((e=>{("function"==typeof l[e]||l[e]instanceof Promise)&&delete l[e]}));const f=oe(l,r,t,s,n,c),d=se(l.photometricInterpretation);return new Promise(((t,r)=>{f.then((function(r){let l=!1;if(n.targetBuffer&&n.targetBuffer.type&&!d){const{arrayBuffer:e,type:t,offset:a=0,length:o}=n.targetBuffer,i=r.pixelDataLength,s=a,c=null!=o?o:i-s,u={Uint8Array,Uint16Array,Int16Array,Float32Array};if(c!==r.pixelDataLength)throw new Error(`target array for image does not have the same length (${c}) as the decoded image length (${r.pixelDataLength}).`);const f=u[t],d=e?new f(e,s,c):new f(r.pixelData);if(c!==r.pixelDataLength)throw new Error("target array for image does not have the same length as the decoded image length.");r.pixelData=d,l=!0}l||ce(r);const c=o.metaData.get(i.IMAGE_PLANE,e)||{},u=o.metaData.get(i.VOI_LUT,e)||{},f=o.metaData.get(i.MODALITY_LUT,e)||{},m=o.metaData.get(i.SOP_COMMON,e)||{},g=o.metaData.get(i.CALIBRATION,e)||{},{rows:p,columns:h}=r;if(d){if(function(e){if(void 0===e)return!1;const{rows:t,columns:r,photometricInterpretation:n,pixelDataLength:a}=e;return a!==4*r*t&&(n.endsWith("420")?a===(3*Math.ceil(r/2)+Math.floor(r/2))*t:n.endsWith("422")?a===(3*Math.ceil(r/2)+Math.floor(r/2))*Math.ceil(t/2)+Math.floor(t/2)*r:"RGB"!==n)}(r)){s.height=r.rows,s.width=r.columns;let e=s.getContext("2d").createImageData(r.columns,r.rows);a||(e={...e,data:new Uint8ClampedArray(r.samplesPerPixel*r.columns*r.rows)}),te(r,e.data,a),r.imageData=e,r.pixelData=e.data,r.pixelDataLength=e.data.length}else if(!a&&r.pixelDataLength===4*p*h){const e=new Uint8Array(r.pixelData.length/4*3);r.pixelData=function(e,t){const r=e.length/4;let n=0,a=0;for(let o=0;o<r;o++)t[a++]=e[n++],t[a++]=e[n++],t[a++]=e[n++],n++;return t}(r.pixelData,e),r.pixelDataLength=r.pixelData.length}const e=Z(r.pixelData);r.smallestPixelValue=e.min,r.largestPixelValue=e.max}const x={imageId:e,dataType:r.pixelData.constructor.name,color:d,calibration:g,columnPixelSpacing:c.columnPixelSpacing,columns:r.columns,height:r.rows,preScale:r.preScale,intercept:f.rescaleIntercept?f.rescaleIntercept:0,slope:f.rescaleSlope?f.rescaleSlope:1,invert:"MONOCHROME1"===r.photometricInterpretation,minPixelValue:r.smallestPixelValue,maxPixelValue:r.largestPixelValue,rowPixelSpacing:c.rowPixelSpacing,rows:r.rows,sizeInBytes:r.pixelData.byteLength,width:r.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:r.decodeTimeInMS,floatPixelData:void 0,imageFrame:r,rgba:d&&a,getPixelData:()=>r.pixelData,getCanvas:void 0,numberOfComponents:r.samplesPerPixel};var y;if(x.color&&(x.getCanvas=function(){if(le===e)return s;const t=x.columns,n=x.rows;s.height=n,s.width=t;const a=s.getContext("2d"),o=a.createImageData(t,n),i=r.pixelData;if(i.length===t*n*4)for(let e=0;e<i.length;e++)o.data[e]=i[e];else if(i.length===t*n*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 r.pixelData=o.data,r.pixelDataLength=o.data.length,r.imageData=o,a.putImageData(r.imageData,0,0),le=e,s}),f.modalityLUTSequence&&f.modalityLUTSequence.length>0&&("1.2.840.10008.5.1.4.1.1.12.1"!==(y=m.sopClassUID)&&"1.2.840.10008.5.1.4.1.1.12.2.1"!==y)&&(x.modalityLUT=f.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)}),r)}))},{ProgressiveIterator:fe}=e,{ImageQualityStatus:de}=t,me=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 ge(e){const t="1.2.840.10008.1.2";if(!e)return t;const r=e.split(";"),n={};r.forEach((e=>{const t=e.split("=");if(2!==t.length)return;const r=t[1].trim().replace(/"/g,"");n[t[0].trim()]=r}));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 n["transfer-syntax"]?n["transfer-syntax"]:e&&!Object.keys(n).length&&a[e]?a[e]:n.type&&a[n.type]?a[n.type]:a[e]?a[e]:t}function pe(e,t=4){const r=e/100-.02;return r>1/4?Math.min(t,0):r>1/16?Math.min(t,1):r>1/64?Math.min(t,2):Math.min(t,3)}const he=function(e,t={}){const r=ct.cornerstone.imageRetrievalPoolManager,n=(new Date).getTime(),a=new fe("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 r.addRequest(async function(e,r,o){a.generate((async a=>{const i=fe.as(K(e,r,o,t));let s=10;for await(const e of i){const{pixelData:o,imageQualityStatus:i=de.FULL_RESOLUTION,percentComplete:l,done:c=!0,extractDone:u=!0}=e,f=ge(e.contentType);if(!u&&!me.has(f))continue;const d=e.decodeLevel??(i===de.FULL_RESOLUTION?0:pe(l,t.retrieveOptions?.decodeLevel));if(c||!(s<=d))try{const e={...t,decodeLevel:d},l=await ue(r,o,f,e),u=(new Date).getTime();l.loadTimeInMS=u-n,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}};const xe={metaData:{getNumberString:L,getNumberValue:v,getNumberValues:E,getValue:T,metaDataProvider:Q},findIndexOfString:h,getPixelData:K,loadImage:he,metaDataManager:N,register:function(e){e.registerImageLoader("wadors",he),e.metaData.addProvider(Q)}};function ye(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 be(e,t,r){const n=[],a=e.elements[t];for(let o=0;o<r[0];o++)16===r[2]?n[o]=e.uint16(t,o):n[o]=e.byteArray[o+a.dataOffset];return n}const Pe=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=ye(e,"x00281101"),t.greenPaletteColorLookupTableDescriptor=ye(e,"x00281102"),t.bluePaletteColorLookupTableDescriptor=ye(e,"x00281103"),0===t.redPaletteColorLookupTableDescriptor[0]&&(t.redPaletteColorLookupTableDescriptor[0]=65536,t.greenPaletteColorLookupTableDescriptor[0]=65536,t.bluePaletteColorLookupTableDescriptor[0]=65536);const r=t.redPaletteColorLookupTableDescriptor[0],n=e.elements.x00281201.length===r?8:16;t.redPaletteColorLookupTableDescriptor[2]!==n&&(t.redPaletteColorLookupTableDescriptor[2]=n,t.greenPaletteColorLookupTableDescriptor[2]=n,t.bluePaletteColorLookupTableDescriptor[2]=n),t.redPaletteColorLookupTableData=be(e,"x00281201",t.redPaletteColorLookupTableDescriptor),t.greenPaletteColorLookupTableData=be(e,"x00281202",t.greenPaletteColorLookupTableDescriptor),t.bluePaletteColorLookupTableData=be(e,"x00281203",t.bluePaletteColorLookupTableDescriptor)}(e,t),t};function we(e,t){let r=t.uint16("x00283002",0);0===r&&(r=65535);let n=0;n=0===e?t.uint16("x00283002",1):t.int16("x00283002",1);const a={id:"1",firstValueMapped:n,numBitsPerEntry:t.uint16("x00283002",2),lut:[]};for(let n=0;n<r;n++)a.lut[n]=0===e?t.uint16("x00283006",n):t.int16("x00283006",n);return a}const Se=function(e,t){if(!t||!t.items||!t.items.length)return;const r=[];for(let n=0;n<t.items.length;n++){const a=we(e,t.items[n].dataSet);a&&r.push(a)}return r};const De=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 r=e.floatString("x00281052"),n=e.floatString("x00281053");if(void 0!==r&&void 0!==n){const t=function(e){const t=e.uint16("x00280103"),r=e.uint16("x00280101");return 0===t?0:-1<<r-1}(e);return t*n+r<0?1:0}return e.elements.x00283000&&e.elements.x00283000.length>0?0:e.uint16("x00280103")};const Ie=function(e,t,r){const n=[],a=e.string(t);if(!a)return;const o=a.split("\\");if(!(r&&o.length<r)){for(let e=0;e<o.length;e++)n.push(parseFloat(o[e]));return n}};const Te=function(e){const t=e.indexOf(":");let r=e.substring(t+1);const n=r.indexOf("frame=");let a;if(-1!==n){const e=r.substring(n+6);a=parseInt(e,10),r=r.substring(0,n-1)}return{scheme:e.substring(0,t),url:r,frame:a,pixelDataFrame:void 0!==a?a-1:void 0}};function Le(e){const{dicomParser:t}=ct;let r,n=t.parseDicom(e,{untilTag:"x7fe00010"});n.elements.x7fe00010||console.warn("Pixel data not found!");try{r=t.parseDicom(e)}catch(e){console.error(e),console.log("pixel data dataset:",e.dataSet),r=e.dataSet}return n.elements.x7fe00010=r.elements.x7fe00010,n=function(e){const t=e.elements.x7fe00010.fragments,r=e.byteArray.length;for(const e of t){const{position:t,length:n}=e;n>r-t&&(console.log(`Truncated fragment, changing fragment length from ${e.length} to ${r-t}`),e.length=r-t)}return e}(n),n}async function ve(e,t,r){const n=Le(e),{uri:a,imageId:o,fileTotalLength:i}=r;return n.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),m=new Uint8Array(n.byteArray.length+d.length);return m.set(n.byteArray),m.set(d,n.byteArray.length),ve(m,t,r)},n}function Ee(e,t,r){const n={};(t?Object.values(t.items[0].dataSet.elements):[]).map((e=>n[e.tag]=e));const a={};return(e?Object.values(e.items[r-1].dataSet.elements):[]).map((e=>a[e.tag]=e)),{shared:n,perFrame:a}}function Ce(e){if(!e)return;const{elements:t,...r}=e,{x52009230:n,x52009229:a,...o}=t;return{NumberOfFrames:e.intString("x00280008"),PerFrameFunctionalGroupsSequence:n,SharedFunctionalGroupsSequence:a,otherElements:o,otherAttributtes:r}}function Ae(e){if(Fe[e])return Fe[e]}function Oe(e){if(!e)return!1;const t=e.intString("x00280008");return t&&t>1}const Me={_get:Ae,generateMultiframeWADOURIs:function(e){const t=[],r=Ae(e);if(Oe(r)){const n=r.intString("x00280008");for(let r=1;r<=n;r++)t.push(`${e}&frame=${r}`)}else t.push(e);return t},retrieveMultiframeDataset:function(e){const t=function(e){return e.indexOf("&frame=")}(e),r=-1===t?e:e.slice(0,t),n=parseInt(e.slice(t+7),10)||1;let a;return a=Fe[r]?Fe[r].dataSet:void 0,{dataSet:a,frame:n}},isMultiframeDataset:function(e){return Oe(Ae(e))}};let Re=0,Fe={},Ue={};function Be(){return{cacheSizeInBytes:Re,numberOfDataSetsCached:Object.keys(Fe).length}}const Ne={isLoaded:function(e){return void 0!==Fe[e]},load:function(e,t=f,r){const{cornerstone:n,dicomParser:a}=ct;if(Fe[e])return new Promise((t=>{Fe[e].cacheCount++,t(Fe[e].dataSet)}));if(Ue[e])return Ue[e].cacheCount++,Ue[e];const o=t(e,r),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 ve(u,t,{uri:e,imageId:r,fileTotalLength:c.fileTotalLength}):a.parseDicom(u)}catch(e){return l(e)}Fe[e]={dataSet:f,cacheCount:i.cacheCount},Re+=f.byteArray.length,s(f),n.triggerEvent(n.events,"datasetscachechanged",{uri:e,action:"loaded",cacheInfo:Be()})}),l).then((()=>{delete Ue[e]}),(()=>{delete Ue[e]}))}));return i.cacheCount=1,Ue[e]=i,i},unload:function(e){const{cornerstone:t}=ct;Fe[e]&&(Fe[e].cacheCount--,0===Fe[e].cacheCount&&(Re-=Fe[e].dataSet.byteArray.length,delete Fe[e],t.triggerEvent(t.events,"datasetscachechanged",{uri:e,action:"unloaded",cacheInfo:Be()})))},getInfo:Be,purge:function(){Fe={},Ue={},Re=0},get:function(e){let t;if(e.includes("&frame=")){const{frame:r,dataSet:n}=Me.retrieveMultiframeDataset(e);t=function(e,t){if(!t)return;const{NumberOfFrames:r,PerFrameFunctionalGroupsSequence:n,SharedFunctionalGroupsSequence:a,otherElements:o}=Ce(t);if(n||r>1){const{shared:r,perFrame:i}=Ee(n,a,e),s={elements:{...o,...r,...i}},l=Object.create(t);return Object.assign(l,s)}return t}(r,n)}else Fe[e]&&(t=Fe[e].dataSet);return t},update:function(e,t){const r=Fe[e];r?(Re-=r.dataSet.byteArray.length,r.dataSet=t,Re+=t.byteArray.length,ct.cornerstone.triggerEvent(ct.cornerstone.events,"datasetscachechanged",{uri:e,action:"updated",cacheInfo:Be()})):console.error(`No loaded dataSet for uri ${e}`)}};function ke(e,t){const r=e.string("x00080008");if(r){const e=r.split("\\");if(e.length>t)return e[t]}}function _e(e){let t=Ie(e,"x00200037",6);return!t&&e.elements.x00209116&&(t=Ie(e.elements.x00209116.items[0].dataSet,"x00200037",6)),t||(t=function(e){let t;const r=e.string("x00080060");if(r?.includes("NM")){const r=ke(e,2);r&&k(r)&&e.elements.x00540022&&(t=Ie(e.elements.x00540022.items[0].dataSet,"x00200037",6))}return t}(e)),t}function je(e){let t=Ie(e,"x00200032",3);return!t&&e.elements.x00209113&&(t=Ie(e.elements.x00209113.items[0].dataSet,"x00200032",3)),t||(t=function(e){let t;const r=e.string("x00080060");if(r?.includes("NM")){const r=ke(e,2);r&&k(r)&&e.elements.x00540022&&(t=Ie(e.elements.x00540022.items[0].dataSet,"x00200032",3))}return t}(e)),t}function Ve(e){let t=Ie(e,"x00280030",2);return!t&&e.elements.x00289110&&(t=Ie(e.elements.x00289110.items[0].dataSet,"x00280030",2)),t}function $e(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 Ge(e){const t=e.elements.x00186011;if(!t||!t.items)return[];return t.items.map((e=>{const t=e.dataSet.double("x0018602c"),r=e.dataSet.double("x0018602e"),n=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:r,physicalUnitsXDirection:n,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 qe=function e(t,r){const{MetadataModules:n}=ct.cornerstone.Enums,{dicomParser:a}=ct;if(Array.isArray(r))return;const o=Te(r);if(t===n.MULTIFRAME){const e=Me.retrieveMultiframeDataset(o.url);if(!e.dataSet)return;const t=function(e,t){if(!e)return;const{NumberOfFrames:r,PerFrameFunctionalGroupsSequence:n,SharedFunctionalGroupsSequence:a}=Ce(e);if(n||r>1){const{shared:e,perFrame:o}=Ee(n,a,t);return{NumberOfFrames:r,PerFrameFunctionalInformation:o,SharedFunctionalInformation:e}}return{NumberOfFrames:r}}(e.dataSet,e.frame);return t}let i=o.url;o.frame&&(i=`${i}&frame=${o.frame}`);const s=Ne.get(i);if(s){if(t===n.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===n.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===n.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===n.PATIENT)return{patientID:s.string("x00100020"),patientName:s.string("x00100010")};if(t===n.PATIENT_STUDY)return{patientAge:s.intString("x00101010"),patientSize:s.floatString("x00101020"),patientSex:s.string("x00100040"),patientWeight:s.floatString("x00101030")};if(t===n.NM_MULTIFRAME_GEOMETRY){const e=s.string("x00080060"),t=ke(s,2);return{modality:e,imageType:s.string("x00080008"),imageSubType:t,imageOrientationPatient:_e(s),imagePositionPatient:je(s),sliceThickness:$e(s),pixelSpacing:Ve(s),numberOfFrames:s.uint16("x00280008"),isNMReconstructable:k(t)&&e.includes("NM")}}if(t===n.IMAGE_PLANE){const e=_e(s),t=je(s),r=Ve(s),n=$e(s);let a=null,o=null;r&&(o=r[0],a=r[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:n,sliceLocation:s.floatString("x00201041"),pixelSpacing:r,rowPixelSpacing:o,columnPixelSpacing:a}}if(t===n.CINE)return{frameTime:s.floatString("x00181063")};if(t===n.IMAGE_PIXEL)return Pe(s);if(t===n.VOI_LUT){const e=De(s);return{windowCenter:Ie(s,"x00281050",1),windowWidth:Ie(s,"x00281051",1),voiLUTSequence:Se(e,s.elements.x00283010)}}if(t===n.MODALITY_LUT)return{rescaleIntercept:s.floatString("x00281052"),rescaleSlope:s.floatString("x00281053"),rescaleType:s.string("x00281054"),modalityLUTSequence:Se(s.uint16("x00280103"),s.elements.x00283000)};if(t===n.SOP_COMMON)return{sopClassUID:s.string("x00080016"),sopInstanceUID:s.string("x00080018")};if(t===n.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===n.OVERLAY_PLANE)return function(e){const t=[];for(let r=0;r<=30;r+=2){let n=`x60${r.toString(16)}`;4===n.length&&(n=`x600${r.toString(16)}`);const a=e.elements[`${n}3000`];if(!a)continue;const o=[];for(let t=0;t<a.length;t++)for(let r=0;r<8;r++){const n=e.byteArray[a.dataOffset+t];o[8*t+r]=n>>r&1}t.push({rows:e.uint16(`${n}0010`),columns:e.uint16(`${n}0011`),type:e.string(`${n}0040`),x:e.int16(`${n}0050`,1)-1,y:e.int16(`${n}0050`,0)-1,pixelData:o,description:e.string(`${n}0022`),label:e.string(`${n}1500`),roiArea:e.string(`${n}1301`),roiMean:e.string(`${n}1302`),roiStandardDeviation:e.string(`${n}1303`)})}return{overlays:t}}(s);if("transferSyntax"===t){let e;try{e=s.string("x00020010")}catch(e){}return{transferSyntaxUID:e}}if(t===n.PET_SERIES)return{correctedImage:s.string("x00280051"),units:s.string("x00541001"),decayCorrection:s.string("x00541102")};if(t===n.PET_IMAGE)return{frameReferenceTime:s.floatString(s.string("x00541300")||""),actualFrameDuration:s.intString(s.string("x00181242"))};if(t===n.ULTRASOUND_ENHANCED_REGION)return Ge(s);if(t===n.CALIBRATION){if("US"===s.string("x00080060")){return{sequenceOfUltrasoundRegions:Ge(s)}}}return"instance"===t?G(r,e,Y):void 0}};let Ye=[];const We={add:function(e){return"dicomfile:"+(Ye.push(e)-1)},get:function(e){return Ye[e]},remove:function(e){Ye[e]=void 0},purge:function(){Ye=[]}};var Xe=n(713);function ze(e,t){const{dicomParser:r}=ct;if(e.elements.x7fe00010&&e.elements.x7fe00010.basicOffsetTable.length)return r.readEncapsulatedImageFrame(e,e.elements.x7fe00010,t);if(function(e){return e.intString("x00280008")!==e.elements.x7fe00010.fragments.length}(e)){const n=r.createJPEGBasicOffsetTable(e,e.elements.x7fe00010);return r.readEncapsulatedImageFrame(e,e.elements.x7fe00010,t,n)}const n=e.elements.x7fe00010.fragments,a=new Xe.ByteStream(e.byteArrayParser,e.byteArray,e.elements.x7fe00010.dataOffset),o=(0,Xe.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>n.length)throw"dicomParser.readEncapsulatedPixelData: frame exceeds number of fragments";const s=i+n[t].offset+8,l=n[t].length;return new Uint8Array(a.byteArray.buffer.slice(a.byteArray.byteOffset+s,a.byteArray.byteOffset+s+l))}function He(e,t){return e&1<<t}const Qe=function(e,t,r){const n=new Uint8Array(r);for(let a=0;a<r;a++){const r=e[Math.floor(a/8)+t],o=a%8;n[a]=He(r,o)?1:0}return n};const Je=function(e,t){const r=e.elements.x7fe00010||e.elements.x7fe00008,n=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=r.dataOffset,l=a*o*i;let c;if(8===n){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===n){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===n){if(c=s+t*l*.125,c>=e.byteArray.length)throw new Error("frame exceeds size of pixelData");return Qe(e.byteArray,c,l)}if(32===n){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 Ke=function(e){const t=Te(e),r=parseInt(t.url,10),n=We.get(r);return new Promise(((e,t)=>{const r=new FileReader;r.onload=t=>{const r=t.target.result;e(r)},r.onerror=t,r.readAsArrayBuffer(n)}))};const Ze=function(e,t=0){const r=e.elements.x7fe00010||e.elements.x7fe00008;return r?r.encapsulatedPixelData?ze(e,t):Je(e,t):null};function et(e,t,r=0,n,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=Ze(e,r),f=e.string("x00020010"),d=(new Date).getTime(),m=ue(t,u,f,a);!function(e,t){e.decache=function(){const e=Te(t);Ne.unload(e.url)}}(s,t),m.then((t=>{t.data=e,t.sharedCacheKey=n;const r=(new Date).getTime();t.loadTimeInMS=d-i,t.totalTimeInMS=r-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 tt(e){return"dicomweb"===e||"wadouri"===e?f:"dicomfile"===e?Ke:void 0}function rt(e,t={}){const r=Te(e);delete(t=Object.assign({},t)).loader;const n=tt(r.scheme);if(Ne.isLoaded(r.url)){return function(e,t,r=0,n,a){const o=(new Date).getTime();return{promise:new Promise(((i,s)=>{const l=(new Date).getTime();let c;try{const n=Ze(e,r),o=e.string("x00020010");c=ue(t,n,o,a)}catch(t){return void s({error:t,dataSet:e})}c.then((t=>{t.data=e,t.sharedCacheKey=n;const r=(new Date).getTime();t.loadTimeInMS=l-o,t.totalTimeInMS=r-o,i(t)}),s)})),cancelFn:void 0}}(Ne.get(r.url,n,e),e,r.pixelDataFrame,r.url,t)}return et(Ne.load(r.url,n,e),e,r.frame,r.url,t)}const nt={metaData:{getImagePixelModule:Pe,getLUTs:Se,getModalityLUTOutputPixelRepresentation:De,getNumberValues:Ie,metaDataProvider:qe},dataSetCacheManager:Ne,fileManager:We,getEncapsulatedImageFrame:ze,getUncompressedImageFrame:Je,loadFileRequest:Ke,loadImageFromPromise:et,getLoaderForScheme:tt,loadImage:rt,parseImageId:Te,unpackBinaryFrame:Qe,register:function(e){e.registerImageLoader("dicomweb",rt),e.registerImageLoader("wadouri",rt),e.registerImageLoader("dicomfile",rt),e.metaData.addProvider(qe)}};const at=function(e){xe.register(e),nt.register(e)};let ot,it;const st=()=>new Worker(new URL(n.p+n.u(920),n.b),{type:void 0}),lt={set cornerstone(e){ot=e,at(ot);const t=u();lt.cornerstone.getWebWorkerManager().registerWorker("dicomImageLoader",st,{maxWorkerInstances:t.maxWebWorkers||1})},get cornerstone(){if(!ot){if(ot=window&&window.cornerstone,!ot)throw new Error("cornerstoneDICOMImageLoader requires a copy of Cornerstone to work properly. Please add cornerstoneDICOMImageLoader.external.cornerstone = cornerstone; to your application.");at(ot)}return ot},set dicomParser(e){it=e},get dicomParser(){if(!it){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.");it=window.dicomParser}return it}},ct=lt;function ut(e,t){const r=e.length,n=new Uint8ClampedArray(r);for(let a=0;a<r;++a)n[a]=e[a]>>t;return n}function ft(e,t,r){const n=e[`${t}PaletteColorLookupTableData`];if(n)return Promise.resolve(n);const a=ct.cornerstone.metaData.get("imagePixelModule",e.imageId);return a&&"function"==typeof a.then?a.then((e=>e?e[`${t}PaletteColorLookupTableData`]:r)):Promise.resolve(a?a[`${t}PaletteColorLookupTableData`]:r)}function dt(e,t,r){const n=e.columns*e.rows,a=e.pixelData;Promise.all([ft(e,"red",null),ft(e,"green",null),ft(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,m=ut(o,d),g=ut(i,d),p=ut(s,d);if(r)for(let e=0;e<n;++e){let e=a[c++];e<f?e=0:e>f+l-1?e=l-1:e-=f,t[u++]=m[e],t[u++]=g[e],t[u++]=p[e],t[u++]=255}else for(let e=0;e<n;++e){let e=a[c++];e<f?e=0:e>f+l-1?e=l-1:e-=f,t[u++]=m[e],t[u++]=g[e],t[u++]=p[e]}}))}const mt=function(e){if(!e.cornerstone||!e.dicomParser)throw new Error('cornerstoneWADOImageLoader.configure: Options object must contain the keys "cornerstone" and "dicomParser".');c(e),ct.cornerstone=e.cornerstone,ct.dicomParser=e.dicomParser};const gt=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},pt={convertRGBColorByPixel:r,convertRGBColorByPlane:o,convertYBRFullByPixel:i,convertYBRFullByPlane:s,convertPALETTECOLOR:dt,wadouri:nt,wadors:xe,configure:mt,convertColorSpace:te,createImage:ue,decodeJPEGBaseline8BitColor:ne,getImageFrame:ie,getPixelData:K,getMinMax:Z,isColorImage:se,isJPEGBaseline8BitColor:gt,internal:I,external:lt}})(),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:()=>j,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 j={xhrRequest:E,streamRequest:k,setOptions:f,getOptions:d};function V(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=V(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 je(e){const t=e.indexOf(":");return e.substring(t+1)}function Ve(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=Ve(t,!1),n=Ve(n,!1),r=Ve(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}}(je(e))}function Xe(e){const t=Be(e["00280008"]);return t&&t>1}const ze={add:function(e,t){const n=je(e);Object.defineProperty(t,"isMultiframe",{value:Xe(t),enumerable:!1}),qe[n]=t},get:function(e){const t=je(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=je(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=Ve(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=Ve(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=Ve(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){const e=Je(o),t=Ke(o),n=_e(o["00280030"],2);let r=null,a=null;n&&(a=n[0],r=n[1]);let i=null,s=null;return e&&(i=[parseFloat(e[0]),parseFloat(e[1]),parseFloat(e[2])],s=[parseFloat(e[3]),parseFloat(e[4]),parseFloat(e[5])]),{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}}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:j,external:p}})(),a})()));
2
2
  //# sourceMappingURL=cornerstoneDICOMImageLoader.bundle.min.js.map