pdf.image_decoders.js 289 KB

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