UNPKG

dicomweb-proxy

Version:

A proxy to translate between dicomweb and dimse

2 lines 14.8 kB
"use strict";(self.webpackChunk=self.webpackChunk||[]).push([[732],{10732:(t,e,r)=>{r.r(e),r.d(e,{ComponentSpec:()=>i,DataStream:()=>a,Decoder:()=>w,FrameHeader:()=>o,HuffmanTable:()=>l,QuantizationTable:()=>f,ScanComponent:()=>d,ScanHeader:()=>p,Utils:()=>h});var s=Object.defineProperty,i={hSamp:0,quantTableSel:0,vSamp:0},a=class{buffer;index;constructor(t,e,r){this.buffer=new Uint8Array(t,e,r),this.index=0}get16(){const t=(this.buffer[this.index]<<8)+this.buffer[this.index+1];return this.index+=2,t}get8(){const t=this.buffer[this.index];return this.index+=1,t}},o=class{dimX=0;dimY=0;numComp=0;precision=0;components=[];read(t){let e,r=0;const s=t.get16();r+=2,this.precision=t.get8(),r+=1,this.dimY=t.get16(),r+=2,this.dimX=t.get16(),r+=2,this.numComp=t.get8(),r+=1;for(let a=1;a<=this.numComp;a+=1){if(r>s)throw new Error("ERROR: frame format error");const a=t.get8();if(r+=1,r>=s)throw new Error("ERROR: frame format error [c>=Lf]");e=t.get8(),r+=1,this.components[a]||(this.components[a]={...i}),this.components[a].hSamp=e>>4,this.components[a].vSamp=15&e,this.components[a].quantTableSel=t.get8(),r+=1}if(r!==s)throw new Error("ERROR: frame format error [Lf!=count]");return 1}},h={};((t,e)=>{for(var r in e)s(t,r,{get:e[r],enumerable:!0})})(h,{crc32:()=>m,crcTable:()=>u,createArray:()=>n,makeCRCTable:()=>c});var n=(...t)=>{if(t.length>1){const e=t[0],r=t.slice(1),s=[];for(let t=0;t<e;t++)s[t]=n(...r);return s}return Array(t[0]).fill(void 0)},c=function(){let t;const e=[];for(let r=0;r<256;r++){t=r;for(let e=0;e<8;e++)t=1&t?3988292384^t>>>1:t>>>1;e[r]=t}return e},u=c(),m=function(t){const e=new Uint8Array(t);let r=~0;for(let t=0;t<e.length;t++)r=r>>>8^u[255&(r^e[t])];return~r>>>0},l=class t{static MSB=2147483648;l;th;v;tc;constructor(){this.l=n(4,2,16),this.th=[0,0,0,0],this.v=n(4,2,16,200),this.tc=[[0,0],[0,0],[0,0],[0,0]]}read(t,e){let r,s,i,a,o,h=0;const n=t.get16();for(h+=2;h<n;){if(r=t.get8(),h+=1,s=15&r,s>3)throw new Error("ERROR: Huffman table ID > 3");if(i=r>>4,i>2)throw new Error("ERROR: Huffman table [Table class > 2 ]");for(this.th[s]=1,this.tc[s][i]=1,a=0;a<16;a+=1)this.l[s][i][a]=t.get8(),h+=1;for(a=0;a<16;a+=1)for(o=0;o<this.l[s][i][a];o+=1){if(h>n)throw new Error("ERROR: Huffman table format error [count>Lh]");this.v[s][i][a][o]=t.get8(),h+=1}}if(h!==n)throw new Error("ERROR: Huffman table format error [count!=Lf]");for(a=0;a<4;a+=1)for(o=0;o<2;o+=1)0!==this.tc[a][o]&&this.buildHuffTable(e[a][o],this.l[a][o],this.v[a][o]);return 1}buildHuffTable(e,r,s){let i,a,o,h,n;for(a=0,o=0;o<8;o+=1)for(h=0;h<r[o];h+=1)for(n=0;n<256>>o+1;n+=1)e[a]=s[o][h]|o+1<<8,a+=1;for(o=1;a<256;o+=1,a+=1)e[a]=o|t.MSB;for(i=1,a=0,o=8;o<16;o+=1)for(h=0;h<r[o];h+=1){for(n=0;n<256>>o-7;n+=1)e[256*i+a]=s[o][h]|o+1<<8,a+=1;if(a>=256){if(a>256)throw new Error("ERROR: Huffman table error(1)!");a=0,i+=1}}}},f=class t{precision=[];tq=[0,0,0,0];quantTables=n(4,64);static enhanceQuantizationTable=function(t,e){for(let r=0;r<8;r+=1)t[e[0+r]]*=90,t[e[32+r]]*=90,t[e[16+r]]*=118,t[e[48+r]]*=49,t[e[40+r]]*=71,t[e[8+r]]*=126,t[e[56+r]]*=25,t[e[24+r]]*=106;for(let r=0;r<8;r+=1)t[e[0+8*r]]*=90,t[e[4+8*r]]*=90,t[e[2+8*r]]*=118,t[e[6+8*r]]*=49,t[e[5+8*r]]*=71,t[e[1+8*r]]*=126,t[e[7+8*r]]*=25,t[e[3+8*r]]*=106;for(let e=0;e<64;e+=1)t[e]>>=6};read(e,r){let s,i,a,o=0;const h=e.get16();for(o+=2;o<h;){if(s=e.get8(),o+=1,i=15&s,i>3)throw new Error("ERROR: Quantization table ID > 3");if(this.precision[i]=s>>4,0===this.precision[i])this.precision[i]=8;else{if(1!==this.precision[i])throw new Error("ERROR: Quantization table precision error");this.precision[i]=16}if(this.tq[i]=1,8===this.precision[i]){for(a=0;a<64;a+=1){if(o>h)throw new Error("ERROR: Quantization table format error");this.quantTables[i][a]=e.get8(),o+=1}t.enhanceQuantizationTable(this.quantTables[i],r)}else{for(a=0;a<64;a+=1){if(o>h)throw new Error("ERROR: Quantization table format error");this.quantTables[i][a]=e.get16(),o+=2}t.enhanceQuantizationTable(this.quantTables[i],r)}}if(o!==h)throw new Error("ERROR: Quantization table error [count!=Lq]");return 1}},d={acTabSel:0,dcTabSel:0,scanCompSel:0},p=class{ah=0;al=0;numComp=0;selection=0;spectralEnd=0;components=[];read(t){let e,r,s=0;const i=t.get16();for(s+=2,this.numComp=t.get8(),s+=1,e=0;e<this.numComp;e+=1){if(this.components[e]={...d},s>i)throw new Error("ERROR: scan header format error");this.components[e].scanCompSel=t.get8(),s+=1,r=t.get8(),s+=1,this.components[e].dcTabSel=r>>4,this.components[e].acTabSel=15&r}if(this.selection=t.get8(),s+=1,this.spectralEnd=t.get8(),s+=1,r=t.get8(),this.ah=r>>4,this.al=15&r,s+=1,s!==i)throw new Error("ERROR: scan header format error [count!=Ns]");return 1}},g=function(){const t=new ArrayBuffer(2);return new DataView(t).setInt16(0,256,!0),256===new Int16Array(t)[0]}(),w=class t{static IDCT_P=[0,5,40,16,45,2,7,42,21,56,8,61,18,47,1,4,41,23,58,13,32,24,37,10,63,17,44,3,6,43,20,57,15,34,29,48,53,26,39,9,60,19,46,22,59,12,33,31,50,55,25,36,11,62,14,35,28,49,52,27,38,30,51,54];static TABLE=[0,1,5,6,14,15,27,28,2,4,7,13,16,26,29,42,3,8,12,17,25,30,41,43,9,11,18,24,31,40,44,53,10,19,23,32,39,45,52,54,20,22,33,38,46,51,55,60,21,34,37,47,50,56,59,61,35,36,48,49,57,58,62,63];static MAX_HUFFMAN_SUBTREE=50;static MSB=2147483648;static RESTART_MARKER_BEGIN=65488;static RESTART_MARKER_END=65495;buffer=null;stream=null;frame=new o;huffTable=new l;quantTable=new f;scan=new p;DU=n(10,4,64);HuffTab=n(4,2,12800);IDCT_Source=[];nBlock=[];acTab=n(10,1);dcTab=n(10,1);qTab=n(10,1);marker=0;markerIndex=0;numComp=0;restartInterval=0;selection=0;xDim=0;yDim=0;xLoc=0;yLoc=0;outputData=null;restarting=!1;mask=0;numBytes=0;precision=void 0;components=[];getter=null;setter=null;output=null;selector=null;constructor(t,e){this.buffer=t??null,this.numBytes=e??0}decompress(t,e,r){return this.decode(t,e,r).buffer}decode(e,r,s,i){let o=0;const h=[];let n,c;const u=[],m=[];let l;e&&(this.buffer=e),void 0!==i&&(this.numBytes=i),this.stream=new a(this.buffer,r,s),this.buffer=null,this.xLoc=0,this.yLoc=0;let f=this.stream.get16();if(65496!==f)throw new Error("Not a JPEG file");for(f=this.stream.get16();f>>4!=4092||65476===f;){switch(f){case 65476:this.huffTable.read(this.stream,this.HuffTab);break;case 65484:throw new Error("Program doesn't support arithmetic coding. (format throw new IOException)");case 65499:this.quantTable.read(this.stream,t.TABLE);break;case 65501:this.restartInterval=this.readNumber()??0;break;case 65504:case 65505:case 65506:case 65507:case 65508:case 65509:case 65510:case 65511:case 65512:case 65513:case 65514:case 65515:case 65516:case 65517:case 65518:case 65519:this.readApp();break;case 65534:this.readComment();break;default:if(f>>8!=255)throw new Error("ERROR: format throw new IOException! (decode)")}f=this.stream.get16()}if(f<65472||f>65479)throw new Error("ERROR: could not handle arithmetic code!");this.frame.read(this.stream),f=this.stream.get16();do{for(;65498!==f;){switch(f){case 65476:this.huffTable.read(this.stream,this.HuffTab);break;case 65484:throw new Error("Program doesn't support arithmetic coding. (format throw new IOException)");case 65499:this.quantTable.read(this.stream,t.TABLE);break;case 65501:this.restartInterval=this.readNumber()??0;break;case 65504:case 65505:case 65506:case 65507:case 65508:case 65509:case 65510:case 65511:case 65512:case 65513:case 65514:case 65515:case 65516:case 65517:case 65518:case 65519:this.readApp();break;case 65534:this.readComment();break;default:if(f>>8!=255)throw new Error("ERROR: format throw new IOException! (Parser.decode)")}f=this.stream.get16()}switch(this.precision=this.frame.precision,this.components=this.frame.components,this.numBytes||(this.numBytes=Math.round(Math.ceil(this.precision/8))),1===this.numBytes?this.mask=255:this.mask=65535,this.scan.read(this.stream),this.numComp=this.scan.numComp,this.selection=this.scan.selection,1===this.numBytes&&3===this.numComp?(this.getter=this.getValueRGB,this.setter=this.setValueRGB,this.output=this.outputRGB):(this.getter=this.getValue8,this.setter=this.setValue8,this.output=this.outputSingle),this.selection){case 2:this.selector=this.select2;break;case 3:this.selector=this.select3;break;case 4:this.selector=this.select4;break;case 5:this.selector=this.select5;break;case 6:this.selector=this.select6;break;case 7:this.selector=this.select7;break;default:this.selector=this.select1}for(n=0;n<this.numComp;n+=1)c=this.scan.components[n].scanCompSel,this.qTab[n]=this.quantTable.quantTables[this.components[c].quantTableSel],this.nBlock[n]=this.components[c].vSamp*this.components[c].hSamp,this.dcTab[n]=this.HuffTab[this.scan.components[n].dcTabSel][0],this.acTab[n]=this.HuffTab[this.scan.components[n].acTabSel][1];for(this.xDim=this.frame.dimX,this.yDim=this.frame.dimY,1===this.numBytes?this.outputData=new Uint8Array(new ArrayBuffer(this.xDim*this.yDim*this.numBytes*this.numComp)):this.outputData=new Uint16Array(new ArrayBuffer(this.xDim*this.yDim*this.numBytes*this.numComp)),o+=1;;){for(u[0]=0,m[0]=0,n=0;n<10;n+=1)h[n]=1<<this.precision-1;if(0===this.restartInterval){for(f=this.decodeUnit(h,u,m);0===f&&this.xLoc<this.xDim&&this.yLoc<this.yDim;)this.output(h),f=this.decodeUnit(h,u,m);break}for(l=0;l<this.restartInterval&&(this.restarting=0===l,f=this.decodeUnit(h,u,m),this.output(h),0===f);l+=1);if(0===f&&(0!==this.markerIndex?(f=65280|this.marker,this.markerIndex=0):f=this.stream.get16()),!(f>=t.RESTART_MARKER_BEGIN&&f<=t.RESTART_MARKER_END))break}65500===f&&1===o&&(this.readNumber(),f=this.stream.get16())}while(65497!==f&&this.xLoc<this.xDim&&this.yLoc<this.yDim&&0===o);return this.outputData}decodeUnit(t,e,r){return 1===this.numComp?this.decodeSingle(t,e,r):3===this.numComp?this.decodeRGB(t,e,r):-1}select1(t){return this.getPreviousX(t)}select2(t){return this.getPreviousY(t)}select3(t){return this.getPreviousXY(t)}select4(t){return this.getPreviousX(t)+this.getPreviousY(t)-this.getPreviousXY(t)}select5(t){return this.getPreviousX(t)+(this.getPreviousY(t)-this.getPreviousXY(t)>>1)}select6(t){return this.getPreviousY(t)+(this.getPreviousX(t)-this.getPreviousXY(t)>>1)}select7(t){return(this.getPreviousX(t)+this.getPreviousY(t))/2}decodeRGB(e,r,s){if(null===this.selector)throw new Error("decode hasn't run yet");let i,a,o,h,n,c,u;for(e[0]=this.selector(0),e[1]=this.selector(1),e[2]=this.selector(2),h=0;h<this.numComp;h+=1)for(o=this.qTab[h],i=this.acTab[h],a=this.dcTab[h],n=0;n<this.nBlock[h];n+=1){for(c=0;c<this.IDCT_Source.length;c+=1)this.IDCT_Source[c]=0;let n=this.getHuffmanValue(a,r,s);if(n>=65280)return n;for(e[h]=this.IDCT_Source[0]=e[h]+this.getn(s,n,r,s),this.IDCT_Source[0]*=o[0],u=1;u<64;u+=1){if(n=this.getHuffmanValue(i,r,s),n>=65280)return n;if(u+=n>>4,15&n)this.IDCT_Source[t.IDCT_P[u]]=this.getn(s,15&n,r,s)*o[u];else if(!(n>>4))break}}return 0}decodeSingle(e,r,s){if(null===this.selector)throw new Error("decode hasn't run yet");let i,a,o,h;for(this.restarting?(this.restarting=!1,e[0]=1<<this.frame.precision-1):e[0]=this.selector(),a=0;a<this.nBlock[0];a+=1){if(i=this.getHuffmanValue(this.dcTab[0],r,s),i>=65280)return i;if(o=this.getn(e,i,r,s),h=o>>8,h>=t.RESTART_MARKER_BEGIN&&h<=t.RESTART_MARKER_END)return h;e[0]+=o}return 0}getHuffmanValue(e,r,s){let i,a;if(!this.stream)throw new Error("stream not initialized");if(s[0]<8?(r[0]<<=8,a=this.stream.get8(),255===a&&(this.marker=this.stream.get8(),0!==this.marker&&(this.markerIndex=9)),r[0]|=a):s[0]-=8,i=e[r[0]>>s[0]],i&t.MSB){if(0!==this.markerIndex)return this.markerIndex=0,65280|this.marker;r[0]&=65535>>16-s[0],r[0]<<=8,a=this.stream.get8(),255===a&&(this.marker=this.stream.get8(),0!==this.marker&&(this.markerIndex=9)),r[0]|=a,i=e[256*(255&i)+(r[0]>>s[0])],s[0]+=8}if(s[0]+=8-(i>>8),s[0]<0)throw new Error("index="+s[0]+" temp="+r[0]+" code="+i+" in HuffmanValue()");return s[0]<this.markerIndex?(this.markerIndex=0,65280|this.marker):(r[0]&=65535>>16-s[0],255&i)}getn(t,e,r,s){let i,a;if(null===this.stream)throw new Error("stream not initialized");if(0===e)return 0;if(16===e)return t[0]>=0?-32768:32768;if(s[0]-=e,s[0]>=0){if(s[0]<this.markerIndex&&!this.isLastPixel())return this.markerIndex=0,(65280|this.marker)<<8;i=r[0]>>s[0],r[0]&=65535>>16-s[0]}else{if(r[0]<<=8,a=this.stream.get8(),255===a&&(this.marker=this.stream.get8(),0!==this.marker&&(this.markerIndex=9)),r[0]|=a,s[0]+=8,s[0]<0){if(0!==this.markerIndex)return this.markerIndex=0,(65280|this.marker)<<8;r[0]<<=8,a=this.stream.get8(),255===a&&(this.marker=this.stream.get8(),0!==this.marker&&(this.markerIndex=9)),r[0]|=a,s[0]+=8}if(s[0]<0)throw new Error("index="+s[0]+" in getn()");if(s[0]<this.markerIndex)return this.markerIndex=0,(65280|this.marker)<<8;i=r[0]>>s[0],r[0]&=65535>>16-s[0]}return i<1<<e-1&&(i+=1+(-1<<e)),i}getPreviousX(t=0){if(null===this.getter)throw new Error("decode hasn't run yet");return this.xLoc>0?this.getter(this.yLoc*this.xDim+this.xLoc-1,t):this.yLoc>0?this.getPreviousY(t):1<<this.frame.precision-1}getPreviousXY(t=0){if(null===this.getter)throw new Error("decode hasn't run yet");return this.xLoc>0&&this.yLoc>0?this.getter((this.yLoc-1)*this.xDim+this.xLoc-1,t):this.getPreviousY(t)}getPreviousY(t=0){if(null===this.getter)throw new Error("decode hasn't run yet");return this.yLoc>0?this.getter((this.yLoc-1)*this.xDim+this.xLoc,t):this.getPreviousX(t)}isLastPixel(){return this.xLoc===this.xDim-1&&this.yLoc===this.yDim-1}outputSingle(t){if(null===this.setter)throw new Error("decode hasn't run yet");this.xLoc<this.xDim&&this.yLoc<this.yDim&&(this.setter(this.yLoc*this.xDim+this.xLoc,this.mask&t[0]),this.xLoc+=1,this.xLoc>=this.xDim&&(this.yLoc+=1,this.xLoc=0))}outputRGB(t){if(null===this.setter)throw new Error("decode hasn't run yet");const e=this.yLoc*this.xDim+this.xLoc;this.xLoc<this.xDim&&this.yLoc<this.yDim&&(this.setter(e,t[0],0),this.setter(e,t[1],1),this.setter(e,t[2],2),this.xLoc+=1,this.xLoc>=this.xDim&&(this.yLoc+=1,this.xLoc=0))}setValue8(t,e){if(!this.outputData)throw new Error("output data not ready");this.outputData[t]=g?e:(255&e)<<8|e>>8&255}getValue8(t){if(null===this.outputData)throw new Error("output data not ready");if(g)return this.outputData[t];{const e=this.outputData[t];return(255&e)<<8|e>>8&255}}setValueRGB(t,e,r=0){null!==this.outputData&&(this.outputData[3*t+r]=e)}getValueRGB(t,e){if(null===this.outputData)throw new Error("output data not ready");return this.outputData[3*t+e]}readApp(){if(null===this.stream)return null;let t=0;const e=this.stream.get16();for(t+=2;t<e;)this.stream.get8(),t+=1;return e}readComment(){if(null===this.stream)return null;let t="",e=0;const r=this.stream.get16();for(e+=2;e<r;)t+=this.stream.get8(),e+=1;return t}readNumber(){if(null===this.stream)return null;if(4!==this.stream.get16())throw new Error("ERROR: Define number format throw new IOException [Ld!=4]");return this.stream.get16()}}}}]); //# sourceMappingURL=732.bundle.56968fbdf8b5bc6cfe3b.js.map