/** * @licstart The following is the entire license notice for the * JavaScript code in this page * * Copyright 2024 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 A={d:(I,g)=>{for(var B in g)A.o(g,B)&&!A.o(I,B)&&Object.defineProperty(I,B,{enumerable:!0,get:g[B]})},o:(A,I)=>Object.prototype.hasOwnProperty.call(A,I)},__webpack_exports__ = globalThis.pdfjsImageDecoders = {};A.d(__webpack_exports__,{Jbig2Error:()=>Jbig2Error,Jbig2Image:()=>Jbig2Image,JpegError:()=>JpegError,JpegImage:()=>JpegImage,JpxError:()=>JpxError,JpxImage:()=>JpxImage,VerbosityLevel:()=>I,getVerbosityLevel:()=>getVerbosityLevel,setVerbosityLevel:()=>setVerbosityLevel});"object"!=typeof process||process+""!="[object process]"||process.versions.nw||process.versions.electron&&process.type&&process.type;const I={ERRORS:0,WARNINGS:1,INFOS:5};let g=I.WARNINGS;function setVerbosityLevel(A){Number.isInteger(A)&&(g=A)}function getVerbosityLevel(){return g}function info(A){g>=I.INFOS&&console.log(`Info: ${A}`)}function util_warn(A){g>=I.WARNINGS&&console.log(`Warning: ${A}`)}function unreachable(A){throw new Error(A)}function shadow(A,I,g,B=!1){Object.defineProperty(A,I,{value:g,enumerable:!B,configurable:!0,writable:!1});return g}const B=function BaseExceptionClosure(){function BaseException(A,I){this.message=A;this.name=I}BaseException.prototype=new Error;BaseException.constructor=BaseException;return BaseException}();class FormatError extends B{constructor(A){super(A,"FormatError")}}function bytesToString(A){"object"==typeof A&&void 0!==A?.length||unreachable("Invalid argument for bytesToString");const I=A.length,g=8192;if(IA.toString(16).padStart(2,"0")));"function"!=typeof Promise.try&&(Promise.try=function(A,...I){return new Promise((g=>{g(A(...I))}))});Symbol("CIRCULAR_REF"),Symbol("EOF");Object.create(null),Object.create(null),Object.create(null);Symbol.iterator;Symbol.iterator;Symbol.iterator;class base_stream_BaseStream{get length(){unreachable("Abstract getter `length` accessed")}get isEmpty(){unreachable("Abstract getter `isEmpty` accessed")}get isDataLoaded(){return shadow(this,"isDataLoaded",!0)}getByte(){unreachable("Abstract method `getByte` called")}getBytes(A){unreachable("Abstract method `getBytes` called")}async getImageData(A,I){return this.getBytes(A,I)}async asyncGetBytes(){unreachable("Abstract method `asyncGetBytes` called")}get isAsync(){return!1}get canAsyncDecodeImageFromBuffer(){return!1}async getTransferableImage(){return null}peekByte(){const A=this.getByte();-1!==A&&this.pos--;return A}peekBytes(A){const I=this.getBytes(A);this.pos-=I.length;return I}getUint16(){const A=this.getByte(),I=this.getByte();return-1===A||-1===I?-1:(A<<8)+I}getInt32(){return(this.getByte()<<24)+(this.getByte()<<16)+(this.getByte()<<8)+this.getByte()}getByteRange(A,I){unreachable("Abstract method `getByteRange` called")}getString(A){return bytesToString(this.getBytes(A))}skip(A){this.pos+=A||1}reset(){unreachable("Abstract method `reset` called")}moveStart(){unreachable("Abstract method `moveStart` called")}makeSubStream(A,I,g=null){unreachable("Abstract method `makeSubStream` called")}getBaseStreams(){return null}}function log2(A){return A>0?Math.ceil(Math.log2(A)):0}function readInt8(A,I){return A[I]<<24>>24}function readUint16(A,I){return A[I]<<8|A[I+1]}function readUint32(A,I){return(A[I]<<24|A[I+1]<<16|A[I+2]<<8|A[I+3])>>>0}const Q=[{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(A,I,g){this.data=A;this.bp=I;this.dataEnd=g;this.chigh=A[I];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 A=this.data;let I=this.bp;if(255===A[I])if(A[I+1]>143){this.clow+=65280;this.ct=8}else{I++;this.clow+=A[I]<<9;this.ct=7;this.bp=I}else{I++;this.clow+=I65535){this.chigh+=this.clow>>16;this.clow&=65535}}readBit(A,I){let g=A[I]>>1,B=1&A[I];const C=Q[g],E=C.qe;let i,o=this.a-E;if(this.chigh>15&1;this.clow=this.clow<<1&65535;this.ct--}while(!(32768&o));this.a=o;A[I]=g<<1|B;return i}}const C=-1,E=[[-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]],i=[[-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]],o=[[-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]],D=[[-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]],F=[[-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(A,I={}){if("function"!=typeof A?.next)throw new Error('CCITTFaxDecoder - invalid "source" parameter.');this.source=A;this.eof=!1;this.encoding=I.K||0;this.eoline=I.EndOfLine||!1;this.byteAlign=I.EncodedByteAlign||!1;this.columns=I.Columns||1728;this.rows=I.Rows||0;this.eoblock=I.EndOfBlock??!0;this.black=I.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 g;for(;0===(g=this._lookBits(12));)this._eatBits(1);1===g&&this._eatBits(12);if(this.encoding>0){this.nextLine2D=!this._lookBits(1);this._eatBits(1)}}readNextChar(){if(this.eof)return-1;const A=this.refLine,I=this.codingLine,g=this.columns;let B,Q,E,i,o;if(0===this.outputBits){this.rowsDone&&(this.eof=!0);if(this.eof)return-1;this.err=!1;let E,o,D;if(this.nextLine2D){for(i=0;I[i]=64);do{o+=D=this._getWhiteCode()}while(D>=64)}else{do{E+=D=this._getWhiteCode()}while(D>=64);do{o+=D=this._getBlackCode()}while(D>=64)}this._addPixels(I[this.codingPos]+E,Q);I[this.codingPos]0?--B:++B;for(;A[B]<=I[this.codingPos]&&A[B]0?--B:++B;for(;A[B]<=I[this.codingPos]&&A[B]0?--B:++B;for(;A[B]<=I[this.codingPos]&&A[B]=64);else do{E+=D=this._getWhiteCode()}while(D>=64);this._addPixels(I[this.codingPos]+E,Q);Q^=1}}let h=!1;this.byteAlign&&(this.inputBits&=-8);if(this.eoblock||this.row!==this.rows-1){E=this._lookBits(12);if(this.eoline)for(;E!==C&&1!==E;){this._eatBits(1);E=this._lookBits(12)}else for(;0===E;){this._eatBits(1);E=this._lookBits(12)}if(1===E){this._eatBits(12);h=!0}else E===C&&(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){E=this._lookBits(12);if(1===E){this._eatBits(12);if(this.encoding>0){this._lookBits(1);this._eatBits(1)}if(this.encoding>=0)for(i=0;i<4;++i){E=this._lookBits(12);1!==E&&info("bad rtc code: "+E);this._eatBits(12);if(this.encoding>0){this._lookBits(1);this._eatBits(1)}}this.eof=!0}}else if(this.err&&this.eoline){for(;;){E=this._lookBits(13);if(E===C){this.eof=!0;return-1}if(E>>1==1)break;this._eatBits(1)}this._eatBits(12);if(this.encoding>0){this._eatBits(1);this.nextLine2D=!(1&E)}}this.outputBits=I[0]>0?I[this.codingPos=0]:I[this.codingPos=1];this.row++}if(this.outputBits>=8){o=1&this.codingPos?0:255;this.outputBits-=8;if(0===this.outputBits&&I[this.codingPos]E){o<<=E;1&this.codingPos||(o|=255>>8-E);this.outputBits-=E;E=0}else{o<<=this.outputBits;1&this.codingPos||(o|=255>>8-this.outputBits);E-=this.outputBits;this.outputBits=0;if(I[this.codingPos]0){o<<=E;E=0}}}while(E)}this.black&&(o^=255);return o}_addPixels(A,I){const g=this.codingLine;let B=this.codingPos;if(A>g[B]){if(A>this.columns){info("row is wrong length");this.err=!0;A=this.columns}1&B^I&&++B;g[B]=A}this.codingPos=B}_addPixelsNeg(A,I){const g=this.codingLine;let B=this.codingPos;if(A>g[B]){if(A>this.columns){info("row is wrong length");this.err=!0;A=this.columns}1&B^I&&++B;g[B]=A}else if(A0&&A=Q){const I=g[A-Q];if(I[0]===B){this._eatBits(B);return[!0,I[1],!0]}}}return[!1,0,!1]}_getTwoDimCode(){let A,I=0;if(this.eoblock){I=this._lookBits(7);A=E[I];if(A?.[0]>0){this._eatBits(A[0]);return A[1]}}else{const A=this._findTableCode(1,7,E);if(A[0]&&A[2])return A[1]}info("Bad two dim code");return C}_getWhiteCode(){let A,I=0;if(this.eoblock){I=this._lookBits(12);if(I===C)return 1;A=I>>5?o[I>>3]:i[I];if(A[0]>0){this._eatBits(A[0]);return A[1]}}else{let A=this._findTableCode(1,9,o);if(A[0])return A[1];A=this._findTableCode(11,12,i);if(A[0])return A[1]}info("bad white code");this._eatBits(1);return 1}_getBlackCode(){let A,I;if(this.eoblock){A=this._lookBits(13);if(A===C)return 1;I=A>>7?!(A>>9)&&A>>7?h[(A>>1)-64]:F[A>>7]:D[A];if(I[0]>0){this._eatBits(I[0]);return I[1]}}else{let A=this._findTableCode(2,6,F);if(A[0])return A[1];A=this._findTableCode(7,12,h,64);if(A[0])return A[1];A=this._findTableCode(10,13,D);if(A[0])return A[1]}info("bad black code");this._eatBits(1);return 1}_lookBits(A){let I;for(;this.inputBits>16-A;this.inputBuf=this.inputBuf<<8|I;this.inputBits+=8}return this.inputBuf>>this.inputBits-A&65535>>16-A}_eatBits(A){(this.inputBits-=A)<0&&(this.inputBits=0)}}class Jbig2Error extends B{constructor(A){super(A,"Jbig2Error")}}class ContextCache{getContexts(A){return A in this?this[A]:this[A]=new Int8Array(65536)}}class DecodingContext{constructor(A,I,g){this.data=A;this.start=I;this.end=g}get decoder(){return shadow(this,"decoder",new ArithmeticDecoder(this.data,this.start,this.end))}get contextCache(){return shadow(this,"contextCache",new ContextCache)}}function decodeInteger(A,I,g){const B=A.getContexts(I);let Q=1;function readBits(A){let I=0;for(let C=0;C>>0}const C=readBits(1),E=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 i;0===C?i=E:E>0&&(i=-E);return i>=-2147483648&&i<=2147483647?i:null}function decodeIAID(A,I,g){const B=A.getContexts("IAID");let Q=1;for(let A=0;A=H&&l=e){x=x<<1&S;for(R=0;R=0&&f=0){b=L[q][f];b&&(x|=b<=A?D<<=1:D=D<<1|N[i][o]}for(G=0;G=U||o<0||o>=c?D<<=1:D=D<<1|B[i][o]}const a=t.readBit(Y,D);I[E]=a}}return N}function decodeTextRegion(A,I,g,B,Q,C,E,i,o,D,h,F,s,G,a,y,w,R,S){if(A&&I)throw new Jbig2Error("refinement with Huffman is not supported");const J=[];let c,U;for(c=0;c1&&(Q=A?S.readBits(R):decodeInteger(N,"IAIT",k));const C=E*t+Q,Y=A?G.symbolIDTable.decode(S):decodeIAID(N,k,o),H=I&&(A?S.readBit():decodeInteger(N,"IARI",k));let e=i[Y],M=e[0].length,n=e.length;if(H){const A=decodeInteger(N,"IARDW",k),I=decodeInteger(N,"IARDH",k);M+=A;n+=I;e=decodeRefinement(M,n,a,e,(A>>1)+decodeInteger(N,"IARDX",k),(I>>1)+decodeInteger(N,"IARDY",k),!1,y,w)}let K=0;D?1&F?K=n-1:B+=n-1:F>1?B+=M-1:K=M-1;const L=C-(1&F?0:n-1),d=B-(2&F?M-1:0);let r,l,q;if(D)for(r=0;r>5&7;const o=[31&E];let D=I+6;if(7===E){i=536870911&readUint32(A,D-1);D+=3;let I=i+7>>3;o[0]=A[D++];for(;--I>0;)o.push(A[D++])}else if(5===E||6===E)throw new Jbig2Error("invalid referred-to flags");g.retainBits=o;let h=4;g.number<=256?h=1:g.number<=65536&&(h=2);const F=[];let G,a;for(G=0;G>>24&255;C[3]=I.height>>16&255;C[4]=I.height>>8&255;C[5]=255&I.height;for(G=D,a=A.length;G>2&3;A.huffmanDWSelector=I>>4&3;A.bitmapSizeSelector=I>>6&1;A.aggregationInstancesSelector=I>>7&1;A.bitmapCodingContextUsed=!!(256&I);A.bitmapCodingContextRetained=!!(512&I);A.template=I>>10&3;A.refinementTemplate=I>>12&1;D+=2;if(!A.huffman){o=0===A.template?4:1;E=[];for(i=0;i>2&3;h.stripSize=1<>4&3;h.transposed=!!(64&F);h.combinationOperator=F>>7&3;h.defaultPixelValue=F>>9&1;h.dsOffset=F<<17>>27;h.refinementTemplate=F>>15&1;if(h.huffman){const A=readUint16(B,D);D+=2;h.huffmanFS=3&A;h.huffmanDS=A>>2&3;h.huffmanDT=A>>4&3;h.huffmanRefinementDW=A>>6&3;h.huffmanRefinementDH=A>>8&3;h.huffmanRefinementDX=A>>10&3;h.huffmanRefinementDY=A>>12&3;h.huffmanRefinementSizeSelector=!!(16384&A)}if(h.refinement&&!h.refinementTemplate){E=[];for(i=0;i<2;i++){E.push({x:readInt8(B,D),y:readInt8(B,D+1)});D+=2}h.refinementAt=E}h.numberOfSymbolInstances=readUint32(B,D);D+=4;C=[h,g.referredTo,B,D,Q];break;case 16:const s={},G=B[D++];s.mmr=!!(1&G);s.template=G>>1&3;s.patternWidth=B[D++];s.patternHeight=B[D++];s.maxPatternIndex=readUint32(B,D);D+=4;C=[s,g.number,B,D,Q];break;case 22:case 23:const a={};a.info=readRegionSegmentInformation(B,D);D+=R;const y=B[D++];a.mmr=!!(1&y);a.template=y>>1&3;a.enableSkip=!!(8&y);a.combinationOperator=y>>4&7;a.defaultPixelValue=y>>7&1;a.gridWidth=readUint32(B,D);D+=4;a.gridHeight=readUint32(B,D);D+=4;a.gridOffsetX=4294967295&readUint32(B,D);D+=4;a.gridOffsetY=4294967295&readUint32(B,D);D+=4;a.gridVectorX=readUint16(B,D);D+=2;a.gridVectorY=readUint16(B,D);D+=2;C=[a,g.referredTo,B,D,Q];break;case 38:case 39:const w={};w.info=readRegionSegmentInformation(B,D);D+=R;const S=B[D++];w.mmr=!!(1&S);w.template=S>>1&3;w.prediction=!!(8&S);if(!w.mmr){o=0===w.template?4:1;E=[];for(i=0;i>2&1;J.combinationOperator=c>>3&3;J.requiresBuffer=!!(32&c);J.combinationOperatorOverride=!!(64&c);C=[J];break;case 49:case 50:case 51:case 62:break;case 53:C=[g.number,B,D,Q];break;default:throw new Jbig2Error(`segment type ${g.typeName}(${g.type}) is not implemented`)}const h="on"+g.typeName;h in I&&I[h].apply(I,C)}function processSegments(A,I){for(let g=0,B=A.length;g>3,g=new Uint8ClampedArray(I*A.height);A.defaultPixelValue&&g.fill(255);this.buffer=g}drawBitmap(A,I){const g=this.currentPageInfo,B=A.width,Q=A.height,C=g.width+7>>3,E=g.combinationOperatorOverride?A.combinationOperator:g.combinationOperator,i=this.buffer,o=128>>(7&A.x);let D,h,F,s,G=A.y*C+(A.x>>3);switch(E){case 0:for(D=0;D>=1;if(!F){F=128;s++}}G+=C}break;case 2:for(D=0;D>=1;if(!F){F=128;s++}}G+=C}break;default:throw new Jbig2Error(`operator ${E} is not supported`)}}onImmediateGenericRegion(A,I,g,B){const Q=A.info,C=new DecodingContext(I,g,B),E=decodeBitmap(A.mmr,Q.width,Q.height,A.template,A.prediction,null,A.at,C);this.drawBitmap(Q,E)}onImmediateLosslessGenericRegion(){this.onImmediateGenericRegion(...arguments)}onSymbolDictionary(A,I,g,B,Q,C){let E,i;if(A.huffman){E=function getSymbolDictionaryHuffmanTables(A,I,g){let B,Q,C,E,i=0;switch(A.huffmanDHSelector){case 0:case 1:B=getStandardTable(A.huffmanDHSelector+4);break;case 3:B=getCustomHuffmanTable(i,I,g);i++;break;default:throw new Jbig2Error("invalid Huffman DH selector")}switch(A.huffmanDWSelector){case 0:case 1:Q=getStandardTable(A.huffmanDWSelector+2);break;case 3:Q=getCustomHuffmanTable(i,I,g);i++;break;default:throw new Jbig2Error("invalid Huffman DW selector")}if(A.bitmapSizeSelector){C=getCustomHuffmanTable(i,I,g);i++}else C=getStandardTable(1);E=A.aggregationInstancesSelector?getCustomHuffmanTable(i,I,g):getStandardTable(1);return{tableDeltaHeight:B,tableDeltaWidth:Q,tableBitmapSize:C,tableAggregateInstances:E}}(A,g,this.customTables);i=new Reader(B,Q,C)}let o=this.symbols;o||(this.symbols=o={});const D=[];for(const A of g){const I=o[A];I&&D.push(...I)}const h=new DecodingContext(B,Q,C);o[I]=function decodeSymbolDictionary(A,I,g,B,Q,C,E,i,o,D,h,F){if(A&&I)throw new Jbig2Error("symbol refinement with Huffman is not supported");const s=[];let G=0,a=log2(g.length+B);const y=h.decoder,w=h.contextCache;let R,S;if(A){R=getStandardTable(1);S=[];a=Math.max(a,1)}for(;s.length1)J=decodeTextRegion(A,I,B,G,0,Q,1,g.concat(s),a,0,0,1,0,C,o,D,h,0,F);else{const A=decodeIAID(w,y,a),I=decodeInteger(w,"IARDX",y),Q=decodeInteger(w,"IARDY",y);J=decodeRefinement(B,G,o,A=32){let g,B,E;switch(I){case 32:if(0===A)throw new Jbig2Error("no previous value in symbol ID table");B=Q.readBits(2)+3;g=C[A-1].prefixLength;break;case 33:B=Q.readBits(3)+3;g=0;break;case 34:B=Q.readBits(7)+11;g=0;break;default:throw new Jbig2Error("invalid code length in symbol ID table")}for(E=0;E=0;w--){e=A?decodeMMRBitmap(H,o,D,!0):decodeBitmap(!1,o,D,g,!1,null,t,a);Y[w]=e}for(M=0;M=0;R--){K^=Y[R][M][n];L|=K<>8;l=F+M*s-n*G>>8;if(r>=0&&r+U<=B&&l>=0&&l+k<=Q)for(w=0;w=Q)){f=y[I];q=d[w];for(R=0;R=0&&A>1&7),o=1+(B>>4&7),D=[];let h,F,s=Q;do{h=E.readBits(i);F=E.readBits(o);D.push(new HuffmanLine([s,h,F,0]));s+=1<>I&1;if(I<=0)this.children[g]=new HuffmanTreeNode(A);else{let B=this.children[g];B||(this.children[g]=B=new HuffmanTreeNode(null));B.buildTree(A,I-1)}}decodeNode(A){if(this.isLeaf){if(this.isOOB)return null;const I=A.readBits(this.rangeLength);return this.rangeLow+(this.isLowerRange?-I:I)}const I=this.children[A.readBit()];if(!I)throw new Jbig2Error("invalid Huffman data");return I.decodeNode(A)}}class HuffmanTable{constructor(A,I){I||this.assignPrefixCodes(A);this.rootNode=new HuffmanTreeNode(null);for(let I=0,g=A.length;I0&&this.rootNode.buildTree(g,g.prefixLength-1)}}decode(A){return this.rootNode.decodeNode(A)}assignPrefixCodes(A){const I=A.length;let g=0;for(let B=0;B=this.end)throw new Jbig2Error("end of data while reading bit");this.currentByte=this.data[this.position++];this.shift=7}const A=this.currentByte>>this.shift&1;this.shift--;return A}readBits(A){let I,g=0;for(I=A-1;I>=0;I--)g|=this.readBit()<=this.end?-1:this.data[this.position++]}}function getCustomHuffmanTable(A,I,g){let B=0;for(let Q=0,C=I.length;Q>g&1;g--}}if(B&&!i){const A=5;for(let I=0;I>=1}}return{imgData:h,width:i,height:o}}(A);this.width=g;this.height=B;return I}}class JpegError extends B{constructor(A){super(A,"JpegError")}}class DNLMarkerError extends B{constructor(A,I){super(A,"DNLMarkerError");this.scanLines=I}}class EOIMarkerError extends B{constructor(A){super(A,"EOIMarkerError")}}const J=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,U=799,k=3406,N=2276,t=1567,Y=3784,H=5793,e=2896;function buildHuffmanTable(A,I){let g,B,Q=0,C=16;for(;C>0&&!A[C-1];)C--;const E=[{children:[],index:0}];let i,o=E[0];for(g=0;g0;)o=E.pop();o.index++;E.push(o);for(;E.length<=g;){E.push(i={children:[],index:0});o.children[o.index]=i.children;o=i}Q++}if(g+10){a--;return G>>a&1}G=A[I++];if(255===G){const B=A[I++];if(B){if(220===B&&D){const B=readUint16(A,I+=2);I+=2;if(B>0&&B!==g.scanLines)throw new DNLMarkerError("Found DNL marker (0xFFDC) while parsing scan data",B)}else if(217===B){if(D){const A=S*(8===g.precision?8:0);if(A>0&&Math.round(g.scanLines/A)>=5)throw new DNLMarkerError("Found EOI marker (0xFFD9) while parsing scan data, possibly caused by incorrect `scanLines` parameter",A)}throw new EOIMarkerError("Found EOI marker (0xFFD9) while parsing scan data")}throw new JpegError(`unexpected marker ${(G<<8|B).toString(16)}`)}}a=7;return G>>>7}function decodeHuffman(A){let I=A;for(;;){I=I[readBit()];switch(typeof I){case"number":return I;case"object":continue}throw new JpegError("invalid huffman sequence")}}function receive(A){let I=0;for(;A>0;){I=I<<1|readBit();A--}return I}function receiveAndExtend(A){if(1===A)return 1===readBit()?1:-1;const I=receive(A);return I>=1<0){y--;return}let g=C;const B=E;for(;g<=B;){const B=decodeHuffman(A.huffmanTableAC),Q=15&B,C=B>>4;if(0===Q){if(C<15){y=receive(C)+(1<>4;if(0===Q)if(D<15){y=receive(D)+(1<>4;if(0===B){if(C<15)break;Q+=16;continue}Q+=C;const E=J[Q];A.blockData[I+E]=receiveAndExtend(B);Q++}};let e,M=0;const n=1===c?B[0].blocksPerLine*B[0].blocksPerColumn:h*g.mcusPerColumn;let K,L;for(;M<=n;){const g=Q?Math.min(n-M,Q):n;if(g>0){for(k=0;k0?"unexpected":"excessive"} MCU data, current marker is: ${e.invalid}`);I=e.offset}if(!(e.marker>=65488&&e.marker<=65495))break;I+=2}return I-s}function quantizeAndInverse(A,I,g){const B=A.quantizationTable,Q=A.blockData;let C,E,i,o,D,h,F,s,G,a,y,w,R,S,J,M,n;if(!B)throw new JpegError("missing required Quantization Table.");for(let A=0;A<64;A+=8){G=Q[I+A];a=Q[I+A+1];y=Q[I+A+2];w=Q[I+A+3];R=Q[I+A+4];S=Q[I+A+5];J=Q[I+A+6];M=Q[I+A+7];G*=B[A];if(a|y|w|R|S|J|M){a*=B[A+1];y*=B[A+2];w*=B[A+3];R*=B[A+4];S*=B[A+5];J*=B[A+6];M*=B[A+7];C=H*G+128>>8;E=H*R+128>>8;i=y;o=J;D=e*(a-M)+128>>8;s=e*(a+M)+128>>8;h=w<<4;F=S<<4;C=C+E+1>>1;E=C-E;n=i*Y+o*t+128>>8;i=i*t-o*Y+128>>8;o=n;D=D+F+1>>1;F=D-F;s=s+h+1>>1;h=s-h;C=C+o+1>>1;o=C-o;E=E+i+1>>1;i=E-i;n=D*N+s*k+2048>>12;D=D*k-s*N+2048>>12;s=n;n=h*U+F*c+2048>>12;h=h*c-F*U+2048>>12;F=n;g[A]=C+s;g[A+7]=C-s;g[A+1]=E+F;g[A+6]=E-F;g[A+2]=i+h;g[A+5]=i-h;g[A+3]=o+D;g[A+4]=o-D}else{n=H*G+512>>10;g[A]=n;g[A+1]=n;g[A+2]=n;g[A+3]=n;g[A+4]=n;g[A+5]=n;g[A+6]=n;g[A+7]=n}}for(let A=0;A<8;++A){G=g[A];a=g[A+8];y=g[A+16];w=g[A+24];R=g[A+32];S=g[A+40];J=g[A+48];M=g[A+56];if(a|y|w|R|S|J|M){C=H*G+2048>>12;E=H*R+2048>>12;i=y;o=J;D=e*(a-M)+2048>>12;s=e*(a+M)+2048>>12;h=w;F=S;C=4112+(C+E+1>>1);E=C-E;n=i*Y+o*t+2048>>12;i=i*t-o*Y+2048>>12;o=n;D=D+F+1>>1;F=D-F;s=s+h+1>>1;h=s-h;C=C+o+1>>1;o=C-o;E=E+i+1>>1;i=E-i;n=D*N+s*k+2048>>12;D=D*k-s*N+2048>>12;s=n;n=h*U+F*c+2048>>12;h=h*c-F*U+2048>>12;F=n;G=C+s;M=C-s;a=E+F;J=E-F;y=i+h;S=i-h;w=o+D;R=o-D;G<16?G=0:G>=4080?G=255:G>>=4;a<16?a=0:a>=4080?a=255:a>>=4;y<16?y=0:y>=4080?y=255:y>>=4;w<16?w=0:w>=4080?w=255:w>>=4;R<16?R=0:R>=4080?R=255:R>>=4;S<16?S=0:S>=4080?S=255:S>>=4;J<16?J=0:J>=4080?J=255:J>>=4;M<16?M=0:M>=4080?M=255:M>>=4;Q[I+A]=G;Q[I+A+8]=a;Q[I+A+16]=y;Q[I+A+24]=w;Q[I+A+32]=R;Q[I+A+40]=S;Q[I+A+48]=J;Q[I+A+56]=M}else{n=H*G+8192>>14;n=n<-2040?0:n>=2024?255:n+2056>>4;Q[I+A]=n;Q[I+A+8]=n;Q[I+A+16]=n;Q[I+A+24]=n;Q[I+A+32]=n;Q[I+A+40]=n;Q[I+A+48]=n;Q[I+A+56]=n}}}function buildComponentData(A,I){const g=I.blocksPerLine,B=I.blocksPerColumn,Q=new Int16Array(64);for(let A=0;A=B)return null;const C=readUint16(A,I);if(C>=65472&&C<=65534)return{invalid:null,marker:C,offset:I};let E=readUint16(A,Q);for(;!(E>=65472&&E<=65534);){if(++Q>=B)return null;E=readUint16(A,Q)}return{invalid:C.toString(16),marker:E,offset:Q}}function prepareComponents(A){const I=Math.ceil(A.samplesPerLine/8/A.maxH),g=Math.ceil(A.scanLines/8/A.maxV);for(const B of A.components){const Q=Math.ceil(Math.ceil(A.samplesPerLine/8)*B.h/A.maxH),C=Math.ceil(Math.ceil(A.scanLines/8)*B.v/A.maxV),E=I*B.h,i=64*(g*B.v)*(E+1);B.blockData=new Int16Array(i);B.blocksPerLine=Q;B.blocksPerColumn=C}A.mcusPerLine=I;A.mcusPerColumn=g}function readDataBlock(A,I){const g=readUint16(A,I);let B=(I+=2)+g-2;const Q=findNextFileMarker(A,B,I);if(Q?.invalid){util_warn("readDataBlock - incorrect length, current marker is: "+Q.invalid);B=Q.offset}const C=A.subarray(I,B);return{appData:C,newOffset:I+=C.length}}function skipData(A,I){const g=readUint16(A,I),B=(I+=2)+g-2,Q=findNextFileMarker(A,B,I);return Q?.invalid?Q.offset:B}class JpegImage{constructor({decodeTransform:A=null,colorTransform:I=-1}={}){this._decodeTransform=A;this._colorTransform=I}static canUseImageDecoder(A,I=-1){let g=0,B=null,Q=readUint16(A,g);g+=2;if(65496!==Q)throw new JpegError("SOI not found");Q=readUint16(A,g);g+=2;A:for(;65497!==Q;){switch(Q){case 65472:case 65473:case 65474:B=A[g+7];break A;case 65535:255!==A[g]&&g--}g=skipData(A,g);Q=readUint16(A,g);g+=2}return 4!==B&&(3!==B||0!==I)}parse(A,{dnlScanLines:I=null}={}){let g,B,Q=0,C=null,E=null,i=0;const o=[],D=[],h=[];let F=readUint16(A,Q);Q+=2;if(65496!==F)throw new JpegError("SOI not found");F=readUint16(A,Q);Q+=2;A:for(;65497!==F;){let s,G,a;switch(F){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:case 65534:const{appData:y,newOffset:w}=readDataBlock(A,Q);Q=w;65504===F&&74===y[0]&&70===y[1]&&73===y[2]&&70===y[3]&&0===y[4]&&(C={version:{major:y[5],minor:y[6]},densityUnits:y[7],xDensity:y[8]<<8|y[9],yDensity:y[10]<<8|y[11],thumbWidth:y[12],thumbHeight:y[13],thumbData:y.subarray(14,14+3*y[12]*y[13])});65518===F&&65===y[0]&&100===y[1]&&111===y[2]&&98===y[3]&&101===y[4]&&(E={version:y[5]<<8|y[6],flags0:y[7]<<8|y[8],flags1:y[9]<<8|y[10],transformCode:y[11]});break;case 65499:const R=readUint16(A,Q);Q+=2;const S=R+Q-2;let c;for(;Q>4){if(I>>4!=1)throw new JpegError("DQT - invalid table spec");for(G=0;G<64;G++){c=J[G];g[c]=readUint16(A,Q);Q+=2}}else for(G=0;G<64;G++){c=J[G];g[c]=A[Q++]}o[15&I]=g}break;case 65472:case 65473:case 65474:if(g)throw new JpegError("Only single frame JPEGs supported");Q+=2;g={};g.extended=65473===F;g.progressive=65474===F;g.precision=A[Q++];const U=readUint16(A,Q);Q+=2;g.scanLines=I||U;g.samplesPerLine=readUint16(A,Q);Q+=2;g.components=[];g.componentIds={};const k=A[Q++];let N=0,t=0;for(s=0;s>4,C=15&A[Q+1];N>4?D:h)[15&I]=buildHuffmanTable(g,C)}break;case 65501:Q+=2;B=readUint16(A,Q);Q+=2;break;case 65498:const H=1==++i&&!I;Q+=2;const e=A[Q++],M=[];for(s=0;s>4];C.huffmanTableAC=D[15&E];M.push(C)}const n=A[Q++],K=A[Q++],L=A[Q++];try{Q+=decodeScan(A,Q,g,M,B,n,K,L>>4,15&L,H)}catch(I){if(I instanceof DNLMarkerError){util_warn(`${I.message} -- attempting to re-parse the JPEG image.`);return this.parse(A,{dnlScanLines:I.scanLines})}if(I instanceof EOIMarkerError){util_warn(`${I.message} -- ignoring the rest of the image data.`);break A}throw I}break;case 65500:Q+=4;break;case 65535:255!==A[Q]&&Q--;break;default:const d=findNextFileMarker(A,Q-2,Q-3);if(d?.invalid){util_warn("JpegImage.parse - unexpected data, current marker is: "+d.invalid);Q=d.offset;break}if(!d||Q>=A.length-1){util_warn("JpegImage.parse - reached the end of the image data without finding an EOI marker (0xFFD9).");break A}throw new JpegError("JpegImage.parse - unknown marker: "+F.toString(16))}F=readUint16(A,Q);Q+=2}if(!g)throw new JpegError("JpegImage.parse - no frame data found.");this.width=g.samplesPerLine;this.height=g.scanLines;this.jfif=C;this.adobe=E;this.components=[];for(const A of g.components){const I=o[A.quantizationId];I&&(A.quantizationTable=I);this.components.push({index:A.index,output:buildComponentData(0,A),scaleX:A.h/g.maxH,scaleY:A.v/g.maxV,blocksPerLine:A.blocksPerLine,blocksPerColumn:A.blocksPerColumn})}this.numComponents=this.components.length}_getLinearizedBlockData(A,I,g=!1){const B=this.width/A,Q=this.height/I;let C,E,i,o,D,h,F,s,G,a,y,w=0;const R=this.components.length,S=A*I*R,J=new Uint8ClampedArray(S),c=new Uint32Array(A),U=4294967288;let k;for(F=0;F>8)+N[G+1];return J}get _isColorConversionNeeded(){return this.adobe?!!this.adobe.transformCode:3===this.numComponents?0!==this._colorTransform&&(82!==this.components[0].index||71!==this.components[1].index||66!==this.components[2].index):1===this._colorTransform}_convertYccToRgb(A){let I,g,B;for(let Q=0,C=A.length;Q4)throw new JpegError("Unsupported color mode");const C=this._getLinearizedBlockData(A,I,Q);if(1===this.numComponents&&(g||B)){const A=C.length*(g?4:3),I=new Uint8ClampedArray(A);let B=0;if(g)!function grayToRGBA(A,I){if(util_FeatureTest.isLittleEndian)for(let g=0,B=A.length;g{I=A;g=B}));B.decode=function(A,{numComponents:I=4,isIndexedColormap:g=!1,smaskInData:Q=!1}){const C=A.length,E=B._malloc(C);B.HEAPU8.set(A,E);const i=B._jp2_decode(E,C,I>0?I:0,!!g,!!Q);B._free(E);if(i){const{errorMessages:A}=B;if(A){delete B.errorMessages;return A}return"Unknown error"}const{imageData:o}=B;B.imageData=null;return o};var Q=Object.assign({},B),C="./this.program",quit_=(A,I)=>{throw I},E="";"undefined"!=typeof document&&document.currentScript&&(E=document.currentScript.src);M&&(E=M);E=E.startsWith("blob:")?"":E.substr(0,E.replace(/[?#].*/,"").lastIndexOf("/")+1);var i=B.print||console.log.bind(console),o=B.printErr||console.error.bind(console);Object.assign(B,Q);Q=null;B.arguments&&B.arguments;B.thisProgram&&(C=B.thisProgram);var D,h=B.wasmBinary;function tryParseAsDataURI(A){if(isDataURI(A))return function intArrayFromBase64(A){for(var I=atob(A),g=new Uint8Array(I.length),B=0;BA.startsWith(N);function instantiateSync(A,I){var g,B=function getBinarySync(A){if(A==w&&h)return new Uint8Array(h);var I=tryParseAsDataURI(A);if(I)return I;throw'sync fetching of the wasm failed: you can preload it to Module["wasmBinary"] manually, or emcc.py will do that for you when generating HTML (but not JS)'}(A);g=new WebAssembly.Module(B);return[new WebAssembly.Instance(g,I),g]}class ExitStatus{name="ExitStatus";constructor(A){this.message=`Program terminated with exit(${A})`;this.status=A}}var t,callRuntimeCallbacks=A=>{for(;A.length>0;)A.shift()(B)},Y=B.noExitRuntime||!0,H=0,e={},handleException=A=>{if(A instanceof ExitStatus||"unwind"==A)return F;quit_(0,A)},keepRuntimeAlive=()=>Y||H>0,_proc_exit=A=>{F=A;if(!keepRuntimeAlive()){B.onExit?.(A);y=!0}quit_(0,new ExitStatus(A))},_exit=(A,I)=>{F=A;_proc_exit(A)},callUserCallback=A=>{if(!y)try{A();(()=>{if(!keepRuntimeAlive())try{_exit(F)}catch(A){handleException(A)}})()}catch(A){handleException(A)}},growMemory=A=>{var I=(A-D.buffer.byteLength+65535)/65536|0;try{D.grow(I);updateMemoryViews();return 1}catch(A){}},n={},getEnvStrings=()=>{if(!getEnvStrings.strings){var A={USER:"web_user",LOGNAME:"web_user",PATH:"/",PWD:"/",HOME:"/home/web_user",LANG:("object"==typeof navigator&&navigator.languages&&navigator.languages[0]||"C").replace("-","_")+".UTF-8",_:C||"./this.program"};for(var I in n)void 0===n[I]?delete A[I]:A[I]=n[I];var g=[];for(var I in A)g.push(`${I}=${A[I]}`);getEnvStrings.strings=g}return getEnvStrings.strings},K=[null,[],[]],L="undefined"!=typeof TextDecoder?new TextDecoder:void 0,UTF8ArrayToString=(A,I=0,g=NaN)=>{for(var B=I+g,Q=I;A[Q]&&!(Q>=B);)++Q;if(Q-I>16&&A.buffer&&L)return L.decode(A.subarray(I,Q));for(var C="";I>10,56320|1023&D)}}else C+=String.fromCharCode((31&E)<<6|i)}else C+=String.fromCharCode(E)}return C},printChar=(A,I)=>{var g=K[A];if(0===I||10===I){(1===A?i:o)(UTF8ArrayToString(g));g.length=0}else g.push(I)},UTF8ToString=(A,I)=>A?UTF8ArrayToString(G,A,I):"",d={m:()=>function abort(A){B.onAbort?.(A);o(A="Aborted("+A+")");y=!0;A+=". Build with -sASSERTIONS for more info.";var I=new WebAssembly.RuntimeError(A);g(I);throw I}(""),c:(A,I,g)=>G.copyWithin(A,I,I+g),l:()=>{Y=!1;H=0},n:(A,I)=>{if(e[A]){clearTimeout(e[A].id);delete e[A]}if(!I)return 0;var g=setTimeout((()=>{delete e[A];callUserCallback((()=>l(A,performance.now())))}),I);e[A]={id:g,timeout_ms:I};return 0},g:function _copy_pixels_1(A,I){A>>=2;const g=B.imageData=new Uint8ClampedArray(I),Q=B.HEAP32.subarray(A,A+I);g.set(Q)},f:function _copy_pixels_3(A,I,g,Q){A>>=2;I>>=2;g>>=2;const C=B.imageData=new Uint8ClampedArray(3*Q),E=B.HEAP32.subarray(A,A+Q),i=B.HEAP32.subarray(I,I+Q),o=B.HEAP32.subarray(g,g+Q);for(let A=0;A>=2;I>>=2;g>>=2;Q>>=2;const E=B.imageData=new Uint8ClampedArray(4*C),i=B.HEAP32.subarray(A,A+C),o=B.HEAP32.subarray(I,I+C),D=B.HEAP32.subarray(g,g+C),h=B.HEAP32.subarray(Q,Q+C);for(let A=0;A{var I,g,B=G.length,Q=2147483648;if((A>>>=0)>Q)return!1;for(var C=1;C<=4;C*=2){var E=B*(1+.2/C);E=Math.min(E,A+100663296);var i=Math.min(Q,(I=Math.max(A,E),g=65536,Math.ceil(I/g)*g));if(growMemory(i))return!0}return!1},p:(A,I)=>{var g=0;getEnvStrings().forEach(((B,Q)=>{var C=I+g;a[A+4*Q>>2]=C;((A,I)=>{for(var g=0;g{var g=getEnvStrings();a[A>>2]=g.length;var B=0;g.forEach((A=>B+=A.length+1));a[I>>2]=B;return 0},r:A=>52,j:function _fd_seek(A,I,g,B,Q){return 70},b:(A,I,g,B)=>{for(var Q=0,C=0;C>2],i=a[I+4>>2];I+=8;for(var o=0;o>2]=Q;return 0},s:function _gray_to_rgba(A,I){A>>=2;const g=B.imageData=new Uint8ClampedArray(4*I),Q=B.HEAP32.subarray(A,A+I);for(let A=0;A>=2;I>>=2;const Q=B.imageData=new Uint8ClampedArray(4*g),C=B.HEAP32.subarray(A,A+g),E=B.HEAP32.subarray(I,I+g);for(let A=0;A>=2;I>>=2;g>>=2;const C=B.imageData=new Uint8ClampedArray(4*Q),E=B.HEAP32.subarray(A,A+Q),i=B.HEAP32.subarray(I,I+Q),o=B.HEAP32.subarray(g,g+Q);for(let A=0;A0)){!function preRun(){if(B.preRun){"function"==typeof B.preRun&&(B.preRun=[B.preRun]);for(;B.preRun.length;)A=B.preRun.shift(),R.unshift(A)}var A;callRuntimeCallbacks(R)}();if(!(c>0))if(B.setStatus){B.setStatus("Running...");setTimeout((()=>{setTimeout((()=>B.setStatus("")),1);doRun()}),1)}else doRun()}function doRun(){if(!t){t=!0;B.calledRun=!0;if(!y){!function initRuntime(){callRuntimeCallbacks(S)}();I(B);B.onRuntimeInitialized?.();!function postRun(){if(B.postRun){"function"==typeof B.postRun&&(B.postRun=[B.postRun]);for(;B.postRun.length;)A=B.postRun.shift(),J.unshift(A)}var A;callRuntimeCallbacks(J)}()}}}}if(B.preInit){"function"==typeof B.preInit&&(B.preInit=[B.preInit]);for(;B.preInit.length>0;)B.preInit.pop()()}run();return B});const K=n;class Stream extends base_stream_BaseStream{constructor(A,I,g,B){super();this.bytes=A instanceof Uint8Array?A:new Uint8Array(A);this.start=I||0;this.pos=this.start;this.end=I+g||this.bytes.length;this.dict=B}get length(){return this.end-this.start}get isEmpty(){return 0===this.length}getByte(){return this.pos>=this.end?-1:this.bytes[this.pos++]}getBytes(A){const I=this.bytes,g=this.pos,B=this.end;if(!A)return I.subarray(g,B);let Q=g+A;Q>B&&(Q=B);this.pos=Q;return I.subarray(g,Q)}getByteRange(A,I){A<0&&(A=0);I>this.end&&(I=this.end);return this.bytes.subarray(A,I)}reset(){this.pos=this.start}moveStart(){this.start=this.pos}makeSubStream(A,I,g=null){return new Stream(this.bytes.buffer,A,I,g)}}class JpxError extends B{constructor(A){super(A,"JpxError")}}class JpxImage{static#A=null;static decode(A,I){I||={};this.#A||=K({warn:util_warn});const g=this.#A.decode(A,I);if("string"==typeof g)throw new JpxError(g);return g}static cleanup(){this.#A=null}static parseImageProperties(A){if(!(A instanceof ArrayBuffer||ArrayBuffer.isView(A)))throw new JpxError("Invalid data format, must be a TypedArray.");let I=(A=new Stream(A)).getByte();for(;I>=0;){const g=I;I=A.getByte();if(65361===(g<<8|I)){A.skip(4);const I=A.getInt32()>>>0,g=A.getInt32()>>>0,B=A.getInt32()>>>0,Q=A.getInt32()>>>0;A.skip(16);return{width:I-B,height:g-Q,bitsPerComponent:8,componentsCount:A.getUint16()}}}throw new JpxError("No size marker found in JPX stream")}}var L=__webpack_exports__.Jbig2Error,d=__webpack_exports__.Jbig2Image,r=__webpack_exports__.JpegError,l=__webpack_exports__.JpegImage,q=__webpack_exports__.JpxError,f=__webpack_exports__.JpxImage,b=__webpack_exports__.VerbosityLevel,W=__webpack_exports__.getVerbosityLevel,Z=__webpack_exports__.setVerbosityLevel;export{L as Jbig2Error,d as Jbig2Image,r as JpegError,l as JpegImage,q as JpxError,f as JpxImage,b as VerbosityLevel,W as getVerbosityLevel,Z as setVerbosityLevel};