2
0

pdf.image_decoders.js 241 KB

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