pdf.image_decoders.js 232 KB

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