dwv
Version:
DICOM Web Viewer.
2 lines • 36.6 kB
JavaScript
var t,e=function(){var t=[{qe:22017,nmps:1,nlps:1,switchFlag:1},{qe:13313,nmps:2,nlps:6,switchFlag:0},{qe:6145,nmps:3,nlps:9,switchFlag:0},{qe:2753,nmps:4,nlps:12,switchFlag:0},{qe:1313,nmps:5,nlps:29,switchFlag:0},{qe:545,nmps:38,nlps:33,switchFlag:0},{qe:22017,nmps:7,nlps:6,switchFlag:1},{qe:21505,nmps:8,nlps:14,switchFlag:0},{qe:18433,nmps:9,nlps:14,switchFlag:0},{qe:14337,nmps:10,nlps:14,switchFlag:0},{qe:12289,nmps:11,nlps:17,switchFlag:0},{qe:9217,nmps:12,nlps:18,switchFlag:0},{qe:7169,nmps:13,nlps:20,switchFlag:0},{qe:5633,nmps:29,nlps:21,switchFlag:0},{qe:22017,nmps:15,nlps:14,switchFlag:1},{qe:21505,nmps:16,nlps:14,switchFlag:0},{qe:20737,nmps:17,nlps:15,switchFlag:0},{qe:18433,nmps:18,nlps:16,switchFlag:0},{qe:14337,nmps:19,nlps:17,switchFlag:0},{qe:13313,nmps:20,nlps:18,switchFlag:0},{qe:12289,nmps:21,nlps:19,switchFlag:0},{qe:10241,nmps:22,nlps:19,switchFlag:0},{qe:9217,nmps:23,nlps:20,switchFlag:0},{qe:8705,nmps:24,nlps:21,switchFlag:0},{qe:7169,nmps:25,nlps:22,switchFlag:0},{qe:6145,nmps:26,nlps:23,switchFlag:0},{qe:5633,nmps:27,nlps:24,switchFlag:0},{qe:5121,nmps:28,nlps:25,switchFlag:0},{qe:4609,nmps:29,nlps:26,switchFlag:0},{qe:4353,nmps:30,nlps:27,switchFlag:0},{qe:2753,nmps:31,nlps:28,switchFlag:0},{qe:2497,nmps:32,nlps:29,switchFlag:0},{qe:2209,nmps:33,nlps:30,switchFlag:0},{qe:1313,nmps:34,nlps:31,switchFlag:0},{qe:1089,nmps:35,nlps:32,switchFlag:0},{qe:673,nmps:36,nlps:33,switchFlag:0},{qe:545,nmps:37,nlps:34,switchFlag:0},{qe:321,nmps:38,nlps:35,switchFlag:0},{qe:273,nmps:39,nlps:36,switchFlag:0},{qe:133,nmps:40,nlps:37,switchFlag:0},{qe:73,nmps:41,nlps:38,switchFlag:0},{qe:37,nmps:42,nlps:39,switchFlag:0},{qe:21,nmps:43,nlps:40,switchFlag:0},{qe:9,nmps:44,nlps:41,switchFlag:0},{qe:5,nmps:45,nlps:42,switchFlag:0},{qe:1,nmps:45,nlps:43,switchFlag:0},{qe:22017,nmps:46,nlps:46,switchFlag:0}];function e(t,e,r){this.data=t,this.bp=e,this.dataEnd=r,this.chigh=t[e],this.clow=0,this.byteIn(),this.chigh=this.chigh<<7&65535|this.clow>>9&127,this.clow=this.clow<<7&65535,this.ct-=7,this.a=32768}return e.prototype={byteIn:function(){var t=this.data,e=this.bp;255===t[e]?t[e+1]>143?(this.clow+=65280,this.ct=8):(e++,this.clow+=t[e]<<9,this.ct=7,this.bp=e):(e++,this.clow+=e<this.dataEnd?t[e]<<8:65280,this.ct=8,this.bp=e),this.clow>65535&&(this.chigh+=this.clow>>16,this.clow&=65535)},readBit:function(e,r){var n,i=e[r]>>1,s=1&e[r],a=t[i],o=a.qe,c=this.a-o;if(this.chigh<o)c<o?(c=o,n=s,i=a.nmps):(c=o,n=1^s,1===a.switchFlag&&(s=n),i=a.nlps);else{if(this.chigh-=o,32768&c)return this.a=c,s;c<o?(n=1^s,1===a.switchFlag&&(s=n),i=a.nlps):(n=s,i=a.nmps)}do{0===this.ct&&this.byteIn(),c<<=1,this.chigh=this.chigh<<1&65535|this.clow>>15&1,this.clow=this.clow<<1&65535,this.ct--}while(!(32768&c));return this.a=c,e[r]=i<<1|s,n}},e}(),r={pdfBug:!1,VERBOSITY_LEVELS:{errors:0,warnings:1,infos:5}};function n(t){r.verbosity>=r.VERBOSITY_LEVELS.warnings&&console.log("Warning: "+t)}function i(t,e,r){return Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!1}),r}r.OPS={dependency:1,setLineWidth:2,setLineCap:3,setLineJoin:4,setMiterLimit:5,setDash:6,setRenderingIntent:7,setFlatness:8,setGState:9,save:10,restore:11,transform:12,moveTo:13,lineTo:14,curveTo:15,curveTo2:16,curveTo3:17,closePath:18,rectangle:19,stroke:20,closeStroke:21,fill:22,eoFill:23,fillStroke:24,eoFillStroke:25,closeFillStroke:26,closeEOFillStroke:27,endPath:28,clip:29,eoClip:30,beginText:31,endText:32,setCharSpacing:33,setWordSpacing:34,setHScale:35,setLeading:36,setFont:37,setTextRenderingMode:38,setTextRise:39,moveText:40,setLeadingMoveText:41,setTextMatrix:42,nextLine:43,showText:44,showSpacedText:45,nextLineShowText:46,nextLineSetSpacingShowText:47,setCharWidth:48,setCharWidthAndBounds:49,setStrokeColorSpace:50,setFillColorSpace:51,setStrokeColor:52,setStrokeColorN:53,setFillColor:54,setFillColorN:55,setStrokeGray:56,setFillGray:57,setStrokeRGBColor:58,setFillRGBColor:59,setStrokeCMYKColor:60,setFillCMYKColor:61,shadingFill:62,beginInlineImage:63,beginImageData:64,endInlineImage:65,paintXObject:66,markPoint:67,markPointProps:68,beginMarkedContent:69,beginMarkedContentProps:70,endMarkedContent:71,beginCompat:72,endCompat:73,paintFormXObjectBegin:74,paintFormXObjectEnd:75,beginGroup:76,endGroup:77,beginAnnotations:78,endAnnotations:79,beginAnnotation:80,endAnnotation:81,paintJpegXObject:82,paintImageMaskXObject:83,paintImageMaskXObjectGroup:84,paintImageXObject:85,paintInlineImageXObject:86,paintInlineImageXObjectGroup:87,paintImageXObjectRepeat:88,paintImageMaskXObjectRepeat:89,paintSolidColorImageMask:90,constructPath:91},r.UNSUPPORTED_FEATURES={unknown:"unknown",forms:"forms",javaScript:"javaScript",smask:"smask",shadingPattern:"shadingPattern",font:"font"},r.UnsupportedManager=(t=[],{listen:function(e){t.push(e)},notify:function(e){n('Unsupported feature "'+e+'"');for(var r=0,i=t.length;r<i;r++)t[r](e)}}),r.isValidUrl=function(t,e){if(!t)return!1;var r=/^[a-z][a-z0-9+\-.]*(?=:)/i.exec(t);if(!r)return e;switch(r=r[0].toLowerCase()){case"http":case"https":case"ftp":case"mailto":case"tel":return!0;default:return!1}},r.shadow=i,r.PasswordResponses={NEED_PASSWORD:1,INCORRECT_PASSWORD:2};var s=function(){function t(t,e){this.name="PasswordException",this.message=t,this.code=e}return t.prototype=new Error,t.constructor=t,t}();r.PasswordException=s;var a=function(){function t(t,e){this.name="UnknownErrorException",this.message=t,this.details=e}return t.prototype=new Error,t.constructor=t,t}();r.UnknownErrorException=a;var o=function(){function t(t){this.name="InvalidPDFException",this.message=t}return t.prototype=new Error,t.constructor=t,t}();r.InvalidPDFException=o;var c=function(){function t(t){this.name="MissingPDFException",this.message=t}return t.prototype=new Error,t.constructor=t,t}();r.MissingPDFException=c;var l=function(){function t(t,e){this.name="UnexpectedResponseException",this.message=t,this.status=e}return t.prototype=new Error,t.constructor=t,t}();function h(t){for(var e=1,r=0;t>e;)e<<=1,r++;return r}function p(t,e){return t[e]<<8|t[e+1]}function u(t,e){return(t[e]<<24|t[e+1]<<16|t[e+2]<<8|t[e+3])>>>0}r.UnexpectedResponseException=l,function(){function t(t){this.message=t}t.prototype=new Error,t.prototype.name="NotImplementedException",t.constructor=t}(),function(){function t(t,e){this.begin=t,this.end=e,this.message="Missing data ["+t+", "+e+")"}t.prototype=new Error,t.prototype.name="MissingDataException",t.constructor=t}(),function(){function t(t){this.message=t}t.prototype=new Error,t.prototype.name="XRefParseException",t.constructor=t}(),Object.defineProperty(r,"isLittleEndian",{configurable:!0,get:function(){return i(r,"isLittleEndian",((t=new Uint8Array(2))[0]=1,1===new Uint16Array(t.buffer)[0]));var t}}),Object.defineProperty(r,"hasCanvasTypedArrays",{configurable:!0,get:function(){return i(r,"hasCanvasTypedArrays",((t=document.createElement("canvas")).width=t.height=1,void 0!==t.getContext("2d").createImageData(1,1).data.buffer));var t}}),Object.create(null);var f,d=r.Util=function(){function t(){}var e=["rgb(",0,",",0,",",0,")"];return t.makeCssRgb=function(t,r,n){return e[1]=t,e[3]=r,e[5]=n,e.join("")},t.transform=function(t,e){return[t[0]*e[0]+t[2]*e[1],t[1]*e[0]+t[3]*e[1],t[0]*e[2]+t[2]*e[3],t[1]*e[2]+t[3]*e[3],t[0]*e[4]+t[2]*e[5]+t[4],t[1]*e[4]+t[3]*e[5]+t[5]]},t.applyTransform=function(t,e){return[t[0]*e[0]+t[1]*e[2]+e[4],t[0]*e[1]+t[1]*e[3]+e[5]]},t.applyInverseTransform=function(t,e){var r=e[0]*e[3]-e[1]*e[2];return[(t[0]*e[3]-t[1]*e[2]+e[2]*e[5]-e[4]*e[3])/r,(-t[0]*e[1]+t[1]*e[0]+e[4]*e[1]-e[5]*e[0])/r]},t.getAxialAlignedBoundingBox=function(e,r){var n=t.applyTransform(e,r),i=t.applyTransform(e.slice(2,4),r),s=t.applyTransform([e[0],e[3]],r),a=t.applyTransform([e[2],e[1]],r);return[Math.min(n[0],i[0],s[0],a[0]),Math.min(n[1],i[1],s[1],a[1]),Math.max(n[0],i[0],s[0],a[0]),Math.max(n[1],i[1],s[1],a[1])]},t.inverseTransform=function(t){var e=t[0]*t[3]-t[1]*t[2];return[t[3]/e,-t[1]/e,-t[2]/e,t[0]/e,(t[2]*t[5]-t[4]*t[3])/e,(t[4]*t[1]-t[5]*t[0])/e]},t.apply3dTransform=function(t,e){return[t[0]*e[0]+t[1]*e[1]+t[2]*e[2],t[3]*e[0]+t[4]*e[1]+t[5]*e[2],t[6]*e[0]+t[7]*e[1]+t[8]*e[2]]},t.singularValueDecompose2dScale=function(t){var e=[t[0],t[2],t[1],t[3]],r=t[0]*e[0]+t[1]*e[2],n=t[0]*e[1]+t[1]*e[3],i=t[2]*e[0]+t[3]*e[2],s=t[2]*e[1]+t[3]*e[3],a=(r+s)/2,o=Math.sqrt((r+s)*(r+s)-4*(r*s-i*n))/2,c=a+o||1,l=a-o||1;return[Math.sqrt(c),Math.sqrt(l)]},t.normalizeRect=function(t){var e=t.slice(0);return t[0]>t[2]&&(e[0]=t[2],e[2]=t[0]),t[1]>t[3]&&(e[1]=t[3],e[3]=t[1]),e},t.intersect=function(e,r){function n(t,e){return t-e}var i=[e[0],e[2],r[0],r[2]].sort(n),s=[e[1],e[3],r[1],r[3]].sort(n),a=[];return e=t.normalizeRect(e),r=t.normalizeRect(r),(i[0]===e[0]&&i[1]===r[0]||i[0]===r[0]&&i[1]===e[0])&&(a[0]=i[1],a[2]=i[2],(s[0]===e[1]&&s[1]===r[1]||s[0]===r[1]&&s[1]===e[1])&&(a[1]=s[1],a[3]=s[2],a))},t.sign=function(t){return t<0?-1:1},t.appendToArray=function(t,e){Array.prototype.push.apply(t,e)},t.prependToArray=function(t,e){Array.prototype.unshift.apply(t,e)},t.extendObj=function(t,e){for(var r in e)t[r]=e[r]},t.getInheritableProperty=function(t,e){for(;t&&!t.has(e);)t=t.get("Parent");return t?t.get(e):null},t.inherit=function(t,e,r){for(var n in t.prototype=Object.create(e.prototype),t.prototype.constructor=t,r)t.prototype[n]=r[n]},t.loadScript=function(t,e){var r=document.createElement("script"),n=!1;r.setAttribute("src",t),e&&(r.onload=function(){n||e(),n=!0}),document.getElementsByTagName("head")[0].appendChild(r)},t}();r.PageViewport=function(){function t(t,e,r,n,i,s){this.viewBox=t,this.scale=e,this.rotation=r,this.offsetX=n,this.offsetY=i;var a,o,c,l,h,p,u,f,d=(t[2]+t[0])/2,m=(t[3]+t[1])/2;switch(r=(r%=360)<0?r+360:r){case 180:a=-1,o=0,c=0,l=1;break;case 90:a=0,o=1,c=1,l=0;break;case 270:a=0,o=-1,c=-1,l=0;break;default:a=1,o=0,c=0,l=-1}s&&(c=-c,l=-l),0===a?(h=Math.abs(m-t[1])*e+n,p=Math.abs(d-t[0])*e+i,u=Math.abs(t[3]-t[1])*e,f=Math.abs(t[2]-t[0])*e):(h=Math.abs(d-t[0])*e+n,p=Math.abs(m-t[1])*e+i,u=Math.abs(t[2]-t[0])*e,f=Math.abs(t[3]-t[1])*e),this.transform=[a*e,o*e,c*e,l*e,h-a*e*d-c*e*m,p-o*e*d-l*e*m],this.width=u,this.height=f,this.fontScale=e}return t.prototype={clone:function(e){var r="scale"in(e=e||{})?e.scale:this.scale,n="rotation"in e?e.rotation:this.rotation;return new t(this.viewBox.slice(),r,n,this.offsetX,this.offsetY,e.dontFlip)},convertToViewportPoint:function(t,e){return d.applyTransform([t,e],this.transform)},convertToViewportRectangle:function(t){var e=d.applyTransform([t[0],t[1]],this.transform),r=d.applyTransform([t[2],t[3]],this.transform);return[e[0],e[1],r[0],r[1]]},convertToPdfPoint:function(t,e){return d.applyInverseTransform([t,e],this.transform)}},t}(),r.createPromiseCapability=function(){var t={};return t.promise=new Promise((function(e,r){t.resolve=e,t.reject=r})),t},r.createBlob=function(t,e){if("undefined"!=typeof Blob)return new Blob([t],{type:e});var r=new MozBlobBuilder;return r.append(t),r.getBlob(e)},r.createObjectURL=(f="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",function(t,e){if(!r.disableCreateObjectURL&&"undefined"!=typeof URL&&URL.createObjectURL){var n=r.createBlob(t,e);return URL.createObjectURL(n)}for(var i="data:"+e+";base64,",s=0,a=t.length;s<a;s+=3){var o=255&t[s],c=255&t[s+1],l=255&t[s+2];i+=f[o>>2]+f[(3&o)<<4|c>>4]+f[s+1<a?(15&c)<<2|l>>6:64]+f[s+2<a?63&l:64]}return i});var m=function(){var t={LL:0,LH:1,HL:1,HH:2};function i(){this.failOnCorruptedImage=!0}function s(t,e){t.x0=Math.ceil(e.XOsiz/t.XRsiz),t.x1=Math.ceil(e.Xsiz/t.XRsiz),t.y0=Math.ceil(e.YOsiz/t.YRsiz),t.y1=Math.ceil(e.Ysiz/t.YRsiz),t.width=t.x1-t.x0,t.height=t.y1-t.y0}function a(t,e){for(var r,n=t.SIZ,i=[],s=Math.ceil((n.Xsiz-n.XTOsiz)/n.XTsiz),a=Math.ceil((n.Ysiz-n.YTOsiz)/n.YTsiz),o=0;o<a;o++)for(var c=0;c<s;c++)(r={}).tx0=Math.max(n.XTOsiz+c*n.XTsiz,n.XOsiz),r.ty0=Math.max(n.YTOsiz+o*n.YTsiz,n.YOsiz),r.tx1=Math.min(n.XTOsiz+(c+1)*n.XTsiz,n.Xsiz),r.ty1=Math.min(n.YTOsiz+(o+1)*n.YTsiz,n.Ysiz),r.width=r.tx1-r.tx0,r.height=r.ty1-r.ty0,r.components=[],i.push(r);t.tiles=i;for(var l=0,h=n.Csiz;l<h;l++)for(var p=e[l],u=0,f=i.length;u<f;u++){var d={};r=i[u],d.tcx0=Math.ceil(r.tx0/p.XRsiz),d.tcy0=Math.ceil(r.ty0/p.YRsiz),d.tcx1=Math.ceil(r.tx1/p.XRsiz),d.tcy1=Math.ceil(r.ty1/p.YRsiz),d.width=d.tcx1-d.tcx0,d.height=d.tcy1-d.tcy0,r.components[l]=d}}function o(t,e,r){var n=e.codingStyleParameters,i={};return n.entropyCoderWithCustomPrecincts?(i.PPx=n.precinctsSizes[r].PPx,i.PPy=n.precinctsSizes[r].PPy):(i.PPx=15,i.PPy=15),i.xcb_=r>0?Math.min(n.xcb,i.PPx-1):Math.min(n.xcb,i.PPx),i.ycb_=r>0?Math.min(n.ycb,i.PPy-1):Math.min(n.ycb,i.PPy),i}function c(t,e,r){var n=1<<r.PPx,i=1<<r.PPy,s=0===e.resLevel,a=1<<r.PPx+(s?0:-1),o=1<<r.PPy+(s?0:-1),c=e.trx1>e.trx0?Math.ceil(e.trx1/n)-Math.floor(e.trx0/n):0,l=e.try1>e.try0?Math.ceil(e.try1/i)-Math.floor(e.try0/i):0,h=c*l;e.precinctParameters={precinctWidth:n,precinctHeight:i,numprecinctswide:c,numprecinctshigh:l,numprecincts:h,precinctWidthInSubband:a,precinctHeightInSubband:o}}function l(t,e,r){var n,i,s,a,o=r.xcb_,c=r.ycb_,l=1<<o,h=1<<c,p=e.tbx0>>o,u=e.tby0>>c,f=e.tbx1+l-1>>o,d=e.tby1+h-1>>c,m=e.resolution.precinctParameters,g=[],v=[];for(i=u;i<d;i++)for(n=p;n<f;n++)if((s={cbx:n,cby:i,tbx0:l*n,tby0:h*i,tbx1:l*(n+1),tby1:h*(i+1)}).tbx0_=Math.max(e.tbx0,s.tbx0),s.tby0_=Math.max(e.tby0,s.tby0),s.tbx1_=Math.min(e.tbx1,s.tbx1),s.tby1_=Math.min(e.tby1,s.tby1),a=Math.floor((s.tbx0_-e.tbx0)/m.precinctWidthInSubband)+Math.floor((s.tby0_-e.tby0)/m.precinctHeightInSubband)*m.numprecinctswide,s.precinctNumber=a,s.subbandType=e.type,s.Lblock=3,!(s.tbx1_<=s.tbx0_||s.tby1_<=s.tby0_)){g.push(s);var b=v[a];void 0!==b?(n<b.cbxMin?b.cbxMin=n:n>b.cbxMax&&(b.cbxMax=n),i<b.cbyMin?b.cbxMin=i:i>b.cbyMax&&(b.cbyMax=i)):v[a]=b={cbxMin:n,cbyMin:i,cbxMax:n,cbyMax:i},s.precinct=b}e.codeblockParameters={codeblockWidth:o,codeblockHeight:c,numcodeblockwide:f-p+1,numcodeblockhigh:d-u+1},e.codeblocks=g,e.precincts=v}function f(t,e,r){for(var n=[],i=t.subbands,s=0,a=i.length;s<a;s++)for(var o=i[s].codeblocks,c=0,l=o.length;c<l;c++){var h=o[c];h.precinctNumber===e&&n.push(h)}return{layerNumber:r,codeblocks:n}}function d(t){for(var e=t.SIZ,r=t.currentTile.index,n=t.tiles[r],i=n.codingStyleDefaultParameters.layersCount,s=e.Csiz,a=0,o=0;o<s;o++)a=Math.max(a,n.components[o].codingStyleParameters.decompositionLevelsCount);var c=0,l=0,h=0,p=0;this.nextPacket=function(){for(;c<i;c++){for(;l<=a;l++){for(;h<s;h++){var t=n.components[h];if(!(l>t.codingStyleParameters.decompositionLevelsCount)){for(var e=t.resolutions[l],r=e.precinctParameters.numprecincts;p<r;){var o=f(e,p,c);return p++,o}p=0}}h=0}l=0}}}function m(t){for(var e=t.SIZ,r=t.currentTile.index,n=t.tiles[r],i=n.codingStyleDefaultParameters.layersCount,s=e.Csiz,a=0,o=0;o<s;o++)a=Math.max(a,n.components[o].codingStyleParameters.decompositionLevelsCount);var c=0,l=0,h=0,p=0;this.nextPacket=function(){for(;c<=a;c++){for(;l<i;l++){for(;h<s;h++){var t=n.components[h];if(!(c>t.codingStyleParameters.decompositionLevelsCount)){for(var e=t.resolutions[c],r=e.precinctParameters.numprecincts;p<r;){var o=f(e,p,l);return p++,o}p=0}}h=0}l=0}}}function g(t){var e,r,n,i,s=t.SIZ,a=t.currentTile.index,o=t.tiles[a],c=o.codingStyleDefaultParameters.layersCount,l=s.Csiz,h=0;for(n=0;n<l;n++){var p=o.components[n];h=Math.max(h,p.codingStyleParameters.decompositionLevelsCount)}var u=new Int32Array(h+1);for(r=0;r<=h;++r){var d=0;for(n=0;n<l;++n){var m=o.components[n].resolutions;r<m.length&&(d=Math.max(d,m[r].precinctParameters.numprecincts))}u[r]=d}e=0,r=0,n=0,i=0,this.nextPacket=function(){for(;r<=h;r++){for(;i<u[r];i++){for(;n<l;n++){var t=o.components[n];if(!(r>t.codingStyleParameters.decompositionLevelsCount)){var s=t.resolutions[r],a=s.precinctParameters.numprecincts;if(!(i>=a)){for(;e<c;){var p=f(s,i,e);return e++,p}e=0}}}n=0}i=0}}}function v(t){var e=t.SIZ,r=t.currentTile.index,n=t.tiles[r],i=n.codingStyleDefaultParameters.layersCount,s=e.Csiz,a=x(n),o=a,c=0,l=0,h=0,p=0,u=0;this.nextPacket=function(){for(;u<o.maxNumHigh;u++){for(;p<o.maxNumWide;p++){for(;h<s;h++){for(var t=n.components[h],e=t.codingStyleParameters.decompositionLevelsCount;l<=e;l++){var r=t.resolutions[l],d=a.components[h].resolutions[l],m=y(p,u,d,o,r);if(null!==m){for(;c<i;){var g=f(r,m,c);return c++,g}c=0}}l=0}h=0}p=0}}}function b(t){var e=t.SIZ,r=t.currentTile.index,n=t.tiles[r],i=n.codingStyleDefaultParameters.layersCount,s=e.Csiz,a=x(n),o=0,c=0,l=0,h=0,p=0;this.nextPacket=function(){for(;l<s;++l){for(var t=n.components[l],e=a.components[l],r=t.codingStyleParameters.decompositionLevelsCount;p<e.maxNumHigh;p++){for(;h<e.maxNumWide;h++){for(;c<=r;c++){var u=t.resolutions[c],d=e.resolutions[c],m=y(h,p,d,e,u);if(null!==m){for(;o<i;){var g=f(u,m,o);return o++,g}o=0}}c=0}h=0}p=0}}}function y(t,e,r,n,i){var s=t*n.minWidth,a=e*n.minHeight;if(s%r.width!=0||a%r.height!=0)return null;var o=a/r.width*i.precinctParameters.numprecinctswide;return s/r.height+o}function x(t){for(var e=t.components.length,r=Number.MAX_VALUE,n=Number.MAX_VALUE,i=0,s=0,a=new Array(e),o=0;o<e;o++){for(var c=t.components[o],l=c.codingStyleParameters.decompositionLevelsCount,h=new Array(l+1),p=Number.MAX_VALUE,u=Number.MAX_VALUE,f=0,d=0,m=1,g=l;g>=0;--g){var v=c.resolutions[g],b=m*v.precinctParameters.precinctWidth,y=m*v.precinctParameters.precinctHeight;p=Math.min(p,b),u=Math.min(u,y),f=Math.max(f,v.precinctParameters.numprecinctswide),d=Math.max(d,v.precinctParameters.numprecinctshigh),h[g]={width:b,height:y},m<<=1}r=Math.min(r,p),n=Math.min(n,u),i=Math.max(i,f),s=Math.max(s,d),a[o]={resolutions:h,minWidth:p,minHeight:u,maxNumWide:f,maxNumHigh:d}}return{components:a,minWidth:r,minHeight:n,maxNumWide:i,maxNumHigh:s}}function w(t){for(var e=t.SIZ,r=t.currentTile.index,n=t.tiles[r],i=e.Csiz,s=0;s<i;s++){for(var a=n.components[s],h=a.codingStyleParameters.decompositionLevelsCount,p=[],u=[],f=0;f<=h;f++){var y,x=o(0,a,f),w={},P=1<<h-f;if(w.trx0=Math.ceil(a.tcx0/P),w.try0=Math.ceil(a.tcy0/P),w.trx1=Math.ceil(a.tcx1/P),w.try1=Math.ceil(a.tcy1/P),w.resLevel=f,c(0,w,x),p.push(w),0===f)(y={}).type="LL",y.tbx0=Math.ceil(a.tcx0/P),y.tby0=Math.ceil(a.tcy0/P),y.tbx1=Math.ceil(a.tcx1/P),y.tby1=Math.ceil(a.tcy1/P),y.resolution=w,l(0,y,x),u.push(y),w.subbands=[y];else{var M=1<<h-f+1,C=[];(y={}).type="HL",y.tbx0=Math.ceil(a.tcx0/M-.5),y.tby0=Math.ceil(a.tcy0/M),y.tbx1=Math.ceil(a.tcx1/M-.5),y.tby1=Math.ceil(a.tcy1/M),y.resolution=w,l(0,y,x),u.push(y),C.push(y),(y={}).type="LH",y.tbx0=Math.ceil(a.tcx0/M),y.tby0=Math.ceil(a.tcy0/M-.5),y.tbx1=Math.ceil(a.tcx1/M),y.tby1=Math.ceil(a.tcy1/M-.5),y.resolution=w,l(0,y,x),u.push(y),C.push(y),(y={}).type="HH",y.tbx0=Math.ceil(a.tcx0/M-.5),y.tby0=Math.ceil(a.tcy0/M-.5),y.tbx1=Math.ceil(a.tcx1/M-.5),y.tby1=Math.ceil(a.tcy1/M-.5),y.resolution=w,l(0,y,x),u.push(y),C.push(y),w.subbands=C}}a.resolutions=p,a.subbands=u}var S=n.codingStyleDefaultParameters.progressionOrder;switch(S){case 0:n.packetsIterator=new d(t);break;case 1:n.packetsIterator=new m(t);break;case 2:n.packetsIterator=new g(t);break;case 3:n.packetsIterator=new v(t);break;case 4:n.packetsIterator=new b(t);break;default:throw new Error("JPX Error: Unsupported progression order "+S)}}function P(t,e,r,n){var i,s=0,a=0,o=!1;function c(t){for(;a<t;){var n=e[r+s];s++,o?(i=i<<7|n,a+=7,o=!1):(i=i<<8|n,a+=8),255===n&&(o=!0)}return i>>>(a-=t)&(1<<t)-1}function l(t){return 255===e[r+s-1]&&e[r+s]===t?(p(1),!0):255===e[r+s]&&e[r+s+1]===t&&(p(2),!0)}function p(t){s+=t}function u(){a=0,o&&(s++,o=!1)}function f(){if(0===c(1))return 1;if(0===c(1))return 2;var t=c(2);return t<3?t+3:(t=c(5))<31?t+6:(t=c(7))+37}for(var d=t.currentTile.index,m=t.tiles[d],g=t.COD.sopMarkerUsed,v=t.COD.ephMarkerUsed,b=m.packetsIterator;s<n;){u(),g&&l(145)&&p(4);var y=b.nextPacket();if(void 0===y)return;if(c(1)){for(var x,w=y.layerNumber,P=[],M=0,C=y.codeblocks.length;M<C;M++){var S=(x=y.codeblocks[M]).precinct,I=x.cbx-S.cbxMin,E=x.cby-S.cbyMin,L=!1,F=!1;if(void 0!==x.included)L=!!c(1);else{var z,O;if(void 0!==(S=x.precinct).inclusionTree)z=S.inclusionTree;else{var A=S.cbxMax-S.cbxMin+1,q=S.cbyMax-S.cbyMin+1;z=new T(A,q,w),O=new k(A,q),S.inclusionTree=z,S.zeroBitPlanesTree=O;for(var X=0;X<w;X++)if(0!==c(1))throw new Error("JPX Error: Invalid tag tree")}if(z.reset(I,E,w))for(;;){if(!c(1)){z.incrementValue(w);break}if(!z.nextLevel()){x.included=!0,L=F=!0;break}}}if(L){if(F){for((O=S.zeroBitPlanesTree).reset(I,E);;)if(c(1)){if(!O.nextLevel())break}else O.incrementValue();x.zeroBitPlanes=O.value}for(var B=f();c(1);)x.Lblock++;var U=h(B),R=c((B<1<<U?U-1:U)+x.Lblock);P.push({codeblock:x,codingpasses:B,dataLength:R})}}for(u(),v&&l(146);P.length>0;){var D=P.shift();void 0===(x=D.codeblock).data&&(x.data=[]),x.data.push({data:e,start:r+s,end:r+s+D.dataLength,codingpasses:D.codingpasses}),s+=D.dataLength}}}return s}function M(t,r,n,i,s,a,o,c){for(var l=i.tbx0,h=i.tby0,p=i.tbx1-i.tbx0,u=i.codeblocks,f="H"===i.type.charAt(0)?1:0,d="H"===i.type.charAt(1)?r:0,m=0,g=u.length;m<g;++m){var v=u[m],b=v.tbx1_-v.tbx0_,y=v.tby1_-v.tby0_;if(0!==b&&0!==y&&void 0!==v.data){var x,w;x=new I(b,y,v.subbandType,v.zeroBitPlanes,a),w=2;var P,M,C,S=v.data,k=0,T=0;for(P=0,M=S.length;P<M;P++)k+=(C=S[P]).end-C.start,T+=C.codingpasses;var E=new Int16Array(k),L=0;for(P=0,M=S.length;P<M;P++){var F=(C=S[P]).data.subarray(C.start,C.end);E.set(F,L),L+=F.length}var z=new e(E,0,k);for(x.setDecoder(z),P=0;P<T;P++){switch(w){case 0:x.runSignificancePropogationPass();break;case 1:x.runMagnitudeRefinementPass();break;case 2:x.runCleanupPass(),c&&x.checkSegmentationSymbol()}w=(w+1)%3}var O,A,q,X=v.tbx0_-l+(v.tby0_-h)*p,B=x.coefficentsSign,U=x.coefficentsMagnitude,R=x.bitsDecoded,D=o?0:.5;L=0;var H="LL"!==i.type;for(P=0;P<y;P++){var Y=2*(X/p|0)*(r-p)+f+d;for(O=0;O<b;O++){if(0!==(A=U[L]))A=(A+D)*s,0!==B[L]&&(A=-A),q=R[L],t[H?Y+(X<<1):X]=o&&q>=a?A:A*(1<<a-q);X++,L++}X+=p-b}}}}function C(e,r,n){for(var i=r.components[n],s=i.codingStyleParameters,a=i.quantizationParameters,o=s.decompositionLevelsCount,c=a.SPqcds,l=a.scalarExpounded,h=a.guardBits,p=s.segmentationSymbolUsed,u=e.components[n].precision,f=s.reversibleTransformation,d=f?new F:new L,m=[],g=0,v=0;v<=o;v++){for(var b=i.resolutions[v],y=b.trx1-b.trx0,x=b.try1-b.try0,w=new Float32Array(y*x),P=0,C=b.subbands.length;P<C;P++){var S,k;l?(S=c[g].mu,k=c[g].epsilon,g++):(S=c[0].mu,k=c[0].epsilon+(v>0?1-v:0));var T=b.subbands[P],I=t[T.type];M(w,y,0,T,f?1:Math.pow(2,u+I-k)*(1+S/2048),h+k-1,f,p)}m.push({width:y,height:x,items:w})}var E=d.calculate(m,i.tcx0,i.tcy0);return{left:i.tcx0,top:i.tcy0,width:E.width,height:E.height,items:E.items}}function S(t,e){for(var r=t.SIZ.Csiz,n=t.tiles[e],i=0;i<r;i++){var s=n.components[i],a=void 0!==t.currentTile.QCC[i]?t.currentTile.QCC[i]:t.currentTile.QCD;s.quantizationParameters=a;var o=void 0!==t.currentTile.COC[i]?t.currentTile.COC[i]:t.currentTile.COD;s.codingStyleParameters=o}n.codingStyleDefaultParameters=t.currentTile.COD}i.prototype={parse:function(t){if(65359!==p(t,0))for(var e=0,i=t.length;e<i;){var s=8,a=u(t,e),o=u(t,e+4);if(e+=s,1===a&&(a=4294967296*u(t,e)+u(t,e+4),e+=8,s+=8),0===a&&(a=i-e+s),a<s)throw new Error("JPX Error: Invalid box field size");var c=a-s,l=!0;switch(o){case 1785737832:l=!1;break;case 1668246642:var h=t[e];if(t[e+1],t[e+2],1===h){var f=u(t,e+3);switch(f){case 16:case 17:case 18:break;default:n("Unknown colorspace "+f)}}else 2===h&&(r.verbosity>=r.VERBOSITY_LEVELS.infos&&console.log("Info: ICC profile not supported"));break;case 1785737827:this.parseCodestream(t,e,e+c);break;case 1783636e3:218793738!==u(t,e)&&n("Invalid JP2 signature");break;case 1783634458:case 1718909296:case 1920099697:case 1919251232:case 1768449138:break;default:n("Unsupported header type "+o+" ("+String.fromCharCode(o>>24&255,o>>16&255,o>>8&255,255&o)+")")}l&&(e+=c)}else this.parseCodestream(t,0,t.length)},parseImageProperties:function(t){for(var e=t.getByte();e>=0;)if(65361==(e<<8|(e=t.getByte()))){t.skip(4);var r=t.getInt32()>>>0,n=t.getInt32()>>>0,i=t.getInt32()>>>0,s=t.getInt32()>>>0;t.skip(16);var a=t.getUint16();return this.width=r-i,this.height=n-s,this.componentsCount=a,void(this.bitsPerComponent=8)}throw new Error("JPX Error: No size marker found in JPX stream")},parseCodestream:function(t,e,r){var i={};try{for(var o=!1,c=e;c+1<r;){var l=p(t,c);c+=2;var h,f,d,m,g,v,b=0;switch(l){case 65359:i.mainHeader=!0;break;case 65497:break;case 65361:b=p(t,c);var y={};y.Xsiz=u(t,c+4),y.Ysiz=u(t,c+8),y.XOsiz=u(t,c+12),y.YOsiz=u(t,c+16),y.XTsiz=u(t,c+20),y.YTsiz=u(t,c+24),y.XTOsiz=u(t,c+28),y.YTOsiz=u(t,c+32);var x=p(t,c+36);y.Csiz=x;var M=[];h=c+38;for(var k=0;k<x;k++){var T={precision:1+(127&t[h]),isSigned:!!(128&t[h]),XRsiz:t[h+1],YRsiz:t[h+1]};s(T,y),M.push(T)}i.SIZ=y,i.components=M,a(i,M),i.QCC=[],i.COC=[];break;case 65372:b=p(t,c);var I={};switch(h=c+2,31&(f=t[h++])){case 0:m=8,g=!0;break;case 1:m=16,g=!1;break;case 2:m=16,g=!0;break;default:throw new Error("JPX Error: Invalid SQcd value "+f)}for(I.noQuantization=8===m,I.scalarExpounded=g,I.guardBits=f>>5,d=[];h<b+c;){var E={};8===m?(E.epsilon=t[h++]>>3,E.mu=0):(E.epsilon=t[h]>>3,E.mu=(7&t[h])<<8|t[h+1],h+=2),d.push(E)}I.SPqcds=d,i.mainHeader?i.QCD=I:(i.currentTile.QCD=I,i.currentTile.QCC=[]);break;case 65373:b=p(t,c);var L,F={};switch(h=c+2,i.SIZ.Csiz<257?L=t[h++]:(L=p(t,h),h+=2),31&(f=t[h++])){case 0:m=8,g=!0;break;case 1:m=16,g=!1;break;case 2:m=16,g=!0;break;default:throw new Error("JPX Error: Invalid SQcd value "+f)}for(F.noQuantization=8===m,F.scalarExpounded=g,F.guardBits=f>>5,d=[];h<b+c;)E={},8===m?(E.epsilon=t[h++]>>3,E.mu=0):(E.epsilon=t[h]>>3,E.mu=(7&t[h])<<8|t[h+1],h+=2),d.push(E);F.SPqcds=d,i.mainHeader?i.QCC[L]=F:i.currentTile.QCC[L]=F;break;case 65362:b=p(t,c);var z={};h=c+2;var O=t[h++];z.entropyCoderWithCustomPrecincts=!!(1&O),z.sopMarkerUsed=!!(2&O),z.ephMarkerUsed=!!(4&O),z.progressionOrder=t[h++],z.layersCount=p(t,h),h+=2,z.multipleComponentTransform=t[h++],z.decompositionLevelsCount=t[h++],z.xcb=2+(15&t[h++]),z.ycb=2+(15&t[h++]);var A=t[h++];if(z.selectiveArithmeticCodingBypass=!!(1&A),z.resetContextProbabilities=!!(2&A),z.terminationOnEachCodingPass=!!(4&A),z.verticalyStripe=!!(8&A),z.predictableTermination=!!(16&A),z.segmentationSymbolUsed=!!(32&A),z.reversibleTransformation=t[h++],z.entropyCoderWithCustomPrecincts){for(var q=[];h<b+c;){var X=t[h++];q.push({PPx:15&X,PPy:X>>4})}z.precinctsSizes=q}var B=[];if(z.selectiveArithmeticCodingBypass&&B.push("selectiveArithmeticCodingBypass"),z.resetContextProbabilities&&B.push("resetContextProbabilities"),z.terminationOnEachCodingPass&&B.push("terminationOnEachCodingPass"),z.verticalyStripe&&B.push("verticalyStripe"),z.predictableTermination&&B.push("predictableTermination"),B.length>0)throw o=!0,new Error("JPX Error: Unsupported COD options ("+B.join(", ")+")");i.mainHeader?i.COD=z:(i.currentTile.COD=z,i.currentTile.COC=[]);break;case 65424:b=p(t,c),(v={}).index=p(t,c+2),v.length=u(t,c+4),v.dataEnd=v.length+c-2,v.partIndex=t[c+8],v.partsCount=t[c+9],i.mainHeader=!1,0===v.partIndex&&(v.COD=i.COD,v.COC=i.COC.slice(0),v.QCD=i.QCD,v.QCC=i.QCC.slice(0)),i.currentTile=v;break;case 65427:0===(v=i.currentTile).partIndex&&(S(i,v.index),w(i)),P(i,t,c,b=v.dataEnd-c);break;case 65365:case 65367:case 65368:case 65380:case 65363:b=p(t,c);break;default:throw new Error("JPX Error: Unknown codestream code: "+l.toString(16))}c+=b}}catch(t){if(o||this.failOnCorruptedImage)throw t;n("Trying to recover from "+t.message)}this.tiles=function(t){for(var e=t.SIZ,r=t.components,n=e.Csiz,i=[],s=0,a=t.tiles.length;s<a;s++){var o,c=t.tiles[s],l=[];for(o=0;o<n;o++)l[o]=C(t,c,o);var h,p,u,f,d,m,g,v,b,y,x,w,P,M,S,k=l[0],T=new Int16Array(k.items.length*n),I={left:k.left,top:k.top,width:k.width,height:k.height,items:T},E=0;if(c.codingStyleDefaultParameters.multipleComponentTransform){var L=4===n,F=l[0].items,z=l[1].items,O=l[2].items,A=L?l[3].items:null;p=.5+(128<<(h=r[0].precision-8)),f=-(d=.5*(u=255*(1<<h)));var q=c.components[0],X=n-3;if(g=F.length,q.codingStyleParameters.reversibleTransformation)for(m=0;m<g;m++,E+=X)v=F[m]+p,b=z[m],x=(w=v-((y=O[m])+b>>2))+y,P=w+b,T[E++]=x<=0?0:x>=u?255:x>>h,T[E++]=w<=0?0:w>=u?255:w>>h,T[E++]=P<=0?0:P>=u?255:P>>h;else for(m=0;m<g;m++,E+=X)v=F[m]+p,b=z[m],x=v+1.402*(y=O[m]),w=v-.34413*b-.71414*y,P=v+1.772*b,T[E++]=x<=0?0:x>=u?255:x>>h,T[E++]=w<=0?0:w>=u?255:w>>h,T[E++]=P<=0?0:P>=u?255:P>>h;if(L)for(m=0,E=3;m<g;m++,E+=4)M=A[m],T[E]=M<=f?0:M>=d?255:M+p>>h}else for(o=0;o<n;o++)if(8===r[o].precision){var B=l[o].items;for(p=.5+(128<<(h=r[o].precision-8)),f=-(u=127.5*(1<<h)),E=o,m=0,g=B.length;m<g;m++)S=B[m],T[E]=S<=f?0:S>=u?255:S+p>>h,E+=n}else{var U=r[o].isSigned;for(B=l[o].items,U?(h=0,p=0):p=.5+(128<<(h=r[o].precision-8)),E=o,m=0,g=B.length;m<g;m++)S=B[m],T[E]=S+p,E+=n}i.push(I)}return i}(i),this.width=i.SIZ.Xsiz-i.SIZ.XOsiz,this.height=i.SIZ.Ysiz-i.SIZ.YOsiz,this.componentsCount=i.SIZ.Csiz}};var k=function(){function t(t,e){var r=h(Math.max(t,e))+1;this.levels=[];for(var n=0;n<r;n++){var i={width:t,height:e,items:[]};this.levels.push(i),t=Math.ceil(t/2),e=Math.ceil(e/2)}}return t.prototype={reset:function(t,e){for(var r,n=0,i=0;n<this.levels.length;){var s=t+e*(r=this.levels[n]).width;if(void 0!==r.items[s]){i=r.items[s];break}r.index=s,t>>=1,e>>=1,n++}n--,(r=this.levels[n]).items[r.index]=i,this.currentLevel=n,delete this.value},incrementValue:function(){var t=this.levels[this.currentLevel];t.items[t.index]++},nextLevel:function(){var t=this.currentLevel,e=this.levels[t],r=e.items[e.index];return--t<0?(this.value=r,!1):(this.currentLevel=t,(e=this.levels[t]).items[e.index]=r,!0)}},t}(),T=function(){function t(t,e,r){var n=h(Math.max(t,e))+1;this.levels=[];for(var i=0;i<n;i++){for(var s=new Int16Array(t*e),a=0,o=s.length;a<o;a++)s[a]=r;var c={width:t,height:e,items:s};this.levels.push(c),t=Math.ceil(t/2),e=Math.ceil(e/2)}}return t.prototype={reset:function(t,e,r){for(var n=0;n<this.levels.length;){var i=this.levels[n],s=t+e*i.width;i.index=s;var a=i.items[s];if(255===a)break;if(a>r)return this.currentLevel=n,this.propagateValues(),!1;t>>=1,e>>=1,n++}return this.currentLevel=n-1,!0},incrementValue:function(t){var e=this.levels[this.currentLevel];e.items[e.index]=t+1,this.propagateValues()},propagateValues:function(){for(var t=this.currentLevel,e=this.levels[t],r=e.items[e.index];--t>=0;)(e=this.levels[t]).items[e.index]=r},nextLevel:function(){var t=this.currentLevel,e=this.levels[t],r=e.items[e.index];return e.items[e.index]=255,!(--t<0||(this.currentLevel=t,(e=this.levels[t]).items[e.index]=r,0))}},t}(),I=function(){var t=17,e=new Uint8Array([0,5,8,0,3,7,8,0,4,7,8,0,0,0,0,0,1,6,8,0,3,7,8,0,4,7,8,0,0,0,0,0,2,6,8,0,3,7,8,0,4,7,8,0,0,0,0,0,2,6,8,0,3,7,8,0,4,7,8,0,0,0,0,0,2,6,8,0,3,7,8,0,4,7,8]),r=new Uint8Array([0,3,4,0,5,7,7,0,8,8,8,0,0,0,0,0,1,3,4,0,6,7,7,0,8,8,8,0,0,0,0,0,2,3,4,0,6,7,7,0,8,8,8,0,0,0,0,0,2,3,4,0,6,7,7,0,8,8,8,0,0,0,0,0,2,3,4,0,6,7,7,0,8,8,8]),n=new Uint8Array([0,1,2,0,1,2,2,0,2,2,2,0,0,0,0,0,3,4,5,0,4,5,5,0,5,5,5,0,0,0,0,0,6,7,7,0,7,7,7,0,7,7,7,0,0,0,0,0,8,8,8,0,8,8,8,0,8,8,8,0,0,0,0,0,8,8,8,0,8,8,8,0,8,8,8]);function i(t,i,s,a,o){this.width=t,this.height=i,this.contextLabelTable="HH"===s?n:"HL"===s?r:e;var c=t*i;this.neighborsSignificance=new Uint8Array(c),this.coefficentsSign=new Uint8Array(c),this.coefficentsMagnitude=o>14?new Uint32Array(c):o>6?new Uint16Array(c):new Uint8Array(c),this.processingFlags=new Uint8Array(c);var l=new Uint8Array(c);if(0!==a)for(var h=0;h<c;h++)l[h]=a;this.bitsDecoded=l,this.reset()}return i.prototype={setDecoder:function(t){this.decoder=t},reset:function(){this.contexts=new Int8Array(19),this.contexts[0]=8,this.contexts[17]=92,this.contexts[18]=6},setNeighborsSignificance:function(t,e,r){var n,i=this.neighborsSignificance,s=this.width,a=this.height,o=e>0,c=e+1<s;t>0&&(n=r-s,o&&(i[n-1]+=16),c&&(i[n+1]+=16),i[n]+=4),t+1<a&&(n=r+s,o&&(i[n-1]+=16),c&&(i[n+1]+=16),i[n]+=4),o&&(i[r-1]+=1),c&&(i[r+1]+=1),i[r]|=128},runSignificancePropogationPass:function(){for(var t=this.decoder,e=this.width,r=this.height,n=this.coefficentsMagnitude,i=this.coefficentsSign,s=this.neighborsSignificance,a=this.processingFlags,o=this.contexts,c=this.contextLabelTable,l=this.bitsDecoded,h=0;h<r;h+=4)for(var p=0;p<e;p++)for(var u=h*e+p,f=0;f<4;f++,u+=e){var d=h+f;if(d>=r)break;if(a[u]&=-2,!n[u]&&s[u]){var m=c[s[u]];if(t.readBit(o,m)){var g=this.decodeSignBit(d,p,u);i[u]=g,n[u]=1,this.setNeighborsSignificance(d,p,u),a[u]|=2}l[u]++,a[u]|=1}}},decodeSignBit:function(t,e,r){var n,i,s,a,o,c,l=this.width,h=this.height,p=this.coefficentsMagnitude,u=this.coefficentsSign;a=e>0&&0!==p[r-1],e+1<l&&0!==p[r+1]?(s=u[r+1],n=a?1-s-(i=u[r-1]):1-s-s):n=a?1-(i=u[r-1])-i:0;var f=3*n;return a=t>0&&0!==p[r-l],t+1<h&&0!==p[r+l]?(s=u[r+l],n=a?1-s-(i=u[r-l])+f:1-s-s+f):n=a?1-(i=u[r-l])-i+f:f,n>=0?(o=9+n,c=this.decoder.readBit(this.contexts,o)):(o=9-n,c=1^this.decoder.readBit(this.contexts,o)),c},runMagnitudeRefinementPass:function(){for(var t,e=this.decoder,r=this.width,n=this.height,i=this.coefficentsMagnitude,s=this.neighborsSignificance,a=this.contexts,o=this.bitsDecoded,c=this.processingFlags,l=r*n,h=4*r,p=0;p<l;p=t){t=Math.min(l,p+h);for(var u=0;u<r;u++)for(var f=p+u;f<t;f+=r)if(i[f]&&!(1&c[f])){var d=16;2&c[f]&&(c[f]^=2,d=127&s[f]?14:15);var m=e.readBit(a,d);i[f]=i[f]<<1|m,o[f]++,c[f]|=1}}},runCleanupPass:function(){for(var e,r=this.decoder,n=this.width,i=this.height,s=this.neighborsSignificance,a=this.coefficentsMagnitude,o=this.coefficentsSign,c=this.contexts,l=this.contextLabelTable,h=this.bitsDecoded,p=this.processingFlags,u=n,f=2*n,d=3*n,m=0;m<i;m=e){e=Math.min(m+4,i);for(var g=m*n,v=m+3<i,b=0;b<n;b++){var y,x=g+b,w=0,P=x,M=m;if(v&&0===p[x]&&0===p[x+u]&&0===p[x+f]&&0===p[x+d]&&0===s[x]&&0===s[x+u]&&0===s[x+f]&&0===s[x+d]){if(!r.readBit(c,18)){h[x]++,h[x+u]++,h[x+f]++,h[x+d]++;continue}0!=(w=r.readBit(c,t)<<1|r.readBit(c,t))&&(M=m+w,P+=w*n),y=this.decodeSignBit(M,b,P),o[P]=y,a[P]=1,this.setNeighborsSignificance(M,b,P),p[P]|=2,P=x;for(var C=m;C<=M;C++,P+=n)h[P]++;w++}for(M=m+w;M<e;M++,P+=n)if(!(a[P]||1&p[P])){var S=l[s[P]];1===r.readBit(c,S)&&(y=this.decodeSignBit(M,b,P),o[P]=y,a[P]=1,this.setNeighborsSignificance(M,b,P),p[P]|=2),h[P]++}}}},checkSegmentationSymbol:function(){var e=this.decoder,r=this.contexts;if(10!=(e.readBit(r,t)<<3|e.readBit(r,t)<<2|e.readBit(r,t)<<1|e.readBit(r,t)))throw new Error("JPX Error: Invalid segmentation symbol")}},i}(),E=function(){function t(){}return t.prototype.calculate=function(t,e,r){for(var n=t[0],i=1,s=t.length;i<s;i++)n=this.iterate(n,t[i],e,r);return n},t.prototype.extend=function(t,e,r){var n=e-1,i=e+1,s=e+r-2,a=e+r;t[n--]=t[i++],t[a++]=t[s--],t[n--]=t[i++],t[a++]=t[s--],t[n--]=t[i++],t[a++]=t[s--],t[n]=t[i],t[a]=t[s]},t.prototype.iterate=function(t,e,r,n){var i,s,a,o,c,l,h=t.width,p=t.height,u=t.items,f=e.width,d=e.height,m=e.items;for(a=0,i=0;i<p;i++)for(o=2*i*f,s=0;s<h;s++,a++,o+=2)m[o]=u[a];u=t.items=null;var g=new Float32Array(f+8);if(1===f){if(1&r)for(l=0,a=0;l<d;l++,a+=f)m[a]*=.5}else for(l=0,a=0;l<d;l++,a+=f)g.set(m.subarray(a,a+f),4),this.extend(g,4,f),this.filter(g,4,f),m.set(g.subarray(4,4+f),a);var v=16,b=[];for(i=0;i<v;i++)b.push(new Float32Array(d+8));var y,x=0;if(t=4+d,1===d){if(1&n)for(c=0;c<f;c++)m[c]*=.5}else for(c=0;c<f;c++){if(0===x){for(v=Math.min(f-c,v),a=c,o=4;o<t;a+=f,o++)for(y=0;y<v;y++)b[y][o]=m[a+y];x=v}var w=b[--x];if(this.extend(w,4,d),this.filter(w,4,d),0===x)for(a=c-v+1,o=4;o<t;a+=f,o++)for(y=0;y<v;y++)m[a+y]=b[y][o]}return{width:f,height:d,items:m}},t}(),L=function(){function t(){E.call(this)}return t.prototype=Object.create(E.prototype),t.prototype.filter=function(t,e,r){var n,i,s,a,o=r>>1,c=-1.586134342059924,l=-.052980118572961,h=.882911075530934,p=.443506852043971,u=1.230174104914001,f=1/u;for(n=(e|=0)-3,i=o+4;i--;n+=2)t[n]*=f;for(s=p*t[(n=e-2)-1],i=o+3;i--&&(a=p*t[n+1],t[n]=u*t[n]-s-a,i--);n+=2)s=p*t[(n+=2)+1],t[n]=u*t[n]-s-a;for(s=h*t[(n=e-1)-1],i=o+2;i--&&(a=h*t[n+1],t[n]-=s+a,i--);n+=2)s=h*t[(n+=2)+1],t[n]-=s+a;for(s=l*t[(n=e)-1],i=o+1;i--&&(a=l*t[n+1],t[n]-=s+a,i--);n+=2)s=l*t[(n+=2)+1],t[n]-=s+a;if(0!==o)for(s=c*t[(n=e+1)-1],i=o;i--&&(a=c*t[n+1],t[n]-=s+a,i--);n+=2)s=c*t[(n+=2)+1],t[n]-=s+a},t}(),F=function(){function t(){E.call(this)}return t.prototype=Object.create(E.prototype),t.prototype.filter=function(t,e,r){var n,i,s=r>>1;for(n=e|=0,i=s+1;i--;n+=2)t[n]-=t[n-1]+t[n+1]+2>>2;for(n=e+1,i=s;i--;n+=2)t[n]+=t[n-1]+t[n+1]>>1},t}();return i}();self.addEventListener("message",(function(t){const e=new m;e.parse(t.data.buffer);const r=e.tiles[0].items;let n=null;8===t.data.meta.bitsAllocated?n=t.data.meta.isSigned?new Int8Array(r):new Uint8Array(r):16===t.data.meta.bitsAllocated&&(n=t.data.meta.isSigned?new Int16Array(r):new Uint16Array(r)),self.postMessage([n])}),!1);
//# sourceMappingURL=jpeg2000.worker.min.js.map