pdf.image_decoders.js 237 KB

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