pdf.image_decoders.js 233 KB

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