pdfjs-dist
Version:
Generic build of Mozilla's PDF.js library.
21 lines • 90.7 kB
JavaScript
/**
* @licstart The following is the entire license notice for the
* JavaScript code in this page
*
* Copyright 2023 Mozilla Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* @licend The above is the entire license notice for the
* JavaScript code in this page
*/var e={d:(t,n)=>{for(var i in n)e.o(n,i)&&!e.o(t,i)&&Object.defineProperty(t,i,{enumerable:!0,get:n[i]})},o:(e,t)=>Object.prototype.hasOwnProperty.call(e,t)},__webpack_exports__=globalThis.pdfjsImageDecoders={};e.d(__webpack_exports__,{Jbig2Image:()=>Jbig2Image,JpegImage:()=>JpegImage,JpxImage:()=>JpxImage,VerbosityLevel:()=>t,getVerbosityLevel:()=>getVerbosityLevel,setVerbosityLevel:()=>setVerbosityLevel});"object"!=typeof process||process+""!="[object process]"||process.versions.nw||process.versions.electron&&process.type&&process.type;const t={ERRORS:0,WARNINGS:1,INFOS:5};let n=t.WARNINGS;function setVerbosityLevel(e){Number.isInteger(e)&&(n=e)}function getVerbosityLevel(){return n}function info(e){n>=t.INFOS&&console.log(`Info: ${e}`)}function util_warn(e){n>=t.WARNINGS&&console.log(`Warning: ${e}`)}function util_unreachable(e){throw new Error(e)}function util_shadow(e,t,n,i=!1){Object.defineProperty(e,t,{value:n,enumerable:!i,configurable:!0,writable:!1});return n}const i=function BaseExceptionClosure(){function BaseException(e,t){this.constructor===BaseException&&util_unreachable("Cannot initialize BaseException.");this.message=e;this.name=t}BaseException.prototype=new Error;BaseException.constructor=BaseException;return BaseException}();class FormatError extends i{constructor(e){super(e,"FormatError")}}class util_FeatureTest{static get isLittleEndian(){return util_shadow(this,"isLittleEndian",function isLittleEndian(){const e=new Uint8Array(4);e[0]=1;return 1===new Uint32Array(e.buffer,0,1)[0]}())}static get isEvalSupported(){return util_shadow(this,"isEvalSupported",function isEvalSupported(){try{new Function("");return!0}catch{return!1}}())}static get isOffscreenCanvasSupported(){return util_shadow(this,"isOffscreenCanvasSupported","undefined"!=typeof OffscreenCanvas)}static get platform(){return"undefined"!=typeof navigator&&"string"==typeof navigator?.platform?util_shadow(this,"platform",{isMac:navigator.platform.includes("Mac")}):util_shadow(this,"platform",{isMac:!1})}static get isCSSRoundSupported(){return util_shadow(this,"isCSSRoundSupported",globalThis.CSS?.supports?.("width: round(1.5px, 1px)"))}}Array.from(Array(256).keys(),(e=>e.toString(16).padStart(2,"0")));Symbol("CIRCULAR_REF"),Symbol("EOF");Object.create(null),Object.create(null),Object.create(null);Symbol.iterator;Symbol.iterator;function log2(e){return e<=0?0:Math.ceil(Math.log2(e))}function readInt8(e,t){return e[t]<<24>>24}function readUint16(e,t){return e[t]<<8|e[t+1]}function readUint32(e,t){return(e[t]<<24|e[t+1]<<16|e[t+2]<<8|e[t+3])>>>0}const s=[{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}];class ArithmeticDecoder{constructor(e,t,n){this.data=e;this.bp=t;this.dataEnd=n;this.chigh=e[t];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}byteIn(){const e=this.data;let t=this.bp;if(255===e[t])if(e[t+1]>143){this.clow+=65280;this.ct=8}else{t++;this.clow+=e[t]<<9;this.ct=7;this.bp=t}else{t++;this.clow+=t<this.dataEnd?e[t]<<8:65280;this.ct=8;this.bp=t}if(this.clow>65535){this.chigh+=this.clow>>16;this.clow&=65535}}readBit(e,t){let n=e[t]>>1,i=1&e[t];const r=s[n],o=r.qe;let a,c=this.a-o;if(this.chigh<o)if(c<o){c=o;a=i;n=r.nmps}else{c=o;a=1^i;1===r.switchFlag&&(i=a);n=r.nlps}else{this.chigh-=o;if(0!=(32768&c)){this.a=c;return i}if(c<o){a=1^i;1===r.switchFlag&&(i=a);n=r.nlps}else{a=i;n=r.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(0==(32768&c));this.a=c;e[t]=n<<1|i;return a}}const r=-1,o=[[-1,-1],[-1,-1],[7,8],[7,7],[6,6],[6,6],[6,5],[6,5],[4,0],[4,0],[4,0],[4,0],[4,0],[4,0],[4,0],[4,0],[3,1],[3,1],[3,1],[3,1],[3,1],[3,1],[3,1],[3,1],[3,1],[3,1],[3,1],[3,1],[3,1],[3,1],[3,1],[3,1],[3,4],[3,4],[3,4],[3,4],[3,4],[3,4],[3,4],[3,4],[3,4],[3,4],[3,4],[3,4],[3,4],[3,4],[3,4],[3,4],[3,3],[3,3],[3,3],[3,3],[3,3],[3,3],[3,3],[3,3],[3,3],[3,3],[3,3],[3,3],[3,3],[3,3],[3,3],[3,3],[1,2],[1,2],[1,2],[1,2],[1,2],[1,2],[1,2],[1,2],[1,2],[1,2],[1,2],[1,2],[1,2],[1,2],[1,2],[1,2],[1,2],[1,2],[1,2],[1,2],[1,2],[1,2],[1,2],[1,2],[1,2],[1,2],[1,2],[1,2],[1,2],[1,2],[1,2],[1,2],[1,2],[1,2],[1,2],[1,2],[1,2],[1,2],[1,2],[1,2],[1,2],[1,2],[1,2],[1,2],[1,2],[1,2],[1,2],[1,2],[1,2],[1,2],[1,2],[1,2],[1,2],[1,2],[1,2],[1,2],[1,2],[1,2],[1,2],[1,2],[1,2],[1,2],[1,2],[1,2]],a=[[-1,-1],[12,-2],[-1,-1],[-1,-1],[-1,-1],[-1,-1],[-1,-1],[-1,-1],[-1,-1],[-1,-1],[-1,-1],[-1,-1],[-1,-1],[-1,-1],[-1,-1],[-1,-1],[11,1792],[11,1792],[12,1984],[12,2048],[12,2112],[12,2176],[12,2240],[12,2304],[11,1856],[11,1856],[11,1920],[11,1920],[12,2368],[12,2432],[12,2496],[12,2560]],c=[[-1,-1],[-1,-1],[-1,-1],[-1,-1],[8,29],[8,29],[8,30],[8,30],[8,45],[8,45],[8,46],[8,46],[7,22],[7,22],[7,22],[7,22],[7,23],[7,23],[7,23],[7,23],[8,47],[8,47],[8,48],[8,48],[6,13],[6,13],[6,13],[6,13],[6,13],[6,13],[6,13],[6,13],[7,20],[7,20],[7,20],[7,20],[8,33],[8,33],[8,34],[8,34],[8,35],[8,35],[8,36],[8,36],[8,37],[8,37],[8,38],[8,38],[7,19],[7,19],[7,19],[7,19],[8,31],[8,31],[8,32],[8,32],[6,1],[6,1],[6,1],[6,1],[6,1],[6,1],[6,1],[6,1],[6,12],[6,12],[6,12],[6,12],[6,12],[6,12],[6,12],[6,12],[8,53],[8,53],[8,54],[8,54],[7,26],[7,26],[7,26],[7,26],[8,39],[8,39],[8,40],[8,40],[8,41],[8,41],[8,42],[8,42],[8,43],[8,43],[8,44],[8,44],[7,21],[7,21],[7,21],[7,21],[7,28],[7,28],[7,28],[7,28],[8,61],[8,61],[8,62],[8,62],[8,63],[8,63],[8,0],[8,0],[8,320],[8,320],[8,384],[8,384],[5,10],[5,10],[5,10],[5,10],[5,10],[5,10],[5,10],[5,10],[5,10],[5,10],[5,10],[5,10],[5,10],[5,10],[5,10],[5,10],[5,11],[5,11],[5,11],[5,11],[5,11],[5,11],[5,11],[5,11],[5,11],[5,11],[5,11],[5,11],[5,11],[5,11],[5,11],[5,11],[7,27],[7,27],[7,27],[7,27],[8,59],[8,59],[8,60],[8,60],[9,1472],[9,1536],[9,1600],[9,1728],[7,18],[7,18],[7,18],[7,18],[7,24],[7,24],[7,24],[7,24],[8,49],[8,49],[8,50],[8,50],[8,51],[8,51],[8,52],[8,52],[7,25],[7,25],[7,25],[7,25],[8,55],[8,55],[8,56],[8,56],[8,57],[8,57],[8,58],[8,58],[6,192],[6,192],[6,192],[6,192],[6,192],[6,192],[6,192],[6,192],[6,1664],[6,1664],[6,1664],[6,1664],[6,1664],[6,1664],[6,1664],[6,1664],[8,448],[8,448],[8,512],[8,512],[9,704],[9,768],[8,640],[8,640],[8,576],[8,576],[9,832],[9,896],[9,960],[9,1024],[9,1088],[9,1152],[9,1216],[9,1280],[9,1344],[9,1408],[7,256],[7,256],[7,256],[7,256],[4,2],[4,2],[4,2],[4,2],[4,2],[4,2],[4,2],[4,2],[4,2],[4,2],[4,2],[4,2],[4,2],[4,2],[4,2],[4,2],[4,2],[4,2],[4,2],[4,2],[4,2],[4,2],[4,2],[4,2],[4,2],[4,2],[4,2],[4,2],[4,2],[4,2],[4,2],[4,2],[4,3],[4,3],[4,3],[4,3],[4,3],[4,3],[4,3],[4,3],[4,3],[4,3],[4,3],[4,3],[4,3],[4,3],[4,3],[4,3],[4,3],[4,3],[4,3],[4,3],[4,3],[4,3],[4,3],[4,3],[4,3],[4,3],[4,3],[4,3],[4,3],[4,3],[4,3],[4,3],[5,128],[5,128],[5,128],[5,128],[5,128],[5,128],[5,128],[5,128],[5,128],[5,128],[5,128],[5,128],[5,128],[5,128],[5,128],[5,128],[5,8],[5,8],[5,8],[5,8],[5,8],[5,8],[5,8],[5,8],[5,8],[5,8],[5,8],[5,8],[5,8],[5,8],[5,8],[5,8],[5,9],[5,9],[5,9],[5,9],[5,9],[5,9],[5,9],[5,9],[5,9],[5,9],[5,9],[5,9],[5,9],[5,9],[5,9],[5,9],[6,16],[6,16],[6,16],[6,16],[6,16],[6,16],[6,16],[6,16],[6,17],[6,17],[6,17],[6,17],[6,17],[6,17],[6,17],[6,17],[4,4],[4,4],[4,4],[4,4],[4,4],[4,4],[4,4],[4,4],[4,4],[4,4],[4,4],[4,4],[4,4],[4,4],[4,4],[4,4],[4,4],[4,4],[4,4],[4,4],[4,4],[4,4],[4,4],[4,4],[4,4],[4,4],[4,4],[4,4],[4,4],[4,4],[4,4],[4,4],[4,5],[4,5],[4,5],[4,5],[4,5],[4,5],[4,5],[4,5],[4,5],[4,5],[4,5],[4,5],[4,5],[4,5],[4,5],[4,5],[4,5],[4,5],[4,5],[4,5],[4,5],[4,5],[4,5],[4,5],[4,5],[4,5],[4,5],[4,5],[4,5],[4,5],[4,5],[4,5],[6,14],[6,14],[6,14],[6,14],[6,14],[6,14],[6,14],[6,14],[6,15],[6,15],[6,15],[6,15],[6,15],[6,15],[6,15],[6,15],[5,64],[5,64],[5,64],[5,64],[5,64],[5,64],[5,64],[5,64],[5,64],[5,64],[5,64],[5,64],[5,64],[5,64],[5,64],[5,64],[4,6],[4,6],[4,6],[4,6],[4,6],[4,6],[4,6],[4,6],[4,6],[4,6],[4,6],[4,6],[4,6],[4,6],[4,6],[4,6],[4,6],[4,6],[4,6],[4,6],[4,6],[4,6],[4,6],[4,6],[4,6],[4,6],[4,6],[4,6],[4,6],[4,6],[4,6],[4,6],[4,7],[4,7],[4,7],[4,7],[4,7],[4,7],[4,7],[4,7],[4,7],[4,7],[4,7],[4,7],[4,7],[4,7],[4,7],[4,7],[4,7],[4,7],[4,7],[4,7],[4,7],[4,7],[4,7],[4,7],[4,7],[4,7],[4,7],[4,7],[4,7],[4,7],[4,7],[4,7]],l=[[-1,-1],[-1,-1],[12,-2],[12,-2],[-1,-1],[-1,-1],[-1,-1],[-1,-1],[-1,-1],[-1,-1],[-1,-1],[-1,-1],[-1,-1],[-1,-1],[-1,-1],[-1,-1],[-1,-1],[-1,-1],[-1,-1],[-1,-1],[-1,-1],[-1,-1],[-1,-1],[-1,-1],[-1,-1],[-1,-1],[-1,-1],[-1,-1],[-1,-1],[-1,-1],[-1,-1],[-1,-1],[11,1792],[11,1792],[11,1792],[11,1792],[12,1984],[12,1984],[12,2048],[12,2048],[12,2112],[12,2112],[12,2176],[12,2176],[12,2240],[12,2240],[12,2304],[12,2304],[11,1856],[11,1856],[11,1856],[11,1856],[11,1920],[11,1920],[11,1920],[11,1920],[12,2368],[12,2368],[12,2432],[12,2432],[12,2496],[12,2496],[12,2560],[12,2560],[10,18],[10,18],[10,18],[10,18],[10,18],[10,18],[10,18],[10,18],[12,52],[12,52],[13,640],[13,704],[13,768],[13,832],[12,55],[12,55],[12,56],[12,56],[13,1280],[13,1344],[13,1408],[13,1472],[12,59],[12,59],[12,60],[12,60],[13,1536],[13,1600],[11,24],[11,24],[11,24],[11,24],[11,25],[11,25],[11,25],[11,25],[13,1664],[13,1728],[12,320],[12,320],[12,384],[12,384],[12,448],[12,448],[13,512],[13,576],[12,53],[12,53],[12,54],[12,54],[13,896],[13,960],[13,1024],[13,1088],[13,1152],[13,1216],[10,64],[10,64],[10,64],[10,64],[10,64],[10,64],[10,64],[10,64]],h=[[8,13],[8,13],[8,13],[8,13],[8,13],[8,13],[8,13],[8,13],[8,13],[8,13],[8,13],[8,13],[8,13],[8,13],[8,13],[8,13],[11,23],[11,23],[12,50],[12,51],[12,44],[12,45],[12,46],[12,47],[12,57],[12,58],[12,61],[12,256],[10,16],[10,16],[10,16],[10,16],[10,17],[10,17],[10,17],[10,17],[12,48],[12,49],[12,62],[12,63],[12,30],[12,31],[12,32],[12,33],[12,40],[12,41],[11,22],[11,22],[8,14],[8,14],[8,14],[8,14],[8,14],[8,14],[8,14],[8,14],[8,14],[8,14],[8,14],[8,14],[8,14],[8,14],[8,14],[8,14],[7,10],[7,10],[7,10],[7,10],[7,10],[7,10],[7,10],[7,10],[7,10],[7,10],[7,10],[7,10],[7,10],[7,10],[7,10],[7,10],[7,10],[7,10],[7,10],[7,10],[7,10],[7,10],[7,10],[7,10],[7,10],[7,10],[7,10],[7,10],[7,10],[7,10],[7,10],[7,10],[7,11],[7,11],[7,11],[7,11],[7,11],[7,11],[7,11],[7,11],[7,11],[7,11],[7,11],[7,11],[7,11],[7,11],[7,11],[7,11],[7,11],[7,11],[7,11],[7,11],[7,11],[7,11],[7,11],[7,11],[7,11],[7,11],[7,11],[7,11],[7,11],[7,11],[7,11],[7,11],[9,15],[9,15],[9,15],[9,15],[9,15],[9,15],[9,15],[9,15],[12,128],[12,192],[12,26],[12,27],[12,28],[12,29],[11,19],[11,19],[11,20],[11,20],[12,34],[12,35],[12,36],[12,37],[12,38],[12,39],[11,21],[11,21],[12,42],[12,43],[10,0],[10,0],[10,0],[10,0],[7,12],[7,12],[7,12],[7,12],[7,12],[7,12],[7,12],[7,12],[7,12],[7,12],[7,12],[7,12],[7,12],[7,12],[7,12],[7,12],[7,12],[7,12],[7,12],[7,12],[7,12],[7,12],[7,12],[7,12],[7,12],[7,12],[7,12],[7,12],[7,12],[7,12],[7,12],[7,12]],d=[[-1,-1],[-1,-1],[-1,-1],[-1,-1],[6,9],[6,8],[5,7],[5,7],[4,6],[4,6],[4,6],[4,6],[4,5],[4,5],[4,5],[4,5],[3,1],[3,1],[3,1],[3,1],[3,1],[3,1],[3,1],[3,1],[3,4],[3,4],[3,4],[3,4],[3,4],[3,4],[3,4],[3,4],[2,3],[2,3],[2,3],[2,3],[2,3],[2,3],[2,3],[2,3],[2,3],[2,3],[2,3],[2,3],[2,3],[2,3],[2,3],[2,3],[2,2],[2,2],[2,2],[2,2],[2,2],[2,2],[2,2],[2,2],[2,2],[2,2],[2,2],[2,2],[2,2],[2,2],[2,2],[2,2]];class CCITTFaxDecoder{constructor(e,t={}){if(!e||"function"!=typeof e.next)throw new Error('CCITTFaxDecoder - invalid "source" parameter.');this.source=e;this.eof=!1;this.encoding=t.K||0;this.eoline=t.EndOfLine||!1;this.byteAlign=t.EncodedByteAlign||!1;this.columns=t.Columns||1728;this.rows=t.Rows||0;this.eoblock=t.EndOfBlock??!0;this.black=t.BlackIs1||!1;this.codingLine=new Uint32Array(this.columns+1);this.refLine=new Uint32Array(this.columns+2);this.codingLine[0]=this.columns;this.codingPos=0;this.row=0;this.nextLine2D=this.encoding<0;this.inputBits=0;this.inputBuf=0;this.outputBits=0;this.rowsDone=!1;let n;for(;0===(n=this._lookBits(12));)this._eatBits(1);1===n&&this._eatBits(12);if(this.encoding>0){this.nextLine2D=!this._lookBits(1);this._eatBits(1)}}readNextChar(){if(this.eof)return-1;const e=this.refLine,t=this.codingLine,n=this.columns;let i,s,o,a,c;if(0===this.outputBits){this.rowsDone&&(this.eof=!0);if(this.eof)return-1;this.err=!1;let o,c,l;if(this.nextLine2D){for(a=0;t[a]<n;++a)e[a]=t[a];e[a++]=n;e[a]=n;t[0]=0;this.codingPos=0;i=0;s=0;for(;t[this.codingPos]<n;){o=this._getTwoDimCode();switch(o){case 0:this._addPixels(e[i+1],s);e[i+1]<n&&(i+=2);break;case 1:o=c=0;if(s){do{o+=l=this._getBlackCode()}while(l>=64);do{c+=l=this._getWhiteCode()}while(l>=64)}else{do{o+=l=this._getWhiteCode()}while(l>=64);do{c+=l=this._getBlackCode()}while(l>=64)}this._addPixels(t[this.codingPos]+o,s);t[this.codingPos]<n&&this._addPixels(t[this.codingPos]+c,1^s);for(;e[i]<=t[this.codingPos]&&e[i]<n;)i+=2;break;case 7:this._addPixels(e[i]+3,s);s^=1;if(t[this.codingPos]<n){++i;for(;e[i]<=t[this.codingPos]&&e[i]<n;)i+=2}break;case 5:this._addPixels(e[i]+2,s);s^=1;if(t[this.codingPos]<n){++i;for(;e[i]<=t[this.codingPos]&&e[i]<n;)i+=2}break;case 3:this._addPixels(e[i]+1,s);s^=1;if(t[this.codingPos]<n){++i;for(;e[i]<=t[this.codingPos]&&e[i]<n;)i+=2}break;case 2:this._addPixels(e[i],s);s^=1;if(t[this.codingPos]<n){++i;for(;e[i]<=t[this.codingPos]&&e[i]<n;)i+=2}break;case 8:this._addPixelsNeg(e[i]-3,s);s^=1;if(t[this.codingPos]<n){i>0?--i:++i;for(;e[i]<=t[this.codingPos]&&e[i]<n;)i+=2}break;case 6:this._addPixelsNeg(e[i]-2,s);s^=1;if(t[this.codingPos]<n){i>0?--i:++i;for(;e[i]<=t[this.codingPos]&&e[i]<n;)i+=2}break;case 4:this._addPixelsNeg(e[i]-1,s);s^=1;if(t[this.codingPos]<n){i>0?--i:++i;for(;e[i]<=t[this.codingPos]&&e[i]<n;)i+=2}break;case r:this._addPixels(n,0);this.eof=!0;break;default:info("bad 2d code");this._addPixels(n,0);this.err=!0}}}else{t[0]=0;this.codingPos=0;s=0;for(;t[this.codingPos]<n;){o=0;if(s)do{o+=l=this._getBlackCode()}while(l>=64);else do{o+=l=this._getWhiteCode()}while(l>=64);this._addPixels(t[this.codingPos]+o,s);s^=1}}let h=!1;this.byteAlign&&(this.inputBits&=-8);if(this.eoblock||this.row!==this.rows-1){o=this._lookBits(12);if(this.eoline)for(;o!==r&&1!==o;){this._eatBits(1);o=this._lookBits(12)}else for(;0===o;){this._eatBits(1);o=this._lookBits(12)}if(1===o){this._eatBits(12);h=!0}else o===r&&(this.eof=!0)}else this.rowsDone=!0;if(!this.eof&&this.encoding>0&&!this.rowsDone){this.nextLine2D=!this._lookBits(1);this._eatBits(1)}if(this.eoblock&&h&&this.byteAlign){o=this._lookBits(12);if(1===o){this._eatBits(12);if(this.encoding>0){this._lookBits(1);this._eatBits(1)}if(this.encoding>=0)for(a=0;a<4;++a){o=this._lookBits(12);1!==o&&info("bad rtc code: "+o);this._eatBits(12);if(this.encoding>0){this._lookBits(1);this._eatBits(1)}}this.eof=!0}}else if(this.err&&this.eoline){for(;;){o=this._lookBits(13);if(o===r){this.eof=!0;return-1}if(o>>1==1)break;this._eatBits(1)}this._eatBits(12);if(this.encoding>0){this._eatBits(1);this.nextLine2D=!(1&o)}}this.outputBits=t[0]>0?t[this.codingPos=0]:t[this.codingPos=1];this.row++}if(this.outputBits>=8){c=1&this.codingPos?0:255;this.outputBits-=8;if(0===this.outputBits&&t[this.codingPos]<n){this.codingPos++;this.outputBits=t[this.codingPos]-t[this.codingPos-1]}}else{o=8;c=0;do{if("number"!=typeof this.outputBits)throw new FormatError('Invalid /CCITTFaxDecode data, "outputBits" must be a number.');if(this.outputBits>o){c<<=o;1&this.codingPos||(c|=255>>8-o);this.outputBits-=o;o=0}else{c<<=this.outputBits;1&this.codingPos||(c|=255>>8-this.outputBits);o-=this.outputBits;this.outputBits=0;if(t[this.codingPos]<n){this.codingPos++;this.outputBits=t[this.codingPos]-t[this.codingPos-1]}else if(o>0){c<<=o;o=0}}}while(o)}this.black&&(c^=255);return c}_addPixels(e,t){const n=this.codingLine;let i=this.codingPos;if(e>n[i]){if(e>this.columns){info("row is wrong length");this.err=!0;e=this.columns}1&i^t&&++i;n[i]=e}this.codingPos=i}_addPixelsNeg(e,t){const n=this.codingLine;let i=this.codingPos;if(e>n[i]){if(e>this.columns){info("row is wrong length");this.err=!0;e=this.columns}1&i^t&&++i;n[i]=e}else if(e<n[i]){if(e<0){info("invalid code");this.err=!0;e=0}for(;i>0&&e<n[i-1];)--i;n[i]=e}this.codingPos=i}_findTableCode(e,t,n,i){const s=i||0;for(let i=e;i<=t;++i){let e=this._lookBits(i);if(e===r)return[!0,1,!1];i<t&&(e<<=t-i);if(!s||e>=s){const t=n[e-s];if(t[0]===i){this._eatBits(i);return[!0,t[1],!0]}}}return[!1,0,!1]}_getTwoDimCode(){let e,t=0;if(this.eoblock){t=this._lookBits(7);e=o[t];if(e?.[0]>0){this._eatBits(e[0]);return e[1]}}else{const e=this._findTableCode(1,7,o);if(e[0]&&e[2])return e[1]}info("Bad two dim code");return r}_getWhiteCode(){let e,t=0;if(this.eoblock){t=this._lookBits(12);if(t===r)return 1;e=t>>5==0?a[t]:c[t>>3];if(e[0]>0){this._eatBits(e[0]);return e[1]}}else{let e=this._findTableCode(1,9,c);if(e[0])return e[1];e=this._findTableCode(11,12,a);if(e[0])return e[1]}info("bad white code");this._eatBits(1);return 1}_getBlackCode(){let e,t;if(this.eoblock){e=this._lookBits(13);if(e===r)return 1;t=e>>7==0?l[e]:e>>9==0&&e>>7!=0?h[(e>>1)-64]:d[e>>7];if(t[0]>0){this._eatBits(t[0]);return t[1]}}else{let e=this._findTableCode(2,6,d);if(e[0])return e[1];e=this._findTableCode(7,12,h,64);if(e[0])return e[1];e=this._findTableCode(10,13,l);if(e[0])return e[1]}info("bad black code");this._eatBits(1);return 1}_lookBits(e){let t;for(;this.inputBits<e;){if(-1===(t=this.source.next()))return 0===this.inputBits?r:this.inputBuf<<e-this.inputBits&65535>>16-e;this.inputBuf=this.inputBuf<<8|t;this.inputBits+=8}return this.inputBuf>>this.inputBits-e&65535>>16-e}_eatBits(e){(this.inputBits-=e)<0&&(this.inputBits=0)}}class Jbig2Error extends i{constructor(e){super(`JBIG2 error: ${e}`,"Jbig2Error")}}class ContextCache{getContexts(e){return e in this?this[e]:this[e]=new Int8Array(65536)}}class DecodingContext{constructor(e,t,n){this.data=e;this.start=t;this.end=n}get decoder(){return util_shadow(this,"decoder",new ArithmeticDecoder(this.data,this.start,this.end))}get contextCache(){return util_shadow(this,"contextCache",new ContextCache)}}const f=2**31-1,u=-(2**31);function decodeInteger(e,t,n){const i=e.getContexts(t);let s=1;function readBits(e){let t=0;for(let r=0;r<e;r++){const e=n.readBit(i,s);s=s<256?s<<1|e:511&(s<<1|e)|256;t=t<<1|e}return t>>>0}const r=readBits(1),o=readBits(1)?readBits(1)?readBits(1)?readBits(1)?readBits(1)?readBits(32)+4436:readBits(12)+340:readBits(8)+84:readBits(6)+20:readBits(4)+4:readBits(2);let a;0===r?a=o:o>0&&(a=-o);return a>=u&&a<=f?a:null}function decodeIAID(e,t,n){const i=e.getContexts("IAID");let s=1;for(let e=0;e<n;e++){s=s<<1|t.readBit(i,s)}return n<31?s&(1<<n)-1:2147483647&s}const m=["SymbolDictionary",null,null,null,"IntermediateTextRegion",null,"ImmediateTextRegion","ImmediateLosslessTextRegion",null,null,null,null,null,null,null,null,"PatternDictionary",null,null,null,"IntermediateHalftoneRegion",null,"ImmediateHalftoneRegion","ImmediateLosslessHalftoneRegion",null,null,null,null,null,null,null,null,null,null,null,null,"IntermediateGenericRegion",null,"ImmediateGenericRegion","ImmediateLosslessGenericRegion","IntermediateGenericRefinementRegion",null,"ImmediateGenericRefinementRegion","ImmediateLosslessGenericRefinementRegion",null,null,null,null,"PageInformation","EndOfPage","EndOfStripe","EndOfFile","Profiles","Tables",null,null,null,null,null,null,null,null,"Extension"],g=[[{x:-1,y:-2},{x:0,y:-2},{x:1,y:-2},{x:-2,y:-1},{x:-1,y:-1},{x:0,y:-1},{x:1,y:-1},{x:2,y:-1},{x:-4,y:0},{x:-3,y:0},{x:-2,y:0},{x:-1,y:0}],[{x:-1,y:-2},{x:0,y:-2},{x:1,y:-2},{x:2,y:-2},{x:-2,y:-1},{x:-1,y:-1},{x:0,y:-1},{x:1,y:-1},{x:2,y:-1},{x:-3,y:0},{x:-2,y:0},{x:-1,y:0}],[{x:-1,y:-2},{x:0,y:-2},{x:1,y:-2},{x:-2,y:-1},{x:-1,y:-1},{x:0,y:-1},{x:1,y:-1},{x:-2,y:0},{x:-1,y:0}],[{x:-3,y:-1},{x:-2,y:-1},{x:-1,y:-1},{x:0,y:-1},{x:1,y:-1},{x:-4,y:0},{x:-3,y:0},{x:-2,y:0},{x:-1,y:0}]],p=[{coding:[{x:0,y:-1},{x:1,y:-1},{x:-1,y:0}],reference:[{x:0,y:-1},{x:1,y:-1},{x:-1,y:0},{x:0,y:0},{x:1,y:0},{x:-1,y:1},{x:0,y:1},{x:1,y:1}]},{coding:[{x:-1,y:-1},{x:0,y:-1},{x:1,y:-1},{x:-1,y:0}],reference:[{x:0,y:-1},{x:-1,y:0},{x:0,y:0},{x:1,y:0},{x:0,y:1},{x:1,y:1}]}],b=[39717,1941,229,405],x=[32,8];function decodeBitmap(e,t,n,i,s,r,o,a){if(e){return decodeMMRBitmap(new Reader(a.data,a.start,a.end),t,n,!1)}if(0===i&&!r&&!s&&4===o.length&&3===o[0].x&&-1===o[0].y&&-3===o[1].x&&-1===o[1].y&&2===o[2].x&&-2===o[2].y&&-2===o[3].x&&-2===o[3].y)return function decodeBitmapTemplate0(e,t,n){const i=n.decoder,s=n.contextCache.getContexts("GB"),r=[];let o,a,c,l,h,d,f;for(a=0;a<t;a++){h=r[a]=new Uint8Array(e);d=a<1?h:r[a-1];f=a<2?h:r[a-2];o=f[0]<<13|f[1]<<12|f[2]<<11|d[0]<<7|d[1]<<6|d[2]<<5|d[3]<<4;for(c=0;c<e;c++){h[c]=l=i.readBit(s,o);o=(31735&o)<<1|(c+3<e?f[c+3]<<11:0)|(c+4<e?d[c+4]<<4:0)|l}}return r}(t,n,a);const c=!!r,l=g[i].concat(o);l.sort((function(e,t){return e.y-t.y||e.x-t.x}));const h=l.length,d=new Int8Array(h),f=new Int8Array(h),u=[];let m,p,x=0,w=0,y=0,k=0;for(p=0;p<h;p++){d[p]=l[p].x;f[p]=l[p].y;w=Math.min(w,l[p].x);y=Math.max(y,l[p].x);k=Math.min(k,l[p].y);p<h-1&&l[p].y===l[p+1].y&&l[p].x===l[p+1].x-1?x|=1<<h-1-p:u.push(p)}const C=u.length,I=new Int8Array(C),B=new Int8Array(C),P=new Uint16Array(C);for(m=0;m<C;m++){p=u[m];I[m]=l[p].x;B[m]=l[p].y;P[m]=1<<h-1-p}const T=-w,S=-k,L=t-y,v=b[i];let M=new Uint8Array(t);const _=[],D=a.decoder,E=a.contextCache.getContexts("GB");let U,A,O,R,H,F=0,z=0;for(let e=0;e<n;e++){if(s){F^=D.readBit(E,v);if(F){_.push(M);continue}}M=new Uint8Array(M);_.push(M);for(U=0;U<t;U++){if(c&&r[e][U]){M[U]=0;continue}if(U>=T&&U<L&&e>=S){z=z<<1&x;for(p=0;p<C;p++){A=e+B[p];O=U+I[p];R=_[A][O];if(R){R=P[p];z|=R}}}else{z=0;H=h-1;for(p=0;p<h;p++,H--){O=U+d[p];if(O>=0&&O<t){A=e+f[p];if(A>=0){R=_[A][O];R&&(z|=R<<H)}}}}const n=D.readBit(E,z);M[U]=n}}return _}function decodeRefinement(e,t,n,i,s,r,o,a,c){let l=p[n].coding;0===n&&(l=l.concat([a[0]]));const h=l.length,d=new Int32Array(h),f=new Int32Array(h);let u;for(u=0;u<h;u++){d[u]=l[u].x;f[u]=l[u].y}let m=p[n].reference;0===n&&(m=m.concat([a[1]]));const g=m.length,b=new Int32Array(g),w=new Int32Array(g);for(u=0;u<g;u++){b[u]=m[u].x;w[u]=m[u].y}const y=i[0].length,k=i.length,C=x[n],I=[],B=c.decoder,P=c.contextCache.getContexts("GR");let T=0;for(let n=0;n<t;n++){if(o){T^=B.readBit(P,C);if(T)throw new Jbig2Error("prediction is not supported")}const t=new Uint8Array(e);I.push(t);for(let o=0;o<e;o++){let a,c,l=0;for(u=0;u<h;u++){a=n+f[u];c=o+d[u];a<0||c<0||c>=e?l<<=1:l=l<<1|I[a][c]}for(u=0;u<g;u++){a=n+w[u]-r;c=o+b[u]-s;a<0||a>=k||c<0||c>=y?l<<=1:l=l<<1|i[a][c]}const m=B.readBit(P,l);t[o]=m}}return I}function decodeTextRegion(e,t,n,i,s,r,o,a,c,l,h,d,f,u,m,g,p,b,x){if(e&&t)throw new Jbig2Error("refinement with Huffman is not supported");const w=[];let y,k;for(y=0;y<i;y++){k=new Uint8Array(n);if(s)for(let e=0;e<n;e++)k[e]=s;w.push(k)}const C=p.decoder,I=p.contextCache;let B=e?-u.tableDeltaT.decode(x):-decodeInteger(I,"IADT",C),P=0;y=0;for(;y<r;){B+=e?u.tableDeltaT.decode(x):decodeInteger(I,"IADT",C);P+=e?u.tableFirstS.decode(x):decodeInteger(I,"IAFS",C);let i=P;for(;;){let s=0;o>1&&(s=e?x.readBits(b):decodeInteger(I,"IAIT",C));const r=o*B+s,P=e?u.symbolIDTable.decode(x):decodeIAID(I,C,c),T=t&&(e?x.readBit():decodeInteger(I,"IARI",C));let S=a[P],L=S[0].length,v=S.length;if(T){const e=decodeInteger(I,"IARDW",C),t=decodeInteger(I,"IARDH",C);L+=e;v+=t;S=decodeRefinement(L,v,m,S,(e>>1)+decodeInteger(I,"IARDX",C),(t>>1)+decodeInteger(I,"IARDY",C),!1,g,p)}let M=0;l?1&d?M=v-1:i+=v-1:d>1?i+=L-1:M=L-1;const _=r-(1&d?0:v-1),D=i-(2&d?L-1:0);let E,U,A;if(l)for(E=0;E<v;E++){k=w[D+E];if(!k)continue;A=S[E];const e=Math.min(n-_,L);switch(f){case 0:for(U=0;U<e;U++)k[_+U]|=A[U];break;case 2:for(U=0;U<e;U++)k[_+U]^=A[U];break;default:throw new Jbig2Error(`operator ${f} is not supported`)}}else for(U=0;U<v;U++){k=w[_+U];if(k){A=S[U];switch(f){case 0:for(E=0;E<L;E++)k[D+E]|=A[E];break;case 2:for(E=0;E<L;E++)k[D+E]^=A[E];break;default:throw new Jbig2Error(`operator ${f} is not supported`)}}}y++;const O=e?u.tableDeltaS.decode(x):decodeInteger(I,"IADS",C);if(null===O)break;i+=M+O+h}}return w}function readSegmentHeader(e,t){const n={};n.number=readUint32(e,t);const i=e[t+4],s=63&i;if(!m[s])throw new Jbig2Error("invalid segment type: "+s);n.type=s;n.typeName=m[s];n.deferredNonRetain=!!(128&i);const r=!!(64&i),o=e[t+5];let a=o>>5&7;const c=[31&o];let l=t+6;if(7===o){a=536870911&readUint32(e,l-1);l+=3;let t=a+7>>3;c[0]=e[l++];for(;--t>0;)c.push(e[l++])}else if(5===o||6===o)throw new Jbig2Error("invalid referred-to flags");n.retainBits=c;let h=4;n.number<=256?h=1:n.number<=65536&&(h=2);const d=[];let f,u;for(f=0;f<a;f++){let t;t=1===h?e[l]:2===h?readUint16(e,l):readUint32(e,l);d.push(t);l+=h}n.referredTo=d;if(r){n.pageAssociation=readUint32(e,l);l+=4}else n.pageAssociation=e[l++];n.length=readUint32(e,l);l+=4;if(4294967295===n.length){if(38!==s)throw new Jbig2Error("invalid unknown segment length");{const t=readRegionSegmentInformation(e,l),i=!!(1&e[l+w]),s=6,r=new Uint8Array(s);if(!i){r[0]=255;r[1]=172}r[2]=t.height>>>24&255;r[3]=t.height>>16&255;r[4]=t.height>>8&255;r[5]=255&t.height;for(f=l,u=e.length;f<u;f++){let t=0;for(;t<s&&r[t]===e[f+t];)t++;if(t===s){n.length=f+s;break}}if(4294967295===n.length)throw new Jbig2Error("segment end was not found")}}n.headerEnd=l;return n}function readSegments(e,t,n,i){const s=[];let r=n;for(;r<i;){const n=readSegmentHeader(t,r);r=n.headerEnd;const i={header:n,data:t};if(!e.randomAccess){i.start=r;r+=n.length;i.end=r}s.push(i);if(51===n.type)break}if(e.randomAccess)for(let e=0,t=s.length;e<t;e++){s[e].start=r;r+=s[e].header.length;s[e].end=r}return s}function readRegionSegmentInformation(e,t){return{width:readUint32(e,t),height:readUint32(e,t+4),x:readUint32(e,t+8),y:readUint32(e,t+12),combinationOperator:7&e[t+16]}}const w=17;function processSegment(e,t){const n=e.header,i=e.data,s=e.end;let r,o,a,c,l=e.start;switch(n.type){case 0:const e={},t=readUint16(i,l);e.huffman=!!(1&t);e.refinement=!!(2&t);e.huffmanDHSelector=t>>2&3;e.huffmanDWSelector=t>>4&3;e.bitmapSizeSelector=t>>6&1;e.aggregationInstancesSelector=t>>7&1;e.bitmapCodingContextUsed=!!(256&t);e.bitmapCodingContextRetained=!!(512&t);e.template=t>>10&3;e.refinementTemplate=t>>12&1;l+=2;if(!e.huffman){c=0===e.template?4:1;o=[];for(a=0;a<c;a++){o.push({x:readInt8(i,l),y:readInt8(i,l+1)});l+=2}e.at=o}if(e.refinement&&!e.refinementTemplate){o=[];for(a=0;a<2;a++){o.push({x:readInt8(i,l),y:readInt8(i,l+1)});l+=2}e.refinementAt=o}e.numberOfExportedSymbols=readUint32(i,l);l+=4;e.numberOfNewSymbols=readUint32(i,l);l+=4;r=[e,n.number,n.referredTo,i,l,s];break;case 6:case 7:const h={};h.info=readRegionSegmentInformation(i,l);l+=w;const d=readUint16(i,l);l+=2;h.huffman=!!(1&d);h.refinement=!!(2&d);h.logStripSize=d>>2&3;h.stripSize=1<<h.logStripSize;h.referenceCorner=d>>4&3;h.transposed=!!(64&d);h.combinationOperator=d>>7&3;h.defaultPixelValue=d>>9&1;h.dsOffset=d<<17>>27;h.refinementTemplate=d>>15&1;if(h.huffman){const e=readUint16(i,l);l+=2;h.huffmanFS=3&e;h.huffmanDS=e>>2&3;h.huffmanDT=e>>4&3;h.huffmanRefinementDW=e>>6&3;h.huffmanRefinementDH=e>>8&3;h.huffmanRefinementDX=e>>10&3;h.huffmanRefinementDY=e>>12&3;h.huffmanRefinementSizeSelector=!!(16384&e)}if(h.refinement&&!h.refinementTemplate){o=[];for(a=0;a<2;a++){o.push({x:readInt8(i,l),y:readInt8(i,l+1)});l+=2}h.refinementAt=o}h.numberOfSymbolInstances=readUint32(i,l);l+=4;r=[h,n.referredTo,i,l,s];break;case 16:const f={},u=i[l++];f.mmr=!!(1&u);f.template=u>>1&3;f.patternWidth=i[l++];f.patternHeight=i[l++];f.maxPatternIndex=readUint32(i,l);l+=4;r=[f,n.number,i,l,s];break;case 22:case 23:const m={};m.info=readRegionSegmentInformation(i,l);l+=w;const g=i[l++];m.mmr=!!(1&g);m.template=g>>1&3;m.enableSkip=!!(8&g);m.combinationOperator=g>>4&7;m.defaultPixelValue=g>>7&1;m.gridWidth=readUint32(i,l);l+=4;m.gridHeight=readUint32(i,l);l+=4;m.gridOffsetX=4294967295&readUint32(i,l);l+=4;m.gridOffsetY=4294967295&readUint32(i,l);l+=4;m.gridVectorX=readUint16(i,l);l+=2;m.gridVectorY=readUint16(i,l);l+=2;r=[m,n.referredTo,i,l,s];break;case 38:case 39:const p={};p.info=readRegionSegmentInformation(i,l);l+=w;const b=i[l++];p.mmr=!!(1&b);p.template=b>>1&3;p.prediction=!!(8&b);if(!p.mmr){c=0===p.template?4:1;o=[];for(a=0;a<c;a++){o.push({x:readInt8(i,l),y:readInt8(i,l+1)});l+=2}p.at=o}r=[p,i,l,s];break;case 48:const x={width:readUint32(i,l),height:readUint32(i,l+4),resolutionX:readUint32(i,l+8),resolutionY:readUint32(i,l+12)};4294967295===x.height&&delete x.height;const y=i[l+16];readUint16(i,l+17);x.lossless=!!(1&y);x.refinement=!!(2&y);x.defaultPixelValue=y>>2&1;x.combinationOperator=y>>3&3;x.requiresBuffer=!!(32&y);x.combinationOperatorOverride=!!(64&y);r=[x];break;case 49:case 50:case 51:case 62:break;case 53:r=[n.number,i,l,s];break;default:throw new Jbig2Error(`segment type ${n.typeName}(${n.type}) is not implemented`)}const h="on"+n.typeName;h in t&&t[h].apply(t,r)}function processSegments(e,t){for(let n=0,i=e.length;n<i;n++)processSegment(e[n],t)}class SimpleSegmentVisitor{onPageInformation(e){this.currentPageInfo=e;const t=e.width+7>>3,n=new Uint8ClampedArray(t*e.height);e.defaultPixelValue&&n.fill(255);this.buffer=n}drawBitmap(e,t){const n=this.currentPageInfo,i=e.width,s=e.height,r=n.width+7>>3,o=n.combinationOperatorOverride?e.combinationOperator:n.combinationOperator,a=this.buffer,c=128>>(7&e.x);let l,h,d,f,u=e.y*r+(e.x>>3);switch(o){case 0:for(l=0;l<s;l++){d=c;f=u;for(h=0;h<i;h++){t[l][h]&&(a[f]|=d);d>>=1;if(!d){d=128;f++}}u+=r}break;case 2:for(l=0;l<s;l++){d=c;f=u;for(h=0;h<i;h++){t[l][h]&&(a[f]^=d);d>>=1;if(!d){d=128;f++}}u+=r}break;default:throw new Jbig2Error(`operator ${o} is not supported`)}}onImmediateGenericRegion(e,t,n,i){const s=e.info,r=new DecodingContext(t,n,i),o=decodeBitmap(e.mmr,s.width,s.height,e.template,e.prediction,null,e.at,r);this.drawBitmap(s,o)}onImmediateLosslessGenericRegion(){this.onImmediateGenericRegion(...arguments)}onSymbolDictionary(e,t,n,i,s,r){let o,a;if(e.huffman){o=function getSymbolDictionaryHuffmanTables(e,t,n){let i,s,r,o,a=0;switch(e.huffmanDHSelector){case 0:case 1:i=getStandardTable(e.huffmanDHSelector+4);break;case 3:i=getCustomHuffmanTable(a,t,n);a++;break;default:throw new Jbig2Error("invalid Huffman DH selector")}switch(e.huffmanDWSelector){case 0:case 1:s=getStandardTable(e.huffmanDWSelector+2);break;case 3:s=getCustomHuffmanTable(a,t,n);a++;break;default:throw new Jbig2Error("invalid Huffman DW selector")}if(e.bitmapSizeSelector){r=getCustomHuffmanTable(a,t,n);a++}else r=getStandardTable(1);o=e.aggregationInstancesSelector?getCustomHuffmanTable(a,t,n):getStandardTable(1);return{tableDeltaHeight:i,tableDeltaWidth:s,tableBitmapSize:r,tableAggregateInstances:o}}(e,n,this.customTables);a=new Reader(i,s,r)}let c=this.symbols;c||(this.symbols=c={});const l=[];for(const e of n){const t=c[e];t&&l.push(...t)}const h=new DecodingContext(i,s,r);c[t]=function decodeSymbolDictionary(e,t,n,i,s,r,o,a,c,l,h,d){if(e&&t)throw new Jbig2Error("symbol refinement with Huffman is not supported");const f=[];let u=0,m=log2(n.length+i);const g=h.decoder,p=h.contextCache;let b,x;if(e){b=getStandardTable(1);x=[];m=Math.max(m,1)}for(;f.length<i;){u+=e?r.tableDeltaHeight.decode(d):decodeInteger(p,"IADH",g);let i=0,s=0;const b=e?x.length:0;for(;;){const b=e?r.tableDeltaWidth.decode(d):decodeInteger(p,"IADW",g);if(null===b)break;i+=b;s+=i;let w;if(t){const s=decodeInteger(p,"IAAI",g);if(s>1)w=decodeTextRegion(e,t,i,u,0,s,1,n.concat(f),m,0,0,1,0,r,c,l,h,0,d);else{const e=decodeIAID(p,g,m),t=decodeInteger(p,"IARDX",g),s=decodeInteger(p,"IARDY",g);w=decodeRefinement(i,u,c,e<n.length?n[e]:f[e-n.length],t,s,!1,l,h)}f.push(w)}else if(e)x.push(i);else{w=decodeBitmap(!1,i,u,o,!1,null,a,h);f.push(w)}}if(e&&!t){const e=r.tableBitmapSize.decode(d);d.byteAlign();let t;if(0===e)t=readUncompressedBitmap(d,s,u);else{const n=d.end,i=d.position+e;d.end=i;t=decodeMMRBitmap(d,s,u,!1);d.end=n;d.position=i}const n=x.length;if(b===n-1)f.push(t);else{let e,i,s,r,o,a=0;for(e=b;e<n;e++){r=x[e];s=a+r;o=[];for(i=0;i<u;i++)o.push(t[i].subarray(a,s));f.push(o);a=s}}}}const w=[],y=[];let k,C,I=!1;const B=n.length+i;for(;y.length<B;){let t=e?b.decode(d):decodeInteger(p,"IAEX",g);for(;t--;)y.push(I);I=!I}for(k=0,C=n.length;k<C;k++)y[k]&&w.push(n[k]);for(let e=0;e<i;k++,e++)y[k]&&w.push(f[e]);return w}(e.huffman,e.refinement,l,e.numberOfNewSymbols,e.numberOfExportedSymbols,o,e.template,e.at,e.refinementTemplate,e.refinementAt,h,a)}onImmediateTextRegion(e,t,n,i,s){const r=e.info;let o,a;const c=this.symbols,l=[];for(const e of t){const t=c[e];t&&l.push(...t)}const h=log2(l.length);if(e.huffman){a=new Reader(n,i,s);o=function getTextRegionHuffmanTables(e,t,n,i,s){const r=[];for(let e=0;e<=34;e++){const t=s.readBits(4);r.push(new HuffmanLine([e,t,0,0]))}const o=new HuffmanTable(r,!1);r.length=0;for(let e=0;e<i;){const t=o.decode(s);if(t>=32){let n,i,o;switch(t){case 32:if(0===e)throw new Jbig2Error("no previous value in symbol ID table");i=s.readBits(2)+3;n=r[e-1].prefixLength;break;case 33:i=s.readBits(3)+3;n=0;break;case 34:i=s.readBits(7)+11;n=0;break;default:throw new Jbig2Error("invalid code length in symbol ID table")}for(o=0;o<i;o++){r.push(new HuffmanLine([e,n,0,0]));e++}}else{r.push(new HuffmanLine([e,t,0,0]));e++}}s.byteAlign();const a=new HuffmanTable(r,!1);let c,l,h,d=0;switch(e.huffmanFS){case 0:case 1:c=getStandardTable(e.huffmanFS+6);break;case 3:c=getCustomHuffmanTable(d,t,n);d++;break;default:throw new Jbig2Error("invalid Huffman FS selector")}switch(e.huffmanDS){case 0:case 1:case 2:l=getStandardTable(e.huffmanDS+8);break;case 3:l=getCustomHuffmanTable(d,t,n);d++;break;default:throw new Jbig2Error("invalid Huffman DS selector")}switch(e.huffmanDT){case 0:case 1:case 2:h=getStandardTable(e.huffmanDT+11);break;case 3:h=getCustomHuffmanTable(d,t,n);d++;break;default:throw new Jbig2Error("invalid Huffman DT selector")}if(e.refinement)throw new Jbig2Error("refinement with Huffman is not supported");return{symbolIDTable:a,tableFirstS:c,tableDeltaS:l,tableDeltaT:h}}(e,t,this.customTables,l.length,a)}const d=new DecodingContext(n,i,s),f=decodeTextRegion(e.huffman,e.refinement,r.width,r.height,e.defaultPixelValue,e.numberOfSymbolInstances,e.stripSize,l,h,e.transposed,e.dsOffset,e.referenceCorner,e.combinationOperator,o,e.refinementTemplate,e.refinementAt,d,e.logStripSize,a);this.drawBitmap(r,f)}onImmediateLosslessTextRegion(){this.onImmediateTextRegion(...arguments)}onPatternDictionary(e,t,n,i,s){let r=this.patterns;r||(this.patterns=r={});const o=new DecodingContext(n,i,s);r[t]=function decodePatternDictionary(e,t,n,i,s,r){const o=[];if(!e){o.push({x:-t,y:0});0===s&&o.push({x:-3,y:-1},{x:2,y:-2},{x:-2,y:-2})}const a=decodeBitmap(e,(i+1)*t,n,s,!1,null,o,r),c=[];for(let e=0;e<=i;e++){const i=[],s=t*e,r=s+t;for(let e=0;e<n;e++)i.push(a[e].subarray(s,r));c.push(i)}return c}(e.mmr,e.patternWidth,e.patternHeight,e.maxPatternIndex,e.template,o)}onImmediateHalftoneRegion(e,t,n,i,s){const r=this.patterns[t[0]],o=e.info,a=new DecodingContext(n,i,s),c=function decodeHalftoneRegion(e,t,n,i,s,r,o,a,c,l,h,d,f,u,m){if(o)throw new Jbig2Error("skip is not supported");if(0!==a)throw new Jbig2Error(`operator "${a}" is not supported in halftone region`);const g=[];let p,b,x;for(p=0;p<s;p++){x=new Uint8Array(i);if(r)for(b=0;b<i;b++)x[b]=r;g.push(x)}const w=t.length,y=t[0],k=y[0].length,C=y.length,I=log2(w),B=[];if(!e){B.push({x:n<=1?3:2,y:-1});0===n&&B.push({x:-3,y:-1},{x:2,y:-2},{x:-2,y:-2})}const P=[];let T,S,L,v,M,_,D,E,U,A,O;e&&(T=new Reader(m.data,m.start,m.end));for(p=I-1;p>=0;p--){S=e?decodeMMRBitmap(T,c,l,!0):decodeBitmap(!1,c,l,n,!1,null,B,m);P[p]=S}for(L=0;L<l;L++)for(v=0;v<c;v++){M=0;_=0;for(b=I-1;b>=0;b--){M^=P[b][L][v];_|=M<<b}D=t[_];E=h+L*u+v*f>>8;U=d+L*f-v*u>>8;if(E>=0&&E+k<=i&&U>=0&&U+C<=s)for(p=0;p<C;p++){O=g[U+p];A=D[p];for(b=0;b<k;b++)O[E+b]|=A[b]}else{let e,t;for(p=0;p<C;p++){t=U+p;if(!(t<0||t>=s)){O=g[t];A=D[p];for(b=0;b<k;b++){e=E+b;e>=0&&e<i&&(O[e]|=A[b])}}}}}return g}(e.mmr,r,e.template,o.width,o.height,e.defaultPixelValue,e.enableSkip,e.combinationOperator,e.gridWidth,e.gridHeight,e.gridOffsetX,e.gridOffsetY,e.gridVectorX,e.gridVectorY,a);this.drawBitmap(o,c)}onImmediateLosslessHalftoneRegion(){this.onImmediateHalftoneRegion(...arguments)}onTables(e,t,n,i){let s=this.customTables;s||(this.customTables=s={});s[e]=function decodeTablesSegment(e,t,n){const i=e[t],s=4294967295&readUint32(e,t+1),r=4294967295&readUint32(e,t+5),o=new Reader(e,t+9,n),a=1+(i>>1&7),c=1+(i>>4&7),l=[];let h,d,f=s;do{h=o.readBits(a);d=o.readBits(c);l.push(new HuffmanLine([f,h,d,0]));f+=1<<d}while(f<r);h=o.readBits(a);l.push(new HuffmanLine([s-1,h,32,0,"lower"]));h=o.readBits(a);l.push(new HuffmanLine([r,h,32,0]));if(1&i){h=o.readBits(a);l.push(new HuffmanLine([h,0]))}return new HuffmanTable(l,!1)}(t,n,i)}}class HuffmanLine{constructor(e){if(2===e.length){this.isOOB=!0;this.rangeLow=0;this.prefixLength=e[0];this.rangeLength=0;this.prefixCode=e[1];this.isLowerRange=!1}else{this.isOOB=!1;this.rangeLow=e[0];this.prefixLength=e[1];this.rangeLength=e[2];this.prefixCode=e[3];this.isLowerRange="lower"===e[4]}}}class HuffmanTreeNode{constructor(e){this.children=[];if(e){this.isLeaf=!0;this.rangeLength=e.rangeLength;this.rangeLow=e.rangeLow;this.isLowerRange=e.isLowerRange;this.isOOB=e.isOOB}else this.isLeaf=!1}buildTree(e,t){const n=e.prefixCode>>t&1;if(t<=0)this.children[n]=new HuffmanTreeNode(e);else{let i=this.children[n];i||(this.children[n]=i=new HuffmanTreeNode(null));i.buildTree(e,t-1)}}decodeNode(e){if(this.isLeaf){if(this.isOOB)return null;const t=e.readBits(this.rangeLength);return this.rangeLow+(this.isLowerRange?-t:t)}const t=this.children[e.readBit()];if(!t)throw new Jbig2Error("invalid Huffman data");return t.decodeNode(e)}}class HuffmanTable{constructor(e,t){t||this.assignPrefixCodes(e);this.rootNode=new HuffmanTreeNode(null);for(let t=0,n=e.length;t<n;t++){const n=e[t];n.prefixLength>0&&this.rootNode.buildTree(n,n.prefixLength-1)}}decode(e){return this.rootNode.decodeNode(e)}assignPrefixCodes(e){const t=e.length;let n=0;for(let i=0;i<t;i++)n=Math.max(n,e[i].prefixLength);const i=new Uint32Array(n+1);for(let n=0;n<t;n++)i[e[n].prefixLength]++;let s,r,o,a=1,c=0;i[0]=0;for(;a<=n;){c=c+i[a-1]<<1;s=c;r=0;for(;r<t;){o=e[r];if(o.prefixLength===a){o.prefixCode=s;s++}r++}a++}}}const y={};function getStandardTable(e){let t,n=y[e];if(n)return n;switch(e){case 1:t=[[0,1,4,0],[16,2,8,2],[272,3,16,6],[65808,3,32,7]];break;case 2:t=[[0,1,0,0],[1,2,0,2],[2,3,0,6],[3,4,3,14],[11,5,6,30],[75,6,32,62],[6,63]];break;case 3:t=[[-256,8,8,254],[0,1,0,0],[1,2,0,2],[2,3,0,6],[3,4,3,14],[11,5,6,30],[-257,8,32,255,"lower"],[75,7,32,126],[6,62]];break;case 4:t=[[1,1,0,0],[2,2,0,2],[3,3,0,6],[4,4,3,14],[12,5,6,30],[76,5,32,31]];break;case 5:t=[[-255,7,8,126],[1,1,0,0],[2,2,0,2],[3,3,0,6],[4,4,3,14],[12,5,6,30],[-256,7,32,127,"lower"],[76,6,32,62]];break;case 6:t=[[-2048,5,10,28],[-1024,4,9,8],[-512,4,8,9],[-256,4,7,10],[-128,5,6,29],[-64,5,5,30],[-32,4,5,11],[0,2,7,0],[128,3,7,2],[256,3,8,3],[512,4,9,12],[1024,4,10,13],[-2049,6,32,62,"lower"],[2048,6,32,63]];break;case 7:t=[[-1024,4,9,8],[-512,3,8,0],[-256,4,7,9],[-128,5,6,26],[-64,5,5,27],[-32,4,5,10],[0,4,5,11],[32,5,5,28],[64,5,6,29],[128,4,7,12],[256,3,8,1],[512,3,9,2],[1024,3,10,3],[-1025,5,32,30,"lower"],[2048,5,32,31]];break;case 8:t=[[-15,8,3,252],[-7,9,1,508],[-5,8,1,253],[-3,9,0,509],[-2,7,0,124],[-1,4,0,10],[0,2,1,0],[2,5,0,26],[3,6,0,58],[4,3,4,4],[20,6,1,59],[22,4,4,11],[38,4,5,12],[70,5,6,27],[134,5,7,28],[262,6,7,60],[390,7,8,125],[646,6,10,61],[-16,9,32,510,"lower"],[1670,9,32,511],[2,1]];break;case 9:t=[[-31,8,4,252],[-15,9,2,508],[-11,8,2,253],[-7,9,1,509],[-5,7,1,124],[-3,4,1,10],[-1,3,1,2],[1,3,1,3],[3,5,1,26],[5,6,1,58],[7,3,5,4],[39,6,2,59],[43,4,5,11],[75,4,6,12],[139,5,7,27],[267,5,8,28],[523,6,8,60],[779,7,9,125],[1291,6,11,61],[-32,9,32,510,"lower"],[3339,9,32,511],[2,0]];break;case 10:t=[[-21,7,4,122],[-5,8,0,252],[-4,7,0,123],[-3,5,0,24],[-2,2,2,0],[2,5,0,25],[3,6,0,54],[4,7,0,124],[5,8,0,253],[6,2,6,1],[70,5,5,26],[102,6,5,55],[134,6,6,56],[198,6,7,57],[326,6,8,58],[582,6,9,59],[1094,6,10,60],[2118,7,11,125],[-22,8,32,254,"lower"],[4166,8,32,255],[2,2]];break;case 11:t=[[1,1,0,0],[2,2,1,2],[4,4,0,12],[5,4,1,13],[7,5,1,28],[9,5,2,29],[13,6,2,60],[17,7,2,122],[21,7,3,123],[29,7,4,124],[45,7,5,125],[77,7,6,126],[141,7,32,127]];break;case 12:t=[[1,1,0,0],[2,2,0,2],[3,3,1,6],[5,5,0,28],[6,5,1,29],[8,6,1,60],[10,7,0,122],[11,7,1,123],[13,7,2,124],[17,7,3,125],[25,7,4,126],[41,8,5,254],[73,8,32,255]];break;case 13:t=[[1,1,0,0],[2,3,0,4],[3,4,0,12],[4,5,0,28],[5,4,1,13],[7,3,3,5],[15,6,1,58],[17,6,2,59],[21,6,3,60],[29,6,4,61],[45,6,5,62],[77,7,6,126],[141,7,32,127]];break;case 14:t=[[-2,3,0,4],[-1,3,0,5],[0,1,0,0],[1,3,0,6],[2,3,0,7]];break;case 15:t=[[-24,7,4,124],[-8,6,2,60],[-4,5,1,28],[-2,4,0,12],[-1,3,0,4],[0,1,0,0],[1,3,0,5],[2,4,0,13],[3,5,1,29],[5,6,2,61],[9,7,4,125],[-25,7,32,126,"lower"],[25,7,32,127]];break;default:throw new Jbig2Error(`standard table B.${e} does not exist`)}for(let e=0,n=t.length;e<n;e++)t[e]=new HuffmanLine(t[e]);n=new HuffmanTable(t,!0);y[e]=n;return n}class Reader{constructor(e,t,n){this.data=e;this.start=t;this.end=n;this.position=t;this.shift=-1;this.currentByte=0}readBit(){if(this.shift<0){if(this.position>=this.end)throw new Jbig2Error("end of data while reading bit");this.currentByte=this.data[this.position++];this.shift=7}const e=this.currentByte>>this.shift&1;this.shift--;return e}readBits(e){let t,n=0;for(t=e-1;t>=0;t--)n|=this.readBit()<<t;return n}byteAlign(){this.shift=-1}next(){return this.position>=this.end?-1:this.data[this.position++]}}function getCustomHuffmanTable(e,t,n){let i=0;for(let s=0,r=t.length;s<r;s++){const r=n[t[s]];if(r){if(e===i)return r;i++}}throw new Jbig2Error("can't find custom Huffman table")}function readUncompressedBitmap(e,t,n){const i=[];for(let s=0;s<n;s++){const n=new Uint8Array(t);i.push(n);for(let i=0;i<t;i++)n[i]=e.readBit();e.byteAlign()}return i}function decodeMMRBitmap(e,t,n,i){const s=new CCITTFaxDecoder(e,{K:-1,Columns:t,Rows:n,BlackIs1:!0,EndOfBlock:i}),r=[];let o,a=!1;for(let e=0;e<n;e++){const e=new Uint8Array(t);r.push(e);let n=-1;for(let i=0;i<t;i++){if(n<0){o=s.readNextChar();if(-1===o){o=0;a=!0}n=7}e[i]=o>>n&1;n--}}if(i&&!a){const e=5;for(let t=0;t<e&&-1!==s.readNextChar();t++);}return r}class Jbig2Image{parseChunks(e){return function parseJbig2Chunks(e){const t=new SimpleSegmentVisitor;for(let n=0,i=e.length;n<i;n++){const i=e[n];processSegments(readSegments({},i.data,i.start,i.end),t)}return t.buffer}(e)}parse(e){const{imgData:t,width:n,height:i}=function parseJbig2(e){const t=e.length;let n=0;if(151!==e[n]||74!==e[n+1]||66!==e[n+2]||50!==e[n+3]||13!==e[n+4]||10!==e[n+5]||26!==e[n+6]||10!==e[n+7])throw new Jbig2Error("parseJbig2 - invalid header.");const i=Object.create(null);n+=8;const s=e[n++];i.randomAccess=!(1&s);if(!(2&s)){i.numberOfPages=readUint32(e,n);n+=4}const r=readSegments(i,e,n,t),o=new SimpleSegmentVisitor;processSegments(r,o);const{width:a,height:c}=o.currentPageInfo,l=o.buffer,h=new Uint8ClampedArray(a*c);let d=0,f=0;for(let e=0;e<c;e++){let e,t=0;for(let n=0;n<a;n++){if(!t){t=128;e=l[f++]}h[d++]=e&t?0:255;t>>=1}}return{imgData:h,width:a,height:c}}(e);this.width=n;this.height=i;return t}}class JpegError extends i{constructor(e){super(`JPEG error: ${e}`,"JpegError")}}class DNLMarkerError extends i{constructor(e,t){super(e,"DNLMarkerError");this.scanLines=t}}class EOIMarkerError extends i{constructor(e){super(e,"EOIMarkerError")}}const k=new Uint8Array([0,1,8,16,9,2,3,10,17,24,32,25,18,11,4,5,12,19,26,33,40,48,41,34,27,20,13,6,7,14,21,28,35,42,49,56,57,50,43,36,29,22,15,23,30,37,44,51,58,59,52,45,38,31,39,46,53,60,61,54,47,55,62,63]),C=4017,I=799,B=3406,P=2276,T=1567,S=3784,L=5793,v=2896;function buildHuffmanTable(e,t){let n,i,s=0,r=16;for(;r>0&&!e[r-1];)r--;const o=[{children:[],index:0}];let a,c=o[0];for(n=0;n<r;n++){for(i=0;i<e[n];i++){c=o.pop();c.children[c.index]=t[s];for(;c.index>0;)c=o.pop();c.index++;o.push(c);for(;o.length<=n;){o.push(a={children:[],index:0});c.children[c.index]=a.children;c=a}s++}if(n+1<r){o.push(a={children:[],index:0});c.children[c.index]=a.children;c=a}}return o[0].children}function getBlockBufferOffset(e,t,n){return 64*((e.blocksPerLine+1)*t+n)}function decodeScan(e,t,n,i,s,r,o,a,c,l=!1){const h=n.mcusPerLine,d=n.progressive,f=t;let u=0,m=0;function readBit(){if(m>0){m--;return u>>m&1}u=e[t++];if(255===u){const i=e[t++];if(i){if(220===i&&l){const i=readUint16(e,t+=2);t+=2;if(i>0&&i!==n.scanLines)throw new DNLMarkerError("Found DNL marker (0xFFDC) while parsing scan data",i)}else if(217===i){if(l){const e=x*(8===n.precision?8:0);if(e>0&&Math.round(n.scanLines/e)>=5)throw new DNLMarkerError("Found EOI marker (0xFFD9) while parsing scan data, possibly caused by incorrect `scanLines` parameter",e)}throw new EOIMarkerError("Found EOI marker (0xFFD9) while parsing scan data")}throw new JpegError(`unexpected marker ${(u<<8|i).toString(16)}`)}}m=7;return u>>>7}function decodeHuffman(e){let t=e;for(;;){t=t[readBit()];switch(typeof t){case"number":return t;case"object":continue}throw new JpegError("invalid huffman sequence")}}function receive(e){let t=0;for(;e>0;){t=t<<1|readBit();e--}return t}function receiveAndExtend(e){if(1===e)return 1===readBit()?1:-1;const t=receive(e);return t>=1<<e-1?t:t+(-1<<e)+1}let g=0;let p,b=0;let x=0;function decodeMcu(e,t,n,i,s){const r=n%h;x=(n/h|0)*e.v+i;const o=r*e.h+s;t(e,getBlockBufferOffset(e,x,o))}function decodeBlock(e,t,n){x=n/e.blocksPerLine|0;const i=n%e.blocksPerLine;t(e,getBlockBufferOffset(e,x,i))}const w=i.length;let y,C,I,B,P,T;T=d?0===r?0===a?function decodeDCFirst(e,t){const n=decodeHuffman(e.huffmanTableDC),i=0===n?0:receiveAndExtend(n)<<c;e.blockData[t]=e.pred+=i}:function decodeDCSuccessive(e,t){e.blockData[t]|=readBit()<<c}:0===a?function decodeACFirst(e,t){if(g>0){g--;return}let n=r;const i=o;for(;n<=i;){const i=decodeHuffman(e.huffmanTableAC),s=15&i,r=i>>4;if(0===s){if(r<15){g=receive(r)+(1<<r)-1;break}n+=16;continue}n+=r;const o=k[n];e.blockData[t+o]=receiveAndExtend(s)*(1<<c);n++}}:function decodeACSuccessive(e,t){let n=r;const i=o;let s,a,l=0;for(;n<=i;){const i=t+k[n],r=e.blockData[i]<0?-1:1;switch(b){case 0:a=decodeHuffman(e.huffmanTableAC);s=15&a;l=a>>4;if(0===s)if(l<15){g=receive(l)+(1<<l);b=4}else{l=16;b=1}else{if(1!==s)throw new JpegError("invalid ACn encoding");p=receiveAndExtend(s);b=l?2:3}continue;case 1:case 2:if(e.blockData[i])e.blockData[i]+=r*(readBit()<<c);else{l--;0===l&&(b=2===b?3:0)}break;case 3:if(e.blockData[i])e.blockData[i]+=r*(readBit()<<c);else{e.blockData[i]=p<<c;b=0}break;case 4:e.blockData[i]&&(e.blockData[i]+=r*(readBit()<<c))}n++}if(4===b){g--;0===g&&(b=0)}}:function decodeBaseline(e,t){const n=decodeHuffman(e.huffmanTableDC),i=0===n?0:receiveAndExtend(n);e.blockData[t]=e.pred+=i;let s=1;for(;s<64;){const n=decodeHuffman(e.huffmanTableAC),i=15&n,r=n>>4;if(0===i){if(r<15)break;s+=16;continue}s+=r;const o=k[s];e.blockData[t+o]=receiveAndExtend(i);s++}};let S,L=0;const v=1===w?i[0].blocksPerLine*i[0].blocksPerColumn:h*n.mcusPerColumn;let M,_;for(;L<=v;){const n=s?Math.min(v-L,s):v;if(n>0){for(C=0;C<w;C++)i[C].pred=0;g=0;if(1===w){y=i[0];for(P=0;P<n;P++){decodeBlock(y,T,L);L++}}else for(P=0;P<n;P++){for(C=0;C<w;C++){y=i[C];M=y.h;_=y.v;for(I=0;I<_;I++)for(B=0;B<M;B++)decodeMcu(y,T,L,I,B)}L++}}m=0;S=findNextFileMarker(e,t);if(!S)break;if(S.invalid){util_warn(`decodeScan - ${n>0?"unexpected":"excessive"} MCU data, current marker is: ${S.invalid}`);t=S.offset}if(!(S.marker>=65488&&S.marker<=65495))break;t+=2}return t-f}function quantizeAndInverse(e,t,n){const i=e.quantizationTable,s=e.blockData;let r,o,a,c,l,h,d,f,u,m,g,p,b,x,w,y,k;if(!i)throw new JpegError("missing required Quantization Table.");for(let e=0;e<64;e+=8){u=s[t+e];m=s[t+e+1];g=s[t+e+2];p=s[t+e+3];b=s[t+e+4];x=s[t+e+5];w=s[t+e+6];y=s[t+e+7];u*=i[e];if(0!=(m|g|p|b|x|w|y)){m