pdf.image_decoders.js 234 KB

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