pdf.image_decoders.js 290 KB

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