pdf.image_decoders.js 310 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413
  1. /**
  2. * @licstart The following is the entire license notice for the
  3. * JavaScript code in this page
  4. *
  5. * Copyright 2022 Mozilla Foundation
  6. *
  7. * Licensed under the Apache License, Version 2.0 (the "License");
  8. * you may not use this file except in compliance with the License.
  9. * You may obtain a copy of the License at
  10. *
  11. * http://www.apache.org/licenses/LICENSE-2.0
  12. *
  13. * Unless required by applicable law or agreed to in writing, software
  14. * distributed under the License is distributed on an "AS IS" BASIS,
  15. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  16. * See the License for the specific language governing permissions and
  17. * limitations under the License.
  18. *
  19. * @licend The above is the entire license notice for the
  20. * JavaScript code in this page
  21. */
  22. (function webpackUniversalModuleDefinition(root, factory) {
  23. if(typeof exports === 'object' && typeof module === 'object')
  24. module.exports = factory();
  25. else if(typeof define === 'function' && define.amd)
  26. define("pdfjs-dist/image_decoders/pdf.image_decoders", [], factory);
  27. else if(typeof exports === 'object')
  28. exports["pdfjs-dist/image_decoders/pdf.image_decoders"] = factory();
  29. else
  30. root["pdfjs-dist/image_decoders/pdf.image_decoders"] = root.pdfjsImageDecoders = factory();
  31. })(this, () => {
  32. return /******/ (() => { // webpackBootstrap
  33. /******/ "use strict";
  34. /******/ var __webpack_modules__ = ([
  35. /* 0 */,
  36. /* 1 */
  37. /***/ ((__unused_webpack_module, exports, __w_pdfjs_require__) => {
  38. Object.defineProperty(exports, "__esModule", ({
  39. value: true
  40. }));
  41. exports.VerbosityLevel = exports.Util = exports.UnknownErrorException = exports.UnexpectedResponseException = exports.UNSUPPORTED_FEATURES = exports.TextRenderingMode = exports.StreamType = exports.RenderingIntentFlag = exports.PermissionFlag = exports.PasswordResponses = exports.PasswordException = exports.PageActionEventType = exports.OPS = exports.MissingPDFException = exports.InvalidPDFException = exports.ImageKind = exports.IDENTITY_MATRIX = exports.FormatError = exports.FontType = exports.FeatureTest = exports.FONT_IDENTITY_MATRIX = exports.DocumentActionEventType = exports.CMapCompressionType = exports.BaseException = exports.AnnotationType = exports.AnnotationStateModelType = exports.AnnotationReviewState = exports.AnnotationReplyType = exports.AnnotationMode = exports.AnnotationMarkedState = exports.AnnotationFlag = exports.AnnotationFieldFlag = exports.AnnotationBorderStyleType = exports.AnnotationActionEventType = exports.AbortException = void 0;
  42. exports.arrayByteLength = arrayByteLength;
  43. exports.arraysToBytes = arraysToBytes;
  44. exports.assert = assert;
  45. exports.bytesToString = bytesToString;
  46. exports.createPromiseCapability = createPromiseCapability;
  47. exports.createValidAbsoluteUrl = createValidAbsoluteUrl;
  48. exports.escapeString = escapeString;
  49. exports.getModificationDate = getModificationDate;
  50. exports.getVerbosityLevel = getVerbosityLevel;
  51. exports.info = info;
  52. exports.isArrayBuffer = isArrayBuffer;
  53. exports.isArrayEqual = isArrayEqual;
  54. exports.isAscii = isAscii;
  55. exports.objectFromMap = objectFromMap;
  56. exports.objectSize = objectSize;
  57. exports.setVerbosityLevel = setVerbosityLevel;
  58. exports.shadow = shadow;
  59. exports.string32 = string32;
  60. exports.stringToBytes = stringToBytes;
  61. exports.stringToPDFString = stringToPDFString;
  62. exports.stringToUTF16BEString = stringToUTF16BEString;
  63. exports.stringToUTF8String = stringToUTF8String;
  64. exports.unreachable = unreachable;
  65. exports.utf8StringToString = utf8StringToString;
  66. exports.warn = warn;
  67. __w_pdfjs_require__(2);
  68. function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
  69. function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
  70. function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
  71. function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
  72. function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
  73. function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
  74. function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"]; if (_i == null) return; var _arr = []; var _n = true; var _d = false; var _s, _e; try { for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
  75. function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
  76. function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e2) { throw _e2; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e3) { didErr = true; err = _e3; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; }
  77. function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
  78. function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
  79. function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
  80. function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
  81. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
  82. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  83. function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); }
  84. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  85. function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
  86. function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); }
  87. function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
  88. function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
  89. function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
  90. var IDENTITY_MATRIX = [1, 0, 0, 1, 0, 0];
  91. exports.IDENTITY_MATRIX = IDENTITY_MATRIX;
  92. var FONT_IDENTITY_MATRIX = [0.001, 0, 0, 0.001, 0, 0];
  93. exports.FONT_IDENTITY_MATRIX = FONT_IDENTITY_MATRIX;
  94. var RenderingIntentFlag = {
  95. ANY: 0x01,
  96. DISPLAY: 0x02,
  97. PRINT: 0x04,
  98. ANNOTATIONS_FORMS: 0x10,
  99. ANNOTATIONS_STORAGE: 0x20,
  100. ANNOTATIONS_DISABLE: 0x40,
  101. OPLIST: 0x100
  102. };
  103. exports.RenderingIntentFlag = RenderingIntentFlag;
  104. var AnnotationMode = {
  105. DISABLE: 0,
  106. ENABLE: 1,
  107. ENABLE_FORMS: 2,
  108. ENABLE_STORAGE: 3
  109. };
  110. exports.AnnotationMode = AnnotationMode;
  111. var PermissionFlag = {
  112. PRINT: 0x04,
  113. MODIFY_CONTENTS: 0x08,
  114. COPY: 0x10,
  115. MODIFY_ANNOTATIONS: 0x20,
  116. FILL_INTERACTIVE_FORMS: 0x100,
  117. COPY_FOR_ACCESSIBILITY: 0x200,
  118. ASSEMBLE: 0x400,
  119. PRINT_HIGH_QUALITY: 0x800
  120. };
  121. exports.PermissionFlag = PermissionFlag;
  122. var TextRenderingMode = {
  123. FILL: 0,
  124. STROKE: 1,
  125. FILL_STROKE: 2,
  126. INVISIBLE: 3,
  127. FILL_ADD_TO_PATH: 4,
  128. STROKE_ADD_TO_PATH: 5,
  129. FILL_STROKE_ADD_TO_PATH: 6,
  130. ADD_TO_PATH: 7,
  131. FILL_STROKE_MASK: 3,
  132. ADD_TO_PATH_FLAG: 4
  133. };
  134. exports.TextRenderingMode = TextRenderingMode;
  135. var ImageKind = {
  136. GRAYSCALE_1BPP: 1,
  137. RGB_24BPP: 2,
  138. RGBA_32BPP: 3
  139. };
  140. exports.ImageKind = ImageKind;
  141. var AnnotationType = {
  142. TEXT: 1,
  143. LINK: 2,
  144. FREETEXT: 3,
  145. LINE: 4,
  146. SQUARE: 5,
  147. CIRCLE: 6,
  148. POLYGON: 7,
  149. POLYLINE: 8,
  150. HIGHLIGHT: 9,
  151. UNDERLINE: 10,
  152. SQUIGGLY: 11,
  153. STRIKEOUT: 12,
  154. STAMP: 13,
  155. CARET: 14,
  156. INK: 15,
  157. POPUP: 16,
  158. FILEATTACHMENT: 17,
  159. SOUND: 18,
  160. MOVIE: 19,
  161. WIDGET: 20,
  162. SCREEN: 21,
  163. PRINTERMARK: 22,
  164. TRAPNET: 23,
  165. WATERMARK: 24,
  166. THREED: 25,
  167. REDACT: 26
  168. };
  169. exports.AnnotationType = AnnotationType;
  170. var AnnotationStateModelType = {
  171. MARKED: "Marked",
  172. REVIEW: "Review"
  173. };
  174. exports.AnnotationStateModelType = AnnotationStateModelType;
  175. var AnnotationMarkedState = {
  176. MARKED: "Marked",
  177. UNMARKED: "Unmarked"
  178. };
  179. exports.AnnotationMarkedState = AnnotationMarkedState;
  180. var AnnotationReviewState = {
  181. ACCEPTED: "Accepted",
  182. REJECTED: "Rejected",
  183. CANCELLED: "Cancelled",
  184. COMPLETED: "Completed",
  185. NONE: "None"
  186. };
  187. exports.AnnotationReviewState = AnnotationReviewState;
  188. var AnnotationReplyType = {
  189. GROUP: "Group",
  190. REPLY: "R"
  191. };
  192. exports.AnnotationReplyType = AnnotationReplyType;
  193. var AnnotationFlag = {
  194. INVISIBLE: 0x01,
  195. HIDDEN: 0x02,
  196. PRINT: 0x04,
  197. NOZOOM: 0x08,
  198. NOROTATE: 0x10,
  199. NOVIEW: 0x20,
  200. READONLY: 0x40,
  201. LOCKED: 0x80,
  202. TOGGLENOVIEW: 0x100,
  203. LOCKEDCONTENTS: 0x200
  204. };
  205. exports.AnnotationFlag = AnnotationFlag;
  206. var AnnotationFieldFlag = {
  207. READONLY: 0x0000001,
  208. REQUIRED: 0x0000002,
  209. NOEXPORT: 0x0000004,
  210. MULTILINE: 0x0001000,
  211. PASSWORD: 0x0002000,
  212. NOTOGGLETOOFF: 0x0004000,
  213. RADIO: 0x0008000,
  214. PUSHBUTTON: 0x0010000,
  215. COMBO: 0x0020000,
  216. EDIT: 0x0040000,
  217. SORT: 0x0080000,
  218. FILESELECT: 0x0100000,
  219. MULTISELECT: 0x0200000,
  220. DONOTSPELLCHECK: 0x0400000,
  221. DONOTSCROLL: 0x0800000,
  222. COMB: 0x1000000,
  223. RICHTEXT: 0x2000000,
  224. RADIOSINUNISON: 0x2000000,
  225. COMMITONSELCHANGE: 0x4000000
  226. };
  227. exports.AnnotationFieldFlag = AnnotationFieldFlag;
  228. var AnnotationBorderStyleType = {
  229. SOLID: 1,
  230. DASHED: 2,
  231. BEVELED: 3,
  232. INSET: 4,
  233. UNDERLINE: 5
  234. };
  235. exports.AnnotationBorderStyleType = AnnotationBorderStyleType;
  236. var AnnotationActionEventType = {
  237. E: "Mouse Enter",
  238. X: "Mouse Exit",
  239. D: "Mouse Down",
  240. U: "Mouse Up",
  241. Fo: "Focus",
  242. Bl: "Blur",
  243. PO: "PageOpen",
  244. PC: "PageClose",
  245. PV: "PageVisible",
  246. PI: "PageInvisible",
  247. K: "Keystroke",
  248. F: "Format",
  249. V: "Validate",
  250. C: "Calculate"
  251. };
  252. exports.AnnotationActionEventType = AnnotationActionEventType;
  253. var DocumentActionEventType = {
  254. WC: "WillClose",
  255. WS: "WillSave",
  256. DS: "DidSave",
  257. WP: "WillPrint",
  258. DP: "DidPrint"
  259. };
  260. exports.DocumentActionEventType = DocumentActionEventType;
  261. var PageActionEventType = {
  262. O: "PageOpen",
  263. C: "PageClose"
  264. };
  265. exports.PageActionEventType = PageActionEventType;
  266. var StreamType = {
  267. UNKNOWN: "UNKNOWN",
  268. FLATE: "FLATE",
  269. LZW: "LZW",
  270. DCT: "DCT",
  271. JPX: "JPX",
  272. JBIG: "JBIG",
  273. A85: "A85",
  274. AHX: "AHX",
  275. CCF: "CCF",
  276. RLX: "RLX"
  277. };
  278. exports.StreamType = StreamType;
  279. var FontType = {
  280. UNKNOWN: "UNKNOWN",
  281. TYPE1: "TYPE1",
  282. TYPE1STANDARD: "TYPE1STANDARD",
  283. TYPE1C: "TYPE1C",
  284. CIDFONTTYPE0: "CIDFONTTYPE0",
  285. CIDFONTTYPE0C: "CIDFONTTYPE0C",
  286. TRUETYPE: "TRUETYPE",
  287. CIDFONTTYPE2: "CIDFONTTYPE2",
  288. TYPE3: "TYPE3",
  289. OPENTYPE: "OPENTYPE",
  290. TYPE0: "TYPE0",
  291. MMTYPE1: "MMTYPE1"
  292. };
  293. exports.FontType = FontType;
  294. var VerbosityLevel = {
  295. ERRORS: 0,
  296. WARNINGS: 1,
  297. INFOS: 5
  298. };
  299. exports.VerbosityLevel = VerbosityLevel;
  300. var CMapCompressionType = {
  301. NONE: 0,
  302. BINARY: 1,
  303. STREAM: 2
  304. };
  305. exports.CMapCompressionType = CMapCompressionType;
  306. var OPS = {
  307. dependency: 1,
  308. setLineWidth: 2,
  309. setLineCap: 3,
  310. setLineJoin: 4,
  311. setMiterLimit: 5,
  312. setDash: 6,
  313. setRenderingIntent: 7,
  314. setFlatness: 8,
  315. setGState: 9,
  316. save: 10,
  317. restore: 11,
  318. transform: 12,
  319. moveTo: 13,
  320. lineTo: 14,
  321. curveTo: 15,
  322. curveTo2: 16,
  323. curveTo3: 17,
  324. closePath: 18,
  325. rectangle: 19,
  326. stroke: 20,
  327. closeStroke: 21,
  328. fill: 22,
  329. eoFill: 23,
  330. fillStroke: 24,
  331. eoFillStroke: 25,
  332. closeFillStroke: 26,
  333. closeEOFillStroke: 27,
  334. endPath: 28,
  335. clip: 29,
  336. eoClip: 30,
  337. beginText: 31,
  338. endText: 32,
  339. setCharSpacing: 33,
  340. setWordSpacing: 34,
  341. setHScale: 35,
  342. setLeading: 36,
  343. setFont: 37,
  344. setTextRenderingMode: 38,
  345. setTextRise: 39,
  346. moveText: 40,
  347. setLeadingMoveText: 41,
  348. setTextMatrix: 42,
  349. nextLine: 43,
  350. showText: 44,
  351. showSpacedText: 45,
  352. nextLineShowText: 46,
  353. nextLineSetSpacingShowText: 47,
  354. setCharWidth: 48,
  355. setCharWidthAndBounds: 49,
  356. setStrokeColorSpace: 50,
  357. setFillColorSpace: 51,
  358. setStrokeColor: 52,
  359. setStrokeColorN: 53,
  360. setFillColor: 54,
  361. setFillColorN: 55,
  362. setStrokeGray: 56,
  363. setFillGray: 57,
  364. setStrokeRGBColor: 58,
  365. setFillRGBColor: 59,
  366. setStrokeCMYKColor: 60,
  367. setFillCMYKColor: 61,
  368. shadingFill: 62,
  369. beginInlineImage: 63,
  370. beginImageData: 64,
  371. endInlineImage: 65,
  372. paintXObject: 66,
  373. markPoint: 67,
  374. markPointProps: 68,
  375. beginMarkedContent: 69,
  376. beginMarkedContentProps: 70,
  377. endMarkedContent: 71,
  378. beginCompat: 72,
  379. endCompat: 73,
  380. paintFormXObjectBegin: 74,
  381. paintFormXObjectEnd: 75,
  382. beginGroup: 76,
  383. endGroup: 77,
  384. beginAnnotations: 78,
  385. endAnnotations: 79,
  386. beginAnnotation: 80,
  387. endAnnotation: 81,
  388. paintJpegXObject: 82,
  389. paintImageMaskXObject: 83,
  390. paintImageMaskXObjectGroup: 84,
  391. paintImageXObject: 85,
  392. paintInlineImageXObject: 86,
  393. paintInlineImageXObjectGroup: 87,
  394. paintImageXObjectRepeat: 88,
  395. paintImageMaskXObjectRepeat: 89,
  396. paintSolidColorImageMask: 90,
  397. constructPath: 91
  398. };
  399. exports.OPS = OPS;
  400. var UNSUPPORTED_FEATURES = {
  401. unknown: "unknown",
  402. forms: "forms",
  403. javaScript: "javaScript",
  404. signatures: "signatures",
  405. smask: "smask",
  406. shadingPattern: "shadingPattern",
  407. font: "font",
  408. errorTilingPattern: "errorTilingPattern",
  409. errorExtGState: "errorExtGState",
  410. errorXObject: "errorXObject",
  411. errorFontLoadType3: "errorFontLoadType3",
  412. errorFontState: "errorFontState",
  413. errorFontMissing: "errorFontMissing",
  414. errorFontTranslate: "errorFontTranslate",
  415. errorColorSpace: "errorColorSpace",
  416. errorOperatorList: "errorOperatorList",
  417. errorFontToUnicode: "errorFontToUnicode",
  418. errorFontLoadNative: "errorFontLoadNative",
  419. errorFontBuildPath: "errorFontBuildPath",
  420. errorFontGetPath: "errorFontGetPath",
  421. errorMarkedContent: "errorMarkedContent",
  422. errorContentSubStream: "errorContentSubStream"
  423. };
  424. exports.UNSUPPORTED_FEATURES = UNSUPPORTED_FEATURES;
  425. var PasswordResponses = {
  426. NEED_PASSWORD: 1,
  427. INCORRECT_PASSWORD: 2
  428. };
  429. exports.PasswordResponses = PasswordResponses;
  430. var verbosity = VerbosityLevel.WARNINGS;
  431. function setVerbosityLevel(level) {
  432. if (Number.isInteger(level)) {
  433. verbosity = level;
  434. }
  435. }
  436. function getVerbosityLevel() {
  437. return verbosity;
  438. }
  439. function info(msg) {
  440. if (verbosity >= VerbosityLevel.INFOS) {
  441. console.log("Info: ".concat(msg));
  442. }
  443. }
  444. function warn(msg) {
  445. if (verbosity >= VerbosityLevel.WARNINGS) {
  446. console.log("Warning: ".concat(msg));
  447. }
  448. }
  449. function unreachable(msg) {
  450. throw new Error(msg);
  451. }
  452. function assert(cond, msg) {
  453. if (!cond) {
  454. unreachable(msg);
  455. }
  456. }
  457. function _isValidProtocol(url) {
  458. if (!url) {
  459. return false;
  460. }
  461. switch (url.protocol) {
  462. case "http:":
  463. case "https:":
  464. case "ftp:":
  465. case "mailto:":
  466. case "tel:":
  467. return true;
  468. default:
  469. return false;
  470. }
  471. }
  472. function createValidAbsoluteUrl(url) {
  473. var baseUrl = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
  474. var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
  475. if (!url) {
  476. return null;
  477. }
  478. try {
  479. if (options && typeof url === "string") {
  480. if (options.addDefaultProtocol && url.startsWith("www.")) {
  481. var dots = url.match(/\./g);
  482. if (dots && dots.length >= 2) {
  483. url = "http://".concat(url);
  484. }
  485. }
  486. if (options.tryConvertEncoding) {
  487. try {
  488. url = stringToUTF8String(url);
  489. } catch (ex) {}
  490. }
  491. }
  492. var absoluteUrl = baseUrl ? new URL(url, baseUrl) : new URL(url);
  493. if (_isValidProtocol(absoluteUrl)) {
  494. return absoluteUrl;
  495. }
  496. } catch (ex) {}
  497. return null;
  498. }
  499. function shadow(obj, prop, value) {
  500. Object.defineProperty(obj, prop, {
  501. value: value,
  502. enumerable: true,
  503. configurable: true,
  504. writable: false
  505. });
  506. return value;
  507. }
  508. var BaseException = function BaseExceptionClosure() {
  509. function BaseException(message, name) {
  510. if (this.constructor === BaseException) {
  511. unreachable("Cannot initialize BaseException.");
  512. }
  513. this.message = message;
  514. this.name = name;
  515. }
  516. BaseException.prototype = new Error();
  517. BaseException.constructor = BaseException;
  518. return BaseException;
  519. }();
  520. exports.BaseException = BaseException;
  521. var PasswordException = /*#__PURE__*/function (_BaseException) {
  522. _inherits(PasswordException, _BaseException);
  523. var _super = _createSuper(PasswordException);
  524. function PasswordException(msg, code) {
  525. var _this;
  526. _classCallCheck(this, PasswordException);
  527. _this = _super.call(this, msg, "PasswordException");
  528. _this.code = code;
  529. return _this;
  530. }
  531. return _createClass(PasswordException);
  532. }(BaseException);
  533. exports.PasswordException = PasswordException;
  534. var UnknownErrorException = /*#__PURE__*/function (_BaseException2) {
  535. _inherits(UnknownErrorException, _BaseException2);
  536. var _super2 = _createSuper(UnknownErrorException);
  537. function UnknownErrorException(msg, details) {
  538. var _this2;
  539. _classCallCheck(this, UnknownErrorException);
  540. _this2 = _super2.call(this, msg, "UnknownErrorException");
  541. _this2.details = details;
  542. return _this2;
  543. }
  544. return _createClass(UnknownErrorException);
  545. }(BaseException);
  546. exports.UnknownErrorException = UnknownErrorException;
  547. var InvalidPDFException = /*#__PURE__*/function (_BaseException3) {
  548. _inherits(InvalidPDFException, _BaseException3);
  549. var _super3 = _createSuper(InvalidPDFException);
  550. function InvalidPDFException(msg) {
  551. _classCallCheck(this, InvalidPDFException);
  552. return _super3.call(this, msg, "InvalidPDFException");
  553. }
  554. return _createClass(InvalidPDFException);
  555. }(BaseException);
  556. exports.InvalidPDFException = InvalidPDFException;
  557. var MissingPDFException = /*#__PURE__*/function (_BaseException4) {
  558. _inherits(MissingPDFException, _BaseException4);
  559. var _super4 = _createSuper(MissingPDFException);
  560. function MissingPDFException(msg) {
  561. _classCallCheck(this, MissingPDFException);
  562. return _super4.call(this, msg, "MissingPDFException");
  563. }
  564. return _createClass(MissingPDFException);
  565. }(BaseException);
  566. exports.MissingPDFException = MissingPDFException;
  567. var UnexpectedResponseException = /*#__PURE__*/function (_BaseException5) {
  568. _inherits(UnexpectedResponseException, _BaseException5);
  569. var _super5 = _createSuper(UnexpectedResponseException);
  570. function UnexpectedResponseException(msg, status) {
  571. var _this3;
  572. _classCallCheck(this, UnexpectedResponseException);
  573. _this3 = _super5.call(this, msg, "UnexpectedResponseException");
  574. _this3.status = status;
  575. return _this3;
  576. }
  577. return _createClass(UnexpectedResponseException);
  578. }(BaseException);
  579. exports.UnexpectedResponseException = UnexpectedResponseException;
  580. var FormatError = /*#__PURE__*/function (_BaseException6) {
  581. _inherits(FormatError, _BaseException6);
  582. var _super6 = _createSuper(FormatError);
  583. function FormatError(msg) {
  584. _classCallCheck(this, FormatError);
  585. return _super6.call(this, msg, "FormatError");
  586. }
  587. return _createClass(FormatError);
  588. }(BaseException);
  589. exports.FormatError = FormatError;
  590. var AbortException = /*#__PURE__*/function (_BaseException7) {
  591. _inherits(AbortException, _BaseException7);
  592. var _super7 = _createSuper(AbortException);
  593. function AbortException(msg) {
  594. _classCallCheck(this, AbortException);
  595. return _super7.call(this, msg, "AbortException");
  596. }
  597. return _createClass(AbortException);
  598. }(BaseException);
  599. exports.AbortException = AbortException;
  600. function bytesToString(bytes) {
  601. if (_typeof(bytes) !== "object" || bytes === null || bytes.length === undefined) {
  602. unreachable("Invalid argument for bytesToString");
  603. }
  604. var length = bytes.length;
  605. var MAX_ARGUMENT_COUNT = 8192;
  606. if (length < MAX_ARGUMENT_COUNT) {
  607. return String.fromCharCode.apply(null, bytes);
  608. }
  609. var strBuf = [];
  610. for (var i = 0; i < length; i += MAX_ARGUMENT_COUNT) {
  611. var chunkEnd = Math.min(i + MAX_ARGUMENT_COUNT, length);
  612. var chunk = bytes.subarray(i, chunkEnd);
  613. strBuf.push(String.fromCharCode.apply(null, chunk));
  614. }
  615. return strBuf.join("");
  616. }
  617. function stringToBytes(str) {
  618. if (typeof str !== "string") {
  619. unreachable("Invalid argument for stringToBytes");
  620. }
  621. var length = str.length;
  622. var bytes = new Uint8Array(length);
  623. for (var i = 0; i < length; ++i) {
  624. bytes[i] = str.charCodeAt(i) & 0xff;
  625. }
  626. return bytes;
  627. }
  628. function arrayByteLength(arr) {
  629. if (arr.length !== undefined) {
  630. return arr.length;
  631. }
  632. if (arr.byteLength !== undefined) {
  633. return arr.byteLength;
  634. }
  635. unreachable("Invalid argument for arrayByteLength");
  636. }
  637. function arraysToBytes(arr) {
  638. var length = arr.length;
  639. if (length === 1 && arr[0] instanceof Uint8Array) {
  640. return arr[0];
  641. }
  642. var resultLength = 0;
  643. for (var i = 0; i < length; i++) {
  644. resultLength += arrayByteLength(arr[i]);
  645. }
  646. var pos = 0;
  647. var data = new Uint8Array(resultLength);
  648. for (var _i = 0; _i < length; _i++) {
  649. var item = arr[_i];
  650. if (!(item instanceof Uint8Array)) {
  651. if (typeof item === "string") {
  652. item = stringToBytes(item);
  653. } else {
  654. item = new Uint8Array(item);
  655. }
  656. }
  657. var itemLength = item.byteLength;
  658. data.set(item, pos);
  659. pos += itemLength;
  660. }
  661. return data;
  662. }
  663. function string32(value) {
  664. return String.fromCharCode(value >> 24 & 0xff, value >> 16 & 0xff, value >> 8 & 0xff, value & 0xff);
  665. }
  666. function objectSize(obj) {
  667. return Object.keys(obj).length;
  668. }
  669. function objectFromMap(map) {
  670. var obj = Object.create(null);
  671. var _iterator = _createForOfIteratorHelper(map),
  672. _step;
  673. try {
  674. for (_iterator.s(); !(_step = _iterator.n()).done;) {
  675. var _step$value = _slicedToArray(_step.value, 2),
  676. key = _step$value[0],
  677. value = _step$value[1];
  678. obj[key] = value;
  679. }
  680. } catch (err) {
  681. _iterator.e(err);
  682. } finally {
  683. _iterator.f();
  684. }
  685. return obj;
  686. }
  687. function isLittleEndian() {
  688. var buffer8 = new Uint8Array(4);
  689. buffer8[0] = 1;
  690. var view32 = new Uint32Array(buffer8.buffer, 0, 1);
  691. return view32[0] === 1;
  692. }
  693. function isEvalSupported() {
  694. try {
  695. new Function("");
  696. return true;
  697. } catch (e) {
  698. return false;
  699. }
  700. }
  701. var FeatureTest = /*#__PURE__*/function () {
  702. function FeatureTest() {
  703. _classCallCheck(this, FeatureTest);
  704. }
  705. _createClass(FeatureTest, null, [{
  706. key: "isLittleEndian",
  707. get: function get() {
  708. return shadow(this, "isLittleEndian", isLittleEndian());
  709. }
  710. }, {
  711. key: "isEvalSupported",
  712. get: function get() {
  713. return shadow(this, "isEvalSupported", isEvalSupported());
  714. }
  715. }, {
  716. key: "isOffscreenCanvasSupported",
  717. get: function get() {
  718. return shadow(this, "isOffscreenCanvasSupported", typeof OffscreenCanvas !== "undefined");
  719. }
  720. }]);
  721. return FeatureTest;
  722. }();
  723. exports.FeatureTest = FeatureTest;
  724. var hexNumbers = _toConsumableArray(Array(256).keys()).map(function (n) {
  725. return n.toString(16).padStart(2, "0");
  726. });
  727. var Util = /*#__PURE__*/function () {
  728. function Util() {
  729. _classCallCheck(this, Util);
  730. }
  731. _createClass(Util, null, [{
  732. key: "makeHexColor",
  733. value: function makeHexColor(r, g, b) {
  734. return "#".concat(hexNumbers[r]).concat(hexNumbers[g]).concat(hexNumbers[b]);
  735. }
  736. }, {
  737. key: "scaleMinMax",
  738. value: function scaleMinMax(transform, minMax) {
  739. var temp;
  740. if (transform[0]) {
  741. if (transform[0] < 0) {
  742. temp = minMax[0];
  743. minMax[0] = minMax[1];
  744. minMax[1] = temp;
  745. }
  746. minMax[0] *= transform[0];
  747. minMax[1] *= transform[0];
  748. if (transform[3] < 0) {
  749. temp = minMax[2];
  750. minMax[2] = minMax[3];
  751. minMax[3] = temp;
  752. }
  753. minMax[2] *= transform[3];
  754. minMax[3] *= transform[3];
  755. } else {
  756. temp = minMax[0];
  757. minMax[0] = minMax[2];
  758. minMax[2] = temp;
  759. temp = minMax[1];
  760. minMax[1] = minMax[3];
  761. minMax[3] = temp;
  762. if (transform[1] < 0) {
  763. temp = minMax[2];
  764. minMax[2] = minMax[3];
  765. minMax[3] = temp;
  766. }
  767. minMax[2] *= transform[1];
  768. minMax[3] *= transform[1];
  769. if (transform[2] < 0) {
  770. temp = minMax[0];
  771. minMax[0] = minMax[1];
  772. minMax[1] = temp;
  773. }
  774. minMax[0] *= transform[2];
  775. minMax[1] *= transform[2];
  776. }
  777. minMax[0] += transform[4];
  778. minMax[1] += transform[4];
  779. minMax[2] += transform[5];
  780. minMax[3] += transform[5];
  781. }
  782. }, {
  783. key: "transform",
  784. value: function transform(m1, m2) {
  785. return [m1[0] * m2[0] + m1[2] * m2[1], m1[1] * m2[0] + m1[3] * m2[1], m1[0] * m2[2] + m1[2] * m2[3], m1[1] * m2[2] + m1[3] * m2[3], m1[0] * m2[4] + m1[2] * m2[5] + m1[4], m1[1] * m2[4] + m1[3] * m2[5] + m1[5]];
  786. }
  787. }, {
  788. key: "applyTransform",
  789. value: function applyTransform(p, m) {
  790. var xt = p[0] * m[0] + p[1] * m[2] + m[4];
  791. var yt = p[0] * m[1] + p[1] * m[3] + m[5];
  792. return [xt, yt];
  793. }
  794. }, {
  795. key: "applyInverseTransform",
  796. value: function applyInverseTransform(p, m) {
  797. var d = m[0] * m[3] - m[1] * m[2];
  798. var xt = (p[0] * m[3] - p[1] * m[2] + m[2] * m[5] - m[4] * m[3]) / d;
  799. var yt = (-p[0] * m[1] + p[1] * m[0] + m[4] * m[1] - m[5] * m[0]) / d;
  800. return [xt, yt];
  801. }
  802. }, {
  803. key: "getAxialAlignedBoundingBox",
  804. value: function getAxialAlignedBoundingBox(r, m) {
  805. var p1 = Util.applyTransform(r, m);
  806. var p2 = Util.applyTransform(r.slice(2, 4), m);
  807. var p3 = Util.applyTransform([r[0], r[3]], m);
  808. var p4 = Util.applyTransform([r[2], r[1]], m);
  809. return [Math.min(p1[0], p2[0], p3[0], p4[0]), Math.min(p1[1], p2[1], p3[1], p4[1]), Math.max(p1[0], p2[0], p3[0], p4[0]), Math.max(p1[1], p2[1], p3[1], p4[1])];
  810. }
  811. }, {
  812. key: "inverseTransform",
  813. value: function inverseTransform(m) {
  814. var d = m[0] * m[3] - m[1] * m[2];
  815. return [m[3] / d, -m[1] / d, -m[2] / d, m[0] / d, (m[2] * m[5] - m[4] * m[3]) / d, (m[4] * m[1] - m[5] * m[0]) / d];
  816. }
  817. }, {
  818. key: "apply3dTransform",
  819. value: function apply3dTransform(m, v) {
  820. return [m[0] * v[0] + m[1] * v[1] + m[2] * v[2], m[3] * v[0] + m[4] * v[1] + m[5] * v[2], m[6] * v[0] + m[7] * v[1] + m[8] * v[2]];
  821. }
  822. }, {
  823. key: "singularValueDecompose2dScale",
  824. value: function singularValueDecompose2dScale(m) {
  825. var transpose = [m[0], m[2], m[1], m[3]];
  826. var a = m[0] * transpose[0] + m[1] * transpose[2];
  827. var b = m[0] * transpose[1] + m[1] * transpose[3];
  828. var c = m[2] * transpose[0] + m[3] * transpose[2];
  829. var d = m[2] * transpose[1] + m[3] * transpose[3];
  830. var first = (a + d) / 2;
  831. var second = Math.sqrt(Math.pow(a + d, 2) - 4 * (a * d - c * b)) / 2;
  832. var sx = first + second || 1;
  833. var sy = first - second || 1;
  834. return [Math.sqrt(sx), Math.sqrt(sy)];
  835. }
  836. }, {
  837. key: "normalizeRect",
  838. value: function normalizeRect(rect) {
  839. var r = rect.slice(0);
  840. if (rect[0] > rect[2]) {
  841. r[0] = rect[2];
  842. r[2] = rect[0];
  843. }
  844. if (rect[1] > rect[3]) {
  845. r[1] = rect[3];
  846. r[3] = rect[1];
  847. }
  848. return r;
  849. }
  850. }, {
  851. key: "intersect",
  852. value: function intersect(rect1, rect2) {
  853. var xLow = Math.max(Math.min(rect1[0], rect1[2]), Math.min(rect2[0], rect2[2]));
  854. var xHigh = Math.min(Math.max(rect1[0], rect1[2]), Math.max(rect2[0], rect2[2]));
  855. if (xLow > xHigh) {
  856. return null;
  857. }
  858. var yLow = Math.max(Math.min(rect1[1], rect1[3]), Math.min(rect2[1], rect2[3]));
  859. var yHigh = Math.min(Math.max(rect1[1], rect1[3]), Math.max(rect2[1], rect2[3]));
  860. if (yLow > yHigh) {
  861. return null;
  862. }
  863. return [xLow, yLow, xHigh, yHigh];
  864. }
  865. }, {
  866. key: "bezierBoundingBox",
  867. value: function bezierBoundingBox(x0, y0, x1, y1, x2, y2, x3, y3) {
  868. var tvalues = [],
  869. bounds = [[], []];
  870. var a, b, c, t, t1, t2, b2ac, sqrtb2ac;
  871. for (var i = 0; i < 2; ++i) {
  872. if (i === 0) {
  873. b = 6 * x0 - 12 * x1 + 6 * x2;
  874. a = -3 * x0 + 9 * x1 - 9 * x2 + 3 * x3;
  875. c = 3 * x1 - 3 * x0;
  876. } else {
  877. b = 6 * y0 - 12 * y1 + 6 * y2;
  878. a = -3 * y0 + 9 * y1 - 9 * y2 + 3 * y3;
  879. c = 3 * y1 - 3 * y0;
  880. }
  881. if (Math.abs(a) < 1e-12) {
  882. if (Math.abs(b) < 1e-12) {
  883. continue;
  884. }
  885. t = -c / b;
  886. if (0 < t && t < 1) {
  887. tvalues.push(t);
  888. }
  889. continue;
  890. }
  891. b2ac = b * b - 4 * c * a;
  892. sqrtb2ac = Math.sqrt(b2ac);
  893. if (b2ac < 0) {
  894. continue;
  895. }
  896. t1 = (-b + sqrtb2ac) / (2 * a);
  897. if (0 < t1 && t1 < 1) {
  898. tvalues.push(t1);
  899. }
  900. t2 = (-b - sqrtb2ac) / (2 * a);
  901. if (0 < t2 && t2 < 1) {
  902. tvalues.push(t2);
  903. }
  904. }
  905. var j = tvalues.length,
  906. mt;
  907. var jlen = j;
  908. while (j--) {
  909. t = tvalues[j];
  910. mt = 1 - t;
  911. bounds[0][j] = mt * mt * mt * x0 + 3 * mt * mt * t * x1 + 3 * mt * t * t * x2 + t * t * t * x3;
  912. bounds[1][j] = mt * mt * mt * y0 + 3 * mt * mt * t * y1 + 3 * mt * t * t * y2 + t * t * t * y3;
  913. }
  914. bounds[0][jlen] = x0;
  915. bounds[1][jlen] = y0;
  916. bounds[0][jlen + 1] = x3;
  917. bounds[1][jlen + 1] = y3;
  918. bounds[0].length = bounds[1].length = jlen + 2;
  919. return [Math.min.apply(Math, _toConsumableArray(bounds[0])), Math.min.apply(Math, _toConsumableArray(bounds[1])), Math.max.apply(Math, _toConsumableArray(bounds[0])), Math.max.apply(Math, _toConsumableArray(bounds[1]))];
  920. }
  921. }]);
  922. return Util;
  923. }();
  924. exports.Util = Util;
  925. var PDFStringTranslateTable = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x2d8, 0x2c7, 0x2c6, 0x2d9, 0x2dd, 0x2db, 0x2da, 0x2dc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x2022, 0x2020, 0x2021, 0x2026, 0x2014, 0x2013, 0x192, 0x2044, 0x2039, 0x203a, 0x2212, 0x2030, 0x201e, 0x201c, 0x201d, 0x2018, 0x2019, 0x201a, 0x2122, 0xfb01, 0xfb02, 0x141, 0x152, 0x160, 0x178, 0x17d, 0x131, 0x142, 0x153, 0x161, 0x17e, 0, 0x20ac];
  926. function stringToPDFString(str) {
  927. if (str[0] >= "\xEF") {
  928. var encoding;
  929. if (str[0] === "\xFE" && str[1] === "\xFF") {
  930. encoding = "utf-16be";
  931. } else if (str[0] === "\xFF" && str[1] === "\xFE") {
  932. encoding = "utf-16le";
  933. } else if (str[0] === "\xEF" && str[1] === "\xBB" && str[2] === "\xBF") {
  934. encoding = "utf-8";
  935. }
  936. if (encoding) {
  937. try {
  938. var decoder = new TextDecoder(encoding, {
  939. fatal: true
  940. });
  941. var buffer = stringToBytes(str);
  942. return decoder.decode(buffer);
  943. } catch (ex) {
  944. warn("stringToPDFString: \"".concat(ex, "\"."));
  945. }
  946. }
  947. }
  948. var strBuf = [];
  949. for (var i = 0, ii = str.length; i < ii; i++) {
  950. var code = PDFStringTranslateTable[str.charCodeAt(i)];
  951. strBuf.push(code ? String.fromCharCode(code) : str.charAt(i));
  952. }
  953. return strBuf.join("");
  954. }
  955. function escapeString(str) {
  956. return str.replace(/([()\\\n\r])/g, function (match) {
  957. if (match === "\n") {
  958. return "\\n";
  959. } else if (match === "\r") {
  960. return "\\r";
  961. }
  962. return "\\".concat(match);
  963. });
  964. }
  965. function isAscii(str) {
  966. return /^[\x00-\x7F]*$/.test(str);
  967. }
  968. function stringToUTF16BEString(str) {
  969. var buf = ["\xFE\xFF"];
  970. for (var i = 0, ii = str.length; i < ii; i++) {
  971. var _char = str.charCodeAt(i);
  972. buf.push(String.fromCharCode(_char >> 8 & 0xff), String.fromCharCode(_char & 0xff));
  973. }
  974. return buf.join("");
  975. }
  976. function stringToUTF8String(str) {
  977. return decodeURIComponent(escape(str));
  978. }
  979. function utf8StringToString(str) {
  980. return unescape(encodeURIComponent(str));
  981. }
  982. function isArrayBuffer(v) {
  983. return _typeof(v) === "object" && v !== null && v.byteLength !== undefined;
  984. }
  985. function isArrayEqual(arr1, arr2) {
  986. if (arr1.length !== arr2.length) {
  987. return false;
  988. }
  989. for (var i = 0, ii = arr1.length; i < ii; i++) {
  990. if (arr1[i] !== arr2[i]) {
  991. return false;
  992. }
  993. }
  994. return true;
  995. }
  996. function getModificationDate() {
  997. var date = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : new Date();
  998. var buffer = [date.getUTCFullYear().toString(), (date.getUTCMonth() + 1).toString().padStart(2, "0"), date.getUTCDate().toString().padStart(2, "0"), date.getUTCHours().toString().padStart(2, "0"), date.getUTCMinutes().toString().padStart(2, "0"), date.getUTCSeconds().toString().padStart(2, "0")];
  999. return buffer.join("");
  1000. }
  1001. function createPromiseCapability() {
  1002. var capability = Object.create(null);
  1003. var isSettled = false;
  1004. Object.defineProperty(capability, "settled", {
  1005. get: function get() {
  1006. return isSettled;
  1007. }
  1008. });
  1009. capability.promise = new Promise(function (resolve, reject) {
  1010. capability.resolve = function (data) {
  1011. isSettled = true;
  1012. resolve(data);
  1013. };
  1014. capability.reject = function (reason) {
  1015. isSettled = true;
  1016. reject(reason);
  1017. };
  1018. });
  1019. return capability;
  1020. }
  1021. /***/ }),
  1022. /* 2 */
  1023. /***/ ((__unused_webpack_module, __unused_webpack_exports, __w_pdfjs_require__) => {
  1024. var _is_node = __w_pdfjs_require__(3);
  1025. if (!globalThis._pdfjsCompatibilityChecked) {
  1026. globalThis._pdfjsCompatibilityChecked = true;
  1027. (function checkNodeBtoa() {
  1028. if (globalThis.btoa || !_is_node.isNodeJS) {
  1029. return;
  1030. }
  1031. globalThis.btoa = function (chars) {
  1032. return Buffer.from(chars, "binary").toString("base64");
  1033. };
  1034. })();
  1035. (function checkNodeAtob() {
  1036. if (globalThis.atob || !_is_node.isNodeJS) {
  1037. return;
  1038. }
  1039. globalThis.atob = function (input) {
  1040. return Buffer.from(input, "base64").toString("binary");
  1041. };
  1042. })();
  1043. (function checkDOMMatrix() {
  1044. if (globalThis.DOMMatrix || !_is_node.isNodeJS) {
  1045. return;
  1046. }
  1047. globalThis.DOMMatrix = require("dommatrix/dist/dommatrix.js");
  1048. })();
  1049. (function checkPromise() {})();
  1050. (function checkReadableStream() {
  1051. if (globalThis.ReadableStream || !_is_node.isNodeJS) {
  1052. return;
  1053. }
  1054. globalThis.ReadableStream = require("web-streams-polyfill/dist/ponyfill.js").ReadableStream;
  1055. })();
  1056. (function checkStructuredClone() {})();
  1057. }
  1058. /***/ }),
  1059. /* 3 */
  1060. /***/ ((__unused_webpack_module, exports) => {
  1061. Object.defineProperty(exports, "__esModule", ({
  1062. value: true
  1063. }));
  1064. exports.isNodeJS = void 0;
  1065. function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
  1066. var isNodeJS = (typeof process === "undefined" ? "undefined" : _typeof(process)) === "object" && process + "" === "[object process]" && !process.versions.nw && !(process.versions.electron && process.type && process.type !== "browser");
  1067. exports.isNodeJS = isNodeJS;
  1068. /***/ }),
  1069. /* 4 */
  1070. /***/ ((__unused_webpack_module, exports, __w_pdfjs_require__) => {
  1071. function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
  1072. Object.defineProperty(exports, "__esModule", ({
  1073. value: true
  1074. }));
  1075. exports.Jbig2Image = void 0;
  1076. var _util = __w_pdfjs_require__(1);
  1077. var _core_utils = __w_pdfjs_require__(5);
  1078. var _arithmetic_decoder = __w_pdfjs_require__(10);
  1079. var _ccitt = __w_pdfjs_require__(11);
  1080. function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
  1081. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
  1082. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  1083. function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); }
  1084. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  1085. function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
  1086. function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); }
  1087. function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
  1088. function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
  1089. function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
  1090. var Jbig2Error = /*#__PURE__*/function (_BaseException) {
  1091. _inherits(Jbig2Error, _BaseException);
  1092. var _super = _createSuper(Jbig2Error);
  1093. function Jbig2Error(msg) {
  1094. _classCallCheck(this, Jbig2Error);
  1095. return _super.call(this, "JBIG2 error: ".concat(msg), "Jbig2Error");
  1096. }
  1097. return _createClass(Jbig2Error);
  1098. }(_util.BaseException);
  1099. var ContextCache = /*#__PURE__*/function () {
  1100. function ContextCache() {
  1101. _classCallCheck(this, ContextCache);
  1102. }
  1103. _createClass(ContextCache, [{
  1104. key: "getContexts",
  1105. value: function getContexts(id) {
  1106. if (id in this) {
  1107. return this[id];
  1108. }
  1109. return this[id] = new Int8Array(1 << 16);
  1110. }
  1111. }]);
  1112. return ContextCache;
  1113. }();
  1114. var DecodingContext = /*#__PURE__*/function () {
  1115. function DecodingContext(data, start, end) {
  1116. _classCallCheck(this, DecodingContext);
  1117. this.data = data;
  1118. this.start = start;
  1119. this.end = end;
  1120. }
  1121. _createClass(DecodingContext, [{
  1122. key: "decoder",
  1123. get: function get() {
  1124. var decoder = new _arithmetic_decoder.ArithmeticDecoder(this.data, this.start, this.end);
  1125. return (0, _util.shadow)(this, "decoder", decoder);
  1126. }
  1127. }, {
  1128. key: "contextCache",
  1129. get: function get() {
  1130. var cache = new ContextCache();
  1131. return (0, _util.shadow)(this, "contextCache", cache);
  1132. }
  1133. }]);
  1134. return DecodingContext;
  1135. }();
  1136. function decodeInteger(contextCache, procedure, decoder) {
  1137. var contexts = contextCache.getContexts(procedure);
  1138. var prev = 1;
  1139. function readBits(length) {
  1140. var v = 0;
  1141. for (var i = 0; i < length; i++) {
  1142. var bit = decoder.readBit(contexts, prev);
  1143. prev = prev < 256 ? prev << 1 | bit : (prev << 1 | bit) & 511 | 256;
  1144. v = v << 1 | bit;
  1145. }
  1146. return v >>> 0;
  1147. }
  1148. var sign = readBits(1);
  1149. var value = 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);
  1150. if (sign === 0) {
  1151. return value;
  1152. } else if (value > 0) {
  1153. return -value;
  1154. }
  1155. return null;
  1156. }
  1157. function decodeIAID(contextCache, decoder, codeLength) {
  1158. var contexts = contextCache.getContexts("IAID");
  1159. var prev = 1;
  1160. for (var i = 0; i < codeLength; i++) {
  1161. var bit = decoder.readBit(contexts, prev);
  1162. prev = prev << 1 | bit;
  1163. }
  1164. if (codeLength < 31) {
  1165. return prev & (1 << codeLength) - 1;
  1166. }
  1167. return prev & 0x7fffffff;
  1168. }
  1169. var SegmentTypes = ["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"];
  1170. var CodingTemplates = [[{
  1171. x: -1,
  1172. y: -2
  1173. }, {
  1174. x: 0,
  1175. y: -2
  1176. }, {
  1177. x: 1,
  1178. y: -2
  1179. }, {
  1180. x: -2,
  1181. y: -1
  1182. }, {
  1183. x: -1,
  1184. y: -1
  1185. }, {
  1186. x: 0,
  1187. y: -1
  1188. }, {
  1189. x: 1,
  1190. y: -1
  1191. }, {
  1192. x: 2,
  1193. y: -1
  1194. }, {
  1195. x: -4,
  1196. y: 0
  1197. }, {
  1198. x: -3,
  1199. y: 0
  1200. }, {
  1201. x: -2,
  1202. y: 0
  1203. }, {
  1204. x: -1,
  1205. y: 0
  1206. }], [{
  1207. x: -1,
  1208. y: -2
  1209. }, {
  1210. x: 0,
  1211. y: -2
  1212. }, {
  1213. x: 1,
  1214. y: -2
  1215. }, {
  1216. x: 2,
  1217. y: -2
  1218. }, {
  1219. x: -2,
  1220. y: -1
  1221. }, {
  1222. x: -1,
  1223. y: -1
  1224. }, {
  1225. x: 0,
  1226. y: -1
  1227. }, {
  1228. x: 1,
  1229. y: -1
  1230. }, {
  1231. x: 2,
  1232. y: -1
  1233. }, {
  1234. x: -3,
  1235. y: 0
  1236. }, {
  1237. x: -2,
  1238. y: 0
  1239. }, {
  1240. x: -1,
  1241. y: 0
  1242. }], [{
  1243. x: -1,
  1244. y: -2
  1245. }, {
  1246. x: 0,
  1247. y: -2
  1248. }, {
  1249. x: 1,
  1250. y: -2
  1251. }, {
  1252. x: -2,
  1253. y: -1
  1254. }, {
  1255. x: -1,
  1256. y: -1
  1257. }, {
  1258. x: 0,
  1259. y: -1
  1260. }, {
  1261. x: 1,
  1262. y: -1
  1263. }, {
  1264. x: -2,
  1265. y: 0
  1266. }, {
  1267. x: -1,
  1268. y: 0
  1269. }], [{
  1270. x: -3,
  1271. y: -1
  1272. }, {
  1273. x: -2,
  1274. y: -1
  1275. }, {
  1276. x: -1,
  1277. y: -1
  1278. }, {
  1279. x: 0,
  1280. y: -1
  1281. }, {
  1282. x: 1,
  1283. y: -1
  1284. }, {
  1285. x: -4,
  1286. y: 0
  1287. }, {
  1288. x: -3,
  1289. y: 0
  1290. }, {
  1291. x: -2,
  1292. y: 0
  1293. }, {
  1294. x: -1,
  1295. y: 0
  1296. }]];
  1297. var RefinementTemplates = [{
  1298. coding: [{
  1299. x: 0,
  1300. y: -1
  1301. }, {
  1302. x: 1,
  1303. y: -1
  1304. }, {
  1305. x: -1,
  1306. y: 0
  1307. }],
  1308. reference: [{
  1309. x: 0,
  1310. y: -1
  1311. }, {
  1312. x: 1,
  1313. y: -1
  1314. }, {
  1315. x: -1,
  1316. y: 0
  1317. }, {
  1318. x: 0,
  1319. y: 0
  1320. }, {
  1321. x: 1,
  1322. y: 0
  1323. }, {
  1324. x: -1,
  1325. y: 1
  1326. }, {
  1327. x: 0,
  1328. y: 1
  1329. }, {
  1330. x: 1,
  1331. y: 1
  1332. }]
  1333. }, {
  1334. coding: [{
  1335. x: -1,
  1336. y: -1
  1337. }, {
  1338. x: 0,
  1339. y: -1
  1340. }, {
  1341. x: 1,
  1342. y: -1
  1343. }, {
  1344. x: -1,
  1345. y: 0
  1346. }],
  1347. reference: [{
  1348. x: 0,
  1349. y: -1
  1350. }, {
  1351. x: -1,
  1352. y: 0
  1353. }, {
  1354. x: 0,
  1355. y: 0
  1356. }, {
  1357. x: 1,
  1358. y: 0
  1359. }, {
  1360. x: 0,
  1361. y: 1
  1362. }, {
  1363. x: 1,
  1364. y: 1
  1365. }]
  1366. }];
  1367. var ReusedContexts = [0x9b25, 0x0795, 0x00e5, 0x0195];
  1368. var RefinementReusedContexts = [0x0020, 0x0008];
  1369. function decodeBitmapTemplate0(width, height, decodingContext) {
  1370. var decoder = decodingContext.decoder;
  1371. var contexts = decodingContext.contextCache.getContexts("GB");
  1372. var bitmap = [];
  1373. var contextLabel, i, j, pixel, row, row1, row2;
  1374. var OLD_PIXEL_MASK = 0x7bf7;
  1375. for (i = 0; i < height; i++) {
  1376. row = bitmap[i] = new Uint8Array(width);
  1377. row1 = i < 1 ? row : bitmap[i - 1];
  1378. row2 = i < 2 ? row : bitmap[i - 2];
  1379. contextLabel = row2[0] << 13 | row2[1] << 12 | row2[2] << 11 | row1[0] << 7 | row1[1] << 6 | row1[2] << 5 | row1[3] << 4;
  1380. for (j = 0; j < width; j++) {
  1381. row[j] = pixel = decoder.readBit(contexts, contextLabel);
  1382. contextLabel = (contextLabel & OLD_PIXEL_MASK) << 1 | (j + 3 < width ? row2[j + 3] << 11 : 0) | (j + 4 < width ? row1[j + 4] << 4 : 0) | pixel;
  1383. }
  1384. }
  1385. return bitmap;
  1386. }
  1387. function decodeBitmap(mmr, width, height, templateIndex, prediction, skip, at, decodingContext) {
  1388. if (mmr) {
  1389. var input = new Reader(decodingContext.data, decodingContext.start, decodingContext.end);
  1390. return decodeMMRBitmap(input, width, height, false);
  1391. }
  1392. if (templateIndex === 0 && !skip && !prediction && at.length === 4 && at[0].x === 3 && at[0].y === -1 && at[1].x === -3 && at[1].y === -1 && at[2].x === 2 && at[2].y === -2 && at[3].x === -2 && at[3].y === -2) {
  1393. return decodeBitmapTemplate0(width, height, decodingContext);
  1394. }
  1395. var useskip = !!skip;
  1396. var template = CodingTemplates[templateIndex].concat(at);
  1397. template.sort(function (a, b) {
  1398. return a.y - b.y || a.x - b.x;
  1399. });
  1400. var templateLength = template.length;
  1401. var templateX = new Int8Array(templateLength);
  1402. var templateY = new Int8Array(templateLength);
  1403. var changingTemplateEntries = [];
  1404. var reuseMask = 0,
  1405. minX = 0,
  1406. maxX = 0,
  1407. minY = 0;
  1408. var c, k;
  1409. for (k = 0; k < templateLength; k++) {
  1410. templateX[k] = template[k].x;
  1411. templateY[k] = template[k].y;
  1412. minX = Math.min(minX, template[k].x);
  1413. maxX = Math.max(maxX, template[k].x);
  1414. minY = Math.min(minY, template[k].y);
  1415. if (k < templateLength - 1 && template[k].y === template[k + 1].y && template[k].x === template[k + 1].x - 1) {
  1416. reuseMask |= 1 << templateLength - 1 - k;
  1417. } else {
  1418. changingTemplateEntries.push(k);
  1419. }
  1420. }
  1421. var changingEntriesLength = changingTemplateEntries.length;
  1422. var changingTemplateX = new Int8Array(changingEntriesLength);
  1423. var changingTemplateY = new Int8Array(changingEntriesLength);
  1424. var changingTemplateBit = new Uint16Array(changingEntriesLength);
  1425. for (c = 0; c < changingEntriesLength; c++) {
  1426. k = changingTemplateEntries[c];
  1427. changingTemplateX[c] = template[k].x;
  1428. changingTemplateY[c] = template[k].y;
  1429. changingTemplateBit[c] = 1 << templateLength - 1 - k;
  1430. }
  1431. var sbb_left = -minX;
  1432. var sbb_top = -minY;
  1433. var sbb_right = width - maxX;
  1434. var pseudoPixelContext = ReusedContexts[templateIndex];
  1435. var row = new Uint8Array(width);
  1436. var bitmap = [];
  1437. var decoder = decodingContext.decoder;
  1438. var contexts = decodingContext.contextCache.getContexts("GB");
  1439. var ltp = 0,
  1440. j,
  1441. i0,
  1442. j0,
  1443. contextLabel = 0,
  1444. bit,
  1445. shift;
  1446. for (var i = 0; i < height; i++) {
  1447. if (prediction) {
  1448. var sltp = decoder.readBit(contexts, pseudoPixelContext);
  1449. ltp ^= sltp;
  1450. if (ltp) {
  1451. bitmap.push(row);
  1452. continue;
  1453. }
  1454. }
  1455. row = new Uint8Array(row);
  1456. bitmap.push(row);
  1457. for (j = 0; j < width; j++) {
  1458. if (useskip && skip[i][j]) {
  1459. row[j] = 0;
  1460. continue;
  1461. }
  1462. if (j >= sbb_left && j < sbb_right && i >= sbb_top) {
  1463. contextLabel = contextLabel << 1 & reuseMask;
  1464. for (k = 0; k < changingEntriesLength; k++) {
  1465. i0 = i + changingTemplateY[k];
  1466. j0 = j + changingTemplateX[k];
  1467. bit = bitmap[i0][j0];
  1468. if (bit) {
  1469. bit = changingTemplateBit[k];
  1470. contextLabel |= bit;
  1471. }
  1472. }
  1473. } else {
  1474. contextLabel = 0;
  1475. shift = templateLength - 1;
  1476. for (k = 0; k < templateLength; k++, shift--) {
  1477. j0 = j + templateX[k];
  1478. if (j0 >= 0 && j0 < width) {
  1479. i0 = i + templateY[k];
  1480. if (i0 >= 0) {
  1481. bit = bitmap[i0][j0];
  1482. if (bit) {
  1483. contextLabel |= bit << shift;
  1484. }
  1485. }
  1486. }
  1487. }
  1488. }
  1489. var pixel = decoder.readBit(contexts, contextLabel);
  1490. row[j] = pixel;
  1491. }
  1492. }
  1493. return bitmap;
  1494. }
  1495. function decodeRefinement(width, height, templateIndex, referenceBitmap, offsetX, offsetY, prediction, at, decodingContext) {
  1496. var codingTemplate = RefinementTemplates[templateIndex].coding;
  1497. if (templateIndex === 0) {
  1498. codingTemplate = codingTemplate.concat([at[0]]);
  1499. }
  1500. var codingTemplateLength = codingTemplate.length;
  1501. var codingTemplateX = new Int32Array(codingTemplateLength);
  1502. var codingTemplateY = new Int32Array(codingTemplateLength);
  1503. var k;
  1504. for (k = 0; k < codingTemplateLength; k++) {
  1505. codingTemplateX[k] = codingTemplate[k].x;
  1506. codingTemplateY[k] = codingTemplate[k].y;
  1507. }
  1508. var referenceTemplate = RefinementTemplates[templateIndex].reference;
  1509. if (templateIndex === 0) {
  1510. referenceTemplate = referenceTemplate.concat([at[1]]);
  1511. }
  1512. var referenceTemplateLength = referenceTemplate.length;
  1513. var referenceTemplateX = new Int32Array(referenceTemplateLength);
  1514. var referenceTemplateY = new Int32Array(referenceTemplateLength);
  1515. for (k = 0; k < referenceTemplateLength; k++) {
  1516. referenceTemplateX[k] = referenceTemplate[k].x;
  1517. referenceTemplateY[k] = referenceTemplate[k].y;
  1518. }
  1519. var referenceWidth = referenceBitmap[0].length;
  1520. var referenceHeight = referenceBitmap.length;
  1521. var pseudoPixelContext = RefinementReusedContexts[templateIndex];
  1522. var bitmap = [];
  1523. var decoder = decodingContext.decoder;
  1524. var contexts = decodingContext.contextCache.getContexts("GR");
  1525. var ltp = 0;
  1526. for (var i = 0; i < height; i++) {
  1527. if (prediction) {
  1528. var sltp = decoder.readBit(contexts, pseudoPixelContext);
  1529. ltp ^= sltp;
  1530. if (ltp) {
  1531. throw new Jbig2Error("prediction is not supported");
  1532. }
  1533. }
  1534. var row = new Uint8Array(width);
  1535. bitmap.push(row);
  1536. for (var j = 0; j < width; j++) {
  1537. var i0 = void 0,
  1538. j0 = void 0;
  1539. var contextLabel = 0;
  1540. for (k = 0; k < codingTemplateLength; k++) {
  1541. i0 = i + codingTemplateY[k];
  1542. j0 = j + codingTemplateX[k];
  1543. if (i0 < 0 || j0 < 0 || j0 >= width) {
  1544. contextLabel <<= 1;
  1545. } else {
  1546. contextLabel = contextLabel << 1 | bitmap[i0][j0];
  1547. }
  1548. }
  1549. for (k = 0; k < referenceTemplateLength; k++) {
  1550. i0 = i + referenceTemplateY[k] - offsetY;
  1551. j0 = j + referenceTemplateX[k] - offsetX;
  1552. if (i0 < 0 || i0 >= referenceHeight || j0 < 0 || j0 >= referenceWidth) {
  1553. contextLabel <<= 1;
  1554. } else {
  1555. contextLabel = contextLabel << 1 | referenceBitmap[i0][j0];
  1556. }
  1557. }
  1558. var pixel = decoder.readBit(contexts, contextLabel);
  1559. row[j] = pixel;
  1560. }
  1561. }
  1562. return bitmap;
  1563. }
  1564. function decodeSymbolDictionary(huffman, refinement, symbols, numberOfNewSymbols, numberOfExportedSymbols, huffmanTables, templateIndex, at, refinementTemplateIndex, refinementAt, decodingContext, huffmanInput) {
  1565. if (huffman && refinement) {
  1566. throw new Jbig2Error("symbol refinement with Huffman is not supported");
  1567. }
  1568. var newSymbols = [];
  1569. var currentHeight = 0;
  1570. var symbolCodeLength = (0, _core_utils.log2)(symbols.length + numberOfNewSymbols);
  1571. var decoder = decodingContext.decoder;
  1572. var contextCache = decodingContext.contextCache;
  1573. var tableB1, symbolWidths;
  1574. if (huffman) {
  1575. tableB1 = getStandardTable(1);
  1576. symbolWidths = [];
  1577. symbolCodeLength = Math.max(symbolCodeLength, 1);
  1578. }
  1579. while (newSymbols.length < numberOfNewSymbols) {
  1580. var deltaHeight = huffman ? huffmanTables.tableDeltaHeight.decode(huffmanInput) : decodeInteger(contextCache, "IADH", decoder);
  1581. currentHeight += deltaHeight;
  1582. var currentWidth = 0,
  1583. totalWidth = 0;
  1584. var firstSymbol = huffman ? symbolWidths.length : 0;
  1585. while (true) {
  1586. var deltaWidth = huffman ? huffmanTables.tableDeltaWidth.decode(huffmanInput) : decodeInteger(contextCache, "IADW", decoder);
  1587. if (deltaWidth === null) {
  1588. break;
  1589. }
  1590. currentWidth += deltaWidth;
  1591. totalWidth += currentWidth;
  1592. var bitmap = void 0;
  1593. if (refinement) {
  1594. var numberOfInstances = decodeInteger(contextCache, "IAAI", decoder);
  1595. if (numberOfInstances > 1) {
  1596. bitmap = decodeTextRegion(huffman, refinement, currentWidth, currentHeight, 0, numberOfInstances, 1, symbols.concat(newSymbols), symbolCodeLength, 0, 0, 1, 0, huffmanTables, refinementTemplateIndex, refinementAt, decodingContext, 0, huffmanInput);
  1597. } else {
  1598. var symbolId = decodeIAID(contextCache, decoder, symbolCodeLength);
  1599. var rdx = decodeInteger(contextCache, "IARDX", decoder);
  1600. var rdy = decodeInteger(contextCache, "IARDY", decoder);
  1601. var symbol = symbolId < symbols.length ? symbols[symbolId] : newSymbols[symbolId - symbols.length];
  1602. bitmap = decodeRefinement(currentWidth, currentHeight, refinementTemplateIndex, symbol, rdx, rdy, false, refinementAt, decodingContext);
  1603. }
  1604. newSymbols.push(bitmap);
  1605. } else if (huffman) {
  1606. symbolWidths.push(currentWidth);
  1607. } else {
  1608. bitmap = decodeBitmap(false, currentWidth, currentHeight, templateIndex, false, null, at, decodingContext);
  1609. newSymbols.push(bitmap);
  1610. }
  1611. }
  1612. if (huffman && !refinement) {
  1613. var bitmapSize = huffmanTables.tableBitmapSize.decode(huffmanInput);
  1614. huffmanInput.byteAlign();
  1615. var collectiveBitmap = void 0;
  1616. if (bitmapSize === 0) {
  1617. collectiveBitmap = readUncompressedBitmap(huffmanInput, totalWidth, currentHeight);
  1618. } else {
  1619. var originalEnd = huffmanInput.end;
  1620. var bitmapEnd = huffmanInput.position + bitmapSize;
  1621. huffmanInput.end = bitmapEnd;
  1622. collectiveBitmap = decodeMMRBitmap(huffmanInput, totalWidth, currentHeight, false);
  1623. huffmanInput.end = originalEnd;
  1624. huffmanInput.position = bitmapEnd;
  1625. }
  1626. var numberOfSymbolsDecoded = symbolWidths.length;
  1627. if (firstSymbol === numberOfSymbolsDecoded - 1) {
  1628. newSymbols.push(collectiveBitmap);
  1629. } else {
  1630. var _i = void 0,
  1631. y = void 0,
  1632. xMin = 0,
  1633. xMax = void 0,
  1634. bitmapWidth = void 0,
  1635. symbolBitmap = void 0;
  1636. for (_i = firstSymbol; _i < numberOfSymbolsDecoded; _i++) {
  1637. bitmapWidth = symbolWidths[_i];
  1638. xMax = xMin + bitmapWidth;
  1639. symbolBitmap = [];
  1640. for (y = 0; y < currentHeight; y++) {
  1641. symbolBitmap.push(collectiveBitmap[y].subarray(xMin, xMax));
  1642. }
  1643. newSymbols.push(symbolBitmap);
  1644. xMin = xMax;
  1645. }
  1646. }
  1647. }
  1648. }
  1649. var exportedSymbols = [],
  1650. flags = [];
  1651. var currentFlag = false,
  1652. i,
  1653. ii;
  1654. var totalSymbolsLength = symbols.length + numberOfNewSymbols;
  1655. while (flags.length < totalSymbolsLength) {
  1656. var runLength = huffman ? tableB1.decode(huffmanInput) : decodeInteger(contextCache, "IAEX", decoder);
  1657. while (runLength--) {
  1658. flags.push(currentFlag);
  1659. }
  1660. currentFlag = !currentFlag;
  1661. }
  1662. for (i = 0, ii = symbols.length; i < ii; i++) {
  1663. if (flags[i]) {
  1664. exportedSymbols.push(symbols[i]);
  1665. }
  1666. }
  1667. for (var j = 0; j < numberOfNewSymbols; i++, j++) {
  1668. if (flags[i]) {
  1669. exportedSymbols.push(newSymbols[j]);
  1670. }
  1671. }
  1672. return exportedSymbols;
  1673. }
  1674. function decodeTextRegion(huffman, refinement, width, height, defaultPixelValue, numberOfSymbolInstances, stripSize, inputSymbols, symbolCodeLength, transposed, dsOffset, referenceCorner, combinationOperator, huffmanTables, refinementTemplateIndex, refinementAt, decodingContext, logStripSize, huffmanInput) {
  1675. if (huffman && refinement) {
  1676. throw new Jbig2Error("refinement with Huffman is not supported");
  1677. }
  1678. var bitmap = [];
  1679. var i, row;
  1680. for (i = 0; i < height; i++) {
  1681. row = new Uint8Array(width);
  1682. if (defaultPixelValue) {
  1683. for (var j = 0; j < width; j++) {
  1684. row[j] = defaultPixelValue;
  1685. }
  1686. }
  1687. bitmap.push(row);
  1688. }
  1689. var decoder = decodingContext.decoder;
  1690. var contextCache = decodingContext.contextCache;
  1691. var stripT = huffman ? -huffmanTables.tableDeltaT.decode(huffmanInput) : -decodeInteger(contextCache, "IADT", decoder);
  1692. var firstS = 0;
  1693. i = 0;
  1694. while (i < numberOfSymbolInstances) {
  1695. var deltaT = huffman ? huffmanTables.tableDeltaT.decode(huffmanInput) : decodeInteger(contextCache, "IADT", decoder);
  1696. stripT += deltaT;
  1697. var deltaFirstS = huffman ? huffmanTables.tableFirstS.decode(huffmanInput) : decodeInteger(contextCache, "IAFS", decoder);
  1698. firstS += deltaFirstS;
  1699. var currentS = firstS;
  1700. do {
  1701. var currentT = 0;
  1702. if (stripSize > 1) {
  1703. currentT = huffman ? huffmanInput.readBits(logStripSize) : decodeInteger(contextCache, "IAIT", decoder);
  1704. }
  1705. var t = stripSize * stripT + currentT;
  1706. var symbolId = huffman ? huffmanTables.symbolIDTable.decode(huffmanInput) : decodeIAID(contextCache, decoder, symbolCodeLength);
  1707. var applyRefinement = refinement && (huffman ? huffmanInput.readBit() : decodeInteger(contextCache, "IARI", decoder));
  1708. var symbolBitmap = inputSymbols[symbolId];
  1709. var symbolWidth = symbolBitmap[0].length;
  1710. var symbolHeight = symbolBitmap.length;
  1711. if (applyRefinement) {
  1712. var rdw = decodeInteger(contextCache, "IARDW", decoder);
  1713. var rdh = decodeInteger(contextCache, "IARDH", decoder);
  1714. var rdx = decodeInteger(contextCache, "IARDX", decoder);
  1715. var rdy = decodeInteger(contextCache, "IARDY", decoder);
  1716. symbolWidth += rdw;
  1717. symbolHeight += rdh;
  1718. symbolBitmap = decodeRefinement(symbolWidth, symbolHeight, refinementTemplateIndex, symbolBitmap, (rdw >> 1) + rdx, (rdh >> 1) + rdy, false, refinementAt, decodingContext);
  1719. }
  1720. var offsetT = t - (referenceCorner & 1 ? 0 : symbolHeight - 1);
  1721. var offsetS = currentS - (referenceCorner & 2 ? symbolWidth - 1 : 0);
  1722. var s2 = void 0,
  1723. t2 = void 0,
  1724. symbolRow = void 0;
  1725. if (transposed) {
  1726. for (s2 = 0; s2 < symbolHeight; s2++) {
  1727. row = bitmap[offsetS + s2];
  1728. if (!row) {
  1729. continue;
  1730. }
  1731. symbolRow = symbolBitmap[s2];
  1732. var maxWidth = Math.min(width - offsetT, symbolWidth);
  1733. switch (combinationOperator) {
  1734. case 0:
  1735. for (t2 = 0; t2 < maxWidth; t2++) {
  1736. row[offsetT + t2] |= symbolRow[t2];
  1737. }
  1738. break;
  1739. case 2:
  1740. for (t2 = 0; t2 < maxWidth; t2++) {
  1741. row[offsetT + t2] ^= symbolRow[t2];
  1742. }
  1743. break;
  1744. default:
  1745. throw new Jbig2Error("operator ".concat(combinationOperator, " is not supported"));
  1746. }
  1747. }
  1748. currentS += symbolHeight - 1;
  1749. } else {
  1750. for (t2 = 0; t2 < symbolHeight; t2++) {
  1751. row = bitmap[offsetT + t2];
  1752. if (!row) {
  1753. continue;
  1754. }
  1755. symbolRow = symbolBitmap[t2];
  1756. switch (combinationOperator) {
  1757. case 0:
  1758. for (s2 = 0; s2 < symbolWidth; s2++) {
  1759. row[offsetS + s2] |= symbolRow[s2];
  1760. }
  1761. break;
  1762. case 2:
  1763. for (s2 = 0; s2 < symbolWidth; s2++) {
  1764. row[offsetS + s2] ^= symbolRow[s2];
  1765. }
  1766. break;
  1767. default:
  1768. throw new Jbig2Error("operator ".concat(combinationOperator, " is not supported"));
  1769. }
  1770. }
  1771. currentS += symbolWidth - 1;
  1772. }
  1773. i++;
  1774. var deltaS = huffman ? huffmanTables.tableDeltaS.decode(huffmanInput) : decodeInteger(contextCache, "IADS", decoder);
  1775. if (deltaS === null) {
  1776. break;
  1777. }
  1778. currentS += deltaS + dsOffset;
  1779. } while (true);
  1780. }
  1781. return bitmap;
  1782. }
  1783. function decodePatternDictionary(mmr, patternWidth, patternHeight, maxPatternIndex, template, decodingContext) {
  1784. var at = [];
  1785. if (!mmr) {
  1786. at.push({
  1787. x: -patternWidth,
  1788. y: 0
  1789. });
  1790. if (template === 0) {
  1791. at.push({
  1792. x: -3,
  1793. y: -1
  1794. }, {
  1795. x: 2,
  1796. y: -2
  1797. }, {
  1798. x: -2,
  1799. y: -2
  1800. });
  1801. }
  1802. }
  1803. var collectiveWidth = (maxPatternIndex + 1) * patternWidth;
  1804. var collectiveBitmap = decodeBitmap(mmr, collectiveWidth, patternHeight, template, false, null, at, decodingContext);
  1805. var patterns = [];
  1806. for (var i = 0; i <= maxPatternIndex; i++) {
  1807. var patternBitmap = [];
  1808. var xMin = patternWidth * i;
  1809. var xMax = xMin + patternWidth;
  1810. for (var y = 0; y < patternHeight; y++) {
  1811. patternBitmap.push(collectiveBitmap[y].subarray(xMin, xMax));
  1812. }
  1813. patterns.push(patternBitmap);
  1814. }
  1815. return patterns;
  1816. }
  1817. function decodeHalftoneRegion(mmr, patterns, template, regionWidth, regionHeight, defaultPixelValue, enableSkip, combinationOperator, gridWidth, gridHeight, gridOffsetX, gridOffsetY, gridVectorX, gridVectorY, decodingContext) {
  1818. var skip = null;
  1819. if (enableSkip) {
  1820. throw new Jbig2Error("skip is not supported");
  1821. }
  1822. if (combinationOperator !== 0) {
  1823. throw new Jbig2Error("operator \"".concat(combinationOperator, "\" is not supported in halftone region"));
  1824. }
  1825. var regionBitmap = [];
  1826. var i, j, row;
  1827. for (i = 0; i < regionHeight; i++) {
  1828. row = new Uint8Array(regionWidth);
  1829. if (defaultPixelValue) {
  1830. for (j = 0; j < regionWidth; j++) {
  1831. row[j] = defaultPixelValue;
  1832. }
  1833. }
  1834. regionBitmap.push(row);
  1835. }
  1836. var numberOfPatterns = patterns.length;
  1837. var pattern0 = patterns[0];
  1838. var patternWidth = pattern0[0].length,
  1839. patternHeight = pattern0.length;
  1840. var bitsPerValue = (0, _core_utils.log2)(numberOfPatterns);
  1841. var at = [];
  1842. if (!mmr) {
  1843. at.push({
  1844. x: template <= 1 ? 3 : 2,
  1845. y: -1
  1846. });
  1847. if (template === 0) {
  1848. at.push({
  1849. x: -3,
  1850. y: -1
  1851. }, {
  1852. x: 2,
  1853. y: -2
  1854. }, {
  1855. x: -2,
  1856. y: -2
  1857. });
  1858. }
  1859. }
  1860. var grayScaleBitPlanes = [];
  1861. var mmrInput, bitmap;
  1862. if (mmr) {
  1863. mmrInput = new Reader(decodingContext.data, decodingContext.start, decodingContext.end);
  1864. }
  1865. for (i = bitsPerValue - 1; i >= 0; i--) {
  1866. if (mmr) {
  1867. bitmap = decodeMMRBitmap(mmrInput, gridWidth, gridHeight, true);
  1868. } else {
  1869. bitmap = decodeBitmap(false, gridWidth, gridHeight, template, false, skip, at, decodingContext);
  1870. }
  1871. grayScaleBitPlanes[i] = bitmap;
  1872. }
  1873. var mg, ng, bit, patternIndex, patternBitmap, x, y, patternRow, regionRow;
  1874. for (mg = 0; mg < gridHeight; mg++) {
  1875. for (ng = 0; ng < gridWidth; ng++) {
  1876. bit = 0;
  1877. patternIndex = 0;
  1878. for (j = bitsPerValue - 1; j >= 0; j--) {
  1879. bit ^= grayScaleBitPlanes[j][mg][ng];
  1880. patternIndex |= bit << j;
  1881. }
  1882. patternBitmap = patterns[patternIndex];
  1883. x = gridOffsetX + mg * gridVectorY + ng * gridVectorX >> 8;
  1884. y = gridOffsetY + mg * gridVectorX - ng * gridVectorY >> 8;
  1885. if (x >= 0 && x + patternWidth <= regionWidth && y >= 0 && y + patternHeight <= regionHeight) {
  1886. for (i = 0; i < patternHeight; i++) {
  1887. regionRow = regionBitmap[y + i];
  1888. patternRow = patternBitmap[i];
  1889. for (j = 0; j < patternWidth; j++) {
  1890. regionRow[x + j] |= patternRow[j];
  1891. }
  1892. }
  1893. } else {
  1894. var regionX = void 0,
  1895. regionY = void 0;
  1896. for (i = 0; i < patternHeight; i++) {
  1897. regionY = y + i;
  1898. if (regionY < 0 || regionY >= regionHeight) {
  1899. continue;
  1900. }
  1901. regionRow = regionBitmap[regionY];
  1902. patternRow = patternBitmap[i];
  1903. for (j = 0; j < patternWidth; j++) {
  1904. regionX = x + j;
  1905. if (regionX >= 0 && regionX < regionWidth) {
  1906. regionRow[regionX] |= patternRow[j];
  1907. }
  1908. }
  1909. }
  1910. }
  1911. }
  1912. }
  1913. return regionBitmap;
  1914. }
  1915. function readSegmentHeader(data, start) {
  1916. var segmentHeader = {};
  1917. segmentHeader.number = (0, _core_utils.readUint32)(data, start);
  1918. var flags = data[start + 4];
  1919. var segmentType = flags & 0x3f;
  1920. if (!SegmentTypes[segmentType]) {
  1921. throw new Jbig2Error("invalid segment type: " + segmentType);
  1922. }
  1923. segmentHeader.type = segmentType;
  1924. segmentHeader.typeName = SegmentTypes[segmentType];
  1925. segmentHeader.deferredNonRetain = !!(flags & 0x80);
  1926. var pageAssociationFieldSize = !!(flags & 0x40);
  1927. var referredFlags = data[start + 5];
  1928. var referredToCount = referredFlags >> 5 & 7;
  1929. var retainBits = [referredFlags & 31];
  1930. var position = start + 6;
  1931. if (referredFlags === 7) {
  1932. referredToCount = (0, _core_utils.readUint32)(data, position - 1) & 0x1fffffff;
  1933. position += 3;
  1934. var bytes = referredToCount + 7 >> 3;
  1935. retainBits[0] = data[position++];
  1936. while (--bytes > 0) {
  1937. retainBits.push(data[position++]);
  1938. }
  1939. } else if (referredFlags === 5 || referredFlags === 6) {
  1940. throw new Jbig2Error("invalid referred-to flags");
  1941. }
  1942. segmentHeader.retainBits = retainBits;
  1943. var referredToSegmentNumberSize = 4;
  1944. if (segmentHeader.number <= 256) {
  1945. referredToSegmentNumberSize = 1;
  1946. } else if (segmentHeader.number <= 65536) {
  1947. referredToSegmentNumberSize = 2;
  1948. }
  1949. var referredTo = [];
  1950. var i, ii;
  1951. for (i = 0; i < referredToCount; i++) {
  1952. var number = void 0;
  1953. if (referredToSegmentNumberSize === 1) {
  1954. number = data[position];
  1955. } else if (referredToSegmentNumberSize === 2) {
  1956. number = (0, _core_utils.readUint16)(data, position);
  1957. } else {
  1958. number = (0, _core_utils.readUint32)(data, position);
  1959. }
  1960. referredTo.push(number);
  1961. position += referredToSegmentNumberSize;
  1962. }
  1963. segmentHeader.referredTo = referredTo;
  1964. if (!pageAssociationFieldSize) {
  1965. segmentHeader.pageAssociation = data[position++];
  1966. } else {
  1967. segmentHeader.pageAssociation = (0, _core_utils.readUint32)(data, position);
  1968. position += 4;
  1969. }
  1970. segmentHeader.length = (0, _core_utils.readUint32)(data, position);
  1971. position += 4;
  1972. if (segmentHeader.length === 0xffffffff) {
  1973. if (segmentType === 38) {
  1974. var genericRegionInfo = readRegionSegmentInformation(data, position);
  1975. var genericRegionSegmentFlags = data[position + RegionSegmentInformationFieldLength];
  1976. var genericRegionMmr = !!(genericRegionSegmentFlags & 1);
  1977. var searchPatternLength = 6;
  1978. var searchPattern = new Uint8Array(searchPatternLength);
  1979. if (!genericRegionMmr) {
  1980. searchPattern[0] = 0xff;
  1981. searchPattern[1] = 0xac;
  1982. }
  1983. searchPattern[2] = genericRegionInfo.height >>> 24 & 0xff;
  1984. searchPattern[3] = genericRegionInfo.height >> 16 & 0xff;
  1985. searchPattern[4] = genericRegionInfo.height >> 8 & 0xff;
  1986. searchPattern[5] = genericRegionInfo.height & 0xff;
  1987. for (i = position, ii = data.length; i < ii; i++) {
  1988. var j = 0;
  1989. while (j < searchPatternLength && searchPattern[j] === data[i + j]) {
  1990. j++;
  1991. }
  1992. if (j === searchPatternLength) {
  1993. segmentHeader.length = i + searchPatternLength;
  1994. break;
  1995. }
  1996. }
  1997. if (segmentHeader.length === 0xffffffff) {
  1998. throw new Jbig2Error("segment end was not found");
  1999. }
  2000. } else {
  2001. throw new Jbig2Error("invalid unknown segment length");
  2002. }
  2003. }
  2004. segmentHeader.headerEnd = position;
  2005. return segmentHeader;
  2006. }
  2007. function readSegments(header, data, start, end) {
  2008. var segments = [];
  2009. var position = start;
  2010. while (position < end) {
  2011. var segmentHeader = readSegmentHeader(data, position);
  2012. position = segmentHeader.headerEnd;
  2013. var segment = {
  2014. header: segmentHeader,
  2015. data: data
  2016. };
  2017. if (!header.randomAccess) {
  2018. segment.start = position;
  2019. position += segmentHeader.length;
  2020. segment.end = position;
  2021. }
  2022. segments.push(segment);
  2023. if (segmentHeader.type === 51) {
  2024. break;
  2025. }
  2026. }
  2027. if (header.randomAccess) {
  2028. for (var i = 0, ii = segments.length; i < ii; i++) {
  2029. segments[i].start = position;
  2030. position += segments[i].header.length;
  2031. segments[i].end = position;
  2032. }
  2033. }
  2034. return segments;
  2035. }
  2036. function readRegionSegmentInformation(data, start) {
  2037. return {
  2038. width: (0, _core_utils.readUint32)(data, start),
  2039. height: (0, _core_utils.readUint32)(data, start + 4),
  2040. x: (0, _core_utils.readUint32)(data, start + 8),
  2041. y: (0, _core_utils.readUint32)(data, start + 12),
  2042. combinationOperator: data[start + 16] & 7
  2043. };
  2044. }
  2045. var RegionSegmentInformationFieldLength = 17;
  2046. function processSegment(segment, visitor) {
  2047. var header = segment.header;
  2048. var data = segment.data,
  2049. end = segment.end;
  2050. var position = segment.start;
  2051. var args, at, i, atLength;
  2052. switch (header.type) {
  2053. case 0:
  2054. var dictionary = {};
  2055. var dictionaryFlags = (0, _core_utils.readUint16)(data, position);
  2056. dictionary.huffman = !!(dictionaryFlags & 1);
  2057. dictionary.refinement = !!(dictionaryFlags & 2);
  2058. dictionary.huffmanDHSelector = dictionaryFlags >> 2 & 3;
  2059. dictionary.huffmanDWSelector = dictionaryFlags >> 4 & 3;
  2060. dictionary.bitmapSizeSelector = dictionaryFlags >> 6 & 1;
  2061. dictionary.aggregationInstancesSelector = dictionaryFlags >> 7 & 1;
  2062. dictionary.bitmapCodingContextUsed = !!(dictionaryFlags & 256);
  2063. dictionary.bitmapCodingContextRetained = !!(dictionaryFlags & 512);
  2064. dictionary.template = dictionaryFlags >> 10 & 3;
  2065. dictionary.refinementTemplate = dictionaryFlags >> 12 & 1;
  2066. position += 2;
  2067. if (!dictionary.huffman) {
  2068. atLength = dictionary.template === 0 ? 4 : 1;
  2069. at = [];
  2070. for (i = 0; i < atLength; i++) {
  2071. at.push({
  2072. x: (0, _core_utils.readInt8)(data, position),
  2073. y: (0, _core_utils.readInt8)(data, position + 1)
  2074. });
  2075. position += 2;
  2076. }
  2077. dictionary.at = at;
  2078. }
  2079. if (dictionary.refinement && !dictionary.refinementTemplate) {
  2080. at = [];
  2081. for (i = 0; i < 2; i++) {
  2082. at.push({
  2083. x: (0, _core_utils.readInt8)(data, position),
  2084. y: (0, _core_utils.readInt8)(data, position + 1)
  2085. });
  2086. position += 2;
  2087. }
  2088. dictionary.refinementAt = at;
  2089. }
  2090. dictionary.numberOfExportedSymbols = (0, _core_utils.readUint32)(data, position);
  2091. position += 4;
  2092. dictionary.numberOfNewSymbols = (0, _core_utils.readUint32)(data, position);
  2093. position += 4;
  2094. args = [dictionary, header.number, header.referredTo, data, position, end];
  2095. break;
  2096. case 6:
  2097. case 7:
  2098. var textRegion = {};
  2099. textRegion.info = readRegionSegmentInformation(data, position);
  2100. position += RegionSegmentInformationFieldLength;
  2101. var textRegionSegmentFlags = (0, _core_utils.readUint16)(data, position);
  2102. position += 2;
  2103. textRegion.huffman = !!(textRegionSegmentFlags & 1);
  2104. textRegion.refinement = !!(textRegionSegmentFlags & 2);
  2105. textRegion.logStripSize = textRegionSegmentFlags >> 2 & 3;
  2106. textRegion.stripSize = 1 << textRegion.logStripSize;
  2107. textRegion.referenceCorner = textRegionSegmentFlags >> 4 & 3;
  2108. textRegion.transposed = !!(textRegionSegmentFlags & 64);
  2109. textRegion.combinationOperator = textRegionSegmentFlags >> 7 & 3;
  2110. textRegion.defaultPixelValue = textRegionSegmentFlags >> 9 & 1;
  2111. textRegion.dsOffset = textRegionSegmentFlags << 17 >> 27;
  2112. textRegion.refinementTemplate = textRegionSegmentFlags >> 15 & 1;
  2113. if (textRegion.huffman) {
  2114. var textRegionHuffmanFlags = (0, _core_utils.readUint16)(data, position);
  2115. position += 2;
  2116. textRegion.huffmanFS = textRegionHuffmanFlags & 3;
  2117. textRegion.huffmanDS = textRegionHuffmanFlags >> 2 & 3;
  2118. textRegion.huffmanDT = textRegionHuffmanFlags >> 4 & 3;
  2119. textRegion.huffmanRefinementDW = textRegionHuffmanFlags >> 6 & 3;
  2120. textRegion.huffmanRefinementDH = textRegionHuffmanFlags >> 8 & 3;
  2121. textRegion.huffmanRefinementDX = textRegionHuffmanFlags >> 10 & 3;
  2122. textRegion.huffmanRefinementDY = textRegionHuffmanFlags >> 12 & 3;
  2123. textRegion.huffmanRefinementSizeSelector = !!(textRegionHuffmanFlags & 0x4000);
  2124. }
  2125. if (textRegion.refinement && !textRegion.refinementTemplate) {
  2126. at = [];
  2127. for (i = 0; i < 2; i++) {
  2128. at.push({
  2129. x: (0, _core_utils.readInt8)(data, position),
  2130. y: (0, _core_utils.readInt8)(data, position + 1)
  2131. });
  2132. position += 2;
  2133. }
  2134. textRegion.refinementAt = at;
  2135. }
  2136. textRegion.numberOfSymbolInstances = (0, _core_utils.readUint32)(data, position);
  2137. position += 4;
  2138. args = [textRegion, header.referredTo, data, position, end];
  2139. break;
  2140. case 16:
  2141. var patternDictionary = {};
  2142. var patternDictionaryFlags = data[position++];
  2143. patternDictionary.mmr = !!(patternDictionaryFlags & 1);
  2144. patternDictionary.template = patternDictionaryFlags >> 1 & 3;
  2145. patternDictionary.patternWidth = data[position++];
  2146. patternDictionary.patternHeight = data[position++];
  2147. patternDictionary.maxPatternIndex = (0, _core_utils.readUint32)(data, position);
  2148. position += 4;
  2149. args = [patternDictionary, header.number, data, position, end];
  2150. break;
  2151. case 22:
  2152. case 23:
  2153. var halftoneRegion = {};
  2154. halftoneRegion.info = readRegionSegmentInformation(data, position);
  2155. position += RegionSegmentInformationFieldLength;
  2156. var halftoneRegionFlags = data[position++];
  2157. halftoneRegion.mmr = !!(halftoneRegionFlags & 1);
  2158. halftoneRegion.template = halftoneRegionFlags >> 1 & 3;
  2159. halftoneRegion.enableSkip = !!(halftoneRegionFlags & 8);
  2160. halftoneRegion.combinationOperator = halftoneRegionFlags >> 4 & 7;
  2161. halftoneRegion.defaultPixelValue = halftoneRegionFlags >> 7 & 1;
  2162. halftoneRegion.gridWidth = (0, _core_utils.readUint32)(data, position);
  2163. position += 4;
  2164. halftoneRegion.gridHeight = (0, _core_utils.readUint32)(data, position);
  2165. position += 4;
  2166. halftoneRegion.gridOffsetX = (0, _core_utils.readUint32)(data, position) & 0xffffffff;
  2167. position += 4;
  2168. halftoneRegion.gridOffsetY = (0, _core_utils.readUint32)(data, position) & 0xffffffff;
  2169. position += 4;
  2170. halftoneRegion.gridVectorX = (0, _core_utils.readUint16)(data, position);
  2171. position += 2;
  2172. halftoneRegion.gridVectorY = (0, _core_utils.readUint16)(data, position);
  2173. position += 2;
  2174. args = [halftoneRegion, header.referredTo, data, position, end];
  2175. break;
  2176. case 38:
  2177. case 39:
  2178. var genericRegion = {};
  2179. genericRegion.info = readRegionSegmentInformation(data, position);
  2180. position += RegionSegmentInformationFieldLength;
  2181. var genericRegionSegmentFlags = data[position++];
  2182. genericRegion.mmr = !!(genericRegionSegmentFlags & 1);
  2183. genericRegion.template = genericRegionSegmentFlags >> 1 & 3;
  2184. genericRegion.prediction = !!(genericRegionSegmentFlags & 8);
  2185. if (!genericRegion.mmr) {
  2186. atLength = genericRegion.template === 0 ? 4 : 1;
  2187. at = [];
  2188. for (i = 0; i < atLength; i++) {
  2189. at.push({
  2190. x: (0, _core_utils.readInt8)(data, position),
  2191. y: (0, _core_utils.readInt8)(data, position + 1)
  2192. });
  2193. position += 2;
  2194. }
  2195. genericRegion.at = at;
  2196. }
  2197. args = [genericRegion, data, position, end];
  2198. break;
  2199. case 48:
  2200. var pageInfo = {
  2201. width: (0, _core_utils.readUint32)(data, position),
  2202. height: (0, _core_utils.readUint32)(data, position + 4),
  2203. resolutionX: (0, _core_utils.readUint32)(data, position + 8),
  2204. resolutionY: (0, _core_utils.readUint32)(data, position + 12)
  2205. };
  2206. if (pageInfo.height === 0xffffffff) {
  2207. delete pageInfo.height;
  2208. }
  2209. var pageSegmentFlags = data[position + 16];
  2210. (0, _core_utils.readUint16)(data, position + 17);
  2211. pageInfo.lossless = !!(pageSegmentFlags & 1);
  2212. pageInfo.refinement = !!(pageSegmentFlags & 2);
  2213. pageInfo.defaultPixelValue = pageSegmentFlags >> 2 & 1;
  2214. pageInfo.combinationOperator = pageSegmentFlags >> 3 & 3;
  2215. pageInfo.requiresBuffer = !!(pageSegmentFlags & 32);
  2216. pageInfo.combinationOperatorOverride = !!(pageSegmentFlags & 64);
  2217. args = [pageInfo];
  2218. break;
  2219. case 49:
  2220. break;
  2221. case 50:
  2222. break;
  2223. case 51:
  2224. break;
  2225. case 53:
  2226. args = [header.number, data, position, end];
  2227. break;
  2228. case 62:
  2229. break;
  2230. default:
  2231. throw new Jbig2Error("segment type ".concat(header.typeName, "(").concat(header.type, ")") + " is not implemented");
  2232. }
  2233. var callbackName = "on" + header.typeName;
  2234. if (callbackName in visitor) {
  2235. visitor[callbackName].apply(visitor, args);
  2236. }
  2237. }
  2238. function processSegments(segments, visitor) {
  2239. for (var i = 0, ii = segments.length; i < ii; i++) {
  2240. processSegment(segments[i], visitor);
  2241. }
  2242. }
  2243. function parseJbig2Chunks(chunks) {
  2244. var visitor = new SimpleSegmentVisitor();
  2245. for (var i = 0, ii = chunks.length; i < ii; i++) {
  2246. var chunk = chunks[i];
  2247. var segments = readSegments({}, chunk.data, chunk.start, chunk.end);
  2248. processSegments(segments, visitor);
  2249. }
  2250. return visitor.buffer;
  2251. }
  2252. function parseJbig2(data) {
  2253. var end = data.length;
  2254. var position = 0;
  2255. if (data[position] !== 0x97 || data[position + 1] !== 0x4a || data[position + 2] !== 0x42 || data[position + 3] !== 0x32 || data[position + 4] !== 0x0d || data[position + 5] !== 0x0a || data[position + 6] !== 0x1a || data[position + 7] !== 0x0a) {
  2256. throw new Jbig2Error("parseJbig2 - invalid header.");
  2257. }
  2258. var header = Object.create(null);
  2259. position += 8;
  2260. var flags = data[position++];
  2261. header.randomAccess = !(flags & 1);
  2262. if (!(flags & 2)) {
  2263. header.numberOfPages = (0, _core_utils.readUint32)(data, position);
  2264. position += 4;
  2265. }
  2266. var segments = readSegments(header, data, position, end);
  2267. var visitor = new SimpleSegmentVisitor();
  2268. processSegments(segments, visitor);
  2269. var _visitor$currentPageI = visitor.currentPageInfo,
  2270. width = _visitor$currentPageI.width,
  2271. height = _visitor$currentPageI.height;
  2272. var bitPacked = visitor.buffer;
  2273. var imgData = new Uint8ClampedArray(width * height);
  2274. var q = 0,
  2275. k = 0;
  2276. for (var i = 0; i < height; i++) {
  2277. var mask = 0,
  2278. buffer = void 0;
  2279. for (var j = 0; j < width; j++) {
  2280. if (!mask) {
  2281. mask = 128;
  2282. buffer = bitPacked[k++];
  2283. }
  2284. imgData[q++] = buffer & mask ? 0 : 255;
  2285. mask >>= 1;
  2286. }
  2287. }
  2288. return {
  2289. imgData: imgData,
  2290. width: width,
  2291. height: height
  2292. };
  2293. }
  2294. var SimpleSegmentVisitor = /*#__PURE__*/function () {
  2295. function SimpleSegmentVisitor() {
  2296. _classCallCheck(this, SimpleSegmentVisitor);
  2297. }
  2298. _createClass(SimpleSegmentVisitor, [{
  2299. key: "onPageInformation",
  2300. value: function onPageInformation(info) {
  2301. this.currentPageInfo = info;
  2302. var rowSize = info.width + 7 >> 3;
  2303. var buffer = new Uint8ClampedArray(rowSize * info.height);
  2304. if (info.defaultPixelValue) {
  2305. buffer.fill(0xff);
  2306. }
  2307. this.buffer = buffer;
  2308. }
  2309. }, {
  2310. key: "drawBitmap",
  2311. value: function drawBitmap(regionInfo, bitmap) {
  2312. var pageInfo = this.currentPageInfo;
  2313. var width = regionInfo.width,
  2314. height = regionInfo.height;
  2315. var rowSize = pageInfo.width + 7 >> 3;
  2316. var combinationOperator = pageInfo.combinationOperatorOverride ? regionInfo.combinationOperator : pageInfo.combinationOperator;
  2317. var buffer = this.buffer;
  2318. var mask0 = 128 >> (regionInfo.x & 7);
  2319. var offset0 = regionInfo.y * rowSize + (regionInfo.x >> 3);
  2320. var i, j, mask, offset;
  2321. switch (combinationOperator) {
  2322. case 0:
  2323. for (i = 0; i < height; i++) {
  2324. mask = mask0;
  2325. offset = offset0;
  2326. for (j = 0; j < width; j++) {
  2327. if (bitmap[i][j]) {
  2328. buffer[offset] |= mask;
  2329. }
  2330. mask >>= 1;
  2331. if (!mask) {
  2332. mask = 128;
  2333. offset++;
  2334. }
  2335. }
  2336. offset0 += rowSize;
  2337. }
  2338. break;
  2339. case 2:
  2340. for (i = 0; i < height; i++) {
  2341. mask = mask0;
  2342. offset = offset0;
  2343. for (j = 0; j < width; j++) {
  2344. if (bitmap[i][j]) {
  2345. buffer[offset] ^= mask;
  2346. }
  2347. mask >>= 1;
  2348. if (!mask) {
  2349. mask = 128;
  2350. offset++;
  2351. }
  2352. }
  2353. offset0 += rowSize;
  2354. }
  2355. break;
  2356. default:
  2357. throw new Jbig2Error("operator ".concat(combinationOperator, " is not supported"));
  2358. }
  2359. }
  2360. }, {
  2361. key: "onImmediateGenericRegion",
  2362. value: function onImmediateGenericRegion(region, data, start, end) {
  2363. var regionInfo = region.info;
  2364. var decodingContext = new DecodingContext(data, start, end);
  2365. var bitmap = decodeBitmap(region.mmr, regionInfo.width, regionInfo.height, region.template, region.prediction, null, region.at, decodingContext);
  2366. this.drawBitmap(regionInfo, bitmap);
  2367. }
  2368. }, {
  2369. key: "onImmediateLosslessGenericRegion",
  2370. value: function onImmediateLosslessGenericRegion() {
  2371. this.onImmediateGenericRegion.apply(this, arguments);
  2372. }
  2373. }, {
  2374. key: "onSymbolDictionary",
  2375. value: function onSymbolDictionary(dictionary, currentSegment, referredSegments, data, start, end) {
  2376. var huffmanTables, huffmanInput;
  2377. if (dictionary.huffman) {
  2378. huffmanTables = getSymbolDictionaryHuffmanTables(dictionary, referredSegments, this.customTables);
  2379. huffmanInput = new Reader(data, start, end);
  2380. }
  2381. var symbols = this.symbols;
  2382. if (!symbols) {
  2383. this.symbols = symbols = {};
  2384. }
  2385. var inputSymbols = [];
  2386. for (var i = 0, ii = referredSegments.length; i < ii; i++) {
  2387. var referredSymbols = symbols[referredSegments[i]];
  2388. if (referredSymbols) {
  2389. inputSymbols = inputSymbols.concat(referredSymbols);
  2390. }
  2391. }
  2392. var decodingContext = new DecodingContext(data, start, end);
  2393. symbols[currentSegment] = decodeSymbolDictionary(dictionary.huffman, dictionary.refinement, inputSymbols, dictionary.numberOfNewSymbols, dictionary.numberOfExportedSymbols, huffmanTables, dictionary.template, dictionary.at, dictionary.refinementTemplate, dictionary.refinementAt, decodingContext, huffmanInput);
  2394. }
  2395. }, {
  2396. key: "onImmediateTextRegion",
  2397. value: function onImmediateTextRegion(region, referredSegments, data, start, end) {
  2398. var regionInfo = region.info;
  2399. var huffmanTables, huffmanInput;
  2400. var symbols = this.symbols;
  2401. var inputSymbols = [];
  2402. for (var i = 0, ii = referredSegments.length; i < ii; i++) {
  2403. var referredSymbols = symbols[referredSegments[i]];
  2404. if (referredSymbols) {
  2405. inputSymbols = inputSymbols.concat(referredSymbols);
  2406. }
  2407. }
  2408. var symbolCodeLength = (0, _core_utils.log2)(inputSymbols.length);
  2409. if (region.huffman) {
  2410. huffmanInput = new Reader(data, start, end);
  2411. huffmanTables = getTextRegionHuffmanTables(region, referredSegments, this.customTables, inputSymbols.length, huffmanInput);
  2412. }
  2413. var decodingContext = new DecodingContext(data, start, end);
  2414. var bitmap = decodeTextRegion(region.huffman, region.refinement, regionInfo.width, regionInfo.height, region.defaultPixelValue, region.numberOfSymbolInstances, region.stripSize, inputSymbols, symbolCodeLength, region.transposed, region.dsOffset, region.referenceCorner, region.combinationOperator, huffmanTables, region.refinementTemplate, region.refinementAt, decodingContext, region.logStripSize, huffmanInput);
  2415. this.drawBitmap(regionInfo, bitmap);
  2416. }
  2417. }, {
  2418. key: "onImmediateLosslessTextRegion",
  2419. value: function onImmediateLosslessTextRegion() {
  2420. this.onImmediateTextRegion.apply(this, arguments);
  2421. }
  2422. }, {
  2423. key: "onPatternDictionary",
  2424. value: function onPatternDictionary(dictionary, currentSegment, data, start, end) {
  2425. var patterns = this.patterns;
  2426. if (!patterns) {
  2427. this.patterns = patterns = {};
  2428. }
  2429. var decodingContext = new DecodingContext(data, start, end);
  2430. patterns[currentSegment] = decodePatternDictionary(dictionary.mmr, dictionary.patternWidth, dictionary.patternHeight, dictionary.maxPatternIndex, dictionary.template, decodingContext);
  2431. }
  2432. }, {
  2433. key: "onImmediateHalftoneRegion",
  2434. value: function onImmediateHalftoneRegion(region, referredSegments, data, start, end) {
  2435. var patterns = this.patterns[referredSegments[0]];
  2436. var regionInfo = region.info;
  2437. var decodingContext = new DecodingContext(data, start, end);
  2438. var bitmap = decodeHalftoneRegion(region.mmr, patterns, region.template, regionInfo.width, regionInfo.height, region.defaultPixelValue, region.enableSkip, region.combinationOperator, region.gridWidth, region.gridHeight, region.gridOffsetX, region.gridOffsetY, region.gridVectorX, region.gridVectorY, decodingContext);
  2439. this.drawBitmap(regionInfo, bitmap);
  2440. }
  2441. }, {
  2442. key: "onImmediateLosslessHalftoneRegion",
  2443. value: function onImmediateLosslessHalftoneRegion() {
  2444. this.onImmediateHalftoneRegion.apply(this, arguments);
  2445. }
  2446. }, {
  2447. key: "onTables",
  2448. value: function onTables(currentSegment, data, start, end) {
  2449. var customTables = this.customTables;
  2450. if (!customTables) {
  2451. this.customTables = customTables = {};
  2452. }
  2453. customTables[currentSegment] = decodeTablesSegment(data, start, end);
  2454. }
  2455. }]);
  2456. return SimpleSegmentVisitor;
  2457. }();
  2458. var HuffmanLine = /*#__PURE__*/_createClass(function HuffmanLine(lineData) {
  2459. _classCallCheck(this, HuffmanLine);
  2460. if (lineData.length === 2) {
  2461. this.isOOB = true;
  2462. this.rangeLow = 0;
  2463. this.prefixLength = lineData[0];
  2464. this.rangeLength = 0;
  2465. this.prefixCode = lineData[1];
  2466. this.isLowerRange = false;
  2467. } else {
  2468. this.isOOB = false;
  2469. this.rangeLow = lineData[0];
  2470. this.prefixLength = lineData[1];
  2471. this.rangeLength = lineData[2];
  2472. this.prefixCode = lineData[3];
  2473. this.isLowerRange = lineData[4] === "lower";
  2474. }
  2475. });
  2476. var HuffmanTreeNode = /*#__PURE__*/function () {
  2477. function HuffmanTreeNode(line) {
  2478. _classCallCheck(this, HuffmanTreeNode);
  2479. this.children = [];
  2480. if (line) {
  2481. this.isLeaf = true;
  2482. this.rangeLength = line.rangeLength;
  2483. this.rangeLow = line.rangeLow;
  2484. this.isLowerRange = line.isLowerRange;
  2485. this.isOOB = line.isOOB;
  2486. } else {
  2487. this.isLeaf = false;
  2488. }
  2489. }
  2490. _createClass(HuffmanTreeNode, [{
  2491. key: "buildTree",
  2492. value: function buildTree(line, shift) {
  2493. var bit = line.prefixCode >> shift & 1;
  2494. if (shift <= 0) {
  2495. this.children[bit] = new HuffmanTreeNode(line);
  2496. } else {
  2497. var node = this.children[bit];
  2498. if (!node) {
  2499. this.children[bit] = node = new HuffmanTreeNode(null);
  2500. }
  2501. node.buildTree(line, shift - 1);
  2502. }
  2503. }
  2504. }, {
  2505. key: "decodeNode",
  2506. value: function decodeNode(reader) {
  2507. if (this.isLeaf) {
  2508. if (this.isOOB) {
  2509. return null;
  2510. }
  2511. var htOffset = reader.readBits(this.rangeLength);
  2512. return this.rangeLow + (this.isLowerRange ? -htOffset : htOffset);
  2513. }
  2514. var node = this.children[reader.readBit()];
  2515. if (!node) {
  2516. throw new Jbig2Error("invalid Huffman data");
  2517. }
  2518. return node.decodeNode(reader);
  2519. }
  2520. }]);
  2521. return HuffmanTreeNode;
  2522. }();
  2523. var HuffmanTable = /*#__PURE__*/function () {
  2524. function HuffmanTable(lines, prefixCodesDone) {
  2525. _classCallCheck(this, HuffmanTable);
  2526. if (!prefixCodesDone) {
  2527. this.assignPrefixCodes(lines);
  2528. }
  2529. this.rootNode = new HuffmanTreeNode(null);
  2530. for (var i = 0, ii = lines.length; i < ii; i++) {
  2531. var line = lines[i];
  2532. if (line.prefixLength > 0) {
  2533. this.rootNode.buildTree(line, line.prefixLength - 1);
  2534. }
  2535. }
  2536. }
  2537. _createClass(HuffmanTable, [{
  2538. key: "decode",
  2539. value: function decode(reader) {
  2540. return this.rootNode.decodeNode(reader);
  2541. }
  2542. }, {
  2543. key: "assignPrefixCodes",
  2544. value: function assignPrefixCodes(lines) {
  2545. var linesLength = lines.length;
  2546. var prefixLengthMax = 0;
  2547. for (var i = 0; i < linesLength; i++) {
  2548. prefixLengthMax = Math.max(prefixLengthMax, lines[i].prefixLength);
  2549. }
  2550. var histogram = new Uint32Array(prefixLengthMax + 1);
  2551. for (var _i2 = 0; _i2 < linesLength; _i2++) {
  2552. histogram[lines[_i2].prefixLength]++;
  2553. }
  2554. var currentLength = 1,
  2555. firstCode = 0,
  2556. currentCode,
  2557. currentTemp,
  2558. line;
  2559. histogram[0] = 0;
  2560. while (currentLength <= prefixLengthMax) {
  2561. firstCode = firstCode + histogram[currentLength - 1] << 1;
  2562. currentCode = firstCode;
  2563. currentTemp = 0;
  2564. while (currentTemp < linesLength) {
  2565. line = lines[currentTemp];
  2566. if (line.prefixLength === currentLength) {
  2567. line.prefixCode = currentCode;
  2568. currentCode++;
  2569. }
  2570. currentTemp++;
  2571. }
  2572. currentLength++;
  2573. }
  2574. }
  2575. }]);
  2576. return HuffmanTable;
  2577. }();
  2578. function decodeTablesSegment(data, start, end) {
  2579. var flags = data[start];
  2580. var lowestValue = (0, _core_utils.readUint32)(data, start + 1) & 0xffffffff;
  2581. var highestValue = (0, _core_utils.readUint32)(data, start + 5) & 0xffffffff;
  2582. var reader = new Reader(data, start + 9, end);
  2583. var prefixSizeBits = (flags >> 1 & 7) + 1;
  2584. var rangeSizeBits = (flags >> 4 & 7) + 1;
  2585. var lines = [];
  2586. var prefixLength,
  2587. rangeLength,
  2588. currentRangeLow = lowestValue;
  2589. do {
  2590. prefixLength = reader.readBits(prefixSizeBits);
  2591. rangeLength = reader.readBits(rangeSizeBits);
  2592. lines.push(new HuffmanLine([currentRangeLow, prefixLength, rangeLength, 0]));
  2593. currentRangeLow += 1 << rangeLength;
  2594. } while (currentRangeLow < highestValue);
  2595. prefixLength = reader.readBits(prefixSizeBits);
  2596. lines.push(new HuffmanLine([lowestValue - 1, prefixLength, 32, 0, "lower"]));
  2597. prefixLength = reader.readBits(prefixSizeBits);
  2598. lines.push(new HuffmanLine([highestValue, prefixLength, 32, 0]));
  2599. if (flags & 1) {
  2600. prefixLength = reader.readBits(prefixSizeBits);
  2601. lines.push(new HuffmanLine([prefixLength, 0]));
  2602. }
  2603. return new HuffmanTable(lines, false);
  2604. }
  2605. var standardTablesCache = {};
  2606. function getStandardTable(number) {
  2607. var table = standardTablesCache[number];
  2608. if (table) {
  2609. return table;
  2610. }
  2611. var lines;
  2612. switch (number) {
  2613. case 1:
  2614. lines = [[0, 1, 4, 0x0], [16, 2, 8, 0x2], [272, 3, 16, 0x6], [65808, 3, 32, 0x7]];
  2615. break;
  2616. case 2:
  2617. lines = [[0, 1, 0, 0x0], [1, 2, 0, 0x2], [2, 3, 0, 0x6], [3, 4, 3, 0xe], [11, 5, 6, 0x1e], [75, 6, 32, 0x3e], [6, 0x3f]];
  2618. break;
  2619. case 3:
  2620. lines = [[-256, 8, 8, 0xfe], [0, 1, 0, 0x0], [1, 2, 0, 0x2], [2, 3, 0, 0x6], [3, 4, 3, 0xe], [11, 5, 6, 0x1e], [-257, 8, 32, 0xff, "lower"], [75, 7, 32, 0x7e], [6, 0x3e]];
  2621. break;
  2622. case 4:
  2623. lines = [[1, 1, 0, 0x0], [2, 2, 0, 0x2], [3, 3, 0, 0x6], [4, 4, 3, 0xe], [12, 5, 6, 0x1e], [76, 5, 32, 0x1f]];
  2624. break;
  2625. case 5:
  2626. lines = [[-255, 7, 8, 0x7e], [1, 1, 0, 0x0], [2, 2, 0, 0x2], [3, 3, 0, 0x6], [4, 4, 3, 0xe], [12, 5, 6, 0x1e], [-256, 7, 32, 0x7f, "lower"], [76, 6, 32, 0x3e]];
  2627. break;
  2628. case 6:
  2629. lines = [[-2048, 5, 10, 0x1c], [-1024, 4, 9, 0x8], [-512, 4, 8, 0x9], [-256, 4, 7, 0xa], [-128, 5, 6, 0x1d], [-64, 5, 5, 0x1e], [-32, 4, 5, 0xb], [0, 2, 7, 0x0], [128, 3, 7, 0x2], [256, 3, 8, 0x3], [512, 4, 9, 0xc], [1024, 4, 10, 0xd], [-2049, 6, 32, 0x3e, "lower"], [2048, 6, 32, 0x3f]];
  2630. break;
  2631. case 7:
  2632. lines = [[-1024, 4, 9, 0x8], [-512, 3, 8, 0x0], [-256, 4, 7, 0x9], [-128, 5, 6, 0x1a], [-64, 5, 5, 0x1b], [-32, 4, 5, 0xa], [0, 4, 5, 0xb], [32, 5, 5, 0x1c], [64, 5, 6, 0x1d], [128, 4, 7, 0xc], [256, 3, 8, 0x1], [512, 3, 9, 0x2], [1024, 3, 10, 0x3], [-1025, 5, 32, 0x1e, "lower"], [2048, 5, 32, 0x1f]];
  2633. break;
  2634. case 8:
  2635. lines = [[-15, 8, 3, 0xfc], [-7, 9, 1, 0x1fc], [-5, 8, 1, 0xfd], [-3, 9, 0, 0x1fd], [-2, 7, 0, 0x7c], [-1, 4, 0, 0xa], [0, 2, 1, 0x0], [2, 5, 0, 0x1a], [3, 6, 0, 0x3a], [4, 3, 4, 0x4], [20, 6, 1, 0x3b], [22, 4, 4, 0xb], [38, 4, 5, 0xc], [70, 5, 6, 0x1b], [134, 5, 7, 0x1c], [262, 6, 7, 0x3c], [390, 7, 8, 0x7d], [646, 6, 10, 0x3d], [-16, 9, 32, 0x1fe, "lower"], [1670, 9, 32, 0x1ff], [2, 0x1]];
  2636. break;
  2637. case 9:
  2638. lines = [[-31, 8, 4, 0xfc], [-15, 9, 2, 0x1fc], [-11, 8, 2, 0xfd], [-7, 9, 1, 0x1fd], [-5, 7, 1, 0x7c], [-3, 4, 1, 0xa], [-1, 3, 1, 0x2], [1, 3, 1, 0x3], [3, 5, 1, 0x1a], [5, 6, 1, 0x3a], [7, 3, 5, 0x4], [39, 6, 2, 0x3b], [43, 4, 5, 0xb], [75, 4, 6, 0xc], [139, 5, 7, 0x1b], [267, 5, 8, 0x1c], [523, 6, 8, 0x3c], [779, 7, 9, 0x7d], [1291, 6, 11, 0x3d], [-32, 9, 32, 0x1fe, "lower"], [3339, 9, 32, 0x1ff], [2, 0x0]];
  2639. break;
  2640. case 10:
  2641. lines = [[-21, 7, 4, 0x7a], [-5, 8, 0, 0xfc], [-4, 7, 0, 0x7b], [-3, 5, 0, 0x18], [-2, 2, 2, 0x0], [2, 5, 0, 0x19], [3, 6, 0, 0x36], [4, 7, 0, 0x7c], [5, 8, 0, 0xfd], [6, 2, 6, 0x1], [70, 5, 5, 0x1a], [102, 6, 5, 0x37], [134, 6, 6, 0x38], [198, 6, 7, 0x39], [326, 6, 8, 0x3a], [582, 6, 9, 0x3b], [1094, 6, 10, 0x3c], [2118, 7, 11, 0x7d], [-22, 8, 32, 0xfe, "lower"], [4166, 8, 32, 0xff], [2, 0x2]];
  2642. break;
  2643. case 11:
  2644. lines = [[1, 1, 0, 0x0], [2, 2, 1, 0x2], [4, 4, 0, 0xc], [5, 4, 1, 0xd], [7, 5, 1, 0x1c], [9, 5, 2, 0x1d], [13, 6, 2, 0x3c], [17, 7, 2, 0x7a], [21, 7, 3, 0x7b], [29, 7, 4, 0x7c], [45, 7, 5, 0x7d], [77, 7, 6, 0x7e], [141, 7, 32, 0x7f]];
  2645. break;
  2646. case 12:
  2647. lines = [[1, 1, 0, 0x0], [2, 2, 0, 0x2], [3, 3, 1, 0x6], [5, 5, 0, 0x1c], [6, 5, 1, 0x1d], [8, 6, 1, 0x3c], [10, 7, 0, 0x7a], [11, 7, 1, 0x7b], [13, 7, 2, 0x7c], [17, 7, 3, 0x7d], [25, 7, 4, 0x7e], [41, 8, 5, 0xfe], [73, 8, 32, 0xff]];
  2648. break;
  2649. case 13:
  2650. lines = [[1, 1, 0, 0x0], [2, 3, 0, 0x4], [3, 4, 0, 0xc], [4, 5, 0, 0x1c], [5, 4, 1, 0xd], [7, 3, 3, 0x5], [15, 6, 1, 0x3a], [17, 6, 2, 0x3b], [21, 6, 3, 0x3c], [29, 6, 4, 0x3d], [45, 6, 5, 0x3e], [77, 7, 6, 0x7e], [141, 7, 32, 0x7f]];
  2651. break;
  2652. case 14:
  2653. lines = [[-2, 3, 0, 0x4], [-1, 3, 0, 0x5], [0, 1, 0, 0x0], [1, 3, 0, 0x6], [2, 3, 0, 0x7]];
  2654. break;
  2655. case 15:
  2656. lines = [[-24, 7, 4, 0x7c], [-8, 6, 2, 0x3c], [-4, 5, 1, 0x1c], [-2, 4, 0, 0xc], [-1, 3, 0, 0x4], [0, 1, 0, 0x0], [1, 3, 0, 0x5], [2, 4, 0, 0xd], [3, 5, 1, 0x1d], [5, 6, 2, 0x3d], [9, 7, 4, 0x7d], [-25, 7, 32, 0x7e, "lower"], [25, 7, 32, 0x7f]];
  2657. break;
  2658. default:
  2659. throw new Jbig2Error("standard table B.".concat(number, " does not exist"));
  2660. }
  2661. for (var i = 0, ii = lines.length; i < ii; i++) {
  2662. lines[i] = new HuffmanLine(lines[i]);
  2663. }
  2664. table = new HuffmanTable(lines, true);
  2665. standardTablesCache[number] = table;
  2666. return table;
  2667. }
  2668. var Reader = /*#__PURE__*/function () {
  2669. function Reader(data, start, end) {
  2670. _classCallCheck(this, Reader);
  2671. this.data = data;
  2672. this.start = start;
  2673. this.end = end;
  2674. this.position = start;
  2675. this.shift = -1;
  2676. this.currentByte = 0;
  2677. }
  2678. _createClass(Reader, [{
  2679. key: "readBit",
  2680. value: function readBit() {
  2681. if (this.shift < 0) {
  2682. if (this.position >= this.end) {
  2683. throw new Jbig2Error("end of data while reading bit");
  2684. }
  2685. this.currentByte = this.data[this.position++];
  2686. this.shift = 7;
  2687. }
  2688. var bit = this.currentByte >> this.shift & 1;
  2689. this.shift--;
  2690. return bit;
  2691. }
  2692. }, {
  2693. key: "readBits",
  2694. value: function readBits(numBits) {
  2695. var result = 0,
  2696. i;
  2697. for (i = numBits - 1; i >= 0; i--) {
  2698. result |= this.readBit() << i;
  2699. }
  2700. return result;
  2701. }
  2702. }, {
  2703. key: "byteAlign",
  2704. value: function byteAlign() {
  2705. this.shift = -1;
  2706. }
  2707. }, {
  2708. key: "next",
  2709. value: function next() {
  2710. if (this.position >= this.end) {
  2711. return -1;
  2712. }
  2713. return this.data[this.position++];
  2714. }
  2715. }]);
  2716. return Reader;
  2717. }();
  2718. function getCustomHuffmanTable(index, referredTo, customTables) {
  2719. var currentIndex = 0;
  2720. for (var i = 0, ii = referredTo.length; i < ii; i++) {
  2721. var table = customTables[referredTo[i]];
  2722. if (table) {
  2723. if (index === currentIndex) {
  2724. return table;
  2725. }
  2726. currentIndex++;
  2727. }
  2728. }
  2729. throw new Jbig2Error("can't find custom Huffman table");
  2730. }
  2731. function getTextRegionHuffmanTables(textRegion, referredTo, customTables, numberOfSymbols, reader) {
  2732. var codes = [];
  2733. for (var i = 0; i <= 34; i++) {
  2734. var codeLength = reader.readBits(4);
  2735. codes.push(new HuffmanLine([i, codeLength, 0, 0]));
  2736. }
  2737. var runCodesTable = new HuffmanTable(codes, false);
  2738. codes.length = 0;
  2739. for (var _i3 = 0; _i3 < numberOfSymbols;) {
  2740. var _codeLength = runCodesTable.decode(reader);
  2741. if (_codeLength >= 32) {
  2742. var repeatedLength = void 0,
  2743. numberOfRepeats = void 0,
  2744. j = void 0;
  2745. switch (_codeLength) {
  2746. case 32:
  2747. if (_i3 === 0) {
  2748. throw new Jbig2Error("no previous value in symbol ID table");
  2749. }
  2750. numberOfRepeats = reader.readBits(2) + 3;
  2751. repeatedLength = codes[_i3 - 1].prefixLength;
  2752. break;
  2753. case 33:
  2754. numberOfRepeats = reader.readBits(3) + 3;
  2755. repeatedLength = 0;
  2756. break;
  2757. case 34:
  2758. numberOfRepeats = reader.readBits(7) + 11;
  2759. repeatedLength = 0;
  2760. break;
  2761. default:
  2762. throw new Jbig2Error("invalid code length in symbol ID table");
  2763. }
  2764. for (j = 0; j < numberOfRepeats; j++) {
  2765. codes.push(new HuffmanLine([_i3, repeatedLength, 0, 0]));
  2766. _i3++;
  2767. }
  2768. } else {
  2769. codes.push(new HuffmanLine([_i3, _codeLength, 0, 0]));
  2770. _i3++;
  2771. }
  2772. }
  2773. reader.byteAlign();
  2774. var symbolIDTable = new HuffmanTable(codes, false);
  2775. var customIndex = 0,
  2776. tableFirstS,
  2777. tableDeltaS,
  2778. tableDeltaT;
  2779. switch (textRegion.huffmanFS) {
  2780. case 0:
  2781. case 1:
  2782. tableFirstS = getStandardTable(textRegion.huffmanFS + 6);
  2783. break;
  2784. case 3:
  2785. tableFirstS = getCustomHuffmanTable(customIndex, referredTo, customTables);
  2786. customIndex++;
  2787. break;
  2788. default:
  2789. throw new Jbig2Error("invalid Huffman FS selector");
  2790. }
  2791. switch (textRegion.huffmanDS) {
  2792. case 0:
  2793. case 1:
  2794. case 2:
  2795. tableDeltaS = getStandardTable(textRegion.huffmanDS + 8);
  2796. break;
  2797. case 3:
  2798. tableDeltaS = getCustomHuffmanTable(customIndex, referredTo, customTables);
  2799. customIndex++;
  2800. break;
  2801. default:
  2802. throw new Jbig2Error("invalid Huffman DS selector");
  2803. }
  2804. switch (textRegion.huffmanDT) {
  2805. case 0:
  2806. case 1:
  2807. case 2:
  2808. tableDeltaT = getStandardTable(textRegion.huffmanDT + 11);
  2809. break;
  2810. case 3:
  2811. tableDeltaT = getCustomHuffmanTable(customIndex, referredTo, customTables);
  2812. customIndex++;
  2813. break;
  2814. default:
  2815. throw new Jbig2Error("invalid Huffman DT selector");
  2816. }
  2817. if (textRegion.refinement) {
  2818. throw new Jbig2Error("refinement with Huffman is not supported");
  2819. }
  2820. return {
  2821. symbolIDTable: symbolIDTable,
  2822. tableFirstS: tableFirstS,
  2823. tableDeltaS: tableDeltaS,
  2824. tableDeltaT: tableDeltaT
  2825. };
  2826. }
  2827. function getSymbolDictionaryHuffmanTables(dictionary, referredTo, customTables) {
  2828. var customIndex = 0,
  2829. tableDeltaHeight,
  2830. tableDeltaWidth;
  2831. switch (dictionary.huffmanDHSelector) {
  2832. case 0:
  2833. case 1:
  2834. tableDeltaHeight = getStandardTable(dictionary.huffmanDHSelector + 4);
  2835. break;
  2836. case 3:
  2837. tableDeltaHeight = getCustomHuffmanTable(customIndex, referredTo, customTables);
  2838. customIndex++;
  2839. break;
  2840. default:
  2841. throw new Jbig2Error("invalid Huffman DH selector");
  2842. }
  2843. switch (dictionary.huffmanDWSelector) {
  2844. case 0:
  2845. case 1:
  2846. tableDeltaWidth = getStandardTable(dictionary.huffmanDWSelector + 2);
  2847. break;
  2848. case 3:
  2849. tableDeltaWidth = getCustomHuffmanTable(customIndex, referredTo, customTables);
  2850. customIndex++;
  2851. break;
  2852. default:
  2853. throw new Jbig2Error("invalid Huffman DW selector");
  2854. }
  2855. var tableBitmapSize, tableAggregateInstances;
  2856. if (dictionary.bitmapSizeSelector) {
  2857. tableBitmapSize = getCustomHuffmanTable(customIndex, referredTo, customTables);
  2858. customIndex++;
  2859. } else {
  2860. tableBitmapSize = getStandardTable(1);
  2861. }
  2862. if (dictionary.aggregationInstancesSelector) {
  2863. tableAggregateInstances = getCustomHuffmanTable(customIndex, referredTo, customTables);
  2864. } else {
  2865. tableAggregateInstances = getStandardTable(1);
  2866. }
  2867. return {
  2868. tableDeltaHeight: tableDeltaHeight,
  2869. tableDeltaWidth: tableDeltaWidth,
  2870. tableBitmapSize: tableBitmapSize,
  2871. tableAggregateInstances: tableAggregateInstances
  2872. };
  2873. }
  2874. function readUncompressedBitmap(reader, width, height) {
  2875. var bitmap = [];
  2876. for (var y = 0; y < height; y++) {
  2877. var row = new Uint8Array(width);
  2878. bitmap.push(row);
  2879. for (var x = 0; x < width; x++) {
  2880. row[x] = reader.readBit();
  2881. }
  2882. reader.byteAlign();
  2883. }
  2884. return bitmap;
  2885. }
  2886. function decodeMMRBitmap(input, width, height, endOfBlock) {
  2887. var params = {
  2888. K: -1,
  2889. Columns: width,
  2890. Rows: height,
  2891. BlackIs1: true,
  2892. EndOfBlock: endOfBlock
  2893. };
  2894. var decoder = new _ccitt.CCITTFaxDecoder(input, params);
  2895. var bitmap = [];
  2896. var currentByte,
  2897. eof = false;
  2898. for (var y = 0; y < height; y++) {
  2899. var row = new Uint8Array(width);
  2900. bitmap.push(row);
  2901. var shift = -1;
  2902. for (var x = 0; x < width; x++) {
  2903. if (shift < 0) {
  2904. currentByte = decoder.readNextChar();
  2905. if (currentByte === -1) {
  2906. currentByte = 0;
  2907. eof = true;
  2908. }
  2909. shift = 7;
  2910. }
  2911. row[x] = currentByte >> shift & 1;
  2912. shift--;
  2913. }
  2914. }
  2915. if (endOfBlock && !eof) {
  2916. var lookForEOFLimit = 5;
  2917. for (var i = 0; i < lookForEOFLimit; i++) {
  2918. if (decoder.readNextChar() === -1) {
  2919. break;
  2920. }
  2921. }
  2922. }
  2923. return bitmap;
  2924. }
  2925. var Jbig2Image = /*#__PURE__*/function () {
  2926. function Jbig2Image() {
  2927. _classCallCheck(this, Jbig2Image);
  2928. }
  2929. _createClass(Jbig2Image, [{
  2930. key: "parseChunks",
  2931. value: function parseChunks(chunks) {
  2932. return parseJbig2Chunks(chunks);
  2933. }
  2934. }, {
  2935. key: "parse",
  2936. value: function parse(data) {
  2937. var _parseJbig = parseJbig2(data),
  2938. imgData = _parseJbig.imgData,
  2939. width = _parseJbig.width,
  2940. height = _parseJbig.height;
  2941. this.width = width;
  2942. this.height = height;
  2943. return imgData;
  2944. }
  2945. }]);
  2946. return Jbig2Image;
  2947. }();
  2948. exports.Jbig2Image = Jbig2Image;
  2949. /***/ }),
  2950. /* 5 */
  2951. /***/ ((__unused_webpack_module, exports, __w_pdfjs_require__) => {
  2952. function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
  2953. Object.defineProperty(exports, "__esModule", ({
  2954. value: true
  2955. }));
  2956. exports.XRefParseException = exports.XRefEntryException = exports.ParserEOFException = exports.MissingDataException = exports.DocStats = void 0;
  2957. exports.collectActions = collectActions;
  2958. exports.encodeToXmlString = encodeToXmlString;
  2959. exports.escapePDFName = escapePDFName;
  2960. exports.getArrayLookupTableFactory = getArrayLookupTableFactory;
  2961. exports.getInheritableProperty = getInheritableProperty;
  2962. exports.getLookupTableFactory = getLookupTableFactory;
  2963. exports.isWhiteSpace = isWhiteSpace;
  2964. exports.log2 = log2;
  2965. exports.parseXFAPath = parseXFAPath;
  2966. exports.readInt8 = readInt8;
  2967. exports.readUint16 = readUint16;
  2968. exports.readUint32 = readUint32;
  2969. exports.recoverJsURL = recoverJsURL;
  2970. exports.toRomanNumerals = toRomanNumerals;
  2971. exports.validateCSSFont = validateCSSFont;
  2972. var _util = __w_pdfjs_require__(1);
  2973. var _primitives = __w_pdfjs_require__(6);
  2974. var _base_stream = __w_pdfjs_require__(9);
  2975. function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; }
  2976. function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
  2977. function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
  2978. function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
  2979. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
  2980. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  2981. function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); }
  2982. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  2983. function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
  2984. function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); }
  2985. function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
  2986. function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
  2987. function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
  2988. function getLookupTableFactory(initializer) {
  2989. var lookup;
  2990. return function () {
  2991. if (initializer) {
  2992. lookup = Object.create(null);
  2993. initializer(lookup);
  2994. initializer = null;
  2995. }
  2996. return lookup;
  2997. };
  2998. }
  2999. function getArrayLookupTableFactory(initializer) {
  3000. var lookup;
  3001. return function () {
  3002. if (initializer) {
  3003. var arr = initializer();
  3004. initializer = null;
  3005. lookup = Object.create(null);
  3006. for (var i = 0, ii = arr.length; i < ii; i += 2) {
  3007. lookup[arr[i]] = arr[i + 1];
  3008. }
  3009. arr = null;
  3010. }
  3011. return lookup;
  3012. };
  3013. }
  3014. var MissingDataException = /*#__PURE__*/function (_BaseException) {
  3015. _inherits(MissingDataException, _BaseException);
  3016. var _super = _createSuper(MissingDataException);
  3017. function MissingDataException(begin, end) {
  3018. var _this;
  3019. _classCallCheck(this, MissingDataException);
  3020. _this = _super.call(this, "Missing data [".concat(begin, ", ").concat(end, ")"), "MissingDataException");
  3021. _this.begin = begin;
  3022. _this.end = end;
  3023. return _this;
  3024. }
  3025. return _createClass(MissingDataException);
  3026. }(_util.BaseException);
  3027. exports.MissingDataException = MissingDataException;
  3028. var ParserEOFException = /*#__PURE__*/function (_BaseException2) {
  3029. _inherits(ParserEOFException, _BaseException2);
  3030. var _super2 = _createSuper(ParserEOFException);
  3031. function ParserEOFException(msg) {
  3032. _classCallCheck(this, ParserEOFException);
  3033. return _super2.call(this, msg, "ParserEOFException");
  3034. }
  3035. return _createClass(ParserEOFException);
  3036. }(_util.BaseException);
  3037. exports.ParserEOFException = ParserEOFException;
  3038. var XRefEntryException = /*#__PURE__*/function (_BaseException3) {
  3039. _inherits(XRefEntryException, _BaseException3);
  3040. var _super3 = _createSuper(XRefEntryException);
  3041. function XRefEntryException(msg) {
  3042. _classCallCheck(this, XRefEntryException);
  3043. return _super3.call(this, msg, "XRefEntryException");
  3044. }
  3045. return _createClass(XRefEntryException);
  3046. }(_util.BaseException);
  3047. exports.XRefEntryException = XRefEntryException;
  3048. var XRefParseException = /*#__PURE__*/function (_BaseException4) {
  3049. _inherits(XRefParseException, _BaseException4);
  3050. var _super4 = _createSuper(XRefParseException);
  3051. function XRefParseException(msg) {
  3052. _classCallCheck(this, XRefParseException);
  3053. return _super4.call(this, msg, "XRefParseException");
  3054. }
  3055. return _createClass(XRefParseException);
  3056. }(_util.BaseException);
  3057. exports.XRefParseException = XRefParseException;
  3058. var DocStats = /*#__PURE__*/function () {
  3059. function DocStats(handler) {
  3060. _classCallCheck(this, DocStats);
  3061. this._handler = handler;
  3062. this._streamTypes = new Set();
  3063. this._fontTypes = new Set();
  3064. }
  3065. _createClass(DocStats, [{
  3066. key: "_send",
  3067. value: function _send() {
  3068. var streamTypes = Object.create(null),
  3069. fontTypes = Object.create(null);
  3070. var _iterator = _createForOfIteratorHelper(this._streamTypes),
  3071. _step;
  3072. try {
  3073. for (_iterator.s(); !(_step = _iterator.n()).done;) {
  3074. var type = _step.value;
  3075. streamTypes[type] = true;
  3076. }
  3077. } catch (err) {
  3078. _iterator.e(err);
  3079. } finally {
  3080. _iterator.f();
  3081. }
  3082. var _iterator2 = _createForOfIteratorHelper(this._fontTypes),
  3083. _step2;
  3084. try {
  3085. for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
  3086. var _type = _step2.value;
  3087. fontTypes[_type] = true;
  3088. }
  3089. } catch (err) {
  3090. _iterator2.e(err);
  3091. } finally {
  3092. _iterator2.f();
  3093. }
  3094. this._handler.send("DocStats", {
  3095. streamTypes: streamTypes,
  3096. fontTypes: fontTypes
  3097. });
  3098. }
  3099. }, {
  3100. key: "addStreamType",
  3101. value: function addStreamType(type) {
  3102. if (this._streamTypes.has(type)) {
  3103. return;
  3104. }
  3105. this._streamTypes.add(type);
  3106. this._send();
  3107. }
  3108. }, {
  3109. key: "addFontType",
  3110. value: function addFontType(type) {
  3111. if (this._fontTypes.has(type)) {
  3112. return;
  3113. }
  3114. this._fontTypes.add(type);
  3115. this._send();
  3116. }
  3117. }]);
  3118. return DocStats;
  3119. }();
  3120. exports.DocStats = DocStats;
  3121. function getInheritableProperty(_ref) {
  3122. var dict = _ref.dict,
  3123. key = _ref.key,
  3124. _ref$getArray = _ref.getArray,
  3125. getArray = _ref$getArray === void 0 ? false : _ref$getArray,
  3126. _ref$stopWhenFound = _ref.stopWhenFound,
  3127. stopWhenFound = _ref$stopWhenFound === void 0 ? true : _ref$stopWhenFound;
  3128. var values;
  3129. var visited = new _primitives.RefSet();
  3130. while (dict instanceof _primitives.Dict && !(dict.objId && visited.has(dict.objId))) {
  3131. if (dict.objId) {
  3132. visited.put(dict.objId);
  3133. }
  3134. var value = getArray ? dict.getArray(key) : dict.get(key);
  3135. if (value !== undefined) {
  3136. if (stopWhenFound) {
  3137. return value;
  3138. }
  3139. if (!values) {
  3140. values = [];
  3141. }
  3142. values.push(value);
  3143. }
  3144. dict = dict.get("Parent");
  3145. }
  3146. return values;
  3147. }
  3148. var ROMAN_NUMBER_MAP = ["", "C", "CC", "CCC", "CD", "D", "DC", "DCC", "DCCC", "CM", "", "X", "XX", "XXX", "XL", "L", "LX", "LXX", "LXXX", "XC", "", "I", "II", "III", "IV", "V", "VI", "VII", "VIII", "IX"];
  3149. function toRomanNumerals(number) {
  3150. var lowerCase = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
  3151. (0, _util.assert)(Number.isInteger(number) && number > 0, "The number should be a positive integer.");
  3152. var romanBuf = [];
  3153. var pos;
  3154. while (number >= 1000) {
  3155. number -= 1000;
  3156. romanBuf.push("M");
  3157. }
  3158. pos = number / 100 | 0;
  3159. number %= 100;
  3160. romanBuf.push(ROMAN_NUMBER_MAP[pos]);
  3161. pos = number / 10 | 0;
  3162. number %= 10;
  3163. romanBuf.push(ROMAN_NUMBER_MAP[10 + pos]);
  3164. romanBuf.push(ROMAN_NUMBER_MAP[20 + number]);
  3165. var romanStr = romanBuf.join("");
  3166. return lowerCase ? romanStr.toLowerCase() : romanStr;
  3167. }
  3168. function log2(x) {
  3169. if (x <= 0) {
  3170. return 0;
  3171. }
  3172. return Math.ceil(Math.log2(x));
  3173. }
  3174. function readInt8(data, offset) {
  3175. return data[offset] << 24 >> 24;
  3176. }
  3177. function readUint16(data, offset) {
  3178. return data[offset] << 8 | data[offset + 1];
  3179. }
  3180. function readUint32(data, offset) {
  3181. return (data[offset] << 24 | data[offset + 1] << 16 | data[offset + 2] << 8 | data[offset + 3]) >>> 0;
  3182. }
  3183. function isWhiteSpace(ch) {
  3184. return ch === 0x20 || ch === 0x09 || ch === 0x0d || ch === 0x0a;
  3185. }
  3186. function parseXFAPath(path) {
  3187. var positionPattern = /(.+)\[(\d+)\]$/;
  3188. return path.split(".").map(function (component) {
  3189. var m = component.match(positionPattern);
  3190. if (m) {
  3191. return {
  3192. name: m[1],
  3193. pos: parseInt(m[2], 10)
  3194. };
  3195. }
  3196. return {
  3197. name: component,
  3198. pos: 0
  3199. };
  3200. });
  3201. }
  3202. function escapePDFName(str) {
  3203. var buffer = [];
  3204. var start = 0;
  3205. for (var i = 0, ii = str.length; i < ii; i++) {
  3206. var _char = str.charCodeAt(i);
  3207. if (_char < 0x21 || _char > 0x7e || _char === 0x23 || _char === 0x28 || _char === 0x29 || _char === 0x3c || _char === 0x3e || _char === 0x5b || _char === 0x5d || _char === 0x7b || _char === 0x7d || _char === 0x2f || _char === 0x25) {
  3208. if (start < i) {
  3209. buffer.push(str.substring(start, i));
  3210. }
  3211. buffer.push("#".concat(_char.toString(16)));
  3212. start = i + 1;
  3213. }
  3214. }
  3215. if (buffer.length === 0) {
  3216. return str;
  3217. }
  3218. if (start < str.length) {
  3219. buffer.push(str.substring(start, str.length));
  3220. }
  3221. return buffer.join("");
  3222. }
  3223. function _collectJS(entry, xref, list, parents) {
  3224. if (!entry) {
  3225. return;
  3226. }
  3227. var parent = null;
  3228. if (entry instanceof _primitives.Ref) {
  3229. if (parents.has(entry)) {
  3230. return;
  3231. }
  3232. parent = entry;
  3233. parents.put(parent);
  3234. entry = xref.fetch(entry);
  3235. }
  3236. if (Array.isArray(entry)) {
  3237. var _iterator3 = _createForOfIteratorHelper(entry),
  3238. _step3;
  3239. try {
  3240. for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
  3241. var element = _step3.value;
  3242. _collectJS(element, xref, list, parents);
  3243. }
  3244. } catch (err) {
  3245. _iterator3.e(err);
  3246. } finally {
  3247. _iterator3.f();
  3248. }
  3249. } else if (entry instanceof _primitives.Dict) {
  3250. if ((0, _primitives.isName)(entry.get("S"), "JavaScript")) {
  3251. var js = entry.get("JS");
  3252. var code;
  3253. if (js instanceof _base_stream.BaseStream) {
  3254. code = js.getString();
  3255. } else if (typeof js === "string") {
  3256. code = js;
  3257. }
  3258. code = code && (0, _util.stringToPDFString)(code);
  3259. if (code) {
  3260. list.push(code);
  3261. }
  3262. }
  3263. _collectJS(entry.getRaw("Next"), xref, list, parents);
  3264. }
  3265. if (parent) {
  3266. parents.remove(parent);
  3267. }
  3268. }
  3269. function collectActions(xref, dict, eventType) {
  3270. var actions = Object.create(null);
  3271. var additionalActionsDicts = getInheritableProperty({
  3272. dict: dict,
  3273. key: "AA",
  3274. stopWhenFound: false
  3275. });
  3276. if (additionalActionsDicts) {
  3277. for (var i = additionalActionsDicts.length - 1; i >= 0; i--) {
  3278. var additionalActions = additionalActionsDicts[i];
  3279. if (!(additionalActions instanceof _primitives.Dict)) {
  3280. continue;
  3281. }
  3282. var _iterator4 = _createForOfIteratorHelper(additionalActions.getKeys()),
  3283. _step4;
  3284. try {
  3285. for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) {
  3286. var key = _step4.value;
  3287. var action = eventType[key];
  3288. if (!action) {
  3289. continue;
  3290. }
  3291. var actionDict = additionalActions.getRaw(key);
  3292. var parents = new _primitives.RefSet();
  3293. var list = [];
  3294. _collectJS(actionDict, xref, list, parents);
  3295. if (list.length > 0) {
  3296. actions[action] = list;
  3297. }
  3298. }
  3299. } catch (err) {
  3300. _iterator4.e(err);
  3301. } finally {
  3302. _iterator4.f();
  3303. }
  3304. }
  3305. }
  3306. if (dict.has("A")) {
  3307. var _actionDict = dict.get("A");
  3308. var _parents = new _primitives.RefSet();
  3309. var _list = [];
  3310. _collectJS(_actionDict, xref, _list, _parents);
  3311. if (_list.length > 0) {
  3312. actions.Action = _list;
  3313. }
  3314. }
  3315. return (0, _util.objectSize)(actions) > 0 ? actions : null;
  3316. }
  3317. var XMLEntities = {
  3318. 0x3c: "&lt;",
  3319. 0x3e: "&gt;",
  3320. 0x26: "&amp;",
  3321. 0x22: "&quot;",
  3322. 0x27: "&apos;"
  3323. };
  3324. function encodeToXmlString(str) {
  3325. var buffer = [];
  3326. var start = 0;
  3327. for (var i = 0, ii = str.length; i < ii; i++) {
  3328. var _char2 = str.codePointAt(i);
  3329. if (0x20 <= _char2 && _char2 <= 0x7e) {
  3330. var entity = XMLEntities[_char2];
  3331. if (entity) {
  3332. if (start < i) {
  3333. buffer.push(str.substring(start, i));
  3334. }
  3335. buffer.push(entity);
  3336. start = i + 1;
  3337. }
  3338. } else {
  3339. if (start < i) {
  3340. buffer.push(str.substring(start, i));
  3341. }
  3342. buffer.push("&#x".concat(_char2.toString(16).toUpperCase(), ";"));
  3343. if (_char2 > 0xd7ff && (_char2 < 0xe000 || _char2 > 0xfffd)) {
  3344. i++;
  3345. }
  3346. start = i + 1;
  3347. }
  3348. }
  3349. if (buffer.length === 0) {
  3350. return str;
  3351. }
  3352. if (start < str.length) {
  3353. buffer.push(str.substring(start, str.length));
  3354. }
  3355. return buffer.join("");
  3356. }
  3357. function validateCSSFont(cssFontInfo) {
  3358. var DEFAULT_CSS_FONT_OBLIQUE = "14";
  3359. var DEFAULT_CSS_FONT_WEIGHT = "400";
  3360. var CSS_FONT_WEIGHT_VALUES = new Set(["100", "200", "300", "400", "500", "600", "700", "800", "900", "1000", "normal", "bold", "bolder", "lighter"]);
  3361. var fontFamily = cssFontInfo.fontFamily,
  3362. fontWeight = cssFontInfo.fontWeight,
  3363. italicAngle = cssFontInfo.italicAngle;
  3364. if (/^".*"$/.test(fontFamily)) {
  3365. if (/[^\\]"/.test(fontFamily.slice(1, fontFamily.length - 1))) {
  3366. (0, _util.warn)("XFA - FontFamily contains some unescaped \": ".concat(fontFamily, "."));
  3367. return false;
  3368. }
  3369. } else if (/^'.*'$/.test(fontFamily)) {
  3370. if (/[^\\]'/.test(fontFamily.slice(1, fontFamily.length - 1))) {
  3371. (0, _util.warn)("XFA - FontFamily contains some unescaped ': ".concat(fontFamily, "."));
  3372. return false;
  3373. }
  3374. } else {
  3375. var _iterator5 = _createForOfIteratorHelper(fontFamily.split(/[ \t]+/)),
  3376. _step5;
  3377. try {
  3378. for (_iterator5.s(); !(_step5 = _iterator5.n()).done;) {
  3379. var ident = _step5.value;
  3380. if (/^(\d|(-(\d|-)))/.test(ident) || !/^[\w-\\]+$/.test(ident)) {
  3381. (0, _util.warn)("XFA - FontFamily contains some invalid <custom-ident>: ".concat(fontFamily, "."));
  3382. return false;
  3383. }
  3384. }
  3385. } catch (err) {
  3386. _iterator5.e(err);
  3387. } finally {
  3388. _iterator5.f();
  3389. }
  3390. }
  3391. var weight = fontWeight ? fontWeight.toString() : "";
  3392. cssFontInfo.fontWeight = CSS_FONT_WEIGHT_VALUES.has(weight) ? weight : DEFAULT_CSS_FONT_WEIGHT;
  3393. var angle = parseFloat(italicAngle);
  3394. cssFontInfo.italicAngle = isNaN(angle) || angle < -90 || angle > 90 ? DEFAULT_CSS_FONT_OBLIQUE : italicAngle.toString();
  3395. return true;
  3396. }
  3397. function recoverJsURL(str) {
  3398. var URL_OPEN_METHODS = ["app.launchURL", "window.open", "xfa.host.gotoURL"];
  3399. var regex = new RegExp("^\\s*(" + URL_OPEN_METHODS.join("|").split(".").join("\\.") + ")\\((?:'|\")([^'\"]*)(?:'|\")(?:,\\s*(\\w+)\\)|\\))", "i");
  3400. var jsUrl = regex.exec(str);
  3401. if (jsUrl && jsUrl[2]) {
  3402. var url = jsUrl[2];
  3403. var newWindow = false;
  3404. if (jsUrl[3] === "true" && jsUrl[1] === "app.launchURL") {
  3405. newWindow = true;
  3406. }
  3407. return {
  3408. url: url,
  3409. newWindow: newWindow
  3410. };
  3411. }
  3412. return null;
  3413. }
  3414. /***/ }),
  3415. /* 6 */
  3416. /***/ ((__unused_webpack_module, exports, __w_pdfjs_require__) => {
  3417. Object.defineProperty(exports, "__esModule", ({
  3418. value: true
  3419. }));
  3420. exports.RefSetCache = exports.RefSet = exports.Ref = exports.Name = exports.EOF = exports.Dict = exports.Cmd = exports.CIRCULAR_REF = void 0;
  3421. exports.clearPrimitiveCaches = clearPrimitiveCaches;
  3422. exports.isCmd = isCmd;
  3423. exports.isDict = isDict;
  3424. exports.isName = isName;
  3425. exports.isRefsEqual = isRefsEqual;
  3426. var _regenerator = _interopRequireDefault(__w_pdfjs_require__(7));
  3427. var _util = __w_pdfjs_require__(1);
  3428. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
  3429. function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
  3430. function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
  3431. function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"]; if (_i == null) return; var _arr = []; var _n = true; var _d = false; var _s, _e; try { for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
  3432. function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
  3433. function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e2) { throw _e2; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e3) { didErr = true; err = _e3; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; }
  3434. function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
  3435. function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
  3436. function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
  3437. function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
  3438. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  3439. function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
  3440. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
  3441. var CIRCULAR_REF = Symbol("CIRCULAR_REF");
  3442. exports.CIRCULAR_REF = CIRCULAR_REF;
  3443. var EOF = Symbol("EOF");
  3444. exports.EOF = EOF;
  3445. var Name = function NameClosure() {
  3446. var nameCache = Object.create(null);
  3447. var Name = /*#__PURE__*/function () {
  3448. function Name(name) {
  3449. _classCallCheck(this, Name);
  3450. this.name = name;
  3451. }
  3452. _createClass(Name, null, [{
  3453. key: "get",
  3454. value: function get(name) {
  3455. var nameValue = nameCache[name];
  3456. return nameValue ? nameValue : nameCache[name] = new Name(name);
  3457. }
  3458. }, {
  3459. key: "_clearCache",
  3460. value: function _clearCache() {
  3461. nameCache = Object.create(null);
  3462. }
  3463. }]);
  3464. return Name;
  3465. }();
  3466. return Name;
  3467. }();
  3468. exports.Name = Name;
  3469. var Cmd = function CmdClosure() {
  3470. var cmdCache = Object.create(null);
  3471. var Cmd = /*#__PURE__*/function () {
  3472. function Cmd(cmd) {
  3473. _classCallCheck(this, Cmd);
  3474. this.cmd = cmd;
  3475. }
  3476. _createClass(Cmd, null, [{
  3477. key: "get",
  3478. value: function get(cmd) {
  3479. var cmdValue = cmdCache[cmd];
  3480. return cmdValue ? cmdValue : cmdCache[cmd] = new Cmd(cmd);
  3481. }
  3482. }, {
  3483. key: "_clearCache",
  3484. value: function _clearCache() {
  3485. cmdCache = Object.create(null);
  3486. }
  3487. }]);
  3488. return Cmd;
  3489. }();
  3490. return Cmd;
  3491. }();
  3492. exports.Cmd = Cmd;
  3493. var nonSerializable = function nonSerializableClosure() {
  3494. return nonSerializable;
  3495. };
  3496. var Dict = /*#__PURE__*/function () {
  3497. function Dict() {
  3498. var xref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null;
  3499. _classCallCheck(this, Dict);
  3500. this._map = Object.create(null);
  3501. this.xref = xref;
  3502. this.objId = null;
  3503. this.suppressEncryption = false;
  3504. this.__nonSerializable__ = nonSerializable;
  3505. }
  3506. _createClass(Dict, [{
  3507. key: "assignXref",
  3508. value: function assignXref(newXref) {
  3509. this.xref = newXref;
  3510. }
  3511. }, {
  3512. key: "size",
  3513. get: function get() {
  3514. return Object.keys(this._map).length;
  3515. }
  3516. }, {
  3517. key: "get",
  3518. value: function get(key1, key2, key3) {
  3519. var value = this._map[key1];
  3520. if (value === undefined && key2 !== undefined) {
  3521. value = this._map[key2];
  3522. if (value === undefined && key3 !== undefined) {
  3523. value = this._map[key3];
  3524. }
  3525. }
  3526. if (value instanceof Ref && this.xref) {
  3527. return this.xref.fetch(value, this.suppressEncryption);
  3528. }
  3529. return value;
  3530. }
  3531. }, {
  3532. key: "getAsync",
  3533. value: function () {
  3534. var _getAsync = _asyncToGenerator( /*#__PURE__*/_regenerator["default"].mark(function _callee(key1, key2, key3) {
  3535. var value;
  3536. return _regenerator["default"].wrap(function _callee$(_context) {
  3537. while (1) {
  3538. switch (_context.prev = _context.next) {
  3539. case 0:
  3540. value = this._map[key1];
  3541. if (value === undefined && key2 !== undefined) {
  3542. value = this._map[key2];
  3543. if (value === undefined && key3 !== undefined) {
  3544. value = this._map[key3];
  3545. }
  3546. }
  3547. if (!(value instanceof Ref && this.xref)) {
  3548. _context.next = 4;
  3549. break;
  3550. }
  3551. return _context.abrupt("return", this.xref.fetchAsync(value, this.suppressEncryption));
  3552. case 4:
  3553. return _context.abrupt("return", value);
  3554. case 5:
  3555. case "end":
  3556. return _context.stop();
  3557. }
  3558. }
  3559. }, _callee, this);
  3560. }));
  3561. function getAsync(_x, _x2, _x3) {
  3562. return _getAsync.apply(this, arguments);
  3563. }
  3564. return getAsync;
  3565. }()
  3566. }, {
  3567. key: "getArray",
  3568. value: function getArray(key1, key2, key3) {
  3569. var value = this._map[key1];
  3570. if (value === undefined && key2 !== undefined) {
  3571. value = this._map[key2];
  3572. if (value === undefined && key3 !== undefined) {
  3573. value = this._map[key3];
  3574. }
  3575. }
  3576. if (value instanceof Ref && this.xref) {
  3577. value = this.xref.fetch(value, this.suppressEncryption);
  3578. }
  3579. if (Array.isArray(value)) {
  3580. value = value.slice();
  3581. for (var i = 0, ii = value.length; i < ii; i++) {
  3582. if (value[i] instanceof Ref && this.xref) {
  3583. value[i] = this.xref.fetch(value[i], this.suppressEncryption);
  3584. }
  3585. }
  3586. }
  3587. return value;
  3588. }
  3589. }, {
  3590. key: "getRaw",
  3591. value: function getRaw(key) {
  3592. return this._map[key];
  3593. }
  3594. }, {
  3595. key: "getKeys",
  3596. value: function getKeys() {
  3597. return Object.keys(this._map);
  3598. }
  3599. }, {
  3600. key: "getRawValues",
  3601. value: function getRawValues() {
  3602. return Object.values(this._map);
  3603. }
  3604. }, {
  3605. key: "set",
  3606. value: function set(key, value) {
  3607. this._map[key] = value;
  3608. }
  3609. }, {
  3610. key: "has",
  3611. value: function has(key) {
  3612. return this._map[key] !== undefined;
  3613. }
  3614. }, {
  3615. key: "forEach",
  3616. value: function forEach(callback) {
  3617. for (var key in this._map) {
  3618. callback(key, this.get(key));
  3619. }
  3620. }
  3621. }], [{
  3622. key: "empty",
  3623. get: function get() {
  3624. var emptyDict = new Dict(null);
  3625. emptyDict.set = function (key, value) {
  3626. (0, _util.unreachable)("Should not call `set` on the empty dictionary.");
  3627. };
  3628. return (0, _util.shadow)(this, "empty", emptyDict);
  3629. }
  3630. }, {
  3631. key: "merge",
  3632. value: function merge(_ref) {
  3633. var xref = _ref.xref,
  3634. dictArray = _ref.dictArray,
  3635. _ref$mergeSubDicts = _ref.mergeSubDicts,
  3636. mergeSubDicts = _ref$mergeSubDicts === void 0 ? false : _ref$mergeSubDicts;
  3637. var mergedDict = new Dict(xref),
  3638. properties = new Map();
  3639. var _iterator = _createForOfIteratorHelper(dictArray),
  3640. _step;
  3641. try {
  3642. for (_iterator.s(); !(_step = _iterator.n()).done;) {
  3643. var dict = _step.value;
  3644. if (!(dict instanceof Dict)) {
  3645. continue;
  3646. }
  3647. for (var _i = 0, _Object$entries = Object.entries(dict._map); _i < _Object$entries.length; _i++) {
  3648. var _Object$entries$_i = _slicedToArray(_Object$entries[_i], 2),
  3649. key = _Object$entries$_i[0],
  3650. value = _Object$entries$_i[1];
  3651. var property = properties.get(key);
  3652. if (property === undefined) {
  3653. property = [];
  3654. properties.set(key, property);
  3655. } else if (!mergeSubDicts || !(value instanceof Dict)) {
  3656. continue;
  3657. }
  3658. property.push(value);
  3659. }
  3660. }
  3661. } catch (err) {
  3662. _iterator.e(err);
  3663. } finally {
  3664. _iterator.f();
  3665. }
  3666. var _iterator2 = _createForOfIteratorHelper(properties),
  3667. _step2;
  3668. try {
  3669. for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
  3670. var _step2$value = _slicedToArray(_step2.value, 2),
  3671. name = _step2$value[0],
  3672. values = _step2$value[1];
  3673. if (values.length === 1 || !(values[0] instanceof Dict)) {
  3674. mergedDict._map[name] = values[0];
  3675. continue;
  3676. }
  3677. var subDict = new Dict(xref);
  3678. var _iterator3 = _createForOfIteratorHelper(values),
  3679. _step3;
  3680. try {
  3681. for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
  3682. var _dict = _step3.value;
  3683. for (var _i2 = 0, _Object$entries2 = Object.entries(_dict._map); _i2 < _Object$entries2.length; _i2++) {
  3684. var _Object$entries2$_i = _slicedToArray(_Object$entries2[_i2], 2),
  3685. _key = _Object$entries2$_i[0],
  3686. _value = _Object$entries2$_i[1];
  3687. if (subDict._map[_key] === undefined) {
  3688. subDict._map[_key] = _value;
  3689. }
  3690. }
  3691. }
  3692. } catch (err) {
  3693. _iterator3.e(err);
  3694. } finally {
  3695. _iterator3.f();
  3696. }
  3697. if (subDict.size > 0) {
  3698. mergedDict._map[name] = subDict;
  3699. }
  3700. }
  3701. } catch (err) {
  3702. _iterator2.e(err);
  3703. } finally {
  3704. _iterator2.f();
  3705. }
  3706. properties.clear();
  3707. return mergedDict.size > 0 ? mergedDict : Dict.empty;
  3708. }
  3709. }]);
  3710. return Dict;
  3711. }();
  3712. exports.Dict = Dict;
  3713. var Ref = function RefClosure() {
  3714. var refCache = Object.create(null);
  3715. var Ref = /*#__PURE__*/function () {
  3716. function Ref(num, gen) {
  3717. _classCallCheck(this, Ref);
  3718. this.num = num;
  3719. this.gen = gen;
  3720. }
  3721. _createClass(Ref, [{
  3722. key: "toString",
  3723. value: function toString() {
  3724. if (this.gen === 0) {
  3725. return "".concat(this.num, "R");
  3726. }
  3727. return "".concat(this.num, "R").concat(this.gen);
  3728. }
  3729. }], [{
  3730. key: "get",
  3731. value: function get(num, gen) {
  3732. var key = gen === 0 ? "".concat(num, "R") : "".concat(num, "R").concat(gen);
  3733. var refValue = refCache[key];
  3734. return refValue ? refValue : refCache[key] = new Ref(num, gen);
  3735. }
  3736. }, {
  3737. key: "_clearCache",
  3738. value: function _clearCache() {
  3739. refCache = Object.create(null);
  3740. }
  3741. }]);
  3742. return Ref;
  3743. }();
  3744. return Ref;
  3745. }();
  3746. exports.Ref = Ref;
  3747. var RefSet = /*#__PURE__*/function (_Symbol$iterator) {
  3748. function RefSet() {
  3749. var parent = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null;
  3750. _classCallCheck(this, RefSet);
  3751. this._set = new Set(parent && parent._set);
  3752. }
  3753. _createClass(RefSet, [{
  3754. key: "has",
  3755. value: function has(ref) {
  3756. return this._set.has(ref.toString());
  3757. }
  3758. }, {
  3759. key: "put",
  3760. value: function put(ref) {
  3761. this._set.add(ref.toString());
  3762. }
  3763. }, {
  3764. key: "remove",
  3765. value: function remove(ref) {
  3766. this._set["delete"](ref.toString());
  3767. }
  3768. }, {
  3769. key: _Symbol$iterator,
  3770. value: function value() {
  3771. return this._set.values();
  3772. }
  3773. }, {
  3774. key: "clear",
  3775. value: function clear() {
  3776. this._set.clear();
  3777. }
  3778. }]);
  3779. return RefSet;
  3780. }(Symbol.iterator);
  3781. exports.RefSet = RefSet;
  3782. var RefSetCache = /*#__PURE__*/function (_Symbol$iterator2) {
  3783. function RefSetCache() {
  3784. _classCallCheck(this, RefSetCache);
  3785. this._map = new Map();
  3786. }
  3787. _createClass(RefSetCache, [{
  3788. key: "size",
  3789. get: function get() {
  3790. return this._map.size;
  3791. }
  3792. }, {
  3793. key: "get",
  3794. value: function get(ref) {
  3795. return this._map.get(ref.toString());
  3796. }
  3797. }, {
  3798. key: "has",
  3799. value: function has(ref) {
  3800. return this._map.has(ref.toString());
  3801. }
  3802. }, {
  3803. key: "put",
  3804. value: function put(ref, obj) {
  3805. this._map.set(ref.toString(), obj);
  3806. }
  3807. }, {
  3808. key: "putAlias",
  3809. value: function putAlias(ref, aliasRef) {
  3810. this._map.set(ref.toString(), this.get(aliasRef));
  3811. }
  3812. }, {
  3813. key: _Symbol$iterator2,
  3814. value: function value() {
  3815. return this._map.values();
  3816. }
  3817. }, {
  3818. key: "clear",
  3819. value: function clear() {
  3820. this._map.clear();
  3821. }
  3822. }]);
  3823. return RefSetCache;
  3824. }(Symbol.iterator);
  3825. exports.RefSetCache = RefSetCache;
  3826. function isName(v, name) {
  3827. return v instanceof Name && (name === undefined || v.name === name);
  3828. }
  3829. function isCmd(v, cmd) {
  3830. return v instanceof Cmd && (cmd === undefined || v.cmd === cmd);
  3831. }
  3832. function isDict(v, type) {
  3833. return v instanceof Dict && (type === undefined || isName(v.get("Type"), type));
  3834. }
  3835. function isRefsEqual(v1, v2) {
  3836. return v1.num === v2.num && v1.gen === v2.gen;
  3837. }
  3838. function clearPrimitiveCaches() {
  3839. Cmd._clearCache();
  3840. Name._clearCache();
  3841. Ref._clearCache();
  3842. }
  3843. /***/ }),
  3844. /* 7 */
  3845. /***/ ((module, __unused_webpack_exports, __w_pdfjs_require__) => {
  3846. module.exports = __w_pdfjs_require__(8);
  3847. /***/ }),
  3848. /* 8 */
  3849. /***/ ((module, __unused_webpack_exports, __w_pdfjs_require__) => {
  3850. /* module decorator */ module = __w_pdfjs_require__.nmd(module);
  3851. function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
  3852. var runtime = function (exports) {
  3853. "use strict";
  3854. var Op = Object.prototype;
  3855. var hasOwn = Op.hasOwnProperty;
  3856. var undefined;
  3857. var $Symbol = typeof Symbol === "function" ? Symbol : {};
  3858. var iteratorSymbol = $Symbol.iterator || "@@iterator";
  3859. var asyncIteratorSymbol = $Symbol.asyncIterator || "@@asyncIterator";
  3860. var toStringTagSymbol = $Symbol.toStringTag || "@@toStringTag";
  3861. function define(obj, key, value) {
  3862. Object.defineProperty(obj, key, {
  3863. value: value,
  3864. enumerable: true,
  3865. configurable: true,
  3866. writable: true
  3867. });
  3868. return obj[key];
  3869. }
  3870. try {
  3871. define({}, "");
  3872. } catch (err) {
  3873. define = function define(obj, key, value) {
  3874. return obj[key] = value;
  3875. };
  3876. }
  3877. function wrap(innerFn, outerFn, self, tryLocsList) {
  3878. var protoGenerator = outerFn && outerFn.prototype instanceof Generator ? outerFn : Generator;
  3879. var generator = Object.create(protoGenerator.prototype);
  3880. var context = new Context(tryLocsList || []);
  3881. generator._invoke = makeInvokeMethod(innerFn, self, context);
  3882. return generator;
  3883. }
  3884. exports.wrap = wrap;
  3885. function tryCatch(fn, obj, arg) {
  3886. try {
  3887. return {
  3888. type: "normal",
  3889. arg: fn.call(obj, arg)
  3890. };
  3891. } catch (err) {
  3892. return {
  3893. type: "throw",
  3894. arg: err
  3895. };
  3896. }
  3897. }
  3898. var GenStateSuspendedStart = "suspendedStart";
  3899. var GenStateSuspendedYield = "suspendedYield";
  3900. var GenStateExecuting = "executing";
  3901. var GenStateCompleted = "completed";
  3902. var ContinueSentinel = {};
  3903. function Generator() {}
  3904. function GeneratorFunction() {}
  3905. function GeneratorFunctionPrototype() {}
  3906. var IteratorPrototype = {};
  3907. define(IteratorPrototype, iteratorSymbol, function () {
  3908. return this;
  3909. });
  3910. var getProto = Object.getPrototypeOf;
  3911. var NativeIteratorPrototype = getProto && getProto(getProto(values([])));
  3912. if (NativeIteratorPrototype && NativeIteratorPrototype !== Op && hasOwn.call(NativeIteratorPrototype, iteratorSymbol)) {
  3913. IteratorPrototype = NativeIteratorPrototype;
  3914. }
  3915. var Gp = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(IteratorPrototype);
  3916. GeneratorFunction.prototype = GeneratorFunctionPrototype;
  3917. define(Gp, "constructor", GeneratorFunctionPrototype);
  3918. define(GeneratorFunctionPrototype, "constructor", GeneratorFunction);
  3919. GeneratorFunction.displayName = define(GeneratorFunctionPrototype, toStringTagSymbol, "GeneratorFunction");
  3920. function defineIteratorMethods(prototype) {
  3921. ["next", "throw", "return"].forEach(function (method) {
  3922. define(prototype, method, function (arg) {
  3923. return this._invoke(method, arg);
  3924. });
  3925. });
  3926. }
  3927. exports.isGeneratorFunction = function (genFun) {
  3928. var ctor = typeof genFun === "function" && genFun.constructor;
  3929. return ctor ? ctor === GeneratorFunction || (ctor.displayName || ctor.name) === "GeneratorFunction" : false;
  3930. };
  3931. exports.mark = function (genFun) {
  3932. if (Object.setPrototypeOf) {
  3933. Object.setPrototypeOf(genFun, GeneratorFunctionPrototype);
  3934. } else {
  3935. genFun.__proto__ = GeneratorFunctionPrototype;
  3936. define(genFun, toStringTagSymbol, "GeneratorFunction");
  3937. }
  3938. genFun.prototype = Object.create(Gp);
  3939. return genFun;
  3940. };
  3941. exports.awrap = function (arg) {
  3942. return {
  3943. __await: arg
  3944. };
  3945. };
  3946. function AsyncIterator(generator, PromiseImpl) {
  3947. function invoke(method, arg, resolve, reject) {
  3948. var record = tryCatch(generator[method], generator, arg);
  3949. if (record.type === "throw") {
  3950. reject(record.arg);
  3951. } else {
  3952. var result = record.arg;
  3953. var value = result.value;
  3954. if (value && _typeof(value) === "object" && hasOwn.call(value, "__await")) {
  3955. return PromiseImpl.resolve(value.__await).then(function (value) {
  3956. invoke("next", value, resolve, reject);
  3957. }, function (err) {
  3958. invoke("throw", err, resolve, reject);
  3959. });
  3960. }
  3961. return PromiseImpl.resolve(value).then(function (unwrapped) {
  3962. result.value = unwrapped;
  3963. resolve(result);
  3964. }, function (error) {
  3965. return invoke("throw", error, resolve, reject);
  3966. });
  3967. }
  3968. }
  3969. var previousPromise;
  3970. function enqueue(method, arg) {
  3971. function callInvokeWithMethodAndArg() {
  3972. return new PromiseImpl(function (resolve, reject) {
  3973. invoke(method, arg, resolve, reject);
  3974. });
  3975. }
  3976. return previousPromise = previousPromise ? previousPromise.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg();
  3977. }
  3978. this._invoke = enqueue;
  3979. }
  3980. defineIteratorMethods(AsyncIterator.prototype);
  3981. define(AsyncIterator.prototype, asyncIteratorSymbol, function () {
  3982. return this;
  3983. });
  3984. exports.AsyncIterator = AsyncIterator;
  3985. exports.async = function (innerFn, outerFn, self, tryLocsList, PromiseImpl) {
  3986. if (PromiseImpl === void 0) PromiseImpl = Promise;
  3987. var iter = new AsyncIterator(wrap(innerFn, outerFn, self, tryLocsList), PromiseImpl);
  3988. return exports.isGeneratorFunction(outerFn) ? iter : iter.next().then(function (result) {
  3989. return result.done ? result.value : iter.next();
  3990. });
  3991. };
  3992. function makeInvokeMethod(innerFn, self, context) {
  3993. var state = GenStateSuspendedStart;
  3994. return function invoke(method, arg) {
  3995. if (state === GenStateExecuting) {
  3996. throw new Error("Generator is already running");
  3997. }
  3998. if (state === GenStateCompleted) {
  3999. if (method === "throw") {
  4000. throw arg;
  4001. }
  4002. return doneResult();
  4003. }
  4004. context.method = method;
  4005. context.arg = arg;
  4006. while (true) {
  4007. var delegate = context.delegate;
  4008. if (delegate) {
  4009. var delegateResult = maybeInvokeDelegate(delegate, context);
  4010. if (delegateResult) {
  4011. if (delegateResult === ContinueSentinel) continue;
  4012. return delegateResult;
  4013. }
  4014. }
  4015. if (context.method === "next") {
  4016. context.sent = context._sent = context.arg;
  4017. } else if (context.method === "throw") {
  4018. if (state === GenStateSuspendedStart) {
  4019. state = GenStateCompleted;
  4020. throw context.arg;
  4021. }
  4022. context.dispatchException(context.arg);
  4023. } else if (context.method === "return") {
  4024. context.abrupt("return", context.arg);
  4025. }
  4026. state = GenStateExecuting;
  4027. var record = tryCatch(innerFn, self, context);
  4028. if (record.type === "normal") {
  4029. state = context.done ? GenStateCompleted : GenStateSuspendedYield;
  4030. if (record.arg === ContinueSentinel) {
  4031. continue;
  4032. }
  4033. return {
  4034. value: record.arg,
  4035. done: context.done
  4036. };
  4037. } else if (record.type === "throw") {
  4038. state = GenStateCompleted;
  4039. context.method = "throw";
  4040. context.arg = record.arg;
  4041. }
  4042. }
  4043. };
  4044. }
  4045. function maybeInvokeDelegate(delegate, context) {
  4046. var method = delegate.iterator[context.method];
  4047. if (method === undefined) {
  4048. context.delegate = null;
  4049. if (context.method === "throw") {
  4050. if (delegate.iterator["return"]) {
  4051. context.method = "return";
  4052. context.arg = undefined;
  4053. maybeInvokeDelegate(delegate, context);
  4054. if (context.method === "throw") {
  4055. return ContinueSentinel;
  4056. }
  4057. }
  4058. context.method = "throw";
  4059. context.arg = new TypeError("The iterator does not provide a 'throw' method");
  4060. }
  4061. return ContinueSentinel;
  4062. }
  4063. var record = tryCatch(method, delegate.iterator, context.arg);
  4064. if (record.type === "throw") {
  4065. context.method = "throw";
  4066. context.arg = record.arg;
  4067. context.delegate = null;
  4068. return ContinueSentinel;
  4069. }
  4070. var info = record.arg;
  4071. if (!info) {
  4072. context.method = "throw";
  4073. context.arg = new TypeError("iterator result is not an object");
  4074. context.delegate = null;
  4075. return ContinueSentinel;
  4076. }
  4077. if (info.done) {
  4078. context[delegate.resultName] = info.value;
  4079. context.next = delegate.nextLoc;
  4080. if (context.method !== "return") {
  4081. context.method = "next";
  4082. context.arg = undefined;
  4083. }
  4084. } else {
  4085. return info;
  4086. }
  4087. context.delegate = null;
  4088. return ContinueSentinel;
  4089. }
  4090. defineIteratorMethods(Gp);
  4091. define(Gp, toStringTagSymbol, "Generator");
  4092. define(Gp, iteratorSymbol, function () {
  4093. return this;
  4094. });
  4095. define(Gp, "toString", function () {
  4096. return "[object Generator]";
  4097. });
  4098. function pushTryEntry(locs) {
  4099. var entry = {
  4100. tryLoc: locs[0]
  4101. };
  4102. if (1 in locs) {
  4103. entry.catchLoc = locs[1];
  4104. }
  4105. if (2 in locs) {
  4106. entry.finallyLoc = locs[2];
  4107. entry.afterLoc = locs[3];
  4108. }
  4109. this.tryEntries.push(entry);
  4110. }
  4111. function resetTryEntry(entry) {
  4112. var record = entry.completion || {};
  4113. record.type = "normal";
  4114. delete record.arg;
  4115. entry.completion = record;
  4116. }
  4117. function Context(tryLocsList) {
  4118. this.tryEntries = [{
  4119. tryLoc: "root"
  4120. }];
  4121. tryLocsList.forEach(pushTryEntry, this);
  4122. this.reset(true);
  4123. }
  4124. exports.keys = function (object) {
  4125. var keys = [];
  4126. for (var key in object) {
  4127. keys.push(key);
  4128. }
  4129. keys.reverse();
  4130. return function next() {
  4131. while (keys.length) {
  4132. var key = keys.pop();
  4133. if (key in object) {
  4134. next.value = key;
  4135. next.done = false;
  4136. return next;
  4137. }
  4138. }
  4139. next.done = true;
  4140. return next;
  4141. };
  4142. };
  4143. function values(iterable) {
  4144. if (iterable) {
  4145. var iteratorMethod = iterable[iteratorSymbol];
  4146. if (iteratorMethod) {
  4147. return iteratorMethod.call(iterable);
  4148. }
  4149. if (typeof iterable.next === "function") {
  4150. return iterable;
  4151. }
  4152. if (!isNaN(iterable.length)) {
  4153. var i = -1,
  4154. next = function next() {
  4155. while (++i < iterable.length) {
  4156. if (hasOwn.call(iterable, i)) {
  4157. next.value = iterable[i];
  4158. next.done = false;
  4159. return next;
  4160. }
  4161. }
  4162. next.value = undefined;
  4163. next.done = true;
  4164. return next;
  4165. };
  4166. return next.next = next;
  4167. }
  4168. }
  4169. return {
  4170. next: doneResult
  4171. };
  4172. }
  4173. exports.values = values;
  4174. function doneResult() {
  4175. return {
  4176. value: undefined,
  4177. done: true
  4178. };
  4179. }
  4180. Context.prototype = {
  4181. constructor: Context,
  4182. reset: function reset(skipTempReset) {
  4183. this.prev = 0;
  4184. this.next = 0;
  4185. this.sent = this._sent = undefined;
  4186. this.done = false;
  4187. this.delegate = null;
  4188. this.method = "next";
  4189. this.arg = undefined;
  4190. this.tryEntries.forEach(resetTryEntry);
  4191. if (!skipTempReset) {
  4192. for (var name in this) {
  4193. if (name.charAt(0) === "t" && hasOwn.call(this, name) && !isNaN(+name.slice(1))) {
  4194. this[name] = undefined;
  4195. }
  4196. }
  4197. }
  4198. },
  4199. stop: function stop() {
  4200. this.done = true;
  4201. var rootEntry = this.tryEntries[0];
  4202. var rootRecord = rootEntry.completion;
  4203. if (rootRecord.type === "throw") {
  4204. throw rootRecord.arg;
  4205. }
  4206. return this.rval;
  4207. },
  4208. dispatchException: function dispatchException(exception) {
  4209. if (this.done) {
  4210. throw exception;
  4211. }
  4212. var context = this;
  4213. function handle(loc, caught) {
  4214. record.type = "throw";
  4215. record.arg = exception;
  4216. context.next = loc;
  4217. if (caught) {
  4218. context.method = "next";
  4219. context.arg = undefined;
  4220. }
  4221. return !!caught;
  4222. }
  4223. for (var i = this.tryEntries.length - 1; i >= 0; --i) {
  4224. var entry = this.tryEntries[i];
  4225. var record = entry.completion;
  4226. if (entry.tryLoc === "root") {
  4227. return handle("end");
  4228. }
  4229. if (entry.tryLoc <= this.prev) {
  4230. var hasCatch = hasOwn.call(entry, "catchLoc");
  4231. var hasFinally = hasOwn.call(entry, "finallyLoc");
  4232. if (hasCatch && hasFinally) {
  4233. if (this.prev < entry.catchLoc) {
  4234. return handle(entry.catchLoc, true);
  4235. } else if (this.prev < entry.finallyLoc) {
  4236. return handle(entry.finallyLoc);
  4237. }
  4238. } else if (hasCatch) {
  4239. if (this.prev < entry.catchLoc) {
  4240. return handle(entry.catchLoc, true);
  4241. }
  4242. } else if (hasFinally) {
  4243. if (this.prev < entry.finallyLoc) {
  4244. return handle(entry.finallyLoc);
  4245. }
  4246. } else {
  4247. throw new Error("try statement without catch or finally");
  4248. }
  4249. }
  4250. }
  4251. },
  4252. abrupt: function abrupt(type, arg) {
  4253. for (var i = this.tryEntries.length - 1; i >= 0; --i) {
  4254. var entry = this.tryEntries[i];
  4255. if (entry.tryLoc <= this.prev && hasOwn.call(entry, "finallyLoc") && this.prev < entry.finallyLoc) {
  4256. var finallyEntry = entry;
  4257. break;
  4258. }
  4259. }
  4260. if (finallyEntry && (type === "break" || type === "continue") && finallyEntry.tryLoc <= arg && arg <= finallyEntry.finallyLoc) {
  4261. finallyEntry = null;
  4262. }
  4263. var record = finallyEntry ? finallyEntry.completion : {};
  4264. record.type = type;
  4265. record.arg = arg;
  4266. if (finallyEntry) {
  4267. this.method = "next";
  4268. this.next = finallyEntry.finallyLoc;
  4269. return ContinueSentinel;
  4270. }
  4271. return this.complete(record);
  4272. },
  4273. complete: function complete(record, afterLoc) {
  4274. if (record.type === "throw") {
  4275. throw record.arg;
  4276. }
  4277. if (record.type === "break" || record.type === "continue") {
  4278. this.next = record.arg;
  4279. } else if (record.type === "return") {
  4280. this.rval = this.arg = record.arg;
  4281. this.method = "return";
  4282. this.next = "end";
  4283. } else if (record.type === "normal" && afterLoc) {
  4284. this.next = afterLoc;
  4285. }
  4286. return ContinueSentinel;
  4287. },
  4288. finish: function finish(finallyLoc) {
  4289. for (var i = this.tryEntries.length - 1; i >= 0; --i) {
  4290. var entry = this.tryEntries[i];
  4291. if (entry.finallyLoc === finallyLoc) {
  4292. this.complete(entry.completion, entry.afterLoc);
  4293. resetTryEntry(entry);
  4294. return ContinueSentinel;
  4295. }
  4296. }
  4297. },
  4298. "catch": function _catch(tryLoc) {
  4299. for (var i = this.tryEntries.length - 1; i >= 0; --i) {
  4300. var entry = this.tryEntries[i];
  4301. if (entry.tryLoc === tryLoc) {
  4302. var record = entry.completion;
  4303. if (record.type === "throw") {
  4304. var thrown = record.arg;
  4305. resetTryEntry(entry);
  4306. }
  4307. return thrown;
  4308. }
  4309. }
  4310. throw new Error("illegal catch attempt");
  4311. },
  4312. delegateYield: function delegateYield(iterable, resultName, nextLoc) {
  4313. this.delegate = {
  4314. iterator: values(iterable),
  4315. resultName: resultName,
  4316. nextLoc: nextLoc
  4317. };
  4318. if (this.method === "next") {
  4319. this.arg = undefined;
  4320. }
  4321. return ContinueSentinel;
  4322. }
  4323. };
  4324. return exports;
  4325. }(( false ? 0 : _typeof(module)) === "object" ? module.exports : {});
  4326. try {
  4327. regeneratorRuntime = runtime;
  4328. } catch (accidentalStrictMode) {
  4329. if ((typeof globalThis === "undefined" ? "undefined" : _typeof(globalThis)) === "object") {
  4330. globalThis.regeneratorRuntime = runtime;
  4331. } else {
  4332. Function("r", "regeneratorRuntime = r")(runtime);
  4333. }
  4334. }
  4335. /***/ }),
  4336. /* 9 */
  4337. /***/ ((__unused_webpack_module, exports, __w_pdfjs_require__) => {
  4338. Object.defineProperty(exports, "__esModule", ({
  4339. value: true
  4340. }));
  4341. exports.BaseStream = void 0;
  4342. var _util = __w_pdfjs_require__(1);
  4343. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  4344. function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
  4345. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
  4346. var BaseStream = /*#__PURE__*/function () {
  4347. function BaseStream() {
  4348. _classCallCheck(this, BaseStream);
  4349. if (this.constructor === BaseStream) {
  4350. (0, _util.unreachable)("Cannot initialize BaseStream.");
  4351. }
  4352. }
  4353. _createClass(BaseStream, [{
  4354. key: "length",
  4355. get: function get() {
  4356. (0, _util.unreachable)("Abstract getter `length` accessed");
  4357. }
  4358. }, {
  4359. key: "isEmpty",
  4360. get: function get() {
  4361. (0, _util.unreachable)("Abstract getter `isEmpty` accessed");
  4362. }
  4363. }, {
  4364. key: "isDataLoaded",
  4365. get: function get() {
  4366. return (0, _util.shadow)(this, "isDataLoaded", true);
  4367. }
  4368. }, {
  4369. key: "getByte",
  4370. value: function getByte() {
  4371. (0, _util.unreachable)("Abstract method `getByte` called");
  4372. }
  4373. }, {
  4374. key: "getBytes",
  4375. value: function getBytes(length) {
  4376. (0, _util.unreachable)("Abstract method `getBytes` called");
  4377. }
  4378. }, {
  4379. key: "peekByte",
  4380. value: function peekByte() {
  4381. var peekedByte = this.getByte();
  4382. if (peekedByte !== -1) {
  4383. this.pos--;
  4384. }
  4385. return peekedByte;
  4386. }
  4387. }, {
  4388. key: "peekBytes",
  4389. value: function peekBytes(length) {
  4390. var bytes = this.getBytes(length);
  4391. this.pos -= bytes.length;
  4392. return bytes;
  4393. }
  4394. }, {
  4395. key: "getUint16",
  4396. value: function getUint16() {
  4397. var b0 = this.getByte();
  4398. var b1 = this.getByte();
  4399. if (b0 === -1 || b1 === -1) {
  4400. return -1;
  4401. }
  4402. return (b0 << 8) + b1;
  4403. }
  4404. }, {
  4405. key: "getInt32",
  4406. value: function getInt32() {
  4407. var b0 = this.getByte();
  4408. var b1 = this.getByte();
  4409. var b2 = this.getByte();
  4410. var b3 = this.getByte();
  4411. return (b0 << 24) + (b1 << 16) + (b2 << 8) + b3;
  4412. }
  4413. }, {
  4414. key: "getByteRange",
  4415. value: function getByteRange(begin, end) {
  4416. (0, _util.unreachable)("Abstract method `getByteRange` called");
  4417. }
  4418. }, {
  4419. key: "getString",
  4420. value: function getString(length) {
  4421. return (0, _util.bytesToString)(this.getBytes(length));
  4422. }
  4423. }, {
  4424. key: "skip",
  4425. value: function skip(n) {
  4426. this.pos += n || 1;
  4427. }
  4428. }, {
  4429. key: "reset",
  4430. value: function reset() {
  4431. (0, _util.unreachable)("Abstract method `reset` called");
  4432. }
  4433. }, {
  4434. key: "moveStart",
  4435. value: function moveStart() {
  4436. (0, _util.unreachable)("Abstract method `moveStart` called");
  4437. }
  4438. }, {
  4439. key: "makeSubStream",
  4440. value: function makeSubStream(start, length) {
  4441. var dict = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
  4442. (0, _util.unreachable)("Abstract method `makeSubStream` called");
  4443. }
  4444. }, {
  4445. key: "getBaseStreams",
  4446. value: function getBaseStreams() {
  4447. return null;
  4448. }
  4449. }]);
  4450. return BaseStream;
  4451. }();
  4452. exports.BaseStream = BaseStream;
  4453. /***/ }),
  4454. /* 10 */
  4455. /***/ ((__unused_webpack_module, exports) => {
  4456. Object.defineProperty(exports, "__esModule", ({
  4457. value: true
  4458. }));
  4459. exports.ArithmeticDecoder = void 0;
  4460. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  4461. function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
  4462. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
  4463. var QeTable = [{
  4464. qe: 0x5601,
  4465. nmps: 1,
  4466. nlps: 1,
  4467. switchFlag: 1
  4468. }, {
  4469. qe: 0x3401,
  4470. nmps: 2,
  4471. nlps: 6,
  4472. switchFlag: 0
  4473. }, {
  4474. qe: 0x1801,
  4475. nmps: 3,
  4476. nlps: 9,
  4477. switchFlag: 0
  4478. }, {
  4479. qe: 0x0ac1,
  4480. nmps: 4,
  4481. nlps: 12,
  4482. switchFlag: 0
  4483. }, {
  4484. qe: 0x0521,
  4485. nmps: 5,
  4486. nlps: 29,
  4487. switchFlag: 0
  4488. }, {
  4489. qe: 0x0221,
  4490. nmps: 38,
  4491. nlps: 33,
  4492. switchFlag: 0
  4493. }, {
  4494. qe: 0x5601,
  4495. nmps: 7,
  4496. nlps: 6,
  4497. switchFlag: 1
  4498. }, {
  4499. qe: 0x5401,
  4500. nmps: 8,
  4501. nlps: 14,
  4502. switchFlag: 0
  4503. }, {
  4504. qe: 0x4801,
  4505. nmps: 9,
  4506. nlps: 14,
  4507. switchFlag: 0
  4508. }, {
  4509. qe: 0x3801,
  4510. nmps: 10,
  4511. nlps: 14,
  4512. switchFlag: 0
  4513. }, {
  4514. qe: 0x3001,
  4515. nmps: 11,
  4516. nlps: 17,
  4517. switchFlag: 0
  4518. }, {
  4519. qe: 0x2401,
  4520. nmps: 12,
  4521. nlps: 18,
  4522. switchFlag: 0
  4523. }, {
  4524. qe: 0x1c01,
  4525. nmps: 13,
  4526. nlps: 20,
  4527. switchFlag: 0
  4528. }, {
  4529. qe: 0x1601,
  4530. nmps: 29,
  4531. nlps: 21,
  4532. switchFlag: 0
  4533. }, {
  4534. qe: 0x5601,
  4535. nmps: 15,
  4536. nlps: 14,
  4537. switchFlag: 1
  4538. }, {
  4539. qe: 0x5401,
  4540. nmps: 16,
  4541. nlps: 14,
  4542. switchFlag: 0
  4543. }, {
  4544. qe: 0x5101,
  4545. nmps: 17,
  4546. nlps: 15,
  4547. switchFlag: 0
  4548. }, {
  4549. qe: 0x4801,
  4550. nmps: 18,
  4551. nlps: 16,
  4552. switchFlag: 0
  4553. }, {
  4554. qe: 0x3801,
  4555. nmps: 19,
  4556. nlps: 17,
  4557. switchFlag: 0
  4558. }, {
  4559. qe: 0x3401,
  4560. nmps: 20,
  4561. nlps: 18,
  4562. switchFlag: 0
  4563. }, {
  4564. qe: 0x3001,
  4565. nmps: 21,
  4566. nlps: 19,
  4567. switchFlag: 0
  4568. }, {
  4569. qe: 0x2801,
  4570. nmps: 22,
  4571. nlps: 19,
  4572. switchFlag: 0
  4573. }, {
  4574. qe: 0x2401,
  4575. nmps: 23,
  4576. nlps: 20,
  4577. switchFlag: 0
  4578. }, {
  4579. qe: 0x2201,
  4580. nmps: 24,
  4581. nlps: 21,
  4582. switchFlag: 0
  4583. }, {
  4584. qe: 0x1c01,
  4585. nmps: 25,
  4586. nlps: 22,
  4587. switchFlag: 0
  4588. }, {
  4589. qe: 0x1801,
  4590. nmps: 26,
  4591. nlps: 23,
  4592. switchFlag: 0
  4593. }, {
  4594. qe: 0x1601,
  4595. nmps: 27,
  4596. nlps: 24,
  4597. switchFlag: 0
  4598. }, {
  4599. qe: 0x1401,
  4600. nmps: 28,
  4601. nlps: 25,
  4602. switchFlag: 0
  4603. }, {
  4604. qe: 0x1201,
  4605. nmps: 29,
  4606. nlps: 26,
  4607. switchFlag: 0
  4608. }, {
  4609. qe: 0x1101,
  4610. nmps: 30,
  4611. nlps: 27,
  4612. switchFlag: 0
  4613. }, {
  4614. qe: 0x0ac1,
  4615. nmps: 31,
  4616. nlps: 28,
  4617. switchFlag: 0
  4618. }, {
  4619. qe: 0x09c1,
  4620. nmps: 32,
  4621. nlps: 29,
  4622. switchFlag: 0
  4623. }, {
  4624. qe: 0x08a1,
  4625. nmps: 33,
  4626. nlps: 30,
  4627. switchFlag: 0
  4628. }, {
  4629. qe: 0x0521,
  4630. nmps: 34,
  4631. nlps: 31,
  4632. switchFlag: 0
  4633. }, {
  4634. qe: 0x0441,
  4635. nmps: 35,
  4636. nlps: 32,
  4637. switchFlag: 0
  4638. }, {
  4639. qe: 0x02a1,
  4640. nmps: 36,
  4641. nlps: 33,
  4642. switchFlag: 0
  4643. }, {
  4644. qe: 0x0221,
  4645. nmps: 37,
  4646. nlps: 34,
  4647. switchFlag: 0
  4648. }, {
  4649. qe: 0x0141,
  4650. nmps: 38,
  4651. nlps: 35,
  4652. switchFlag: 0
  4653. }, {
  4654. qe: 0x0111,
  4655. nmps: 39,
  4656. nlps: 36,
  4657. switchFlag: 0
  4658. }, {
  4659. qe: 0x0085,
  4660. nmps: 40,
  4661. nlps: 37,
  4662. switchFlag: 0
  4663. }, {
  4664. qe: 0x0049,
  4665. nmps: 41,
  4666. nlps: 38,
  4667. switchFlag: 0
  4668. }, {
  4669. qe: 0x0025,
  4670. nmps: 42,
  4671. nlps: 39,
  4672. switchFlag: 0
  4673. }, {
  4674. qe: 0x0015,
  4675. nmps: 43,
  4676. nlps: 40,
  4677. switchFlag: 0
  4678. }, {
  4679. qe: 0x0009,
  4680. nmps: 44,
  4681. nlps: 41,
  4682. switchFlag: 0
  4683. }, {
  4684. qe: 0x0005,
  4685. nmps: 45,
  4686. nlps: 42,
  4687. switchFlag: 0
  4688. }, {
  4689. qe: 0x0001,
  4690. nmps: 45,
  4691. nlps: 43,
  4692. switchFlag: 0
  4693. }, {
  4694. qe: 0x5601,
  4695. nmps: 46,
  4696. nlps: 46,
  4697. switchFlag: 0
  4698. }];
  4699. var ArithmeticDecoder = /*#__PURE__*/function () {
  4700. function ArithmeticDecoder(data, start, end) {
  4701. _classCallCheck(this, ArithmeticDecoder);
  4702. this.data = data;
  4703. this.bp = start;
  4704. this.dataEnd = end;
  4705. this.chigh = data[start];
  4706. this.clow = 0;
  4707. this.byteIn();
  4708. this.chigh = this.chigh << 7 & 0xffff | this.clow >> 9 & 0x7f;
  4709. this.clow = this.clow << 7 & 0xffff;
  4710. this.ct -= 7;
  4711. this.a = 0x8000;
  4712. }
  4713. _createClass(ArithmeticDecoder, [{
  4714. key: "byteIn",
  4715. value: function byteIn() {
  4716. var data = this.data;
  4717. var bp = this.bp;
  4718. if (data[bp] === 0xff) {
  4719. if (data[bp + 1] > 0x8f) {
  4720. this.clow += 0xff00;
  4721. this.ct = 8;
  4722. } else {
  4723. bp++;
  4724. this.clow += data[bp] << 9;
  4725. this.ct = 7;
  4726. this.bp = bp;
  4727. }
  4728. } else {
  4729. bp++;
  4730. this.clow += bp < this.dataEnd ? data[bp] << 8 : 0xff00;
  4731. this.ct = 8;
  4732. this.bp = bp;
  4733. }
  4734. if (this.clow > 0xffff) {
  4735. this.chigh += this.clow >> 16;
  4736. this.clow &= 0xffff;
  4737. }
  4738. }
  4739. }, {
  4740. key: "readBit",
  4741. value: function readBit(contexts, pos) {
  4742. var cx_index = contexts[pos] >> 1,
  4743. cx_mps = contexts[pos] & 1;
  4744. var qeTableIcx = QeTable[cx_index];
  4745. var qeIcx = qeTableIcx.qe;
  4746. var d;
  4747. var a = this.a - qeIcx;
  4748. if (this.chigh < qeIcx) {
  4749. if (a < qeIcx) {
  4750. a = qeIcx;
  4751. d = cx_mps;
  4752. cx_index = qeTableIcx.nmps;
  4753. } else {
  4754. a = qeIcx;
  4755. d = 1 ^ cx_mps;
  4756. if (qeTableIcx.switchFlag === 1) {
  4757. cx_mps = d;
  4758. }
  4759. cx_index = qeTableIcx.nlps;
  4760. }
  4761. } else {
  4762. this.chigh -= qeIcx;
  4763. if ((a & 0x8000) !== 0) {
  4764. this.a = a;
  4765. return cx_mps;
  4766. }
  4767. if (a < qeIcx) {
  4768. d = 1 ^ cx_mps;
  4769. if (qeTableIcx.switchFlag === 1) {
  4770. cx_mps = d;
  4771. }
  4772. cx_index = qeTableIcx.nlps;
  4773. } else {
  4774. d = cx_mps;
  4775. cx_index = qeTableIcx.nmps;
  4776. }
  4777. }
  4778. do {
  4779. if (this.ct === 0) {
  4780. this.byteIn();
  4781. }
  4782. a <<= 1;
  4783. this.chigh = this.chigh << 1 & 0xffff | this.clow >> 15 & 1;
  4784. this.clow = this.clow << 1 & 0xffff;
  4785. this.ct--;
  4786. } while ((a & 0x8000) === 0);
  4787. this.a = a;
  4788. contexts[pos] = cx_index << 1 | cx_mps;
  4789. return d;
  4790. }
  4791. }]);
  4792. return ArithmeticDecoder;
  4793. }();
  4794. exports.ArithmeticDecoder = ArithmeticDecoder;
  4795. /***/ }),
  4796. /* 11 */
  4797. /***/ ((__unused_webpack_module, exports, __w_pdfjs_require__) => {
  4798. Object.defineProperty(exports, "__esModule", ({
  4799. value: true
  4800. }));
  4801. exports.CCITTFaxDecoder = void 0;
  4802. var _util = __w_pdfjs_require__(1);
  4803. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  4804. function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
  4805. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
  4806. var ccittEOL = -2;
  4807. var ccittEOF = -1;
  4808. var twoDimPass = 0;
  4809. var twoDimHoriz = 1;
  4810. var twoDimVert0 = 2;
  4811. var twoDimVertR1 = 3;
  4812. var twoDimVertL1 = 4;
  4813. var twoDimVertR2 = 5;
  4814. var twoDimVertL2 = 6;
  4815. var twoDimVertR3 = 7;
  4816. var twoDimVertL3 = 8;
  4817. var twoDimTable = [[-1, -1], [-1, -1], [7, twoDimVertL3], [7, twoDimVertR3], [6, twoDimVertL2], [6, twoDimVertL2], [6, twoDimVertR2], [6, twoDimVertR2], [4, twoDimPass], [4, twoDimPass], [4, twoDimPass], [4, twoDimPass], [4, twoDimPass], [4, twoDimPass], [4, twoDimPass], [4, twoDimPass], [3, twoDimHoriz], [3, twoDimHoriz], [3, twoDimHoriz], [3, twoDimHoriz], [3, twoDimHoriz], [3, twoDimHoriz], [3, twoDimHoriz], [3, twoDimHoriz], [3, twoDimHoriz], [3, twoDimHoriz], [3, twoDimHoriz], [3, twoDimHoriz], [3, twoDimHoriz], [3, twoDimHoriz], [3, twoDimHoriz], [3, twoDimHoriz], [3, twoDimVertL1], [3, twoDimVertL1], [3, twoDimVertL1], [3, twoDimVertL1], [3, twoDimVertL1], [3, twoDimVertL1], [3, twoDimVertL1], [3, twoDimVertL1], [3, twoDimVertL1], [3, twoDimVertL1], [3, twoDimVertL1], [3, twoDimVertL1], [3, twoDimVertL1], [3, twoDimVertL1], [3, twoDimVertL1], [3, twoDimVertL1], [3, twoDimVertR1], [3, twoDimVertR1], [3, twoDimVertR1], [3, twoDimVertR1], [3, twoDimVertR1], [3, twoDimVertR1], [3, twoDimVertR1], [3, twoDimVertR1], [3, twoDimVertR1], [3, twoDimVertR1], [3, twoDimVertR1], [3, twoDimVertR1], [3, twoDimVertR1], [3, twoDimVertR1], [3, twoDimVertR1], [3, twoDimVertR1], [1, twoDimVert0], [1, twoDimVert0], [1, twoDimVert0], [1, twoDimVert0], [1, twoDimVert0], [1, twoDimVert0], [1, twoDimVert0], [1, twoDimVert0], [1, twoDimVert0], [1, twoDimVert0], [1, twoDimVert0], [1, twoDimVert0], [1, twoDimVert0], [1, twoDimVert0], [1, twoDimVert0], [1, twoDimVert0], [1, twoDimVert0], [1, twoDimVert0], [1, twoDimVert0], [1, twoDimVert0], [1, twoDimVert0], [1, twoDimVert0], [1, twoDimVert0], [1, twoDimVert0], [1, twoDimVert0], [1, twoDimVert0], [1, twoDimVert0], [1, twoDimVert0], [1, twoDimVert0], [1, twoDimVert0], [1, twoDimVert0], [1, twoDimVert0], [1, twoDimVert0], [1, twoDimVert0], [1, twoDimVert0], [1, twoDimVert0], [1, twoDimVert0], [1, twoDimVert0], [1, twoDimVert0], [1, twoDimVert0], [1, twoDimVert0], [1, twoDimVert0], [1, twoDimVert0], [1, twoDimVert0], [1, twoDimVert0], [1, twoDimVert0], [1, twoDimVert0], [1, twoDimVert0], [1, twoDimVert0], [1, twoDimVert0], [1, twoDimVert0], [1, twoDimVert0], [1, twoDimVert0], [1, twoDimVert0], [1, twoDimVert0], [1, twoDimVert0], [1, twoDimVert0], [1, twoDimVert0], [1, twoDimVert0], [1, twoDimVert0], [1, twoDimVert0], [1, twoDimVert0], [1, twoDimVert0], [1, twoDimVert0]];
  4818. var whiteTable1 = [[-1, -1], [12, ccittEOL], [-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]];
  4819. var whiteTable2 = [[-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]];
  4820. var blackTable1 = [[-1, -1], [-1, -1], [12, ccittEOL], [12, ccittEOL], [-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]];
  4821. var blackTable2 = [[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]];
  4822. var blackTable3 = [[-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]];
  4823. var CCITTFaxDecoder = /*#__PURE__*/function () {
  4824. function CCITTFaxDecoder(source) {
  4825. var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  4826. _classCallCheck(this, CCITTFaxDecoder);
  4827. if (!source || typeof source.next !== "function") {
  4828. throw new Error('CCITTFaxDecoder - invalid "source" parameter.');
  4829. }
  4830. this.source = source;
  4831. this.eof = false;
  4832. this.encoding = options.K || 0;
  4833. this.eoline = options.EndOfLine || false;
  4834. this.byteAlign = options.EncodedByteAlign || false;
  4835. this.columns = options.Columns || 1728;
  4836. this.rows = options.Rows || 0;
  4837. var eoblock = options.EndOfBlock;
  4838. if (eoblock === null || eoblock === undefined) {
  4839. eoblock = true;
  4840. }
  4841. this.eoblock = eoblock;
  4842. this.black = options.BlackIs1 || false;
  4843. this.codingLine = new Uint32Array(this.columns + 1);
  4844. this.refLine = new Uint32Array(this.columns + 2);
  4845. this.codingLine[0] = this.columns;
  4846. this.codingPos = 0;
  4847. this.row = 0;
  4848. this.nextLine2D = this.encoding < 0;
  4849. this.inputBits = 0;
  4850. this.inputBuf = 0;
  4851. this.outputBits = 0;
  4852. this.rowsDone = false;
  4853. var code1;
  4854. while ((code1 = this._lookBits(12)) === 0) {
  4855. this._eatBits(1);
  4856. }
  4857. if (code1 === 1) {
  4858. this._eatBits(12);
  4859. }
  4860. if (this.encoding > 0) {
  4861. this.nextLine2D = !this._lookBits(1);
  4862. this._eatBits(1);
  4863. }
  4864. }
  4865. _createClass(CCITTFaxDecoder, [{
  4866. key: "readNextChar",
  4867. value: function readNextChar() {
  4868. if (this.eof) {
  4869. return -1;
  4870. }
  4871. var refLine = this.refLine;
  4872. var codingLine = this.codingLine;
  4873. var columns = this.columns;
  4874. var refPos, blackPixels, bits, i;
  4875. if (this.outputBits === 0) {
  4876. if (this.rowsDone) {
  4877. this.eof = true;
  4878. }
  4879. if (this.eof) {
  4880. return -1;
  4881. }
  4882. this.err = false;
  4883. var code1, code2, code3;
  4884. if (this.nextLine2D) {
  4885. for (i = 0; codingLine[i] < columns; ++i) {
  4886. refLine[i] = codingLine[i];
  4887. }
  4888. refLine[i++] = columns;
  4889. refLine[i] = columns;
  4890. codingLine[0] = 0;
  4891. this.codingPos = 0;
  4892. refPos = 0;
  4893. blackPixels = 0;
  4894. while (codingLine[this.codingPos] < columns) {
  4895. code1 = this._getTwoDimCode();
  4896. switch (code1) {
  4897. case twoDimPass:
  4898. this._addPixels(refLine[refPos + 1], blackPixels);
  4899. if (refLine[refPos + 1] < columns) {
  4900. refPos += 2;
  4901. }
  4902. break;
  4903. case twoDimHoriz:
  4904. code1 = code2 = 0;
  4905. if (blackPixels) {
  4906. do {
  4907. code1 += code3 = this._getBlackCode();
  4908. } while (code3 >= 64);
  4909. do {
  4910. code2 += code3 = this._getWhiteCode();
  4911. } while (code3 >= 64);
  4912. } else {
  4913. do {
  4914. code1 += code3 = this._getWhiteCode();
  4915. } while (code3 >= 64);
  4916. do {
  4917. code2 += code3 = this._getBlackCode();
  4918. } while (code3 >= 64);
  4919. }
  4920. this._addPixels(codingLine[this.codingPos] + code1, blackPixels);
  4921. if (codingLine[this.codingPos] < columns) {
  4922. this._addPixels(codingLine[this.codingPos] + code2, blackPixels ^ 1);
  4923. }
  4924. while (refLine[refPos] <= codingLine[this.codingPos] && refLine[refPos] < columns) {
  4925. refPos += 2;
  4926. }
  4927. break;
  4928. case twoDimVertR3:
  4929. this._addPixels(refLine[refPos] + 3, blackPixels);
  4930. blackPixels ^= 1;
  4931. if (codingLine[this.codingPos] < columns) {
  4932. ++refPos;
  4933. while (refLine[refPos] <= codingLine[this.codingPos] && refLine[refPos] < columns) {
  4934. refPos += 2;
  4935. }
  4936. }
  4937. break;
  4938. case twoDimVertR2:
  4939. this._addPixels(refLine[refPos] + 2, blackPixels);
  4940. blackPixels ^= 1;
  4941. if (codingLine[this.codingPos] < columns) {
  4942. ++refPos;
  4943. while (refLine[refPos] <= codingLine[this.codingPos] && refLine[refPos] < columns) {
  4944. refPos += 2;
  4945. }
  4946. }
  4947. break;
  4948. case twoDimVertR1:
  4949. this._addPixels(refLine[refPos] + 1, blackPixels);
  4950. blackPixels ^= 1;
  4951. if (codingLine[this.codingPos] < columns) {
  4952. ++refPos;
  4953. while (refLine[refPos] <= codingLine[this.codingPos] && refLine[refPos] < columns) {
  4954. refPos += 2;
  4955. }
  4956. }
  4957. break;
  4958. case twoDimVert0:
  4959. this._addPixels(refLine[refPos], blackPixels);
  4960. blackPixels ^= 1;
  4961. if (codingLine[this.codingPos] < columns) {
  4962. ++refPos;
  4963. while (refLine[refPos] <= codingLine[this.codingPos] && refLine[refPos] < columns) {
  4964. refPos += 2;
  4965. }
  4966. }
  4967. break;
  4968. case twoDimVertL3:
  4969. this._addPixelsNeg(refLine[refPos] - 3, blackPixels);
  4970. blackPixels ^= 1;
  4971. if (codingLine[this.codingPos] < columns) {
  4972. if (refPos > 0) {
  4973. --refPos;
  4974. } else {
  4975. ++refPos;
  4976. }
  4977. while (refLine[refPos] <= codingLine[this.codingPos] && refLine[refPos] < columns) {
  4978. refPos += 2;
  4979. }
  4980. }
  4981. break;
  4982. case twoDimVertL2:
  4983. this._addPixelsNeg(refLine[refPos] - 2, blackPixels);
  4984. blackPixels ^= 1;
  4985. if (codingLine[this.codingPos] < columns) {
  4986. if (refPos > 0) {
  4987. --refPos;
  4988. } else {
  4989. ++refPos;
  4990. }
  4991. while (refLine[refPos] <= codingLine[this.codingPos] && refLine[refPos] < columns) {
  4992. refPos += 2;
  4993. }
  4994. }
  4995. break;
  4996. case twoDimVertL1:
  4997. this._addPixelsNeg(refLine[refPos] - 1, blackPixels);
  4998. blackPixels ^= 1;
  4999. if (codingLine[this.codingPos] < columns) {
  5000. if (refPos > 0) {
  5001. --refPos;
  5002. } else {
  5003. ++refPos;
  5004. }
  5005. while (refLine[refPos] <= codingLine[this.codingPos] && refLine[refPos] < columns) {
  5006. refPos += 2;
  5007. }
  5008. }
  5009. break;
  5010. case ccittEOF:
  5011. this._addPixels(columns, 0);
  5012. this.eof = true;
  5013. break;
  5014. default:
  5015. (0, _util.info)("bad 2d code");
  5016. this._addPixels(columns, 0);
  5017. this.err = true;
  5018. }
  5019. }
  5020. } else {
  5021. codingLine[0] = 0;
  5022. this.codingPos = 0;
  5023. blackPixels = 0;
  5024. while (codingLine[this.codingPos] < columns) {
  5025. code1 = 0;
  5026. if (blackPixels) {
  5027. do {
  5028. code1 += code3 = this._getBlackCode();
  5029. } while (code3 >= 64);
  5030. } else {
  5031. do {
  5032. code1 += code3 = this._getWhiteCode();
  5033. } while (code3 >= 64);
  5034. }
  5035. this._addPixels(codingLine[this.codingPos] + code1, blackPixels);
  5036. blackPixels ^= 1;
  5037. }
  5038. }
  5039. var gotEOL = false;
  5040. if (this.byteAlign) {
  5041. this.inputBits &= ~7;
  5042. }
  5043. if (!this.eoblock && this.row === this.rows - 1) {
  5044. this.rowsDone = true;
  5045. } else {
  5046. code1 = this._lookBits(12);
  5047. if (this.eoline) {
  5048. while (code1 !== ccittEOF && code1 !== 1) {
  5049. this._eatBits(1);
  5050. code1 = this._lookBits(12);
  5051. }
  5052. } else {
  5053. while (code1 === 0) {
  5054. this._eatBits(1);
  5055. code1 = this._lookBits(12);
  5056. }
  5057. }
  5058. if (code1 === 1) {
  5059. this._eatBits(12);
  5060. gotEOL = true;
  5061. } else if (code1 === ccittEOF) {
  5062. this.eof = true;
  5063. }
  5064. }
  5065. if (!this.eof && this.encoding > 0 && !this.rowsDone) {
  5066. this.nextLine2D = !this._lookBits(1);
  5067. this._eatBits(1);
  5068. }
  5069. if (this.eoblock && gotEOL && this.byteAlign) {
  5070. code1 = this._lookBits(12);
  5071. if (code1 === 1) {
  5072. this._eatBits(12);
  5073. if (this.encoding > 0) {
  5074. this._lookBits(1);
  5075. this._eatBits(1);
  5076. }
  5077. if (this.encoding >= 0) {
  5078. for (i = 0; i < 4; ++i) {
  5079. code1 = this._lookBits(12);
  5080. if (code1 !== 1) {
  5081. (0, _util.info)("bad rtc code: " + code1);
  5082. }
  5083. this._eatBits(12);
  5084. if (this.encoding > 0) {
  5085. this._lookBits(1);
  5086. this._eatBits(1);
  5087. }
  5088. }
  5089. }
  5090. this.eof = true;
  5091. }
  5092. } else if (this.err && this.eoline) {
  5093. while (true) {
  5094. code1 = this._lookBits(13);
  5095. if (code1 === ccittEOF) {
  5096. this.eof = true;
  5097. return -1;
  5098. }
  5099. if (code1 >> 1 === 1) {
  5100. break;
  5101. }
  5102. this._eatBits(1);
  5103. }
  5104. this._eatBits(12);
  5105. if (this.encoding > 0) {
  5106. this._eatBits(1);
  5107. this.nextLine2D = !(code1 & 1);
  5108. }
  5109. }
  5110. if (codingLine[0] > 0) {
  5111. this.outputBits = codingLine[this.codingPos = 0];
  5112. } else {
  5113. this.outputBits = codingLine[this.codingPos = 1];
  5114. }
  5115. this.row++;
  5116. }
  5117. var c;
  5118. if (this.outputBits >= 8) {
  5119. c = this.codingPos & 1 ? 0 : 0xff;
  5120. this.outputBits -= 8;
  5121. if (this.outputBits === 0 && codingLine[this.codingPos] < columns) {
  5122. this.codingPos++;
  5123. this.outputBits = codingLine[this.codingPos] - codingLine[this.codingPos - 1];
  5124. }
  5125. } else {
  5126. bits = 8;
  5127. c = 0;
  5128. do {
  5129. if (typeof this.outputBits !== "number") {
  5130. throw new _util.FormatError('Invalid /CCITTFaxDecode data, "outputBits" must be a number.');
  5131. }
  5132. if (this.outputBits > bits) {
  5133. c <<= bits;
  5134. if (!(this.codingPos & 1)) {
  5135. c |= 0xff >> 8 - bits;
  5136. }
  5137. this.outputBits -= bits;
  5138. bits = 0;
  5139. } else {
  5140. c <<= this.outputBits;
  5141. if (!(this.codingPos & 1)) {
  5142. c |= 0xff >> 8 - this.outputBits;
  5143. }
  5144. bits -= this.outputBits;
  5145. this.outputBits = 0;
  5146. if (codingLine[this.codingPos] < columns) {
  5147. this.codingPos++;
  5148. this.outputBits = codingLine[this.codingPos] - codingLine[this.codingPos - 1];
  5149. } else if (bits > 0) {
  5150. c <<= bits;
  5151. bits = 0;
  5152. }
  5153. }
  5154. } while (bits);
  5155. }
  5156. if (this.black) {
  5157. c ^= 0xff;
  5158. }
  5159. return c;
  5160. }
  5161. }, {
  5162. key: "_addPixels",
  5163. value: function _addPixels(a1, blackPixels) {
  5164. var codingLine = this.codingLine;
  5165. var codingPos = this.codingPos;
  5166. if (a1 > codingLine[codingPos]) {
  5167. if (a1 > this.columns) {
  5168. (0, _util.info)("row is wrong length");
  5169. this.err = true;
  5170. a1 = this.columns;
  5171. }
  5172. if (codingPos & 1 ^ blackPixels) {
  5173. ++codingPos;
  5174. }
  5175. codingLine[codingPos] = a1;
  5176. }
  5177. this.codingPos = codingPos;
  5178. }
  5179. }, {
  5180. key: "_addPixelsNeg",
  5181. value: function _addPixelsNeg(a1, blackPixels) {
  5182. var codingLine = this.codingLine;
  5183. var codingPos = this.codingPos;
  5184. if (a1 > codingLine[codingPos]) {
  5185. if (a1 > this.columns) {
  5186. (0, _util.info)("row is wrong length");
  5187. this.err = true;
  5188. a1 = this.columns;
  5189. }
  5190. if (codingPos & 1 ^ blackPixels) {
  5191. ++codingPos;
  5192. }
  5193. codingLine[codingPos] = a1;
  5194. } else if (a1 < codingLine[codingPos]) {
  5195. if (a1 < 0) {
  5196. (0, _util.info)("invalid code");
  5197. this.err = true;
  5198. a1 = 0;
  5199. }
  5200. while (codingPos > 0 && a1 < codingLine[codingPos - 1]) {
  5201. --codingPos;
  5202. }
  5203. codingLine[codingPos] = a1;
  5204. }
  5205. this.codingPos = codingPos;
  5206. }
  5207. }, {
  5208. key: "_findTableCode",
  5209. value: function _findTableCode(start, end, table, limit) {
  5210. var limitValue = limit || 0;
  5211. for (var i = start; i <= end; ++i) {
  5212. var code = this._lookBits(i);
  5213. if (code === ccittEOF) {
  5214. return [true, 1, false];
  5215. }
  5216. if (i < end) {
  5217. code <<= end - i;
  5218. }
  5219. if (!limitValue || code >= limitValue) {
  5220. var p = table[code - limitValue];
  5221. if (p[0] === i) {
  5222. this._eatBits(i);
  5223. return [true, p[1], true];
  5224. }
  5225. }
  5226. }
  5227. return [false, 0, false];
  5228. }
  5229. }, {
  5230. key: "_getTwoDimCode",
  5231. value: function _getTwoDimCode() {
  5232. var code = 0;
  5233. var p;
  5234. if (this.eoblock) {
  5235. code = this._lookBits(7);
  5236. p = twoDimTable[code];
  5237. if (p && p[0] > 0) {
  5238. this._eatBits(p[0]);
  5239. return p[1];
  5240. }
  5241. } else {
  5242. var result = this._findTableCode(1, 7, twoDimTable);
  5243. if (result[0] && result[2]) {
  5244. return result[1];
  5245. }
  5246. }
  5247. (0, _util.info)("Bad two dim code");
  5248. return ccittEOF;
  5249. }
  5250. }, {
  5251. key: "_getWhiteCode",
  5252. value: function _getWhiteCode() {
  5253. var code = 0;
  5254. var p;
  5255. if (this.eoblock) {
  5256. code = this._lookBits(12);
  5257. if (code === ccittEOF) {
  5258. return 1;
  5259. }
  5260. if (code >> 5 === 0) {
  5261. p = whiteTable1[code];
  5262. } else {
  5263. p = whiteTable2[code >> 3];
  5264. }
  5265. if (p[0] > 0) {
  5266. this._eatBits(p[0]);
  5267. return p[1];
  5268. }
  5269. } else {
  5270. var result = this._findTableCode(1, 9, whiteTable2);
  5271. if (result[0]) {
  5272. return result[1];
  5273. }
  5274. result = this._findTableCode(11, 12, whiteTable1);
  5275. if (result[0]) {
  5276. return result[1];
  5277. }
  5278. }
  5279. (0, _util.info)("bad white code");
  5280. this._eatBits(1);
  5281. return 1;
  5282. }
  5283. }, {
  5284. key: "_getBlackCode",
  5285. value: function _getBlackCode() {
  5286. var code, p;
  5287. if (this.eoblock) {
  5288. code = this._lookBits(13);
  5289. if (code === ccittEOF) {
  5290. return 1;
  5291. }
  5292. if (code >> 7 === 0) {
  5293. p = blackTable1[code];
  5294. } else if (code >> 9 === 0 && code >> 7 !== 0) {
  5295. p = blackTable2[(code >> 1) - 64];
  5296. } else {
  5297. p = blackTable3[code >> 7];
  5298. }
  5299. if (p[0] > 0) {
  5300. this._eatBits(p[0]);
  5301. return p[1];
  5302. }
  5303. } else {
  5304. var result = this._findTableCode(2, 6, blackTable3);
  5305. if (result[0]) {
  5306. return result[1];
  5307. }
  5308. result = this._findTableCode(7, 12, blackTable2, 64);
  5309. if (result[0]) {
  5310. return result[1];
  5311. }
  5312. result = this._findTableCode(10, 13, blackTable1);
  5313. if (result[0]) {
  5314. return result[1];
  5315. }
  5316. }
  5317. (0, _util.info)("bad black code");
  5318. this._eatBits(1);
  5319. return 1;
  5320. }
  5321. }, {
  5322. key: "_lookBits",
  5323. value: function _lookBits(n) {
  5324. var c;
  5325. while (this.inputBits < n) {
  5326. if ((c = this.source.next()) === -1) {
  5327. if (this.inputBits === 0) {
  5328. return ccittEOF;
  5329. }
  5330. return this.inputBuf << n - this.inputBits & 0xffff >> 16 - n;
  5331. }
  5332. this.inputBuf = this.inputBuf << 8 | c;
  5333. this.inputBits += 8;
  5334. }
  5335. return this.inputBuf >> this.inputBits - n & 0xffff >> 16 - n;
  5336. }
  5337. }, {
  5338. key: "_eatBits",
  5339. value: function _eatBits(n) {
  5340. if ((this.inputBits -= n) < 0) {
  5341. this.inputBits = 0;
  5342. }
  5343. }
  5344. }]);
  5345. return CCITTFaxDecoder;
  5346. }();
  5347. exports.CCITTFaxDecoder = CCITTFaxDecoder;
  5348. /***/ }),
  5349. /* 12 */
  5350. /***/ ((__unused_webpack_module, exports, __w_pdfjs_require__) => {
  5351. Object.defineProperty(exports, "__esModule", ({
  5352. value: true
  5353. }));
  5354. exports.JpegImage = void 0;
  5355. var _util = __w_pdfjs_require__(1);
  5356. var _core_utils = __w_pdfjs_require__(5);
  5357. function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
  5358. function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
  5359. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
  5360. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  5361. function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); }
  5362. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  5363. function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
  5364. function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); }
  5365. function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
  5366. function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
  5367. function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
  5368. var JpegError = /*#__PURE__*/function (_BaseException) {
  5369. _inherits(JpegError, _BaseException);
  5370. var _super = _createSuper(JpegError);
  5371. function JpegError(msg) {
  5372. _classCallCheck(this, JpegError);
  5373. return _super.call(this, "JPEG error: ".concat(msg), "JpegError");
  5374. }
  5375. return _createClass(JpegError);
  5376. }(_util.BaseException);
  5377. var DNLMarkerError = /*#__PURE__*/function (_BaseException2) {
  5378. _inherits(DNLMarkerError, _BaseException2);
  5379. var _super2 = _createSuper(DNLMarkerError);
  5380. function DNLMarkerError(message, scanLines) {
  5381. var _this;
  5382. _classCallCheck(this, DNLMarkerError);
  5383. _this = _super2.call(this, message, "DNLMarkerError");
  5384. _this.scanLines = scanLines;
  5385. return _this;
  5386. }
  5387. return _createClass(DNLMarkerError);
  5388. }(_util.BaseException);
  5389. var EOIMarkerError = /*#__PURE__*/function (_BaseException3) {
  5390. _inherits(EOIMarkerError, _BaseException3);
  5391. var _super3 = _createSuper(EOIMarkerError);
  5392. function EOIMarkerError(msg) {
  5393. _classCallCheck(this, EOIMarkerError);
  5394. return _super3.call(this, msg, "EOIMarkerError");
  5395. }
  5396. return _createClass(EOIMarkerError);
  5397. }(_util.BaseException);
  5398. var dctZigZag = 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]);
  5399. var dctCos1 = 4017;
  5400. var dctSin1 = 799;
  5401. var dctCos3 = 3406;
  5402. var dctSin3 = 2276;
  5403. var dctCos6 = 1567;
  5404. var dctSin6 = 3784;
  5405. var dctSqrt2 = 5793;
  5406. var dctSqrt1d2 = 2896;
  5407. function buildHuffmanTable(codeLengths, values) {
  5408. var k = 0,
  5409. i,
  5410. j,
  5411. length = 16;
  5412. while (length > 0 && !codeLengths[length - 1]) {
  5413. length--;
  5414. }
  5415. var code = [{
  5416. children: [],
  5417. index: 0
  5418. }];
  5419. var p = code[0],
  5420. q;
  5421. for (i = 0; i < length; i++) {
  5422. for (j = 0; j < codeLengths[i]; j++) {
  5423. p = code.pop();
  5424. p.children[p.index] = values[k];
  5425. while (p.index > 0) {
  5426. p = code.pop();
  5427. }
  5428. p.index++;
  5429. code.push(p);
  5430. while (code.length <= i) {
  5431. code.push(q = {
  5432. children: [],
  5433. index: 0
  5434. });
  5435. p.children[p.index] = q.children;
  5436. p = q;
  5437. }
  5438. k++;
  5439. }
  5440. if (i + 1 < length) {
  5441. code.push(q = {
  5442. children: [],
  5443. index: 0
  5444. });
  5445. p.children[p.index] = q.children;
  5446. p = q;
  5447. }
  5448. }
  5449. return code[0].children;
  5450. }
  5451. function getBlockBufferOffset(component, row, col) {
  5452. return 64 * ((component.blocksPerLine + 1) * row + col);
  5453. }
  5454. function decodeScan(data, offset, frame, components, resetInterval, spectralStart, spectralEnd, successivePrev, successive) {
  5455. var parseDNLMarker = arguments.length > 9 && arguments[9] !== undefined ? arguments[9] : false;
  5456. var mcusPerLine = frame.mcusPerLine;
  5457. var progressive = frame.progressive;
  5458. var startOffset = offset;
  5459. var bitsData = 0,
  5460. bitsCount = 0;
  5461. function readBit() {
  5462. if (bitsCount > 0) {
  5463. bitsCount--;
  5464. return bitsData >> bitsCount & 1;
  5465. }
  5466. bitsData = data[offset++];
  5467. if (bitsData === 0xff) {
  5468. var nextByte = data[offset++];
  5469. if (nextByte) {
  5470. if (nextByte === 0xdc && parseDNLMarker) {
  5471. offset += 2;
  5472. var scanLines = (0, _core_utils.readUint16)(data, offset);
  5473. offset += 2;
  5474. if (scanLines > 0 && scanLines !== frame.scanLines) {
  5475. throw new DNLMarkerError("Found DNL marker (0xFFDC) while parsing scan data", scanLines);
  5476. }
  5477. } else if (nextByte === 0xd9) {
  5478. if (parseDNLMarker) {
  5479. var maybeScanLines = blockRow * (frame.precision === 8 ? 8 : 0);
  5480. if (maybeScanLines > 0 && Math.round(frame.scanLines / maybeScanLines) >= 10) {
  5481. throw new DNLMarkerError("Found EOI marker (0xFFD9) while parsing scan data, " + "possibly caused by incorrect `scanLines` parameter", maybeScanLines);
  5482. }
  5483. }
  5484. throw new EOIMarkerError("Found EOI marker (0xFFD9) while parsing scan data");
  5485. }
  5486. throw new JpegError("unexpected marker ".concat((bitsData << 8 | nextByte).toString(16)));
  5487. }
  5488. }
  5489. bitsCount = 7;
  5490. return bitsData >>> 7;
  5491. }
  5492. function decodeHuffman(tree) {
  5493. var node = tree;
  5494. while (true) {
  5495. node = node[readBit()];
  5496. switch (_typeof(node)) {
  5497. case "number":
  5498. return node;
  5499. case "object":
  5500. continue;
  5501. }
  5502. throw new JpegError("invalid huffman sequence");
  5503. }
  5504. }
  5505. function receive(length) {
  5506. var n = 0;
  5507. while (length > 0) {
  5508. n = n << 1 | readBit();
  5509. length--;
  5510. }
  5511. return n;
  5512. }
  5513. function receiveAndExtend(length) {
  5514. if (length === 1) {
  5515. return readBit() === 1 ? 1 : -1;
  5516. }
  5517. var n = receive(length);
  5518. if (n >= 1 << length - 1) {
  5519. return n;
  5520. }
  5521. return n + (-1 << length) + 1;
  5522. }
  5523. function decodeBaseline(component, blockOffset) {
  5524. var t = decodeHuffman(component.huffmanTableDC);
  5525. var diff = t === 0 ? 0 : receiveAndExtend(t);
  5526. component.blockData[blockOffset] = component.pred += diff;
  5527. var k = 1;
  5528. while (k < 64) {
  5529. var rs = decodeHuffman(component.huffmanTableAC);
  5530. var s = rs & 15,
  5531. r = rs >> 4;
  5532. if (s === 0) {
  5533. if (r < 15) {
  5534. break;
  5535. }
  5536. k += 16;
  5537. continue;
  5538. }
  5539. k += r;
  5540. var z = dctZigZag[k];
  5541. component.blockData[blockOffset + z] = receiveAndExtend(s);
  5542. k++;
  5543. }
  5544. }
  5545. function decodeDCFirst(component, blockOffset) {
  5546. var t = decodeHuffman(component.huffmanTableDC);
  5547. var diff = t === 0 ? 0 : receiveAndExtend(t) << successive;
  5548. component.blockData[blockOffset] = component.pred += diff;
  5549. }
  5550. function decodeDCSuccessive(component, blockOffset) {
  5551. component.blockData[blockOffset] |= readBit() << successive;
  5552. }
  5553. var eobrun = 0;
  5554. function decodeACFirst(component, blockOffset) {
  5555. if (eobrun > 0) {
  5556. eobrun--;
  5557. return;
  5558. }
  5559. var k = spectralStart;
  5560. var e = spectralEnd;
  5561. while (k <= e) {
  5562. var rs = decodeHuffman(component.huffmanTableAC);
  5563. var s = rs & 15,
  5564. r = rs >> 4;
  5565. if (s === 0) {
  5566. if (r < 15) {
  5567. eobrun = receive(r) + (1 << r) - 1;
  5568. break;
  5569. }
  5570. k += 16;
  5571. continue;
  5572. }
  5573. k += r;
  5574. var z = dctZigZag[k];
  5575. component.blockData[blockOffset + z] = receiveAndExtend(s) * (1 << successive);
  5576. k++;
  5577. }
  5578. }
  5579. var successiveACState = 0,
  5580. successiveACNextValue;
  5581. function decodeACSuccessive(component, blockOffset) {
  5582. var k = spectralStart;
  5583. var e = spectralEnd;
  5584. var r = 0;
  5585. var s;
  5586. var rs;
  5587. while (k <= e) {
  5588. var offsetZ = blockOffset + dctZigZag[k];
  5589. var sign = component.blockData[offsetZ] < 0 ? -1 : 1;
  5590. switch (successiveACState) {
  5591. case 0:
  5592. rs = decodeHuffman(component.huffmanTableAC);
  5593. s = rs & 15;
  5594. r = rs >> 4;
  5595. if (s === 0) {
  5596. if (r < 15) {
  5597. eobrun = receive(r) + (1 << r);
  5598. successiveACState = 4;
  5599. } else {
  5600. r = 16;
  5601. successiveACState = 1;
  5602. }
  5603. } else {
  5604. if (s !== 1) {
  5605. throw new JpegError("invalid ACn encoding");
  5606. }
  5607. successiveACNextValue = receiveAndExtend(s);
  5608. successiveACState = r ? 2 : 3;
  5609. }
  5610. continue;
  5611. case 1:
  5612. case 2:
  5613. if (component.blockData[offsetZ]) {
  5614. component.blockData[offsetZ] += sign * (readBit() << successive);
  5615. } else {
  5616. r--;
  5617. if (r === 0) {
  5618. successiveACState = successiveACState === 2 ? 3 : 0;
  5619. }
  5620. }
  5621. break;
  5622. case 3:
  5623. if (component.blockData[offsetZ]) {
  5624. component.blockData[offsetZ] += sign * (readBit() << successive);
  5625. } else {
  5626. component.blockData[offsetZ] = successiveACNextValue << successive;
  5627. successiveACState = 0;
  5628. }
  5629. break;
  5630. case 4:
  5631. if (component.blockData[offsetZ]) {
  5632. component.blockData[offsetZ] += sign * (readBit() << successive);
  5633. }
  5634. break;
  5635. }
  5636. k++;
  5637. }
  5638. if (successiveACState === 4) {
  5639. eobrun--;
  5640. if (eobrun === 0) {
  5641. successiveACState = 0;
  5642. }
  5643. }
  5644. }
  5645. var blockRow = 0;
  5646. function decodeMcu(component, decode, mcu, row, col) {
  5647. var mcuRow = mcu / mcusPerLine | 0;
  5648. var mcuCol = mcu % mcusPerLine;
  5649. blockRow = mcuRow * component.v + row;
  5650. var blockCol = mcuCol * component.h + col;
  5651. var blockOffset = getBlockBufferOffset(component, blockRow, blockCol);
  5652. decode(component, blockOffset);
  5653. }
  5654. function decodeBlock(component, decode, mcu) {
  5655. blockRow = mcu / component.blocksPerLine | 0;
  5656. var blockCol = mcu % component.blocksPerLine;
  5657. var blockOffset = getBlockBufferOffset(component, blockRow, blockCol);
  5658. decode(component, blockOffset);
  5659. }
  5660. var componentsLength = components.length;
  5661. var component, i, j, k, n;
  5662. var decodeFn;
  5663. if (progressive) {
  5664. if (spectralStart === 0) {
  5665. decodeFn = successivePrev === 0 ? decodeDCFirst : decodeDCSuccessive;
  5666. } else {
  5667. decodeFn = successivePrev === 0 ? decodeACFirst : decodeACSuccessive;
  5668. }
  5669. } else {
  5670. decodeFn = decodeBaseline;
  5671. }
  5672. var mcu = 0,
  5673. fileMarker;
  5674. var mcuExpected;
  5675. if (componentsLength === 1) {
  5676. mcuExpected = components[0].blocksPerLine * components[0].blocksPerColumn;
  5677. } else {
  5678. mcuExpected = mcusPerLine * frame.mcusPerColumn;
  5679. }
  5680. var h, v;
  5681. while (mcu <= mcuExpected) {
  5682. var mcuToRead = resetInterval ? Math.min(mcuExpected - mcu, resetInterval) : mcuExpected;
  5683. if (mcuToRead > 0) {
  5684. for (i = 0; i < componentsLength; i++) {
  5685. components[i].pred = 0;
  5686. }
  5687. eobrun = 0;
  5688. if (componentsLength === 1) {
  5689. component = components[0];
  5690. for (n = 0; n < mcuToRead; n++) {
  5691. decodeBlock(component, decodeFn, mcu);
  5692. mcu++;
  5693. }
  5694. } else {
  5695. for (n = 0; n < mcuToRead; n++) {
  5696. for (i = 0; i < componentsLength; i++) {
  5697. component = components[i];
  5698. h = component.h;
  5699. v = component.v;
  5700. for (j = 0; j < v; j++) {
  5701. for (k = 0; k < h; k++) {
  5702. decodeMcu(component, decodeFn, mcu, j, k);
  5703. }
  5704. }
  5705. }
  5706. mcu++;
  5707. }
  5708. }
  5709. }
  5710. bitsCount = 0;
  5711. fileMarker = findNextFileMarker(data, offset);
  5712. if (!fileMarker) {
  5713. break;
  5714. }
  5715. if (fileMarker.invalid) {
  5716. var partialMsg = mcuToRead > 0 ? "unexpected" : "excessive";
  5717. (0, _util.warn)("decodeScan - ".concat(partialMsg, " MCU data, current marker is: ").concat(fileMarker.invalid));
  5718. offset = fileMarker.offset;
  5719. }
  5720. if (fileMarker.marker >= 0xffd0 && fileMarker.marker <= 0xffd7) {
  5721. offset += 2;
  5722. } else {
  5723. break;
  5724. }
  5725. }
  5726. return offset - startOffset;
  5727. }
  5728. function quantizeAndInverse(component, blockBufferOffset, p) {
  5729. var qt = component.quantizationTable,
  5730. blockData = component.blockData;
  5731. var v0, v1, v2, v3, v4, v5, v6, v7;
  5732. var p0, p1, p2, p3, p4, p5, p6, p7;
  5733. var t;
  5734. if (!qt) {
  5735. throw new JpegError("missing required Quantization Table.");
  5736. }
  5737. for (var row = 0; row < 64; row += 8) {
  5738. p0 = blockData[blockBufferOffset + row];
  5739. p1 = blockData[blockBufferOffset + row + 1];
  5740. p2 = blockData[blockBufferOffset + row + 2];
  5741. p3 = blockData[blockBufferOffset + row + 3];
  5742. p4 = blockData[blockBufferOffset + row + 4];
  5743. p5 = blockData[blockBufferOffset + row + 5];
  5744. p6 = blockData[blockBufferOffset + row + 6];
  5745. p7 = blockData[blockBufferOffset + row + 7];
  5746. p0 *= qt[row];
  5747. if ((p1 | p2 | p3 | p4 | p5 | p6 | p7) === 0) {
  5748. t = dctSqrt2 * p0 + 512 >> 10;
  5749. p[row] = t;
  5750. p[row + 1] = t;
  5751. p[row + 2] = t;
  5752. p[row + 3] = t;
  5753. p[row + 4] = t;
  5754. p[row + 5] = t;
  5755. p[row + 6] = t;
  5756. p[row + 7] = t;
  5757. continue;
  5758. }
  5759. p1 *= qt[row + 1];
  5760. p2 *= qt[row + 2];
  5761. p3 *= qt[row + 3];
  5762. p4 *= qt[row + 4];
  5763. p5 *= qt[row + 5];
  5764. p6 *= qt[row + 6];
  5765. p7 *= qt[row + 7];
  5766. v0 = dctSqrt2 * p0 + 128 >> 8;
  5767. v1 = dctSqrt2 * p4 + 128 >> 8;
  5768. v2 = p2;
  5769. v3 = p6;
  5770. v4 = dctSqrt1d2 * (p1 - p7) + 128 >> 8;
  5771. v7 = dctSqrt1d2 * (p1 + p7) + 128 >> 8;
  5772. v5 = p3 << 4;
  5773. v6 = p5 << 4;
  5774. v0 = v0 + v1 + 1 >> 1;
  5775. v1 = v0 - v1;
  5776. t = v2 * dctSin6 + v3 * dctCos6 + 128 >> 8;
  5777. v2 = v2 * dctCos6 - v3 * dctSin6 + 128 >> 8;
  5778. v3 = t;
  5779. v4 = v4 + v6 + 1 >> 1;
  5780. v6 = v4 - v6;
  5781. v7 = v7 + v5 + 1 >> 1;
  5782. v5 = v7 - v5;
  5783. v0 = v0 + v3 + 1 >> 1;
  5784. v3 = v0 - v3;
  5785. v1 = v1 + v2 + 1 >> 1;
  5786. v2 = v1 - v2;
  5787. t = v4 * dctSin3 + v7 * dctCos3 + 2048 >> 12;
  5788. v4 = v4 * dctCos3 - v7 * dctSin3 + 2048 >> 12;
  5789. v7 = t;
  5790. t = v5 * dctSin1 + v6 * dctCos1 + 2048 >> 12;
  5791. v5 = v5 * dctCos1 - v6 * dctSin1 + 2048 >> 12;
  5792. v6 = t;
  5793. p[row] = v0 + v7;
  5794. p[row + 7] = v0 - v7;
  5795. p[row + 1] = v1 + v6;
  5796. p[row + 6] = v1 - v6;
  5797. p[row + 2] = v2 + v5;
  5798. p[row + 5] = v2 - v5;
  5799. p[row + 3] = v3 + v4;
  5800. p[row + 4] = v3 - v4;
  5801. }
  5802. for (var col = 0; col < 8; ++col) {
  5803. p0 = p[col];
  5804. p1 = p[col + 8];
  5805. p2 = p[col + 16];
  5806. p3 = p[col + 24];
  5807. p4 = p[col + 32];
  5808. p5 = p[col + 40];
  5809. p6 = p[col + 48];
  5810. p7 = p[col + 56];
  5811. if ((p1 | p2 | p3 | p4 | p5 | p6 | p7) === 0) {
  5812. t = dctSqrt2 * p0 + 8192 >> 14;
  5813. if (t < -2040) {
  5814. t = 0;
  5815. } else if (t >= 2024) {
  5816. t = 255;
  5817. } else {
  5818. t = t + 2056 >> 4;
  5819. }
  5820. blockData[blockBufferOffset + col] = t;
  5821. blockData[blockBufferOffset + col + 8] = t;
  5822. blockData[blockBufferOffset + col + 16] = t;
  5823. blockData[blockBufferOffset + col + 24] = t;
  5824. blockData[blockBufferOffset + col + 32] = t;
  5825. blockData[blockBufferOffset + col + 40] = t;
  5826. blockData[blockBufferOffset + col + 48] = t;
  5827. blockData[blockBufferOffset + col + 56] = t;
  5828. continue;
  5829. }
  5830. v0 = dctSqrt2 * p0 + 2048 >> 12;
  5831. v1 = dctSqrt2 * p4 + 2048 >> 12;
  5832. v2 = p2;
  5833. v3 = p6;
  5834. v4 = dctSqrt1d2 * (p1 - p7) + 2048 >> 12;
  5835. v7 = dctSqrt1d2 * (p1 + p7) + 2048 >> 12;
  5836. v5 = p3;
  5837. v6 = p5;
  5838. v0 = (v0 + v1 + 1 >> 1) + 4112;
  5839. v1 = v0 - v1;
  5840. t = v2 * dctSin6 + v3 * dctCos6 + 2048 >> 12;
  5841. v2 = v2 * dctCos6 - v3 * dctSin6 + 2048 >> 12;
  5842. v3 = t;
  5843. v4 = v4 + v6 + 1 >> 1;
  5844. v6 = v4 - v6;
  5845. v7 = v7 + v5 + 1 >> 1;
  5846. v5 = v7 - v5;
  5847. v0 = v0 + v3 + 1 >> 1;
  5848. v3 = v0 - v3;
  5849. v1 = v1 + v2 + 1 >> 1;
  5850. v2 = v1 - v2;
  5851. t = v4 * dctSin3 + v7 * dctCos3 + 2048 >> 12;
  5852. v4 = v4 * dctCos3 - v7 * dctSin3 + 2048 >> 12;
  5853. v7 = t;
  5854. t = v5 * dctSin1 + v6 * dctCos1 + 2048 >> 12;
  5855. v5 = v5 * dctCos1 - v6 * dctSin1 + 2048 >> 12;
  5856. v6 = t;
  5857. p0 = v0 + v7;
  5858. p7 = v0 - v7;
  5859. p1 = v1 + v6;
  5860. p6 = v1 - v6;
  5861. p2 = v2 + v5;
  5862. p5 = v2 - v5;
  5863. p3 = v3 + v4;
  5864. p4 = v3 - v4;
  5865. if (p0 < 16) {
  5866. p0 = 0;
  5867. } else if (p0 >= 4080) {
  5868. p0 = 255;
  5869. } else {
  5870. p0 >>= 4;
  5871. }
  5872. if (p1 < 16) {
  5873. p1 = 0;
  5874. } else if (p1 >= 4080) {
  5875. p1 = 255;
  5876. } else {
  5877. p1 >>= 4;
  5878. }
  5879. if (p2 < 16) {
  5880. p2 = 0;
  5881. } else if (p2 >= 4080) {
  5882. p2 = 255;
  5883. } else {
  5884. p2 >>= 4;
  5885. }
  5886. if (p3 < 16) {
  5887. p3 = 0;
  5888. } else if (p3 >= 4080) {
  5889. p3 = 255;
  5890. } else {
  5891. p3 >>= 4;
  5892. }
  5893. if (p4 < 16) {
  5894. p4 = 0;
  5895. } else if (p4 >= 4080) {
  5896. p4 = 255;
  5897. } else {
  5898. p4 >>= 4;
  5899. }
  5900. if (p5 < 16) {
  5901. p5 = 0;
  5902. } else if (p5 >= 4080) {
  5903. p5 = 255;
  5904. } else {
  5905. p5 >>= 4;
  5906. }
  5907. if (p6 < 16) {
  5908. p6 = 0;
  5909. } else if (p6 >= 4080) {
  5910. p6 = 255;
  5911. } else {
  5912. p6 >>= 4;
  5913. }
  5914. if (p7 < 16) {
  5915. p7 = 0;
  5916. } else if (p7 >= 4080) {
  5917. p7 = 255;
  5918. } else {
  5919. p7 >>= 4;
  5920. }
  5921. blockData[blockBufferOffset + col] = p0;
  5922. blockData[blockBufferOffset + col + 8] = p1;
  5923. blockData[blockBufferOffset + col + 16] = p2;
  5924. blockData[blockBufferOffset + col + 24] = p3;
  5925. blockData[blockBufferOffset + col + 32] = p4;
  5926. blockData[blockBufferOffset + col + 40] = p5;
  5927. blockData[blockBufferOffset + col + 48] = p6;
  5928. blockData[blockBufferOffset + col + 56] = p7;
  5929. }
  5930. }
  5931. function buildComponentData(frame, component) {
  5932. var blocksPerLine = component.blocksPerLine;
  5933. var blocksPerColumn = component.blocksPerColumn;
  5934. var computationBuffer = new Int16Array(64);
  5935. for (var blockRow = 0; blockRow < blocksPerColumn; blockRow++) {
  5936. for (var blockCol = 0; blockCol < blocksPerLine; blockCol++) {
  5937. var offset = getBlockBufferOffset(component, blockRow, blockCol);
  5938. quantizeAndInverse(component, offset, computationBuffer);
  5939. }
  5940. }
  5941. return component.blockData;
  5942. }
  5943. function findNextFileMarker(data, currentPos) {
  5944. var startPos = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : currentPos;
  5945. var maxPos = data.length - 1;
  5946. var newPos = startPos < currentPos ? startPos : currentPos;
  5947. if (currentPos >= maxPos) {
  5948. return null;
  5949. }
  5950. var currentMarker = (0, _core_utils.readUint16)(data, currentPos);
  5951. if (currentMarker >= 0xffc0 && currentMarker <= 0xfffe) {
  5952. return {
  5953. invalid: null,
  5954. marker: currentMarker,
  5955. offset: currentPos
  5956. };
  5957. }
  5958. var newMarker = (0, _core_utils.readUint16)(data, newPos);
  5959. while (!(newMarker >= 0xffc0 && newMarker <= 0xfffe)) {
  5960. if (++newPos >= maxPos) {
  5961. return null;
  5962. }
  5963. newMarker = (0, _core_utils.readUint16)(data, newPos);
  5964. }
  5965. return {
  5966. invalid: currentMarker.toString(16),
  5967. marker: newMarker,
  5968. offset: newPos
  5969. };
  5970. }
  5971. var JpegImage = /*#__PURE__*/function () {
  5972. function JpegImage() {
  5973. var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
  5974. _ref$decodeTransform = _ref.decodeTransform,
  5975. decodeTransform = _ref$decodeTransform === void 0 ? null : _ref$decodeTransform,
  5976. _ref$colorTransform = _ref.colorTransform,
  5977. colorTransform = _ref$colorTransform === void 0 ? -1 : _ref$colorTransform;
  5978. _classCallCheck(this, JpegImage);
  5979. this._decodeTransform = decodeTransform;
  5980. this._colorTransform = colorTransform;
  5981. }
  5982. _createClass(JpegImage, [{
  5983. key: "parse",
  5984. value: function parse(data) {
  5985. var _ref2 = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
  5986. _ref2$dnlScanLines = _ref2.dnlScanLines,
  5987. dnlScanLines = _ref2$dnlScanLines === void 0 ? null : _ref2$dnlScanLines;
  5988. function readDataBlock() {
  5989. var length = (0, _core_utils.readUint16)(data, offset);
  5990. offset += 2;
  5991. var endOffset = offset + length - 2;
  5992. var fileMarker = findNextFileMarker(data, endOffset, offset);
  5993. if (fileMarker && fileMarker.invalid) {
  5994. (0, _util.warn)("readDataBlock - incorrect length, current marker is: " + fileMarker.invalid);
  5995. endOffset = fileMarker.offset;
  5996. }
  5997. var array = data.subarray(offset, endOffset);
  5998. offset += array.length;
  5999. return array;
  6000. }
  6001. function prepareComponents(frame) {
  6002. var mcusPerLine = Math.ceil(frame.samplesPerLine / 8 / frame.maxH);
  6003. var mcusPerColumn = Math.ceil(frame.scanLines / 8 / frame.maxV);
  6004. for (var i = 0, ii = frame.components.length; i < ii; i++) {
  6005. var component = frame.components[i];
  6006. var blocksPerLine = Math.ceil(Math.ceil(frame.samplesPerLine / 8) * component.h / frame.maxH);
  6007. var blocksPerColumn = Math.ceil(Math.ceil(frame.scanLines / 8) * component.v / frame.maxV);
  6008. var blocksPerLineForMcu = mcusPerLine * component.h;
  6009. var blocksPerColumnForMcu = mcusPerColumn * component.v;
  6010. var blocksBufferSize = 64 * blocksPerColumnForMcu * (blocksPerLineForMcu + 1);
  6011. component.blockData = new Int16Array(blocksBufferSize);
  6012. component.blocksPerLine = blocksPerLine;
  6013. component.blocksPerColumn = blocksPerColumn;
  6014. }
  6015. frame.mcusPerLine = mcusPerLine;
  6016. frame.mcusPerColumn = mcusPerColumn;
  6017. }
  6018. var offset = 0;
  6019. var jfif = null;
  6020. var adobe = null;
  6021. var frame, resetInterval;
  6022. var numSOSMarkers = 0;
  6023. var quantizationTables = [];
  6024. var huffmanTablesAC = [],
  6025. huffmanTablesDC = [];
  6026. var fileMarker = (0, _core_utils.readUint16)(data, offset);
  6027. offset += 2;
  6028. if (fileMarker !== 0xffd8) {
  6029. throw new JpegError("SOI not found");
  6030. }
  6031. fileMarker = (0, _core_utils.readUint16)(data, offset);
  6032. offset += 2;
  6033. markerLoop: while (fileMarker !== 0xffd9) {
  6034. var i = void 0,
  6035. j = void 0,
  6036. l = void 0;
  6037. switch (fileMarker) {
  6038. case 0xffe0:
  6039. case 0xffe1:
  6040. case 0xffe2:
  6041. case 0xffe3:
  6042. case 0xffe4:
  6043. case 0xffe5:
  6044. case 0xffe6:
  6045. case 0xffe7:
  6046. case 0xffe8:
  6047. case 0xffe9:
  6048. case 0xffea:
  6049. case 0xffeb:
  6050. case 0xffec:
  6051. case 0xffed:
  6052. case 0xffee:
  6053. case 0xffef:
  6054. case 0xfffe:
  6055. var appData = readDataBlock();
  6056. if (fileMarker === 0xffe0) {
  6057. if (appData[0] === 0x4a && appData[1] === 0x46 && appData[2] === 0x49 && appData[3] === 0x46 && appData[4] === 0) {
  6058. jfif = {
  6059. version: {
  6060. major: appData[5],
  6061. minor: appData[6]
  6062. },
  6063. densityUnits: appData[7],
  6064. xDensity: appData[8] << 8 | appData[9],
  6065. yDensity: appData[10] << 8 | appData[11],
  6066. thumbWidth: appData[12],
  6067. thumbHeight: appData[13],
  6068. thumbData: appData.subarray(14, 14 + 3 * appData[12] * appData[13])
  6069. };
  6070. }
  6071. }
  6072. if (fileMarker === 0xffee) {
  6073. if (appData[0] === 0x41 && appData[1] === 0x64 && appData[2] === 0x6f && appData[3] === 0x62 && appData[4] === 0x65) {
  6074. adobe = {
  6075. version: appData[5] << 8 | appData[6],
  6076. flags0: appData[7] << 8 | appData[8],
  6077. flags1: appData[9] << 8 | appData[10],
  6078. transformCode: appData[11]
  6079. };
  6080. }
  6081. }
  6082. break;
  6083. case 0xffdb:
  6084. var quantizationTablesLength = (0, _core_utils.readUint16)(data, offset);
  6085. offset += 2;
  6086. var quantizationTablesEnd = quantizationTablesLength + offset - 2;
  6087. var z = void 0;
  6088. while (offset < quantizationTablesEnd) {
  6089. var quantizationTableSpec = data[offset++];
  6090. var tableData = new Uint16Array(64);
  6091. if (quantizationTableSpec >> 4 === 0) {
  6092. for (j = 0; j < 64; j++) {
  6093. z = dctZigZag[j];
  6094. tableData[z] = data[offset++];
  6095. }
  6096. } else if (quantizationTableSpec >> 4 === 1) {
  6097. for (j = 0; j < 64; j++) {
  6098. z = dctZigZag[j];
  6099. tableData[z] = (0, _core_utils.readUint16)(data, offset);
  6100. offset += 2;
  6101. }
  6102. } else {
  6103. throw new JpegError("DQT - invalid table spec");
  6104. }
  6105. quantizationTables[quantizationTableSpec & 15] = tableData;
  6106. }
  6107. break;
  6108. case 0xffc0:
  6109. case 0xffc1:
  6110. case 0xffc2:
  6111. if (frame) {
  6112. throw new JpegError("Only single frame JPEGs supported");
  6113. }
  6114. offset += 2;
  6115. frame = {};
  6116. frame.extended = fileMarker === 0xffc1;
  6117. frame.progressive = fileMarker === 0xffc2;
  6118. frame.precision = data[offset++];
  6119. var sofScanLines = (0, _core_utils.readUint16)(data, offset);
  6120. offset += 2;
  6121. frame.scanLines = dnlScanLines || sofScanLines;
  6122. frame.samplesPerLine = (0, _core_utils.readUint16)(data, offset);
  6123. offset += 2;
  6124. frame.components = [];
  6125. frame.componentIds = {};
  6126. var componentsCount = data[offset++];
  6127. var maxH = 0,
  6128. maxV = 0;
  6129. for (i = 0; i < componentsCount; i++) {
  6130. var componentId = data[offset];
  6131. var h = data[offset + 1] >> 4;
  6132. var v = data[offset + 1] & 15;
  6133. if (maxH < h) {
  6134. maxH = h;
  6135. }
  6136. if (maxV < v) {
  6137. maxV = v;
  6138. }
  6139. var qId = data[offset + 2];
  6140. l = frame.components.push({
  6141. h: h,
  6142. v: v,
  6143. quantizationId: qId,
  6144. quantizationTable: null
  6145. });
  6146. frame.componentIds[componentId] = l - 1;
  6147. offset += 3;
  6148. }
  6149. frame.maxH = maxH;
  6150. frame.maxV = maxV;
  6151. prepareComponents(frame);
  6152. break;
  6153. case 0xffc4:
  6154. var huffmanLength = (0, _core_utils.readUint16)(data, offset);
  6155. offset += 2;
  6156. for (i = 2; i < huffmanLength;) {
  6157. var huffmanTableSpec = data[offset++];
  6158. var codeLengths = new Uint8Array(16);
  6159. var codeLengthSum = 0;
  6160. for (j = 0; j < 16; j++, offset++) {
  6161. codeLengthSum += codeLengths[j] = data[offset];
  6162. }
  6163. var huffmanValues = new Uint8Array(codeLengthSum);
  6164. for (j = 0; j < codeLengthSum; j++, offset++) {
  6165. huffmanValues[j] = data[offset];
  6166. }
  6167. i += 17 + codeLengthSum;
  6168. (huffmanTableSpec >> 4 === 0 ? huffmanTablesDC : huffmanTablesAC)[huffmanTableSpec & 15] = buildHuffmanTable(codeLengths, huffmanValues);
  6169. }
  6170. break;
  6171. case 0xffdd:
  6172. offset += 2;
  6173. resetInterval = (0, _core_utils.readUint16)(data, offset);
  6174. offset += 2;
  6175. break;
  6176. case 0xffda:
  6177. var parseDNLMarker = ++numSOSMarkers === 1 && !dnlScanLines;
  6178. offset += 2;
  6179. var selectorsCount = data[offset++],
  6180. components = [];
  6181. for (i = 0; i < selectorsCount; i++) {
  6182. var index = data[offset++];
  6183. var componentIndex = frame.componentIds[index];
  6184. var component = frame.components[componentIndex];
  6185. component.index = index;
  6186. var tableSpec = data[offset++];
  6187. component.huffmanTableDC = huffmanTablesDC[tableSpec >> 4];
  6188. component.huffmanTableAC = huffmanTablesAC[tableSpec & 15];
  6189. components.push(component);
  6190. }
  6191. var spectralStart = data[offset++],
  6192. spectralEnd = data[offset++],
  6193. successiveApproximation = data[offset++];
  6194. try {
  6195. var processed = decodeScan(data, offset, frame, components, resetInterval, spectralStart, spectralEnd, successiveApproximation >> 4, successiveApproximation & 15, parseDNLMarker);
  6196. offset += processed;
  6197. } catch (ex) {
  6198. if (ex instanceof DNLMarkerError) {
  6199. (0, _util.warn)("".concat(ex.message, " -- attempting to re-parse the JPEG image."));
  6200. return this.parse(data, {
  6201. dnlScanLines: ex.scanLines
  6202. });
  6203. } else if (ex instanceof EOIMarkerError) {
  6204. (0, _util.warn)("".concat(ex.message, " -- ignoring the rest of the image data."));
  6205. break markerLoop;
  6206. }
  6207. throw ex;
  6208. }
  6209. break;
  6210. case 0xffdc:
  6211. offset += 4;
  6212. break;
  6213. case 0xffff:
  6214. if (data[offset] !== 0xff) {
  6215. offset--;
  6216. }
  6217. break;
  6218. default:
  6219. var nextFileMarker = findNextFileMarker(data, offset - 2, offset - 3);
  6220. if (nextFileMarker && nextFileMarker.invalid) {
  6221. (0, _util.warn)("JpegImage.parse - unexpected data, current marker is: " + nextFileMarker.invalid);
  6222. offset = nextFileMarker.offset;
  6223. break;
  6224. }
  6225. if (!nextFileMarker || offset >= data.length - 1) {
  6226. (0, _util.warn)("JpegImage.parse - reached the end of the image data " + "without finding an EOI marker (0xFFD9).");
  6227. break markerLoop;
  6228. }
  6229. throw new JpegError("JpegImage.parse - unknown marker: " + fileMarker.toString(16));
  6230. }
  6231. fileMarker = (0, _core_utils.readUint16)(data, offset);
  6232. offset += 2;
  6233. }
  6234. this.width = frame.samplesPerLine;
  6235. this.height = frame.scanLines;
  6236. this.jfif = jfif;
  6237. this.adobe = adobe;
  6238. this.components = [];
  6239. for (var _i = 0, ii = frame.components.length; _i < ii; _i++) {
  6240. var _component = frame.components[_i];
  6241. var quantizationTable = quantizationTables[_component.quantizationId];
  6242. if (quantizationTable) {
  6243. _component.quantizationTable = quantizationTable;
  6244. }
  6245. this.components.push({
  6246. index: _component.index,
  6247. output: buildComponentData(frame, _component),
  6248. scaleX: _component.h / frame.maxH,
  6249. scaleY: _component.v / frame.maxV,
  6250. blocksPerLine: _component.blocksPerLine,
  6251. blocksPerColumn: _component.blocksPerColumn
  6252. });
  6253. }
  6254. this.numComponents = this.components.length;
  6255. return undefined;
  6256. }
  6257. }, {
  6258. key: "_getLinearizedBlockData",
  6259. value: function _getLinearizedBlockData(width, height) {
  6260. var isSourcePDF = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
  6261. var scaleX = this.width / width,
  6262. scaleY = this.height / height;
  6263. var component, componentScaleX, componentScaleY, blocksPerScanline;
  6264. var x, y, i, j, k;
  6265. var index;
  6266. var offset = 0;
  6267. var output;
  6268. var numComponents = this.components.length;
  6269. var dataLength = width * height * numComponents;
  6270. var data = new Uint8ClampedArray(dataLength);
  6271. var xScaleBlockOffset = new Uint32Array(width);
  6272. var mask3LSB = 0xfffffff8;
  6273. var lastComponentScaleX;
  6274. for (i = 0; i < numComponents; i++) {
  6275. component = this.components[i];
  6276. componentScaleX = component.scaleX * scaleX;
  6277. componentScaleY = component.scaleY * scaleY;
  6278. offset = i;
  6279. output = component.output;
  6280. blocksPerScanline = component.blocksPerLine + 1 << 3;
  6281. if (componentScaleX !== lastComponentScaleX) {
  6282. for (x = 0; x < width; x++) {
  6283. j = 0 | x * componentScaleX;
  6284. xScaleBlockOffset[x] = (j & mask3LSB) << 3 | j & 7;
  6285. }
  6286. lastComponentScaleX = componentScaleX;
  6287. }
  6288. for (y = 0; y < height; y++) {
  6289. j = 0 | y * componentScaleY;
  6290. index = blocksPerScanline * (j & mask3LSB) | (j & 7) << 3;
  6291. for (x = 0; x < width; x++) {
  6292. data[offset] = output[index + xScaleBlockOffset[x]];
  6293. offset += numComponents;
  6294. }
  6295. }
  6296. }
  6297. var transform = this._decodeTransform;
  6298. if (!isSourcePDF && numComponents === 4 && !transform) {
  6299. transform = new Int32Array([-256, 255, -256, 255, -256, 255, -256, 255]);
  6300. }
  6301. if (transform) {
  6302. for (i = 0; i < dataLength;) {
  6303. for (j = 0, k = 0; j < numComponents; j++, i++, k += 2) {
  6304. data[i] = (data[i] * transform[k] >> 8) + transform[k + 1];
  6305. }
  6306. }
  6307. }
  6308. return data;
  6309. }
  6310. }, {
  6311. key: "_isColorConversionNeeded",
  6312. get: function get() {
  6313. if (this.adobe) {
  6314. return !!this.adobe.transformCode;
  6315. }
  6316. if (this.numComponents === 3) {
  6317. if (this._colorTransform === 0) {
  6318. return false;
  6319. } else if (this.components[0].index === 0x52 && this.components[1].index === 0x47 && this.components[2].index === 0x42) {
  6320. return false;
  6321. }
  6322. return true;
  6323. }
  6324. if (this._colorTransform === 1) {
  6325. return true;
  6326. }
  6327. return false;
  6328. }
  6329. }, {
  6330. key: "_convertYccToRgb",
  6331. value: function _convertYccToRgb(data) {
  6332. var Y, Cb, Cr;
  6333. for (var i = 0, length = data.length; i < length; i += 3) {
  6334. Y = data[i];
  6335. Cb = data[i + 1];
  6336. Cr = data[i + 2];
  6337. data[i] = Y - 179.456 + 1.402 * Cr;
  6338. data[i + 1] = Y + 135.459 - 0.344 * Cb - 0.714 * Cr;
  6339. data[i + 2] = Y - 226.816 + 1.772 * Cb;
  6340. }
  6341. return data;
  6342. }
  6343. }, {
  6344. key: "_convertYcckToRgb",
  6345. value: function _convertYcckToRgb(data) {
  6346. var Y, Cb, Cr, k;
  6347. var offset = 0;
  6348. for (var i = 0, length = data.length; i < length; i += 4) {
  6349. Y = data[i];
  6350. Cb = data[i + 1];
  6351. Cr = data[i + 2];
  6352. k = data[i + 3];
  6353. data[offset++] = -122.67195406894 + Cb * (-6.60635669420364e-5 * Cb + 0.000437130475926232 * Cr - 5.4080610064599e-5 * Y + 0.00048449797120281 * k - 0.154362151871126) + Cr * (-0.000957964378445773 * Cr + 0.000817076911346625 * Y - 0.00477271405408747 * k + 1.53380253221734) + Y * (0.000961250184130688 * Y - 0.00266257332283933 * k + 0.48357088451265) + k * (-0.000336197177618394 * k + 0.484791561490776);
  6354. data[offset++] = 107.268039397724 + Cb * (2.19927104525741e-5 * Cb - 0.000640992018297945 * Cr + 0.000659397001245577 * Y + 0.000426105652938837 * k - 0.176491792462875) + Cr * (-0.000778269941513683 * Cr + 0.00130872261408275 * Y + 0.000770482631801132 * k - 0.151051492775562) + Y * (0.00126935368114843 * Y - 0.00265090189010898 * k + 0.25802910206845) + k * (-0.000318913117588328 * k - 0.213742400323665);
  6355. data[offset++] = -20.810012546947 + Cb * (-0.000570115196973677 * Cb - 2.63409051004589e-5 * Cr + 0.0020741088115012 * Y - 0.00288260236853442 * k + 0.814272968359295) + Cr * (-1.53496057440975e-5 * Cr - 0.000132689043961446 * Y + 0.000560833691242812 * k - 0.195152027534049) + Y * (0.00174418132927582 * Y - 0.00255243321439347 * k + 0.116935020465145) + k * (-0.000343531996510555 * k + 0.24165260232407);
  6356. }
  6357. return data.subarray(0, offset);
  6358. }
  6359. }, {
  6360. key: "_convertYcckToCmyk",
  6361. value: function _convertYcckToCmyk(data) {
  6362. var Y, Cb, Cr;
  6363. for (var i = 0, length = data.length; i < length; i += 4) {
  6364. Y = data[i];
  6365. Cb = data[i + 1];
  6366. Cr = data[i + 2];
  6367. data[i] = 434.456 - Y - 1.402 * Cr;
  6368. data[i + 1] = 119.541 - Y + 0.344 * Cb + 0.714 * Cr;
  6369. data[i + 2] = 481.816 - Y - 1.772 * Cb;
  6370. }
  6371. return data;
  6372. }
  6373. }, {
  6374. key: "_convertCmykToRgb",
  6375. value: function _convertCmykToRgb(data) {
  6376. var c, m, y, k;
  6377. var offset = 0;
  6378. for (var i = 0, length = data.length; i < length; i += 4) {
  6379. c = data[i];
  6380. m = data[i + 1];
  6381. y = data[i + 2];
  6382. k = data[i + 3];
  6383. data[offset++] = 255 + c * (-0.00006747147073602441 * c + 0.0008379262121013727 * m + 0.0002894718188643294 * y + 0.003264231057537806 * k - 1.1185611867203937) + m * (0.000026374107616089405 * m - 0.00008626949158638572 * y - 0.0002748769067499491 * k - 0.02155688794978967) + y * (-0.00003878099212869363 * y - 0.0003267808279485286 * k + 0.0686742238595345) - k * (0.0003361971776183937 * k + 0.7430659151342254);
  6384. data[offset++] = 255 + c * (0.00013596372813588848 * c + 0.000924537132573585 * m + 0.00010567359618683593 * y + 0.0004791864687436512 * k - 0.3109689587515875) + m * (-0.00023545346108370344 * m + 0.0002702845253534714 * y + 0.0020200308977307156 * k - 0.7488052167015494) + y * (0.00006834815998235662 * y + 0.00015168452363460973 * k - 0.09751927774728933) - k * (0.0003189131175883281 * k + 0.7364883807733168);
  6385. data[offset++] = 255 + c * (0.000013598650411385307 * c + 0.00012423956175490851 * m + 0.0004751985097583589 * y - 0.0000036729317476630422 * k - 0.05562186980264034) + m * (0.00016141380598724676 * m + 0.0009692239130725186 * y + 0.0007782692450036253 * k - 0.44015232367526463) + y * (5.068882914068769e-7 * y + 0.0017778369011375071 * k - 0.7591454649749609) - k * (0.0003435319965105553 * k + 0.7063770186160144);
  6386. }
  6387. return data.subarray(0, offset);
  6388. }
  6389. }, {
  6390. key: "getData",
  6391. value: function getData(_ref3) {
  6392. var width = _ref3.width,
  6393. height = _ref3.height,
  6394. _ref3$forceRGB = _ref3.forceRGB,
  6395. forceRGB = _ref3$forceRGB === void 0 ? false : _ref3$forceRGB,
  6396. _ref3$isSourcePDF = _ref3.isSourcePDF,
  6397. isSourcePDF = _ref3$isSourcePDF === void 0 ? false : _ref3$isSourcePDF;
  6398. if (this.numComponents > 4) {
  6399. throw new JpegError("Unsupported color mode");
  6400. }
  6401. var data = this._getLinearizedBlockData(width, height, isSourcePDF);
  6402. if (this.numComponents === 1 && forceRGB) {
  6403. var dataLength = data.length;
  6404. var rgbData = new Uint8ClampedArray(dataLength * 3);
  6405. var offset = 0;
  6406. for (var i = 0; i < dataLength; i++) {
  6407. var grayColor = data[i];
  6408. rgbData[offset++] = grayColor;
  6409. rgbData[offset++] = grayColor;
  6410. rgbData[offset++] = grayColor;
  6411. }
  6412. return rgbData;
  6413. } else if (this.numComponents === 3 && this._isColorConversionNeeded) {
  6414. return this._convertYccToRgb(data);
  6415. } else if (this.numComponents === 4) {
  6416. if (this._isColorConversionNeeded) {
  6417. if (forceRGB) {
  6418. return this._convertYcckToRgb(data);
  6419. }
  6420. return this._convertYcckToCmyk(data);
  6421. } else if (forceRGB) {
  6422. return this._convertCmykToRgb(data);
  6423. }
  6424. }
  6425. return data;
  6426. }
  6427. }]);
  6428. return JpegImage;
  6429. }();
  6430. exports.JpegImage = JpegImage;
  6431. /***/ }),
  6432. /* 13 */
  6433. /***/ ((__unused_webpack_module, exports, __w_pdfjs_require__) => {
  6434. function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
  6435. Object.defineProperty(exports, "__esModule", ({
  6436. value: true
  6437. }));
  6438. exports.JpxImage = void 0;
  6439. var _util = __w_pdfjs_require__(1);
  6440. var _core_utils = __w_pdfjs_require__(5);
  6441. var _arithmetic_decoder = __w_pdfjs_require__(10);
  6442. function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
  6443. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
  6444. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  6445. function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); }
  6446. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  6447. function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
  6448. function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); }
  6449. function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
  6450. function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
  6451. function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
  6452. var JpxError = /*#__PURE__*/function (_BaseException) {
  6453. _inherits(JpxError, _BaseException);
  6454. var _super = _createSuper(JpxError);
  6455. function JpxError(msg) {
  6456. _classCallCheck(this, JpxError);
  6457. return _super.call(this, "JPX error: ".concat(msg), "JpxError");
  6458. }
  6459. return _createClass(JpxError);
  6460. }(_util.BaseException);
  6461. var SubbandsGainLog2 = {
  6462. LL: 0,
  6463. LH: 1,
  6464. HL: 1,
  6465. HH: 2
  6466. };
  6467. var JpxImage = /*#__PURE__*/function () {
  6468. function JpxImage() {
  6469. _classCallCheck(this, JpxImage);
  6470. this.failOnCorruptedImage = false;
  6471. }
  6472. _createClass(JpxImage, [{
  6473. key: "parse",
  6474. value: function parse(data) {
  6475. var head = (0, _core_utils.readUint16)(data, 0);
  6476. if (head === 0xff4f) {
  6477. this.parseCodestream(data, 0, data.length);
  6478. return;
  6479. }
  6480. var length = data.length;
  6481. var position = 0;
  6482. while (position < length) {
  6483. var headerSize = 8;
  6484. var lbox = (0, _core_utils.readUint32)(data, position);
  6485. var tbox = (0, _core_utils.readUint32)(data, position + 4);
  6486. position += headerSize;
  6487. if (lbox === 1) {
  6488. lbox = (0, _core_utils.readUint32)(data, position) * 4294967296 + (0, _core_utils.readUint32)(data, position + 4);
  6489. position += 8;
  6490. headerSize += 8;
  6491. }
  6492. if (lbox === 0) {
  6493. lbox = length - position + headerSize;
  6494. }
  6495. if (lbox < headerSize) {
  6496. throw new JpxError("Invalid box field size");
  6497. }
  6498. var dataLength = lbox - headerSize;
  6499. var jumpDataLength = true;
  6500. switch (tbox) {
  6501. case 0x6a703268:
  6502. jumpDataLength = false;
  6503. break;
  6504. case 0x636f6c72:
  6505. var method = data[position];
  6506. if (method === 1) {
  6507. var colorspace = (0, _core_utils.readUint32)(data, position + 3);
  6508. switch (colorspace) {
  6509. case 16:
  6510. case 17:
  6511. case 18:
  6512. break;
  6513. default:
  6514. (0, _util.warn)("Unknown colorspace " + colorspace);
  6515. break;
  6516. }
  6517. } else if (method === 2) {
  6518. (0, _util.info)("ICC profile not supported");
  6519. }
  6520. break;
  6521. case 0x6a703263:
  6522. this.parseCodestream(data, position, position + dataLength);
  6523. break;
  6524. case 0x6a502020:
  6525. if ((0, _core_utils.readUint32)(data, position) !== 0x0d0a870a) {
  6526. (0, _util.warn)("Invalid JP2 signature");
  6527. }
  6528. break;
  6529. case 0x6a501a1a:
  6530. case 0x66747970:
  6531. case 0x72726571:
  6532. case 0x72657320:
  6533. case 0x69686472:
  6534. break;
  6535. default:
  6536. var headerType = String.fromCharCode(tbox >> 24 & 0xff, tbox >> 16 & 0xff, tbox >> 8 & 0xff, tbox & 0xff);
  6537. (0, _util.warn)("Unsupported header type ".concat(tbox, " (").concat(headerType, ")."));
  6538. break;
  6539. }
  6540. if (jumpDataLength) {
  6541. position += dataLength;
  6542. }
  6543. }
  6544. }
  6545. }, {
  6546. key: "parseImageProperties",
  6547. value: function parseImageProperties(stream) {
  6548. var newByte = stream.getByte();
  6549. while (newByte >= 0) {
  6550. var oldByte = newByte;
  6551. newByte = stream.getByte();
  6552. var code = oldByte << 8 | newByte;
  6553. if (code === 0xff51) {
  6554. stream.skip(4);
  6555. var Xsiz = stream.getInt32() >>> 0;
  6556. var Ysiz = stream.getInt32() >>> 0;
  6557. var XOsiz = stream.getInt32() >>> 0;
  6558. var YOsiz = stream.getInt32() >>> 0;
  6559. stream.skip(16);
  6560. var Csiz = stream.getUint16();
  6561. this.width = Xsiz - XOsiz;
  6562. this.height = Ysiz - YOsiz;
  6563. this.componentsCount = Csiz;
  6564. this.bitsPerComponent = 8;
  6565. return;
  6566. }
  6567. }
  6568. throw new JpxError("No size marker found in JPX stream");
  6569. }
  6570. }, {
  6571. key: "parseCodestream",
  6572. value: function parseCodestream(data, start, end) {
  6573. var context = {};
  6574. var doNotRecover = false;
  6575. try {
  6576. var position = start;
  6577. while (position + 1 < end) {
  6578. var code = (0, _core_utils.readUint16)(data, position);
  6579. position += 2;
  6580. var length = 0,
  6581. j = void 0,
  6582. sqcd = void 0,
  6583. spqcds = void 0,
  6584. spqcdSize = void 0,
  6585. scalarExpounded = void 0,
  6586. tile = void 0;
  6587. switch (code) {
  6588. case 0xff4f:
  6589. context.mainHeader = true;
  6590. break;
  6591. case 0xffd9:
  6592. break;
  6593. case 0xff51:
  6594. length = (0, _core_utils.readUint16)(data, position);
  6595. var siz = {};
  6596. siz.Xsiz = (0, _core_utils.readUint32)(data, position + 4);
  6597. siz.Ysiz = (0, _core_utils.readUint32)(data, position + 8);
  6598. siz.XOsiz = (0, _core_utils.readUint32)(data, position + 12);
  6599. siz.YOsiz = (0, _core_utils.readUint32)(data, position + 16);
  6600. siz.XTsiz = (0, _core_utils.readUint32)(data, position + 20);
  6601. siz.YTsiz = (0, _core_utils.readUint32)(data, position + 24);
  6602. siz.XTOsiz = (0, _core_utils.readUint32)(data, position + 28);
  6603. siz.YTOsiz = (0, _core_utils.readUint32)(data, position + 32);
  6604. var componentsCount = (0, _core_utils.readUint16)(data, position + 36);
  6605. siz.Csiz = componentsCount;
  6606. var components = [];
  6607. j = position + 38;
  6608. for (var i = 0; i < componentsCount; i++) {
  6609. var component = {
  6610. precision: (data[j] & 0x7f) + 1,
  6611. isSigned: !!(data[j] & 0x80),
  6612. XRsiz: data[j + 1],
  6613. YRsiz: data[j + 2]
  6614. };
  6615. j += 3;
  6616. calculateComponentDimensions(component, siz);
  6617. components.push(component);
  6618. }
  6619. context.SIZ = siz;
  6620. context.components = components;
  6621. calculateTileGrids(context, components);
  6622. context.QCC = [];
  6623. context.COC = [];
  6624. break;
  6625. case 0xff5c:
  6626. length = (0, _core_utils.readUint16)(data, position);
  6627. var qcd = {};
  6628. j = position + 2;
  6629. sqcd = data[j++];
  6630. switch (sqcd & 0x1f) {
  6631. case 0:
  6632. spqcdSize = 8;
  6633. scalarExpounded = true;
  6634. break;
  6635. case 1:
  6636. spqcdSize = 16;
  6637. scalarExpounded = false;
  6638. break;
  6639. case 2:
  6640. spqcdSize = 16;
  6641. scalarExpounded = true;
  6642. break;
  6643. default:
  6644. throw new Error("Invalid SQcd value " + sqcd);
  6645. }
  6646. qcd.noQuantization = spqcdSize === 8;
  6647. qcd.scalarExpounded = scalarExpounded;
  6648. qcd.guardBits = sqcd >> 5;
  6649. spqcds = [];
  6650. while (j < length + position) {
  6651. var spqcd = {};
  6652. if (spqcdSize === 8) {
  6653. spqcd.epsilon = data[j++] >> 3;
  6654. spqcd.mu = 0;
  6655. } else {
  6656. spqcd.epsilon = data[j] >> 3;
  6657. spqcd.mu = (data[j] & 0x7) << 8 | data[j + 1];
  6658. j += 2;
  6659. }
  6660. spqcds.push(spqcd);
  6661. }
  6662. qcd.SPqcds = spqcds;
  6663. if (context.mainHeader) {
  6664. context.QCD = qcd;
  6665. } else {
  6666. context.currentTile.QCD = qcd;
  6667. context.currentTile.QCC = [];
  6668. }
  6669. break;
  6670. case 0xff5d:
  6671. length = (0, _core_utils.readUint16)(data, position);
  6672. var qcc = {};
  6673. j = position + 2;
  6674. var cqcc = void 0;
  6675. if (context.SIZ.Csiz < 257) {
  6676. cqcc = data[j++];
  6677. } else {
  6678. cqcc = (0, _core_utils.readUint16)(data, j);
  6679. j += 2;
  6680. }
  6681. sqcd = data[j++];
  6682. switch (sqcd & 0x1f) {
  6683. case 0:
  6684. spqcdSize = 8;
  6685. scalarExpounded = true;
  6686. break;
  6687. case 1:
  6688. spqcdSize = 16;
  6689. scalarExpounded = false;
  6690. break;
  6691. case 2:
  6692. spqcdSize = 16;
  6693. scalarExpounded = true;
  6694. break;
  6695. default:
  6696. throw new Error("Invalid SQcd value " + sqcd);
  6697. }
  6698. qcc.noQuantization = spqcdSize === 8;
  6699. qcc.scalarExpounded = scalarExpounded;
  6700. qcc.guardBits = sqcd >> 5;
  6701. spqcds = [];
  6702. while (j < length + position) {
  6703. var _spqcd = {};
  6704. if (spqcdSize === 8) {
  6705. _spqcd.epsilon = data[j++] >> 3;
  6706. _spqcd.mu = 0;
  6707. } else {
  6708. _spqcd.epsilon = data[j] >> 3;
  6709. _spqcd.mu = (data[j] & 0x7) << 8 | data[j + 1];
  6710. j += 2;
  6711. }
  6712. spqcds.push(_spqcd);
  6713. }
  6714. qcc.SPqcds = spqcds;
  6715. if (context.mainHeader) {
  6716. context.QCC[cqcc] = qcc;
  6717. } else {
  6718. context.currentTile.QCC[cqcc] = qcc;
  6719. }
  6720. break;
  6721. case 0xff52:
  6722. length = (0, _core_utils.readUint16)(data, position);
  6723. var cod = {};
  6724. j = position + 2;
  6725. var scod = data[j++];
  6726. cod.entropyCoderWithCustomPrecincts = !!(scod & 1);
  6727. cod.sopMarkerUsed = !!(scod & 2);
  6728. cod.ephMarkerUsed = !!(scod & 4);
  6729. cod.progressionOrder = data[j++];
  6730. cod.layersCount = (0, _core_utils.readUint16)(data, j);
  6731. j += 2;
  6732. cod.multipleComponentTransform = data[j++];
  6733. cod.decompositionLevelsCount = data[j++];
  6734. cod.xcb = (data[j++] & 0xf) + 2;
  6735. cod.ycb = (data[j++] & 0xf) + 2;
  6736. var blockStyle = data[j++];
  6737. cod.selectiveArithmeticCodingBypass = !!(blockStyle & 1);
  6738. cod.resetContextProbabilities = !!(blockStyle & 2);
  6739. cod.terminationOnEachCodingPass = !!(blockStyle & 4);
  6740. cod.verticallyStripe = !!(blockStyle & 8);
  6741. cod.predictableTermination = !!(blockStyle & 16);
  6742. cod.segmentationSymbolUsed = !!(blockStyle & 32);
  6743. cod.reversibleTransformation = data[j++];
  6744. if (cod.entropyCoderWithCustomPrecincts) {
  6745. var precinctsSizes = [];
  6746. while (j < length + position) {
  6747. var precinctsSize = data[j++];
  6748. precinctsSizes.push({
  6749. PPx: precinctsSize & 0xf,
  6750. PPy: precinctsSize >> 4
  6751. });
  6752. }
  6753. cod.precinctsSizes = precinctsSizes;
  6754. }
  6755. var unsupported = [];
  6756. if (cod.selectiveArithmeticCodingBypass) {
  6757. unsupported.push("selectiveArithmeticCodingBypass");
  6758. }
  6759. if (cod.terminationOnEachCodingPass) {
  6760. unsupported.push("terminationOnEachCodingPass");
  6761. }
  6762. if (cod.verticallyStripe) {
  6763. unsupported.push("verticallyStripe");
  6764. }
  6765. if (cod.predictableTermination) {
  6766. unsupported.push("predictableTermination");
  6767. }
  6768. if (unsupported.length > 0) {
  6769. doNotRecover = true;
  6770. (0, _util.warn)("JPX: Unsupported COD options (".concat(unsupported.join(", "), ")."));
  6771. }
  6772. if (context.mainHeader) {
  6773. context.COD = cod;
  6774. } else {
  6775. context.currentTile.COD = cod;
  6776. context.currentTile.COC = [];
  6777. }
  6778. break;
  6779. case 0xff90:
  6780. length = (0, _core_utils.readUint16)(data, position);
  6781. tile = {};
  6782. tile.index = (0, _core_utils.readUint16)(data, position + 2);
  6783. tile.length = (0, _core_utils.readUint32)(data, position + 4);
  6784. tile.dataEnd = tile.length + position - 2;
  6785. tile.partIndex = data[position + 8];
  6786. tile.partsCount = data[position + 9];
  6787. context.mainHeader = false;
  6788. if (tile.partIndex === 0) {
  6789. tile.COD = context.COD;
  6790. tile.COC = context.COC.slice(0);
  6791. tile.QCD = context.QCD;
  6792. tile.QCC = context.QCC.slice(0);
  6793. }
  6794. context.currentTile = tile;
  6795. break;
  6796. case 0xff93:
  6797. tile = context.currentTile;
  6798. if (tile.partIndex === 0) {
  6799. initializeTile(context, tile.index);
  6800. buildPackets(context);
  6801. }
  6802. length = tile.dataEnd - position;
  6803. parseTilePackets(context, data, position, length);
  6804. break;
  6805. case 0xff53:
  6806. (0, _util.warn)("JPX: Codestream code 0xFF53 (COC) is not implemented.");
  6807. case 0xff55:
  6808. case 0xff57:
  6809. case 0xff58:
  6810. case 0xff64:
  6811. length = (0, _core_utils.readUint16)(data, position);
  6812. break;
  6813. default:
  6814. throw new Error("Unknown codestream code: " + code.toString(16));
  6815. }
  6816. position += length;
  6817. }
  6818. } catch (e) {
  6819. if (doNotRecover || this.failOnCorruptedImage) {
  6820. throw new JpxError(e.message);
  6821. } else {
  6822. (0, _util.warn)("JPX: Trying to recover from: \"".concat(e.message, "\"."));
  6823. }
  6824. }
  6825. this.tiles = transformComponents(context);
  6826. this.width = context.SIZ.Xsiz - context.SIZ.XOsiz;
  6827. this.height = context.SIZ.Ysiz - context.SIZ.YOsiz;
  6828. this.componentsCount = context.SIZ.Csiz;
  6829. }
  6830. }]);
  6831. return JpxImage;
  6832. }();
  6833. exports.JpxImage = JpxImage;
  6834. function calculateComponentDimensions(component, siz) {
  6835. component.x0 = Math.ceil(siz.XOsiz / component.XRsiz);
  6836. component.x1 = Math.ceil(siz.Xsiz / component.XRsiz);
  6837. component.y0 = Math.ceil(siz.YOsiz / component.YRsiz);
  6838. component.y1 = Math.ceil(siz.Ysiz / component.YRsiz);
  6839. component.width = component.x1 - component.x0;
  6840. component.height = component.y1 - component.y0;
  6841. }
  6842. function calculateTileGrids(context, components) {
  6843. var siz = context.SIZ;
  6844. var tiles = [];
  6845. var tile;
  6846. var numXtiles = Math.ceil((siz.Xsiz - siz.XTOsiz) / siz.XTsiz);
  6847. var numYtiles = Math.ceil((siz.Ysiz - siz.YTOsiz) / siz.YTsiz);
  6848. for (var q = 0; q < numYtiles; q++) {
  6849. for (var p = 0; p < numXtiles; p++) {
  6850. tile = {};
  6851. tile.tx0 = Math.max(siz.XTOsiz + p * siz.XTsiz, siz.XOsiz);
  6852. tile.ty0 = Math.max(siz.YTOsiz + q * siz.YTsiz, siz.YOsiz);
  6853. tile.tx1 = Math.min(siz.XTOsiz + (p + 1) * siz.XTsiz, siz.Xsiz);
  6854. tile.ty1 = Math.min(siz.YTOsiz + (q + 1) * siz.YTsiz, siz.Ysiz);
  6855. tile.width = tile.tx1 - tile.tx0;
  6856. tile.height = tile.ty1 - tile.ty0;
  6857. tile.components = [];
  6858. tiles.push(tile);
  6859. }
  6860. }
  6861. context.tiles = tiles;
  6862. var componentsCount = siz.Csiz;
  6863. for (var i = 0, ii = componentsCount; i < ii; i++) {
  6864. var component = components[i];
  6865. for (var j = 0, jj = tiles.length; j < jj; j++) {
  6866. var tileComponent = {};
  6867. tile = tiles[j];
  6868. tileComponent.tcx0 = Math.ceil(tile.tx0 / component.XRsiz);
  6869. tileComponent.tcy0 = Math.ceil(tile.ty0 / component.YRsiz);
  6870. tileComponent.tcx1 = Math.ceil(tile.tx1 / component.XRsiz);
  6871. tileComponent.tcy1 = Math.ceil(tile.ty1 / component.YRsiz);
  6872. tileComponent.width = tileComponent.tcx1 - tileComponent.tcx0;
  6873. tileComponent.height = tileComponent.tcy1 - tileComponent.tcy0;
  6874. tile.components[i] = tileComponent;
  6875. }
  6876. }
  6877. }
  6878. function getBlocksDimensions(context, component, r) {
  6879. var codOrCoc = component.codingStyleParameters;
  6880. var result = {};
  6881. if (!codOrCoc.entropyCoderWithCustomPrecincts) {
  6882. result.PPx = 15;
  6883. result.PPy = 15;
  6884. } else {
  6885. result.PPx = codOrCoc.precinctsSizes[r].PPx;
  6886. result.PPy = codOrCoc.precinctsSizes[r].PPy;
  6887. }
  6888. result.xcb_ = r > 0 ? Math.min(codOrCoc.xcb, result.PPx - 1) : Math.min(codOrCoc.xcb, result.PPx);
  6889. result.ycb_ = r > 0 ? Math.min(codOrCoc.ycb, result.PPy - 1) : Math.min(codOrCoc.ycb, result.PPy);
  6890. return result;
  6891. }
  6892. function buildPrecincts(context, resolution, dimensions) {
  6893. var precinctWidth = 1 << dimensions.PPx;
  6894. var precinctHeight = 1 << dimensions.PPy;
  6895. var isZeroRes = resolution.resLevel === 0;
  6896. var precinctWidthInSubband = 1 << dimensions.PPx + (isZeroRes ? 0 : -1);
  6897. var precinctHeightInSubband = 1 << dimensions.PPy + (isZeroRes ? 0 : -1);
  6898. var numprecinctswide = resolution.trx1 > resolution.trx0 ? Math.ceil(resolution.trx1 / precinctWidth) - Math.floor(resolution.trx0 / precinctWidth) : 0;
  6899. var numprecinctshigh = resolution.try1 > resolution.try0 ? Math.ceil(resolution.try1 / precinctHeight) - Math.floor(resolution.try0 / precinctHeight) : 0;
  6900. var numprecincts = numprecinctswide * numprecinctshigh;
  6901. resolution.precinctParameters = {
  6902. precinctWidth: precinctWidth,
  6903. precinctHeight: precinctHeight,
  6904. numprecinctswide: numprecinctswide,
  6905. numprecinctshigh: numprecinctshigh,
  6906. numprecincts: numprecincts,
  6907. precinctWidthInSubband: precinctWidthInSubband,
  6908. precinctHeightInSubband: precinctHeightInSubband
  6909. };
  6910. }
  6911. function buildCodeblocks(context, subband, dimensions) {
  6912. var xcb_ = dimensions.xcb_;
  6913. var ycb_ = dimensions.ycb_;
  6914. var codeblockWidth = 1 << xcb_;
  6915. var codeblockHeight = 1 << ycb_;
  6916. var cbx0 = subband.tbx0 >> xcb_;
  6917. var cby0 = subband.tby0 >> ycb_;
  6918. var cbx1 = subband.tbx1 + codeblockWidth - 1 >> xcb_;
  6919. var cby1 = subband.tby1 + codeblockHeight - 1 >> ycb_;
  6920. var precinctParameters = subband.resolution.precinctParameters;
  6921. var codeblocks = [];
  6922. var precincts = [];
  6923. var i, j, codeblock, precinctNumber;
  6924. for (j = cby0; j < cby1; j++) {
  6925. for (i = cbx0; i < cbx1; i++) {
  6926. codeblock = {
  6927. cbx: i,
  6928. cby: j,
  6929. tbx0: codeblockWidth * i,
  6930. tby0: codeblockHeight * j,
  6931. tbx1: codeblockWidth * (i + 1),
  6932. tby1: codeblockHeight * (j + 1)
  6933. };
  6934. codeblock.tbx0_ = Math.max(subband.tbx0, codeblock.tbx0);
  6935. codeblock.tby0_ = Math.max(subband.tby0, codeblock.tby0);
  6936. codeblock.tbx1_ = Math.min(subband.tbx1, codeblock.tbx1);
  6937. codeblock.tby1_ = Math.min(subband.tby1, codeblock.tby1);
  6938. var pi = Math.floor((codeblock.tbx0_ - subband.tbx0) / precinctParameters.precinctWidthInSubband);
  6939. var pj = Math.floor((codeblock.tby0_ - subband.tby0) / precinctParameters.precinctHeightInSubband);
  6940. precinctNumber = pi + pj * precinctParameters.numprecinctswide;
  6941. codeblock.precinctNumber = precinctNumber;
  6942. codeblock.subbandType = subband.type;
  6943. codeblock.Lblock = 3;
  6944. if (codeblock.tbx1_ <= codeblock.tbx0_ || codeblock.tby1_ <= codeblock.tby0_) {
  6945. continue;
  6946. }
  6947. codeblocks.push(codeblock);
  6948. var precinct = precincts[precinctNumber];
  6949. if (precinct !== undefined) {
  6950. if (i < precinct.cbxMin) {
  6951. precinct.cbxMin = i;
  6952. } else if (i > precinct.cbxMax) {
  6953. precinct.cbxMax = i;
  6954. }
  6955. if (j < precinct.cbyMin) {
  6956. precinct.cbxMin = j;
  6957. } else if (j > precinct.cbyMax) {
  6958. precinct.cbyMax = j;
  6959. }
  6960. } else {
  6961. precincts[precinctNumber] = precinct = {
  6962. cbxMin: i,
  6963. cbyMin: j,
  6964. cbxMax: i,
  6965. cbyMax: j
  6966. };
  6967. }
  6968. codeblock.precinct = precinct;
  6969. }
  6970. }
  6971. subband.codeblockParameters = {
  6972. codeblockWidth: xcb_,
  6973. codeblockHeight: ycb_,
  6974. numcodeblockwide: cbx1 - cbx0 + 1,
  6975. numcodeblockhigh: cby1 - cby0 + 1
  6976. };
  6977. subband.codeblocks = codeblocks;
  6978. subband.precincts = precincts;
  6979. }
  6980. function createPacket(resolution, precinctNumber, layerNumber) {
  6981. var precinctCodeblocks = [];
  6982. var subbands = resolution.subbands;
  6983. for (var i = 0, ii = subbands.length; i < ii; i++) {
  6984. var subband = subbands[i];
  6985. var codeblocks = subband.codeblocks;
  6986. for (var j = 0, jj = codeblocks.length; j < jj; j++) {
  6987. var codeblock = codeblocks[j];
  6988. if (codeblock.precinctNumber !== precinctNumber) {
  6989. continue;
  6990. }
  6991. precinctCodeblocks.push(codeblock);
  6992. }
  6993. }
  6994. return {
  6995. layerNumber: layerNumber,
  6996. codeblocks: precinctCodeblocks
  6997. };
  6998. }
  6999. function LayerResolutionComponentPositionIterator(context) {
  7000. var siz = context.SIZ;
  7001. var tileIndex = context.currentTile.index;
  7002. var tile = context.tiles[tileIndex];
  7003. var layersCount = tile.codingStyleDefaultParameters.layersCount;
  7004. var componentsCount = siz.Csiz;
  7005. var maxDecompositionLevelsCount = 0;
  7006. for (var q = 0; q < componentsCount; q++) {
  7007. maxDecompositionLevelsCount = Math.max(maxDecompositionLevelsCount, tile.components[q].codingStyleParameters.decompositionLevelsCount);
  7008. }
  7009. var l = 0,
  7010. r = 0,
  7011. i = 0,
  7012. k = 0;
  7013. this.nextPacket = function JpxImage_nextPacket() {
  7014. for (; l < layersCount; l++) {
  7015. for (; r <= maxDecompositionLevelsCount; r++) {
  7016. for (; i < componentsCount; i++) {
  7017. var component = tile.components[i];
  7018. if (r > component.codingStyleParameters.decompositionLevelsCount) {
  7019. continue;
  7020. }
  7021. var resolution = component.resolutions[r];
  7022. var numprecincts = resolution.precinctParameters.numprecincts;
  7023. for (; k < numprecincts;) {
  7024. var packet = createPacket(resolution, k, l);
  7025. k++;
  7026. return packet;
  7027. }
  7028. k = 0;
  7029. }
  7030. i = 0;
  7031. }
  7032. r = 0;
  7033. }
  7034. throw new JpxError("Out of packets");
  7035. };
  7036. }
  7037. function ResolutionLayerComponentPositionIterator(context) {
  7038. var siz = context.SIZ;
  7039. var tileIndex = context.currentTile.index;
  7040. var tile = context.tiles[tileIndex];
  7041. var layersCount = tile.codingStyleDefaultParameters.layersCount;
  7042. var componentsCount = siz.Csiz;
  7043. var maxDecompositionLevelsCount = 0;
  7044. for (var q = 0; q < componentsCount; q++) {
  7045. maxDecompositionLevelsCount = Math.max(maxDecompositionLevelsCount, tile.components[q].codingStyleParameters.decompositionLevelsCount);
  7046. }
  7047. var r = 0,
  7048. l = 0,
  7049. i = 0,
  7050. k = 0;
  7051. this.nextPacket = function JpxImage_nextPacket() {
  7052. for (; r <= maxDecompositionLevelsCount; r++) {
  7053. for (; l < layersCount; l++) {
  7054. for (; i < componentsCount; i++) {
  7055. var component = tile.components[i];
  7056. if (r > component.codingStyleParameters.decompositionLevelsCount) {
  7057. continue;
  7058. }
  7059. var resolution = component.resolutions[r];
  7060. var numprecincts = resolution.precinctParameters.numprecincts;
  7061. for (; k < numprecincts;) {
  7062. var packet = createPacket(resolution, k, l);
  7063. k++;
  7064. return packet;
  7065. }
  7066. k = 0;
  7067. }
  7068. i = 0;
  7069. }
  7070. l = 0;
  7071. }
  7072. throw new JpxError("Out of packets");
  7073. };
  7074. }
  7075. function ResolutionPositionComponentLayerIterator(context) {
  7076. var siz = context.SIZ;
  7077. var tileIndex = context.currentTile.index;
  7078. var tile = context.tiles[tileIndex];
  7079. var layersCount = tile.codingStyleDefaultParameters.layersCount;
  7080. var componentsCount = siz.Csiz;
  7081. var l, r, c, p;
  7082. var maxDecompositionLevelsCount = 0;
  7083. for (c = 0; c < componentsCount; c++) {
  7084. var component = tile.components[c];
  7085. maxDecompositionLevelsCount = Math.max(maxDecompositionLevelsCount, component.codingStyleParameters.decompositionLevelsCount);
  7086. }
  7087. var maxNumPrecinctsInLevel = new Int32Array(maxDecompositionLevelsCount + 1);
  7088. for (r = 0; r <= maxDecompositionLevelsCount; ++r) {
  7089. var maxNumPrecincts = 0;
  7090. for (c = 0; c < componentsCount; ++c) {
  7091. var resolutions = tile.components[c].resolutions;
  7092. if (r < resolutions.length) {
  7093. maxNumPrecincts = Math.max(maxNumPrecincts, resolutions[r].precinctParameters.numprecincts);
  7094. }
  7095. }
  7096. maxNumPrecinctsInLevel[r] = maxNumPrecincts;
  7097. }
  7098. l = 0;
  7099. r = 0;
  7100. c = 0;
  7101. p = 0;
  7102. this.nextPacket = function JpxImage_nextPacket() {
  7103. for (; r <= maxDecompositionLevelsCount; r++) {
  7104. for (; p < maxNumPrecinctsInLevel[r]; p++) {
  7105. for (; c < componentsCount; c++) {
  7106. var _component = tile.components[c];
  7107. if (r > _component.codingStyleParameters.decompositionLevelsCount) {
  7108. continue;
  7109. }
  7110. var resolution = _component.resolutions[r];
  7111. var numprecincts = resolution.precinctParameters.numprecincts;
  7112. if (p >= numprecincts) {
  7113. continue;
  7114. }
  7115. for (; l < layersCount;) {
  7116. var packet = createPacket(resolution, p, l);
  7117. l++;
  7118. return packet;
  7119. }
  7120. l = 0;
  7121. }
  7122. c = 0;
  7123. }
  7124. p = 0;
  7125. }
  7126. throw new JpxError("Out of packets");
  7127. };
  7128. }
  7129. function PositionComponentResolutionLayerIterator(context) {
  7130. var siz = context.SIZ;
  7131. var tileIndex = context.currentTile.index;
  7132. var tile = context.tiles[tileIndex];
  7133. var layersCount = tile.codingStyleDefaultParameters.layersCount;
  7134. var componentsCount = siz.Csiz;
  7135. var precinctsSizes = getPrecinctSizesInImageScale(tile);
  7136. var precinctsIterationSizes = precinctsSizes;
  7137. var l = 0,
  7138. r = 0,
  7139. c = 0,
  7140. px = 0,
  7141. py = 0;
  7142. this.nextPacket = function JpxImage_nextPacket() {
  7143. for (; py < precinctsIterationSizes.maxNumHigh; py++) {
  7144. for (; px < precinctsIterationSizes.maxNumWide; px++) {
  7145. for (; c < componentsCount; c++) {
  7146. var component = tile.components[c];
  7147. var decompositionLevelsCount = component.codingStyleParameters.decompositionLevelsCount;
  7148. for (; r <= decompositionLevelsCount; r++) {
  7149. var resolution = component.resolutions[r];
  7150. var sizeInImageScale = precinctsSizes.components[c].resolutions[r];
  7151. var k = getPrecinctIndexIfExist(px, py, sizeInImageScale, precinctsIterationSizes, resolution);
  7152. if (k === null) {
  7153. continue;
  7154. }
  7155. for (; l < layersCount;) {
  7156. var packet = createPacket(resolution, k, l);
  7157. l++;
  7158. return packet;
  7159. }
  7160. l = 0;
  7161. }
  7162. r = 0;
  7163. }
  7164. c = 0;
  7165. }
  7166. px = 0;
  7167. }
  7168. throw new JpxError("Out of packets");
  7169. };
  7170. }
  7171. function ComponentPositionResolutionLayerIterator(context) {
  7172. var siz = context.SIZ;
  7173. var tileIndex = context.currentTile.index;
  7174. var tile = context.tiles[tileIndex];
  7175. var layersCount = tile.codingStyleDefaultParameters.layersCount;
  7176. var componentsCount = siz.Csiz;
  7177. var precinctsSizes = getPrecinctSizesInImageScale(tile);
  7178. var l = 0,
  7179. r = 0,
  7180. c = 0,
  7181. px = 0,
  7182. py = 0;
  7183. this.nextPacket = function JpxImage_nextPacket() {
  7184. for (; c < componentsCount; ++c) {
  7185. var component = tile.components[c];
  7186. var precinctsIterationSizes = precinctsSizes.components[c];
  7187. var decompositionLevelsCount = component.codingStyleParameters.decompositionLevelsCount;
  7188. for (; py < precinctsIterationSizes.maxNumHigh; py++) {
  7189. for (; px < precinctsIterationSizes.maxNumWide; px++) {
  7190. for (; r <= decompositionLevelsCount; r++) {
  7191. var resolution = component.resolutions[r];
  7192. var sizeInImageScale = precinctsIterationSizes.resolutions[r];
  7193. var k = getPrecinctIndexIfExist(px, py, sizeInImageScale, precinctsIterationSizes, resolution);
  7194. if (k === null) {
  7195. continue;
  7196. }
  7197. for (; l < layersCount;) {
  7198. var packet = createPacket(resolution, k, l);
  7199. l++;
  7200. return packet;
  7201. }
  7202. l = 0;
  7203. }
  7204. r = 0;
  7205. }
  7206. px = 0;
  7207. }
  7208. py = 0;
  7209. }
  7210. throw new JpxError("Out of packets");
  7211. };
  7212. }
  7213. function getPrecinctIndexIfExist(pxIndex, pyIndex, sizeInImageScale, precinctIterationSizes, resolution) {
  7214. var posX = pxIndex * precinctIterationSizes.minWidth;
  7215. var posY = pyIndex * precinctIterationSizes.minHeight;
  7216. if (posX % sizeInImageScale.width !== 0 || posY % sizeInImageScale.height !== 0) {
  7217. return null;
  7218. }
  7219. var startPrecinctRowIndex = posY / sizeInImageScale.width * resolution.precinctParameters.numprecinctswide;
  7220. return posX / sizeInImageScale.height + startPrecinctRowIndex;
  7221. }
  7222. function getPrecinctSizesInImageScale(tile) {
  7223. var componentsCount = tile.components.length;
  7224. var minWidth = Number.MAX_VALUE;
  7225. var minHeight = Number.MAX_VALUE;
  7226. var maxNumWide = 0;
  7227. var maxNumHigh = 0;
  7228. var sizePerComponent = new Array(componentsCount);
  7229. for (var c = 0; c < componentsCount; c++) {
  7230. var component = tile.components[c];
  7231. var decompositionLevelsCount = component.codingStyleParameters.decompositionLevelsCount;
  7232. var sizePerResolution = new Array(decompositionLevelsCount + 1);
  7233. var minWidthCurrentComponent = Number.MAX_VALUE;
  7234. var minHeightCurrentComponent = Number.MAX_VALUE;
  7235. var maxNumWideCurrentComponent = 0;
  7236. var maxNumHighCurrentComponent = 0;
  7237. var scale = 1;
  7238. for (var r = decompositionLevelsCount; r >= 0; --r) {
  7239. var resolution = component.resolutions[r];
  7240. var widthCurrentResolution = scale * resolution.precinctParameters.precinctWidth;
  7241. var heightCurrentResolution = scale * resolution.precinctParameters.precinctHeight;
  7242. minWidthCurrentComponent = Math.min(minWidthCurrentComponent, widthCurrentResolution);
  7243. minHeightCurrentComponent = Math.min(minHeightCurrentComponent, heightCurrentResolution);
  7244. maxNumWideCurrentComponent = Math.max(maxNumWideCurrentComponent, resolution.precinctParameters.numprecinctswide);
  7245. maxNumHighCurrentComponent = Math.max(maxNumHighCurrentComponent, resolution.precinctParameters.numprecinctshigh);
  7246. sizePerResolution[r] = {
  7247. width: widthCurrentResolution,
  7248. height: heightCurrentResolution
  7249. };
  7250. scale <<= 1;
  7251. }
  7252. minWidth = Math.min(minWidth, minWidthCurrentComponent);
  7253. minHeight = Math.min(minHeight, minHeightCurrentComponent);
  7254. maxNumWide = Math.max(maxNumWide, maxNumWideCurrentComponent);
  7255. maxNumHigh = Math.max(maxNumHigh, maxNumHighCurrentComponent);
  7256. sizePerComponent[c] = {
  7257. resolutions: sizePerResolution,
  7258. minWidth: minWidthCurrentComponent,
  7259. minHeight: minHeightCurrentComponent,
  7260. maxNumWide: maxNumWideCurrentComponent,
  7261. maxNumHigh: maxNumHighCurrentComponent
  7262. };
  7263. }
  7264. return {
  7265. components: sizePerComponent,
  7266. minWidth: minWidth,
  7267. minHeight: minHeight,
  7268. maxNumWide: maxNumWide,
  7269. maxNumHigh: maxNumHigh
  7270. };
  7271. }
  7272. function buildPackets(context) {
  7273. var siz = context.SIZ;
  7274. var tileIndex = context.currentTile.index;
  7275. var tile = context.tiles[tileIndex];
  7276. var componentsCount = siz.Csiz;
  7277. for (var c = 0; c < componentsCount; c++) {
  7278. var component = tile.components[c];
  7279. var decompositionLevelsCount = component.codingStyleParameters.decompositionLevelsCount;
  7280. var resolutions = [];
  7281. var subbands = [];
  7282. for (var r = 0; r <= decompositionLevelsCount; r++) {
  7283. var blocksDimensions = getBlocksDimensions(context, component, r);
  7284. var resolution = {};
  7285. var scale = 1 << decompositionLevelsCount - r;
  7286. resolution.trx0 = Math.ceil(component.tcx0 / scale);
  7287. resolution.try0 = Math.ceil(component.tcy0 / scale);
  7288. resolution.trx1 = Math.ceil(component.tcx1 / scale);
  7289. resolution.try1 = Math.ceil(component.tcy1 / scale);
  7290. resolution.resLevel = r;
  7291. buildPrecincts(context, resolution, blocksDimensions);
  7292. resolutions.push(resolution);
  7293. var subband = void 0;
  7294. if (r === 0) {
  7295. subband = {};
  7296. subband.type = "LL";
  7297. subband.tbx0 = Math.ceil(component.tcx0 / scale);
  7298. subband.tby0 = Math.ceil(component.tcy0 / scale);
  7299. subband.tbx1 = Math.ceil(component.tcx1 / scale);
  7300. subband.tby1 = Math.ceil(component.tcy1 / scale);
  7301. subband.resolution = resolution;
  7302. buildCodeblocks(context, subband, blocksDimensions);
  7303. subbands.push(subband);
  7304. resolution.subbands = [subband];
  7305. } else {
  7306. var bscale = 1 << decompositionLevelsCount - r + 1;
  7307. var resolutionSubbands = [];
  7308. subband = {};
  7309. subband.type = "HL";
  7310. subband.tbx0 = Math.ceil(component.tcx0 / bscale - 0.5);
  7311. subband.tby0 = Math.ceil(component.tcy0 / bscale);
  7312. subband.tbx1 = Math.ceil(component.tcx1 / bscale - 0.5);
  7313. subband.tby1 = Math.ceil(component.tcy1 / bscale);
  7314. subband.resolution = resolution;
  7315. buildCodeblocks(context, subband, blocksDimensions);
  7316. subbands.push(subband);
  7317. resolutionSubbands.push(subband);
  7318. subband = {};
  7319. subband.type = "LH";
  7320. subband.tbx0 = Math.ceil(component.tcx0 / bscale);
  7321. subband.tby0 = Math.ceil(component.tcy0 / bscale - 0.5);
  7322. subband.tbx1 = Math.ceil(component.tcx1 / bscale);
  7323. subband.tby1 = Math.ceil(component.tcy1 / bscale - 0.5);
  7324. subband.resolution = resolution;
  7325. buildCodeblocks(context, subband, blocksDimensions);
  7326. subbands.push(subband);
  7327. resolutionSubbands.push(subband);
  7328. subband = {};
  7329. subband.type = "HH";
  7330. subband.tbx0 = Math.ceil(component.tcx0 / bscale - 0.5);
  7331. subband.tby0 = Math.ceil(component.tcy0 / bscale - 0.5);
  7332. subband.tbx1 = Math.ceil(component.tcx1 / bscale - 0.5);
  7333. subband.tby1 = Math.ceil(component.tcy1 / bscale - 0.5);
  7334. subband.resolution = resolution;
  7335. buildCodeblocks(context, subband, blocksDimensions);
  7336. subbands.push(subband);
  7337. resolutionSubbands.push(subband);
  7338. resolution.subbands = resolutionSubbands;
  7339. }
  7340. }
  7341. component.resolutions = resolutions;
  7342. component.subbands = subbands;
  7343. }
  7344. var progressionOrder = tile.codingStyleDefaultParameters.progressionOrder;
  7345. switch (progressionOrder) {
  7346. case 0:
  7347. tile.packetsIterator = new LayerResolutionComponentPositionIterator(context);
  7348. break;
  7349. case 1:
  7350. tile.packetsIterator = new ResolutionLayerComponentPositionIterator(context);
  7351. break;
  7352. case 2:
  7353. tile.packetsIterator = new ResolutionPositionComponentLayerIterator(context);
  7354. break;
  7355. case 3:
  7356. tile.packetsIterator = new PositionComponentResolutionLayerIterator(context);
  7357. break;
  7358. case 4:
  7359. tile.packetsIterator = new ComponentPositionResolutionLayerIterator(context);
  7360. break;
  7361. default:
  7362. throw new JpxError("Unsupported progression order ".concat(progressionOrder));
  7363. }
  7364. }
  7365. function parseTilePackets(context, data, offset, dataLength) {
  7366. var position = 0;
  7367. var buffer,
  7368. bufferSize = 0,
  7369. skipNextBit = false;
  7370. function readBits(count) {
  7371. while (bufferSize < count) {
  7372. var b = data[offset + position];
  7373. position++;
  7374. if (skipNextBit) {
  7375. buffer = buffer << 7 | b;
  7376. bufferSize += 7;
  7377. skipNextBit = false;
  7378. } else {
  7379. buffer = buffer << 8 | b;
  7380. bufferSize += 8;
  7381. }
  7382. if (b === 0xff) {
  7383. skipNextBit = true;
  7384. }
  7385. }
  7386. bufferSize -= count;
  7387. return buffer >>> bufferSize & (1 << count) - 1;
  7388. }
  7389. function skipMarkerIfEqual(value) {
  7390. if (data[offset + position - 1] === 0xff && data[offset + position] === value) {
  7391. skipBytes(1);
  7392. return true;
  7393. } else if (data[offset + position] === 0xff && data[offset + position + 1] === value) {
  7394. skipBytes(2);
  7395. return true;
  7396. }
  7397. return false;
  7398. }
  7399. function skipBytes(count) {
  7400. position += count;
  7401. }
  7402. function alignToByte() {
  7403. bufferSize = 0;
  7404. if (skipNextBit) {
  7405. position++;
  7406. skipNextBit = false;
  7407. }
  7408. }
  7409. function readCodingpasses() {
  7410. if (readBits(1) === 0) {
  7411. return 1;
  7412. }
  7413. if (readBits(1) === 0) {
  7414. return 2;
  7415. }
  7416. var value = readBits(2);
  7417. if (value < 3) {
  7418. return value + 3;
  7419. }
  7420. value = readBits(5);
  7421. if (value < 31) {
  7422. return value + 6;
  7423. }
  7424. value = readBits(7);
  7425. return value + 37;
  7426. }
  7427. var tileIndex = context.currentTile.index;
  7428. var tile = context.tiles[tileIndex];
  7429. var sopMarkerUsed = context.COD.sopMarkerUsed;
  7430. var ephMarkerUsed = context.COD.ephMarkerUsed;
  7431. var packetsIterator = tile.packetsIterator;
  7432. while (position < dataLength) {
  7433. alignToByte();
  7434. if (sopMarkerUsed && skipMarkerIfEqual(0x91)) {
  7435. skipBytes(4);
  7436. }
  7437. var packet = packetsIterator.nextPacket();
  7438. if (!readBits(1)) {
  7439. continue;
  7440. }
  7441. var layerNumber = packet.layerNumber,
  7442. queue = [];
  7443. var codeblock = void 0;
  7444. for (var i = 0, ii = packet.codeblocks.length; i < ii; i++) {
  7445. codeblock = packet.codeblocks[i];
  7446. var precinct = codeblock.precinct;
  7447. var codeblockColumn = codeblock.cbx - precinct.cbxMin;
  7448. var codeblockRow = codeblock.cby - precinct.cbyMin;
  7449. var codeblockIncluded = false;
  7450. var firstTimeInclusion = false;
  7451. var valueReady = void 0,
  7452. zeroBitPlanesTree = void 0;
  7453. if (codeblock.included !== undefined) {
  7454. codeblockIncluded = !!readBits(1);
  7455. } else {
  7456. precinct = codeblock.precinct;
  7457. var inclusionTree = void 0;
  7458. if (precinct.inclusionTree !== undefined) {
  7459. inclusionTree = precinct.inclusionTree;
  7460. } else {
  7461. var width = precinct.cbxMax - precinct.cbxMin + 1;
  7462. var height = precinct.cbyMax - precinct.cbyMin + 1;
  7463. inclusionTree = new InclusionTree(width, height, layerNumber);
  7464. zeroBitPlanesTree = new TagTree(width, height);
  7465. precinct.inclusionTree = inclusionTree;
  7466. precinct.zeroBitPlanesTree = zeroBitPlanesTree;
  7467. for (var l = 0; l < layerNumber; l++) {
  7468. if (readBits(1) !== 0) {
  7469. throw new JpxError("Invalid tag tree");
  7470. }
  7471. }
  7472. }
  7473. if (inclusionTree.reset(codeblockColumn, codeblockRow, layerNumber)) {
  7474. while (true) {
  7475. if (readBits(1)) {
  7476. valueReady = !inclusionTree.nextLevel();
  7477. if (valueReady) {
  7478. codeblock.included = true;
  7479. codeblockIncluded = firstTimeInclusion = true;
  7480. break;
  7481. }
  7482. } else {
  7483. inclusionTree.incrementValue(layerNumber);
  7484. break;
  7485. }
  7486. }
  7487. }
  7488. }
  7489. if (!codeblockIncluded) {
  7490. continue;
  7491. }
  7492. if (firstTimeInclusion) {
  7493. zeroBitPlanesTree = precinct.zeroBitPlanesTree;
  7494. zeroBitPlanesTree.reset(codeblockColumn, codeblockRow);
  7495. while (true) {
  7496. if (readBits(1)) {
  7497. valueReady = !zeroBitPlanesTree.nextLevel();
  7498. if (valueReady) {
  7499. break;
  7500. }
  7501. } else {
  7502. zeroBitPlanesTree.incrementValue();
  7503. }
  7504. }
  7505. codeblock.zeroBitPlanes = zeroBitPlanesTree.value;
  7506. }
  7507. var codingpasses = readCodingpasses();
  7508. while (readBits(1)) {
  7509. codeblock.Lblock++;
  7510. }
  7511. var codingpassesLog2 = (0, _core_utils.log2)(codingpasses);
  7512. var bits = (codingpasses < 1 << codingpassesLog2 ? codingpassesLog2 - 1 : codingpassesLog2) + codeblock.Lblock;
  7513. var codedDataLength = readBits(bits);
  7514. queue.push({
  7515. codeblock: codeblock,
  7516. codingpasses: codingpasses,
  7517. dataLength: codedDataLength
  7518. });
  7519. }
  7520. alignToByte();
  7521. if (ephMarkerUsed) {
  7522. skipMarkerIfEqual(0x92);
  7523. }
  7524. while (queue.length > 0) {
  7525. var packetItem = queue.shift();
  7526. codeblock = packetItem.codeblock;
  7527. if (codeblock.data === undefined) {
  7528. codeblock.data = [];
  7529. }
  7530. codeblock.data.push({
  7531. data: data,
  7532. start: offset + position,
  7533. end: offset + position + packetItem.dataLength,
  7534. codingpasses: packetItem.codingpasses
  7535. });
  7536. position += packetItem.dataLength;
  7537. }
  7538. }
  7539. return position;
  7540. }
  7541. function copyCoefficients(coefficients, levelWidth, levelHeight, subband, delta, mb, reversible, segmentationSymbolUsed, resetContextProbabilities) {
  7542. var x0 = subband.tbx0;
  7543. var y0 = subband.tby0;
  7544. var width = subband.tbx1 - subband.tbx0;
  7545. var codeblocks = subband.codeblocks;
  7546. var right = subband.type.charAt(0) === "H" ? 1 : 0;
  7547. var bottom = subband.type.charAt(1) === "H" ? levelWidth : 0;
  7548. for (var i = 0, ii = codeblocks.length; i < ii; ++i) {
  7549. var codeblock = codeblocks[i];
  7550. var blockWidth = codeblock.tbx1_ - codeblock.tbx0_;
  7551. var blockHeight = codeblock.tby1_ - codeblock.tby0_;
  7552. if (blockWidth === 0 || blockHeight === 0) {
  7553. continue;
  7554. }
  7555. if (codeblock.data === undefined) {
  7556. continue;
  7557. }
  7558. var bitModel = new BitModel(blockWidth, blockHeight, codeblock.subbandType, codeblock.zeroBitPlanes, mb);
  7559. var currentCodingpassType = 2;
  7560. var data = codeblock.data;
  7561. var totalLength = 0,
  7562. codingpasses = 0;
  7563. var j = void 0,
  7564. jj = void 0,
  7565. dataItem = void 0;
  7566. for (j = 0, jj = data.length; j < jj; j++) {
  7567. dataItem = data[j];
  7568. totalLength += dataItem.end - dataItem.start;
  7569. codingpasses += dataItem.codingpasses;
  7570. }
  7571. var encodedData = new Uint8Array(totalLength);
  7572. var position = 0;
  7573. for (j = 0, jj = data.length; j < jj; j++) {
  7574. dataItem = data[j];
  7575. var chunk = dataItem.data.subarray(dataItem.start, dataItem.end);
  7576. encodedData.set(chunk, position);
  7577. position += chunk.length;
  7578. }
  7579. var decoder = new _arithmetic_decoder.ArithmeticDecoder(encodedData, 0, totalLength);
  7580. bitModel.setDecoder(decoder);
  7581. for (j = 0; j < codingpasses; j++) {
  7582. switch (currentCodingpassType) {
  7583. case 0:
  7584. bitModel.runSignificancePropagationPass();
  7585. break;
  7586. case 1:
  7587. bitModel.runMagnitudeRefinementPass();
  7588. break;
  7589. case 2:
  7590. bitModel.runCleanupPass();
  7591. if (segmentationSymbolUsed) {
  7592. bitModel.checkSegmentationSymbol();
  7593. }
  7594. break;
  7595. }
  7596. if (resetContextProbabilities) {
  7597. bitModel.reset();
  7598. }
  7599. currentCodingpassType = (currentCodingpassType + 1) % 3;
  7600. }
  7601. var offset = codeblock.tbx0_ - x0 + (codeblock.tby0_ - y0) * width;
  7602. var sign = bitModel.coefficentsSign;
  7603. var magnitude = bitModel.coefficentsMagnitude;
  7604. var bitsDecoded = bitModel.bitsDecoded;
  7605. var magnitudeCorrection = reversible ? 0 : 0.5;
  7606. var k = void 0,
  7607. n = void 0,
  7608. nb = void 0;
  7609. position = 0;
  7610. var interleave = subband.type !== "LL";
  7611. for (j = 0; j < blockHeight; j++) {
  7612. var row = offset / width | 0;
  7613. var levelOffset = 2 * row * (levelWidth - width) + right + bottom;
  7614. for (k = 0; k < blockWidth; k++) {
  7615. n = magnitude[position];
  7616. if (n !== 0) {
  7617. n = (n + magnitudeCorrection) * delta;
  7618. if (sign[position] !== 0) {
  7619. n = -n;
  7620. }
  7621. nb = bitsDecoded[position];
  7622. var pos = interleave ? levelOffset + (offset << 1) : offset;
  7623. if (reversible && nb >= mb) {
  7624. coefficients[pos] = n;
  7625. } else {
  7626. coefficients[pos] = n * (1 << mb - nb);
  7627. }
  7628. }
  7629. offset++;
  7630. position++;
  7631. }
  7632. offset += width - blockWidth;
  7633. }
  7634. }
  7635. }
  7636. function transformTile(context, tile, c) {
  7637. var component = tile.components[c];
  7638. var codingStyleParameters = component.codingStyleParameters;
  7639. var quantizationParameters = component.quantizationParameters;
  7640. var decompositionLevelsCount = codingStyleParameters.decompositionLevelsCount;
  7641. var spqcds = quantizationParameters.SPqcds;
  7642. var scalarExpounded = quantizationParameters.scalarExpounded;
  7643. var guardBits = quantizationParameters.guardBits;
  7644. var segmentationSymbolUsed = codingStyleParameters.segmentationSymbolUsed;
  7645. var resetContextProbabilities = codingStyleParameters.resetContextProbabilities;
  7646. var precision = context.components[c].precision;
  7647. var reversible = codingStyleParameters.reversibleTransformation;
  7648. var transform = reversible ? new ReversibleTransform() : new IrreversibleTransform();
  7649. var subbandCoefficients = [];
  7650. var b = 0;
  7651. for (var i = 0; i <= decompositionLevelsCount; i++) {
  7652. var resolution = component.resolutions[i];
  7653. var width = resolution.trx1 - resolution.trx0;
  7654. var height = resolution.try1 - resolution.try0;
  7655. var coefficients = new Float32Array(width * height);
  7656. for (var j = 0, jj = resolution.subbands.length; j < jj; j++) {
  7657. var mu = void 0,
  7658. epsilon = void 0;
  7659. if (!scalarExpounded) {
  7660. mu = spqcds[0].mu;
  7661. epsilon = spqcds[0].epsilon + (i > 0 ? 1 - i : 0);
  7662. } else {
  7663. mu = spqcds[b].mu;
  7664. epsilon = spqcds[b].epsilon;
  7665. b++;
  7666. }
  7667. var subband = resolution.subbands[j];
  7668. var gainLog2 = SubbandsGainLog2[subband.type];
  7669. var delta = reversible ? 1 : Math.pow(2, precision + gainLog2 - epsilon) * (1 + mu / 2048);
  7670. var mb = guardBits + epsilon - 1;
  7671. copyCoefficients(coefficients, width, height, subband, delta, mb, reversible, segmentationSymbolUsed, resetContextProbabilities);
  7672. }
  7673. subbandCoefficients.push({
  7674. width: width,
  7675. height: height,
  7676. items: coefficients
  7677. });
  7678. }
  7679. var result = transform.calculate(subbandCoefficients, component.tcx0, component.tcy0);
  7680. return {
  7681. left: component.tcx0,
  7682. top: component.tcy0,
  7683. width: result.width,
  7684. height: result.height,
  7685. items: result.items
  7686. };
  7687. }
  7688. function transformComponents(context) {
  7689. var siz = context.SIZ;
  7690. var components = context.components;
  7691. var componentsCount = siz.Csiz;
  7692. var resultImages = [];
  7693. for (var i = 0, ii = context.tiles.length; i < ii; i++) {
  7694. var tile = context.tiles[i];
  7695. var transformedTiles = [];
  7696. for (var c = 0; c < componentsCount; c++) {
  7697. transformedTiles[c] = transformTile(context, tile, c);
  7698. }
  7699. var tile0 = transformedTiles[0];
  7700. var out = new Uint8ClampedArray(tile0.items.length * componentsCount);
  7701. var result = {
  7702. left: tile0.left,
  7703. top: tile0.top,
  7704. width: tile0.width,
  7705. height: tile0.height,
  7706. items: out
  7707. };
  7708. var shift = void 0,
  7709. offset = void 0;
  7710. var pos = 0,
  7711. j = void 0,
  7712. jj = void 0,
  7713. y0 = void 0,
  7714. y1 = void 0,
  7715. y2 = void 0;
  7716. if (tile.codingStyleDefaultParameters.multipleComponentTransform) {
  7717. var fourComponents = componentsCount === 4;
  7718. var y0items = transformedTiles[0].items;
  7719. var y1items = transformedTiles[1].items;
  7720. var y2items = transformedTiles[2].items;
  7721. var y3items = fourComponents ? transformedTiles[3].items : null;
  7722. shift = components[0].precision - 8;
  7723. offset = (128 << shift) + 0.5;
  7724. var component0 = tile.components[0];
  7725. var alpha01 = componentsCount - 3;
  7726. jj = y0items.length;
  7727. if (!component0.codingStyleParameters.reversibleTransformation) {
  7728. for (j = 0; j < jj; j++, pos += alpha01) {
  7729. y0 = y0items[j] + offset;
  7730. y1 = y1items[j];
  7731. y2 = y2items[j];
  7732. out[pos++] = y0 + 1.402 * y2 >> shift;
  7733. out[pos++] = y0 - 0.34413 * y1 - 0.71414 * y2 >> shift;
  7734. out[pos++] = y0 + 1.772 * y1 >> shift;
  7735. }
  7736. } else {
  7737. for (j = 0; j < jj; j++, pos += alpha01) {
  7738. y0 = y0items[j] + offset;
  7739. y1 = y1items[j];
  7740. y2 = y2items[j];
  7741. var g = y0 - (y2 + y1 >> 2);
  7742. out[pos++] = g + y2 >> shift;
  7743. out[pos++] = g >> shift;
  7744. out[pos++] = g + y1 >> shift;
  7745. }
  7746. }
  7747. if (fourComponents) {
  7748. for (j = 0, pos = 3; j < jj; j++, pos += 4) {
  7749. out[pos] = y3items[j] + offset >> shift;
  7750. }
  7751. }
  7752. } else {
  7753. for (var _c = 0; _c < componentsCount; _c++) {
  7754. var items = transformedTiles[_c].items;
  7755. shift = components[_c].precision - 8;
  7756. offset = (128 << shift) + 0.5;
  7757. for (pos = _c, j = 0, jj = items.length; j < jj; j++) {
  7758. out[pos] = items[j] + offset >> shift;
  7759. pos += componentsCount;
  7760. }
  7761. }
  7762. }
  7763. resultImages.push(result);
  7764. }
  7765. return resultImages;
  7766. }
  7767. function initializeTile(context, tileIndex) {
  7768. var siz = context.SIZ;
  7769. var componentsCount = siz.Csiz;
  7770. var tile = context.tiles[tileIndex];
  7771. for (var c = 0; c < componentsCount; c++) {
  7772. var component = tile.components[c];
  7773. var qcdOrQcc = context.currentTile.QCC[c] !== undefined ? context.currentTile.QCC[c] : context.currentTile.QCD;
  7774. component.quantizationParameters = qcdOrQcc;
  7775. var codOrCoc = context.currentTile.COC[c] !== undefined ? context.currentTile.COC[c] : context.currentTile.COD;
  7776. component.codingStyleParameters = codOrCoc;
  7777. }
  7778. tile.codingStyleDefaultParameters = context.currentTile.COD;
  7779. }
  7780. var TagTree = /*#__PURE__*/function () {
  7781. function TagTree(width, height) {
  7782. _classCallCheck(this, TagTree);
  7783. var levelsLength = (0, _core_utils.log2)(Math.max(width, height)) + 1;
  7784. this.levels = [];
  7785. for (var i = 0; i < levelsLength; i++) {
  7786. var level = {
  7787. width: width,
  7788. height: height,
  7789. items: []
  7790. };
  7791. this.levels.push(level);
  7792. width = Math.ceil(width / 2);
  7793. height = Math.ceil(height / 2);
  7794. }
  7795. }
  7796. _createClass(TagTree, [{
  7797. key: "reset",
  7798. value: function reset(i, j) {
  7799. var currentLevel = 0,
  7800. value = 0,
  7801. level;
  7802. while (currentLevel < this.levels.length) {
  7803. level = this.levels[currentLevel];
  7804. var index = i + j * level.width;
  7805. if (level.items[index] !== undefined) {
  7806. value = level.items[index];
  7807. break;
  7808. }
  7809. level.index = index;
  7810. i >>= 1;
  7811. j >>= 1;
  7812. currentLevel++;
  7813. }
  7814. currentLevel--;
  7815. level = this.levels[currentLevel];
  7816. level.items[level.index] = value;
  7817. this.currentLevel = currentLevel;
  7818. delete this.value;
  7819. }
  7820. }, {
  7821. key: "incrementValue",
  7822. value: function incrementValue() {
  7823. var level = this.levels[this.currentLevel];
  7824. level.items[level.index]++;
  7825. }
  7826. }, {
  7827. key: "nextLevel",
  7828. value: function nextLevel() {
  7829. var currentLevel = this.currentLevel;
  7830. var level = this.levels[currentLevel];
  7831. var value = level.items[level.index];
  7832. currentLevel--;
  7833. if (currentLevel < 0) {
  7834. this.value = value;
  7835. return false;
  7836. }
  7837. this.currentLevel = currentLevel;
  7838. level = this.levels[currentLevel];
  7839. level.items[level.index] = value;
  7840. return true;
  7841. }
  7842. }]);
  7843. return TagTree;
  7844. }();
  7845. var InclusionTree = /*#__PURE__*/function () {
  7846. function InclusionTree(width, height, defaultValue) {
  7847. _classCallCheck(this, InclusionTree);
  7848. var levelsLength = (0, _core_utils.log2)(Math.max(width, height)) + 1;
  7849. this.levels = [];
  7850. for (var i = 0; i < levelsLength; i++) {
  7851. var items = new Uint8Array(width * height);
  7852. for (var j = 0, jj = items.length; j < jj; j++) {
  7853. items[j] = defaultValue;
  7854. }
  7855. var level = {
  7856. width: width,
  7857. height: height,
  7858. items: items
  7859. };
  7860. this.levels.push(level);
  7861. width = Math.ceil(width / 2);
  7862. height = Math.ceil(height / 2);
  7863. }
  7864. }
  7865. _createClass(InclusionTree, [{
  7866. key: "reset",
  7867. value: function reset(i, j, stopValue) {
  7868. var currentLevel = 0;
  7869. while (currentLevel < this.levels.length) {
  7870. var level = this.levels[currentLevel];
  7871. var index = i + j * level.width;
  7872. level.index = index;
  7873. var value = level.items[index];
  7874. if (value === 0xff) {
  7875. break;
  7876. }
  7877. if (value > stopValue) {
  7878. this.currentLevel = currentLevel;
  7879. this.propagateValues();
  7880. return false;
  7881. }
  7882. i >>= 1;
  7883. j >>= 1;
  7884. currentLevel++;
  7885. }
  7886. this.currentLevel = currentLevel - 1;
  7887. return true;
  7888. }
  7889. }, {
  7890. key: "incrementValue",
  7891. value: function incrementValue(stopValue) {
  7892. var level = this.levels[this.currentLevel];
  7893. level.items[level.index] = stopValue + 1;
  7894. this.propagateValues();
  7895. }
  7896. }, {
  7897. key: "propagateValues",
  7898. value: function propagateValues() {
  7899. var levelIndex = this.currentLevel;
  7900. var level = this.levels[levelIndex];
  7901. var currentValue = level.items[level.index];
  7902. while (--levelIndex >= 0) {
  7903. level = this.levels[levelIndex];
  7904. level.items[level.index] = currentValue;
  7905. }
  7906. }
  7907. }, {
  7908. key: "nextLevel",
  7909. value: function nextLevel() {
  7910. var currentLevel = this.currentLevel;
  7911. var level = this.levels[currentLevel];
  7912. var value = level.items[level.index];
  7913. level.items[level.index] = 0xff;
  7914. currentLevel--;
  7915. if (currentLevel < 0) {
  7916. return false;
  7917. }
  7918. this.currentLevel = currentLevel;
  7919. level = this.levels[currentLevel];
  7920. level.items[level.index] = value;
  7921. return true;
  7922. }
  7923. }]);
  7924. return InclusionTree;
  7925. }();
  7926. var BitModel = function BitModelClosure() {
  7927. var UNIFORM_CONTEXT = 17;
  7928. var RUNLENGTH_CONTEXT = 18;
  7929. var LLAndLHContextsLabel = new Uint8Array([0, 5, 8, 0, 3, 7, 8, 0, 4, 7, 8, 0, 0, 0, 0, 0, 1, 6, 8, 0, 3, 7, 8, 0, 4, 7, 8, 0, 0, 0, 0, 0, 2, 6, 8, 0, 3, 7, 8, 0, 4, 7, 8, 0, 0, 0, 0, 0, 2, 6, 8, 0, 3, 7, 8, 0, 4, 7, 8, 0, 0, 0, 0, 0, 2, 6, 8, 0, 3, 7, 8, 0, 4, 7, 8]);
  7930. var HLContextLabel = new Uint8Array([0, 3, 4, 0, 5, 7, 7, 0, 8, 8, 8, 0, 0, 0, 0, 0, 1, 3, 4, 0, 6, 7, 7, 0, 8, 8, 8, 0, 0, 0, 0, 0, 2, 3, 4, 0, 6, 7, 7, 0, 8, 8, 8, 0, 0, 0, 0, 0, 2, 3, 4, 0, 6, 7, 7, 0, 8, 8, 8, 0, 0, 0, 0, 0, 2, 3, 4, 0, 6, 7, 7, 0, 8, 8, 8]);
  7931. var HHContextLabel = new Uint8Array([0, 1, 2, 0, 1, 2, 2, 0, 2, 2, 2, 0, 0, 0, 0, 0, 3, 4, 5, 0, 4, 5, 5, 0, 5, 5, 5, 0, 0, 0, 0, 0, 6, 7, 7, 0, 7, 7, 7, 0, 7, 7, 7, 0, 0, 0, 0, 0, 8, 8, 8, 0, 8, 8, 8, 0, 8, 8, 8, 0, 0, 0, 0, 0, 8, 8, 8, 0, 8, 8, 8, 0, 8, 8, 8]);
  7932. var BitModel = /*#__PURE__*/function () {
  7933. function BitModel(width, height, subband, zeroBitPlanes, mb) {
  7934. _classCallCheck(this, BitModel);
  7935. this.width = width;
  7936. this.height = height;
  7937. var contextLabelTable;
  7938. if (subband === "HH") {
  7939. contextLabelTable = HHContextLabel;
  7940. } else if (subband === "HL") {
  7941. contextLabelTable = HLContextLabel;
  7942. } else {
  7943. contextLabelTable = LLAndLHContextsLabel;
  7944. }
  7945. this.contextLabelTable = contextLabelTable;
  7946. var coefficientCount = width * height;
  7947. this.neighborsSignificance = new Uint8Array(coefficientCount);
  7948. this.coefficentsSign = new Uint8Array(coefficientCount);
  7949. var coefficentsMagnitude;
  7950. if (mb > 14) {
  7951. coefficentsMagnitude = new Uint32Array(coefficientCount);
  7952. } else if (mb > 6) {
  7953. coefficentsMagnitude = new Uint16Array(coefficientCount);
  7954. } else {
  7955. coefficentsMagnitude = new Uint8Array(coefficientCount);
  7956. }
  7957. this.coefficentsMagnitude = coefficentsMagnitude;
  7958. this.processingFlags = new Uint8Array(coefficientCount);
  7959. var bitsDecoded = new Uint8Array(coefficientCount);
  7960. if (zeroBitPlanes !== 0) {
  7961. for (var i = 0; i < coefficientCount; i++) {
  7962. bitsDecoded[i] = zeroBitPlanes;
  7963. }
  7964. }
  7965. this.bitsDecoded = bitsDecoded;
  7966. this.reset();
  7967. }
  7968. _createClass(BitModel, [{
  7969. key: "setDecoder",
  7970. value: function setDecoder(decoder) {
  7971. this.decoder = decoder;
  7972. }
  7973. }, {
  7974. key: "reset",
  7975. value: function reset() {
  7976. this.contexts = new Int8Array(19);
  7977. this.contexts[0] = 4 << 1 | 0;
  7978. this.contexts[UNIFORM_CONTEXT] = 46 << 1 | 0;
  7979. this.contexts[RUNLENGTH_CONTEXT] = 3 << 1 | 0;
  7980. }
  7981. }, {
  7982. key: "setNeighborsSignificance",
  7983. value: function setNeighborsSignificance(row, column, index) {
  7984. var neighborsSignificance = this.neighborsSignificance;
  7985. var width = this.width,
  7986. height = this.height;
  7987. var left = column > 0;
  7988. var right = column + 1 < width;
  7989. var i;
  7990. if (row > 0) {
  7991. i = index - width;
  7992. if (left) {
  7993. neighborsSignificance[i - 1] += 0x10;
  7994. }
  7995. if (right) {
  7996. neighborsSignificance[i + 1] += 0x10;
  7997. }
  7998. neighborsSignificance[i] += 0x04;
  7999. }
  8000. if (row + 1 < height) {
  8001. i = index + width;
  8002. if (left) {
  8003. neighborsSignificance[i - 1] += 0x10;
  8004. }
  8005. if (right) {
  8006. neighborsSignificance[i + 1] += 0x10;
  8007. }
  8008. neighborsSignificance[i] += 0x04;
  8009. }
  8010. if (left) {
  8011. neighborsSignificance[index - 1] += 0x01;
  8012. }
  8013. if (right) {
  8014. neighborsSignificance[index + 1] += 0x01;
  8015. }
  8016. neighborsSignificance[index] |= 0x80;
  8017. }
  8018. }, {
  8019. key: "runSignificancePropagationPass",
  8020. value: function runSignificancePropagationPass() {
  8021. var decoder = this.decoder;
  8022. var width = this.width,
  8023. height = this.height;
  8024. var coefficentsMagnitude = this.coefficentsMagnitude;
  8025. var coefficentsSign = this.coefficentsSign;
  8026. var neighborsSignificance = this.neighborsSignificance;
  8027. var processingFlags = this.processingFlags;
  8028. var contexts = this.contexts;
  8029. var labels = this.contextLabelTable;
  8030. var bitsDecoded = this.bitsDecoded;
  8031. var processedInverseMask = ~1;
  8032. var processedMask = 1;
  8033. var firstMagnitudeBitMask = 2;
  8034. for (var i0 = 0; i0 < height; i0 += 4) {
  8035. for (var j = 0; j < width; j++) {
  8036. var index = i0 * width + j;
  8037. for (var i1 = 0; i1 < 4; i1++, index += width) {
  8038. var i = i0 + i1;
  8039. if (i >= height) {
  8040. break;
  8041. }
  8042. processingFlags[index] &= processedInverseMask;
  8043. if (coefficentsMagnitude[index] || !neighborsSignificance[index]) {
  8044. continue;
  8045. }
  8046. var contextLabel = labels[neighborsSignificance[index]];
  8047. var decision = decoder.readBit(contexts, contextLabel);
  8048. if (decision) {
  8049. var sign = this.decodeSignBit(i, j, index);
  8050. coefficentsSign[index] = sign;
  8051. coefficentsMagnitude[index] = 1;
  8052. this.setNeighborsSignificance(i, j, index);
  8053. processingFlags[index] |= firstMagnitudeBitMask;
  8054. }
  8055. bitsDecoded[index]++;
  8056. processingFlags[index] |= processedMask;
  8057. }
  8058. }
  8059. }
  8060. }
  8061. }, {
  8062. key: "decodeSignBit",
  8063. value: function decodeSignBit(row, column, index) {
  8064. var width = this.width,
  8065. height = this.height;
  8066. var coefficentsMagnitude = this.coefficentsMagnitude;
  8067. var coefficentsSign = this.coefficentsSign;
  8068. var contribution, sign0, sign1, significance1;
  8069. var contextLabel, decoded;
  8070. significance1 = column > 0 && coefficentsMagnitude[index - 1] !== 0;
  8071. if (column + 1 < width && coefficentsMagnitude[index + 1] !== 0) {
  8072. sign1 = coefficentsSign[index + 1];
  8073. if (significance1) {
  8074. sign0 = coefficentsSign[index - 1];
  8075. contribution = 1 - sign1 - sign0;
  8076. } else {
  8077. contribution = 1 - sign1 - sign1;
  8078. }
  8079. } else if (significance1) {
  8080. sign0 = coefficentsSign[index - 1];
  8081. contribution = 1 - sign0 - sign0;
  8082. } else {
  8083. contribution = 0;
  8084. }
  8085. var horizontalContribution = 3 * contribution;
  8086. significance1 = row > 0 && coefficentsMagnitude[index - width] !== 0;
  8087. if (row + 1 < height && coefficentsMagnitude[index + width] !== 0) {
  8088. sign1 = coefficentsSign[index + width];
  8089. if (significance1) {
  8090. sign0 = coefficentsSign[index - width];
  8091. contribution = 1 - sign1 - sign0 + horizontalContribution;
  8092. } else {
  8093. contribution = 1 - sign1 - sign1 + horizontalContribution;
  8094. }
  8095. } else if (significance1) {
  8096. sign0 = coefficentsSign[index - width];
  8097. contribution = 1 - sign0 - sign0 + horizontalContribution;
  8098. } else {
  8099. contribution = horizontalContribution;
  8100. }
  8101. if (contribution >= 0) {
  8102. contextLabel = 9 + contribution;
  8103. decoded = this.decoder.readBit(this.contexts, contextLabel);
  8104. } else {
  8105. contextLabel = 9 - contribution;
  8106. decoded = this.decoder.readBit(this.contexts, contextLabel) ^ 1;
  8107. }
  8108. return decoded;
  8109. }
  8110. }, {
  8111. key: "runMagnitudeRefinementPass",
  8112. value: function runMagnitudeRefinementPass() {
  8113. var decoder = this.decoder;
  8114. var width = this.width,
  8115. height = this.height;
  8116. var coefficentsMagnitude = this.coefficentsMagnitude;
  8117. var neighborsSignificance = this.neighborsSignificance;
  8118. var contexts = this.contexts;
  8119. var bitsDecoded = this.bitsDecoded;
  8120. var processingFlags = this.processingFlags;
  8121. var processedMask = 1;
  8122. var firstMagnitudeBitMask = 2;
  8123. var length = width * height;
  8124. var width4 = width * 4;
  8125. for (var index0 = 0, indexNext; index0 < length; index0 = indexNext) {
  8126. indexNext = Math.min(length, index0 + width4);
  8127. for (var j = 0; j < width; j++) {
  8128. for (var index = index0 + j; index < indexNext; index += width) {
  8129. if (!coefficentsMagnitude[index] || (processingFlags[index] & processedMask) !== 0) {
  8130. continue;
  8131. }
  8132. var contextLabel = 16;
  8133. if ((processingFlags[index] & firstMagnitudeBitMask) !== 0) {
  8134. processingFlags[index] ^= firstMagnitudeBitMask;
  8135. var significance = neighborsSignificance[index] & 127;
  8136. contextLabel = significance === 0 ? 15 : 14;
  8137. }
  8138. var bit = decoder.readBit(contexts, contextLabel);
  8139. coefficentsMagnitude[index] = coefficentsMagnitude[index] << 1 | bit;
  8140. bitsDecoded[index]++;
  8141. processingFlags[index] |= processedMask;
  8142. }
  8143. }
  8144. }
  8145. }
  8146. }, {
  8147. key: "runCleanupPass",
  8148. value: function runCleanupPass() {
  8149. var decoder = this.decoder;
  8150. var width = this.width,
  8151. height = this.height;
  8152. var neighborsSignificance = this.neighborsSignificance;
  8153. var coefficentsMagnitude = this.coefficentsMagnitude;
  8154. var coefficentsSign = this.coefficentsSign;
  8155. var contexts = this.contexts;
  8156. var labels = this.contextLabelTable;
  8157. var bitsDecoded = this.bitsDecoded;
  8158. var processingFlags = this.processingFlags;
  8159. var processedMask = 1;
  8160. var firstMagnitudeBitMask = 2;
  8161. var oneRowDown = width;
  8162. var twoRowsDown = width * 2;
  8163. var threeRowsDown = width * 3;
  8164. var iNext;
  8165. for (var i0 = 0; i0 < height; i0 = iNext) {
  8166. iNext = Math.min(i0 + 4, height);
  8167. var indexBase = i0 * width;
  8168. var checkAllEmpty = i0 + 3 < height;
  8169. for (var j = 0; j < width; j++) {
  8170. var index0 = indexBase + j;
  8171. var allEmpty = checkAllEmpty && processingFlags[index0] === 0 && processingFlags[index0 + oneRowDown] === 0 && processingFlags[index0 + twoRowsDown] === 0 && processingFlags[index0 + threeRowsDown] === 0 && neighborsSignificance[index0] === 0 && neighborsSignificance[index0 + oneRowDown] === 0 && neighborsSignificance[index0 + twoRowsDown] === 0 && neighborsSignificance[index0 + threeRowsDown] === 0;
  8172. var i1 = 0,
  8173. index = index0;
  8174. var i = i0,
  8175. sign = void 0;
  8176. if (allEmpty) {
  8177. var hasSignificantCoefficent = decoder.readBit(contexts, RUNLENGTH_CONTEXT);
  8178. if (!hasSignificantCoefficent) {
  8179. bitsDecoded[index0]++;
  8180. bitsDecoded[index0 + oneRowDown]++;
  8181. bitsDecoded[index0 + twoRowsDown]++;
  8182. bitsDecoded[index0 + threeRowsDown]++;
  8183. continue;
  8184. }
  8185. i1 = decoder.readBit(contexts, UNIFORM_CONTEXT) << 1 | decoder.readBit(contexts, UNIFORM_CONTEXT);
  8186. if (i1 !== 0) {
  8187. i = i0 + i1;
  8188. index += i1 * width;
  8189. }
  8190. sign = this.decodeSignBit(i, j, index);
  8191. coefficentsSign[index] = sign;
  8192. coefficentsMagnitude[index] = 1;
  8193. this.setNeighborsSignificance(i, j, index);
  8194. processingFlags[index] |= firstMagnitudeBitMask;
  8195. index = index0;
  8196. for (var i2 = i0; i2 <= i; i2++, index += width) {
  8197. bitsDecoded[index]++;
  8198. }
  8199. i1++;
  8200. }
  8201. for (i = i0 + i1; i < iNext; i++, index += width) {
  8202. if (coefficentsMagnitude[index] || (processingFlags[index] & processedMask) !== 0) {
  8203. continue;
  8204. }
  8205. var contextLabel = labels[neighborsSignificance[index]];
  8206. var decision = decoder.readBit(contexts, contextLabel);
  8207. if (decision === 1) {
  8208. sign = this.decodeSignBit(i, j, index);
  8209. coefficentsSign[index] = sign;
  8210. coefficentsMagnitude[index] = 1;
  8211. this.setNeighborsSignificance(i, j, index);
  8212. processingFlags[index] |= firstMagnitudeBitMask;
  8213. }
  8214. bitsDecoded[index]++;
  8215. }
  8216. }
  8217. }
  8218. }
  8219. }, {
  8220. key: "checkSegmentationSymbol",
  8221. value: function checkSegmentationSymbol() {
  8222. var decoder = this.decoder;
  8223. var contexts = this.contexts;
  8224. var symbol = decoder.readBit(contexts, UNIFORM_CONTEXT) << 3 | decoder.readBit(contexts, UNIFORM_CONTEXT) << 2 | decoder.readBit(contexts, UNIFORM_CONTEXT) << 1 | decoder.readBit(contexts, UNIFORM_CONTEXT);
  8225. if (symbol !== 0xa) {
  8226. throw new JpxError("Invalid segmentation symbol");
  8227. }
  8228. }
  8229. }]);
  8230. return BitModel;
  8231. }();
  8232. return BitModel;
  8233. }();
  8234. var Transform = /*#__PURE__*/function () {
  8235. function Transform() {
  8236. _classCallCheck(this, Transform);
  8237. if (this.constructor === Transform) {
  8238. (0, _util.unreachable)("Cannot initialize Transform.");
  8239. }
  8240. }
  8241. _createClass(Transform, [{
  8242. key: "calculate",
  8243. value: function calculate(subbands, u0, v0) {
  8244. var ll = subbands[0];
  8245. for (var i = 1, ii = subbands.length; i < ii; i++) {
  8246. ll = this.iterate(ll, subbands[i], u0, v0);
  8247. }
  8248. return ll;
  8249. }
  8250. }, {
  8251. key: "extend",
  8252. value: function extend(buffer, offset, size) {
  8253. var i1 = offset - 1,
  8254. j1 = offset + 1;
  8255. var i2 = offset + size - 2,
  8256. j2 = offset + size;
  8257. buffer[i1--] = buffer[j1++];
  8258. buffer[j2++] = buffer[i2--];
  8259. buffer[i1--] = buffer[j1++];
  8260. buffer[j2++] = buffer[i2--];
  8261. buffer[i1--] = buffer[j1++];
  8262. buffer[j2++] = buffer[i2--];
  8263. buffer[i1] = buffer[j1];
  8264. buffer[j2] = buffer[i2];
  8265. }
  8266. }, {
  8267. key: "filter",
  8268. value: function filter(x, offset, length) {
  8269. (0, _util.unreachable)("Abstract method `filter` called");
  8270. }
  8271. }, {
  8272. key: "iterate",
  8273. value: function iterate(ll, hl_lh_hh, u0, v0) {
  8274. var llWidth = ll.width,
  8275. llHeight = ll.height;
  8276. var llItems = ll.items;
  8277. var width = hl_lh_hh.width;
  8278. var height = hl_lh_hh.height;
  8279. var items = hl_lh_hh.items;
  8280. var i, j, k, l, u, v;
  8281. for (k = 0, i = 0; i < llHeight; i++) {
  8282. l = i * 2 * width;
  8283. for (j = 0; j < llWidth; j++, k++, l += 2) {
  8284. items[l] = llItems[k];
  8285. }
  8286. }
  8287. llItems = ll.items = null;
  8288. var bufferPadding = 4;
  8289. var rowBuffer = new Float32Array(width + 2 * bufferPadding);
  8290. if (width === 1) {
  8291. if ((u0 & 1) !== 0) {
  8292. for (v = 0, k = 0; v < height; v++, k += width) {
  8293. items[k] *= 0.5;
  8294. }
  8295. }
  8296. } else {
  8297. for (v = 0, k = 0; v < height; v++, k += width) {
  8298. rowBuffer.set(items.subarray(k, k + width), bufferPadding);
  8299. this.extend(rowBuffer, bufferPadding, width);
  8300. this.filter(rowBuffer, bufferPadding, width);
  8301. items.set(rowBuffer.subarray(bufferPadding, bufferPadding + width), k);
  8302. }
  8303. }
  8304. var numBuffers = 16;
  8305. var colBuffers = [];
  8306. for (i = 0; i < numBuffers; i++) {
  8307. colBuffers.push(new Float32Array(height + 2 * bufferPadding));
  8308. }
  8309. var b,
  8310. currentBuffer = 0;
  8311. ll = bufferPadding + height;
  8312. if (height === 1) {
  8313. if ((v0 & 1) !== 0) {
  8314. for (u = 0; u < width; u++) {
  8315. items[u] *= 0.5;
  8316. }
  8317. }
  8318. } else {
  8319. for (u = 0; u < width; u++) {
  8320. if (currentBuffer === 0) {
  8321. numBuffers = Math.min(width - u, numBuffers);
  8322. for (k = u, l = bufferPadding; l < ll; k += width, l++) {
  8323. for (b = 0; b < numBuffers; b++) {
  8324. colBuffers[b][l] = items[k + b];
  8325. }
  8326. }
  8327. currentBuffer = numBuffers;
  8328. }
  8329. currentBuffer--;
  8330. var buffer = colBuffers[currentBuffer];
  8331. this.extend(buffer, bufferPadding, height);
  8332. this.filter(buffer, bufferPadding, height);
  8333. if (currentBuffer === 0) {
  8334. k = u - numBuffers + 1;
  8335. for (l = bufferPadding; l < ll; k += width, l++) {
  8336. for (b = 0; b < numBuffers; b++) {
  8337. items[k + b] = colBuffers[b][l];
  8338. }
  8339. }
  8340. }
  8341. }
  8342. }
  8343. return {
  8344. width: width,
  8345. height: height,
  8346. items: items
  8347. };
  8348. }
  8349. }]);
  8350. return Transform;
  8351. }();
  8352. var IrreversibleTransform = /*#__PURE__*/function (_Transform) {
  8353. _inherits(IrreversibleTransform, _Transform);
  8354. var _super2 = _createSuper(IrreversibleTransform);
  8355. function IrreversibleTransform() {
  8356. _classCallCheck(this, IrreversibleTransform);
  8357. return _super2.apply(this, arguments);
  8358. }
  8359. _createClass(IrreversibleTransform, [{
  8360. key: "filter",
  8361. value: function filter(x, offset, length) {
  8362. var len = length >> 1;
  8363. offset |= 0;
  8364. var j, n, current, next;
  8365. var alpha = -1.586134342059924;
  8366. var beta = -0.052980118572961;
  8367. var gamma = 0.882911075530934;
  8368. var delta = 0.443506852043971;
  8369. var K = 1.230174104914001;
  8370. var K_ = 1 / K;
  8371. j = offset - 3;
  8372. for (n = len + 4; n--; j += 2) {
  8373. x[j] *= K_;
  8374. }
  8375. j = offset - 2;
  8376. current = delta * x[j - 1];
  8377. for (n = len + 3; n--; j += 2) {
  8378. next = delta * x[j + 1];
  8379. x[j] = K * x[j] - current - next;
  8380. if (n--) {
  8381. j += 2;
  8382. current = delta * x[j + 1];
  8383. x[j] = K * x[j] - current - next;
  8384. } else {
  8385. break;
  8386. }
  8387. }
  8388. j = offset - 1;
  8389. current = gamma * x[j - 1];
  8390. for (n = len + 2; n--; j += 2) {
  8391. next = gamma * x[j + 1];
  8392. x[j] -= current + next;
  8393. if (n--) {
  8394. j += 2;
  8395. current = gamma * x[j + 1];
  8396. x[j] -= current + next;
  8397. } else {
  8398. break;
  8399. }
  8400. }
  8401. j = offset;
  8402. current = beta * x[j - 1];
  8403. for (n = len + 1; n--; j += 2) {
  8404. next = beta * x[j + 1];
  8405. x[j] -= current + next;
  8406. if (n--) {
  8407. j += 2;
  8408. current = beta * x[j + 1];
  8409. x[j] -= current + next;
  8410. } else {
  8411. break;
  8412. }
  8413. }
  8414. if (len !== 0) {
  8415. j = offset + 1;
  8416. current = alpha * x[j - 1];
  8417. for (n = len; n--; j += 2) {
  8418. next = alpha * x[j + 1];
  8419. x[j] -= current + next;
  8420. if (n--) {
  8421. j += 2;
  8422. current = alpha * x[j + 1];
  8423. x[j] -= current + next;
  8424. } else {
  8425. break;
  8426. }
  8427. }
  8428. }
  8429. }
  8430. }]);
  8431. return IrreversibleTransform;
  8432. }(Transform);
  8433. var ReversibleTransform = /*#__PURE__*/function (_Transform2) {
  8434. _inherits(ReversibleTransform, _Transform2);
  8435. var _super3 = _createSuper(ReversibleTransform);
  8436. function ReversibleTransform() {
  8437. _classCallCheck(this, ReversibleTransform);
  8438. return _super3.apply(this, arguments);
  8439. }
  8440. _createClass(ReversibleTransform, [{
  8441. key: "filter",
  8442. value: function filter(x, offset, length) {
  8443. var len = length >> 1;
  8444. offset |= 0;
  8445. var j, n;
  8446. for (j = offset, n = len + 1; n--; j += 2) {
  8447. x[j] -= x[j - 1] + x[j + 1] + 2 >> 2;
  8448. }
  8449. for (j = offset + 1, n = len; n--; j += 2) {
  8450. x[j] += x[j - 1] + x[j + 1] >> 1;
  8451. }
  8452. }
  8453. }]);
  8454. return ReversibleTransform;
  8455. }(Transform);
  8456. /***/ })
  8457. /******/ ]);
  8458. /************************************************************************/
  8459. /******/ // The module cache
  8460. /******/ var __webpack_module_cache__ = {};
  8461. /******/
  8462. /******/ // The require function
  8463. /******/ function __w_pdfjs_require__(moduleId) {
  8464. /******/ // Check if module is in cache
  8465. /******/ var cachedModule = __webpack_module_cache__[moduleId];
  8466. /******/ if (cachedModule !== undefined) {
  8467. /******/ return cachedModule.exports;
  8468. /******/ }
  8469. /******/ // Create a new module (and put it into the cache)
  8470. /******/ var module = __webpack_module_cache__[moduleId] = {
  8471. /******/ id: moduleId,
  8472. /******/ loaded: false,
  8473. /******/ exports: {}
  8474. /******/ };
  8475. /******/
  8476. /******/ // Execute the module function
  8477. /******/ __webpack_modules__[moduleId](module, module.exports, __w_pdfjs_require__);
  8478. /******/
  8479. /******/ // Flag the module as loaded
  8480. /******/ module.loaded = true;
  8481. /******/
  8482. /******/ // Return the exports of the module
  8483. /******/ return module.exports;
  8484. /******/ }
  8485. /******/
  8486. /************************************************************************/
  8487. /******/ /* webpack/runtime/node module decorator */
  8488. /******/ (() => {
  8489. /******/ __w_pdfjs_require__.nmd = (module) => {
  8490. /******/ module.paths = [];
  8491. /******/ if (!module.children) module.children = [];
  8492. /******/ return module;
  8493. /******/ };
  8494. /******/ })();
  8495. /******/
  8496. /************************************************************************/
  8497. var __webpack_exports__ = {};
  8498. // This entry need to be wrapped in an IIFE because it need to be isolated against other modules in the chunk.
  8499. (() => {
  8500. var exports = __webpack_exports__;
  8501. Object.defineProperty(exports, "__esModule", ({
  8502. value: true
  8503. }));
  8504. Object.defineProperty(exports, "Jbig2Image", ({
  8505. enumerable: true,
  8506. get: function get() {
  8507. return _jbig.Jbig2Image;
  8508. }
  8509. }));
  8510. Object.defineProperty(exports, "JpegImage", ({
  8511. enumerable: true,
  8512. get: function get() {
  8513. return _jpg.JpegImage;
  8514. }
  8515. }));
  8516. Object.defineProperty(exports, "JpxImage", ({
  8517. enumerable: true,
  8518. get: function get() {
  8519. return _jpx.JpxImage;
  8520. }
  8521. }));
  8522. Object.defineProperty(exports, "getVerbosityLevel", ({
  8523. enumerable: true,
  8524. get: function get() {
  8525. return _util.getVerbosityLevel;
  8526. }
  8527. }));
  8528. Object.defineProperty(exports, "setVerbosityLevel", ({
  8529. enumerable: true,
  8530. get: function get() {
  8531. return _util.setVerbosityLevel;
  8532. }
  8533. }));
  8534. var _util = __w_pdfjs_require__(1);
  8535. var _jbig = __w_pdfjs_require__(4);
  8536. var _jpg = __w_pdfjs_require__(12);
  8537. var _jpx = __w_pdfjs_require__(13);
  8538. var pdfjsVersion = '2.14.305';
  8539. var pdfjsBuild = 'eaaa8b4ad';
  8540. })();
  8541. /******/ return __webpack_exports__;
  8542. /******/ })()
  8543. ;
  8544. });
  8545. //# sourceMappingURL=pdf.image_decoders.js.map