2
0

pdf.image_decoders.js 290 KB

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