pdf.image_decoders.js 237 KB

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